19#include <boost/archive/binary_oarchive.hpp>
23#include <unordered_map>
25#include <fmt/format.h>
41 std::string_view name)
42 :
fQa(
Qa(qaManager, name))
53 throw std::runtime_error(
"Tracking Chain: RecoSetup object was not registered");
57 L_(info) <<
"Tracking Chain: CA parameters from " <<
GNb << caParPath <<
CL <<
'\n';
59 L_(info) <<
"Tracking Chain: parameters object: \n" << parameters.ToString(1) <<
'\n';
72 : *(
Opts().NumOMPThreads()));
85 L_(info) <<
"TRACKING QA: " <<
fQa.IsActive();
92 xpu::scoped_timer t_(
"CA");
116 auto fileName =
"./monitor.out";
117 std::ofstream ofs(fileName);
118 boost::archive::binary_oarchive oa(ofs);
128 int nHitsTot = recoResults.
stsHits.NElements() + recoResults.
tofHits.NElements() + recoResults.
trdHits.NElements();
129 L_(debug) <<
"Tracking chain: input has " << nHitsTot <<
" hits";
150 L_(debug) <<
"Tracking chain: " <<
fCaDataManager.GetNofHits() <<
" hits will be passed to the ca::Framework";
162 int nTracks = output.
tracks.size();
168 int trackFirstHit = 0;
169 for (
int iTrk = 0; iTrk < nTracks; ++iTrk) {
173 int nHits = output.
tracks[iTrk].fNofHits;
174 for (
int iHit = 0; iHit < nHits; ++iHit) {
189 trackFirstHit += nHits;
201 if (
fQa.IsActive()) {
215 auto fileName = fmt::format(
"./ca_monitor_nth_{}_ts{}.dat",
fCaFramework.GetNofThreads(), tsIndex);
216 std::ofstream ofs(fileName);
217 boost::archive::binary_oarchive oa(ofs);
232template<EDetectorID DetID>
235 int nSt =
fCaFramework.GetParameters().GetNstationsActive();
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);
253 int iStLocal = pSetupUnit->GetTrackingStationId(extHitAddress);
258 int iStActive =
fCaFramework.GetParameters().GetStationIndexActive(iStLocal, DetID);
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];
300 if constexpr (IsSts) {
301 caHit.
SetFrontKey(firstHitKey + hit.fFrontClusterId);
302 caHit.
SetBackKey(firstHitKey + hit.fBackClusterId);
310 if constexpr (IsTof) {
318 auto misalignmentTolerance =
fCaFramework.GetParameters().GetConfig().GetMisalignmentTolerance(DetID);
322 caHit.
SetT(hit.Time());
323 caHit.
SetDx2(hit.Dx() * hit.Dx() + misalignmentTolerance.GetXsq());
324 caHit.
SetDy2(hit.Dy() * hit.Dy() + misalignmentTolerance.GetYsq());
325 if constexpr (IsSts) caHit.
SetDxy(hit.fDxy);
326 caHit.
SetDt2(hit.TimeError() * hit.TimeError() + misalignmentTolerance.GetTimeSq());
332 if constexpr (IsTrd) {
338 else if (iStLocal == 1) {
349 if ((caHit.
T() < lastTime - 1000.) && (dataStream < 100000)) {
352 lastTime = caHit.
T();
367 if constexpr (IsMvd) {
370 if constexpr (IsSts) {
373 if constexpr (IsMuch) {
376 if constexpr (IsTrd) {
379 if constexpr (IsTof) {
Compile-time constants definition for the CA tracking algorithm.
A generic hit for the CA tracker (header)
ECbmRecoMode
Reconstruct the full time slice or event-by-event.
static vector< vector< QAHit > > hits
friend fvec sqrt(const fvec &a)
This file contains the definition of the ParFiles class.
constexpr char GNb[]
bold green
A chain class to execute CA tracking algorithm in online reconstruction (header)
TrackingChain(ECbmRecoMode recoMode, const std::unique_ptr< cbm::algo::qa::Manager > &qaManager=nullptr, std::string_view name="")
Constructor from parameters.
const Options & Opts() const
A chain for tracking algorithm.
Output_t Run(Input_t recoResults)
Provides action for a given time-slice.
ca::Framework fCaFramework
CA framework instance.
std::shared_ptr< RecoSetup > fpSetup
setup interface
static constexpr bool kStoreMonitor
Store monitor (debug)
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.
ca::DataManager fCaDataManager
CA data manager.
ca::Vector< std::tuple< ca::EDetectorID, uint32_t, uint32_t > > faHitExternalIndices
External indices of used hits.
void Init(const std::string &caParPath)
Provides action in the initialization of the run.
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.
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.
void SetDxy(fscal dxy)
Set the X/Y covariance.
void SetY(fscal y)
Set the Y coordinate.
void AddMonitorData(const MonitorData< ECounterKey, ETimerKey > &data, bool parallel=false)
Adds the other monitor data to this.
A container for all external parameters of the CA tracking algorithm.
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 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
DetIdTypeArr_t< MvdHit, StsHit, MuchHit, TrdHit, TofHit > HitTypes_t
constexpr DetIdArray_t< const char * > kDetName
Detector subsystem names.
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
constexpr ECbmModuleId ToCbmModuleId(EDetectorID detID)
Conversion map from EDetectorID to ECbmModuleId.
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.
std::tuple_element_t< static_cast< std::size_t >(DetID), std::tuple< Types... > > at
static Parameters< Float > Load(const std::string &fileName)
Loads parameters from file.