CbmRoot
Loading...
Searching...
No Matches
CbmAlgoBuildRawEvents.h
Go to the documentation of this file.
1/* Copyright (C) 2020-2024 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer], Dominik Smith, Alexandru Bercuci*/
4
5#ifndef CBMALGOBUILDRAWEVENTS_H
6#define CBMALGOBUILDRAWEVENTS_H
7
9#include "CbmDefs.h"
10
12
14#include "TFolder.h"
15
17#include <boost/any.hpp>
18
19#include <array>
20#include <map>
21#include <set>
22#include <tuple>
23#include <vector>
24
26class CbmEvent;
27class CbmMuchDigi;
29class CbmPsdDigi;
30class CbmFsdDigi;
31class CbmRichDigi;
32class CbmStsDigi;
33class CbmTofDigi;
34class CbmTrdDigi;
35class CbmBmonDigi;
36class TClonesArray;
37class TH1;
38class TH2;
39class TProfile;
40class TNamed;
41class TStopwatch;
42class TCanvas;
43class TDirectoryFile;
44
46{
51};
52
54 public:
56
57 RawEventBuilderDetector(ECbmModuleId detIdIn, ECbmDataType dataTypeIn, std::string sNameIn)
58 : detId{detIdIn}
59 , dataType{dataTypeIn}
60 , sName{sNameIn}
61 {
62 }
63
64 RawEventBuilderDetector(ECbmModuleId detIdIn, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn,
65 Int_t iTriggerMaxDigisIn, Double_t fdTimeWinBegIn, Double_t fdTimeWinEndIn,
66 UInt_t uTriggerMinLayersIn = 0, Double_t fdHistMaxDigiNbIn = 1000)
67 : RawEventBuilderDetector(detIdIn, dataTypeIn, sNameIn)
68 {
69 fuTriggerMinDigis = uTriggerMinDigisIn;
70 fiTriggerMaxDigis = iTriggerMaxDigisIn;
71 fuTriggerMinLayers = uTriggerMinLayersIn;
72 fdTimeWinBeg = fdTimeWinBegIn;
73 fdTimeWinEnd = fdTimeWinEndIn;
74 fdHistMaxDigiNb = fdHistMaxDigiNbIn;
75 }
76
77 bool operator==(const RawEventBuilderDetector& other) const { return (other.detId == this->detId); }
78 bool operator!=(const RawEventBuilderDetector& other) const { return (other.detId != this->detId); }
79
80 Double_t GetTimeWinRange() { return fdTimeWinEnd - fdTimeWinBeg; }
81
85 std::string sName = "Invalid";
93 Double_t fdTimeWinBeg = -100;
94 Double_t fdTimeWinEnd = 100;
96 Double_t fdHistMaxDigiNb = 1000;
98 UInt_t fuStartIndex = 0;
99 UInt_t fuEndIndex = 0;
100};
101
122
124 public:
127
130
133
135 Bool_t InitAlgo();
136
138 void ProcessTs();
139
141 void Finish();
142
143 void SetFillHistos(Bool_t var) { fbFillHistos = var; }
144 void ResetHistograms(Bool_t bResetTime = kTRUE);
145
147 void SetTimings(Bool_t var) { fbGetTimings = var; }
148 void PrintTimings();
149
150 void SetReferenceDetector(ECbmModuleId refDet, ECbmDataType dataTypeIn, std::string sNameIn,
151 UInt_t uTriggerMinDigisIn = 0, Int_t iTriggerMaxDigisIn = -1,
152 Double_t fdTimeWinBegIn = -100, Double_t fdTimeWinEndIn = 100);
153 void AddDetector(ECbmModuleId selDet, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn = 0,
154 Int_t iTriggerMaxDigisIn = -1, Double_t fdTimeWinBegIn = -100, Double_t fdTimeWinEndIn = 100);
155
156 void SetReferenceDetector(RawEventBuilderDetector refDetIn, std::vector<bool> select = {});
159
160 void SetTriggerMinNumber(ECbmModuleId selDet, UInt_t uVal);
161 void SetTriggerMaxNumber(ECbmModuleId selDet, Int_t iVal);
162 void SetTriggerMinLayersNumber(ECbmModuleId selDet, UInt_t uVal);
163 void SetTriggerWindow(ECbmModuleId selDet, Double_t dWinBeg, Double_t dWinEnd);
164 void SetHistogramMaxDigiNb(ECbmModuleId selDet, Double_t dDigiNbMax);
165 void SetTsParameters(Double_t dTsStartTime, Double_t dTsLength, Double_t dTsOverLength)
166 {
168 fdTsLength = dTsLength;
169 fdTsOverLength = dTsOverLength;
170 fbUseTsMetaData = kFALSE;
171 }
172
173 void SetSeedTimeWindow(Double_t timeWinBeg, Double_t timeWinEnd)
174 {
175 fdSeedTimeWinBeg = timeWinBeg;
176 fdSeedTimeWinEnd = timeWinEnd;
179 }
180
183 void SetIgnoreTsOverlap(Bool_t bFlagIn = kTRUE) { fbIgnoreTsOverlap = bFlagIn; }
184
185 void ChangeMuchBeamtimeDigiFlag(Bool_t bFlagIn = kFALSE) { fbUseMuchBeamtimeDigi = bFlagIn; }
186
188 void AddHistoToVector(TNamed* pointer, std::string sFolder = "")
189 {
190 fvpAllHistoPointers.push_back(std::pair<TNamed*, std::string>(pointer, sFolder));
191 }
192 std::vector<std::pair<TNamed*, std::string>> GetHistoVector() { return fvpAllHistoPointers; }
193 void AddCanvasToVector(TCanvas* pointer, std::string sFolder = "")
194 {
195 fvpAllCanvasPointers.push_back(std::pair<TCanvas*, std::string>(pointer, sFolder));
196 }
197 std::vector<std::pair<TCanvas*, std::string>> GetCanvasVector() { return fvpAllCanvasPointers; }
198
200 void SetDigis(std::vector<CbmBmonDigi>* BmonDigis) { fBmonDigis = BmonDigis; }
201 void SetDigis(std::vector<CbmStsDigi>* StsDigis) { fStsDigis = StsDigis; }
202 void SetDigis(std::vector<CbmMuchDigi>* MuchDigis)
203 {
204 fMuchDigis = MuchDigis;
205 fbUseMuchBeamtimeDigi = kFALSE;
206 }
207 void SetDigis(std::vector<CbmTrdDigi>* TrdDigis) { fTrdDigis = TrdDigis; }
208 void SetDigis(std::vector<CbmTofDigi>* TofDigis) { fTofDigis = TofDigis; }
209 void SetDigis(std::vector<CbmRichDigi>* RichDigis) { fRichDigis = RichDigis; }
210 void SetDigis(std::vector<CbmPsdDigi>* PsdDigis) { fPsdDigis = PsdDigis; }
211 void SetDigis(std::vector<CbmFsdDigi>* FsdDigis) { fFsdDigis = FsdDigis; }
212 void SetDigis(std::vector<CbmMuchBeamTimeDigi>* MuchBeamTimeDigis)
213 {
214 fMuchBeamTimeDigis = MuchBeamTimeDigis;
215 fbUseMuchBeamtimeDigi = kTRUE;
216 }
217
218 void SetSeedTimes(std::vector<Double_t>* SeedTimes) { fSeedTimes = SeedTimes; }
219
220 // TS metadata
221 void SetTimeSliceMetaDataArray(TClonesArray* TimeSliceMetaDataArray)
222 {
223 fTimeSliceMetaDataArray = TimeSliceMetaDataArray;
224 }
225
226 // Output folder for histograms
227 TDirectoryFile* GetOutFolder() { return outFolder; }
228
230 std::vector<CbmEvent*>& GetEventVector() { return fEventVector; }
231 void ClearEventVector();
232
233 private:
236 void InitTs();
237 void InitSeedWindow();
238 void BuildEvents();
239
240 void CreateHistograms();
241 void FillHistos();
242
243 template<class DigiSeed>
244 void LoopOnSeeds();
245
246 void CheckSeed(Double_t dSeedTime, UInt_t uSeedDigiIdx);
247 void CheckTriggerCondition(Double_t dSeedTime);
248
249 template<class DigiCheck>
250 void SearchMatches(Double_t dSeedTime, RawEventBuilderDetector& detMatch);
251 void SearchMatches(Double_t dSeedTime, RawEventBuilderDetector& detMatch);
252 void AddDigiToEvent(const RawEventBuilderDetector& det, Int_t uIdx);
253 Bool_t HasTrigger(CbmEvent*);
255
258
259 void SwitchBmonStation(int id, bool on = true);
260 bool SetBmonEventTime(CbmEvent* event);
261
262 void CheckBmonInUse();
263
268 bool filterBmon(int32_t add);
270
271 TDirectoryFile* outFolder; // oputput folder to store histograms
272
274 static constexpr Double_t kdDefaultTimeWinBeg = -100.0;
275 static constexpr Double_t kdDefaultTimeWinEnd = 100.0;
276
279 Bool_t fbIgnoreTsOverlap = kFALSE;
280 Bool_t fbFillHistos{kTRUE};
281 Bool_t fbUseMuchBeamtimeDigi = kTRUE;
282 Bool_t fbGetTimings = kFALSE;
283 Bool_t fbUseTsMetaData = kTRUE;
284 std::vector<bool> fUseBmonMap = {};
285
288
289 TStopwatch* fTimer = nullptr;
290
295 bool fbBmonInUse = false;
296
301 Double_t fdSeedWindowBeg = 0;
302 Double_t fdSeedWindowEnd = 0;
303
304 Double_t fdTsStartTime = -1;
305 Double_t fdTsLength = -1;
306 Double_t fdTsOverLength = -1;
307
309 TClonesArray* fTimeSliceMetaDataArray = nullptr;
310
311 const std::vector<CbmBmonDigi>* fBmonDigis = nullptr;
312 const std::vector<CbmMuchDigi>* fMuchDigis = nullptr;
313 const std::vector<CbmMuchBeamTimeDigi>* fMuchBeamTimeDigis = nullptr;
314 const std::vector<CbmStsDigi>* fStsDigis = nullptr;
315 const std::vector<CbmTrdDigi>* fTrdDigis = nullptr;
316 const std::vector<CbmTofDigi>* fTofDigis = nullptr;
317 const std::vector<CbmRichDigi>* fRichDigis = nullptr;
318 const std::vector<CbmPsdDigi>* fPsdDigis = nullptr;
319 const std::vector<CbmFsdDigi>* fFsdDigis = nullptr;
320
321 // If explicit seed times are supplied.
322 const std::vector<Double_t>* fSeedTimes = nullptr;
323 Double_t fdSeedTimeWinBeg = -100.0;
324 Double_t fdSeedTimeWinEnd = 100.0;
325
327 UInt_t GetNofDigis(ECbmModuleId detId);
328 template<class Digi>
329 const Digi* GetDigi(UInt_t uDigi);
330 uint64_t GetSizeFromDigisNb(ECbmModuleId detId, uint64_t ulNbDigis);
331
332 Double_t GetSeedTimeWinRange();
333
336 std::vector<CbmEvent*> fEventVector = {};
337
349 std::vector<std::pair<TNamed*, std::string>>
351 std::vector<std::pair<TCanvas*, std::string>>
353
354 TH1* fhEventTime = nullptr;
355 TH1* fhEventDt = nullptr;
356 TH1* fhEventSize = nullptr;
357 TH2* fhNbDigiPerEvtTime = nullptr;
358 TH1* fhCpuTimePerTs = nullptr;
359 TH1* fhRealTimePerTs = nullptr;
360
361 TH1* fhCpuTimePerTsHist = nullptr;
362 TH1* fhRealTimePerTsHist = nullptr;
363
364 std::vector<TH2*> fvhNbDigiPerEvtTimeDet =
365 {};
366 std::vector<TH1*> fvhNbDigiPerEvtDet = {};
367 std::vector<TH1*> fvhTDiff = {}; // digi time difference to seed
368
369 std::vector<TH1*> fvhSelRatioPerTsNb = {};
370 std::vector<TH1*> fvhInpRatioPerTsSz = {};
371 std::vector<TH1*> fvhOutRatioPerTsSz = {};
372 TH1* fhSizeReductionPerTs = nullptr;
373
374 TH1* fhOverEventShare = nullptr;
375 TProfile* fhOverEventShareTs = nullptr;
376 TH2* fhOverEventSizeTs = nullptr;
377
379 UInt_t fuCurEv = 0;
380 UInt_t fuNrTs = 0;
381 Double_t fdPrevEvtTime = 0.;
382 Double_t fdPrevEvtEndTime = 0.;
383
385};
386
387#endif // CBMALGOBUILDRAWEVENTS_H
static const RawEventBuilderDetector kRawEventBuilderDetSts
Pre-defined detector types.
static const RawEventBuilderDetector kRawEventBuilderDetTrd2D
static const RawEventBuilderDetector kRawEventBuilderDetBmon
static const RawEventBuilderDetector kRawEventBuilderDetFsd
static const RawEventBuilderDetector kRawEventBuilderDetTrd
static const RawEventBuilderDetector kRawEventBuilderDetPsd
static const RawEventBuilderDetector kRawEventBuilderDetRich
static const RawEventBuilderDetector kRawEventBuilderDetTof
static const RawEventBuilderDetector kRawEventBuilderDetMuch
static const RawEventBuilderDetector kRawEventBuilderDetUndef
ECbmDataType
Definition CbmDefs.h:90
ECbmModuleId
Definition CbmDefs.h:39
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kNotExist
If not found.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kTrd2d
TRD-FASP Detector (FIXME)
@ kMuch
Muon detection system.
@ kFsd
Forward spectator detector.
@ kRich
Ring-Imaging Cherenkov Detector.
static double dTsStartTime
CbmAlgoBuildRawEvents()=default
Bool_t CheckTriggerConditions(CbmEvent *event, const RawEventBuilderDetector &det)
void SetEventOverlapMode(EOverlapModeRaw mode)
Control flags.
static constexpr Double_t kdDefaultTimeWinBeg
Constants.
void SetTimeSliceMetaDataArray(TClonesArray *TimeSliceMetaDataArray)
void SetDigis(std::vector< CbmStsDigi > *StsDigis)
UInt_t fuCurEv
histogram with size of overlap between evt vs TS index, AllowOverlap only
const std::vector< CbmTrdDigi > * fTrdDigis
const std::vector< CbmBmonDigi > * fBmonDigis
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
void AddDigiToEvent(const RawEventBuilderDetector &det, Int_t uIdx)
TH1 * fhCpuTimePerTsHist
Processing time per TS.
void SetDigis(std::vector< CbmRichDigi > *RichDigis)
std::vector< TH1 * > fvhOutRatioPerTsSz
ratio of input digi size in total input size vs TS in run
void SetHistogramMaxDigiNb(ECbmModuleId selDet, Double_t dDigiNbMax)
int32_t getNofFilteredBmonDigis(CbmEvent *ev)
TH2 * fhOverEventSizeTs
histogram with proportion of overlap evt vs TS index, AllowOverlap only
void SetIgnoreTsOverlap(Bool_t bFlagIn=kTRUE)
uint64_t GetSizeFromDigisNb(ECbmModuleId detId, uint64_t ulNbDigis)
const std::vector< Double_t > * fSeedTimes
EOverlapModeRaw fOverMode
bit map for Bmon trigger. Defined by user
TH2 * fhNbDigiPerEvtTime
histogram with the nb of all digis in the event
std::vector< std::pair< TNamed *, std::string > > fvpAllHistoPointers
vector with all created events
void SetDigis(std::vector< CbmTofDigi > *TofDigis)
std::vector< TH2 * > fvhNbDigiPerEvtTimeDet
Plotting time per TS.
static constexpr Double_t kdDefaultTimeWinEnd
TH1 * fhEventSize
histogram with the interval in seed time of consecutive events
void CheckTriggerCondition(Double_t dSeedTime)
Double_t fdPrevEvtEndTime
Save previous time information.
std::vector< TH1 * > fvhSelRatioPerTsNb
void SetDigis(std::vector< CbmTrdDigi > *TrdDigis)
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()
void SwitchBmonStation(int id, bool on=true)
void ChangeMuchBeamtimeDigiFlag(Bool_t bFlagIn=kFALSE)
Bool_t fbUseMuchBeamtimeDigi
Switch ON/OFF filling of histograms.
const std::vector< CbmTofDigi > * fTofDigis
CbmEvent * fCurrentEvent
Data ouptut.
void SetTsParameters(Double_t dTsStartTime, Double_t dTsLength, Double_t dTsOverLength)
void SetDigis(std::vector< CbmMuchBeamTimeDigi > *MuchBeamTimeDigis)
ClassDefNV(CbmAlgoBuildRawEvents, 2)
Save previous event last digi time information.
void SetSeedTimeWindow(Double_t timeWinBeg, Double_t timeWinEnd)
CbmAlgoBuildRawEvents operator=(const CbmAlgoBuildRawEvents &)=delete
std::vector< RawEventBuilderDetector > fvDets
TH1 * fhCpuTimePerTs
histogram with the nb of all digis per event vs seed time of the events
UInt_t GetNofDigis(ECbmModuleId detId)
void SetDigis(std::vector< CbmFsdDigi > *FsdDigis)
void SetSeedTimes(std::vector< Double_t > *SeedTimes)
UInt_t fuNrTs
Event Counter.
std::vector< std::pair< TCanvas *, std::string > > fvpAllCanvasPointers
Vector of pointers to histograms + optional folder name.
Double_t fdSeedWindowBeg
Seed window.
void RemoveDetector(RawEventBuilderDetector selDet)
void AddDetector(ECbmModuleId selDet, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn=0, Int_t iTriggerMaxDigisIn=-1, Double_t fdTimeWinBegIn=-100, Double_t fdTimeWinEndIn=100)
std::vector< CbmEvent * > fEventVector
pointer to the event which is currently build
TDirectoryFile * GetOutFolder()
Bool_t fbFillHistos
Ignore data in Overlap part of the TS.
std::vector< CbmEvent * > & GetEventVector()
Data output access.
void AddHistoToVector(TNamed *pointer, std::string sFolder="")
For monitor algos.
void SearchMatches(Double_t dSeedTime, RawEventBuilderDetector &detMatch)
TH1 * fhSizeReductionPerTs
ratio of selected digi size in total event size vs TS in run
void SetTriggerMaxNumber(ECbmModuleId selDet, Int_t iVal)
const std::vector< CbmRichDigi > * fRichDigis
TH1 * fhRealTimePerTsHist
Plotting time per TS.
const std::vector< CbmStsDigi > * fStsDigis
TH1 * fhEventTime
Vector of pointers to canvases + optional folder name.
Bool_t fbGetTimings
Switch between MUCH digi classes.
const std::vector< CbmMuchBeamTimeDigi > * fMuchBeamTimeDigis
std::vector< TH1 * > fvhTDiff
histograms with the nb of digis in each detector per event
const std::vector< CbmMuchDigi > * fMuchDigis
void SetDigis(std::vector< CbmPsdDigi > *PsdDigis)
void ResetHistograms(Bool_t bResetTime=kTRUE)
TH1 * fhRealTimePerTs
Processing time per TS.
TProfile * fhOverEventShareTs
histogram with proportion of overlap evt, AllowOverlap only
bool filterBmon(int32_t add)
Filter Bmon stations. Hack added for the mCBM2024 data (AB)
void AddCanvasToVector(TCanvas *pointer, std::string sFolder="")
Bool_t fbUseTsMetaData
Measure CPU time using stopwatch.
std::vector< TH1 * > fvhNbDigiPerEvtDet
histograms with the nb of digis in each detector per event vs seed time of the events
void CheckSeed(Double_t dSeedTime, UInt_t uSeedDigiIdx)
void SetTriggerMinLayersNumber(ECbmModuleId selDet, UInt_t uVal)
Double_t fdPrevEvtTime
Timeslice Counter.
void SetTriggerMinNumber(ECbmModuleId selDet, UInt_t uVal)
TH1 * fhOverEventShare
ratio of total selected size to input size selected vs TS in run
TClonesArray * fTimeSliceMetaDataArray
Data input.
Bool_t CheckDataAvailable(const RawEventBuilderDetector &det)
Internal methods.
void SetDigis(std::vector< CbmBmonDigi > *BmonDigis)
Set digi containers.
void SetReferenceDetector(ECbmModuleId refDet, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn=0, Int_t iTriggerMaxDigisIn=-1, Double_t fdTimeWinBegIn=-100, Double_t fdTimeWinEndIn=100)
bool SetBmonEventTime(CbmEvent *event)
CbmAlgoBuildRawEvents(const CbmAlgoBuildRawEvents &)=delete
const std::vector< CbmPsdDigi > * fPsdDigis
RawEventBuilderDetector fRefDet
is create when fbGetTimings is set before init
void SetTriggerWindow(ECbmModuleId selDet, Double_t dWinBeg, Double_t dWinEnd)
void SetDigis(std::vector< CbmMuchDigi > *MuchDigis)
const Digi * GetDigi(UInt_t uDigi)
const std::vector< CbmFsdDigi > * fFsdDigis
TH1 * fhEventDt
histogram with the seed time of the events
std::vector< bool > fUseBmonMap
Read Ts Parameters from input tree.
std::vector< TH1 * > fvhInpRatioPerTsSz
ratio of selected/input digi vs TS in run
Data class for a signal in the t-zero detector.
Definition CbmBmonDigi.h:30
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
Data class for FSD digital information.
Definition CbmFsdDigi.h:36
Data class for PSD digital information.
Definition CbmPsdDigi.h:36
Data class for a single-channel message in the STS.
Definition CbmStsDigi.h:40
Data class for expanded digital TOF information.
Definition CbmTofDigi.h:47
RawEventBuilderDetector(ECbmModuleId detIdIn, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn, Int_t iTriggerMaxDigisIn, Double_t fdTimeWinBegIn, Double_t fdTimeWinEndIn, UInt_t uTriggerMinLayersIn=0, Double_t fdHistMaxDigiNbIn=1000)
Int_t fiTriggerMaxDigis
Maximum number of digis per detector needed to generate an event, -1 means no cut,...
UInt_t fuTriggerMinLayers
Minimum number of fired layers needed to generate an event, 0 means do not require for event selectio...
RawEventBuilderDetector()=default
RawEventBuilderDetector(ECbmModuleId detIdIn, ECbmDataType dataTypeIn, std::string sNameIn)
ECbmModuleId detId
Settings.
Double_t fdTimeWinBeg
Selection Window.
bool operator!=(const RawEventBuilderDetector &other) const
UInt_t fuTriggerMinDigis
Minimum number of digis per detector needed to generate an event, 0 means do not use for event select...
bool operator==(const RawEventBuilderDetector &other) const
Double_t fdHistMaxDigiNb
Histo configuration.
UInt_t fuStartIndex
Book-keeping variables.