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

Implementation of the TVirtualMCStack interface. More...

#include <Ex03cMCStack.h>

Inheritance diagram for Ex03cMCStack:

Public Member Functions

 Ex03cMCStack (Int_t size)
 
 Ex03cMCStack ()
 
virtual ~Ex03cMCStack ()
 
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)
 
virtual Int_t GetNtrack () const
 
virtual Int_t GetNprimary () const
 
virtual TParticle * GetCurrentTrack () const
 
virtual Int_t GetCurrentTrackNumber () const
 
virtual Int_t GetCurrentParentTrackNumber () const
 
TParticle * GetParticle (Int_t id) const
 

Private Attributes

std::stack< TParticle * > fStack
 The stack of particles (transient)
 
TClonesArray * fParticles
 The array of particle (persistent)
 
Int_t fCurrentTrack
 The current track number.
 
Int_t fNPrimary
 The number of primaries.
 

Detailed Description

Implementation of the TVirtualMCStack interface.

A variant of the Ex03CalorimeterSD class updated for multiple engine runs.

Date
21/08/2019
Author
Benedikt Volkel, CERN

Definition at line 36 of file Ex03cMCStack.h.

Constructor & Destructor Documentation

◆ Ex03cMCStack() [1/2]

Ex03cMCStack::Ex03cMCStack ( Int_t size)

Standard constructor

Parameters
sizeThe stack size

Definition at line 34 of file Ex03cMCStack.cxx.

36{
37 /// Standard constructor
38 /// \param size The stack size
39
40 fParticles = new TClonesArray("TParticle", size);
41}
TClonesArray * fParticles
The array of particle (persistent)
Int_t fCurrentTrack
The current track number.
Int_t fNPrimary
The number of primaries.

◆ Ex03cMCStack() [2/2]

Ex03cMCStack::Ex03cMCStack ( )

Default constructor

Definition at line 44 of file Ex03cMCStack.cxx.

45{
46 /// Default constructor
47}

◆ ~Ex03cMCStack()

Ex03cMCStack::~Ex03cMCStack ( )
virtual

Destructor

Definition at line 50 of file Ex03cMCStack.cxx.

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

Member Function Documentation

◆ PushTrack()

void Ex03cMCStack::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). Use TParticle::fMother[1] to store Track ID.

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

Forward to the TMCManager in case of multi-run

Definition at line 63 of file Ex03cMCStack.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 /// Use TParticle::fMother[1] to store Track ID.
72 /// \param toBeDone 1 if particles should go to tracking, 0 otherwise
73 /// \param parent number of the parent track, -1 if track is primary
74 /// \param pdg PDG encoding
75 /// \param px particle momentum - x component [GeV/c]
76 /// \param py particle momentum - y component [GeV/c]
77 /// \param pz particle momentum - z component [GeV/c]
78 /// \param e total energy [GeV]
79 /// \param vx position - x component [cm]
80 /// \param vy position - y component [cm]
81 /// \param vz position - z component [cm]
82 /// \param tof time of flight [s]
83 /// \param polx polarization - x component
84 /// \param poly polarization - y component
85 /// \param polz polarization - z component
86 /// \param mech creator process VMC code
87 /// \param ntr track number (is filled by the stack
88 /// \param weight particle weight
89 /// \param is generation status code
90
91 const Int_t kFirstDaughter = -1;
92 const Int_t kLastDaughter = -1;
93
94 TClonesArray& particlesRef = *fParticles;
95 Int_t trackId = GetNtrack();
96 TParticle* particle = new (particlesRef[trackId]) TParticle(pdg, is, parent,
97 trackId, kFirstDaughter, kLastDaughter, px, py, pz, e, vx, vy, vz, tof);
98
99 particle->SetPolarisation(polx, poly, polz);
100 particle->SetWeight(weight);
101 particle->SetUniqueID(mech);
102
103 if (parent < 0) fNPrimary++;
104
105 if (toBeDone) fStack.push(particle);
106
107 ntr = GetNtrack() - 1;
108
109 /// Forward to the TMCManager in case of multi-run
110 TMCManager* mgr = TMCManager::Instance();
111 if (mgr) {
112 mgr->ForwardTrack(toBeDone, ntr, parent, particle);
113 }
114}
std::stack< TParticle * > fStack
The stack of particles (transient)
virtual Int_t GetNtrack() const

◆ PopNextTrack()

TParticle * Ex03cMCStack::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 117 of file Ex03cMCStack.cxx.

