From eae56b23cb57c8a8042e2cf44102ee8fec262f34 Mon Sep 17 00:00:00 2001
From: Pascal Raisig <praisig@ikf.uni-frankfurt.de>
Date: Thu, 5 Aug 2021 16:02:51 +0200
Subject: [PATCH] Fix digi counting in event header

Before this fix only the number of digis of the last component of a subsystem endet up in the counter of the event header. Now an Add function is used and the counters a resetted at the beginning of each timeslice.
---
 core/data/CbmTsEventHeader.cxx | 15 ++++++++
 core/data/CbmTsEventHeader.h   | 68 +++++++++++++++++++++-------------
 reco/steer/CbmRecoUnpack.cxx   | 17 +++++----
 3 files changed, 66 insertions(+), 34 deletions(-)

diff --git a/core/data/CbmTsEventHeader.cxx b/core/data/CbmTsEventHeader.cxx
index 6c9724edf6..360500d8e5 100644
--- a/core/data/CbmTsEventHeader.cxx
+++ b/core/data/CbmTsEventHeader.cxx
@@ -7,3 +7,18 @@
 // -----   Constructor   ------------------------------------------------------
 CbmTsEventHeader::CbmTsEventHeader() {}
 // ----------------------------------------------------------------------------
+
+
+// ---- Reset ----
+void CbmTsEventHeader::Reset()
+{
+  // Reset the digi counters
+  fNDigisPsd   = 0;
+  fNDigisRich  = 0;
+  fNDigisSts   = 0;
+  fNDigisTof   = 0;
+  fNDigisTrd1D = 0;
+  fNDigisTrd2D = 0;
+}
+
+ClassImp(CbmTsEventHeader)
diff --git a/core/data/CbmTsEventHeader.h b/core/data/CbmTsEventHeader.h
index 71f43e1a66..422096e804 100644
--- a/core/data/CbmTsEventHeader.h
+++ b/core/data/CbmTsEventHeader.h
@@ -21,39 +21,55 @@ public:
   /** Default destructor */
   virtual ~CbmTsEventHeader() {};
 
-  /** Get the Start time of the this Timeslice linked to this event header*/
-  uint64_t GetTsIndex() { return fTsIndex; }
-  /** Get the Start time of the this Timeslice linked to this event header*/
-  uint64_t GetTsStartTime() { return fTsStartTime; }
+  /** @brief Add a number of digis from this Ts */
+  void AddNDigisPsd(uint64_t value) { fNDigisPsd += value; }
+  /** @brief Add a number of digis from this Ts */
+  void AddNDigisRich(uint64_t value) { fNDigisRich += value; }
+  /** @brief Add a number of digis from this Ts */
+  void AddNDigisSts(uint64_t value) { fNDigisSts += value; }
+  /** @brief Add a number of digis from this Ts */
+  void AddNDigisTof(uint64_t value) { fNDigisTof += value; }
+  /** @brief Add a number of digis from this Ts */
+  void AddNDigisTrd1D(uint64_t value) { fNDigisTrd1D += value; }
+  /** @brief Add a number of digis from this Ts */
+  void AddNDigisTrd2D(uint64_t value) { fNDigisTrd2D += value; }
 
   /** @brief Get the number of digis in this Ts */
-  ULong64_t GetNDigisPsd(ULong64_t) { return fNDigisPsd; }
+  uint64_t GetNDigisPsd() { return fNDigisPsd; }
   /** @brief Get the number of digis in this Ts */
-  ULong64_t GetNDigisRich(ULong64_t) { return fNDigisRich; }
+  uint64_t GetNDigisRich() { return fNDigisRich; }
   /** @brief Get the number of digis in this Ts */
-  ULong64_t GetNDigisSts(ULong64_t) { return fNDigisSts; }
+  uint64_t GetNDigisSts() { return fNDigisSts; }
   /** @brief Get the number of digis in this Ts */
-  ULong64_t GetNDigisTof(ULong64_t) { return fNDigisTof; }
+  uint64_t GetNDigisTof() { return fNDigisTof; }
   /** @brief Get the number of digis in this Ts */
