photos_pythia_example.cxx
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "Pythia.h"
00011 #include "HepMCInterface.h"
00012
00013
00014 #include "Generate.h"
00015 #include "HepMCEvent.H"
00016 #include "Setup.H"
00017
00018
00019 #include "Photos/Photos.h"
00020 #include "Photos/PhotosHepMCEvent.h"
00021 #include "Photos/Log.h"
00022
00023 using namespace std;
00024 using namespace Pythia8;
00025 using namespace Photospp;
00026
00027 bool ShowersOn=true;
00028 unsigned long NumberOfEvents = 10000;
00029 unsigned int EventsToCheck=20;
00030
00031
00032
00033
00034
00035 void checkMomentumConservationInEvent(HepMC::GenEvent *evt)
00036 {
00037
00038
00039 double px=0.0,py=0.0,pz=0.0,e=0.0;
00040
00041 for ( HepMC::GenEvent::particle_const_iterator p = evt->particles_begin();
00042 p != evt->particles_end(); ++p )
00043 {
00044 if( (*p)->status() == 1 )
00045 {
00046 HepMC::FourVector m = (*p)->momentum();
00047 px+=m.px();
00048 py+=m.py();
00049 pz+=m.pz();
00050 e +=m.e();
00051
00052 }
00053 }
00054 cout.precision(6);
00055 cout.setf(ios_base::floatfield);
00056 cout<<endl<<"Vector Sum: "<<px<<" "<<py<<" "<<pz<<" "<<e<<endl;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 void switch_history_entries_status(HepMC::GenEvent *evt)
00076 {
00077 for ( HepMC::GenEvent::particle_const_iterator p = evt->particles_begin();
00078 p != evt->particles_end(); ++p )
00079 {
00080 if((*p)->status()==3)
00081 {
00082 if((*p)->pdg_id()==22) continue;
00083
00084 int barcode = (*p)->barcode();
00085
00086 HepMC::GenVertex *v = (*p)->production_vertex();
00087
00088
00089
00090 int position = 0;
00091 int last_photon_position = -1;
00092
00093 for(HepMC::GenVertex::particles_out_const_iterator p2 = v->particles_out_const_begin();
00094 p2 != v->particles_out_const_end(); ++p2)
00095 {
00096 position++;
00097
00098 if((*p2)->barcode()==barcode) break;
00099
00100 if((*p2)->pdg_id()==22) { last_photon_position=position; }
00101 }
00102
00103
00104 if(last_photon_position<0) continue;
00105
00106 position -= last_photon_position;
00107 HepMC::GenParticle *part = NULL;
00108
00109
00110 for(HepMC::GenVertex::particles_out_const_iterator p2 = v->particles_out_const_begin();
00111 p2 != v->particles_out_const_end(); ++p2)
00112 {
00113 --position;
00114
00115 if (position > 0) continue;
00116 else if(position == 0) part = *p2;
00117 else
00118 {
00119
00120 if((*p2)->pdg_id()==22 ) (*p2)->set_status(3);
00121
00122
00123 else break;
00124 }
00125 }
00126
00127
00128 if( part->pdg_id() != (*p)->pdg_id())
00129 {
00130 cout<<"switch_history_entries_status: mismatch in pdg_id of history entry"<<endl;
00131 cout<<"and its corresponding particle. The algorithm does not work correctly."<<endl;
00132 exit(-1);
00133 }
00134
00135
00136 if(part->status()!=1) continue;
00137
00138
00139 part->set_status(3);
00140 (*p)->set_status(1);
00141 }
00142 }
00143 }
00144
00145 int main(int argc,char **argv)
00146 {
00147
00148 HepMC::I_Pythia8 ToHepMC;
00149 Pythia pythia;
00150 Event& event = pythia.event;
00151
00152
00153 pythia.readString("PartonLevel:ISR = on");
00154 pythia.readString("PartonLevel:FSR = off");
00155
00156 pythia.readString("WeakSingleBoson:ffbar2gmZ = on");
00157 pythia.readString("23:onMode = off");
00158 pythia.readString("23:onIfAny = 13");
00159 pythia.init( 11, -11, 91.187);
00160
00161 MC_Initialize();
00162
00163 Photos::initialize();
00164
00165
00166
00167 Photos::setInfraredCutOff(0.01/91.187);
00168 Photos::maxWtInterference(3.0);
00169
00170
00171 Photos::iniInfo();
00172 Log::SummaryAtExit();
00173 cout.setf(ios::fixed);
00174
00175
00176 for(unsigned long iEvent = 0; iEvent < NumberOfEvents; ++iEvent)
00177 {
00178 if(iEvent%1000==0) Log::Info()<<"Event: "<<iEvent<<"\t("<<iEvent*(100./NumberOfEvents)<<"%)"<<endl;
00179 if (!pythia.next()) continue;
00180
00181
00182 HepMC::GenEvent * HepMCEvt = new HepMC::GenEvent();
00183 ToHepMC.fill_next_event(event, HepMCEvt);
00184
00185
00186 if(iEvent<EventsToCheck)
00187 {
00188 cout<<" "<<endl;
00189 cout<<"Momentum conservation chceck BEFORE/AFTER Photos"<<endl;
00190 checkMomentumConservationInEvent(HepMCEvt);
00191 }
00192
00193
00194
00195
00196 PhotosHepMCEvent evt(HepMCEvt);
00197 evt.process();
00198
00199
00200
00201
00202
00203 if(iEvent<EventsToCheck)
00204 {
00205 checkMomentumConservationInEvent(HepMCEvt);
00206 }
00207
00208
00209
00210
00211 HepMCEvent temp_event(*HepMCEvt,false);
00212 MC_Analyze(&temp_event);
00213
00214
00215 if(iEvent>=NumberOfEvents-5) HepMCEvt->print();
00216
00217
00218 delete HepMCEvt;
00219 }
00220 pythia.statistics();
00221 MC_Finalize();
00222 }