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 ----
67{
68 //kSpadic_Info_Types
69 {
71 if (pair != fOtherHistoMap.end()) {
72 auto histo = pair->second.find(moduleid)->second;
73 histo->Fill(static_cast<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, 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<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<uint32_t, uint8_t>(modulepair.first, parmoddigi->GetOrientation()));
167 fModuleNrRows.emplace(std::pair<uint32_t, uint8_t>(modulepair.first, parmoddigi->GetNofRows()));
168 fModuleNrColumns.emplace(std::pair<uint32_t, 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<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<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, uint32_t moduleid, std::shared_ptr<TH1> histo)
421{
422 auto triggerpair = digi->GetTriggerPair(digi->GetTriggerType());
423 auto triggertype = triggerpair.first;
424 auto isMultihit = triggerpair.second;
425 switch (kHisto) {
427 if (triggertype != CbmTrdDigi::eTriggerType::kSelf) {
428 return;
429 }
430 else {
431 auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel());
432 histo->Fill(addresspair.second, addresspair.first);
433 break;
434 }
435 }
437 if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) {
438 return;
439 }
440 else {
441 auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel());
442 histo->Fill(addresspair.second, addresspair.first);
443 break;
444 }
445 }
446 case eDigiHistos::kMap: {
447 auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel());
448 histo->Fill(addresspair.second, addresspair.first);
449 break;
450 }
451
452 case eDigiHistos::kCharge: histo->Fill(digi->GetCharge()); break;
454 if (triggertype != CbmTrdDigi::eTriggerType::kSelf) {
455 return;
456 }
457 histo->Fill(digi->GetCharge());
458 break;
460 if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) {
461 return;
462 }
463 histo->Fill(digi->GetCharge());
464 break;
465
466 case eDigiHistos::kChannel: histo->Fill(digi->GetAddressChannel()); break;
468 if (triggertype != CbmTrdDigi::eTriggerType::kSelf) {
469 return;
470 }
471 histo->Fill(digi->GetAddressChannel());
472 break;
474 if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) {
475 return;
476 }
477 histo->Fill(digi->GetAddressChannel());
478 break;
479
481 if (isMultihit) histo->Fill(static_cast<int>(CbmTrdDigi::eTriggerType::kMulti));
482 histo->Fill(static_cast<int>(triggertype));
483 break;
484 }
485 case eDigiHistos::kDigiDeltaT: histo->Fill(digi->GetAddressChannel(), getDeltaT(digi)); break;
486 case eDigiHistos::kDigiNtCorr: fillNtCorrHisto(histo, digi); break;
487
488 default: return; break;
489 }
490}
491
492// ---- fillHisto ----
493void CbmTrdUnpackMonitor::fillHisto(CbmTrdRawMessageSpadic* raw, eRawHistos kHisto, std::shared_ptr<TH1> histo,
494 CbmTrdDigi* digi)
495{
496 auto triggertype = static_cast<Spadic::eTriggerType>(raw->GetHitType());
497 switch (kHisto) {
498 case eRawHistos::kSignalshape: fillSamplesHisto(histo, raw); break;
500 if (triggertype != Spadic::eTriggerType::kSelf && triggertype != Spadic::eTriggerType::kSandN) return;
501 fillSamplesHisto(histo, raw);
502 break;
504 if (triggertype != Spadic::eTriggerType::kNeigh) return;
505 fillSamplesHisto(histo, raw);
506 break;
507 case eRawHistos::kMap: histo->Fill(raw->GetElinkId(), raw->GetChannelId()); break;
509 if (triggertype != Spadic::eTriggerType::kSelf && triggertype != Spadic::eTriggerType::kSandN) return;
510 histo->Fill(raw->GetElinkId(), raw->GetChannelId());
511 break;
513 if (triggertype != Spadic::eTriggerType::kNeigh) return;
514 histo->Fill(raw->GetElinkId(), raw->GetChannelId());
515 break;
516 case eRawHistos::kElinkId: histo->Fill(raw->GetElinkId()); break;
517 case eRawHistos::kSampleDistStdDev: histo->Fill(getSamplesStdDev(raw)); break;
519 if (!digi) return;
520 histo->Fill(digi->GetAddressChannel(), raw->GetSamples()->at(0));
521 break;
522 }
523 case eRawHistos::kHitType: histo->Fill(static_cast<int>(raw->GetHitType())); break;
525 //raw->GetTime() is relative to TS start only, so one needs to add fCurrentTimesliceStartTimeNs to it
527 histo->Fill((fCurrentTimesliceStartTimeNs + (uint64_t) raw->GetTime() - fCurrentTimeplotStartNs) * 1.0 / 1E9, 10);
528 break;
529 default: return; break;
530 }
531}
532
533// ---- fillSamplesHisto ----
535{
536 for (size_t isample = 0; isample < raw->GetSamples()->size(); isample++) {
537 histo->Fill(isample, raw->GetSamples()->at(isample));
538 }
539}
540
541// ---- getDeltaT ----
543{
544 auto moduleid = digi->GetAddressModule();
545 auto channelid = digi->GetAddressChannel();
546 auto modulevecpair = fLastDigiTimeMap.find(moduleid);
547 if (modulevecpair == fLastDigiTimeMap.end()) {
548 auto nchannels = fModuleNrColumns.find(moduleid)->second * fModuleNrRows.find(moduleid)->second;
549 std::vector<size_t> channelsvec(nchannels, 0);
550 if (channelid > nchannels) return 0;
551 channelsvec.at(channelid) = digi->GetTime();
552 auto pair = std::make_pair(moduleid, channelsvec);
553 fLastDigiTimeMap.emplace(pair);
554 return digi->GetTime();
555 ;
556 }
557 else {
558 auto prevtime = modulevecpair->second.at(channelid);
559 modulevecpair->second.at(channelid) = digi->GetTime();
560 auto dt = digi->GetTime() - prevtime;
561 return dt;
562 }
563}
564
565// ---- fillNtCorrHisto ----
566void CbmTrdUnpackMonitor::fillNtCorrHisto(std::shared_ptr<TH1> histo, CbmTrdDigi* digi)
567{
568 Double_t newDigiTime = digi->GetTime();
569 Int_t newDigiAddrCh = digi->GetAddressChannel();
570 Int_t newDigiAddrModule = digi->GetAddressModule();
571
572 int nTrdDigis = fDigiOutputVec->size();
573
574 for (int iDigi = nTrdDigis - 1; iDigi > 0; --iDigi) {
575 const CbmTrdDigi digiRef = fDigiOutputVec->at(iDigi);
576
577 Double_t refDigiTime = digiRef.GetTime();
578
579 if (digiRef.GetAddressModule() == newDigiAddrModule) {
580 if (digiRef.GetTriggerType() == static_cast<Int_t>(CbmTrdDigi::eTriggerType::kNeighbor)
581 && digi->GetTriggerType() == static_cast<Int_t>(CbmTrdDigi::eTriggerType::kSelf))
582 histo->Fill(digiRef.GetAddressChannel(), newDigiAddrCh);
583 else if (digiRef.GetTriggerType() == static_cast<Int_t>(CbmTrdDigi::eTriggerType::kSelf)
584 && digi->GetTriggerType() == static_cast<Int_t>(CbmTrdDigi::eTriggerType::kNeighbor))
585 histo->Fill(newDigiAddrCh, digiRef.GetAddressChannel());
586 }
587
588 if (refDigiTime < newDigiTime - 500 /*|| iDigi < nTrdDigis - 20*/) break;
589 }
590}
591
592// ---- getHistoName ----
594{
595 std::string histoname = "";
596
597 switch (kHisto) {
598 case eDigiHistos::kMap: histoname += "Map"; break;
599 case eDigiHistos::kMap_St: histoname += "Map_St"; break;
600 case eDigiHistos::kMap_Nt: histoname += "Map_Nt"; break;
601 case eDigiHistos::kCharge: histoname += "Charge"; break;
602 case eDigiHistos::kCharge_St: histoname += "Charge_St"; break;
603 case eDigiHistos::kCharge_Nt: histoname += "Charge_Nt"; break;
604 case eDigiHistos::kChannel: histoname += "Channel"; break;
605 case eDigiHistos::kChannel_St: histoname += "Channel_St"; break;
606 case eDigiHistos::kChannel_Nt: histoname += "Channel_Nt"; break;
607 case eDigiHistos::kTriggerType: histoname += "TriggerType"; break;
608 case eDigiHistos::kDigiDeltaT: histoname += "DigiDeltaT"; break;
609 case eDigiHistos::kDigiNtCorr: histoname += "DigiNtCorr"; break;
610 }
611 return histoname;
612}
613
614// ---- getHistoName ----
616{
617 std::string histoname = "";
618
619 switch (kHisto) {
620 case eRawHistos::kSignalshape: histoname += "Signalshape"; break;
621 case eRawHistos::kSignalshape_St: histoname += "Signalshape_St"; break;
622 case eRawHistos::kSignalshape_Nt: histoname += "Signalshape_Nt"; break;
623 case eRawHistos::kMap: histoname += "Map"; break;
624 case eRawHistos::kMap_St: histoname += "Map_St"; break;
625 case eRawHistos::kMap_Nt: histoname += "Map_Nt"; break;
626 case eRawHistos::kElinkId: histoname += "ElinkId"; break;
627 case eRawHistos::kSampleDistStdDev: histoname += "SampleDistStdDev"; break;
628 case eRawHistos::kSample0perChannel: histoname += "Sample0perChannel"; break;
629 case eRawHistos::kHitType: histoname += "HitType"; break;
630 case eRawHistos::kRawRate: histoname += "RawRate"; break;
631 }
632 return histoname;
633}
634
635// ---- getHistoName ----
637{
638 std::string histoname = "";
639
640 switch (kHisto) {
641 case eOtherHistos::kSpadic_Info_Types: histoname += "Spadic_Info_Types"; break;
642 case eOtherHistos::kMs_Flags: histoname += "Ms_Flags"; break;
643 case eOtherHistos::kBomRate: histoname += "BomRate"; break;
644 case eOtherHistos::kBufRate: histoname += "BufRate"; break;
645 case eOtherHistos::kBomPerRawRate: histoname += "BomPerRawRate"; break;
646 }
647 return histoname;
648}
649
650// ---- getHistoType ----
651std::string CbmTrdUnpackMonitor::getHistoType(std::shared_ptr<TH1> histo)
652{
653 std::string histoname = histo->GetName();
654 // The type follows on the module id separated by the first occurance of "-"
655 auto startpos = histoname.find_first_of("-");
656 // Now we are positioned at "-" so we move one further to get the correct place
657 startpos++;
658 // Extract the type from the rest of the string
659 auto length = histoname.find_first_of("_", startpos) - startpos;
660 auto histotype = histoname.substr(startpos, length);
661
662 return histotype;
663}
664
665// ---- getRowAndCol ----
666std::pair<uint32_t, uint32_t> CbmTrdUnpackMonitor::getRowAndCol(uint32_t moduleid, uint32_t channelid)
667{
668 // Check if we have to rotate the address, is true in case of 180(2) or 270(3) degree rotation
669 bool doRotate = fModuleOrientation.find(moduleid)->second / 2;
670 bool isYsensitive = fModuleOrientation.find(moduleid)->second % 2;
671 auto nrows = static_cast<uint32_t>(fModuleNrRows.find(moduleid)->second);
672 auto ncols = static_cast<uint32_t>(fModuleNrColumns.find(moduleid)->second);
673
674 // Potentially rotate the address
675 uint32_t rotatedid = doRotate ? (channelid * (-1) + (nrows * ncols) - 1) : channelid;
676
677 auto row = rotatedid / ncols;
678 auto col = rotatedid % ncols;
679
680 // In case we have a chamber with the columns along x we return row,col
681 if (!isYsensitive)
682 return std::make_pair(row, col);
683 else
684 // In case we have a chamber with the columns along y we return col,row
685 return std::make_pair(col, row);
686}
687
688// ---- getSamplesStdDev ----
690{
691 std::float_t sum = std::accumulate(raw->GetSamples()->begin(), raw->GetSamples()->end(), 0);
692
693 std::float_t mean = sum / raw->GetNrSamples();
694
695 std::float_t dev = 0;
696
697 for (auto sample : *raw->GetSamples()) {
698 dev += (sample - mean) * (sample - mean);
699 }
700 return std::sqrt(1.0 / raw->GetNrSamples() * dev);
701}
702
703// ---- resetTimeplots ----
705{
706 for (auto typemappair : fRawHistoMap) {
707 switch (typemappair.first) {
709 for (auto histopair : typemappair.second) {
710 histopair.second->Reset("ICESM");
711 }
712 break;
713 default: break;
714 }
715 }
716 for (auto typemappair : fOtherHistoMap) {
717 switch (typemappair.first) {
721 for (auto histopair : typemappair.second) {
722 histopair.second->Reset("ICESM");
723 }
724 break;
725 default: break;
726 }
727 }
728}
729
730// ---- adjustTimeplots ----
732{
734
735 // shift timeplot start offset until the new time lies within the plot time boundaries
736 while (newtime > fCurrentTimeplotStartNs + kTimeplotLenghtSeconds * 1E9) {
738 std::cout << "adjusting timeplot start to " << fCurrentTimeplotStartNs << " ns" << std::endl;
740 }
741}
742
ClassImp(CbmConverterManager)
Monitor class to monitor the data from the Trd unpacker algorithms.
static constexpr size_t size()
Definition KfSimdPseudo.h:2
int Int_t
bool Bool_t
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:160
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:155
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< int16_t > * GetSamples() const
std::pair< uint32_t, uint32_t > getRowAndCol(uint32_t moduleid, uint32_t channelid)
Get the row and column ids (potentially rotated chambers are adjusted to humand readable rotations)
void Finish()
Actions at the end of the run, e.g. write histos to file if flag is set.
static std::string getTypeName(eDigiHistos kHisto)
Get the Type Name for the given histo.
virtual ~CbmTrdUnpackMonitor()
Destroy the Cbm Trd Unpack Task object.
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::map< uint32_t, uint8_t > fModuleNrColumns
Map with the number of columns of the modules. Performance helper to not go through the extraction fr...
std::string getHistoName(eDigiHistos kHisto)
Get the Histo Name for the given histo.
void adjustTimeplots(uint64_t newtime)
Adjust the boundaries of all timeplots to contain newtime.
virtual void fillHisto(CbmTrdDigi *digi, eDigiHistos kHisto, uint32_t moduleid, std::shared_ptr< TH1 > histo)
Fill the given histo with the information from the digi.
void fillNtCorrHisto(std::shared_ptr< TH1 > histo, CbmTrdDigi *digi)
Fill the NeighborTrigger Checking Histogram.
eDigiHistos
Enum for the predefined digi histograms.
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< uint32_t, std::vector< size_t > > fLastDigiTimeMap
Map with the last digi time for each channel of a given module.
std::string getHistoType(std::shared_ptr< TH1 > histo)
Get the Histo Type, i.e. "Digi/Raw/Other", deduced from the histo name.
std::vector< uint32_t > fModuleIdsVec
Vector with the unique module Ids.
Bool_t Init(CbmTrdParSetDigi *digiParSet, CbmTrdParSetAsic *asicParSet=nullptr)
Init all required parameter informations.
uint64_t fCurrentTimesliceStartTimeNs
Variable which holds the start time in ns of the current timeslice.
static const uint32_t kTimeplotLenghtSeconds
Constant which defines the lenght of the time axis in seconds of plots which display a quantity over ...
std::shared_ptr< CbmTrdSpadic > fSpadic
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)
uint64_t fCurrentTimeplotStartNs
Variable which holds the start time in ns of the current time axis of plots which display a quantity ...
std::map< eDigiHistos, std::map< uint32_t, std::shared_ptr< TH1 > > > fDigiHistoMap
Digi histogram pointers stored in a map together with the module id.
void FillHisto(Spadic::MsInfoType type, uint32_t moduleid)
Fill the given histo with the information on the info type.
std::map< uint32_t, uint8_t > fModuleNrRows
Map with the number of rows of the modules. Performance helper to not go through the extraction from ...
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.
std::map< uint32_t, uint8_t > fModuleOrientation
Map with the orientations of the modules. Performance helper to not go through the extraction from Pa...
void FillHistos(CbmTrdDigi *digi, CbmTrdRawMessageSpadic *raw=nullptr)
fill the stored digi histograms
eOtherHistos
Enum for the predefined other histograms.
std::map< eRawHistos, std::map< uint32_t, std::shared_ptr< TH1 > > > fRawHistoMap
Raw histogram pointers stored in a map together with the module id.
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.
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.
void addHistoToMap(std::shared_ptr< TH1 > histo, std::map< histotype, std::map< uint32_t, std::shared_ptr< TH1 > > > *histomap, uint32_t moduleid, histotype kHisto)
std::map< eOtherHistos, std::map< uint32_t, std::shared_ptr< TH1 > > > fOtherHistoMap
Other histogram pointers stored in a map together with the module id.
virtual void createHistos()
Create the actual TH1 shared_ptrs.
size_t writeHistosToFile(std::map< histotype, std::map< uint32_t, std::shared_ptr< TH1 > > > *histomap, TFile *file)
@ 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.
@ kSandN
Self and neighbor trigger at the same time.