52namespace chron = std::chrono;
61 bool hasOutputFile = !opts.
OutputFile().empty();
64 if (!hasOutputFile && hasOutputType) {
65 throw FatalError(
"Output types specified, but no output file given: -o <file> missing");
68 if (hasOutputFile && !hasOutputType) {
69 throw FatalError(
"Output file specified, but no output types given: -O <types> missing");
73 throw FatalError(
"Archive compression enabled but compiled without Zstd: Remove --archive-compression flag");
77 throw FatalError(
"Local reco can't run without unpacking: Add 'Unpack' to the reco steps");
81 throw FatalError(
"Tracking can't run without local reco: Add 'LocalReco' to the reco steps");
87 if (
fInitialized)
throw std::runtime_error(
"Chain already initialized");
94 if (
Opts().HistogramUri() !=
"") {
96 std::make_shared<HistogramSender>(
Opts().HistogramUri(),
Opts().HistogramHwm(),
Opts().CompressHistograms());
101 fRunStartTimeNs = chron::duration_cast<chron::nanoseconds>(chron::system_clock::now().time_since_epoch()).count();
105 xpu::device_prop props{xpu::device::active()};
107 <<
" OpenMP threads)";
111 L_(info) <<
"Monitoring enabled, sending to " << opts.
MonitorUri();
118 L_(info) <<
"Using parameter files for setup " << parFiles.
setup;
154 sts::Unpack::Config cfg{.readout = readout, .walkMap = walkMap, .bCollectAuxData = bCollectAux};
155 fStsUnpack = std::make_unique<sts::Unpack>(cfg);
159 fStsDigiQa->RegisterReadoutSetup(readoutSetup);
167 fTofUnpack = std::make_unique<tof::Unpack>(cfg);
172 fTrdUnpack = std::make_unique<trd::Unpack>(cfg);
183 auto pTrackingSetup = std::make_shared<TrackingSetup>();
184 pTrackingSetup->SetContext(&
fContext);
185 pTrackingSetup->Use(Subsystem::STS,
Opts().Has(Subsystem::STS));
186 pTrackingSetup->Use(Subsystem::TRD,
Opts().Has(Subsystem::TRD));
187 pTrackingSetup->Use(Subsystem::TOF,
Opts().Has(Subsystem::TOF));
188 pTrackingSetup->Init();
192 fs::path configFile = opts.
ParamsDir() /
"EventbuildConfig.yaml";
198 auto pTriggerQa = std::make_shared<evbuild::V0TriggerQa>(
fQaManager);
202 fEventBuild->RegisterTrackingSetup(pTrackingSetup);
211 hitFinderPars.
setup = std::move(hitFinderSetup);
224 fTofHitFinder = std::make_unique<tof::Hitfind>(hitfindSetup);
236 fTrdHitfind = std::make_unique<trd::Hitfind>(setup, setup2d);
257 fTracking->RegisterSetup(pTrackingSetup);
291 fV0Finder = std::make_unique<V0FinderChain>();
305 L_(debug) <<
"CBM Reco finished initialization";
312 throw std::runtime_error(
"Chain not initialized");
320 xpu::scoped_timer t_(fmt::format(
"TS {}", ts.index()), &procMon.
time);
323 L_(info) <<
">>> Processing TS " << ts.index();
324 xpu::set<cbm::algo::Params>(
Params());
330 xpu::scoped_timer timerU(
"Unpack", &procMon.
timeUnpack);
345 L_(info) <<
"TS contains Digis: STS=" << digis.
fSts.size() <<
" MUCH=" << digis.
fMuch.size()
346 <<
" TOF=" << digis.
fTof.size() <<
" BMON=" << digis.
fBmon.size() <<
" TRD=" << digis.
fTrd.size()
347 <<
" TRD2D=" << digis.
fTrd2d.size() <<
" RICH=" << digis.
fRich.size() <<
" PSD=" << digis.
fPsd.size()
348 <<
" FSD=" << digis.
fFsd.size();
350 if (
fSender !=
nullptr &&
Opts().Has(Subsystem::STS)) {
361 xpu::scoped_timer timerSTS(
"STS Reco", &procMon.
timeSTS);
364 auto stsResults = (*fStsHitFinder)(digis.
fSts, storeClusters);
365 stsHitfinderMonitor = std::move(stsResults.monitor);
366 recoData.
stsHits = stsResults.hits;
367 recoData.
stsClusters = std::move(stsResults.clusters);
373 xpu::scoped_timer timerTOF(
"TOF Reco", &procMon.
timeTOF);
375 auto [caldigis, calmonitor] = (*fTofCalibrator)(digis.
fTof);
376 auto nUnknownRPC = calmonitor.fDigiCalibUnknownRPC;
377 if (nUnknownRPC > 0) {
378 L_(error) <<
"TOF Digis with unknown RPCs: " << nUnknownRPC;
380 auto [
hits, hitmonitor, digiindices] = (*fTofHitFinder)(caldigis);
392 xpu::scoped_timer timerTRD(
"TRD Reco", &procMon.
timeTRD);
395 const auto& digis1d = digis.
fTrd;
396 const auto& digis2d = digis.
fTrd2d;
398 allDigis.reserve(digis1d.size() + digis2d.size());
399 std::copy(digis1d.begin(), digis1d.end(), std::back_inserter(allDigis));
400 std::copy(digis2d.begin(), digis2d.end(), std::back_inserter(allDigis));
401 auto trdResults = (*fTrdHitfind)(allDigis);
402 recoData.
trdHits = std::move(std::get<0>(trdResults));
406 L_(info) <<
"TS contains Hits: STS=" << recoData.
stsHits.NElements() <<
" TOF=" << recoData.
tofHits.NElements()
407 <<
" TRD=" << recoData.
trdHits.NElements();
413 xpu::scoped_timer timerCA(
"CA", &procMon.
timeCA);
423 recoData.
tracks = std::move(trackingOutput.tracks);
424 std::sort(recoData.
tracks.begin(), recoData.
tracks.end(),
426 return track1.fParPV.Time() < track2.fParPV.Time();
432 std::vector<DigiEvent> events;
435 auto [ev, mon] =
fEventBuild->Run(digis, recoData);
436 events = std::move(ev);
437 evbuildMonitor = mon;
445 for (
auto& event : events) {
450 auto v0FinderMonitor =
fV0Finder->GetMonitor();
503 L_(info) <<
"Track finding in a timeslice:";
507 L_(info) <<
"Track finding in digi events:";
520 if (
Opts().TimingsFile() !=
"") {
521 std::ofstream file(
Opts().TimingsFile().
string());
529 if (
Opts().CollectKernelTimes()) {
537 L_(info) <<
"TS Processing time (Wall): " << timings.wall() <<
" ms";
548 auto [calDigis, calMonitor] = (*fBmonCalibrator)(digiEvent.
fBmon);
549 auto [
hits, hitMonitor, digiIndices] = (*fBmonHitFinder)(calDigis);
563 auto stsResults = (*fStsHitFinder)(digiEvent.
fSts);
565 if (stsResults.hits.NElements() < 4) {
569 recoEvent.
stsHits = stsResults.hits;
575 auto [caldigis, calmonitor] = (*fTofCalibrator)(digiEvent.
fTof);
576 auto [
hits, hitmonitor, digiindices] = (*fTofHitFinder)(caldigis);
578 if (
hits.NElements() < 2) {
589 const auto& digis1d = digiEvent.
fTrd;
590 const auto& digis2d = digiEvent.
fTrd2d;
592 allDigis.reserve(digis1d.size() + digis2d.size());
593 std::copy(digis1d.begin(), digis1d.end(), std::back_inserter(allDigis));
594 std::copy(digis2d.begin(), digis2d.end(), std::back_inserter(allDigis));
595 auto trdResults = (*fTrdHitfind)(allDigis);
597 recoEvent.
trdHits = std::move(std::get<0>(trdResults));
612 if (recoEvent.
tracks.size() < 2) {
620 triggers =
fV0Finder->ProcessEvent(recoEvent);
622 L_(info) <<
"!!! Found event with potential lambda candidates";
630template<
class Unpacker>
636 auto [digis, monitor, aux] = (*unpacker)(ts);
637 QueueUnpackerMetricsDet(monitor);
638 return std::make_tuple(digis, aux);
641template<
class MSMonitor>
650 auto MkKey = [&](std::string_view key) {
return fmt::format(
"{}{}", key,
Capitalize(det)); };
652 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
657 {MkKey(
"unpackNumMs"), monitor.
numMs},
667 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
669 {
"stsRecoNumClusters", (
unsigned long) monitor.
nClusterTotal},
670 {
"stsRecoNumHits", (
unsigned long) monitor.
nHitsTotal},
680 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
693 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
695 {
"trdRecoNumDigisIn", mon.
numDigis},
696 {
"trdRecoNumHits", mon.
numHits},
704 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
706 {
"tofCalibTimeTotal", mon.
fTime.wall()},
718 const MetricTagSet tags = {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}};
720 size_t nDigisTotal = 0;
721 size_t nDigisInEventsTotal = 0;
723 auto queueDetMetrics = [&](std::string_view det,
auto& detMon) {
724 size_t nDigis = detMon.nDigis;
725 size_t nDigisInEvents = detMon.nDigisInEvents;
726 double selectionRatio = nDigis > 0 ? double(nDigisInEvents) / nDigis : 0;
728 nDigisTotal += nDigis;
729 nDigisInEventsTotal += nDigisInEvents;
732 {{fmt::format(
"{}NumDigisTotal", det), nDigis},
733 {fmt::format(
"{}NumDigisInEvents", det), nDigisInEvents},
734 {fmt::format(
"{}EvSelectionRatio", det), selectionRatio}});
745 double totalSelectionRatio = nDigisTotal > 0 ? double(nDigisInEventsTotal) / nDigisTotal : 0;
760 {
"totalEvSelectionRatio", totalSelectionRatio}});
769 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
784 MetricFieldSet fields = {
785 {
"processingTimeTotal", mon.
time.wall()}, {
"processingThroughput",
FilterNan(mon.
time.throughput())},
793 fields.emplace_back(
"tsDelta", *mon.
tsDelta);
796 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
811 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
Collection of auxiliary data from unpackers (header)
source file for the ca::Track class
static vector< vector< QAHit > > hits
This file contains the definition of the ParFiles class.
QA manager for the online data reconstruction.
QA module for STS raw digis (source)
A chain class to execute CA tracking algorithm in online reconstruction (header)
A detector setup interface used for tracking input data initialization (source)
Calibrator for the BMON digis (implementation)
Class to store different triggers for a given event.
bool Test(ETrigger key) const
Tests a particular single trigger.
Data class for a single-channel message in the STS.
Data class for expanded digital TOF information.
const std::vector< RecoData > & OutputTypes() const
const std::string & MonitorUri() const
fs::path ParamsDir() const
bool ReconstructDigiEvents() const
uint64_t RunStart() const
bool CompressArchive() const
fs::path OutputFile() const
bool HasOutput(RecoData recoData) const
bool CollectAuxData() const
bool Has(fles::Subsystem detector) const
const std::string & ChildId() const
A vector that is partitioned into multiple subvectors.
std::unique_ptr< tof::Hitfind > fTofHitFinder
std::unique_ptr< tof::HitfindQa > fTofHitFinderQa
bool fbReconstructDigiEvents
std::optional< u64 > prevTsId
std::unique_ptr< TrackingChain > fTrackingEvent
Tracking in event.
void Init(const Options &)
std::unique_ptr< bmon::HitfindQa > fBmonHitFinderQa
std::unique_ptr< trd::Hitfind > fTrdHitfind
void QueueTofRecoMetrics(const tof::HitfindMonitorData &)
std::shared_ptr< HistogramSender > fSender
std::unique_ptr< bmon::Unpack > fBmonUnpack
std::unique_ptr< sts::Unpack > fStsUnpack
std::unique_ptr< rich::Unpack > fRichUnpack
std::unique_ptr< V0FinderChain > fV0Finder
V0-finding chain (in event or a bunch of events)
void QueueTrdRecoMetrics(const trd::HitfindMonitorData &)
std::unique_ptr< much::Unpack > fMuchUnpack
CbmEventTriggers ReconstructEvent(const DigiEvent &event)
auto RunUnpacker(const std::unique_ptr< Unpacker > &, const fles::Timeslice &) -> UnpackResult_t< Unpacker >
xpu::timings fTimesliceTimesAcc
evselect::Monitor fEvSelectingMonitor
Monitor for event selecting.
std::unique_ptr< sts::DigiQa > fStsDigiQa
Raw STS-digis QA.
std::unique_ptr< tof::Unpack > fTofUnpack
void QueueProcessingMetrics(const ProcessingMonitor &)
std::unique_ptr< qa::Manager > fQaManager
static double FilterNan(double x)
std::unique_ptr< bmon::Calibrate > fBmonCalibrator
void QueueStsRecoMetrics(const sts::HitfinderMon &)
std::unique_ptr< bmon::Hitfind > fBmonHitFinder
std::unique_ptr< tof::Calibrate > fTofCalibrator
void QueueTofCalibMetrics(const tof::CalibrateMonitorData &)
std::unique_ptr< trd2d::Unpack > fTrd2dUnpack
std::unique_ptr< qa::RecoGeneralQa > fGeneralQa
QA of online processing itself.
std::unique_ptr< sts::HitfinderChain > fStsHitFinder
std::unique_ptr< TrackingChain > fTracking
Tracking in timeslice.
void Validate(const Options &opts)
std::unique_ptr< trd::Unpack > fTrdUnpack
std::unique_ptr< evbuild::EventbuildChain > fEventBuild
RecoResults Run(const fles::Timeslice &)
void PrintTimings(xpu::timings &)
void QueueUnpackerMetricsDet(const UnpackMonitor< MSMonitor > &)
void QueueTrackingMetrics(const ca::TrackingMonitorData &)
void QueueEvbuildMetrics(const evbuild::EventbuildChainMonitorData &)
void QueueProcessingExtraMetrics(const ProcessingExtraMonitor &)
const RecoParams & Params() const
Monitor & GetMonitor() const
void SetContext(const ChainContext *ctx)
const Options & Opts() const
int GetCounterValue(ECounterKey key) const
Gets counter value.
const Timer & GetTimer(ETimerKey key) const
Gets timer.
std::string ToString() const
Prints counters summary to string.
void IncrementCounter(ECounterKey key)
Increments key counter by 1.
void Reset()
Resets the counters.
void StartTimer(ETimerKey key)
Starts timer.
void StopTimer(ETimerKey key)
Stops timer.
double GetTotalMs() const
Gets total time [ms].
Class representing an output track in the CA tracking algorithm.
Configuration of digi event building.
Provides the hardware-to-software address mapping for the CBM-RICH.
Provides the hardware-to-software address mapping for the CBM-STS.
A light-weight TRD hit class for online reconstruction, based on CbmTrdHit. .
@ RecoHit
number of reconstructed hits
@ RecoTrack
number of reconstructed tracks
@ SubTS
number of sub time-slices
@ RecoHitUsed
number of used reconstructed hits
@ EventsNeStsHits
Events with not enough STS hits.
@ LambdaCandidates
Number of lambda-candidates, returned by KFParticleFinder.
@ EventsTotal
Total number of events processed.
@ EventsSelected
Number of selected events.
@ EventsNeTofHits
Events with enough STS hits, but not enough TOF hits.
@ Timeslices
number of processed timeslices
@ EventsNeTracks
Events with enough hits, but not enough tracks.
@ KfpLambdaCandidates
Number of lambda-candidates.
size_t SizeBytes(const fles::Timeslice &ts)
T ReadFromFile(fs::path path)
std::string_view ToString(T t)
std::tuple< algo_traits::Output_t< Unpacker >, algo_traits::Aux_t< Unpacker > > UnpackResult_t
std::string MakeReportSubtimers(std::string_view title, const xpu::timings &t, size_t align)
Print timings from subtimers.
std::string MakeReportYaml(const xpu::timings &t)
Print timings in YAML format.
std::vector< T, PODAllocator< T > > PODVector
PODVector is a std::vector that doesn't initialize its elements.
std::string MakeReportSummary(std::string_view title, const xpu::timings &t, size_t align)
Only print the top-level times (Elapsed time, total kernel time, memcpy and memset times)....
std::string Capitalize(std::string_view str)
Capitalize the first letter of a string. The rest of the string is made lowercase.
Collection of auxiliary digi objects from different module unpackers.
UnpackAux< bmon::UnpackAuxData > fBmon
UnpackAux< trd2d::UnpackAuxData > fTrd2d
UnpackAux< rich::UnpackAuxData > fRich
UnpackAux< sts::UnpackAuxData > fSts
UnpackAux< much::UnpackAuxData > fMuch
UnpackAux< tof::UnpackAuxData > fTof
UnpackAux< trd::UnpackAuxData > fTrd
std::unique_ptr< cbm::Monitor > monitor
Collection of digis from all detector systems.
PODVector< CbmRichDigi > fRich
Unpacked RICH digis.
PODVector< CbmTrdDigi > fTrd
Unpacked TRD digis.
PODVector< CbmStsDigi > fSts
Unpacked STS digis.
PODVector< CbmTrdDigi > fTrd2d
Unpacked TRD2D digis.
PODVector< CbmFsdDigi > fFsd
Unpacked FSD digis.
PODVector< CbmTofDigi > fTof
Unpacked TOF digis.
PODVector< CbmPsdDigi > fPsd
Unpacked PSD digis.
PODVector< CbmMuchDigi > fMuch
Unpacked MUCH digis.
PODVector< CbmBmonDigi > fBmon
Unpacked Bmon digis.
Event data with event number and trigger time.
Indicates an unrecoverable error. Should tear down the process.
Class to hold the paths to the parameter files for the different detectors.
struct cbm::algo::ParFiles::@2 tof
struct cbm::algo::ParFiles::@0 bmon
struct cbm::algo::ParFiles::@1 sts
struct cbm::algo::ParFiles::@3 trd
std::optional< i64 > tsDelta
struct cbm::algo::RecoParams::STS::Memory memory
ca::Vector< std::vector< HitId_t > > trackTofHitIndices
PartitionedVector< trd::Hit > trdHits
PODVector< CbmMuchDigi > muchDigis
PartitionedVector< sts::Cluster > stsClusters
ca::Vector< ca::Track > tracks
PartitionedVector< tof::Hit > tofHits
ca::Vector< std::vector< HitId_t > > trackTrdHitIndices
std::vector< DigiEvent > events
PODVector< CbmTrdDigi > trd2dDigis
PartitionedVector< bmon::Hit > bmonHits
PartitionedSpan< sts::Hit > stsHits
PODVector< CbmTofDigi > tofDigis
ca::Vector< std::vector< HitId_t > > trackStsHitIndices
PODVector< CbmRichDigi > richDigis
PODVector< CbmStsDigi > stsDigis
PODVector< CbmTrdDigi > trdDigis
PODVector< CbmBmonDigi > bmonDigis
Output from the TrackingChain.
ca::Vector< ca::Track > tracks
Reconstructed tracks.
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.
Readout setup / Hardware cabling for BMon Used to create the hardware mapping for the BMon unpacker.
double ExpansionFactor() const
size_t numTriggers
Number of input triggers.
EventBuilderDetectorMonitorData much
Monitoring data for MUCH.
EventBuilderDetectorMonitorData rich
Monitoring data for RICH.
size_t numEvents
Number of built and selected events.
EventBuilderDetectorMonitorData sts
Monitoring data for STS.
EventBuilderDetectorMonitorData tof
Monitoring data for TOF.
EventBuilderDetectorMonitorData bmon
Monitoring data for Bmon.
EventBuilderDetectorMonitorData trd2d
Monitoring data for TRD2D.
xpu::timings time
Time for event building.
EventBuilderDetectorMonitorData trd
Monitoring data for TRD.
TimeClusterTriggerMonitorData hitMultTrigger
EventBuilderMonitorData evbuild
TimeClusterTriggerMonitorData digiMultTrigger
V0TriggerMoniData v0Trigger
xpu::timings time
Time for trigger building.
xpu::timings time
Time for trigger building.
size_t numTrackPairsAfterTimeCut
RecoParams::STS::Memory memory
i32 nClusterBucketOverflow
static LandauTable FromFile(fs::path path)
Readout setup / Hardware cabling for STS Used to create the hardware mapping for the STS unpacker.
Monitoring data for calibration.
size_t fDigiCalibUnknownRPC
Monitoring data for hitfinding.
Readout setup / Hardware cabling for TOF Used to create the hardware mapping for the TOF unpacker.
Monitoring data for hitfinding.