CbmRoot
Loading...
Searching...
No Matches
CbmTaskDigiEventQa.cxx
Go to the documentation of this file.
1/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
6
7#include "CbmReco.h" // for CbmRecoConfig
8#include "algo/qa/Histo1D.h"
9
10#include <FairRunOnline.h>
11#include <Logger.h>
12
13#include <TH1D.h>
14#include <THttpServer.h>
15#include <TStopwatch.h>
16
17#include <cassert>
18#include <iomanip>
19
20using namespace std;
24
25#define NUM_BINS 100
26#define BORDER 10.
27
28
29// ----- Constructor -----------------------------------------------------
30CbmTaskDigiEventQa::CbmTaskDigiEventQa() : FairTask("DigiEventQa") {}
31// ---------------------------------------------------------------------------
32
33
34// ----- Destructor ------------------------------------------------------
36// ---------------------------------------------------------------------------
37
38
39// ----- Configuration ---------------------------------------------------
41{
42
43 // The histogram ranges are defined by the event building windows. The number of bins
44 // is hard-coded. To be changed on request.
45
46 for (const auto& entry : config.fBuilder.fWindows) {
47 ECbmModuleId system = entry.first;
48
49 // --- Create histogram
50 string name = "hDigiTime" + ToString(entry.first);
51 string title = ToString(entry.first) + " digi time in event";
52 double lower = entry.second.first - BORDER; // Lower edge of histogram
53 double upper = entry.second.second + BORDER; // Upper edge of histogram
54 assert(fDigiTimeHistos.count(system) == 0);
55 fDigiTimeHistos[system] = new TH1D(name.c_str(), title.c_str(), NUM_BINS, lower, upper);
56
57 // --- Set algo configuration
58 assert(fConfig.fData.count(system) == 0);
59 fConfig.fData[system] = {NUM_BINS, lower, upper};
60 }
61}
62// ---------------------------------------------------------------------------
63
64
65// ----- Execution -------------------------------------------------------
67{
68
69 // --- Timer and counters
70 TStopwatch timer;
71 timer.Start();
72
73 // --- Algo execution
74 DigiEventQaConfig config;
76
77 // --- Copy QA results (Histo1D) into ROOT output histograms
78 // TODO: Probably not the most efficient implementation. Creates first a ROOT histogram from a CBM one (data copy),
79 // which is then added to the member histogram (another data copy). Should implement a method for direct addition TH1D + Histo1D.
80 for (const auto& entry : result.fDigiTimeHistos) {
81 ECbmModuleId subsystem = entry.first;
82 fDigiTimeHistos[subsystem]->Add(ToTH1D(*entry.second));
83 }
84
85 // --- Timeslice log
86 timer.Stop();
87 fExecTime += timer.RealTime();
88 size_t numEvents = result.fNumEvents;
89 stringstream logOut;
90 logOut << setw(15) << left << GetName() << " [";
91 logOut << fixed << setw(8) << setprecision(1) << right << timer.RealTime() * 1000. << " ms] ";
92 logOut << "TS " << fNumTs << ", events " << numEvents;
93 LOG(info) << logOut.str();
94
95 // --- Run statistics
96 fNumTs++;
97 fNumEvents += numEvents;
98}
99// ----------------------------------------------------------------------------
100
101
102// ----- End-of-timeslice action ------------------------------------------
104{
105 LOG(info) << "=====================================";
106 LOG(info) << GetName() << ": Run summary";
107 LOG(info) << "Timeslices : " << fNumTs;
108 LOG(info) << "Events : " << fNumEvents;
109 LOG(info) << "Exec time : " << fixed << setprecision(2) << 1000. * fExecTime / double(fNumTs) << " ms / TS";
110 for (const auto& entry : fDigiTimeHistos) {
111 ECbmModuleId subsystem = entry.first;
112 TH1D* histo = entry.second;
113 LOG(info) << ToString(subsystem) << " digi times: entries " << histo->GetEntries() << ", mean " << histo->GetMean()
114 << ", stddev " << histo->GetStdDev();
115 histo->Write();
116 }
117 LOG(info) << "=====================================";
118}
119// ----------------------------------------------------------------------------
120
121
122// ----- Initialisation ---------------------------------------------------
124{
125 // --- Get FairRootManager instance
126 FairRootManager* ioman = FairRootManager::Instance();
127 assert(ioman);
128
129 LOG(info) << "==================================================";
130 LOG(info) << GetName() << ": Initialising...";
131
132 // --- Input data
133 fEvents = ioman->InitObjectAs<const std::vector<CbmDigiEvent>*>("DigiEvent");
134 if (!fEvents) {
135 LOG(error) << GetName() << ": No input branch DigiEvent!";
136 return kFATAL;
137 }
138 LOG(info) << "--- Found branch DigiEvent";
139
140 // --- Register histograms
141 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
142 if (server) {
143 LOG(info) << "--- Http server present; registering histograms";
144 for (const auto& entry : fDigiTimeHistos)
145 server->Register("DigiEvent", entry.second);
146 }
147 else
148 LOG(info) << "--- No Http server present";
149
150 // --- Configure algorithm
151 fAlgo = std::make_unique<cbm::algo::evbuild::DigiEventQa>(fConfig);
152 LOG(info) << fAlgo->ToString();
153
154 LOG(info) << "==================================================";
155 return kSUCCESS;
156}
157// ----------------------------------------------------------------------------
158
159
160// ----- Convert CBM histogram to ROOT histogram --------------------------
162{
163 bool add = TH1::AddDirectoryStatus();
164 TH1::AddDirectory(false); // Needed to prevent ROOT from adding histogram to its internal registry
165 TH1D* result = new TH1D(source.GetName().c_str(), source.GetName().c_str(), source.GetNbinsX(), source.GetMinX(),
166 source.GetMaxX());
167 TH1::AddDirectory(add); // Needed to prevent ROOT from adding histogram to its internal registry
168 for (uint32_t bin = 0; bin <= source.GetNbinsX() + 1; bin++) {
169 result->SetBinContent(bin, source.GetBinContent(bin));
170 }
171 result->SetEntries(source.GetEntries());
172 return result;
173}
174// ----------------------------------------------------------------------------
175
ClassImp(CbmConverterManager)
std::string ToString(ECbmModuleId modId)
Definition CbmDefs.cxx:70
ECbmModuleId
Definition CbmDefs.h:39
#define NUM_BINS
#define BORDER
QA task class for digi events produced by the event builder.
size_t fNumTs
Input data (events)
CbmTaskDigiEventQa()
Constructor.
std::unique_ptr< cbm::algo::evbuild::DigiEventQa > fAlgo
double fExecTime
Execution time [s].
const std::vector< CbmDigiEvent > * fEvents
std::map< ECbmModuleId, TH1D * > fDigiTimeHistos
cbm::algo::evbuild::DigiEventQaConfig fConfig
TH1D * ToTH1D(const cbm::algo::qa::H1D &source)
Create a ROOT TH1D from a H1D object.
virtual void Exec(Option_t *opt)
Task execution.
virtual ~CbmTaskDigiEventQa()
Destructor.
size_t fNumEvents
Number of analysed events.
virtual InitStatus Init()
Task initialisation.
void Config(const cbm::algo::evbuild::Config &config)
Configuration.
virtual void Finish()
Finish timeslice.
Configuration of digi event building.
EventBuilderConfig fBuilder
Event builder configuration.
std::map< ECbmModuleId, std::pair< double, double > > fWindows
Key: detector; value: [tmin, tmax].
1D-histogram
double GetBinContent(uint32_t iBin) const
Gets bin content.
Definition Histogram.h:492
const std::string & GetName() const
Gets name.
Definition Histogram.h:297
double GetMaxX() const
Gets x-axis lower bound.
Definition Histogram.h:312
double GetEntries() const
Gets number of entries.
Definition Histogram.h:286
double GetMinX() const
Gets x-axis lower bound.
Definition Histogram.h:309
uint32_t GetNbinsX() const
Gets number of bins for x axis.
Definition Histogram.h:306
Hash for CbmL1LinkKey.
static std::vector< DigiEvent > FromCbmDigiEvents(const std::vector< CbmDigiEvent > &events)
Definition DigiData.cxx:98
Configuration data for the QA of CbmDigiEvents.
Definition DigiEventQa.h:56
std::map< ECbmModuleId, DigiEventQaDetConfig > fData
Definition DigiEventQa.h:57
QA results for CbmDigiEvent objects.
Definition DigiEventQa.h:26
std::unordered_map< ECbmModuleId, qa::H1D * > fDigiTimeHistos
Definition DigiEventQa.h:28
Configuration data for the QA of CbmDigiEvents for a given detector.
Definition DigiEventQa.h:38