From a0093fe76cc101df6f75d1a81624185e66e30885 Mon Sep 17 00:00:00 2001
From: Christos Anastopoulos <christos.anastopoulos@cern.ch>
Date: Thu, 19 Nov 2020 13:11:25 +0000
Subject: [PATCH] TrackSummary Tool, make Event context aware i.e add ability
 to pass EventContext from the caller and then propagate down the call chain

---
 .../src/EMBremCollectionBuilder.cxx           |   8 +-
 .../egammaAlgs/src/EMBremCollectionBuilder.h  |   4 +-
 .../TrkTools/TrkToolInterfaces/CMakeLists.txt |   4 +-
 .../IExtendedTrackSummaryTool.h               |  50 +++--
 .../IExtendedTrackSummaryTool.icc             |  56 +++++
 .../TrkToolInterfaces/ITrackSummaryTool.h     |  24 ++-
 .../TrkToolInterfaces/ITrackSummaryTool.icc   |  29 +++
 .../TrkTrackSummaryTool/TrackSummaryTool.h    |  73 ++++---
 .../TrkTrackSummaryTool/TrackSummaryTool.icc  |  26 +--
 .../src/TrackSummaryTool.cxx                  | 194 ++++++++++++------
 10 files changed, 336 insertions(+), 132 deletions(-)
 create mode 100644 Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/IExtendedTrackSummaryTool.icc
 create mode 100644 Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITrackSummaryTool.icc

diff --git a/Reconstruction/egamma/egammaAlgs/src/EMBremCollectionBuilder.cxx b/Reconstruction/egamma/egammaAlgs/src/EMBremCollectionBuilder.cxx
index bd9cc982d7d..5b86b901316 100644
--- a/Reconstruction/egamma/egammaAlgs/src/EMBremCollectionBuilder.cxx
+++ b/Reconstruction/egamma/egammaAlgs/src/EMBremCollectionBuilder.cxx
@@ -148,7 +148,7 @@ EMBremCollectionBuilder::execute(const EventContext& ctx) const
   /*
    * Fill the final collections
    */
