00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include <list>
00013
00014 #include "HepMC/IO_GenEvent.h"
00015 #include "HepMC/IO_AsciiParticles.h"
00016 #include "HepMC/GenEvent.h"
00017
00018
00019 #include "IsGoodEvent.h"
00020 #include "testHepMCIteration.h"
00021
00022 bool findW( HepMC::GenEvent* evt, std::ofstream& os);
00023 bool simpleIter( HepMC::GenEvent* evt, std::ofstream& os );
00024
00025 int main() {
00026
00027
00028 HepMC::IO_GenEvent ascii_in("@srcdir@/testIOGenEvent.input",std::ios::in);
00029
00030 IsGoodEvent is_good_event;
00031
00032 std::ofstream os( "testHepMCIteration.out" );
00033
00034 int icount=0;
00035 int num_good_events=0;
00036 HepMC::GenEvent* evt = ascii_in.read_next_event();
00037 HepMC::GenEvent* evcopy;
00038 while ( evt ) {
00039 icount++;
00040 if ( icount%50==1 ) std::cout << "Processing Event Number " << icount
00041 << " its # " << evt->event_number()
00042 << std::endl;
00043
00044 if ( icount==100 ) std::cout << "Processing Event Number " << icount
00045 << " its # " << evt->event_number()
00046 << std::endl;
00047 evcopy = evt;
00048 if ( is_good_event(evcopy) ) {
00049 os << "Event " << evcopy->event_number() << " is good " << std::endl;
00050 ++num_good_events;
00051
00052 simpleIter( evcopy, os );
00053 findW( evcopy, os );
00054 }
00055 evcopy->clear();
00056
00057
00058 delete evt;
00059 evt = ascii_in.read_next_event();
00060 }
00061
00062 std::cout << num_good_events << " out of " << icount
00063 << " processed events passed the cuts. Finished." << std::endl;
00064 }
00065
00066 bool simpleIter( HepMC::GenEvent* evt, std::ofstream& os )
00067 {
00068
00069
00070 std::list<HepMC::GenVertex*> allvertices;
00071 for ( HepMC::GenEvent::vertex_iterator v = evt->vertices_begin();
00072 v != evt->vertices_end(); ++v ) {
00073 allvertices.push_back(*v);
00074 }
00075
00076
00077 std::list<HepMC::GenVertex*> allvertices2;
00078 copy( evt->vertices_begin(), evt->vertices_end(),
00079 back_inserter(allvertices2) );
00080
00081
00082
00083 IsFinalState isfinal;
00084 std::list<HepMC::GenParticle*> finalstateparticles;
00085 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin();
00086 p != evt->particles_end(); ++p ) {
00087 if ( isfinal(*p) ) finalstateparticles.push_back(*p);
00088 }
00089
00090
00091
00092
00093 std::list<HepMC::GenParticle*> finalstateparticles2;
00094 HepMC::copy_if( evt->particles_begin(), evt->particles_end(),
00095 back_inserter(finalstateparticles2), IsFinalState() );
00096
00097
00098 os << "photons in event " << evt->event_number() << ":" << std::endl;
00099 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin();
00100 p != evt->particles_end(); ++p ) {
00101 if ( IsPhoton(*p) ) (*p)->print( os );
00102 }
00103 return true;
00104 }
00105
00106 bool findW( HepMC::GenEvent* evt, std::ofstream& os )
00107 {
00108 int num_W=0;
00109
00110
00111
00112
00113
00114
00115 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin();
00116 p != evt->particles_end(); ++p ) {
00117 if ( IsWBoson(*p) ) {
00118 ++num_W;
00119 os << "A W boson has been found in event: " << evt->event_number() << std::endl;
00120 (*p)->print( os );
00121
00122
00123
00124 os << "\t Its parents are: " << std::endl;
00125 if ( (*p)->production_vertex() ) {
00126 for ( HepMC::GenVertex::particle_iterator mother
00127 = (*p)->production_vertex()->
00128 particles_begin(HepMC::parents);
00129 mother != (*p)->production_vertex()->
00130 particles_end(HepMC::parents);
00131 ++mother ) {
00132 os << "\t";
00133 (*mother)->print( os );
00134 }
00135 }
00136
00137
00138 os << "\t\t" << "Its children are: " << std::endl;
00139 if ( (*p)->end_vertex() ) {
00140 for ( HepMC::GenVertex::particle_iterator child =
00141 (*p)->end_vertex()->particles_begin(HepMC::children);
00142 child != (*p)->end_vertex()->particles_end(HepMC::children);
00143 ++child ) {
00144
00145 HepMC::GenVertex::particle_iterator cp = child;
00146
00147 os << "\t\t\t (id,barcode,status) "
00148 << (*cp)->pdg_id() << " "
00149 << (*child)->barcode() << " "
00150 << (*cp)->status() << std::endl;
00151 }
00152 }
00153
00154
00155
00156
00157 os << "\t\t Its descendants are: " << std::endl;
00158 if ( (*p)->end_vertex() ) {
00159 for ( HepMC::GenVertex::particle_iterator des
00160 =(*p)->end_vertex()->
00161 particles_begin(HepMC::descendants);
00162 des != (*p)->end_vertex()->
00163 particles_end(HepMC::descendants);
00164 ++des ) {
00165 os << "\t\t";
00166 (*des)->print( os );
00167 }
00168 }
00169 }
00170 }
00171 return true;
00172 }
00173