From 9f37185b3af8548e958d6b082e8ec47af06db662 Mon Sep 17 00:00:00 2001
From: Volker Friese <v.friese@gsi.de>
Date: Thu, 3 Aug 2023 14:06:07 +0000
Subject: [PATCH] CbmEvent: Number of objects returns 0 now for empty branches

---
 core/data/CbmEvent.cxx                        | 35 +++++++++-------
 core/data/CbmEvent.h                          | 18 +++------
 core/data/test/_GTestCbmEvent.cxx             | 40 +++++++++----------
 reco/L1/CbmL1ReadEvent.cxx                    | 10 ++---
 .../rich/mcbm/CbmRichMCbmAerogelAna.cxx       |  4 +-
 .../detectors/rich/mcbm/CbmRichMCbmQaReal.cxx | 34 ++++++++--------
 .../rich/mcbm/CbmRichMCbmQaRichOnly.cxx       |  6 +--
 .../rich/mcbm/CbmRichMCbmSEDisplay.cxx        |  4 +-
 reco/detectors/trd/CbmTrdClusterFinder.cxx    |  2 +-
 .../digis/CbmAlgoBuildRawEvents.cxx           | 19 ++++-----
 .../eventbuilder/tracks/CbmEventBuilderQa.cxx |  2 +-
 11 files changed, 84 insertions(+), 90 deletions(-)

diff --git a/core/data/CbmEvent.cxx b/core/data/CbmEvent.cxx
index de4c99c2c3..37857fa7e8 100644
--- a/core/data/CbmEvent.cxx
+++ b/core/data/CbmEvent.cxx
@@ -10,10 +10,10 @@
 #include "CbmEvent.h"
 
 #include <algorithm>  // for std::sort
-#include <iostream>  // for operator<<, basic_ostream
-#include <sstream>   // for stringstream
-#include <string>    // for char_traits
-#include <utility>   // for pair
+#include <iostream>   // for operator<<, basic_ostream
+#include <sstream>    // for stringstream
+#include <string>     // for char_traits
+#include <utility>    // for pair
 
 // -----   Add data to event   ---------------------------------------------
 CbmEvent::CbmEvent(const CbmEvent& rhs)
@@ -21,7 +21,6 @@ CbmEvent::CbmEvent(const CbmEvent& rhs)
   , fNumber(rhs.fNumber)
   , fTimeStart(rhs.fTimeStart)
   , fTimeEnd(rhs.fTimeEnd)
-  , fNofData(rhs.fNofData)
   , fVertex(rhs.fVertex)
   , fMatch(nullptr)
   , fIndexMap(rhs.fIndexMap)
@@ -31,12 +30,7 @@ CbmEvent::CbmEvent(const CbmEvent& rhs)
 // -------------------------------------------------------------------------
 
 // -----   Add data to event   ---------------------------------------------
-void CbmEvent::AddData(ECbmDataType type, uint32_t index)
-{
-
-  fIndexMap[type].push_back(index);
-  fNofData++;
-}
+void CbmEvent::AddData(ECbmDataType type, uint32_t index) { fIndexMap[type].push_back(index); }
 // -------------------------------------------------------------------------
 
 
@@ -51,11 +45,23 @@ uint32_t CbmEvent::GetIndex(ECbmDataType type, uint32_t iData)
 // -------------------------------------------------------------------------
 
 
+// -----   Get total number of data objects   ------------------------------
+size_t CbmEvent::GetNofData() const
+{
+  size_t result = 0;
+  for (auto& entry : fIndexMap) {
+    result += entry.second.size();
+  }
+  return result;
+}
+// -------------------------------------------------------------------------
+
+
 // -----   Get number of data of a type in this event   --------------------
-int32_t CbmEvent::GetNofData(ECbmDataType type) const
+size_t CbmEvent::GetNofData(ECbmDataType type) const
 {
 
-  if (fIndexMap.find(type) == fIndexMap.end()) return -1;
+  if (fIndexMap.find(type) == fIndexMap.end()) return 0;
   else
     return fIndexMap.at(type).size();
 }
@@ -76,7 +82,6 @@ void CbmEvent::Swap(CbmEvent& e)
   std::swap(fNumber, e.fNumber);
   std::swap(fTimeStart, e.fTimeStart);
   std::swap(fTimeEnd, e.fTimeEnd);
-  std::swap(fNofData, e.fNofData);
   std::swap(fVertex, e.fVertex);
   std::swap(fMatch, e.fMatch);
   std::swap(fIndexMap, e.fIndexMap);
