From c380cd46129ee280aefb9263ac3c41ff9c491ed0 Mon Sep 17 00:00:00 2001
From: William Axel Leight <william.axel.leight@cern.ch>
Date: Mon, 20 Jul 2020 09:46:50 +0000
Subject: [PATCH] Reject poor quality EM-only tracks

EM segments that are not used in any other tracks are made into MS tracks: however, these tracks are often of quite poor quality, and cannot be extrapolated successfully.
If they cannot be extrapolated, they are essentially never used to form muons, and anyway MuGirl should catch any tracks that MuidCo misses because of this.
So we will now not make MuonCandidates from EM-only MS tracks that cannot be extrapolated.
This will also have the helpful side effect of greatly reducing the number of warnings generated, such as those in ATLASRECTS-4464 and ATLASRECTS-5426.
---
 .../src/MuonCandidateTool.cxx                 | 26 +++++++++++++++----
 .../src/MuonCandidateTool.h                   |  2 ++
 .../PROCTools/data/master_q221_AOD_digest.ref |  2 +-
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.cxx b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.cxx
index 2e36749dbaf..14f2b0e0d1a 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.cxx
+++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.cxx
@@ -10,6 +10,7 @@
 //  (c) ATLAS Combined Muon software
 //////////////////////////////////////////////////////////////////////////////
 
+#include "TrkTrackSummary/MuonTrackSummary.h"
 #include "MuonCandidateTool.h"
 
 namespace MuonCombined {
@@ -40,6 +41,7 @@ namespace MuonCombined {
     if( !m_trackExtrapolationTool.empty() ) ATH_CHECK(m_trackExtrapolationTool.retrieve());
     else m_trackExtrapolationTool.disable();
     ATH_CHECK(m_ambiguityProcessor.retrieve());
+    ATH_CHECK(m_idHelperSvc.retrieve());
     ATH_CHECK(m_beamSpotKey.initialize());
     return StatusCode::SUCCESS;
   }
@@ -89,11 +91,25 @@ namespace MuonCombined {
         else if( !standaloneTrack->perigeeParameters()->covariance() ) ATH_MSG_WARNING(" Track with perigee without covariance " << standaloneTrack);
 	trackLinks[ standaloneTrack ] = std::make_pair(trackLink,standaloneTrack);
       }else{
-	standaloneTrack=new Trk::Track(msTrack);
-	trackLinks[ standaloneTrack ] = std::make_pair(trackLink,nullptr);
-      }      
-      extrapTracks->push_back( standaloneTrack );
-      tracksToBeDeleted.insert( standaloneTrack ); // insert track for deletion
+	//We can create tracks from EM segments+TGC hits
+	//If these are not successfully extrapolated, they are too low quality to be useful
+	//So only make candidates from un-extrapolated tracks if they are not EM-only
+	bool skipTrack=true;
+	for(auto& chs : msTrack.trackSummary()->muonTrackSummary()->chamberHitSummary()){
+	  if(chs.isMdt() && m_idHelperSvc->stationIndex(chs.chamberId())!=Muon::MuonStationIndex::EM){
+	    skipTrack=false;
+	    break;
+	  }
+	}
+	if(!skipTrack){
+	  standaloneTrack=new Trk::Track(msTrack);
+	  trackLinks[ standaloneTrack ] = std::make_pair(trackLink,nullptr);
+	}
+      }
+      if(standaloneTrack){
+	extrapTracks->push_back( standaloneTrack );
+	tracksToBeDeleted.insert( standaloneTrack ); // insert track for deletion
+      }
     }
     ATH_MSG_DEBUG("Finished back-tracking, total number of successfull fits " << ntracks);
 
diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.h b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.h
index 29a84b2b5b4..5313474c3a7 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.h
+++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.h
@@ -16,6 +16,7 @@
 #include "MuidInterfaces/ICombinedMuonTrackBuilder.h"
 #include "MuonRecHelperTools/MuonEDMPrinterTool.h"
 #include "MuonRecToolInterfaces/IMuonTrackExtrapolationTool.h"
+#include "MuonIdHelpers/IMuonIdHelperSvc.h"
 
 namespace MuonCombined {
 
@@ -37,6 +38,7 @@ namespace MuonCombined {
     ToolHandle<Rec::ICombinedMuonTrackBuilder> m_trackBuilder;
     ToolHandle<Muon::IMuonTrackExtrapolationTool> m_trackExtrapolationTool;
     ToolHandle<Trk::ITrackAmbiguityProcessorTool> m_ambiguityProcessor;
+    ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
     SG::ReadCondHandleKey<InDet::BeamSpotData> m_beamSpotKey { this, "BeamSpotKey", "BeamSpotData", "SG key for beam spot" };
 
     unsigned int m_extrapolationStrategy;
diff --git a/Tools/PROCTools/data/master_q221_AOD_digest.ref b/Tools/PROCTools/data/master_q221_AOD_digest.ref
index 04311936100..4be2ccf40c7 100644
--- a/Tools/PROCTools/data/master_q221_AOD_digest.ref
+++ b/Tools/PROCTools/data/master_q221_AOD_digest.ref
@@ -9,7 +9,7 @@
       284500    87473063          62          76           5           2           6           2           4           6           4           2
       284500    87473068          26          35           1           1           0           0           0           0           0           0
       284500    87473075          72          84           6           0           5           0           5           5           4           1
-      284500    87473084          83          85           7           3          14           1          13          10           5           5
+      284500    87473084          83          85           7           2          14           1          13          10           5           5
       284500    87473091          43          49           3           0           2           1           1           5           2           3
       284500    87473096          72          75           3           2           2           0           2           3           2           1
       284500    87473104          61          63           6           0           6           1           5           5           4           1
-- 
GitLab