CbmRoot
Loading...
Searching...
No Matches
CaParameters.h
Go to the documentation of this file.
1/* Copyright (C) 2021-2022 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 "CaConfig.h"
13#include "CaDefs.h"
14#include "CaIteration.h"
16#include "CaSetup.h"
17#include "CaVector.h"
18#include "KfFieldRegion.h"
19#include "KfSetup.h"
20
21#include <boost/archive/binary_iarchive.hpp>
22#include <boost/archive/binary_oarchive.hpp>
23#include <boost/serialization/array.hpp>
24#include <boost/serialization/utility.hpp>
25
26#include <array>
27#include <numeric>
28#include <type_traits>
29#include <utility>
30
31namespace cbm::algo::ca
32{
33 enum class EDetectorID;
34
35 using constants::Undef;
36
39
40 // FIXME: Remove TrackingMode (at least)
47
51 template<typename DataT>
52 class alignas(constants::misc::Alignment) Parameters {
53 friend class ParametersIO;
54
55 using DetectorID_t = std::underlying_type_t<EDetectorID>;
56 template<typename T>
57 using StationArray_t = std::array<T, constants::size::MaxNstations>;
58
59 public:
61 Parameters() = default;
62
67 Parameters(ca::Setup<DataT>&& setup, ca::Config&& config, SearchWindowMapContainer&& searchWindows);
68
70 template<typename DataIn>
72 : fSetup(other.GetSetup())
73 , fConfig(other.GetConfig())
74 , fSwMaps(other.GetSearchWindows())
75 {
76 }
77
79 Parameters(const Parameters& other) = default;
80
82 ~Parameters() noexcept = default;
83
85 Parameters(Parameters&& other) = default;
86
88 Parameters& operator=(const Parameters& other) = default;
89
91 Parameters& operator=(Parameters&& other) = default;
92
94 void Print(int verbosityLevel = 0) const;
95
99 std::string ToString(int verbosity = 0, int indentLevel = 0) const;
100
102 kf::EFieldMode GetFieldMode() const { return fSetup.GetGeometrySetup().GetField().GetFieldMode(); }
103
105 int GetNstationsActive() const { return fSetup.GetNofActStations(); }
106
108 int GetNstationsActive(EDetectorID detId) const { return fSetup.GetNofActStations(detId); }
109
111 int GetNstationsGeometry() const { return fSetup.GetNofGeoStations(); }
112
114 int GetNstationsGeometry(EDetectorID detId) const { return fSetup.GetNofGeoStations(detId); }
115
117 //const std::array<int, constants::size::MaxNdetectors + 1>& GetFirstGeoId() const { return fvFirstGeoId; }
118
122 [[gnu::always_inline]] std::pair<EDetectorID, int> GetStationIndexLocal(int geoId) const
123 {
124 return fSetup.GeoToLocStationId(geoId);
125 }
126
128 //const StationArray_t<std::pair<EDetectorID, int>>& GetGeoToLocalIdMap() const { return fvGeoToLocalIdMap; }
129
133 // TODO: remove function
134 [[gnu::always_inline]] int GetStationIndexGeometry(int locId, EDetectorID detId) const
135 {
136 if (locId >= GetNstationsGeometry(detId)) {
137 return -1;
138 }
139 return fSetup.LocToGeoStationId(detId, locId);
140 }
141
143 //const StationArray_t<int>& GetLocalToGeoIdMap() const { return fvLocalToGeoIdMap; }
144
148 [[gnu::always_inline]] int GetStationIndexActive(int locId, EDetectorID detId) const
149 {
150 return fSetup.LocToActStationId(detId, locId);
151 }
152
154 const auto& GetCAIterations() const { return fConfig.GetIterations(); }
155
157 int GetNcaIterations() const { return fConfig.GetIterations().size(); }
158
160 const auto& GetActiveSetup() const { return fSetup.GetActiveSetup(); }
161
163 const auto& GetGeometrySetup() const { return fSetup.GetGeometrySetup(); }
164
167 bool IsActive(EDetectorID detId) const { return GetNstationsActive(detId) != 0; }
168
170 void CheckConsistency() const;
171
173 const Setup<DataT>& GetSetup() const { return fSetup; }
174
176 const Config& GetConfig() const { return fConfig; }
177
180
181 private:
185
188 template<class Archive>
189 void serialize(Archive& ar, const unsigned int)
190 {
191 ar& fSetup;
192 ar& fConfig;
193 ar& fSwMaps;
194 }
195 };
196
197
202 ~ParametersIO() = delete;
203
206 template<typename Float>
207 static Parameters<Float> Load(const std::string& fileName);
208
212 static void Store(const Parameters<double>& parameters, const std::string& fileName);
213 };
214
215 //* Template methods implementation
216
217 // -------------------------------------------------------------------------------------------------------------------
218 //
219 template<typename Float>
220 Parameters<Float> ParametersIO::Load(const std::string& fileName)
221 {
222 Parameters<double> parameters;
223 std::ifstream ifs(fileName, std::ios::binary);
224 if (!ifs) {
225 throw std::runtime_error(fmt::format("ca::ParametersIO::Load: intput setup file \"{}\" was not found", fileName));
226 }
227 try {
228 boost::archive::binary_iarchive ia(ifs);
229 ia >> parameters;
230 }
231 catch (const std::exception& err) {
232 throw std::runtime_error(fmt::format("ca::ParametersIO::Load: input setup file \"{}\" has inconsistent format or "
233 "was corrupted. The exception message: ",
234 fileName, err.what()));
235 }
236 if constexpr (std::is_same_v<Float, double>) {
237 return parameters;
238 }
239 else {
240 return Parameters<Float>(parameters);
241 }
242 }
243} // namespace cbm::algo::ca
Configuration for the CA tracking algorithm (source)
Compile-time constants definition for the CA tracking algorithm.
A container for search window maps.
A setup representation in CA tracking.
Magnetic flux density interpolation along the track vs. z-coordinate (header)
EFieldMode
Enumiration for the magnetic field representation variants in the track fitting algorithm.
Definition KfDefs.h:108
Setup representation for the Kalman-filter framework (header)
Configuration of the CA tracking (excluding geometry)
Definition CaConfig.h:36
A container for all external parameters of the CA tracking algorithm.
Config fConfig
Configuration.
void serialize(Archive &ar, const unsigned int)
Setup< DataT > fSetup
Setup representation.
const auto & GetActiveSetup() const
Gets active setup.
const Setup< DataT > & GetSetup() const
Constant accessor to CA setup.
kf::EFieldMode GetFieldMode() const
Gets field mode.
int GetNstationsGeometry(EDetectorID detId) const
Gets number of stations, provided by setup geometry for given detector ID.
Parameters(const Parameters< DataIn > &other)
Copy constructor with type conversion.
int GetStationIndexGeometry(int locId, EDetectorID detId) const
Provides access to local indexes of stations (const)
Parameters()=default
Default constructor.
int GetStationIndexActive(int locId, EDetectorID detId) const
Provides access to global indexes of stations among geometry (const)
const SearchWindowMapContainer & GetSearchWindows() const
Constant accessor to search window map container.
int GetNstationsGeometry() const
Gets total number of stations, provided by setup geometry.
std::string ToString(int verbosity=0, int indentLevel=0) const
String representation of the class contents.
~Parameters() noexcept=default
Destructor.
int GetNstationsActive() const
Gets total number of active stations.
const Config & GetConfig() const
Constant accessor to CA config.
SearchWindowMapContainer fSwMaps
Search window map.
std::array< T, constants::size::MaxNstations > StationArray_t
void Print(int verbosityLevel=0) const
Prints configuration.
const auto & GetGeometrySetup() const
Gets active setup.
const auto & GetCAIterations() const
Provides access to L1CAIteration vector (const)
void CheckConsistency() const
Class invariant checker.
std::pair< EDetectorID, int > GetStationIndexLocal(int geoId) const
Provides access to the first index of the station on each particular detector (const)
friend class boost::serialization::access
Serialization function.
std::underlying_type_t< EDetectorID > DetectorID_t
Parameters(const Parameters &other)=default
Copy constructor.
int GetNstationsActive(EDetectorID detId) const
Gets number of active stations for given detector ID.
bool IsActive(EDetectorID detId) const
Checks, if the detector subsystem active.
int GetNcaIterations() const
Provides number of iterations.
Setup representation for tracking.
Definition CaSetup.h:54
constexpr T2 Undef
Undefined values.
Definition CaDefs.h:117
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14
Vector< Iteration > IterationsContainer_t
Type definitions for used containers.
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
Definition CbmDefs.h:216
Hash for CbmL1LinkKey.
A class for loading/storing the Parameters objects.
static void Store(const Parameters< double > &parameters, const std::string &fileName)
Stores parameter to file.
static Parameters< Float > Load(const std::string &fileName)
Loads parameters from file.
~ParametersIO()=delete
Destructor.