FairRoot/PandaRoot
photos_test.cxx
Go to the documentation of this file.
1 
9 //Pythia header files
10 #include "Pythia.h"
11 #include "HepMCInterface.h"
12 
13 //MC-TESTER header files
14 #include "Generate.h"
15 #include "HepMCEvent.H"
16 #include "Setup.H"
17 
18 //PHOTOS header files
19 #include "Photos/Photos.h"
21 #include "Photos/Log.h"
22 
23 using namespace std;
24 using namespace Pythia8;
25 using namespace Photospp;
26 
27 unsigned long NumberOfEvents = 10000;
28 unsigned int EventsToCheck=20;
29 
30 // elementary test of HepMC typically executed before
31 // detector simulation based on http://home.fnal.gov/~mrenna/HCPSS/HCPSShepmc.html
32 // similar test was performed in Fortran
33 // we perform it before and after Photos (for the first several events)
34 void checkMomentumConservationInEvent(HepMC::GenEvent *evt)
35 {
36  //cout<<"List of stable particles: "<<endl;
37 
38  double px=0.0,py=0.0,pz=0.0,e=0.0;
39 
40  for ( HepMC::GenEvent::particle_const_iterator p = evt->particles_begin();
41  p != evt->particles_end(); ++p )
42  {
43  if( (*p)->status() == 1 )
44  {
45  HepMC::FourVector m = (*p)->momentum();
46  px+=m.px();
47  py+=m.py();
48  pz+=m.pz();
49  e +=m.e();
50  //(*p)->print();
51  }
52  }
53  cout.precision(6);
54  cout.setf(ios_base::floatfield);
55  cout<<endl<<"Vector Sum: "<<px<<" "<<py<<" "<<pz<<" "<<e<<endl;
56 }
57 
58 // Finds X Y -> 6 -6 decay and converts it to 100 -> 6 -6, where 100 = X + Y
59 // Method used only in test for t bar t pair production
60 void fixForMctester(HepMC::GenEvent *evt)
61 {
62  for(HepMC::GenEvent::particle_const_iterator p=evt->particles_begin();p!=evt->particles_end(); p++)
63  if((*p)->pdg_id()==6)
64  {
65  HepMC::GenParticle *pt = *p;
66  int id=(* pt->production_vertex()->particles_in_const_begin() )->pdg_id();
67  if(id!=21 && id!=11 && id>5) continue;
68 
69  // Get first mother and add 2x second mother to it
70  HepMC::GenParticle *X = (* pt->production_vertex()->particles_in_const_begin());
71  HepMC::GenParticle *Y = (* ++(pt->production_vertex()->particles_in_const_begin()) );
72  HepMC::FourVector fX = X->momentum();
73  HepMC::FourVector fY = Y->momentum();
74  HepMC::FourVector fXY(fX.px()+fY.px(),fX.py()+fY.py(),fX.pz()+fY.pz(),fX.e()+fY.e());
75  X->set_momentum(fXY);
76  // Unique ID for MC-Tester to analyze
77  X->set_pdg_id(100);
78 
79  // Set 2nd mother as decayed and delete it from production vertex
80  Y->set_status(1);
81  (* Y->production_vertex()->particles_in_const_begin())->set_status(1);
82  pt->production_vertex()->remove_particle(Y);
83  return;
84  }
85 }
86 
87 int main(int argc,char **argv)
88 {
89 
90  // Program needs at least 3 parameters
91  if(argc<4)
92  {
93  cout<<endl<<"Usage: "<<argv[0]<<" <pythia_conf> <pythia_mode> <no_events> [ <special_mode> ]"<<endl;
94  cout<<endl<<" eg. "<<argv[0]<<" pythia_W.conf 0 10000 4 0"<<endl;
95  cout<<endl;
96  return -1;
97  }
98 
99  HepMC::I_Pythia8 ToHepMC;
100 
101  // Initialization of pythia
102  Pythia pythia;
103  Event& event = pythia.event;
104 
105  pythia.readString("HadronLevel:Hadronize = off");
106  pythia.readString("SpaceShower:QEDshower = off");
107  pythia.readString("SpaceShower:QEDshowerByL = off");
108  pythia.readString("SpaceShower:QEDshowerByQ = off");
109  pythia.readString("PartonLevel:ISR = off");
110  pythia.readString("PartonLevel:FSR = off");
111 
112  // Tauola is currently set to undecay taus. Otherwise, uncomment this line.
113  //pythia.particleData.readString("15:mayDecay = off");
114 
115  /********************************************************
116  Read input parameters from console. List of parameters:
117  1. Pythia configuration filename
118  2. Pythia mode - e+e-@200GeV , e+e-@91.187GeV or pp@14TeV
119  3. Number of events
120  4. Special mode - default(off), ttbar, NLO
121  5. Photos - use 1-photon mode on/off
122 
123  Example where all input parameters are used:
124 
125  ./photos_test.exe pythia_W.conf 0 100000 0 0
126  - use pythia_W.conf
127  - initialize using e+ e- @ 200GeV collisions
128  - generate 100 000 events
129  - default configuration (not using any special mode)
130  - Photos is not using 1-photon mode (default option, except for WmunuNLO and ZmumuNLO)
131  *********************************************************/
132 
133  // 1. Load pythia configuration file (argv[1], from console)
134  if(argc>1) pythia.readFile(argv[1]);
135 
136  // 2. Initialize pythia (argv[2], from console)
137  if(atoi(argv[2])==0) pythia.init( 11, -11, 200.); //e+ e- collisions
138  else if(atoi(argv[2])==1) pythia.init( 11, -11, 91.187); //e+ e- collisions
139  else pythia.init( -2212, -2212, 14000.0); //p p collisions
140 
141  // 3. Get number of events (argv[3], from console)
142  if(argc>3) NumberOfEvents=atoi(argv[3]);
143 
145 
146  Photos::setInfraredCutOff(1.e-6);
147  Photos::maxWtInterference(3.0);
148 
149  bool topDecays = false;
150 
151  // 5. Check if we're using any special mode
152  if(argc>4)
153  {
154  // Top decays
155  if(atoi(argv[4])==1) topDecays=true;
156  // NLO mode
157  else if(atoi(argv[4])==2)
158  {
159  Photos::setMeCorrectionWtForW(true);
160  Photos::setMeCorrectionWtForZ(true);
161  //Photos::meCorrectionWtForScalar(true);
162  }
163  }
164 
165  // 1-photon mode
166  if(argc>5 && atoi(argv[5])==1)
167  {
168  Photos::setDoubleBrem(false);
169  Photos::setExponentiation(false);
170  Photos::setInfraredCutOff(0.001);
171  Photos::maxWtInterference(2.0);
172 
173 
174  }
175 
176 
177  MC_Initialize();
178 
179  Photos::iniInfo();
180  Log::SummaryAtExit();
181  cout.setf(ios::fixed);
182 
183  // Begin event loop
184  for(unsigned long iEvent = 0; iEvent < NumberOfEvents; ++iEvent)
185  {
186  if(iEvent%1000==0) Log::Info()<<"Event: "<<iEvent<<"\t("<<iEvent*(100./NumberOfEvents)<<"%)"<<endl;
187  if (!pythia.next()) continue;
188 
189  HepMC::GenEvent * HepMCEvt = new HepMC::GenEvent();
190  ToHepMC.fill_next_event(event, HepMCEvt);
191 
192  if(iEvent<EventsToCheck)
193  {
194  cout<<" "<<endl;
195  cout<<"Momentum conservation chceck BEFORE/AFTER Photos"<<endl;
197  }
198 
199  // Run PHOTOS on the event
200  PhotosHepMCEvent evt(HepMCEvt);
201  evt.process();
202 
203  if(iEvent<EventsToCheck)
204  {
206  }
207 
208  // Top decays - we mess with the event so MC-TESTER can work on it as in LC analysis case
209  if(topDecays) fixForMctester(HepMCEvt);
210 
211  // Run MC-TESTER on the event
212  HepMCEvent temp_event(*HepMCEvt,false);
213  MC_Analyze(&temp_event);
214 
215  // Clean up
216  delete HepMCEvt;
217  }
218  pythia.statistics();
219  MC_Finalize();
220 }
void fixForMctester(HepMC::GenEvent *evt)
Definition: photos_test.cxx:60
void checkMomentumConservationInEvent(HepMC::GenEvent *evt)
Definition: photos_test.cxx:34
__m128 m
Definition: P4_F32vec4.h:28
int main(int argc, char **argv)
Definition: photos_test.cxx:87
unsigned long NumberOfEvents
Definition: photos_test.cxx:27
Double_t fX
Definition: PndCaloDraw.cxx:34
int evt
Definition: checkhelixhit.C:36
double Y
Definition: anaLmdDigi.C:68
Double_t p
Definition: anasim.C:58
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
Definition: Log.h:30
void initialize()
unsigned int EventsToCheck
Definition: photos_test.cxx:28
double X
Definition: anaLmdDigi.C:68
Double_t fY
Definition: PndCaloDraw.cxx:34
Pythia8::Pythia * pythia
double pz[39]
Definition: pipisigmas.h:14