From 1e94054ca1e3d4ac3f4d70cbb12ce4f8af55469b Mon Sep 17 00:00:00 2001
From: Georgios Stavropoulos <George.Stavropoulos@cern.ch>
Date: Mon, 20 Jul 2020 13:23:10 +0200
Subject: [PATCH] Migrate CscClusterization to the MuonDetectorManager from the
 conditions store.

---
 .../CscPeakThresholdClusterBuilderTool.cxx    | 76 ++++++++++-------
 .../src/CscPeakThresholdClusterBuilderTool.h  | 15 ++--
 .../src/CscThresholdClusterBuilderTool.cxx    | 81 +++++++++++--------
 .../src/CscThresholdClusterBuilderTool.h      | 15 ++--
 .../src/ParabolaCscClusterFitter.cxx          | 18 +++--
 .../src/ParabolaCscClusterFitter.h            | 10 +--
 .../src/QratCscClusterFitter.cxx              | 16 +++-
 .../src/QratCscClusterFitter.h                |  8 +-
 .../src/SimpleCscClusterFitter.cxx            | 15 +++-
 .../src/SimpleCscClusterFitter.h              |  8 +-
 10 files changed, 160 insertions(+), 102 deletions(-)

diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.cxx
index 6bbeef22093..70746b9da01 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.cxx
@@ -9,7 +9,6 @@
 #include "MuonPrepRawData/CscStripPrepDataContainer.h"
 #include "MuonPrepRawData/CscStripPrepData.h"
 #include "MuonReadoutGeometry/CscReadoutElement.h"
-#include "MuonReadoutGeometry/MuonDetectorManager.h"
 #include "TrkSurfaces/Surface.h"
 #include "MuonPrepRawData/CscClusterStatus.h"
 
