![]() |
HepMC Reference DocumentationHepMC |
00001 00002 // Matt.Dobbs@Cern.CH, Feb 2000 00003 // Example of applying an event selection to the events written to file 00004 // using example_MyPythia.cxx 00005 // Events containing a photon of pT > 25 GeV pass the selection and are 00006 // written to "example_EventSelection.dat" 00008 // To Compile: go to the HepMC directory and type: 00009 // gmake examples/example_EventSelection.exe 00010 // 00011 00012 #include "HepMC/IO_GenEvent.h" 00013 #include "HepMC/GenEvent.h" 00014 00016 00020 class IsEventGood { 00021 public: 00023 bool operator()( const HepMC::GenEvent* evt ) { 00024 for ( HepMC::GenEvent::particle_const_iterator p 00025 = evt->particles_begin(); p != evt->particles_end(); ++p ){ 00026 if ( (*p)->pdg_id() == 22 && (*p)->momentum().perp() > 25. ) { 00027 //std::cout << "Event " << evt->event_number() 00028 // << " is a good event." << std::endl; 00029 //(*p)->print(); 00030 return 1; 00031 } 00032 } 00033 return 0; 00034 } 00035 }; 00036 00037 int main() { 00038 // declare an input strategy to read the data produced with the 00039 // example_MyPythia 00040 { // begin scope of ascii_in and ascii_out 00041 HepMC::IO_GenEvent ascii_in("example_MyPythia.dat",std::ios::in); 00042 // declare another IO_GenEvent for writing out the good events 00043 HepMC::IO_GenEvent ascii_out("example_EventSelection.dat",std::ios::out); 00044 // declare an instance of the event selection predicate 00045 IsEventGood is_good_event; 00046 //........................................EVENT LOOP 00047 int icount=0; 00048 int num_good_events=0; 00049 HepMC::GenEvent* evt = ascii_in.read_next_event(); 00050 while ( evt ) { 00051 icount++; 00052 if ( icount%50==1 ) std::cout << "Processing Event Number " << icount 00053 << " its # " << evt->event_number() 00054 << std::endl; 00055 if ( is_good_event(evt) ) { 00056 ascii_out << evt; 00057 ++num_good_events; 00058 } 00059 delete evt; 00060 ascii_in >> evt; 00061 } 00062 //........................................PRINT RESULT 00063 std::cout << num_good_events << " out of " << icount 00064 << " processed events passed the cuts. Finished." << std::endl; 00065 } // end scope of ascii_in and ascii_out 00066 return 0; 00067 } 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077