From 2395232cdaef42f7a078c38cc09a61c5135c6860 Mon Sep 17 00:00:00 2001
From: "P.-A. Loizeau" <p.-a.loizeau@gsi.de>
Date: Mon, 13 May 2024 19:12:59 +0200
Subject: [PATCH] [mCBM] in BMon/TOF legacy monitor, add support for 2024 sCVD
 detector

---
 macro/beamtime/mcbm2024/mBmonCriPar.par       | 14 ++---
 macro/run/run_unpack_online_bmon.C            |  5 ++
 .../tof/unpack/CbmTofUnpackMonitor.cxx        | 60 +++++++++++++------
 .../tof/unpack/CbmTofUnpackMonitor.h          | 48 +++++++++------
 4 files changed, 85 insertions(+), 42 deletions(-)

diff --git a/macro/beamtime/mcbm2024/mBmonCriPar.par b/macro/beamtime/mcbm2024/mBmonCriPar.par
index 73ac789cd7..66af831d48 100644
--- a/macro/beamtime/mcbm2024/mBmonCriPar.par
+++ b/macro/beamtime/mcbm2024/mBmonCriPar.par
@@ -1,23 +1,23 @@
 ####################################################################################################
 [CbmMcbm2018BmonPar]
 //----------------------------------------------------------------------------
-NrOfGdpbs: Int_t 4
+NrOfGdpbs: Int_t 5
 GdpbIdArray: Int_t \
-0xabf0 0xabf1 0xabf2 0xabf3
+0xabf0 0xabf1 0xabf2 0xabf3 0xabf4
 //0xabf3 0xabf2 0xabf1 0xabf0
 NrOfFeesPerGdpb: Int_t 10
 NrOfGet4PerFee:  Int_t 8
 NrOfChannelsPerGet4: Int_t 4
-NrOfGbtx: Int_t  8
+NrOfGbtx: Int_t  10
 NrOfModule: Int_t 0
 NrOfRpc: Int_t \
-  1  1  1  1
+  1  1  1  1 1
 RpcType: Int_t \
- 99 -1 99 -1 99 -1 99 -1
+ 99 -1 99 -1 99 -1 99 -1 99 -1
 RpcSide: Int_t \
-  0  0  0  0  0  0  0  0
+  0  0  0  0  0  0  0  0  1  0
 ModuleId: Int_t \
-  0 -1  0 -1  0 -1  0 -1
+  0 -1  0 -1  0 -1  0 -1  0 -1
 NbMsTot: Int_t 100
 NbMsOverlap: Int_t 1
 SizeMsInNs: Double_t 102400.0
diff --git a/macro/run/run_unpack_online_bmon.C b/macro/run/run_unpack_online_bmon.C
index 5ecca0b04f..0927909ac0 100644
--- a/macro/run/run_unpack_online_bmon.C
+++ b/macro/run/run_unpack_online_bmon.C
@@ -115,6 +115,11 @@ void run_unpack_online_bmon(std::vector<std::string> publisher = {"tcp://localho
       bmonconfig->GetMonitor()->SetSpillThreshold(250);
       bmonconfig->GetMonitor()->SetSpillThresholdNonPulser(100);
     }
+    if (2981 <= runid) {
+      bmonconfig->GetMonitor()->SetSpillThreshold(900);
+      bmonconfig->GetMonitor()->SetSpillThresholdNonPulser(750);
+      bmonconfig->GetMonitor()->SetBmonScvdMode(true);
+    }
   }
   // -------------
 
