StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHepParticle.cxx
1 // @(#)root/eg:$Id: StHepParticle.cxx,v 1.5 2009/08/25 20:49:16 fine Exp $
2 // Author: Victor Perev 17/03/2009
3 
4 //______________________________________________________________________________
5 #include <stdlib.h>
6 #include <math.h>
7 #include <vector>
8 #include <cassert>
9 #include <cstring>
10 
11 #include "StHepParticle.h"
12 my_hepevt* StHepParticleMaster::mgMyHepevt=0;
13 StHepParticleMaster *StHepParticleMaster::mgInst =0;
14 static std::vector<StHepParticle*> myVec;
15 
16 //______________________________________________________________________________
17 
18 class my_hepevt {
19 public:
20  enum {NMXHEP=4000};
21  int nevhep; /* The event number */
22  int nhep; /* The number of entries in this event */
23  int isthep[NMXHEP]; /* The Particle status code*/
24  int idhep [NMXHEP]; /* The particle id */
25  int jmohep[NMXHEP][2]; /* The position of the mother particle */
26  int jdahep[NMXHEP][2]; /* Position of the first daughter... */
27  double phep[NMXHEP][5]; /* 4-Momentum, mass */
28  double vhep[NMXHEP][4]; /* Vertex information */
29 };
30 
31 //______________________________________________________________________________
32 StHepParticleMaster::StHepParticleMaster(void *addr)
33 {
34  assert(!mgInst && "StHepParticleMaster created twice. NEVER,JAMAIS");
35  mgInst = this;
36  mgMyHepevt = (my_hepevt*)addr;
37 }
38 //______________________________________________________________________________
39 StHepParticleMaster::~StHepParticleMaster()
40 {
41  mgInst = 0;
42  mgMyHepevt = 0;
43  for (int i=0;i<(int)myVec.size();i++) { delete myVec[i]; }
44  myVec.resize(0);
45 }
46 //______________________________________________________________________________
47 void StHepParticleMaster::Update()
48 {
49  mNTk = mgMyHepevt->nhep;
50  if (mNTk <= (int)myVec.size()) return;
51  for (int i = (int)myVec.size(); i < mNTk;i++)
52  {
53  myVec.push_back(new StHepParticle(i));
54  }
55 }
56 //______________________________________________________________________________
57 const StHepParticleMaster *StHepParticleMaster::Instance()
58 {
59  assert(mgInst && "No new for StHepParticleMaster. Never,Jamais");
60  return mgInst;
61 }
62 //______________________________________________________________________________
63 const StHepParticle *StHepParticleMaster::operator()(int idx) const
64 {
65  ((StHepParticleMaster*)this)->Update();
66  assert(idx>=0 && "Never,Jamais");
67  if (idx >= (int)myVec.size()) return 0;
68  if (!myVec[idx]->GetStatusCode()) return 0;
69  return myVec[idx];
70 }
71 
72 //______________________________________________________________________________
73 //______________________________________________________________________________
74  StHepParticle::StHepParticle(int idx):StGenParticle(idx) {}
75 //______________________________________________________________________________
76 int StHepParticle::GetStatusCode() const
77 {
78  return StHepParticleMaster::mgMyHepevt->isthep[mIdx];
79 }
80 //______________________________________________________________________________
81 int StHepParticle::GetPdgCode() const
82 {
83  return StHepParticleMaster::mgMyHepevt->idhep[mIdx];
84 }
85 //______________________________________________________________________________
86 const StHepParticle *StHepParticle::GetMother(int i) const
87 {
88  int j = StHepParticleMaster::mgMyHepevt->jmohep[mIdx][i];
89 
90  return (j) ? myVec[j-1]:0;
91 }
92 //______________________________________________________________________________
93 const StHepParticle *StHepParticle::GetDaughter(int i) const
94 {
95  int j0 = StHepParticleMaster::mgMyHepevt->jdahep[mIdx][0];
96  if (!j0) return 0;
97  int j1 = StHepParticleMaster::mgMyHepevt->jdahep[mIdx][1];
98  j0+=i; if (j0>j1) return 0;
99  return myVec[j0-1];
100 }
101 
102 //______________________________________________________________________________
103 double StHepParticle::GetMass() const
104 {
105  return StHepParticleMaster::mgMyHepevt->phep[mIdx][4];
106 }
107 //______________________________________________________________________________
108 int StHepParticle::GetNDaughters() const
109 {
110  int j0 = StHepParticleMaster::mgMyHepevt->jdahep[mIdx][0];
111  if (!j0) return 0;
112  int j1 = StHepParticleMaster::mgMyHepevt->jdahep[mIdx][1];
113  return j1-j0+1;
114 }
115 //______________________________________________________________________________
116 void StHepParticle::Momentum(double p4[4]) const
117 {
118  memcpy(p4,StHepParticleMaster::mgMyHepevt->phep[mIdx],4*sizeof(double));
119 }
120 //______________________________________________________________________________
121 void StHepParticle::Vertex(double v[3]) const
122 {
123  double *V = StHepParticleMaster::mgMyHepevt->vhep[mIdx];
124  for (int i=0;i<3;i++) {v[i] = V[i]*10;}
125 }
126 //______________________________________________________________________________
127 double StHepParticle::Time() const
128 {
129  return StHepParticleMaster::mgMyHepevt->vhep[mIdx][3]*10;
130 }
Abstract base class for particles related to common /HEPEVT/.