From 3445749f959bcefc7559aa29f85363aa4c3b1c66 Mon Sep 17 00:00:00 2001
From: Nicolas Koehler <nicolas.koehler@cern.ch>
Date: Thu, 30 Apr 2020 18:18:29 +0000
Subject: [PATCH] Use AtlasFieldCacheCondObj instead of IMagFieldSvc in
 MuonSegmentMakerTools

---
 .../MuonConfig/python/MuonRecToolsConfig.py   |   9 --
 .../python/MuonTrackBuildingConfig.py         |  10 +-
 .../MuonRecExample/python/MooreTools.py       |   1 +
 .../python/MuonRecExampleConfigDb.py          |   4 +-
 .../MuonSegmentMatchingTools/CMakeLists.txt   |   3 +-
 .../src/MuonSegmentMatchingTool.cxx           | 125 ++++++------------
 .../src/MuonSegmentMatchingTool.h             |  27 ++--
 .../MuonSegmentMomentum/CMakeLists.txt        |   9 +-
 .../src/MuonSegmentMomentumFromField.cxx      | 107 +++++++--------
 .../src/MuonSegmentMomentumFromField.h        |  24 ++--
 10 files changed, 122 insertions(+), 197 deletions(-)

diff --git a/MuonSpectrometer/MuonConfig/python/MuonRecToolsConfig.py b/MuonSpectrometer/MuonConfig/python/MuonRecToolsConfig.py
index d1191f21402..3f7d08d8082 100644
--- a/MuonSpectrometer/MuonConfig/python/MuonRecToolsConfig.py
+++ b/MuonSpectrometer/MuonConfig/python/MuonRecToolsConfig.py
@@ -66,13 +66,7 @@ def MuonSeededSegmentFinderCfg(flags,name="MuonSeededSegmentFinder", **kwargs):
         
 def MuonSegmentMomentumFromFieldCfg(flags, name="MuonSegmentMomentumFromField", **kwargs):
     MuonSegmentMomentumFromField=CompFactory.MuonSegmentMomentumFromField
-    from MagFieldServices.MagFieldServicesConfig import MagneticFieldSvcCfg
-    
     result = ComponentAccumulator()
-    acc  = MagneticFieldSvcCfg(flags) 
-    magfieldsvc = acc.getPrimary()
-    result.merge(acc)
-    kwargs.setdefault("MagFieldSvc", magfieldsvc)
     
     navigator_ca = MuonNavigatorCfg(flags)
     navigator = navigator_ca.popPrivateTools()
