VMC Examples Version 6.8
Loading...
Searching...
No Matches
Ex03dMCStack Class Reference

Implementation of the TVirtualMCStack interface. More...

#include <Ex03dMCStack.h>

Inheritance diagram for Ex03dMCStack:

Public Member Functions

 Ex03dMCStack (Int_t size)
 Ex03dMCStack ()
virtual ~Ex03dMCStack ()
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 ()
void Register ()
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
std::vector< TParticle > * fParticles
 < The stack of particles (transient)
std::vector< Ex03dParticle > * fExParticles
 < The vector of particle (persistent)
Int_t fCurrentTrack { -1 }
 < The vector of particle (persistent)
Int_t fNPrimary { 0 }
 < The current track number

Detailed Description

Implementation of the TVirtualMCStack interface.

A variant of the Ex03MCStack class updated for RNTuple output.

Date
07/07/2026
Author
Radoslaw Karabowicz; GSI

Definition at line 37 of file Ex03dMCStack.h.

Constructor & Destructor Documentation

◆ Ex03dMCStack() [1/2]

Ex03dMCStack::Ex03dMCStack ( Int_t size)

Standard constructor

Parameters
sizeThe stack size

Definition at line 32 of file Ex03dMCStack.cxx.

33{
34 /// Standard constructor
35 /// \param size The stack size
36}

◆ Ex03dMCStack() [2/2]

Ex03dMCStack::Ex03dMCStack ( )

Default constructor

Definition at line 39 of file Ex03dMCStack.cxx.

40{
41 /// Default constructor
42}

◆ ~Ex03dMCStack()

Ex03dMCStack::~Ex03dMCStack ( )
virtual

Destructor

Definition at line 45 of file Ex03dMCStack.cxx.

46{
47 /// Destructor
48
49 delete fParticles;
50}
std::vector< TParticle > * fParticles
< The stack of particles (transient)

Member Function Documentation

◆ PushTrack()

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

Definition at line 61 of file Ex03dMCStack.cxx.

65{
66 /// Create a new particle and push into stack;
67 /// adds it to the particles array (fParticles) and if not done to the
68 /// stack (fStack).
69 /// Use TParticle::fMother[1] to store Track ID.
70 /// \param toBeDone 1 if particles should go to tracking, 0 otherwise
71 /// \param parent number of the parent track, -1 if track is primary
72 /// \param pdg PDG encoding
73 /// \param px particle momentum - x component [GeV/c]
74 /// \param py particle momentum - y component [GeV/c]
75 /// \param pz particle momentum - z component [GeV/c]
76 /// \param e total energy [GeV]
77 /// \param vx position - x component [cm]
78 /// \param vy position - y component [cm]
79 /// \param vz position - z component [cm]
80 /// \param tof time of flight [s]
81 /// \param polx polarization - x component
82 /// \param poly polarization - y component
83 /// \param polz polarization - z component
84 /// \param mech creator process VMC code
85 /// \param ntr track number (is filled by the stack
86 /// \param weight particle weight
87 /// \param is generation status code
88
89 const Int_t kFirstDaughter = -1;
90 const Int_t kLastDaughter = -1;
91
92 Int_t trackId = GetNtrack();
93 fParticles->push_back(TParticle(pdg, is, parent, trackId, kFirstDaughter,
94 kLastDaughter, px, py, pz, e, vx, vy, vz, tof));
95 auto particle = &fParticles->back();
96
97 particle->SetPolarisation(polx, poly, polz);
98 particle->SetWeight(weight);
99 particle->SetUniqueID(mech);
100
101 fExParticles->push_back(Ex03dParticle(pdg, is, parent, trackId,
102 kFirstDaughter, kLastDaughter, px, py, pz, e, vx, vy, vz, tof));
103 auto exParticle = &fExParticles->back();
104
105 exParticle->SetPolarisation(polx, poly, polz);
106 exParticle->SetWeight(weight);
107
108 if (parent < 0) fNPrimary++;
109
110 if (toBeDone) fStack.push(particle);
111
112 ntr = GetNtrack() - 1;
113}
virtual Int_t GetNtrack() const
std::vector< Ex03dParticle > * fExParticles
< The vector of particle (persistent)
Int_t fNPrimary
< The current track number
std::stack< TParticle * > fStack

◆ PopNextTrack()

TParticle * Ex03dMCStack::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 Ex03dMCStack.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 TParticle* particle = fStack.top();
126 fStack.pop();
127
128 if (!particle) return 0;
129
130 fCurrentTrack = particle->GetSecondMother();
131 itrack = fCurrentTrack;
132
133 return particle;
134}
Int_t fCurrentTrack
< The vector of particle (persistent)

◆ PopPrimaryForTracking()

TParticle * Ex03dMCStack::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 Ex03dMCStack.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 &(*fParticles)[i];
147}

◆ Print()

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

Print info for all particles.

Definition at line 150 of file Ex03dMCStack.cxx.

151{
152 /// Print info for all particles.
153
154 cout << "Ex03dMCStack 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++) GetParticle(i)->Print();
159}
virtual Int_t GetNprimary() const
TParticle * GetParticle(Int_t id) const

◆ Reset()

void Ex03dMCStack::Reset ( )

Delete contained particles, reset particles array and stack.

Definition at line 162 of file Ex03dMCStack.cxx.

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

◆ Register()

void Ex03dMCStack::Register ( )

Definition at line 55 of file Ex03dMCStack.cxx.

56{
57 TMCRootManager::Instance()->Register("particles", fExParticles);
58}

◆ SetCurrentTrack()

void Ex03dMCStack::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 Ex03dMCStack.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 Ex03dMCStack::GetNtrack ( ) const
virtual
Returns
The total number of all tracks.

Definition at line 182 of file Ex03dMCStack.cxx.

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

◆ GetNprimary()

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

Definition at line 189 of file Ex03dMCStack.cxx.

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

◆ GetCurrentTrack()

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

Definition at line 197 of file Ex03dMCStack.cxx.

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

◆ GetCurrentTrackNumber()

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

Definition at line 210 of file Ex03dMCStack.cxx.

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

◆ GetCurrentParentTrackNumber()

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

Definition at line 218 of file Ex03dMCStack.cxx.

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

◆ GetParticle()

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

Definition at line 231 of file Ex03dMCStack.cxx.

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

Member Data Documentation

◆ fStack

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

Definition at line 69 of file Ex03dMCStack.h.

◆ fParticles

std::vector<TParticle>* Ex03dMCStack::fParticles
private
Initial value:
{
new std::vector<TParticle>
}

< The stack of particles (transient)

Definition at line 70 of file Ex03dMCStack.h.

70 {
71 new std::vector<TParticle>
72 }; //! < The vector of particle (persistent)

◆ fExParticles

std::vector<Ex03dParticle>* Ex03dMCStack::fExParticles
private
Initial value:
{
new std::vector<Ex03dParticle>
}

< The vector of particle (persistent)

Definition at line 75 of file Ex03dMCStack.h.

75 {
76 new std::vector<Ex03dParticle>
77 }; //! < The vector of particle (persistent)

◆ fCurrentTrack

Int_t Ex03dMCStack::fCurrentTrack { -1 }
private

< The vector of particle (persistent)

Definition at line 78 of file Ex03dMCStack.h.

78{ -1 }; /// < The current track number

◆ fNPrimary

Int_t Ex03dMCStack::fNPrimary { 0 }
private

< The current track number

Definition at line 79 of file Ex03dMCStack.h.

79{ 0 }; /// < The number of primaries

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