00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <cmath>
00013 #include <ostream>
00014
00015 #include "HepMC/IO_GenEvent.h"
00016 #include "HepMC/GenEvent.h"
00017 #include "HepMC/Version.h"
00018
00019
00020 #include "IsGoodEvent.h"
00021
00022 void massInfo( const HepMC::GenEvent*, std::ostream& os );
00023
00024 int main() {
00025
00026 std::ofstream os( "testMass.cout" );
00027
00028 {
00029
00030
00031 HepMC::IO_GenEvent ascii_in("@srcdir@/testIOGenEvent.input",std::ios::in);
00032 ascii_in.use_input_units( HepMC::Units::GEV, HepMC::Units::MM );
00033
00034 HepMC::IO_GenEvent ascii_out("testMass1.out",std::ios::out);
00035
00036 IsGoodEvent is_good_event;
00037
00038 HepMC::version(os);
00039
00040 int icount=0;
00041 int num_good_events=0;
00042 double x1=0., x2=0., q=0., xf1=0., xf2=0.;
00043 HepMC::GenEvent* evt = ascii_in.read_next_event();
00044 while ( evt ) {
00045 icount++;
00046 if ( icount%50==1 ) os << "Processing Event Number " << icount
00047 << " its # " << evt->event_number()
00048 << std::endl;
00049 if ( is_good_event(evt) ) {
00050 if (num_good_events == 0 ) {
00051
00052 x1 = std::min(0.8, 0.07 * icount);
00053 x2 = 1-x1;
00054 q = 1.69 * icount;
00055
00056 if( evt->valid_beam_particles() ) {
00057 HepMC::GenParticle* bp1 = evt->beam_particles().first;
00058 xf1 = x1*bp1->momentum().rho();
00059 xf2 = x2*bp1->momentum().rho();
00060 } else {
00061 xf1 = x1*0.34;
00062 xf2 = x2*0.34;
00063 }
00064
00065
00066 HepMC::PdfInfo pdf( 2, 3, x1, x2, q, xf1, xf2, 230, 230);
00067 evt->set_pdf_info(pdf);
00068
00069 HepMC::HeavyIon ion(23,11,12,15,3,5,0,0,0,0.0145);
00070 evt->set_heavy_ion( ion );
00071 }
00072 os << "saving Event " << evt->event_number() << std::endl;
00073 if( evt->weights().size() > 0 ) {
00074 os << "Weights: ";
00075 evt->weights().print(os);
00076 }
00077 ascii_out << evt;
00078 ++num_good_events;
00079 }
00080
00081
00082 delete evt;
00083 ascii_in >> evt;
00084 }
00085
00086 os << num_good_events << " out of " << icount
00087 << " processed events passed the cuts. Finished." << std::endl;
00088 }
00089
00090 {
00091
00092 const char infile[] = "testMass1.out";
00093 std::ifstream istr( infile );
00094 if( !istr ) {
00095 std::cerr << "testMass: cannot open " << infile << std::endl;
00096 exit(-1);
00097 }
00098 HepMC::IO_GenEvent xin(istr);
00099
00100 HepMC::IO_GenEvent xout("testMass2.out",std::ios::out);
00101
00102 int ixin=0;
00103 HepMC::GenEvent* evt = xin.read_next_event();
00104 while ( evt ) {
00105 ixin++;
00106 os << "reading Event " << evt->event_number() << std::endl;
00107 if( evt->weights().size() > 0 ) {
00108 os << "Weights: ";
00109 evt->weights().print(os);
00110 }
00111 xout << evt;
00112
00113 massInfo(evt,os);
00114
00115
00116 delete evt;
00117 xin >> evt;
00118 }
00119
00120 os << ixin << " events in the second pass. Finished." << std::endl;
00121 }
00122 }
00123
00124 void massInfo( const HepMC::GenEvent* e, std::ostream& os )
00125 {
00126 double gm, m, d;
00127 for ( HepMC::GenEvent::particle_const_iterator p = e->particles_begin(); p != e->particles_end();
00128 ++p ) {
00129
00130 gm = (*p)->generated_mass();
00131 m = (*p)->momentum().m();
00132 d = fabs(m-gm);
00133 if( d > 1.0e-5 ) {
00134 os << "Event " << e->event_number()
00135 << " Particle " << (*p)->barcode()
00136 << " " << (*p)->pdg_id()
00137 << " generated mass " << gm
00138 << " mass from momentum " << m
00139 << " difference " << d << std::endl;
00140 }
00141 }
00142 }