21#include <boost/archive/binary_oarchive.hpp>
25#include <unordered_map>
27#include <fmt/format.h>
44 std::string_view name)
45 : fQa(
Qa(qaManager, name))
55 throw std::runtime_error(
"Tracking Chain: TrackingSetup object was not registered");
69 L_(info) <<
"Tracking Chain: reading geometry from CA parameters file " << GNb << geomCfgFile << CL <<
'\n';
70 L_(info) <<
"Tracking Chain: reading geometry setup file " << GNb << setupCfgFile << CL <<
'\n';
71 L_(info) <<
"Tracking Chain: reading parameters from CA main config " << GNb << mainCfgFile << CL <<
'\n';
76 manager.SetConfigMain(mainCfgFile);
77 if (!userCfgFile.empty()) {
78 L_(info) <<
"Tracking Chain: applying user configuration from " << GNb << userCfgFile << CL <<
'\n';
79 manager.SetConfigUser(userCfgFile);
84 manager.ReadParametersObject(geomCfgFile);
85 auto paramIn = manager.TakeParameters();
86 manager.ClearSetupInfo();
93 manager.SetFieldFunction([](
const double(&)[3],
double(&outB)[3]) {
98 manager.SetTargetPosition(target.
GetX(), target.
GetY(), target.
GetZ());
99 manager.InitTargetField(2.5 );
100 manager.AddStations(paramIn);
101 manager.InitStationLayout();
102 manager.ReadInputConfigs();
103 manager.SetGeometrySetup(geoSetup);
104 manager.DevSetIsParSearchWUsed(
false);
105 if (!manager.FormParametersContainer()) {
106 throw std::runtime_error(
"Initialization of CA parameters failed");
109 auto parameters = manager.TakeParameters();
111 L_(info) <<
"Tracking Chain: parameters object: \n" << parameters.ToString(1) <<
'\n';
115 fbDetUsed[EDetectorID::kSts] =
Opts().
Has(fles::Subsystem::STS) && parameters.IsActive(EDetectorID::kSts);
116 fbDetUsed[EDetectorID::kTof] =
Opts().
Has(fles::Subsystem::TOF) && parameters.IsActive(EDetectorID::kTof);
117 fbDetUsed[EDetectorID::kTrd] =
Opts().
Has(fles::Subsystem::TRD) && parameters.IsActive(EDetectorID::kTrd);
123 : *(
Opts().NumOMPThreads()));
143 xpu::scoped_timer t_(
"CA");
168 std::ofstream ofs(fileName);
169 boost::archive::binary_oarchive oa(ofs);
179 int nHitsTot = recoResults.
stsHits.NElements() + recoResults.
tofHits.NElements() + recoResults.
trdHits.NElements();
180 L_(debug) <<
"Tracking chain: input has " << nHitsTot <<
" hits";
213 int nTracks = output.
tracks.size();
219 int trackFirstHit = 0;
220 for (
int iTrk = 0; iTrk < nTracks; ++iTrk) {
224 int nHits = output.
tracks[iTrk].fNofHits;
225 for (
int iHit = 0; iHit < nHits; ++iHit) {
240 trackFirstHit += nHits;
267 std::ofstream ofs(fileName);
268 boost::archive::binary_oarchive oa(ofs);
283template<EDetectorID DetID>
289 constexpr bool IsMvd = (DetID == EDetectorID::kMvd);
290 constexpr bool IsSts = (DetID == EDetectorID::kSts);
291 constexpr bool IsMuch = (DetID == EDetectorID::kMuch);
292 constexpr bool IsTrd = (DetID == EDetectorID::kTrd);
293 constexpr bool IsTof = (DetID == EDetectorID::kTof);
295 xpu::t_add_bytes(
hits.NElements() *
sizeof(Hit_t));
297 int64_t dataStreamDet =
static_cast<int64_t
>(DetID) << 60;
298 int64_t dataStream = 0;
299 for (
size_t iPartition = 0; iPartition <
hits.NPartitions(); ++iPartition, ++dataStream) {
300 const auto& [vHits, extHitAddress] =
hits.Partition(iPartition);
314 if (iStActive >= nSt) {
315 L_(error) <<
"TrackingChain: found hit with wrong active station index above the upper limit: " << iStActive
319 double lastTime = -1e9;
322 for (
size_t iPartHit = 0; iPartHit < vHits.size(); ++iPartHit) {
323 const auto& hit = vHits[iPartHit];
350 if constexpr (IsSts) {
351 caHit.
SetFrontKey(firstHitKey + hit.fFrontClusterId);
352 caHit.
SetBackKey(firstHitKey + hit.fBackClusterId);
360 if constexpr (IsTof) {
371 caHit.
SetT(hit.Time());
374 if constexpr (IsSts) caHit.
SetDxy(hit.fDxy);
381 if constexpr (IsTrd) {
387 else if (iStLocal == 1) {
398 if ((caHit.
T() < lastTime - 1000.) && (dataStream < 100000)) {
401 lastTime = caHit.
T();
416 if constexpr (IsMvd) {
419 if constexpr (IsSts) {
422 if constexpr (IsMuch) {
425 if constexpr (IsTrd) {
428 if constexpr (IsTof) {
Compile-time constants definition for the CA tracking algorithm.
A generic hit for the CA tracker (header)
Input data management class for the CA tracking algorithm (header)
ECbmRecoMode
Reconstruct the full time slice or event-by-event.
static vector< vector< QAHit > > hits
A base KF-Setup initialization class (source)
friend fvec sqrt(const fvec &a)
This file contains the definition of the ParFiles class.
A chain class to execute CA tracking algorithm in online reconstruction (header)
fs::path ParamsDir() const
bool Has(fles::Subsystem detector) const
const Options & Opts() const
A chain for tracking algorithm.
Output_t Run(Input_t recoResults)
Provides action for a given time-slice.
std::shared_ptr< TrackingSetup > fpSetup
setup interface
ca::Framework fCaFramework
CA framework instance.
void ReadHits(PartitionedSpan< const ca::HitTypes_t::at< DetID > > hits)
Reads from different detector subsystems.
TrackingChain(ECbmRecoMode recoMode, const std::unique_ptr< cbm::algo::qa::Manager > &qaManager=nullptr, std::string_view name="")
Constructor from parameters.
Output_t PrepareOutput()
Prepares output data.
ca::TrackingMonitorData fCaMonitorData
CA monitor data object.
void PrepareInput(Input_t recoResults)
Prepares input data.
void Init()
Provides action in the initialization of the run.
ca::DataManager fCaDataManager
CA data manager.
ca::Vector< std::tuple< ca::EDetectorID, uint32_t, uint32_t > > faHitExternalIndices
External indices of used hits.
TrackingChainConfig fConfig
Tracking config.
ECbmRecoMode fRecoMode
Reconstruction mode.
static constexpr bool kDEBUG
Debug mode.
ca::HitKeyIndex_t fNofHitKeys
Current number of hit keys (aux)
ca::TrackingMonitor fCaMonitor
CA internal monitor (debug purposes)
void Finalize()
Provides action in the end of the run.
ca::DetIdArray_t< bool > fbDetUsed
Flags of detector subsystems used in tracking.
void SetNhitKeys(int nKeys)
Sets the number of hit keys.
void PushBackHit(const Hit &hit, int64_t streamId)
Pushes back a hit (with a data stream info)
InputData && TakeInputData()
Takes (moves) the instance of the input data object.
void ResetInputData(HitIndex_t nHits=0) noexcept
Resets the input data block.
int GetNofHits()
Gets number of hits stored.
const TrackingMonitorData & GetMonitorData() const
Gets monitor data.
int GetNofThreads() const
Gets number of threads.
const InputData & GetInputData() const
Gets pointer to input data object for external access.
Vector< Track > fRecoTracks
reconstructed tracks
void SetNofThreads(int nThreads)
Sets number of threads.
void ReceiveParameters(Parameters< fvec > &¶meters)
Receives tracking parameters.
Vector< ca::HitIndex_t > fRecoHits
packed hits of reconstructed tracks
void ReceiveInputData(InputData &&inputData)
Receives input data.
void SetMonitorData(const TrackingMonitorData &monitorData)
Sets monitor data.
void Init(const TrackingMode mode)
const Parameters< fvec > & GetParameters() const
Gets a pointer to the Framework parameters object.
ca::Hit class describes a generic hit for the CA tracker
void SetX(fscal x)
Set the X coordinate.
HitKeyIndex_t BackKey() const
Get the back key index.
void SetRangeT(fscal rangeT)
Set the +/- range of uncertainty of time.
void SetDt2(fscal dt2)
Set the uncertainty of time.
void SetDy2(fscal dy2)
Set the uncertainty of Y coordinate.
void SetRangeY(fscal rangeY)
Set the +/- range of uncertainty of Y coordinate.
void SetStation(int station)
Set the station index.
void SetDx2(fscal dx2)
Set the uncertainty of X coordinate.
void SetRangeX(fscal rangeX)
Set the +/- range of uncertainty of X coordinate.
void SetZ(fscal z)
Set the Z coordinate.
void SetBackKey(HitKeyIndex_t key)
Set the back key index.
void SetFrontKey(HitKeyIndex_t key)
Set the front key index.
void SetId(HitIndex_t id)
Set the hit id.
bool Check() const
Checks, if the hit is defined.
HitKeyIndex_t FrontKey() const
Get the front key index.
fscal T() const
Get the time.
void SetT(fscal t)
Set the time.
HitIndex_t Id() const
Get the hit id.
void SetDxy(fscal dxy)
Set the X/Y covariance.
void SetY(fscal y)
Set the Y coordinate.
A CA Parameters object initialization class.
void SetDetectorNames(const std::array< const char *, Size > &container)
Sets detector names.
int GetCounterValue(ECounterKey key) const
Gets counter value.
void Reset()
Resets all the counters and timers.
void StopTimer(ETimerKey key)
Stops timer.
void IncrementCounter(ECounterKey key)
Increments key counter by 1.
void StartTimer(ETimerKey key)
Starts timer.
const Timer & GetTimer(ETimerKey key) const
Gets timer.
std::string ToString() const
Prints counters summary to string.
void Reset()
Resets the counters.
void AddMonitorData(const MonitorData< ECounterKey, ETimerKey > &data, bool parallel=false)
Adds the other monitor data to this.
int GetCounterValue(ECounterKey key) const
Gets counter value.
A container for all external parameters of the CA tracking algorithm.
void Exec()
QA execution function.
void RegisterParameters(const Parameters< fvec > *pParameters)
Registers tracking parameters object.
void Init()
Initializes the QA.
void RegisterRecoHitIndices(const Vector< HitIndex_t > *pvRecoHits)
Registers reco hits indices vector.
void RegisterInputData(const InputData *pInputData)
Registers tracking input data object.
void RegisterTracks(const Vector< Track > *pvTracks)
Registers track vector.
double GetTotal() const
Gets total time [s].
Class representing an output track in the CA tracking algorithm.
A monitor specialization for cbm::algo::ca::Framework class.
void push_back(Tinput value)
Pushes back a value to the vector.
void reserve(std::size_t count)
Reserves a new size for the vector.
void reset(std::size_t count, Tinput... value)
Clears vector and resizes it to the selected size with selected values.
static Setup< T > Load(const std::string &fileName)
Loads a serialized setup from a file.
A geometry layer in the target region.
const T & GetY() const
Gets y-coordinate of the nominal target center.
const T & GetX() const
Gets x-coordinate of the nominal target center.
const T & GetZ() const
Gets z-coordinate of the nominal target center.
constexpr char GNb[]
bold green
unsigned int HitKeyIndex_t
Index of the hit key (e.g. front / back cluster id for STS)
@ RecoTrack
number of reconstructed tracks
@ RecoStsHit
number of STS hits in tracks
@ UndefinedTofHit
number of undefined TOF hits
@ TrackingCall
number of the routine calls
@ UndefinedTrdHit
number of undefined TRD hits
@ RecoTrdHit
number of TRD hits in tracks
@ UndefinedMvdHit
number of undefined MVD hits
@ RecoTofHit
number of TOF hits in tracks
@ UndefinedMuchHit
number of undefined MuCh hits
@ UndefinedStsHit
number of undefined STS hits
constexpr DetIdArray_t< const char * > kDetName
Detector subsystem names.
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
constexpr fles::Subsystem ToFlesSubsystem()
T ReadFromFile(fs::path path)
Class to hold the paths to the parameter files for the different detectors.
struct cbm::algo::ParFiles::@4 ca
std::string fsGeomConfig
Tracking geometry file name (TMP: includes all other settings, but the settings are rewritten)
std::string fsUserConfig
User configuration file (full path)
std::string fsSetupFilename
Geometry setup input file.
std::string fsMainConfig
Main configuration file (rel path in online parameters directory)
bool fbStoreMonitor
Stores monitor snapshot.
std::string fsMoniOutName
Monitor output file name.
Output from the TrackingChain.
ca::Vector< ca::Track > tracks
Reconstructed tracks.
ca::TrackingMonitorData monitorData
Monitor data.
ca::Vector< std::vector< std::pair< uint32_t, uint32_t > > > trdHitIndices
TRD hit indices.
ca::Vector< std::vector< std::pair< uint32_t, uint32_t > > > tofHitIndices
TOF hit indices.
ca::Vector< std::vector< std::pair< uint32_t, uint32_t > > > stsHitIndices
STS hit indices.
Array of types, indexed by EDetectorID.
std::tuple_element_t< static_cast< std::size_t >(DetID), std::tuple< Types... > > at