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
9#include <FairRunOnline.h>
10#include <Logger.h>
11
12#include <TH1D.h>
13#include <THttpServer.h>
14#include <TStopwatch.h>
15
16#include <cassert>
17#include <iomanip>
18
19using namespace std;
23
24#define NUM_BINS 100
25#define BORDER 10.
26
27
28// ----- Constructor -----------------------------------------------------
29CbmTaskDigiEventQa::CbmTaskDigiEventQa() : FairTask("DigiEventQa") {}
30// ---------------------------------------------------------------------------
31
32
33// ----- Destructor ------------------------------------------------------
35// ---------------------------------------------------------------------------
36
37
38// ----- Configuration ---------------------------------------------------
40{
41
42 // The histogram ranges are defined by the event building windows. The number of bins
43 // is hard-coded. To be changed on request.
44
45 for (const auto& entry : config.fBuilder.fWindows) {
46 ECbmModuleId system = entry.first;
47
48 // --- Create histogram
49 string name = "hDigiTime" + std::string(cbm::util::ToString(entry.first));
50 string title = std::string(cbm::util::ToString(entry.first)) + " digi time in event";
51 double lower = entry.second.first - BORDER; // Lower edge of histogram
52 double upper = entry.second.second + BORDER; // Upper edge of histogram
53 assert(fDigiTimeHistos.count(system) == 0);
54 fDigiTimeHistos[system] = new TH1D(name.c_str(), title.c_str(), NUM_BINS, lower, upper);
55
56 // --- Set algo configuration
57 assert(fConfig.fData.count(system) == 0);
58 fConfig.fData[system] = {NUM_BINS, lower, upper};
59 }
60}
61// ---------------------------------------------------------------------------
62
63
64// ----- Execution -------------------------------------------------------
66{
67
68 // --- Timer and counters
69 TStopwatch timer;
70 timer.Start();
71
72 // --- Algo execution
73 DigiEventQaConfig config;
75
76 // --- Copy QA results (Histo1D) into ROOT output histograms
77 // TODO: Probably not the most efficient implementation. Creates first a ROOT histogram from a CBM one (data copy),
78 // which is then added to the member histogram (another data copy). Should implement a method for direct addition TH1D + Histo1D.
79 for (const auto& entry : result.fDigiTimeHistos) {
80 ECbmModuleId subsystem = entry.first;
81 fDigiTimeHistos[subsystem]->Add(ToTH1D(*entry.second));
82 }
83
84 // --- Timeslice log
85 timer.Stop();
86 fExecTime += timer.RealTime();
87 size_t numEvents = result.fNumEvents;
88 stringstream logOut;
89 logOut << setw(15) << left << GetName() << " [";
90 logOut << fixed << setw(8) << setprecision(1) << right << timer.RealTime() * 1000. << " ms] ";
91 logOut << "TS " << fNumTs << ", events " << numEvents;
92 LOG(info) << logOut.str();
93
94 // --- Run statistics
95 fNumTs++;
96 fNumEvents += numEvents;
97}
98// ----------------------------------------------------------------------------
99
100
101// ----- End-of-timeslice action ------------------------------------------
103{
104 LOG(info) << "=====================================";
105 LOG(info) << GetName() << ": Run summary";
106 LOG(info) << "Timeslices : " << fNumTs;
107 LOG(info) << "Events : " << fNumEvents;
108 LOG(info) << "Exec time : " << fixed << setprecision(2) << 1000. * fExecTime / double(fNumTs) << " ms / TS";
109 for (const auto& entry : fDigiTimeHistos) {
110 ECbmModuleId subsystem = entry.first;
111 TH1D* histo = entry.second;
112 LOG(info) << subsystem << " digi times: entries " << histo->GetEntries() << ", mean " << histo->GetMean()
113 << ", stddev " << histo->GetStdDev();
114 histo->Write();
115 }
116 LOG(info) << "=====================================";
117}
118// ----------------------------------------------------------------------------
119
120
121// ----- Initialisation ---------------------------------------------------
123{
124 // --- Get FairRootManager instance
125 FairRootManager* ioman = FairRootManager::Instance();
126 assert(ioman);
127
128 LOG(info) << "==================================================";
129 LOG(info) << GetName() << ": Initialising...";
130
131 // --- Input data
132 fEvents = ioman->InitObjectAs<const std::vector<CbmDigiEvent>*>("DigiEvent");
133 if (!fEvents) {
134 LOG(error) << GetName() << ": No input branch DigiEvent!";
135 return kFATAL;
136 }
137 LOG(info) << "--- Found branch DigiEvent";
138
139 // --- Register histograms
140 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
141 if (server) {
142 LOG(info) << "--- Http server present; registering histograms";
143 for (const auto& entry : fDigiTimeHistos)
144 server->Register("DigiEvent", entry.second);
145 }
146 else
147 LOG(info) << "--- No Http server present";
148
149 // --- Configure algorithm
150 fAlgo = std::make_unique<cbm::algo::evbuild::DigiEventQa>(fConfig);
151 LOG(info) << fAlgo->ToString();
152
153 LOG(info) << "==================================================";
154 return kSUCCESS;
155}
156// ----------------------------------------------------------------------------
157
158
159// ----- Convert CBM histogram to ROOT histogram --------------------------
161{
162 bool add = TH1::AddDirectoryStatus();
163 TH1::AddDirectory(false); // Needed to prevent ROOT from adding histogram to its internal registry
164 TH1D* result = new TH1D(source.GetName().c_str(), source.GetName().c_str(), source.GetNbinsX(), source.GetMinX(),
165 source.GetMaxX());
166 TH1::AddDirectory(add); // Needed to prevent ROOT from adding histogram to its internal registry
167 for (uint32_t bin = 0; bin <= source.GetNbinsX() + 1; bin++) {
168 result->SetBinContent(bin, source.GetBinContent(bin));
169 }
170 result->SetEntries(source.GetEntries());
171 return result;
172}
173// ----------------------------------------------------------------------------
174
ClassImp(CbmConverterManager)
ECbmModuleId
Enumerator for module Identifiers.
Definition CbmDefs.h:45
#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
Definition Histogram.h:442
double GetBinContent(uint32_t iBin) const
Gets bin content.
Definition Histogram.h:493
const std::string & GetName() const
Gets name.
Definition Histogram.h:298
double GetMaxX() const
Gets x-axis lower bound.
Definition Histogram.h:313
double GetEntries() const
Gets number of entries.
Definition Histogram.h:287
double GetMinX() const
Gets x-axis lower bound.
Definition Histogram.h:310
uint32_t GetNbinsX() const
Gets number of bins for x axis.
Definition Histogram.h:307
std::string_view ToString(T t)
Definition CbmEnumDict.h:64
Hash for CbmL1LinkKey.
static std::vector< DigiEvent > FromCbmDigiEvents(const std::vector< CbmDigiEvent > &events)
Definition DigiData.cxx:106
Configuration data for the QA of CbmDigiEvents.
Definition DigiEventQa.h:56
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