From 263022d7ff0620f9ffe35f190ffaac7eb0424f1b Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Fri, 5 Apr 2024 19:50:15 +0200
Subject: [PATCH] ca: terminating track finder routine, if the input data
 contain no hits

---
 algo/ca/core/tracking/CaTrackFinder.cxx | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/algo/ca/core/tracking/CaTrackFinder.cxx b/algo/ca/core/tracking/CaTrackFinder.cxx
index 695dabeaef..7884a02050 100644
--- a/algo/ca/core/tracking/CaTrackFinder.cxx
+++ b/algo/ca/core/tracking/CaTrackFinder.cxx
@@ -46,6 +46,13 @@ TrackFinder::~TrackFinder() {}
 //
 void TrackFinder::FindTracks()
 {
+  frAlgo.fRecoTracks.clear();
+  frAlgo.fRecoHits.clear();
+  if (frAlgo.GetInputData().GetNhits() < 1) {
+    LOG(warn) << "No hits were passed to the ca::TrackFinder. Stopping the routine";
+    return;
+  }
+
   //
   // The main CaTrackFinder routine
   // It splits the input data into sub-timeslices
@@ -182,24 +189,29 @@ void TrackFinder::FindTracks()
 
 
   if (fStatTsEnd < fStatTsStart) {  // all hits belong to one sub-timeslice
-                                    // statTsEnd = statTsStart;
+    fStatTsEnd = fStatTsStart;
   }
 
   if (fStatTsEnd > fStatTsStart + 500.e6) {  // 500 ms maximal length of the TS
     fStatTsEnd = fStatTsStart + 500.e6;
   }
 
-  LOG(info) << "CA tracker process time slice " << fStatTsStart / 1.e6 << " ms ... " << fStatTsEnd / 1.e6 << " ms with "
+  LOG(info) << "CA tracker process time slice " << fStatTsStart * 1.e-6 << " -- " << fStatTsEnd * 1.e-6 << " [ms] with "
             << fStatNhitsTotal << " hits";
 
   int nWindows = static_cast<int>((fStatTsEnd - fStatTsStart - fWindowOverlap - fWindowMargin)
                                   / (fWindowLength - fWindowOverlap - fWindowMargin))
                  + 1;
+  if (nWindows < 1) {  // Situation, when fStatTsEnd == fStatTsStart
+    nWindows = 1;
+  }
+
   int nWindowsThread = nWindows / frAlgo.GetNofThreads();
   float windowDelta  = fWindowLength - fWindowOverlap - fWindowMargin;
   //LOG(info) << "CA: estimated number of time windows: " << nWindows;
 
 
+  fvWindowStartThread[0] = fStatTsStart;
   {  // Estimation of number of hits in time windows
     //Timer time;
     //time.Start();
@@ -247,7 +259,6 @@ void TrackFinder::FindTracks()
     HitIndex_t nHitsPerThread = nHitsCollected / frAlgo.GetNofThreads();
     auto windowIt             = nHitsWindow.begin();
     size_t iWbegin            = 0;
-    fvWindowStartThread[0]    = fStatTsStart;
     for (int iTh = 1; iTh < frAlgo.GetNofThreads(); ++iTh) {
       windowIt                   = std::lower_bound(windowIt, nHitsWindow.end(), iTh * nHitsPerThread);
       iWbegin                    = std::distance(nHitsWindow.begin(), windowIt) + 1;
@@ -277,8 +288,6 @@ void TrackFinder::FindTracks()
 
   frAlgo.fMonitorData.StopTimer(ETimer::PrepareTimeslice);
   // Save tracks
-  frAlgo.fRecoTracks.clear();
-  frAlgo.fRecoHits.clear();
   if (frAlgo.GetNofThreads() == 1) {
     this->FindTracksThread(0);
     frAlgo.fMonitorData.StartTimer(ETimer::StoreTracksFinal);
-- 
GitLab