00001
00002
00003
00004
00005 #include <stdlib.h>
00006 #include <math.h>
00007 #include <vector>
00008 #include <cassert>
00009
00010 #include "StG3Particle.h"
00011 #include "StGENParticle.h"
00012
00013 StG3ParticleMaster *StG3ParticleMaster::mgInst =0;
00014 GFKINE_t StG3ParticleMaster::mgFK=0;
00015 GFVERT_t StG3ParticleMaster::mgFV=0;
00016
00017 static std::vector<StGENParticle*> myVec;
00018
00019
00020 StG3ParticleMaster::StG3ParticleMaster(GFKINE_t fk,GFVERT_t fv)
00021 {
00022 assert(!mgInst && "Never,Jamais");
00023 mgInst = this;
00024 mgFK = fk;
00025 mgFV = fv;
00026 }
00027
00028 StG3ParticleMaster::~StG3ParticleMaster()
00029 {
00030 mgInst = 0;
00031 for (int i=0;i<(int)myVec.size();i++) { delete myVec[i]; }
00032 myVec.resize(0);
00033 }
00034
00035 const StG3ParticleMaster *StG3ParticleMaster::Instance()
00036 {
00037 assert(mgInst && "Never,Jamais");
00038 return mgInst;
00039 }
00040
00041 void StG3ParticleMaster::Update()
00042 {
00043
00044
00045 const double kC =2.99792458000000000e+10;
00046
00047 int ITRA,IPART,NVERT,NWBUF,UBUF[100];
00048 float VERT[4],PVERT[5];
00049 int NVTX,NTBEAM,NTTARG;
00050 float V[3],TOFG;
00051 mNTk = 0;
00052 int size0 = myVec.size();
00053
00054 for (ITRA = 1; 2009; ITRA++)
00055 {
00056 (mgFK)(ITRA,VERT,PVERT,IPART,NVERT,UBUF,NWBUF);
00057 if (!IPART) break;
00058 mNTk = ITRA;
00059 NVTX = NVERT;
00060 TOFG = 0;NTBEAM=0,NTTARG=0;
00061 if (NVTX) {
00062 (mgFV)(NVTX,V,NTBEAM,NTTARG,TOFG,UBUF,NWBUF);
00063 }
00064 if (ITRA > size0) {myVec.push_back(new StGENParticle(ITRA-1));}
00065 else {myVec[ITRA-1]->Clear() ;}
00066 StGENParticle *tk = myVec[ITRA-1];
00067 tk->Clear();
00068 VERT[3] = TOFG*kC;
00069 PVERT[4] = Gea2Mas(IPART);
00070 tk->SetGea(IPART);
00071 tk->SetPdg(Gea2Pdg(IPART));
00072 tk->SetVert(VERT);
00073 tk->SetMom(PVERT);
00074 if (!NVTX) continue;
00075 if (NTBEAM) {
00076 assert(NTBEAM<ITRA && "Never,Jamais");
00077 tk->SetMother(0,myVec[NTBEAM-1]);
00078 myVec[NTBEAM-1]->AddDaughter(tk);
00079 }
00080 if (NTTARG>0 && NTTARG<ITRA) tk->SetMother(1,myVec[NTTARG-1]);
00081 }
00082
00083 }
00084
00085 const StGenParticle *StG3ParticleMaster::operator()(int idx) const
00086 {
00087 assert(idx>=0 && "Never,Jamais");
00088 if (idx >= mNTk) return 0;
00089 if (!myVec[idx]->GetStatusCode()) return 0;
00090 return myVec[idx];
00091 }
00092