-  ATH_CHECK(createCollections(refitted,failedfit,trtAloneTrkTracks,
+  ATH_CHECK(createCollections(ctx,refitted,failedfit,trtAloneTrkTracks,
                     cPtrTracks,cPtrTrkPart,trackTES.ptr()));
    /*
    * update counters
@@ -192,6 +192,7 @@ EMBremCollectionBuilder::refitTracks(
 
 StatusCode
 EMBremCollectionBuilder::createCollections(
+  const EventContext& ctx,
   std::vector<TrackWithIndex>& refitted,
   std::vector<TrackWithIndex>& failedfit,
   std::vector<TrackWithIndex>& trtAlone,
@@ -204,7 +205,7 @@ EMBremCollectionBuilder::createCollections(
    * so need to update the summary
    */
   for (auto& Info : refitted){
-    updateGSFTrack(Info, AllTracks);
+    updateGSFTrack(ctx,Info, AllTracks);
   }
 
   for (auto& Info : refitted){
@@ -305,12 +306,13 @@ EMBremCollectionBuilder::createNew(
 
 void
 EMBremCollectionBuilder::updateGSFTrack(
+  const EventContext& ctx,
   const TrackWithIndex& Info,
   const xAOD::TrackParticleContainer* AllTracks) const
 {
 
   //update the summary of the non-const track without hole search
-  m_summaryTool->updateTrackSummary(*(Info.track));
+  m_summaryTool->updateTrackSummary(ctx,*(Info.track));
   //Get the summary so as to add info to it
   Trk::TrackSummary* summary = Info.track->trackSummary();
 
diff --git a/Reconstruction/egamma/egammaAlgs/src/EMBremCollectionBuilder.h b/Reconstruction/egamma/egammaAlgs/src/EMBremCollectionBuilder.h
index 8c2bd549be0..a36e62ce0dc 100644
--- a/Reconstruction/egamma/egammaAlgs/src/EMBremCollectionBuilder.h
+++ b/Reconstruction/egamma/egammaAlgs/src/EMBremCollectionBuilder.h
@@ -67,6 +67,7 @@ private:
                          std::vector<TrackWithIndex>& failedfit) const;
 
   StatusCode createCollections(
+    const EventContext& ctx,
     std::vector<TrackWithIndex>& refitted,
     std::vector<TrackWithIndex>& failedfit,
     std::vector<TrackWithIndex>& trtAlone,
@@ -79,7 +80,8 @@ private:
                        xAOD::TrackParticleContainer* finalTrkPartContainer,
                        const xAOD::TrackParticleContainer* AllTracks) const;
 
-  void updateGSFTrack(const TrackWithIndex& Info,
+  void updateGSFTrack(const EventContext& ctx,
+                      const TrackWithIndex& Info,
                       const xAOD::TrackParticleContainer* AllTracks) const;
 
   /** @brief The track refitter */
diff --git a/Tracking/TrkTools/TrkToolInterfaces/CMakeLists.txt b/Tracking/TrkTools/TrkToolInterfaces/CMakeLists.txt
index c72223fa952..604c4c65083 100644
--- a/Tracking/TrkTools/TrkToolInterfaces/CMakeLists.txt
+++ b/Tracking/TrkTools/TrkToolInterfaces/CMakeLists.txt
@@ -8,5 +8,7 @@ atlas_subdir( TrkToolInterfaces )
 # Component(s) in the package:
 atlas_add_library( TrkToolInterfaces
                    PUBLIC_HEADERS TrkToolInterfaces
-                   LINK_LIBRARIES AthContainers AthLinks EventPrimitives xAODTracking xAODTruth GaudiKernel TrkSurfaces TrkCompetingRIOsOnTrack TrkEventPrimitives TrkEventUtils TrkMaterialOnTrack TrkParameters TrkParticleBase TrkSegment TrkTrack TrkTrackSummary TrkEventUtils CxxUtils )
+                   LINK_LIBRARIES AthContainers AthLinks EventPrimitives xAODTracking xAODTruth GaudiKernel 
+                   TrkSurfaces TrkCompetingRIOsOnTrack TrkEventPrimitives TrkEventUtils TrkMaterialOnTrack TrkParameters 
+                   TrkParticleBase TrkSegment TrkTrack TrkTrackSummary TrkEventUtils CxxUtils )
 
diff --git a/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/IExtendedTrackSummaryTool.h b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/IExtendedTrackSummaryTool.h
index 7e2510cc2df..e8929962950 100644
--- a/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/IExtendedTrackSummaryTool.h
+++ b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/IExtendedTrackSummaryTool.h
@@ -25,11 +25,11 @@ class IExtendedTrackSummaryTool : virtual public ITrackSummaryTool
 public:
   static const InterfaceID& interfaceID();
 
-  using  ITrackSummaryTool::summary;
-  using  ITrackSummaryTool::updateTrackSummary;
-  using  ITrackSummaryTool::summaryNoHoleSearch;
-  using  ITrackSummaryTool::updateSharedHitCount;
-  using  ITrackSummaryTool::updateAdditionalInfo;
+  using ITrackSummaryTool::summary;
+  using ITrackSummaryTool::summaryNoHoleSearch;
+  using ITrackSummaryTool::updateAdditionalInfo;
+  using ITrackSummaryTool::updateSharedHitCount;
+  using ITrackSummaryTool::updateTrackSummary;
 
   /** Compute track summary and replace the summary in given track.
    * @param track the track whose track summary is replaced with a newly
@@ -45,35 +45,55 @@ public:
    * search properties unless the suppress_hole_search argument is true.
    */
   virtual void computeAndReplaceTrackSummary(
+    const EventContext& ctx,
     Track& track,
     const Trk::PRDtoTrackMap* prd_to_track_map,
     bool suppress_hole_search = false) const = 0;
-  
-   /* Start from a copy of the existing input track summary if there,
-    * otherwise start from a new one. Fill it and return it.
-    * Does not modify the const track.
-    */
+
+  void computeAndReplaceTrackSummary(Track& track,
+                                     const Trk::PRDtoTrackMap* prd_to_track_map,
+                                     bool suppress_hole_search = false) const;
+
+  /* Start from a copy of the existing input track summary if there,
+   * otherwise start from a new one. Fill it and return it.
+   * Does not modify the const track.
+   */
   virtual std::unique_ptr<Trk::TrackSummary> summary(
+    const EventContext& ctx,
     const Track& track,
     const Trk::PRDtoTrackMap* prd_to_track_map) const = 0;
 
+  std::unique_ptr<Trk::TrackSummary> summary(
+    const Track& track,
+    const Trk::PRDtoTrackMap* prd_to_track_map) const;
+
   /** method which can be used to update the summary of a track.
    * If a summary is present is modified in place
    * otherwise a new one is created.
    */
-  virtual void updateTrackSummary(Track& track,
+  virtual void updateTrackSummary(const EventContext& ctx,
+                                  Track& track,
                                   const Trk::PRDtoTrackMap* prd_to_track_map,
                                   bool suppress_hole_search = false) const = 0;
 
+  void updateTrackSummary(Track& track,
+                          const Trk::PRDtoTrackMap* prd_to_track_map,
+                          bool suppress_hole_search = false) const;
+
   /* Start from a copy of the existing input track summary if there,
    * otherwise start from a new one. Fill it and return it.
    * but without doing the hole search.
    * Does not modify the const track.
    */
   virtual std::unique_ptr<Trk::TrackSummary> summaryNoHoleSearch(
+    const EventContext& ctx,
     const Track& track,
     const Trk::PRDtoTrackMap* prd_to_track_map) const = 0;
 
+  std::unique_ptr<Trk::TrackSummary> summaryNoHoleSearch(
+    const Track& track,
+    const Trk::PRDtoTrackMap* prd_to_track_map) const;
+
   /** Update the shared hit count of the given track summary.
    * @param track the track which corresponds to the given track summary and is
    * used to compute the numbers of shared hits.
@@ -112,12 +132,6 @@ public:
 
   virtual void updateAdditionalInfo(Track& track) const = 0;
 };
-
-inline const InterfaceID&
-Trk::IExtendedTrackSummaryTool::interfaceID()
-{
-  return IID_IExtendedTrackSummaryTool;
-}
-
 }
+#include "TrkToolInterfaces/IExtendedTrackSummaryTool.icc"
 #endif
diff --git a/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/IExtendedTrackSummaryTool.icc b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/IExtendedTrackSummaryTool.icc
new file mode 100644
index 00000000000..fa46575fc05
--- /dev/null
+++ b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/IExtendedTrackSummaryTool.icc
@@ -0,0 +1,56 @@
+/*
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+*/
+
+namespace Trk {
+
+inline const InterfaceID&
+IExtendedTrackSummaryTool::interfaceID()
+{
+  return IID_IExtendedTrackSummaryTool;
+}
+
+inline void
+IExtendedTrackSummaryTool::computeAndReplaceTrackSummary(
+  Track& track,
+  const Trk::PRDtoTrackMap* prd_to_track_map,
+  bool suppress_hole_search) const
+{
+  computeAndReplaceTrackSummary(Gaudi::Hive::currentContext(),
+                                track,
+                                prd_to_track_map,
+                                suppress_hole_search);
+}
+
+inline std::unique_ptr<Trk::TrackSummary>
+IExtendedTrackSummaryTool::summary(
+  const Track& track,
+  const Trk::PRDtoTrackMap* prd_to_track_map) const
+{
+  return summary(Gaudi::Hive::currentContext(), track, prd_to_track_map);
+}
+
+inline void
+IExtendedTrackSummaryTool::updateTrackSummary(
+  Track& track,
+  const Trk::PRDtoTrackMap* prd_to_track_map,
+  bool suppress_hole_search) const
+{
+
+  updateTrackSummary(Gaudi::Hive::currentContext(),
+                     track,
+                     prd_to_track_map,
+                     suppress_hole_search);
+}
+
+inline std::unique_ptr<Trk::TrackSummary>
+IExtendedTrackSummaryTool::summaryNoHoleSearch(
+  const Track& track,
+  const Trk::PRDtoTrackMap* prd_to_track_map) const
+{
+  return summaryNoHoleSearch(
+    Gaudi::Hive::currentContext(), track, prd_to_track_map);
+}
+
+}
+
diff --git a/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITrackSummaryTool.h b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITrackSummaryTool.h
index 102a1f8b1cd..02213cb25d6 100755
--- a/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITrackSummaryTool.h
+++ b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITrackSummaryTool.h
@@ -5,9 +5,10 @@
 #ifndef TRKITRACKSUMMARYTOOL_H
 #define TRKITRACKSUMMARYTOOL_H
 
-#include "CxxUtils/checker_macros.h"
+#include "GaudiKernel/EventContext.h"
+#include "GaudiKernel/ThreadLocalContext.h"
 #include "GaudiKernel/IAlgTool.h"
-
+#include "TrkTrackSummary/TrackSummary.h" 
 #include <memory>
 namespace Trk {
 
@@ -32,30 +33,40 @@ public:
    * Does not modify the const track.
    */
   virtual std::unique_ptr<Trk::TrackSummary> summary(
+    const EventContext& ctx,
     const Track& track) const = 0;
-  
+
+  std::unique_ptr<Trk::TrackSummary> summary(const Track& track) const;
+
   /* Start from a copy of the existing input track summary if there,
    * otherwise start from a new one. Fill it and return it.
    * but without doing the hole search.
    * Does not modify the const track.
    */
   virtual std::unique_ptr<Trk::TrackSummary> summaryNoHoleSearch(
+    const EventContext& ctx,
     const Track& track) const = 0;
 
+  std::unique_ptr<Trk::TrackSummary> summaryNoHoleSearch(
+    const Track& track) const;
+
   /** Same behavious as
    * IExtendedTrackSummaryTool:computeAndReplaceTrackSummary
    * but without the need to pass
    * Trk::PRDtoTrackMap
    * Does hole search
    */
-  virtual void updateTrack(Track& track) const = 0;
+  virtual void updateTrack(const EventContext& ctx, Track& track) const = 0;
+  void updateTrack(Track& track) const;
 
   /** method which can be used to update the summary of a track
-   * it, without doing shared hit/ or hole search. 
+   * it, without doing shared hit/ or hole search.
    * If a summary is present is modified in place
    * otherwise a new one is created.
    */
-  virtual void updateTrackSummary(Track& track) const = 0;
+  virtual void updateTrackSummary(const EventContext& ctx,
+                                  Track& track) const = 0;
+  void updateTrackSummary(Track& track) const;
 
   /** method to update the shared hit content only, this is optimised for track
    * collection merging. */
@@ -73,4 +84,5 @@ Trk::ITrackSummaryTool::interfaceID()
 }
 
 }
+#include "TrkToolInterfaces/ITrackSummaryTool.icc"
 #endif
diff --git a/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITrackSummaryTool.icc b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITrackSummaryTool.icc
new file mode 100644
index 00000000000..b716f90b7c5
--- /dev/null
+++ b/Tracking/TrkTools/TrkToolInterfaces/TrkToolInterfaces/ITrackSummaryTool.icc
@@ -0,0 +1,29 @@
+/*
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+*/
+namespace Trk {
+
+inline std::unique_ptr<Trk::TrackSummary>
+ITrackSummaryTool::summary(const Track& track) const
+{
+  return summary(Gaudi::Hive::currentContext(), track);
+}
+
+inline std::unique_ptr<Trk::TrackSummary>
+ITrackSummaryTool::summaryNoHoleSearch(const Track& track) const
+{
+  return summaryNoHoleSearch(Gaudi::Hive::currentContext(), track);
+}
+
+inline void
+ITrackSummaryTool::updateTrack(Track& track) const
+{
+  updateTrack(Gaudi::Hive::currentContext(), track);
+}
+
+inline void
+ITrackSummaryTool::updateTrackSummary(Track& track) const
+{
+  updateTrackSummary(Gaudi::Hive::currentContext(), track);
+}
+}
diff --git a/Tracking/TrkTools/TrkTrackSummaryTool/TrkTrackSummaryTool/TrackSummaryTool.h b/Tracking/TrkTools/TrkTrackSummaryTool/TrkTrackSummaryTool/TrackSummaryTool.h
index b11b5b0919c..c1e8a41cd52 100755
--- a/Tracking/TrkTools/TrkTrackSummaryTool/TrkTrackSummaryTool/TrackSummaryTool.h
+++ b/Tracking/TrkTools/TrkTrackSummaryTool/TrkTrackSummaryTool/TrackSummaryTool.h
@@ -7,7 +7,7 @@
 
 #include "AthenaBaseComps/AthAlgTool.h"
 #include "GaudiKernel/ToolHandle.h"
-#include "TrkTrack/Track.h" //used in the included icc file
+#include "TrkTrack/Track.h"               //used in the included icc file
 #include "TrkTrackSummary/TrackSummary.h" //used in the included icc file
 
 #include "TRT_ElectronPidTools/ITRT_ToT_dEdx.h" //template parameter to tool handle
@@ -16,10 +16,9 @@
 #include "TrkToolInterfaces/ITRT_ElectronPidTool.h" //template parameter to tool handle
 
 #include "TrkToolInterfaces/IExtendedTrackSummaryTool.h"
-#include <vector>
-#include <memory> //unique_ptr
 #include <bitset>
-
+#include <memory> //unique_ptr
+#include <vector>
 
 class EventContext;
 class AtlasDetectorID;
@@ -28,7 +27,8 @@ class Identifier;
 namespace Trk {
 
 /** @enum flag the methods for the probability calculation */
-enum TRT_ElectronPidProbability{
+enum TRT_ElectronPidProbability
+{
   Combined = 0,
   HighThreshold = 1,
   TimeOverThreshold = 2,
@@ -61,10 +61,16 @@ public:
    * search is performed according to the settings of the ID and muon hole
    * search properties unless the suppress_hole_search argument is true.
    */
+  using IExtendedTrackSummaryTool::computeAndReplaceTrackSummary;
+  using IExtendedTrackSummaryTool::summary;
+  using IExtendedTrackSummaryTool::summaryNoHoleSearch;
+  using IExtendedTrackSummaryTool::updateTrack;
+  
   virtual void computeAndReplaceTrackSummary(
+    const EventContext& ctx,
     Track& track,
     const Trk::PRDtoTrackMap* pPrdToTrackMap,
-    bool suppress_hole_search = false) const override;
+    bool suppress_hole_search = false) const override final;
 
   /** Same behavious as
    * IExtendedTrackSummaryTool:computeAndReplaceTrackSummary
@@ -72,14 +78,16 @@ public:
    * Trk::PRDtoTrackMap
    * Does hole search
    */
-  virtual void updateTrack(Track& track) const override;
-  
+  virtual void updateTrack(const EventContext& ctx,
+                           Track& track) const override final;
+
   /* Start from a copy of the existing input track summary if there,
    * otherwise start from a new one. Fill it and return it.
    * Does not modify the const track.
    */
   virtual std::unique_ptr<Trk::TrackSummary> summary(
-    const Track& track) const override;
+    const EventContext& ctx,
+    const Track& track) const override final;
 
   /* Start from a copy of the existing input track summary if there,
    * otherwise start from a new one. Fill it and return it.
@@ -87,40 +95,45 @@ public:
    * Does not modify the const track.
    */
   virtual std::unique_ptr<Trk::TrackSummary> summaryNoHoleSearch(
-    const Track& track) const override;
+    const EventContext& ctx,
+    const Track& track) const override final;
 
   /* Start from a copy of the existing input track summary if there,
    * otherwise start from a new one. Fill it and return it.
    * Does not modify the const track.
    */
   virtual std::unique_ptr<Trk::TrackSummary> summary(
+    const EventContext& ctx,
     const Track& track,
-    const Trk::PRDtoTrackMap* pPrdToTrackMap) const override;
-  
+    const Trk::PRDtoTrackMap* pPrdToTrackMap) const override final;
+
   /* Start from a copy of the existing input track summary if there,
    * otherwise start from a new one. Fill it and return it.
    * but without doing the hole search.
    * Does not modify the const track.
    */
   virtual std::unique_ptr<Trk::TrackSummary> summaryNoHoleSearch(
+    const EventContext& ctx,
     const Track& track,
-    const Trk::PRDtoTrackMap* pPrdToTrackMap) const override;
+    const Trk::PRDtoTrackMap* pPrdToTrackMap) const override final;
 
   /** method which can be used to update the summary of a track
-   * it, without doing shared hit/ or hole search. 
+   * it, without doing shared hit/ or hole search.
    * If a summary is present it is  modified in place.
    * Otherwise a new one is created and filled.
    */
-  virtual void updateTrackSummary(Track& track) const override;
+  virtual void updateTrackSummary(const EventContext& ctx,
+                                  Track& track) const override final;
 
   /** method which can be used to update the summary of a track
    * If a summary is present it is  modified in place.
    * Otherwise a new one is created and filled.
    */
   virtual void updateTrackSummary(
+    const EventContext& ctx,
     Track& track,
     const Trk::PRDtoTrackMap* pPrdToTrackMap,
-    bool suppress_hole_search = false) const override;
+    bool suppress_hole_search = false) const override final;
 
   /** method to update the shared hit content only, this is optimised for track
    * collection merging. */
@@ -128,7 +141,6 @@ public:
     Track& track,
     const Trk::PRDtoTrackMap* pPrdToTrackMap) const override;
 
