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;
213
214 bool isCurrentTrackDaughterOf(int parentid) const;
215
216 // returns the index of the currently transported primary
217 int getCurrentPrimaryIndex() const;
218
219 // Fill container with all parent ids for current track
220 // The resulting ids will be in strictly monotonously decreasing order
221 void fillParentIDs(std::vector<int>& ids) const;
222
226 void setMCEventStats(o2::dataformats::MCEventStats* header);
227
229 void updateEventStats();
230
232 bool currentTrackLeftHit() const { return mCurrentParticle.TestBit(ParticleStatus::kHasHits); }
233
235 bool currentTrackLeftTrackRef() const { return mCurrentParticle.TestBit(ParticleStatus::kHasTrackRefs); }
236
238 void setTrackSeedingMode(bool m) { mDoTrackSeeding = m; }
239
240 typedef std::function<bool(const TParticle& p, const std::vector<TParticle>& particles)> TransportFcn;
241
242 private:
245 std::stack<TParticle> mStack;
246
249 std::vector<o2::MCTrack> mParticles;
250 std::vector<int> mTransportedIDs;
251 std::vector<int> mIndexOfPrimaries;
252 std::vector<int> mTrackIDtoParticlesEntry;
253 // the current TParticle object
254 TParticle mCurrentParticle;
255 TParticle mCurrentParticle0;
256
257 // keep primary particles in its original form
258 // (mainly for the PopPrimaryParticleInterface
259 std::vector<TParticle> mPrimaryParticles;
260
262 std::vector<o2::MCTrack>* mTracks;
263
265 std::map<Int_t, Int_t> mIndexMap;
266
268 std::vector<o2::base::Detector*> mActiveDetectors;
269
271 Int_t mIndexOfCurrentTrack;
272 Int_t mIndexOfCurrentPrimary;
273 Int_t mNumberOfPrimaryParticles;
274 Int_t mNumberOfEntriesInParticles;
275 Int_t mNumberOfEntriesInTracks;
276 Int_t mNumberOfPrimariesforTracking;
277 Int_t mNumberOfPrimariesPopped;
278 Int_t mIndex;
279
281 Bool_t mStoreMothers;
282 Bool_t mStoreSecondaries;
283 bool mPruneKinematics = false; // whether or not we filter the output kinematics
284 Int_t mMinHits;
285 Int_t mHitCounter = 0;
286 Double32_t mEnergyCut;
287
288 // variables for the cleanup / filtering procedure
289 Int_t mCleanupCounter = 0;
290 Int_t mCleanupThreshold = 1;
291 Int_t mPrimariesDone = 0;
292 Int_t mTracksDone = 0;
293
294 bool mIsG4Like = false;
295
296 bool mIsExternalMode = false; // is stack an external factory or directly used inside simulation?
297 bool mDoTrackSeeding = false; // whether to do track based seeding
298
299 TransportFcn mTransportPrimary = [](const TParticle& p, const std::vector<TParticle>& particles) { return false; };
300
301 // storage for track references
302 std::vector<o2::TrackReference>* mTrackRefs = nullptr;
303
305 o2::dataformats::MCEventStats* mMCEventStats = nullptr;
306
310 bool selectTracks();
311
312 bool isPrimary(const MCTrack& part);
313 bool isFromPrimaryDecayChain(const MCTrack& part);
314 bool isFromPrimaryPairProduction(const MCTrack& part);
315
316 bool keepPhysics(const MCTrack& part);
317
318 Stack(const Stack&);
319
320 Stack& operator=(const Stack&);
321
325 void addHit(int iDet, Int_t iTrack);
326
327 void handleTransportPrimary(TParticle& p);
328
329 ClassDefOverride(Stack, 1);
330};
331
332inline void Stack::addTrackReference(const o2::TrackReference& ref)
333{
334 if (mIndexOfCurrentTrack >= mNumberOfPrimaryParticles) {
335 Int_t iTrack = mTrackIDtoParticlesEntry[mIndexOfCurrentTrack];
336 auto& part = mParticles[iTrack];
337 part.setStore(true);
338 }
339 mCurrentParticle.SetBit(ParticleStatus::kHasTrackRefs, 1); // mark that this particle has track refs
340 mTrackRefs->push_back(ref);
341}
342
343inline int Stack::getCurrentPrimaryIndex() const { return mPrimaryParticles.size() - 1 - mPrimariesDone; }
344
345inline int Stack::getMotherTrackId(int trackid) const
346{
347 const auto entryinParticles = mTrackIDtoParticlesEntry[trackid];
348 return mParticles[entryinParticles].getMotherTrackId();
349}
350
351inline bool Stack::isCurrentTrackDaughterOf(int parentid) const
352{
353 // if parentid is current primary the answer is certainly yes
354 if (parentid == getCurrentPrimaryIndex()) {
355 return true;
356 }
357
358 // otherwise ...
359 return isTrackDaughterOf(mIndexOfCurrentTrack, parentid);
360}
361
362inline void Stack::setMCEventStats(o2::dataformats::MCEventStats* header)
363{
364 mMCEventStats = header;
365}
366
367inline TMCProcess Stack::GetProdProcessOfCurrentTrack() const
368{
369 return (TMCProcess)o2::data::Stack::GetCurrentTrack()->GetUniqueID();
370}
371
372} // namespace data
373} // namespace o2
374
375#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:232
bool isTrackDaughterOf(int, int) const
Definition Stack.cxx:831
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:238
Int_t GetNprimary() const override
Definition Stack.h:122
bool currentTrackLeftTrackRef() const
returns if current track left a TrackReference
Definition Stack.h:235
void StoreMothers(Bool_t choice=kTRUE)
Definition Stack.h:171
int getCurrentPrimaryIndex() const
Definition Stack.h:343
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:240
const GLfloat * m
Definition glcorearb.h:4066
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
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
constexpr size_t min