@@ -67,7 +66,7 @@ CscPeakThresholdClusterBuilderTool(const std::string &type, const std::string &a
     m_pfitter_def("SimpleCscClusterFitter/SimpleCscClusterFitter"),
     m_pfitter_prec("QratCscClusterFitter/QratCscClusterFitter"),
     m_pfitter_split("CscSplitClusterFitter/CscSplitClusterFitter"),
-    m_pmuon_detmgr(0), m_phelper(0), m_fullEventDone(false)
+    m_fullEventDone(false)
 {
 
   declareInterface<ICscClusterBuilder>(this);
@@ -138,14 +137,9 @@ StatusCode CscPeakThresholdClusterBuilderTool::initialize(){
   } 
   ATH_MSG_DEBUG ( "Retrieved CSC split cluster fitting tool" );
                  
-  if ( detStore()->retrieve(m_pmuon_detmgr).isFailure() ) {
-    ATH_MSG_FATAL ( " Cannot retrieve MuonGeoModel " );
-    return StatusCode::FAILURE;
-  }
-  ATH_MSG_DEBUG ( "Retrieved geometry." );
-
-  m_phelper = m_pmuon_detmgr->cscIdHelper();
-
+  // retrieve MuonDetectorManager from the conditions store     
+  ATH_CHECK(m_DetectorManagerKey.initialize()); 
+  ATH_CHECK(m_idHelperSvc.retrieve());
 
   return StatusCode::SUCCESS;
 }
@@ -159,7 +153,7 @@ StatusCode CscPeakThresholdClusterBuilderTool::getClusters(std::vector<Identifie
 
   if (!m_cluster_handle.isPresent()) {
     /// clean up the PrepRawData container
-    auto object = std::make_unique<CscPrepDataContainer>(m_phelper->module_hash_max());
+    auto object = std::make_unique<CscPrepDataContainer>(m_idHelperSvc->cscIdHelper().module_hash_max());
     
     /// record the container in storeGate
     if ( m_cluster_handle.record(std::move(object)).isFailure() ) {
@@ -234,9 +228,9 @@ StatusCode CscPeakThresholdClusterBuilderTool::getClusters(IdentifierHash givenH
   ATH_MSG_DEBUG ( "Retrieved " << col->size() << " CSC Strip PrepDatas." );
   
   Identifier colid = col->identify();
-  int istation = m_phelper->stationName(colid) - 49;
-  int zsec = m_phelper->stationEta(colid);
-  int phisec = m_phelper->stationPhi(colid);
+  int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49;
+  int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid);
+  int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid);
 
   ATH_MSG_DEBUG ( "  Strip collection " << chamber(istation, zsec, phisec)
                   << " has " << col->size() << " strips" );
@@ -245,6 +239,14 @@ StatusCode CscPeakThresholdClusterBuilderTool::getClusters(IdentifierHash givenH
   vector<const CscStripPrepData*> strips[8];
   int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0};
   
+  // retrieve MuonDetectorManager from the conditions store  
+  SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey};     
+  const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr();     
+  if(MuonDetMgr==nullptr){       
+    ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object");       
+    return StatusCode::FAILURE;     
+  }
+
   IdentifierHash hash;
   // Loop over digits and fill these arrays.
   for ( CscStripPrepDataCollection::const_iterator idig=col->begin();
@@ -252,9 +254,9 @@ StatusCode CscPeakThresholdClusterBuilderTool::getClusters(IdentifierHash givenH
     const CscStripPrepData& dig = **idig;
     Identifier did = dig.identify();
     hash=dig.collectionHash();
-    const CscReadoutElement* pro = m_pmuon_detmgr->getCscReadoutElement(did);
-    int wlay = m_phelper->wireLayer(did);
-    int measphi = m_phelper->measuresPhi(did);
+    const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did);
+    int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did);
+    int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did);
     int idx = 2*(wlay-1) + measphi;
     // First entry for a cathode plane, initialize.
     if ( maxstrip[idx] == 0 ) {
@@ -262,7 +264,7 @@ StatusCode CscPeakThresholdClusterBuilderTool::getClusters(IdentifierHash givenH
       for ( int istrip=0; istrip<maxstrip[idx]; ++istrip ) 
         strips[idx].push_back(0);
     }
-    int istrip = m_phelper->strip(did) - 1;
+    int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1;
     if ( istrip<0 || istrip>=maxstrip[idx] ) {
       ATH_MSG_WARNING ( "Invalid strip number" );
       continue;
@@ -315,9 +317,9 @@ StatusCode CscPeakThresholdClusterBuilderTool::getClusters(std::vector<Identifie
        icol!=con.end(); ++icol) {
     const CscStripPrepDataCollection& col = **icol;
     Identifier colid = col.identify();
-    int istation = m_phelper->stationName(colid) - 49;
-    int zsec = m_phelper->stationEta(colid);
-    int phisec = m_phelper->stationPhi(colid);
+    int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49;
+    int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid);
+    int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid);
     ATH_MSG_DEBUG ( "  Strip collection " << chamber(istation, zsec, phisec)
                     << " has " << col.size() << " strips" );
     
@@ -325,6 +327,14 @@ StatusCode CscPeakThresholdClusterBuilderTool::getClusters(std::vector<Identifie
     vector<const CscStripPrepData*> strips[8];
     int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0};
     
+    // retrieve MuonDetectorManager from the conditions store  
+    SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey};     
+    const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr();     
+    if(MuonDetMgr==nullptr){       
+      ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object");       
+      return StatusCode::FAILURE;     
+    }
+
     IdentifierHash hash;
     // Loop over digits and fill these arrays.
     for ( CscStripPrepDataCollection::const_iterator idig=col.begin();
@@ -332,9 +342,9 @@ StatusCode CscPeakThresholdClusterBuilderTool::getClusters(std::vector<Identifie
       const CscStripPrepData& dig = **idig;
       Identifier did = dig.identify();
       hash=dig.collectionHash();
-      const CscReadoutElement* pro = m_pmuon_detmgr->getCscReadoutElement(did);
-      int wlay = m_phelper->wireLayer(did);
-      int measphi = m_phelper->measuresPhi(did);
+      const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did);
+      int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did);
+      int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did);
       int idx = 2*(wlay-1) + measphi;
       // First entry for a cathode plane, initialize.
       if ( maxstrip[idx] == 0 ) {
@@ -342,7 +352,7 @@ StatusCode CscPeakThresholdClusterBuilderTool::getClusters(std::vector<Identifie
         for ( int istrip=0; istrip<maxstrip[idx]; ++istrip ) 
           strips[idx].push_back(0);
       }
-      int istrip = m_phelper->strip(did) - 1;
+      int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1;
       if ( istrip<0 || istrip>=maxstrip[idx] ) {
         ATH_MSG_WARNING ( "Invalid strip number" );
         continue;
@@ -415,7 +425,7 @@ make_clusters(bool measphi, const vector<const CscStripPrepData*>& strips,CscPre
 
     if ( pstrip ) {
       if (!newCollection) {
-        Identifier elementId = m_phelper->elementID(pstrip->identify());
+        Identifier elementId = m_idHelperSvc->cscIdHelper().elementID(pstrip->identify());
         cscHashId=pstrip->collectionHash(); 
         newCollection = new CscPrepDataCollection(cscHashId);
         newCollection->setIdentifier(elementId);
@@ -539,6 +549,14 @@ make_clusters(bool measphi, const vector<const CscStripPrepData*>& strips,CscPre
       }
     }
     
+    // retrieve MuonDetectorManager from the conditions store  
+    SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey};     
+    const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr();     
+    if(MuonDetMgr==nullptr){       
+      ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object");       
+      return 0;     
+    }
+
     // Check results.
     unsigned int nresults = results.size();
     for (unsigned int ire=0; ire<nresults; ++ire) {
@@ -574,11 +592,11 @@ make_clusters(bool measphi, const vector<const CscStripPrepData*>& strips,CscPre
       // Create ATLAS CSC cluster.
       Identifier cluster_id = pstrip_id->identify();
       IdentifierHash cluster_hash = pstrip_id->collectionHash();
-      int zsec = m_phelper->stationEta(cluster_id);
-      int wlay = m_phelper->wireLayer(cluster_id);
+      int zsec = m_idHelperSvc->cscIdHelper().stationEta(cluster_id);
+      int wlay = m_idHelperSvc->cscIdHelper().wireLayer(cluster_id);
       // This local position is in the muon (not tracking) coordinate system.
       //      const CscReadoutElement* pro = pstrip_id->detectorElement();
-      const CscReadoutElement* pro = m_pmuon_detmgr->getCscReadoutElement(cluster_id);
+      const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(cluster_id);
       Amg::Vector3D local_pos = pro->nominalLocalClusterPos(zsec, wlay, measphi, pos);
       Amg::MatrixX* cov = new Amg::MatrixX(1,1);
       (*cov)(0,0) = err*err;
diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.h
index 69e9d61c6a3..6d6d5ad1bf7 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.h
@@ -61,11 +61,9 @@
 #include "CscClusterization/ICscClusterFitter.h"
 #include "CscClusterization/ICscClusterBuilder.h"
 
+#include "MuonReadoutGeometry/MuonDetectorManager.h"
+#include "MuonIdHelpers/IMuonIdHelperSvc.h"
 
-namespace MuonGM {
-  class MuonDetectorManager;
-}
-class CscIdHelper;
 namespace Muon {
   class CscPrepData;
   class CscStripPrepData;
@@ -125,12 +123,11 @@ private:  // data
   ToolHandle<ICscClusterFitter> m_pfitter_prec;
   ToolHandle<ICscClusterFitter> m_pfitter_split;
 
-  // Pointer to muon geometry manager.
-  const MuonGM::MuonDetectorManager* m_pmuon_detmgr;
-
+  ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
 
-  // Geometry helper.
-  const CscIdHelper* m_phelper;
+  /** retrieve MuonDetectorManager from the conditions store */     
+  SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey {this, "DetectorManagerKey", 	
+      "MuonDetectorManager", 	"Key of input MuonDetectorManager condition data"};    
 
   // keep track of full event being already processed
   bool m_fullEventDone;
diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.cxx
index 2067a000b74..5e4ed65d17a 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.cxx
@@ -11,7 +11,6 @@
 #include "MuonPrepRawData/CscStripPrepDataContainer.h"
 #include "MuonPrepRawData/CscStripPrepData.h"
 #include "MuonReadoutGeometry/CscReadoutElement.h"
-#include "MuonReadoutGeometry/MuonDetectorManager.h"
 #include "TrkSurfaces/Surface.h"
 #include "MuonPrepRawData/CscClusterStatus.h"
 
@@ -72,7 +71,7 @@ CscThresholdClusterBuilderTool(const std::string &type, const std::string &aname
     m_pfitter_def("SimpleCscClusterFitter/SimpleCscClusterFitter"),
     m_pfitter_prec("QratCscClusterFitter/QratCscClusterFitter"),
     m_pfitter_split("CscSplitClusterFitter/CscSplitClusterFitter"),
-    m_pmuon_detmgr(0), m_phelper(0), m_fullEventDone(false){
+    m_fullEventDone(false){
 
   declareInterface<ICscClusterBuilder>(this);
   
@@ -160,15 +159,10 @@ StatusCode CscThresholdClusterBuilderTool::initialize(){
     return StatusCode::RECOVERABLE;
   } 
   ATH_MSG_DEBUG ( "Retrieved CSC split cluster fitting tool" );
-                 
-  if ( detStore()->retrieve(m_pmuon_detmgr).isFailure() ) {
-    ATH_MSG_ERROR ( " Cannot retrieve MuonGeoModel " );
-    return StatusCode::RECOVERABLE;
-  }
-  ATH_MSG_DEBUG ( "Retrieved geometry." );
-
-  m_phelper = m_pmuon_detmgr->cscIdHelper();
 
+  // retrieve MuonDetectorManager from the conditions store     
+  ATH_CHECK(m_DetectorManagerKey.initialize()); 
+  ATH_CHECK(m_idHelperSvc.retrieve());
 
   return StatusCode::SUCCESS;
 }
@@ -180,7 +174,7 @@ StatusCode CscThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHas
   // clear output vector of selected data collections containing data
   decodedIds.clear();
   SG::WriteHandle<Muon::CscPrepDataContainer> wh_pclusters(m_pclusters);
-  CscPrepDataContainer *object  = new CscPrepDataContainer(m_phelper->module_hash_max());  
+  CscPrepDataContainer *object  = new CscPrepDataContainer(m_idHelperSvc->cscIdHelper().module_hash_max());  
 
    if (!wh_pclusters.isPresent()) {
      /// record the container in storeGate
@@ -258,9 +252,9 @@ StatusCode CscThresholdClusterBuilderTool::getClusters(IdentifierHash givenHashI
   ATH_MSG_DEBUG ( "Retrieved " << col->size() << " CSC Strip PrepDatas." );
   
   Identifier colid = col->identify();
-  int istation = m_phelper->stationName(colid) - 49;
-  int zsec = m_phelper->stationEta(colid);
-  int phisec = m_phelper->stationPhi(colid);
+  int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49;
+  int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid);
+  int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid);
 
   ATH_MSG_DEBUG ( "  Strip collection " << chamber(istation, zsec, phisec)
                   << " has " << col->size() << " strips" );
@@ -269,6 +263,14 @@ StatusCode CscThresholdClusterBuilderTool::getClusters(IdentifierHash givenHashI
   vector<const CscStripPrepData*> strips[8];
   int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0};
   
+  // retrieve MuonDetectorManager from the conditions store  
+  SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey};     
+  const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr();     
+  if(MuonDetMgr==nullptr){       
+    ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object");       
+    return StatusCode::FAILURE;     
+  }
+
   IdentifierHash hash;
   // Loop over digits and fill these arrays.
   for ( CscStripPrepDataCollection::const_iterator idig=col->begin();
@@ -276,9 +278,9 @@ StatusCode CscThresholdClusterBuilderTool::getClusters(IdentifierHash givenHashI
     const CscStripPrepData& dig = **idig;
     Identifier did = dig.identify();
     hash=dig.collectionHash();
-    const CscReadoutElement* pro = m_pmuon_detmgr->getCscReadoutElement(did);
-    int wlay = m_phelper->wireLayer(did);
-    int measphi = m_phelper->measuresPhi(did);
+    const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did);
+    int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did);
+    int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did);
     int idx = 2*(wlay-1) + measphi;
     // First entry for a cathode plane, initialize.
     if ( maxstrip[idx] == 0 ) {
@@ -286,7 +288,7 @@ StatusCode CscThresholdClusterBuilderTool::getClusters(IdentifierHash givenHashI
       for ( int istrip=0; istrip<maxstrip[idx]; ++istrip ) 
         strips[idx].push_back(0);
     }
-    int istrip = m_phelper->strip(did) - 1;
+    int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1;
     if ( istrip<0 || istrip>=maxstrip[idx] ) {
       ATH_MSG_WARNING ( "Invalid strip number" );
       continue;
@@ -344,16 +346,24 @@ StatusCode CscThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHas
       continue;      
     }
     Identifier colid = col.identify();
-    int istation = m_phelper->stationName(colid) - 49;
-    int zsec = m_phelper->stationEta(colid);
-    int phisec = m_phelper->stationPhi(colid);
-    ATH_MSG_DEBUG ( "**Strip collection " << chamber(istation, zsec, phisec) << " sector " << m_phelper->sector(colid) 
+    int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49;
+    int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid);
+    int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid);
+    ATH_MSG_DEBUG ( "**Strip collection " << chamber(istation, zsec, phisec) << " sector " << m_idHelperSvc->cscIdHelper().sector(colid) 
                     << " has " << col.size() << " strips" );
     
     // Create arrays to hold digits and cathode plane parameters.
     vector<const CscStripPrepData*> strips[8];
     int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0};
     
+    // retrieve MuonDetectorManager from the conditions store  
+    SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey};     
+    const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr();     
+    if(MuonDetMgr==nullptr){       
+      ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object");       
+      return StatusCode::FAILURE;     
+    }
+
     IdentifierHash hash;
     // Loop over digits and fill these arrays.
     for ( CscStripPrepDataCollection::const_iterator idig=col.begin();
@@ -361,9 +371,9 @@ StatusCode CscThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHas
       const CscStripPrepData& dig = **idig;
       Identifier did = dig.identify();
       hash=dig.collectionHash();
-      const CscReadoutElement* pro = m_pmuon_detmgr->getCscReadoutElement(did);
-      int wlay = m_phelper->wireLayer(did);
-      int measphi = m_phelper->measuresPhi(did);
+      const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did);
+      int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did);
+      int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did);
       int idx = 2*(wlay-1) + measphi;
       // First entry for a cathode plane, initialize.
       if ( maxstrip[idx] == 0 ) {
@@ -371,7 +381,7 @@ StatusCode CscThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHas
         for ( int istrip=0; istrip<maxstrip[idx]; ++istrip ) 
           strips[idx].push_back(0);
       }
-      int istrip = m_phelper->strip(did) - 1;
+      int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1;
       if ( istrip<0 || istrip>=maxstrip[idx] ) {
         ATH_MSG_WARNING ( "Invalid strip number" );
         continue;
@@ -386,7 +396,7 @@ StatusCode CscThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHas
         int idx = 2*(wlay-1) + measphi;
         if ( maxstrip[idx] ) {
           ATH_MSG_DEBUG ("*** " <<  chamber(istation, zsec, phisec) << " sector "
-                         << m_phelper->sector(colid) << "  " << wlay << "th layer ");
+                         << m_idHelperSvc->cscIdHelper().sector(colid) << "  " << wlay << "th layer ");
           make_clusters(measphi, strips[idx], newCollection);
         }
       }
@@ -449,7 +459,7 @@ make_clusters(bool measphi, const vector<const CscStripPrepData*>& strips,
     bool isBadChannel = false;
     if ( pstrip ) {
       if (!newCollection) {
-        Identifier elementId = m_phelper->elementID(pstrip->identify());
+        Identifier elementId = m_idHelperSvc->cscIdHelper().elementID(pstrip->identify());
         cscHashId=pstrip->collectionHash(); 
         newCollection = new CscPrepDataCollection(cscHashId);
         newCollection->setIdentifier(elementId);
@@ -459,7 +469,7 @@ make_clusters(bool measphi, const vector<const CscStripPrepData*>& strips,
   
       IdentifierHash stripHash;
       Identifier stripId = pstrip->identify();
-      if (m_phelper->get_channel_hash(stripId, stripHash)){ 
+      if (m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, stripHash)){ 
         ATH_MSG_WARNING ( "Unable to get CSC striphash id " << " the identifier is " );
         stripId.show();
       }
@@ -935,10 +945,17 @@ make_clusters(bool measphi, const vector<const CscStripPrepData*>& strips,
       // Create ATLAS CSC cluster.
       Identifier cluster_id = pstrip_id->identify();
       IdentifierHash cluster_hash = pstrip_id->collectionHash();
-      int zsec = m_phelper->stationEta(cluster_id);
-      int wlay = m_phelper->wireLayer(cluster_id);
+      int zsec = m_idHelperSvc->cscIdHelper().stationEta(cluster_id);
+      int wlay = m_idHelperSvc->cscIdHelper().wireLayer(cluster_id);
       // This local position is in the muon (not tracking) coordinate system.
-      const CscReadoutElement* pro = m_pmuon_detmgr->getCscReadoutElement(cluster_id);
+      // retrieve MuonDetectorManager from the conditions store  
+      SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey};     
+      const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr();     
+      if(MuonDetMgr==nullptr){       
+	ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object");       
+	return 0;     
+      }
+      const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(cluster_id);
       //Amg::Vector3D local_pos = pro->localClusterPos(zsec, wlay, measphi, pos);
       Amg::Vector3D localTrk_pos = pro->nominalLocalClusterPos(zsec, wlay, measphi, pos);
 
diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.h
index ef02cd258cb..1343046d435 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.h
@@ -61,14 +61,13 @@
 #include "MuonPrepRawData/CscPrepDataContainer.h"
 #include "MuonPrepRawData/CscStripPrepDataContainer.h"
 
+#include "MuonReadoutGeometry/MuonDetectorManager.h"
+#include "MuonIdHelpers/IMuonIdHelperSvc.h"
+
 class ICscCalibTool;
 class ICscStripFitter;
 class ICscClusterFitter;
 
-namespace MuonGM {
-  class MuonDetectorManager;
-}
-class CscIdHelper;
 namespace Muon {
   class CscPrepData;
   class CscStripPrepData;
@@ -137,11 +136,11 @@ private:  // data
   ToolHandle<ICscClusterFitter> m_pfitter_prec;
   ToolHandle<ICscClusterFitter> m_pfitter_split;
 
-  // Pointer to muon geometry manager.
-  const MuonGM::MuonDetectorManager* m_pmuon_detmgr;
+  ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
 
-  // Geometry helper.
-  const CscIdHelper* m_phelper;
+  /** retrieve MuonDetectorManager from the conditions store */     
+  SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey {this, "DetectorManagerKey", 	
+      "MuonDetectorManager", 	"Key of input MuonDetectorManager condition data"};    
 
   // keep track of full event being already processed
   bool m_fullEventDone;
diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/ParabolaCscClusterFitter.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/ParabolaCscClusterFitter.cxx
index 2c7272b261d..ffc195ba6e6 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/ParabolaCscClusterFitter.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/ParabolaCscClusterFitter.cxx
@@ -8,7 +8,6 @@
 #include "MuonPrepRawData/CscStripPrepData.h"
 #include "MuonPrepRawData/CscPrepData.h"
 #include "MuonReadoutGeometry/CscReadoutElement.h"
-#include "MuonReadoutGeometry/MuonDetectorManager.h"
 #include "TrkEventPrimitives/ParamDefs.h"
 #include "TrkEventPrimitives/LocalDirection.h"
 #include "EventPrimitives/EventPrimitives.h"
@@ -100,8 +99,7 @@ double ParabolaCscClusterFitter::ParabolaCorrection(CscPlane &plane, double &raw
 //*************************************************************************
 
 ParabolaCscClusterFitter::ParabolaCscClusterFitter(std::string type, std::string aname, const IInterface* parent) :
-    AthAlgTool(type, aname, parent),
-    m_detMgr(nullptr) {
+  AthAlgTool(type, aname, parent) {
   declareInterface<ICscClusterFitter>(this);
   m_max_width.push_back(5);  // CSS eta
   m_max_width.push_back(5);  // CSL eta
@@ -121,7 +119,6 @@ StatusCode ParabolaCscClusterFitter::initialize() {
   
   ATH_MSG_VERBOSE ( "Initalizing " << name() );
 
-  ATH_CHECK(detStore()->retrieve(m_detMgr,"Muon"));
   ATH_CHECK(m_idHelperSvc.retrieve());
 
   ATH_MSG_DEBUG ( "Properties for " << name() << ":" );
@@ -130,6 +127,8 @@ StatusCode ParabolaCscClusterFitter::initialize() {
   ATH_MSG_DEBUG ( "   CSS eta pos-slope slope: " << m_xtan_css_eta_slope );
   ATH_MSG_DEBUG ( "  CSL eta pos-slope offset: " << m_xtan_csl_eta_offset );
   ATH_MSG_DEBUG ( "   CSL eta pos-slope slope: " << m_xtan_csl_eta_slope );
+  // retrieve MuonDetectorManager from the conditions store     
+  ATH_CHECK(m_DetectorManagerKey.initialize()); 
 
   return StatusCode::SUCCESS;
 }
@@ -185,7 +184,16 @@ Results ParabolaCscClusterFitter::fit(const StripFitList& sfits, double tantheta
   // Use the first strip to extract the layer parameters.
   const CscStripPrepData* pstrip = sfits[0].strip;
   Identifier idStrip0 = pstrip->identify();
-  const CscReadoutElement* pro = m_detMgr->getCscReadoutElement(idStrip0);
+
+  // retrieve MuonDetectorManager from the conditions store  
+  SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey};     
+  const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr();     
+  if(MuonDetMgr==nullptr){       
+    ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object");       
+    return results;     
+  }
+  const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(idStrip0);
+
   //  const CscReadoutElement* pro = pstrip->detectorElement(); fixed by Woochun
   bool measphi = m_idHelperSvc->cscIdHelper().CscIdHelper::measuresPhi(idStrip0);
   double pitch = pro->cathodeReadoutPitch(0, measphi);
diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/ParabolaCscClusterFitter.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/ParabolaCscClusterFitter.h
index 2831cf1eda4..daee9ce0116 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/ParabolaCscClusterFitter.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/ParabolaCscClusterFitter.h
@@ -16,14 +16,12 @@ May 2009
 #include "AthenaBaseComps/AthAlgTool.h"
 #include "GaudiKernel/ServiceHandle.h"
 
+#include "MuonReadoutGeometry/MuonDetectorManager.h"
 #include "MuonIdHelpers/IMuonIdHelperSvc.h"
 
 namespace Muon {
   class CscPrepData;
 }
-namespace MuonGM {
-  class MuonDetectorManager;
-}
 
 enum CscStation { UNKNOWN_STATION, CSS, CSL };
 enum CscPlane { CSS_ETA, CSL_ETA, CSS_PHI, CSL_PHI, UNKNOWN_PLANE };
@@ -79,9 +77,11 @@ private:
   /** threshold multiplier  for cluster peak finding */
   double m_multi;
 
-  const MuonGM::MuonDetectorManager* m_detMgr;
-
   ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
 
+  /** retrieve MuonDetectorManager from the conditions store */     
+  SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey {this, "DetectorManagerKey", 	
+      "MuonDetectorManager", 	"Key of input MuonDetectorManager condition data"};    
+
 };
 #endif
diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.cxx
index fa3e9750b5e..d75e378db93 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.cxx
@@ -8,7 +8,6 @@
 #include "MuonPrepRawData/CscStripPrepData.h"
 #include "MuonPrepRawData/CscPrepData.h"
 #include "MuonReadoutGeometry/CscReadoutElement.h"
-#include "MuonReadoutGeometry/MuonDetectorManager.h"
 #include "TrkEventPrimitives/ParamDefs.h"
 #include "TrkEventPrimitives/LocalDirection.h"
 #include "EventPrimitives/EventPrimitives.h"
@@ -211,7 +210,6 @@ int qrat_atanh(const double a, const double b, double c, const double x0,
 
 QratCscClusterFitter::QratCscClusterFitter(std::string type, std::string aname, const IInterface* parent) :
     AthAlgTool(type, aname, parent),
-    m_detMgr(nullptr), 
     m_alignmentTool("CscAlignmentTool/CscAlignmentTool", this)
 {
   declareInterface<ICscClusterFitter>(this);
@@ -263,7 +261,9 @@ StatusCode QratCscClusterFitter::initialize() {
   
   ATH_MSG_VERBOSE ( "Initalizing " << name() );
 
-  ATH_CHECK(detStore()->retrieve(m_detMgr,"Muon"));
+  // retrieve MuonDetectorManager from the conditions store     
+  ATH_CHECK(m_DetectorManagerKey.initialize()); 
+
   ATH_CHECK(m_idHelperSvc.retrieve());
 
   if ( m_alignmentTool.retrieve().isFailure() )   {
@@ -374,7 +374,15 @@ Results QratCscClusterFitter::fit(const StripFitList& sfits, double tantheta) co
   const CscStripPrepData* pstrip = sfits[0].strip;
   Identifier idStrip0 = pstrip->identify();
 
-  const CscReadoutElement* pro = m_detMgr->getCscReadoutElement(idStrip0);
+  // retrieve MuonDetectorManager from the conditions store  
+  SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey};     
+  const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr();     
+  if(MuonDetMgr==nullptr){       
+    ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object");       
+    return results;     
+  }
+  const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(idStrip0);
+
   bool measphi = m_idHelperSvc->cscIdHelper().CscIdHelper::measuresPhi(idStrip0);
   double pitch = pro->cathodeReadoutPitch(0, measphi);
   unsigned int maxstrip = pro->maxNumberOfStrips(measphi);
diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.h
index 4108bed62de..ff962f4c1b0 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.h
@@ -15,6 +15,7 @@
 #include "GaudiKernel/ServiceHandle.h"
 #include "GaudiKernel/ToolHandle.h"
 
+#include "MuonReadoutGeometry/MuonDetectorManager.h"
 #include "MuonIdHelpers/IMuonIdHelperSvc.h"
 #include "MuonPrepRawData/CscClusterStatus.h"
 #include "CscClusterization/ICscAlignmentTool.h"
@@ -22,9 +23,6 @@
 namespace Muon {
   class CscPrepData;
 }
-namespace MuonGM {
-  class MuonDetectorManager;
-}
 
 class QratCscClusterFitter : virtual public ICscClusterFitter, public AthAlgTool {
   
@@ -77,7 +75,9 @@ private:
 
   double m_dposmin; // MS: minimum position error in mm
 
-  const MuonGM::MuonDetectorManager* m_detMgr;
+  /** retrieve MuonDetectorManager from the conditions store */     
+  SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey {this, "DetectorManagerKey", 	
+      "MuonDetectorManager", 	"Key of input MuonDetectorManager condition data"};    
 
   ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
 
diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.cxx
index 2a1688d5394..65eec9561b4 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.cxx
@@ -8,7 +8,6 @@
 #include "MuonPrepRawData/CscPrepData.h"
 #include "MuonPrepRawData/CscStripPrepData.h"
 #include "MuonReadoutGeometry/CscReadoutElement.h"
-#include "MuonReadoutGeometry/MuonDetectorManager.h"
 
 #include <sstream>
 #include <iomanip>
@@ -26,7 +25,6 @@ enum CscPlane { CSS_R, CSL_R, CSS_PHI, CSL_PHI, UNKNOWN_PLANE };
 
 SimpleCscClusterFitter::SimpleCscClusterFitter(std::string type, std::string aname, const IInterface* parent) :
     AthAlgTool(type, aname, parent),
-    m_detMgr(nullptr),
     m_alignmentTool("CscAlignmentTool/CscAlignmentTool", this)
 {
   declareInterface<ICscClusterFitter>(this);
@@ -59,6 +57,8 @@ StatusCode SimpleCscClusterFitter::initialize() {
   } else {
     ATH_MSG_DEBUG ( name() << ": retrieved " << m_alignmentTool );
   }
+  // retrieve MuonDetectorManager from the conditions store     
+  ATH_CHECK(m_DetectorManagerKey.initialize()); 
   return StatusCode::SUCCESS;
 }
 
@@ -93,7 +93,16 @@ Results SimpleCscClusterFitter::fit(const StripFitList& sfits) const {
      return results;
   }
   Identifier idStrip0 = pstrip->identify();
-  const CscReadoutElement* pro = m_detMgr->getCscReadoutElement(idStrip0);
+
+  // retrieve MuonDetectorManager from the conditions store  
+  SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey};     
+  const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr();     
+  if(MuonDetMgr==nullptr){       
+    ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object");       
+    return results;     
+  }
+  const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(idStrip0);
+
   bool measphi = m_idHelperSvc->cscIdHelper().CscIdHelper::measuresPhi(idStrip0);
   double pitch = pro->cathodeReadoutPitch(0, measphi);
   int maxstrip = pro->maxNumberOfStrips(measphi);
diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.h
index c78f77eae9f..7421986bb8b 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.h
@@ -15,6 +15,7 @@
 #include "GaudiKernel/ServiceHandle.h"
 #include "GaudiKernel/ToolHandle.h"
 
+#include "MuonReadoutGeometry/MuonDetectorManager.h"
 #include "MuonIdHelpers/IMuonIdHelperSvc.h"
 #include "MuonPrepRawData/CscClusterStatus.h"
 #include "CscClusterization/ICscAlignmentTool.h"
@@ -22,9 +23,6 @@
 namespace Muon {
   class CscPrepData;
 }
-namespace MuonGM {
-  class MuonDetectorManager;
-}
 
 class SimpleCscClusterFitter : virtual public ICscClusterFitter, public AthAlgTool {
   
@@ -54,6 +52,10 @@ private:
 
   ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
 
+  /** retrieve MuonDetectorManager from the conditions store */     
+  SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey {this, "DetectorManagerKey", 	
+      "MuonDetectorManager", 	"Key of input MuonDetectorManager condition data"};    
+
   ToolHandle<ICscAlignmentTool> m_alignmentTool;
 };
 #endif
-- 
GitLab