photos_standalone_example.cxx

00001 /**
00002  * Example of photos usage.
00003  * Events are loaded from pre-generated set featuring Z0 -> tau+ tau- decays
00004  * and processed by photos.
00005  *
00006  * @author Tomasz Przedzinski
00007  * @date 17 July 2010
00008  */
00009 
00010 //HepMC header files
00011 #include "HepMC/IO_GenEvent.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 Photospp;
00020 
00021 int EventsToCheck=20;
00022 
00023 // elementary test of HepMC typically executed before
00024 // detector simulation based on http://home.fnal.gov/~mrenna/HCPSS/HCPSShepmc.html
00025 // similar test was performed in Fortran
00026 // we perform it before and after Photos (for the first several events)
00027 void checkMomentumConservationInEvent(HepMC::GenEvent *evt)
00028 {
00029         //cout<<"List of stable particles: "<<endl;
00030 
00031         double px=0.0,py=0.0,pz=0.0,e=0.0;
00032         
00033         for ( HepMC::GenEvent::particle_const_iterator p = evt->particles_begin();
00034               p != evt->particles_end(); ++p )
00035         {
00036                 if( (*p)->status() == 1 )
00037                 {
00038                         HepMC::FourVector m = (*p)->momentum();
00039                         px+=m.px();
00040                         py+=m.py();
00041                         pz+=m.pz();
00042                         e +=m.e();
00043                         //(*p)->print();
00044                 }
00045         }
00046   cout.precision(6);
00047   cout.setf(ios_base::floatfield);
00048         cout<<endl<<"Vector Sum: "<<px<<" "<<py<<" "<<pz<<" "<<e<<endl;
00049 }
00050 
00051 int main()
00052 {
00053         HepMC::IO_GenEvent file("photos_standalone_example.dat",std::ios::in);
00054 
00055         Photos::initialize();
00056         Photos::setInfraredCutOff(0.001/200);
00057 
00058         int photonAdded=0,twoAdded=0,moreAdded=0,evtCount=0;
00059         // Begin event loop. Generate event.
00060         while(true)
00061         {
00062                 // Create event
00063                 HepMC::GenEvent *HepMCEvt = new HepMC::GenEvent();
00064                 file.fill_next_event(HepMCEvt);
00065                 if(file.rdstate()) break;
00066                 evtCount++;
00067                 int buf = -HepMCEvt->particles_size();
00068 
00069                 //cout << "BEFORE:"<<endl;
00070                 //HepMCEvt->print();
00071 
00072                 if(evtCount<EventsToCheck)
00073                 {
00074                         cout<<"                                          "<<endl;
00075                         cout<<"Momentum conservation chceck BEFORE/AFTER Photos"<<endl;
00076                         checkMomentumConservationInEvent(HepMCEvt);
00077                 }
00078 
00079                 // Process by photos
00080                 PhotosHepMCEvent evt(HepMCEvt);
00081                 evt.process();
00082 
00083                 if(evtCount<EventsToCheck)
00084                 {
00085                         checkMomentumConservationInEvent(HepMCEvt);
00086                 }
00087 
00088                 buf+=HepMCEvt->particles_size();
00089                 if(buf==1)      photonAdded++;
00090                 else if(buf==2) twoAdded++;
00091                 else if(buf>2)  moreAdded++;
00092 
00093                 //cout << "AFTER:"<<endl;
00094                 //HepMCEvt->print();
00095 
00096                 //clean up
00097                 delete HepMCEvt;
00098         }
00099 
00100         // Print results
00101         cout.precision(2);
00102         cout.setf(ios::fixed);
00103         cout<<endl;
00104         if(evtCount==0)
00105         {
00106                 cout<<"Something went wrong with the input file: photos_standalone_example.dat"<<endl;
00107                 cout<<"No events were processed."<<endl<<endl;
00108                 return 0;
00109         }
00110         cout<<"Summary (whole event processing):"<<endl;
00111         cout<<evtCount   <<"\tevents processed"<<endl;
00112         cout<<photonAdded<<"\ttimes one photon added to the event           \t("<<(photonAdded*100./evtCount)<<"%)"<<endl;
00113         cout<<twoAdded   <<"\ttimes two photons added to the event          \t("<<(twoAdded*100./evtCount)<<"%)"<<endl;
00114         cout<<moreAdded  <<"\ttimes more than two photons added to the event\t("<<(moreAdded*100./evtCount)<<"%)"<<endl<<endl;
00115         cout<<"(Contrary to results from MC-Tester, these values are technical and infrared unstable)"<<endl<<endl;
00116 }
Generated on Sun Oct 20 20:23:56 2013 for C++InterfacetoPHOTOS by  doxygen 1.6.3