From ff80e3485f2933eaebfabe18cab7d2610055125a Mon Sep 17 00:00:00 2001
From: Will Leight <wleight@cern.ch>
Date: Tue, 5 Mar 2019 15:51:39 +0100
Subject: [PATCH 1/2] Require that ID tracks used by STACO muons can reach at
 least one calo layer

Only for STACO muons is this basic requirement not imposed: applying it will also fix the crash reported in ATLASRECTS-4871.
---
 .../src/MuonCombinedStacoTagTool.cxx                 | 12 ++++++++++--
 .../src/MuonCombinedStacoTagTool.h                   |  4 +++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.cxx b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.cxx
index 65b24990ca82..804ea1324d35 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.cxx
+++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 //////////////////////////////////////////////////////////////////////////////
@@ -28,12 +28,14 @@ namespace MuonCombined {
     :	AthAlgTool(type, name, parent),
 	m_printer("Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"),
 	m_tagTool("MuonCombined::MuonTrackTagTestTool/MuonTrackTagTestTool"),
-        m_extrapolator        ("Trk::Extrapolator/AtlasExtrapolator")
+        m_extrapolator("Trk::Extrapolator/AtlasExtrapolator"),
+	m_caloExtTool("Trk::ParticleCaloExtensionTool/ParticleCaloExtensionTool")
   {
     declareInterface<IMuonCombinedTagTool>(this);
     declareProperty("Printer",m_printer );
     declareProperty("TagTool",m_tagTool );
     declareProperty("Extrapolator",m_extrapolator );
+    declareProperty("ParticleCaloExtensionTool", m_caloExtTool);
   }
 
   MuonCombinedStacoTagTool::~MuonCombinedStacoTagTool()
@@ -47,6 +49,7 @@ namespace MuonCombined {
     ATH_CHECK(m_printer.retrieve());
     ATH_CHECK(m_tagTool.retrieve());
     ATH_CHECK(m_extrapolator.retrieve());
+    ATH_CHECK(m_caloExtTool.retrieve());
 
     return StatusCode::SUCCESS;
   }
@@ -78,6 +81,11 @@ namespace MuonCombined {
       // ensure that also the id has a perigee with covariance
       if( !idTP->indetTrackParticle().perigeeParameters().covariance() ) continue;
 
+      //ensure that id tp can be extrapolated to something
+      std::unique_ptr<Trk::CaloExtension> caloExtension = m_caloExtTool->caloExtension(idTP->indetTrackParticle());
+      if(!caloExtension) continue;
+      if(caloExtension->caloLayerIntersections().empty()) continue;
+
       const Trk::Perigee* idPer = &idTP->indetTrackParticle().perigeeParameters();
       const Trk::Perigee* msPer = muonCandidate.extrapolatedTrack()->perigeeParameters();
 
diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.h b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.h
index 0bc7e2be2bde..e718b4a7348a 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.h
+++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef MUONCOMBINEDBASETOOLS_MUONCOMBINEDSTACOTAGTOOL_H
@@ -14,6 +14,7 @@
 #include "TrkTrack/TrackCollection.h"
 #include "TrkParameters/TrackParameters.h"
 #include "TrkSegment/SegmentCollection.h"
+#include "RecoToolInterfaces/IParticleCaloExtensionTool.h"
 #include <vector>
 
 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
@@ -55,6 +56,7 @@ namespace MuonCombined {
     ToolHandle<Muon::MuonEDMPrinterTool>        m_printer;
     ToolHandle<MuonCombined::IMuonTrackTagTool> m_tagTool;
     ToolHandle<Trk::IExtrapolator>              m_extrapolator;
+    ToolHandle<Trk::IParticleCaloExtensionTool> m_caloExtTool;
 
   };
 
-- 
GitLab


From 2bd6ccd86f150b66237030a98cc211ca89c07eed Mon Sep 17 00:00:00 2001
From: Will Leight <wleight@cern.ch>
Date: Wed, 6 Mar 2019 13:07:42 +0100
Subject: [PATCH 2/2] Make tools private (except for the extrapolator)

---
 .../MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.cxx  | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.cxx b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.cxx
index 804ea1324d35..64c4acc58c8a 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.cxx
+++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCombinedStacoTagTool.cxx
@@ -26,10 +26,10 @@ namespace MuonCombined {
 
   MuonCombinedStacoTagTool::MuonCombinedStacoTagTool (const std::string& type, const std::string& name, const IInterface* parent)
     :	AthAlgTool(type, name, parent),
-	m_printer("Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"),
-	m_tagTool("MuonCombined::MuonTrackTagTestTool/MuonTrackTagTestTool"),
+	m_printer("Muon::MuonEDMPrinterTool/MuonEDMPrinterTool",this),
+	m_tagTool("MuonCombined::MuonTrackTagTestTool/MuonTrackTagTestTool",this),
         m_extrapolator("Trk::Extrapolator/AtlasExtrapolator"),
-	m_caloExtTool("Trk::ParticleCaloExtensionTool/ParticleCaloExtensionTool")
+	m_caloExtTool("Trk::ParticleCaloExtensionTool/ParticleCaloExtensionTool",this)
   {
     declareInterface<IMuonCombinedTagTool>(this);
     declareProperty("Printer",m_printer );
-- 
GitLab