@@ -88,7 +93,7 @@ std::string CbmEvent::ToString() const
 {
   std::stringstream ss;
   ss << "Event " << fNumber << " at t = " << fTimeStart << " ns. Registered data types: " << fIndexMap.size()
-     << ", data objects: " << fNofData << (nullptr != fMatch ? ", with matches" : ", without matches") << "\n";
+     << ", data objects: " << GetNofData() << (nullptr != fMatch ? ", with matches" : ", without matches") << "\n";
   for (auto it = fIndexMap.begin(); it != fIndexMap.end(); it++) {
     ss << "          -- Data type " << it->first << ", number of data " << it->second.size() << "\n";
   }
diff --git a/core/data/CbmEvent.h b/core/data/CbmEvent.h
index e71c4945cf..01f416f26b 100644
--- a/core/data/CbmEvent.h
+++ b/core/data/CbmEvent.h
@@ -47,7 +47,6 @@ public:
     , fNumber(number)
     , fTimeStart(startTime)
     , fTimeEnd(endTime)
-    , fNofData(0)
     , fVertex()
     , fMatch(nullptr)
     , fIndexMap()
@@ -65,7 +64,7 @@ public:
   }
 
   /** Overload TObject Clear to clear the map! **/
-  void Clear(Option_t* /*option*/) { fIndexMap.clear(); }
+  void Clear(Option_t*) { fIndexMap.clear(); }
 
 
   /** Add a data object to the index map
@@ -96,15 +95,14 @@ public:
 
 
   /** Get total number of data (of all types) in the event **/
-  int32_t GetNofData() const { return fNofData; }
+  size_t GetNofData() const;
 
 
   /** Get number of data objects of a given type in this event
    ** @param DataType  Type of data (for values see CbmDetectorList.h)
    ** @value Number of objects of type DataType in the event.
-   ** -1 is data type is not registered.
    **/
-  int32_t GetNofData(ECbmDataType type) const;
+  size_t GetNofData(ECbmDataType type) const;
 
 
   /** Get number of STS tracks
@@ -178,12 +176,7 @@ public:
    ** Old content will be overwritten.
    ** @param indexVector  Vector with indices of STS tracks
    **/
-  void SetStsTracks(std::vector<uint32_t>& indexVector)
-  {
-    fNofData -= fIndexMap[ECbmDataType::kStsTrack].size();
-    fIndexMap[ECbmDataType::kStsTrack] = indexVector;
-    fNofData += fIndexMap[ECbmDataType::kStsTrack].size();
-  }
+  void SetStsTracks(std::vector<uint32_t>& indexVector) { fIndexMap[ECbmDataType::kStsTrack] = indexVector; }
 
 
   /** Set the event vertex variables
@@ -221,7 +214,6 @@ private:
   double fTimeStart = 0.;        ///< Event start time [ns]
   double fTimeEnd   = 0.;        ///< Event end time [ns]
   double fTzero     = -999999.;  ///< T0 of event for TOF PID [ns]
-  int32_t fNofData  = 0;         ///< Number of data objects in the event
   CbmVertex fVertex = {};        ///< Primary Vertex
   CbmMatch* fMatch  = nullptr;   ///< Match object to MCEvent
 
@@ -230,7 +222,7 @@ private:
 
   CbmEvent& operator=(const CbmEvent&);
 
-  ClassDef(CbmEvent, 2);
+  ClassDef(CbmEvent, 3);
 };
 
 #endif /* CBMEVENT_H_ */
diff --git a/core/data/test/_GTestCbmEvent.cxx b/core/data/test/_GTestCbmEvent.cxx
index aeebc1c1d8..58a361341c 100644
--- a/core/data/test/_GTestCbmEvent.cxx
+++ b/core/data/test/_GTestCbmEvent.cxx
@@ -137,11 +137,11 @@ TEST(_GTestCbmEvent, CheckAddData)
     SCOPED_TRACE("CheckAddData: Add first MCTrack");
     compareEventDataMembers(test, -111, 1., 2., 1, nullptr, nullptr);
     compareEventMap(test, 1, 1, ECbmDataType::kMCTrack, mctrack);
-    compareEventMap(test, 1, -1, ECbmDataType::kStsPoint, stspoint);
-    compareEventMap(test, 1, -1, ECbmDataType::kStsDigi, stsdigi);
-    compareEventMap(test, 1, -1, ECbmDataType::kStsCluster, stscluster);
-    compareEventMap(test, 1, -1, ECbmDataType::kStsHit, stshit);
-    compareEventMap(test, 1, -1, ECbmDataType::kStsTrack, ststrack);
+    compareEventMap(test, 1, 0, ECbmDataType::kStsPoint, stspoint);
+    compareEventMap(test, 1, 0, ECbmDataType::kStsDigi, stsdigi);
+    compareEventMap(test, 1, 0, ECbmDataType::kStsCluster, stscluster);
+    compareEventMap(test, 1, 0, ECbmDataType::kStsHit, stshit);
+    compareEventMap(test, 1, 0, ECbmDataType::kStsTrack, ststrack);
   }
 
   mctrack.push_back(23);
