21#include "FairRootManager.h"
23#include "FairRunOnline.h"
24#include "FairRuntimeDb.h"
28#include "TClonesArray.h"
30#include "THttpServer.h"
60 , fvMsComponentsListSts()
61 , fvMsComponentsListTof()
64 , fbIgnoreOverlapMs(kFALSE)
65 , fUnpackParSts(nullptr)
67 , fmStsDpbIdIndexMap()
69 , fUnpackParTof(nullptr)
71 , fmTofDpbIdIndexMap()
74 , fdStsTofOffsetNs(0.0)
75 , fdMuchTofOffsetNs(0.0)
76 , fbUseBestPair(kFALSE)
77 , fbTsLevelAna(kFALSE)
78 , fsHistoFileFullname(
"data/mCBMsyncHistos.root")
79 , fbPrintMessages(kFALSE)
80 , fPrintMessCtrlSts(
stsxyter::MessagePrintMask::msg_print_Human)
84 , fuCurrentEquipmentId(0)
87 , fiRunStartDateTimeSec(-1)
88 , fiBinSizeDatePlots(-1)
89 , fvulStsCurrentTsMsb()
90 , fvuStsCurrentTsMsbCycle()
91 , fvmStsSdpbHitsInMs()
92 , fvmStsSdpbHitsInTs()
93 , fulTofCurrentTsIndex(0)
99 , fviTofMsgCounter(1 +
gdpbv100::MSG_STAR_TRI_D, 0)
100 , fvulTofCurrentEpoch()
101 , fvulTofCurrentEpochCycle()
102 , fvulTofCurrentEpochFull()
103 , fulTofCurrentEpochTime(0)
104 , fvmTofEpSupprBuffer()
105 , fvmTofGdpbHitsInMs()
106 , fvmTofGdpbHitsInTs()
107 , fhMcbmHitsNbPerMs()
108 , fhMcbmTimeDiffToDiamond()
109 , fhMcbmTimeDiffToDiamondWide()
110 , fhMcbmTimeDiffToDiamondTs()
111 , fhMcbmTimeDiffToMuch()
112 , fhMcbmTimeDiffToMuchWide()
113 , fhMcbmTimeDiffToMuchTs()
114 , fhMcbmStsTimeDiffToMuchVsAdc()
115 , fhMcbmStsTimeDiffToMuchWideVsAdc()
116 , fhMcbmStsTimeDiffToMuchTsVsAdc()
117 , fvhMcbmTimeDiffToDiamondEvoDpb()
118 , fvhMcbmTimeDiffToDiamondWideEvoDpb()
119 , fvhMcbmTimeDiffToDiamondTsEvoDpb()
122 , fdSpillStartC(-1.0)
123 , fvhHitsTimeEvoSpillA()
124 , fvhHitsTimeEvoSpillB()
125 , fvhMcbmTimeDiffToDiamondEvoSpillA()
126 , fvhMcbmTimeDiffToDiamondEvoSpillB()
127 , fvhMcbmTimeDiffToMuchEvoSpillA()
128 , fvhMcbmTimeDiffToMuchEvoSpillB()
136 LOG(info) <<
"Initializing flib StsXyter unpacker for STS";
138 FairRootManager* ioman = FairRootManager::Instance();
139 if (ioman ==
nullptr) { LOG(fatal) <<
"No FairRootManager instance"; }
146 LOG(info) <<
"Setting parameter containers for " << GetName();
154 LOG(info) <<
"Init parameter containers for " << GetName();
166 LOG(info) <<
"ReInit parameter containers for " << GetName();
175 LOG(info) <<
"Eq. ID for DPB #" << std::setw(2) << uDpb <<
" = 0x" << std::setw(4) << std::hex
210 switch (usDetectorId) {
222 LOG(warning) <<
"CbmMcbm2018MonitorStsSync::AddMsComponentToList => "
223 <<
"Ignore component " << component <<
" as detector id " << usDetectorId
224 <<
" is not supported by this unpacker.";
258 TString sHistName {
""};
316 LOG(info) <<
"Done Creating STS Histograms";
323 TString sHistName {
""};
389 LOG(info) <<
"Done Creating TOF Histograms";
396 TString sHistName {
""};
397 TString sHistTitle {
""};
401 sHistName =
"hMcbmHitsNbPerMs";
402 sHistTitle =
"Nb of hits per DPB; Nb of hits []; DPB []";
405 sHistName =
"hMcbmTimeDiffToDiamond";
406 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
407 "Diamond hit; <tn - tDia> [ns]; DPB []";
410 sHistName =
"hMcbmTimeDiffToDiamondWide";
411 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
412 "Diamond hit, wide range; <tn - tDia> [us]; DPB []";
415 sHistName =
"hMcbmTimeDiffToDiamondTs";
416 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
417 "Diamond hit, TS range; <tn - tDia> [ms]; DPB []";
420 sHistName =
"hMcbmTimeDiffToMuch";
421 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
422 "Much hit; <tn - tMuch> [ns]; DPB []";
425 sHistName =
"hMcbmTimeDiffToMuchWide";
426 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
427 "Much hit, wide range; <tn - tMuch> [us]; DPB []";
429 sHistName =
"hMcbmTimeDiffToMuchTs";
430 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
431 "Much hit, TS range; <tn - tMuch> [ms]; DPB []";
435 sHistName =
"hMcbmStsTimeDiffToMuchVsAdc";
436 sHistTitle =
"Time difference for STS hits against any Much hit vs STS hit "
437 "ADC; <tSts - tMuch> [ns]; ADC Sts [bin]";
441 sHistName =
"hMcbmStsTimeDiffToMuchWideVsAdc";
442 sHistTitle =
"Time difference for STS hits against any Much hit vs STS hit "
443 "ADC, wide range; <tSts - tMuch> [us]; ADC Sts [bin]";
446 sHistName =
"hMcbmStsTimeDiffToMuchTsVsAdc";
447 sHistTitle =
"Time difference for STS hits against any Much hit vs STS hit "
448 "ADC, TS range; <tSts - tMuch> [ms]; ADC Sts [bin]";
454 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoDpb%02u", uDpb);
455 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
456 "against any Diamond hit; TS []; <tn - tDia> [ns]",
462 sHistName = Form(
"hMcbmTimeDiffToDiamondWideEvoDpb%02u", uDpb);
463 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
464 "against any Diamond hit, wide range; TS []; <tn - tDia> [us]",
467 new TH2D(sHistName, sHistTitle, 2000.0, 0., 200000., 4000.0, -200., 200.));
469 sHistName = Form(
"hMcbmTimeDiffToDiamondTsEvoDpb%02u", uDpb);
470 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
471 "against any Diamond hit, TS range; TS []; <tn - tDia> [ms]",
476 sHistName = Form(
"hHitsTimeEvoSpillADpb%02u", uDpb);
477 sHistTitle = Form(
"Evolution of hit counts VS time for DPB %02u in the "
478 "first spill; tHit [s]; counts",
483 sHistName = Form(
"hHitsTimeEvoSpillBDpb%02u", uDpb);
484 sHistTitle = Form(
"Evolution of hit counts VS time for DPB %02u in the "
485 "second spill; tHit [s]; counts",
490 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoSpillADpb%02u", uDpb);
491 sHistTitle = Form(
"Evolution of Time Diff to diam VS time for DPB %02u "
492 "in the first spill; tHit [s]; <tn - tDia> [us]",
497 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoSpillBDpb%02u", uDpb);
498 sHistTitle = Form(
"Evolution of Time Diff to diam VS time for DPB %02u "
499 "in the second spill; tHit [s]; <tn - tDia> [us]",
504 sHistName = Form(
"hMcbmTimeDiffToMuchEvoSpillADpb%02u", uDpb);
505 sHistTitle = Form(
"Evolution of Time Diff to MUCH VS time for DPB %02u "
506 "in the first spill; tHit [s]; <tn - tDia> [us]",
511 sHistName = Form(
"hMcbmTimeDiffToMuchEvoSpillBDpb%02u", uDpb);
512 sHistTitle = Form(
"Evolution of Time Diff to MUCH VS time for DPB %02u "
513 "in the second spill; tHit [s]; <tn - tDia> [us]",
519 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
539 server->RegisterCommand(
"/Reset_All",
"bMcbm2018ResetSync=kTRUE");
540 server->RegisterCommand(
"/Save_All",
"bMcbm2018WriteSync=kTRUE");
542 server->Restrict(
"/Reset_All",
"allow=admin");
543 server->Restrict(
"/Save_All",
"allow=admin");
550 new TCanvas(
"cSyncMcbm",
"Time difference for STS and TOF hits, per DPB, against any Diamond hit", w,
h);
551 cSyncMcbm->Divide(2);
565 LOG(info) <<
"Done Creating mCBM Histograms";
581 LOG(debug) <<
"Timeslice contains " << ts.num_microslices(component) <<
"microslices.";
594 for (UInt_t uMsIdx = 0; uMsIdx < uNbMsLoop; uMsIdx++) {
599 if (kFALSE ==
ProcessStsMs(ts, uMsComp, uMsIdx))
return kFALSE;
606 if (kFALSE ==
ProcessTofMs(ts, uMsComp, uMsIdx))
return kFALSE;
640 for (UInt_t uHitDia = 0; uHitDia < uNbDiaHits; uHitDia++) {
650 Double_t dBestDt = 1e9;
651 UInt_t uNbIncrDt = 0;
653 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
664 Double_t dDt = dHitTime - dDiaTime;
668 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
669 else if (dBestDt < dDt)
673 if (5 == dBestDt)
break;
697 Double_t dBestDt = 1e9;
698 UInt_t uNbIncrDt = 0;
700 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
708 Double_t dDt = dHitTime - dDiaTime;
712 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
713 else if (dBestDt < dDt)
717 if (5 == dBestDt)
break;
740 for (UInt_t uHitMuch = 0; uHitMuch < uNbMuchHits; uHitMuch++) {
748 Double_t dBestDt = 1e9;
750 UInt_t uNbIncrDt = 0;
752 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
758 Double_t dDt = dHitTime - dMuchTime;
762 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) {
766 else if (dBestDt < dDt)
770 if (5 == dBestDt)
break;
792 Double_t dBestDt = 1e9;
793 UInt_t uNbIncrDt = 0;
795 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
798 Double_t dDt = dHitTime - dMuchTime;
802 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
803 else if (dBestDt < dDt)
807 if (5 == dBestDt)
break;
847 LOG(fatal) <<
"Done with the spills";
857 for (UInt_t uHitDia = 0; uHitDia < uNbDiaHits; uHitDia++) {
862 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
865 Double_t dDt = dHitTime - dDiaTime;
868 if (300e3 < dDt)
break;
875 Double_t dDiaTimeSec = dDiaTime * 1e-9;
888 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
891 Double_t dDt = dHitTime - dDiaTime;
894 if (300e3 < dDt)
break;
901 Double_t dDiaTimeSec = dDiaTime * 1e-9;
913 for (UInt_t uHitMuch = 0; uHitMuch < uNbMuchHits; uHitMuch++) {
925 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
931 Double_t dDt = dHitTime - dMuchTime;
934 if (300e3 < dDt)
break;
940 Double_t dMuchTimeSec = dMuchTime * 1e-9;
954 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
957 Double_t dDt = dHitTime - dMuchTime;
960 if (300e3 < dDt)
break;
964 Double_t dMuchTimeSec = dMuchTime * 1e-9;
984 if (0 == ts.index() % 1000) {
985 LOG(info) <<
"End of TS " << std::setw(7) << ts.index();
994 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
996 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
998 uint32_t uSize = msDescriptor.size;
1002 <<
" has size: " << uSize;
1015 LOG(warning) <<
"TS MSB cycle from MS header does not match current cycle from data "
1018 << uTsMsbCycleHeader;
1024 LOG(error) <<
"The input microslice buffer does NOT "
1025 <<
"contain only complete nDPB messages!";
1031 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>(msContent);
1033 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
1035 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
1060 LOG(info) <<
"CbmMcbm2018MonitorMcbmSync::DoUnpack => "
1061 <<
"EPOCH message at unexpected position in MS: message " << uIdx <<
" VS message 0 expected!";
1070 LOG(fatal) <<
"CbmMcbm2018MonitorMcbmSync::DoUnpack => "
1071 <<
"Unknown message type, should never happen, stopping here!";
1086 UInt_t uAsicIdx = 0;
1115 if (usRawAdc < 15)
return;
1130 if ((0 == uChanIdx % 2) && (543 < uChanIdx) && (uChanIdx < 633)) {
return; }
1135 Long64_t ulStsHitTime = usRawTs;
1166 LOG(info) <<
"TS MSb Jump in "
1168 << std::setw(4) << uMsIdx <<
" Msg Idx " << std::setw(5) << uMessIdx <<
" DPB " << std::setw(2)
1170 << std::setw(5) << uVal;
1191 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
1194 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
1196 uint32_t
size = msDescriptor.size;
1198 if (
size > 0) LOG(debug) <<
"Microslice: " << msDescriptor.idx <<
" has size: " <<
size;
1200 Int_t messageType = -111;
1204 LOG(error) <<
"The input microslice buffer does NOT "
1205 <<
"contain only complete nDPB messages!";
1215 const uint64_t* pInBuff =
reinterpret_cast<const uint64_t*
>(msContent);
1216 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
1218 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
1227 if (fair::Logger::Logging(fair::Severity::debug2)) {
1236 switch (messageType) {
1256 LOG(error) <<
"Message type " << std::hex << std::setw(2) << static_cast<uint16_t>(messageType)
1257 <<
" not included in Get4 unpacker.";
1281 if (0 < ulCurEpochGdpbGet4) ulCurEpochGdpbGet4--;
1314 if (0 < iBufferSize) {
1315 LOG(debug) <<
"Now processing stored messages for for gDPB " <<
fuTofGdpbNr <<
" with epoch number "
1322 for (Int_t iMsgIdx = 0; iMsgIdx < iBufferSize; iMsgIdx++) {
1350 LOG(info) <<
"-------------------------------------";
1360 TFile* oldFile = gFile;
1361 TDirectory* oldDir = gDirectory;
1363 TFile* histoFile =
nullptr;
1364 if (
"" != sFileName) {
1366 histoFile =
new TFile(sFileName,
"RECREATE");
1377 gDirectory->mkdir(
"mcbmDt");
1378 gDirectory->cd(
"mcbmDt");
1409 gDirectory->cd(
"..");
1412 if (
"" != sFileName) {
1419 gDirectory = oldDir;
ClassImp(CbmConverterManager)
Bool_t bMcbm2018WriteSync
Bool_t bMcbm2018ResetSync
static constexpr size_t size()
void SaveAllHistos(TString sFileName="")
void CreateStsHistograms()
All hits (time in bins, ADC in bins, asic, channel) in last TS, sorted with "<" operator.
TH2 * fhMcbmStsTimeDiffToMuchVsAdc
UInt_t fuCurrDpbIdx
Temp holder until Current equipment ID is properly filled in MS.
TH2 * fhMcbmStsTimeDiffToMuchWideVsAdc
Bool_t ReInitContainers()
CbmMcbm2018MonitorMcbmSync()
std::vector< size_t > fvMsComponentsListTof
void FillTofHitInfo(gdpbv100::Message)
void CreateMcbmHistograms()
std::map< UInt_t, UInt_t > fmStsDpbIdIndexMap
Total number of Sts DPBs in system.
UInt_t fuCurrDpbId
Current equipment ID, tells from which DPB the current MS is originating.
virtual void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
virtual void AddMsComponentToList(size_t component, UShort_t usDetectorId)
std::map< UInt_t, UInt_t > fmTofDpbIdIndexMap
Total number of GDPBs in the system.
TH2 * fhMcbmTimeDiffToDiamond
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondEvoSpillB
void FillTofEpochInfo(gdpbv100::Message)
Bool_t ProcessStsMs(const fles::Timeslice &ts, size_t uMsComp, UInt_t uMsIdx)
std::vector< std::vector< stsxyter::FinalHit > > fvmStsSdpbHitsInMs
Current TS MSB cycle for DPB.
std::vector< ULong64_t > fvulTofCurrentEpochCycle
UInt_t fuTotalNrOfDpb
Global parameters.
std::vector< TH2 * > fvhMcbmTimeDiffToMuchEvoSpillA
std::vector< size_t > fvMsComponentsListSts
std::vector< TH1 * > fvhHitsTimeEvoSpillA
TH2 * fhMcbmTimeDiffToMuchWide
void AddMsComponentToListTof(size_t component)
std::vector< ULong64_t > fvulTofCurrentEpochFull
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondEvoDpb
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
void AddMsComponentToListSts(size_t component)
std::vector< int > fviTofMsgCounter
std::vector< TH1 * > fvhHitsTimeEvoSpillB
CbmMcbm2018TofPar * fUnpackParTof
Unpacking and mapping parameters for TOF.
std::vector< UInt_t > fvuStsCurrentTsMsbCycle
Current TS MSB for each DPB.
Bool_t ProcessTofMs(const fles::Timeslice &ts, size_t uMsComp, UInt_t uMsIdx)
void FillTofEpochCycle(uint64_t ulCycleData)
Double_t fdStsTofOffsetNs
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondEvoSpillA
std::vector< TH2 * > fvhMcbmTimeDiffToMuchEvoSpillB
UInt_t fuMuchDpbIdx
Map of DPB Identifier to DPB index.
std::vector< std::vector< gdpbv100::FullMessage > > fvmTofGdpbHitsInTs
TH2 * fhMcbmTimeDiffToMuchTs
std::vector< ULong64_t > fvulTofCurrentEpoch
ULong64_t fulTofCurrentEpochTime
std::vector< ULong64_t > fvulStsCurrentTsMsb
Bin size in s for the plots with date as X axis.
ULong64_t fulCurrentMsIdx
std::vector< std::vector< gdpbv100::FullMessage > > fvmTofGdpbHitsInMs
Buffer for system sync check.
static const UInt_t kuStsBytesPerMessage
ULong64_t fulCurrentTsIdx
TH2 * fhMcbmTimeDiffToDiamondWide
void FillStsTsMsbInfo(stsxyter::Message mess, UInt_t uMessIdx=0, UInt_t uMsIdx=0)
TH2 * fhMcbmTimeDiffToMuch
void FillStsEpochInfo(stsxyter::Message mess)
void FillStsHitInfo(stsxyter::Message mess, const UInt_t &uMsIdx)
TH2 * fhMcbmStsTimeDiffToMuchTsVsAdc
std::vector< std::vector< stsxyter::FinalHit > > fvmStsSdpbHitsInTs
All hits (time in bins, ADC in bins, asic, channel) in last TS, sorted with "<" operator.
TH2 * fhMcbmTimeDiffToDiamondTs
static const UInt_t kuTofBytesPerMessage
TODO => move to the message class!!
stsxyter::MessagePrintMask fPrintMessCtrlSts
std::map< stsxyter::MessType, UInt_t > fmMsgCounter
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondWideEvoDpb
std::vector< std::vector< gdpbv100::Message > > fvmTofEpSupprBuffer
Buffer for suppressed epoch processing.
Double_t fdMuchTofOffsetNs
void CreateTofHistograms()
Processing methods.
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondTsEvoDpb
virtual ~CbmMcbm2018MonitorMcbmSync()
CbmMcbm2018StsPar * fUnpackParSts
UInt_t fuCurrentEquipmentId
TString fsHistoFileFullname
UInt_t GetDpbId(UInt_t uDpbIdx)
UInt_t ElinkIdxToAsicIdx(Bool_t bFebType, UInt_t uElink)
static constexpr UInt_t GetNbChanPerAsic()
Int_t GetNrOfGdpbs()
FIXME: replace with method returning the correspondign constants! see Star2019 parameter.
Data class with information on a STS local track.
uint16_t getGdpbHitIs24b() const
uint32_t getGdpbEpEpochNb() const
void setGdpbEpEpochNb(uint32_t v)
uint16_t getGdpbGenChipId() const
void printDataCout(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to cout.
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 4 bit.
uint64_t getMsgFullTime(uint64_t epoch) const
Returns expanded and adjusted time of message (in ns)
XPU_D uint16_t GetHitAdc() const
For Hit data: Returns ADC value (5 bit field)
XPU_D uint16_t GetHitChannel() const
For Hit data: Returns StsXYTER channel number (7 bit field)
bool PrintMess(std::ostream &os, MessagePrintMask ctrl=MessagePrintMask::msg_print_Human, bool bBinning=true) const
XPU_D uint16_t GetLinkIndex() const
For all data: Returns the (global) index of the eLink on which the message was received (n bit field)
XPU_D MessType GetMessType() const
Returns the message type, see enum MessType.
XPU_D uint16_t GetHitTime() const
For Hit data: Returns timestamp (8 bit field, 2 MSB bits overlap removed)
XPU_D uint32_t GetTsMsbVal() const
For TS MSB data: Returns the TS MSB 22 bit field)
const uint64_t kulEpochCycleBins
const uint32_t kuChipIdMergedEpoch
const uint32_t kuEpochCounterSz
const uint64_t kulEpochCycleFieldSz
static constexpr uint64_t kulTsCycleNbBins
static constexpr uint32_t kuHitNbTsBins
static constexpr uint32_t kuHitNbAdcBins
Status/properties constants.
static constexpr double kdClockCycleNs