From ae9ab92f9c90feb09edb0b9c90c6206395c343f8 Mon Sep 17 00:00:00 2001
From: christos <christos@cern.ch>
Date: Fri, 12 Feb 2021 01:25:15 +0000
Subject: [PATCH 1/2] TruthParticlesInConeTool, pass event context

---
 .../src/MCTruthClassifierAthena.cxx           |  2 +-
 .../ITruthParticlesInConeTool.h               | 57 ++++++-----
 .../src/TruthParticlesInConeTool.cxx          | 97 +++++++++++--------
 .../src/TruthParticlesInConeTool.h            | 77 ++++++++-------
 4 files changed, 132 insertions(+), 101 deletions(-)

diff --git a/PhysicsAnalysis/MCTruthClassifier/src/MCTruthClassifierAthena.cxx b/PhysicsAnalysis/MCTruthClassifier/src/MCTruthClassifierAthena.cxx
index 50785ea25eb5..5f379bc2b58e 100644
--- a/PhysicsAnalysis/MCTruthClassifier/src/MCTruthClassifierAthena.cxx
+++ b/PhysicsAnalysis/MCTruthClassifier/src/MCTruthClassifierAthena.cxx
@@ -125,7 +125,7 @@ MCTruthClassifier::egammaClusMatch(const xAOD::CaloCluster* clus, bool isFwrdEle
   }
 
   std::vector<const xAOD::TruthParticle*> tps;
