CbmRoot
Loading...
Searching...
No Matches
EventBuilder.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
5#include "EventBuilder.h"
6
7#include <cassert>
8#include <iomanip>
9
10#include <xpu/host.h>
11
12using std::is_sorted;
13using std::vector;
14
15namespace cbm::algo::evbuild
16{
17
18 // ----- Algorithm execution --------------------------------------------
19 EventBuilder::resultType EventBuilder::operator()(const DigiData& ts, const vector<double> triggers,
20 std::optional<DigiEventSelector> selector) const
21 {
22 xpu::push_timer("EventBuilder");
23 xpu::t_add_bytes(ts.TotalSizeBytes());
24
25 // --- Output data
26 resultType result = {};
27 auto& events = result.first;
28 events.resize(triggers.size());
29
30 std::transform(triggers.begin(), triggers.end(), events.begin(),
31 [&ts, &result, this](const double& trigger) { return BuildEvent(ts, result.second, trigger); });
32
33 // --- Apply event selector
34 if (selector.has_value()) {
35 auto notSelected = [&](DigiEvent& ev) { return !((*selector)(ev)); };
36 auto removeIt = std::remove_if(events.begin(), events.end(), notSelected);
37 events.erase(removeIt, events.end());
38 }
39
40 EventBuilderMonitorData& monitor = result.second;
41
42 monitor.sts.nDigis += ts.fSts.size();
43 monitor.rich.nDigis += ts.fRich.size();
44 monitor.much.nDigis += ts.fMuch.size();
45 monitor.trd.nDigis += ts.fTrd.size();
46 monitor.trd2d.nDigis += ts.fTrd2d.size();
47 monitor.tof.nDigis += ts.fTof.size();
48 monitor.psd.nDigis += ts.fPsd.size();
49 monitor.fsd.nDigis += ts.fFsd.size();
50 monitor.bmon.nDigis += ts.fBmon.size();
51 monitor.numTriggers += triggers.size();
52 monitor.numEvents += result.first.size();
53
54 monitor.time = xpu::pop_timer();
55 return result;
56 }
57
58 // --- Build a single event
59 DigiEvent EventBuilder::BuildEvent(const DigiData& ts, EventBuilderMonitorData& monitor, double trigger) const
60 {
61 DigiEvent event;
62 event.fTime = trigger;
63
64 // --- Loop over systems
65 for (auto entry : fConfig.fWindows) {
66
67 auto system = entry.first;
68 const double tMin = trigger + entry.second.first;
69 const double tMax = trigger + entry.second.second;
70
71 // --- Build the event using trigger window
72 switch (system) {
73 case ECbmModuleId::kSts: {
74 event.fSts = CopyRange(ts.fSts, tMin, tMax);
75 break;
76 }
78 event.fRich = CopyRange(ts.fRich, tMin, tMax);
79 break;
80 }
82 event.fMuch = CopyRange(ts.fMuch, tMin, tMax);
83 break;
84 }
85 case ECbmModuleId::kTrd: {
86 event.fTrd = CopyRange(ts.fTrd, tMin, tMax);
87 break;
88 }
90 event.fTrd2d = CopyRange(ts.fTrd2d, tMin, tMax);
91 break;
92 }
93 case ECbmModuleId::kTof: {
94 event.fTof = CopyRange(ts.fTof, tMin, tMax);
95 break;
96 }
97 case ECbmModuleId::kPsd: {
98 event.fPsd = CopyRange(ts.fPsd, tMin, tMax);
99 break;
100 }
101 case ECbmModuleId::kFsd: {
102 event.fFsd = CopyRange(ts.fFsd, tMin, tMax);
103 break;
104 }
105 case ECbmModuleId::kBmon: {
106 event.fBmon = CopyRange(ts.fBmon, tMin, tMax);
107 break;
108 }
109 default: break;
110 }
111 }
112 monitor.sts.nDigisInEvents += event.fSts.size();
113 monitor.rich.nDigisInEvents += event.fRich.size();
114 monitor.much.nDigisInEvents += event.fMuch.size();
115 monitor.trd.nDigisInEvents += event.fTrd.size();
116 monitor.trd2d.nDigisInEvents += event.fTrd2d.size();
117 monitor.tof.nDigisInEvents += event.fTof.size();
118 monitor.psd.nDigisInEvents += event.fPsd.size();
119 monitor.fsd.nDigisInEvents += event.fFsd.size();
120 monitor.bmon.nDigisInEvents += event.fBmon.size();
121 return event;
122 }
123 // --------------------------------------------------------------------------
124
125
126 // ----- Info to string -------------------------------------------------
127 std::string EventBuilder::ToString() const
128 {
129 std::stringstream out;
130 out << "--- Using EventBuilder with event windows:";
131 for (const auto& entry : fConfig.fWindows) {
132 out << "\n " << std::left << std::setw(5) << ::ToString(entry.first) << ": ";
133 out << " [" << std::right << std::setw(5) << entry.second.first;
134 out << ", " << std::right << std::setw(5) << entry.second.second << "] ns";
135 }
136 return out.str();
137 }
138 // --------------------------------------------------------------------------
139
140} // namespace cbm::algo::evbuild
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kTrd2d
TRD-FASP Detector (FIXME)
@ kMuch
Muon detection system.
@ kFsd
Forward spectator detector.
@ kRich
Ring-Imaging Cherenkov Detector.
std::map< ECbmModuleId, std::pair< double, double > > fWindows
Key: detector; value: [tmin, tmax].
DigiEvent BuildEvent(const DigiData &ts, EventBuilderMonitorData &monitor, double trigger) const
Build a single event from a trigger time.
std::pair< std::vector< DigiEvent >, EventBuilderMonitorData > resultType
EventBuilderConfig fConfig
Configuration / parameters.
resultType operator()(const DigiData &ts, const std::vector< double > triggers, std::optional< DigiEventSelector > selector) const
Execution.
static Vector CopyRange(const Vector &source, double tMin, double tMax)
Copy data objects in a given time interval from the source to the target vector.
std::string ToString() const
Info to string.
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
size_t TotalSizeBytes() const
Get the total number of bytes used by all digis.
Definition DigiData.cxx:49
Event data with event number and trigger time.
Definition DigiData.h:79
double fTime
Event trigger time [ns].
Definition DigiData.h:82
size_t nDigisInEvents
Number of digis collected into events.
size_t nDigis
Full number of digis in input source.
Monitoring data for event building.
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 fsd
Monitoring data for FSD.
EventBuilderDetectorMonitorData trd
Monitoring data for TRD.
EventBuilderDetectorMonitorData psd
Monitoring data for PSD.