From 2a162fec471cba91d21f74ff489859ececdb2beb Mon Sep 17 00:00:00 2001
From: Patrick Scholer <patrick.scholer@cern.ch>
Date: Fri, 10 Jul 2020 15:39:39 +0000
Subject: [PATCH] Manual Sweep: Introduce MMClusterOnTrackCreator

---
 .../share/SiSmearing_noPU_CompletedjO.py      |   6 +-
 .../src/MMClusterOnTrackCreator.cxx           | 102 ++++++++++++++
 .../src/MMClusterOnTrackCreator.h             |  78 +++++++++++
 .../src/MuonClusterOnTrackCreator.cxx         |  28 ++--
 .../MuonClusterOnTrackCreator_entries.cxx     |   2 +
 .../MuonRecExample/python/MuonRecTools.py     |   3 +
 .../share/MuonHolesSearch_jobOptions.py       |   1 +
 .../src/MuonSegmentFinderAlg.cxx              |  12 +-
 .../src/MuonSegmentFinderAlg.h                |   3 +-
 .../RIO_OnTrackCreator.h                      |   2 +
 .../src/RIO_OnTrackCreator.cxx                | 127 ++++++++----------
 .../python/TrigMuonEFCosmicConfig.py          |   1 +
 12 files changed, 269 insertions(+), 96 deletions(-)
 create mode 100644 MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MMClusterOnTrackCreator.cxx
 create mode 100644 MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MMClusterOnTrackCreator.h

diff --git a/InnerDetector/InDetDigitization/FastSiDigitization/share/SiSmearing_noPU_CompletedjO.py b/InnerDetector/InDetDigitization/FastSiDigitization/share/SiSmearing_noPU_CompletedjO.py
index 34f3e1e3870..ee3d95e8ff6 100644
--- a/InnerDetector/InDetDigitization/FastSiDigitization/share/SiSmearing_noPU_CompletedjO.py
+++ b/InnerDetector/InDetDigitization/FastSiDigitization/share/SiSmearing_noPU_CompletedjO.py
@@ -236,7 +236,8 @@ InDetRotCreator = Trk__RIO_OnTrackCreator(name                = 'InDetRotCreator
                                           ToolPixelCluster    = PixelPlanarClusterOnTrackTool,
                                           ToolSCT_Cluster     = SCT_PlanarClusterOnTrackTool,
                                           ToolMuonCluster     = None,
-                                          ToolMuonDriftCircle = None,       
+                                          ToolMuonDriftCircle = None,
+                                          ToolMuonMMCluster   = None,       
                                           ToolTRT_DriftCircle = None,    
                                           Mode                = 'indet')
 InDetRotCreator.OutputLevel = OutputLevel
@@ -247,7 +248,8 @@ BroadInDetRotCreator = Trk__RIO_OnTrackCreator(name                = 'BroadInDet
                                                ToolPixelCluster    = PixelPlanarClusterOnTrackTool,
                                                ToolSCT_Cluster     = SCT_PlanarClusterOnTrackTool,
                                                ToolMuonCluster     = None,
-                                               ToolMuonDriftCircle = None,       
+                                               ToolMuonDriftCircle = None,
+                                               ToolMuonMMCluster   = None,       
                                                ToolTRT_DriftCircle = None,    
                                                Mode                = 'indet')
 BroadInDetRotCreator.OutputLevel = OutputLevel
