17 #include "FairLogger.h"
18 #include "FairRootManager.h"
20 #include "FairRunOnline.h"
21 #include "FairRuntimeDb.h"
24 #include "TClonesArray.h"
26 #include "THttpServer.h"
55 , fvMsComponentsListSts()
56 , fvMsComponentsListTof()
59 , fbIgnoreOverlapMs(kFALSE)
60 , fUnpackParSts(nullptr)
62 , fmStsDpbIdIndexMap()
64 , fUnpackParTof(nullptr)
66 , fmTofDpbIdIndexMap()
69 , fdStsTofOffsetNs(0.0)
70 , fdMuchTofOffsetNs(0.0)
71 , fbUseBestPair(kFALSE)
72 , fbTsLevelAna(kFALSE)
73 , fsHistoFileFullname(
"data/mCBMsyncHistos.root")
74 , fbPrintMessages(kFALSE)
79 , fuCurrentEquipmentId(0)
82 , fiRunStartDateTimeSec(-1)
83 , fiBinSizeDatePlots(-1)
84 , fvulStsCurrentTsMsb()
85 , fvuStsCurrentTsMsbCycle()
86 , fvmStsSdpbHitsInMs()
87 , fvmStsSdpbHitsInTs()
88 , fulTofCurrentTsIndex(0)
95 , fvulTofCurrentEpoch()
96 , fvulTofCurrentEpochCycle()
97 , fvulTofCurrentEpochFull()
98 , fulTofCurrentEpochTime(0)
99 , fvmTofEpSupprBuffer()
100 , fvmTofGdpbHitsInMs()
101 , fvmTofGdpbHitsInTs()
102 , fhMcbmHitsNbPerMs()
103 , fhMcbmTimeDiffToDiamond()
104 , fhMcbmTimeDiffToDiamondWide()
105 , fhMcbmTimeDiffToDiamondTs()
106 , fhMcbmTimeDiffToMuch()
107 , fhMcbmTimeDiffToMuchWide()
108 , fhMcbmTimeDiffToMuchTs()
109 , fhMcbmStsTimeDiffToMuchVsAdc()
110 , fhMcbmStsTimeDiffToMuchWideVsAdc()
111 , fhMcbmStsTimeDiffToMuchTsVsAdc()
112 , fvhMcbmTimeDiffToDiamondEvoDpb()
113 , fvhMcbmTimeDiffToDiamondWideEvoDpb()
114 , fvhMcbmTimeDiffToDiamondTsEvoDpb()
117 , fdSpillStartC(-1.0)
118 , fvhHitsTimeEvoSpillA()
119 , fvhHitsTimeEvoSpillB()
120 , fvhMcbmTimeDiffToDiamondEvoSpillA()
121 , fvhMcbmTimeDiffToDiamondEvoSpillB()
122 , fvhMcbmTimeDiffToMuchEvoSpillA()
123 , fvhMcbmTimeDiffToMuchEvoSpillB() {}
128 LOG(info) <<
"Initializing flib StsXyter unpacker for STS";
130 FairRootManager* ioman = FairRootManager::Instance();
131 if (ioman ==
nullptr) { LOG(fatal) <<
"No FairRootManager instance"; }
137 LOG(info) <<
"Setting parameter containers for " << GetName();
140 "CbmMcbm2018StsPar"));
143 "CbmMcbm2018TofPar"));
148 LOG(info) <<
"Init parameter containers for " << GetName();
159 LOG(info) <<
"ReInit parameter containers for " << GetName();
168 LOG(info) <<
"Eq. ID for DPB #" << std::setw(2) << uDpb <<
" = 0x"
170 << std::dec <<
" => "
187 LOG(info) <<
"GDPB Id of TOF " <<
i <<
" : " << std::hex
204 UShort_t usDetectorId) {
205 switch (usDetectorId) {
217 LOG(warning) <<
"CbmMcbm2018MonitorStsSync::AddMsComponentToList => "
218 <<
"Ignore component " << component <<
" as detector id "
219 << usDetectorId <<
" is not supported by this unpacker.";
241 size_t uOverlapMsNb) {
250 TString sHistName {
""};
308 LOG(info) <<
"Done Creating STS Histograms";
314 TString sHistName {
""};
380 LOG(info) <<
"Done Creating TOF Histograms";
386 TString sHistName {
""};
387 TString sHistTitle {
""};
391 sHistName =
"hMcbmHitsNbPerMs";
392 sHistTitle =
"Nb of hits per DPB; Nb of hits []; DPB []";
402 sHistName =
"hMcbmTimeDiffToDiamond";
403 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
404 "Diamond hit; <tn - tDia> [ns]; DPB []";
413 sHistName =
"hMcbmTimeDiffToDiamondWide";
414 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
415 "Diamond hit, wide range; <tn - tDia> [us]; DPB []";
424 sHistName =
"hMcbmTimeDiffToDiamondTs";
425 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
426 "Diamond hit, TS range; <tn - tDia> [ms]; DPB []";
436 sHistName =
"hMcbmTimeDiffToMuch";
437 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
438 "Much hit; <tn - tMuch> [ns]; DPB []";
447 sHistName =
"hMcbmTimeDiffToMuchWide";
448 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
449 "Much hit, wide range; <tn - tMuch> [us]; DPB []";
458 sHistName =
"hMcbmTimeDiffToMuchTs";
459 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
460 "Much hit, TS range; <tn - tMuch> [ms]; DPB []";
471 sHistName =
"hMcbmStsTimeDiffToMuchVsAdc";
472 sHistTitle =
"Time difference for STS hits against any Much hit vs STS hit "
473 "ADC; <tSts - tMuch> [ns]; ADC Sts [bin]";
482 sHistName =
"hMcbmStsTimeDiffToMuchWideVsAdc";
483 sHistTitle =
"Time difference for STS hits against any Much hit vs STS hit "
484 "ADC, wide range; <tSts - tMuch> [us]; ADC Sts [bin]";
493 sHistName =
"hMcbmStsTimeDiffToMuchTsVsAdc";
494 sHistTitle =
"Time difference for STS hits against any Much hit vs STS hit "
495 "ADC, TS range; <tSts - tMuch> [ms]; ADC Sts [bin]";
507 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoDpb%02u", uDpb);
509 Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
510 "against any Diamond hit; TS []; <tn - tDia> [ns]",
522 sHistName = Form(
"hMcbmTimeDiffToDiamondWideEvoDpb%02u", uDpb);
524 Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
525 "against any Diamond hit, wide range; TS []; <tn - tDia> [us]",
528 sHistName, sHistTitle, 2000.0, 0., 200000., 4000.0, -200., 200.));
530 sHistName = Form(
"hMcbmTimeDiffToDiamondTsEvoDpb%02u", uDpb);
532 Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
533 "against any Diamond hit, TS range; TS []; <tn - tDia> [ms]",
536 new TH2D(sHistName, sHistTitle, 2000.0, 0., 200000., 200.0, -10., 10.));
539 sHistName = Form(
"hHitsTimeEvoSpillADpb%02u", uDpb);
540 sHistTitle = Form(
"Evolution of hit counts VS time for DPB %02u in the "
541 "first spill; tHit [s]; counts",
550 sHistName = Form(
"hHitsTimeEvoSpillBDpb%02u", uDpb);
551 sHistTitle = Form(
"Evolution of hit counts VS time for DPB %02u in the "
552 "second spill; tHit [s]; counts",
561 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoSpillADpb%02u", uDpb);
562 sHistTitle = Form(
"Evolution of Time Diff to diam VS time for DPB %02u "
563 "in the first spill; tHit [s]; <tn - tDia> [us]",
575 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoSpillBDpb%02u", uDpb);
576 sHistTitle = Form(
"Evolution of Time Diff to diam VS time for DPB %02u "
577 "in the second spill; tHit [s]; <tn - tDia> [us]",
589 sHistName = Form(
"hMcbmTimeDiffToMuchEvoSpillADpb%02u", uDpb);
590 sHistTitle = Form(
"Evolution of Time Diff to MUCH VS time for DPB %02u "
591 "in the first spill; tHit [s]; <tn - tDia> [us]",
603 sHistName = Form(
"hMcbmTimeDiffToMuchEvoSpillBDpb%02u", uDpb);
604 sHistTitle = Form(
"Evolution of Time Diff to MUCH VS time for DPB %02u "
605 "in the second spill; tHit [s]; <tn - tDia> [us]",
618 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
638 server->RegisterCommand(
"/Reset_All",
"bMcbm2018ResetSync=kTRUE");
639 server->RegisterCommand(
"/Save_All",
"bMcbm2018WriteSync=kTRUE");
641 server->Restrict(
"/Reset_All",
"allow=admin");
642 server->Restrict(
"/Save_All",
"allow=admin");
648 TCanvas* cSyncMcbm =
new TCanvas(
650 "Time difference for STS and TOF hits, per DPB, against any Diamond hit",
653 cSyncMcbm->Divide(2);
667 LOG(info) <<
"Done Creating mCBM Histograms";
683 LOG(debug) <<
"Timeslice contains " << ts.num_microslices(component)
697 for (UInt_t uMsIdx = 0; uMsIdx < uNbMsLoop; uMsIdx++) {
703 if (kFALSE ==
ProcessStsMs(ts, uMsComp, uMsIdx))
return kFALSE;
711 if (kFALSE ==
ProcessTofMs(ts, uMsComp, uMsIdx))
return kFALSE;
748 for (UInt_t uHitDia = 0; uHitDia < uNbDiaHits; uHitDia++) {
761 Double_t dBestDt = 1e9;
762 UInt_t uNbIncrDt = 0;
764 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
777 Double_t dDt = dHitTime - dDiaTime;
781 if (TMath::Abs(dDt) < TMath::Abs(dBestDt))
783 else if (dBestDt < dDt)
787 if (5 == dBestDt)
break;
813 Double_t dBestDt = 1e9;
814 UInt_t uNbIncrDt = 0;
816 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
824 Double_t dDt = dHitTime - dDiaTime;
828 if (TMath::Abs(dDt) < TMath::Abs(dBestDt))
830 else if (dBestDt < dDt)
834 if (5 == dBestDt)
break;
863 for (UInt_t uHitMuch = 0; uHitMuch < uNbMuchHits; uHitMuch++) {
873 Double_t dBestDt = 1e9;
875 UInt_t uNbIncrDt = 0;
877 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
885 Double_t dDt = dHitTime - dMuchTime;
889 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) {
893 else if (dBestDt < dDt)
897 if (5 == dBestDt)
break;
921 Double_t dBestDt = 1e9;
922 UInt_t uNbIncrDt = 0;
924 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
927 Double_t dDt = dHitTime - dMuchTime;
931 if (TMath::Abs(dDt) < TMath::Abs(dBestDt))
933 else if (dBestDt < dDt)
937 if (5 == dBestDt)
break;
981 LOG(fatal) <<
"Done with the spills";
991 for (UInt_t uHitDia = 0; uHitDia < uNbDiaHits; uHitDia++) {
997 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
1001 Double_t dDt = dHitTime - dDiaTime;
1004 if (300e3 < dDt)
break;
1012 Double_t dDiaTimeSec = dDiaTime * 1e-9;
1028 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
1031 Double_t dDt = dHitTime - dDiaTime;
1034 if (300e3 < dDt)
break;
1042 Double_t dDiaTimeSec = dDiaTime * 1e-9;
1046 dDiaTimeSec, dDt / 1e3);
1048 dDiaTimeSec, dDt / 1e3);
1057 for (UInt_t uHitMuch = 0; uHitMuch < uNbMuchHits; uHitMuch++) {
1070 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
1078 Double_t dDt = dHitTime - dMuchTime;
1081 if (300e3 < dDt)
break;
1088 Double_t dMuchTimeSec = dMuchTime * 1e-9;
1105 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
1108 Double_t dDt = dHitTime - dMuchTime;
1111 if (300e3 < dDt)
break;
1115 Double_t dMuchTimeSec = dMuchTime * 1e-9;
1119 dMuchTimeSec, dDt / 1e3);
1121 dMuchTimeSec, dDt / 1e3);
1138 if (0 == ts.index() % 1000) {
1139 LOG(info) <<
"End of TS " << std::setw(7) << ts.index();
1149 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
1151 const uint8_t* msContent =
1152 reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
1154 uint32_t uSize = msDescriptor.size;
1157 LOG(debug) <<
"Microslice: " <<
fulCurrentMsIdx <<
" from EqId " << std::hex
1164 UInt_t uTsMsbCycleHeader = std::floor(
1174 <<
"TS MSB cycle from MS header does not match current cycle from data "
1178 << uTsMsbCycleHeader;
1184 LOG(error) <<
"The input microslice buffer does NOT "
1185 <<
"contain only complete nDPB messages!";
1188 uint32_t uNbMessages =
1192 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>(msContent);
1194 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
1196 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
1221 LOG(info) <<
"CbmMcbm2018MonitorMcbmSync::DoUnpack => "
1222 <<
"EPOCH message at unexpected position in MS: message "
1223 << uIdx <<
" VS message 0 expected!";
1233 <<
"CbmMcbm2018MonitorMcbmSync::DoUnpack => "
1234 <<
"Unknown message type, should never happen, stopping here!";
1279 if (usRawAdc < 15)
return;
1294 if ((0 == uChanIdx % 2) && (543 < uChanIdx) && (uChanIdx < 633)) {
1301 Long64_t ulStsHitTime = usRawTs;
1331 <<
" new TsMsb " << std::setw(5) << uVal;
1337 LOG(info) <<
"TS MSb Jump in "
1340 << uMsIdx <<
" Msg Idx " << std::setw(5) << uMessIdx <<
" DPB "
1343 <<
" new TsMsb " << std::setw(5) << uVal;
1364 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
1367 const uint8_t* msContent =
1368 reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
1370 uint32_t size = msDescriptor.size;
1373 LOG(debug) <<
"Microslice: " << msDescriptor.idx <<
" has size: " << size;
1375 Int_t messageType = -111;
1379 LOG(error) <<
"The input microslice buffer does NOT "
1380 <<
"contain only complete nDPB messages!";
1383 uint32_t uNbMessages =
1391 const uint64_t* pInBuff =
reinterpret_cast<const uint64_t*
>(msContent);
1392 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
1394 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
1403 if (gLogger->IsLogNeeded(fair::Severity::debug2)) {
1412 switch (messageType) {
1434 LOG(error) <<
"Message type " << std::hex << std::setw(2)
1435 <<
static_cast<uint16_t
>(messageType)
1436 <<
" not included in Get4 unpacker.";
1458 if (0 < ulCurEpochGdpbGet4)
1459 ulCurEpochGdpbGet4--;
1494 if (0 < iBufferSize) {
1495 LOG(debug) <<
"Now processing stored messages for for gDPB " <<
fuTofGdpbNr
1496 <<
" with epoch number "
1504 for (Int_t iMsgIdx = 0; iMsgIdx < iBufferSize; iMsgIdx++) {
1531 LOG(info) <<
"-------------------------------------";
1539 TDirectory* oldDir =
nullptr;
1540 TFile* histoFile =
nullptr;
1541 if (
"" != sFileName) {
1543 oldDir = gDirectory;
1545 histoFile =
new TFile(sFileName,
"RECREATE");
1556 gDirectory->mkdir(
"mcbmDt");
1557 gDirectory->cd(
"mcbmDt");
1588 gDirectory->cd(
"..");
1591 if (
"" != sFileName) {