From f66d29a7df811db85e2bb14103d2b29c12b464b8 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Thu, 19 May 2022 21:11:03 +0200
Subject: [PATCH] L1Algo: reorganised station number containers in
 L1InitManager

---
 reco/L1/CbmL1.cxx                        | 30 +++++++----
 reco/L1/CbmL1ReadEvent.cxx               | 14 ++---
 reco/L1/L1Algo/L1Algo.cxx                |  6 +--
 reco/L1/L1Algo/L1InitManager.cxx         | 65 ++++++++++++-----------
 reco/L1/L1Algo/L1InitManager.h           | 66 +++++++++++++++++-------
 reco/L1/L1Algo/L1Parameters.h            | 17 +++---
 reco/L1/ParticleFinder/CbmL1PFFitter.cxx |  6 +--
 7 files changed, 118 insertions(+), 86 deletions(-)

diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index 1b34c98b30..c610a6fee4 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -520,11 +520,11 @@ InitStatus CbmL1::Init()
   NStationGeom     = NMvdStationsGeom + NStsStationsGeom + NMuchStationsGeom + NTrdStationsGeom + NTOFStationGeom;
 
   // Provide crosscheck number of stations for the fpInitManagera
-  fpInitManager->SetNstationsCrosscheck(L1DetectorID::kMvd, NMvdStationsGeom);
-  fpInitManager->SetNstationsCrosscheck(L1DetectorID::kSts, NStsStationsGeom);
-  fpInitManager->SetNstationsCrosscheck(L1DetectorID::kMuch, NMuchStationsGeom);
-  fpInitManager->SetNstationsCrosscheck(L1DetectorID::kTrd, NTrdStationsGeom);
-  fpInitManager->SetNstationsCrosscheck(L1DetectorID::kTof, NTOFStationGeom);
+  fpInitManager->SetNstations(L1DetectorID::kMvd, NMvdStationsGeom);
+  fpInitManager->SetNstations(L1DetectorID::kSts, NStsStationsGeom);
+  fpInitManager->SetNstations(L1DetectorID::kMuch, NMuchStationsGeom);
+  fpInitManager->SetNstations(L1DetectorID::kTrd, NTrdStationsGeom);
+  fpInitManager->SetNstations(L1DetectorID::kTof, NTOFStationGeom);
 
   {
     if (fSTAPDataMode % 2 == 1) {  // 1,3
@@ -703,12 +703,20 @@ InitStatus CbmL1::Init()
 
   /*** Get numbers of active stations ***/
 
-  NMvdStations  = fpInitManager->GetNstations(L1DetectorID::kMvd);
-  NStsStations  = fpInitManager->GetNstations(L1DetectorID::kSts);
-  NTrdStations  = fpInitManager->GetNstations(L1DetectorID::kTrd);
-  NMuchStations = fpInitManager->GetNstations(L1DetectorID::kMuch);
-  NTOFStation   = fpInitManager->GetNstations(L1DetectorID::kTof);
-  NStation      = fpInitManager->GetNstations();
+  NMvdStations  = fpInitManager->GetNstationsActive(L1DetectorID::kMvd);
+  NStsStations  = fpInitManager->GetNstationsActive(L1DetectorID::kSts);
+  NTrdStations  = fpInitManager->GetNstationsActive(L1DetectorID::kTrd);
+  NMuchStations = fpInitManager->GetNstationsActive(L1DetectorID::kMuch);
+  NTOFStation   = fpInitManager->GetNstationsActive(L1DetectorID::kTof);
+  NStation      = fpInitManager->GetNstationsActive();
+
+  LOG(info) << "----- Numbers of stations active in tracking -----";
+  LOG(info) << "  MVD:    " << NMvdStations;
+  LOG(info) << "  STS:    " << NStsStations;
+  LOG(info) << "  MuCh:   " << NTrdStations;
+  LOG(info) << "  TRD:    " << NTrdStations;
+  LOG(info) << "  ToF:    " << NTOFStation;
+  LOG(info) << "  Total:  " << NStation;
 
   /****************************************
    **                                    **
diff --git a/reco/L1/CbmL1ReadEvent.cxx b/reco/L1/CbmL1ReadEvent.cxx
index abc81daae9..0d92e26026 100644
--- a/reco/L1/CbmL1ReadEvent.cxx
+++ b/reco/L1/CbmL1ReadEvent.cxx
@@ -514,7 +514,7 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength,
         th.id         = tmpHits.size();
         th.iStation   = mh->GetStationNr();
 
-        int stIdx = algo->GetInitManager()->GetActiveStationsIndexMap()[mh->GetStationNr()];
+        int stIdx = algo->GetInitManager()->GetStationIndexActive(mh->GetStationNr(), L1DetectorID::kMvd);
         if (stIdx == -1) continue;
         th.iStation = stIdx;  //mh->GetStationNr() - 1;
         th.iStripF  = firstDetStrip + j;
@@ -611,8 +611,7 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength,
         th.ExtIndex   = hitIndexSort;
         th.Det        = 1;
         int stIdx     = algo->GetInitManager()
-                      ->GetActiveStationsIndexMap()[CbmStsSetup::Instance()->GetStationNumber(mh->GetAddress())
-                                                    + NMvdStationsGeom];
+                      ->GetStationIndexActive(CbmStsSetup::Instance()->GetStationNumber(mh->GetAddress()), L1DetectorID::kSts);
 
         if (stIdx == -1) continue;
 
@@ -768,7 +767,7 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength,
 
         int DetId = stationNumber * 3 + layerNumber;
 
-        int stIdx = algo->GetInitManager()->GetActiveStationsIndexMap()[DetId + NMvdStationsGeom + NStsStationsGeom];
+        int stIdx = algo->GetInitManager()->GetStationIndexActive(DetId, L1DetectorID::kMuch);
         if (stIdx == -1) continue;
         th.iStation = stIdx;  //mh->GetStationNr() - 1;
 
@@ -868,9 +867,7 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength,
 
       int sta = mh->GetPlaneId();
 
-      int stIdx =
-        algo->GetInitManager()
-          ->GetActiveStationsIndexMap()[mh->GetPlaneId() + NMvdStationsGeom + NStsStationsGeom + NMuchStationsGeom];
+      int stIdx = algo->GetInitManager()->GetStationIndexActive(mh->GetPlaneId(), L1DetectorID::kTrd);
       if (stIdx == -1) continue;
 
       if ((fTrackingMode == L1Algo::TrackingMode::kMcbm) && (sta > 1) && (fMissingHits)) { sta = sta - 1; }
@@ -1057,8 +1054,7 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, float& TsStart, float& TsLength,
         if ((th.x > 20) && (th.z > 270) && (fTofDigiBdfPar->GetTrackingStation(mh) == 1)) sttof = 2;
       if (th.z > 400) continue;
 
-      int stIdx = algo->GetInitManager()->GetActiveStationsIndexMap()[sttof + NMvdStationsGeom + NStsStationsGeom
-                                                                      + NMuchStationsGeom + NTrdStationsGeom];
+      int stIdx = algo->GetInitManager()->GetStationIndexActive(sttof, L1DetectorID::kTof);
       if (stIdx == -1) continue;
       th.iStation = stIdx;
 
diff --git a/reco/L1/L1Algo/L1Algo.cxx b/reco/L1/L1Algo/L1Algo.cxx
index 60a4f47d19..1d1d4f40d3 100644
--- a/reco/L1/L1Algo/L1Algo.cxx
+++ b/reco/L1/L1Algo/L1Algo.cxx
@@ -78,8 +78,8 @@ void L1Algo::Init(const bool UseHitErrors, const TrackingMode mode, const bool M
 
 
   //int NMvdStations = static_cast<int>(geo[ind++]);  // TODO: get rid of NMbdStations (S. Zh.)
-  int nStationsSts     = fInitManager.GetNstations(static_cast<L1DetectorID>(1));
-  fNstationsBeforePipe = fInitManager.GetNstations(static_cast<L1DetectorID>(0));
+  int nStationsSts     = fInitManager.GetNstationsActive(static_cast<L1DetectorID>(1));
+  fNstationsBeforePipe = fInitManager.GetNstationsActive(static_cast<L1DetectorID>(0));
   //int NStsStations = static_cast<int>(geo[ind++]);  // TODO: get rid of NStsStations (S. Zh.)
 
   fNfieldStations = nStationsSts + fNstationsBeforePipe;  // TODO: Provide special getter for it (S.Zharko, 12.05.2022)
@@ -100,7 +100,7 @@ void L1Algo::Init(const bool UseHitErrors, const TrackingMode mode, const bool M
   fRealTargetZ = fInitManager.GetTargetPosition()[2];
 
   // Get number of station
-  fNstations = fInitManager.GetNstations();
+  fNstations = fInitManager.GetNstationsActive();
 
   // Get field near target
   fVtxFieldValue  = fInitManager.GetTargetFieldValue();
diff --git a/reco/L1/L1Algo/L1InitManager.cxx b/reco/L1/L1Algo/L1InitManager.cxx
index ea4fb6978f..33ec18aced 100644
--- a/reco/L1/L1Algo/L1InitManager.cxx
+++ b/reco/L1/L1Algo/L1InitManager.cxx
@@ -24,7 +24,6 @@ void L1InitManager::AddStation(const L1BaseStationInfo& inStation)
 {
   // Check if other fields were defined already
   // Active detector IDs
-
   L1MASSERT(0, fInitController.GetFlag(EInitKey::kActiveDetectorIDs),
             "Attempt to add a station info before the active detetors set had been initialized");
 
@@ -65,11 +64,16 @@ void L1InitManager::AddStation(const L1BaseStationInfo& inStation)
               << ")";
       L1MASSERT(0, insertionResult.second, aStream.str().c_str());
     }
-    fActiveStationsIndexMap.push_back(fStationsInfo.size() - 1);
+    int index = fStationsInfo.size() - 1 + 
+      (fNstationsGeometry[fNstationsGeometry.size() - 1] - fNstationsActive[fNstationsActive.size() - 1]);
+    fActiveStationGlobalIDs[index] = fStationsInfo.size() - 1;
   }
   else {
-    fActiveStationsIndexMap.push_back(-1);
-    fNstationsActiveCrosscheck[inStation.GetDetectorID()]--;
+    int index = fStationsInfo.size() + 
+      (fNstationsGeometry[fNstationsGeometry.size() - 1] - fNstationsActive[fNstationsActive.size() - 1]);
+    fActiveStationGlobalIDs[index] = -1;
+    fNstationsActive[static_cast<L1DetectorID_t>(inStation.GetDetectorID())]--;
+    fNstationsActive[fNstationsActive.size() - 1]--;
   }
   LOG(debug) << "L1InitManager: adding a station with stationID = " << inStation.GetStationID()
              << " and detectorID = " << static_cast<int>(inStation.GetDetectorID())
@@ -84,16 +88,6 @@ void L1InitManager::CheckInit()
   this->CheckStationsInfoInit();
 }
 
-//-----------------------------------------------------------------------------------------------------------------------
-//
-int L1InitManager::GetNstations(L1DetectorID detectorID) const
-{
-  auto ifDetectorIdDesired = [&detectorID](const L1BaseStationInfo& station) {
-    return station.GetDetectorID() == detectorID;
-  };
-  return std::count_if(fStationsInfo.begin(), fStationsInfo.end(), ifDetectorIdDesired);
-}
-
 //-----------------------------------------------------------------------------------------------------------------------
 //
 void L1InitManager::InitTargetField(double zStep)
@@ -227,24 +221,32 @@ void L1InitManager::SetMomentumCutOff(float momentumCutOff)
 
 //-----------------------------------------------------------------------------------------------------------------------
 //
-void L1InitManager::SetNstationsCrosscheck(L1DetectorID detectorID, int nStations)
+void L1InitManager::SetNstations(L1DetectorID detectorID, int nStations)
 {
   L1MASSERT(0, fInitController.GetFlag(EInitKey::kActiveDetectorIDs),
             "Attempt to set crosscheck number of stations before the active detetors set had been initialized");
+
   // NOTE: We add and check only those detectors which will be active (?)
   // For INACTIVE detectors the initialization code for it inside CbmL1/BmnL1 can (and must) be still in,
   // but it will be ignored inside L1InitManager.
   if (fActiveDetectorIDs.find(detectorID) != fActiveDetectorIDs.end()) {
-    fNstationsActualCrosscheck[detectorID] = nStations;
-    fNstationsActiveCrosscheck[detectorID] = nStations;
+    if (nStations) {
+      fNstationsGeometry[static_cast<L1DetectorID_t>(detectorID)] = nStations;
+      fNstationsActive[static_cast<L1DetectorID_t>(detectorID)]   = nStations;
+    } 
+    else {
+      // TODO: Probably it is better to replace fatal with warn and remove the detectorID from active detectors (S.Zharko)
+      LOG(fatal) << "L1InitManager::SetNstations: attempt to initialize zero stations for active detector: " 
+        << static_cast<L1DetectorID_t>(detectorID);
+    }
   }
 
   // Check if all the station numbers for active detectors are initialized now:
-  LOG(debug) << "SetNstationsCrosscheck called for detectorID = " << static_cast<int>(detectorID);
+  LOG(debug) << "L1InitManager::SetNstations called for detectorID = " << static_cast<int>(detectorID);
   if (!fInitController.GetFlag(EInitKey::kStationsNumberCrosscheck)) {
     bool ifInitialized = true;
     for (auto item : fActiveDetectorIDs) {
-      if (fNstationsActualCrosscheck.find(item) == fNstationsActualCrosscheck.end()) {
+      if (fNstationsGeometry[static_cast<L1DetectorID_t>(item)] == 0) {
         ifInitialized = false;
         break;
       }
@@ -252,11 +254,8 @@ void L1InitManager::SetNstationsCrosscheck(L1DetectorID detectorID, int nStation
     fInitController.SetFlag(EInitKey::kStationsNumberCrosscheck, ifInitialized);
   }
   if (fInitController.GetFlag(EInitKey::kStationsNumberCrosscheck)) {
-    int nStationsExpected = 0;
-    for (auto item : fNstationsActualCrosscheck) {
-      nStationsExpected += item.second;
-    }
-    fActiveStationsIndexMap.reserve(nStationsExpected);
+    fNstationsGeometry[L1Parameters::kMaxNdetectors] = std::accumulate(fNstationsGeometry.begin(), fNstationsGeometry.end() - 1, 0);
+    fNstationsActive[L1Parameters::kMaxNdetectors] = fNstationsGeometry[L1Parameters::kMaxNdetectors];
   }
 }
 
@@ -304,7 +303,7 @@ void L1InitManager::TransferL1StationArray(std::array<L1Station, L1Parameters::k
   // 2) Check, if destinationArraySize is enough for the transfer
   //
   {
-    int nStationsTotal = this->GetNstations();
+    int nStationsTotal = this->GetNstationsActive();
     std::stringstream aStream;
     aStream << "Destination array size (" << destinationArray.size()
             << ") is smaller then the actual number of active tracking stations (" << nStationsTotal << ")";
@@ -353,9 +352,12 @@ void L1InitManager::CheckStationsInfoInit()
     // 1) Check numbers of stations passed
     //
     // loop over active detectors
-    for (const auto& itemDetector : fActiveDetectorIDs) {
-      int nStations         = GetNstations(itemDetector);
-      int nStationsExpected = fNstationsActiveCrosscheck.at(itemDetector);
+    for (auto itemDetector : fActiveDetectorIDs) {
+      auto selectDetector = [&itemDetector](const L1BaseStationInfo& station) { 
+        return station.GetDetectorID() == itemDetector;   
+      };
+      int nStationsExpected = GetNstationsActive(itemDetector);
+      int nStations         = std::count_if(fStationsInfo.begin(), fStationsInfo.end(), selectDetector);
       if (nStations != nStationsExpected) {
         LOG(error) << "L1InitManager::CheckStationsInfoInit: Incorrect number of L1BaseStationInfo objects passed"
                    << " to the L1Manager for L1DetectorID = " << static_cast<int>(itemDetector) << ": " << nStations
@@ -368,11 +370,12 @@ void L1InitManager::CheckStationsInfoInit()
     //
     // 2) Check for maximum allowed number of stations
     //
-    int nStationsTotal = GetNstations();
+    int nStationsTotal = fNstationsGeometry[fNstationsGeometry.size() - 1];
     if (nStationsTotal > L1Parameters::kMaxNstations) {
       std::stringstream aStream;
-      aStream << "Actual total number of registered stations (" << nStationsTotal << ") is larger then designed one ("
-              << L1Parameters::kMaxNstations << "). Please, select another set of active tracking detectors";
+      aStream << "Actual total number of registered stations in geometry (" << nStationsTotal << ") is larger then possible ("
+              << L1Parameters::kMaxNstations << "). Please, select another set of active tracking detectors or recompile the code with enlarged"
+              << " L1Parameters::kMaxNstations value";
       // TODO: We have to provide an instruction of how to increase the kMaxNstations
       //       number keeping the code consistent (S.Zharko)
       ifInitPassed = false;
diff --git a/reco/L1/L1Algo/L1InitManager.h b/reco/L1/L1Algo/L1InitManager.h
index 123af865f9..d165bb320a 100644
--- a/reco/L1/L1Algo/L1InitManager.h
+++ b/reco/L1/L1Algo/L1InitManager.h
@@ -19,14 +19,20 @@
 #include "L1Vector.h"
 
 //#include <string>
+#include <array>
 #include <bitset>
 #include <memory>  //unique_ptr
+#include <numeric>
 #include <set>
+#include <type_traits>
 
 /// Forward declaration of the tracking detectors scoped enumeration. Concrete realization of this enumeration must be
 /// determined in the concrete setup class (i.e. CbmL1/BmnL1)
 enum class L1DetectorID;
 
+/// Underlying 
+using L1DetectorID_t = std::underlying_type_t<L1DetectorID>;
+
 /// Initialization manager for L1Algo
 ///
 /// ==== Expected initialization steps ==== (TODO: keep this instruction up-to-date)
@@ -112,6 +118,7 @@ public:
   void AddStation(const L1BaseStationInfo* pStation) { AddStation(*pStation); }
   /// Adds another station of a given type using std::unique_ptr-wraped pointer to L1BaseStationInfo
   void AddStation(const std::unique_ptr<L1BaseStationInfo>& puStation) { AddStation(*puStation); }
+
   /// Provides final checks of large fields initialization calling Check"Object"Init() privat methods,
   /// must be called in the begining of L1Algo::Init()
   void CheckInit();
@@ -123,8 +130,6 @@ public:
   //
   /// Gets a set of active detectors for this analysis
   const L1DetectorIDSet_t& GetActiveDetectorIDs() const { return fActiveDetectorIDs; }
-  /// Gets a vector of active stations indeces. If the station is inactive, it's index equals -1
-  const L1Vector<int>& GetActiveStationsIndexMap() const { return fActiveStationsIndexMap; }
   /// Gets ghost suppression flag
   int GetGhostSuppression() const { return fGhostSuppression; }
   /// Gets momentum cutoff
@@ -133,13 +138,32 @@ public:
   const L1ObjectInitController_t& GetInitController() const { return fInitController; }
   /// Gets a pointer to L1Parameters instance with a posibility of its fields modification
   const L1Parameters* GetParameters() const { return fpParameters; }
-  /// Gets a total number of active stations
-  int GetNstations() const { return static_cast<int>(fStationsInfo.size()); }
-  /// Gets a number of active stations for a particualr detector ID
-  int GetNstations(L1DetectorID detectorID) const;
-  /// Gets a L1FieldRegion object at primary vertex
+  /// Gets total number of active stations
+  int GetNstationsActive() const { return fNstationsActive[fNstationsActive.size() - 1]; }
+  /// Gets number of active stations for given detector ID
+  int GetNstationsActive(L1DetectorID detectorID) const { return fNstationsActive[static_cast<L1DetectorID_t>(detectorID)]; }
+  /// Gets total number of stations, provided by setup geometry
+  int GetNstationsGeometry() const { return fNstationsGeometry[fNstationsGeometry.size() - 1]; }
+  /// Gets number of stations, provided by setup geometry for given detector ID
+  int GetNstationsGeometry(L1DetectorID detectorID) const { return fNstationsGeometry[static_cast<L1DetectorID_t>(detectorID)]; }
+  /// Calculates global index of station among geometry (accounts for inactive stations)
+  /// \param localIndex  index of the detector subsystem module/station/layer provided by detector subsystem experts
+  /// \param detectorID  ID of the detector subsystem
+  __attribute__((always_inline)) int GetStationIndexGeometry(int localIndex, L1DetectorID detectorID) const 
+  {
+    return localIndex + std::accumulate(fNstationsGeometry.cbegin(), fNstationsGeometry.cbegin() + static_cast<int>(detectorID), 0);
+  }
+  /// Calculates global index of station used by track finder
+  /// \param localIndex  index of the detector subsystem module/station/layer provided by detector subsystem experts
+  /// \param detectorID  ID of the detector subsystem
+  __attribute__((always_inline)) int GetStationIndexActive(int localIndex, L1DetectorID detectorID) const
+  {
+    return fActiveStationGlobalIDs[GetStationIndexGeometry(localIndex, detectorID)];
+  }
+
+  /// Gets L1FieldRegion object at primary vertex
   const L1FieldRegion& GetTargetFieldRegion() const { return fTargetFieldRegion; }
-  /// Gets a L1FieldValue object at primary vertex
+  /// Gets L1FieldValue object at primary vertex
   const L1FieldValue& GetTargetFieldValue() const { return fTargetFieldValue; }
   /// Gets a target position
   const std::array<double, 3>& GetTargetPosition() const { return fTargetPos; }
@@ -179,7 +203,7 @@ public:
   ///
   void SetTrackingLevel(int trackingLevel);
   /// Sets a number of actual stations for a particular tracking detector ID to provide initialization cross-check
-  void SetNstationsCrosscheck(L1DetectorID detectorID, int nStations);
+  void SetNstations(L1DetectorID detectorID, int nStations);
   /// Sets target poisition
   void SetTargetPosition(double x, double y, double z);
 
@@ -207,18 +231,20 @@ private:
   /* Stations related fields */
 
   std::set<L1BaseStationInfo> fStationsInfo {};  ///< Set of L1BaseStationInfo objects
-
+  
+  /// Numbers of stations, which are active in tracking. Index of an array element (except the last one) corresponds to a given
+  /// L1DetectorID of the detector subystem. The last array element corresponds to the total number of stations.
+  std::array<int, L1Parameters::kMaxNdetectors + 1> fNstationsActive {};
+  /// Actual numbers of stations, provided by geometry. Index of an array element (except the last one) corresponds to a given
+  /// L1DetectorID of the detector subystem. The last array element corresponds to the total number of stations.
+  std::array<int, L1Parameters::kMaxNdetectors + 1> fNstationsGeometry {};
   /// Map of the actual detector indeces to the active detector indeces
-  /// The vector maps actual station index (which is defined by ) to the index of station in tracking. If the station is inactive, its index is equal to -1.
-  /// Example: let stations 1 and 4 be inactive. Then:
-  ///   actual index:  0  1  2  3  4  5  6  7  8  9
-  ///   active index:  0 -1  1  2 -1  3  4  5  6  7
-  L1Vector<int> fActiveStationsIndexMap {"L1InitManager::fActiveStationsIndexMap"};
-
-  /// Actual number of stations in the setup
-  L1DetectorIDIntMap_t fNstationsActualCrosscheck {};
-  /// Number of stations active in tracking
-  L1DetectorIDIntMap_t fNstationsActiveCrosscheck {};
+  /// The vector maps actual station index (which is defined by ) to the index of station in tracking. If the station is inactive, 
+  /// its index is equal to -1. Example: let stations 1 and 4 be inactive. Then:
+  ///   actual index:  0  1  2  3  4  5  6  7  8  9  0  0  0  0
+  ///   active index:  0 -1  1  2 -1  3  4  5  6  7  0  0  0  0 
+  std::array<int, L1Parameters::kMaxNstations>      fActiveStationGlobalIDs {}; 
+  
   /// A function which returns magnetic field vector B in a radius-vector xyz
   L1FieldFunction_t fFieldFunction {[](const double (&)[3], double (&)[3]) {}};
   // NOTE: Stations of daetectors which will not be assigned as active, will not be included in the tracking!!!!!!!
diff --git a/reco/L1/L1Algo/L1Parameters.h b/reco/L1/L1Algo/L1Parameters.h
index 6e4b938ff2..8f96f574fb 100644
--- a/reco/L1/L1Algo/L1Parameters.h
+++ b/reco/L1/L1Algo/L1Parameters.h
@@ -34,17 +34,18 @@ public:
   /// Order of polynomial to approximate field in the vicinity of station plane
   static constexpr int kMaxFieldApproxPolynomialOrder {5};
 
-  static constexpr unsigned int kStationBits {6u};  ///> Amount of bits to code one station
-  static constexpr unsigned int kThreadBits {6u};   ///> Amount of bits to code one thread
-  static constexpr unsigned int kTripletBits {32u - kStationBits - kThreadBits};  ///> Amount of bits to code one triple
+  static constexpr unsigned int kStationBits {6u};  ///< Amount of bits to code one station
+  static constexpr unsigned int kThreadBits {6u};   ///< Amount of bits to code one thread
+  static constexpr unsigned int kTripletBits {32u - kStationBits - kThreadBits};  ///< Amount of bits to code one triple
 
-  static constexpr int kMaxNstations {1u << kStationBits};  ///> Max number of stations, 2^6  = 64
-  static constexpr int kMaxNthreads {1u << kThreadBits};    ///> Max number of threads, 2^6  = 64
-  static constexpr int kMaxNtriplets {1u << kTripletBits};  ///> Max number of triplets, 2^20 = 1,048,576
+  static constexpr int kMaxNdetectors {5};                  ///< Max number of tracking detectors
+  static constexpr int kMaxNstations {1u << kStationBits};  ///< Max number of stations, 2^6  = 64
+  static constexpr int kMaxNthreads {1u << kThreadBits};    ///< Max number of threads, 2^6  = 64
+  static constexpr int kMaxNtriplets {1u << kTripletBits};  ///< Max number of triplets, 2^20 = 1,048,576
 
-  static constexpr int kStandardIOWidth {15};  ///> Width of one output entry, passed to the std::setw()
+  static constexpr int kStandardIOWidth {15};  ///< Width of one output entry, passed to the std::setw()
 
-  static constexpr int kAssertionLevel {0};  ///> Assertion level
+  static constexpr int kAssertionLevel {0};  ///< Assertion level
 
   //
   // Compile control flags
diff --git a/reco/L1/ParticleFinder/CbmL1PFFitter.cxx b/reco/L1/ParticleFinder/CbmL1PFFitter.cxx
index 1d42a261e9..31034994c3 100644
--- a/reco/L1/ParticleFinder/CbmL1PFFitter.cxx
+++ b/reco/L1/ParticleFinder/CbmL1PFFitter.cxx
@@ -46,7 +46,6 @@
 
 using std::vector;
 
-
 namespace NS_L1TrackFitter
 {
   const fvec c_light = 0.000299792458, c_light_i = 1. / c_light;
@@ -187,7 +186,7 @@ void CbmL1PFFitter::Fit(vector<CbmStsTrack>& Tracks, vector<int>& pidHypo)
           posy = hit->GetY();
           posz = hit->GetZ();
           // ista = hit->GetStationNr();
-          ista = CbmL1::Instance()->algo->GetInitManager()->GetActiveStationsIndexMap()[hit->GetStationNr()];
+          ista = CbmL1::Instance()->algo->GetInitManager()->GetStationIndexActive(hit->GetStationNr(), L1DetectorID::kMvd);
           if (ista == -1) continue;
         }
         else {
@@ -200,8 +199,7 @@ void CbmL1PFFitter::Fit(vector<CbmStsTrack>& Tracks, vector<int>& pidHypo)
           posz = hit->GetZ();
           //  ista = CbmStsSetup::Instance()->GetStationNumber(hit->GetAddress())
           //       + NMvdStations;  //hit->GetStationNr() - 1 + NMvdStations;
-          ista = CbmL1::Instance()->algo->GetInitManager()->GetActiveStationsIndexMap()
-                   [CbmStsSetup::Instance()->GetStationNumber(hit->GetAddress()) + CbmL1::Instance()->NMvdStationsGeom];
+          ista = CbmL1::Instance()->algo->GetInitManager()->GetStationIndexActive(CbmStsSetup::Instance()->GetStationNumber(hit->GetAddress()), L1DetectorID::kSts);
           if (ista == -1) continue;
         }
         w[ista][iVec] = 1.f;
-- 
GitLab