-  ULong64_t GetNDigisTrd1D(ULong64_t) { return fNDigisTrd; }
+  uint64_t GetNDigisTrd1D() { return fNDigisTrd1D; }
   /** @brief Get the number of digis in this Ts */
-  ULong64_t GetNDigisTrd2D(ULong64_t) { return fNDigisTrd2D; }
+  uint64_t GetNDigisTrd2D() { return fNDigisTrd2D; }
+
+  /** Get the Start time of the this Timeslice linked to this event header*/
+  uint64_t GetTsIndex() { return fTsIndex; }
+  /** Get the Start time of the this Timeslice linked to this event header*/
+  uint64_t GetTsStartTime() { return fTsStartTime; }
+
+  /** @brief Resets counters and variables for a new Timeslice, e.g. the NDigis counter are set back to 0*/
+  void Reset();
 
   /** @brief Set the number of digis in this Ts */
-  void SetNDigisPsd(ULong64_t value) { fNDigisPsd = value; }
+  void SetNDigisPsd(uint64_t value) { fNDigisPsd = value; }
   /** @brief Set the number of digis in this Ts */
-  void SetNDigisRich(ULong64_t value) { fNDigisRich = value; }
+  void SetNDigisRich(uint64_t value) { fNDigisRich = value; }
   /** @brief Set the number of digis in this Ts */
-  void SetNDigisSts(ULong64_t value) { fNDigisSts = value; }
+  void SetNDigisSts(uint64_t value) { fNDigisSts = value; }
   /** @brief Set the number of digis in this Ts */
-  void SetNDigisTof(ULong64_t value) { fNDigisTof = value; }
+  void SetNDigisTof(uint64_t value) { fNDigisTof = value; }
   /** @brief Set the number of digis in this Ts */
-  void SetNDigisTrd1D(ULong64_t value) { fNDigisTrd = value; }
+  void SetNDigisTrd1D(uint64_t value) { fNDigisTrd1D = value; }
   /** @brief Set the number of digis in this Ts */
-  void SetNDigisTrd2D(ULong64_t value) { fNDigisTrd2D = value; }
+  void SetNDigisTrd2D(uint64_t value) { fNDigisTrd2D = value; }
 
   /** @brief Set the Ts Start Time @param value Start time of the TS */
-  void SetTsIndex(uint32_t value) { fTsIndex = value; }
+  void SetTsIndex(uint64_t value) { fTsIndex = value; }
   /** @brief Set the Ts Start Time @param value Start time of the TS */
   void SetTsStartTime(uint64_t value) { fTsStartTime = value; }
 
@@ -64,18 +80,18 @@ protected:
   uint64_t fTsStartTime = 0;
 
   /** @brief nDigis in "this" timeslice measured by the PSD */
-  ULong64_t fNDigisPsd = 0;
+  uint64_t fNDigisPsd = 0;
   /** @brief nDigis in "this" timeslice measured by the RICH */
-  ULong64_t fNDigisRich = 0;
+  uint64_t fNDigisRich = 0;
   /** @brief nDigis in "this" timeslice measured by the STS */
-  ULong64_t fNDigisSts = 0;
-  /** @brief nDigis in "this" timeslice measured by the TRD1D @remark the member is not renamed to fNDigisTrd1D for easier backwards compatibility */
-  ULong64_t fNDigisTrd = 0;
-  /** @brief nDigis in "this" timeslice measured by the TRD2D */
-  ULong64_t fNDigisTrd2D = 0;
+  uint64_t fNDigisSts = 0;
   /** @brief nDigis in "this" timeslice measured by the TOF */
-  ULong64_t fNDigisTof = 0;
+  uint64_t fNDigisTof = 0;
+  /** @brief nDigis in "this" timeslice measured by the TRD1D */
+  uint64_t fNDigisTrd1D = 0;
+  /** @brief nDigis in "this" timeslice measured by the TRD2D */
+  uint64_t fNDigisTrd2D = 0;
 
-  ClassDef(CbmTsEventHeader, 4)
+  ClassDef(CbmTsEventHeader, 5)
 };
 #endif
