CbmRoot
Loading...
Searching...
No Matches
Reco.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Felix Weiglhofer [committer], P.-A. Loizeau */
4#include "Reco.h"
5
7#include "AuxDigiData.h"
8#include "BuildInfo.h"
9#include "CbmDigiEvent.h"
10#include "EventbuildChain.h"
11#include "Exceptions.h"
12#include "HistogramSender.h"
13#include "ParFiles.h"
14#include "RecoGeneralQa.h"
15#include "StsDigiQa.h"
16#include "TrackingSetup.h"
17#include "bmon/ReadoutConfig.h"
18#include "bmon/Unpack.h"
19#include "ca/TrackingChain.h"
21#include "compat/OpenMP.h"
22#include "evbuild/Config.h"
23#include "much/Unpack.h"
24#include "rich/Unpack.h"
25#include "sts/ChannelMaskSet.h"
26#include "sts/HitfinderChain.h"
27#include "sts/Unpack.h"
28#include "tof/Calibrate.h"
29#include "tof/Hitfind.h"
30#include "tof/Unpack.h"
31#include "trd/Hitfind.h"
32#include "trd/Unpack.h"
33#include "trd2d/Unpack.h"
34#include "util/TimingsFormat.h"
35#include "util/TsUtils.h"
36#include "yaml/Yaml.h"
37
38#include <Monitor.hpp>
39#include <System.hpp>
40
41#include <xpu/host.h>
42
43using namespace cbm::algo;
44using fles::Subsystem;
45
46namespace chron = std::chrono;
47
48Reco::Reco() {}
50
51void Reco::Validate(const Options& opts)
52{
53 if (!fs::exists(opts.ParamsDir())) throw FatalError("ParamsDir does not exist: {}", opts.ParamsDir().string());
54
55 bool hasOutputFile = !opts.OutputFile().empty();
56 bool hasOutputType = !opts.OutputTypes().empty();
57
58 if (!hasOutputFile && hasOutputType) {
59 throw FatalError("Output types specified, but no output file given: -o <file> missing");
60 }
61
62 if (hasOutputFile && !hasOutputType) {
63 throw FatalError("Output file specified, but no output types given: -O <types> missing");
64 }
65
67 throw FatalError("Archive compression enabled but compiled without Zstd: Remove --archive-compression flag");
68 }
69
70 if (opts.Has(Step::LocalReco) && !opts.Has(Step::Unpack)) {
71 throw FatalError("Local reco can't run without unpacking: Add 'Unpack' to the reco steps");
72 }
73
74 if (opts.Has(Step::Tracking) && !opts.Has(Step::LocalReco)) {
75 throw FatalError("Tracking can't run without local reco: Add 'LocalReco' to the reco steps");
76 }
77}
78
79void Reco::Init(const Options& opts)
80{
81 if (fInitialized) throw std::runtime_error("Chain already initialized");
82
83 Validate(opts);
84
85 fContext.opts = opts;
87
88 if (Opts().HistogramUri() != "") {
89 fSender =
90 std::make_shared<HistogramSender>(Opts().HistogramUri(), Opts().HistogramHwm(), Opts().CompressHistograms());
91 // fContext.sender = fSender;
92
94 if (0 == fRunStartTimeNs) {
95 fRunStartTimeNs = chron::duration_cast<chron::nanoseconds>(chron::system_clock::now().time_since_epoch()).count();
96 }
97 }
98
99 xpu::device_prop props{xpu::device::active()};
100 L_(info) << "Running CBM Reco on Device '" << props.name() << "' (Using " << openmp::GetMaxThreads()
101 << " OpenMP threads)";
102
103 if (!opts.MonitorUri().empty()) {
104 fContext.monitor = std::make_unique<cbm::Monitor>(opts.MonitorUri());
105 L_(info) << "Monitoring enabled, sending to " << opts.MonitorUri();
106 }
107
108 // Reco Params
109 fContext.recoParams = yaml::ReadFromFile<RecoParams>(opts.ParamsDir() / "RecoParams.yaml");
110
111 ParFiles parFiles(opts.RunId());
112 L_(info) << "Using parameter files for setup " << parFiles.setup;
113
114 // General QA
115 if (fSender != nullptr) {
116 fGeneralQa = std::make_unique<qa::RecoGeneralQa>(fRunStartTimeNs, fSender);
117 }
118
119 // Unpackers
120 if (Opts().Has(Subsystem::BMON) && Opts().Has(Step::Unpack)) {
121 bmon::ReadoutSetup readoutSetup =
123 bmon::ReadoutConfig cfg{readoutSetup};
124 fBmonUnpack = std::make_unique<bmon::Unpack>(cfg);
125 }
126
127 if (Opts().Has(Subsystem::MUCH) && Opts().Has(Step::Unpack)) {
129 fMuchUnpack = std::make_unique<much::Unpack>(cfg);
130 }
131
132 if (Opts().Has(Subsystem::RICH) && Opts().Has(Step::Unpack)) {
134 fRichUnpack = std::make_unique<rich::Unpack>(cfg);
135 }
136
137 if (Opts().Has(Subsystem::STS) && Opts().Has(Step::Unpack)) {
138 sts::ReadoutSetup readoutSetup = yaml::ReadFromFile<sts::ReadoutSetup>(Opts().ParamsDir() / parFiles.sts.readout);
139 auto chanMask = yaml::ReadFromFile<sts::ChannelMaskSet>(Opts().ParamsDir() / parFiles.sts.chanMask);
140 auto walkMap = yaml::ReadFromFile<sts::WalkMap>(Opts().ParamsDir() / parFiles.sts.walkMap);
141 bool bCollectAux = (fSender != nullptr && Opts().CollectAuxData());
142 sts::ReadoutConfig readout{readoutSetup, chanMask};
143 sts::Unpack::Config cfg{.readout = readout, .walkMap = walkMap, .bCollectAuxData = bCollectAux};
144 fStsUnpack = std::make_unique<sts::Unpack>(cfg);
145 if (fSender != nullptr && Opts().Has(QaStep::UnpackSts)) {
146 fStsDigiQa = std::make_unique<sts::DigiQa>(fSender);
147 fStsDigiQa->SetUseAuxData(bCollectAux);
148 fStsDigiQa->RegisterReadoutSetup(readoutSetup);
149 fStsDigiQa->Init();
150 }
151 }
152
153 if (Opts().Has(Subsystem::TOF) && Opts().Has(Step::Unpack)) {
154 tof::ReadoutSetup readoutSetup = yaml::ReadFromFile<tof::ReadoutSetup>(Opts().ParamsDir() / parFiles.tof.readout);
155 tof::ReadoutConfig cfg{readoutSetup};
156 fTofUnpack = std::make_unique<tof::Unpack>(cfg);
157 }
158
159 if (Opts().Has(Subsystem::TRD) && Opts().Has(Step::Unpack)) {
160 auto cfg = yaml::ReadFromFile<trd::ReadoutConfig>(Opts().ParamsDir() / parFiles.trd.readout);
161 fTrdUnpack = std::make_unique<trd::Unpack>(cfg);
162 }
163
164 if (Opts().Has(Subsystem::TRD2D) && Opts().Has(Step::Unpack)) {
165 auto cfg = yaml::ReadFromFile<trd2d::ReadoutConfig>(Opts().ParamsDir() / parFiles.trd.readout2d);
166 fTrd2dUnpack = std::make_unique<trd2d::Unpack>(cfg);
167 }
168
169 // --- Tracking setup
170 auto pTrackingSetup = std::make_shared<TrackingSetup>();
171 pTrackingSetup->SetContext(&fContext);
172 pTrackingSetup->Use(Subsystem::STS, Opts().Has(Subsystem::STS));
173 pTrackingSetup->Use(Subsystem::TRD, Opts().Has(Subsystem::TRD));
174 pTrackingSetup->Use(Subsystem::TOF, Opts().Has(Subsystem::TOF));
175 pTrackingSetup->Init();
176
177 // --- Event building
178 if (Opts().Has(Step::DigiTrigger)) {
179 fs::path configFile = opts.ParamsDir() / "EventbuildConfig.yaml";
180 evbuild::Config config(YAML::LoadFile(configFile.string()));
182 std::make_unique<evbuild::EventbuildChain>(config, (Opts().Has(QaStep::EventBuilding) ? fSender : nullptr));
183 fEventBuild->RegisterTrackingSetup(pTrackingSetup);
184 }
185
186 // STS Hitfinder
187 if (Opts().Has(fles::Subsystem::STS) && Opts().Has(Step::LocalReco)) {
188 sts::HitfinderPars hitFinderSetup =
190 hitFinderSetup.landauTable = sts::LandauTable::FromFile(opts.ParamsDir() / "LandauWidthTable.txt");
191 sts::HitfinderChainPars hitFinderPars;
192 hitFinderPars.setup = std::move(hitFinderSetup);
193 hitFinderPars.memory = Params().sts.memory;
194 fStsHitFinder = std::make_unique<sts::HitfinderChain>();
195 fStsHitFinder->SetContext(&fContext);
196 fStsHitFinder->SetParameters(hitFinderPars);
197 }
198
199
200 // TOF Hitfinder
201 if (Opts().Has(fles::Subsystem::TOF) && Opts().Has(Step::LocalReco)) {
202 auto calibSetup = yaml::ReadFromFile<tof::CalibrateSetup>(opts.ParamsDir() / parFiles.tof.calibrate);
203 fTofCalibrator = std::make_unique<tof::Calibrate>(calibSetup);
204
205 auto hitfindSetup = yaml::ReadFromFile<tof::HitfindSetup>(opts.ParamsDir() / parFiles.tof.hitfinder);
206 fTofHitFinder = std::make_unique<tof::Hitfind>(hitfindSetup);
207 }
208
209 if (Opts().Has(fles::Subsystem::TRD) && Opts().Has(Step::LocalReco)) {
210 auto setup = yaml::ReadFromFile<trd::HitfindSetup>(opts.ParamsDir() / parFiles.trd.hitfinder);
211 auto setup2d = yaml::ReadFromFile<trd::Hitfind2DSetup>(opts.ParamsDir() / parFiles.trd.hitfinder2d);
212 fTrdHitfind = std::make_unique<trd::Hitfind>(setup, setup2d);
213 }
214
215 // Tracking
216 if (Opts().Has(Step::Tracking)) {
217 fTracking = std::make_unique<TrackingChain>(Opts().Has(QaStep::Tracking) ? fSender : nullptr);
218 fTracking->RegisterSetup(pTrackingSetup);
219 fTracking->SetContext(&fContext);
220 fTracking->Init();
221 }
222
223 fInitialized = true;
224
225 L_(debug) << "CBM Reco finished initialization";
226}
227
228
229RecoResults Reco::Run(const fles::Timeslice& ts)
230{
231 if (!fInitialized) {
232 throw std::runtime_error("Chain not initialized");
233 }
234
235 ProcessingMonitor procMon;
236
237 RecoResults recoData;
238 RecoResults results;
239 {
240 xpu::scoped_timer t_(fmt::format("TS {}", ts.index()), &procMon.time);
241 xpu::t_add_bytes(ts_utils::SizeBytes(ts));
242
243 L_(info) << ">>> Processing TS " << ts.index();
244 xpu::set<cbm::algo::Params>(Params());
245
246 DigiData digis;
247 AuxDigiData auxDigis;
248
249 if (Opts().Has(Step::Unpack)) {
250 xpu::scoped_timer timerU("Unpack", &procMon.timeUnpack);
251 xpu::t_add_bytes(ts_utils::SizeBytes(ts));
252
253 std::tie(digis.fBmon, auxDigis.fBmon) = RunUnpacker(fBmonUnpack, ts);
254 std::tie(digis.fMuch, auxDigis.fMuch) = RunUnpacker(fMuchUnpack, ts);
255 std::tie(digis.fRich, auxDigis.fRich) = RunUnpacker(fRichUnpack, ts);
256 std::tie(digis.fSts, auxDigis.fSts) = RunUnpacker(fStsUnpack, ts);
257 std::tie(digis.fTof, auxDigis.fTof) = RunUnpacker(fTofUnpack, ts);
258 std::tie(digis.fTrd, auxDigis.fTrd) = RunUnpacker(fTrdUnpack, ts);
259 std::tie(digis.fTrd2d, auxDigis.fTrd2d) = RunUnpacker(fTrd2dUnpack, ts);
260
261 // No unpackers for these yet
262 // digis.fPsd = RunUnpacker(fPsdUnpack, ts);
263 // digis.fFsd = RunUnpacker(fFsdUnpack, ts);
264
265 L_(info) << "TS contains Digis: STS=" << digis.fSts.size() << " MUCH=" << digis.fMuch.size()
266 << " TOF=" << digis.fTof.size() << " BMON=" << digis.fBmon.size() << " TRD=" << digis.fTrd.size()
267 << " TRD2D=" << digis.fTrd2d.size() << " RICH=" << digis.fRich.size() << " PSD=" << digis.fPsd.size()
268 << " FSD=" << digis.fFsd.size();
269 // --- Raw digi QAs
270 if (fSender != nullptr && Opts().Has(Subsystem::STS)) {
271 fStsDigiQa->RegisterDigiData(&digis.fSts);
272 fStsDigiQa->RegisterAuxDigiData(&auxDigis.fSts);
273 fStsDigiQa->SetTimesliceIndex(ts.index());
274 fStsDigiQa->Exec();
275 }
276 }
277
278
279 sts::HitfinderMon stsHitfinderMonitor;
280 if (fStsHitFinder) {
281 xpu::scoped_timer timerSTS("STS Reco", &procMon.timeSTS);
282 xpu::t_add_bytes(digis.fSts.size() * sizeof(CbmStsDigi));
283 bool storeClusters = Opts().HasOutput(RecoData::Cluster);
284 auto stsResults = (*fStsHitFinder)(digis.fSts, storeClusters);
285 stsHitfinderMonitor = std::move(stsResults.monitor);
286 recoData.stsHits = stsResults.hits;
287 recoData.stsClusters = std::move(stsResults.clusters);
288 QueueStsRecoMetrics(stsHitfinderMonitor);
289 }
290
292 if (Opts().Has(Step::LocalReco) && Opts().Has(fles::Subsystem::TOF)) {
293 xpu::scoped_timer timerTOF("TOF Reco", &procMon.timeTOF);
294 xpu::t_add_bytes(digis.fTof.size() * sizeof(CbmTofDigi));
295 auto [caldigis, calmonitor] = (*fTofCalibrator)(digis.fTof);
296 auto nUnknownRPC = calmonitor.fDigiCalibUnknownRPC;
297 if (nUnknownRPC > 0) {
298 L_(error) << "TOF Digis with unknown RPCs: " << nUnknownRPC;
299 }
300 auto [hits, hitmonitor, digiindices] = (*fTofHitFinder)(caldigis);
301 recoData.tofHits = std::move(hits);
302 QueueTofCalibMetrics(calmonitor);
303 QueueTofRecoMetrics(hitmonitor);
304 }
305
307 if (fTrdHitfind) {
308 xpu::scoped_timer timerTRD("TRD Reco", &procMon.timeTRD);
309 xpu::t_add_bytes(digis.fTrd.size() * sizeof(CbmTrdDigi));
310 // FIXME: additional copy of digis, figure out how to pass 1d + 2d digis at once to hitfinder
311 const auto& digis1d = digis.fTrd;
312 const auto& digis2d = digis.fTrd2d;
313 PODVector<CbmTrdDigi> allDigis{};
314 allDigis.reserve(digis1d.size() + digis2d.size());
315 std::copy(digis1d.begin(), digis1d.end(), std::back_inserter(allDigis));
316 std::copy(digis2d.begin(), digis2d.end(), std::back_inserter(allDigis));
317 auto trdResults = (*fTrdHitfind)(allDigis);
318 recoData.trdHits = std::move(std::get<0>(trdResults));
319 QueueTrdRecoMetrics(std::get<1>(trdResults));
320 }
321
322 L_(info) << "TS contains Hits: STS=" << recoData.stsHits.NElements() << " TOF=" << recoData.tofHits.NElements()
323 << " TRD=" << recoData.trdHits.NElements();
324
325
326 // --- Tracking
327 TrackingChain::Output_t trackingOutput{};
328 if (Opts().Has(Step::Tracking)) {
329 xpu::scoped_timer timerCA("CA", &procMon.timeCA);
330 xpu::t_add_bytes(recoData.stsHits.NElements() * sizeof(sts::Hit));
331 xpu::t_add_bytes(recoData.tofHits.NElements() * sizeof(tof::Hit));
332 xpu::t_add_bytes(recoData.trdHits.NElements() * sizeof(trd::Hit));
334 .stsHits = recoData.stsHits,
335 .tofHits = recoData.tofHits,
336 .trdHits = recoData.trdHits,
337 };
338 trackingOutput = fTracking->Run(input);
339 recoData.tracks = std::move(trackingOutput.tracks);
340 std::sort(recoData.tracks.begin(), recoData.tracks.end(),
341 [](const cbm::algo::ca::Track& track1, const cbm::algo::ca::Track& track2) {
342 return track1.fParPV.Time() < track2.fParPV.Time();
343 });
344 QueueTrackingMetrics(trackingOutput.monitorData);
345 }
346
347 // --- Event building
348 std::vector<DigiEvent> events;
350 if (Opts().Has(Step::DigiTrigger)) {
351 auto [ev, mon] = fEventBuild->Run(digis, recoData);
352 events = std::move(ev);
353 evbuildMonitor = mon;
354 QueueEvbuildMetrics(evbuildMonitor);
355 }
356
357 // --- Filter data for output
358 if (Opts().HasOutput(RecoData::DigiTimeslice)) {
359 results.bmonDigis = std::move(digis.fBmon);
360 results.stsDigis = std::move(digis.fSts);
361 results.muchDigis = std::move(digis.fMuch);
362 results.trd2dDigis = std::move(digis.fTrd2d);
363 results.trdDigis = std::move(digis.fTrd);
364 results.tofDigis = std::move(digis.fTof);
365 results.richDigis = std::move(digis.fRich);
366 }
367 if (Opts().HasOutput(RecoData::Track)) {
368 results.tracks = std::move(recoData.tracks);
369 results.trackStsHitIndices = std::move(trackingOutput.stsHitIndices);
370 results.trackTofHitIndices = std::move(trackingOutput.tofHitIndices);
371 }
372 if (Opts().HasOutput(RecoData::DigiEvent)) results.events = std::move(events);
373 if (Opts().HasOutput(RecoData::Cluster)) results.stsClusters = std::move(recoData.stsClusters);
374 if (Opts().HasOutput(RecoData::Hit)) {
375 results.stsHits = std::move(recoData.stsHits);
376 results.tofHits = std::move(recoData.tofHits);
377 results.trdHits = std::move(recoData.trdHits);
378 }
379
380 // General QA
381 if (fSender != nullptr) {
382 (*fGeneralQa)(ts);
383 }
384 }
385 PrintTimings(procMon.time);
386 if (prevTsId) {
387 procMon.tsDelta = ts.index() - *prevTsId;
388 }
389 prevTsId = ts.index();
390 QueueProcessingMetrics(procMon);
391
392 return results;
393}
394
396{
397 if (fStsHitFinder) {
398 fStsHitFinder->Finalize();
399 }
400 if (fTracking) {
401 fTracking->Finalize();
402 }
403
404 if (Opts().Profiling() >= ProfilingSummary) {
405 L_(info) << MakeReportSubtimers("Run Summary", fTimesliceTimesAcc) << "\n"
407
408 if (Opts().TimingsFile() != "") {
409 std::ofstream file(Opts().TimingsFile().string());
411 }
412 }
413}
414
415void Reco::PrintTimings(xpu::timings& timings)
416{
417 if (Opts().CollectKernelTimes()) {
418 fTimesliceTimesAcc.merge(timings);
419 }
420
421 if (Opts().Profiling() >= ProfilingPerTS) {
422 L_(info) << MakeReportSubtimers("TS timings", timings) << "\n" << MakeReportSummary("Total", timings);
423 }
424 else {
425 L_(info) << "TS Processing time (Wall): " << timings.wall() << " ms";
426 }
427}
428
429template<class Unpacker>
430auto Reco::RunUnpacker(const std::unique_ptr<Unpacker>& unpacker, const fles::Timeslice& ts) -> UnpackResult_t<Unpacker>
431{
432 if (!unpacker) {
433 return {};
434 }
435 auto [digis, monitor, aux] = (*unpacker)(ts);
436 QueueUnpackerMetricsDet(monitor);
437 return std::make_tuple(digis, aux);
438}
439
440template<class MSMonitor>
442{
443 if (!HasMonitor()) {
444 return;
445 }
446
447 std::string_view det = ToString(monitor.system);
448
449 auto MkKey = [&](std::string_view key) { return fmt::format("{}{}", key, Capitalize(det)); };
450
451 GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}},
452 {
453 {MkKey("unpackBytesIn"), monitor.sizeBytesIn},
454 {MkKey("unpackBytesOut"), monitor.sizeBytesOut},
455 {MkKey("unpackExpansionFactor"), monitor.ExpansionFactor()},
456 {MkKey("unpackNumMs"), monitor.numMs},
457 {MkKey("unpackNumErrInvalidSysVer"), monitor.errInvalidSysVer},
458 {MkKey("unpackNumErrInvalidEqId"), monitor.errInvalidEqId},
459 });
460}
461
463{
464 if (!HasMonitor()) return;
465
466 GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}},
467 {
468 {"stsRecoNumClusters", (unsigned long) monitor.nClusterTotal},
469 {"stsRecoNumHits", (unsigned long) monitor.nHitsTotal},
470 {"stsRecoNumClusterBucketOverflow", monitor.nClusterBucketOverflow},
471 {"stsRecoNumHitBucketOverflow", monitor.nHitBucketOverflow},
472 });
473}
474
476{
477 if (!HasMonitor()) return;
478
479 GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}},
480 {
481 {"tofRecoNumDigisIn", mon.fNumDigis},
482 {"tofRecoNumHits", mon.fNumHits},
483 });
484}
485
487{
488 if (!HasMonitor()) {
489 return;
490 }
491
492 GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}},
493 {
494 {"trdRecoNumDigisIn", mon.numDigis},
495 {"trdRecoNumHits", mon.numHits},
496 });
497}
498
500{
501 if (!HasMonitor()) return;
502
503 GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}},
504 {
505 {"tofCalibTimeTotal", mon.fTime.wall()},
506 {"tofCalibThroughput", FilterNan(mon.fTime.throughput())},
507 {"tofCalibNumDigisIn", mon.fNumDigis},
508 {"tofCalibUnknownRPC", mon.fDigiCalibUnknownRPC},
509 });
510}
511
512
514{
515 if (!HasMonitor()) return;
516
517 const MetricTagSet tags = {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}};
518
519 size_t nDigisTotal = 0;
520 size_t nDigisInEventsTotal = 0;
521
522 auto queueDetMetrics = [&](std::string_view det, auto& detMon) {
523 size_t nDigis = detMon.nDigis;
524 size_t nDigisInEvents = detMon.nDigisInEvents;
525 double selectionRatio = nDigis > 0 ? double(nDigisInEvents) / nDigis : 0;
526
527 nDigisTotal += nDigis;
528 nDigisInEventsTotal += nDigisInEvents;
529
530 GetMonitor().QueueMetric("cbmreco", tags,
531 {{fmt::format("{}NumDigisTotal", det), nDigis},
532 {fmt::format("{}NumDigisInEvents", det), nDigisInEvents},
533 {fmt::format("{}EvSelectionRatio", det), selectionRatio}});
534 };
535
536 queueDetMetrics("sts", mon.evbuild.sts);
537 queueDetMetrics("much", mon.evbuild.much);
538 queueDetMetrics("tof", mon.evbuild.tof);
539 queueDetMetrics("bmon", mon.evbuild.bmon);
540 queueDetMetrics("trd", mon.evbuild.trd);
541 queueDetMetrics("trd2d", mon.evbuild.trd2d);
542 queueDetMetrics("rich", mon.evbuild.rich);
543
544 double totalSelectionRatio = nDigisTotal > 0 ? double(nDigisInEventsTotal) / nDigisTotal : 0;
545 GetMonitor().QueueMetric("cbmreco", tags,
546 {{"digiTriggerTimeTotal", mon.digiMultTrigger.time.wall()},
547 {"digiTriggerThroughput", FilterNan(mon.digiMultTrigger.time.throughput())},
548 {"hitTriggerTimeTotal", mon.hitMultTrigger.time.wall()},
549 {"hitTriggerThroughput", FilterNan(mon.hitMultTrigger.time.throughput())},
550 {"v0TriggerNumTrackPairs", mon.v0Trigger.numTrackPairs},
551 {"v0TriggerNumTrackPairsCoinc", mon.v0Trigger.numTrackPairsAfterTimeCut},
552 {"v0TriggerErrTracksUnsorted", mon.v0Trigger.errTracksUnsorted},
553 {"v0TriggerTimeTotal", mon.v0Trigger.time.wall()},
554 {"v0TriggerThroughput", FilterNan(mon.v0Trigger.time.throughput())},
555 {"eventbuildTimeTotal", mon.evbuild.time.wall()},
556 {"eventbuildThroughput", FilterNan(mon.evbuild.time.throughput())},
557 {"numTrigger", mon.evbuild.numTriggers},
558 {"numEvents", mon.evbuild.numEvents},
559 {"totalEvSelectionRatio", totalSelectionRatio}});
560}
561
563{
564 if (!HasMonitor()) {
565 return;
566 }
567
568 GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}},
569 {{"caTrackFinderTime", monitor.GetTimer(ca::ETimer::FindTracks).GetTotalMs()},
570 {"caTrackFitterTime", monitor.GetTimer(ca::ETimer::FitTracks).GetTotalMs()},
571 {"caNofRecoTracks", monitor.GetCounterValue(ca::ECounter::RecoTrack)},
572 {"caNofRecoHitsTotal", monitor.GetCounterValue(ca::ECounter::RecoHit)},
573 {"caNofRecoHitsUsed", monitor.GetCounterValue(ca::ECounter::RecoHitUsed)},
574 {"caNofWindows", monitor.GetCounterValue(ca::ECounter::SubTS)}});
575}
576
578{
579 if (!HasMonitor()) {
580 return;
581 }
582
583 MetricFieldSet fields = {
584 {"processingTimeTotal", mon.time.wall()}, {"processingThroughput", FilterNan(mon.time.throughput())},
585 {"caRecoTimeTotal", mon.timeCA.wall()}, {"caRecoThroughput", FilterNan(mon.timeCA.throughput())},
586 {"trdRecoTimeTotal", mon.timeTRD.wall()}, {"trdRecoThroughput", FilterNan(mon.timeTRD.throughput())},
587 {"tofRecoTimeTotal", mon.timeTOF.wall()}, {"tofRecoThroughput", FilterNan(mon.timeTOF.throughput())},
588 {"stsRecoTimeTotal", mon.timeSTS.wall()}, {"stsRecoThroughput", FilterNan(mon.timeSTS.throughput())},
589 {"unpackTimeTotal", mon.timeUnpack.wall()}, {"unpackThroughput", FilterNan(mon.timeUnpack.throughput())}};
590
591 if (mon.tsDelta) {
592 fields.emplace_back("tsDelta", *mon.tsDelta);
593 }
594
595 GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}},
596 std::move(fields));
597}
598
600{
601 if (!HasMonitor()) {
602 return;
603 }
604
605 MetricFieldSet fields = {{"processingTimeIdle", FilterNan(mon.timeIdle)},
606 {"processingTimeWriteArchive", mon.timeWriteArchive.wall()},
607 {"processingThroughputWriteArchive", FilterNan(mon.timeWriteArchive.throughput())},
608 {"processingBytesWritten", FilterNan(mon.bytesWritten)}};
609
610 GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}},
611 std::move(fields));
612}
#define L_(level)
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 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)
Data class for a single-channel message in the STS.
Definition CbmStsDigi.h:40
Data class for expanded digital TOF information.
Definition CbmTofDigi.h:47
const std::vector< RecoData > & OutputTypes() const
const std::string & MonitorUri() const
fs::path ParamsDir() const
uint64_t RunStart() const
bool CompressArchive() const
uint64_t RunId() 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
Definition Reco.h:163
ChainContext fContext
Definition Reco.h:136
std::optional< u64 > prevTsId
Definition Reco.h:141
void Init(const Options &)
Definition Reco.cxx:79
std::unique_ptr< trd::Hitfind > fTrdHitfind
Definition Reco.h:168
void QueueTofRecoMetrics(const tof::HitfindMonitorData &)
Definition Reco.cxx:475
std::shared_ptr< HistogramSender > fSender
Definition Reco.h:138
std::unique_ptr< bmon::Unpack > fBmonUnpack
Definition Reco.h:147
std::unique_ptr< sts::Unpack > fStsUnpack
Definition Reco.h:156
std::unique_ptr< rich::Unpack > fRichUnpack
Definition Reco.h:153
void QueueTrdRecoMetrics(const trd::HitfindMonitorData &)
Definition Reco.cxx:486
std::unique_ptr< much::Unpack > fMuchUnpack
Definition Reco.h:150
bool fInitialized
Definition Reco.h:135
auto RunUnpacker(const std::unique_ptr< Unpacker > &, const fles::Timeslice &) -> UnpackResult_t< Unpacker >
Definition Reco.cxx:430
uint64_t fRunStartTimeNs
Definition Reco.h:139
void Finalize()
Definition Reco.cxx:395
xpu::timings fTimesliceTimesAcc
Definition Reco.h:137
std::unique_ptr< sts::DigiQa > fStsDigiQa
Raw STS-digis QA.
Definition Reco.h:157
std::unique_ptr< tof::Unpack > fTofUnpack
Definition Reco.h:161
void QueueProcessingMetrics(const ProcessingMonitor &)
Definition Reco.cxx:577
static double FilterNan(double x)
Definition Reco.h:176
void QueueStsRecoMetrics(const sts::HitfinderMon &)
Definition Reco.cxx:462
std::unique_ptr< tof::Calibrate > fTofCalibrator
Definition Reco.h:162
void QueueTofCalibMetrics(const tof::CalibrateMonitorData &)
Definition Reco.cxx:499
std::unique_ptr< trd2d::Unpack > fTrd2dUnpack
Definition Reco.h:167
std::unique_ptr< qa::RecoGeneralQa > fGeneralQa
QA of online processing itself.
Definition Reco.h:144
std::unique_ptr< sts::HitfinderChain > fStsHitFinder
Definition Reco.h:158
std::unique_ptr< TrackingChain > fTracking
Definition Reco.h:174
void Validate(const Options &opts)
Definition Reco.cxx:51
std::unique_ptr< trd::Unpack > fTrdUnpack
Definition Reco.h:166
std::unique_ptr< evbuild::EventbuildChain > fEventBuild
Definition Reco.h:171
RecoResults Run(const fles::Timeslice &)
Definition Reco.cxx:229
void PrintTimings(xpu::timings &)
Definition Reco.cxx:415
void QueueUnpackerMetricsDet(const UnpackMonitor< MSMonitor > &)
Definition Reco.cxx:441
void QueueTrackingMetrics(const ca::TrackingMonitorData &)
Definition Reco.cxx:562
void QueueEvbuildMetrics(const evbuild::EventbuildChainMonitorData &)
Definition Reco.cxx:513
void QueueProcessingExtraMetrics(const ProcessingExtraMonitor &)
Definition Reco.cxx:599
const RecoParams & Params() const
Definition SubChain.h:21
Monitor & GetMonitor() const
Definition SubChain.h:25
bool HasMonitor() const
Definition SubChain.h:23
void SetContext(const ChainContext *ctx)
Definition SubChain.h:18
const Options & Opts() const
Definition SubChain.h:20
int GetCounterValue(ECounterKey key) const
Gets counter value.
const Timer & GetTimer(ETimerKey key) const
Gets timer.
double GetTotalMs() const
Gets total time [ms].
Definition CaTimer.h:80
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. .
constexpr bool WITH_ZSTD
Definition BuildInfo.h:62
@ RecoHit
number of reconstructed hits
@ RecoTrack
number of reconstructed tracks
@ SubTS
number of sub time-slices
@ RecoHitUsed
number of used reconstructed hits
int GetMaxThreads()
Definition OpenMP.h:46
size_t SizeBytes(const fles::Timeslice &ts)
Definition TsUtils.h:10
T ReadFromFile(fs::path path)
Definition Yaml.h:51
std::string_view ToString(T t)
Definition EnumDict.h:64
std::tuple< algo_traits::Output_t< Unpacker >, algo_traits::Aux_t< Unpacker > > UnpackResult_t
Definition Reco.h:87
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.
Definition PODVector.h:17
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.
Definition StlUtils.cxx:9
Collection of auxiliary digi objects from different module unpackers.
Definition AuxDigiData.h:27
UnpackAux< bmon::UnpackAuxData > fBmon
Definition AuxDigiData.h:28
UnpackAux< trd2d::UnpackAuxData > fTrd2d
Definition AuxDigiData.h:34
UnpackAux< rich::UnpackAuxData > fRich
Definition AuxDigiData.h:30
UnpackAux< sts::UnpackAuxData > fSts
Definition AuxDigiData.h:31
UnpackAux< much::UnpackAuxData > fMuch
Definition AuxDigiData.h:29
UnpackAux< tof::UnpackAuxData > fTof
Definition AuxDigiData.h:32
UnpackAux< trd::UnpackAuxData > fTrd
Definition AuxDigiData.h:33
std::unique_ptr< cbm::Monitor > monitor
Collection of digis from all detector systems.
Definition DigiData.h:31
PODVector< CbmRichDigi > fRich
Unpacked RICH digis.
Definition DigiData.h:38
PODVector< CbmTrdDigi > fTrd
Unpacked TRD digis.
Definition DigiData.h:36
PODVector< CbmStsDigi > fSts
Unpacked STS digis.
Definition DigiData.h:32
PODVector< CbmTrdDigi > fTrd2d
Unpacked TRD2D digis.
Definition DigiData.h:37
PODVector< CbmFsdDigi > fFsd
Unpacked FSD digis.
Definition DigiData.h:40
PODVector< CbmTofDigi > fTof
Unpacked TOF digis.
Definition DigiData.h:34
PODVector< CbmPsdDigi > fPsd
Unpacked PSD digis.
Definition DigiData.h:39
PODVector< CbmMuchDigi > fMuch
Unpacked MUCH digis.
Definition DigiData.h:33
PODVector< CbmBmonDigi > fBmon
Unpacked Bmon digis.
Definition DigiData.h:35
Indicates an unrecoverable error. Should tear down the process.
Definition Exceptions.h:34
Class to hold the paths to the parameter files for the different detectors.
Definition ParFiles.h:21
fs::path hitfinder
Definition ParFiles.h:35
fs::path hitfinder2d
Definition ParFiles.h:48
struct cbm::algo::ParFiles::@2 tof
struct cbm::algo::ParFiles::@0 bmon
struct cbm::algo::ParFiles::@1 sts
struct cbm::algo::ParFiles::@3 trd
fs::path calibrate
Definition ParFiles.h:40
fs::path readout2d
Definition ParFiles.h:46
fs::path chanMask
Definition ParFiles.h:33
Monitor for additional processing steps.
Definition Reco.h:111
xpu::timings timeUnpack
Definition Reco.h:99
std::optional< i64 > tsDelta
Definition Reco.h:104
struct cbm::algo::RecoParams::STS::Memory memory
PartitionedVector< trd::Hit > trdHits
Definition RecoResults.h:43
PODVector< CbmMuchDigi > muchDigis
Definition RecoResults.h:31
PartitionedVector< sts::Cluster > stsClusters
Definition RecoResults.h:39
ca::Vector< ca::Track > tracks
Definition RecoResults.h:45
PartitionedVector< tof::Hit > tofHits
Definition RecoResults.h:42
ca::Vector< std::vector< std::pair< uint32_t, uint32_t > > > trackStsHitIndices
Definition RecoResults.h:46
std::vector< DigiEvent > events
Definition RecoResults.h:37
PODVector< CbmTrdDigi > trd2dDigis
Definition RecoResults.h:32
ca::Vector< std::vector< std::pair< uint32_t, uint32_t > > > trackTofHitIndices
Definition RecoResults.h:47
PartitionedSpan< sts::Hit > stsHits
Definition RecoResults.h:41
PODVector< CbmTofDigi > tofDigis
Definition RecoResults.h:34
PODVector< CbmRichDigi > richDigis
Definition RecoResults.h:35
PODVector< CbmStsDigi > stsDigis
Definition RecoResults.h:30
PODVector< CbmTrdDigi > trdDigis
Definition RecoResults.h:33
PODVector< CbmBmonDigi > bmonDigis
Definition RecoResults.h:29
Input to the TrackingChain.
Output from the TrackingChain.
Readout setup / Hardware cabling for BMon Used to create the hardware mapping for the BMon unpacker.
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
TimeClusterTriggerMonitorData digiMultTrigger
xpu::timings time
Time for trigger building.
xpu::timings time
Time for trigger building.
Definition V0Trigger.h:29
RecoParams::STS::Memory memory
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.
Definition Calibrate.h:28
Monitoring data for hitfinding.
Definition tof/Hitfind.h:30
Readout setup / Hardware cabling for TOF Used to create the hardware mapping for the TOF unpacker.
Monitoring data for hitfinding.
Definition trd/Hitfind.h:36