1 |
// $Id: PamVMCStack.cxx,v 1.0 2007/06/03 |
2 |
// |
3 |
// Class PamVMCStack |
4 |
|
5 |
#include <TParticle.h> |
6 |
#include <TClonesArray.h> |
7 |
#include <TError.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("TParticle", 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 TParticle::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 |
TParticle* particle |
57 |
= new(particlesRef[trackId]) |
58 |
TParticle(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 |
} |
69 |
|
70 |
TParticle* PamVMCStack::PopNextTrack(Int_t& itrack) |
71 |
{ |
72 |
// Gets next particle for tracking from the stack. |
73 |
|
74 |
itrack = -1; |
75 |
if (fStack.empty()) return 0; |
76 |
|
77 |
TParticle* particle = fStack.top(); |
78 |
fStack.pop(); |
79 |
|
80 |
if (!particle) return 0; |
81 |
|
82 |
fCurrentTrack = particle->GetSecondMother(); |
83 |
itrack = fCurrentTrack; |
84 |
|
85 |
return particle; |
86 |
} |
87 |
|
88 |
TParticle* PamVMCStack::PopPrimaryForTracking(Int_t i) |
89 |
{ |
90 |
// Returns i-th particle in fParticles. |
91 |
|
92 |
|
93 |
if (i < 0 || i >= fNPrimary) |
94 |
Fatal("GetPrimaryForTracking", "Index out of range"); |
95 |
|
96 |
return (TParticle*)fParticles->At(i); |
97 |
} |
98 |
|
99 |
void PamVMCStack::Print(Option_t* /*option*/) const |
100 |
{ |
101 |
// Prints info for all particles. |
102 |
|
103 |
cout << "PamVMCStack Info " << endl; |
104 |
cout << "Total number of particles: " << GetNtrack() << endl; |
105 |
cout << "Number of primary particles: " << GetNprimary() << endl; |
106 |
|
107 |
for (Int_t i=0; i<GetNtrack(); i++){ |
108 |
GetParticle(i)->Print(); |
109 |
|
110 |
} |
111 |
} |
112 |
|
113 |
void PamVMCStack::Reset() |
114 |
{ |
115 |
// Deletes contained particles, resets particles array and stack. |
116 |
|
117 |
fCurrentTrack = -1; |
118 |
fNPrimary = 0; |
119 |
fParticles->Clear(); |
120 |
} |
121 |
|
122 |
void PamVMCStack::SetCurrentTrack(Int_t track) |
123 |
{ |
124 |
// Sets the current track to a given value. |
125 |
|
126 |
fCurrentTrack = track; |
127 |
} |
128 |
|
129 |
Int_t PamVMCStack::GetNtrack() const |
130 |
{ |
131 |
// Returns the number of all tracks. |
132 |
|
133 |
return fParticles->GetEntriesFast(); |
134 |
} |
135 |
|
136 |
Int_t PamVMCStack::GetNprimary() const |
137 |
{ |
138 |
// Returns the number of primary tracks. |
139 |
|
140 |
return fNPrimary; |
141 |
} |
142 |
|
143 |
TParticle* PamVMCStack::GetCurrentTrack() const |
144 |
{ |
145 |
// Returns the current track parent ID. |
146 |
|
147 |
TParticle* current = GetParticle(fCurrentTrack); |
148 |
|
149 |
if (!current) |
150 |
Warning("GetCurrentTrack", "Current track not found in the stack"); |
151 |
|
152 |
return current; |
153 |
} |
154 |
|
155 |
Int_t PamVMCStack::GetCurrentTrackNumber() const |
156 |
{ |
157 |
// Returns the current track ID. |
158 |
|
159 |
return fCurrentTrack; |
160 |
} |
161 |
|
162 |
Int_t PamVMCStack::GetCurrentParentTrackNumber() const |
163 |
{ |
164 |
// Returns the current track parent ID. |
165 |
|
166 |
TParticle* current = GetCurrentTrack(); |
167 |
|
168 |
if (current) |
169 |
return current->GetFirstMother(); |
170 |
else |
171 |
return -1; |
172 |
} |
173 |
|
174 |
TParticle* PamVMCStack::GetParticle(Int_t id) const |
175 |
{ |
176 |
// Returns id-th particle in fParticles. |
177 |
|
178 |
if (id < 0 || id >= fParticles->GetEntriesFast()) |
179 |
Fatal("GetParticle", "Index out of range"); |
180 |
|
181 |
return (TParticle*)fParticles->At(id); |
182 |
} |
183 |
|
184 |
|