From e42da2ccf6930f962fe158b8b9dbd7bee183d3c3 Mon Sep 17 00:00:00 2001
From: sgorbuno <se.gorbunov@gsi.de>
Date: Mon, 26 Jul 2021 15:34:19 +0000
Subject: [PATCH] L1: bugfix in identifying the presence of unprocessed data

---
 reco/L1/CbmL1.cxx          | 34 +++++++++++++++++-----------------
 reco/L1/CbmL1.h            |  6 +++---
 reco/L1/CbmL1ReadEvent.cxx | 12 ++++++++----
 3 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index 7552866588..df491c40bf 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -1045,11 +1045,11 @@ void CbmL1::Reconstruct(CbmEvent* event)
 
   float start_t = 10000000000;
 
-  bool newTS      = 1;      // whole TS processed?
-  float TsStart   = 0;      // starting time of sub-TS
-  float TsLength  = 10000;  // length of sub-TS
-  float TsOverlap = 15;     // min length of overlap region
-  int FstHitinTs  = 0;      // 1st hit index in TS
+  bool areDataLeft = true;   // whole TS processed?
+  float TsStart    = 0;      // starting time of sub-TS
+  float TsLength   = 10000;  // length of sub-TS
+  float TsOverlap  = 15;     // min length of overlap region
+  int FstHitinTs   = 0;      // 1st hit index in TS
 
   /// sort input hits by time
   for (Int_t j = 0; j < listStsHits->GetEntriesFast(); j++) {
@@ -1110,7 +1110,7 @@ void CbmL1::Reconstruct(CbmEvent* event)
 
   fTrackingTime = 0;
 
-  while (newTS) {
+  while (areDataLeft) {
 
     fData->Clear();
 
@@ -1118,11 +1118,11 @@ void CbmL1::Reconstruct(CbmEvent* event)
 
       fData->fStripFlag.clear();
 
-      newTS      = 0;
-      TsStart    = 0;
-      TsLength   = 2000000000;
-      TsOverlap  = 0;
-      FstHitinTs = 0;
+      areDataLeft = false;
+      TsStart     = 0;
+      TsLength    = 2000000000;
+      TsOverlap   = 0;
+      FstHitinTs  = 0;
     }
 
     if (fSTAPDataMode >= 2) {  // 2,3
@@ -1132,7 +1132,7 @@ void CbmL1::Reconstruct(CbmEvent* event)
                     fData->GetStsHitsStopIndex());
     }
     else {
-      ReadEvent(fData, TsStart, TsLength, TsOverlap, FstHitinTs, newTS, event);
+      ReadEvent(fData, TsStart, TsLength, TsOverlap, FstHitinTs, areDataLeft, event);
     }
 
     if (0) {  // correct hits on MC // dbg
@@ -1177,9 +1177,9 @@ void CbmL1::Reconstruct(CbmEvent* event)
         u += 3.5 * sqrt(sta.frontInfo.sigma2)[0] * random.Uniform(-1, 1);
         v += 3.5 * sqrt(sta.backInfo.sigma2)[0] * random.Uniform(-1, 1);
 #endif
-        h.u                                         = u;
-        h.v                                         = v;
-        h.z                                         = mcp.z;
+        h.u = u;
+        h.v = v;
+        h.z = mcp.z;
       }
     }
 
@@ -1901,8 +1901,8 @@ void CbmL1::ReadSTAPAlgoData()
     for (int i = 0; i < n; i++) {
       L1Hit element;
       fadata >> element_f >> element_b >> element_n >> element.z >> element.u >> element.v >> element.t;
-      element.f  = static_cast<THitI>(element_f);
-      element.b  = static_cast<THitI>(element_b);
+      element.f = static_cast<THitI>(element_f);
+      element.b = static_cast<THitI>(element_b);
       algo->vStsHits->push_back(element);
     }
     if (fVerbose >= 4) {
diff --git a/reco/L1/CbmL1.h b/reco/L1/CbmL1.h
index a2eec04e3c..a2efa047f3 100644
--- a/reco/L1/CbmL1.h
+++ b/reco/L1/CbmL1.h
@@ -186,8 +186,8 @@ private:
 
   /// Read information about hits, mcPoints and mcTracks into L1 classes
 
-  void ReadEvent(L1AlgoInputData* fData_, float& fTsStart, float& fTsLength, float& fTsOverlap, int& fFstHitinTs,
-                 bool& fnewTS, CbmEvent* event = NULL);
+  void ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength, float& TsOverlap, int& FstHitinTs,
+                 bool& areDataLeft, CbmEvent* event = NULL);
 
   bool ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int MVD);  // help procedure
   bool ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int MVD);
@@ -254,7 +254,7 @@ private:
   int NTrdStations {0};   // number of trd stations
   int NTOFStation {0};    // number of tof stations
 
-  Int_t fPerformance {0};  // 0 - w\o perf. 1 - L1-Efficiency definition. 2 - QA-Eff.definition
+  Int_t fPerformance {0};     // 0 - w\o perf. 1 - L1-Efficiency definition. 2 - QA-Eff.definition
   double fTrackingTime {0.};  // time of track finding
 
   int fSTAPDataMode {0};  // way to work with file for standalone package.
diff --git a/reco/L1/CbmL1ReadEvent.cxx b/reco/L1/CbmL1ReadEvent.cxx
index decfe7d2b3..2566b451bd 100644
--- a/reco/L1/CbmL1ReadEvent.cxx
+++ b/reco/L1/CbmL1ReadEvent.cxx
@@ -81,10 +81,12 @@ struct TmpHit {  // used for sort Hits before writing in the normal arrays
 
 /// Repack data from Clones Arrays to L1 arrays
 void CbmL1::ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength, float& /*TsOverlap*/, int& FstHitinTs,
-                      bool& newTS, CbmEvent* event)
+                      bool& areDataLeft, CbmEvent* event)
 {
   if (fVerbose >= 10) cout << "ReadEvent: start." << endl;
 
+  areDataLeft = false;  // no data left after reading the sub-timeslice
+
   fData_->Clear();
 
   // clear arrays for next event
@@ -505,9 +507,11 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength,
         else
           th.id = tmpHits.size();
 
-        if ((th.time > (TsStart + TsLength)) && ((nEntSts - hitIndex) > 300))
-          break;                                   /// stop if reco TS ends or few hits left
-        if (hitIndex == (nEntSts - 1)) newTS = 0;  ///stop while if all hits are processed
+        /// stop if reco TS ends and many hits left
+        if ((th.time > (TsStart + TsLength)) && ((nEntSts - hitIndex) > 300)) {
+          areDataLeft = true;  // there are unprocessed data left in the time slice
+          break;
+        }
 
         TVector3 pos, err;
         mh->Position(pos);
-- 
GitLab