photos_test.cxx

00001 /**
00002  * Main program for testing photos C++ interface.
00003  * Pythia events are generated first and photos used for FSR.
00004  *
00005  * @author Nadia Davidson and Tomasz Przedzinski
00006  * @date 10 May 2011
00007  */
00008 
00009 //Pythia header files
00010 #include "Pythia.h"
00011 #include "HepMCInterface.h"
00012 
00013 //MC-TESTER header files
00014 #include "Generate.h"
00015 #include "HepMCEvent.H"
00016 #include "Setup.H"
00017 
00018 //PHOTOS header files
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 unsigned long NumberOfEvents = 10000;
00028 unsigned int EventsToCheck=20;
00029 
00030 // elementary test of HepMC typically executed before
00031 // detector simulation based on http://home.fnal.gov/~mrenna/HCPSS/HCPSShepmc.html
00032 // similar test was performed in Fortran
00033 // we perform it before and after Photos (for the first several events)
00034 void checkMomentumConservationInEvent(HepMC::GenEvent *evt)
00035 {
00036         //cout<<"List of stable particles: "<<endl;
00037 
00038         double px=0.0,py=0.0,pz=0.0,e=0.0;
00039         
00040         for ( HepMC::GenEvent::particle_const_iterator p = evt->particles_begin();
00041               p != evt->particles_end(); ++p )
00042         {
00043                 if( (*p)->status() == 1 )
00044                 {
00045                         HepMC::FourVector m = (*p)->momentum();
00046                         px+=m.px();
00047                         py+=m.py();
00048                         pz+=m.pz();
00049                         e +=m.e();
00050                         //(*p)->print();
00051                 }
00052         }
00053   cout.precision(6);
00054   cout.setf(ios_base::floatfield);
00055         cout<<endl<<"Vector Sum: "<<px<<" "<<py<<" "<<pz<<" "<<e<<endl;
00056 }
00057 
00058 // Finds X Y -> 6 -6 decay and converts it to 100 -> 6 -6, where 100 = X + Y
00059 // Method used only in test for t bar  t pair production
00060 void fixForMctester(HepMC::GenEvent *evt)
00061 {
00062         for(HepMC::GenEvent::particle_const_iterator p=evt->particles_begin();p!=evt->particles_end(); p++)
00063         if((*p)->pdg_id()==6)
00064         {
00065                 HepMC::GenParticle *pt = *p;
00066                 int id=(* pt->production_vertex()->particles_in_const_begin() )->pdg_id();
00067                 if(id!=21 && id!=11 && id>5) continue;
00068 
00069                 // Get first mother and add 2x second mother to it
00070                 HepMC::GenParticle *X = (* pt->production_vertex()->particles_in_const_begin());
00071                 HepMC::GenParticle *Y = (* ++(pt->production_vertex()->particles_in_const_begin()) );
00072                 HepMC::FourVector fX = X->momentum();
00073                 HepMC::FourVector fY = Y->momentum();
00074                 HepMC::FourVector fXY(fX.px()+fY.px(),fX.py()+fY.py(),fX.pz()+fY.pz(),fX.e()+fY.e());
00075                 X->set_momentum(fXY);
00076                 // Unique ID for MC-Tester to analyze
00077                 X->set_pdg_id(100);
00078 
00079                 // Set 2nd mother as decayed and delete it from production vertex
00080                 Y->set_status(1);
00081                 (* Y->production_vertex()->particles_in_const_begin())->set_status(1);
00082                 pt->production_vertex()->remove_particle(Y);
00083                 return;
00084         }
00085 }
00086 
00087 int main(int argc,char **argv)
00088 {
00089 
00090         // Program needs at least 3 parameters
00091         if(argc<4)
00092         {
00093                 cout<<endl<<"Usage: "<<argv[0]<<" <pythia_conf> <pythia_mode> <no_events> [ <special_mode> ]"<<endl;
00094                 cout<<endl<<"   eg. "<<argv[0]<<" pythia_W.conf 0 10000 4 0"<<endl;
00095                 cout<<endl;
00096                 return -1;
00097         }
00098 
00099         HepMC::I_Pythia8 ToHepMC;
00100 
00101         // Initialization of pythia
00102         Pythia pythia;
00103         Event& event = pythia.event;
00104 
00105         pythia.readString("HadronLevel:Hadronize = off");
00106         pythia.readString("SpaceShower:QEDshower = off");
00107         pythia.readString("SpaceShower:QEDshowerByL = off");
00108         pythia.readString("SpaceShower:QEDshowerByQ = off");
00109         pythia.readString("PartonLevel:ISR = off");
00110         pythia.readString("PartonLevel:FSR = off");
00111 
00112         // Tauola is currently set to undecay taus. Otherwise, uncomment this line.
00113         //pythia.particleData.readString("15:mayDecay = off");
00114 
00115         /********************************************************
00116           Read input parameters from console. List of parameters:
00117           1. Pythia configuration filename
00118           2. Pythia mode - e+e-@200GeV , e+e-@91.187GeV or pp@14TeV
00119           3. Number of events
00120           4. Special mode - default(off), ttbar, NLO
00121           5. Photos - use 1-photon mode on/off
00122 
00123           Example where all input parameters are used:
00124 
00125           ./photos_test.exe pythia_W.conf 0 100000 0 0
00126             - use pythia_W.conf
00127             - initialize using e+ e- @ 200GeV collisions
00128             - generate 100 000 events
00129             - default configuration (not using any special mode)
00130             - Photos is not using 1-photon mode (default option, except for WmunuNLO and ZmumuNLO)
00131         *********************************************************/
00132 
00133         // 1. Load pythia configuration file (argv[1], from console)
00134         if(argc>1) pythia.readFile(argv[1]);
00135 
00136         // 2. Initialize pythia (argv[2], from console)
00137         if(atoi(argv[2])==0)      pythia.init( 11, -11, 200.);         //e+ e- collisions
00138         else if(atoi(argv[2])==1) pythia.init( 11, -11, 91.187);       //e+ e- collisions
00139         else                      pythia.init( -2212, -2212, 14000.0); //p  p  collisions
00140 
00141         // 3. Get number of events (argv[3], from console)
00142         if(argc>3) NumberOfEvents=atoi(argv[3]);
00143 
00144         Photos::initialize();
00145 
00146         Photos::setInfraredCutOff(1.e-6);
00147         Photos::maxWtInterference(3.0);
00148 
00149         bool topDecays = false;
00150 
00151         // 5. Check if we're using any special mode
00152         if(argc>4)
00153         {
00154                 // Top decays
00155                 if(atoi(argv[4])==1)      topDecays=true;
00156                 // NLO mode
00157                 else if(atoi(argv[4])==2)
00158                 {
00159                         Photos::setMeCorrectionWtForW(true);
00160                         Photos::setMeCorrectionWtForZ(true);
00161                         //Photos::meCorrectionWtForScalar(true);
00162                 }
00163         }
00164 
00165         // 1-photon mode
00166         if(argc>5 && atoi(argv[5])==1)
00167         {
00168                 Photos::setDoubleBrem(false);
00169                 Photos::setExponentiation(false);
00170                 Photos::setInfraredCutOff(0.001);
00171                 Photos::maxWtInterference(2.0);
00172 
00173 
00174         }
00175 
00176 
00177         MC_Initialize();
00178 
00179         Photos::iniInfo();
00180         Log::SummaryAtExit();
00181         cout.setf(ios::fixed);
00182 
00183         // Begin event loop
00184         for(unsigned long iEvent = 0; iEvent < NumberOfEvents; ++iEvent)
00185         {
00186                 if(iEvent%1000==0) Log::Info()<<"Event: "<<iEvent<<"\t("<<iEvent*(100./NumberOfEvents)<<"%)"<<endl;
00187                 if (!pythia.next()) continue;
00188 
00189                 HepMC::GenEvent * HepMCEvt = new HepMC::GenEvent();
00190                 ToHepMC.fill_next_event(event, HepMCEvt);
00191 
00192                 if(iEvent<EventsToCheck)
00193                 {
00194                         cout<<"                                          "<<endl;
00195                         cout<<"Momentum conservation chceck BEFORE/AFTER Photos"<<endl;
00196                         checkMomentumConservationInEvent(HepMCEvt);
00197                 }
00198 
00199                 // Run PHOTOS on the event
00200                 PhotosHepMCEvent evt(HepMCEvt);
00201                 evt.process();
00202 
00203                 if(iEvent<EventsToCheck)
00204                 {
00205                         checkMomentumConservationInEvent(HepMCEvt);
00206                 }
00207 
00208                 // Top decays - we mess with the event so MC-TESTER can work on it as in LC analysis case
00209                 if(topDecays) fixForMctester(HepMCEvt);
00210 
00211                 // Run MC-TESTER on the event
00212                 HepMCEvent temp_event(*HepMCEvt,false);
00213                 MC_Analyze(&temp_event);
00214 
00215                 // Clean up
00216                 delete HepMCEvt;
00217         }
00218         pythia.statistics();
00219         MC_Finalize();
00220 }
Generated on Sun Oct 20 20:23:56 2013 for C++InterfacetoPHOTOS by  doxygen 1.6.3