![]() |
HepMC Reference DocumentationHepMC |
00001 //------------------------------------------------------------------- 00002 // testMass.cc.in 00003 // 00004 // garren@fnal.gov, March 2006 00005 // Read events written by example_MyPythia.cc 00006 // Select events containing a photon of pT > 25 GeV 00007 // Add arbitrary PDF information to one of the good events 00008 // Add arbitrary HeavyIon information to one of the good events 00009 // Write the selected events and read them back in using an istream 00010 //------------------------------------------------------------------- 00011 00012 #include <cmath> // for min() 00013 00014 #include "HepMC/IO_GenEvent.h" 00015 #include "HepMC/GenEvent.h" 00016 #include "HepMC/Version.h" 00017 00018 // define methods and classes used by this test 00019 #include "IsGoodEvent.h" 00020 00021 void massInfo( const HepMC::GenEvent* ); 00022 00023 int main() { 00024 // read and process the input file 00025 { 00026 // declare an input strategy to read the data produced with the 00027 // example_MyPythia 00028 HepMC::IO_GenEvent ascii_in("@srcdir@/testIOGenEvent.input",std::ios::in); 00029 ascii_in.use_input_units( HepMC::Units::GEV, HepMC::Units::MM ); 00030 // declare another IO_GenEvent for output 00031 HepMC::IO_GenEvent ascii_out("testMass1.out",std::ios::out); 00032 // declare an instance of the event selection predicate 00033 IsGoodEvent is_good_event; 00034 // send version to standard output 00035 HepMC::version(); 00036 //........................................EVENT LOOP 00037 int icount=0; 00038 int num_good_events=0; 00039 double x1=0., x2=0., q=0., xf1=0., xf2=0.; 00040 HepMC::GenEvent* evt = ascii_in.read_next_event(); 00041 while ( evt ) { 00042 icount++; 00043 if ( icount%50==1 ) std::cout << "Processing Event Number " << icount 00044 << " its # " << evt->event_number() 00045 << std::endl; 00046 if ( is_good_event(evt) ) { 00047 if (num_good_events == 0 ) { 00048 // add some arbitrary PDF information 00049 x1 = std::min(0.8, 0.07 * icount); 00050 x2 = 1-x1; 00051 q = 1.69 * icount; 00052 // use beam momentum 00053 if( evt->valid_beam_particles() ) { 00054 HepMC::GenParticle* bp1 = evt->beam_particles().first; 00055 xf1 = x1*bp1->momentum().rho(); 00056 xf2 = x2*bp1->momentum().rho(); 00057 } else { 00058 xf1 = x1*0.34; 00059 xf2 = x2*0.34; 00060 } 00061 // provide optional pdf set id numbers 00062 // (two ints at the end of the constructor) 00063 HepMC::PdfInfo pdf( 2, 3, x1, x2, q, xf1, xf2, 230, 230); 00064 evt->set_pdf_info(pdf); 00065 // add some arbitrary HeavyIon information 00066 HepMC::HeavyIon ion(23,11,12,15,3,5,0,0,0,0.0145); 00067 evt->set_heavy_ion( ion ); 00068 } 00069 ascii_out << evt; 00070 ++num_good_events; 00071 } 00072 00073 // clean up and get next event 00074 delete evt; 00075 ascii_in >> evt; 00076 } 00077 //........................................PRINT RESULT 00078 std::cout << num_good_events << " out of " << icount 00079 << " processed events passed the cuts. Finished." << std::endl; 00080 } 00081 // now read the file we just created 00082 { 00083 // declare an input strategy 00084 const char infile[] = "testMass1.out"; 00085 std::ifstream istr( infile ); 00086 if( !istr ) { 00087 std::cerr << "testMass: cannot open " << infile << std::endl; 00088 exit(-1); 00089 } 00090 HepMC::IO_GenEvent xin(istr); 00091 // declare another IO_GenEvent for output 00092 HepMC::IO_GenEvent xout("testMass2.out",std::ios::out); 00093 //........................................EVENT LOOP 00094 int ixin=0; 00095 HepMC::GenEvent* evt = xin.read_next_event(); 00096 while ( evt ) { 00097 ixin++; 00098 std::cout << "reading Event " << ixin << std::endl; 00099 xout << evt; 00100 // look at mass info 00101 massInfo(evt); 00102 00103 // clean up and get next event 00104 delete evt; 00105 xin >> evt; 00106 } 00107 //........................................PRINT RESULT 00108 std::cout << ixin 00109 << " events in the second pass. Finished." << std::endl; 00110 } 00111 } 00112 00113 void massInfo( const HepMC::GenEvent* e ) 00114 { 00115 double gm, m, d; 00116 for ( HepMC::GenEvent::particle_const_iterator p = e->particles_begin(); p != e->particles_end(); 00117 ++p ) { 00118 00119 gm = (*p)->generated_mass(); 00120 m = (*p)->momentum().m(); 00121 d = fabs(m-gm); 00122 if( d > 1.0e-5 ) { 00123 std::cout << "Event " << e->event_number() 00124 << " Particle " << (*p)->barcode() 00125 << " " << (*p)->pdg_id() 00126 << " generated mass " << gm 00127 << " mass from momentum " << m 00128 << " difference " << d << std::endl; 00129 } 00130 } 00131 }