VMC Examples Version 6.6
Loading...
Searching...
No Matches
Ex02MCStack Class Reference

Implementation of the TVirtualMCStack interface. More...

#include <Ex02MCStack.h>

Inheritance diagram for Ex02MCStack:

Public Member Functions

 Ex02MCStack (Int_t size)
 
 Ex02MCStack ()
 
virtual ~Ex02MCStack ()
 
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 TParticle * PopNextTrack (Int_t &track)
 
virtual TParticle * PopPrimaryForTracking (Int_t i)
 
virtual void Print (Option_t *option="") const
 
void Reset ()
 
virtual void SetCurrentTrack (Int_t track)
 
void SetObjectNumber ()
 
virtual Int_t GetNtrack () const
 
virtual Int_t GetNprimary () const
 
virtual TParticle * GetCurrentTrack () const
 
virtual Int_t GetCurrentTrackNumber () const
 
virtual Int_t GetCurrentParentTrackNumber () const
 
Ex02ParticleGetParticle (Int_t id) const
 

Private Attributes

std::stack< Ex02Particle * > fStack
 The stack of particles (transient)
 
TObjArray * fParticles
 The array of particle (persistent)
 
Int_t fCurrentTrack
 The current track number.
 
Int_t fNPrimary
 The number of primaries.
 
Int_t fObjectNumber
 The Root object number counter.
 

Detailed Description

Implementation of the TVirtualMCStack interface.

Date
05/04/2002
Author
I. Hrivnacova; IPN, Orsay

Definition at line 32 of file Ex02MCStack.h.

Constructor & Destructor Documentation

◆ Ex02MCStack() [1/2]

Ex02MCStack::Ex02MCStack ( Int_t size)

Standard constructor

Parameters
sizeThe stack size

Definition at line 33 of file Ex02MCStack.cxx.

35{
36 /// Standard constructor
37 /// \param size The stack size
38
39 fParticles = new TObjArray(size);
40}
Int_t fCurrentTrack
The current track number.
Definition Ex02MCStack.h:65
Int_t fObjectNumber
The Root object number counter.
Definition Ex02MCStack.h:67
Int_t fNPrimary
The number of primaries.
Definition Ex02MCStack.h:66
TObjArray * fParticles
The array of particle (persistent)
Definition Ex02MCStack.h:64

◆ Ex02MCStack() [2/2]

Ex02MCStack::Ex02MCStack ( )

Default constructor

Definition at line 43 of file Ex02MCStack.cxx.

45{
46 /// Default constructor
47}

◆ ~Ex02MCStack()

Ex02MCStack::~Ex02MCStack ( )
virtual

Destructor

Definition at line 50 of file Ex02MCStack.cxx.

51{
52 /// Destructor
53
54 if (fParticles) fParticles->Delete();
55 delete fParticles;
56}

Member Function Documentation

◆ PushTrack()

void Ex02MCStack::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

Create a new particle and push into stack; adds it to the particles array (fParticles) and if not done to the stack (fStack).

Parameters
toBeDone1 if particles should go to tracking, 0 otherwise
parentnumber of the parent track, -1 if track is primary
pdgPDG encoding
pxparticle momentum - x component [GeV/c]
pyparticle momentum - y component [GeV/c]
pzparticle momentum - z component [GeV/c]
etotal energy [GeV]
vxposition - x component [cm]
vyposition - y component [cm]
vzposition - z component [cm]
toftime of flight [s]
polxpolarization - x component
polypolarization - y component
polzpolarization - z component
mechcreator process VMC code
ntrtrack number (is filled by the stack
weightparticle weight
isgeneration status code

Definition at line 63 of file Ex02MCStack.cxx.

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}
virtual Int_t GetNtrack() const
Ex02Particle * GetParticle(Int_t id) const
std::stack< Ex02Particle * > fStack
The stack of particles (transient)
Definition Ex02MCStack.h:63
Extended TParticle with pointers to mother and daughter particles.
void AddDaughter(Ex02Particle *particle)

◆ PopNextTrack()

TParticle * Ex02MCStack::PopNextTrack ( Int_t & track)
virtual

Get next particle for tracking from the stack.

Returns
The popped particle object
Parameters
trackThe index of the popped track

