CbmRoot
Loading...
Searching...
No Matches
CaInitManager.h
Go to the documentation of this file.
1/* Copyright (C) 2021-2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov, Sergei Zharko [committer] */
4
9
10#pragma once // include this header only once per compilation unit
11
12#include "CaDefs.h"
13#include "CaIteration.h"
15#include "CaParameters.h"
16#include "CaSimd.h"
18#include "KfFieldRegion.h"
19
20#include <array>
21#include <bitset>
22#include <memory> //unique_ptr
23#include <numeric>
24#include <set>
25#include <string>
26#include <type_traits>
27#include <unordered_map>
28
29namespace cbm::algo::ca
30{
35 enum class EDetectorID;
36} // namespace cbm::algo::ca
37
39template<>
40struct std::hash<cbm::algo::ca::EDetectorID> {
41 int operator()(cbm::algo::ca::EDetectorID t) const { return static_cast<int>(t); }
42};
43
44namespace cbm::algo::ca
45{
47 using DetectorID_t = std::underlying_type_t<EDetectorID>;
48
56 class InitManager {
57 private:
59 enum class EInitKey
60 {
61 // NOTE: Please, keep the numbers of the enumeration items in the existing order: it helps to debug the
62 // initialization with this->GetObjectInitController().ToString() method call (S.Zharko)
74 kEnd
75 };
76
77 using DetectorIDIntMap_t = std::unordered_map<EDetectorID, int>;
78 using DetectorIDSet_t = std::set<EDetectorID>;
79 using FieldFunction_t = std::function<void(const double (&xyz)[3], double (&B)[3])>;
81 template<typename T>
82 using DetectorIDArr_t = std::array<T, constants::size::MaxNdetectors>;
83
84 public:
86 InitManager() = default;
87
89 ~InitManager() = default;
90
92 InitManager(const InitManager& /*other*/) = delete;
93
95 InitManager(InitManager&& /*other*/) = delete;
96
98 InitManager& operator=(const InitManager& /*other*/) = delete;
99
101 InitManager& operator=(InitManager&& /*other*/) = delete;
102
106 void AddStation(const StationInitializer& station);
107
109 void CheckInit();
110
112 void ClearCAIterations();
113
115 void ClearSetupInfo();
116
120
124 const std::string& GetDetectorName(EDetectorID detId) const { return fvDetectorNames[static_cast<int>(detId)]; }
125
127 int GetGhostSuppression() const { return fParameters.fGhostSuppression; }
128
130 const std::string& GetInputConfigMain() const { return fsConfigInputMain; }
131
133 const std::string& GetInputConfigUser() const { return fsConfigInputMain; }
134
137
139 int GetNstationsActive() const;
140
142 int GetNstationsActive(EDetectorID detectorID) const;
143
145 int GetNstationsGeometry() const;
146
148 int GetNstationsGeometry(EDetectorID detectorID) const;
149
151 const std::string& GetOutputConfigName() const { return fConfigOutputName; }
152
154 std::vector<StationInitializer>& GetStationInfo();
155
161 void InitStationLayout();
162
165 void InitTargetField(double zStep);
166
168 bool IsActive(EDetectorID detectorID) const { return GetNstationsActive(detectorID) != 0; }
169
171 bool IsPresent(EDetectorID detectorID) const { return GetNstationsGeometry(detectorID) != 0; }
172
174 void PushBackCAIteration(const Iteration& iteration);
175
177 void PushBackCAIteration(const Iteration* pIteration) { PushBackCAIteration(*pIteration); }
178
180 void PushBackCAIteration(const std::unique_ptr<Iteration>& puIteration) { PushBackCAIteration(*puIteration); }
181
183 void ReadInputConfigs();
184
187 void ReadGeometrySetup(const std::string& fileName);
188
191 void ReadParametersObject(const std::string& fileName);
192
195 void ReadSearchWindows(const std::string& fileName);
196
198 // TODO: remove this method
199 void SetCAIterationsNumberCrosscheck(int nIterations);
200
205 void SetConfigMain(const std::string& mainConfig) { fsConfigInputMain = mainConfig; }
206
210 void SetConfigUser(const std::string& userConfig) { fsConfigInputUser = userConfig; }
211
214 template<size_t Size>
215 void SetDetectorNames(const std::array<const char*, Size>& container)
216 {
217 static_assert(Size <= constants::size::MaxNdetectors,
218 "Please, be ensured that the constants::size::MaxNdetectors is not lower then the "
219 "EDetectorID::kEND value, provided by your setup");
220 std::copy(container.begin(), container.end(), fvDetectorNames.begin());
221 }
222
224 void SetFieldFunction(const FieldFunction_t& fieldFcn);
225
227 void SetGhostSuppression(int ghostSuppression);
228
233 void SetOutputConfigName(const std::string& filename) { fConfigOutputName = filename; }
234
238 void SetRandomSeed(unsigned int seed);
239
240 // TODO: Use kf::Setup instead
245 void SetTargetPosition(double x, double y, double z);
246
248 void SetMaxDoubletsPerSinglet(unsigned int value) { fParameters.fMaxDoubletsPerSinglet = value; }
249
251 void SetMaxTripletPerDoublets(unsigned int value) { fParameters.fMaxTripletPerDoublets = value; }
252
255 template<typename DataT>
257 {
259 std::stringstream msg;
260 msg << "ca::InitManager: setup cannot be set until the station layout is initialized";
261 throw std::runtime_error(msg.str());
262 }
263 fParameters.fGeometrySetup = kf::Setup<fvec>(setup);
264 fParameters.fActiveSetup = fParameters.fGeometrySetup;
265 // A sequence of the last inactive materials will be anyway thrown away, so it is more effective to
266 // loop over stations downstream
267 for (int iStGeo = setup.GetNofLayers() - 1; iStGeo >= 0; --iStGeo) {
268 auto [detID, locID] = fParameters.GetStationIndexLocal(iStGeo);
269 int iStActive = fParameters.GetStationIndexActive(locID, detID);
270 if (iStActive < 0) {
271 fParameters.fActiveSetup.DisableLayer(detID, locID);
272 }
273 }
274 LOG(info) << "Geometry setup:" << fParameters.fGeometrySetup.ToString(1);
275 LOG(info) << "Active setup:" << fParameters.fActiveSetup.ToString(1);
277 }
278
284 void SetMisalignmentTolerance(EDetectorID detectorId, double x, double y, double t)
285 {
286 fParameters.fMisalignmentX[static_cast<int>(detectorId)] = x;
287 fParameters.fMisalignmentY[static_cast<int>(detectorId)] = y;
288 fParameters.fMisalignmentT[static_cast<int>(detectorId)] = t;
289 }
290
293 void SetDefaultMass(double mass) { fParameters.fDefaultMass = mass; }
294
298
301 void WriteParametersObject(const std::string& fileName) const;
302
303 // ***************************
304 // ** Flags for development **
305 // ***************************
306
308 void DevSetIgnoreHitSearchAreas(bool value = true) { fParameters.fDevIsIgnoreHitSearchAreas = value; }
309
311 void DevSetUseOfOriginalField(bool value = true) { fParameters.fDevIsUseOfOriginalField = value; }
312
314 void DevSetIsMatchDoubletsViaMc(bool value = true) { fParameters.fDevIsMatchDoubletsViaMc = value; }
315
317 void DevSetIsMatchTripletsViaMc(bool value = true) { fParameters.fDevIsMatchTripletsViaMc = value; }
318
320 void DevSetIsExtendTracksViaMc(bool value = true) { fParameters.fDevIsExtendTracksViaMc = value; }
321
323 void DevSetIsSuppressOverlapHitsViaMc(bool value = true) { fParameters.fDevIsSuppressOverlapHitsViaMc = value; }
324
328 void DevSetIsParSearchWUsed(bool value = true) { fParameters.fDevIsParSearchWUsed = value; }
329
330 private:
334
338
340 void ClearStationLayout();
341
344
345 double fTargetZ{0.};
346
347 std::vector<StationInitializer> fvStationInfo{};
348
350 FieldFunction_t fFieldFunction{[](const double (&)[3], double (&)[3]) {}};
351 // NOTE: Stations of the detectors which are not assigned as active, are not included in the tracking!
352
353 // TODO: remove
355
357 // TODO: With a separate KF-framework instance we need to figure it out, how to store and read the corresponding
358 // parameters (essential for the online reconstruction!!!)
359
360 std::string fsConfigInputMain = "";
361 std::string fsConfigInputUser = "";
362 std::string fConfigOutputName = "";
363
364 bool fbConfigIsRead = false;
365 bool fbGeometryConfigLock = false;
366 };
367
368
369} // namespace cbm::algo::ca
Compile-time constants definition for the CA tracking algorithm.
An interface for the CA Station object initialization.
Magnetic flux density interpolation along the track vs. z-coordinate (header)
A CA Parameters object initialization class.
InitManager(const InitManager &)=delete
Copy constructor is forbidden.
std::vector< StationInitializer > & GetStationInfo()
Gets a reference to the stations array.
void SetTargetPosition(double x, double y, double z)
Sets target position.
void ClearStationLayout()
Returns station layout into undefined condition.
InitManager & operator=(InitManager &&)=delete
Move assignment operator is forbidden.
void SetConfigUser(const std::string &userConfig)
Sets user configuration file.
void SetFieldFunction(const FieldFunction_t &fieldFcn)
Sets a magnetic field function, which will be applied for all the stations.
InitController_t fInitController
Initialization flags.
void ReadSearchWindows(const std::string &fileName)
Reads search windows from file.
void InitTargetField(double zStep)
Calculates kf::FieldValue and L1FieldReference values for a selected step in z-axis from the target p...
Parameters< fvec > fParameters
CA parameters object.
int fCAIterationsNumberCrosscheck
Number of iterations to be passed (must be used for cross-checks)
bool fbConfigIsRead
Flag, if configuration file was read.
void SetCAIterationsNumberCrosscheck(int nIterations)
Sets a number of CA track finder iterations to provide initialization cross-check.
void SetConfigMain(const std::string &mainConfig)
Sets base configuration file.
~InitManager()=default
Destructor.
void ReadGeometrySetup(const std::string &fileName)
Reads geometry setup from file.
int GetNstationsGeometry() const
Gets total number of stations, provided by setup geometry.
InitManager & operator=(const InitManager &)=delete
Copy assignment operator is forbidden.
void ClearCAIterations()
Clears vector of CA track finder iterations.
InitManager(InitManager &&)=delete
Move constructor is forbidden.
void DevSetIsExtendTracksViaMc(bool value=true)
Flag to match triplets using Mc information.
void InitStationLayout()
Initializes station layout.
Parameters< fvec > && TakeParameters()
Takes parameters object from the init-manager instance.
bool fbGeometryConfigLock
Lock geometry initialization.
void SetGeometrySetup(const cbm::algo::kf::Setup< DataT > &setup)
Sets setup.
void SetDefaultMass(double mass)
Sets default fitter mass.
void ReadParametersObject(const std::string &fileName)
Reads parameters object from boost-serialized binary file.
void SetMaxDoubletsPerSinglet(unsigned int value)
Sets upper-bound cut on max number of doublets per one singlet.
bool IsPresent(EDetectorID detectorID) const
Checks, if the detector is present in the geometry.
std::function< void(const double(&xyz)[3], double(&B)[3])> FieldFunction_t
void SetGhostSuppression(int ghostSuppression)
Sets the flag to enable/disable the ghost suppression routine.
std::set< EDetectorID > DetectorIDSet_t
void CheckCAIterationsInit()
Checker for Iteration container initialization (sets EInitKey::kCAIterations)
void ClearSetupInfo()
Clears vector of base setup.
void DevSetIsMatchTripletsViaMc(bool value=true)
Flag to match triplets using Mc information.
void WriteParametersObject(const std::string &fileName) const
Writes parameters object from boost-serialized binary file.
const InitController_t & GetInitController() const
Gets a const reference to ca::ObjectInitController.
double fTargetZ
Target position z component in double precision.
void PushBackCAIteration(const Iteration *pIteration)
Pushes an CA track finder iteration into a sequence of iteration using raw pointer.
void SetRandomSeed(unsigned int seed)
Sets pseudo-random numbers generator seed.
std::string fsConfigInputMain
name for the input configuration file
void ReadInputConfigs()
Reads main and user parameters configs.
void DevSetUseOfOriginalField(bool value=true)
Force use of the original field (not approximated)
FieldFunction_t fFieldFunction
A function which returns magnetic field vector B in a radius-vector xyz.
bool IsActive(EDetectorID detectorID) const
Checks, if the detector is active.
void SetDetectorNames(const std::array< const char *, Size > &container)
Sets detector names.
int GetNstationsActive() const
Gets total number of active stations.
void DevSetIsMatchDoubletsViaMc(bool value=true)
Flag to match doublets using MC information.
void DevSetIgnoreHitSearchAreas(bool value=true)
Ignore hit search areas.
void DevSetIsParSearchWUsed(bool value=true)
Flag to use estimated hit search windows.
void PushBackCAIteration(const Iteration &iteration)
Pushes an CA track finder iteration into a sequence of iteration using reference.
const std::string & GetDetectorName(EDetectorID detId) const
Gets name of the detector.
std::vector< StationInitializer > fvStationInfo
Vector of StationInitializer objects (active + inactive)
void SetMisalignmentTolerance(EDetectorID detectorId, double x, double y, double t)
Sets misalignment parameters in X direction.
std::unordered_map< EDetectorID, int > DetectorIDIntMap_t
const std::string & GetOutputConfigName() const
Gets a name of the output configuration file.
void AddStation(const StationInitializer &station)
Adds a tracking station to the geometry.
void CheckInit()
Provides final checks of the parameters object.
EInitKey
Init-controller key set.
@ kSearchWindows
6) If the hit search windows were initialized
@ kEnd
11) [technical] number of entries in the enumeration
@ kFieldFunction
0) If magnetic field getter function is set
@ kTargetPos
1) If target position was defined
@ kSetupInitialized
10) If KF-setup initialized
@ kCAIterationsNumberCrosscheck
4) If the number of CA track finder is initialized
@ kStationLayoutInitialized
9) If stations layout is initialized
@ kRandomSeed
8) If the random seed is provided
@ kStationsInfo
3) If all the planned stations were added to the manager
@ kPrimaryVertexField
2) If magnetic field value and region defined at primary vertex
@ kCAIterations
5) If the CA track finder iterations were initialized
DetectorIDArr_t< std::string > fvDetectorNames
Names of the detectors.
bool FormParametersContainer()
Forms parameters container.
void PushBackCAIteration(const std::unique_ptr< Iteration > &puIteration)
Pushes an CA track finder iteration into a sequence of iteration using std::unique_ptr.
const std::string & GetInputConfigMain() const
Gets a name of the main input configuration file.
std::string fConfigOutputName
name for the output configuration file
int GetGhostSuppression() const
Gets ghost suppression flag.
void CheckStationsInfoInit()
Checker for StationInitializer set initialization (sets EInitKey::kStationsInfo)
InitManager()=default
Default constructor.
std::string fsConfigInputUser
name for the input configuration file
const std::string & GetInputConfigUser() const
Gets a name of the user input configuration file.
void DevSetIsSuppressOverlapHitsViaMc(bool value=true)
Flag to match triplets using Mc information.
std::array< T, constants::size::MaxNdetectors > DetectorIDArr_t
void SetMaxTripletPerDoublets(unsigned int value)
Sets upper-bound cut on max number of triplets per one doublet.
void SetOutputConfigName(const std::string &filename)
Sets a name of the output configuration file.
A set of parameters for the CA Track finder iteration.
bool GetFlag(InitKeyEnum bitKey) const
void SetFlag(InitKeyEnum bitKey, bool newStatus=true)
A container for all external parameters of the CA tracking algorithm.
A base class which provides interface to L1Algo station geometry.
KF-framework representation of the detector setup.
Definition KfSetup.h:33
int GetNofLayers() const
Gets number of geometry layers.
Definition KfSetup.h:101
constexpr int MaxNdetectors
Max number of tracking detectors.
Definition CaDefs.h:43
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14
std::underlying_type_t< EDetectorID > DetectorID_t
Underlying integer type for the DetectorID.
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
Definition CbmDefs.h:176
int operator()(cbm::algo::ca::EDetectorID t) const