diff --git a/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MMClusterOnTrackCreator.cxx b/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MMClusterOnTrackCreator.cxx
new file mode 100644
index 00000000000..d812bd04ffa
--- /dev/null
+++ b/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MMClusterOnTrackCreator.cxx
@@ -0,0 +1,102 @@
+/*
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+*/
+
+
+#include "MMClusterOnTrackCreator.h"
+
+
+#include "MuonRIO_OnTrack/MMClusterOnTrack.h"
+
+Muon::MMClusterOnTrackCreator::MMClusterOnTrackCreator
+  (const std::string& ty, const std::string& na, const IInterface* pa)
+    : AthAlgTool(ty, na, pa) {
+
+    // algtool interface - necessary!
+    declareInterface<IMuonClusterOnTrackCreator>(this);
+    declareInterface<IRIO_OnTrackCreator>(this);
+}
+
+
+StatusCode Muon::MMClusterOnTrackCreator::initialize() {
+    ATH_CHECK(m_idHelperSvc.retrieve());
+    return StatusCode::SUCCESS;
+}
+
+
+
+
+const Muon::MuonClusterOnTrack* Muon::MMClusterOnTrackCreator::createRIO_OnTrack(const Trk::PrepRawData& RIO,
+                                                    const Amg::Vector3D& GP) const {
+    MuonClusterOnTrack* MClT = nullptr;
+
+    // check whether PrepRawData has detector element, if not there print warning
+    const Trk::TrkDetElementBase* EL = RIO.detectorElement();
+    if ( !EL ) {
+      ATH_MSG_WARNING("RIO does not have associated detectorElement!, cannot produce ROT");
+      return nullptr;
+    }
+
+    // MuClusterOnTrack production
+    //
+    // in RIO_OnTrack the local param and cov should have the same dimension
+    Trk::LocalParameters locpar(RIO.localPosition());
+
+    if (RIO.localCovariance().cols() != RIO.localCovariance().rows()) {
+      ATH_MSG_FATAL("Rows and colums not equal!");
+    }
+
+    if (RIO.localCovariance().cols() > 1) {
+      ATH_MSG_VERBOSE("Making 2-dim local parameters: " << m_idHelperSvc->toString(RIO.identify()));
+    } else {
+      Trk::DefinedParameter  radiusPar(RIO.localPosition().x(), Trk::locX);
+      locpar = Trk::LocalParameters(radiusPar);
+      ATH_MSG_VERBOSE("Making 1-dim local parameters: "  << m_idHelperSvc->toString(RIO.identify()));
+    }
+
+    Amg::Vector2D lp;
+    double positionAlongStrip = 0;
+
+    if ( !EL->surface(RIO.identify()).globalToLocal(GP, GP, lp) ) {
+      Amg::Vector3D lpos = RIO.detectorElement()->surface(RIO.identify()).transform().inverse()*GP;
+      ATH_MSG_WARNING("Extrapolated GlobalPosition not on detector surface! Distance " << lpos.z());
+      lp[Trk::locX]  = lpos.x();
+      lp[Trk::locY]  = lpos.y();
+    }
+    positionAlongStrip = lp[Trk::locY];
+
+    Amg::MatrixX loce = RIO.localCovariance();
+    ATH_MSG_DEBUG("All: new err matrix is " << loce);
+
+
+
+
+    if ( m_idHelperSvc->isMM(RIO.identify()) ) {
+      // cast to MMPrepData
+      const MMPrepData* MClus   = dynamic_cast<const MMPrepData*> (&RIO);
+      if (!MClus) {
+        ATH_MSG_WARNING("RIO not of type MMPrepData, cannot create ROT");
+        return nullptr;
+      }
+      ATH_MSG_VERBOSE("generating MMClusterOnTrack in MMClusterBuilder");
+      MClT = new MMClusterOnTrack(MClus, locpar, loce, positionAlongStrip);
+     } else {
+      ATH_MSG_WARNING("MMClusterOnTrackCreator called with an non MM identifier");
+    }
+
+    return MClT;
+}
+
+
+
+const Muon::MuonClusterOnTrack* Muon::MMClusterOnTrackCreator::createRIO_OnTrack(const Trk::PrepRawData& RIO,
+                                                    const Amg::Vector3D& GP,
+                                                    const Amg::Vector3D&) const {
+    return createRIO_OnTrack(RIO, GP);
+}
+
+
+
+const Muon::MuonClusterOnTrack* Muon::MMClusterOnTrackCreator::correct(const Trk::PrepRawData& RIO, const Trk::TrackParameters& TP) const {
+    return createRIO_OnTrack(RIO, TP.position());
+}
diff --git a/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MMClusterOnTrackCreator.h b/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MMClusterOnTrackCreator.h
new file mode 100644
index 00000000000..66f6a9ce464
--- /dev/null
+++ b/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MMClusterOnTrackCreator.h
@@ -0,0 +1,78 @@
+/*
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef MMClusterOnTrackCreator_H
+#define MMClusterOnTrackCreator_H
+
+#include "AthenaBaseComps/AthAlgTool.h"
+#include "GaudiKernel/ToolHandle.h"
+#include "MuonRecToolInterfaces/IMuonClusterOnTrackCreator.h"
+#include "MuonRIO_OnTrack/MuonClusterOnTrack.h"
+#include "MuonIdHelpers/IMuonIdHelperSvc.h"
+
+#include "MuonReadoutGeometry/MuonDetectorManager.h"
+#include "TrkPrepRawData/PrepRawDataCLASS_DEF.h"
+#include "TrkParameters/TrackParameters.h"
+
+namespace Muon {
+
+
+  /** @class MMClusterOnTrackCreator
+      @brief Interface for the reconstruction to calibration and alignment corrections. It should be used by 
+             reconstruction and pattern recognition to create Muon::MuonClusterOnTrack objects (s).
+
+       It offers several interfaces:
+       - Create new Muon::MuonClusterOnTrack from a Trk::PrepRawData and a predicted Trk::TrackParameter.       
+         @code const MuonClusterOnTrack* correct ( const Trk::PrepRawData& RIO, const Trk::TrackParameters& tp) const @endcode
+       - Create new Muon::MuonClusterOnTrack from a Trk::PrepRawData and a prediction of the global position and direction.
+         @code createRIO_OnTrack(const Trk::PrepRawData& ROP, const Trk::GlobalPosition& GP, const Trk::GlobalDirection GD) const @endcode
+       - Create new Muon::MuonClusterOnTrack from a Trk::PrepRawData and a prediction intersect position of the muon with the 
+         measurement surface.
+         Kept for legacy with interface
+         @code createRIO_OnTrack(const Trk::PrepRawData& RIO, const Trk::GlobalPosition& GP) const @endcode
+       
+       JobOptions Flags:
+       - MuonIdHelperTool : choose muon id helper tool
+   */
+ class MMClusterOnTrackCreator : public AthAlgTool, virtual public IMuonClusterOnTrackCreator {
+  public:
+    
+    MMClusterOnTrackCreator(const std::string&,const std::string&,const IInterface*);
+    virtual ~MMClusterOnTrackCreator()=default;
+    virtual StatusCode initialize() override;
+ 
+    /** @brief Create new Muon::MuonClusterOnTrack from a Trk::PrepRawData and a predicted Trk::TrackParameter. 
+	@param RIO Trk::PrepRawData object to be calibrated
+	@param GP  Predicted intersect position of the muon with the measurement plane 
+	@return a pointer to a new Muon::MuonClusterOnTrack object, zero if calibration failed.
+	The ownership of the new Muon::MuonClusterOnTrack is passed to the client calling the tool
+    */       
+    virtual const MuonClusterOnTrack* createRIO_OnTrack(const Trk::PrepRawData& RIO,
+                                                        const Amg::Vector3D& GP) const override;
+
+    /** @brief Create new Muon::MuonClusterOnTrack from a Trk::PrepRawData and a prediction of the global position and direction.
+	It is only implemented for the CSCs, for RPC and TGC Trk::PrepRawData the result is the same as for the routine without the direction. 
+	@param RIO Trk::PrepRawData object to be calibrated
+	@param GP  Predicted intersect position of the muon with the measurement plane 
+	@param GD  Predicted direction at the intersect position of the muon with the measurement plane 
+	@return a pointer to a new Muon::MuonClusterOnTrack object, zero if calibration failed.
+	The ownership of the new Muon::MuonClusterOnTrack is passed to the client calling the tool
+    */
+    virtual const MuonClusterOnTrack* createRIO_OnTrack(const Trk::PrepRawData& RIO,
+                                                        const Amg::Vector3D& GP,
+                                                        const Amg::Vector3D& GD) const override;
+ 
+    /** @brief Create new Muon::MuonClusterOnTrack from a Trk::PrepRawData and the predicted Trk::TrackParameter at the measurement surface. 
+	@param RIO Trk::PrepRawData object to be calibrated
+	@param TP  Predicted Trk::TrackParameter at the measurement surface
+	@return a pointer to a new Muon::MuonClusterOnTrack object, zero if calibration failed.
+	The ownership of the new Muon::MuonClusterOnTrack is passed to the client calling the tool
+    */
+    virtual const MuonClusterOnTrack* correct(const Trk::PrepRawData& RIO,const Trk::TrackParameters& TP) const override; 
+  
+  private:
+    ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
+ }; // end of class def
+}  //  namespace Muon
+#endif // MMClusterOnTrackCreator_H
diff --git a/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MuonClusterOnTrackCreator.cxx b/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MuonClusterOnTrackCreator.cxx
index 063d84d75c2..56c7a643744 100755
--- a/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MuonClusterOnTrackCreator.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/MuonClusterOnTrackCreator.cxx
@@ -14,13 +14,11 @@
 #include "MuonPrepRawData/TgcPrepData.h"
 #include "MuonPrepRawData/CscPrepData.h"
 #include "MuonPrepRawData/sTgcPrepData.h"
