00001
00002
00003
00004
00005 #include <stdlib.h>
00006 #include <math.h>
00007 #include <vector>
00008 #include <cassert>
00009 #include <cstring>
00010
00011 #include "StHepParticle.h"
00012 my_hepevt* StHepParticleMaster::mgMyHepevt=0;
00013 StHepParticleMaster *StHepParticleMaster::mgInst =0;
00014 static std::vector<StHepParticle*> myVec;
00015
00016
00017
00018 class my_hepevt {
00019 public:
00020 enum {NMXHEP=4000};
00021 int nevhep;
00022 int nhep;
00023 int isthep[NMXHEP];
00024 int idhep [NMXHEP];
00025 int jmohep[NMXHEP][2];
00026 int jdahep[NMXHEP][2];
00027 double phep[NMXHEP][5];
00028 double vhep[NMXHEP][4];
00029 };
00030
00031
00032 StHepParticleMaster::StHepParticleMaster(void *addr)
00033 {
00034 assert(!mgInst && "StHepParticleMaster created twice. NEVER,JAMAIS");
00035 mgInst = this;
00036 mgMyHepevt = (my_hepevt*)addr;
00037 }
00038
00039 StHepParticleMaster::~StHepParticleMaster()
00040 {
00041 mgInst = 0;
00042 mgMyHepevt = 0;
00043 for (int i=0;i<(int)myVec.size();i++) { delete myVec[i]; }
00044 myVec.resize(0);
00045 }
00046
00047 void StHepParticleMaster::Update()
00048 {
00049 mNTk = mgMyHepevt->nhep;
00050 if (mNTk <= (int)myVec.size()) return;
00051 for (int i = (int)myVec.size(); i < mNTk;i++)
00052 {
00053 myVec.push_back(new StHepParticle(i));
00054 }
00055 }
00056
00057 const StHepParticleMaster *StHepParticleMaster::Instance()
00058 {
00059 assert(mgInst && "No new for StHepParticleMaster. Never,Jamais");
00060 return mgInst;
00061 }
00062
00063 const StHepParticle *StHepParticleMaster::operator()(int idx) const
00064 {
00065 ((StHepParticleMaster*)this)->Update();
00066 assert(idx>=0 && "Never,Jamais");
00067 if (idx >= (int)myVec.size()) return 0;
00068 if (!myVec[idx]->GetStatusCode()) return 0;
00069 return myVec[idx];
00070 }
00071
00072
00073
00074 StHepParticle::StHepParticle(int idx):StGenParticle(idx) {}
00075
00076 int StHepParticle::GetStatusCode() const
00077 {
00078 return StHepParticleMaster::mgMyHepevt->isthep[mIdx];
00079 }
00080
00081 int StHepParticle::GetPdgCode() const
00082 {
00083 return StHepParticleMaster::mgMyHepevt->idhep[mIdx];
00084 }
00085
00086 const StHepParticle *StHepParticle::GetMother(int i) const
00087 {
00088 int j = StHepParticleMaster::mgMyHepevt->jmohep[mIdx][i];
00089
00090 return (j) ? myVec[j-1]:0;
00091 }
00092
00093 const StHepParticle *StHepParticle::GetDaughter(int i) const
00094 {
00095 int j0 = StHepParticleMaster::mgMyHepevt->jdahep[mIdx][0];
00096 if (!j0) return 0;
00097 int j1 = StHepParticleMaster::mgMyHepevt->jdahep[mIdx][1];
00098 j0+=i; if (j0>j1) return 0;
00099 return myVec[j0-1];
00100 }
00101
00102
00103 double StHepParticle::GetMass() const
00104 {
00105 return StHepParticleMaster::mgMyHepevt->phep[mIdx][4];
00106 }
00107
00108 int StHepParticle::GetNDaughters() const
00109 {
00110 int j0 = StHepParticleMaster::mgMyHepevt->jdahep[mIdx][0];
00111 if (!j0) return 0;
00112 int j1 = StHepParticleMaster::mgMyHepevt->jdahep[mIdx][1];
00113 return j1-j0+1;
00114 }
00115
00116 void StHepParticle::Momentum(double p4[4]) const
00117 {
00118 memcpy(p4,StHepParticleMaster::mgMyHepevt->phep[mIdx],4*sizeof(double));
00119 }
00120
00121 void StHepParticle::Vertex(double v[3]) const
00122 {
00123 double *V = StHepParticleMaster::mgMyHepevt->vhep[mIdx];
00124 for (int i=0;i<3;i++) {v[i] = V[i]*10;}
00125 }
00126
00127 double StHepParticle::Time() const
00128 {
00129 return StHepParticleMaster::mgMyHepevt->vhep[mIdx][3]*10;
00130 }