From 5e412fbda1bd4a32572cd2488d23264d8e57561c Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Wed, 30 Oct 2024 15:58:52 +0100
Subject: [PATCH] CA: separation of detector usage flags into the in-geometry
 and is-active

1) in-geometry: if the detector subsystem exists in geometry
2) is-active: if the detector subsystem provides hits and was not disabled manually (case of MVD in tb)
---
 algo/ca/core/pars/CaConfigReader.cxx     |   6 +-
 algo/ca/core/pars/CaConfigReader.h       |   2 +-
 algo/ca/core/pars/CaInitManager.cxx      |  30 +-----
 algo/ca/core/pars/CaInitManager.h        |  30 +++---
 reco/L1/CbmL1.cxx                        | 122 +++++++++++------------
 reco/L1/CbmL1.h                          |  10 --
 reco/kfnew/CbmKfTrackingSetupBuilder.cxx |  17 +---
 reco/kfnew/CbmKfTrackingSetupBuilder.h   |   8 +-
 8 files changed, 87 insertions(+), 138 deletions(-)

diff --git a/algo/ca/core/pars/CaConfigReader.cxx b/algo/ca/core/pars/CaConfigReader.cxx
index 4e76d2b48e..88dd41f4ef 100644
--- a/algo/ca/core/pars/CaConfigReader.cxx
+++ b/algo/ca/core/pars/CaConfigReader.cxx
@@ -78,11 +78,13 @@ std::vector<std::string> ConfigReader::GetNodeKeys(const YAML::Node& node) const
 //
 void ConfigReader::Read()
 {
+  // TODO: Remove fbGeometryLock as soon as the legacy geometry variables are removed from the ca::Parameters class
   if (!fbGeometryLock) {  // Unset inactive tracking stations
     if (fVerbose >= 1) {
-      LOG(info) << "- unsetting inactive tracking stations";
+      LOG(info) << "- disabling inactive tracking stations";
     }
     auto inactiveMap = this->ReadInactiveStationMap();
+
     if (std::any_of(inactiveMap.begin(), inactiveMap.end(), [](const auto& s) { return (s.size() != 0); })) {
       for (auto& station : fpInitManager->GetStationInfo()) {
         int iDet   = static_cast<int>(station.GetDetectorID());
@@ -251,7 +253,7 @@ std::vector<std::set<int>> ConfigReader::ReadInactiveStationMap()
   auto node             = this->GetNode([](YAML::Node n) { return n["core"]["common"]["inactive_stations"]; });
 
   // Fill map of inactive stations
-  std::vector<std::set<int>> vGeoIdToTrackingStatus(fpInitManager->GetNstationsGeometry());
+  std::vector<std::set<int>> vGeoIdToTrackingStatus(constants::size::MaxNdetectors);
 
   if (node && node.size()) {
     std::unordered_map<std::string, int> mDetNameToID;
diff --git a/algo/ca/core/pars/CaConfigReader.h b/algo/ca/core/pars/CaConfigReader.h
index b95c15e5ff..e13ffd807f 100644
--- a/algo/ca/core/pars/CaConfigReader.h
+++ b/algo/ca/core/pars/CaConfigReader.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2022-2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
+/* Copyright (C) 2022-2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
    SPDX-License-Identifier: GPL-3.0-only
    Authors: Sergei Zharko [committer] */
 
diff --git a/algo/ca/core/pars/CaInitManager.cxx b/algo/ca/core/pars/CaInitManager.cxx
index 4203b81425..14117a2d88 100644
--- a/algo/ca/core/pars/CaInitManager.cxx
+++ b/algo/ca/core/pars/CaInitManager.cxx
@@ -29,20 +29,7 @@ using cbm::algo::ca::StationInitializer;
 
 // ----------------------------------------------------------------------------------------------------------------------
 //
-void InitManager::AddStation(const StationInitializer& inStation)
-{
-  // TODO: SZh 15.08.2023: Replace L1MASSERT with throw logic_error
-  if (!fInitController.GetFlag(EInitKey::kActiveDetectorIDs)) {
-    std::stringstream msg;
-    msg << "ca::InitManager: Attempt to add a station info before the active detectors set had been initialized";
-    throw std::runtime_error(msg.str());
-  }
-
-  // Check, if the detector subsystem for this station is active
-  if (fActiveDetectorIDs.find(inStation.GetDetectorID()) != fActiveDetectorIDs.end()) {
-    fvStationInfo.push_back(inStation);
-  }
-}
+void InitManager::AddStation(const StationInitializer& inStation) { fvStationInfo.push_back(inStation); }
 
 // ----------------------------------------------------------------------------------------------------------------------
 //
@@ -66,10 +53,6 @@ void InitManager::ClearSetupInfo()
   // Set number of stations do default values
   this->ClearStationLayout();
 
-  // Clear active detectors
-  fActiveDetectorIDs.clear();
-  fInitController.SetFlag(EInitKey::kActiveDetectorIDs, false);
-
   // Clear field info
   fParameters.fVertexFieldRegion = kf::FieldRegion<fvec>();
   fParameters.fVertexFieldValue  = kf::FieldValue<fvec>();
@@ -238,6 +221,7 @@ std::vector<StationInitializer>& InitManager::GetStationInfo()
 //
 void InitManager::InitStationLayout()
 {
+  LOG(info) << "ca::InitManager::InitStationLayout(): ....";
   this->ClearStationLayout();
   std::sort(fvStationInfo.begin(), fvStationInfo.end());
 
@@ -389,7 +373,6 @@ void InitManager::ReadParametersObject(const std::string& fileName)
   fInitController.SetFlag(EInitKey::kStationLayoutInitialized, true);
   fInitController.SetFlag(EInitKey::kPrimaryVertexField, true);
   fInitController.SetFlag(EInitKey::kSearchWindows, true);
-  fInitController.SetFlag(EInitKey::kActiveDetectorIDs);
 }
 
 // ---------------------------------------------------------------------------------------------------------------------
@@ -443,15 +426,6 @@ void InitManager::ReadSearchWindows(const std::string& fileName)
   fInitController.SetFlag(EInitKey::kSearchWindows, true);
 }
 
-// ----------------------------------------------------------------------------------------------------------------------
-//
-void InitManager::SetActiveDetectorIDs(const DetectorIDSet_t& detectorIDs)
-{
-  // TODO: To think about redefinition possibilities: should it be allowed or not? (S.Zh.)
-  fActiveDetectorIDs = detectorIDs;
-  fInitController.SetFlag(EInitKey::kActiveDetectorIDs);
-}
-
 // ----------------------------------------------------------------------------------------------------------------------
 //
 void InitManager::SetCAIterationsNumberCrosscheck(int nIterations)
diff --git a/algo/ca/core/pars/CaInitManager.h b/algo/ca/core/pars/CaInitManager.h
index a4cc95bcbf..84c7e5248d 100644
--- a/algo/ca/core/pars/CaInitManager.h
+++ b/algo/ca/core/pars/CaInitManager.h
@@ -60,19 +60,18 @@ namespace cbm::algo::ca
     {
       // NOTE: Please, keep the numbers of the enumeration items in the existing order: it helps to debug the
       //       initialization with this->GetObjectInitController().ToString() method call (S.Zharko)
-      kActiveDetectorIDs,             ///< 0) If the detector sequence is set
-      kFieldFunction,                 ///< 1) If magnetic field getter function is set
-      kTargetPos,                     ///< 2) If target position was defined
-      kPrimaryVertexField,            ///< 3) If magnetic field value and region defined at primary vertex
-      kStationsInfo,                  ///< 4) If all the planned stations were added to the manager
-      kCAIterationsNumberCrosscheck,  ///< 5) If the number of CA track finder is initialized
-      kCAIterations,                  ///< 6) If the CA track finder iterations were initialized
-      kSearchWindows,                 ///< 7) If the hit search windows were initialized
-      kGhostSuppression,              ///< 9)
-      kRandomSeed,                    ///< 10) If the random seed is provided
-      kStationLayoutInitialized,      ///< 11) If stations layout is initialized
-      kSetupInitialized,              ///< 12) If KF-setup initialized
-      kEnd                            ///< 13) [technical] number of entries in the enumeration
+      kFieldFunction,                 ///< 0) If magnetic field getter function is set
+      kTargetPos,                     ///< 1) If target position was defined
+      kPrimaryVertexField,            ///< 2) If magnetic field value and region defined at primary vertex
+      kStationsInfo,                  ///< 3) If all the planned stations were added to the manager
+      kCAIterationsNumberCrosscheck,  ///< 4) If the number of CA track finder is initialized
+      kCAIterations,                  ///< 5) If the CA track finder iterations were initialized
+      kSearchWindows,                 ///< 6) If the hit search windows were initialized
+      kGhostSuppression,              ///< 7)
+      kRandomSeed,                    ///< 8) If the random seed is provided
+      kStationLayoutInitialized,      ///< 9) If stations layout is initialized
+      kSetupInitialized,              ///< 10) If KF-setup initialized
+      kEnd                            ///< 11) [technical] number of entries in the enumeration
     };
 
     using DetectorIDIntMap_t = std::unordered_map<EDetectorID, int>;
@@ -195,10 +194,6 @@ namespace cbm::algo::ca
     /// \param  fileName  Name of input file
     void ReadSearchWindows(const std::string& fileName);
 
-    /// \brief Sets a set of active tracking detector IDs
-    /// \param detectorIDs  A set of the used EDetectorID
-    void SetActiveDetectorIDs(const DetectorIDSet_t& detectorIDs);
-
     /// \brief Sets a number of CA track finder iterations to provide initialization cross-check
     // TODO: remove this method
     void SetCAIterationsNumberCrosscheck(int nIterations);
@@ -348,7 +343,6 @@ namespace cbm::algo::ca
     void ClearStationLayout();
 
     InitController_t fInitController{};              ///< Initialization flags
-    DetectorIDSet_t fActiveDetectorIDs{};            ///< Set of tracking detectors, active during the run
     DetectorIDArr_t<std::string> fvDetectorNames{};  ///< Names of the detectors
 
     double fTargetZ{0.};  ///< Target position z component in double precision
diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index 0f934b50e9..63c771f712 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -116,25 +116,6 @@ CbmL1::~CbmL1()
   if (fpInstance == this) fpInstance = nullptr;
 }
 
-// ---------------------------------------------------------------------------------------------------------------------
-//
-void CbmL1::CheckDetectorPresence()
-{
-  fUseMVD  = fUseMVD && CbmSetup::Instance()->IsActive(ECbmModuleId::kMvd);
-  fUseSTS  = fUseSTS && CbmSetup::Instance()->IsActive(ECbmModuleId::kSts);
-  fUseMUCH = fUseMUCH && CbmSetup::Instance()->IsActive(ECbmModuleId::kMuch);
-  fUseTRD  = fUseTRD && CbmSetup::Instance()->IsActive(ECbmModuleId::kTrd);
-  fUseTOF  = fUseTOF && CbmSetup::Instance()->IsActive(ECbmModuleId::kTof);
-  {
-    // TODO: temporary code!!
-    // for a moment, the MVD digitizer doesn't work in TB mode
-    // check the presence of MVD hits to make sure the MVD is really active
-    if (!FairRootManager::Instance()->GetObject("MvdHit")) {
-      fUseMVD = false;
-    }
-  }
-}
-
 // ---------------------------------------------------------------------------------------------------------------------
 //
 void CbmL1::DisableTrackingStation(ca::EDetectorID detID, int iSt)
@@ -194,11 +175,17 @@ try {
   // turn on reconstruction in sub-detectors
 
   auto* pSetupBuilder{cbm::kf::TrackingSetupBuilder::Instance()};
-  fUseMVD  = pSetupBuilder->Has(ca::EDetectorID::kMvd);
-  fUseSTS  = pSetupBuilder->Has(ca::EDetectorID::kSts);
-  fUseMUCH = pSetupBuilder->Has(ca::EDetectorID::kMuch);
-  fUseTRD  = pSetupBuilder->Has(ca::EDetectorID::kTrd);
-  fUseTOF  = pSetupBuilder->Has(ca::EDetectorID::kTof);
+  bool bGeoMVD  = pSetupBuilder->IsInGeometry(ca::EDetectorID::kMvd);
+  bool bGeoSTS  = pSetupBuilder->IsInGeometry(ca::EDetectorID::kSts);
+  bool bGeoMUCH = pSetupBuilder->IsInGeometry(ca::EDetectorID::kMuch);
+  bool bGeoTRD  = pSetupBuilder->IsInGeometry(ca::EDetectorID::kTrd);
+  bool bGeoTOF  = pSetupBuilder->IsInGeometry(ca::EDetectorID::kTof);
+
+  bool bUseMVD  = pSetupBuilder->HasHits(ca::EDetectorID::kMvd);
+  bool bUseSTS  = pSetupBuilder->HasHits(ca::EDetectorID::kSts);
+  bool bUseMUCH = pSetupBuilder->HasHits(ca::EDetectorID::kMuch);
+  bool bUseTRD  = pSetupBuilder->HasHits(ca::EDetectorID::kTrd);
+  bool bUseTOF  = pSetupBuilder->HasHits(ca::EDetectorID::kTof);
 
   // *****************************
   // **                         **
@@ -240,11 +227,11 @@ try {
     auto trdInterface  = CbmTrdTrackingInterface::Instance();
     auto tofInterface  = CbmTofTrackingInterface::Instance();
 
-    int nMvdStationsGeom  = (fUseMVD) ? mvdInterface->GetNtrackingStations() : 0;
-    int nStsStationsGeom  = (fUseSTS) ? stsInterface->GetNtrackingStations() : 0;
-    int nMuchStationsGeom = (fUseMUCH) ? muchInterface->GetNtrackingStations() : 0;
-    int nTrdStationsGeom  = (fUseTRD) ? trdInterface->GetNtrackingStations() : 0;
-    int nTofStationsGeom  = (fUseTOF) ? tofInterface->GetNtrackingStations() : 0;
+    int nMvdStationsGeom  = (bGeoMVD) ? mvdInterface->GetNtrackingStations() : 0;
+    int nStsStationsGeom  = (bGeoSTS) ? stsInterface->GetNtrackingStations() : 0;
+    int nMuchStationsGeom = (bGeoMUCH) ? muchInterface->GetNtrackingStations() : 0;
+    int nTrdStationsGeom  = (bGeoTRD) ? trdInterface->GetNtrackingStations() : 0;
+    int nTofStationsGeom  = (bGeoTOF) ? tofInterface->GetNtrackingStations() : 0;
 
     // **************************
     // ** Field initialization **
@@ -291,24 +278,14 @@ try {
     // ** Active tracking detector subsystems selection **
     // ***************************************************
 
-    std::set<ca::EDetectorID> vActiveTrackingDetectorIDs{};  // Set of detectors active in tracking
 
-    if (fUseMVD) {
-      vActiveTrackingDetectorIDs.insert(ca::EDetectorID::kMvd);
-    }
-    if (fUseSTS) {
-      vActiveTrackingDetectorIDs.insert(ca::EDetectorID::kSts);
-    }
-    if (fUseMUCH) {
-      vActiveTrackingDetectorIDs.insert(ca::EDetectorID::kMuch);
-    }
-    if (fUseTRD) {
-      vActiveTrackingDetectorIDs.insert(ca::EDetectorID::kTrd);
-    }
-    if (fUseTOF) {
-      vActiveTrackingDetectorIDs.insert(ca::EDetectorID::kTof);
+    // Explicitly disable MVD, if it is not required from the STSFindTracks task
+    if (bUseMVD) {
+      auto* pTrackFinderTask = dynamic_cast<CbmStsFindTracks*>(FairRunAna::Instance()->GetTask("STSFindTracks"));
+      if (pTrackFinderTask) {
+        bUseMVD = pTrackFinderTask->MvdUsage();
+      }
     }
-    fInitManager.SetActiveDetectorIDs(vActiveTrackingDetectorIDs);
 
 
     // *************************************
@@ -320,7 +297,7 @@ try {
     bool bDisableTime = false;  /// TMP, move to parameters!
 
     // *** MVD stations info ***
-    if (fUseMVD) {
+    if (bGeoMVD) {
       for (int iSt = 0; iSt < nMvdStationsGeom; ++iSt) {
         auto stationInfo = ca::StationInitializer(ca::EDetectorID::kMvd, iSt);
         // TODO: SZh 15.08.2022: Replace station type with ca::EDetectorID
@@ -337,13 +314,16 @@ try {
             != fvmDisabledStationIDs[ca::EDetectorID::kMvd].cend()) {
           stationInfo.SetTrackingStatus(false);
         }
+        if (!bUseMVD) {
+          stationInfo.SetTrackingStatus(false);
+        }
         fInitManager.AddStation(stationInfo);
         LOG(info) << "- MVD station " << iSt << " at z = " << stationInfo.GetZref() << " cm ";
       }
     }
 
     // *** STS stations info ***
-    if (fUseSTS) {
+    if (bGeoSTS) {
       for (int iSt = 0; iSt < nStsStationsGeom; ++iSt) {
         auto stationInfo = ca::StationInitializer(ca::EDetectorID::kSts, iSt);
         // TODO: SZh 15.08.2022: Replace station type with ca::EDetectorID
@@ -361,13 +341,16 @@ try {
             != fvmDisabledStationIDs[ca::EDetectorID::kSts].cend()) {
           stationInfo.SetTrackingStatus(false);
         }
+        if (!bUseSTS) {
+          stationInfo.SetTrackingStatus(false);
+        }
         fInitManager.AddStation(stationInfo);
         LOG(info) << "- STS station " << iSt << " at z = " << stationInfo.GetZref() << " cm ";
       }
     }
 
     // *** MuCh stations info ***
-    if (fUseMUCH) {
+    if (bGeoMUCH) {
       for (int iSt = 0; iSt < nMuchStationsGeom; ++iSt) {
         auto stationInfo = ca::StationInitializer(ca::EDetectorID::kMuch, iSt);
         // TODO: SZh 15.08.2022: Replace station type with ca::EDetectorID
@@ -385,13 +368,16 @@ try {
             != fvmDisabledStationIDs[ca::EDetectorID::kMuch].cend()) {
           stationInfo.SetTrackingStatus(false);
         }
+        if (!bUseMUCH) {
+          stationInfo.SetTrackingStatus(false);
+        }
         fInitManager.AddStation(stationInfo);
         LOG(info) << "- MuCh station " << iSt << " at z = " << stationInfo.GetZref() << " cm";
       }
     }
 
     // *** TRD stations info ***
-    if (fUseTRD) {
+    if (bGeoTRD) {
       for (int iSt = 0; iSt < nTrdStationsGeom; ++iSt) {
         auto stationInfo = ca::StationInitializer(ca::EDetectorID::kTrd, iSt);
         // TODO: SZh 15.08.2022: Replace station type with ca::EDetectorID
@@ -412,13 +398,16 @@ try {
             != fvmDisabledStationIDs[ca::EDetectorID::kTrd].cend()) {
           stationInfo.SetTrackingStatus(false);
         }
+        if (!bUseTRD) {
+          stationInfo.SetTrackingStatus(false);
+        }
         fInitManager.AddStation(stationInfo);
         LOG(info) << "- TRD station " << iSt << " at z = " << stationInfo.GetZref() << " cm";
       }
     }
 
     // *** TOF stations info ***
-    if (fUseTOF) {
+    if (bGeoTOF) {
       for (int iSt = 0; iSt < nTofStationsGeom; ++iSt) {
         auto stationInfo = ca::StationInitializer(ca::EDetectorID::kTof, iSt);
         // TODO: SZh 15.08.2022: Replace station type with ca::EDetectorID
@@ -436,6 +425,9 @@ try {
             != fvmDisabledStationIDs[ca::EDetectorID::kTof].cend()) {
           stationInfo.SetTrackingStatus(false);
         }
+        if (!bUseTOF) {
+          stationInfo.SetTrackingStatus(false);
+        }
         fInitManager.AddStation(stationInfo);
         LOG(info) << "- TOF station " << iSt << " at z = " << stationInfo.GetZref() << " cm";
       }
@@ -477,11 +469,11 @@ try {
       return kFATAL;
     }
 
-    fUseMVD &= fInitManager.IsActive(ca::EDetectorID::kMvd);
-    fUseSTS &= fInitManager.IsActive(ca::EDetectorID::kSts);
-    fUseMUCH &= fInitManager.IsActive(ca::EDetectorID::kMuch);
-    fUseTRD &= fInitManager.IsActive(ca::EDetectorID::kTrd);
-    fUseTOF &= fInitManager.IsActive(ca::EDetectorID::kTof);
+    bUseMVD  = fInitManager.IsActive(ca::EDetectorID::kMvd);
+    bUseSTS  = fInitManager.IsActive(ca::EDetectorID::kSts);
+    bUseMUCH = fInitManager.IsActive(ca::EDetectorID::kMuch);
+    bUseTRD  = fInitManager.IsActive(ca::EDetectorID::kTrd);
+    bUseTOF  = fInitManager.IsActive(ca::EDetectorID::kTof);
 
     // Write parameters object to file if needed
     if (1 == fSTAPDataMode || 4 == fSTAPDataMode) {
@@ -517,11 +509,11 @@ try {
 
   // Initialize time-slice reader
   fpTSReader = std::make_unique<TimeSliceReader>();
-  fpTSReader->SetDetector(ca::EDetectorID::kMvd, fUseMVD);
-  fpTSReader->SetDetector(ca::EDetectorID::kSts, fUseSTS);
-  fpTSReader->SetDetector(ca::EDetectorID::kMuch, fUseMUCH);
-  fpTSReader->SetDetector(ca::EDetectorID::kTrd, fUseTRD);
-  fpTSReader->SetDetector(ca::EDetectorID::kTof, fUseTOF);
+  fpTSReader->SetDetector(ca::EDetectorID::kMvd, bUseMVD);
+  fpTSReader->SetDetector(ca::EDetectorID::kSts, bUseSTS);
+  fpTSReader->SetDetector(ca::EDetectorID::kMuch, bUseMUCH);
+  fpTSReader->SetDetector(ca::EDetectorID::kTrd, bUseTRD);
+  fpTSReader->SetDetector(ca::EDetectorID::kTof, bUseTOF);
 
   fpTSReader->RegisterParameters(pParameters);
   fpTSReader->RegisterHitIndexContainer(fvExternalHits);
@@ -533,11 +525,11 @@ try {
 
   if (fPerformance) {
     fpMCModule = std::make_unique<MCModule>(fVerbose, fPerformance);
-    fpMCModule->SetDetector(ca::EDetectorID::kMvd, fUseMVD);
-    fpMCModule->SetDetector(ca::EDetectorID::kSts, fUseSTS);
-    fpMCModule->SetDetector(ca::EDetectorID::kMuch, fUseMUCH);
-    fpMCModule->SetDetector(ca::EDetectorID::kTrd, fUseTRD);
-    fpMCModule->SetDetector(ca::EDetectorID::kTof, fUseTOF);
+    fpMCModule->SetDetector(ca::EDetectorID::kMvd, bUseMVD);
+    fpMCModule->SetDetector(ca::EDetectorID::kSts, bUseSTS);
+    fpMCModule->SetDetector(ca::EDetectorID::kMuch, bUseMUCH);
+    fpMCModule->SetDetector(ca::EDetectorID::kTrd, bUseTRD);
+    fpMCModule->SetDetector(ca::EDetectorID::kTof, bUseTOF);
 
     fpMCModule->RegisterMCData(fMCData);
     fpMCModule->RegisterRecoTrackContainer(fvRecoTracks);
diff --git a/reco/L1/CbmL1.h b/reco/L1/CbmL1.h
index 3d85ccf17b..2e78fc97df 100644
--- a/reco/L1/CbmL1.h
+++ b/reco/L1/CbmL1.h
@@ -185,10 +185,6 @@ class CbmL1 : public FairTask {
 
   // ** Specific member functions **
 
-  /// Checks, if detector subsystems are present in the setup
-  /// If a particular subsystem is absent, it is not used in tracking.
-  void CheckDetectorPresence();
-
   /// @brief  Disables tracking station for a given detector subsystem
   /// @param  detID  Detector ID
   /// @param  iSt    Index of station in tracking station interface
@@ -491,12 +487,6 @@ class CbmL1 : public FairTask {
   Int_t fTrackingLevel     = 2;    // currently not used
   Double_t fMomentumCutOff = 0.1;  // currently not used
 
-  bool fUseMVD  = false;  ///< if Mvd data should be processed
-  bool fUseSTS  = false;  ///< if Mvd data should be processed
-  bool fUseMUCH = false;  ///< if Much data should be processed
-  bool fUseTRD  = false;  ///< if Trd data should be processed
-  bool fUseTOF  = false;  ///< if Tof data should be processed
-
   int fEventNo       = 0;  ///< Current number of event/TS
   int fNofRecoTracks = 0;  ///< Total number of reconstructed tracks
 
diff --git a/reco/kfnew/CbmKfTrackingSetupBuilder.cxx b/reco/kfnew/CbmKfTrackingSetupBuilder.cxx
index 07c29edc06..347f7c6931 100644
--- a/reco/kfnew/CbmKfTrackingSetupBuilder.cxx
+++ b/reco/kfnew/CbmKfTrackingSetupBuilder.cxx
@@ -38,9 +38,10 @@ void TrackingSetupBuilder::CheckDetectorPresence()
   LOG(info) << "TrackingSetupBuilder: detector subsystems in geometry: ";
   auto Check = [&](EDetectorID detID) {
     auto modId = cbm::algo::ca::ToCbmModuleId(detID);
-    fvbDetUsed[detID] =
-      CbmSetup::Instance()->IsActive(modId) && FairRootManager::Instance()->GetObject(kDetHitBrName[detID]);
-    LOG(info) << fmt::format("\t{:6}: {}", ToString(modId), fvbDetUsed[detID]);
+    fvbDetInGeometry[detID] = CbmSetup::Instance()->IsActive(modId);
+    fvbDetHasHits[detID]    = fvbDetInGeometry[detID] && FairRootManager::Instance()->GetObject(kDetHitBrName[detID]);
+    LOG(info) << fmt::format("\t{:6} in geometry: {:5}, has hits: {:5}", ToString(modId), fvbDetInGeometry[detID],
+                             fvbDetHasHits[detID]);
   };
 
   Check(EDetectorID::kMvd);
@@ -48,14 +49,6 @@ void TrackingSetupBuilder::CheckDetectorPresence()
   Check(EDetectorID::kMuch);
   Check(EDetectorID::kTrd);
   Check(EDetectorID::kTof);
-
-  // Explicitly disable MVD, if it is not required from the STSFindTracks task
-  if (fvbDetUsed[EDetectorID::kMvd]) {
-    auto* pTrackFinderTask = dynamic_cast<CbmStsFindTracks*>(FairRunAna::Instance()->GetTask("STSFindTracks"));
-    if (pTrackFinderTask) {
-      fvbDetUsed[EDetectorID::kMvd] = pTrackFinderTask->MvdUsage();
-    }
-  }
 }
 
 // ---------------------------------------------------------------------------------------------------------------------
@@ -100,7 +93,7 @@ try {
 
   // Tracking station property initialization
   auto CollectStations = [&](const auto* pIfs, EDetectorID detID) -> void {
-    if (!fvbDetUsed[detID]) {
+    if (!fvbDetInGeometry[detID]) {
       return;
     }
     for (int iSt = 0; iSt < pIfs->GetNtrackingStations(); ++iSt) {
diff --git a/reco/kfnew/CbmKfTrackingSetupBuilder.h b/reco/kfnew/CbmKfTrackingSetupBuilder.h
index a3d2ff0cec..a4754c4efe 100644
--- a/reco/kfnew/CbmKfTrackingSetupBuilder.h
+++ b/reco/kfnew/CbmKfTrackingSetupBuilder.h
@@ -43,7 +43,10 @@ namespace cbm::kf
     }
 
     /// \brief  Checks, if a tracking detector is used (is in geometry and has hits)
-    bool Has(cbm::algo::ca::EDetectorID detID) const { return fvbDetUsed[detID]; }
+    bool IsInGeometry(cbm::algo::ca::EDetectorID detID) const { return fvbDetInGeometry[detID]; }
+
+    /// \brief  Checks, if a tracking detector has hits
+    bool HasHits(cbm::algo::ca::EDetectorID detID) const { return fvbDetHasHits[detID]; }
 
     // Disable copy and move
     TrackingSetupBuilder(const TrackingSetupBuilder&) = delete;
@@ -92,7 +95,8 @@ namespace cbm::kf
     inline static std::mutex fMutex{};
 
     cbm::algo::kf::SetupBuilder fBuilder{};       ///< KF-setup builder
-    DetectorIDArray_t<bool> fvbDetUsed{{false}};  ///< Detector subsystem usage flag
+    DetectorIDArray_t<bool> fvbDetInGeometry{{false}};  ///< Is detector subsystem in geometry?
+    DetectorIDArray_t<bool> fvbDetHasHits{{false}};     ///< Does detector subsystem have hits?
 
     /// \brief An instance of the tracking KF-setup in a double precision
     /// \note  The original magnetic field is defined.
-- 
GitLab