CbmRoot
Loading...
Searching...
No Matches
CbmStackFilter.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
13#include "CbmStackFilter.h"
14
15#include <Logger.h>
16
17#include "TClonesArray.h"
18#include "TMCProcess.h"
19#include "TParticle.h"
20
21#include <cassert>
22
23
24using std::make_pair;
25using std::vector;
26
27
28// ----- Constructor ----------------------------------------------------
30 : fStoreAllPrimaries(kTRUE)
31 , fStoreAllMothers(kTRUE)
32 , fStoreAllDecays(kFALSE)
33 , fMinNofPoints()
34 , fMinEkin(0.)
35 , fStore()
36{
37
38 // Initialise NofPoints cuts
40 fMinNofPoints[iDet] = 1;
41 fMinNofPoints[ECbmModuleId::kPsd] = 5; // A hard-coded number. I'll rot in hell for that.
42}
43// --------------------------------------------------------------------------
44
45
46// ----- Destructor -----------------------------------------------------
48// --------------------------------------------------------------------------
49
50
51// ----- Selection procedure --------------------------------------------
52const vector<Bool_t>& CbmStackFilter::Select(const TClonesArray& particles, const PointMap& points)
53{
54
55 // Adjust size of output vector
56 assert(particles.GetEntriesFast() >= 0);
57 UInt_t nParticles = particles.GetEntriesFast();
58 fStore.resize(nParticles);
59 Int_t nSelected = 0;
60
61 // Loop over particles in array
62 for (UInt_t index = 0; index < nParticles; index++) {
63
64 // Get particle object
65 TParticle* particle = dynamic_cast<TParticle*>(particles.At(index));
66 assert(particle);
67
68 // Check for being a primary
70 if (particle->GetUniqueID() == kPPrimary) {
71 fStore[index] = kTRUE;
72 nSelected++;
73 continue;
74 } //? is a primary
75 } //? store all primaries
76
77 // Check cuts on number of points in detectors
78 fStore[index] = kFALSE;
79 for (ECbmModuleId system = ECbmModuleId::kRef; system < ECbmModuleId::kNofSystems; ++system) {
80 auto it = points.find(make_pair(index, system));
81 UInt_t nPoints = (it == points.end() ? 0 : it->second);
82 if (nPoints >= fMinNofPoints[system]) {
83 fStore[index] = kTRUE;
84 continue;
85 } //? Number cut satisfied
86 } //# detector systems
87
88 // Check cut on kinetic energy
89 // Implementation note VF/191029): In rare cases, the kinetic energy of the
90 // particle can be negative (observed for ions with GEANT4). We thus check
91 // first whether a kinetic energy cut was set at all.
92 if (fMinEkin > 1.e-9) {
93 if (particle->Ek() < fMinEkin) fStore[index] = kFALSE;
94 } //? Cut in kinetic energy set
95
96 } //# particles
97
98
99 // Mark all decay daughters of primaries for storage (if chosen such)
100 TParticle* particle = nullptr;
101 if (fStoreAllDecays) {
102 for (UInt_t index = 0; index < nParticles; index++) {
103 if (fStore[index]) continue; // already selected
104 particle = dynamic_cast<TParticle*>(particles.At(index));
105 assert(particle);
106
107 // Follow the mother chain up to the primary.
108 Bool_t store = kTRUE;
109 UInt_t process = particle->GetUniqueID();
110 while (process != kPPrimary) {
111 if (process != kPDecay) {
112 store = kFALSE;
113 break; // not a decay
114 } //? not a decay
115 Int_t iMother = particle->GetMother(0); // mother index
116 particle = dynamic_cast<TParticle*>(particles.At(iMother));
117 assert(particle);
118 process = particle->GetUniqueID();
119 } //? not a primary
120
121 fStore[index] = store;
122
123 } //# particles
124 } //? store all decays
125
126
127 // Mark recursively all mothers of already selected tracks for storage
128 if (fStoreAllMothers) {
129 for (UInt_t index = 0; index < nParticles; index++) {
130 if (!fStore[index]) continue;
131 Int_t iMother = dynamic_cast<TParticle*>(particles.At(index))->GetMother(0);
132 while (iMother >= 0) {
133 fStore[iMother] = kTRUE;
134 iMother = dynamic_cast<TParticle*>(particles.At(iMother))->GetMother(0);
135 } //? not a primary
136 } //# particles
137 } //? store all mothers
138
139
140 return fStore;
141}
142// --------------------------------------------------------------------------
143
144
TClonesArray * points
ClassImp(CbmConverterManager)
ECbmModuleId
Definition CbmDefs.h:39
@ kPsd
Projectile spectator detector.
@ kRef
Reference plane.
@ kNofSystems
For loops over active systems.
Class for filtering the stack before writing.
Bool_t fStoreAllDecays
Flag for storage of all primary decay daughters.
CbmStackFilter()
Constructor.
Bool_t fStoreAllMothers
Flag for storage of mothers.
Double_t fMinEkin
Cut value for kinetic energy.
std::map< ECbmModuleId, UInt_t > fMinNofPoints
Cut values for the number of points.
Bool_t fStoreAllPrimaries
Flag for storage of primaries.
virtual ~CbmStackFilter()
Destructor.
std::map< std::pair< Int_t, ECbmModuleId >, Int_t > PointMap
Map holding the number of points for each detector. The key is a pair of (track index,...
std::vector< Bool_t > fStore
Vector with storage decision.
virtual const std::vector< Bool_t > & Select(const TClonesArray &particles, const PointMap &points)
Check the stack particles for fulfilling the storage criteria.