Definition at line 116 of file Ex02MCStack.cxx.

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}
Int_t GetID() const
TParticle * GetParticle() const

◆ PopPrimaryForTracking()

TParticle * Ex02MCStack::PopPrimaryForTracking ( Int_t i)
virtual

Return i -th particle in fParticles.

Returns
The popped primary particle object
Parameters
iThe index of primary particle to be popped

Definition at line 137 of file Ex02MCStack.cxx.

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}

◆ Print()

void Ex02MCStack::Print ( Option_t * option = "") const
virtual

Print info for all particles.

Definition at line 150 of file Ex02MCStack.cxx.

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}
virtual Int_t GetNprimary() const
virtual void Print(Option_t *option="") const

◆ Reset()

void Ex02MCStack::Reset ( )

Delete contained particles, reset particles array and stack.

Definition at line 165 of file Ex02MCStack.cxx.

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}

◆ SetCurrentTrack()

void Ex02MCStack::SetCurrentTrack ( Int_t track)
virtual

Set the current track number to a given value.

Parameters
trackThe current track number

Definition at line 183 of file Ex02MCStack.cxx.

184{
185 /// Set the current track number to a given value.
186 /// \param track The current track number
187
188 fCurrentTrack = track;
189}

◆ SetObjectNumber()

void Ex02MCStack::SetObjectNumber ( )

Set the current value of Root object counter into fObjectNumber. Tis value will be restored in Reset.

Definition at line 192 of file Ex02MCStack.cxx.

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}

◆ GetNtrack()

Int_t Ex02MCStack::GetNtrack ( ) const
virtual
Returns
The total number of all tracks.

Definition at line 201 of file Ex02MCStack.cxx.

202{
203 /// \return The total number of all tracks.
204
205 return fParticles->GetEntriesFast();
206}

◆ GetNprimary()

Int_t Ex02MCStack::GetNprimary ( ) const
virtual
Returns
The total number of primary tracks.

Definition at line 209 of file Ex02MCStack.cxx.

210{
211 /// \return The total number of primary tracks.
212
213 return fNPrimary;
214}

◆ GetCurrentTrack()

TParticle * Ex02MCStack::GetCurrentTrack ( ) const
virtual
Returns
The current track particle

Definition at line 217 of file Ex02MCStack.cxx.

218{
219 /// \return The current track particle
220
222
223 if (current)
224 return current->GetParticle();
225 else
226 return 0;
227}

◆ GetCurrentTrackNumber()

Int_t Ex02MCStack::GetCurrentTrackNumber ( ) const
virtual
Returns
The current track number

Definition at line 230 of file Ex02MCStack.cxx.

231{
232 /// \return The current track number
233
234 return fCurrentTrack;
235}

◆ GetCurrentParentTrackNumber()

Int_t Ex02MCStack::GetCurrentParentTrackNumber ( ) const
virtual
Returns
The current track parent ID.

Definition at line 238 of file Ex02MCStack.cxx.

239{
240 /// \return The current track parent ID.
241
243
244 if (!current) return -1;
245
246 Ex02Particle* mother = current->GetMother();
247
248 if (!mother) return -1;
249
250 return mother->GetID();
251}
Ex02Particle * GetMother() const

◆ GetParticle()

Ex02Particle * Ex02MCStack::GetParticle ( Int_t id) const
Returns
The id -th particle in fParticles
Parameters
idThe index of the particle to be returned

Definition at line 254 of file Ex02MCStack.cxx.

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}

Member Data Documentation

◆ fStack

std::stack<Ex02Particle*> Ex02MCStack::fStack
private

The stack of particles (transient)

Definition at line 63 of file Ex02MCStack.h.

◆ fParticles

TObjArray* Ex02MCStack::fParticles
private

The array of particle (persistent)

Definition at line 64 of file Ex02MCStack.h.

◆ fCurrentTrack

Int_t Ex02MCStack::fCurrentTrack
private

The current track number.

Definition at line 65 of file Ex02MCStack.h.

◆ fNPrimary

Int_t Ex02MCStack::fNPrimary
private

The number of primaries.

Definition at line 66 of file Ex02MCStack.h.

◆ fObjectNumber

Int_t Ex02MCStack::fObjectNumber
private

The Root object number counter.

Definition at line 67 of file Ex02MCStack.h.


The documentation for this class was generated from the following files: