photosLCG_pythia_example.cxx

00001 /**
00002  * Example of use of photos C++ interface. Pythia events are
00003  * generated first and photos used for FSR.
00004  *
00005  * @author LCG & Tomasz Przedzinski
00006  * @date 6 May 2011
00007  */
00008 
00009 //pythia header files
00010 #include "Pythia.h"
00011 #include "HepMCInterface.h"
00012 
00013 //PHOTOS header files
00014 #include "Photos/Photos.h"
00015 #include "Photos/PhotosHepMCEvent.h"
00016 #include "Photos/Log.h"
00017 
00018 using namespace std;
00019 using namespace Pythia8;
00020 using namespace Photospp;
00021 
00022 bool ShowersOn=true;
00023 unsigned long NumberOfEvents = 100000;
00024 
00025 // Calculates energy ratio between (l + bar_l) and (l + bar_l + X)
00026 double calculate_ratio(HepMC::GenEvent *evt, double *ratio_2)
00027 {
00028         double ratio = 0.0;
00029         for(HepMC::GenEvent::particle_const_iterator p=evt->particles_begin();p!=evt->particles_end(); p++)
00030         {
00031                 // Search for Z
00032                 if( (*p)->pdg_id() != 23 ) continue;
00033 
00034                 // Ignore this Z if it does not have at least two daughters
00035                 if( !(*p)->end_vertex() || (*p)->end_vertex()->particles_out_size() < 2 ) continue;
00036 
00037                 // Sum all daughters other than photons
00038                 double sum = 0.0;
00039                 for(HepMC::GenVertex::particle_iterator pp = (*p)->end_vertex()->particles_begin(HepMC::children);
00040                     pp != (*p)->end_vertex()->particles_end(HepMC::children);
00041                     ++pp)
00042                 {
00043                    // (*pp)->print();
00044                    if( (*pp)->pdg_id() != 22 ) sum += (*pp)->momentum().e();
00045                 }
00046 
00047                 // Calculate ratio and ratio^2
00048                 ratio    = sum     /   (*p)->momentum().e();
00049                 *ratio_2 = sum*sum / ( (*p)->momentum().e() * (*p)->momentum().e() );
00050 
00051                 // Assuming only one Z decay per event
00052                 return ratio;
00053         }
00054         return 0.0;
00055 }
00056 
00057 int main(int argc,char **argv)
00058 {
00059         // Initialization of pythia
00060         HepMC::I_Pythia8 ToHepMC;
00061         Pythia pythia;
00062         Event& event = pythia.event;
00063         //pythia.settings.listAll();
00064 
00065         if(!ShowersOn)
00066         {
00067                 //pythia.readString("HadronLevel:all = off");
00068                 pythia.readString("HadronLevel:Hadronize = off");
00069                 pythia.readString("SpaceShower:QEDshower = off");
00070                 pythia.readString("SpaceShower:QEDshowerByL = off");
00071                 pythia.readString("SpaceShower:QEDshowerByQ = off");
00072         }
00073         pythia.readString("PartonLevel:ISR = on");
00074         pythia.readString("PartonLevel:FSR = off");
00075 
00076         pythia.readString("WeakSingleBoson:ffbar2gmZ = on");
00077         pythia.readString("23:onMode = off");
00078         pythia.readString("23:onIfAny = 13");
00079         //pythia.readString("23:onIfAny = 11");
00080         pythia.init( 11, -11, 91.187);                           //e+ e- collisions
00081 
00082         Photos::initialize();
00083 
00084         // Turn on NLO corrections - only for PHOTOS 3.2 or higher
00085 
00086         //Photos::setMeCorrectionWtForZ(zNLO);
00087         //Photos::maxWtInterference(4.0);
00088         //Photos::iniInfo();
00089 
00090         Log::SummaryAtExit();
00091         cout.setf(ios::fixed);
00092 
00093         double ratio_exp   = 0.0, ratio_alpha   = 0.0;
00094         double ratio_exp_2 = 0.0, ratio_alpha_2 = 0.0;
00095         double buf = 0.0;
00096 
00097         Photos::setDoubleBrem(true);
00098         Photos::setExponentiation(true);
00099         Photos::setInfraredCutOff(0.000001);
00100 
00101         Log::Info() << "---------------- First run - EXP ----------------" <<endl;
00102 
00103         // Begin event loop
00104         for(unsigned long iEvent = 0; iEvent < NumberOfEvents; ++iEvent)
00105         {
00106                 if(iEvent%10000==0) Log::Info()<<"Event: "<<iEvent<<"\t("<<iEvent*(100./NumberOfEvents)<<"%)"<<endl;
00107                 if (!pythia.next()) continue;
00108 
00109                 HepMC::GenEvent * HepMCEvt = new HepMC::GenEvent();
00110                 ToHepMC.fill_next_event(event, HepMCEvt);
00111                 //HepMCEvt->print();
00112 
00113                 //Log::LogPhlupa(1,3);
00114 
00115                 // Call photos
00116                 PhotosHepMCEvent evt(HepMCEvt);
00117                 evt.process();
00118 
00119                 ratio_exp   += calculate_ratio(HepMCEvt,&buf);
00120                 ratio_exp_2 += buf;
00121 
00122                 //HepMCEvt->print();
00123 
00124                 // Clean up
00125                 delete HepMCEvt;
00126         }
00127 
00128         Photos::setDoubleBrem(false);
00129         Photos::setExponentiation(false);
00130         Photos::setInfraredCutOff(1./91.187);  // that is 1 GeV for
00131                                                // pythia.init( 11, -11, 91.187);
00132 
00133         Log::Info() << "---------------- Second run - ALPHA ORDER ----------------" <<endl;
00134         
00135         // Begin event loop
00136         for(unsigned long iEvent = 0; iEvent < NumberOfEvents; ++iEvent)
00137         {
00138                 if(iEvent%10000==0) Log::Info()<<"Event: "<<iEvent<<"\t("<<iEvent*(100./NumberOfEvents)<<"%)"<<endl;
00139                 if (!pythia.next()) continue;
00140 
00141                 HepMC::GenEvent * HepMCEvt = new HepMC::GenEvent();
00142                 ToHepMC.fill_next_event(event, HepMCEvt);
00143                 //HepMCEvt->print();
00144 
00145                 //Log::LogPhlupa(1,3);
00146 
00147                 // Call photos
00148                 PhotosHepMCEvent evt(HepMCEvt);
00149                 evt.process();
00150 
00151                 ratio_alpha   += calculate_ratio(HepMCEvt,&buf);
00152                 ratio_alpha_2 += buf;
00153 
00154                 //HepMCEvt->print();
00155 
00156                 // Clean up
00157                 delete HepMCEvt;
00158         }
00159         
00160         pythia.statistics();
00161 
00162         ratio_exp   = ratio_exp   / (double)NumberOfEvents;
00163         ratio_exp_2 = ratio_exp_2 / (double)NumberOfEvents;
00164 
00165         ratio_alpha   = ratio_alpha   / (double)NumberOfEvents;
00166         ratio_alpha_2 = ratio_alpha_2 / (double)NumberOfEvents;
00167 
00168         double err_exp   = sqrt( (ratio_exp_2   - ratio_exp   * ratio_exp  ) / (double)NumberOfEvents );
00169         double err_alpha = sqrt( (ratio_alpha_2 - ratio_alpha * ratio_alpha) / (double)NumberOfEvents );
00170         
00171         cout.precision(6);
00172         cout.setf(ios::fixed);
00173         cout << "********************************************************" << endl;
00174         cout << "* Z -> l + bar_l + gammas                              *" << endl;
00175         cout << "* E(l + bar_l) / E(l + bar_l + gammas) ratio           *" << endl;
00176         cout << "*                                                      *" << endl;
00177         cout << "* PHOTOS - EXP:          " << ratio_exp   <<" +/- "<<err_exp  <<"      *" << endl;
00178         cout << "* PHOTOS - ALPHA ORDER:  " << ratio_alpha <<" +/- "<<err_alpha<<"      *" << endl;
00179         cout << "********************************************************" << endl;
00180 
00181 }
Generated on Sun Oct 20 20:23:56 2013 for C++InterfacetoPHOTOS by  doxygen 1.6.3