1 |
// $Id: PamVMCStack.cxx,v 1.0 2007/06/03 |
2 |
// Class PamVMCStack |
3 |
|
4 |
#include <PamVMCParticle.h> |
5 |
#include <TClonesArray.h> |
6 |
#include <TError.h> |
7 |
#include <TString.h> |
8 |
#include <Riostream.h> |
9 |
|
10 |
#include "PamVMCStack.h" |
11 |
|
12 |
ClassImp(PamVMCStack) |
13 |
|
14 |
PamVMCStack::PamVMCStack(Int_t size) |
15 |
: fParticles(0), |
16 |
fCurrentTrack(-1), |
17 |
fNPrimary(0) |
18 |
{ |
19 |
fParticles = new TClonesArray("PamVMCParticle", size); |
20 |
} |
21 |
|
22 |
PamVMCStack::PamVMCStack() |
23 |
: fParticles(0), |
24 |
fCurrentTrack(-1), |
25 |
fNPrimary(0) |
26 |
{ |
27 |
|
28 |
|
29 |
} |
30 |
|
31 |
PamVMCStack::~PamVMCStack() |
32 |
{ |
33 |
|
34 |
if (fParticles) fParticles->Delete(); |
35 |
delete fParticles; |
36 |
} |
37 |
|
38 |
|
39 |
void PamVMCStack::PushTrack(Int_t toBeDone, Int_t parent, Int_t pdg, |
40 |
Double_t px, Double_t py, Double_t pz, Double_t e, |
41 |
Double_t vx, Double_t vy, Double_t vz, Double_t tof, |
42 |
Double_t polx, Double_t poly, Double_t polz, |
43 |
TMCProcess mech, Int_t& ntr, Double_t weight, |
44 |
Int_t is) |
45 |
{ |
46 |
// Creates a new particle with specified properties, |
47 |
// adds it to the particles array (fParticles) and if not done to the |
48 |
// stack (fStack). |
49 |
// Use PamVMCParticle::fMother[1] to store Track ID. |
50 |
|
51 |
const Int_t kFirstDaughter=-1; |
52 |
const Int_t kLastDaughter=-1; |
53 |
|
54 |
TClonesArray& particlesRef = *fParticles; |
55 |
Int_t trackId = GetNtrack(); |
56 |
PamVMCParticle* particle |
57 |
= new(particlesRef[trackId]) |
58 |
PamVMCParticle(pdg, is, parent, trackId, kFirstDaughter, kLastDaughter, |
59 |
px, py, pz, e, vx, vy, vz, tof); |
60 |
|
61 |
particle->SetPolarisation(polx, poly, polz); |
62 |
particle->SetWeight(weight); |
63 |
particle->SetUniqueID(mech); |
64 |
|
65 |
if (parent<0) fNPrimary++; |
66 |
|
67 |
if (toBeDone) fStack.push(particle); |
68 |
ntr=trackId-1; |
69 |
} |
70 |
|
71 |
PamVMCParticle* PamVMCStack::PopNextTrack(Int_t& itrack) |
72 |
{ |
73 |
// Gets next particle for tracking from the stack. |
74 |
|
75 |
itrack = -1; |
76 |
if (fStack.empty()) return 0; |
77 |
|
78 |
PamVMCParticle* particle = fStack.top(); |
79 |
fStack.pop(); |
80 |
|
81 |
if (!particle) return 0; |
82 |
|
83 |
fCurrentTrack = particle->GetSecondMother(); |
84 |
itrack = fCurrentTrack; |
85 |
|
86 |
return particle; |
87 |
} |
88 |
|
89 |
PamVMCParticle* PamVMCStack::PopPrimaryForTracking(Int_t i) |
90 |
{ |
91 |
// Returns i-th particle in fParticles. |
92 |
|
93 |
|
94 |
if (i < 0 || i >= fNPrimary) |
95 |
Fatal("GetPrimaryForTracking", "Index out of range"); |
96 |
|
97 |
return (PamVMCParticle*)fParticles->At(i); |
98 |
} |
99 |
|
100 |
void PamVMCStack::Print(Option_t* /*option*/) const |
101 |
{ |
102 |
// Prints info for all particles. |
103 |
|
104 |
cout << "PamVMCStack Info " << endl; |
105 |
cout << "Total number of particles: " << GetNtrack() << endl; |
106 |
cout << "Number of primary particles: " << GetNprimary() << endl; |
107 |
|
108 |
for (Int_t i=0; i<GetNtrack(); i++){ |
109 |
GetParticle(i)->Print(); |
110 |
|
111 |
} |
112 |
} |
113 |
|
114 |
void PamVMCStack::Reset() |
115 |
{ |
116 |
// Deletes contained particles, resets particles array and stack. |
117 |
|
118 |
fCurrentTrack = -1; |
119 |
fNPrimary = 0; |
120 |
fParticles->Clear("C"); |
121 |
fParticles->Compress(); |
122 |
} |
123 |
|
124 |
void PamVMCStack::SetCurrentTrack(Int_t track) |
125 |
{ |
126 |
// Sets the current track to a given value. |
127 |
|
128 |
fCurrentTrack = track; |
129 |
} |
130 |
|
131 |
Int_t PamVMCStack::GetNtrack() const |
132 |
{ |
133 |
// Returns the number of all tracks. |
134 |
|
135 |
return fParticles->GetEntriesFast(); |
136 |
} |
137 |
|
138 |
Int_t PamVMCStack::GetNprimary() const |
139 |
{ |
140 |
// Returns the number of primary tracks. |
141 |
|
142 |
return fNPrimary; |
143 |
} |
144 |
|
145 |
PamVMCParticle* PamVMCStack::GetCurrentTrack() const |
146 |
{ |
147 |
// Returns the current track parent ID. |
148 |
|
149 |
PamVMCParticle* current = GetParticle(fCurrentTrack); |
150 |
|
151 |
if (!current) |
152 |
Warning("GetCurrentTrack", "Current track not found in the stack"); |
153 |
|
154 |
return current; |
155 |
} |
156 |
|
157 |
Int_t PamVMCStack::GetCurrentTrackNumber() const |
158 |
{ |
159 |
// Returns the current track ID. |
160 |
|
161 |
return fCurrentTrack; |
162 |
} |
163 |
|
164 |
Int_t PamVMCStack::GetCurrentParentTrackNumber() const |
165 |
{ |
166 |
// Returns the current track parent ID. |
167 |
|
168 |
PamVMCParticle* current = GetCurrentTrack(); |
169 |
|
170 |
if (current) |
171 |
return current->GetFirstMother(); |
172 |
else |
173 |
return -1; |
174 |
} |
175 |
|
176 |
PamVMCParticle* PamVMCStack::GetParticle(Int_t id) const |
177 |
{ |
178 |
// Returns id-th particle in fParticles. |
179 |
|
180 |
if (id < 0 || id >= fParticles->GetEntriesFast()){ |
181 |
TString e="Index out of range "; |
182 |
e+=id; |
183 |
// Fatal("GetParticle", "Index out of range"); |
184 |
Fatal("GetParticle", e.Data()); |
185 |
} |
186 |
return (PamVMCParticle*)fParticles->At(id); |
187 |
} |
188 |
|
189 |
|