15#include <boost/archive/binary_iarchive.hpp>
16#include <boost/archive/binary_oarchive.hpp>
17#include <boost/archive/text_iarchive.hpp>
114 LOG(error) <<
"ca::InitManager: Attempt to form parameters container before all necessary fields were initialized"
122 if (!station.GetTrackingStatus()) {
125 *destIt = station.GetStation();
134 catch (
const std::logic_error& err) {
135 LOG(error) <<
"ca::InitManager: parameters container consistency check failed. Reason: " << err.what();
147 std::stringstream msg;
148 msg <<
"ca::InitManager: number of active stations cannot be accessed until the station layout is initialized";
149 throw std::runtime_error(msg.str());
159 std::stringstream msg;
160 msg <<
"ca::InitManager: number of active stations cannot be accessed until the station layout is initialized";
161 throw std::runtime_error(msg.str());
171 std::stringstream msg;
172 msg <<
"ca::InitManager: number of geometry stations cannot be accessed until the station layout is initialized";
173 throw std::runtime_error(msg.str());
183 std::stringstream msg;
184 msg <<
"ca::InitManager: number of geometry stations cannot be accessed until the station layout is initialized";
185 throw std::runtime_error(msg.str());
187 return fParameters.GetNstationsGeometry(detectorID);
195 std::stringstream msg;
196 msg <<
"ca::InitManager: station info container cannot be accessed until the station layout is initialized";
197 throw std::runtime_error(msg.str());
207 LOG(info) <<
"ca::InitManager::InitStationLayout(): ....";
212 ++
fParameters.fvFirstGeoId[
static_cast<int>(aStation.GetDetectorID()) + 1];
214 for (
int iDet = 1; iDet < static_cast<int>(
fParameters.fvFirstGeoId.size()) - 1; ++iDet) {
219 for (
int iStGeo = 0; iStGeo < static_cast<int>(
fvStationInfo.size()); ++iStGeo) {
221 int iDet =
static_cast<int>(aStation.GetDetectorID());
222 int iStLocal = aStation.GetStationID();
224 fParameters.fvGeoToLocalIdMap[iStGeo] = std::make_pair(aStation.GetDetectorID(), iStLocal);
228 int iStActive = aStation.GetTrackingStatus() ?
fParameters.fNstationsActiveTotal++ : -1;
230 if (iStActive > -1) {
237 aStation.SetGeoLayerID(
fParameters.GetStationIndexGeometry(aStation.GetStationID(), aStation.GetDetectorID()));
246 LOG(warn) <<
"ca::InitManager::InitTargetField: attempt to reinitialize the field value and field region "
247 <<
"near target. Ignore";
253 std::stringstream msg;
254 msg <<
"Attempt to initialize the field value and field region near target before initializing field function";
255 throw std::runtime_error(msg.str());
259 std::stringstream msg;
260 msg <<
"Attempt to initialize the field value and field region near target before the target position"
262 throw std::runtime_error(msg.str());
264 constexpr int nDimensions{3};
265 constexpr int nPointsNodal{3};
268 std::array<kf::FieldValue<fvec>, nPointsNodal> B{};
269 std::array<fvec, nPointsNodal> z{};
271 for (
int idx = 0; idx < nPointsNodal; ++idx) {
272 double point[nDimensions]{0., 0., inputNodalZ[idx]};
273 double field[nDimensions]{};
275 z[idx] = inputNodalZ[idx];
276 B[idx].Set(field[0], field[1], field[2]);
278 fParameters.fVertexFieldRegion.Set(B[0], z[0], B[1], z[1], B[2], z[2]);
290 std::stringstream msg;
291 msg <<
"Attempt to push back a CA track finder iteration before the number of iterations was defined";
292 throw std::runtime_error(msg.str());
302 LOG(info) <<
"ca::InitManager: reading parameter configuration ...";
310 LOG(info) <<
"ca::InitManager: reading parameter configuration ... \033[1;32mdone\033[0m";
312 catch (
const std::runtime_error& err) {
313 LOG(error) <<
"ca::InitManager: reading parameter configuration ... \033[1;31mfail\033[0m. Reason: "
337 std::ifstream ifs(fileName, std::ios::binary);
339 std::stringstream msg;
340 msg <<
"ca::InitManager: parameters data file \"" <<
clrs::GNb << fileName <<
clrs::CL <<
"\" was not found";
341 throw std::runtime_error(msg.str());
346 boost::archive::binary_iarchive ia(ifs);
350 catch (
const std::exception&) {
351 std::stringstream msg;
352 msg <<
"ca::InitManager: parameters file \"" <<
clrs::GNb << fileName <<
clrs::CL
353 <<
"\" has incorrect data format or was corrupted";
354 throw std::runtime_error(msg.str());
367 std::ifstream ifs(fileName);
369 std::stringstream msg;
370 msg <<
"ca::InitManager: search window file \"" << fileName <<
"\" was not found";
371 throw std::runtime_error(msg.str());
375 boost::archive::text_iarchive ia(ifs);
381 std::stringstream errMsg;
382 for (
int iW = 0; iW < nWindows; ++iW) {
388 errMsg <<
"\t- wrong station id for entry " << iW <<
": " << iStationID <<
" (should be between 0 and "
392 errMsg <<
"\t- wrong track group id for entry " << iW <<
": " << iTrackGrID <<
" (should be between 0 and "
397 if (errMsg.str().size()) {
398 std::stringstream msg;
399 msg <<
"ca::InitManager: some errors occurred while reading search windows: " << errMsg.str();
400 throw std::runtime_error(msg.str());
403 catch (
const std::exception& err) {
404 std::stringstream msg;
405 msg <<
"search windows file \"" << fileName <<
"\" has incorrect data format or was corrupted. ";
406 msg <<
"Exception catched: " << err.what();
407 throw std::runtime_error(msg.str());
418 auto& iterationsContainer =
fParameters.fCAIterations;
421 iterationsContainer.reserve(nIterations);
434 LOG(warn) <<
"ca::InitManager::SetFieldFunction: attempt to reinitialize the field function. Ignored";
444 <<
"ca::InitManager::SetGhostSuppression: attempt of reinitializating the ghost suppresion flag. Ignore";
456 LOG(warn) <<
"ca::InitManager::SetRandomSeed: attempt of reinitializating the random seed. Ignore";
468 LOG(warn) <<
"ca::InitManager::SetTargetPosition: attempt to reinitialize the target position. Ignore";
492 std::ofstream ofs(fileName, std::ios::binary);
494 std::stringstream msg;
495 msg <<
"ca::InitManager: failed opening file \"" << GNb << fileName << CL <<
"\" to write parameters object";
496 throw std::runtime_error(msg.str());
499 LOG(info) <<
"ca::InitManager: writing CA parameters object to file \"" << GNb << fileName <<
'\"' << CL;
502 boost::archive::binary_oarchive oa(ofs);
510 bool ifInitPassed =
true;
512 int nIterationsActual =
fParameters.fCAIterations.size();
514 if (nIterationsActual != nIterationsExpected) {
515 LOG(warn) <<
"ca::InitManager::CheckCAIterations: incorrect number of iterations registered: "
516 << nIterationsActual <<
" of " << nIterationsExpected <<
" expected";
517 ifInitPassed =
false;
527 bool ifInitPassed =
true;
531 [](
const auto& st) { return st.GetInitController().IsFinalized(); });
532 if (!bStationsFinalized) {
533 std::stringstream msg;
534 msg <<
"ca::InitManager: At least one of the StationInitializer objects is not finalized";
539 std::stringstream msg;
540 msg <<
"Actual total number of registered stations in geometry (" <<
fParameters.GetNstationsGeometry()
542 <<
"). Please, select another set of active tracking detectors or recompile the code with enlarged"
543 <<
" constants::size::MaxNstations value";
544 throw std::runtime_error(msg.str());
Configuration parameter file reader for the CA tracking algorithm (header)
Input data management class for the CA tracking algorithm (header)
A base KF-Setup initialization class (source)
A reader for the CA parameters from the YAML configuration files.
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.
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 ReadGeometrySetup(const std::string &fileName)
Reads geometry setup from file.
int GetNstationsGeometry() const
Gets total number of stations, provided by setup geometry.
void ClearCAIterations()
Clears vector of CA track finder iterations.
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 ReadParametersObject(const std::string &fileName)
Reads parameters object from boost-serialized binary file.
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.
void CheckCAIterationsInit()
Checker for Iteration container initialization (sets EInitKey::kCAIterations)
void ClearSetupInfo()
Clears vector of base setup.
void WriteParametersObject(const std::string &fileName) const
Writes parameters object from boost-serialized binary file.
double fTargetZ
Target position z component in double precision.
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.
FieldFunction_t fFieldFunction
A function which returns magnetic field vector B in a radius-vector xyz.
int GetNstationsActive() const
Gets total number of active stations.
void PushBackCAIteration(const Iteration &iteration)
Pushes an CA track finder iteration into a sequence of iteration using reference.
std::vector< StationInitializer > fvStationInfo
Vector of StationInitializer objects (active + inactive)
void AddStation(const StationInitializer &station)
Adds a tracking station to the geometry.
void CheckInit()
Provides final checks of the parameters object.
@ kSearchWindows
6) If the hit search windows were initialized
@ kFieldFunction
0) If magnetic field getter function is set
@ kTargetPos
1) If target position was defined
@ 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
bool FormParametersContainer()
Forms parameters container.
void CheckStationsInfoInit()
Checker for StationInitializer set initialization (sets EInitKey::kStationsInfo)
std::string fsConfigInputUser
name for the input configuration file
A set of parameters for the CA Track finder iteration.
bool GetFlag(InitKeyEnum bitKey) const
void SetFlag(InitKeyEnum bitKey, bool newStatus=true)
bool IsFinalized() const
Checks, if the object is finalized, i.e. all its fields were set up.
std::string ToString(int indentLevel=0) const
A container for all external parameters of the CA tracking algorithm.
Class L1SearchWindow defines a parameterisation of hits search window for CA tracking algorithm TODO:...
int GetStationID() const
Gets station id.
int GetTrackGroupID() const
Gets track group id.
A base class which provides interface to L1Algo station geometry.
Magnetic field region, corresponding to a hit triplet.
Magnetic flux density vector.
static Setup< T > Load(const std::string &fileName)
Loads a serialized setup from a file.
constexpr char GNb[]
bold green
constexpr int MaxNstations
Max number of stations, 2^6 = 64.
constexpr int MaxNtrackGroups
TODO: SZh 8.11.2022: add selection of parameterisation.
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.