CbmRoot
Loading...
Searching...
No Matches
CbmTrdUnpackMonitor.cxx
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
6
7#include "CbmTrdDigi.h"
8#include "CbmTrdParModAsic.h"
9#include "CbmTrdParModDigi.h"
11
12#include <MicrosliceDescriptor.hpp>
13
14#include <FairRun.h>
15#include <FairRunOnline.h>
16#include <Logger.h>
17
18#include <RtypesCore.h>
19#include <TFile.h>
20#include <TH1.h>
21#include <TH2.h>
22#include <TProfile.h>
23#include <TROOT.h>
24
25#include <boost/math/special_functions/math_fwd.hpp>
26
27#include <cmath>
28#include <cstdint>
29#include <iostream>
30#include <memory>
31#include <numeric>
32#include <string>
33#include <utility>
34#include <vector>
35
37
39
40// ---- FillHistos ----
42{
43 auto moduleid = digi->GetAddressModule();
44 for (auto pair : fDigiHistoMap) {
45 auto modulepair = pair.second.find(moduleid);
46 auto histo = modulepair->second;
47 fillHisto(digi, pair.first, moduleid, histo);
48 }
49
50 if (raw) {
51 for (auto pair : fRawHistoMap) {
52 auto modulepair = pair.second.find(moduleid);
53 auto histo = modulepair->second;
54 fillHisto(raw, pair.first, histo, digi);
55 }
56
57 /* Always save the time of the last processed raw message to use it as time
58 for BUF/BOM messages which have no time information themselves.
59 raw->GetTime() is relative to TS start only, so one needs to add fCurrentTimesliceStartTimeNs to it.
60 */
62 }
63}
64
65// ---- FillHistos ----
66void CbmTrdUnpackMonitor::FillHisto(Spadic::MsInfoType type, std::uint32_t moduleid)
67{
68 //kSpadic_Info_Types
69 {
71 if (pair != fOtherHistoMap.end()) {
72 auto histo = pair->second.find(moduleid)->second;
73 histo->Fill(static_cast<std::uint32_t>(type));
74 }
75 }
76
77 //kBomRate
78 if (type == Spadic::MsInfoType::kBOM) {
79 auto pair = fOtherHistoMap.find(eOtherHistos::kBomRate);
80 if (pair != fOtherHistoMap.end()) {
81 auto histo = pair->second.find(moduleid)->second;
82 histo->Fill((fLastRawTime - fCurrentTimeplotStartNs) * 1.0 / 1E9, 10);
83 }
84 }
85
86 //kBufRate
87 if (type == Spadic::MsInfoType::kBUF) {
88 auto pair = fOtherHistoMap.find(eOtherHistos::kBufRate);
89 if (pair != fOtherHistoMap.end()) {
90 auto histo = pair->second.find(moduleid)->second;
91 histo->Fill((fLastRawTime - fCurrentTimeplotStartNs) * 1.0 / 1E9, 10);
92 }
93 }
94
95 //kBomPerRawRate
96 if (type == Spadic::MsInfoType::kBOM) {
97 auto pairBomPerRawRate = fOtherHistoMap.find(eOtherHistos::kBomPerRawRate);
98 auto pairBomRate = fOtherHistoMap.find(eOtherHistos::kBomRate);
99 auto pairRawRate = fRawHistoMap.find(eRawHistos::kRawRate);
100 if (pairBomPerRawRate != fOtherHistoMap.end() && pairBomRate != fOtherHistoMap.end()
101 && pairRawRate != fRawHistoMap.end()) {
102 auto histoBomPerRawRate = pairBomPerRawRate->second.find(moduleid)->second;
103 auto histoBomRate = pairBomRate->second.find(moduleid)->second;
104 auto histoRawRate = pairRawRate->second.find(moduleid)->second;
105
106 Int_t modifiedBin = histoBomRate->FindBin((fLastRawTime - fCurrentTimeplotStartNs) * 1.0 / 1E9);
107 if (histoRawRate->GetBinContent(modifiedBin) != 0)
108 histoBomPerRawRate->SetBinContent(modifiedBin, histoBomRate->GetBinContent(modifiedBin)
109 / histoRawRate->GetBinContent(modifiedBin));
110 }
111 }
112}
113
114// ---- FillHistos ----
115void CbmTrdUnpackMonitor::FillHisto(fles::MicrosliceFlags flag, std::uint32_t moduleid)
116{
117 auto pair = fOtherHistoMap.find(eOtherHistos::kMs_Flags);
118 if (pair == fOtherHistoMap.end()) return;
119
120 auto histo = pair->second.find(moduleid)->second;
121
122 histo->Fill(static_cast<std::uint32_t>(flag));
123}
124
126{
127 LOG(info) << Class_Name() << "::Finish() - ";
128
129 if (fDoWriteToFile) {
130 size_t nhistos = 0;
131
133 TFile* oldFile = gFile;
134 TDirectory* oldDir = gDirectory;
135
137 TFile histofile(fOutfilename.data(), "RECREATE");
138
139 nhistos += writeHistosToFile(&fDigiHistoMap, &histofile);
140 nhistos += writeHistosToFile(&fRawHistoMap, &histofile);
141 nhistos += writeHistosToFile(&fOtherHistoMap, &histofile);
142
144 gFile = oldFile;
145 gDirectory = oldDir;
146
147 // histofile->Close();
148 histofile.Close();
149
150 LOG(info) << Class_Name() << "::Finish() nHistos " << nhistos << " written to " << fOutfilename.data();
151 }
152}
153
154// ---- Init ----
156{
157 auto modulemap = digiParSet->GetModuleMap();
158 for (auto modulepair : modulemap) {
159 auto parmoddigi = static_cast<CbmTrdParModDigi*>(modulepair.second);
160 if (asicParSet) {
161 auto asicParMod = static_cast<const CbmTrdParModAsic*>(asicParSet->GetModulePar(modulepair.first));
162 if (asicParMod->GetAsicType() != CbmTrdDigi::eCbmTrdAsicType::kSPADIC) continue;
163 }
164 fModuleIdsVec.emplace_back(modulepair.first);
165
166 fModuleOrientation.emplace(std::pair<std::uint32_t, std::uint8_t>(modulepair.first, parmoddigi->GetOrientation()));
167 fModuleNrRows.emplace(std::pair<std::uint32_t, std::uint8_t>(modulepair.first, parmoddigi->GetNofRows()));
168 fModuleNrColumns.emplace(std::pair<std::uint32_t, std::uint8_t>(modulepair.first, parmoddigi->GetNofColumns()));
169 }
170
171 if (fModuleOrientation.empty() || fModuleNrRows.empty() || fModuleNrColumns.empty()) return kFALSE;
172
173 // Check if there is a HttpServer and if so we later on register the created histograms in it.
174 if (FairRun::Instance()->IsA() == FairRunOnline::Class()) {
175 auto run = static_cast<FairRunOnline*>(FairRun::Instance());
176
177 fHistoServer = run->GetHttpServer();
178 }
179
181 TFile* oldFile = gFile;
182 TDirectory* oldDir = gDirectory;
183 gROOT->cd();
184
185 createHistos();
186
188 gFile = oldFile;
189 gDirectory = oldDir;
190
191 return kTRUE;
192}
193
194// ---- createHisto ----
196{
197 std::string histoname = "";
198 std::shared_ptr<TH1> newhisto = nullptr;
199
200 for (auto moduleid : fModuleIdsVec) {
201 auto ncols = fModuleNrColumns.find(moduleid)->second;
202 auto nrows = fModuleNrRows.find(moduleid)->second;
203 auto nchannels = nrows * ncols;
204 auto rotation = fModuleOrientation.find(moduleid)->second;
205
206 histoname = "ModuleId_" + std::to_string(moduleid) + "-";
207 histoname += getTypeName(kHisto) + "_";
208 histoname += getHistoName(kHisto);
209
210 switch (kHisto) {
214 // Check if we have chamber sensitive along the x-axis
215 if (rotation % 2 == 0) {
216 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), ncols, -0.5, (ncols - 0.5), nrows, -0.5,
217 (nrows - 0.5));
218 newhisto->SetXTitle("Pad column");
219 newhisto->SetYTitle("Pad row");
220 }
221 // If not it is sensitive along the y-axis
222 else {
223 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nrows, -0.5, (nrows - 0.5), ncols, -0.5,
224 (ncols - 0.5));
225 newhisto->SetXTitle("Pad row");
226 newhisto->SetYTitle("Pad column");
227 }
228 break;
229
233 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), fSpadic->GetDynamicRange(), 0 - 0.5,
234 fSpadic->GetDynamicRange() - 0.5);
235 newhisto->SetXTitle("MaxAdc [ADC units]");
236 newhisto->SetYTitle("Counts");
237 break;
239 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(),
240 static_cast<Int_t>(CbmTrdDigi::eTriggerType::kNTrg), -0.5,
241 (static_cast<Int_t>(CbmTrdDigi::eTriggerType::kNTrg) - 0.5));
242 newhisto->SetXTitle("CbmTrdDigi eTriggerType");
243 newhisto->SetYTitle("Counts");
244 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(CbmTrdDigi::eTriggerType::kSelf) + 1), "St");
245 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(CbmTrdDigi::eTriggerType::kNeighbor) + 1), "Nt");
246 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(CbmTrdDigi::eTriggerType::kMulti) + 1), "Multihit");
247
248 break;
252 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5));
253 newhisto->SetXTitle("ChannelId");
254 newhisto->SetYTitle("Counts");
255 break;
257 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5), 3500,
258 -2e6, 5e6);
259 newhisto->SetXTitle("ChannelId");
260 newhisto->SetYTitle("#DeltaT(Digi(n)-Digi(n-1)) [ns]");
261 break;
263 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5),
264 nchannels, -0.5, (nchannels - 0.5));
265 newhisto->SetXTitle("NT AddressChannel");
266 newhisto->SetYTitle("ST AddressChannel");
267 break;
268 // default: return; break;
269 }
270 LOG(debug) << Class_Name() << "::CreateHisto() HistoDigi " << static_cast<size_t>(kHisto) << " Module " << moduleid
271 << " initialized as " << histoname.data();
272 if (newhisto) {
273 addHistoToMap<eDigiHistos>(newhisto, &fDigiHistoMap, moduleid, kHisto);
274 }
275 }
276}
277
278// ---- createHisto ----
280{
281 std::string histoname = "";
282 std::shared_ptr<TH1> newhisto = nullptr;
283
284 for (auto moduleid : fModuleIdsVec) {
285 auto ncols = fModuleNrColumns.find(moduleid)->second;
286 auto nrows = fModuleNrRows.find(moduleid)->second;
287 auto nchannels = nrows * ncols;
288
289 histoname = "ModuleId_" + std::to_string(moduleid) + "-";
290 histoname += getTypeName(kHisto) + "_";
291 histoname += getHistoName(kHisto);
292 switch (kHisto) {
296 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), 32, -0.5, 31.5, 520, -260, 260);
297 newhisto->SetXTitle("ADC Sample [CC]");
298 newhisto->SetYTitle("ADC Value [a.u.]");
299 break;
300 case eRawHistos::kMap:
303 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), 42, -0.5, 41.5, 16, -0.5, 15.5);
304 newhisto->SetXTitle("ElinkId");
305 newhisto->SetYTitle("eLink-ChannelId");
306 break;
308 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), 42, -0.5, 41.5);
309 newhisto->SetXTitle("ElinkId");
310 newhisto->SetYTitle("Counts");
311 break;
313 newhisto = std::make_shared<TH1F>(histoname.data(), histoname.data(), 200, 0.0, 100.0);
314 newhisto->SetXTitle("ADC signal std. deviation [#sigma]");
315 newhisto->SetYTitle("Counts");
316 break;
318 newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5), 601,
319 -300, 300);
320 newhisto->SetXTitle("ChannelId");
321 newhisto->SetYTitle("ADC Value(Sample-0) [a.u.]");
322 break;
324 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(),
325 static_cast<Int_t>(Spadic::eTriggerType::kGlobal) + 1, -0.5,
326 (static_cast<Int_t>(Spadic::eTriggerType::kSandN) + 0.5));
327 newhisto->SetXTitle("Spadic::eTriggerType");
328 newhisto->SetYTitle("Counts");
329 break;
331 newhisto = std::make_shared<TH1D>(histoname.data(), histoname.data(), kTimeplotLenghtSeconds * 10 + 1, -0.05,
333 newhisto->SetXTitle("Time t [s]");
334 newhisto->SetYTitle("Rate [Hz]");
335 break;
336 default: return; break;
337 }
338 LOG(debug) << Class_Name() << "::CreateHisto() HistoRaw " << static_cast<size_t>(kHisto) << " Module " << moduleid
339 << "initialized as " << histoname.data();
341 if (newhisto) {
342 addHistoToMap<eRawHistos>(newhisto, &fRawHistoMap, moduleid, kHisto);
343 }
344 }
345}
346
347// ---- createHisto ----
349{
350 std::string histoname = "";
351 std::shared_ptr<TH1> newhisto = nullptr;
352
353 for (auto moduleid : fModuleIdsVec) {
354 histoname = "ModuleId_" + std::to_string(moduleid) + "-";
355 histoname += getTypeName(kHisto) + "_";
356 histoname += getHistoName(kHisto);
357 switch (kHisto) {
359 auto nbins = static_cast<std::uint32_t>(Spadic::MsInfoType::kNInfMsgs);
360 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nbins, -0.5, nbins - 0.5);
361 newhisto->SetXTitle("Info message type");
362 newhisto->SetYTitle("Counts");
363 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kBOM) + 1), "BOM");
364 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kMSB) + 1), "MSB");
365 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kBUF) + 1), "BUF");
366 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kUNU) + 1), "UNU");
367 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kMIS) + 1), "MIS");
368 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kChannelBuf) + 1), "ChBuf");
369 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kOrdFifoBuf) + 1), "OrdFifoBuf");
370 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kChannelBufM) + 1), "ChBufMH");
371 ;
372 break;
373 }
375 auto nbins = static_cast<std::uint32_t>(fles::MicrosliceFlags::DataError) + 1;
376 newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nbins, -0.5, nbins - 0.5);
377 newhisto->SetXTitle("#muSlice info/error flags");
378 newhisto->SetYTitle("Counts");
379 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::CrcValid) + 1), "CrcValid");
380 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::OverflowFlim) + 1), "OverflowFlim");
381 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::OverflowUser) + 1), "OverflowUser");
382 newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::DataError) + 1), "DataError");
383 break;
384 }
388 newhisto = std::make_shared<TH1D>(histoname.data(), histoname.data(), kTimeplotLenghtSeconds * 10 + 1, -0.05,
390 newhisto->SetXTitle("Time t [s]");
391 newhisto->SetYTitle("Rate [Hz]");
392 break;
393 }
394 default: return; break;
395 }
396 LOG(debug) << Class_Name() << "::CreateHisto() HistoOther " << static_cast<size_t>(kHisto) << " Module " << moduleid
397 << "initialized as " << histoname.data();
398
399 if (newhisto) {
400 addHistoToMap<eOtherHistos>(newhisto, &fOtherHistoMap, moduleid, kHisto);
401 }
402 }
403}
404
405// ---- createHistos ----
407{
408 for (auto kHisto : fActiveDigiHistos) {
409 createHisto(kHisto);
410 }
411 for (auto kHisto : fActiveRawHistos) {
412 createHisto(kHisto);
413 }
414 for (auto kHisto : fActiveOtherHistos) {
415 createHisto(kHisto);
416 }
417}
418
419// ---- fillHisto ----
420void CbmTrdUnpackMonitor::fillHisto(CbmTrdDigi* digi, eDigiHistos kHisto, std::uint32_t moduleid,
421 std::shared_ptr<TH1> histo)
422{
423 auto triggerpair = digi->GetTriggerPair(digi->GetTriggerType());
424 auto triggertype = triggerpair.first;
425 auto isMultihit = triggerpair.second;
426 switch (kHisto) {
428 if (triggertype != CbmTrdDigi::eTriggerType::kSelf) {
429 return;
430 }
431 else {
432 auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel());
433 histo->Fill(addresspair.second, addresspair.first);
434 break;
435 }
436 }
438 if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) {
439 return;
440 }
441 else {
442 auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel());
443 histo->Fill(addresspair.second, addresspair.first);
444 break;
445 }
446 }
447 case eDigiHistos::kMap: {
448 auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel());
449 histo->Fill(addresspair.second, addresspair.first);
450 break;
451 }
452
453 case eDigiHistos::kCharge: histo->Fill(digi->GetCharge()); break;
455 if (triggertype != CbmTrdDigi::eTriggerType::kSelf) {
456 return;
457 }
458 histo->Fill(digi->GetCharge());
459 break;
461 if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) {
462 return;
463 }
464 histo->Fill(digi->GetCharge());
465 break;
466
467 case eDigiHistos::kChannel: histo->Fill(digi->GetAddressChannel()); break;
469 if (triggertype != CbmTrdDigi::eTriggerType::kSelf) {
470 return;
471 }
472 histo->Fill(digi->GetAddressChannel());
473 break;
475 if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) {
476 return;
477 }
478 histo->Fill(digi->GetAddressChannel());
479 break;
480
482 if (isMultihit) histo->Fill(static_cast<int>(CbmTrdDigi::eTriggerType::kMulti));
483 histo->Fill(static_cast<int>(triggertype));
484 break;
485 }
486 case eDigiHistos::kDigiDeltaT: histo->Fill(digi->GetAddressChannel(), getDeltaT(digi)); break;
487 case eDigiHistos::kDigiNtCorr: fillNtCorrHisto(histo, digi); break;
488
489 default: return; break;
490 }
491}
492
493// ---- fillHisto ----
494void CbmTrdUnpackMonitor::fillHisto(CbmTrdRawMessageSpadic* raw, eRawHistos kHisto, std::shared_ptr<TH1> histo,
495 CbmTrdDigi* digi)
496{
497 auto triggertype = static_cast<Spadic::eTriggerType>(raw->GetHitType());
498 switch (kHisto) {
499 case eRawHistos::kSignalshape: fillSamplesHisto(histo, raw); break;
501 if (triggertype != Spadic::eTriggerType::kSelf && triggertype != Spadic::eTriggerType::kSandN) return;
502 fillSamplesHisto(histo, raw);
503 break;
505 if (triggertype != Spadic::eTriggerType::kNeigh) return;
506 fillSamplesHisto(histo, raw);
507 break;
508 case eRawHistos::kMap: histo->Fill(raw->GetElinkId(), raw->GetChannelId()); break;
510 if (triggertype != Spadic::eTriggerType::kSelf && triggertype != Spadic::eTriggerType::kSandN) return;
511 histo->Fill(raw->GetElinkId(), raw->GetChannelId());
512 break;
514 if (triggertype != Spadic::eTriggerType::kNeigh) return;
515 histo->Fill(raw->GetElinkId(), raw->GetChannelId());
516 break;
517 case eRawHistos::kElinkId: histo->Fill(raw->GetElinkId()); break;
518 case eRawHistos::kSampleDistStdDev: histo->Fill(getSamplesStdDev(raw)); break;
520 if (!digi) return;
521 histo->Fill(digi->GetAddressChannel(), raw->GetSamples()->at(0));
522 break;
523 }
524 case eRawHistos::kHitType: histo->Fill(static_cast<int>(raw->GetHitType())); break;
526 //raw->GetTime() is relative to TS start only, so one needs to add fCurrentTimesliceStartTimeNs to it
528 histo->Fill((fCurrentTimesliceStartTimeNs + (std::uint64_t) raw->GetTime() - fCurrentTimeplotStartNs) * 1.0 / 1E9,
529 10);
530 break;
531 default: return; break;
532 }
533}
534
535// ---- fillSamplesHisto ----
537{
538 for (size_t isample = 0; isample < raw->GetSamples()->size(); isample++) {
539 histo->Fill(isample, raw->GetSamples()->at(isample));
540 }
541}
542
543// ---- getDeltaT ----
545{
546 auto moduleid = digi->GetAddressModule();
547 auto channelid = digi->GetAddressChannel();
548 auto modulevecpair = fLastDigiTimeMap.find(moduleid);
549 if (modulevecpair == fLastDigiTimeMap.end()) {
550 auto nchannels = fModuleNrColumns.find(moduleid)->second * fModuleNrRows.find(moduleid)->second;
551 std::vector<size_t> channelsvec(nchannels, 0);
552 if (channelid > nchannels) return 0;
553 channelsvec.at(channelid) = digi->GetTime();
554 auto pair = std::make_pair(moduleid, channelsvec);
555 fLastDigiTimeMap.emplace(pair);
556 return digi->GetTime();
557 ;
558 }
559 else {
560 auto prevtime = modulevecpair->second.at(channelid);
561 modulevecpair->second.at(channelid) = digi->GetTime();
562 auto dt = digi->GetTime() - prevtime;
563 return dt;
564 }
565}
566
567// ---- fillNtCorrHisto ----
568void CbmTrdUnpackMonitor::fillNtCorrHisto(std::shared_ptr<TH1> histo, CbmTrdDigi* digi)
569{
570 Double_t newDigiTime = digi->GetTime();
571 Int_t newDigiAddrCh = digi->GetAddressChannel();
572 Int_t newDigiAddrModule = digi->GetAddressModule();
573
574 int nTrdDigis = fDigiOutputVec->size();
575
576 for (int iDigi = nTrdDigis - 1; iDigi > 0; --iDigi) {
577 const CbmTrdDigi digiRef = fDigiOutputVec->at(iDigi);
578
579 Double_t refDigiTime = digiRef.GetTime();
580
581 if (digiRef.GetAddressModule() == newDigiAddrModule) {
582 if (digiRef.GetTriggerType() == static_cast<Int_t>(CbmTrdDigi::eTriggerType::kNeighbor)
583 && digi->GetTriggerType() == static_cast<Int_t>(CbmTrdDigi::eTriggerType::kSelf))
584 histo->Fill(digiRef.GetAddressChannel(), newDigiAddrCh);
585 else if (digiRef.GetTriggerType() == static_cast<Int_t>(CbmTrdDigi::eTriggerType::kSelf)
586 && digi->GetTriggerType() == static_cast<Int_t>(CbmTrdDigi::eTriggerType::kNeighbor))
587 histo->Fill(newDigiAddrCh, digiRef.GetAddressChannel());
588 }
589
590 if (refDigiTime < newDigiTime - 500 /*|| iDigi < nTrdDigis - 20*/) break;
591 }
592}
593
594// ---- getHistoName ----
596{
597 std::string histoname = "";
598
599 switch (kHisto) {
600 case eDigiHistos::kMap: histoname += "Map"; break;
601 case eDigiHistos::kMap_St: histoname += "Map_St"; break;
602 case eDigiHistos::kMap_Nt: histoname += "Map_Nt"; break;
603 case eDigiHistos::kCharge: histoname += "Charge"; break;
604 case eDigiHistos::kCharge_St: histoname += "Charge_St"; break;
605 case eDigiHistos::kCharge_Nt: histoname += "Charge_Nt"; break;
606 case eDigiHistos::kChannel: histoname += "Channel"; break;
607 case eDigiHistos::kChannel_St: histoname += "Channel_St"; break;
608 case eDigiHistos::kChannel_Nt: histoname += "Channel_Nt"; break;
609 case eDigiHistos::kTriggerType: histoname += "TriggerType"; break;
610 case eDigiHistos::kDigiDeltaT: histoname += "DigiDeltaT"; break;
611 case eDigiHistos::kDigiNtCorr: histoname += "DigiNtCorr"; break;
612 }
613 return histoname;
614}
615
616// ---- getHistoName ----
618{
619 std::string histoname = "";
620
621 switch (kHisto) {
622 case eRawHistos::kSignalshape: histoname += "Signalshape"; break;
623 case eRawHistos::kSignalshape_St: histoname += "Signalshape_St"; break;
624 case eRawHistos::kSignalshape_Nt: histoname += "Signalshape_Nt"; break;
625 case eRawHistos::kMap: histoname += "Map"; break;
626 case eRawHistos::kMap_St: histoname += "Map_St"; break;
627 case eRawHistos::kMap_Nt: histoname += "Map_Nt"; break;
628 case eRawHistos::kElinkId: histoname += "ElinkId"; break;
629 case eRawHistos::kSampleDistStdDev: histoname += "SampleDistStdDev"; break;
630 case eRawHistos::kSample0perChannel: histoname += "Sample0perChannel"; break;
631 case eRawHistos::kHitType: histoname += "HitType"; break;
632 case eRawHistos::kRawRate: histoname += "RawRate"; break;
633 }
634 return histoname;
635}
636
637// ---- getHistoName ----
639{
640 std::string histoname = "";
641
642 switch (kHisto) {
643 case eOtherHistos::kSpadic_Info_Types: histoname += "Spadic_Info_Types"; break;
644 case eOtherHistos::kMs_Flags: histoname += "Ms_Flags"; break;
645 case eOtherHistos::kBomRate: histoname += "BomRate"; break;
646 case eOtherHistos::kBufRate: histoname += "BufRate"; break;
647 case eOtherHistos::kBomPerRawRate: histoname += "BomPerRawRate"; break;
648 }
649 return histoname;
650}
651
652// ---- getHistoType ----
653std::string CbmTrdUnpackMonitor::getHistoType(std::shared_ptr<TH1> histo)
654{
655 std::string histoname = histo->GetName();
656 // The type follows on the module id separated by the first occurance of "-"
657 auto startpos = histoname.find_first_of("-");
658 // Now we are positioned at "-" so we move one further to get the correct place
659 startpos++;
660 // Extract the type from the rest of the string
661 auto length = histoname.find_first_of("_", startpos) - startpos;
662 auto histotype = histoname.substr(startpos, length);
663
664 return histotype;
665}
666
667// ---- getRowAndCol ----
668std::pair<std::uint32_t, std::uint32_t> CbmTrdUnpackMonitor::getRowAndCol(std::uint32_t moduleid,
669 std::uint32_t channelid)
670{
671 // Check if we have to rotate the address, is true in case of 180(2) or 270(3) degree rotation
672 bool doRotate = fModuleOrientation.find(moduleid)->second / 2;
673 bool isYsensitive = fModuleOrientation.find(moduleid)->second % 2;
674 auto nrows = static_cast<std::uint32_t>(fModuleNrRows.find(moduleid)->second);
675 auto ncols = static_cast<std::uint32_t>(fModuleNrColumns.find(moduleid)->second);
676
677 // Potentially rotate the address
678 std::uint32_t rotatedid = doRotate ? (channelid * (-1) + (nrows * ncols) - 1) : channelid;
679
680 auto row = rotatedid / ncols;
681 auto col = rotatedid % ncols;
682
683 // In case we have a chamber with the columns along x we return row,col
684 if (!isYsensitive)
685 return std::make_pair(row, col);
686 else
687 // In case we have a chamber with the columns along y we return col,row
688 return std::make_pair(col, row);
689}
690
691// ---- getSamplesStdDev ----
693{
694 std::float_t sum = std::accumulate(raw->GetSamples()->begin(), raw->GetSamples()->end(), 0);
695
696 std::float_t mean = sum / raw->GetNrSamples();
697
698 std::float_t dev = 0;
699
700 for (auto sample : *raw->GetSamples()) {
701 dev += (sample - mean) * (sample - mean);
702 }
703 return std::sqrt(1.0 / raw->GetNrSamples() * dev);
704}
705
706// ---- resetTimeplots ----
708{
709 for (auto typemappair : fRawHistoMap) {
710 switch (typemappair.first) {
712 for (auto histopair : typemappair.second) {
713 histopair.second->Reset("ICESM");
714 }
715 break;
716 default: break;
717 }
718 }
719 for (auto typemappair : fOtherHistoMap) {
720 switch (typemappair.first) {
724 for (auto histopair : typemappair.second) {
725 histopair.second->Reset("ICESM");
726 }
727 break;
728 default: break;
729 }
730 }
731}
732
733// ---- adjustTimeplots ----
734void CbmTrdUnpackMonitor::adjustTimeplots(std::uint64_t newtime)
735{
737
738 // shift timeplot start offset until the new time lies within the plot time boundaries
739 while (newtime > fCurrentTimeplotStartNs + kTimeplotLenghtSeconds * 1E9) {
741 std::cout << "adjusting timeplot start to " << fCurrentTimeplotStartNs << " ns" << std::endl;
743 }
744}
745
ClassImp(CbmConverterManager)
Monitor class to monitor the data from the Trd unpacker algorithms.
static constexpr size_t size()
Definition KfSimdPseudo.h:2
int32_t GetAddressModule() const
Getter module address in the experiment.
static std::pair< eTriggerType, bool > GetTriggerPair(const int32_t triggerValue)
Get the trigger combination, i.e. St or Nt and is multihit or not (true/false)
int32_t GetTriggerType() const
Channel trigger type. SPADIC specific see CbmTrdTriggerType.
Definition CbmTrdDigi.h:163
int32_t GetAddressChannel() const
Getter read-out id.
double GetTime() const
Getter for physical time [ns]. Accounts for clock representation of each ASIC. In SPADIC case physica...
Definition CbmTrdDigi.h:153
double GetCharge() const
Common purpose charge getter.
Describe TRD module ASIC settings (electronic gain, delays, etc)
Definition of chamber gain conversion for one TRD module.
Describe TRD module ASIC settings (electronic gain, delays, etc)
virtual const CbmTrdParMod * GetModulePar(Int_t detId) const
std::map< Int_t, CbmTrdParMod * > GetModuleMap()
Base class for storing raw information which comes from the Spadic v2.2 trough flib or from a tsa fil...
const std::vector< std::int16_t > * GetSamples() const
std::uint8_t GetChannelId() const
std::uint8_t GetNrSamples() const
std::uint8_t GetHitType() const
std::uint8_t GetElinkId() const
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 ...
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.
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.
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
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.
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.
size_t writeHistosToFile(std::map< histotype, std::map< std::uint32_t, std::shared_ptr< TH1 > > > *histomap, TFile *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 ...
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.
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.
@ kUNU
Unused request. 100. .... .... .... cccc.
@ kChannelBufM
Channel buffer full and multihit from kEPO msg.
@ kChannelBuf
Channel buffer full from kEPO msg.
@ kNInfMsgs
Number of different info messages.
@ kBOM
Buffer overflow count. 11nn nnnn nnnn nnnn cccc.
@ kMIS
Missing request. 101. .... .... .... ....
@ kOrdFifoBuf
Multi-hit but ordering buffer full from kEPO msg.
@ kBUF
Buffer full. 011b b... .... .... cccc.
@ kMSB
Message build error. 010. .... .... .... cccc.
@ kNeigh
Neighbor trigger.
@ kGlobal
global trigger.
@ kSelf
Self trigger.
@ kSandN
Self and neighbor trigger at the same time.