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