197 auto msDescriptor = ts.descriptor(uMsCompIdx, uMsIdx);
199 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsCompIdx, uMsIdx));
201 uint32_t uSize = msDescriptor.size;
207 <<
" has size: " << uSize;
217 LOG(info) <<
"---------------------------------------------------------------";
220 LOG(warning) <<
"Could not find the gDPB index for AFCK id 0x" << std::hex <<
fuCurrDpbId << std::dec
221 <<
" in timeslice " <<
fulCurrentTsIdx <<
" in microslice " << uMsIdx <<
" component " << uMsCompIdx
223 <<
"If valid this index has to be added in the PSD "
224 "parameter file in the DbpIdArray field";
269 LOG(error) <<
"negative time! ";
276 LOG(error) <<
"The input microslice buffer does NOT "
277 <<
"contain only complete nDPB messages!";
283 const uint64_t* pInBuff =
reinterpret_cast<const uint64_t*
>(msContent);
285 if (fair::Logger::Logging(fair::Severity::debug)) {
286 if (uNbMessages != 0) printf(
"\n\n");
287 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
289 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
290 printf(
"%016llx\n", (
long long int) ulData);
299 if (fair::Logger::Logging(fair::Severity::debug)) PsdReader.
SetPrintOutMode(
true);
301 if (uNbMessages > 1) {
303 int ReadResult = PsdReader.
ReadMs();
304 if (ReadResult == 0) {
309 for (uint64_t hit_iter = 0; hit_iter < PsdReader.
VectHitHdr.size(); hit_iter++) {
311 LOG(error) <<
"Different vector headers sizes!"
312 <<
" in VectPackHdr " << PsdReader.
VectPackHdr.size() <<
" in VectHitHdr "
317 uint16_t uHitChannel = PsdReader.
VectHitHdr.at(hit_iter).uHitChannel;
319 uint32_t uSignalCharge = PsdReader.
VectHitHdr.at(hit_iter).uSignalCharge;
320 uint16_t uZeroLevel = PsdReader.
VectHitHdr.at(hit_iter).uZeroLevel;
321 uint32_t uAccum = PsdReader.
VectHitHdr.at(hit_iter).uFeeAccum;
324 std::vector<uint16_t> uWfm = PsdReader.
VectHitData.at(hit_iter).uWfm;
331 LOG(error) <<
"hit channel number out of range! channel index: " << uHitChannel
346 double dHitAmlpitude = 0;
347 double dHitChargeWfm = 0;
352 dHitChargeWfm = std::accumulate(uWfm.begin(), uWfm.end(), 0);
353 dHitChargeWfm -= uZeroLevel * uWfm.size();
354 auto const max_iter = std::max_element(uWfm.begin(), uWfm.end());
355 assert(max_iter != uWfm.end());
356 if (max_iter == uWfm.end())
break;
358 dHitAmlpitude = *max_iter - uZeroLevel;
366 for (UInt_t wfm_iter = 0; wfm_iter < uWfm.size(); wfm_iter++)
367 fvhHitWfmChan[uHitChannel]->Fill(wfm_iter, uWfm.at(wfm_iter));
369 Form(
"Waveform channel %03u charge %0u zero level %0u; Time [adc "
370 "counts]; Amplitude [adc counts]",
371 uHitChannel, uSignalCharge, uZeroLevel));
374 UInt_t uFlatIndexOfChange = i *
kuNbChanPsd + uHitChannel;
377 UInt_t uFlatIndexHisto =
381 for (UInt_t wfm_iter = 0; wfm_iter < uWfm.size(); wfm_iter++)
384 Form(
"Waveform channel %03u charge %0u zero level %0u; Time "
385 "[adc counts]; Amplitude [adc counts]",
386 uHitChannel, uSignalCharge, uZeroLevel));
406 std::complex<float> first_fit_harmonic = {0.72, 0.0};
407 std::complex<float> second_fit_harmonic = {0.38, -0.0};
418 Float_t fit_R2 = Pfitter.
GetRSquare(gate_beg, uWfm.size() - 1);
420 std::complex<float>* harmonics = Pfitter.
GetHarmonics();
421 std::vector<uint16_t> uFitWfm = Pfitter.
GetFitWfm();
422 for (UInt_t wfm_iter = 0; wfm_iter < uFitWfm.size(); wfm_iter++)
424 fvhHitWfmChan[uHitChannel]->SetTitle(Form(
"Waveform channel %03u charge %0u zero level %0u R2 %.5f; "
425 "Time [adc counts]; Amplitude [adc counts]",
426 uHitChannel, uSignalCharge, uZeroLevel, fit_R2));
430 if (fit_R2 > 0.02)
continue;
437 else if (ReadResult == 1) {
438 LOG(error) <<
"no pack headers in message!";
441 else if (ReadResult == 2) {
445 else if (ReadResult == 3) {
446 LOG(error) <<
"check number of waveform points! In header: " << PsdReader.
HitHdr.
uWfmWords - 1;
450 LOG(error) <<
"PsdGbtReader.ReadEventFles() didn't return expected values";
459 LOG(error) <<
"Wrong amount of messages read!"
463 std::ofstream error_log(Form(
"%llu_errorlog.txt",
fulCurrentMsIdx), std::ofstream::out);
464 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
465 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
466 error_log << Form(
"%016llx\n", (
long long int) ulData);
490 if (fair::Logger::Logging(fair::Severity::debug)) PsdReader.
SetPrintOutMode(
true);
491 if (uNbMessages > 1) {
495 LOG(error) <<
"too many triggered channels! In header: " << PsdReader.
EvHdrAb.
uHitsNumber
500 if (ReadResult == 0) {
507 UInt_t uHitChannel = PsdReader.
VectHitHdr.at(hit_iter).uHitChannel;
508 UInt_t uSignalCharge = PsdReader.
VectHitHdr.at(hit_iter).uSignalCharge;
509 UInt_t uZeroLevel = PsdReader.
VectHitHdr.at(hit_iter).uZeroLevel;
510 std::vector<uint16_t> uWfm = PsdReader.
VectHitData.at(hit_iter).uWfm;
515 LOG(error) <<
"hit channel number out of range! channel index: " << uHitChannel
530 double dHitAmlpitude = 0;
531 double dHitChargeWfm = 0;
535 dHitChargeWfm = std::accumulate(uWfm.begin(), uWfm.end(), 0);
536 dHitChargeWfm -= uZeroLevel * uWfm.size();
537 auto const max_iter = std::max_element(uWfm.begin(), uWfm.end());
538 assert(max_iter != uWfm.end());
539 if (max_iter == uWfm.end())
break;
541 dHitAmlpitude = *max_iter - uZeroLevel;
548 for (UInt_t wfm_iter = 0; wfm_iter < uWfm.size(); wfm_iter++)
549 fvhHitWfmChan[uHitChannel]->Fill(wfm_iter, uWfm.at(wfm_iter));
551 Form(
"Waveform channel %03u charge %0u zero level %0u; Time [adc "
552 "counts]; Amplitude [adc counts]",
553 uHitChannel, uSignalCharge, uZeroLevel));
556 UInt_t uFlatIndexOfChange = i *
kuNbChanPsd + uHitChannel;
559 UInt_t uFlatIndexHisto =
563 for (UInt_t wfm_iter = 0; wfm_iter < uWfm.size(); wfm_iter++)
566 Form(
"Waveform channel %03u charge %0u zero level %0u; Time "
567 "[adc counts]; Amplitude [adc counts]",
568 uHitChannel, uSignalCharge, uZeroLevel));
580 int gate_end = uWfm.size() - 1;
593 Float_t fit_R2 = Pfitter.
GetRSquare(gate_beg, gate_end);
595 std::complex<float>* harmonics = Pfitter.
GetHarmonics();
596 std::vector<uint16_t> uFitWfm = Pfitter.
GetFitWfm();
597 for (UInt_t wfm_iter = 0; wfm_iter < uFitWfm.size(); wfm_iter++)
599 fvhHitWfmChan[uHitChannel]->SetTitle(Form(
"Waveform channel %03u charge %0u zero level %0u R2 %.5f; "
600 "Time [adc counts]; Amplitude [adc counts]",
601 uHitChannel, uSignalCharge, uZeroLevel, fit_R2));
605 if (fit_R2 > 0.02)
continue;
613 else if (ReadResult == 1) {
614 LOG(error) <<
"no event headers in message!";
617 else if (ReadResult == 2) {
618 LOG(error) <<
"check number of waveform points! In header: " << PsdReader.
HitHdr.
uWfmPoints
619 <<
" should be: " << 8;
622 else if (ReadResult == 3) {
623 LOG(error) <<
"wrong amount of hits read! In header: " << PsdReader.
EvHdrAb.
uHitsNumber
624 <<
" in hit vector: " << PsdReader.
VectHitHdr.size();
628 LOG(error) <<
"PsdGbtReader.ReadEventFles() didn't return expected values";
636 LOG(error) <<
"Wrong amount of messages read!"
640 std::ofstream error_log(Form(
"%llu_errorlog.txt",
fulCurrentMsIdx), std::ofstream::out);
641 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
642 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
643 error_log << Form(
"%016llx\n", (
long long int) ulData);
652 LOG(error) <<
"Wrong MS index!"
683 std::string sFolder =
"MoniPsd";
684 std::string sFitFolder =
"PronyFit";
685 LOG(info) <<
"create Histos for PSD monitoring ";
688 uint32_t iNbBinsLog = 0;
691 double* dBinsLog = dBinsLogVector.data();
696 "Map of hits in PSD detector electronics vs time in "
697 "run; Chan; Time in run [s]; Hits Count []",
700 "Map of hits in PSD detector vs time in run; "
701 "Chan; Time in run [s]; Hits Count []",
705 fhMissedData =
new TH1I(
"hMissedData",
"PSD Missed data", 2, 0, 2);
707 fhAdcTime =
new TH1I(
"hAdcTime",
"ADC time; Adc time []", 100, 0, 160000);
709 fhMsLengthEvo =
new TH2I(
"hMsLengthEvo",
"Evolution of MS length vs time in run; Time in run [s]; MS length [ns]",
713 "Evolution of TotalMsgs counts, per MS vs time in run; Time in "
714 "run [s]; TotalMsgs Count/MS []; MS",
717 "Evolution of ReadMsgs counts, per MS vs time in run; Time in run "
718 "[s]; ReadMsgs Count/MS []; MS",
721 "Evolution of LostMsgs counts, per MS vs time in run; Time in run "
722 "[s]; LostMsgs Count/MS []; MS",
725 "Evolution of ReadEvents counts, per MS vs time in run; Time in "
726 "run [s]; ReadEvents Count/MS []; MS",
746 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; ++uChan) {
749 Form(
"hHitZLChanEvo%03u", uChan),
750 Form(
"Hits ZeroLevel evolution for channel %03u; Time in run [s]; ZeroLevel [adc counts]", uChan),
754 Form(
"hHitLPChanEvo%03u", uChan),
755 Form(
"Hits LastPoint evolution for channel %03u; Time in run [s]; ZeroLevel [adc counts]", uChan),
759 Form(
"hHitFAChanEvo%03u", uChan),
760 Form(
"Hits FeeAccumulator evolution for channel %03u; Time in run [s]; ZeroLevel [adc counts]", uChan),
766 Form(
"Hits charge distribution for channel %03u; Charge [mV]", uChan),
770 new TH1I(Form(
"hHitZeroLevelChan%03u", uChan),
771 Form(
"Hits zero level distribution for channel %03u; ZeroLevel [adc counts]", uChan),
775 Form(
"Hits amplitude distribution for channel %03u; Amplitude [mV]", uChan),
779 new TH1I(Form(
"hHitChargeByWfmChan%03u", uChan),
780 Form(
"Hits charge by waveform distribution for channel %03u; "
795 fvhHitWfmChan[uChan] =
new TH1I(Form(
"hHitWfmChan%03u", uChan), Form(
"HitWfmChan%03u", uChan), 32, 0, 32);
799 for (UInt_t uWfmRangeIter = 0; uWfmRangeIter <
kuNbWfmRanges; uWfmRangeIter++) {
800 for (UInt_t uWfmExampleIter = 0; uWfmExampleIter <
kuNbWfmExamples; uWfmExampleIter++) {
803 new TH1I(Form(
"hHitWfmChan%03uRange%02uExample%02u", uChan, uWfmRangeIter, uWfmExampleIter),
804 Form(
"HitWfmChan%03uRange%02uExample%02u", uChan, uWfmRangeIter, uWfmExampleIter), 32, 0, 32);
813 new TH1I(Form(
"hHitFitWfmChan%03u", uChan), Form(
"HitFitWfmChan%03u", uChan), 32, 0, 32);
818 Form(
"hFitHarmonic1Chan%03u", uChan),
819 Form(
"Waveform fit harmonic 1 for channel %03u; Real part []; Imag part []", uChan), 400, -2, 2, 200, -1, 1);
823 Form(
"hFitHarmonic2Chan%03u", uChan),
824 Form(
"Waveform fit harmonic 2 for channel %03u; Real part []; Imag part []", uChan), 400, -2, 2, 200, -1, 1);
828 Form(
"hFitQaChan%03u", uChan), Form(
"Waveform fit QA for channel %03u; Integral [adc counts]; R2 []", uChan),
847 fcHitMaps =
new TCanvas(
"cHitMaps",
"Hit maps", w,
h);
867 fcSummary =
new TCanvas(
"cSummary",
"Hit maps, Hit rate, Error fraction", w,
h);
900 fcGenCntsPerMs =
new TCanvas(
"cGenCntsPerMs",
"Messages and hit cnt per MS, Error and Evt Loss Fract. per MS ", w,
h);
938 fcZLevo =
new TCanvas(
"cZLevo",
"ZeroLevel evolaution in all channels", w,
h);
941 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
953 fcChargesFPGA =
new TCanvas(
"cChargesFPGA",
"Charges spectra in all channels calculated by FPGA", w,
h);
956 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
966 fcChargesWfm =
new TCanvas(
"cChargesWfm",
"Charges spectra in all channels calculated over waveform", w,
h);
969 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
979 fcAmplitudes =
new TCanvas(
"cAmplitudes",
"Amplitude spectra in all channels", w,
h);
982 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
992 fcZeroLevels =
new TCanvas(
"cZeroLevels",
"Zero Level spectra in all channels", w,
h);
995 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1007 fcWfmsAllChannels =
new TCanvas(
"cWfmsAllChannels",
"Last waveforms in PSD fired channels", w,
h);
1010 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1024 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1026 new TCanvas(Form(
"cWfmsChan%03u", uChan), Form(
"Canvas with last waveforms in channel %03u", uChan), w,
h);
1030 for (UInt_t uWfmRangeIter = 0; uWfmRangeIter <
kuNbWfmRanges; uWfmRangeIter++) {
1031 for (UInt_t uWfmExampleIter = 0; uWfmExampleIter <
kuNbWfmExamples; uWfmExampleIter++) {
1048 fcPronyFit =
new TCanvas(
"cPronyFit",
"Prony wfm fitting", w,
h);
1052 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {
1058 for (UInt_t uChan = 0; uChan <
kuNbChanPsd; uChan++) {