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);
177 void modifiesHit(int iDet);
178
179 TClonesArray* GetListOfParticles() override;
180
181 std::vector<MCTrack> const* const getMCTracks() const { return mTracks; }
182
184 FairGenericStack* CloneStack() const override;
185
186 // methods concerning track references
187 void addTrackReference(const o2::TrackReference& p);
188
189 // get primaries
190 const std::vector<TParticle>& getPrimaries() const { return mPrimaryParticles; }
191
192 // initialize Stack from external vector containing primaries
193
194 void initFromPrimaries(std::vector<TParticle>& primaries)
195 {
196 Reset();
197 for (auto p : primaries) {
198 Int_t doTrack = 0;
199 if (p.TestBit(ParticleStatus::kToBeDone)) {
200 doTrack = 1;
201 }
202 PushTrack(doTrack, p);
203 }
204 mNumberOfPrimaryParticles = primaries.size();
205 mNumberOfEntriesInParticles = mNumberOfPrimaryParticles;
206 }
207
208 void setExternalMode(bool m) { mIsExternalMode = m; }
209
211 int getMotherTrackId(int /*trackid*/) const;
212
215 bool isTrackDaughterOf(int /*trackid*/, int /*parentid*/) const;
218 bool isFromRadDecay(int trackid) const;
219
220 bool isCurrentTrackDaughterOf(int parentid) const;
221
222 // returns the index of the currently transported primary
223 int getCurrentPrimaryIndex() const;
224
225 // Fill container with all parent ids for current track
226 // The resulting ids will be in strictly monotonously decreasing order
227 void fillParentIDs(std::vector<int>& ids) const;
228
232 void setMCEventStats(o2::dataformats::MCEventStats* header);
233
235 void updateEventStats();
236
238 bool currentTrackLeftHit() const { return mCurrentParticle.TestBit(ParticleStatus::kHasHits); }
239
241 bool currentTrackLeftTrackRef() const { return mCurrentParticle.TestBit(ParticleStatus::kHasTrackRefs); }
242
244 void setTrackSeedingMode(bool m) { mDoTrackSeeding = m; }
245
246 typedef std::function<bool(const TParticle& p, const std::vector<TParticle>& particles)> TransportFcn;
247
248 private:
251 std::stack<TParticle> mStack;
252
255 std::vector<o2::MCTrack> mParticles;
256 std::vector<int> mTransportedIDs;
257 std::vector<int> mIndexOfPrimaries;
258 std::vector<int> mTrackIDtoParticlesEntry;
259 // the current TParticle object
260 TParticle mCurrentParticle;
261 TParticle mCurrentParticle0;
262
263 // keep primary particles in its original form
264 // (mainly for the PopPrimaryParticleInterface
265 std::vector<TParticle> mPrimaryParticles;
266
268 std::vector<o2::MCTrack>* mTracks;
269
271 std::map<Int_t, Int_t> mIndexMap;
272
274 std::vector<o2::base::Detector*> mActiveDetectors;
275
277 Int_t mIndexOfCurrentTrack;
278 Int_t mIndexOfCurrentPrimary;
279 Int_t mNumberOfPrimaryParticles;
280 Int_t mNumberOfEntriesInParticles;
281 Int_t mNumberOfEntriesInTracks;
282 Int_t mNumberOfPrimariesforTracking;
283 Int_t mNumberOfPrimariesPopped;
284 Int_t mIndex;
285
287 Bool_t mStoreMothers;
288 Bool_t mStoreSecondaries;
289 bool mPruneKinematics = false; // whether or not we filter the output kinematics
290 Int_t mMinHits;
291 Int_t mHitCounter = 0;
292 Double32_t mEnergyCut;
293
294 // variables for the cleanup / filtering procedure
295 Int_t mCleanupCounter = 0;
296 Int_t mCleanupThreshold = 1;
297 Int_t mPrimariesDone = 0;
298 Int_t mTracksDone = 0;
299
300 bool mIsG4Like = false;
301
302 bool mIsExternalMode = false; // is stack an external factory or directly used inside simulation?
303 bool mDoTrackSeeding = false; // whether to do track based seeding
304
305 TransportFcn mTransportPrimary = [](const TParticle& p, const std::vector<TParticle>& particles) { return false; };
306
307 // storage for track references
308 std::vector<o2::TrackReference>* mTrackRefs = nullptr;
309
311 o2::dataformats::MCEventStats* mMCEventStats = nullptr;
312
316 bool selectTracks();
317
318 bool isPrimary(const MCTrack& part);
319 bool isFromPrimaryDecayChain(const MCTrack& part);
320 bool isFromPrimaryPairProduction(const MCTrack& part);
321
322 bool keepPhysics(const MCTrack& part);
323
324 Stack(const Stack&);
325
326 Stack& operator=(const Stack&);
327
331 void addHit(int iDet, Int_t iTrack);
332
333 void handleTransportPrimary(TParticle& p);
334
335 ClassDefOverride(Stack, 1);
336};
337
338inline void Stack::addTrackReference(const o2::TrackReference& ref)
339{
340 if (mIndexOfCurrentTrack >= mNumberOfPrimaryParticles) {
341 Int_t iTrack = mTrackIDtoParticlesEntry[mIndexOfCurrentTrack];
342 auto& part = mParticles[iTrack];
343 part.setStore(true);
344 }
345 mCurrentParticle.SetBit(ParticleStatus::kHasTrackRefs, 1); // mark that this particle has track refs
346 mTrackRefs->push_back(ref);
347}
348
349inline int Stack::getCurrentPrimaryIndex() const { return mPrimaryParticles.size() - 1 - mPrimariesDone; }
350
351inline int Stack::getMotherTrackId(int trackid) const
352{
353 const auto entryinParticles = mTrackIDtoParticlesEntry[trackid];
354 return mParticles[entryinParticles].getMotherTrackId();
355}
356
357inline bool Stack::isFromRadDecay(int trackid) const
358{
359 // Check whether particle originates directly or indirectly from radioactive decay.
360 // Walks up the mother chain until a primary is reached. Only meaningful during
361 // transport, since selectTracks() later rewrites the mother indices in mParticles.
362 //
363 // Note that primaries are not kept in mParticles and that mTrackIDtoParticlesEntry
364 // is meaningless for them, so the chain has to be terminated on the trackID itself.
365 for (int id = trackid; id >= mNumberOfPrimaryParticles;) {
366 if (id >= static_cast<int>(mTrackIDtoParticlesEntry.size())) {
367 return false;
368 }
369 const auto entry = mTrackIDtoParticlesEntry[id];
370 if (entry < 0 || entry >= static_cast<int>(mParticles.size())) {
371 return false;
372 }
373 const auto& part = mParticles[entry];
374 if (part.getProcess() == kPRadDecay) {
375 return true;
376 }
377 id = part.getMotherTrackId();
378 }
379 return false;
380}
381
382inline bool Stack::isCurrentTrackDaughterOf(int parentid) const
383{
384 // if parentid is current primary the answer is certainly yes
385 if (parentid == getCurrentPrimaryIndex()) {
386 return true;
387 }
388
389 // otherwise ...
390 return isTrackDaughterOf(mIndexOfCurrentTrack, parentid);
391}
392
393inline void Stack::setMCEventStats(o2::dataformats::MCEventStats* header)
394{
395 mMCEventStats = header;
396}
397
398inline TMCProcess Stack::GetProdProcessOfCurrentTrack() const
399{
400 return (TMCProcess)o2::data::Stack::GetCurrentTrack()->GetUniqueID();
401}
402
403} // namespace data
404} // namespace o2
405
406#endif
int16_t time
Definition RawEventData.h:4
std::vector< std::string > header
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:181
void SetCurrentTrack(Int_t iTrack) override
Definition Stack.cxx:296
void initFromPrimaries(std::vector< TParticle > &primaries)
Definition Stack.h:194
void setExternalMode(bool m)
Definition Stack.h:208
TParticle * GetCurrentTrack() const override
Definition Stack.h:125
bool currentTrackLeftHit() const
returns if current track left a hit
Definition Stack.h:238
bool isTrackDaughterOf(int, int) const
Definition Stack.cxx:842
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:190
void setTrackSeedingMode(bool m)
set track seeding mode (tracks are seeded individually for increased reproducability)
Definition Stack.h:244
Int_t GetNprimary() const override
Definition Stack.h:122
bool currentTrackLeftTrackRef() const
returns if current track left a TrackReference
Definition Stack.h:241
void StoreMothers(Bool_t choice=kTRUE)
Definition Stack.h:171
int getCurrentPrimaryIndex() const
Definition Stack.h:349
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:246
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
GLint ref
Definition glcorearb.h:291
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