VMC Version 2.0
Loading...
Searching...
No Matches
TMCManagerStack.cxx
Go to the documentation of this file.
1// -----------------------------------------------------------------------
2// Copyright (C) 2019 CERN and copyright holders of VMC Project.
3// This software is distributed under the terms of the GNU General Public
4// License v3 (GPL Version 3), copied verbatim in the file "LICENSE".
5//
6// See https://github.com/vmc-project/vmc for full licensing information.
7// -----------------------------------------------------------------------
8
9// Authors: Benedikt Volkel 07/03/2019
10
11/*************************************************************************
12 * Copyright (C) 2019, Rene Brun and Fons Rademakers. *
13 * Copyright (C) 2019, ALICE Experiment at CERN. *
14 * All rights reserved. *
15 * *
16 * For the licensing terms see $ROOTSYS/LICENSE. *
17 * For the list of contributors see $ROOTSYS/README/CREDITS. *
18 *************************************************************************/
19
20#include "TError.h"
21#include "TParticle.h"
22#include "TGeoBranchArray.h"
24#include "TMCParticleStatus.h"
25#include "TMCManagerStack.h"
26
37
39 : TVirtualMCStack(), fCurrentTrackId(-1), fUserStack(nullptr), fTotalNPrimaries(nullptr), fTotalNTracks(nullptr),
40 fParticles(nullptr), fParticlesStatus(nullptr), fBranchArrayContainer(nullptr)
41{
42}
43
48
49void TMCManagerStack::PushTrack(Int_t toBeDone, Int_t parent, Int_t pdg, Double_t px, Double_t py, Double_t pz,
50 Double_t e, Double_t vx, Double_t vy, Double_t vz, Double_t tof, Double_t polx,
51 Double_t poly, Double_t polz, TMCProcess mech, Int_t &ntr, Double_t weight, Int_t is)
52{
53 // Just forward to user stack
54 fUserStack->PushTrack(toBeDone, parent, pdg, px, py, pz, e, vx, vy, vz, tof, polx, poly, polz, mech, ntr, weight,
55 is);
56}
57
62
63TParticle *TMCManagerStack::PopNextTrack(Int_t &itrack)
64{
65
66 if (fPrimariesStack.empty() && fSecondariesStack.empty()) {
67 itrack = -1;
68 return nullptr;
69 }
70
71 std::stack<Int_t> *mcStack = &fPrimariesStack;
72
73 if (fPrimariesStack.empty()) {
74 mcStack = &fSecondariesStack;
75 }
76 itrack = mcStack->top();
77 mcStack->pop();
78 SetCurrentTrack(itrack);
79 return fParticles->operator[](itrack);
80}
81
86
88{
89 Int_t itrack = -1;
90 return PopPrimaryForTracking(i, itrack);
91}
92
98
99TParticle *TMCManagerStack::PopPrimaryForTracking(Int_t i, Int_t &itrack)
100{
101 // Completely ignore the index i, that is meaningless since the user does not
102 // know how the stack is handled internally.
103 Warning("PopPrimaryForTracking", "Lookup index %i is ignored.", i);
104 if (fPrimariesStack.empty()) {
105 itrack = -1;
106 return nullptr;
107 }
108 itrack = fPrimariesStack.top();
109 fPrimariesStack.pop();
110 return fParticles->operator[](itrack);
111}
112
117
119{
120 return *fTotalNTracks;
121}
122
127
129{
130 return fPrimariesStack.size() + fSecondariesStack.size();
131}
132
137
139{
140 return *fTotalNPrimaries;
141}
142
147
149{
150 return fPrimariesStack.size();
151}
152
157
159{
160 if (fCurrentTrackId < 0) {
161 Fatal("GetCurrentTrack", "There is no current track set");
162 }
163 // That is not actually the current track but the user's TParticle at the
164 // vertex.
165 return fParticles->operator[](fCurrentTrackId);
166}
167
172
174{
175 return fCurrentTrackId;
176}
177
182
184{
185 return fParticlesStatus->operator[](fCurrentTrackId)->fParentId;
186}
187
193
195{
196 if (!HasTrackId(trackId)) {
197 Fatal("SetCurrentTrack", "Invalid track ID %i", trackId);
198 }
199 fCurrentTrackId = trackId;
200 fUserStack->SetCurrentTrack(trackId);
201}
202
207
209{
210 if (!HasTrackId(trackId)) {
211 Fatal("GetParticleStatus", "Invalid track ID %i", trackId);
212 }
213 return fParticlesStatus->operator[](trackId).get();
214}
215
220
221const TGeoBranchArray *TMCManagerStack::GetGeoState(Int_t trackId) const
222{
223 if (!HasTrackId(trackId)) {
224 Fatal("GetParticleStatus", "Invalid track ID %i", trackId);
225 }
226 return fBranchArrayContainer->GetGeoState(fParticlesStatus->operator[](trackId)->fGeoStateIndex);
227}
228
233
234const TGeoBranchArray *TMCManagerStack::GetCurrentGeoState() const
235{
236 return fBranchArrayContainer->GetGeoState(fParticlesStatus->operator[](fCurrentTrackId)->fGeoStateIndex);
237}
238
243
244Bool_t TMCManagerStack::HasTrackId(Int_t trackId) const
245{
246 if (trackId >= 0 && trackId < static_cast<Int_t>(fParticles->size()) && fParticles->operator[](trackId)) {
247 return kTRUE;
248 }
249 return kFALSE;
250}
251
256
258{
259 fUserStack = stack;
260}
261
266
267void TMCManagerStack::ConnectTrackContainers(std::vector<TParticle *> *particles,
268 std::vector<std::unique_ptr<TMCParticleStatus>> *tracksStatus,
269 TGeoMCBranchArrayContainer *branchArrayContainer, Int_t *totalNPrimaries,
270 Int_t *totalNTracks)
271{
272 fParticles = particles;
273 fParticlesStatus = tracksStatus;
274 fBranchArrayContainer = branchArrayContainer;
275 fTotalNPrimaries = totalNPrimaries;
276 fTotalNTracks = totalNTracks;
277}
278
283
285{
286 fPrimariesStack.push(trackId);
287}
288
293
295{
296 fSecondariesStack.push(trackId);
297}
298
303
305{
306 // Reset current stack and track IDs
307 fCurrentTrackId = -1;
308 while (!fPrimariesStack.empty()) {
309 fPrimariesStack.pop();
310 }
311 while (!fSecondariesStack.empty()) {
312 fSecondariesStack.pop();
313 }
314}
TMCProcess
VMC physics process codes.
Definition: TMCProcess.h:30
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.
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;.