@@ -84,9 +78,6 @@ def MuonSegmentMomentumFromFieldCfg(flags, name="MuonSegmentMomentumFromField",
     muon_prop = acc.getPrimary()
     result.merge(acc)
     kwargs.setdefault("PropagatorTool", muon_prop)
-    
-    kwargs.setdefault("HasCSC",  flags.Detector.GeometryCSC)
-    kwargs.setdefault("HasSTgc", flags.Detector.GeometrysTGC)
         
     muon_seg_mom_from_field = MuonSegmentMomentumFromField(name=name, **kwargs)
     result.setPrivateTools(muon_seg_mom_from_field)
diff --git a/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py b/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py
index bab91aac709..5b9fd569662 100644
--- a/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py
+++ b/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py
@@ -182,24 +182,20 @@ def MooTrackBuilderCfg(flags, name="MooTrackBuilderTemplate", **kwargs):
 # Not bothering with MuonSegmentMatchingToolTight - just pass in TightSegmentMatching=True
 def MuonSegmentMatchingToolCfg(flags, name="MuonSegmentMatchingTool", **kwargs):
     Muon__MuonSegmentMatchingTool=CompFactory.Muon.MuonSegmentMatchingTool
-    from MagFieldServices.MagFieldServicesConfig import MagneticFieldSvcCfg
     
     kwargs.setdefault( "doThetaMatching", flags.Muon.useSegmentMatching)
     kwargs.setdefault( "doPhiMatching", False )
     if flags.Beam.Type == 'cosmics':
         kwargs.setdefault("OverlapMatchAveragePhiHitPullCut",  200.)
-            
+        kwargs.setdefault( "ToroidOn", False ) # Was "not jobproperties.BField.allToroidOn()" but do not have access to Field here.
+
     # There are two tools which this depends on which aren't properties and which weren't defined in old configuration
     # Ignore for now, but FIXME one day
     # m_overlapResolvingTool("Muon::MuonSegmentInOverlapResolvingTool/MuonSegmentInOverlapResolvingTool"),
     # m_pairMatchingTool("Muon::MuonSegmentPairMatchingTool/MuonSegmentPairMatchingTool"),
     # Also, residual pull calculator not yet configured. #FIXME
     
-    result  = MagneticFieldSvcCfg(flags) 
-    magfieldsvc = result.getPrimary()
-    
-    kwargs.setdefault( "MagFieldSvc", magfieldsvc )
-    
+    result = ComponentAccumulator()
     matching = Muon__MuonSegmentMatchingTool(name, **kwargs)
     result.setPrivateTools(matching)
     return result
diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MooreTools.py b/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MooreTools.py
index cc388d67f2a..dc60454c09e 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MooreTools.py
+++ b/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MooreTools.py
@@ -288,6 +288,7 @@ class MuonSegmentMatchingTool(CfgMgr.Muon__MuonSegmentMatchingTool):
     def __init__(self,name='MuonSegmentMatchingTool',**kwargs):
         kwargs.setdefault( "doThetaMatching", muonStandaloneFlags.useSegmentMatching() )
         kwargs.setdefault( "doPhiMatching", False )
+        kwargs.setdefault( "ToroidOn", jobproperties.BField.allToroidOn() )
         if beamFlags.beamType() == 'cosmics':
             # switch off cut of phi hit pulls
             kwargs.setdefault("OverlapMatchAveragePhiHitPullCut", 200. )
diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonRecExampleConfigDb.py b/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonRecExampleConfigDb.py
index 198e44c885d..fca36cb8790 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonRecExampleConfigDb.py
+++ b/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonRecExampleConfigDb.py
@@ -62,7 +62,7 @@ addTool("MuonRecExample.MuonRecTools.MuonStraightLineExtrapolator", "MuonStraigh
 
 addTool("Trk::KalmanUpdator", "MuonMeasUpdator")
 
-addService("Muon::MuonIdHelperSvc", "MuonIdHelperSvc", HasCSC=MuonGeometryFlags.hasCSC(), HasSTgc=(CommonGeometryFlags.Run() in ["RUN3", "RUN4"]), HasMM=(CommonGeometryFlags.Run() in ["RUN3", "RUN4"]))
+addService("Muon::MuonIdHelperSvc", "MuonIdHelperSvc", HasCSC=MuonGeometryFlags.hasCSC(), HasSTgc=MuonGeometryFlags.hasSTGC(), HasMM=MuonGeometryFlags.hasMM())
 addTool("Muon::MuonIdHelperTool", "MuonIdHelperTool")
 
 addTool("Muon::MuonTrackTruthTool", "MuonTrackTruthTool")
@@ -85,7 +85,7 @@ addTool( "MuonRecExample.MuonRecTools.MuonChi2TrackFitter", "MuonChi2TrackFitter
 addTool( "MuonRecExample.MuonRecTools.MuonChi2TrackFitter", "MuonChi2SLTrackFitter", StraightLine=True )
 
 addTool( "MuonRecExample.MuonRecTools.MuonSegmentMomentum", "MuonSegmentMomentum" )
-addTool( "MuonRecExample.MuonRecTools.MuonSegmentMomentumFromField", "MuonSegmentMomentumFromField", HasCSC=MuonGeometryFlags.hasCSC(), HasSTgc=(CommonGeometryFlags.Run() in ["RUN3", "RUN4"]))
+addTool( "MuonRecExample.MuonRecTools.MuonSegmentMomentumFromField", "MuonSegmentMomentumFromField")
     
 addTool( "MuonRecExample.MuonRecTools.MuonPhiHitSelector", "MuonPhiHitSelector" )
 
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/CMakeLists.txt b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/CMakeLists.txt
index 90081cc3880..a40dc079278 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/CMakeLists.txt
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/CMakeLists.txt
@@ -10,7 +10,6 @@ atlas_depends_on_subdirs( PRIVATE
                           Control/AthenaBaseComps
                           DetectorDescription/GeoPrimitives
                           GaudiKernel
-                          MagneticField/MagFieldInterfaces
                           MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry
                           MuonSpectrometer/MuonIdHelpers
                           MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonRIO_OnTrack
@@ -34,5 +33,5 @@ atlas_add_component( MuonSegmentMatchingTools
                      src/*.cxx
                      src/components/*.cxx
                      INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS}
-                     LINK_LIBRARIES ${EIGEN_LIBRARIES} AthenaBaseComps GeoPrimitives GaudiKernel MagFieldInterfaces MuonReadoutGeometry MuonIdHelpersLib MuonRIO_OnTrack MuonCompetingRIOsOnTrack MuonSegment MuonRecHelperToolsLib TrkDetDescrUtils TrkGeometry TrkEventPrimitives TrkParameters TrkTrack TrkExInterfaces TrkToolInterfaces )
+                     LINK_LIBRARIES ${EIGEN_LIBRARIES} AthenaBaseComps GeoPrimitives GaudiKernel MuonReadoutGeometry MuonIdHelpersLib MuonRIO_OnTrack MuonCompetingRIOsOnTrack MuonSegment MuonRecHelperToolsLib TrkDetDescrUtils TrkGeometry TrkEventPrimitives TrkParameters TrkTrack TrkExInterfaces TrkToolInterfaces )
 
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/src/MuonSegmentMatchingTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/src/MuonSegmentMatchingTool.cxx
index dd704556cd5..e2cf6904e14 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/src/MuonSegmentMatchingTool.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/src/MuonSegmentMatchingTool.cxx
@@ -1,31 +1,21 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "MuonSegmentMatchingTool.h"
- 
-#include "MuonIdHelpers/MuonIdHelperTool.h"
-#include "MuonRecHelperTools/IMuonEDMHelperSvc.h"
-#include "MuonRecHelperTools/MuonEDMPrinterTool.h"
-
-#include "MuonSegmentMakerToolInterfaces/IMuonSegmentInOverlapResolvingTool.h"
-#include "MuonSegmentMakerToolInterfaces/IMuonSegmentPairMatchingTool.h"
 
 #include "MuonSegment/MuonSegment.h"
 
 #include <cmath>
 #include <iostream>
 
-
 namespace Muon {
 
   MuonSegmentMatchingTool::MuonSegmentMatchingTool(const std::string& ty,const std::string& na,const IInterface* pa)
     : AthAlgTool(ty,na,pa),
-      m_idHelperTool("Muon::MuonIdHelperTool/MuonIdHelperTool"), 
       m_printer("Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"),
       m_overlapResolvingTool("Muon::MuonSegmentInOverlapResolvingTool/MuonSegmentInOverlapResolvingTool"),
       m_pairMatchingTool("Muon::MuonSegmentPairMatchingTool/MuonSegmentPairMatchingTool"),
-      m_magFieldSvc("AtlasFieldSvc",na),
       m_straightLineMatches(0),m_straightLineMatchesGood(0),
       m_overlapMatches(0),m_overlapMatchesGood(0),
       m_curvedMatches(0),m_curvedMatchesGood(0)
@@ -76,49 +66,16 @@ namespace Muon {
     declareProperty("DrExtrapolationRMS", m_drExtrapRMS = 10 );
     declareProperty("DThetaExtrapolationRMS", m_dthetaExtrapRMS = 0.01*2 );
     declareProperty("DrExtrapolationAlignementOffset", m_drExtrapAlignmentOffset = 50 );
-    declareProperty("MagFieldSvc",    m_magFieldSvc );
 }
 
-
-  MuonSegmentMatchingTool::~MuonSegmentMatchingTool(){}
-
-
   StatusCode MuonSegmentMatchingTool::initialize()
   {
-    if( AthAlgTool::initialize().isFailure() ) {
-      return StatusCode::FAILURE;
-    }
-
-    if (m_magFieldSvc.retrieve().isFailure()){
-      ATH_MSG_ERROR("Could not get " << m_magFieldSvc); 
-      return StatusCode::FAILURE;
-    }
-
-    if( m_edmHelperSvc.retrieve().isFailure() ){
-      ATH_MSG_ERROR("Could not get " << m_edmHelperSvc ); 
-      return StatusCode::FAILURE;
-    }
-
-    if( m_printer.retrieve().isFailure() ){
-      ATH_MSG_ERROR("Could not get " << m_printer ); 
-      return StatusCode::FAILURE;
-    }
-
-    if( m_idHelperTool.retrieve().isFailure()){
-      ATH_MSG_ERROR("Could not get " << m_idHelperTool ); 
-      return StatusCode::FAILURE;
-    }
-
-    if( m_pairMatchingTool.retrieve().isFailure() ){
-      ATH_MSG_ERROR("Could not find "<<m_pairMatchingTool);
-      return StatusCode::FAILURE;
-    }
-
-    if( m_overlapResolvingTool.retrieve().isFailure() ){
-      ATH_MSG_ERROR("Could not find "<<m_overlapResolvingTool);
-      return StatusCode::FAILURE;
-    }
-
+    ATH_CHECK(AthAlgTool::initialize());
+    ATH_CHECK(m_edmHelperSvc.retrieve());
+    ATH_CHECK(m_printer.retrieve());
+    ATH_CHECK(m_idHelperSvc.retrieve());
+    ATH_CHECK(m_pairMatchingTool.retrieve());
+    ATH_CHECK(m_overlapResolvingTool.retrieve());
     return StatusCode::SUCCESS;
   }
 
@@ -152,21 +109,21 @@ namespace Muon {
     Identifier chid2 = m_edmHelperSvc->chamberId(seg2);
     if( chid1 == chid2 ) return false;
 
-    MuonStationIndex::StIndex stIndex1 = m_idHelperTool->stationIndex(chid1);
-    MuonStationIndex::StIndex stIndex2 = m_idHelperTool->stationIndex(chid2);
+    MuonStationIndex::StIndex stIndex1 = m_idHelperSvc->stationIndex(chid1);
+    MuonStationIndex::StIndex stIndex2 = m_idHelperSvc->stationIndex(chid2);
 
     if( isSLMatch(chid1,chid2) ){ 
-      if( !m_idHelperTool->isMdt(chid1) || !m_idHelperTool->isMdt(chid2)) return false;
+      if( !m_idHelperSvc->isMdt(chid1) || !m_idHelperSvc->isMdt(chid2)) return false;
       // if there is a stereo angle match using overlap matching tool
 
       if( stIndex1 == stIndex2 ){
 	
 	if( hasStereoAngle(chid1,chid2) ){
 	  if( !m_doOverlapMatch ) return true;
-	  int eta1 = m_idHelperTool->mdtIdHelper().stationEta(chid1);
-	  int eta2 =  m_idHelperTool->mdtIdHelper().stationEta(chid2); 
-	  int phi1 = m_idHelperTool->sector(chid1);
-	  int phi2 =  m_idHelperTool->sector(chid2);
+	  int eta1 = m_idHelperSvc->mdtIdHelper().stationEta(chid1);
+	  int eta2 =  m_idHelperSvc->mdtIdHelper().stationEta(chid2); 
+	  int phi1 = m_idHelperSvc->sector(chid1);
+	  int phi2 =  m_idHelperSvc->sector(chid2);
 	  
 	  // require that the two segments are close in eta AND are in adjecent sectors
 	  if( (eta1==eta2||eta1==eta2-1||eta1==eta2+1) && 
@@ -248,8 +205,8 @@ namespace Muon {
     }
     if (segDist > m_maxDistSegments) return false;
 
-    if( !m_idHelperTool->isMdt(chid) ) {
-      ATH_MSG_DEBUG(" not a mdt segment " << m_idHelperTool->toString(chid));
+    if( !m_idHelperSvc->isMdt(chid) ) {
+      ATH_MSG_DEBUG(" not a mdt segment " << m_idHelperSvc->toString(chid));
       return true;
     }
 
@@ -294,10 +251,10 @@ namespace Muon {
   bool MuonSegmentMatchingTool::isSLMatch( const Identifier& chid1, const Identifier& chid2 ) const {
     
     // check whether there is field
-    if( !m_magFieldSvc->toroidOn() ) return true;
+    if(!m_toroidOn) return true;
 
-    MuonStationIndex::StIndex stIndex1 = m_idHelperTool->stationIndex(chid1);
-    MuonStationIndex::StIndex stIndex2 = m_idHelperTool->stationIndex(chid2);
+    MuonStationIndex::StIndex stIndex1 = m_idHelperSvc->stationIndex(chid1);
+    MuonStationIndex::StIndex stIndex2 = m_idHelperSvc->stationIndex(chid2);
     
     // check whether segments in same station
     if( stIndex1 == stIndex2 ) return true;
@@ -313,14 +270,14 @@ namespace Muon {
   bool MuonSegmentMatchingTool::hasStereoAngle( const Identifier& id1, const Identifier& id2 ) const {
    
     // check whether same phi, else stereo angle (need correction for cosmic up-down tracks)
-    int phi1 = m_idHelperTool->mdtIdHelper().stationPhi(id1);
-    int phi2 =  m_idHelperTool->mdtIdHelper().stationPhi(id2);
+    int phi1 = m_idHelperSvc->mdtIdHelper().stationPhi(id1);
+    int phi2 =  m_idHelperSvc->mdtIdHelper().stationPhi(id2);
     
     if( phi1!=phi2) return true; 
     
     // check whether there is a small/large overlap 
-    bool isSmallChamber1 = m_idHelperTool->isSmallChamber(id1);
-    bool isSmallChamber2 = m_idHelperTool->isSmallChamber(id2);
+    bool isSmallChamber1 = m_idHelperSvc->isSmallChamber(id1);
+    bool isSmallChamber2 = m_idHelperSvc->isSmallChamber(id2);
 
     return isSmallChamber1 != isSmallChamber2;
   }
@@ -334,23 +291,23 @@ namespace Muon {
     // calculate matching variables
     IMuonSegmentPairMatchingTool::SegmentMatchResult result = m_pairMatchingTool->matchResult(seg1,seg2);
 
-    MuonStationIndex::StIndex station_a = m_idHelperTool->stationIndex( result.chid_a );
-    MuonStationIndex::StIndex station_b = m_idHelperTool->stationIndex( result.chid_b );
+    MuonStationIndex::StIndex station_a = m_idHelperSvc->stationIndex( result.chid_a );
+    MuonStationIndex::StIndex station_b = m_idHelperSvc->stationIndex( result.chid_b );
 
-    bool isEndcap_a   = m_idHelperTool->isEndcap( result.chid_a );
-    bool isCSC_a      = m_idHelperTool->isCsc( result.chid_a );
+    bool isEndcap_a   = m_idHelperSvc->isEndcap( result.chid_a );
+    bool isCSC_a      = m_idHelperSvc->isCsc( result.chid_a );
     bool isBEE_a      = station_a == MuonStationIndex::BE;
 
-    bool isEndcap_b   = m_idHelperTool->isEndcap( result.chid_b );
-    bool isCSC_b      = m_idHelperTool->isCsc( result.chid_b );
+    bool isEndcap_b   = m_idHelperSvc->isEndcap( result.chid_b );
+    bool isCSC_b      = m_idHelperSvc->isCsc( result.chid_b );
     bool isBEE_b      = station_a == MuonStationIndex::BE;
 
     
     if ( m_dumpAngles ) {
 
       std::cout << "SegmentPositionChange "
-	      << " " << m_idHelperTool->chamberNameString(result.chid_a)
-	      << " " << m_idHelperTool->chamberNameString(result.chid_b)
+	      << " " << m_idHelperSvc->chamberNameString(result.chid_a)
+	      << " " << m_idHelperSvc->chamberNameString(result.chid_b)
 	      << " " << result.phiSector_a
 	      << " " << result.phiSector_b
 	      << " " << result.deltaTheta_a
@@ -363,8 +320,8 @@ namespace Muon {
 //      return true; // to get the maximum statistics and not be hindered by current cuts
     }    
   
-    ATH_MSG_VERBOSE( "matching " << m_idHelperTool->chamberNameString(result.chid_a)
-		     << " " << m_idHelperTool->chamberNameString(result.chid_b)
+    ATH_MSG_VERBOSE( "matching " << m_idHelperSvc->chamberNameString(result.chid_a)
+		     << " " << m_idHelperSvc->chamberNameString(result.chid_b)
 		     << " phis " << result.phiSector_a
 		     << " " << result.phiSector_b
 		     << " thetas " << result.deltaTheta_a
@@ -706,17 +663,17 @@ namespace Muon {
     // calculate matching variables
     IMuonSegmentPairMatchingTool::SegmentMatchResult result = m_pairMatchingTool->matchResult(seg1,seg2);
     
-    MuonStationIndex::StIndex station_a = m_idHelperTool->stationIndex( result.chid_a );
-    MuonStationIndex::StIndex station_b = m_idHelperTool->stationIndex( result.chid_b );
+    MuonStationIndex::StIndex station_a = m_idHelperSvc->stationIndex( result.chid_a );
+    MuonStationIndex::StIndex station_b = m_idHelperSvc->stationIndex( result.chid_b );
        
-    bool isEndcap_a   = m_idHelperTool->isEndcap( result.chid_a );
+    bool isEndcap_a   = m_idHelperSvc->isEndcap( result.chid_a );
        
-    bool isEndcap_b   = m_idHelperTool->isEndcap( result.chid_b );
+    bool isEndcap_b   = m_idHelperSvc->isEndcap( result.chid_b );
        
     if ( m_dumpAngles ) {
       std::cout << "SegmentPositionChange Phi"
-		<< " " << m_idHelperTool->chamberNameString(result.chid_a)
-		<< " " << m_idHelperTool->chamberNameString(result.chid_b)
+		<< " " << m_idHelperSvc->chamberNameString(result.chid_a)
+		<< " " << m_idHelperSvc->chamberNameString(result.chid_b)
 		<< " deltaPhipos " << result.deltaPhipos
 		<< " deltaPhidir " << result.deltaPhidir
 		<< " phiposerr_a " << result.phiposerr_a
@@ -1064,8 +1021,8 @@ namespace Muon {
     Identifier chid2 = m_edmHelperSvc->chamberId(seg2);
     if( chid1 == chid2 ) return false;
 
-    MuonStationIndex::StIndex stIndex1 = m_idHelperTool->stationIndex(chid1);
-    MuonStationIndex::StIndex stIndex2 = m_idHelperTool->stationIndex(chid2);
+    MuonStationIndex::StIndex stIndex1 = m_idHelperSvc->stationIndex(chid1);
+    MuonStationIndex::StIndex stIndex2 = m_idHelperSvc->stationIndex(chid2);
     if( stIndex1 == stIndex2 ) return false;
 
     const MuonSegment* segInner = 0;
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/src/MuonSegmentMatchingTool.h b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/src/MuonSegmentMatchingTool.h
index 5a15c7f0b35..823994d5486 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/src/MuonSegmentMatchingTool.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMatchingTools/src/MuonSegmentMatchingTool.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef MUON_MUONSEGMENTMATCHINGTOOL_H
@@ -10,19 +10,15 @@
 #include "AthenaBaseComps/AthAlgTool.h"
 #include "GaudiKernel/ToolHandle.h"
 #include "GaudiKernel/ServiceHandle.h"
-#include "MagFieldInterfaces/IMagFieldSvc.h"
-#include "TrkGeometry/MagneticFieldProperties.h"
-#include "MuonRecHelperTools/IMuonEDMHelperSvc.h"
-#include <atomic>
 
-class Identifier;
+#include "MuonRecHelperTools/IMuonEDMHelperSvc.h"
+#include "MuonRecHelperTools/MuonEDMPrinterTool.h"
+#include "MuonIdHelpers/IMuonIdHelperSvc.h"
+#include "MuonSegmentMakerToolInterfaces/IMuonSegmentInOverlapResolvingTool.h"
+#include "MuonSegmentMakerToolInterfaces/IMuonSegmentPairMatchingTool.h"
+#include "TrkGeometry/MagneticFieldProperties.h"
 
-namespace Muon {
-  class MuonIdHelperTool;
-  class MuonEDMPrinterTool;
-  class IMuonSegmentInOverlapResolvingTool;
-  class IMuonSegmentPairMatchingTool;
-}
+#include <atomic>
 
 namespace Muon {
   
@@ -42,7 +38,7 @@ namespace Muon {
     MuonSegmentMatchingTool(const std::string&,const std::string&,const IInterface*);
 
     /** @brief destructor */
-    virtual ~MuonSegmentMatchingTool ();
+    virtual ~MuonSegmentMatchingTool()=default;
     
     /** @brief AlgTool initilize */
     StatusCode initialize();
@@ -86,14 +82,15 @@ namespace Muon {
     /** @brief match an endcap middle or outer segment with an inner segment using a simple analytic extrapolation model */
     bool endcapExtrapolationMatch( const MuonSegment& seg1, const MuonSegment& seg2, bool useTightCuts ) const;
 
-    ToolHandle<Muon::MuonIdHelperTool>                   m_idHelperTool;         //!< IdHelper tool
+    ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
     ServiceHandle<Muon::IMuonEDMHelperSvc>               m_edmHelperSvc {this, "edmHelper", 
       "Muon::MuonEDMHelperSvc/MuonEDMHelperSvc", 
       "Handle to the service providing the IMuonEDMHelperSvc interface" };           //!< EDM Helper tool
     ToolHandle<Muon::MuonEDMPrinterTool>                 m_printer;              //!< EDM printer tool
     ToolHandle<Muon::IMuonSegmentInOverlapResolvingTool> m_overlapResolvingTool; //!< matching tool to handle the overlaps
     ToolHandle<Muon::IMuonSegmentPairMatchingTool>       m_pairMatchingTool;     //!< matching tool to handle the pairs of segments
-    ServiceHandle<MagField::IMagFieldSvc>                m_magFieldSvc; 
+
+    Gaudi::Property<bool> m_toroidOn { this, "ToroidOn", true, "Status of toroidal B-Field" };
 
     mutable std::atomic_uint m_straightLineMatches;
     mutable std::atomic_uint m_straightLineMatchesGood;
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/CMakeLists.txt b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/CMakeLists.txt
index b51509a05d4..2bfbd9ffafb 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/CMakeLists.txt
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/CMakeLists.txt
@@ -9,7 +9,8 @@ atlas_subdir( MuonSegmentMomentum )
 atlas_depends_on_subdirs( PUBLIC
                           Control/AthenaBaseComps
                           GaudiKernel
-                          MagneticField/MagFieldInterfaces
+                          MagneticField/MagFieldElements
+                          MagneticField/MagFieldConditions
                           MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonRecToolInterfaces
                           PRIVATE
                           DetectorDescription/GeoPrimitives
@@ -30,11 +31,13 @@ atlas_add_library( MuonSegmentMomentumLib
                    src/*.cxx
                    NO_PUBLIC_HEADERS
                    PRIVATE_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS}
-                   LINK_LIBRARIES AthenaBaseComps GaudiKernel MagFieldInterfaces MuonRecToolInterfaces MuonIdHelpersLib
+                   LINK_LIBRARIES AthenaBaseComps GaudiKernel MagFieldElements MagFieldConditions
+ MuonRecToolInterfaces MuonIdHelpersLib
                    PRIVATE_LINK_LIBRARIES ${EIGEN_LIBRARIES} GeoPrimitives MuonSegment TrkGeometry TrkCompetingRIOsOnTrack TrkParameters TrkRIO_OnTrack TrkExInterfaces TrkExUtils )
 
 atlas_add_component( MuonSegmentMomentum
                      src/components/*.cxx
                      INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS}
-                     LINK_LIBRARIES ${EIGEN_LIBRARIES} AthenaBaseComps GaudiKernel MagFieldInterfaces MuonRecToolInterfaces GeoPrimitives MuonIdHelpersLib MuonSegment TrkGeometry TrkCompetingRIOsOnTrack TrkParameters TrkRIO_OnTrack TrkExInterfaces TrkExUtils MuonSegmentMomentumLib )
+                     LINK_LIBRARIES ${EIGEN_LIBRARIES} AthenaBaseComps GaudiKernel MagFieldElements MagFieldConditions
+ MuonRecToolInterfaces GeoPrimitives MuonIdHelpersLib MuonSegment TrkGeometry TrkCompetingRIOsOnTrack TrkParameters TrkRIO_OnTrack TrkExInterfaces TrkExUtils MuonSegmentMomentumLib )
 
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/src/MuonSegmentMomentumFromField.cxx b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/src/MuonSegmentMomentumFromField.cxx
index 76a12e754a3..876c063c791 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/src/MuonSegmentMomentumFromField.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/src/MuonSegmentMomentumFromField.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "MuonSegmentMomentumFromField.h"
@@ -14,12 +14,8 @@
 #include "TrkGeometry/TrackingVolume.h"
 #include "TrkRIO_OnTrack/RIO_OnTrack.h"
 #include "TrkCompetingRIOsOnTrack/CompetingRIOsOnTrack.h"
-
-#include "MuonIdHelpers/RpcIdHelper.h"
-#include "MuonIdHelpers/CscIdHelper.h"
-#include "MuonIdHelpers/TgcIdHelper.h"
-#include "MuonIdHelpers/sTgcIdHelper.h"
 #include "GeoPrimitives/GeoPrimitivesToStringConverter.h"
+#include <TString.h> // for Form
 
 MuonSegmentMomentumFromField::MuonSegmentMomentumFromField(const std::string& type,const std::string& name,const IInterface* 
 							   parent):AthAlgTool(type,name,parent)
@@ -29,33 +25,16 @@ MuonSegmentMomentumFromField::MuonSegmentMomentumFromField(const std::string& ty
 
 StatusCode MuonSegmentMomentumFromField::initialize()
 {
-
   ATH_MSG_VERBOSE(" MuonSegmentMomentumFromField::Initializing ");
-
-  ATH_CHECK( m_magFieldSvc.retrieve() );
-
-  ATH_CHECK( m_propagator.retrieve() );
-
-  ATH_CHECK( m_navigator.retrieve() );
-
-  if (m_hasCSC) ATH_CHECK( detStore()->retrieve( m_cscid ) );
-
-  ATH_CHECK( detStore()->retrieve( m_rpcid ) );
-
-  ATH_CHECK( detStore()->retrieve( m_tgcid ) );
-
-  if (m_hasSTgc) ATH_CHECK( detStore()->retrieve( m_stgcid ) );
-
+  ATH_CHECK(AthAlgTool::initialize());
+  ATH_CHECK(m_propagator.retrieve());
+  ATH_CHECK(m_navigator.retrieve());
+  ATH_CHECK(m_idHelperSvc.retrieve());
+  ATH_CHECK(m_fieldCondObjInputKey.initialize());
   ATH_MSG_VERBOSE("End of Initializing");  
-
   return StatusCode::SUCCESS; 
 }
 
-StatusCode MuonSegmentMomentumFromField::finalize()
-{
-  return StatusCode::SUCCESS;
-}
-
 void MuonSegmentMomentumFromField::fitMomentumVectorSegments( const std::vector <const Muon::MuonSegment*> segments, double & signedMomentum ) const
 {
 
@@ -81,14 +60,9 @@ void MuonSegmentMomentumFromField::fitMomentumVectorSegments( const std::vector
     it++;
     it2++;
   }
-
-
   ATH_MSG_DEBUG( " Estimated signed momentum " << signedMomentum );
-
 }
 
-
-
 double MuonSegmentMomentumFromField::fieldIntegralEstimate( const Muon::MuonSegment* segment1, const Muon::MuonSegment* segment2) const 
 {
 
@@ -104,13 +78,21 @@ double MuonSegmentMomentumFromField::fieldIntegralEstimate( const Muon::MuonSegm
   Amg::Vector3D point2=pos1+.5*posdiff;
   Amg::Vector3D point3=pos1+.75*posdiff;
   Amg::Vector3D field1,field2,field3;
-  m_magFieldSvc->getField(point1.data(),field1.data()); // field in kiloTesla
-  m_magFieldSvc->getField(point2.data(),field2.data());
-  m_magFieldSvc->getField(point3.data(),field3.data());
+
+  MagField::AtlasFieldCache fieldCache;
+  SG::ReadCondHandle<AtlasFieldCacheCondObj> readHandle{m_fieldCondObjInputKey, Gaudi::Hive::currentContext()};
+  const AtlasFieldCacheCondObj* fieldCondObj{*readHandle};
+  if (!fieldCondObj) {
+    throw std::runtime_error(Form("File: %s, Line: %d\nMuonSegmentMomentumFromField::fieldIntegralEstimate() - Failed to retrieve AtlasFieldCacheCondObj with key %s", __FILE__, __LINE__, (m_fieldCondObjInputKey.key()).c_str()));
+  }
+  fieldCondObj->getInitializedCache(fieldCache);
+
+  fieldCache.getField(point1.data(),field1.data()); // field in kiloTesla
+  fieldCache.getField(point2.data(),field2.data());
+  fieldCache.getField(point3.data(),field3.data());
   ATH_MSG_DEBUG("Mid Point " << Amg::toString(point2) << " field " << Amg::toString(field2) );
   field1[2]=field2[2]=field3[2]=0;
   Amg::Vector3D fieldsum=field1+field2+field3;
-  //double averageBcrossl=(field1.cross(posdiff.unit()).mag()+field2.cross(posdiff.unit()).mag()+field3.cross(posdiff.unit()).mag())/3;
   Amg::Vector3D crossvec=posdiff.unit().cross(field1+field2+field3);
   Amg::Vector2D rphidir(-posdiff.y(),posdiff.x());
   double averagelcrossB=crossvec.mag()/3;
@@ -158,8 +140,8 @@ void MuonSegmentMomentumFromField::fitMomentum2Segments( const Muon::MuonSegment
     if (!rot) continue;
     Identifier id=rot->identify();
 
-    if ((m_rpcid->is_rpc(id) && m_rpcid->measuresPhi(id)) || (m_cscid && m_cscid->is_csc(id) && m_cscid->measuresPhi(id)) || (m_tgcid->is_tgc(id) && m_tgcid->isStrip(id))
-        || (m_stgcid && m_stgcid->is_stgc(id) && m_stgcid->measuresPhi(id) ) ){
+    if ((m_idHelperSvc->isRpc(id) && m_idHelperSvc->rpcIdHelper().measuresPhi(id)) || (m_idHelperSvc->isCsc(id) && m_idHelperSvc->cscIdHelper().measuresPhi(id)) || (m_idHelperSvc->isTgc(id) && m_idHelperSvc->tgcIdHelper().isStrip(id))
+        || (m_idHelperSvc->issTgc(id) && m_idHelperSvc->stgcIdHelper().measuresPhi(id) ) ){
       if (!firstphi1) firstphi1=rot;
       lastphi1=rot;
     }
@@ -172,15 +154,15 @@ void MuonSegmentMomentumFromField::fitMomentum2Segments( const Muon::MuonSegment
     }
     if (!rot) continue;
     Identifier id=rot->identify();
-    if ((m_rpcid->is_rpc(id) && m_rpcid->measuresPhi(id)) || (m_cscid && m_cscid->is_csc(id) && m_cscid->measuresPhi(id)) || (m_tgcid->is_tgc(id) && m_tgcid->isStrip(id))
-        || (m_stgcid && m_stgcid->is_stgc(id) && m_stgcid->measuresPhi(id) ) ){
+    if ((m_idHelperSvc->isRpc(id) && m_idHelperSvc->rpcIdHelper().measuresPhi(id)) || (m_idHelperSvc->isCsc(id) && m_idHelperSvc->cscIdHelper().measuresPhi(id)) || (m_idHelperSvc->isTgc(id) && m_idHelperSvc->tgcIdHelper().isStrip(id))
+        || (m_idHelperSvc->issTgc(id) && m_idHelperSvc->stgcIdHelper().measuresPhi(id) ) ){
       if (!firstphi2) firstphi2=rot;
       lastphi2=rot;
     }
   }
   bool flip = false;
-  if (firstphi1) dist1=fabs((firstphi1->globalPosition()-lastphi1->globalPosition()).dot(myseg1->globalDirection()));
-  if (firstphi2) dist2=fabs((firstphi2->globalPosition()-lastphi2->globalPosition()).dot(myseg2->globalDirection()));
+  if (firstphi1) dist1=std::abs((firstphi1->globalPosition()-lastphi1->globalPosition()).dot(myseg1->globalDirection()));
+  if (firstphi2) dist2=std::abs((firstphi2->globalPosition()-lastphi2->globalPosition()).dot(myseg2->globalDirection()));
   if (dist2>dist1) {
     flip = true;
     bestseg=myseg2;
@@ -201,7 +183,7 @@ void MuonSegmentMomentumFromField::fitMomentum2Segments( const Muon::MuonSegment
     }
 
     signedMomentum =-.3e3*fieldintegral/deltatheta;
-    if(fabs(signedMomentum)<1000.) signedMomentum = 1e6;
+    if(std::abs(signedMomentum)<1000.) signedMomentum = 1e6;
     ATH_MSG_DEBUG("integral: " << fieldintegral << " deltatheta: " << deltatheta << " signedmomentum : " << signedMomentum);
     double residual = 9999.;
     double resi[4],qoverp[4];
@@ -225,20 +207,20 @@ void MuonSegmentMomentumFromField::fitMomentum2Segments( const Muon::MuonSegment
           if(qoverp[i]!=qoverp[i-1]) {
             double derivative = -(resi[i]-resi[i-1])/(qoverp[i]-qoverp[i-1]);
             ATH_MSG_DEBUG(" numerical derivative " << derivative << " derivative from track " << (*jac)(1,4) << " der_simple " << der_simple);
-            if(fabs(derivative)>fabs((*jac)(1,4))) {
+            if(std::abs(derivative)>std::abs((*jac)(1,4))) {
               ATH_MSG_DEBUG(" use numerical derivative " << derivative << " derivative from track " << (*jac)(1,4));
               delta_qoverp = residual/derivative;
             }
           }
         } else {
-          if(fabs(der_simple)>fabs((*jac)(1,4))) {
+          if(std::abs(der_simple)>std::abs((*jac)(1,4))) {
             ATH_MSG_DEBUG(" use simple numerical derivative " << der_simple << " derivative from track " << (*jac)(1,4));
             delta_qoverp = residual/der_simple;
           }
         }
         ATH_MSG_DEBUG("residual: " << residual << " jac " << (*jac)(1,4) << " signedmomentum: " << signedMomentum << " delta_qoverp " << delta_qoverp);
         double signedMomentum_updated = signedMomentum/(1+signedMomentum*delta_qoverp);
-        if(fabs(signedMomentum_updated)<1000.) {
+        if(std::abs(signedMomentum_updated)<1000.) {
           ATH_MSG_DEBUG("Too low signed momentum " << signedMomentum_updated );
 //      protect against too low momenta as propagation will fail
           signedMomentum = signedMomentum_updated>0? 1000.:-1000;
@@ -251,7 +233,7 @@ void MuonSegmentMomentumFromField::fitMomentum2Segments( const Muon::MuonSegment
         if (std::abs(residual)<1) break;
       }
     }
-    if(fabs(residual)>10.) {
+    if(std::abs(residual)>10.) {
        ATH_MSG_DEBUG("NOT converged residual: " << residual << " itry " << itry);
        if(itry==1) ATH_MSG_DEBUG("NOT converged residual after two trials ");
     } else break;
@@ -274,9 +256,18 @@ double MuonSegmentMomentumFromField::fieldIntegralEstimate_old( const Muon::Muon
   Amg::Vector3D point2=pos1+.5*posdiff;
   Amg::Vector3D point3=pos1+.75*posdiff;
   Amg::Vector3D field1,field2,field3;
-  m_magFieldSvc->getField((double*)&point1,(double*)&field1); // field in kiloTesla
-  m_magFieldSvc->getField((double*)&point2,(double*)&field2);
-  m_magFieldSvc->getField((double*)&point3,(double*)&field3);
+
+  MagField::AtlasFieldCache fieldCache;
+  SG::ReadCondHandle<AtlasFieldCacheCondObj> readHandle{m_fieldCondObjInputKey, Gaudi::Hive::currentContext()};
+  const AtlasFieldCacheCondObj* fieldCondObj{*readHandle};
+  if (!fieldCondObj) {
+    throw std::runtime_error(Form("File: %s, Line: %d\nMuonSegmentMomentumFromField::fieldIntegralEstimate_old() - Failed to retrieve AtlasFieldCacheCondObj with key %s", __FILE__, __LINE__, (m_fieldCondObjInputKey.key()).c_str()));
+  }
+  fieldCondObj->getInitializedCache(fieldCache);
+
+  fieldCache.getField(point1.data(),field1.data()); // field in kiloTesla
+  fieldCache.getField(point2.data(),field2.data());
+  fieldCache.getField(point3.data(),field3.data());
   ATH_MSG_DEBUG("Mid Point " << Amg::toString(point2) << " field " << Amg::toString(field2) );
   double averageBcrossl=(field1.cross(posdiff.unit()).mag()+field2.cross(posdiff.unit()).mag()+field3.cross(posdiff.unit()).mag())/3;
   ATH_MSG_DEBUG("field integral " << averageBcrossl << "dist " << posdiff.mag() << " tot " << averageBcrossl*posdiff.mag());
@@ -322,8 +313,8 @@ void MuonSegmentMomentumFromField::fitMomentum2Segments_old( const Muon::MuonSeg
     if (!rot) continue;
     Identifier id=rot->identify();
 
-    if ((m_rpcid->is_rpc(id) && m_rpcid->measuresPhi(id)) || (m_cscid && m_cscid->is_csc(id) && m_cscid->measuresPhi(id)) ||
-	(m_tgcid->is_tgc(id) && m_tgcid->isStrip(id))){    
+    if ((m_idHelperSvc->isRpc(id) && m_idHelperSvc->rpcIdHelper().measuresPhi(id)) || (m_idHelperSvc->isCsc(id) && m_idHelperSvc->cscIdHelper().measuresPhi(id)) ||
+	(m_idHelperSvc->isTgc(id) && m_idHelperSvc->tgcIdHelper().isStrip(id))){    
       if (!firstphi1) firstphi1=rot;
       lastphi1=rot;
     }
@@ -336,21 +327,20 @@ void MuonSegmentMomentumFromField::fitMomentum2Segments_old( const Muon::MuonSeg
     }
     if (!rot) continue;
     Identifier id=rot->identify();
-    if ((m_rpcid->is_rpc(id) && m_rpcid->measuresPhi(id)) || (m_cscid && m_cscid->is_csc(id) && m_cscid->measuresPhi(id)) ||
-	(m_tgcid->is_tgc(id) && m_tgcid->isStrip(id))){
+    if ((m_idHelperSvc->isRpc(id) && m_idHelperSvc->rpcIdHelper().measuresPhi(id)) || (m_idHelperSvc->isCsc(id) && m_idHelperSvc->cscIdHelper().measuresPhi(id)) ||
+	(m_idHelperSvc->isTgc(id) && m_idHelperSvc->tgcIdHelper().isStrip(id))){
       if (!firstphi2) firstphi2=rot;
       lastphi2=rot;
     }
   }
 
-  if (firstphi1) dist1=fabs((firstphi1->globalPosition()-lastphi1->globalPosition()).dot(myseg1->globalDirection()));
-  if (firstphi2) dist2=fabs((firstphi2->globalPosition()-lastphi2->globalPosition()).dot(myseg2->globalDirection()));
+  if (firstphi1) dist1=std::abs((firstphi1->globalPosition()-lastphi1->globalPosition()).dot(myseg1->globalDirection()));
+  if (firstphi2) dist2=std::abs((firstphi2->globalPosition()-lastphi2->globalPosition()).dot(myseg2->globalDirection()));
   if (dist2>dist1) {
     bestseg=myseg2;
     worstseg=myseg1;
   }
   signedMomentum =-.3e3*fieldintegral/deltatheta;
-  //std::cout << "integral: " << fieldintegral << " deltatheta: " << deltatheta << " signedmomentum : " << signedMomentum << std::endl;
   ATH_MSG_DEBUG("integral: " << fieldintegral << " deltatheta: " << deltatheta << " signedmomentum : " << signedMomentum);
   for (int i=0;i<3;i++){
     Trk::AtaPlane startpar(bestseg->globalPosition(),bestseg->globalDirection().phi(),bestseg->globalDirection().theta(),
@@ -364,7 +354,6 @@ void MuonSegmentMomentumFromField::fitMomentum2Segments_old( const Muon::MuonSeg
       double delta_qoverp=residual/(*jac)(1,4);
       signedMomentum=1/(1/signedMomentum+delta_qoverp);
       ATH_MSG_DEBUG("residual: " << residual << " jac " << (*jac)(1,4) << " dp " << delta_qoverp << " signedmomentum: " << signedMomentum);
-      //std::cout << "residual: " << residual << " signedmomentum: " << signedMomentum << std::endl;
       delete par;
       delete jac;
       if (std::abs(residual)<1) break;
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/src/MuonSegmentMomentumFromField.h b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/src/MuonSegmentMomentumFromField.h
index cce19fbf0e4..84fe76202c3 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/src/MuonSegmentMomentumFromField.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerTools/MuonSegmentMomentum/src/MuonSegmentMomentumFromField.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef MuonSegmentMomentumFromField_MuonSegmentMomentumFromField_H
@@ -7,15 +7,14 @@
 
 #include "AthenaBaseComps/AthAlgTool.h"
 #include "MuonRecToolInterfaces/IMuonSegmentMomentumEstimator.h"
+#include "GaudiKernel/ServiceHandle.h"
 #include "GaudiKernel/ToolHandle.h"
-#include "MagFieldInterfaces/IMagFieldSvc.h"
 #include "TrkExInterfaces/IPropagator.h"
 #include "TrkExInterfaces/INavigator.h"
-
-class RpcIdHelper;
-class CscIdHelper;
-class TgcIdHelper;
-class sTgcIdHelper;
+#include "MuonIdHelpers/IMuonIdHelperSvc.h"
+#include "StoreGate/ReadCondHandleKey.h"
+#include "MagFieldConditions/AtlasFieldCacheCondObj.h"
+#include "MagFieldElements/AtlasFieldCache.h"
 
 namespace Muon {
   class MuonSegment;
@@ -30,8 +29,6 @@ class MuonSegmentMomentumFromField : public AthAlgTool, virtual public Muon::IMu
   
   /** to initiate private members */
   virtual StatusCode initialize(); 
-  /** to delete private members */
-  virtual StatusCode finalize(); 
 
   /** fits a momentum to 2 segments */
   virtual void fitMomentum2Segments( const Muon::MuonSegment* segment1, const Muon::MuonSegment* segment2, double & signedMomentum ) const;
@@ -43,19 +40,14 @@ class MuonSegmentMomentumFromField : public AthAlgTool, virtual public Muon::IMu
   double fieldIntegralEstimate(const Muon::MuonSegment* segment1, const Muon::MuonSegment* segment2) const;
   double fieldIntegralEstimate_old(const Muon::MuonSegment* segment1, const Muon::MuonSegment* segment2) const;
   
-  ServiceHandle<MagField::IMagFieldSvc> m_magFieldSvc {this, "MagFieldSvc", "AtlasFieldSvc"};
   ToolHandle<Trk::IPropagator>          m_propagator{this, "PropagatorTool", 
                                           "Trk::STEP_Propagator/MuonPropagator"};  
   ToolHandle<Trk::INavigator>           m_navigator {this, "NavigatorTool",
                                           "Trk::Navigator/MuonNavigator"};
+  ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
+  SG::ReadCondHandleKey<AtlasFieldCacheCondObj> m_fieldCondObjInputKey {this, "AtlasFieldCacheCondObj", "fieldCondObj"};
 
-  const RpcIdHelper*                  m_rpcid {nullptr};
-  const TgcIdHelper*                  m_tgcid {nullptr};
-  const CscIdHelper*                  m_cscid {nullptr};
-  const sTgcIdHelper*                 m_stgcid {nullptr};
   Gaudi::Property<bool> m_doOld {this, "DoOld", false, "Use old fitMomentum2Segments"};
-  Gaudi::Property<bool> m_hasCSC {this, "HasCSC", true, "Is CSC available?"};
-  Gaudi::Property<bool> m_hasSTgc {this, "HasSTgc", true, "is sTGC available?"};
 };
 
 #endif // MuonSegmentMomentumFromField_H
-- 
GitLab