-
   /** Update the shared hit count of the given track summary.
    * @param summary the summary to be updated i.e. a copy of the track summary
    * of the given track.
@@ -170,12 +182,12 @@ public:
   virtual void updateAdditionalInfo(Track& track) const override;
 
 private:
-
   /*
    * Fill the summary info for a Track*/
-  void fillSummary(Trk::TrackSummary& ts,
+  void fillSummary(const EventContext& ctx,
+                   Trk::TrackSummary& ts,
                    const Trk::Track& track,
-                   const Trk::PRDtoTrackMap *pPrdToTrackMap,
+                   const Trk::PRDtoTrackMap* pPrdToTrackMap,
                    bool doHolesInDet,
                    bool doHolesMuon) const;
 
@@ -183,10 +195,11 @@ private:
    * If a summary is there Update it with the required info.
    * If not there create a new one with the required info.
    */
-  void UpdateSummary(Track& track,
+  void UpdateSummary(const EventContext& ctx,
+                     Track& track,
                      const Trk::PRDtoTrackMap* pPrdToTrackMap,
                      bool suppress_hole_search) const;
-  
+
   void updateAdditionalInfo(const Track& track,
                             TrackSummary& summary,
                             bool initialise_to_zero) const;
@@ -195,10 +208,12 @@ private:
   for this track but not returned. the summary can then be obtained from the
   track. Because it is taken from the track the ownership stays with the track
   */
-  void updateTrack(Track& track,
+  void updateTrack(const EventContext& ctx,
+                   Track& track,
                    const Trk::PRDtoTrackMap* pPrdToTrackMap) const;
 
   std::unique_ptr<Trk::TrackSummary> createSummary(
+    const EventContext& ctx,
     const Track& track,
     const Trk::PRDtoTrackMap* pPrdToTrackMap,
     bool doHolesInDet,
@@ -213,7 +228,10 @@ private:
   ToolHandle<IExtendedTrackSummaryHelperTool>
     m_idTool{ this, "InDetSummaryHelperTool", "", "" };
   /**tool to calculate electron probabilities*/
-  ToolHandle<ITRT_ElectronPidTool> m_eProbabilityTool{ this,"TRT_ElectronPidTool","","" };
+  ToolHandle<ITRT_ElectronPidTool> m_eProbabilityTool{ this,
+                                                       "TRT_ElectronPidTool",
+                                                       "",
+                                                       "" };
   /**tool to calculate dE/dx using pixel clusters*/
   ToolHandle<IPixelToTPIDTool> m_dedxtool{ this, "PixelToTPIDTool", "", "" };
   /**tool to decipher muon RoTs*/
@@ -243,9 +261,10 @@ private:
   /** switch to deactivate Pixel info init */
   Gaudi::Property<bool> m_pixelExists{ this, "PixelExists", true, "" };
 
-  Gaudi::Property<bool> m_alwaysRecomputeHoles {
-    this, "AlwaysRecomputeHoles", false, ""
-  };
+  Gaudi::Property<bool> m_alwaysRecomputeHoles{ this,
+                                                "AlwaysRecomputeHoles",
+                                                false,
+                                                "" };
 
   /**atlas id helper*/
   const AtlasDetectorID* m_detID;
diff --git a/Tracking/TrkTools/TrkTrackSummaryTool/TrkTrackSummaryTool/TrackSummaryTool.icc b/Tracking/TrkTools/TrkTrackSummaryTool/TrkTrackSummaryTool/TrackSummaryTool.icc
index a62dbcf25ec..59c6cc29031 100644
--- a/Tracking/TrkTools/TrkTrackSummaryTool/TrkTrackSummaryTool/TrackSummaryTool.icc
+++ b/Tracking/TrkTools/TrkTrackSummaryTool/TrkTrackSummaryTool/TrackSummaryTool.icc
@@ -4,27 +4,29 @@
 
 namespace Trk {
 inline void
-TrackSummaryTool::updateTrack(Track& track) const
+TrackSummaryTool::updateTrack(const EventContext& ctx, Track& track) const
 {
   computeAndReplaceTrackSummary(
-    track, nullptr, false /*DO NOT suppress hole search*/);
+    ctx, track, nullptr, false /*DO NOT suppress hole search*/);
 }
 
 inline void
-TrackSummaryTool::updateTrackSummary(Track& track) const
+TrackSummaryTool::updateTrackSummary(const EventContext& ctx,
+                                     Track& track) const
 {
   /*suppress hole search*/
-  UpdateSummary(track, nullptr, true);
+  UpdateSummary(ctx, track, nullptr, true);
   /*Needed for expected B-Layer*/
   m_idTool->updateExpectedHitInfo(track, *track.trackSummary());
 }
 
 inline void
-TrackSummaryTool::updateTrackSummary(Track& track,
+TrackSummaryTool::updateTrackSummary(const EventContext& ctx,
+                                     Track& track,
                                      const Trk::PRDtoTrackMap* pPrdToTrackMap,
                                      bool suppress_hole_search) const
 {
-  UpdateSummary(track, pPrdToTrackMap, suppress_hole_search);
+  UpdateSummary(ctx, track, pPrdToTrackMap, suppress_hole_search);
 }
 
 inline void
@@ -40,7 +42,6 @@ TrackSummaryTool::updateSharedHitCount(
   }
 }
 
-
 inline void
 TrackSummaryTool::updateSharedHitCount(Track& track) const
 {
@@ -53,9 +54,8 @@ TrackSummaryTool::updateSharedHitCount(Track& track) const
 }
 
 inline void
-TrackSummaryTool::updateAdditionalInfo(
-  const Track& track,
-  TrackSummary& summary) const
+TrackSummaryTool::updateAdditionalInfo(const Track& track,
+                                       TrackSummary& summary) const
 {
   updateAdditionalInfo(track, summary, false);
 }
@@ -74,14 +74,16 @@ TrackSummaryTool::updateAdditionalInfo(Track& track) const
   }
 }
 inline void
-TrackSummaryTool::UpdateSummary(Track& track,
+TrackSummaryTool::UpdateSummary(const EventContext& ctx,
+                                Track& track,
                                 const Trk::PRDtoTrackMap* pPrdToTrackMap,
                                 bool suppress_hole_search) const
 {
   if (!track.trackSummary()) {
     track.setTrackSummary(std::make_unique<Trk::TrackSummary>());
   }
-  fillSummary(*(track.trackSummary()),
+  fillSummary(ctx,
+              *(track.trackSummary()),
               track,
               pPrdToTrackMap,
               m_doHolesInDet && !suppress_hole_search,
diff --git a/Tracking/TrkTools/TrkTrackSummaryTool/src/TrackSummaryTool.cxx b/Tracking/TrkTools/TrkTrackSummaryTool/src/TrackSummaryTool.cxx
index 2b60bf60189..cc47250394d 100755
--- a/Tracking/TrkTools/TrkTrackSummaryTool/src/TrackSummaryTool.cxx
+++ b/Tracking/TrkTools/TrkTrackSummaryTool/src/TrackSummaryTool.cxx
@@ -24,22 +24,28 @@
 #include <cmath> //std::sqrt
 
 namespace {
-  template<class Indexable, class IntegerArray>
-  void
-  setTheseElements(Indexable& container, const IntegerArray & indices, const typename Indexable::value_type & toValue){
-   for (const auto idx: indices){
-     container[idx] = toValue;
-   }
+template<class Indexable, class IntegerArray>
+void
+setTheseElements(Indexable& container,
+                 const IntegerArray& indices,
+                 const typename Indexable::value_type& toValue)
+{
+  for (const auto idx : indices) {
+    container[idx] = toValue;
   }
+}
   //
-  template <class Indexable>
-  void
-  setTheseElements(Indexable& container, const std::initializer_list<size_t> & indices, const typename Indexable::value_type & toValue){
-   for (const auto idx: indices){
-     container[idx] = toValue;
-   }
+template<class Indexable>
+void
+setTheseElements(Indexable& container,
+                 const std::initializer_list<size_t>& indices,
+                 const typename Indexable::value_type& toValue)
+{
+  for (const auto idx : indices) {
+    container[idx] = toValue;
   }
 }
+}
 
 
 Trk::TrackSummaryTool::TrackSummaryTool(const std::string& t,
@@ -92,62 +98,84 @@ Trk::TrackSummaryTool::finalize(){
  */
 void
 Trk::TrackSummaryTool::computeAndReplaceTrackSummary(
+  const EventContext& ctx,
   Trk::Track& track,
   const Trk::PRDtoTrackMap* pPrdToTrackMap,
-  bool suppress_hole_search) const{
-  track.setTrackSummary(createSummary(track, pPrdToTrackMap,
+  bool suppress_hole_search) const
+{
+  track.setTrackSummary(createSummary(ctx,
+                                      track,
+                                      pPrdToTrackMap,
                                       m_doHolesInDet & !suppress_hole_search,
                                       m_doHolesMuon & !suppress_hole_search));
 }
 
 std::unique_ptr<Trk::TrackSummary>
-Trk::TrackSummaryTool::summary(const Track& track) const{
-  return createSummary(track, nullptr, m_doHolesInDet, m_doHolesMuon);
+Trk::TrackSummaryTool::summary(const EventContext& ctx,
+                               const Track& track) const
+{
+  return createSummary(ctx, track, nullptr, m_doHolesInDet, m_doHolesMuon);
 }
 
 std::unique_ptr<Trk::TrackSummary>
-Trk::TrackSummaryTool::summary(const Track& track,
-                               const Trk::PRDtoTrackMap* pPrdToTrackMap) const{
-  return createSummary(track, pPrdToTrackMap, m_doHolesInDet, m_doHolesMuon);
+Trk::TrackSummaryTool::summary(const EventContext& ctx,
+                               const Track& track,
+                               const Trk::PRDtoTrackMap* pPrdToTrackMap) const
+{
+  return createSummary(
+    ctx, track, pPrdToTrackMap, m_doHolesInDet, m_doHolesMuon);
 }
 
 std::unique_ptr<Trk::TrackSummary>
-Trk::TrackSummaryTool::summaryNoHoleSearch(const Track& track) const{
-  return createSummary(track, nullptr, false, false);
+Trk::TrackSummaryTool::summaryNoHoleSearch(const EventContext& ctx,
+                                           const Track& track) const
+{
+  return createSummary(ctx, track, nullptr, false, false);
 }
 
 std::unique_ptr<Trk::TrackSummary>
 Trk::TrackSummaryTool::summaryNoHoleSearch(
+  const EventContext& ctx,
   const Track& track,
   const Trk::PRDtoTrackMap* pPrdToTrackMap) const{
-  return createSummary(track, pPrdToTrackMap, false, false);
+  return createSummary(ctx,track, pPrdToTrackMap, false, false);
 }
 
-//Method to create a new summary
+// Method to create a new summary
 std::unique_ptr<Trk::TrackSummary>
-Trk::TrackSummaryTool::createSummary( const Track& track,
-                                      const Trk::PRDtoTrackMap *pPrdToTrackMap,
-                                      bool doHolesInDet,
-                                      bool doHolesMuon) const{
+Trk::TrackSummaryTool::createSummary(const EventContext& ctx,
+                                     const Track& track,
+                                     const Trk::PRDtoTrackMap* pPrdToTrackMap,
+                                     bool doHolesInDet,
+                                     bool doHolesMuon) const
+{
   std::unique_ptr<Trk::TrackSummary> ts;
 
   // first check if track has summary already and then clone it.
-  if (track.trackSummary()!=nullptr) {
-    ATH_MSG_DEBUG ("Return cached summary for author : "<<track.info().dumpInfo());
+  if (track.trackSummary() != nullptr) {
+    ATH_MSG_DEBUG(
+      "Return cached summary for author : " << track.info().dumpInfo());
     ts = std::make_unique<Trk::TrackSummary>(*(track.trackSummary()));
   } else {
     ts = std::make_unique<Trk::TrackSummary>();
   }
-  //fill the summary
-  fillSummary(*ts, track, pPrdToTrackMap, doHolesInDet, doHolesMuon);
+  // fill the summary
+  fillSummary(ctx, *ts, track, pPrdToTrackMap, doHolesInDet, doHolesMuon);
   return ts;
 }
 
 // Method filling the summary with information
 void
-Trk::TrackSummaryTool::fillSummary(Trk::TrackSummary& ts,const Trk::Track& track,const Trk::PRDtoTrackMap *prdToTrackMap,bool doHolesInDet,bool doHolesMuon) const {
+Trk::TrackSummaryTool::fillSummary(const EventContext& ctx,
+                                   Trk::TrackSummary& ts,
+                                   const Trk::Track& track,
+                                   const Trk::PRDtoTrackMap* prdToTrackMap,
+                                   bool doHolesInDet,
+                                   bool doHolesMuon) const
+{
   std::vector<int>& information = ts.m_information;
-  information.resize(std::min(information.size(),static_cast<size_t>(numberOfTrackSummaryTypes)));
+  information.resize(std::min(information.size(),
+                              static_cast<size_t>(numberOfTrackSummaryTypes)));
 
   // Troels.Petersen@cern.ch:
   std::vector<float> eProbability = Trk::eProbabilityDefault;;
@@ -160,8 +188,8 @@ Trk::TrackSummaryTool::fillSummary(Trk::TrackSummary& ts,const Trk::Track& track
     if (m_pixelExists) {
       constexpr size_t numberOfPixelCounters{14};
       const std::array<size_t, numberOfPixelCounters> atPixelIndices{
-        numberOfContribPixelLayers, 
-        numberOfInnermostPixelLayerHits, numberOfInnermostPixelLayerOutliers, 
+        numberOfContribPixelLayers,
+        numberOfInnermostPixelLayerHits, numberOfInnermostPixelLayerOutliers,
         numberOfNextToInnermostPixelLayerHits, numberOfNextToInnermostPixelLayerOutliers,
         numberOfPixelHits, numberOfPixelOutliers,
         numberOfGangedPixels, numberOfGangedFlaggedFakes,
@@ -175,7 +203,7 @@ Trk::TrackSummaryTool::fillSummary(Trk::TrackSummary& ts,const Trk::Track& track
       information[Trk::numberOfDBMHits] = 0;
     }
     constexpr size_t numberOfSctOrTrtCounters{11};
-    const std::array<size_t, numberOfSctOrTrtCounters> atSctOrTrtIndices{
+    constexpr std::array<size_t, numberOfSctOrTrtCounters> atSctOrTrtIndices{
       numberOfSCTHits, numberOfSCTSpoiltHits, numberOfSCTOutliers,
       numberOfTRTHits, numberOfTRTXenonHits, numberOfTRTHighThresholdHits, numberOfTRTHighThresholdHitsTotal,
       numberOfTRTOutliers, numberOfTRTHighThresholdOutliers, numberOfTRTTubeHits, numberOfTRTSharedHits
@@ -183,20 +211,25 @@ Trk::TrackSummaryTool::fillSummary(Trk::TrackSummary& ts,const Trk::Track& track
     setTheseElements(information, atSctOrTrtIndices, toZero);
     if (!m_eProbabilityTool.empty()) {
       eProbability = m_eProbabilityTool->electronProbability(track);
-      information[Trk::numberOfTRTHitsUsedFordEdx] = static_cast<int>(eProbability[Trk::eProbabilityNumberOfTRTHitsUsedFordEdx]);
+      information[Trk::numberOfTRTHitsUsedFordEdx] = static_cast<int>(
+        eProbability[Trk::eProbabilityNumberOfTRTHitsUsedFordEdx]);
     }
   }
   if (m_doSharedHits) {
-    information [numberOfSCTSharedHits]      = 0;
+    information[numberOfSCTSharedHits] = 0;
     if (m_pixelExists) {
-      setTheseElements(information, {numberOfInnermostPixelLayerSharedHits, numberOfNextToInnermostPixelLayerSharedHits, numberOfPixelSharedHits}, toZero);
+      setTheseElements(information,
+                       { numberOfInnermostPixelLayerSharedHits,
+                         numberOfNextToInnermostPixelLayerSharedHits,
+                         numberOfPixelSharedHits },
+                       toZero);
     }
   }
   if (!m_muonTool.empty()) {
     constexpr size_t numberOfMuonRelatedCounters{15};
-    const std::array<size_t, numberOfMuonRelatedCounters> atMuonIndices{
+    constexpr std::array<size_t, numberOfMuonRelatedCounters> atMuonIndices{
       numberOfMdtHits,
-      numberOfTgcPhiHits, numberOfTgcEtaHits, 
+      numberOfTgcPhiHits, numberOfTgcEtaHits,
       numberOfCscPhiHits, numberOfCscEtaHits, numberOfCscUnspoiltEtaHits,
       numberOfRpcPhiHits, numberOfRpcEtaHits,
       Trk::numberOfMdtHoles,
@@ -206,7 +239,7 @@ Trk::TrackSummaryTool::fillSummary(Trk::TrackSummary& ts,const Trk::Track& track
     };
     // New Small Wheel
     constexpr size_t numberOfNswRelatedCounters{6};
-    const std::array<size_t, numberOfNswRelatedCounters> atNswIndices{
+    constexpr std::array<size_t, numberOfNswRelatedCounters> atNswIndices{
       Trk::numberOfStgcEtaHits, Trk::numberOfStgcPhiHits, Trk::numberOfMmHits,
       Trk::numberOfStgcEtaHoles, Trk::numberOfStgcPhiHoles, Trk::numberOfMmHoles
     };
@@ -216,12 +249,20 @@ Trk::TrackSummaryTool::fillSummary(Trk::TrackSummary& ts,const Trk::Track& track
 
   std::bitset<numberOfDetectorTypes> hitPattern;
   ATH_MSG_DEBUG ("Produce summary for: "<<track.info().dumpInfo());
-  const EventContext& ctx= Gaudi::Hive::currentContext();
-  if (track.trackStateOnSurfaces()){
+  if (track.trackStateOnSurfaces()) {
     information[Trk::numberOfOutliersOnTrack] = 0;
-    processTrackStates(ctx,track,prdToTrackMap,track.trackStateOnSurfaces(),information,hitPattern,doHolesInDet,doHolesMuon);
+    processTrackStates(ctx,
+                       track,
+                       prdToTrackMap,
+                       track.trackStateOnSurfaces(),
+                       information,
+                       hitPattern,
+                       doHolesInDet,
+                       doHolesMuon);
   } else {
-    ATH_MSG_WARNING ("Null pointer to TSoS found on Track (author = "<<track.info().dumpInfo()<<"). This should never happen! ");
+    ATH_MSG_WARNING("Null pointer to TSoS found on Track (author = "
+                    << track.info().dumpInfo()
+                    << "). This should never happen! ");
   }
 
   bool holeSearchDone = (
@@ -257,15 +298,21 @@ Trk::TrackSummaryTool::fillSummary(Trk::TrackSummary& ts,const Trk::Track& track
   }
 }
 
-void 
-Trk::TrackSummaryTool::updateSharedHitCount(const Track& track, const Trk::PRDtoTrackMap *prdToTrackMap,TrackSummary &summary) const{
+void
+Trk::TrackSummaryTool::updateSharedHitCount(
+  const Track& track,
+  const Trk::PRDtoTrackMap* prdToTrackMap,
+  TrackSummary& summary) const
+{
   // first check if track has no summary - then it is recreated
   m_idTool->updateSharedHitCount(track, prdToTrackMap, summary);
 }
 
-
-void 
-Trk::TrackSummaryTool::updateAdditionalInfo(const Track& track,  TrackSummary &summary, bool initialiseToZero) const{
+void
+Trk::TrackSummaryTool::updateAdditionalInfo(const Track& track,
+                                            TrackSummary& summary,
+                                            bool initialiseToZero) const
+{
   std::vector<float> eProbability = Trk::eProbabilityDefault;
   if (!m_eProbabilityTool.empty()) {
     eProbability = m_eProbabilityTool->electronProbability(track);
@@ -288,15 +335,21 @@ Trk::TrackSummaryTool::updateAdditionalInfo(const Track& track,  TrackSummary &s
   if (m_addInDetDetailedSummary) m_idTool->addDetailedTrackSummary(track,summary);
 }
 
-
-
-
 /*
  * Then the internal helpers
  */
 void
-Trk::TrackSummaryTool::processTrackStates(const EventContext& ctx,const Track& track,const Trk::PRDtoTrackMap* prdToTrackMap,const DataVector<const TrackStateOnSurface>* tsos,std::vector<int>& information,std::bitset<numberOfDetectorTypes>& hitPattern,bool doHolesInDet,bool doHolesMuon) const{
-  ATH_MSG_DEBUG ("Starting to process " << tsos->size() << " track states");
+Trk::TrackSummaryTool::processTrackStates(
+  const EventContext& ctx,
+  const Track& track,
+  const Trk::PRDtoTrackMap* prdToTrackMap,
+  const DataVector<const TrackStateOnSurface>* tsos,
+  std::vector<int>& information,
+  std::bitset<numberOfDetectorTypes>& hitPattern,
+  bool doHolesInDet,
+  bool doHolesMuon) const
+{
+  ATH_MSG_DEBUG("Starting to process " << tsos->size() << " track states");
   int measCounter = 0;
   int cntAddChi2 = 0;
   float chi2Sum = 0;
@@ -350,12 +403,20 @@ Trk::TrackSummaryTool::processTrackStates(const EventContext& ctx,const Track& t
   if (cntAddChi2>0){
     const auto inverseCount{1./cntAddChi2};
     varChi2 = (chi2Sum2 - (chi2Sum * chi2Sum * inverseCount)) * inverseCount;
-  } 
+  }
   if (varChi2>0 && varChi2<1.e13) information[Trk::standardDeviationOfChi2OS] = int(std::sqrt(varChi2)*100);
 }
 
-void 
-Trk::TrackSummaryTool::processMeasurement(const EventContext& ctx,const Track& track,const Trk::PRDtoTrackMap *prdToTrackMap,const Trk::MeasurementBase* meas,const Trk::TrackStateOnSurface* tsos,std::vector<int>& information,std::bitset<numberOfDetectorTypes>& hitPattern) const{
+void
+Trk::TrackSummaryTool::processMeasurement(
+  const EventContext& ctx,
+  const Track& track,
+  const Trk::PRDtoTrackMap* prdToTrackMap,
+  const Trk::MeasurementBase* meas,
+  const Trk::TrackStateOnSurface* tsos,
+  std::vector<int>& information,
+  std::bitset<numberOfDetectorTypes>& hitPattern) const
+{
   // Check if the measurement type is RIO on Track (ROT)
   const RIO_OnTrack* rot = nullptr;
   if (meas->type(Trk::MeasurementBaseType::RIO_OnTrack)) {
@@ -425,9 +486,14 @@ Trk::TrackSummaryTool::getTool(const Identifier& id) const{
   return nullptr;
 }
 
-void Trk::TrackSummaryTool::searchHolesStepWise( const Trk::Track& track,std::vector<int>& information,bool doHolesInDet,bool doHolesMuon) const{
-  ATH_MSG_VERBOSE ("Entering Trk::TrackSummaryTool::searchHolesStepWise");
-// -------- obtain hits in Pixel and SCT only
+void
+Trk::TrackSummaryTool::searchHolesStepWise(const Trk::Track& track,
+                                           std::vector<int>& information,
+                                           bool doHolesInDet,
+                                           bool doHolesMuon) const
+{
+  ATH_MSG_VERBOSE("Entering Trk::TrackSummaryTool::searchHolesStepWise");
+  // -------- obtain hits in Pixel and SCT only
   if (track.trackStateOnSurfaces()==nullptr){
     ATH_MSG_DEBUG ("No trackStatesOnSurface!!!!");
     const int toMinusOne{-1};
@@ -435,7 +501,7 @@ void Trk::TrackSummaryTool::searchHolesStepWise( const Trk::Track& track,std::ve
       numberOfPixelHoles, numberOfPixelDeadSensors,
       numberOfSCTHoles, numberOfSCTDoubleHoles, numberOfSCTDeadSensors,
       numberOfTRTHoles, numberOfTRTDeadStraws,
-      numberOfCscEtaHoles, numberOfCscPhiHoles, 
+      numberOfCscEtaHoles, numberOfCscPhiHoles,
       numberOfRpcEtaHoles, numberOfRpcPhiHoles,
       numberOfTgcEtaHoles, numberOfTgcPhiHoles,
       //new small wheels
@@ -462,7 +528,7 @@ void Trk::TrackSummaryTool::searchHolesStepWise( const Trk::Track& track,std::ve
     // and probably more efficient. But this hopefully works for now! EJWM
     constexpr size_t numberOfRelatedMuonCounters{10};
     const std::array<size_t, numberOfRelatedMuonCounters> atMuonIndices{
-      numberOfMdtHoles, 
+      numberOfMdtHoles,
       numberOfCscEtaHoles, numberOfCscPhiHoles,
       numberOfRpcEtaHoles, numberOfRpcPhiHoles,
       numberOfTgcEtaHoles, numberOfTgcPhiHoles,
-- 
GitLab