diff --git a/reco/detectors/tof/unpack/CbmTofUnpackMonitor.cxx b/reco/detectors/tof/unpack/CbmTofUnpackMonitor.cxx
index 388f419bbb..49f3b26cca 100644
--- a/reco/detectors/tof/unpack/CbmTofUnpackMonitor.cxx
+++ b/reco/detectors/tof/unpack/CbmTofUnpackMonitor.cxx
@@ -426,6 +426,30 @@ Bool_t CbmTofUnpackMonitor::ResetHistograms()
 
 Bool_t CbmTofUnpackMonitor::CreateBmonHistograms()
 {
+  if (fBmonScvdMode) {
+    fuNbChanBmon  = kuNbChanBmonScvd;
+    fuBmonChanMap = std::vector<UInt_t>(kuBmonChanMapScvd, kuBmonChanMapScvd + kuNbChanBmonScvd);
+  }
+  else {
+    fuNbChanBmon  = kuNbChanBmon;
+    fuBmonChanMap = std::vector<UInt_t>(kuBmonChanMap, kuBmonChanMap + kuNbChanBmon);
+  }
+  fvuBmonHitCntChanMs.resize(fuNbChanBmon, 0);
+  fvuBmonErrorCntChanMs.resize(fuNbChanBmon, 0);
+  fvuBmonEvtLostCntChanMs.resize(fuNbChanBmon, 0);
+  fvhBmonMsgCntEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonMsgCntPerMsEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonHitCntEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonHitCntPerMsEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonErrorCntEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonErrorCntPerMsEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonEvtLostCntEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonEvtLostCntPerMsEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonErrorFractEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonErrorFractPerMsEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonEvtLostFractEvoChan.resize(fuNbChanBmon, nullptr);
+  fvhBmonEvtLostFractPerMsEvoChan.resize(fuNbChanBmon, nullptr);
+
   /// Logarithmic bining
   uint32_t iNbBinsLog = 0;
   /// Parameters are NbDecadesLog, NbStepsDecade, NbSubStepsInStep
@@ -439,7 +463,7 @@ Bool_t CbmTofUnpackMonitor::CreateBmonHistograms()
                              fuNbOfComps, -0.5, fuNbOfComps - 0.5);
   fhBmonCompGet4 = new TH2I("hBmonCompGet4", "Map of hits on Bmon detector; Comp.; GET4; Counts []",
                            fuNbOfComps*80, -0.5, fuNbOfComps*80 - 0.5,
-                           2*kuNbChanBmon, -0.5, 2*kuNbChanBmon - 0.5);
+                           2*fuNbChanBmon, -0.5, 2*fuNbChanBmon - 0.5);
   fhBmonGet4Map = new TH1I("hBmonGet4Map", "Map of hits on Bmon detector; GET4; Hits Count []",
                           fuNbOfComps*80, -0.5, fuNbOfComps*80 - 0.5);
   fhBmonGet4MapEvo     = new TH2I("hBmonGet4MapEvo",
@@ -448,44 +472,44 @@ Bool_t CbmTofUnpackMonitor::CreateBmonHistograms()
                                   fuHistoryHistoSize, 0, fuHistoryHistoSize,
                                   fuNbOfComps*80, -0.5, fuNbOfComps*80 - 0.5);
   fhBmonChannelMapAll    = new TH1I("hChannelMapAll", "Map of hits on Bmon detector; Strip; Hits Count []",
-                                    kuNbChanBmon, -0.5, kuNbChanBmon - 0.5);
+                                    fuNbChanBmon, -0.5, fuNbChanBmon - 0.5);
   fhBmonChannelTotAll    = new TH2I("hChannelTotAll", "Tot of hits on Bmon detector per channel; Strip; Tot; Hits Count []",
-                                    kuNbChanBmon, -0.5, kuNbChanBmon - 0.5, 256, -0.5, 255.5);
+                                    fuNbChanBmon, -0.5, fuNbChanBmon - 0.5, 256, -0.5, 255.5);
   fhBmonHitMapEvoAll     = new TH2I("hBmonHitMapEvoAll",
                                      "Map of hits on Bmon detector vs time in run; Chan; "
                                      "Time in run [s]; Hits Count []",
-                                     kuNbChanBmon, -0.5, kuNbChanBmon - 0.5,
+                                     fuNbChanBmon, -0.5, fuNbChanBmon - 0.5,
                                      fuHistoryHistoSize, 0, fuHistoryHistoSize);
   fhBmonHitTotEvoAll     = new TH2I("hBmonHitTotEvoAll",
                                     "Evolution of TOT in Bmon detector vs time in run; Time "
                                     "in run [s]; TOT [ bin ]; Hits Count []",
                                     fuHistoryHistoSize, 0, fuHistoryHistoSize, 256, -0.5, 255.5);
   fhBmonChanHitMapAll    = new TH1D("fhBmonChanHitMapAll", "Map of hits on Bmon detector; Strip; Hits Count []",
-                                    kuNbChanBmon, -0.5, kuNbChanBmon - 0.5);
+                                    fuNbChanBmon, -0.5, fuNbChanBmon - 0.5);
   fhBmonChanHitMapEvoAll = new TH2I("hBmonChanHitMapEvoAll",
                                     "Map of hits on Bmon detector vs time in run; "
                                     "Strip; Time in run [s]; Hits Count []",
-                                    kuNbChanBmon, 0., kuNbChanBmon, fuHistoryHistoSize, 0, fuHistoryHistoSize);
+                                    fuNbChanBmon, 0., fuNbChanBmon, fuHistoryHistoSize, 0, fuHistoryHistoSize);
 
 
   fhBmonCompMap = new TH1I("hBmonCompMap", "Map of hits on Bmon detector; Comp.; Hits Count []",
                           fuNbOfComps, -0.5, fuNbOfComps - 0.5);
   fhBmonChannelMap    = new TH1I("hChannelMap", "Map of hits on Bmon detector; Strip; Hits Count []",
-                                 kuNbChanBmon, -0.5, kuNbChanBmon - 0.5);
+                                 fuNbChanBmon, -0.5, fuNbChanBmon - 0.5);
   fhBmonHitMapEvo     = new TH2I("hBmonHitMapEvo",
                          "Map of hits on Bmon detector vs time in run; Chan; "
                          "Time in run [s]; Hits Count []",
-                         kuNbChanBmon, -0.5, kuNbChanBmon - 0.5, fuHistoryHistoSize, 0, fuHistoryHistoSize);
+                         fuNbChanBmon, -0.5, fuNbChanBmon - 0.5, fuHistoryHistoSize, 0, fuHistoryHistoSize);
   fhBmonHitTotEvo     = new TH2I("hBmonHitTotEvo",
                          "Evolution of TOT in Bmon detector vs time in run; Time "
                          "in run [s]; TOT [ bin ]; Hits Count []",
                          fuHistoryHistoSize, 0, fuHistoryHistoSize, 256, -0.5, 255.5);
   fhBmonChanHitMap    = new TH1D("fhBmonChanHitMap", "Map of hits on Bmon detector; Strip; Hits Count []",
-                                 kuNbChanBmon, -0.5, kuNbChanBmon - 0.5);
+                                 fuNbChanBmon, -0.5, fuNbChanBmon - 0.5);
   fhBmonChanHitMapEvo = new TH2I("hBmonChanHitMapEvo",
                              "Map of hits on Bmon detector vs time in run; "
                              "Strip; Time in run [s]; Hits Count []",
-                             kuNbChanBmon, 0., kuNbChanBmon, fuHistoryHistoSize, 0, fuHistoryHistoSize);
+                             fuNbChanBmon, 0., fuNbChanBmon, fuHistoryHistoSize, 0, fuHistoryHistoSize);
   for (UInt_t uSpill = 0; uSpill < kuNbSpillPlots; uSpill++) {
     fvhBmonCompMapSpill.push_back(
       new TH1I(Form("hBmonCompMapSpill%02u", uSpill),
@@ -495,7 +519,7 @@ Bool_t CbmTofUnpackMonitor::CreateBmonHistograms()
                                           Form("Map of hits on Bmon detector in current spill %02u; Strip; "
                                                "Hits Count []",
                                                uSpill),
-                                          kuNbChanBmon, -0.5, kuNbChanBmon - 0.5));
+                                          fuNbChanBmon, -0.5, fuNbChanBmon - 0.5));
   }  // for( UInt_t uSpill = 0; uSpill < kuNbSpillPlots; uSpill ++)
   fhBmonHitsPerSpill = new TH1I("hBmonHitsPerSpill", "Hit count per spill; Spill; Hits Count []", 2000, 0., 2000);
 
