CbmRoot
Loading...
Searching...
No Matches
CbmL1.h
Go to the documentation of this file.
1/* Copyright (C) 2006-2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Ivan Kisel, Sergey Gorbunov, Maksym Zyzak, Valentina Akishina, Igor Kulakov, Denis Bertini [committer], Sergei Zharko */
4
5/*
6 *====================================================================
7 *
8 * CBM Level 1 Reconstruction
9 *
10 * Authors: I.Kisel, S.Gorbunov
11 *
12 * e-mail : ikisel@kip.uni-heidelberg.de
13 *
14 *====================================================================
15 *
16 * CbmL1 header file
17 *
18 *====================================================================
19 */
20
21#ifndef _CbmL1_h_
22#define _CbmL1_h_
23
24#include "CaDataManager.h"
25#include "CaFramework.h"
26#include "CaMcData.h"
27#include "CaMonitor.h"
28#include "CaVector.h"
29#include "CbmCaMCModule.h"
32#include "CbmL1DetectorID.h"
33#include "CbmL1HitId.h"
34#include "CbmL1Track.h"
35#include "KfMaterialMonitor.h"
36#include "KfTrackParam.h"
37
38#include <FairDetector.h>
39#include <FairRootManager.h>
40#include <FairTask.h>
41#include <Logger.h>
42
43#include <TClonesArray.h>
44#include <TH1.h>
45
46#include <boost/functional/hash.hpp>
47
48#include <algorithm>
49#include <fstream>
50#include <iostream>
51#include <map>
52#include <set>
53#include <string_view>
54#include <unordered_map>
55#include <utility>
56
57class CbmMCDataObject;
58class CbmEvent;
59class TProfile2D;
60class TNtuple;
61class TGeoNode;
62
63
64namespace
65{
66 namespace ca = cbm::algo::ca;
67 namespace kf = cbm::algo::kf;
68}
69
73 CbmL1LinkKey(int32_t index, int32_t entry, int32_t file) : fIndex(index), fEntry(entry), fFile(file) {}
74 bool operator==(const CbmL1LinkKey& other) const
75 {
76 return fFile == other.fFile && fEntry == other.fEntry && fIndex == other.fIndex;
77 }
78
79 int32_t fIndex = -1;
80 int32_t fEntry = -1;
81 int32_t fFile = -1;
82};
83
85namespace std
86{
87 template<>
88 struct hash<CbmL1LinkKey> {
89 std::size_t operator()(const CbmL1LinkKey& key) const
90 {
91 std::size_t res = 0;
92 boost::hash_combine(res, key.fFile);
93 boost::hash_combine(res, key.fEntry);
94 boost::hash_combine(res, key.fIndex);
95 return res;
96 }
97 };
98} // namespace std
99
100
101// TODO: insert documentation! (S.Zh.)
102//
105class CbmL1 : public FairTask {
106 public:
107 // **********************
108 // ** Types definition **
109 // **********************
110
111 using DFSET = std::set<std::pair<int, int>>;
112
113 // **************************
114 // ** Friends classes list **
115 // **************************
116
117 friend class L1AlgoDraw;
118 friend class L1AlgoPulls;
119
120 template<int NHits>
122
123 friend class CbmL1PFFitter;
124
125 enum class EInitMode
126 {
129 };
130
131 // **********************************
132 // ** Member functions declaration **
133 // **********************************
134
135 // ** Constructors and destructor **
136
138 CbmL1();
139
148 CbmL1(const char* name, Int_t verbose = 1, Int_t performance = 0);
149
151 CbmL1(const CbmL1&) = delete;
152
154 CbmL1(CbmL1&&) = delete;
155
157 CbmL1& operator=(const CbmL1&) = delete;
158
160 CbmL1& operator=(CbmL1&&) = delete;
161
163 ~CbmL1();
164
166 static CbmL1* Instance() { return fpInstance; }
167
168 // ** Member functions override from FairTask **
169
171 virtual InitStatus Init();
172
174 virtual InitStatus ReInit();
175
177 void Finish();
178
180 const cbm::algo::ca::McData& GetMCData() const { return fMCData; }
181
182 // ** Specific member functions **
183
189 void DisableTrackingStation(ca::EDetectorID detID, int iSt);
190
193 void SetInitMode(EInitMode mode) { fInitMode = mode; }
194
198
200 void SetMaterialBudgetNbins(int nBinsPerDimension) { fMatBudgetNbins = nBinsPerDimension; }
201
203 void SetMaterialBudgetNrays(int nRaysPerDimension) { fMatBudgetNrays = nRaysPerDimension; }
204
206 void SetMaterialBudgetPitch(double pitchCm) { fMatBudgetPitch = pitchCm; }
207
211
214 void SetConfigUser(const char* path) { fsUserConfig = path; }
215
218 void SetParameterFilename(const char* filename) { fSTAPParamFile = TString(filename); }
219
222 void SetSetupFilename(const char* filename) { fSTAPSetupFile = TString(filename); }
223
227 void SetOutputDataDir(const char* dirname) { fSTAPDataDir = TString(dirname); }
228
232 void SetOutputMcTripletsTreeFilename(const char* filename) { fsMcTripletsOutputFilename = std::string(filename); }
233
236 const auto& GetQaHits() const { return fvHitDebugInfo; }
237
239 static constexpr const char* GetDetectorName(ca::EDetectorID detectorID)
240 {
241 switch (detectorID) {
242 case ca::EDetectorID::kMvd: return "MVD";
243 case ca::EDetectorID::kSts: return "STS";
244 case ca::EDetectorID::kMuch: return "MuCh";
245 case ca::EDetectorID::kTrd: return "TRD";
246 case ca::EDetectorID::kTof: return "TOF";
247 case ca::EDetectorID::END: break;
248 }
249 return "";
250 }
251
256
258
259 // void SetTrackingLevel( Int_t iLevel ){ fTrackingLevel = iLevel; }
260 // void MomentumCutOff( Double_t cut ){ fMomentumCutOff = cut; }
261 // void SetDetectorEfficiency( Double_t eff ){ fDetectorEfficiency = eff; }
262
265 void Reconstruct(CbmEvent* event = nullptr);
266
267 static double boundedGaus(double sigma);
268
270
272 void SetMvdMaterialBudgetFileName(const TString&)
273 {
274 LOG(warning) << "CbmL1::SetMvdMaterialBudgetFileName() is obsolete and will be deleted soon, don't call it\n"
275 << " ! The material budget files are not used anymore !";
276 }
277
279 void SetStsMaterialBudgetFileName(const TString&)
280 {
281 LOG(warning) << "CbmL1::SetStsMaterialBudgetFileName() is obsolete and will be deleted soon, don't call it\n"
282 << " ! The material budget files are not used anymore !";
283 }
284
286 void SetMuchMaterialBudgetFileName(const TString&)
287 {
288 LOG(warning) << "CbmL1::SetMuchMaterialBudgetFileName() is obsolete and will be deleted soon, don't call it\n"
289 << " ! The material budget files are not used anymore !";
290 }
291
293 void SetTrdMaterialBudgetFileName(const TString&)
294 {
295 LOG(warning) << "CbmL1::SetTrdMaterialBudgetFileName() is obsolete and will be deleted soon, don't call it\n"
296 << " ! The material budget files are not used anymore !";
297 }
298
300 void SetTofMaterialBudgetFileName(const TString&)
301 {
302 LOG(warning) << "CbmL1::SetTofMaterialBudgetFileName() is obsolete and will be deleted soon, don't call it\n"
303 << " ! The material budget files are not used anymore !";
304 }
305
306 private:
308 TString name, title;
309 int nbins;
310 float xMin, xMax;
311 };
312
314 void IdealTrackFinder();
315
318
319 /*
320 * Input Performance
321 */
322
327 template<ca::EDetectorID DetId>
328 std::tuple<int, std::vector<int>> MatchHitWithMc(int iHit) const;
329
330 void FieldApproxCheck(); // Build histograms with difference between Field map and approximated field
331 void FieldIntegralCheck(); // Build 2D histogram: dependence of the field integral on phi and theta
332 void TimeHist();
333
334 // ********************************
335 // ** Reconstruction Performance **
336 // ********************************
337
340 void SetRandomSeed(unsigned int)
341 {
342 LOG(warn) << "CbmL1::SetRandomSeed(unsigned int) does nothing! Please, remove it from your caller";
343 }
344
346 void EfficienciesPerformance(bool doFinish = kFALSE);
347
350 void TrackFitPerformance();
351
352 void FillFitHistos(cbm::algo::kf::TrackParamV& tr, const cbm::algo::ca::McPoint& mc, bool isTimeFitted, TH1F* h[]);
353
355 void HistoPerformance();
356
360
361
362 // ** STandAlone Package service-functions **
363
372 void DefineSTAPNames();
373
376
380 void WriteSTAPAlgoInputData(int iJob = 0);
381
383
388
389 void ReadSTAPAlgoInputData(int iJob = 0);
390
392
393 void WriteHistosCurFile(TObject* obj);
394
395 static std::istream& eatwhite(std::istream& is); // skip spaces
396 static void writedir2current(TObject* obj); // help procedure
397
398 void DumpMaterialToFile(TString fileName, std::shared_ptr<const cbm::algo::ca::Parameters<double>> par);
399
400 private:
401 // ***************************
402 // ** Member variables list **
403 // ***************************
404
405 std::string fInputDataFilename{};
406 std::string fsUserConfig{};
407
408 std::unique_ptr<cbm::ca::TimeSliceReader> fpTSReader = nullptr;
409 std::unique_ptr<cbm::ca::MCModule> fpMCModule = nullptr;
411
412 std::shared_ptr<ca::DataManager> fpIODataManager = nullptr;
413
414
415 public:
416 // ** Basic data members **
417
419
421
422 ca::Vector<CbmL1Track> fvRecoTracks = {"CbmL1::fvRecoTracks"};
423
424 private:
426
429
430 // TODO: remove
431 double fTargetX{1.e10};
432 double fTargetY{1.e10};
433 double fTargetZ{1.e10};
434
435 int fNStations = 0;
436
438 double fTrackingTime = 0.;
439
448
449 TString fSTAPDataDir = "";
450 TString fSTAPDataPrefix = "test";
451 TString fSTAPParamFile = "";
452 TString fSTAPSetupFile = "";
453
455 static constexpr std::string_view kSTAPParamSuffix = "ca.par";
456 static constexpr std::string_view kSTAPSetupSuffix = "kf.setup";
457
464 static constexpr std::string_view kSTAPAlgoIDataSuffix = "job%d.ca.input.dat";
465
467 static constexpr std::string_view kSTAPAlgoIDataDir = "input_hits";
468
469
470 Int_t fTrackingLevel = 2; // currently not used
471 Double_t fMomentumCutOff = 0.1; // currently not used
472
473 int fEventNo = 0;
475
476 public:
477 // ** Repacked input data **
478
479 ca::Vector<CbmL1HitId> fvExternalHits = {"CbmL1::fvExternalHits"};
480
481 private:
483 "CbmL1::fvMcHitDebugInfo"};
484 // indices of MCPoints in fvMCPoints, indexed by index of hit in algo->vHits array. According to StsMatch. Used for IdealResponce
485 // ca::Vector<int> vHitMCRef1;
486 // CbmMatch HitMatch;
487
489
490 // *****************************
491 // ** Tracking performance QA **
492 // *****************************
493 // TODO: move to a separate class (S.Zharko)
494 TFile* fPerfFile{nullptr};
495 TDirectory* fHistoDir{nullptr};
496 TDirectory* fTableDir{nullptr};
497
498 static const int fNTimeHistos = 22;
499 TH1F* fTimeHisto[fNTimeHistos]{nullptr};
500
501 static const int fNGhostHistos = 9;
502 TH1F* fGhostHisto[fNGhostHistos]{nullptr};
503
504 TFile* fpMcTripletsOutFile = nullptr;
505 TTree* fpMcTripletsTree = nullptr;
506 std::string fsMcTripletsOutputFilename = "";
507
510 double fMatBudgetPitch{0.1};
511
513
516
518
519 std::vector<cbm::algo::kf::MaterialMonitor> fMaterialMonitor{};
520
522};
523
524
525#endif //_CbmL1_h_
Input-output data manager for L1 tracking algorithm.
Data structure for internal tracking MC-information (header)
CA Tracking monitor class.
CA Tracking performance interface for CBM (header)
Time-slice/event reader for CA tracker in CBM (header)
Implementation of L1DetectorID enum class for CBM.
A class to collect statistics for kf::MaterialMap.
int Int_t
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
EInitMode
Definition CbmL1.h:126
@ Param
Parameter initialization (when algorithm execution is not required)
Definition CbmL1.h:128
@ Full
Full initialization (default)
Definition CbmL1.h:127
ClassDef(CbmL1, 0)
std::shared_ptr< ca::DataManager > fpIODataManager
Input-output data manager.
Definition CbmL1.h:412
bool fMatBudgetParallelProjection
Definition CbmL1.h:514
int fNStations
number of total active detector stations
Definition CbmL1.h:435
void SetMvdMaterialBudgetFileName(const TString &)
Obsolete setters to be removed.
Definition CbmL1.h:272
void SetInitMode(EInitMode mode)
Sets initialization mode.
Definition CbmL1.h:193
void SetMaterialBudgetNrays(int nRaysPerDimension)
Sets material budget n rays per dimansion in each bin.
Definition CbmL1.h:203
static CbmL1 * Instance()
Pointer to CbmL1 instance.
Definition CbmL1.h:166
TH1F * fTimeHisto[fNTimeHistos]
Definition CbmL1.h:499
TDirectory * fHistoDir
Definition CbmL1.h:495
friend class L1AlgoEfficiencyPerformance
Definition CbmL1.h:121
void Reconstruct(CbmEvent *event=nullptr)
Definition CbmL1.cxx:312
double fTrackingTime
time of track finding procedure
Definition CbmL1.h:438
std::string fInputDataFilename
File name to read/write input hits.
Definition CbmL1.h:405
std::vector< cbm::algo::kf::MaterialMonitor > fMaterialMonitor
Material monitors for each material budget map.
Definition CbmL1.h:519
static const int fNGhostHistos
Definition CbmL1.h:501
void SetMcbmMode()
Definition CbmL1.h:254
void WriteHistosCurFile(TObject *obj)
void DefineSTAPNames()
Defines names for output in STAP mode.
Definition CbmL1.cxx:562
const auto & GetQaHits() const
Definition CbmL1.h:236
void EfficienciesPerformance(bool doFinish=kFALSE)
Calculates tracking efficiencies (counters)
double fTargetX
target position X
Definition CbmL1.h:431
std::tuple< int, std::vector< int > > MatchHitWithMc(int iHit) const
Matches hit with MC point.
void SetMaterialBudgetNbins(int nBinsPerDimension)
Sets material budget binning.
Definition CbmL1.h:200
TTree * fpMcTripletsTree
Tree to save MC-triplets.
Definition CbmL1.h:505
void SetTrdMaterialBudgetFileName(const TString &)
Sets material budget file name for TRD.
Definition CbmL1.h:293
void SetTofMaterialBudgetFileName(const TString &)
Sets material budget file name for TOF.
Definition CbmL1.h:300
std::string fsMcTripletsOutputFilename
Name of file to save MC-triplets tree.
Definition CbmL1.h:506
static std::istream & eatwhite(std::istream &is)
void Fill_vMCTracks()
Fills the fvMCTracks vector and the fmMCTracksMap.
double fMatBudgetPitch
material budget minimal bin size in cm
Definition CbmL1.h:510
void WriteSTAPParamObject()
Writes initialized L1Parameters object to file "".
void ReadSTAPPerfInputData()
Definition CbmL1.cxx:637
void SetConfigUser(const char *path)
Sets user configuration filename.
Definition CbmL1.h:214
static CbmL1 * fpInstance
Instance of CbmL1.
Definition CbmL1.h:425
cbm::algo::ca::McData fMCData
MC Data object.
Definition CbmL1.h:410
virtual InitStatus Init()
Defines action in the beginning of the run (initialization)
Definition CbmL1.cxx:128
cbm::ca::DetIdArr_t< std::set< int > > fvmDisabledStationIDs
Definition CbmL1.h:488
CbmL1()
Default constructor.
Definition CbmL1.cxx:85
void WriteSTAPAlgoInputData(int iJob=0)
Definition CbmL1.cxx:608
const cbm::algo::ca::McData & GetMCData() const
Gets reference to MC data object.
Definition CbmL1.h:180
void DisableTrackingStation(ca::EDetectorID detID, int iSt)
Disables tracking station for a given detector subsystem.
Definition CbmL1.cxx:111
std::unique_ptr< cbm::ca::MCModule > fpMCModule
MC module.
Definition CbmL1.h:409
void ReadSTAPAlgoInputData(int iJob=0)
Definition CbmL1.cxx:626
int fSTAPDataMode
Option to work with files for the standalone mode.
Definition CbmL1.h:447
ca::Vector< CbmL1HitId > fvExternalHits
Array of hits.
Definition CbmL1.h:479
double fTargetZ
target position Z
Definition CbmL1.h:433
Int_t fPerformance
performance mode: 0 - w\o perf. 1 - L1-Efficiency definition. 2 - QA-Eff.definition
Definition CbmL1.h:437
int fEventNo
Current number of event/TS.
Definition CbmL1.h:473
ca::Framework * fpAlgo
Pointer to the L1 track finder algorithm.
Definition CbmL1.h:418
void FillFitHistos(cbm::algo::kf::TrackParamV &tr, const cbm::algo::ca::McPoint &mc, bool isTimeFitted, TH1F *h[])
CbmL1(const CbmL1 &)=delete
Copy constructor.
TDirectory * fTableDir
Definition CbmL1.h:496
ca::TrackingMonitor fMonitor
Tracking monitor.
Definition CbmL1.h:257
void FieldIntegralCheck()
std::string fsUserConfig
User config path.
Definition CbmL1.h:406
TString fSTAPSetupFile
Name of the setup file (generated automatically, if not provided manually)
Definition CbmL1.h:452
void WriteSTAPPerfInputData()
Definition CbmL1.cxx:619
friend class CbmL1PFFitter
Definition CbmL1.h:123
static constexpr std::string_view kSTAPParamSuffix
Extension for IO of the L1Parameters object.
Definition CbmL1.h:455
EInitMode fInitMode
Initialization mode.
Definition CbmL1.h:512
ca::Vector< CbmL1Track > fvRecoTracks
Reconstructed tracks container.
Definition CbmL1.h:422
static constexpr std::string_view kSTAPAlgoIDataDir
Name of subdirectory for handling ca::InputData objects.
Definition CbmL1.h:467
bool fDoSafeMaterialInitialization
Definition CbmL1.h:427
friend class L1AlgoPulls
Definition CbmL1.h:118
void IdealTrackFinder()
Runs ideal track finder: copies all MC-tracks into reconstructed tracks.
Definition CbmL1.cxx:506
void SetParameterFilename(const char *filename)
Sets a name for the ca-parameter file.
Definition CbmL1.h:218
void SetOutputMcTripletsTreeFilename(const char *filename)
Sets output file for MC triplets tree If the filename is empty string, tree is not filled.
Definition CbmL1.h:232
void TrackFitPerformance()
double fTargetY
target position Y
Definition CbmL1.h:432
TString fSTAPParamFile
Name of the parameter file (generated automatically, if not provided manually)
Definition CbmL1.h:451
TFile * fPerfFile
Array of local indices of disabled tracking stations.
Definition CbmL1.h:494
Double_t fMomentumCutOff
Definition CbmL1.h:471
void Finish()
Defines action in the end of the run (saves results)
Definition CbmL1.cxx:414
CbmL1 & operator=(CbmL1 &&)=delete
Move assignment operator.
TString fSTAPDataPrefix
Name of input/output file prefix. The prefix is defined by output TTree file.
Definition CbmL1.h:450
friend class L1AlgoDraw
Definition CbmL1.h:117
void DumpMaterialToFile(TString fileName, std::shared_ptr< const cbm::algo::ca::Parameters< double > > par)
Definition CbmL1.cxx:644
void SetRandomSeed(unsigned int)
Sets random seed to CA internal random generator.
Definition CbmL1.h:340
CbmL1 & operator=(const CbmL1 &)=delete
Copy assignment operator.
CbmL1(CbmL1 &&)=delete
Move constructor.
bool fExtrapolateToTheEndOfSTS
Definition CbmL1.h:517
Int_t fTrackingLevel
Definition CbmL1.h:470
int fMatBudgetNbins
n bins in mat budget maps (fMatBudgetNbins x fMatBudgetNbins)
Definition CbmL1.h:508
ca::TrackingMode fTrackingMode
Tracking mode.
Definition CbmL1.h:420
void SetSafeMaterialInitialization(bool val=true)
Definition CbmL1.h:197
void SetStsOnlyMode()
Definition CbmL1.h:253
void SetGlobalMode()
Definition CbmL1.h:255
void DumpMCTripletsToTree()
std::unique_ptr< cbm::ca::TimeSliceReader > fpTSReader
event/TS reader
Definition CbmL1.h:408
void TimeHist()
static constexpr const char * GetDetectorName(ca::EDetectorID detectorID)
Utility to map the L1DetectorID items into detector names.
Definition CbmL1.h:239
std::set< std::pair< int, int > > DFSET
Definition CbmL1.h:111
~CbmL1()
Destructor.
Definition CbmL1.cxx:104
void SetMaterialBudgetParallelProjection()
Definition CbmL1.h:210
static constexpr std::string_view kSTAPSetupSuffix
Definition CbmL1.h:456
int fMatBudgetNrays
material budget n rays per dimansion in each bin
Definition CbmL1.h:509
void HistoPerformance()
Fills performance histograms.
void SetMaterialBudgetPitch(double pitchCm)
Sets material budget minimal bin size in cm.
Definition CbmL1.h:206
void ReadSTAPParamObject()
TString fSTAPDataDir
Name of input/output directory for running in a STAP mode.
Definition CbmL1.h:449
ca::Vector< cbm::algo::ca::McHitInfo > fvHitDebugInfo
Container of hits with extended information.
Definition CbmL1.h:482
void FieldApproxCheck()
TH1F * fGhostHisto[fNGhostHistos]
Definition CbmL1.h:502
void SetExtrapolateToTheEndOfSTS(bool b)
Definition CbmL1.h:252
void SetMuchMaterialBudgetFileName(const TString &)
Sets material budget file name for MuCh.
Definition CbmL1.h:286
static void writedir2current(TObject *obj)
Definition CbmL1.cxx:488
static constexpr std::string_view kSTAPAlgoIDataSuffix
Definition CbmL1.h:464
int fNofRecoTracks
Total number of reconstructed tracks.
Definition CbmL1.h:474
static const int fNTimeHistos
Definition CbmL1.h:498
void SetStsMaterialBudgetFileName(const TString &)
Sets material budget file name for STS.
Definition CbmL1.h:279
void SetSetupFilename(const char *filename)
Sets a name for the kf-setup file.
Definition CbmL1.h:222
void SetOutputDataDir(const char *dirname)
Sets a name for parameters output dir.
Definition CbmL1.h:227
static double boundedGaus(double sigma)
virtual InitStatus ReInit()
Reruns the initialization.
Definition CbmL1.cxx:120
TFile * fpMcTripletsOutFile
File to save MC-triplets tree.
Definition CbmL1.h:504
Access to a MC data branch for time-based analysis.
Data class with information on a STS local track.
This class represents a package for tracking-related data.
Definition CaMcData.h:33
Class describes a unified MC-point, used in CA tracking QA analysis.
Definition CaMcPoint.h:33
A container for all external parameters of the CA tracking algorithm.
A monitor specialization for cbm::algo::ca::Framework class.
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
Definition CbmDefs.h:216
TrackParam< fvec > TrackParamV
cbm::core::EnumArray< ca::EDetectorID, T > DetIdArr_t
Alias to array, indexed by L1DetectorID enum.
Hash for CbmL1LinkKey.
Internal structure to handle link keys.
Definition CbmL1.h:71
int32_t fFile
index of link file
Definition CbmL1.h:81
int32_t fEntry
index of link entry
Definition CbmL1.h:80
int32_t fIndex
index of point/track, saved to link
Definition CbmL1.h:79
CbmL1LinkKey(int32_t index, int32_t entry, int32_t file)
Constructor from links.
Definition CbmL1.h:73
bool operator==(const CbmL1LinkKey &other) const
Definition CbmL1.h:74
std::size_t operator()(const CbmL1LinkKey &key) const
Definition CbmL1.h:89