20#include <boost/archive/binary_oarchive.hpp>
24#include <unordered_map>
26#include <fmt/format.h>
49 throw std::runtime_error(
"Tracking Chain: TrackingSetup object was not registered");
63 L_(info) <<
"Tracking Chain: reading geometry from CA parameters file " << GNb << geomCfgFile << CL <<
'\n';
64 L_(info) <<
"Tracking Chain: reading geometry setup file " << GNb << setupCfgFile << CL <<
'\n';
65 L_(info) <<
"Tracking Chain: reading parameters from CA main config " << GNb << mainCfgFile << CL <<
'\n';
68 manager.SetConfigMain(mainCfgFile);
69 if (!userCfgFile.empty()) {
70 L_(info) <<
"Tracking Chain: applying user configuration from " << GNb << userCfgFile << CL <<
'\n';
71 manager.SetConfigUser(userCfgFile);
73 manager.ReadParametersObject(geomCfgFile);
74 manager.ReadInputConfigs();
75 manager.ReadGeometrySetup(setupCfgFile);
76 auto parameters = manager.TakeParameters();
77 L_(info) <<
"Tracking Chain: parameters object: \n" << parameters.ToString(1) <<
'\n';
81 fbDetUsed[EDetectorID::kSts] =
Opts().
Has(fles::Subsystem::STS) && parameters.IsActive(EDetectorID::kSts);
82 fbDetUsed[EDetectorID::kTof] =
Opts().
Has(fles::Subsystem::TOF) && parameters.IsActive(EDetectorID::kTof);
83 fbDetUsed[EDetectorID::kTrd] =
Opts().
Has(fles::Subsystem::TRD) && parameters.IsActive(EDetectorID::kTrd);
88 : *(
Opts().NumOMPThreads()));
103 xpu::scoped_timer t_(
"CA");
128 std::ofstream ofs(fileName);
129 boost::archive::binary_oarchive oa(ofs);
139 int nHitsTot = recoResults.
stsHits.NElements() + recoResults.
tofHits.NElements() + recoResults.
trdHits.NElements();
140 L_(debug) <<
"Tracking chain: input has " << nHitsTot <<
" hits";
165 int nTracks = output.
tracks.size();
171 int trackFirstHit = 0;
172 for (
int iTrk = 0; iTrk < nTracks; ++iTrk) {
176 int nHits = output.
tracks[iTrk].fNofHits;
177 for (
int iHit = 0; iHit < nHits; ++iHit) {
191 trackFirstHit += nHits;
217 std::ofstream ofs(fileName);
218 boost::archive::binary_oarchive oa(ofs);
233template<EDetectorID DetID>
239 constexpr bool IsMvd = (DetID == EDetectorID::kMvd);
240 constexpr bool IsSts = (DetID == EDetectorID::kSts);
241 constexpr bool IsMuch = (DetID == EDetectorID::kMuch);
242 constexpr bool IsTrd = (DetID == EDetectorID::kTrd);
243 constexpr bool IsTof = (DetID == EDetectorID::kTof);
245 xpu::t_add_bytes(
hits.NElements() *
sizeof(Hit_t));
247 int64_t dataStreamDet =
static_cast<int64_t
>(DetID) << 60;
248 int64_t dataStream = 0;
249 for (
size_t iPartition = 0; iPartition <
hits.NPartitions(); ++iPartition, ++dataStream) {
250 const auto& [vHits, extHitAddress] =
hits.Partition(iPartition);
264 if (iStActive >= nSt) {
265 L_(error) <<
"TrackingChain: found hit with wrong active station index above the upper limit: " << iStActive
269 double lastTime = -1e9;
272 for (
size_t iPartHit = 0; iPartHit < vHits.size(); ++iPartHit) {
273 const auto& hit = vHits[iPartHit];
299 if constexpr (IsSts) {
300 caHit.
SetFrontKey(firstHitKey + hit.fFrontClusterId);
301 caHit.
SetBackKey(firstHitKey + hit.fBackClusterId);
311 caHit.
SetT(hit.Time());
314 if constexpr (IsSts) caHit.
SetDxy(hit.fDxy);
321 if constexpr (IsTrd) {
327 else if (iStLocal == 1) {
337 if ((caHit.
T() < lastTime - 1000.) && (dataStream < 100000)) {
340 lastTime = caHit.
T();
351 if constexpr (IsMvd) {
354 if constexpr (IsSts) {
357 if constexpr (IsMuch) {
360 if constexpr (IsTrd) {
363 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)
static vector< vector< QAHit > > hits
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.
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.
TrackingChain(std::shared_ptr< HistogramSender > histoSender=nullptr)
Constructor from parameters.
ca::Vector< std::tuple< ca::EDetectorID, uint32_t, uint32_t > > faHitExternalIndices
External indices of used hits.
TrackingChainConfig fConfig
Tracking config.
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.
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.
bool IsSenderDefined() const
Checks, if the histogram sender is defined.
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.
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