diff --git a/reco/steer/CbmRecoUnpack.cxx b/reco/steer/CbmRecoUnpack.cxx
index 15eb072e9a..2e38369d41 100644
--- a/reco/steer/CbmRecoUnpack.cxx
+++ b/reco/steer/CbmRecoUnpack.cxx
@@ -11,8 +11,6 @@
 #include "CbmTrdDigi.h"
 #include "CbmTsEventHeader.h"
 
-#include "MicrosliceDescriptor.hpp"
-
 #include <FairRootManager.h>
 #include <Logger.h>
 
@@ -214,6 +212,9 @@ void CbmRecoUnpack::performanceProfiling()
 // -----   Reset   ------------------------------------------------------------
 void CbmRecoUnpack::Reset()
 {
+  // Reset the event header for a new timeslice
+  fCbmTsEventHeader->Reset();
+
   // Reset the unpackers for a new timeslice, e.g. clear the output vectors
 
   // ---- Psd ----
@@ -252,7 +253,7 @@ void CbmRecoUnpack::Unpack(unique_ptr<Timeslice> ts)
     switch (systemId) {
       case fkFlesPsd: {
         if (fPsdConfig) {
-          fCbmTsEventHeader->SetNDigisPsd(unpack(systemId, &timeslice, component, fPsdConfig,
+          fCbmTsEventHeader->AddNDigisPsd(unpack(systemId, &timeslice, component, fPsdConfig,
                                                  fPsdConfig->GetOptOutAVec(), fPsdConfig->GetOptOutBVec()));
         }
 
@@ -260,28 +261,28 @@ void CbmRecoUnpack::Unpack(unique_ptr<Timeslice> ts)
       }
       case fkFlesRich: {
         if (fRichConfig) {
-          fCbmTsEventHeader->SetNDigisRich(unpack(systemId, &timeslice, component, fRichConfig,
+          fCbmTsEventHeader->AddNDigisRich(unpack(systemId, &timeslice, component, fRichConfig,
                                                   fRichConfig->GetOptOutAVec(), fRichConfig->GetOptOutBVec()));
         }
         break;
       }
       case fkFlesSts: {
         if (fStsConfig) {
-          fCbmTsEventHeader->SetNDigisSts(unpack(systemId, &timeslice, component, fStsConfig,
+          fCbmTsEventHeader->AddNDigisSts(unpack(systemId, &timeslice, component, fStsConfig,
                                                  fStsConfig->GetOptOutAVec(), fStsConfig->GetOptOutBVec()));
         }
         break;
       }
       case fkFlesTof: {
         if (fTofConfig) {
-          fCbmTsEventHeader->SetNDigisTof(unpack(systemId, &timeslice, component, fTofConfig,
+          fCbmTsEventHeader->AddNDigisTof(unpack(systemId, &timeslice, component, fTofConfig,
                                                  fTofConfig->GetOptOutAVec(), fTofConfig->GetOptOutBVec()));
         }
         break;
       }
       case fkFlesTrd: {
         if (fTrd1DConfig) {
-          fCbmTsEventHeader->SetNDigisTrd1D(unpack(systemId, &timeslice, component, fTrd1DConfig,
+          fCbmTsEventHeader->AddNDigisTrd1D(unpack(systemId, &timeslice, component, fTrd1DConfig,
                                                    fTrd1DConfig->GetOptOutAVec(), fTrd1DConfig->GetOptOutBVec()));
         }
         break;
@@ -289,7 +290,7 @@ void CbmRecoUnpack::Unpack(unique_ptr<Timeslice> ts)
       case fkFlesTrd2D: {
         if (fTrd2DConfig)
           if (fTrd2DConfig) {
-            fCbmTsEventHeader->SetNDigisTrd2D(unpack(systemId, &timeslice, component, fTrd2DConfig,
+            fCbmTsEventHeader->AddNDigisTrd2D(unpack(systemId, &timeslice, component, fTrd2DConfig,
                                                      fTrd2DConfig->GetOptOutAVec(), fTrd2DConfig->GetOptOutBVec()));
           }
         break;
-- 
GitLab