From 3af1d492a36c6ecf5b228c65ace57163f7ff4563 Mon Sep 17 00:00:00 2001
From: Will Leight <wleight@cern.ch>
Date: Fri, 15 Jan 2021 17:12:49 +0100
Subject: [PATCH 1/4] Fix for ATLASRECTS-5888

This ensures that the final segment collections written out contain both MuGirl and Muon(Moo)SegmentFinderAlg segments.
The xAOD segment container is now created and filled in the MuonCreatorAlg (so the xAODMuonCnvAlg is removed from the configuration).
The Muon(Moo)SegmentFinderAlg segments are copied into the final Trk::SegmentCollection in MuonCreatorAlg.
Conversion of the segments now happens in the the MuonCreatorAlg as well.
MuGirl segments are only added to the collection if they correspond to a muon with primary author MuGirl.
The MuonSegmentContainer used for associating segments to muons is now passed directly to the tool, rather than retrieved from SG.
---
 .../MuonRecExample/python/MuonStandalone.py   |  3 --
 .../MuonCombinedAlgs/CMakeLists.txt           |  2 +-
 .../MuonCombinedAlgs/src/MuonCreatorAlg.cxx   | 20 ++++++++++
 .../MuonCombinedAlgs/src/MuonCreatorAlg.h     |  7 ++--
 .../src/MuonCreatorTool.cxx                   | 39 +++++++++----------
 .../src/MuonCreatorTool.h                     |  4 +-
 .../src/TrackSegmentAssociationTool.cxx       | 30 +++-----------
 .../src/TrackSegmentAssociationTool.h         |  5 +--
 8 files changed, 52 insertions(+), 58 deletions(-)

diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonStandalone.py b/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonStandalone.py
index a3b56dfb570d..5783027ecf51 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonStandalone.py
+++ b/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonStandalone.py
@@ -193,9 +193,6 @@ class MuonStandalone(ConfiguredMuonRec):
             if (not cfgKeyStore.isInInput ('xAOD::MuonSegmentContainer', 'MuonSegments_NCB')):
                 self.addAlg( CfgMgr.xAODMaker__MuonSegmentCnvAlg("MuonSegmentCnvAlg_NCB",SegmentContainerName="NCB_TrackMuonSegments",xAODContainerName="NCB_MuonSegments") )
 
-        if (not cfgKeyStore.isInInput ('xAOD::MuonSegmentContainer', 'MuonSegments')):
-            self.addAlg( CfgMgr.xAODMaker__MuonSegmentCnvAlg("MuonSegmentCnvAlg") )
-        
         if muonStandaloneFlags.doSegmentsOnly():
             return	                    
         # Tracks builder
diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt b/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt
index 38cdd9f98f66..5b3435ce5d0d 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt
@@ -7,6 +7,6 @@ atlas_subdir( MuonCombinedAlgs )
 atlas_add_component( MuonCombinedAlgs
                      src/*.cxx
                      src/components/*.cxx
-                     LINK_LIBRARIES AthenaBaseComps AthenaMonitoringKernelLib xAODCaloEvent xAODMuon xAODTruth xAODTracking GaudiKernel MuonSegment MuonRecToolInterfaces MuonLayerEvent MuonCombinedEvent MuonCombinedToolInterfaces MuonPrepRawData StoreGateLib TrkSegment TrkTrack TrkToolInterfaces)
+                     LINK_LIBRARIES AthenaBaseComps AthenaMonitoringKernelLib xAODCaloEvent xAODMuon xAODMuonCnvLib xAODTruth xAODTracking GaudiKernel MuonSegment MuonRecToolInterfaces MuonLayerEvent MuonCombinedEvent MuonCombinedToolInterfaces MuonPrepRawData StoreGateLib TrkSegment TrkTrack TrkToolInterfaces)
 
 atlas_install_python_modules( python/MuonCombinedAlgsMonitoring.py POST_BUILD_CMD ${ATLAS_FLAKE8} )
diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
index e442f3ba5e53..571cdf0d9d21 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
@@ -32,12 +32,14 @@ StatusCode MuonCreatorAlg::initialize()
 {
 
   ATH_CHECK(m_muonCreatorTool.retrieve());
+  ATH_CHECK(m_muonSegmentConverterTool.retrieve());
   ATH_CHECK(m_muonCollectionName.initialize());
   ATH_CHECK(m_slowMuonCollectionName.initialize(m_buildSlowMuon));
   ATH_CHECK(m_indetCandidateCollectionName.initialize(!m_doSA));
   ATH_CHECK(m_muonCandidateCollectionName.initialize(!m_buildSlowMuon));
   //Can't use a flag in intialize for an array of keys
   if(!m_doSA) ATH_CHECK(m_tagMaps.initialize());
+  ATH_CHECK(m_inputSegContainerName.initialize());
   ATH_CHECK(m_segContainerName.initialize());
   ATH_CHECK(m_segTrkContainerName.initialize());
   m_combinedTrkCollectionName = m_combinedCollectionName.key()+"Tracks";
@@ -130,6 +132,24 @@ StatusCode MuonCreatorAlg::execute()
   SG::WriteHandle<Trk::SegmentCollection> wh_segmentTrk(m_segTrkContainerName);
   ATH_CHECK(wh_segmentTrk.record(std::make_unique<Trk::SegmentCollection>()));
   output.muonSegmentCollection=wh_segmentTrk.ptr();
+  //now copy the input segments to the final container
+  SG::ReadHandle<Trk::SegmentCollection> inputSegs(m_inputSegContainerName);
+  if(inputSegs.isValid()){
+    for( auto it = inputSegs->begin();it!=inputSegs->end();++it ){
+      //have to cast because the collection stores Trk::Segments
+      const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(&(**it));
+      if(muonSegment) wh_segmentTrk->push_back(new Muon::MuonSegment(*muonSegment));
+    }
+  }
+  //now convert
+  unsigned int index = 0;
+  for( auto it = wh_segmentTrk->begin();it!=wh_segmentTrk->end();++it,++index){
+    //have to cast because the collection stores Trk::Segments
+    const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(&(**it));
+    if( !muonSegment ) continue;
+    ElementLink< Trk::SegmentCollection > link(*wh_segmentTrk,index);
+    m_muonSegmentConverterTool->convert(link,wh_segment.ptr());
+  }
 
   // calo clusters
   SG::WriteHandle<xAOD::CaloClusterContainer> wh_clusters;
diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
index 754f58f9aa67..6d8de3b8552e 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
@@ -17,6 +17,7 @@
 #include "MuonCombinedEvent/InDetCandidateToTagMap.h"
 
 #include "MuonCombinedToolInterfaces/IMuonCreatorTool.h"
+#include "xAODMuonCnv/IMuonSegmentConverterTool.h"
 
 #include "xAODMuon/MuonContainer.h"
 #include "xAODMuon/SlowMuonContainer.h"
@@ -41,6 +42,7 @@ class MuonCreatorAlg : public AthAlgorithm
 
  private:
   ToolHandle<MuonCombined::IMuonCreatorTool> m_muonCreatorTool{this,"MuonCreatorTool","MuonCombined::MuonCreatorTool/MuonCreatorTool","Muon creator tool"};
+  ToolHandle<xAODMaker::IMuonSegmentConverterTool> m_muonSegmentConverterTool {this, "MuonSegmentConverterTool", "Muon::MuonSegmentConverterTool/MuonSegmentConverterTool"};
   SG::WriteHandleKey<xAOD::MuonContainer> m_muonCollectionName{this,"MuonContainerLocation", "Muons", "Muon Container"};
   SG::WriteHandleKey<xAOD::SlowMuonContainer> m_slowMuonCollectionName{this, "SlowMuonContainerLocation", "SlowMuons", "Slow Muon Container"};
   SG::WriteHandleKey<xAOD::TrackParticleContainer> m_combinedCollectionName{this, "CombinedLocation", "CombinedMuon", "Combined muons"};
@@ -52,9 +54,8 @@ class MuonCreatorAlg : public AthAlgorithm
   SG::ReadHandleKey<InDetCandidateCollection> m_indetCandidateCollectionName{this,"InDetCandidateLocation","InDetCandidates","ID candidates"};
   SG::ReadHandleKey<MuonCandidateCollection> m_muonCandidateCollectionName{this,"MuonCandidateLocation","MuonCandidates","Muon candidates"};
   SG::ReadHandleKeyArray<MuonCombined::InDetCandidateToTagMap> m_tagMaps{this,"TagMaps",{"muidcoTagMap","stacoTagMap","muGirlTagMap","caloTagMap","segmentTagMap"},"ID candidate to tag maps"};
-  SG::WriteHandleKey<xAOD::MuonSegmentContainer> m_segContainerName{this, "SegmentContainerName", "xaodMuonSegments", "Segments"};
-
-  // the following Trk::SegmentCollection MuonSegments are MuGirl segments, the standard MuonSegments are store in MuonSegmentFinderAlg.h
+  SG::ReadHandleKey<Trk::SegmentCollection> m_inputSegContainerName{this,"InputSegmentContainerName","TrackMuonSegments","Input track segments"};
+  SG::WriteHandleKey<xAOD::MuonSegmentContainer> m_segContainerName{this, "SegmentContainerName", "MuonSegments", "Segments"};
   SG::WriteHandleKey<Trk::SegmentCollection> m_segTrkContainerName{this,"TrackSegmentContainerName","TrkMuonSegments","Track segments"};
 
   SG::WriteHandleKey<xAOD::CaloClusterContainer> m_clusterContainerName{this, "ClusterContainerName", "MuonClusterCollection", "Clusters"};
diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.cxx b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.cxx
index 0a5c02b700c5..91840f88c9b5 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.cxx
+++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.cxx
@@ -32,7 +32,6 @@
 #include "TrkSegment/SegmentCollection.h"
 #include "xAODMuon/MuonSegmentContainer.h"
 #include "xAODMuon/MuonSegment.h"
-#include "xAODMuonCnv/IMuonSegmentConverterTool.h"
 #include "muonEvent/CaloEnergy.h"
 #include "FourMomUtils/P4Helpers.h"
 #include "xAODCaloEvent/CaloCluster.h"
@@ -296,7 +295,7 @@ namespace MuonCombined {
       return nullptr;
     }
     
-    if( !dressMuon(*muon) ){
+    if( !dressMuon(*muon,outputData.xaodSegmentContainer) ){
       ATH_MSG_WARNING("Failed to dress muon");
       outputData.muonContainer->pop_back();
       return nullptr;
@@ -464,7 +463,7 @@ namespace MuonCombined {
       }
     }// m_buildStauContainer
 
-    if( !dressMuon(*muon) ){ 
+    if( !dressMuon(*muon,outputData.xaodSegmentContainer) ){ 
       ATH_MSG_WARNING("Failed to dress muon");
       outputData.muonContainer->pop_back();
       return 0;
@@ -733,28 +732,26 @@ namespace MuonCombined {
 											 outputData.extrapolatedTrackCollection);
                 
         if( link.isValid() ) {
-          //link.toPersistent();
           ATH_MSG_DEBUG("Adding MuGirl: pt " << (*link)->pt() << " eta " << (*link)->eta() << " phi " << (*link)->phi() );
           muon.setTrackParticleLink(xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle, link );
         }
         else ATH_MSG_WARNING("Creating of MuGirl TrackParticle Link failed");
       }
-    }
-
-    if (outputData.xaodSegmentContainer){
-      ATH_MSG_DEBUG( "Adding MuGirl muonSegmentCollection");
 
-      std::vector< ElementLink< xAOD::MuonSegmentContainer > > segments;
-      for( const auto& segLink : tag->segments() ){ 
-        ElementLink<xAOD::MuonSegmentContainer> link = createMuonSegmentElementLink(segLink, *outputData.xaodSegmentContainer, outputData.muonSegmentCollection);
-        if( link.isValid() ) {
-          //link.toPersistent();
-          segments.push_back(link);
+      if (outputData.xaodSegmentContainer){
+	ATH_MSG_DEBUG( "Adding MuGirl muonSegmentCollection");
+	
+	std::vector< ElementLink< xAOD::MuonSegmentContainer > > segments;
+	for( const auto& segLink : tag->segments() ){ 
+	  ElementLink<xAOD::MuonSegmentContainer> link = createMuonSegmentElementLink(segLink, *outputData.xaodSegmentContainer, outputData.muonSegmentCollection);
+	  if( link.isValid() ) {
+	    segments.push_back(link);
           ATH_MSG_DEBUG("Adding MuGirl: xaod::MuonSegment px " << (*link)->px() << " py " << (*link)->py() << " pz " << (*link)->pz() ); 
-        }
-        else ATH_MSG_WARNING("Creating of MuGirl segment Link failed");         
+	  }
+	  else ATH_MSG_WARNING("Creating of MuGirl segment Link failed");         
+	}
+	muon.setMuonSegmentLinks(segments);
       }
-      muon.setMuonSegmentLinks(segments);
     }
     ATH_MSG_DEBUG("Done Adding MuGirl Muon  " << tag->author() << " type " << tag->type());    
   }
@@ -1273,7 +1270,7 @@ namespace MuonCombined {
     return newtrack;
   }
 
-  bool MuonCreatorTool::dressMuon(  xAOD::Muon& muon  ) const {
+  bool MuonCreatorTool::dressMuon(  xAOD::Muon& muon, const xAOD::MuonSegmentContainer* segments  ) const {
 
     if( muon.primaryTrackParticleLink().isValid() ){
       const xAOD::TrackParticle* primary = muon.primaryTrackParticle();
@@ -1370,7 +1367,7 @@ namespace MuonCombined {
     if( m_fillTimingInformationOnMuon  ) addRpcTiming(muon);
     
     if( !m_trackSegmentAssociationTool.empty() && muon.author()!=xAOD::Muon::MuTagIMO && muon.author()!=xAOD::Muon::MuGirl && 
-	(muon.author()!=xAOD::Muon::MuGirlLowBeta || m_segLowBeta)) addSegmentsOnTrack(muon);
+	(muon.author()!=xAOD::Muon::MuGirlLowBeta || m_segLowBeta)) addSegmentsOnTrack(muon,segments);
 
     addMSIDScatteringAngles(muon);
     if(muon.combinedTrackParticleLink().isValid()) addMSIDScatteringAngles(**(muon.combinedTrackParticleLink()));
@@ -1483,10 +1480,10 @@ namespace MuonCombined {
     tp.auxdecor< std::vector<float> >("rpcHitTime")              = rpcHitTime;
   }
   
-  void MuonCreatorTool::addSegmentsOnTrack( xAOD::Muon& muon ) const {
+  void MuonCreatorTool::addSegmentsOnTrack( xAOD::Muon& muon, const xAOD::MuonSegmentContainer* segments ) const {
     
     std::vector< ElementLink<xAOD::MuonSegmentContainer> > associatedSegments;
-    if( !m_trackSegmentAssociationTool->associatedSegments(muon,associatedSegments) ){
+    if( !m_trackSegmentAssociationTool->associatedSegments(muon,segments,associatedSegments) ){
       ATH_MSG_DEBUG("Failed to find associated segments ");
     }
     muon.setMuonSegmentLinks(associatedSegments) ;
diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.h b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.h
index 3762e97b4f21..3604b6465ce9 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.h
+++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCreatorTool.h
@@ -122,7 +122,7 @@ namespace MuonCombined {
     Trk::Track* createDummyTrack( std::vector<const Muon::MuonSegment*> segments, const Trk::Track& indetTrack ) const;
     void setMuonHitCounts( xAOD::Muon& muon ) const;
 
-    bool dressMuon(  xAOD::Muon& muon ) const;
+    bool dressMuon(  xAOD::Muon& muon, const xAOD::MuonSegmentContainer* segments ) const;
 
     void addEnergyLossToMuon( xAOD::Muon& muon ) const;
 
@@ -142,7 +142,7 @@ namespace MuonCombined {
     void addRpcTiming( xAOD::Muon& muon ) const;
     void addMSIDScatteringAngles(xAOD::Muon& muon) const;
     void addMSIDScatteringAngles(const xAOD::TrackParticle& track) const;
-    void addSegmentsOnTrack( xAOD::Muon& muon ) const;
+    void addSegmentsOnTrack( xAOD::Muon& muon, const xAOD::MuonSegmentContainer* segments ) const;
     void addAlignmentEffectsOnTrack( xAOD::TrackParticleContainer* trkCont ) const;
 
     ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/TrackSegmentAssociationTool.cxx b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/TrackSegmentAssociationTool.cxx
index b7caac4d9d7e..86e93d52fc12 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/TrackSegmentAssociationTool.cxx
+++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/TrackSegmentAssociationTool.cxx
@@ -20,40 +20,22 @@ namespace Muon {
   StatusCode TrackSegmentAssociationTool::initialize() {
     ATH_CHECK(m_edmHelperSvc.retrieve());
     ATH_CHECK(m_printer.retrieve());
-    ATH_CHECK(m_segments.initialize());
     return StatusCode::SUCCESS;
   }
 
-  const xAOD::MuonSegmentContainer* TrackSegmentAssociationTool::retrieveSegments( std::string location ) const {
-    
-    if( !evtStore()->contains<xAOD::MuonSegmentContainer>(location) ) {
-      ATH_MSG_DEBUG( "No segments in StoreGate at " << location );
-      return 0;
-    }
-    const xAOD::MuonSegmentContainer* segments = 0;
-    if( evtStore()->retrieve(segments, location).isFailure() || !segments ) {
-      ATH_MSG_DEBUG( "Unable to retrieve segments at " << location );
-      return 0;
-    }
-    ATH_MSG_VERBOSE("Got segments " << segments->size() << " at " << location);
-    return segments;
-  }
-  
   /** Returns a list of segments that match with the input Muon. */
-  bool TrackSegmentAssociationTool::associatedSegments(const xAOD::Muon& muon, 
+  bool TrackSegmentAssociationTool::associatedSegments(const xAOD::Muon& muon,
+						       const xAOD::MuonSegmentContainer* segments,
                                                        std::vector< ElementLink<xAOD::MuonSegmentContainer> >& associatedSegments ) const {
 
-    // get segments 
-    SG::ReadHandle<xAOD::MuonSegmentContainer> segments(m_segments);
-    if(!segments.isPresent()){
-      ATH_MSG_DEBUG(m_segments.key()<<" not present");
+    if(!segments){
+      ATH_MSG_DEBUG("no segment container passed, returning");
       return false;
     }
-    if(!segments.isValid()){
-      ATH_MSG_WARNING(m_segments.key()<<" not valid");
+    if(segments->empty()){
+      ATH_MSG_DEBUG("no segments in container, returning");
       return false;
     }
-
     // only fill if the primary track particle is not equal to the ID track particle and 
     // it has an associated track with track states 
     const xAOD::TrackParticle* tp = muon.primaryTrackParticle();        
diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/TrackSegmentAssociationTool.h b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/TrackSegmentAssociationTool.h
index 68879dc3ec63..dde71d45407a 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/TrackSegmentAssociationTool.h
+++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/TrackSegmentAssociationTool.h
@@ -38,21 +38,18 @@ namespace Muon{
 
     /** Returns a list of segments that match with the input Muon. */
     bool associatedSegments(const xAOD::Muon& muon, 
+			    const xAOD::MuonSegmentContainer* segments,
                             std::vector< ElementLink<xAOD::MuonSegmentContainer> >& associatedSegments ) const;
 
     /** @brief access to tool interface */
     static const InterfaceID& interfaceID() { return IID_TrackSegmentAssociationTool; }
   private:
 
-    const xAOD::MuonSegmentContainer* retrieveSegments( std::string location ) const;
-
     ServiceHandle<Muon::IMuonEDMHelperSvc>  m_edmHelperSvc {this, "edmHelper", 
       "Muon::MuonEDMHelperSvc/MuonEDMHelperSvc", 
       "Handle to the service providing the IMuonEDMHelperSvc interface" };
     ToolHandle<Muon::MuonEDMPrinterTool> m_printer{this,"MuonEDMPrinterTool","Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"};
 
-    SG::ReadHandleKey<xAOD::MuonSegmentContainer> m_segments{this,"MuonSegmentLocation","MuonSegments","muon segments"};
-
   };
 }
 
-- 
GitLab


From 63a2300420aebdb25f3e6ec59ea02bf5ee8d2abb Mon Sep 17 00:00:00 2001
From: Will Leight <wleight@cern.ch>
Date: Sun, 17 Jan 2021 18:58:26 +0100
Subject: [PATCH 2/4] Since the MuonSegmentTagAlg needs the
 xAOD::MuonSegmentContainer to be present, the MuonSegmentCnvAlg needs to be
 in the configuration. However, the names are changed so the MuonSegmentCnvAlg
 container is the intermediate one and the MuonCreatorAlg is the final one.
 Segment conversion is removed from the MuonCreatorAlg, which just copies now.

---
 Event/xAOD/xAODMuonCnv/src/MuonSegmentCnvAlg.h  |  2 +-
 .../MuonRecExample/python/MuonStandalone.py     |  4 ++++
 .../MuonCombinedAlgs/CMakeLists.txt             |  2 +-
 .../MuonCombinedAlgs/src/MuonCreatorAlg.cxx     | 17 +++++++----------
 .../MuonCombinedAlgs/src/MuonCreatorAlg.h       |  3 +--
 .../MuonCombinedAlgs/src/MuonSegmentTagAlg.h    |  2 +-
 6 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/Event/xAOD/xAODMuonCnv/src/MuonSegmentCnvAlg.h b/Event/xAOD/xAODMuonCnv/src/MuonSegmentCnvAlg.h
index 08f850428c44..87866806dd79 100644
--- a/Event/xAOD/xAODMuonCnv/src/MuonSegmentCnvAlg.h
+++ b/Event/xAOD/xAODMuonCnv/src/MuonSegmentCnvAlg.h
@@ -37,7 +37,7 @@ namespace xAODMaker {
    private:
      // the following segments do NOT contain MuGirl segments
      SG::ReadHandleKey<Trk::SegmentCollection> m_muonSegmentLocation{this,"SegmentContainerName","TrackMuonSegments"};
-     SG::WriteHandleKey<xAOD::MuonSegmentContainer> m_xaodContainerName{this,"xAODContainerName","MuonSegments"};
+     SG::WriteHandleKey<xAOD::MuonSegmentContainer> m_xaodContainerName{this,"xAODContainerName","xaodMuonSegments"};
 
      ToolHandle<xAODMaker::IMuonSegmentConverterTool> m_muonSegmentConverterTool{this,"MuonSegmentConverterTool","Muon::MuonSegmentConverterTool/MuonSegmentConverterTool"};
    }; // class MuonSegmentCnvAlg
diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonStandalone.py b/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonStandalone.py
index 5783027ecf51..e577913d2cb1 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonStandalone.py
+++ b/MuonSpectrometer/MuonReconstruction/MuonRecExample/python/MuonStandalone.py
@@ -193,6 +193,10 @@ class MuonStandalone(ConfiguredMuonRec):
             if (not cfgKeyStore.isInInput ('xAOD::MuonSegmentContainer', 'MuonSegments_NCB')):
                 self.addAlg( CfgMgr.xAODMaker__MuonSegmentCnvAlg("MuonSegmentCnvAlg_NCB",SegmentContainerName="NCB_TrackMuonSegments",xAODContainerName="NCB_MuonSegments") )
 
+        if (not cfgKeyStore.isInInput ('xAOD::MuonSegmentContainer', 'MuonSegments')):
+            self.addAlg( CfgMgr.xAODMaker__MuonSegmentCnvAlg("MuonSegmentCnvAlg") )
+
+
         if muonStandaloneFlags.doSegmentsOnly():
             return	                    
         # Tracks builder
diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt b/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt
index 5b3435ce5d0d..38cdd9f98f66 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt
@@ -7,6 +7,6 @@ atlas_subdir( MuonCombinedAlgs )
 atlas_add_component( MuonCombinedAlgs
                      src/*.cxx
                      src/components/*.cxx
-                     LINK_LIBRARIES AthenaBaseComps AthenaMonitoringKernelLib xAODCaloEvent xAODMuon xAODMuonCnvLib xAODTruth xAODTracking GaudiKernel MuonSegment MuonRecToolInterfaces MuonLayerEvent MuonCombinedEvent MuonCombinedToolInterfaces MuonPrepRawData StoreGateLib TrkSegment TrkTrack TrkToolInterfaces)
+                     LINK_LIBRARIES AthenaBaseComps AthenaMonitoringKernelLib xAODCaloEvent xAODMuon xAODTruth xAODTracking GaudiKernel MuonSegment MuonRecToolInterfaces MuonLayerEvent MuonCombinedEvent MuonCombinedToolInterfaces MuonPrepRawData StoreGateLib TrkSegment TrkTrack TrkToolInterfaces)
 
 atlas_install_python_modules( python/MuonCombinedAlgsMonitoring.py POST_BUILD_CMD ${ATLAS_FLAKE8} )
diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
index 571cdf0d9d21..339e495fa273 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
@@ -32,7 +32,6 @@ StatusCode MuonCreatorAlg::initialize()
 {
 
   ATH_CHECK(m_muonCreatorTool.retrieve());
-  ATH_CHECK(m_muonSegmentConverterTool.retrieve());
   ATH_CHECK(m_muonCollectionName.initialize());
   ATH_CHECK(m_slowMuonCollectionName.initialize(m_buildSlowMuon));
   ATH_CHECK(m_indetCandidateCollectionName.initialize(!m_doSA));
@@ -40,6 +39,7 @@ StatusCode MuonCreatorAlg::initialize()
   //Can't use a flag in intialize for an array of keys
   if(!m_doSA) ATH_CHECK(m_tagMaps.initialize());
   ATH_CHECK(m_inputSegContainerName.initialize());
+  ATH_CHECK(m_inputxAODSegContainerName.initialize());
   ATH_CHECK(m_segContainerName.initialize());
   ATH_CHECK(m_segTrkContainerName.initialize());
   m_combinedTrkCollectionName = m_combinedCollectionName.key()+"Tracks";
@@ -132,7 +132,7 @@ StatusCode MuonCreatorAlg::execute()
   SG::WriteHandle<Trk::SegmentCollection> wh_segmentTrk(m_segTrkContainerName);
   ATH_CHECK(wh_segmentTrk.record(std::make_unique<Trk::SegmentCollection>()));
   output.muonSegmentCollection=wh_segmentTrk.ptr();
-  //now copy the input segments to the final container
+  //now copy the input segments to the final containers
   SG::ReadHandle<Trk::SegmentCollection> inputSegs(m_inputSegContainerName);
   if(inputSegs.isValid()){
     for( auto it = inputSegs->begin();it!=inputSegs->end();++it ){
@@ -141,14 +141,11 @@ StatusCode MuonCreatorAlg::execute()
       if(muonSegment) wh_segmentTrk->push_back(new Muon::MuonSegment(*muonSegment));
     }
   }
-  //now convert
-  unsigned int index = 0;
-  for( auto it = wh_segmentTrk->begin();it!=wh_segmentTrk->end();++it,++index){
-    //have to cast because the collection stores Trk::Segments
-    const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(&(**it));
-    if( !muonSegment ) continue;
-    ElementLink< Trk::SegmentCollection > link(*wh_segmentTrk,index);
-    m_muonSegmentConverterTool->convert(link,wh_segment.ptr());
+  SG::ReadHandle<xAOD::MuonSegmentContainer> inputxAODSegs(m_inputxAODSegContainerName);
+  if(inputxAODSegs.isValid()){
+    for( auto it = inputxAODSegs->begin();it!=inputxAODSegs->end();++it ){
+      wh_segment->push_back(new xAOD::MuonSegment(**it));
+    }
   }
 
   // calo clusters
diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
index 6d8de3b8552e..fc9c8053c296 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
@@ -17,7 +17,6 @@
 #include "MuonCombinedEvent/InDetCandidateToTagMap.h"
 
 #include "MuonCombinedToolInterfaces/IMuonCreatorTool.h"
-#include "xAODMuonCnv/IMuonSegmentConverterTool.h"
 
 #include "xAODMuon/MuonContainer.h"
 #include "xAODMuon/SlowMuonContainer.h"
@@ -42,7 +41,6 @@ class MuonCreatorAlg : public AthAlgorithm
 
  private:
   ToolHandle<MuonCombined::IMuonCreatorTool> m_muonCreatorTool{this,"MuonCreatorTool","MuonCombined::MuonCreatorTool/MuonCreatorTool","Muon creator tool"};
-  ToolHandle<xAODMaker::IMuonSegmentConverterTool> m_muonSegmentConverterTool {this, "MuonSegmentConverterTool", "Muon::MuonSegmentConverterTool/MuonSegmentConverterTool"};
   SG::WriteHandleKey<xAOD::MuonContainer> m_muonCollectionName{this,"MuonContainerLocation", "Muons", "Muon Container"};
   SG::WriteHandleKey<xAOD::SlowMuonContainer> m_slowMuonCollectionName{this, "SlowMuonContainerLocation", "SlowMuons", "Slow Muon Container"};
   SG::WriteHandleKey<xAOD::TrackParticleContainer> m_combinedCollectionName{this, "CombinedLocation", "CombinedMuon", "Combined muons"};
@@ -55,6 +53,7 @@ class MuonCreatorAlg : public AthAlgorithm
   SG::ReadHandleKey<MuonCandidateCollection> m_muonCandidateCollectionName{this,"MuonCandidateLocation","MuonCandidates","Muon candidates"};
   SG::ReadHandleKeyArray<MuonCombined::InDetCandidateToTagMap> m_tagMaps{this,"TagMaps",{"muidcoTagMap","stacoTagMap","muGirlTagMap","caloTagMap","segmentTagMap"},"ID candidate to tag maps"};
   SG::ReadHandleKey<Trk::SegmentCollection> m_inputSegContainerName{this,"InputSegmentContainerName","TrackMuonSegments","Input track segments"};
+  SG::ReadHandleKey<xAOD::MuonSegmentContainer> m_inputxAODSegContainerName{this, "InputxAODSegmentContainerName", "xaodMuonSegments", "Segments"};
   SG::WriteHandleKey<xAOD::MuonSegmentContainer> m_segContainerName{this, "SegmentContainerName", "MuonSegments", "Segments"};
   SG::WriteHandleKey<Trk::SegmentCollection> m_segTrkContainerName{this,"TrackSegmentContainerName","TrkMuonSegments","Track segments"};
 
diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonSegmentTagAlg.h b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonSegmentTagAlg.h
index d3d04242b880..bf2033545b70 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonSegmentTagAlg.h
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonSegmentTagAlg.h
@@ -29,7 +29,7 @@ class MuonSegmentTagAlg : public AthAlgorithm
  private:
   ToolHandle<MuonCombined::IMuonSegmentTagTool> m_muonSegmentTagTool{this,"MuonSegmentTagTool","MuonCombined::MuonSegmentTagTool/MuonSegmentTagTool","Muon segment tag tool"};
   SG::ReadHandleKey<InDetCandidateCollection> m_indetCandidateCollectionName{this,"InDetCandidateLocation","InDetCandidates","name of ID candidate collection"};
-  SG::ReadHandleKey<xAOD::MuonSegmentContainer> m_muonSegmentCollectionName{this,"MuonSegmentLocation","MuonSegments","name of muon segment container"};
+  SG::ReadHandleKey<xAOD::MuonSegmentContainer> m_muonSegmentCollectionName{this,"MuonSegmentLocation","xaodMuonSegments","name of muon segment container"};
   SG::WriteHandleKey<MuonCombined::InDetCandidateToTagMap> m_tagMap{this,"TagMap","segmentTagMap","tag map"};
 };
 
-- 
GitLab


From 4941be77aec32fc0e09e85ffc188342cbb5cdc12 Mon Sep 17 00:00:00 2001
From: Will Leight <wleight@cern.ch>
Date: Mon, 18 Jan 2021 00:37:33 +0100
Subject: [PATCH 3/4] Fix LRT segment-tagged muon configuration, and add
 conversion back to the MuonCreatorAlg to ensure that the links are set
 correctly.

---
 .../MuonCombinedAlgs/CMakeLists.txt              |  2 +-
 .../MuonCombinedAlgs/src/MuonCreatorAlg.cxx      | 16 ++++++++++------
 .../MuonCombinedAlgs/src/MuonCreatorAlg.h        |  3 ++-
 .../python/MuonCombinedAlgs.py                   |  2 +-
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt b/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt
index 38cdd9f98f66..5b3435ce5d0d 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/CMakeLists.txt
@@ -7,6 +7,6 @@ atlas_subdir( MuonCombinedAlgs )
 atlas_add_component( MuonCombinedAlgs
                      src/*.cxx
                      src/components/*.cxx
-                     LINK_LIBRARIES AthenaBaseComps AthenaMonitoringKernelLib xAODCaloEvent xAODMuon xAODTruth xAODTracking GaudiKernel MuonSegment MuonRecToolInterfaces MuonLayerEvent MuonCombinedEvent MuonCombinedToolInterfaces MuonPrepRawData StoreGateLib TrkSegment TrkTrack TrkToolInterfaces)
+                     LINK_LIBRARIES AthenaBaseComps AthenaMonitoringKernelLib xAODCaloEvent xAODMuon xAODMuonCnvLib xAODTruth xAODTracking GaudiKernel MuonSegment MuonRecToolInterfaces MuonLayerEvent MuonCombinedEvent MuonCombinedToolInterfaces MuonPrepRawData StoreGateLib TrkSegment TrkTrack TrkToolInterfaces)
 
 atlas_install_python_modules( python/MuonCombinedAlgsMonitoring.py POST_BUILD_CMD ${ATLAS_FLAKE8} )
diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
index 339e495fa273..56b729c3e919 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
@@ -32,6 +32,7 @@ StatusCode MuonCreatorAlg::initialize()
 {
 
   ATH_CHECK(m_muonCreatorTool.retrieve());
+  ATH_CHECK(m_muonSegmentConverterTool.retrieve());
   ATH_CHECK(m_muonCollectionName.initialize());
   ATH_CHECK(m_slowMuonCollectionName.initialize(m_buildSlowMuon));
   ATH_CHECK(m_indetCandidateCollectionName.initialize(!m_doSA));
@@ -39,7 +40,6 @@ StatusCode MuonCreatorAlg::initialize()
   //Can't use a flag in intialize for an array of keys
   if(!m_doSA) ATH_CHECK(m_tagMaps.initialize());
   ATH_CHECK(m_inputSegContainerName.initialize());
-  ATH_CHECK(m_inputxAODSegContainerName.initialize());
   ATH_CHECK(m_segContainerName.initialize());
   ATH_CHECK(m_segTrkContainerName.initialize());
   m_combinedTrkCollectionName = m_combinedCollectionName.key()+"Tracks";
@@ -141,13 +141,17 @@ StatusCode MuonCreatorAlg::execute()
       if(muonSegment) wh_segmentTrk->push_back(new Muon::MuonSegment(*muonSegment));
     }
   }
-  SG::ReadHandle<xAOD::MuonSegmentContainer> inputxAODSegs(m_inputxAODSegContainerName);
-  if(inputxAODSegs.isValid()){
-    for( auto it = inputxAODSegs->begin();it!=inputxAODSegs->end();++it ){
-      wh_segment->push_back(new xAOD::MuonSegment(**it));
-    }
+  //now convert
+  unsigned int index = 0;
+  for( auto it = wh_segmentTrk->begin();it!=wh_segmentTrk->end();++it,++index){
+    //have to cast because the collection stores Trk::Segments
+    const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(&(**it));
+    if( !muonSegment ) continue;
+    ElementLink< Trk::SegmentCollection > link(*wh_segmentTrk,index);
+    m_muonSegmentConverterTool->convert(link,wh_segment.ptr());
   }
 
+
   // calo clusters
   SG::WriteHandle<xAOD::CaloClusterContainer> wh_clusters;
   SG::WriteHandle<CaloClusterCellLinkContainer> wh_clusterslink;
diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
index fc9c8053c296..6d8de3b8552e 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
@@ -17,6 +17,7 @@
 #include "MuonCombinedEvent/InDetCandidateToTagMap.h"
 
 #include "MuonCombinedToolInterfaces/IMuonCreatorTool.h"
+#include "xAODMuonCnv/IMuonSegmentConverterTool.h"
 
 #include "xAODMuon/MuonContainer.h"
 #include "xAODMuon/SlowMuonContainer.h"
@@ -41,6 +42,7 @@ class MuonCreatorAlg : public AthAlgorithm
 
  private:
   ToolHandle<MuonCombined::IMuonCreatorTool> m_muonCreatorTool{this,"MuonCreatorTool","MuonCombined::MuonCreatorTool/MuonCreatorTool","Muon creator tool"};
+  ToolHandle<xAODMaker::IMuonSegmentConverterTool> m_muonSegmentConverterTool {this, "MuonSegmentConverterTool", "Muon::MuonSegmentConverterTool/MuonSegmentConverterTool"};
   SG::WriteHandleKey<xAOD::MuonContainer> m_muonCollectionName{this,"MuonContainerLocation", "Muons", "Muon Container"};
   SG::WriteHandleKey<xAOD::SlowMuonContainer> m_slowMuonCollectionName{this, "SlowMuonContainerLocation", "SlowMuons", "Slow Muon Container"};
   SG::WriteHandleKey<xAOD::TrackParticleContainer> m_combinedCollectionName{this, "CombinedLocation", "CombinedMuon", "Combined muons"};
@@ -53,7 +55,6 @@ class MuonCreatorAlg : public AthAlgorithm
   SG::ReadHandleKey<MuonCandidateCollection> m_muonCandidateCollectionName{this,"MuonCandidateLocation","MuonCandidates","Muon candidates"};
   SG::ReadHandleKeyArray<MuonCombined::InDetCandidateToTagMap> m_tagMaps{this,"TagMaps",{"muidcoTagMap","stacoTagMap","muGirlTagMap","caloTagMap","segmentTagMap"},"ID candidate to tag maps"};
   SG::ReadHandleKey<Trk::SegmentCollection> m_inputSegContainerName{this,"InputSegmentContainerName","TrackMuonSegments","Input track segments"};
-  SG::ReadHandleKey<xAOD::MuonSegmentContainer> m_inputxAODSegContainerName{this, "InputxAODSegmentContainerName", "xaodMuonSegments", "Segments"};
   SG::WriteHandleKey<xAOD::MuonSegmentContainer> m_segContainerName{this, "SegmentContainerName", "MuonSegments", "Segments"};
   SG::WriteHandleKey<Trk::SegmentCollection> m_segTrkContainerName{this,"TrackSegmentContainerName","TrkMuonSegments","Track segments"};
 
diff --git a/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuonCombinedAlgs.py b/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuonCombinedAlgs.py
index 2d333ff62101..47e5eed6fd55 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuonCombinedAlgs.py
+++ b/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuonCombinedAlgs.py
@@ -46,7 +46,7 @@ def MuonSegmentTagAlg_LRT( name="MuonSegmentTagAlg_LRT", **kwargs ):
     kwargs.setdefault("MuonSegmentTagTool", getPublicTool("MuonSegmentTagTool") )
     kwargs.setdefault("InDetCandidateLocation", MuonCbKeys.InDetTrackParticlesLargeD0())
     kwargs.setdefault("TagMap","segmentTagMap_LRT")
-    kwargs.setdefault("MuonSegmentLocation","MuonSegments")
+    kwargs.setdefault("MuonSegmentLocation","xaodMuonSegments")
     return CfgMgr.MuonSegmentTagAlg(name,**kwargs)
 
 def MuonInsideOutRecoAlg( name="MuonInsideOutRecoAlg", **kwargs ):
-- 
GitLab


From 4df1e9e523b7c9b1748b710204719cff4692322b Mon Sep 17 00:00:00 2001
From: Will Leight <wleight@cern.ch>
Date: Mon, 18 Jan 2021 19:10:44 +0100
Subject: [PATCH 4/4] Don't copy segments for trigger or stau running.

---
 .../MuonCombinedAlgs/src/MuonCreatorAlg.cxx   | 37 +++++++++++--------
 .../MuonCombinedAlgs/src/MuonCreatorAlg.h     |  1 +
 .../MuonCombinedReconstructionConfig.py       |  2 +-
 .../python/MuonCombinedAlgs.py                |  4 +-
 4 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
index 56b729c3e919..f3214ffaed6e 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.cxx
@@ -32,14 +32,17 @@ StatusCode MuonCreatorAlg::initialize()
 {
 
   ATH_CHECK(m_muonCreatorTool.retrieve());
-  ATH_CHECK(m_muonSegmentConverterTool.retrieve());
+  m_copySegs=true; //to have MuGirl and MuidCo segments in the same final collection/container; not needed for trigger or stau
+  if(m_buildSlowMuon || name().find("Trig")!=std::string::npos) m_copySegs=false;
+  if(m_copySegs) ATH_CHECK(m_muonSegmentConverterTool.retrieve());
+  else m_muonSegmentConverterTool.disable();
   ATH_CHECK(m_muonCollectionName.initialize());
   ATH_CHECK(m_slowMuonCollectionName.initialize(m_buildSlowMuon));
   ATH_CHECK(m_indetCandidateCollectionName.initialize(!m_doSA));
   ATH_CHECK(m_muonCandidateCollectionName.initialize(!m_buildSlowMuon));
   //Can't use a flag in intialize for an array of keys
   if(!m_doSA) ATH_CHECK(m_tagMaps.initialize());
-  ATH_CHECK(m_inputSegContainerName.initialize());
+  ATH_CHECK(m_inputSegContainerName.initialize(m_copySegs));
   ATH_CHECK(m_segContainerName.initialize());
   ATH_CHECK(m_segTrkContainerName.initialize());
   m_combinedTrkCollectionName = m_combinedCollectionName.key()+"Tracks";
@@ -132,24 +135,26 @@ StatusCode MuonCreatorAlg::execute()
   SG::WriteHandle<Trk::SegmentCollection> wh_segmentTrk(m_segTrkContainerName);
   ATH_CHECK(wh_segmentTrk.record(std::make_unique<Trk::SegmentCollection>()));
   output.muonSegmentCollection=wh_segmentTrk.ptr();
-  //now copy the input segments to the final containers
-  SG::ReadHandle<Trk::SegmentCollection> inputSegs(m_inputSegContainerName);
-  if(inputSegs.isValid()){
-    for( auto it = inputSegs->begin();it!=inputSegs->end();++it ){
+  if(m_copySegs){
+    //now copy the input segments to the final container
+    SG::ReadHandle<Trk::SegmentCollection> inputSegs(m_inputSegContainerName);
+    if(inputSegs.isValid()){
+      for( auto it = inputSegs->begin();it!=inputSegs->end();++it ){
+	//have to cast because the collection stores Trk::Segments
+	const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(&(**it));
+	if(muonSegment) wh_segmentTrk->push_back(new Muon::MuonSegment(*muonSegment));
+      }
+    }
+    //now convert
+    unsigned int index = 0;
+    for( auto it = wh_segmentTrk->begin();it!=wh_segmentTrk->end();++it,++index){
       //have to cast because the collection stores Trk::Segments
       const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(&(**it));
-      if(muonSegment) wh_segmentTrk->push_back(new Muon::MuonSegment(*muonSegment));
+      if( !muonSegment ) continue;
+      ElementLink< Trk::SegmentCollection > link(*wh_segmentTrk,index);
+      m_muonSegmentConverterTool->convert(link,wh_segment.ptr());
     }
   }
-  //now convert
-  unsigned int index = 0;
-  for( auto it = wh_segmentTrk->begin();it!=wh_segmentTrk->end();++it,++index){
-    //have to cast because the collection stores Trk::Segments
-    const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(&(**it));
-    if( !muonSegment ) continue;
-    ElementLink< Trk::SegmentCollection > link(*wh_segmentTrk,index);
-    m_muonSegmentConverterTool->convert(link,wh_segment.ptr());
-  }
 
 
   // calo clusters
diff --git a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
index 6d8de3b8552e..435ed11dc521 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
+++ b/Reconstruction/MuonIdentification/MuonCombinedAlgs/src/MuonCreatorAlg.h
@@ -64,6 +64,7 @@ class MuonCreatorAlg : public AthAlgorithm
   Gaudi::Property<bool> m_buildSlowMuon{this, "BuildSlowMuon", false};
   Gaudi::Property<bool> m_doSA{this, "CreateSAmuons", false};
   Gaudi::Property<bool> m_makeClusters{this, "MakeClusters", true};
+  bool m_copySegs;
 
   // Monitoring tool
   ToolHandle< GenericMonitoringTool > m_monTool { this, "MonTool", "", "Monitoring tool" };
diff --git a/Reconstruction/MuonIdentification/MuonCombinedConfig/python/MuonCombinedReconstructionConfig.py b/Reconstruction/MuonIdentification/MuonCombinedConfig/python/MuonCombinedReconstructionConfig.py
index eee23de4e0d0..34fee00f4d16 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedConfig/python/MuonCombinedReconstructionConfig.py
+++ b/Reconstruction/MuonIdentification/MuonCombinedConfig/python/MuonCombinedReconstructionConfig.py
@@ -255,7 +255,7 @@ def StauCreatorAlgCfg(flags, name="StauCreatorAlg", **kwargs ):
     kwargs.setdefault("ExtrapolatedLocation","ExtrapolatedStau")
     kwargs.setdefault("MSOnlyExtrapolatedLocation","MSOnlyExtrapolatedStau")
     kwargs.setdefault("MuonCandidateLocation","")
-    kwargs.setdefault("SegmentContainerName","xaodStauSegments")
+    kwargs.setdefault("SegmentContainerName","StauSegments")
     kwargs.setdefault("TrackSegmentContainerName","TrkStauSegments")
     kwargs.setdefault("BuildSlowMuon",1)
     kwargs.setdefault("ClusterContainerName", "SlowMuonClusterCollection")
diff --git a/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuonCombinedAlgs.py b/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuonCombinedAlgs.py
index 47e5eed6fd55..1b4a78bccf77 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuonCombinedAlgs.py
+++ b/Reconstruction/MuonIdentification/MuonCombinedRecExample/python/MuonCombinedAlgs.py
@@ -183,7 +183,7 @@ def MuonCreatorAlg_LRT( name="MuonCreatorAlg_LRT",**kwargs ):
     kwargs.setdefault("ExtrapolatedLocation", "ExtraPolated"+MuonCbKeys.FinalMuonsLargeD0())
     kwargs.setdefault("MSOnlyExtrapolatedLocation", "MSOnlyExtraPolated"+MuonCbKeys.FinalMuonsLargeD0())
     kwargs.setdefault("CombinedLocation", "Combined"+MuonCbKeys.FinalMuonsLargeD0())
-    kwargs.setdefault("SegmentContainerName", "xaodMuonSegments_LRT")
+    kwargs.setdefault("SegmentContainerName", "MuonSegments_LRT")
     kwargs.setdefault("TrackSegmentContainerName", "TrkMuonSegments_LRT")
     kwargs.setdefault("BuildSlowMuon", False)
     kwargs.setdefault("MakeClusters", False)
@@ -197,7 +197,7 @@ def StauCreatorAlg( name="StauCreatorAlg", **kwargs ):
     kwargs.setdefault("ExtrapolatedLocation","ExtrapolatedStau")
     kwargs.setdefault("MSOnlyExtrapolatedLocation","MSOnlyExtrapolatedStau")
     kwargs.setdefault("MuonCandidateLocation","")
-    kwargs.setdefault("SegmentContainerName","xaodStauSegments")
+    kwargs.setdefault("SegmentContainerName","StauSegments")
     kwargs.setdefault("TrackSegmentContainerName","TrkStauSegments")
     kwargs.setdefault("BuildSlowMuon",1)
     kwargs.setdefault("ClusterContainerName", "SlowMuonClusterCollection")
-- 
GitLab