photos_standalone_example.cxx
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "HepMC/IO_GenEvent.h"
00012
00013
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
00024
00025
00026
00027 void checkMomentumConservationInEvent(HepMC::GenEvent *evt)
00028 {
00029
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
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
00060 while(true)
00061 {
00062
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
00070
00071
00072 if(evtCount<EventsToCheck)
00073 {
00074 cout<<" "<<endl;
00075 cout<<"Momentum conservation chceck BEFORE/AFTER Photos"<<endl;
00076 checkMomentumConservationInEvent(HepMCEvt);
00077 }
00078
00079
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
00094
00095
00096
00097 delete HepMCEvt;
00098 }
00099
00100
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 }