15 #include "FairLogger.h"
16 #include "FairRootManager.h"
18 #include "FairRunOnline.h"
19 #include "FairRuntimeDb.h"
26 #include "TPaveStats.h"
42 , fbDebugMonitorMode(kTRUE)
43 , fvbMaskedComponents()
44 , fbFirstPackageError(kTRUE)
49 , fuNrOfChannelsPerFee(0)
50 , fuNrOfChannelsPerGdpb(0)
54 , fdTsStopTimeCore(-1.0)
58 , fuCurrentEquipmentId(0)
61 , fiRunStartDateTimeSec(-1)
62 , fiBinSizeDatePlots(-1)
64 , fvulCurrentEpochCycle()
65 , fvulCurrentEpochFull()
67 , fdStartTimeMsSz(0.0)
68 , ftStartTimeUnix(std::chrono::steady_clock::now())
69 , fuHistoryHistoSize(3600)
70 , fviHistoChargeArgs(3, 0)
71 , fviHistoAmplArgs(3, 0)
72 , fviHistoZLArgs(3, 0)
75 , fuReadMsgsCntInMs(0)
76 , fuLostMsgsCntInMs(0)
78 , fvuHitCntChanMs(kuNbChanPsd, 0)
79 , fvuErrorCntChanMs(kuNbChanPsd, 0)
80 , fvuEvtLostCntChanMs(kuNbChanPsd, 0)
81 , fvhHitCntEvoChan(kuNbChanPsd, nullptr)
82 , fvhHitCntPerMsEvoChan(kuNbChanPsd, nullptr)
83 , fvhHitChargeChan(kuNbChanPsd, nullptr)
84 , fvhHitZeroLevelChan(kuNbChanPsd, nullptr)
85 , fvhHitAmplChan(kuNbChanPsd, nullptr)
86 , fvhHitChargeByWfmChan(kuNbChanPsd, nullptr)
87 , fvhHitChargeEvoChan(kuNbChanPsd, nullptr)
88 , fvhHitWfmChan(kuNbChanPsd, nullptr)
89 , fvhHitFitWfmChan(kuNbChanPsd, nullptr)
90 , kvuWfmRanges(kuNbWfmRanges, 0)
91 , kvuWfmInRangeToChangeChan(kuNbChanPsd * kuNbWfmRanges, 0)
92 , fv3hHitWfmFlattenedChan(kuNbChanPsd * kuNbWfmRanges * kuNbWfmExamples,
95 , fuCurrentSpillIdx(0)
96 , fuCurrentSpillPlot(0)
97 , fdStartTimeSpill(-1.0)
98 , fdLastSecondTime(-1.0)
99 , fuCountsLastSecond(0)
100 , fhChannelMap(nullptr)
101 , fhHitChargeMap(nullptr)
102 , fhHitMapEvo(nullptr)
103 , fhChanHitMapEvo(nullptr)
104 , fvhChannelMapSpill()
105 , fhHitsPerSpill(nullptr)
106 , fhMsgsCntEvo(nullptr)
107 , fhReadMsgsCntEvo(nullptr)
108 , fhLostMsgsCntEvo(nullptr)
109 , fhReadEvtsCntEvo(nullptr)
110 , fhAdcTimeEvo(nullptr)
111 , fhMsLengthEvo(nullptr)
112 , fhMsgsCntPerMsEvo(nullptr)
113 , fhReadMsgsCntPerMsEvo(nullptr)
114 , fhLostMsgsCntPerMsEvo(nullptr)
115 , fhReadEvtsCntPerMsEvo(nullptr)
116 , fvhFitHarmonic1Chan(kuNbChanPsd, nullptr)
117 , fvhFitHarmonic2Chan(kuNbChanPsd, nullptr)
118 , fvhFitQaChan(kuNbChanPsd, nullptr)
121 , fcChargesFPGA(nullptr)
122 , fcChargesWfm(nullptr)
123 , fcAmplitudes(nullptr)
124 , fcGenCntsPerMs(nullptr)
125 , fcSpillCounts(nullptr)
126 , fcSpillCountsHori(nullptr)
127 , fcWfmsAllChannels(nullptr)
128 , fvcWfmsChan(kuNbChanPsd, nullptr) {}
135 LOG(info) <<
"Initializing mCBM Psd 2019 monitor algo";
148 LOG(info) <<
"Init parameter containers for CbmMcbm2018MonitorAlgoPsd";
154 LOG(info) <<
"**********************************************";
155 LOG(info) <<
"ReInit parameter containers for CbmMcbm2018MonitorAlgoPsd";
187 LOG(info) <<
"GDPB Id of PSD " <<
i <<
" : " << std::hex
201 UShort_t usDetectorId) {
209 LOG(info) <<
"CbmMcbm2018MonitorAlgoPsd::AddMsComponentToList => Component "
210 << component <<
" with detector ID 0x" << std::hex << usDetectorId
211 << std::dec <<
" added to list";
217 fdTsStartTime =
static_cast<Double_t
>(ts.descriptor(0, 0).idx);
221 LOG(info) <<
"Reseting Histos for a new run";
240 LOG(info) <<
"In each TS " <<
fuNbMsLoop <<
" MS will be looped over";
256 <<
fuMsIndex <<
" for component " << uMsComp;
282 auto msDescriptor = ts.descriptor(uMsCompIdx, uMsIdx);
284 const uint8_t* msContent =
285 reinterpret_cast<const uint8_t*
>(ts.content(uMsCompIdx, uMsIdx));
287 uint32_t uSize = msDescriptor.size;
292 LOG(debug) <<
"Microslice: " <<
fulCurrentMsIdx <<
" from EqId " << std::hex
305 <<
"---------------------------------------------------------------";
308 LOG(warning) <<
"Could not find the gDPB index for AFCK id 0x" << std::hex
311 <<
" component " << uMsCompIdx <<
"\n"
312 <<
"If valid this index has to be added in the PSD "
313 "parameter file in the DbpIdArray field";
361 LOG(error) <<
"negative time! ";
368 LOG(error) <<
"The input microslice buffer does NOT "
369 <<
"contain only complete nDPB messages!";
372 uint32_t uNbMessages =
376 const uint64_t* pInBuff =
reinterpret_cast<const uint64_t*
>(msContent);
378 if (gLogger->IsLogNeeded(fair::Severity::debug)) {
379 if (uNbMessages != 0) printf(
"\n\n");
380 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
382 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
383 printf(
"%016llx\n", (
long long int) ulData);
395 if (gLogger->IsLogNeeded(fair::Severity::debug))
401 LOG(error) <<
"too many triggered channels! In header: "
407 if (ReadResult == 0) {
417 UInt_t uHitChannel = PsdReader.
VectHitHdr.at(hit_iter).uHitChannel;
418 UInt_t uSignalCharge =
419 PsdReader.
VectHitHdr.at(hit_iter).uSignalCharge;
420 UInt_t uZeroLevel = PsdReader.
VectHitHdr.at(hit_iter).uZeroLevel;
421 std::vector<uint16_t> uWfm = PsdReader.
VectHitData.at(hit_iter).uWfm;
425 LOG(error) <<
"hit channel number out of range! channel index: "
448 uint16_t uHitAmlpitude = 0;
449 uint16_t uHitChargeWfm = 0;
452 for (UInt_t wfm_iter = 0; wfm_iter < uWfm.size(); wfm_iter++) {
453 if (uWfm.at(wfm_iter) > uHitAmlpitude)
454 uHitAmlpitude = uWfm.at(wfm_iter);
455 uHitChargeWfm += uWfm.at(wfm_iter) - uZeroLevel;
456 fvhHitWfmChan[uHitChannel]->Fill(wfm_iter, uWfm.at(wfm_iter));
459 Form(
"Waveform channel %03u charge %0u zero level %0u; Time [adc "
460 "counts]; Amplitude [adc counts]",
464 uHitAmlpitude -= uZeroLevel;
471 UInt_t uFlatIndexOfChange =
i *
kuNbChanPsd + uHitChannel;
473 UInt_t uWfmExampleIter =
475 UInt_t uFlatIndexHisto =
480 for (UInt_t wfm_iter = 0; wfm_iter < uWfm.size(); wfm_iter++)
482 wfm_iter, uWfm.at(wfm_iter));
484 Form(
"Waveform channel %03u charge %0u zero level %0u; Time "
485 "[adc counts]; Amplitude [adc counts]",
507 SignalBeg - 1, SignalBeg + 1);
513 Float_t fit_integral = Pfitter.
GetIntegral(gate_beg, gate_end);
514 Float_t fit_R2 = Pfitter.
GetRSquare(gate_beg, gate_end);
516 std::complex<float>* harmonics = Pfitter.
GetHarmonics();
517 std::vector<uint16_t> uFitWfm = Pfitter.
GetFitWfm();
518 for (UInt_t wfm_iter = 0; wfm_iter < uFitWfm.size(); wfm_iter++) {
521 Form(
"Waveform channel %03u charge %0u zero level %0u R2 %.5f; "
522 "Time [adc counts]; Amplitude [adc counts]",
531 if (fit_R2 > 0.02)
continue;
533 std::imag(harmonics[1]));
535 std::imag(harmonics[2]));
538 }
else if (ReadResult == 1) {
539 LOG(error) <<
"no event headers in message!";
541 }
else if (ReadResult == 2) {
542 LOG(error) <<
"check number of waveform points! In header: "
545 }
else if (ReadResult == 3) {
546 LOG(error) <<
"wrong amount of hits read! In header: "
548 <<
" in hit vector: " << PsdReader.
VectHitHdr.size();
552 <<
"PsdGbtReader.ReadEventFles() didn't return expected values";
559 LOG(error) <<
"Wrong amount of messages read!"
560 <<
" in microslice " << uNbMessages <<
" by PsdReader "
566 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
567 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
568 error_log << Form(
"%016llx\n", (
long long int) ulData);
577 LOG(error) <<
"Wrong MS index!"
609 std::string sFolder =
"MoniPsd";
610 std::string sFitFolder =
"PronyFit";
611 LOG(info) <<
"create Histos for PSD monitoring ";
614 uint32_t iNbBinsLog = 0;
617 double* dBinsLog = dBinsLogVector.data();
620 "Map of hits in PSD detector; Chan; Hits Count []",
625 new TH2I(
"hHitChargeMap",
626 "Map of hits charges in PSD detector; Chan; Charge [adc counts]",
634 "Map of hits in PSD detector electronics vs time in "
635 "run; Chan; Time in run [s]; Hits Count []",
643 "Map of hits in PSD detector vs time in run; "
644 "Chan; Time in run [s]; Hits Count []",
653 new TH1I(Form(
"hChannelMapSpill%02u", uSpill),
654 Form(
"Map of hits in PSD detector in current spill %02u; Chan; "
662 "Hit count per spill; Spill; Hits Count []",
668 "Evolution of TotalMsgs counts vs time in run; Time "
669 "in run [s]; Msgs Count []",
674 "Evolution of ReadMsgs counts vs time in run; "
675 "Time in run [s]; ReadMsgs Count []",
680 "Evolution of LostMsgs counts vs time in run; "
681 "Time in run [s]; LostMsgs Count []",
686 "Evolution of ReadEvents counts vs time in run; "
687 "Time in run [s]; ReadEvents Count []",
694 "Evolution of ADC time vs time in run; Time in run [s]; Adc time *12.5[ns]",
704 "Evolution of MS length vs time in run; Time in run [s]; MS length [ns]",
713 new TH2I(
"hMsgsCntPerMsEvo",
714 "Evolution of TotalMsgs counts, per MS vs time in run; Time in "
715 "run [s]; TotalMsgs Count/MS []; MS",
722 new TH2I(
"ReadMsgsCntPerMsEvo",
723 "Evolution of ReadMsgs counts, per MS vs time in run; Time in run "
724 "[s]; ReadMsgs Count/MS []; MS",
731 new TH2I(
"hLostMsgsCntPerMsEvo",
732 "Evolution of LostMsgs counts, per MS vs time in run; Time in run "
733 "[s]; LostMsgs Count/MS []; MS",
740 new TH2I(
"hReadEvtCntPerMsEvo",
741 "Evolution of ReadEvents, per MS counts vs time in run; Time in "
742 "run [s]; ReadEvents Count/MS []; MS",
772 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; ++uChan) {
774 new TH1I(Form(
"hHitCntEvoChan%03u", uChan),
775 Form(
"Evolution of Hit counts vs time in run for channel %03u; "
776 "Time in run [s]; Hits Count []",
783 new TH2I(Form(
"hHitCntPerMsEvoChan%03u", uChan),
784 Form(
"Evolution of Hit counts per MS vs time in run for channel "
785 "%03u; Time in run [s]; Hits Count/MS []; MS",
794 Form(
"hHitChargeChan%03u", uChan),
795 Form(
"Hits charge distribution for channel %03u; Charge [adc counts]",
802 Form(
"hHitZeroLevelChan%03u", uChan),
804 "Hits zero level distribution for channel %03u; ZeroLevel [adc counts]",
811 Form(
"hHitAmplChan%03u", uChan),
813 "Hits amplitude distribution for channel %03u; Amplitude [adc counts]",
820 new TH1I(Form(
"hHitChargeByWfmChan%03u", uChan),
821 Form(
"Hits charge by waveform distribution for channel %03u; "
822 "Charge [adc counts]",
829 new TH2I(Form(
"hHitChargeEvoChan%03u", uChan),
830 Form(
"Evolution of Hit charge vs time in run for channel %03u; "
831 "Time in run [s]; Charge [adc counts]",
841 Form(
"hHitWfmChan%03u", uChan), Form(
"HitWfmChan%03u", uChan), 8, 0, 8);
846 Form(
"HitFitWfmChan%03u", uChan),
853 for (UInt_t uWfmRangeIter = 0; uWfmRangeIter <
kuNbWfmRanges;
860 new TH1I(Form(
"hHitWfmChan%03uRange%02uExample%02u",
864 Form(
"HitWfmChan%03uRange%02uExample%02u",
876 Form(
"hFitHarmonic1Chan%03u", uChan),
878 "Waveform fit harmonic 1 for channel %03u; Real part []; Imag part []",
889 Form(
"hFitHarmonic2Chan%03u", uChan),
891 "Waveform fit harmonic 2 for channel %03u; Real part []; Imag part []",
902 Form(
"hFitQaChan%03u", uChan),
903 Form(
"Waveform fit QA for channel %03u; Integral [adc counts]; R2 []",
937 fcHitMaps =
new TCanvas(
"cHitMaps",
"Hit maps", w,
h);
964 new TCanvas(
"cSummary",
"Hit maps, Hit rate, Error fraction", w,
h);
998 "cChargesFPGA",
"Charges spectra in all channels calculated by FPGA", w,
h);
1001 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1012 new TCanvas(
"cChargesWfm",
1013 "Charges spectra in all channels calculated over waveform",
1018 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1029 new TCanvas(
"cAmplitudes",
"Amplitude spectra in all channels", w,
h);
1032 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1044 "Messages and hit cnt per MS, Error and Evt Loss Fract. per MS ",
1083 new TCanvas(
"cSpillCounts",
1084 "Counts per spill, last 5 spills including current one",
1102 "cWfmsAllChannels",
"Last waveforms in PSD fired channels", w,
h);
1105 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1116 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1118 new TCanvas(Form(
"cWfmsChan%03u", uChan),
1119 Form(
"Canvas with last waveforms in channel %03u", uChan),
1125 for (UInt_t uWfmRangeIter = 0; uWfmRangeIter <
kuNbWfmRanges;
1128 uWfmExampleIter++) {
1142 fcPronyFit =
new TCanvas(
"cPronyFit",
"Prony wfm fitting", w,
h);
1146 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1152 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1165 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; ++uChan) {
1185 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; ++uChan) {
1201 for (UInt_t uFlatIndex = 0;