10 #include "Pythia8/Pythia.h"
11 #include "Pythia8Plugins/HepMC2.h"
15 #include "HepMCEvent.H"
19 #include "Photos/Photos.h"
20 #include "Photos/PhotosHepMCEvent.h"
21 #include "Photos/Log.h"
24 using namespace Pythia8;
25 using namespace Photospp;
28 unsigned long NumberOfEvents = 10000;
29 unsigned int EventsToCheck=20;
35 void checkMomentumConservationInEvent(HepMC::GenEvent *evt)
39 double px=0.0,py=0.0,pz=0.0,e=0.0;
41 for ( HepMC::GenEvent::particle_const_iterator p = evt->particles_begin();
42 p != evt->particles_end(); ++p )
44 if( (*p)->status() == 1 )
46 HepMC::FourVector m = (*p)->momentum();
55 cout.setf(ios_base::scientific, ios_base::floatfield);
56 cout<<endl<<
"Vector Sum: "<<px<<
" "<<py<<
" "<<pz<<
" "<<e<<endl;
75 void switch_history_entries_status(HepMC::GenEvent *evt)
77 for ( HepMC::GenEvent::particle_const_iterator p = evt->particles_begin();
78 p != evt->particles_end(); ++p )
82 if((*p)->pdg_id()==22)
continue;
84 int barcode = (*p)->barcode();
86 HepMC::GenVertex *v = (*p)->production_vertex();
91 int last_photon_position = -1;
93 for(HepMC::GenVertex::particles_out_const_iterator p2 = v->particles_out_const_begin();
94 p2 != v->particles_out_const_end(); ++p2)
98 if((*p2)->barcode()==barcode)
break;
100 if((*p2)->pdg_id()==22) { last_photon_position=position; }
104 if(last_photon_position<0)
continue;
106 position -= last_photon_position;
107 HepMC::GenParticle *part = NULL;
110 for(HepMC::GenVertex::particles_out_const_iterator p2 = v->particles_out_const_begin();
111 p2 != v->particles_out_const_end(); ++p2)
115 if (position > 0)
continue;
116 else if(position == 0) part = *p2;
120 if((*p2)->pdg_id()==22 ) (*p2)->set_status(3);
128 if( part->pdg_id() != (*p)->pdg_id())
130 cout<<
"switch_history_entries_status: mismatch in pdg_id of history entry"<<endl;
131 cout<<
"and its corresponding particle. The algorithm does not work correctly."<<endl;
136 if(part->status()!=1)
continue;
145 int main(
int argc,
char **argv)
148 HepMC::Pythia8ToHepMC ToHepMC;
150 Event&
event = pythia.event;
153 pythia.readFile(
"photos_pythia_example.conf");
158 Photos::initialize();
162 Photos::setInfraredCutOff(0.01/91.187);
163 Photos::maxWtInterference(3.0);
167 Log::SummaryAtExit();
168 cout.setf(ios_base::fixed, ios_base::floatfield);
171 for(
unsigned long iEvent = 0; iEvent < NumberOfEvents; ++iEvent)
173 if(iEvent%1000==0) Log::Info()<<
"Event: "<<iEvent<<
"\t("<<iEvent*(100./NumberOfEvents)<<
"%)"<<endl;
174 if (!pythia.next())
continue;
177 HepMC::GenEvent * HepMCEvt =
new HepMC::GenEvent();
178 ToHepMC.fill_next_event(event, HepMCEvt);
181 if(iEvent<EventsToCheck)
184 cout<<
"Momentum conservation chceck BEFORE/AFTER Photos"<<endl;
185 checkMomentumConservationInEvent(HepMCEvt);
198 if(iEvent<EventsToCheck)
200 checkMomentumConservationInEvent(HepMCEvt);
206 HepMCEvent temp_event(*HepMCEvt,
false);
207 MC_Analyze(&temp_event);
210 if(iEvent>=NumberOfEvents-5) HepMCEvt->print();