BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnRootIterator.h
Go to the documentation of this file.
1/*
2 BM@N alignment routine
3 BM@N experiment at NICA complex, JINR, 2025
4
5 Department: Math & Soft Group of HEP lab
6 Author: Igor Polev, polev@jinr.int
7
8 BmnRootIterator class declaration
9 Iterator for tracks and hits stored in ROOT files
10*/
11
12#ifndef BMNROOTITERATOR_H
13#define BMNROOTITERATOR_H
14
15#include "BmnDataFilters.h"
16#include "BmnDataIterator.h"
17#include "BmnDataReader.h"
18#include "BmnDetectorModel.h"
19#include "BmnHitRecord.h" // MIN_HIT_ERROR / MAX_WEIGHT, used by HitWx() and HitWy()
21#include "CbmStsHit.h"
22#include "CbmStsTrack.h"
23#include "DstEventHeader.h"
24#include "TTreeReaderValue.h"
25
26#include <vector>
27
28#define BMN_EVENT_BRANCH_NAME "DstEventHeader."
29#define BMN_TRACKS_BRANCH_NAME "StsVector"
30#define BMN_HITS_BRANCH_NAME "StsHit"
31#define BMN_HIT_CLASS_NAME "CbmStsHit"
32#define BMN_BEAM_BRANCH_NAME "BmnSiBTHit"
33
34/*
35 * A detector model with a target element (BmnDetectorModel::TargetID()) makes
36 * the iterator prepend a synthetic vertex hit to the tracks that take it, see
37 * ScanEvent(). That hit has no CbmStsHit behind it: GetHit() returns null on it.
38 */
39
41{
42 public:
45
46 BmnRootIterator() = delete;
47 BmnRootIterator(const char* filesPathList,
48 const BmnDetectorModel& detModel,
49 TrackFilter_t trackFilter,
50 HitFilter_t hitFilter,
51 BmnSimpleProgressBar* pb = nullptr,
52 Bool_t verbose = kFALSE, // verbose mode of BmnDataReader
53 Int_t maxTracks = 0 // for special use only (0 means no limit)
54 );
55 virtual ~BmnRootIterator();
56
57 void CountElements();
58 virtual void ResetAll() override;
59 virtual void NextTrack() override;
60 inline virtual void ResetHits() override;
61 inline virtual void NextHit() override;
62 inline virtual Double_t HitX() const override;
63 inline virtual Double_t HitY() const override;
64 inline virtual Double_t HitZ() const override;
65 inline virtual Double_t HitWx() const override;
66 inline virtual Double_t HitWy() const override;
67 inline virtual Int_t HitDetectorID() const override;
68 inline virtual Int_t HitsInTrack() const override;
69
70 UInt_t EventID() const noexcept { return fEventID; }
71 Long64_t GetTotalEvents() const noexcept { return fTotalEvents; }
72 Int_t GetTotalTracks() const noexcept { return fTotalTracks; }
73 Int_t GetTotalHits() const noexcept { return fTotalHits; }
74 const Hit_t* GetHit() const noexcept { return fpCurrentHit; }
75 const Track_t* GetTrack() const noexcept { return fpCurrentTrack; }
76 Bool_t IsNewEvent() const noexcept { return fEventTracks == 1; }
77 Bool_t HasVertexHit() const noexcept { return fHasVertex; }
78 // variance of the event's vertex point, before its weight is shared among the tracks
79 Double_t VertexVarX() const noexcept { return fVertexVarX; }
80 Double_t VertexVarY() const noexcept { return fVertexVarY; }
81 TChain& GetChain() const noexcept { return fpData->Chain(); }
82 // SiBT hits of the current event, null when the model has no target element
83 const TClonesArray* GetBeamHits() const { return fpRootBeamHits ? fpRootBeamHits->Get() : nullptr; }
84
85 private:
86 // the class is involved into ROOT dictionary schema which utilizes forward
87 // declarations - only pointers (or refs) to classes are possible as a field
89 // predicates, not data: kept out of the ROOT I/O schema by the '!' mark
90 TrackFilter_t fTrackFilter; //! kTRUE keeps the track
91 HitFilter_t fHitFilter; //! kTRUE keeps the hit
96
101 fHitsInTrack{0}, // hits of the current track the hit filter keeps
102 fHitsRaw{0}, // hits the current track declares
103 fTrackIdx{-1}, fHitIdx{-1}, // position in the track's own hit list, filtered hits skipped
104 fTrackLimit{0}, fTrackCount{0}, fEventTracks{0}; // tracks of the current event the track filter kept so far
106
107 // vertex hit of the current event, see ScanEvent()
108 std::vector<Bool_t> fVertexTrack; //! per track of the event: kTRUE if it takes the vertex hit
110 fVertexZ{0.0}, // target centre, read from the model by every ResetAll():
111 // the target may move between passes, see BmnAligner::PrepareData()
113 Bool_t fHasVertex{kFALSE}, // the current track takes the vertex hit
114 fAtVertex{kFALSE}; // the vertex hit is the current hit
115
117
118 inline Hit_t* HitAt(Int_t idx) const;
119 inline Int_t NextUsableHit(Int_t from) const;
120 inline Int_t CountUsableHits();
121 inline void UnsetProperties();
122 void ScanEvent();
123};
124
125// === inline implementation =====================================================
126
128{
129 return (Hit_t*)(*fpRootHits)->At(fpCurrentTrack->GetStsHitIndex(idx));
130}
131
133{
134 for (Int_t i = from; i < fHitsRaw; i++)
135 if (fHitFilter(*HitAt(i)))
136 return i;
137 return fHitsRaw;
138}
139
141{
142 fHitsRaw = fpCurrentTrack->GetNStsHits();
143 fHitsInTrack = 0;
144 for (Int_t i = 0; i < fHitsRaw; i++)
145 if (fHitFilter(*HitAt(i)))
146 fHitsInTrack++;
147 return fHitsInTrack;
148}
149
159
161{
162 if (!fInitialized || fEndOfHits)
163 return;
164 if (fAtVertex)
165 fAtVertex = kFALSE; // fHitIdx already points at the first STS hit
166 else
168 if (fHitIdx >= fHitsRaw) {
169 fpCurrentHit = nullptr;
171 } else
173}
174
176{
177 if (!fInitialized || fEndOfHits)
178 return 0.0;
179 return fAtVertex ? fVertexX : fpCurrentHit->GetX();
180}
181
183{
184 if (!fInitialized || fEndOfHits)
185 return 0.0;
186 return fAtVertex ? fVertexY : fpCurrentHit->GetY();
187}
188
190{
191 if (!fInitialized || fEndOfHits)
192 return 0.0;
193 return fAtVertex ? fVertexZ : fpCurrentHit->GetZ();
194}
195
197{
198 if (!fInitialized || fEndOfHits)
199 return 0.0;
201}
202
204{
205 if (!fInitialized || fEndOfHits)
206 return 0.0;
208}
209
211{
212 if (!fInitialized || fEndOfHits)
213 return 0;
214 if (fAtVertex)
215 return fpDetModel->TargetID();
216 return fpDetModel->IDfromHit(fpCurrentHit->GetDetectorID());
217 // this is the moment when hit detector encoding transformed into alignment encoding
218}
219
221{
223 return 0;
224 return fHitsInTrack + (fHasVertex ? 1 : 0);
225}
226
228{
229 fTracksInEvent = 0;
230 fHitsInTrack = 0;
231 fHitsRaw = 0;
232 fEventID = -1;
233 fTrackIdx = -1;
234 fHitIdx = -1;
235 fTrackCount = 0;
236 fEventTracks = 0;
239 fpCurrentTrack = nullptr;
240 fpCurrentHit = nullptr;
243 fVertexTrack.clear();
244}
245
246#endif
std::function< Bool_t(const CbmStsHit &)> HitFilter_t
std::function< Bool_t(const CbmStsTrack &, Int_t usableHits)> TrackFilter_t
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
unsigned int UInt_t
constexpr Bool_t kFALSE
double Double_t
long long Long64_t
constexpr Bool_t kTRUE
BmnDataIterator(BmnSimpleProgressBar *pb=nullptr)
static constexpr Double_t Weight(Double_t error) noexcept
Hit_t * HitAt(Int_t idx) const
virtual Double_t HitY() const override
UInt_t EventID() const noexcept
virtual void ResetAll() override
HitFilter_t fHitFilter
kTRUE keeps the track
virtual Double_t HitWy() const override
const BmnDetectorModel * fpDetModel
virtual Int_t HitDetectorID() const override
Double_t fVertexX
per track of the event: kTRUE if it takes the vertex hit
TrackFilter_t fTrackFilter
TChain & GetChain() const noexcept
const Hit_t * GetHit() const noexcept
Bool_t IsNewEvent() const noexcept
Track_t * fpCurrentTrack
TTreeReaderValue< TClonesArray > * fpRootBeamHits
const Track_t * GetTrack() const noexcept
virtual Double_t HitZ() const override
BmnRootIterator()=delete
BmnDataReader * fpData
kTRUE keeps the hit
virtual Double_t HitX() const override
Double_t VertexVarY() const noexcept
Int_t GetTotalTracks() const noexcept
TTreeReaderValue< DstEventHeader > * fpRootEventHeader
std::vector< Bool_t > fVertexTrack
virtual Int_t HitsInTrack() const override
virtual Double_t HitWx() const override
TTreeReader * fpReader
Int_t GetTotalHits() const noexcept
Bool_t HasVertexHit() const noexcept
Int_t NextUsableHit(Int_t from) const
virtual void ResetHits() override
CbmStsTrack Track_t
TTreeReaderValue< TClonesArray > * fpRootHits
Long64_t GetTotalEvents() const noexcept
virtual ~BmnRootIterator()
virtual void NextTrack() override
TTreeReaderValue< TClonesArray > * fpRootTracks
Double_t VertexVarX() const noexcept
virtual void NextHit() override
const TClonesArray * GetBeamHits() const