118{
119 /// Get next particle for tracking from the stack.
120 /// \return The popped particle object
121 /// \param track The index of the popped track
122
123 itrack = -1;
124 if (fStack.empty()) return 0;
125
126 TParticle* particle = fStack.top();
127 fStack.pop();
128
129 if (!particle) return 0;
130
131 fCurrentTrack = particle->GetSecondMother();
132 itrack = fCurrentTrack;
133
134 return particle;
135}

◆ PopPrimaryForTracking()

TParticle * Ex03cMCStack::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 138 of file Ex03cMCStack.cxx.

139{
140 /// Return \em i -th particle in fParticles.
141 /// \return The popped primary particle object
142 /// \param i The index of primary particle to be popped
143
144 if (i < 0 || i >= fNPrimary)
145 Fatal("GetPrimaryForTracking", "Index out of range");
146
147 return (TParticle*)fParticles->At(i);
148}

◆ Print()

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

Print info for all particles.

Definition at line 151 of file Ex03cMCStack.cxx.

152{
153 /// Print info for all particles.
154
155 cout << "Ex03cMCStack Info " << endl;
156 cout << "Total number of particles: " << GetNtrack() << endl;
157 cout << "Number of primary particles: " << GetNprimary() << endl;
158
159 for (Int_t i = 0; i < GetNtrack(); i++) GetParticle(i)->Print();
160}
TParticle * GetParticle(Int_t id) const
virtual Int_t GetNprimary() const

◆ Reset()

void Ex03cMCStack::Reset ( )

Delete contained particles, reset particles array and stack.

Definition at line 163 of file Ex03cMCStack.cxx.

164{
165 /// Delete contained particles, reset particles array and stack.
166
167 fCurrentTrack = -1;
168 fNPrimary = 0;
169 fParticles->Clear();
170}

◆ SetCurrentTrack()

void Ex03cMCStack::SetCurrentTrack ( Int_t track)
virtual

Set the current track number to a given value.

Parameters
trackThe current track number

Definition at line 173 of file Ex03cMCStack.cxx.

174{
175 /// Set the current track number to a given value.
176 /// \param track The current track number
177
178 fCurrentTrack = track;
179}

◆ GetNtrack()

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

Definition at line 182 of file Ex03cMCStack.cxx.

183{
184 /// \return The total number of all tracks.
185
186 return fParticles->GetEntriesFast();
187}

◆ GetNprimary()

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

Definition at line 190 of file Ex03cMCStack.cxx.

191{
192 /// \return The total number of primary tracks.
193
194 return fNPrimary;
195}

◆ GetCurrentTrack()

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

Definition at line 198 of file Ex03cMCStack.cxx.

199{
200 /// \return The current track particle
201
202 TParticle* current = GetParticle(fCurrentTrack);
203
204 if (!current)
205 Warning("GetCurrentTrack", "Current track not found in the stack");
206
207 return current;
208}

◆ GetCurrentTrackNumber()

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

Definition at line 211 of file Ex03cMCStack.cxx.

212{
213 /// \return The current track number
214
215 return fCurrentTrack;
216}

◆ GetCurrentParentTrackNumber()

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

Definition at line 219 of file Ex03cMCStack.cxx.

220{
221 /// \return The current track parent ID.
222
223 TParticle* current = GetCurrentTrack();
224
225 if (current)
226 return current->GetFirstMother();
227 else
228 return -1;
229}
virtual TParticle * GetCurrentTrack() const

◆ GetParticle()

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

Definition at line 232 of file Ex03cMCStack.cxx.

233{
234 /// \return The \em id -th particle in fParticles
235 /// \param id The index of the particle to be returned
236
237 if (id < 0 || id >= fParticles->GetEntriesFast())
238 Fatal("GetParticle", "Index out of range");
239
240 return (TParticle*)fParticles->At(id);
241}

Member Data Documentation

◆ fStack

std::stack<TParticle*> Ex03cMCStack::fStack
private

The stack of particles (transient)

Definition at line 66 of file Ex03cMCStack.h.

◆ fParticles

TClonesArray* Ex03cMCStack::fParticles
private

The array of particle (persistent)

Definition at line 67 of file Ex03cMCStack.h.

◆ fCurrentTrack

Int_t Ex03cMCStack::fCurrentTrack
private

The current track number.

Definition at line 68 of file Ex03cMCStack.h.

◆ fNPrimary

Int_t Ex03cMCStack::fNPrimary
private

The number of primaries.

Definition at line 69 of file Ex03cMCStack.h.


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