CbmRoot
Loading...
Searching...
No Matches
CbmTrdUnpackMonitor.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Goethe-University Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pascal Raisig [committer] */
4
21#ifndef CbmTrdUnpackMonitor_H
22#define CbmTrdUnpackMonitor_H
23
24#include "CbmTrdDigi.h"
25#include "CbmTrdParSetAsic.h"
26#include "CbmTrdParSetDigi.h"
28#include "CbmTrdSpadic.h"
29
30#include <MicrosliceDescriptor.hpp>
31#include <Timeslice.hpp>
32
33#include <FairRunOnline.h>
34#include <FairTask.h>
35#include <Logger.h>
36
37#include <Rtypes.h> // for types
38#include <RtypesCore.h>
39#include <TFile.h>
40#include <TH1.h>
41#include <THttpServer.h> // for histogram server
42
43#include <cmath>
44#include <cstdint>
45#include <map>
46#include <memory>
47#include <string>
48#include <vector>
49
51 public:
53 enum class eDigiHistos : size_t
54 {
55 kMap = 0,
56 kMap_St,
57 kMap_Nt,
61 kCharge,
67 };
68
70 enum class eRawHistos : size_t
71 {
72 kSignalshape = 0,
75 kMap,
76 kMap_St,
77 kMap_Nt,
83 };
84
86 enum class eOtherHistos : size_t
87 {
93 };
94
96 static const std::uint32_t kTimeplotLenghtSeconds = 600; // 10 minuntes
97
99 CbmTrdUnpackMonitor(/* args */);
100
102 virtual ~CbmTrdUnpackMonitor();
103
106
109
111 void FillHistos(CbmTrdDigi* digi, CbmTrdRawMessageSpadic* raw = nullptr);
112
118 void FillHisto(Spadic::MsInfoType type, std::uint32_t moduleid);
119
125 void FillHisto(fles::MicrosliceFlags flag, std::uint32_t moduleid);
126
128 void Finish();
129
130 // Runtime functions
132 Bool_t Init(CbmTrdParSetDigi* digiParSet, CbmTrdParSetAsic* asicParSet = nullptr);
133
135 void SetActiveHistos(std::vector<eDigiHistos> vec) { fActiveDigiHistos.swap(vec); }
136
138 void SetActiveHistos(std::vector<eRawHistos> vec) { fActiveRawHistos.swap(vec); }
139
141 void SetActiveHistos(std::vector<eOtherHistos> vec) { fActiveOtherHistos.swap(vec); }
142
144 void SetSpadicObject(std::shared_ptr<CbmTrdSpadic> value) { fSpadic = value; }
145
147 void SetWriteToFile(std::string filename)
148 {
149 fOutfilename = filename;
150 fDoWriteToFile = true;
151 }
152
154 void SetDigiOutputVec(std::vector<CbmTrdDigi>* digiOutputVec) { fDigiOutputVec = digiOutputVec; }
155
157 void SetCurrentTimesliceStartTime(std::uint64_t time) { fCurrentTimesliceStartTimeNs = time; };
158
159
160 protected:
161 template<class histotype>
162 void addHistoToMap(std::shared_ptr<TH1> histo,
163 std::map<histotype, std::map<std::uint32_t, std::shared_ptr<TH1>>>* histomap,
164 std::uint32_t moduleid, histotype kHisto)
165 {
166 // If the histogram already exists we stop here
167 if (checkIfHistoExists(kHisto, histomap, moduleid)) return;
168
169 // Create a histo module pair
170 auto histopair = std::make_pair(moduleid, histo);
171
172 // Check if already have a histo map for the histo category
173 auto histomapIt = histomap->find(kHisto);
174 if (histomapIt == histomap->end()) {
175 // There is no map yet for the given histogram category
176 std::map<std::uint32_t, std::shared_ptr<TH1>> newmap = {};
177 newmap.emplace(histopair);
178 // Create a pair with the map and the histogram category
179 auto pair = std::make_pair(kHisto, newmap);
180 // And put it to the digi histo map
181 histomap->emplace(pair);
182 }
183 else {
184 // We found a map where we can put the histopair into
185 histomapIt->second.emplace(histopair);
186 }
187 // And finally if we have HttpServer we pass the histogram pointer to it
188 if (fHistoServer) {
189
190 std::string directory = std::to_string(moduleid) + "/" + getHistoType(histo) + "/";
191 fHistoServer->Register(directory.data(), histo.get());
192 }
193 }
194
195 template<typename THistotype>
196 bool checkIfHistoExists(THistotype etype,
197 std::map<THistotype, std::map<std::uint32_t, std::shared_ptr<TH1>>>* histomap,
198 std::uint32_t moduleid)
199 {
200 // First check if the map knows about the type, if not the histo does not exist yet.
201 auto histotypemapIt = histomap->find(etype);
202 if (histotypemapIt == histomap->end()) return false;
203
204 // Check if at the moduleId position we find something
205 auto histopair = histotypemapIt->second.find(moduleid);
206 if (histopair == histotypemapIt->second.end()) return false;
207
208 // Check if there is a pointer to the histo which not null
209 if (histopair->second != nullptr) return true;
210
211 return false;
212 }
213
215 virtual void createHistos();
216
218 virtual void createHisto(eDigiHistos kHisto);
219
221 virtual void createHisto(eRawHistos kHisto);
222
224 virtual void createHisto(eOtherHistos kHisto);
225
234 virtual void fillHisto(CbmTrdDigi* digi, eDigiHistos kHisto, std::uint32_t moduleid, std::shared_ptr<TH1> histo);
235
243 void fillHisto(CbmTrdRawMessageSpadic* raw, eRawHistos kHisto, std::shared_ptr<TH1> histo, CbmTrdDigi* digi);
244
251 void fillSamplesHisto(std::shared_ptr<TH1> histo, CbmTrdRawMessageSpadic* raw);
252
254 std::double_t getDeltaT(CbmTrdDigi* digi);
255
257 std::string getHistoName(eDigiHistos kHisto);
258
260 std::string getHistoName(eRawHistos kHisto);
261
263 std::string getHistoName(eOtherHistos kHisto);
264
266 static std::string getTypeName(eDigiHistos kHisto)
267 {
268 (void) kHisto;
269 return "Digi";
270 };
271
273 static std::string getTypeName(eRawHistos kHisto)
274 {
275 (void) kHisto;
276 return "Raw";
277 };
278
280 static std::string getTypeName(eOtherHistos kHisto)
281 {
282 (void) kHisto;
283 return "Other";
284 };
285
287 std::string getHistoType(std::shared_ptr<TH1> histo);
288
296 std::pair<std::uint32_t, std::uint32_t> getRowAndCol(std::uint32_t moduleid, std::uint32_t channelid);
297
299 std::float_t getSamplesStdDev(CbmTrdRawMessageSpadic* raw);
300
301 template<class histotype>
302 size_t writeHistosToFile(std::map<histotype, std::map<std::uint32_t, std::shared_ptr<TH1>>>* histomap, TFile* file)
303 {
304 // Counter of written histos
305 size_t nhistos = 0;
306
307 // Make sure we are in the file to which we want to write our histos
308 file->cd();
309 for (auto typemappair : *histomap) {
310 for (auto histopair : typemappair.second) {
311
312 // Make sure we end up in chosen folder
313 std::string moduleidname = std::to_string(histopair.first);
314 if (nullptr == gDirectory->Get(moduleidname.data())) gDirectory->mkdir(moduleidname.data());
315 gDirectory->cd(moduleidname.data());
316
317 // Now move(create) to the histotype folder (digi, raw or other histo)
318 std::string histotypename = getTypeName(typemappair.first);
319 // (Create and) Move to the directory of the type
320 if (nullptr == gDirectory->Get(histotypename.data())) gDirectory->mkdir(histotypename.data());
321 gDirectory->cd(histotypename.data());
322
323 // Write histogram
324 LOG(debug) << Class_Name() << "::Finish() Write histo " << histopair.second->GetName() << " to file "
325 << file->GetName() << " in folder " << moduleidname.data() << "/" << histotypename.data();
326 histopair.second->Write();
327 nhistos++;
328 // Move back to root directory of the output file
329 file->cd();
330 }
331 }
332 return nhistos;
333 }
334
336 void fillNtCorrHisto(std::shared_ptr<TH1> histo, CbmTrdDigi* digi);
337
339 void resetTimeplots();
340
342 void adjustTimeplots(std::uint64_t newtime);
343
344 // Member variables
346 std::map<eDigiHistos, std::map<std::uint32_t, std::shared_ptr<TH1>>> fDigiHistoMap = {};
347
349 std::map<eRawHistos, std::map<std::uint32_t, std::shared_ptr<TH1>>> fRawHistoMap = {};
350
352 std::map<eOtherHistos, std::map<std::uint32_t, std::shared_ptr<TH1>>> fOtherHistoMap = {};
353
355 std::vector<eDigiHistos> fActiveDigiHistos = {};
356
358 std::vector<eRawHistos> fActiveRawHistos = {};
359
361 std::vector<eOtherHistos> fActiveOtherHistos = {};
362
364 THttpServer* fHistoServer = nullptr;
365
367 bool fDoWriteToFile = false;
368
370 std::string fOutfilename = "";
371
372 // ---- TRD parameters ----
374 std::vector<std::uint32_t> fModuleIdsVec = {};
375
377 std::map<std::uint32_t, std::uint8_t> fModuleOrientation = {};
378
380 std::map<std::uint32_t, std::uint8_t> fModuleNrRows = {};
381
383 std::map<std::uint32_t, std::uint8_t> fModuleNrColumns = {};
384
386 std::map<std::uint32_t, std::vector<size_t>> fLastDigiTimeMap = {};
387
389 std::vector<CbmTrdDigi>* fDigiOutputVec = {};
390
391 // All other parameters and containers
392 std::shared_ptr<CbmTrdSpadic> fSpadic = nullptr;
393
395 std::uint64_t fCurrentTimeplotStartNs = 0;
396
399
401 std::uint64_t fLastRawTime = 0;
402
403 private:
404 ClassDef(CbmTrdUnpackMonitor, 2)
405};
406
407#endif // CbmTrdUnpackMonitor_H
Software representation of the SPADIC v2.2+.
Describe TRD module ASIC settings (electronic gain, delays, etc)
Base class for storing raw information which comes from the Spadic v2.2 trough flib or from a tsa fil...
void Finish()
Actions at the end of the run, e.g. write histos to file if flag is set.
void FillHisto(Spadic::MsInfoType type, std::uint32_t moduleid)
Fill the given histo with the information on the info type.
static std::string getTypeName(eDigiHistos kHisto)
Get the Type Name for the given histo.
virtual ~CbmTrdUnpackMonitor()
Destroy the Cbm Trd Unpack Task object.
std::map< std::uint32_t, std::uint8_t > fModuleNrColumns
Map with the number of columns of the modules. Performance helper to not go through the extraction fr...
CbmTrdUnpackMonitor()
Create the Cbm Trd Unpack AlgoBase object.
void fillSamplesHisto(std::shared_ptr< TH1 > histo, CbmTrdRawMessageSpadic *raw)
Fill the passed histo with the samples as function of time.
std::vector< eDigiHistos > fActiveDigiHistos
Enums of Digi histos to be activated.
std::string getHistoName(eDigiHistos kHisto)
Get the Histo Name for the given histo.
void fillNtCorrHisto(std::shared_ptr< TH1 > histo, CbmTrdDigi *digi)
Fill the NeighborTrigger Checking Histogram.
eDigiHistos
Enum for the predefined digi histograms.
std::uint64_t fCurrentTimeplotStartNs
Variable which holds the start time in ns of the current time axis of plots which display a quantity ...
CbmTrdUnpackMonitor(const CbmTrdUnpackMonitor &)=delete
Copy constructor - not implemented.
std::map< std::uint32_t, std::vector< size_t > > fLastDigiTimeMap
Map with the last digi time for each channel of a given module.
virtual void createHisto(eDigiHistos kHisto)
Create the actual TH1 shared_ptrs of the Digi histos.
std::vector< eRawHistos > fActiveRawHistos
Enums of Raw histos to be activated.
std::map< eDigiHistos, std::map< std::uint32_t, std::shared_ptr< TH1 > > > fDigiHistoMap
Digi histogram pointers stored in a map together with the module id.
std::pair< std::uint32_t, std::uint32_t > getRowAndCol(std::uint32_t moduleid, std::uint32_t channelid)
Get the row and column ids (potentially rotated chambers are adjusted to humand readable rotations)
void adjustTimeplots(std::uint64_t newtime)
Adjust the boundaries of all timeplots to contain newtime.
std::string getHistoType(std::shared_ptr< TH1 > histo)
Get the Histo Type, i.e. "Digi/Raw/Other", deduced from the histo name.
void SetDigiOutputVec(std::vector< CbmTrdDigi > *digiOutputVec)
Set digi outpout vector (to make it usable for correlations)
static std::string getTypeName(eOtherHistos kHisto)
Get the Type Name for the given histo.
void SetActiveHistos(std::vector< eOtherHistos > vec)
transfer the enums for the histos to be activated to the member vector
Bool_t Init(CbmTrdParSetDigi *digiParSet, CbmTrdParSetAsic *asicParSet=nullptr)
Init all required parameter informations.
std::map< std::uint32_t, std::uint8_t > fModuleOrientation
Map with the orientations of the modules. Performance helper to not go through the extraction from Pa...
std::map< eOtherHistos, std::map< std::uint32_t, std::shared_ptr< TH1 > > > fOtherHistoMap
Other histogram pointers stored in a map together with the module id.
static std::string getTypeName(eRawHistos kHisto)
Get the Type Name for the given histo.
std::map< eRawHistos, std::map< std::uint32_t, std::shared_ptr< TH1 > > > fRawHistoMap
Raw histogram pointers stored in a map together with the module id.
std::shared_ptr< CbmTrdSpadic > fSpadic
void SetActiveHistos(std::vector< eDigiHistos > vec)
transfer the enums for the histos to be activated to the member vector
static const std::uint32_t kTimeplotLenghtSeconds
Constant which defines the lenght of the time axis in seconds of plots which display a quantity over ...
std::vector< eOtherHistos > fActiveOtherHistos
Enums of Raw histos to be activated.
std::vector< CbmTrdDigi > * fDigiOutputVec
Variable which holds a reference to the TRD digi output vector (for correlations)
virtual void fillHisto(CbmTrdDigi *digi, eDigiHistos kHisto, std::uint32_t moduleid, std::shared_ptr< TH1 > histo)
Fill the given histo with the information from the digi.
void SetActiveHistos(std::vector< eRawHistos > vec)
transfer the enums for the histos to be activated to the member vector
std::vector< std::uint32_t > fModuleIdsVec
Vector with the unique module Ids.
bool fDoWriteToFile
Flag whether to write histos to file or not, gets activated if a output filename gets set.
std::double_t getDeltaT(CbmTrdDigi *digi)
Get the time difference between this digi and the previous one from the channel of this digi.
void FillHistos(CbmTrdDigi *digi, CbmTrdRawMessageSpadic *raw=nullptr)
fill the stored digi histograms
eOtherHistos
Enum for the predefined other histograms.
eRawHistos
Enum for the predefined raw histograms.
THttpServer * fHistoServer
Pointer to the histogram server, in case we run the online monitoring, the pointer is automatically d...
std::float_t getSamplesStdDev(CbmTrdRawMessageSpadic *raw)
Extract the std deviation of all samples in the message.
bool checkIfHistoExists(THistotype etype, std::map< THistotype, std::map< std::uint32_t, std::shared_ptr< TH1 > > > *histomap, std::uint32_t moduleid)
size_t writeHistosToFile(std::map< histotype, std::map< std::uint32_t, std::shared_ptr< TH1 > > > *histomap, TFile *file)
void SetWriteToFile(std::string filename)
Set the output filename, automatically also sets the flag to create an output file.
void addHistoToMap(std::shared_ptr< TH1 > histo, std::map< histotype, std::map< std::uint32_t, std::shared_ptr< TH1 > > > *histomap, std::uint32_t moduleid, histotype kHisto)
std::map< std::uint32_t, std::uint8_t > fModuleNrRows
Map with the number of rows of the modules. Performance helper to not go through the extraction from ...
void SetCurrentTimesliceStartTime(std::uint64_t time)
Set the start time of the current timeslice in ns.
std::uint64_t fLastRawTime
Variable which holds the time in ns of the last processed raw message.
void resetTimeplots()
Reset the contents of all timeplots.
std::string fOutfilename
File name for the output file.
CbmTrdUnpackMonitor & operator=(const CbmTrdUnpackMonitor &)=delete
Assignment operator - not implemented.
void SetSpadicObject(std::shared_ptr< CbmTrdSpadic > value)
Set the Spadic Object.
virtual void createHistos()
Create the actual TH1 shared_ptrs.
std::uint64_t fCurrentTimesliceStartTimeNs
Variable which holds the start time in ns of the current timeslice.