@@ -550,11 +574,11 @@ Bool_t CbmTofUnpackMonitor::CreateBmonHistograms()
                                     fuHistoryHistoSize, 0, fuHistoryHistoSize, 1000, 0, 1);
 
   fhBmonChannelMapPulser = new TH1I("fhBmonChannelMapPulser", "Map of pulser hits on Bmon detector; Chan; Hits Count []",
-                                kuNbChanBmon, 0., kuNbChanBmon);
+                                fuNbChanBmon, 0., fuNbChanBmon);
   fhBmonHitMapEvoPulser  = new TH2I("fhBmonHitMapEvoPulser",
                                "Map of hits on Bmon detector vs time in run; "
                                "Chan; Time in run [s]; Hits Count []",
-                               kuNbChanBmon, 0., kuNbChanBmon, fuHistoryHistoSize, 0, fuHistoryHistoSize);
+                               fuNbChanBmon, 0., fuNbChanBmon, fuHistoryHistoSize, 0, fuHistoryHistoSize);
   // clang-format on
 
   /// Add pointers to the vector with all histo for access by steering class
@@ -607,7 +631,7 @@ Bool_t CbmTofUnpackMonitor::CreateBmonHistograms()
 
   /*******************************************************************/
   sFolder = "RatePerChan";
-  for (UInt_t uChan = 0; uChan < kuNbChanBmon; ++uChan) {
+  for (UInt_t uChan = 0; uChan < fuNbChanBmon; ++uChan) {
     // clang-format off
     fvhBmonMsgCntEvoChan[uChan]      = new TH1I(Form("hBmonMsgCntEvoChan%02u", uChan),
                                        Form("Evolution of Messages counts vs time in run for channel "
@@ -690,14 +714,14 @@ Bool_t CbmTofUnpackMonitor::CreateBmonHistograms()
     AddHistoToVector(fvhBmonErrorFractPerMsEvoChan[uChan], sFolder);
     AddHistoToVector(fvhBmonEvtLostFractEvoChan[uChan], sFolder);
     AddHistoToVector(fvhBmonEvtLostFractPerMsEvoChan[uChan], sFolder);
-  }  // for( UInt_t uChan = 0; uChan < kuNbChanBmon; ++uChan )
+  }  // for( UInt_t uChan = 0; uChan < fuNbChanBmon; ++uChan )
 
   return kTRUE;
 }
 
 Bool_t CbmTofUnpackMonitor::ResetBmonHistograms(Bool_t bResetTime)
 {
-  for (UInt_t uChan = 0; uChan < kuNbChanBmon; ++uChan) {
+  for (UInt_t uChan = 0; uChan < fuNbChanBmon; ++uChan) {
     fvhBmonMsgCntEvoChan[uChan]->Reset();
     fvhBmonMsgCntPerMsEvoChan[uChan]->Reset();
 
@@ -715,7 +739,7 @@ Bool_t CbmTofUnpackMonitor::ResetBmonHistograms(Bool_t bResetTime)
 
     fvhBmonEvtLostFractEvoChan[uChan]->Reset();
     fvhBmonEvtLostFractPerMsEvoChan[uChan]->Reset();
-  }  // for( UInt_t uChan = 0; uChan < kuNbChanBmon; ++uChan )
+  }  // for( UInt_t uChan = 0; uChan < fuNbChanBmon; ++uChan )
 
   fhBmonCompMap->Reset();
   fhBmonCompGet4->Reset();
@@ -1415,7 +1439,7 @@ void CbmTofUnpackMonitor::FillHitBmonMonitoringHistos(const double_t& dMsTime, c
     fhBmonGet4Map->Fill(uGet4Id + 80 * uCurrCompIdx);
     fhBmonGet4MapEvo->Fill(dMsTime - fdStartTime, uGet4Id + 80 * uCurrCompIdx);
     fhBmonCompGet4->Fill(uGet4Id + 80 * uCurrCompIdx, uChannelBmon);
-    if (kuNbChanBmon <= uChannelBmon) return;
+    if (fuNbChanBmon <= uChannelBmon) return;
 
     fhBmonCompMapAll->Fill(uCurrCompIdx);
     fhBmonChannelMapAll->Fill(uChannelBmon);
diff --git a/reco/detectors/tof/unpack/CbmTofUnpackMonitor.h b/reco/detectors/tof/unpack/CbmTofUnpackMonitor.h
index 34580a6e2d..b7200627b1 100644
--- a/reco/detectors/tof/unpack/CbmTofUnpackMonitor.h
+++ b/reco/detectors/tof/unpack/CbmTofUnpackMonitor.h
@@ -107,7 +107,7 @@ public:
   /** @brief Activate the BMon mode */
   void SetBmonMode(bool value) { fBmonMode = value; }
 
-  /** @brief Read the Bmon mode */
+  /** @brief Read the BMon mode */
   bool GetBmonMode() { return fBmonMode; }
 
   /// Fill BMon Microspill histograms
@@ -121,6 +121,12 @@ public:
   /** @brief Read the Bmon mode */
   bool GetBmonMicroSpillMode() { return fBmonMicroSpillMode; }
 
+  /** @brief Activate the BMon sCVD mode */
+  void SetBmonScvdMode(bool value) { fBmonScvdMode = value; }
+
+  /** @brief Read the BMon mode */
+  bool GetBmonScvdMode() { return fBmonScvdMode; }
+
   /** @brief Activate/de-activate the internal histo serve mode */
   void SetInternalHttpMode(bool value) { fbInternalHttp = value; }
 
@@ -156,6 +162,7 @@ private:
 
   /** @brief Flag if debug mode is active or not */
   bool fBmonMode           = false;
+  bool fBmonScvdMode       = false;
   bool fBmonMicroSpillMode = false;
   bool fbInternalHttp      = true;
 
@@ -163,6 +170,7 @@ private:
   static const UInt_t kuMaxNbFlibLinks  = 32;
   static const UInt_t kuBytesPerMessage = 8;
   static const UInt_t kuNbChanBmon      = 16;
+  static const UInt_t kuNbChanBmonScvd  = 20;
   static const UInt_t kuNbSpillPlots    = 5;
 
   /// ---> User settings: Data correction parameters
@@ -174,7 +182,13 @@ private:
   /// Map from electronics channel to BMon strip
   /// 2022 mapping: Y[0-3] on c0, Y[4-7] on c1, X[4-7] on c2, X[0-3] on c3, re-ordered in par file and par class
   /// Y not cabled for diamond but pulser there
-  UInt_t fuBmonChanMap[kuNbChanBmon] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+  static constexpr UInt_t kuBmonChanMap[kuNbChanBmon] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+  /// 2024 mapping: +4 channels scvd added
+  static constexpr UInt_t kuBmonChanMapScvd[kuNbChanBmonScvd] = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
+                                                                 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
+  /// Runtime values
+  UInt_t fuNbChanBmon               = 0;
+  std::vector<UInt_t> fuBmonChanMap = {};
 
   /// MS size histograms
   TH1* fvhMsSize[kuMaxNbFlibLinks];
@@ -205,21 +219,21 @@ private:
 
   /// BMon specific histograms
   /// ---> Channel rate plots
-  std::vector<UInt_t> fvuBmonHitCntChanMs           = std::vector<UInt_t>(kuNbChanBmon, 0);
-  std::vector<UInt_t> fvuBmonErrorCntChanMs         = std::vector<UInt_t>(kuNbChanBmon, 0);
-  std::vector<UInt_t> fvuBmonEvtLostCntChanMs       = std::vector<UInt_t>(kuNbChanBmon, 0);
-  std::vector<TH1*> fvhBmonMsgCntEvoChan            = std::vector<TH1*>(kuNbChanBmon, nullptr);
-  std::vector<TH2*> fvhBmonMsgCntPerMsEvoChan       = std::vector<TH2*>(kuNbChanBmon, nullptr);
-  std::vector<TH1*> fvhBmonHitCntEvoChan            = std::vector<TH1*>(kuNbChanBmon, nullptr);
-  std::vector<TH2*> fvhBmonHitCntPerMsEvoChan       = std::vector<TH2*>(kuNbChanBmon, nullptr);
-  std::vector<TH1*> fvhBmonErrorCntEvoChan          = std::vector<TH1*>(kuNbChanBmon, nullptr);
-  std::vector<TH2*> fvhBmonErrorCntPerMsEvoChan     = std::vector<TH2*>(kuNbChanBmon, nullptr);
-  std::vector<TH1*> fvhBmonEvtLostCntEvoChan        = std::vector<TH1*>(kuNbChanBmon, nullptr);
-  std::vector<TH2*> fvhBmonEvtLostCntPerMsEvoChan   = std::vector<TH2*>(kuNbChanBmon, nullptr);
-  std::vector<TProfile*> fvhBmonErrorFractEvoChan   = std::vector<TProfile*>(kuNbChanBmon, nullptr);
-  std::vector<TH2*> fvhBmonErrorFractPerMsEvoChan   = std::vector<TH2*>(kuNbChanBmon, nullptr);
-  std::vector<TProfile*> fvhBmonEvtLostFractEvoChan = std::vector<TProfile*>(kuNbChanBmon, nullptr);
-  std::vector<TH2*> fvhBmonEvtLostFractPerMsEvoChan = std::vector<TH2*>(kuNbChanBmon, nullptr);
+  std::vector<UInt_t> fvuBmonHitCntChanMs           = {};
+  std::vector<UInt_t> fvuBmonErrorCntChanMs         = {};
+  std::vector<UInt_t> fvuBmonEvtLostCntChanMs       = {};
+  std::vector<TH1*> fvhBmonMsgCntEvoChan            = {};
+  std::vector<TH2*> fvhBmonMsgCntPerMsEvoChan       = {};
+  std::vector<TH1*> fvhBmonHitCntEvoChan            = {};
+  std::vector<TH2*> fvhBmonHitCntPerMsEvoChan       = {};
+  std::vector<TH1*> fvhBmonErrorCntEvoChan          = {};
+  std::vector<TH2*> fvhBmonErrorCntPerMsEvoChan     = {};
+  std::vector<TH1*> fvhBmonEvtLostCntEvoChan        = {};
+  std::vector<TH2*> fvhBmonEvtLostCntPerMsEvoChan   = {};
+  std::vector<TProfile*> fvhBmonErrorFractEvoChan   = {};
+  std::vector<TH2*> fvhBmonErrorFractPerMsEvoChan   = {};
+  std::vector<TProfile*> fvhBmonEvtLostFractEvoChan = {};
+  std::vector<TH2*> fvhBmonEvtLostFractPerMsEvoChan = {};
   /// ---> Channels maps without cuts
   TH1* fhBmonCompMapAll       = nullptr;
   TH2* fhBmonCompGet4         = nullptr;
-- 
GitLab