From 9f003f325cbca85a10ba5736e1209fdfd8edb5c8 Mon Sep 17 00:00:00 2001
From: "se.gorbunov" <se.gorbunov@gsi.de>
Date: Thu, 20 Jul 2023 11:53:41 +0000
Subject: [PATCH] CA: automatically  sort detectors in Z

---
 reco/L1/CbmL1.cxx                  | 14 ++++++++++++--
 reco/L1/L1Algo/L1BaseStationInfo.h |  9 ++++++---
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index c9db466cb9..9b08602aab 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -609,6 +609,11 @@ InitStatus CbmL1::Init()
       }
     }
 
+    // ** Order stations in Z
+    {
+      std::sort(vStations.begin(), vStations.end());
+    }
+
     // ****************************************
     // **                                    **
     // ** Initialize material maps           **
@@ -651,8 +656,6 @@ InitStatus CbmL1::Init()
                   << " cm."
                   << " Material is collected between z = " << zLast << " and z = " << zNew;
 
-        fInitManager.AddStation(station);
-
         zLast = zNew;
       }
 
@@ -661,6 +664,13 @@ InitStatus CbmL1::Init()
       LOG(info) << "- Generating material maps tooks " << materialGenerationTime << " seconds";
     }
 
+    // ** Put stations to the init manager
+
+    for (unsigned int ist = 0; ist < vStations.size(); ist++) {
+      auto& station = vStations[ist];
+      fInitManager.AddStation(station);
+    }
+
     // ****************************************
     // **                                    **
     // ** TRACKING ITERATIONS INITIALIZATION **
diff --git a/reco/L1/L1Algo/L1BaseStationInfo.h b/reco/L1/L1Algo/L1BaseStationInfo.h
index 7eb6b37106..316c590d82 100644
--- a/reco/L1/L1Algo/L1BaseStationInfo.h
+++ b/reco/L1/L1Algo/L1BaseStationInfo.h
@@ -87,11 +87,14 @@ public:
   /// Move assignment operator
   L1BaseStationInfo& operator=(L1BaseStationInfo&& other) noexcept;
 
-  /// Less operator for L1BaseStationInfo object to perform sorts. Sorting is carried out first by fDetectorID,
-  /// and then by fStationID. The detectorID must be defined in L1DetectorID enum class
+  /// Less operator for L1BaseStationInfo object to sort stations in Z
   bool operator<(const L1BaseStationInfo& right) const
   {
-    return fDetectorID != right.fDetectorID ? fDetectorID < right.fDetectorID : fStationID < right.fStationID;
+    return (GetZdouble() < right.GetZdouble());
+
+    /// This way sorting is carried out first by fDetectorID,
+    /// and then by fStationID. The detectorID must be defined in L1DetectorID enum class
+    // return fDetectorID != right.fDetectorID ? fDetectorID < right.fDetectorID : fStationID < right.fStationID;
   }
 
   /// Gets detector ID
-- 
GitLab