15#include <boost/archive/binary_iarchive.hpp>
16#include <boost/archive/binary_oarchive.hpp>
17#include <boost/archive/text_iarchive.hpp>
39 stationInfo.SetStationType(stationIn.type);
40 stationInfo.SetZmin(0.);
41 stationInfo.SetZmax(0.);
42 stationInfo.SetZref(stationIn.fZ);
43 stationInfo.SetXmax(stationIn.Xmax);
44 stationInfo.SetYmax(stationIn.Ymax);
45 stationInfo.SetFieldStatus(stationIn.fieldStatus);
46 stationInfo.SetTimeInfo(stationIn.timeInfo);
47 stationInfo.SetTrackingStatus(
true);
102 fParameters.fDevIsSuppressOverlapHitsViaMc =
false;
139 LOG(error) <<
"ca::InitManager: Attempt to form parameters container before all necessary fields were initialized"
147 if (!station.GetTrackingStatus()) {
150 *destIt = station.GetStation();
159 catch (
const std::logic_error& err) {
160 LOG(error) <<
"ca::InitManager: parameters container consistency check failed. Reason: " << err.what();
172 std::stringstream msg;
173 msg <<
"ca::InitManager: number of active stations cannot be accessed until the station layout is initialized";
174 throw std::runtime_error(msg.str());
184 std::stringstream msg;
185 msg <<
"ca::InitManager: number of active stations cannot be accessed until the station layout is initialized";
186 throw std::runtime_error(msg.str());
196 std::stringstream msg;
197 msg <<
"ca::InitManager: number of geometry stations cannot be accessed until the station layout is initialized";
198 throw std::runtime_error(msg.str());
208 std::stringstream msg;
209 msg <<
"ca::InitManager: number of geometry stations cannot be accessed until the station layout is initialized";
210 throw std::runtime_error(msg.str());
212 return fParameters.GetNstationsGeometry(detectorID);
220 std::stringstream msg;
221 msg <<
"ca::InitManager: station info container cannot be accessed until the station layout is initialized";
222 throw std::runtime_error(msg.str());
232 LOG(info) <<
"ca::InitManager::InitStationLayout(): ....";
237 ++
fParameters.fvFirstGeoId[
static_cast<int>(aStation.GetDetectorID()) + 1];
239 for (
int iDet = 1; iDet < static_cast<int>(
fParameters.fvFirstGeoId.size()) - 1; ++iDet) {
244 for (
int iStGeo = 0; iStGeo < static_cast<int>(
fvStationInfo.size()); ++iStGeo) {
246 int iDet =
static_cast<int>(aStation.GetDetectorID());
247 int iStLocal = aStation.GetStationID();
249 fParameters.fvGeoToLocalIdMap[iStGeo] = std::make_pair(aStation.GetDetectorID(), iStLocal);
253 int iStActive = aStation.GetTrackingStatus() ?
fParameters.fNstationsActiveTotal++ : -1;
255 if (iStActive > -1) {
262 aStation.SetGeoLayerID(
fParameters.GetStationIndexGeometry(aStation.GetStationID(), aStation.GetDetectorID()));
271 LOG(warn) <<
"ca::InitManager::InitTargetField: attempt to reinitialize the field value and field region "
272 <<
"near target. Ignore";
278 std::stringstream msg;
279 msg <<
"Attempt to initialize the field value and field region near target before initializing field function";
280 throw std::runtime_error(msg.str());
284 std::stringstream msg;
285 msg <<
"Attempt to initialize the field value and field region near target before the target position"
287 throw std::runtime_error(msg.str());
289 constexpr int nDimensions{3};
290 constexpr int nPointsNodal{3};
293 std::array<kf::FieldValue<fvec>, nPointsNodal> B{};
294 std::array<fvec, nPointsNodal> z{};
296 for (
int idx = 0; idx < nPointsNodal; ++idx) {
297 double point[nDimensions]{0., 0., inputNodalZ[idx]};
298 double field[nDimensions]{};
300 z[idx] = inputNodalZ[idx];
301 B[idx].Set(field[0], field[1], field[2]);
303 fParameters.fVertexFieldRegion.Set(B[0], z[0], B[1], z[1], B[2], z[2]);
315 std::stringstream msg;
316 msg <<
"Attempt to push back a CA track finder iteration before the number of iterations was defined";
317 throw std::runtime_error(msg.str());
327 LOG(info) <<
"ca::InitManager: reading parameter configuration ...";
335 LOG(info) <<
"ca::InitManager: reading parameter configuration ... \033[1;32mdone\033[0m";
337 catch (
const std::runtime_error& err) {
338 LOG(error) <<
"ca::InitManager: reading parameter configuration ... \033[1;31mfail\033[0m. Reason: "
362 std::ifstream ifs(fileName, std::ios::binary);
364 std::stringstream msg;
365 msg <<
"ca::InitManager: parameters data file \"" <<
clrs::GNb << fileName <<
clrs::CL <<
"\" was not found";
366 throw std::runtime_error(msg.str());
371 boost::archive::binary_iarchive ia(ifs);
375 catch (
const std::exception&) {
376 std::stringstream msg;
377 msg <<
"ca::InitManager: parameters file \"" <<
clrs::GNb << fileName <<
clrs::CL
378 <<
"\" has incorrect data format or was corrupted";
379 throw std::runtime_error(msg.str());
392 std::ifstream ifs(fileName);
394 std::stringstream msg;
395 msg <<
"ca::InitManager: search window file \"" << fileName <<
"\" was not found";
396 throw std::runtime_error(msg.str());
400 boost::archive::text_iarchive ia(ifs);
406 std::stringstream errMsg;
407 for (
int iW = 0; iW < nWindows; ++iW) {
413 errMsg <<
"\t- wrong station id for entry " << iW <<
": " << iStationID <<
" (should be between 0 and "
417 errMsg <<
"\t- wrong track group id for entry " << iW <<
": " << iTrackGrID <<
" (should be between 0 and "
422 if (errMsg.str().size()) {
423 std::stringstream msg;
424 msg <<
"ca::InitManager: some errors occurred while reading search windows: " << errMsg.str();
425 throw std::runtime_error(msg.str());
428 catch (
const std::exception& err) {
429 std::stringstream msg;
430 msg <<
"search windows file \"" << fileName <<
"\" has incorrect data format or was corrupted. ";
431 msg <<
"Exception catched: " << err.what();
432 throw std::runtime_error(msg.str());
443 auto& iterationsContainer =
fParameters.fCAIterations;
446 iterationsContainer.reserve(nIterations);
459 LOG(warn) <<
"ca::InitManager::SetFieldFunction: attempt to reinitialize the field function. Ignored";
469 <<
"ca::InitManager::SetGhostSuppression: attempt of reinitializating the ghost suppresion flag. Ignore";
481 LOG(warn) <<
"ca::InitManager::SetRandomSeed: attempt of reinitializating the random seed. Ignore";
493 LOG(warn) <<
"ca::InitManager::SetTargetPosition: attempt to reinitialize the target position. Ignore";
517 std::ofstream ofs(fileName, std::ios::binary);
519 std::stringstream msg;
520 msg <<
"ca::InitManager: failed opening file \"" << GNb << fileName << CL <<
"\" to write parameters object";
521 throw std::runtime_error(msg.str());
524 LOG(info) <<
"ca::InitManager: writing CA parameters object to file \"" << GNb << fileName <<
'\"' << CL;
527 boost::archive::binary_oarchive oa(ofs);
535 bool ifInitPassed =
true;
537 int nIterationsActual =
fParameters.fCAIterations.size();
539 if (nIterationsActual != nIterationsExpected) {
540 LOG(warn) <<
"ca::InitManager::CheckCAIterations: incorrect number of iterations registered: "
541 << nIterationsActual <<
" of " << nIterationsExpected <<
" expected";
542 ifInitPassed =
false;
552 bool ifInitPassed =
true;
556 [](
const auto& st) { return st.GetInitController().IsFinalized(); });
557 if (!bStationsFinalized) {
558 std::stringstream msg;
559 msg <<
"ca::InitManager: At least one of the StationInitializer objects is not finalized";
564 std::stringstream msg;
565 msg <<
"Actual total number of registered stations in geometry (" <<
fParameters.GetNstationsGeometry()
567 <<
"). Please, select another set of active tracking detectors or recompile the code with enlarged"
568 <<
" constants::size::MaxNstations value";
569 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.
void AddStations(const Parameters< fvec > &par)
Adds tracking stations from the parameters 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.
int GetNstationsActive() const
Gets total number of active stations.
const StationArray_t< int > & GetActiveToGeoMap() const
Provides access to the map of active to geo station indices (const)
const StationsContainer_t< DataT > & GetStations() const
Provides access to L1Stations container (const)
std::pair< EDetectorID, int > GetStationIndexLocal(int geoIndex) const
Gets local index of station.
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.