VMC Examples Version 6.6
Loading...
Searching...
No Matches
Ex01MCStack.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 Ex01MCStack.cxx
11/// \brief Implementation of the Ex01MCStack class
12///
13/// Geant4 ExampleN01 adapted to Virtual Monte Carlo
14///
15/// \date 05/04/2002
16/// \author I. Hrivnacova; IPN, Orsay
17
18#include "Ex01MCStack.h"
19
20#include <TError.h>
21#include <TObjArray.h>
22#include <TParticle.h>
23
24/// \cond CLASSIMP
25ClassImp(Ex01MCStack)
26 /// \endcond
27
28 //_____________________________________________________________________________
30 : fParticles(0), fCurrentTrack(-1), fNPrimary(0)
31{
32 /// Standard constructor
33 /// \param size The stack size
34
35 fParticles = new TObjArray(size);
36}
37
38//_____________________________________________________________________________
39Ex01MCStack::Ex01MCStack() : fParticles(0), fCurrentTrack(-1), fNPrimary(0)
40{
41 /// Default constructor
42}
43
44//_____________________________________________________________________________
46{
47 /// Destructor
48
49 if (fParticles) fParticles->Delete();
50 delete fParticles;
51}
52
53// private methods
54
55//_____________________________________________________________________________
57{
58 /// \return The \em id -th particle in fParticles
59 /// \param id The index of the particle to be returned
60
61 if (id < 0 || id >= fParticles->GetEntriesFast())
62 Fatal("GetParticle", "Index out of range");
63
64 return (Ex01Particle*)fParticles->At(id);
65}
66
67// public methods
68
69//_____________________________________________________________________________
70void Ex01MCStack::PushTrack(Int_t toBeDone, Int_t parent, Int_t pdg,
71 Double_t px, Double_t py, Double_t pz, Double_t e, Double_t vx, Double_t vy,
72 Double_t vz, Double_t tof, Double_t polx, Double_t poly, Double_t polz,
73 TMCProcess mech, Int_t& ntr, Double_t weight, Int_t is)
74{
75 /// Create a new particle and push into stack;
76 /// adds it to the particles array (fParticles) and if not done to the
77 /// stack (fStack).
78 /// \param toBeDone 1 if particles should go to tracking, 0 otherwise
79 /// \param parent number of the parent track, -1 if track is primary
80 /// \param pdg PDG encoding
81 /// \param px particle momentum - x component [GeV/c]
82 /// \param py particle momentum - y component [GeV/c]
83 /// \param pz particle momentum - z component [GeV/c]
84 /// \param e total energy [GeV]
85 /// \param vx position - x component [cm]
86 /// \param vy position - y component [cm]
87 /// \param vz position - z component [cm]
88 /// \param tof time of flight [s]
89 /// \param polx polarization - x component
90 /// \param poly polarization - y component
91 /// \param polz polarization - z component
92 /// \param mech creator process VMC code
93 /// \param ntr track number (is filled by the stack
94 /// \param weight particle weight
95 /// \param is generation status code
96
97 const Int_t kFirstDaughter = -1;
98 const Int_t kLastDaughter = -1;
99
100 TParticle* particleDef = new TParticle(pdg, is, parent, -1, kFirstDaughter,
101 kLastDaughter, px, py, pz, e, vx, vy, vz, tof);
102
103 particleDef->SetPolarisation(polx, poly, polz);
104 particleDef->SetWeight(weight);
105 particleDef->SetUniqueID(mech);
106
107 Ex01Particle* mother = 0;
108 if (parent >= 0)
109 mother = GetParticle(parent);
110 else
111 fNPrimary++;
112
113 Ex01Particle* particle = new Ex01Particle(GetNtrack(), particleDef, mother);
114
115 fParticles->Add(particle);
116
117 if (toBeDone) fStack.push(particle);
118
119 ntr = GetNtrack() - 1;
120}
121
122//_____________________________________________________________________________
123TParticle* Ex01MCStack::PopNextTrack(Int_t& itrack)
124{
125 /// Get next particle for tracking from the stack.
126 /// \return The popped particle object
127 /// \param itrack The index of the popped track
128
129 itrack = -1;
130 if (fStack.empty()) return 0;
131
132 Ex01Particle* particle = fStack.top();
133 fStack.pop();
134
135 if (!particle) return 0;
136
137 itrack = particle->GetID();
138 fCurrentTrack = itrack;
139
140 return particle->GetParticle();
141}
142
143//_____________________________________________________________________________
145{
146 /// Return \em i -th particle in fParticles.
147 /// \return The popped primary particle object
148 /// \param i The index of primary particle to be popped
149
150 if (i < 0 || i >= fNPrimary)
151 Fatal("GetPrimaryForTracking", "Index out of range");
152
153 return ((Ex01Particle*)fParticles->At(i))->GetParticle();
154}
155
156//_____________________________________________________________________________
158{
159 /// Set the current track number to a given value.
160 /// \param itrack The current track number
161
162 fCurrentTrack = itrack;
163}
164
165//_____________________________________________________________________________
167{
168 /// \return The total number of all tracks.
169
170 return fParticles->GetEntriesFast();
171}
172
173//_____________________________________________________________________________
175{
176 /// \return The total number of primary tracks.
177
178 return fNPrimary;
179}
180
181//_____________________________________________________________________________
183{
184 /// \return The current track particle
185
187
188 if (current)
189 return current->GetParticle();
190 else
191 return 0;
192}
193
194//_____________________________________________________________________________
196{
197 /// \return The current track number
198
199 return fCurrentTrack;
200}
201//_____________________________________________________________________________
203{
204 /// \return The current track parent ID.
205
207
208 if (!current) return -1;
209
210 Ex01Particle* mother = current->GetMother();
211
212 if (!mother) return -1;
213
214 return mother->GetID();
215}
Definition of the Ex01MCStack class.
Implementation of the TVirtualMCStack interface.
Definition Ex01MCStack.h:33
virtual TParticle * PopPrimaryForTracking(Int_t i)
virtual void SetCurrentTrack(Int_t itrack)
virtual Int_t GetCurrentTrackNumber() const
TObjArray * fParticles
The array of particle (persistent)
Definition Ex01MCStack.h:63
virtual Int_t GetNtrack() const
Int_t fNPrimary
The number of primaries.
Definition Ex01MCStack.h:65
Ex01Particle * GetParticle(Int_t id) const
Int_t fCurrentTrack
The current track number.
Definition Ex01MCStack.h:64
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)
std::stack< Ex01Particle * > fStack
The stack of particles (transient)
Definition Ex01MCStack.h:62
virtual Int_t GetCurrentParentTrackNumber() const
virtual TParticle * GetCurrentTrack() const
virtual Int_t GetNprimary() const
virtual TParticle * PopNextTrack(Int_t &itrack)
virtual ~Ex01MCStack()
Extended TParticle with pointers to mother and daughter particles.
Ex01Particle * GetMother() const
Int_t GetID() const
TParticle * GetParticle() const