Project
Loading...
Searching...
No Matches
Stack.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef ALICEO2_DATA_STACK_H_
17#define ALICEO2_DATA_STACK_H_
18
20#include "FairGenericStack.h"
25#include "Rtypes.h"
26#include "TParticle.h"
27
28#include <map>
29#include <memory>
30#include <stack>
31#include <utility>
32#include <functional>
33
34class TClonesArray;
35class TRefArray;
36
37namespace o2
38{
39namespace base
40{
41class Detector;
42}
43
44namespace data
45{
60class Stack : public FairGenericStack
61{
62 public:
65 Stack(Int_t size = 100);
66
68 ~Stack() override;
69
84 void PushTrack(Int_t toBeDone, Int_t parentID, Int_t pdgCode, Double_t px, Double_t py, Double_t pz, Double_t e,
85 Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly, Double_t polz,
86 TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is) override;
87
88 void PushTrack(Int_t toBeDone, Int_t parentID, Int_t pdgCode, Double_t px, Double_t py, Double_t pz, Double_t e,
89 Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly, Double_t polz,
90 TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is, Int_t secondParentId) override;
91
92 void PushTrack(Int_t toBeDone, Int_t parentID, Int_t pdgCode, Double_t px, Double_t py, Double_t pz, Double_t e,
93 Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly, Double_t polz,
94 TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is, Int_t secondParentId, Int_t daughter1Id, Int_t daughter2Id,
95 TMCProcess proc2);
96
97 // similar function taking a particle
98 void PushTrack(Int_t toBeDone, TParticle&);
99
104 TParticle* PopNextTrack(Int_t& iTrack) override;
105
110 TParticle* PopPrimaryForTracking(Int_t iPrim) override;
111
115 void SetCurrentTrack(Int_t iTrack) override;
116
119 Int_t GetNtrack() const override { return mNumberOfEntriesInParticles; }
122 Int_t GetNprimary() const override { return mNumberOfPrimaryParticles; }
125 TParticle* GetCurrentTrack() const override
126 {
127 // the const cast is necessary ... the interface should have been `const TParticle* GetCurrentParticle() const`
128 return const_cast<TParticle*>(&mCurrentParticle);
129 }
130
133 Int_t GetCurrentTrackNumber() const override { return mIndexOfCurrentTrack; }
136 Int_t GetCurrentParentTrackNumber() const override;
137
139 TMCProcess GetProdProcessOfCurrentTrack() const;
140
142 void FillTrackArray() override;
143
145 void UpdateTrackIndex(TRefArray* detArray = nullptr) override;
146
148 void FinishPrimary() override;
149
151 void Reset() override;
152
154 void Register() override;
155
158
159 virtual void Print(Int_t iVerbose = 0) const;
160
163 void Print(Option_t* option = nullptr) const override;
164
165 void ReorderKine(std::vector<MCTrack>& particles, std::vector<int>& reOrderedIndices);
167 void StoreSecondaries(Bool_t choice = kTRUE) { mStoreSecondaries = choice; }
168 void pruneKinematics(bool choice = true) { mPruneKinematics = choice; }
169 void setMinHits(Int_t min) { mMinHits = min; }
170 void SetEnergyCut(Double_t eMin) { mEnergyCut = eMin; }
171 void StoreMothers(Bool_t choice = kTRUE) { mStoreMothers = choice; }
174 void addHit(int iDet);
175
176 TClonesArray* GetListOfParticles() override;
177
178 std::vector<MCTrack> const* const getMCTracks() const { return mTracks; }
179
181 FairGenericStack* CloneStack() const override;
182
183 // methods concerning track references
184 void addTrackReference(const o2::TrackReference& p);
185
186 // get primaries
187 const std::vector<TParticle>& getPrimaries() const { return mPrimaryParticles; }
188
189 // initialize Stack from external vector containing primaries
190
191 void initFromPrimaries(std::vector<TParticle>& primaries)
192 {
193 Reset();
194 for (auto p : primaries) {
195 Int_t doTrack = 0;
196 if (p.TestBit(ParticleStatus::kToBeDone)) {
197 doTrack = 1;
198 }
199 PushTrack(doTrack, p);
200 }
201 mNumberOfPrimaryParticles = primaries.size();
202 mNumberOfEntriesInParticles = mNumberOfPrimaryParticles;
203 }
204
205 void setExternalMode(bool m) { mIsExternalMode = m; }
206
208 int getMotherTrackId(int /*trackid*/) const;
209
212 bool isTrackDaughterOf(int /*trackid*/, int /*parentid*/) const;
215 bool isFromRadDecay(int trackid) const;
216
217 bool isCurrentTrackDaughterOf(int parentid) const;
218
219 // returns the index of the currently transported primary
220 int getCurrentPrimaryIndex() const;
221
222 // Fill container with all parent ids for current track
223 // The resulting ids will be in strictly monotonously decreasing order
224 void fillParentIDs(std::vector<int>& ids) const;
225
229 void setMCEventStats(o2::dataformats::MCEventStats* header);
230
232 void updateEventStats();
233
235 bool currentTrackLeftHit() const { return mCurrentParticle.TestBit(ParticleStatus::kHasHits); }
236
238 bool currentTrackLeftTrackRef() const { return mCurrentParticle.TestBit(ParticleStatus::kHasTrackRefs); }
239
241 void setTrackSeedingMode(bool m) { mDoTrackSeeding = m; }
242
243 typedef std::function<bool(const TParticle& p, const std::vector<TParticle>& particles)> TransportFcn;
244
245 private:
248 std::stack<TParticle> mStack;
249
252 std::vector<o2::MCTrack> mParticles;
253 std::vector<int> mTransportedIDs;
254 std::vector<int> mIndexOfPrimaries;
255 std::vector<int> mTrackIDtoParticlesEntry;
256 // the current TParticle object
257 TParticle mCurrentParticle;
258 TParticle mCurrentParticle0;
259
260 // keep primary particles in its original form
261 // (mainly for the PopPrimaryParticleInterface
262 std::vector<TParticle> mPrimaryParticles;
263
265 std::vector<o2::MCTrack>* mTracks;
266
268 std::map<Int_t, Int_t> mIndexMap;
269
271 std::vector<o2::base::Detector*> mActiveDetectors;
272
274 Int_t mIndexOfCurrentTrack;
275 Int_t mIndexOfCurrentPrimary;
276 Int_t mNumberOfPrimaryParticles;
277 Int_t mNumberOfEntriesInParticles;
278 Int_t mNumberOfEntriesInTracks;
279 Int_t mNumberOfPrimariesforTracking;
280 Int_t mNumberOfPrimariesPopped;
281 Int_t mIndex;
282
284 Bool_t mStoreMothers;
285 Bool_t mStoreSecondaries;
286 bool mPruneKinematics = false; // whether or not we filter the output kinematics
287 Int_t mMinHits;
288 Int_t mHitCounter = 0;
289 Double32_t mEnergyCut;
290
291 // variables for the cleanup / filtering procedure
292 Int_t mCleanupCounter = 0;
293 Int_t mCleanupThreshold = 1;
294 Int_t mPrimariesDone = 0;
295 Int_t mTracksDone = 0;
296
297 bool mIsG4Like = false;
298
299 bool mIsExternalMode = false; // is stack an external factory or directly used inside simulation?
300 bool mDoTrackSeeding = false; // whether to do track based seeding
301
302 TransportFcn mTransportPrimary = [](const TParticle& p, const std::vector<TParticle>& particles) { return false; };
303
304 // storage for track references
305 std::vector<o2::TrackReference>* mTrackRefs = nullptr;
306
308 o2::dataformats::MCEventStats* mMCEventStats = nullptr;
309
313 bool selectTracks();
314
315 bool isPrimary(const MCTrack& part);
316 bool isFromPrimaryDecayChain(const MCTrack& part);
317 bool isFromPrimaryPairProduction(const MCTrack& part);
318
319 bool keepPhysics(const MCTrack& part);
320
321 Stack(const Stack&);
322
323 Stack& operator=(const Stack&);
324
328 void addHit(int iDet, Int_t iTrack);
329
330 void handleTransportPrimary(TParticle& p);
331
332 ClassDefOverride(Stack, 1);
333};
334
335inline void Stack::addTrackReference(const o2::TrackReference& ref)
336{
337 if (mIndexOfCurrentTrack >= mNumberOfPrimaryParticles) {
338 Int_t iTrack = mTrackIDtoParticlesEntry[mIndexOfCurrentTrack];
339 auto& part = mParticles[iTrack];
340 part.setStore(true);
341 }
342 mCurrentParticle.SetBit(ParticleStatus::kHasTrackRefs, 1); // mark that this particle has track refs
343 mTrackRefs->push_back(ref);
344}
345
346inline int Stack::getCurrentPrimaryIndex() const { return mPrimaryParticles.size() - 1 - mPrimariesDone; }
347
348inline int Stack::getMotherTrackId(int trackid) const
349{
350 const auto entryinParticles = mTrackIDtoParticlesEntry[trackid];
351 return mParticles[entryinParticles].getMotherTrackId();
352}
353
354inline bool Stack::isFromRadDecay(int trackid) const
355{
356 // Check whether particle originates directly or indirectly from radioactive decay.
357 // Walks up the mother chain until a primary is reached. Only meaningful during
358 // transport, since selectTracks() later rewrites the mother indices in mParticles.
359 //
360 // Note that primaries are not kept in mParticles and that mTrackIDtoParticlesEntry
361 // is meaningless for them, so the chain has to be terminated on the trackID itself.
362 for (int id = trackid; id >= mNumberOfPrimaryParticles;) {
363 if (id >= static_cast<int>(mTrackIDtoParticlesEntry.size())) {
364 return false;
365 }
366 const auto entry = mTrackIDtoParticlesEntry[id];
367 if (entry < 0 || entry >= static_cast<int>(mParticles.size())) {
368 return false;
369 }
370 const auto& part = mParticles[entry];
371 if (part.getProcess() == kPRadDecay) {
372 return true;
373 }
374 id = part.getMotherTrackId();
375 }
376 return false;
377}
378
379inline bool Stack::isCurrentTrackDaughterOf(int parentid) const
380{
381 // if parentid is current primary the answer is certainly yes
382 if (parentid == getCurrentPrimaryIndex()) {
383 return true;
384 }
385
386 // otherwise ...
387 return isTrackDaughterOf(mIndexOfCurrentTrack, parentid);
388}
389
390inline void Stack::setMCEventStats(o2::dataformats::MCEventStats* header)
391{
392 mMCEventStats = header;
393}
394
395inline TMCProcess Stack::GetProdProcessOfCurrentTrack() const
396{
397 return (TMCProcess)o2::data::Stack::GetCurrentTrack()->GetUniqueID();
398}
399
400} // namespace data
401} // namespace o2
402
403#endif
int16_t time
Definition RawEventData.h:4
Definition of the MCTrack class.
@ kHasHits
@ kHasTrackRefs
@ kToBeDone
o2::header::Stack Stack
void SetEnergyCut(Double_t eMin)
Definition Stack.h:170
void PushTrack(Int_t toBeDone, TParticle &)
std::vector< MCTrack > const *const getMCTracks() const
Definition Stack.h:178
void SetCurrentTrack(Int_t iTrack) override
Definition Stack.cxx:296
void initFromPrimaries(std::vector< TParticle > &primaries)
Definition Stack.h:191
void setExternalMode(bool m)
Definition Stack.h:205
TParticle * GetCurrentTrack() const override
Definition Stack.h:125
bool currentTrackLeftHit() const
returns if current track left a hit
Definition Stack.h:235
bool isTrackDaughterOf(int, int) const
Definition Stack.cxx:832
TParticle * PopPrimaryForTracking(Int_t iPrim) override
Definition Stack.cxx:379
TParticle * PopNextTrack(Int_t &iTrack) override
Definition Stack.cxx:330
Int_t GetNtrack() const override
Definition Stack.h:119
void PushTrack(Int_t toBeDone, Int_t parentID, Int_t pdgCode, Double_t px, Double_t py, Double_t pz, Double_t e, Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly, Double_t polz, TMCProcess proc, Int_t &ntr, Double_t weight, Int_t is) override
Definition Stack.cxx:176
void pruneKinematics(bool choice=true)
Definition Stack.h:168
Int_t GetCurrentTrackNumber() const override
Definition Stack.h:133
void Reset() override
Resets arrays and stack and deletes particles and tracks.
Definition Stack.cxx:588
const std::vector< TParticle > & getPrimaries() const
Definition Stack.h:187
void setTrackSeedingMode(bool m)
set track seeding mode (tracks are seeded individually for increased reproducability)
Definition Stack.h:241
Int_t GetNprimary() const override
Definition Stack.h:122
bool currentTrackLeftTrackRef() const
returns if current track left a TrackReference
Definition Stack.h:238
void StoreMothers(Bool_t choice=kTRUE)
Definition Stack.h:171
int getCurrentPrimaryIndex() const
Definition Stack.h:346
void setMinHits(Int_t min)
Definition Stack.h:169
void StoreSecondaries(Bool_t choice=kTRUE)
Modifiers.
Definition Stack.h:167
std::function< bool(const TParticle &p, const std::vector< TParticle > &particles)> TransportFcn
Definition Stack.h:243
const GLfloat * m
Definition glcorearb.h:4066
GLuint entry
Definition glcorearb.h:5735
GLsizeiptr size
Definition glcorearb.h:659
GLuint * ids
Definition glcorearb.h:647
GLuint GLuint GLfloat weight
Definition glcorearb.h:5477
GLboolean * data
Definition glcorearb.h:298
GLuint id
Definition glcorearb.h:650
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
constexpr size_t min