Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TMCManagerStack.h
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 #ifndef ROOT_TMCManagerStack
14 #define ROOT_TMCManagerStack
15 
16 // Class TMCManagerStack
17 // ---------------------
18 // stack used by the TMCManager when handling multiple engines
19 //
20 
21 #include <vector>
22 #include <stack>
23 #include <memory>
24 
25 #include "TMCtls.h"
26 #include "TLorentzVector.h"
27 #include "TMCProcess.h"
28 
29 #include "TVirtualMCStack.h"
30 
31 struct TMCParticleStatus;
32 class TGeoBranchArray;
33 class TGeoMCBranchArrayContainer;
34 
35 class TMCManagerStack : public TVirtualMCStack {
36 
37 public:
38  /// Default constructor
39  TMCManagerStack();
40  /// Destructor
41  virtual ~TMCManagerStack() = default;
42 
43  //
44  // Methods for stacking
45  //
46 
47  /// This will just forward the call to the fUserStack's PushTrack
48  ///
49  /// Create a new particle and push into stack;
50  /// - toBeDone - 1 if particles should go to tracking, 0 otherwise
51  /// - parent - number of the parent track, -1 if track is primary
52  /// - pdg - PDG encoding
53  /// - px, py, pz - particle momentum [GeV/c]
54  /// - e - total energy [GeV]
55  /// - vx, vy, vz - position [cm]
56  /// - tof - time of flight [s]
57  /// - polx, poly, polz - polarization
58  /// - mech - creator process VMC code
59  /// - ntr - track number (is filled by the stack
60  /// - weight - particle weight
61  /// - is - generation status code
62  void PushTrack(Int_t toBeDone, Int_t parent, Int_t pdg, Double_t px, Double_t py, Double_t pz, Double_t e,
63  Double_t vx, Double_t vy, Double_t vz, Double_t tof, Double_t polx, Double_t poly, Double_t polz,
64  TMCProcess mech, Int_t &ntr, Double_t weight, Int_t is) override final;
65 
66  //
67  // Get methods
68  //
69 
70  /// Pop next track
71  TParticle *PopNextTrack(Int_t &itrack) override final;
72 
73  /// Pop i'th primar, that does not mean that this primariy also has ID==i
74  TParticle *PopPrimaryForTracking(Int_t i) override final;
75 
76  /// Pop i'th primary, that does not mean that this primariy also has ID==i.
77  /// including actual index
78  TParticle *PopPrimaryForTracking(Int_t i, Int_t &itrack);
79 
80  /// Get number of tracks on current sub-stack
81  Int_t GetNtrack() const override final;
82 
83  /// Get only the number of currently stacked tracks
84  Int_t GetStackedNtrack() const;
85 
86  /// Get number of primaries on current sub-stack
87  Int_t GetNprimary() const override final;
88 
89  /// Get only the number of currently stacked primaries
90  Int_t GetStackedNprimary() const;
91 
92  /// Current track
93  TParticle *GetCurrentTrack() const override final;
94 
95  /// Current track number
96  Int_t GetCurrentTrackNumber() const override final;
97 
98  /// Number of the parent of the current track
99  Int_t GetCurrentParentTrackNumber() const override final;
100 
101  /// Set the current track id from the outside and forward this to the
102  /// user's stack
103  void SetCurrentTrack(Int_t trackId) override final;
104 
105  /// Get TMCParticleStatus by trackId
106  const TMCParticleStatus *GetParticleStatus(Int_t trackId) const;
107 
108  /// Get particle's geometry status by trackId
109  const TGeoBranchArray *GetGeoState(Int_t trackId) const;
110 
111  /// Get current particle's geometry status
112  const TGeoBranchArray *GetCurrentGeoState() const;
113 
114 private:
115  friend class TMCManager;
116  /// Check whether track trackId exists
117  Bool_t HasTrackId(Int_t trackId) const;
118  /// Set the user stack
119  void SetUserStack(TVirtualMCStack *stack);
120  /// Set the pointer to vector with all particles and status
121  void ConnectTrackContainers(std::vector<TParticle *> *particles,
122  std::vector<std::unique_ptr<TMCParticleStatus>> *tracksStatus,
123  TGeoMCBranchArrayContainer *branchArrayContainer, Int_t *totalNPrimaries,
124  Int_t *totalNTracks);
125  /// Push primary id to be processed
126  void PushPrimaryTrackId(Int_t trackId);
127  /// Push secondary id to be processed
128  void PushSecondaryTrackId(Int_t trackId);
129  /// Reset internals, clear engine stack and fParticles and reset buffered values
130  void ResetInternals();
131 
132 private:
133  /// Pointer to current track
134  Int_t fCurrentTrackId;
135  /// Pointer to user stack for forwarding PushTrack calls
136  TVirtualMCStack *fUserStack;
137  /// Number of all primaries ever pushed linked from the TMCManager
138  Int_t *fTotalNPrimaries;
139  /// Number of all tracks ever pushed linked from the TMCManager
140  Int_t *fTotalNTracks;
141  /// All tracks linked from the TMCManager
142  std::vector<TParticle *> *fParticles;
143  /// All TMCParticleStatus linked from the TMCManager
144  std::vector<std::unique_ptr<TMCParticleStatus>> *fParticlesStatus;
145  /// Storage of TGeoBranchArray pointers
146  TGeoMCBranchArrayContainer *fBranchArrayContainer;
147  /// IDs of primaries to be tracked
148  std::stack<Int_t> fPrimariesStack;
149  /// IDs of secondaries to be trackedk
150  std::stack<Int_t> fSecondariesStack;
151 
152  ClassDefOverride(TMCManagerStack, 1)
153 };
154 
155 #endif // ROOT_TMCManagerStack