-  if (!m_truthInConeTool->particlesInCone(etaClus, phiClus, 0.5, tps)) {
+  if (!m_truthInConeTool->particlesInCone(ctx,etaClus, phiClus, 0.5, tps)) {
     ATH_MSG_WARNING("Truth Particle in Cone failed");
     return theMatchPart;
   }
diff --git a/Reconstruction/RecoTools/ParticlesInConeTools/ParticlesInConeTools/ITruthParticlesInConeTool.h b/Reconstruction/RecoTools/ParticlesInConeTools/ParticlesInConeTools/ITruthParticlesInConeTool.h
index 1d3a54886399..e02c7b9242fd 100644
--- a/Reconstruction/RecoTools/ParticlesInConeTools/ParticlesInConeTools/ITruthParticlesInConeTool.h
+++ b/Reconstruction/RecoTools/ParticlesInConeTools/ParticlesInConeTools/ITruthParticlesInConeTool.h
@@ -9,36 +9,45 @@
 #define PARTICLESINCONETOOLS_ITRUTHPARTICLESINCONETOOL_H
 
 #include "GaudiKernel/IAlgTool.h"
+#include "GaudiKernel/EventContext.h"
 #include "xAODTruth/TruthParticle.h"
 #include <vector>
 
 namespace xAOD {
 
-  static const InterfaceID IID_ITruthParticlesInConeTool("xAOD::ITruthParticlesInConeTool", 1, 0);
-
-  /** @class ITruthParticlesInConeTool
-      @brief interface for collecting truth particles inside a cone 
-      @author Niels van Eldik
+static const InterfaceID
+  IID_ITruthParticlesInConeTool("xAOD::ITruthParticlesInConeTool", 1, 0);
+
+/** @class ITruthParticlesInConeTool
+    @brief interface for collecting truth particles inside a cone
+    @author Niels van Eldik
+ */
+class ITruthParticlesInConeTool : virtual public IAlgTool
+{
+public:
+  static const InterfaceID& interfaceID();
+
+  /**ITruthParticlesInConeTool interface:
+     @param[in] eta       eta for matching
+     @param[in] phi       phi for matching
+     @param[in] dr        cone size
+     @param[in] output    output vector to be filled
+     @return true if the calculation was successfull
    */
-  class ITruthParticlesInConeTool : virtual public IAlgTool {
-  public:
-
-    static const InterfaceID& interfaceID( ) ;
-
-    /**ITruthParticlesInConeTool interface: 
-       @param[in] eta       eta for matching
-       @param[in] phi       phi for matching
-       @param[in] dr        cone size
-       @param[in] output    output vector to be filled
-       @return true if the calculation was successfull
-     */    
-    virtual bool particlesInCone( float eta, float phi, float dr, std::vector< const TruthParticle*>& output ) const = 0;
-  };
-
-  inline const InterfaceID& ITruthParticlesInConeTool::interfaceID() { 
-    return IID_ITruthParticlesInConeTool; 
-  }
+  virtual bool particlesInCone(
+    const EventContext& ctx,
+    float eta,
+    float phi,
+    float dr,
+    std::vector<const TruthParticle*>& output) const = 0;
+};
+
+inline const InterfaceID&
+ITruthParticlesInConeTool::interfaceID()
+{
+  return IID_ITruthParticlesInConeTool;
+}
 
 } // end of namespace
 
-#endif 
+#endif
diff --git a/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.cxx b/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.cxx
index af05a1352955..6d7ac971b23b 100644
--- a/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.cxx
+++ b/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.cxx
@@ -12,46 +12,57 @@
 
 namespace xAOD {
 
-    TruthParticlesInConeTool::TruthParticlesInConeTool (const std::string& type, const std::string& name, const IInterface* parent)
-        :	AthAlgTool(type, name, parent){
-        declareInterface<ITruthParticlesInConeTool>(this);
-    }
-
-    TruthParticlesInConeTool::~TruthParticlesInConeTool(){
-    }
-
-    StatusCode TruthParticlesInConeTool::initialize() {
-        ATH_CHECK(m_truthParticleLocation.initialize());
-        return StatusCode::SUCCESS;
-    }
-
-    StatusCode TruthParticlesInConeTool::finalize() {
-        return StatusCode::SUCCESS;
-    }
-
-    const TruthParticlesInConeTool::LookUpTable* TruthParticlesInConeTool::getTable() const{
-        const std::string tableName = name() + "LookUpTable";
-        SG::ReadHandle<LookUpTable> rh (tableName);
-        if (rh.isValid()){
-            return &*rh;
-        }
-	SG::ReadHandle<TruthParticleContainer> truthParticles(m_truthParticleLocation);
-        if( !truthParticles.isValid() ) {
-	  ATH_MSG_ERROR("Could not open a TruthParticle container with key " << 
-			m_truthParticleLocation.key());
-	  return nullptr;
-	}
-        auto lut = std::make_unique<LookUpTable>();
-        lut->init(*truthParticles);
-        SG::WriteHandle<LookUpTable> wh (tableName);
-        return wh.put (std::move (lut), true);
-    }
-
-    bool TruthParticlesInConeTool::particlesInCone( float eta, float phi, float dr, 
-            std::vector< const TruthParticle*>& output ) const {
-
-        /// initialize if needed
-        const LookUpTable* lut = getTable();
-        return lut->iParticlesInCone( eta, phi, dr, output );
-    }
-}	// end of namespace
+TruthParticlesInConeTool::TruthParticlesInConeTool(const std::string& type,
+                                                   const std::string& name,
+                                                   const IInterface* parent)
+  : AthAlgTool(type, name, parent)
+{
+  declareInterface<ITruthParticlesInConeTool>(this);
+}
+
+
+StatusCode
+TruthParticlesInConeTool::initialize()
+{
+  ATH_CHECK(m_truthParticleLocation.initialize());
+  const std::string tableName = name() + "LookUpTable";
+  m_LookUpTableCacheRead = tableName;
+  m_LookUpTableCacheWrite = tableName;
+  ATH_CHECK(m_LookUpTableCacheRead.initialize());
+  ATH_CHECK(m_LookUpTableCacheWrite.initialize());
+  return StatusCode::SUCCESS;
+}
+
+const TruthParticlesInConeTool::LookUpTable*
+TruthParticlesInConeTool::getTable(const EventContext& ctx) const
+{
+  SG::ReadHandle<LookUpTable> rh(m_LookUpTableCacheRead, ctx);
+  if (rh.isValid()) {
+    return &*rh;
+  }
+  SG::ReadHandle<TruthParticleContainer> truthParticles(m_truthParticleLocation,
+                                                        ctx);
+  if (!truthParticles.isValid()) {
+    ATH_MSG_ERROR("Could not open a TruthParticle container with key "
+                  << m_truthParticleLocation.key());
+    return nullptr;
+  }
+  auto lut = std::make_unique<LookUpTable>();
+  lut->init(*truthParticles);
+  SG::WriteHandle<LookUpTable> wh(m_LookUpTableCacheWrite, ctx);
+  return wh.put(std::move(lut), true);
+}
+
+bool
+TruthParticlesInConeTool::particlesInCone(
+  const EventContext& ctx,
+  float eta,
+  float phi,
+  float dr,
+  std::vector<const TruthParticle*>& output) const
+{
+  /// initialize if needed
+  const LookUpTable* lut = getTable(ctx);
+  return lut->iParticlesInCone(eta, phi, dr, output);
+}
+} // end of namespace
diff --git a/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.h b/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.h
index 65ea4ade678a..8ecab5be4e00 100644
--- a/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.h
+++ b/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.h
@@ -9,44 +9,55 @@
 #include "GaudiKernel/ServiceHandle.h"
 #include "StoreGate/ReadHandleKey.h"
 
-#include "ParticlesInConeTools/ITruthParticlesInConeTool.h"
 #include "IParticlesLookUpTable.h"
