8 #include "CbmCosy2018MonitorPulser.h"
13 #include "CbmCern2017UnpackParHodo.h"
17 #include "FairLogger.h"
18 #include "FairRootManager.h"
20 #include "FairRunOnline.h"
21 #include "FairRuntimeDb.h"
24 #include "TClonesArray.h"
25 #include "THttpServer.h"
45 , fUnpackParHodo(NULL)
52 , fsHistoFileFullname(
"data/SetupHistos.root")
53 , fbPrintMessages(kFALSE)
58 , fuCurrentEquipmentId(0)
61 , fiRunStartDateTimeSec(-1)
62 , fiBinSizeDatePlots(-1)
64 , fvuCurrentTsMsbCycle()
66 , fvulChanLastHitTime()
67 , fvdChanLastHitTime()
70 , fvdChanLastHitTimeInMs()
71 , fvusChanLastHitAdcInMs()
75 , fdStartTimeMsSz(-1.0)
76 , ftStartTimeUnix(std::chrono::steady_clock::now())
79 , fuMaxNbMicroslices(100)
80 , fbLongHistoEnable(kFALSE)
81 , fuLongHistoNbSeconds(0)
82 , fuLongHistoBinSizeSec(0)
86 , fdCoincMin(fdCoincCenter - fdCoincBorder)
87 , fdCoincMax(fdCoincCenter + fdCoincBorder)
89 , fhPulserMessType(NULL)
90 , fhPulserSysMessType(NULL)
91 , fhPulserMessTypePerDpb(NULL)
92 , fhPulserSysMessTypePerDpb(NULL)
93 , fhPulserMessTypePerElink(NULL)
94 , fhPulserSysMessTypePerElink(NULL)
95 , fhPulserChanCntRaw()
96 , fhPulserChanCntRawGood()
97 , fhPulserChanAdcRaw()
98 , fhPulserChanAdcRawProf()
100 , fhPulserChanMissEvt()
101 , fhPulserChanMissEvtEvo()
102 , fhPulserChanHitRateEvo()
103 , fhPulserFebRateEvo()
104 , fhPulserFebMissEvtEvo()
105 , fhPulserChanHitRateEvoLong()
106 , fhPulserFebRateEvoLong()
110 , fhPulserTimeDiffPerAsic()
111 , fhPulserTimeDiffPerAsicPair()
112 , fhPulserTimeDiffEvoPerAsicPair()
113 , fhPulserTsLsbMatchPerAsicPair()
114 , fhPulserTsMsbMatchPerAsicPair()
115 , fhPulserIntervalAsic()
116 , fhPulserIntervalLongAsic() {}
121 LOG(info) <<
"Initializing flib StsXyter unpacker for STS";
123 FairRootManager* ioman = FairRootManager::Instance();
124 if (ioman == NULL) { LOG(fatal) <<
"No FairRootManager instance"; }
130 LOG(info) <<
"Setting parameter containers for " << GetName();
132 (CbmCern2017UnpackParHodo*) (FairRun::Instance()
134 ->getContainer(
"CbmCern2017UnpackParHodo"));
139 LOG(info) <<
"Init parameter containers for " << GetName();
148 LOG(info) <<
"ReInit parameter containers for " << GetName();
156 LOG(info) <<
"Nr. of STS DPBs: " <<
fuNrOfDpbs;
160 for (UInt_t uDpb = 0; uDpb <
fuNrOfDpbs; ++uDpb) {
162 LOG(info) <<
"Eq. ID for DPB #" << std::setw(2) << uDpb <<
" = "
164 << std::dec <<
" => "
177 for (UInt_t uDpb = 0; uDpb <
fuNrOfDpbs; ++uDpb) {
178 LOG(info) <<
"ASIC ID for eLinks in DPB #" << std::setw(2) << uDpb <<
": ";
180 std::stringstream ss;
182 if (0 == uElink % 10) ss <<
"\n------> ";
186 LOG(info) << ss.str();
193 for (UInt_t uDpb = 0; uDpb <
fuNrOfDpbs; ++uDpb) {
217 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters; ++uXyterIdx) {
242 LOG(info) <<
"CbmCosy2018MonitorPulser::ReInitContainers => Changed "
243 "fvuChanNbHitsInMs size "
245 LOG(info) <<
"CbmCosy2018MonitorPulser::ReInitContainers => Changed "
246 "fvuChanNbHitsInMs size "
248 LOG(info) <<
"CbmCosy2018MonitorPulser::ReInitContainers => Changed "
249 "fvuChanNbHitsInMs size "
256 Double_t dBorderVal) {
264 TString sHistName {
""};
267 sHistName =
"hPulserMessageType";
268 title =
"Nb of message for each type; Type";
283 sHistName =
"hPulserSysMessType";
284 title =
"Nb of system message for each type; System Type";
292 sHistName =
"hPulserMessageTypePerDpb";
293 title =
"Nb of message of each type for each DPB; DPB; Type";
309 sHistName =
"hPulserSysMessTypePerDpb";
310 title =
"Nb of system message of each type for each DPB; DPB; System Type";
319 sHistName =
"hPulserMessageTypePerElink";
320 title =
"Nb of message of each type for each eLink; eLink; Type";
342 sHistName =
"hPulserSysMessTypePerElink";
344 "Nb of system message of each type for each eLink; eLink; System Type";
363 const Int_t iNbDecadesRate = 9;
364 const Int_t iNbStepsDecade = 9;
365 const Int_t iNbSubStepsInStep = 10;
366 const Int_t iNbBinsRate =
367 iNbStepsDecade + iNbStepsDecade * iNbSubStepsInStep * iNbDecadesRate + 1;
368 Double_t dBinsRate[iNbBinsRate];
370 for (Int_t iSubU = 0; iSubU < iNbStepsDecade; iSubU++)
371 dBinsRate[iSubU] = 0.1 * (1 + iSubU);
372 std::cout << std::endl;
374 Double_t dSubstepSize = 1.0 / iNbSubStepsInStep;
375 for (Int_t iDecade = 0; iDecade < iNbDecadesRate; iDecade++) {
376 Double_t dBase = std::pow(10, iDecade);
378 iNbStepsDecade + iDecade * iNbStepsDecade * iNbSubStepsInStep;
379 for (Int_t iStep = 0; iStep < iNbStepsDecade; iStep++) {
380 Int_t iStepIdx = iDecadeIdx + iStep * iNbSubStepsInStep;
381 for (Int_t iSubStep = 0; iSubStep < iNbSubStepsInStep; iSubStep++) {
382 dBinsRate[iStepIdx + iSubStep] =
383 dBase * (1 + iStep) + dBase * dSubstepSize * iSubStep;
387 dBinsRate[iNbBinsRate - 1] = std::pow(10, iNbDecadesRate);
390 UInt_t uAlignedLimit =
394 UInt_t uNbBinEvo = (32768 + 1) * 2;
395 Double_t dMaxEdgeEvo =
397 Double_t dMinEdgeEvo = dMaxEdgeEvo * -1.0;
402 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters; ++uXyterIdx) {
404 sHistName = Form(
"hPulserChanCntRaw_%03u", uXyterIdx);
405 title = Form(
"Hits Count per channel, StsXyter #%03u; Channel; Hits []",
410 sHistName = Form(
"hPulserChanCntRawGood_%03u", uXyterIdx);
412 "Hits Count per channel in good MS, StsXyter #%03u; Channel; Hits []",
418 sHistName = Form(
"hPulserChanAdcRaw_%03u", uXyterIdx);
419 title = Form(
"Raw Adc distribution per channel, StsXyter #%03u; Channel "
420 "[]; Adc []; Hits []",
432 sHistName = Form(
"hPulserChanAdcRawProfc_%03u", uXyterIdx);
434 Form(
"Raw Adc prodile per channel, StsXyter #%03u; Channel []; Adc []",
440 sHistName = Form(
"hPulserChanRawTs_%03u", uXyterIdx);
441 title = Form(
"Raw Timestamp distribution per channel, StsXyter #%03u; "
442 "Channel []; Ts []; Hits []",
454 sHistName = Form(
"hPulserChanMissEvt_%03u", uXyterIdx);
455 title = Form(
"Missed Event flags per channel, StsXyter #%03u; Channel []; "
456 "Miss Evt []; Hits []",
469 sHistName = Form(
"hPulserChanMissEvtEvo_%03u", uXyterIdx);
470 title = Form(
"Missed Evt flags per second & channel in StsXyter #%03u; "
471 "Time [s]; Channel []; Missed Evt flags []",
484 sHistName = Form(
"hPulserFebMissEvtEvo%03u", uXyterIdx);
485 title = Form(
"Missed Evt flags per second in StsXyter #%03u; Time [s]; "
486 "Missed Evt flags []",
491 sHistName = Form(
"hPulserChanRateEvo_%03u", uXyterIdx);
492 title = Form(
"Hits per second & channel in StsXyter #%03u; Time [s]; "
493 "Channel []; Hits []",
505 sHistName = Form(
"hPulserFebRateEvo_%03u", uXyterIdx);
507 Form(
"Hits per second in StsXyter #%03u; Time [s]; Hits []", uXyterIdx);
511 sHistName = Form(
"hPulserChanRateEvoLong_%03u", uXyterIdx);
512 title = Form(
"Hits per second & channel in StsXyter #%03u; Time [min]; "
513 "Channel []; Hits []",
525 sHistName = Form(
"hPulserFebRateEvoLong_%03u", uXyterIdx);
527 Form(
"Hits per second in StsXyter #%03u; Time [min]; Hits []", uXyterIdx);
532 sHistName = Form(
"fhPulserTimeDiffPerAsic_%03u", uXyterIdx);
533 title = Form(
"Time diff for pulser hits between ASIC %03u and other ASICs; "
534 "tn - t%03u [ns]; ASIC n; Counts",
546 for (UInt_t uXyterIdxB = 0; uXyterIdxB <
fuNbStsXyters; ++uXyterIdxB) {
547 if (uXyterIdxB == uXyterIdx) {
548 sHistName = Form(
"fhPulserTimeDiffSameAsic_%03u", uXyterIdx);
550 "Time diff for consecutive hits in ASIC %03u; tn - t [ns]; Counts",
555 Form(
"fhPulserTimeDiffPerAsicPair_%03u_%03u", uXyterIdx, uXyterIdxB);
556 title = Form(
"Time diff for pulser hits in ASIC %03u and %03u; tn - t "
562 new TH1I(sHistName, title, uNbBinEvo, dMinEdgeEvo, dMaxEdgeEvo));
564 if (uXyterIdxB == uXyterIdx) {
565 sHistName = Form(
"fhPulserTimeDiffEvoSameAsic_%03u", uXyterIdx);
566 title = Form(
"Time diff for consecutive hits in ASIC %03u; Time in run "
567 "[s]; tn - t [ns]; Counts",
572 "fhPulserTimeDiffEvoPerAsicPair_%03u_%03u", uXyterIdx, uXyterIdxB);
573 title = Form(
"Time diff for pulser hits in ASIC %03u and %03u; Time in "
574 "run [s]; tn - t [ns]; Counts",
589 Form(
"fhPulserTsLsbMatchPerAsicPair_%03u_%03u", uXyterIdx, uXyterIdxB);
590 title = Form(
"TS LSB for pulser hits in ASIC %03u and %03u; TS LSB %03u "
591 "[bin]; TS LSB %03u [bin]",
597 new TH2I(sHistName, title, 256, -0.5, 255.5, 256, -0.5, 255.5));
600 Form(
"fhPulserTsMsbMatchPerAsicPair_%03u_%03u", uXyterIdx, uXyterIdxB);
601 title = Form(
"TS MSB for pulser hits in ASIC %03u and %03u; TS MSB %03u "
602 "[bin]; TS MSB %03u [bin]",
608 new TH2I(sHistName, title, 64, -0.5, 63.5, 64, -0.5, 63.5));
611 sHistName = Form(
"fhPulserIntervalAsic_%03u", uXyterIdx);
613 Form(
"Time diff between consecutive hits in ASIC %03us; dt [ns]; Counts",
619 sHistName = Form(
"fhPulserIntervalLongAsic_%03u", uXyterIdx);
621 Form(
"Time diff between consecutive hits in ASIC %03us; dt [ns]; Counts",
648 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
656 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters; ++uXyterIdx) {
671 for (UInt_t uXyterIdxB = 0; uXyterIdxB <
fuNbStsXyters; ++uXyterIdxB) {
672 if (uXyterIdxB == uXyterIdx) {
673 server->Register(
"/DtChan",
679 server->Register(
"/DtAsicPair",
685 server->Register(
"/TsMatch",
687 server->Register(
"/TsMatch",
695 server->RegisterCommand(
"/Reset_All_Pulser",
"bCosy2018ResetPulser=kTRUE");
696 server->RegisterCommand(
"/Write_All_Pulser",
"bCosy2018WritePulser=kTRUE");
698 server->Restrict(
"/Reset_All_Pulser",
"allow=admin");
699 server->Restrict(
"/Write_All_Pulser",
"allow=admin");
707 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters; ++uXyterIdx) {
709 new TCanvas(Form(
"cStsSum_%03u", uXyterIdx),
710 Form(
"Summary plots for StsXyter %03u", uXyterIdx),
713 cStsSumm->Divide(2, 2);
735 TCanvas* cDtPerAsic =
736 new TCanvas(
"cDtPerAsic",
"Time Differences per ASIC", w,
h);
739 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters; ++uXyterIdx) {
740 cDtPerAsic->cd(1 + uXyterIdx);
750 new TCanvas(
"cDtInAsic",
"Time Differences in ASIC", w,
h);
753 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters; ++uXyterIdx) {
754 cDtInAsic->cd(1 + uXyterIdx);
762 TCanvas* cDtAsicPairs =
763 new TCanvas(
"cDtAsicPairs",
"Time Differences in ASIC", w,
h);
765 cDtAsicPairs->Divide(3);
767 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters && uXyterIdx < 3;
769 for (UInt_t uXyterIdxB = uXyterIdx + 1; uXyterIdxB <
fuNbStsXyters;
771 cDtAsicPairs->cd(uXyterIdx + uXyterIdxB);
780 TCanvas* cTsLsbAsicPairs =
781 new TCanvas(
"cTsLsbAsicPairs",
"Time Differences in ASIC", w,
h);
783 cTsLsbAsicPairs->Divide(3);
785 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters && uXyterIdx < 3;
787 for (UInt_t uXyterIdxB = uXyterIdx + 1; uXyterIdxB <
fuNbStsXyters;
789 cTsLsbAsicPairs->cd(uXyterIdx + uXyterIdxB);
799 TCanvas* cTsMsbAsicPairs =
800 new TCanvas(
"cTsMsbAsicPairs",
"Time Differences in ASIC", w,
h);
802 cTsMsbAsicPairs->Divide(3);
804 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters && uXyterIdx < 3;
806 for (UInt_t uXyterIdxB = uXyterIdx + 1; uXyterIdxB <
fuNbStsXyters;
808 cTsMsbAsicPairs->cd(uXyterIdx + uXyterIdxB);
821 fcMsSizeAll =
dynamic_cast<TCanvas*
>(gROOT->FindObject(
"cMsSizeAll"));
824 new TCanvas(
"cMsSizeAll",
"Evolution of MS size in last 300 s", w,
h);
826 LOG(info) <<
"Created MS size canvas in STS monitor";
829 LOG(info) <<
"Recovered MS size canvas in STS monitor";
837 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
848 LOG(debug) <<
"Timeslice contains " << ts.num_microslices(component)
852 if (NULL ==
fhMsSz[component]) {
853 TString sMsSzName = Form(
"MsSz_link_%02lu", component);
855 Form(
"Size of MS for nDPB of link %02lu; Ms Size [bytes]", component);
857 new TH1F(sMsSzName.Data(), sMsSzTitle.Data(), 160000, 0., 20000.);
859 if (server) server->Register(
"/FlibRaw",
fhMsSz[component]);
860 sMsSzName = Form(
"MsSzTime_link_%02lu", component);
862 "Size of MS vs time for gDPB of link %02lu; Time[s] ; Ms Size [bytes]",
865 new TProfile(sMsSzName.Data(), sMsSzTitle.Data(), 15000, 0., 300.);
867 if (server) server->Register(
"/FlibRaw",
fhMsSzTime[component]);
873 LOG(info) <<
"Added MS size histo for component: " << component
879 size_t numCompMsInTs = ts.num_microslices(component);
894 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters; ++uXyterIdx) {
910 <<
"CbmCosy2018MonitorPulser::DoUnpack => Changed fvuChanNbHitsInMs size "
912 LOG(info) <<
"CbmCosy2018MonitorPulser::DoUnpack => Changed "
913 "fvuChanNbHitsInMs size "
915 LOG(info) <<
"CbmCosy2018MonitorPulser::DoUnpack => Changed "
916 "fvuChanNbHitsInMs size "
920 for (
size_t m = 0;
m < numCompMsInTs; ++
m) {
924 auto msDescriptor = ts.descriptor(component,
m);
926 const uint8_t* msContent =
927 reinterpret_cast<const uint8_t*
>(ts.content(component,
m));
929 uint32_t size = msDescriptor.size;
932 LOG(debug) <<
"Microslice: " <<
fulCurrentMsIdx <<
" from EqId " << std::hex
940 fhMsSz[component]->Fill(size);
949 LOG(error) <<
"The input microslice buffer does NOT "
950 <<
"contain only complete nDPB messages!";
953 uint32_t uNbMessages =
957 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>(msContent);
959 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
961 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
972 static_cast<uint16_t
>(typeMess));
979 LOG(fatal) <<
"CbmCosy2018MonitorPulser::DoUnpack => "
980 <<
"eLink index out of bounds!" << usElinkIdx <<
" VS "
985 static_cast<uint16_t
>(typeMess));
1001 LOG(info) <<
"CbmCosy2018MonitorPulser::DoUnpack => "
1002 <<
"EPOCH message at unexpected position in MS: message "
1003 << uIdx <<
" VS message 0 expected!";
1015 <<
"CbmCosy2018MonitorPulser::DoUnpack => "
1016 <<
"Unknown message type, should never happen, stopping here!";
1032 ULong64_t ulLastHitTime = (*(
fvmHitsInTs.rbegin())).GetTs();
1033 std::vector<stsxyter::FinalHit>::iterator it;
1034 std::vector<stsxyter::FinalHit>::iterator itB;
1036 std::chrono::steady_clock::time_point tNow =
1037 std::chrono::steady_clock::now();
1038 Double_t dUnixTimeInRun =
1039 std::chrono::duration_cast<std::chrono::seconds>(tNow -
ftStartTimeUnix)
1046 UShort_t usAsicIdx = (*it).GetAsic();
1047 UShort_t usChanIdx = (*it).GetChan();
1048 ULong64_t ulHitTs = (*it).GetTs();
1049 UShort_t usHitAdc = (*it).GetAdc();
1051 Double_t dTimeSinceStartSec =
1064 UShort_t usChanIdx = (*it).GetChan();
1067 Double_t dTimeSinceStartSec =
1070 for (UInt_t uAsicB = uAsic; uAsicB <
fuNbStsXyters; uAsicB++) {
1074 UShort_t usChanIdxB = (*itB).GetChan();
1075 Double_t dDt = (
static_cast<Double_t
>((*itB).GetTs())
1076 -
static_cast<Double_t
>((*it).GetTs()))
1082 dTimeSinceStartSec, dDt);
1085 (*it).GetTs() & 0x000FF, (*itB).GetTs() & 0x000FF);
1087 ((*it).GetTs() & 0x03F00) >> 8,
1088 ((*itB).GetTs() & 0x03F00) >> 8);
1093 (
static_cast<Double_t
>((*it).GetTs())
1112 for (UInt_t uDpb = 0; uDpb <
fuNrOfDpbs; ++uDpb) {
1113 Double_t dTsMsbTime =
1120 LOG(info) <<
"End of TS " << std::setw(7) << ts.index() <<
" eDPB "
1121 << std::setw(2) << uDpb <<
" current TS MSB counter is "
1123 <<
" current TS MSB cycle counter is " << std::setw(12)
1125 << std::setw(12) << dTsMsbTime <<
" s";
1133 const UShort_t& usElinkIdx,
1134 const UInt_t& uAsicIdx,
1135 const UInt_t& uMsIdx) {
1164 Double_t dHitTimeNs =
1216 Double_t dTimeSinceStartSec =
1218 Double_t dTimeSinceStartMin = dTimeSinceStartSec / 60.0;
1222 dTimeSinceStartMin, usChan, 1.0 / 60.0);
1276 << std::setw(5) << uVal;
1291 ULong64_t ulNewTsMsbTime =
1314 LOG(info) <<
"-------------------------------------";
1315 LOG(info) <<
"CbmCosy2018MonitorPulser statistics are ";
1324 <<
" Empty messages: "
1327 LOG(info) <<
"-------------------------------------";
1335 TDirectory* oldDir = NULL;
1336 TFile* histoFile = NULL;
1337 if (
"" != sFileName) {
1339 oldDir = gDirectory;
1341 histoFile =
new TFile(sFileName,
"RECREATE");
1346 gDirectory->mkdir(
"Sts_Raw");
1347 gDirectory->cd(
"Sts_Raw");
1356 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters; ++uXyterIdx) {
1377 gDirectory->cd(
"..");
1382 gDirectory->mkdir(
"Flib_Raw");
1383 gDirectory->cd(
"Flib_Raw");
1385 TString sMsSzName = Form(
"MsSz_link_%02u", uLinks);
1386 if (
fHM->
Exists(sMsSzName.Data()))
fHM->
H1(sMsSzName.Data())->Write();
1388 sMsSzName = Form(
"MsSzTime_link_%02u", uLinks);
1389 if (
fHM->
Exists(sMsSzName.Data()))
fHM->
P1(sMsSzName.Data())->Write();
1392 TH1* pMissedTsH1 =
dynamic_cast<TH1*
>(gROOT->FindObjectAny(
"Missed_TS"));
1393 if (NULL != pMissedTsH1) pMissedTsH1->Write();
1395 TProfile* pMissedTsEvoP =
1396 dynamic_cast<TProfile*
>(gROOT->FindObjectAny(
"Missed_TS_Evo"));
1397 if (NULL != pMissedTsEvoP) pMissedTsEvoP->Write();
1399 gDirectory->cd(
"..");
1402 if (
"" != sFileName) {
1409 LOG(info) <<
"Reseting all STS histograms.";
1418 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters; ++uXyterIdx) {
1440 for (UInt_t uXyterIdxB = 0; uXyterIdxB <
fuNbStsXyters; ++uXyterIdxB) {
1451 TString sMsSzName = Form(
"MsSz_link_%02u", uLinks);
1452 if (
fHM->
Exists(sMsSzName.Data()))
fHM->
H1(sMsSzName.Data())->Reset();
1454 sMsSzName = Form(
"MsSzTime_link_%02u", uLinks);
1455 if (
fHM->
Exists(sMsSzName.Data()))
fHM->
P1(sMsSzName.Data())->Reset();
1465 TDatime* fRunStartDateTime =
new TDatime(dateIn, timeIn);
1469 LOG(info) <<
"Assigned new MUCH Run Start Date-Time: "
1470 << fRunStartDateTime->AsString();