CbmRoot
Loading...
Searching...
No Matches
CbmTaskTriggerDigi.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
6
7#include "CbmDefs.h"
8#include "CbmDigiManager.h"
9#include "CbmDigiTimeslice.h"
10#include "CbmModuleList.h"
11#include "CbmMuchDigi.h"
12#include "CbmPsdDigi.h"
13#include "CbmRichDigi.h"
14#include "CbmStsDigi.h"
15#include "CbmTofDigi.h"
16#include "CbmTrdDigi.h"
17#include "TimeClusterTrigger.h"
18
19#include <FairRootManager.h>
20#include <Logger.h>
21
22#include <algorithm>
23#include <cassert>
24#include <iomanip>
25#include <vector>
26
27// ----- Constructor -----------------------------------------------------
28CbmTaskTriggerDigi::CbmTaskTriggerDigi() : FairTask("TriggerDigi") {}
29// ---------------------------------------------------------------------------
30
31// ----- Destructor ------------------------------------------------------
36// ---------------------------------------------------------------------------
37
38// ----- Execution -------------------------------------------------------
40{
41
42 // --- Timer and counters
43 TStopwatch timerStep;
44 TStopwatch timerTot;
45 timerTot.Start();
46
47 // --- Get digi times
48 std::vector<double> digiTimes;
49
50 // --- Case: input CbmDigiTimeslice
51 if (fTimeslice) {
52 for (const auto& system : fSystems) {
53 std::vector<double> systemDigiTimes = GetDigiTimes(system);
54 digiTimes.insert(digiTimes.end(), systemDigiTimes.begin(), systemDigiTimes.end());
55 }
56 if (fSystems.size() > 1) {
57 std::sort(digiTimes.begin(), digiTimes.end());
58 }
59 }
60
61 // --- Case: input digi branches
62 else {
63 for (const auto& system : fSystems) {
64 CbmDigiBranchBase* digiBranch = fDigiMan->GetBranch(system);
65 std::vector<double> locDigiTimes;
66 switch (system) {
67 case ECbmModuleId::kMuch: { //we do not support the "MuchBeamTimeDigi"
68 locDigiTimes = GetDigiTimes<CbmMuchDigi>(digiBranch);
69 break;
70 }
71 case ECbmModuleId::kSts: {
72 locDigiTimes = GetDigiTimes<CbmStsDigi>(digiBranch);
73 break;
74 }
75 case ECbmModuleId::kTof: {
76 locDigiTimes = GetDigiTimes<CbmTofDigi>(digiBranch);
77 break;
78 }
79 case ECbmModuleId::kTrd: {
80 locDigiTimes = GetDigiTimes<CbmTrdDigi>(digiBranch);
81 break;
82 }
84 locDigiTimes = GetDigiTimes<CbmRichDigi>(digiBranch);
85 break;
86 }
87 case ECbmModuleId::kPsd: {
88 locDigiTimes = GetDigiTimes<CbmPsdDigi>(digiBranch);
89 break;
90 }
91 case ECbmModuleId::kBmon: { //Bmon has Tof digis
92 locDigiTimes = GetDigiTimes<CbmTofDigi>(digiBranch);
93 break;
94 }
95 default: {
96 LOG(error) << GetName() << ": Unknown detector type!";
97 break;
98 }
99 }
100 digiTimes.insert(digiTimes.end(), locDigiTimes.begin(), locDigiTimes.end());
101 }
102 if (fSystems.size() > 1) {
103 std::sort(digiTimes.begin(), digiTimes.end());
104 }
105 }
106
107 // --- Call the trigger algorithm
108 timerStep.Start();
109 *fTriggers = (*fAlgo)(digiTimes).first;
110 timerStep.Stop();
111 fTimeFind += timerStep.RealTime();
112
113 // --- Timeslice statistics
114 size_t numDigis = digiTimes.size();
115 size_t numTriggers = fTriggers->size();
116
117 // --- Timeslice log
118 timerTot.Stop();
119 fTimeTot += timerTot.RealTime();
120 stringstream logOut;
121 logOut << setw(15) << left << GetName() << " [";
122 logOut << fixed << setw(8) << setprecision(1) << right << timerTot.RealTime() * 1000. << " ms] ";
123 logOut << "TS " << fNumTs << ", digis " << numDigis << ", triggers " << numTriggers;
124 LOG(info) << logOut.str();
125
126 // --- Run statistics
127 fNumTs++;
128 fNumDigis += numDigis;
129 fNumTriggers += numTriggers;
130}
131// ----------------------------------------------------------------------------
132
133
134// ----- Get digi times from CbmDigiTimeslice -----------------------------
136{
137 assert(fTimeslice);
138 std::vector<double> result;
139 switch (system) {
140 case ECbmModuleId::kSts: {
141 result.resize(fTimeslice->fData.fSts.fDigis.size());
142 auto it1 = fTimeslice->fData.fSts.fDigis.begin();
143 auto it2 = fTimeslice->fData.fSts.fDigis.end();
144 std::transform(it1, it2, result.begin(), [](const CbmStsDigi& digi) { return digi.GetTime(); });
145 break;
146 }
147 case ECbmModuleId::kRich: {
148 result.resize(fTimeslice->fData.fRich.fDigis.size());
149 auto it1 = fTimeslice->fData.fRich.fDigis.begin();
150 auto it2 = fTimeslice->fData.fRich.fDigis.end();
151 std::transform(it1, it2, result.begin(), [](const CbmRichDigi& digi) { return digi.GetTime(); });
152 break;
153 }
154 case ECbmModuleId::kMuch: {
155 result.resize(fTimeslice->fData.fMuch.fDigis.size());
156 auto it1 = fTimeslice->fData.fMuch.fDigis.begin();
157 auto it2 = fTimeslice->fData.fMuch.fDigis.end();
158 std::transform(it1, it2, result.begin(), [](const CbmMuchDigi& digi) { return digi.GetTime(); });
159 break;
160 }
161 case ECbmModuleId::kTrd: {
162 result.resize(fTimeslice->fData.fTrd.fDigis.size());
163 auto it1 = fTimeslice->fData.fTrd.fDigis.begin();
164 auto it2 = fTimeslice->fData.fTrd.fDigis.end();
165 std::transform(it1, it2, result.begin(), [](const CbmTrdDigi& digi) { return digi.GetTime(); });
166 break;
167 }
168 case ECbmModuleId::kTof: {
169 result.resize(fTimeslice->fData.fTof.fDigis.size());
170 auto it1 = fTimeslice->fData.fTof.fDigis.begin();
171 auto it2 = fTimeslice->fData.fTof.fDigis.end();
172 std::transform(it1, it2, result.begin(), [](const CbmTofDigi& digi) { return digi.GetTime(); });
173 break;
174 }
175 case ECbmModuleId::kPsd: {
176 result.resize(fTimeslice->fData.fPsd.fDigis.size());
177 auto it1 = fTimeslice->fData.fPsd.fDigis.begin();
178 auto it2 = fTimeslice->fData.fPsd.fDigis.end();
179 std::transform(it1, it2, result.begin(), [](const CbmPsdDigi& digi) { return digi.GetTime(); });
180 break;
181 }
182 case ECbmModuleId::kBmon: {
183 result.resize(fTimeslice->fData.fBmon.fDigis.size());
184 auto it1 = fTimeslice->fData.fBmon.fDigis.begin();
185 auto it2 = fTimeslice->fData.fBmon.fDigis.end();
186 std::transform(it1, it2, result.begin(), [](const CbmTofDigi& digi) { return digi.GetTime(); });
187 break;
188 }
189 default: {
190 LOG(error) << GetName() << ": Unknown system " << system;
191 break;
192 }
193 } //? system
194
195 return result;
196}
197// ----------------------------------------------------------------------------
198
199
200// ----- End-of-timeslice action ------------------------------------------
202{
203 LOG(info) << "=====================================";
204 LOG(info) << GetName() << ": Run summary";
205 LOG(info) << "Timeslices : " << fNumTs;
206 LOG(info) << "Digis : " << fNumDigis;
207 LOG(info) << "Triggers : " << fNumTriggers;
208 LOG(info) << "Time / TS : " << fixed << setprecision(2) << 1000. * fTimeTot / double(fNumTs) << " ms";
209 LOG(info) << "Time extract : " << fixed << setprecision(2) << 1000. * fTimeExtract / double(fNumTs)
210 << " ms = " << 100. * fTimeExtract / fTimeTot << " %";
211 LOG(info) << "Time find trigger : " << fixed << setprecision(2) << 1000. * fTimeFind / double(fNumTs)
212 << " ms = " << 100. * fTimeFind / fTimeTot << " %";
213 LOG(info) << "=====================================";
214}
215// ----------------------------------------------------------------------------
216
217
218// ----- Initialisation ---------------------------------------------------
220{
221
222 // --- Get FairRootManager instance
223 FairRootManager* ioman = FairRootManager::Instance();
224 assert(ioman);
225
226 LOG(info) << "==================================================";
227 LOG(info) << GetName() << ": Initialising...";
228
229 // --- Check input data
230 // --- DigiTimeslice: Unpacked data from FLES
231 fTimeslice = ioman->InitObjectAs<const CbmDigiTimeslice*>("DigiTimeslice.");
232 if (fTimeslice) {
233 LOG(info) << "--- Found branch DigiTimeslice.";
234 }
235 // --- DigiManager: Simulated digi data
236 else {
238 fDigiMan->Init();
239 for (const auto& system : fSystems) {
240 if (!fDigiMan->IsPresent(system)) {
241 LOG(fatal) << GetName() << ": No digi branch for " << CbmModuleList::GetModuleNameCaps(system);
242 return kFATAL;
243 }
244 LOG(info) << "--- Found digi branch for " << CbmModuleList::GetModuleNameCaps(system);
245 }
246 }
247
248 // --- Register output array (Triggers)
249 if (ioman->GetObject("Trigger")) {
250 LOG(fatal) << GetName() << ": Branch Trigger already exists!";
251 return kFATAL;
252 }
253 fTriggers = new vector<double>;
254 ioman->RegisterAny("Trigger", fTriggers, IsOutputBranchPersistent("Trigger"));
255 if (!fTriggers) {
256 LOG(fatal) << GetName() << ": Output branch could not be created!";
257 return kFATAL;
258 }
259 LOG(info) << "--- Registered branch Trigger";
260
261 // --- Configure algorithm
262 fAlgo.reset(new cbm::algo::evbuild::TimeClusterTrigger(fConfig->Window(), fConfig->Threshold(), fConfig->DeadTime()));
263 LOG(info) << "--- Using trigger detector " << ::ToString(fConfig->Detector());
264 LOG(info) << fAlgo->ToString();
265
266 LOG(info) << "==================================================";
267 return kSUCCESS;
268}
269// ----------------------------------------------------------------------------
270
ClassImp(CbmConverterManager)
std::string ToString(ECbmModuleId modId)
Definition CbmDefs.cxx:70
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.
@ kRich
Ring-Imaging Cherenkov Detector.
bool first
std::vector< CbmBmonDigi > fDigis
Data vector.
Abstract base class for CBM digi branches.
CbmPsdDigiData fPsd
PSD data.
Definition CbmDigiData.h:42
CbmTrdDigiData fTrd
TRD data.
Definition CbmDigiData.h:39
CbmTofDigiData fTof
TOF data.
Definition CbmDigiData.h:41
CbmStsDigiData fSts
STS data.
Definition CbmDigiData.h:36
CbmRichDigiData fRich
RICH data.
Definition CbmDigiData.h:38
CbmMuchDigiData fMuch
MUCH data.
Definition CbmDigiData.h:37
CbmBmonDigiData fBmon
Beam monitor data.
Definition CbmDigiData.h:35
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
CbmDigiBranchBase * GetBranch(ECbmModuleId system)
Access to a digi branch.
InitStatus Init()
Initialisation.
static CbmDigiManager * Instance()
Static instance.
Collection of digis from all detector systems within one timeslice.
CbmDigiData fData
Timeslice data.
static TString GetModuleNameCaps(ECbmModuleId moduleId)
std::vector< CbmMuchDigi > fDigis
Data vector.
std::vector< CbmPsdDigi > fDigis
Data vector.
Data class for PSD digital information.
Definition CbmPsdDigi.h:36
std::vector< CbmRichDigi > fDigis
Data vector.
std::vector< CbmStsDigi > fDigis
Data vector.
Data class for a single-channel message in the STS.
Definition CbmStsDigi.h:40
Task class for minimum-bias event trigger from time-distribution of digi data.
CbmDigiManager * fDigiMan
Input data (from unpacking)
std::vector< ECbmModuleId > fSystems
Input data (from simulation)
std::vector< double > * fTriggers
std::unique_ptr< cbm::algo::evbuild::TimeClusterTrigger > fAlgo
Output data.
virtual void Exec(Option_t *opt)
Task execution.
virtual void Finish()
Finish timeslice.
virtual ~CbmTaskTriggerDigi()
Destructor.
const CbmDigiTimeslice * fTimeslice
std::unique_ptr< cbm::algo::evbuild::DigiTriggerConfig > fConfig
Algorithm.
CbmTaskTriggerDigi()
Constructor.
std::vector< double > GetDigiTimes(const CbmDigiBranchBase *digiBranch)
Extract digi times from digi branch.
virtual InitStatus Init()
Task initialisation.
std::vector< CbmTofDigi > fDigis
Data vector.
Data class for expanded digital TOF information.
Definition CbmTofDigi.h:47
std::vector< CbmTrdDigi > fDigis
Data vector.
Finds clusters in time-series data.