VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
E02
src
Ex02MCStack.cxx
Go to the documentation of this file.
1
//------------------------------------------------
2
// The Virtual Monte Carlo examples
3
// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4
// All rights reserved.
5
//
6
// For the licensing terms see geant4_vmc/LICENSE.
7
// Contact: root-vmc@cern.ch
8
//-------------------------------------------------
9
10
/// \file Ex02MCStack.cxx
11
/// \brief Implementation of the Ex02MCStack class
12
///
13
/// Geant4 ExampleN02 adapted to Virtual Monte Carlo
14
///
15
/// \date 21/04/2002
16
/// \author I. Hrivnacova; IPN, Orsay
17
18
#include "
Ex02MCStack.h
"
19
20
#include <TError.h>
21
#include <TObjArray.h>
22
#include <TParticle.h>
23
24
#include <iostream>
25
26
using namespace
std;
27
28
/// \cond CLASSIMP
29
ClassImp(
Ex02MCStack
)
30
/// \endcond
31
32
//_____________________________________________________________________________
33
Ex02MCStack
::
Ex02MCStack
(Int_t size)
34
:
fParticles
(0),
fCurrentTrack
(-1),
fNPrimary
(0),
fObjectNumber
(0)
35
{
36
/// Standard constructor
37
/// \param size The stack size
38
39
fParticles
=
new
TObjArray(size);
40
}
41
42
//_____________________________________________________________________________
43
Ex02MCStack::Ex02MCStack
()
44
:
fParticles
(0),
fCurrentTrack
(-1),
fNPrimary
(0),
fObjectNumber
(0)
45
{
46
/// Default constructor
47
}
48
49
//_____________________________________________________________________________
50
Ex02MCStack::~Ex02MCStack
()
51
{
52
/// Destructor
53
54
if
(
fParticles
)
fParticles
->Delete();
55
delete
fParticles
;
56
}
57
58
// private methods
59
60
// public methods
61
62
//_____________________________________________________________________________
63
void
Ex02MCStack::PushTrack
(Int_t toBeDone, Int_t parent, Int_t pdg,
64
Double_t px, Double_t py, Double_t pz, Double_t e, Double_t vx, Double_t vy,
65
Double_t vz, Double_t tof, Double_t polx, Double_t poly, Double_t polz,
66
TMCProcess mech, Int_t& ntr, Double_t weight, Int_t is)
67
{
68
/// Create a new particle and push into stack;
69
/// adds it to the particles array (fParticles) and if not done to the
70
/// stack (fStack).
71
/// \param toBeDone 1 if particles should go to tracking, 0 otherwise
72
/// \param parent number of the parent track, -1 if track is primary
73
/// \param pdg PDG encoding
74
/// \param px particle momentum - x component [GeV/c]
75
/// \param py particle momentum - y component [GeV/c]
76
/// \param pz particle momentum - z component [GeV/c]
77
/// \param e total energy [GeV]
78
/// \param vx position - x component [cm]
79
/// \param vy position - y component [cm]
80
/// \param vz position - z component [cm]
81
/// \param tof time of flight [s]
82
/// \param polx polarization - x component
83
/// \param poly polarization - y component
84
/// \param polz polarization - z component
85
/// \param mech creator process VMC code
86
/// \param ntr track number (is filled by the stack
87
/// \param weight particle weight
88
/// \param is generation status code
89
90
const
Int_t kFirstDaughter = -1;
91
const
Int_t kLastDaughter = -1;
92
93
TParticle* particleDef =
new
TParticle(pdg, is, parent, -1, kFirstDaughter,
94
kLastDaughter, px, py, pz, e, vx, vy, vz, tof);
95
96
particleDef->SetPolarisation(polx, poly, polz);
97
particleDef->SetWeight(weight);
98
particleDef->SetUniqueID(mech);
99
100
Ex02Particle
* mother = 0;
101
if
(parent >= 0)
102
mother =
GetParticle
(parent);
103
else
104
fNPrimary
++;
105
106
Ex02Particle
* particle =
new
Ex02Particle
(
GetNtrack
(), particleDef, mother);
107
if
(mother) mother->
AddDaughter
(particle);
108
fParticles
->Add(particle);
109
110
if
(toBeDone)
fStack
.push(particle);
111
112
ntr =
GetNtrack
() - 1;
113
}
114
115
//_____________________________________________________________________________
116
TParticle*
Ex02MCStack::PopNextTrack
(Int_t& itrack)
117
{
118
/// Get next particle for tracking from the stack.
119
/// \return The popped particle object
120
/// \param track The index of the popped track
121
122
itrack = -1;
123
if
(
fStack
.empty())
return
0;
124
125
Ex02Particle
* particle =
fStack
.top();
126
fStack
.pop();
127
128
if
(!particle)
return
0;
129
130
itrack = particle->
GetID
();
131
fCurrentTrack
= itrack;
132
133
return
particle->
GetParticle
();
134
}
135
136
//_____________________________________________________________________________
137
TParticle*
Ex02MCStack::PopPrimaryForTracking
(Int_t i)
138
{
139
/// Return \em i -th particle in fParticles.
140
/// \return The popped primary particle object
141
/// \param i The index of primary particle to be popped
142
143
if
(i < 0 || i >=
fNPrimary
)
144
Fatal(
"GetPrimaryForTracking"
,
"Index out of range"
);
145
146
return
((
Ex02Particle
*)
fParticles
->At(i))->GetParticle();
147
}
148
149
//_____________________________________________________________________________
150
void
Ex02MCStack::Print
(Option_t*
/*option*/
)
const
151
{
152
/// Print info for all particles.
153
154
cout <<
"Ex02MCStack Info "
<< endl;
155
cout <<
"Total number of particles: "
<<
GetNtrack
() << endl;
156
cout <<
"Number of primary particles: "
<<
GetNprimary
() << endl;
157
158
for
(Int_t i = 0; i <
GetNtrack
(); i++) {
159
GetParticle
(i)->
Print
();
160
// GetParticle(i)->PrintDaughters();
161
}
162
}
163
164
//_____________________________________________________________________________
165
void
Ex02MCStack::Reset
()
166
{
167
/// Delete contained particles, reset particles array and stack.
168
169
// reset fStack
170
fCurrentTrack
= -1;
171
fNPrimary
= 0;
172
// fParticles->Delete();
173
fParticles
->Clear();
174
175
// Restore Object count
176
// To save space in the table keeping track of all referenced objects
177
// we assume that our events do not address each other. We reset the
178
// object count to what it was at the beginning of the event
179
TProcessID::SetObjectCount(
fObjectNumber
);
180
}
181
182
//_____________________________________________________________________________
183
void
Ex02MCStack::SetCurrentTrack
(Int_t track)
184
{
185
/// Set the current track number to a given value.
186
/// \param track The current track number
187
188
fCurrentTrack
= track;
189
}
190
191
//_____________________________________________________________________________
192
void
Ex02MCStack::SetObjectNumber
()
193
{
194
/// Set the current value of Root object counter into fObjectNumber.
195
/// Tis value will be restored in Reset.
196
197
fObjectNumber
= TProcessID::GetObjectCount();
198
}
199
200
//_____________________________________________________________________________
201
Int_t
Ex02MCStack::GetNtrack
()
const
202
{
203
/// \return The total number of all tracks.
204
205
return
fParticles
->GetEntriesFast();
206
}
207
208
//_____________________________________________________________________________
209
Int_t
Ex02MCStack::GetNprimary
()
const
210
{
211
/// \return The total number of primary tracks.
212
213
return
fNPrimary
;
214
}
215
216
//_____________________________________________________________________________
217
TParticle*
Ex02MCStack::GetCurrentTrack
()
const
218
{
219
/// \return The current track particle
220
221
Ex02Particle
* current =
GetParticle
(
fCurrentTrack
);
222
223
if
(current)
224
return
current->
GetParticle
();
225
else
226
return
0;
227
}
228
229
//_____________________________________________________________________________
230
Int_t
Ex02MCStack::GetCurrentTrackNumber
()
const
231
{
232
/// \return The current track number
233
234
return
fCurrentTrack
;
235
}
236
237
//_____________________________________________________________________________
238
Int_t
Ex02MCStack::GetCurrentParentTrackNumber
()
const
239
{
240
/// \return The current track parent ID.
241
242
Ex02Particle
* current =
GetParticle
(
fCurrentTrack
);
243
244
if
(!current)
return
-1;
245
246
Ex02Particle
* mother = current->
GetMother
();
247
248
if
(!mother)
return
-1;
249
250
return
mother->
GetID
();
251
}
252
253
//_____________________________________________________________________________
254
Ex02Particle
*
Ex02MCStack::GetParticle
(Int_t
id
)
const
255
{
256
/// \return The \em id -th particle in fParticles
257
/// \param id The index of the particle to be returned
258
259
if
(id < 0 || id >=
fParticles
->GetEntriesFast())
260
Fatal(
"GetParticle"
,
"Index out of range"
);
261
262
return
(
Ex02Particle
*)
fParticles
->At(
id
);
263
}
Ex02MCStack.h
Definition of the Ex02MCStack class.
Ex02MCStack
Implementation of the TVirtualMCStack interface.
Definition
Ex02MCStack.h:33
Ex02MCStack::~Ex02MCStack
virtual ~Ex02MCStack()
Definition
Ex02MCStack.cxx:50
Ex02MCStack::Print
virtual void Print(Option_t *option="") const
Definition
Ex02MCStack.cxx:150
Ex02MCStack::Ex02MCStack
Ex02MCStack(Int_t size)
Definition
Ex02MCStack.cxx:33
Ex02MCStack::Reset
void Reset()
Definition
Ex02MCStack.cxx:165
Ex02MCStack::GetCurrentTrack
virtual TParticle * GetCurrentTrack() const
Definition
Ex02MCStack.cxx:217
Ex02MCStack::SetCurrentTrack
virtual void SetCurrentTrack(Int_t track)
Definition
Ex02MCStack.cxx:183
Ex02MCStack::fCurrentTrack
Int_t fCurrentTrack
The current track number.
Definition
Ex02MCStack.h:65
Ex02MCStack::PopPrimaryForTracking
virtual TParticle * PopPrimaryForTracking(Int_t i)
Definition
Ex02MCStack.cxx:137
Ex02MCStack::GetNtrack
virtual Int_t GetNtrack() const
Definition
Ex02MCStack.cxx:201
Ex02MCStack::PopNextTrack
virtual TParticle * PopNextTrack(Int_t &track)
Definition
Ex02MCStack.cxx:116
Ex02MCStack::PushTrack
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)
Definition
Ex02MCStack.cxx:63
Ex02MCStack::GetParticle
Ex02Particle * GetParticle(Int_t id) const
Definition
Ex02MCStack.cxx:254
Ex02MCStack::SetObjectNumber
void SetObjectNumber()
Definition
Ex02MCStack.cxx:192
Ex02MCStack::GetCurrentTrackNumber
virtual Int_t GetCurrentTrackNumber() const
Definition
Ex02MCStack.cxx:230
Ex02MCStack::fObjectNumber
Int_t fObjectNumber
The Root object number counter.
Definition
Ex02MCStack.h:67
Ex02MCStack::GetCurrentParentTrackNumber
virtual Int_t GetCurrentParentTrackNumber() const
Definition
Ex02MCStack.cxx:238
Ex02MCStack::GetNprimary
virtual Int_t GetNprimary() const
Definition
Ex02MCStack.cxx:209
Ex02MCStack::fStack
std::stack< Ex02Particle * > fStack
The stack of particles (transient).
Definition
Ex02MCStack.h:63
Ex02MCStack::Ex02MCStack
Ex02MCStack()
Definition
Ex02MCStack.cxx:43
Ex02MCStack::fNPrimary
Int_t fNPrimary
The number of primaries.
Definition
Ex02MCStack.h:66
Ex02MCStack::fParticles
TObjArray * fParticles
The array of particle (persistent).
Definition
Ex02MCStack.h:64
Ex02Particle
Extended TParticle with pointers to mother and daughter particles.
Definition
Ex02Particle.h:34
Ex02Particle::GetID
Int_t GetID() const
Definition
Ex02Particle.cxx:122
Ex02Particle::Print
virtual void Print(Option_t *option="") const
Definition
Ex02Particle.cxx:87
Ex02Particle::GetMother
Ex02Particle * GetMother() const
Definition
Ex02Particle.cxx:138
Ex02Particle::GetParticle
TParticle * GetParticle() const
Definition
Ex02Particle.cxx:130
Ex02Particle::AddDaughter
void AddDaughter(Ex02Particle *particle)
Definition
Ex02Particle.cxx:78
Generated on
for VMC Examples by
1.17.0