@@ -150,11 +150,11 @@ TEST(_GTestCbmEvent, CheckAddData)
     SCOPED_TRACE("CheckAddData: Add second MCTrack");
     compareEventDataMembers(test, -111, 1., 2., 2, nullptr, nullptr);
     compareEventMap(test, 2, 2, ECbmDataType::kMCTrack, mctrack);
-    compareEventMap(test, 2, -1, ECbmDataType::kStsPoint, stspoint);
-    compareEventMap(test, 2, -1, ECbmDataType::kStsDigi, stsdigi);
-    compareEventMap(test, 2, -1, ECbmDataType::kStsCluster, stscluster);
-    compareEventMap(test, 2, -1, ECbmDataType::kStsHit, stshit);
-    compareEventMap(test, 2, -1, ECbmDataType::kStsTrack, ststrack);
+    compareEventMap(test, 2, 0, ECbmDataType::kStsPoint, stspoint);
+    compareEventMap(test, 2, 0, ECbmDataType::kStsDigi, stsdigi);
+    compareEventMap(test, 2, 0, ECbmDataType::kStsCluster, stscluster);
+    compareEventMap(test, 2, 0, ECbmDataType::kStsHit, stshit);
+    compareEventMap(test, 2, 0, ECbmDataType::kStsTrack, ststrack);
   }
 
   uint32_t retValUInt = test.GetIndex(ECbmDataType::kMCTrack, 25);
@@ -167,10 +167,10 @@ TEST(_GTestCbmEvent, CheckAddData)
     compareEventDataMembers(test, -111, 1., 2., 3, nullptr, nullptr);
     compareEventMap(test, 3, 2, ECbmDataType::kMCTrack, mctrack);
     compareEventMap(test, 3, 1, ECbmDataType::kStsPoint, stspoint);
-    compareEventMap(test, 3, -1, ECbmDataType::kStsDigi, stsdigi);
-    compareEventMap(test, 3, -1, ECbmDataType::kStsCluster, stscluster);
-    compareEventMap(test, 3, -1, ECbmDataType::kStsHit, stshit);
-    compareEventMap(test, 3, -1, ECbmDataType::kStsTrack, ststrack);
+    compareEventMap(test, 3, 0, ECbmDataType::kStsDigi, stsdigi);
+    compareEventMap(test, 3, 0, ECbmDataType::kStsCluster, stscluster);
+    compareEventMap(test, 3, 0, ECbmDataType::kStsHit, stshit);
+    compareEventMap(test, 3, 0, ECbmDataType::kStsTrack, ststrack);
   }
 
   stsdigi.push_back(2);
@@ -181,9 +181,9 @@ TEST(_GTestCbmEvent, CheckAddData)
     compareEventMap(test, 4, 2, ECbmDataType::kMCTrack, mctrack);
     compareEventMap(test, 4, 1, ECbmDataType::kStsPoint, stspoint);
     compareEventMap(test, 4, 1, ECbmDataType::kStsDigi, stsdigi);
-    compareEventMap(test, 4, -1, ECbmDataType::kStsCluster, stscluster);
-    compareEventMap(test, 4, -1, ECbmDataType::kStsHit, stshit);
-    compareEventMap(test, 4, -1, ECbmDataType::kStsTrack, ststrack);
+    compareEventMap(test, 4, 0, ECbmDataType::kStsCluster, stscluster);
+    compareEventMap(test, 4, 0, ECbmDataType::kStsHit, stshit);
+    compareEventMap(test, 4, 0, ECbmDataType::kStsTrack, ststrack);
   }
 
   stscluster.push_back(3);
@@ -195,8 +195,8 @@ TEST(_GTestCbmEvent, CheckAddData)
     compareEventMap(test, 5, 1, ECbmDataType::kStsPoint, stspoint);
     compareEventMap(test, 5, 1, ECbmDataType::kStsDigi, stsdigi);
     compareEventMap(test, 5, 1, ECbmDataType::kStsCluster, stscluster);
-    compareEventMap(test, 5, -1, ECbmDataType::kStsHit, stshit);
-    compareEventMap(test, 5, -1, ECbmDataType::kStsTrack, ststrack);
+    compareEventMap(test, 5, 0, ECbmDataType::kStsHit, stshit);
+    compareEventMap(test, 5, 0, ECbmDataType::kStsTrack, ststrack);
   }
 
   stshit.push_back(4);
