00001
00002 #include "Utilities/Configuration/interface/Architecture.h"
00003
00004 #include <Utilities/Notification/interface/Observer.h>
00005 #include "Utilities/Notification/interface/PackageInitializer.h"
00006 #include <Utilities/UI/interface/SimpleConfigurable.h>
00007
00008 #include "CARF/SimEvent/interface/SimEvent.h"
00009 #include "GeneratorInterface/HepEvent/interface/RawHepEvent.h"
00010 #include "GeneratorInterface/EventProxyInterface/interface/HepEventG3EventProxyReader.h"
00011 #include "GeneratorInterface/Particle/interface/RawParticle.h"
00012 #include "GeneratorInterface/Particle/interface/RawHepEventParticle.h"
00013 #include "GeneratorInterface/HepPDT/interface/HepPDTable.h"
00014 #include "GeneratorInterface/HepPDT/interface/HepParticleData.h"
00015
00016 #include <XANADOO/XANAMcInfo/interface/XANAGeneratorEvent.h>
00017 #include <XANADOO/XANAMcInfo/interface/XANAGeneratorParticle.h>
00018 #include <XANADOO/XANAMcInfo/interface/XANAGeantEvent.h>
00019 #include <XANADOO/XANAMcInfo/interface/XANAGeantVertex.h>
00020 #include <XANADOO/XANAMcInfo/interface/XANAGeantTrack.h>
00021 #include <XANADOO/XANAUtilities/interface/XANAToolkit.h>
00022
00023
00024 class XANAMcInfoTester : private Observer<G3EventProxy *> {
00025
00026 public:
00027
00028 SimpleConfigurable<bool> readPileup_;
00029 SimpleConfigurable<int> minBunch_;
00030 SimpleConfigurable<int> maxBunch_;
00031 SimpleConfigurable<bool> readVertices_;
00032
00033 XANAMcInfoTester()
00034 {
00035 xana::out(1) << "[update] Constructing an XANAMcInfoTester" << endl ;
00036 Observer<G3EventProxy *>::init() ;
00037 readPileup_=SimpleConfigurable<bool>(false,"HepG3EventProxyReader:ReadPileup");
00038 minBunch_=SimpleConfigurable<int>(0,"HepG3EventProxyReader:MinBunch");
00039 maxBunch_=SimpleConfigurable<int>(0,"HepG3EventProxyReader:MaxBunch");
00040 readVertices_=SimpleConfigurable<bool>(false,"HepG3EventProxyReader:ReadVertices");
00041 }
00042
00043 ~XANAMcInfoTester()
00044 {
00045 }
00046
00047 void upDate( G3EventProxy * ev )
00048 {
00049
00050 if (!ev) return ;
00051
00052
00053 vector<XANAGeneratorParticle> particles;
00054
00055 const RawHepEventParticle * aHepParticle;
00056 HepEventG3EventProxyReader EventReader(ev);
00057 RawHepEvent MyHepEvent;
00058 MyHepEvent.read(&EventReader);
00059
00060 xana::out(4) << std::endl;
00061 xana::out(4) << "[update] --- RawHepEvent ---" << std::endl;
00062 MyHepEvent.print();
00063 xana::out(4) << std::endl << "[update] --- total event tree ---" << std::endl;
00064 MyHepEvent.printTree();
00065 xana::out(4) << std::endl;
00066
00067 XANAGeneratorEvent *aMcEvent = new XANAGeneratorEvent;
00068 XANAGeneratorParticle *aMcParticle;
00069
00070 for(unsigned int i=1; i<=MyHepEvent.n(); i++) {
00071 aHepParticle = MyHepEvent.getParticle(i);
00072 HepLorentzVector momentum(aHepParticle->px(), aHepParticle->py(),
00073 aHepParticle->pz(), aHepParticle->e());
00074 aMcParticle = new XANAGeneratorParticle(aHepParticle->line(), aHepParticle->status(),
00075 aHepParticle->pid(), aHepParticle->mother1(), aHepParticle->mother2(),
00076 aHepParticle->daughter1(), aHepParticle->daughter2(), momentum,
00077 aHepParticle->mass(), aHepParticle->vertex());
00078
00079 if (i<=MyHepEvent.nSignal()) {
00080 aMcEvent->addSignalParticle(aMcParticle);
00081 } else {
00082 aMcEvent->addPileupParticle(aMcParticle);
00083 }
00084 }
00085
00086 xana::out(4) << std::endl << "[update] --- XANAGeneratorEvent ---" << std::endl;
00087 aMcEvent->print();
00088 xana::out(4) << std::endl;
00089
00090
00091
00092 xana::out(4) << "[update] --- GEANT vertices -----------------------------------" << std::endl;
00093 SimEvent::vertex_container GeantVertices;
00094
00095 GeantVertices = ev->simSignal()->proxy()->vertices();
00096 xana::out(4) << "[update] This event has " << GeantVertices.size() << " GEANT vertices." <<std::endl;
00097 xana::out(4).setf(std::ios::fixed, std::ios::floatfield);
00098 xana::out(2) << "[update] The annihilation process took place at "
00099 << "x=" << std::setw(7) << std::setprecision(4) << GeantVertices[0].position().x()
00100 << ", y=" << std::setw(7) << std::setprecision(4) << GeantVertices[0].position().y()
00101 << ", z=" << std::setw(7) << std::setprecision(4) << GeantVertices[0].position().z()
00102 << std::endl;
00103
00104 xana::out(4) << "[update] --- GEANT tracks -----------------------------------" << std::endl;
00105
00106 SimEvent::track_container GeantTracks;
00107
00108 GeantTracks = ev->simSignal()->proxy()->tracks();
00109 xana::out(4) << "[update] This event has " << GeantTracks.size() << " GEANT tracks." <<std::endl;
00110 xana::out(2) << "[update] The first track is:" << std::endl;
00111 xana::out(2) << GeantTracks[0] << std::endl;
00112
00113 SimEvent::genpart_container GenParts;
00114 GenParts = ev->simSignal()->proxy()->genparts();
00115 if (! GeantTracks[0].noGenpart()) {
00116 int genpart = GeantTracks[0].genpartIndex();
00117 xana::out(2) << "[update] This corresponds to generator particle ";
00118 xana::out(2) << genpart << std::endl;
00119 GenParts[genpart].print();
00120 }
00121 if (! GeantTracks[0].noVertex()) {
00122 int vertex = GeantTracks[0].vertIndex();
00123 xana::out(2) << "[update] This track comes from the Geant Vertex ";
00124 xana::out(2) << vertex << " at " << std::endl;
00125 xana::out(2) << "x=" << std::setw(7) << std::setprecision(4) << GeantVertices[vertex].position().x()
00126 << ", y=" << std::setw(7) << std::setprecision(4) << GeantVertices[vertex].position().y()
00127 << ", z=" << std::setw(7) << std::setprecision(4) << GeantVertices[vertex].position().z()
00128 << std::endl;
00129 }
00130
00131 XANAGeantEvent aGeantEvent;
00132 aGeantEvent.addGeneratorEvent(aMcEvent);
00133 XANAGeantVertex *vtx=0;
00134 XANAGeantTrack *trk=0;
00135 int vertex=0;
00136
00137 for(unsigned int it=0; it<GeantTracks.size(); it++) {
00138 xana::out(2) << "[update] Track:" << it << " is " << std::endl;
00139 xana::out(2) << GeantTracks[it] << std::endl;
00140
00141 xana::out(2) << "[update] track momentum " << GeantTracks[it].momentum() << std::endl;
00142 HepLorentzVector mom(GeantTracks[it].momentum());
00143 int mothindex = 0 ;
00144 if (mom.e() < 0.) {
00145 mothindex = (int)(-GeantTracks[it].momentum().e()) ;
00146 xana::out(2) << "[update] track has daughter " << mothindex << std::endl;
00147 double energy2 = mom.perp2();
00148 double mass = HepPDT::theTable().getParticleData(GeantTracks[it].type())->mass();
00149 energy2 += mass*mass ;
00150 double energy = sqrt(energy2) ;
00151 mom.setE(energy);
00152 }
00153 xana::out(2) << "[update] recomputed geant track momentum " << mom << std::endl;
00154
00155 trk = new XANAGeantTrack(it+1,GeantTracks[it].type(), mom, mothindex);
00156 if (! GeantTracks[it].noVertex()) {
00157 vertex = GeantTracks[it].vertIndex();
00158 xana::out(2) << "[update] This track comes from the Geant Vertex ";
00159 xana::out(2) << vertex << " at " << std::endl;
00160 xana::out(2) << "x=" << std::setw(7) << std::setprecision(4) << GeantVertices[vertex].position().x()
00161 << ", y=" << std::setw(7) << std::setprecision(4) << GeantVertices[vertex].position().y()
00162 << ", z=" << std::setw(7) << std::setprecision(4) << GeantVertices[vertex].position().z()
00163 << endl;
00164 vtx = new XANAGeantVertex(GeantVertices[vertex].position());
00165 aGeantEvent.addGeantVertex(vtx);
00166 aGeantEvent.addGeantTrack(trk, vtx);
00167 } else
00168 aGeantEvent.addGeantTrack(trk);
00169
00170 xana::out(2) << "[update] Now setting link to generator particle"<< std::endl;
00171 XANAGeneratorParticle *parent;
00172 if (! GeantTracks[it].noGenpart()) {
00173 int genpart = GeantTracks[it].genpartIndex();
00174 xana::out(2) << "[update] This corresponds to generator particle ";
00175 xana::out(2) << genpart << std::endl;
00176 GenParts[genpart].print();
00177
00178 parent = new XANAGeneratorParticle(genpart+1, GenParts[genpart].status(),
00179 GenParts[genpart].pid(), GenParts[genpart].mother1(), GenParts[genpart].mother2(),
00180 GenParts[genpart].daughter1(), GenParts[genpart].daughter2(),
00181 GenParts[genpart].fourmomentum(),
00182 0., GeantVertices[vertex].position());
00183 aGeantEvent.setGeneratorParticle(trk, parent);
00184 }
00185
00186 }
00187 xana::out(4) << std::endl;
00188 xana::out(4) << "[update] Printing XANAGeantEvent "<< std::endl;
00189 aGeantEvent.print();
00190 xana::out(4) << std::endl;
00191 xana::out(4) << "[update] Related generator event is "<< std::endl;
00192 aGeantEvent.getGeneratorEvent()->print();
00193 xana::out(4) << std::endl;
00194
00195 }
00196
00197 };
00198
00199 static PKBuilder<XANAMcInfoTester> mybuilder("XANAMcInfoTester");