CbmRoot
Loading...
Searching...
No Matches
EventbuildChain.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
5#include "EventbuildChain.h"
6
7#include "CbmDigiTimeslice.h"
8#include "DigiData.h"
10#include "evbuild/Config.h"
11
12#include <sstream>
13#include <string>
14
15using namespace cbm::algo;
16using namespace cbm::algo::evbuild;
17
18
19// ----- Constructor ------------------------------------------------------
20EventbuildChain::EventbuildChain(const Config& config, std::shared_ptr<HistogramSender> sender)
21 : fConfig(config)
22 , fTriggerDet(config.fDigiTrigger.Detector())
23 , fDigiMultTrigger(config.fDigiTrigger.Window(), config.fDigiTrigger.Threshold(), config.fDigiTrigger.DeadTime())
24 , fHitMultTrigger(config.fHitMultTrigger)
25 , fV0Trigger()
26 , fBuilder(config.fBuilder)
27 , fSelector(config.fSelector)
28 , fQa(DigiEventQaConfig(config.fBuilder, 10., 100))
29 , fSender(sender)
30{
31 Status();
32
33 if (fSender) {
37 std::vector<std::pair<std::string, std::string>> histsCfg = fQa.GetConfig().GetHistosConfigs();
38 std::vector<std::pair<std::string, std::string>> canvsCfg = fQa.GetConfig().GetCanvasConfigs();
39 fSender->PrepareAndSendMsg(std::pair<uint32_t, uint32_t>(histsCfg.size(), canvsCfg.size()),
40 zmq::send_flags::sndmore);
41
45 for (const auto& cfg : histsCfg) {
46 fSender->PrepareAndSendMsg(cfg, zmq::send_flags::sndmore);
47 }
48
52 for (const auto& cfg : canvsCfg) {
53 fSender->PrepareAndSendMsg(cfg, zmq::send_flags::sndmore);
54 }
55
57 fSender->PrepareAndSendMsg(qa::HistogramContainer{}, zmq::send_flags::none);
58 }
59}
60// ----------------------------------------------------------------------------
61
62// ----- Destructor ------------------------------------------------------
64// ----------------------------------------------------------------------------
65
66// ----- Run event building on a timeslice --------------------------------
68
70{
71
72 // --- Local variables
73 std::vector<double> triggers;
74 ResultType result;
75
76 // --- If V0Trigger is configured, use it
77 if (fConfig.fV0Trigger.IsSet()) {
78 auto [v0Triggers, v0TriggerMon] = fV0Trigger(recoData.tracks, fConfig.fV0Trigger);
79 triggers = std::move(v0Triggers);
80 result.second.v0Trigger = std::move(v0TriggerMon);
81 }
82
83 // --- Else, check the hit multiplicity trigger
84 else if (fConfig.fHitMultTrigger.IsSet()) {
85 auto [hitTriggers, digiTriggerMon] = fHitMultTrigger(recoData);
86 triggers = std::move(hitTriggers);
87 result.second.hitMultTrigger = std::move(digiTriggerMon);
88 }
89
90 // --- Else, use the digi multiplicity trigger
91 else if (fConfig.fDigiTrigger.IsSet()) {
92 std::vector<double> digiTimes = GetDigiTimes(digiData, fTriggerDet);
93 auto [digiTriggers, digiTriggerMon] = fDigiMultTrigger(digiTimes);
94 triggers = std::move(digiTriggers);
95 result.second.digiMultTrigger = std::move(digiTriggerMon);
96 }
97
98 // --- Else, throw exception
99 else
100 throw std::runtime_error("no trigger is configured");
101
102 // --- Perform event building
103 auto [events, evbuildMon] = fBuilder(digiData, triggers, fSelector);
104 result.first = std::move(events);
105 result.second.evbuild = evbuildMon;
106
108 if (fSender) {
109 L_(info) << "Running DigiEventQa";
110 // --- Run event QA
111 DigiEventQaData qaData = fQa(result.first);
112 L_(info) << "Running DigiEventQa: done";
113
114 fSender->PrepareAndSendMsg(qaData.fHistContainer, zmq::send_flags::none);
115 int nHistograms = std::distance(qaData.fHistContainer.fvH1.begin(), qaData.fHistContainer.fvH1.end());
116 L_(info) << "Published histograms, nb: " << nHistograms;
117 }
118
119 // --- Some log
120 L_(info) << "Triggers: " << triggers.size() << ", events " << result.first.size();
121
122 return result;
123}
124// ----------------------------------------------------------------------------
125
126
127// ----- Status info ------------------------------------------------------
129{
130 L_(info) << "=== Eventbuilder configuration ===================";
132 L_(info) << fV0Trigger.ToString();
133 else if (fConfig.fHitMultTrigger.IsSet())
134 L_(info) << fHitMultTrigger.ToString();
135 else {
136 L_(info) << "--- Using digi multiplicity trigger with trigger detector " << ::ToString(fTriggerDet);
137 L_(info) << fDigiMultTrigger.ToString();
138 }
139 L_(info) << fBuilder.ToString();
140 L_(info) << fSelector.ToString();
141 L_(info) << fQa.ToString();
142 L_(info) << "======================================================";
143}
144// ----------------------------------------------------------------------------
145
146
147// ----- Get digi times from CbmDigiTimeslice -----------------------------
148std::vector<double> EventbuildChain::GetDigiTimes(const DigiData& timeslice, ECbmModuleId system)
149{
150 std::vector<double> result;
151 switch (system) {
152 case ECbmModuleId::kSts: {
153 result.resize(timeslice.fSts.size());
154 auto it1 = timeslice.fSts.begin();
155 auto it2 = timeslice.fSts.end();
156 std::transform(it1, it2, result.begin(), [](const CbmStsDigi& digi) { return digi.GetTime(); });
157 break;
158 }
159 case ECbmModuleId::kRich: {
160 result.resize(timeslice.fRich.size());
161 auto it1 = timeslice.fRich.begin();
162 auto it2 = timeslice.fRich.end();
163 std::transform(it1, it2, result.begin(), [](const CbmRichDigi& digi) { return digi.GetTime(); });
164 break;
165 }
166 case ECbmModuleId::kMuch: {
167 result.resize(timeslice.fMuch.size());
168 auto it1 = timeslice.fMuch.begin();
169 auto it2 = timeslice.fMuch.end();
170 std::transform(it1, it2, result.begin(), [](const CbmMuchDigi& digi) { return digi.GetTime(); });
171 break;
172 }
173 case ECbmModuleId::kTrd: {
174 result.resize(timeslice.fTrd.size());
175 auto it1 = timeslice.fTrd.begin();
176 auto it2 = timeslice.fTrd.end();
177 std::transform(it1, it2, result.begin(), [](const CbmTrdDigi& digi) { return digi.GetTime(); });
178 break;
179 }
180 case ECbmModuleId::kTof: {
181 result.resize(timeslice.fTof.size());
182 auto it1 = timeslice.fTof.begin();
183 auto it2 = timeslice.fTof.end();
184 std::transform(it1, it2, result.begin(), [](const CbmTofDigi& digi) { return digi.GetTime(); });
185 break;
186 }
187 case ECbmModuleId::kPsd: {
188 result.resize(timeslice.fPsd.size());
189 auto it1 = timeslice.fPsd.begin();
190 auto it2 = timeslice.fPsd.end();
191 std::transform(it1, it2, result.begin(), [](const CbmPsdDigi& digi) { return digi.GetTime(); });
192 break;
193 }
194 case ECbmModuleId::kFsd: {
195 result.resize(timeslice.fFsd.size());
196 auto it1 = timeslice.fFsd.begin();
197 auto it2 = timeslice.fFsd.end();
198 std::transform(it1, it2, result.begin(), [](const CbmFsdDigi& digi) { return digi.GetTime(); });
199 break;
200 }
201 case ECbmModuleId::kBmon: {
202 result.resize(timeslice.fBmon.size());
203 auto it1 = timeslice.fBmon.begin();
204 auto it2 = timeslice.fBmon.end();
205 std::transform(it1, it2, result.begin(), [](const CbmTofDigi& digi) { return digi.GetTime(); });
206 break;
207 }
208 default: {
209 L_(error) << "EventbuildChain::GetDigiTimes: Unknown system " << system;
210 break;
211 }
212 } //? system
213
214 return result;
215}
216// ----------------------------------------------------------------------------
#define L_(level)
ECbmModuleId
Definition CbmDefs.h:39
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kMuch
Muon detection system.
@ kFsd
Forward spectator detector.
@ kRich
Ring-Imaging Cherenkov Detector.
cbm::algo::ca::Vector< cbm::algo::ca::Track > TrackVector
A histogram container for the histogram server (header)
Data class for FSD digital information.
Definition CbmFsdDigi.h:36
Data class for PSD digital information.
Definition CbmPsdDigi.h:36
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
Configuration of digi event building.
V0TriggerConfig fV0Trigger
V0 trigger configuration.
DigiTriggerConfig fDigiTrigger
Digi trigger configuration.
DigiTriggerConfig fHitMultTrigger
Hit multiplicity trigger configuration.
std::string ToString() const
Info to string.
const DigiEventQaConfig & GetConfig() const
Const access to Qa config.
std::string ToString() const
Info to string.
bool IsSet() const
Check whether config was set.
std::string ToString() const
Info to string.
DigiEventSelector fSelector
Event selector algorithm.
ResultType Run(const DigiData &, const RecoResults &)
Execution.
ECbmModuleId fTriggerDet
Trigger detector.
std::pair< std::vector< DigiEvent >, EventbuildChainMonitorData > ResultType
void Status() const
Status info to logger.
DigiEventQa fQa
Event QA algorithm.
std::vector< double > GetDigiTimes(const DigiData &timeslice, ECbmModuleId system)
Extract digi times from CbmDigiTimeslice.
EventBuilder fBuilder
Event builder algorithm.
EventbuildChain(const Config &config, std::shared_ptr< HistogramSender > sender=nullptr)
Constructor.
std::shared_ptr< HistogramSender > fSender
Histogram sender.
Config fConfig
Global configuration.
TimeClusterTrigger fDigiMultTrigger
Digi multiplicity trigger algorithm.
V0Trigger fV0Trigger
V0 trigger algorithm.
HitMultTrigger fHitMultTrigger
Hit multiplicity trigger algorithm.
std::string ToString() const
Info to string.
std::string ToString() const
Info to string.
bool IsSet() const
Check whether config was set.
std::string ToString() const
Info to string.
std::string_view ToString(T t)
Definition EnumDict.h:64
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< 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
ca::Vector< ca::Track > tracks
Definition RecoResults.h:45
Configuration data for the QA of CbmDigiEvents.
Definition DigiEventQa.h:56
std::vector< std::pair< std::string, std::string > > GetHistosConfigs() const
Definition DigiEventQa.h:79
std::vector< std::pair< std::string, std::string > > GetCanvasConfigs() const
Definition DigiEventQa.h:87
QA results for CbmDigiEvent objects.
Definition DigiEventQa.h:26
qa::HistogramContainer fHistContainer
Definition DigiEventQa.h:27
Structure to keep the histograms for sending them on the histogram server.
std::forward_list< qa::H1D > fvH1
List of 1D-histograms.