-#include "MuonPrepRawData/MMPrepData.h"
 
 #include "MuonRIO_OnTrack/CscClusterOnTrack.h"
 #include "MuonRIO_OnTrack/TgcClusterOnTrack.h"
 #include "MuonRIO_OnTrack/RpcClusterOnTrack.h"
 #include "MuonRIO_OnTrack/sTgcClusterOnTrack.h"
-#include "MuonRIO_OnTrack/MMClusterOnTrack.h"
 #include <sstream>
 
 #define SIG_VEL 4.80000  // ns/m
@@ -77,13 +75,13 @@ namespace Muon {
 									 const Amg::Vector3D& GP) const
 
   {
-    MuonClusterOnTrack* MClT = 0;
+    MuonClusterOnTrack* MClT = nullptr;
  
     // check whether PrepRawData has detector element, if not there print warning 
     const Trk::TrkDetElementBase* EL = RIO.detectorElement();
     if( !EL ){
       ATH_MSG_WARNING ( "RIO does not have associated detectorElement!, cannot produce ROT" );
-      return 0;
+      return nullptr;
     }
 
     // MuClusterOnTrack production
@@ -133,7 +131,7 @@ namespace Muon {
       const RpcPrepData* MClus   = dynamic_cast<const RpcPrepData*> (&RIO);
       if (!MClus) {
 	ATH_MSG_WARNING ( "RIO not of type RpcPrepData, cannot create ROT" );
-	return 0;
+	return nullptr;
       }
         
       bool measphi = m_idHelperSvc->measuresPhi(RIO.identify());
@@ -187,7 +185,7 @@ namespace Muon {
       const TgcPrepData* MClus   = dynamic_cast<const TgcPrepData*> (&RIO);
       if (!MClus) {
 	ATH_MSG_WARNING ( "RIO not of type TgcPrepData, cannot create ROT" );
-	return 0;
+	return nullptr;
       }
 
       // calculation of 2D error matrix for TGC phi strips
@@ -237,7 +235,7 @@ namespace Muon {
       const CscPrepData* MClus   = dynamic_cast<const CscPrepData*> (&RIO);
       if (!MClus) {
 	ATH_MSG_WARNING ( "RIO not of type CscPrepData, cannot create ROT" );
-	return 0;
+	return nullptr;
       }
 
       bool measphi = m_idHelperSvc->measuresPhi(RIO.identify());
@@ -259,22 +257,12 @@ namespace Muon {
       // current not changing CscClusterStatus but passing status of RIO
       MClT = new CscClusterOnTrack(MClus,locpar,loce,positionAlongStrip,MClus->status(),MClus->timeStatus());
 
-    }else if( m_idHelperSvc->isMM(RIO.identify()) ){
-      // cast to MMPrepData
-      const MMPrepData* MClus   = dynamic_cast<const MMPrepData*> (&RIO);
-      if (!MClus) {
-	        ATH_MSG_WARNING ( "RIO not of type MMPrepData, cannot create ROT" );
-	        return 0;
-      }
-      MClT = new MMClusterOnTrack(MClus,locpar,loce,positionAlongStrip);
-
     }else if( m_idHelperSvc->issTgc(RIO.identify()) ){
-
       // cast to sTgcPrepData
       const sTgcPrepData* MClus   = dynamic_cast<const sTgcPrepData*> (&RIO);
       if (!MClus) {
       	ATH_MSG_WARNING ( "RIO not of type sTgcPrepData, cannot create ROT" );
-      	return 0;
+      	return nullptr;
       }
 
       
@@ -285,11 +273,11 @@ namespace Muon {
 
   const MuonClusterOnTrack* MuonClusterOnTrackCreator::
   createRIO_OnTrack(const Trk::PrepRawData& RIO, const Amg::Vector3D& GP, const Amg::Vector3D&) const {
-    return createRIO_OnTrack(RIO,GP);
+    return createRIO_OnTrack(RIO, GP);
   }
 
   const MuonClusterOnTrack* MuonClusterOnTrackCreator::correct(const Trk::PrepRawData& RIO,const Trk::TrackParameters& TP) const 
-  {
+  {  
     return createRIO_OnTrack(RIO,TP.position(),TP.momentum());
   }
 }
diff --git a/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/components/MuonClusterOnTrackCreator_entries.cxx b/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/components/MuonClusterOnTrackCreator_entries.cxx
index 920fedc942a..a746963dc0d 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/components/MuonClusterOnTrackCreator_entries.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MuonClusterOnTrackCreator/src/components/MuonClusterOnTrackCreator_entries.cxx
@@ -1,8 +1,10 @@
 #include "../MuonClusterOnTrackCreator.h"
 #include "../CscClusterOnTrackCreator.h"
+#include "../MMClusterOnTrackCreator.h"
 
 using namespace Muon;
 
 DECLARE_COMPONENT( MuonClusterOnTrackCreator )
 DECLARE_COMPONENT( CscClusterOnTrackCreator )
+DECLARE_COMPONENT( MMClusterOnTrackCreator )
 
diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonRecTools.py b/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonRecTools.py
index b1f4ca7f6a6..7f950dfa1d0 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonRecTools.py
+++ b/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonRecTools.py
@@ -48,6 +48,9 @@ def MuonClusterOnTrackCreator(name="MuonClusterOnTrackCreator",**kwargs):
 
     return CfgMgr.Muon__MuonClusterOnTrackCreator(name,**kwargs)
 
+def MMClusterOnTrackCreator(name="MMClusterOnTrackCreator",**kwargs):
+    return CfgMgr.Muon__MMClusterOnTrackCreator(name,**kwargs)
+
 def getMuonRIO_OnTrackErrorScalingCondAlg() :
     error_scaling_def=["CSCRIO_OnTrackErrorScaling:/MUON/TrkErrorScalingCSC"]
     return getRIO_OnTrackErrorScalingCondAlg( name                = "MuonRIO_OnTrackErrorScalingCondAlg",
diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTGRecTools/share/MuonHolesSearch_jobOptions.py b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTGRecTools/share/MuonHolesSearch_jobOptions.py
index 89ce40f8c76..561b2a56376 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTGRecTools/share/MuonHolesSearch_jobOptions.py
+++ b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTGRecTools/share/MuonHolesSearch_jobOptions.py
@@ -85,6 +85,7 @@ if ( doMuonOutliers ) :
     ToolSvc += RotCreator
     ToolSvc.RotCreator.Mode = "muon"
     ToolSvc.RotCreator.ToolMuonCluster = 'MuonClusterOnTrackTool'
+    ToolSvc.RotCreator.ToolMuonMMCluster = 'MMClusterOnTrackTool'
     print RotCreator
 
     ToolSvc.MuonHolesOnTrackTool.RIO_OnTrackCreator = RotCreator
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentCombiners/MuonSegmentCombinerTools/MooSegmentCombinationFinder/src/MuonSegmentFinderAlg.cxx b/MuonSpectrometer/MuonReconstruction/MuonSegmentCombiners/MuonSegmentCombinerTools/MooSegmentCombinationFinder/src/MuonSegmentFinderAlg.cxx
index 4a1d9848772..88fa757e2b1 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentCombiners/MuonSegmentCombinerTools/MooSegmentCombinationFinder/src/MuonSegmentFinderAlg.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentCombiners/MuonSegmentCombinerTools/MooSegmentCombinationFinder/src/MuonSegmentFinderAlg.cxx
@@ -31,6 +31,7 @@ MuonSegmentFinderAlg::MuonSegmentFinderAlg(const std::string& name, ISvcLocator*
   m_clusterSegMaker("Muon::MuonClusterSegmentFinder/MuonClusterSegmentFinder", this),
   m_segmentOverlapRemovalTool("Muon::MuonSegmentOverlapRemovalTool/MuonSegmentOverlapRemovalTool", this),
   m_clusterCreator("Muon::MuonClusterOnTrackCreator/MuonClusterOnTrackCreator", this),
+  m_mmClusterCreator("Muon::MMClusterOnTrackCreator/MMClusterOnTrackCreator", this),
   m_clusterSegMakerNSW("Muon::MuonClusterSegmentFinderTool/MuonClusterSegmentFinderTool", this),
   m_truthSummaryTool("Muon::MuonTruthSummaryTool/MuonTruthSummaryTool", this),
   m_csc2dSegmentFinder("Csc2dSegmentMaker/Csc2dSegmentMaker", this),
@@ -42,6 +43,7 @@ MuonSegmentFinderAlg::MuonSegmentFinderAlg(const std::string& name, ISvcLocator*
   declareProperty("MuonPatternSegmentMaker", m_patternSegmentMaker);
   declareProperty("SegmentMaker",m_segmentMaker);
   declareProperty("ClusterCreator",m_clusterCreator);
+  declareProperty("MMClusterCreator",m_mmClusterCreator);
   declareProperty("MuonClusterSegmentFinderTool",m_clusterSegMakerNSW);
   declareProperty("MuonTruthSummaryTool",m_truthSummaryTool);
   declareProperty("Csc2dSegmentMaker", m_csc2dSegmentFinder);
@@ -249,9 +251,15 @@ void MuonSegmentFinderAlg::createSegmentsFromClusters(const Muon::MuonPatternCom
       if( !cl ) continue;
       int sector = m_idHelperSvc->sector(id);
       std::vector<const Muon::MuonClusterOnTrack*>& clusters = clustersPerSector[sector];
-      const Muon::MuonClusterOnTrack* clust = m_clusterCreator->createRIO_OnTrack( *cl, cl->globalPosition() );
       
-      clusters.push_back(clust);
+      if(m_idHelperSvc->isMM((*pit)->identify())){
+        const Muon::MuonClusterOnTrack* clust = m_mmClusterCreator->createRIO_OnTrack( *cl, cl->globalPosition() );
+        clusters.push_back(clust);
+      } else {  //  must be an sTGC prd
+        const Muon::MuonClusterOnTrack* clust = m_clusterCreator->createRIO_OnTrack( *cl, cl->globalPosition() );
+        clusters.push_back(clust);
+      }
+
     }
   }
   
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentCombiners/MuonSegmentCombinerTools/MooSegmentCombinationFinder/src/MuonSegmentFinderAlg.h b/MuonSpectrometer/MuonReconstruction/MuonSegmentCombiners/MuonSegmentCombinerTools/MooSegmentCombinationFinder/src/MuonSegmentFinderAlg.h
index 6162da4e94c..ba9e6ffa3cd 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentCombiners/MuonSegmentCombinerTools/MooSegmentCombinationFinder/src/MuonSegmentFinderAlg.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentCombiners/MuonSegmentCombinerTools/MooSegmentCombinationFinder/src/MuonSegmentFinderAlg.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 MOOSEGMENTFINDERS_MUOSEGMENTFINDERALGS_H
@@ -58,6 +58,7 @@ class MuonSegmentFinderAlg : public AthAlgorithm
   ToolHandle<Muon::IMuonClusterSegmentFinder>     m_clusterSegMaker;
   ToolHandle<Muon::IMuonSegmentOverlapRemovalTool> m_segmentOverlapRemovalTool;
   ToolHandle<Muon::IMuonClusterOnTrackCreator>    m_clusterCreator;  //<! pointer to muon cluster rio ontrack creator
+  ToolHandle<Muon::IMuonClusterOnTrackCreator>    m_mmClusterCreator;  //<! pointer to mm cluster rio ontrack creator
   ToolHandle<Muon::IMuonClusterSegmentFinderTool> m_clusterSegMakerNSW;
   ToolHandle<Muon::IMuonTruthSummaryTool>         m_truthSummaryTool;
   ToolHandle<ICscSegmentFinder>                  m_csc2dSegmentFinder;
diff --git a/Tracking/TrkTools/TrkRIO_OnTrackCreator/TrkRIO_OnTrackCreator/RIO_OnTrackCreator.h b/Tracking/TrkTools/TrkRIO_OnTrackCreator/TrkRIO_OnTrackCreator/RIO_OnTrackCreator.h
index 73d3fba7db5..64811383024 100755
--- a/Tracking/TrkTools/TrkRIO_OnTrackCreator/TrkRIO_OnTrackCreator/RIO_OnTrackCreator.h
+++ b/Tracking/TrkTools/TrkRIO_OnTrackCreator/TrkRIO_OnTrackCreator/RIO_OnTrackCreator.h
@@ -89,6 +89,8 @@ namespace Trk {
     ToolHandle<IRIO_OnTrackCreator>  m_muonDriftCircleCor;
     //! Detector-specific helper tool, performing the actual calibration corrections for the remaining muon detector technologies: RPC, TGC and CSC.
     ToolHandle<IRIO_OnTrackCreator>  m_muonClusterCor;
+    //! Detector-specific helper tool, performing the actual calibration corrections for every Muon::MMPrepData 
+    ToolHandle<IRIO_OnTrackCreator>  m_mmClusterCor;
     std::string                      m_mode;   //!< flag: can be 'all', 'indet' or 'muon'
     int*                  m_nwarning;          //!< counter to locally control # of warnings
     bool                             m_doPixel; //!< Load Pixel IRIO_OnTrackCreator
diff --git a/Tracking/TrkTools/TrkRIO_OnTrackCreator/src/RIO_OnTrackCreator.cxx b/Tracking/TrkTools/TrkRIO_OnTrackCreator/src/RIO_OnTrackCreator.cxx
index 00e8c8bcd0c..c77d174f2a0 100755
--- a/Tracking/TrkTools/TrkRIO_OnTrackCreator/src/RIO_OnTrackCreator.cxx
+++ b/Tracking/TrkTools/TrkRIO_OnTrackCreator/src/RIO_OnTrackCreator.cxx
@@ -28,11 +28,12 @@ Trk::RIO_OnTrackCreator::RIO_OnTrackCreator(const std::string& t,
 			      const IInterface* p)
   :  AthAlgTool(t,n,p),
      m_idHelper(nullptr),
-     m_pixClusCor        ("InDet::PixelClusterOnTrackTool/PixelClusterOnTrackTool"),
+     m_pixClusCor        ("InDet::PixelClusterOnTrackTool/PixelClusterOnTrackTool", this),
      m_sctClusCor        ("InDet::SCT_ClusterOnTrackTool/SCT_ClusterOnTrackTool", this),
-     m_trt_Cor           ("InDet::TRT_DriftCircleOnTrackTool/TRT_DriftCircleOnTrackTool"),
-     m_muonDriftCircleCor("Muon::MdtDriftCircleOnTrackCreator/MdtDriftCircleOnTrackTool"),
-     m_muonClusterCor    ("Muon::MuonClusterOnTrackCreator/MuonClusterOnTrackTool"),
+     m_trt_Cor           ("InDet::TRT_DriftCircleOnTrackTool/TRT_DriftCircleOnTrackTool", this),
+     m_muonDriftCircleCor("Muon::MdtDriftCircleOnTrackCreator/MdtDriftCircleOnTrackTool", this),
+     m_muonClusterCor    ("Muon::MuonClusterOnTrackCreator/MuonClusterOnTrackTool", this),
+     m_mmClusterCor      ("Muon::MMClusterOnTrackCreator/MMClusterOnTrackTool", this),
      m_doPixel(true),
      m_doSCT(true),
      m_doTRT(true)
@@ -45,6 +46,7 @@ Trk::RIO_OnTrackCreator::RIO_OnTrackCreator(const std::string& t,
    declareProperty("ToolTRT_DriftCircle",m_trt_Cor);
    declareProperty("ToolMuonDriftCircle",m_muonDriftCircleCor);
    declareProperty("ToolMuonCluster"    ,m_muonClusterCor);
+   declareProperty("ToolMuonMMCluster"  ,m_mmClusterCor);
    declareProperty("Mode"               ,m_mode);
  }
 
@@ -60,53 +62,41 @@ StatusCode Trk::RIO_OnTrackCreator::initialize()
   if (AlgTool::initialize().isFailure()) return StatusCode::FAILURE; 
 
   if (m_mode != "all" && m_mode != "indet" &&m_mode != "muon") {
-    msg(MSG::FATAL) << "Mode is set to unknown value " << m_mode << endmsg;
+    ATH_MSG_FATAL("Mode is set to unknown value " << m_mode);
     return StatusCode::FAILURE;
   }
 
-  ATH_MSG_INFO( " RIO_OnTrackCreator job configuration:" << std::endl
-		 << std::endl << " (i) The following RIO correction "
-		 << "tools configured (depends on mode = "<< m_mode <<"):" << std::endl
-		 << "     Pixel      : " << m_pixClusCor << std::endl
-		 << "     SCT        : " << m_sctClusCor << std::endl
-		 << "     TRT        : " << m_trt_Cor       << std::endl
-		 << "     MDT        : " << m_muonDriftCircleCor << std::endl
-		 << "     CSC/RPC/TGC: " << m_muonClusterCor << std::endl
-       );
+  ATH_MSG_INFO("RIO_OnTrackCreator job configuration:" << std::endl
+     << std::endl << " (i) The following RIO correction "
+     << "tools configured (depends on mode = "<< m_mode <<"):" << std::endl
+     << "     Pixel      : " << m_pixClusCor << std::endl
+     << "     SCT        : " << m_sctClusCor << std::endl
+     << "     TRT        : " << m_trt_Cor       << std::endl
+     << "     MDT        : " << m_muonDriftCircleCor << std::endl
+     << "     CSC/RPC/TGC/sTGC: " << m_muonClusterCor << std::endl
+     << "     MM: " << m_mmClusterCor);
 
   // Get the correction tool to create Pixel/SCT/TRT RIO_onTrack
 
   if (m_mode == "all" || m_mode == "indet") {
-
     if (!m_pixClusCor.empty()) {
-      if ( m_pixClusCor.retrieve().isFailure() ) {
-	      ATH_MSG_FATAL( "Failed to retrieve tool " << m_pixClusCor);
-	      return StatusCode::FAILURE;
-      } 
-	      ATH_MSG_INFO( "Retrieved tool " << m_pixClusCor);
-      
+      ATH_CHECK(m_pixClusCor.retrieve());
+      ATH_MSG_INFO("Retrieved tool " << m_pixClusCor);
     } else {
       m_doPixel = false;
     }
 
     if (!m_sctClusCor.empty()) {
-      if ( m_sctClusCor.retrieve().isFailure() ) {
-        ATH_MSG_FATAL( "Failed to retrieve tool " << m_sctClusCor);
-	      return StatusCode::FAILURE;
-      } 
-	      ATH_MSG_INFO( "Retrieved tool " << m_sctClusCor);
-      
+      ATH_CHECK(m_sctClusCor.retrieve());
+      ATH_MSG_INFO("Retrieved tool " << m_sctClusCor);
     } else {
       m_doSCT = false;
     }
 
-    if (!m_trt_Cor.empty()) {
-      if ( m_trt_Cor.retrieve().isFailure() ) {
-        ATH_MSG_FATAL( "Failed to retrieve tool " << m_trt_Cor);
-	      return StatusCode::FAILURE;
-      } 
-	      ATH_MSG_INFO( "Retrieved tool " << m_trt_Cor);
       
+    if (!m_trt_Cor.empty()) {
+      ATH_CHECK(m_trt_Cor.retrieve());
+      ATH_MSG_INFO("Retrieved tool " << m_trt_Cor);
     } else {
       m_doTRT = false;
     }
@@ -117,30 +107,22 @@ StatusCode Trk::RIO_OnTrackCreator::initialize()
   }
 
   if (m_mode == "all" || m_mode == "muon") {
-    if ( m_muonDriftCircleCor.retrieve().isFailure() ) {
-      ATH_MSG_FATAL( "Failed to retrieve tool " << m_muonDriftCircleCor);      
-      return StatusCode::FAILURE;
-    } 
-      ATH_MSG_INFO( "Retrieved tool " << m_muonDriftCircleCor);
-    
+    ATH_CHECK(m_muonDriftCircleCor.retrieve());
+    ATH_MSG_INFO("Retrieved tool " << m_muonDriftCircleCor);
 
-    if ( m_muonClusterCor.retrieve().isFailure() ) {
-      ATH_MSG_FATAL( "Failed to retrieve tool " << m_muonClusterCor);            
-      return StatusCode::FAILURE;
-    } 
-      ATH_MSG_INFO( "Retrieved tool " << m_muonClusterCor);
-    
-  }
-  else{
+    ATH_CHECK(m_muonClusterCor.retrieve());
+    ATH_MSG_INFO("Retrieved tool " << m_muonClusterCor);
+
+    ATH_CHECK(m_mmClusterCor.retrieve());
+    ATH_MSG_INFO("Retrieved tool " << m_mmClusterCor);
+  } else{
     m_muonClusterCor.disable();
     m_muonDriftCircleCor.disable();
+    m_mmClusterCor.disable();
   }
-  
+
   // Set up ATLAS ID helper to be able to identify the RIO's det-subsystem.
-  if (detStore()->retrieve(m_idHelper, "AtlasID").isFailure()) {
-    ATH_MSG_ERROR ("Could not get AtlasDetectorID helper" );
-    return StatusCode::FAILURE;
-  }
+  ATH_CHECK(detStore()->retrieve(m_idHelper, "AtlasID"));
 
   ATH_MSG_INFO("initialize() successful in " << name());
   return StatusCode::SUCCESS;
@@ -170,7 +152,7 @@ Trk::RIO_OnTrackCreator::correct(const Trk::PrepRawData& rio,
     if (m_mode == "muon") {
       ATH_MSG_WARNING("I have no tool to correct the current Pixel hit! - Giving back nil.");
       return nullptr;
-    } 
+    }
       ATH_MSG_DEBUG ("RIO identified as PixelCluster.");
       return m_pixClusCor->correct(rio, trk);
     
@@ -180,41 +162,44 @@ Trk::RIO_OnTrackCreator::correct(const Trk::PrepRawData& rio,
     if (m_mode == "muon") {
       ATH_MSG_WARNING("I have no tool to correct the current SCT hit! - Giving back nil.");
       return nullptr;
-    } 
-      ATH_MSG_DEBUG ("RIO identified as SCT_Cluster.");
-      return m_sctClusCor->correct(rio, trk);
-    
+    }
+    ATH_MSG_DEBUG("RIO identified as SCT_Cluster.");
+    return m_sctClusCor->correct(rio, trk);
   }
 
   if (m_doTRT && m_idHelper->is_trt(id)) {
     if (m_mode == "muon") {
       ATH_MSG_WARNING("I have no tool to correct a TRT DriftCircle! - Giving back nil.");
       return nullptr;
-    } 
-      ATH_MSG_DEBUG ("RIO identified as TRT_DriftCircle.");
-      return m_trt_Cor->correct(rio, trk);
-    
+    }
+    ATH_MSG_DEBUG ("RIO identified as TRT_DriftCircle.");
+    return m_trt_Cor->correct(rio, trk);
   }
 
   if (m_idHelper->is_mdt(id)){
     if (m_mode == "indet") {
       ATH_MSG_WARNING("I have no tool to correct a MDT DriftCircle! - Giving back nil.");
       return nullptr;
-    } 
-      ATH_MSG_DEBUG ("RIO identified as MuonDriftCircle.");
-      return m_muonDriftCircleCor->correct(rio, trk);
-    
+    }
+    ATH_MSG_DEBUG("RIO identified as MuonDriftCircle.");
+    return m_muonDriftCircleCor->correct(rio, trk);
   }
-  
   if ( (m_idHelper->is_csc(id)) || (m_idHelper->is_rpc(id))
-       || (m_idHelper->is_tgc(id)) || (m_idHelper->is_mm(id)) || (m_idHelper->is_stgc(id)) ) {
+       || (m_idHelper->is_tgc(id)) || (m_idHelper->is_stgc(id)) ) {
     if (m_mode == "indet") {
-      ATH_MSG_WARNING("I have no tool to correct a CSC/RPC/TGC hit! - Giving back nil.");
+      ATH_MSG_WARNING("I have no tool to correct a CSC/RPC/TGC/sTGC hit! - Giving back nil.");
       return nullptr;
-    } 
-      ATH_MSG_DEBUG ("RIO identified as MuonCluster.");
+    }
+      ATH_MSG_DEBUG("RIO identified as MuonCluster.");
       return m_muonClusterCor->correct(rio, trk);
-    
+  }
+  if (m_idHelper->is_mm(id)) {
+    if (m_mode == "indet") {
+      ATH_MSG_WARNING("I have no tool to correct a MM hit! - Giving back nil.");
+      return nullptr;
+    }
+      ATH_MSG_DEBUG("RIO identified as MMCluster.");
+      return m_mmClusterCor->correct(rio, trk);
   }
 
   ATH_MSG_WARNING( "idHelper could not identify sub-detector for: "<<m_idHelper->print_to_string(id)<<". Return nil RIO_OnTrack");
diff --git a/Trigger/TrigAlgorithms/TrigMuonEF/python/TrigMuonEFCosmicConfig.py b/Trigger/TrigAlgorithms/TrigMuonEF/python/TrigMuonEFCosmicConfig.py
index 299fc851bf8..0eba5a3718b 100755
--- a/Trigger/TrigAlgorithms/TrigMuonEF/python/TrigMuonEFCosmicConfig.py
+++ b/Trigger/TrigAlgorithms/TrigMuonEF/python/TrigMuonEFCosmicConfig.py
@@ -79,6 +79,7 @@ from TrkRIO_OnTrackCreator.TrkRIO_OnTrackCreatorConf import Trk__RIO_OnTrackCrea
 TMEF_MuonRotCreatorCosmic =  Trk__RIO_OnTrackCreator("TMEF_MuonRotCreatorCosmic",
                                                      ToolMuonDriftCircle = TMEF_MdtDriftCircleOnTrackCreatorCosmic,
                                                      ToolMuonCluster     = "MuonClusterOnTrackCreator"    ,
+                                                     ToolMuonMMCluster   = "MMClusterOnTrackCreator"    ,
                                                      Mode                = 'muon'
                                                      )
 
-- 
GitLab