+#include "ParticlesInConeTools/ITruthParticlesInConeTool.h"
 #include "xAODTruth/TruthParticle.h"
 #include "xAODTruth/TruthParticleContainer.h"
 
 namespace xAOD {
 
-    class TruthParticlesInConeTool: public AthAlgTool, virtual public ITruthParticlesInConeTool{
-    public:
-        /** constructor */
-        TruthParticlesInConeTool(const std::string& type, const std::string& name, const IInterface* parent);
-
-        /** destructor */
-        ~TruthParticlesInConeTool(void); 
-
-        /** initialize */
-        StatusCode initialize() final;
-
-        /** finalize */
-        StatusCode finalize() final;
-
-        /**ITruthParticlesInConeTool interface */    
-        bool particlesInCone( float eta, float phi, float dr, std::vector< const TruthParticle*>& output ) const final;
-
-        typedef IParticlesLookUpTable<TruthParticle> LookUpTable;
-
-    private:
-
-        // init look-up table
-        const LookUpTable* getTable() const;
-
-        /** Truth Particle collection name */
-        SG::ReadHandleKey<TruthParticleContainer> m_truthParticleLocation {this,
-	    "TruthParticleLocation", "TruthParticles"};
-    };
-}	// end of namespace
-
-CLASS_DEF( xAOD::TruthParticlesInConeTool::LookUpTable, 151156931 , 0 )
+class TruthParticlesInConeTool
+  : public AthAlgTool
+  , virtual public ITruthParticlesInConeTool
+{
+public:
+  /** constructor */
+  TruthParticlesInConeTool(const std::string& type,
+                           const std::string& name,
+                           const IInterface* parent);
+
+  /** destructor */
+  virtual ~TruthParticlesInConeTool() = default;
+
+  /** initialize */
+  virtual StatusCode initialize() override final;
+
+  /**ITruthParticlesInConeTool interface */
+  virtual bool particlesInCone(
+    const EventContext& ctx,
+    float eta,
+    float phi,
+    float dr,
+    std::vector<const TruthParticle*>& output) const override final;
+
+  typedef IParticlesLookUpTable<TruthParticle> LookUpTable;
+
+private:
+  // init look-up table
+  const LookUpTable* getTable(const EventContext& ctx) const;
+
+  /** Truth Particle collection name */
+  SG::ReadHandleKey<TruthParticleContainer> m_truthParticleLocation{
+    this,
+    "TruthParticleLocation",
+    "TruthParticles"
+  };
+
+  SG::ReadHandleKey<LookUpTable> m_LookUpTableCacheRead{ "LookUpTable" };
+  SG::WriteHandleKey<LookUpTable> m_LookUpTableCacheWrite{ "LookUpTable" };
+};
+} // end of namespace
+
+CLASS_DEF(xAOD::TruthParticlesInConeTool::LookUpTable, 151156931, 0)
 #endif
 
-
-- 
GitLab


From fb89c06dfc87e7fb7db04c78a0fb64a8cb15941f Mon Sep 17 00:00:00 2001
From: christos <christos@cern.ch>
Date: Fri, 12 Feb 2021 14:04:17 +0000
Subject: [PATCH 2/2] change a few copyrights to 2021

---
 .../ParticlesInConeTools/ITruthParticlesInConeTool.h            | 2 +-
 .../ParticlesInConeTools/src/TruthParticlesInConeTool.cxx       | 2 +-
 .../ParticlesInConeTools/src/TruthParticlesInConeTool.h         | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Reconstruction/RecoTools/ParticlesInConeTools/ParticlesInConeTools/ITruthParticlesInConeTool.h b/Reconstruction/RecoTools/ParticlesInConeTools/ParticlesInConeTools/ITruthParticlesInConeTool.h
index e02c7b9242fd..ac77a5c33494 100644
--- a/Reconstruction/RecoTools/ParticlesInConeTools/ParticlesInConeTools/ITruthParticlesInConeTool.h
+++ b/Reconstruction/RecoTools/ParticlesInConeTools/ParticlesInConeTools/ITruthParticlesInConeTool.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
diff --git a/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.cxx b/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.cxx
index 6d7ac971b23b..23c9e06b9300 100644
--- a/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.cxx
+++ b/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.cxx
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+   Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
    */
 
 //////////////////////////////////////////////////////////////////////////////
diff --git a/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.h b/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.h
index 8ecab5be4e00..c59a28bb9762 100644
--- a/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.h
+++ b/Reconstruction/RecoTools/ParticlesInConeTools/src/TruthParticlesInConeTool.h
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+   Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
  */
 
 #ifndef PARTICLESINCONETOOLS_TRUTHPARTICLESINCONETOOL_H
-- 
GitLab