Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMCManagerStack.cxx
Go to the documentation of this file.
1// @(#)root/vmc:$Id$
2// Authors: Benedikt Volkel 07/03/2019
3
4/*************************************************************************
5 * Copyright (C) 2019, Rene Brun and Fons Rademakers. *
6 * Copyright (C) 2019, ALICE Experiment at CERN. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include "TError.h"
14#include "TParticle.h"
15#include "TGeoBranchArray.h"
17#include "TMCParticleStatus.h"
18#include "TMCManagerStack.h"
19
20/** \class TMCManagerStack
21 \ingroup vmc
22
23Concrete implementation of particles stack used by the TMCManager.
24*/
25
26////////////////////////////////////////////////////////////////////////////////
27///
28/// Default constructor
29///
30
32 : TVirtualMCStack(), fCurrentTrackId(-1), fUserStack(nullptr), fTotalNPrimaries(nullptr), fTotalNTracks(nullptr),
33 fParticles(nullptr), fParticlesStatus(nullptr), fBranchArrayContainer(nullptr)
34{
35}
36
37////////////////////////////////////////////////////////////////////////////////
38///
39/// This will just forward the call to the fUserStack's PushTrack
40///
41
42void TMCManagerStack::PushTrack(Int_t toBeDone, Int_t parent, Int_t pdg, Double_t px, Double_t py, Double_t pz,
43 Double_t e, Double_t vx, Double_t vy, Double_t vz, Double_t tof, Double_t polx,
44 Double_t poly, Double_t polz, TMCProcess mech, Int_t &ntr, Double_t weight, Int_t is)
45{
46 // Just forward to user stack
47 fUserStack->PushTrack(toBeDone, parent, pdg, px, py, pz, e, vx, vy, vz, tof, polx, poly, polz, mech, ntr, weight,
48 is);
49}
50
51////////////////////////////////////////////////////////////////////////////////
52///
53/// Pop next track
54///
55
57{
58
59 if (fPrimariesStack.empty() && fSecondariesStack.empty()) {
60 itrack = -1;
61 return nullptr;
62 }
63
64 std::stack<Int_t> *mcStack = &fPrimariesStack;
65
66 if (fPrimariesStack.empty()) {
67 mcStack = &fSecondariesStack;
68 }
69 itrack = mcStack->top();
70 mcStack->pop();
71 SetCurrentTrack(itrack);
72 return fParticles->operator[](itrack);
73}
74
75////////////////////////////////////////////////////////////////////////////////
76///
77/// Pop i'th primary; that does not mean that this primariy has ID==i
78///
79
81{
82 Int_t itrack = -1;
83 return PopPrimaryForTracking(i, itrack);
84}
85
86////////////////////////////////////////////////////////////////////////////////
87///
88/// Pop i'th primary; that does not mean that this primariy has ID==i.
89/// including actual index
90///
91
93{
94 // Completely ignore the index i, that is meaningless since the user does not
95 // know how the stack is handled internally.
96 Warning("PopPrimaryForTracking", "Lookup index %i is ignored.", i);
97 if (fPrimariesStack.empty()) {
98 itrack = -1;
99 return nullptr;
100 }
101 itrack = fPrimariesStack.top();
102 fPrimariesStack.pop();
103 return fParticles->operator[](itrack);
104}
105
106////////////////////////////////////////////////////////////////////////////////
107///
108/// Get number of tracks on current sub-stack
109///
110
112{
113 return *fTotalNTracks;
114}
115
116////////////////////////////////////////////////////////////////////////////////
117///
118/// Get only the number of currently stacked tracks
119///
120
122{
123 return fPrimariesStack.size() + fSecondariesStack.size();
124}
125
126////////////////////////////////////////////////////////////////////////////////
127///
128/// Get number of primaries on current sub-stack
129///
130
132{
133 return *fTotalNPrimaries;
134}
135
136////////////////////////////////////////////////////////////////////////////////
137///
138/// Get number of primaries on current sub-stack
139///
140
142{
143 return fPrimariesStack.size();
144}
145
146////////////////////////////////////////////////////////////////////////////////
147///
148/// Current track
149///
150
152{
153 if (fCurrentTrackId < 0) {
154 Fatal("GetCurrentTrack", "There is no current track set");
155 }
156 // That is not actually the current track but the user's TParticle at the
157 // vertex.
158 return fParticles->operator[](fCurrentTrackId);
159}
160
161////////////////////////////////////////////////////////////////////////////////
162///
163/// Current track number
164///
165
167{
168 return fCurrentTrackId;
169}
170
171////////////////////////////////////////////////////////////////////////////////
172///
173/// Number of the parent of the current track
174///
175
177{
178 return fParticlesStatus->operator[](fCurrentTrackId)->fParentId;
179}
180
181////////////////////////////////////////////////////////////////////////////////
182///
183/// Set the current track id from the outside and forward this to the
184/// user's stack
185///
186
188{
189 if (!HasTrackId(trackId)) {
190 Fatal("SetCurrentTrack", "Invalid track ID %i", trackId);
191 }
192 fCurrentTrackId = trackId;
193 fUserStack->SetCurrentTrack(trackId);
194}
195
196////////////////////////////////////////////////////////////////////////////////
197///
198/// Get TMCParticleStatus by trackId
199///
200
202{
203 if (!HasTrackId(trackId)) {
204 Fatal("GetParticleStatus", "Invalid track ID %i", trackId);
205 }
206 return fParticlesStatus->operator[](trackId).get();
207}
208
209////////////////////////////////////////////////////////////////////////////////
210///
211/// Get particle's geometry status by trackId
212///
213
215{
216 if (!HasTrackId(trackId)) {
217 Fatal("GetParticleStatus", "Invalid track ID %i", trackId);
218 }
219 return fBranchArrayContainer->GetGeoState(fParticlesStatus->operator[](trackId)->fGeoStateIndex);
220}
221
222////////////////////////////////////////////////////////////////////////////////
223///
224/// Get current particle's geometry status
225///
226
228{
229 return fBranchArrayContainer->GetGeoState(fParticlesStatus->operator[](fCurrentTrackId)->fGeoStateIndex);
230}
231
232////////////////////////////////////////////////////////////////////////////////
233///
234/// Check whether track trackId exists
235///
236
238{
239 if (trackId >= 0 && trackId < static_cast<Int_t>(fParticles->size()) && fParticles->operator[](trackId)) {
240 return kTRUE;
241 }
242 return kFALSE;
243}
244
245////////////////////////////////////////////////////////////////////////////////
246///
247/// Set the user stack
248///
249
251{
252 fUserStack = stack;
253}
254
255////////////////////////////////////////////////////////////////////////////////
256///
257/// Connect an engine's stack to the centrally managed vectors
258///
259
260void TMCManagerStack::ConnectTrackContainers(std::vector<TParticle *> *particles,
261 std::vector<std::unique_ptr<TMCParticleStatus>> *tracksStatus,
262 TGeoMCBranchArrayContainer *branchArrayContainer, Int_t *totalNPrimaries,
263 Int_t *totalNTracks)
264{
265 fParticles = particles;
266 fParticlesStatus = tracksStatus;
267 fBranchArrayContainer = branchArrayContainer;
268 fTotalNPrimaries = totalNPrimaries;
269 fTotalNTracks = totalNTracks;
270}
271
272////////////////////////////////////////////////////////////////////////////////
273///
274/// Push primary track id to be processed
275///
276
278{
279 fPrimariesStack.push(trackId);
280}
281
282////////////////////////////////////////////////////////////////////////////////
283///
284/// Push secondary track id to be processed
285///
286
288{
289 fSecondariesStack.push(trackId);
290}
291
292////////////////////////////////////////////////////////////////////////////////
293///
294/// Reset internals, clear engine stack and fParticles and reset buffered values
295///
296
298{
299 // Reset current stack and track IDs
300 fCurrentTrackId = -1;
301 while (!fPrimariesStack.empty()) {
302 fPrimariesStack.pop();
303 }
304 while (!fSecondariesStack.empty()) {
305 fSecondariesStack.pop();
306 }
307}
#define e(i)
Definition RSha256.hxx:103
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
TMCProcess
VMC physics process codes.
Definition TMCProcess.h:24
An array of daughter indices making a geometry path.
Storing and re-using geometry states of the TGeoManager in use by storing them as TGeoBranchArrays.
const TGeoBranchArray * GetGeoState(UInt_t userIndex)
Get a TGeoBranchArray to read the current state from.
Bool_t HasTrackId(Int_t trackId) const
Check whether track trackId exists.
void ResetInternals()
Reset internals, clear engine stack and fParticles and reset buffered values.
TParticle * PopPrimaryForTracking(Int_t i) override final
Pop i'th primar, that does not mean that this primariy also has ID==i.
Int_t * fTotalNTracks
Number of all tracks ever pushed linked from the TMCManager.
Int_t GetNtrack() const override final
Get number of tracks on current sub-stack.
std::vector< TParticle * > * fParticles
All tracks linked from the TMCManager.
void SetCurrentTrack(Int_t trackId) override final
Set the current track id from the outside and forward this to the user's stack.
TParticle * PopNextTrack(Int_t &itrack) override final
Pop next track.
Int_t GetStackedNtrack() const
Get only the number of currently stacked tracks.
void PushPrimaryTrackId(Int_t trackId)
Push primary id to be processed.
std::vector< std::unique_ptr< TMCParticleStatus > > * fParticlesStatus
All TMCParticleStatus linked from the TMCManager.
Int_t GetNprimary() const override final
Get number of primaries on current sub-stack.
std::stack< Int_t > fSecondariesStack
IDs of secondaries to be trackedk.
TVirtualMCStack * fUserStack
Pointer to user stack for forwarding PushTrack calls.
TParticle * GetCurrentTrack() const override final
Current track.
void PushSecondaryTrackId(Int_t trackId)
Push secondary id to be processed.
Int_t * fTotalNPrimaries
Number of all primaries ever pushed linked from the TMCManager.
Int_t GetCurrentTrackNumber() const override final
Current track number.
std::stack< Int_t > fPrimariesStack
IDs of primaries to be tracked.
const TGeoBranchArray * GetGeoState(Int_t trackId) const
Get particle's geometry status by trackId.
TGeoMCBranchArrayContainer * fBranchArrayContainer
Storage of TGeoBranchArray pointers.
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) override final
This will just forward the call to the fUserStack's PushTrack.
TMCManagerStack()
Default constructor.
Int_t GetCurrentParentTrackNumber() const override final
Number of the parent of the current track.
const TMCParticleStatus * GetParticleStatus(Int_t trackId) const
Get TMCParticleStatus by trackId.
Int_t fCurrentTrackId
Pointer to current track.
Int_t GetStackedNprimary() const
Get only the number of currently stacked primaries.
void ConnectTrackContainers(std::vector< TParticle * > *particles, std::vector< std::unique_ptr< TMCParticleStatus > > *tracksStatus, TGeoMCBranchArrayContainer *branchArrayContainer, Int_t *totalNPrimaries, Int_t *totalNTracks)
Set the pointer to vector with all particles and status.
void SetUserStack(TVirtualMCStack *stack)
Set the user stack.
const TGeoBranchArray * GetCurrentGeoState() const
Get current particle's geometry status.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:879
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:921
Description of the dynamic properties of a particle.
Definition TParticle.h:26
Interface to a user defined particles stack.
virtual void SetCurrentTrack(Int_t trackNumber)=0
Set the current track number.
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)=0
Create a new particle and push into stack;.