StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarParticleStack.cxx
1 #include "StarParticleStack.h"
2 ClassImp(StarParticleStack);
3 
4 #include <assert.h>
5 
6 // Interface to STARSIM particle stack
7 #define agsvert F77_NAME(agsvert,AGSVERT)
8 #define agskine F77_NAME(agskine,AGSKINE)
9 
10 #include "TMCProcess.h"
11 using namespace std;
12 
13 extern "C"
14 {
15  void type_of_call agsvert( Float_t *vertex, Int_t *ntbeam, Int_t *nttarg, Float_t *ubuf, Int_t *nu, Int_t *nv );
16  void type_of_call agskine( Float_t *plab, Int_t *iparti, Int_t *nv, Float_t *ubuf, Int_t *nb, Int_t *nt );
17 };
18 
19 const Int_t kDefaultStackSize = 400;
20 const Int_t kDefaultArraySize = 4000;
21 
22 // ----------------------------------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------------------------------
25 StarParticleStack::StarParticleStack( const Char_t *name ) :
26  TVirtualMCStack(),
27  mNumPrimary(0),
28  mCurrent(-1),
29  mArraySize(0),
30  mArray(0),
31  mStackSize(0)
32 {
33 
34  mArray = new TClonesArray("TParticle", kDefaultArraySize );
35 
36 }
37 // ----------------------------------------------------------------------------------------------------
38 //
39 // ----------------------------------------------------------------------------------------------------
40 StarParticleStack::~StarParticleStack()
41 {
42  if ( mArray ) delete mArray;
43 }
44 // ----------------------------------------------------------------------------------------------------
45 //
46 // ----------------------------------------------------------------------------------------------------
47 void StarParticleStack::PushTrack( Int_t toDo, Int_t parent, Int_t pdg,
48  Double_t px, Double_t py, Double_t pz, Double_t energy,
49  Double_t vx, Double_t vy, Double_t vz, Double_t vt,
50  Double_t polx, Double_t poly, Double_t polz,
51  TMCProcess mech, Int_t& ntr, Double_t weight,
52  Int_t is )
53 {
54 
55 
56  //
57  // Add a new particle to the array. Note: VMC standard PushTrack does not specify the children
58  // (or 2nd parent) of particles. So these are entered with value of -1.
59  //
60  TClonesArray &array = (*mArray);
61  TParticle *particle = new(array[mArraySize]) TParticle( pdg, is, parent, -1, -1, -1,
62  px, py, pz, energy, vx, vy, vz, vt);
63  particle->SetPolarisation( polx, poly, polz );
64  particle->SetWeight(weight);
65  particle->SetUniqueID(mech);
66 
67 
68  // Increment primary track count
69  if ( parent<0 )
70  {
71  mNumPrimary++;
72  }
73 
74  // Add to the stack of particles
75  if ( toDo )
76  {
77 
78  mStack.push_back( particle );
79  mStackIdx.push_back( mArraySize ); // store stack ID
80 
81  }
82  ntr = mArraySize; // guess this is supposed to be track number (index in array)
83 
84  // Increment mArraySize
85  mArraySize++;
86 
87 }
88 // ----------------------------------------------------------------------------------------------------
89 //
90 // ----------------------------------------------------------------------------------------------------
91 TParticle *StarParticleStack::PopNextTrack( Int_t &itrack )
92 {
93 
94  // Start with invalid track index
95  itrack = -1;
96 
97  // The stack is empty. Signal the end.
98  if ( mStack.empty() )
99  {
100  return NULL;
101  }
102 
103  // Get the particle on the top of the stack
104  TParticle *particle = mStack.front(); mStack.pop_front();
105  itrack = mStackIdx.front(); mStackIdx.pop_front();
106  mCurrent = itrack;
107 
108  return particle;
109 
110 }
111 // ----------------------------------------------------------------------------------------------------
112 //
113 // ----------------------------------------------------------------------------------------------------
115 {
116  assert(i<mArraySize);
117  return (TParticle *)(*mArray)[i];
118 }
119 // ----------------------------------------------------------------------------------------------------
120 //
121 // ----------------------------------------------------------------------------------------------------
123 {
124  mCurrent = tn;
125 }
126 // ----------------------------------------------------------------------------------------------------
127 //
128 // ----------------------------------------------------------------------------------------------------
130 {
131  return mArray->GetEntriesFast();
132 }
133 // ----------------------------------------------------------------------------------------------------
134 //
135 // ----------------------------------------------------------------------------------------------------
137 {
138  return GetParticle(mCurrent);
139 }
140 // ----------------------------------------------------------------------------------------------------
141 //
142 // ----------------------------------------------------------------------------------------------------
144 {
145  return mCurrent;
146 }
147 // ----------------------------------------------------------------------------------------------------
148 //
149 // ----------------------------------------------------------------------------------------------------
151 {
152  TParticle *current = GetCurrentTrack();
153  return (current)? current->GetFirstMother() : -1;
154 }
155 // ----------------------------------------------------------------------------------------------------
156 //
157 // ----------------------------------------------------------------------------------------------------
158 TParticle *StarParticleStack::GetParticle( Int_t idx ) const
159 {
160  return (TParticle *)(*mArray)[idx];
161 }
162 // ----------------------------------------------------------------------------------------------------
163 //
164 // ----------------------------------------------------------------------------------------------------
165 void StarParticleStack::Clear( const Option_t *opts )
166 {
167  mArray->Clear();
168  mStack.clear();
169  mCurrent = -1;
170  mArraySize = 0;
171  mStackSize = 0;
172 }
173 // ----------------------------------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------------------------------
static TParticlePDG * pdg(Int_t pdgid)
virtual void SetCurrentTrack(Int_t trackNumber)
Set the current track number.
virtual void PushTrack(Int_t toBeDone, Int_t parent, Int_t pdg, Double_t px, Double_t py, Double_t pz, Double_t e, Double_t vx, Double_t vy, Double_t vz, Double_t tof, Double_t polx, Double_t poly, Double_t polz, TMCProcess mech, Int_t &ntr, Double_t weight, Int_t is)
virtual Int_t GetCurrentTrackNumber() const
Current track number.
virtual TParticle * GetParticle(const Int_t i) const
Retrieve the ith particle in the array.
virtual Int_t GetCurrentParentTrackNumber() const
Number of the parent of the current track.
virtual TParticle * GetCurrentTrack() const
Current track particle.
Implementation of the VMC particle stack for use in STAR.
virtual TParticle * PopPrimaryForTracking(Int_t i)
virtual Int_t GetNtrack() const
Total number of tracks.
virtual TParticle * PopNextTrack(Int_t &itrack)
virtual void Clear(const Option_t *opts="")
Clear the stack.