@@ -209,7 +209,7 @@ TEST(_GTestCbmEvent, CheckAddData)
     compareEventMap(test, 6, 1, ECbmDataType::kStsDigi, stsdigi);
     compareEventMap(test, 6, 1, ECbmDataType::kStsCluster, stscluster);
     compareEventMap(test, 6, 1, ECbmDataType::kStsHit, stshit);
-    compareEventMap(test, 6, -1, ECbmDataType::kStsTrack, ststrack);
+    compareEventMap(test, 6, 0, ECbmDataType::kStsTrack, ststrack);
   }
 
   ststrack.push_back(5);
diff --git a/reco/L1/CbmL1ReadEvent.cxx b/reco/L1/CbmL1ReadEvent.cxx
index 6a616ba207..dbc60d7073 100644
--- a/reco/L1/CbmL1ReadEvent.cxx
+++ b/reco/L1/CbmL1ReadEvent.cxx
@@ -169,11 +169,11 @@ void CbmL1::ReadEvent(CbmEvent* event)
   {  // reserve enough space for hits
     int nHitsTotal = 0;
     if (event) {  // be careful: GetNofData() can return -1
-      if (fUseMVD && fpMvdHits) { nHitsTotal += std::max(event->GetNofData(ECbmDataType::kMvdHit), 0); }
-      if (fUseSTS && fpStsHits) { nHitsTotal += std::max(event->GetNofData(ECbmDataType::kStsHit), 0); }
-      if (fUseMUCH && fpMuchPixelHits) { nHitsTotal += std::max(event->GetNofData(ECbmDataType::kMuchPixelHit), 0); }
-      if (fUseTRD && fpTrdHits) { nHitsTotal += std::max(event->GetNofData(ECbmDataType::kTrdHit), 0); }
-      if (fUseTOF && fpTofHits) { nHitsTotal += std::max(event->GetNofData(ECbmDataType::kTofHit), 0); }
+      if (fUseMVD && fpMvdHits) { nHitsTotal += event->GetNofData(ECbmDataType::kMvdHit); }
+      if (fUseSTS && fpStsHits) { nHitsTotal += event->GetNofData(ECbmDataType::kStsHit); }
+      if (fUseMUCH && fpMuchPixelHits) { nHitsTotal += event->GetNofData(ECbmDataType::kMuchPixelHit); }
+      if (fUseTRD && fpTrdHits) { nHitsTotal += event->GetNofData(ECbmDataType::kTrdHit); }
+      if (fUseTOF && fpTofHits) { nHitsTotal += event->GetNofData(ECbmDataType::kTofHit); }
     }
     else {
       if (fUseMVD && fpMvdHits) { nHitsTotal += fpMvdHits->GetEntriesFast(); }
diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmAerogelAna.cxx b/reco/detectors/rich/mcbm/CbmRichMCbmAerogelAna.cxx
index c2896a2c58..8c643852ae 100644
--- a/reco/detectors/rich/mcbm/CbmRichMCbmAerogelAna.cxx
+++ b/reco/detectors/rich/mcbm/CbmRichMCbmAerogelAna.cxx
@@ -204,7 +204,7 @@ void CbmRichMCbmAerogelAna::Exec(Option_t* /*option*/)
     std::vector<int> evRichHitIndx;
 
 
-    for (int j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
+    for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
       auto iRichHit = ev->GetIndex(ECbmDataType::kRichHit, j);
       evRichHitIndx.push_back(iRichHit);
 
@@ -235,7 +235,7 @@ void CbmRichMCbmAerogelAna::Exec(Option_t* /*option*/)
 
     if (ringIndx.size() > 0) {  // Ring in CbmEvent
       //loop over all Hits in a CbmEvent with Ring:
-      for (int j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
+      for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
         auto iRichHit       = ev->GetIndex(ECbmDataType::kRichHit, j);
         CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
         fHM->H1("fhEventRichHitToT")->Fill(richHit->GetToT());
diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmQaReal.cxx b/reco/detectors/rich/mcbm/CbmRichMCbmQaReal.cxx
index 3ee44e81b8..b7e93adc98 100644
--- a/reco/detectors/rich/mcbm/CbmRichMCbmQaReal.cxx
+++ b/reco/detectors/rich/mcbm/CbmRichMCbmQaReal.cxx
@@ -740,7 +740,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
 
   for (int i = 0; i < fNCbmEvent; i++) {
     CbmEvent* ev = static_cast<CbmEvent*>(fCbmEvent->At(i));
-    if (fTriggerRichHits != 0 && (ev->GetNofData(ECbmDataType::kRichHit) < fTriggerRichHits)) continue;
+    if (fTriggerRichHits != 0 && (Int_t(ev->GetNofData(ECbmDataType::kRichHit)) < fTriggerRichHits)) continue;
     fHM->H1("fhNofCbmEvents")->Fill(1);
     //if (fTriggerTofHits != 0 && (ev->GetNofData(ECbmDataType::kTofHit) < fTriggerTofHits)) continue;
 
@@ -766,7 +766,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
 
     fHM->H1("fhT0DigiMultiplicity")->Fill(ev->GetNofData(ECbmDataType::kT0Digi));
     //std::cout<<ev->GetNofData(ECbmDataType::kT0Digi)<<std::endl;
-    for (int j = 0; j < ev->GetNofData(ECbmDataType::kT0Digi); j++) {
+    for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kT0Digi); j++) {
       auto iT0Digi             = ev->GetIndex(ECbmDataType::kT0Digi, j);
       const CbmTofDigi* T0Digi = nullptr;
       if (fT0Digis) T0Digi = &(fT0Digis->at(iT0Digi));
@@ -792,7 +792,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
 
     Double_t meanRichHitTime = 0.;
     if (fDoTimePlots) {
-      for (int j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
+      for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
         auto iRichHit       = ev->GetIndex(ECbmDataType::kRichHit, j);
         CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
         meanRichHitTime += richHit->GetTime();
@@ -800,7 +800,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
       if (ev->GetNofData(ECbmDataType::kRichHit) > 0) meanRichHitTime /= ev->GetNofData(ECbmDataType::kRichHit);
 
       Double_t meanTofHitTime = 0.;
-      for (int j = 0; j < ev->GetNofData(ECbmDataType::kTofHit); j++) {
+      for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kTofHit); j++) {
         auto iTofHit      = ev->GetIndex(ECbmDataType::kTofHit, j);
         CbmTofHit* tofHit = static_cast<CbmTofHit*>(fTofHits->At(iTofHit));
         meanTofHitTime += tofHit->GetTime();
@@ -812,7 +812,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
       fHM->H1("fhHitTimeMeanRichHitVsMeanTof")->Fill(meanRichHitTime - meanTofHitTime);
     }
 
-    for (int j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
+    for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
       auto iRichHit = ev->GetIndex(ECbmDataType::kRichHit, j);
       evRichHitIndx.push_back(iRichHit);
       CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
@@ -861,7 +861,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
         }
       }
 
-      for (int k = 0; k < ev->GetNofData(ECbmDataType::kTofHit); k++) {
+      for (size_t k = 0; k < ev->GetNofData(ECbmDataType::kTofHit); k++) {
         auto iTofHit      = ev->GetIndex(ECbmDataType::kTofHit, k);
         CbmTofHit* tofHit = static_cast<CbmTofHit*>(fTofHits->At(iTofHit));
         if (tofHit->GetTime() < startTime) { startTime = tofHit->GetTime(); /* flagRich = 0;*/ }
@@ -941,7 +941,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
     auto noftofTracks = ev->GetNofData(ECbmDataType::kTofTrack);
     fHM->H1("fhTofTracksPerEvent")->Fill(noftofTracks);
 
-    for (int j = 0; j < noftofTracks; j++) {
+    for (size_t j = 0; j < noftofTracks; j++) {
       auto iTofTrack         = ev->GetIndex(ECbmDataType::kTofTrack, j);
       CbmTofTracklet* tTrack = static_cast<CbmTofTracklet*>(fTofTracks->At(iTofTrack));
       if (tTrack == nullptr) continue;
@@ -958,7 +958,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
         //Track in  RICH
         fTracksinRich++;
         Int_t goodHit = 0;
-        for (int k = 0; k < ev->GetNofData(ECbmDataType::kRichHit); k++) {
+        for (size_t k = 0; k < ev->GetNofData(ECbmDataType::kRichHit); k++) {
           auto iRichHit       = ev->GetIndex(ECbmDataType::kRichHit, k);
           CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
           if (richHit == nullptr) continue;
@@ -1043,7 +1043,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
 
     std::vector<TVector3> RichTofEv;
 
-    for (int j = 0; j < ev->GetNofData(ECbmDataType::kTofHit); j++) {
+    for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kTofHit); j++) {
       auto iTofHit      = ev->GetIndex(ECbmDataType::kTofHit, j);
       CbmTofHit* tofHit = static_cast<CbmTofHit*>(fTofHits->At(iTofHit));
       if (tofHit->GetZ() < 2.) continue;  // Cut T0 away!
@@ -1077,7 +1077,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
       //TRACKS
       auto nofTofTracks = ev->GetNofData(ECbmDataType::kTofTrack);
       fHM->H1("fhTofTracksPerRichEvent")->Fill(nofTofTracks);
-      for (int j = 0; j < nofTofTracks; j++) {
+      for (size_t j = 0; j < nofTofTracks; j++) {
         auto iTofTrack        = ev->GetIndex(ECbmDataType::kTofTrack, j);
         CbmTofTracklet* track = static_cast<CbmTofTracklet*>(fTofTracks->At(iTofTrack));
         if (track == nullptr) continue;
@@ -1085,7 +1085,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
         TracksOfEvnt.emplace_back(track);
         if (!isOnTarget(track)) continue;
         fHM->H2("fhTofTrackRichRingXY")->Fill(track->GetFitX(RichZPos), track->GetFitY(RichZPos));
-        for (int k = 0; k < ev->GetNofData(ECbmDataType::kRichHit); k++) {
+        for (size_t k = 0; k < ev->GetNofData(ECbmDataType::kRichHit); k++) {
           auto iRichHit       = ev->GetIndex(ECbmDataType::kRichHit, k);
           CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
           if (richHit == nullptr) continue;
@@ -1168,7 +1168,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
         auto clTrack = FindClosestTrack(ring, TracksOfEvnt);  // has no cut on distance
         analyseRing(ring, ev, clTrack);
 
-        for (int j = 0; j < nofTofTracks; j++) {
+        for (size_t j = 0; j < nofTofTracks; j++) {
           auto iTofTrack        = ev->GetIndex(ECbmDataType::kTofTrack, j);
           CbmTofTracklet* track = static_cast<CbmTofTracklet*>(fTofTracks->At(iTofTrack));
           if (track == nullptr) continue;
@@ -1261,7 +1261,7 @@ void CbmRichMCbmQaReal::Exec(Option_t* /*option*/)
         double xBlob = -7.95 + (int((j / 9)) * 5.3) + fXOffsetHisto;
         double yBlob = 21.2 - ((j % 9) * 5.3);
         //std::cout<<"BLOB X:" << i << "   "<< xBlob << std::endl;
-        for (int k = 0; k < ev->GetNofData(ECbmDataType::kTofTrack); k++) {
+        for (size_t k = 0; k < ev->GetNofData(ECbmDataType::kTofTrack); k++) {
           auto iTofTrack        = ev->GetIndex(ECbmDataType::kTofTrack, k);
           CbmTofTracklet* track = static_cast<CbmTofTracklet*>(fTofTracks->At(iTofTrack));
           if (track == nullptr) continue;
@@ -1358,9 +1358,9 @@ std::pair<int, double> CbmRichMCbmQaReal::FindClosestRing(CbmTofTracklet* track,
     int ringY = ring->GetCenterY();
 
     //Calc if Track is in Ring (+20% )
-    const double xDist        = (x_track - ringX);
-    const double yDist        = (y_track - ringY);
-    const double rDist        = std::sqrt(xDist * xDist + yDist * yDist);
+    const double xDist = (x_track - ringX);
+    const double yDist = (y_track - ringY);
+    const double rDist = std::sqrt(xDist * xDist + yDist * yDist);
     //const double RadiusFactor = 1.2;  // Factor of how big radius of acceptance should
 
     if (/*rDist < ring->GetRadius() * RadiusFactor &&*/ cutRadius(ring)) {
@@ -2656,7 +2656,7 @@ void CbmRichMCbmQaReal::analyseRing(const CbmRichRing* ring, CbmEvent* ev, std::
 
   int InnerHitCnt     = 0;
   int InnerHitCnt_cut = 0;
-  for (int j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
+  for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
     auto iRichHit       = ev->GetIndex(ECbmDataType::kRichHit, j);
     CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
     if (nullptr == richHit) continue;
diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmQaRichOnly.cxx b/reco/detectors/rich/mcbm/CbmRichMCbmQaRichOnly.cxx
index 01c1d1902b..ae45f46e95 100644
--- a/reco/detectors/rich/mcbm/CbmRichMCbmQaRichOnly.cxx
+++ b/reco/detectors/rich/mcbm/CbmRichMCbmQaRichOnly.cxx
@@ -226,7 +226,7 @@ void CbmRichMCbmQaRichOnly::Exec(Option_t* /*option*/)
     fHM->H1("fhNofCbmEvents")->Fill(1);
     CbmEvent* ev = static_cast<CbmEvent*>(fCbmEvent->At(i));
 
-    if (fTriggerRichHits != 0 && (ev->GetNofData(ECbmDataType::kRichHit) < fTriggerRichHits)) continue;
+    if (fTriggerRichHits != 0 && (Int_t(ev->GetNofData(ECbmDataType::kRichHit)) < fTriggerRichHits)) continue;
 
 
     std::vector<int> ringIndx;
@@ -236,7 +236,7 @@ void CbmRichMCbmQaRichOnly::Exec(Option_t* /*option*/)
       a = 0;
 
     // Map Rings to CbmEvent
-    for (int j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
+    for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
       auto iRichHit = ev->GetIndex(ECbmDataType::kRichHit, j);
       evRichHitIndx.push_back(iRichHit);
       CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
@@ -707,7 +707,7 @@ void CbmRichMCbmQaRichOnly::analyseRing(CbmRichRing* ring, CbmEvent* ev)
 
   int InnerHitCnt     = 0;
   int InnerHitCnt_cut = 0;
-  for (int j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
+  for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
     auto iRichHit       = ev->GetIndex(ECbmDataType::kRichHit, j);
     CbmRichHit* richHit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
     if (nullptr == richHit) continue;
diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmSEDisplay.cxx b/reco/detectors/rich/mcbm/CbmRichMCbmSEDisplay.cxx
index 07cc3ac411..7978cfa701 100644
--- a/reco/detectors/rich/mcbm/CbmRichMCbmSEDisplay.cxx
+++ b/reco/detectors/rich/mcbm/CbmRichMCbmSEDisplay.cxx
@@ -203,7 +203,7 @@ void CbmRichMCbmSEDisplay::DrawEvent(CbmEvent* ev, std::vector<int>& ringIndx, b
   uint nofDrawHits = 0;
 
   // ---- Draw Rich Hits -----------------------------------------------------------
-  for (int j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
+  for (size_t j = 0; j < ev->GetNofData(ECbmDataType::kRichHit); j++) {
     auto iRichHit   = ev->GetIndex(ECbmDataType::kRichHit, j);
     CbmRichHit* hit = static_cast<CbmRichHit*>(fRichHits->At(iRichHit));
     if (nullptr == hit) continue;
@@ -257,7 +257,7 @@ void CbmRichMCbmSEDisplay::DrawEvent(CbmEvent* ev, std::vector<int>& ringIndx, b
 
   // ---- Draw Tracks in RICH Plane ------------------------------------------------
   auto nofTofTracks = ev->GetNofData(ECbmDataType::kTofTrack);
-  for (int j = 0; j < nofTofTracks; j++) {
+  for (size_t j = 0; j < nofTofTracks; j++) {
     auto iTofTrack        = ev->GetIndex(ECbmDataType::kTofTrack, j);
     CbmTofTracklet* track = static_cast<CbmTofTracklet*>(fTofTracks->At(iTofTrack));
     if (nullptr == track) continue;
diff --git a/reco/detectors/trd/CbmTrdClusterFinder.cxx b/reco/detectors/trd/CbmTrdClusterFinder.cxx
index 6fbd1cc512..96990f7ff4 100644
--- a/reco/detectors/trd/CbmTrdClusterFinder.cxx
+++ b/reco/detectors/trd/CbmTrdClusterFinder.cxx
@@ -106,7 +106,7 @@ UInt_t CbmTrdClusterFinder::addDigisToModules()
 // ---- addDigisToModules ----
 UInt_t CbmTrdClusterFinder::addDigisToModules(CbmEvent* event)
 {
-  UInt_t ndigis = static_cast<UInt_t>(std::abs(event->GetNofData(ECbmDataType::kTrdDigi)));
+  UInt_t ndigis = static_cast<UInt_t>(event->GetNofData(ECbmDataType::kTrdDigi));
   if (ndigis == 0) return 0;
   for (size_t idigi = 0; idigi < ndigis; idigi++) {
     auto digiindex = event->GetIndex(ECbmDataType::kTrdDigi, idigi);
diff --git a/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.cxx b/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.cxx
index dee887ec98..1d990db2db 100644
--- a/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.cxx
+++ b/reco/eventbuilder/digis/CbmAlgoBuildRawEvents.cxx
@@ -1228,7 +1228,7 @@ void CbmAlgoBuildRawEvents::FillHistos()
     for (UInt_t uDetIdx = 0; uDetIdx < fvDets.size(); ++uDetIdx) {
       if (nullptr == fvhNbDigiPerEvtDet[uDetIdx]) continue;
 
-      for (int idigi = 0; idigi < evt->GetNofData(fvDets[uDetIdx].dataType); ++idigi) {
+      for (size_t idigi = 0; idigi < evt->GetNofData(fvDets[uDetIdx].dataType); ++idigi) {
         double dTimeDiff = 1.E30;
         uint idx         = evt->GetIndex(fvDets[uDetIdx].dataType, idigi);
         switch (fvDets[uDetIdx].dataType) {
@@ -1299,7 +1299,7 @@ void CbmAlgoBuildRawEvents::FillHistos()
     /// Reference detector
     if (ECbmModuleId::kNotExist != fRefDet.detId) {
       if (nullptr != fvhNbDigiPerEvtDet[uRefDetIdx]) {
-        for (int idigi = 0; idigi < evt->GetNofData(fRefDet.dataType); ++idigi) {
+        for (size_t idigi = 0; idigi < evt->GetNofData(fRefDet.dataType); ++idigi) {
           double dTimeDiff = 1.E30;
           uint idx         = evt->GetIndex(fRefDet.dataType, idigi);
           switch (fRefDet.dataType) {
@@ -1389,14 +1389,12 @@ void CbmAlgoBuildRawEvents::FillHistos()
         fvhNbDigiPerEvtTimeDet[uDetIdx]->Fill(evt->GetStartTime() * 1e-9, uNbDataTrd2d);
       }
       else {
-        fvhNbDigiPerEvtDet[uDetIdx]->Fill(TMath::Max(0, evt->GetNofData(fvDets[uDetIdx].dataType)));
-        fvhNbDigiPerEvtTimeDet[uDetIdx]->Fill(evt->GetStartTime() * 1e-9,
-                                              TMath::Max(0, evt->GetNofData(fvDets[uDetIdx].dataType)));
+        fvhNbDigiPerEvtDet[uDetIdx]->Fill(evt->GetNofData(fvDets[uDetIdx].dataType));
+        fvhNbDigiPerEvtTimeDet[uDetIdx]->Fill(evt->GetStartTime() * 1e-9, evt->GetNofData(fvDets[uDetIdx].dataType));
 
         if (0 < GetNofDigis(fvDets[uDetIdx].detId)) {
           /// Selection ratio
-          uint64_t ulDigiSizeOut =
-            GetSizeFromDigisNb(fvDets[uDetIdx].detId, TMath::Max(0, evt->GetNofData(fvDets[uDetIdx].dataType)));
+          uint64_t ulDigiSizeOut = GetSizeFromDigisNb(fvDets[uDetIdx].detId, evt->GetNofData(fvDets[uDetIdx].dataType));
 
           ulTotalOutputSize += ulDigiSizeOut;
           vulTotalOutputSizeDet[uDetIdx] += ulDigiSizeOut;
@@ -1423,13 +1421,12 @@ void CbmAlgoBuildRawEvents::FillHistos()
         fvhNbDigiPerEvtTimeDet[uRefDetIdx]->Fill(evt->GetStartTime() * 1e-9, uNbDataTrd2d);
       }
       else {
-        fvhNbDigiPerEvtDet[uRefDetIdx]->Fill(TMath::Max(0, evt->GetNofData(fRefDet.dataType)));
-        fvhNbDigiPerEvtTimeDet[uRefDetIdx]->Fill(evt->GetStartTime() * 1e-9,
-                                                 TMath::Max(0, evt->GetNofData(fRefDet.dataType)));
+        fvhNbDigiPerEvtDet[uRefDetIdx]->Fill(evt->GetNofData(fRefDet.dataType));
+        fvhNbDigiPerEvtTimeDet[uRefDetIdx]->Fill(evt->GetStartTime() * 1e-9, evt->GetNofData(fRefDet.dataType));
 
         if (0 < GetNofDigis(fRefDet.detId)) {
           /// Selection ratio
-          uint64_t ulDigiSizeOut = GetSizeFromDigisNb(fRefDet.detId, TMath::Max(0, evt->GetNofData(fRefDet.dataType)));
+          uint64_t ulDigiSizeOut = GetSizeFromDigisNb(fRefDet.detId, evt->GetNofData(fRefDet.dataType));
 
           ulTotalOutputSize += ulDigiSizeOut;
           vulTotalOutputSizeDet[uRefDetIdx] += ulDigiSizeOut;
diff --git a/reco/eventbuilder/tracks/CbmEventBuilderQa.cxx b/reco/eventbuilder/tracks/CbmEventBuilderQa.cxx
index 4c54d22be7..c53e565ac7 100644
--- a/reco/eventbuilder/tracks/CbmEventBuilderQa.cxx
+++ b/reco/eventbuilder/tracks/CbmEventBuilderQa.cxx
@@ -585,7 +585,7 @@ void CbmEventBuilderQa::Exec(Option_t* /*opt*/)
     CbmEvent* event = Ev[k].Event;  //(CbmEvent*) fEvents->At(k);
 
     int iCol = k % 5;
-    for (int i = 0; i < event->GetNofData(ECbmDataType::kStsTrack); i++) {
+    for (size_t i = 0; i < event->GetNofData(ECbmDataType::kStsTrack); i++) {
       const int stsTrackIndex = event->GetStsTrackIndex(i);
       CbmStsTrack* track      = (CbmStsTrack*) fStsTracks->At(stsTrackIndex);
 
-- 
GitLab