From ba38e1087e8bf0f71eba98781a921afa250db08c Mon Sep 17 00:00:00 2001
From: Joao Victor Da Fonseca Pinto <joao.victor.da.fonseca.pinto@cern.ch>
Date: Mon, 22 Mar 2021 15:14:04 +0000
Subject: [PATCH] setup ringer as ASG into the fast step

---
 .../RingerSelectorTools/CMakeLists.txt        |   6 +-
 .../AsgRingerSelectorTool.h                   |  90 ++++++++++++
 .../IAsgRingerSelectorTool.h                  |  60 ++++++++
 .../RingerSelectorTools/tools/onnx/Model.h    |   2 +-
 ...{RingerSelectorTool.h => RingerSelector.h} |  36 +++--
 .../Root/AsgRingerSelectorTool.cxx            |  84 ++++++++++++
 .../{src => Root/tools}/onnx/Model.cxx        |   1 -
 .../tools/onnx/RingerSelector.cxx}            | 128 ++++++------------
 .../{src => Root/tools}/onnx/Threshold.cxx    |   0
 .../RingerSelectorTools_entries.cxx           |   4 +-
 .../python/TrigEgammaFastCaloHypoTool.py      |   6 +-
 .../src/TrigEgammaFastCaloHypoToolInc.cxx     |  24 ++--
 .../src/TrigEgammaFastCaloHypoToolInc.h       |  12 +-
 13 files changed, 319 insertions(+), 134 deletions(-)
 create mode 100644 PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/AsgRingerSelectorTool.h
 create mode 100644 PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/IAsgRingerSelectorTool.h
 rename PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/{RingerSelectorTool.h => RingerSelector.h} (62%)
 create mode 100644 PhysicsAnalysis/RingerSelectorTools/Root/AsgRingerSelectorTool.cxx
 rename PhysicsAnalysis/RingerSelectorTools/{src => Root/tools}/onnx/Model.cxx (98%)
 rename PhysicsAnalysis/RingerSelectorTools/{src/onnx/RingerSelectorTool.cxx => Root/tools/onnx/RingerSelector.cxx} (69%)
 rename PhysicsAnalysis/RingerSelectorTools/{src => Root/tools}/onnx/Threshold.cxx (100%)

diff --git a/PhysicsAnalysis/RingerSelectorTools/CMakeLists.txt b/PhysicsAnalysis/RingerSelectorTools/CMakeLists.txt
index 73e28564e8ab..d5464aa72d4d 100644
--- a/PhysicsAnalysis/RingerSelectorTools/CMakeLists.txt
+++ b/PhysicsAnalysis/RingerSelectorTools/CMakeLists.txt
@@ -22,7 +22,7 @@ atlas_add_library( RingerSelectorToolsLib
                    Root/*.cxx
                    Root/procedures/*.cxx
                    Root/tools/*.cxx
-                   src/onnx/*.cxx
+                   Root/tools/onnx/*.cxx
                    PUBLIC_HEADERS RingerSelectorTools
                    INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${ONNXRUNTIME_INCLUDE_DIRS}
                    LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES} ${ONNXRUNTIME_LIBRARIES} AsgTools CxxUtils xAODCaloRings xAODEgamma xAODTracking 
@@ -32,8 +32,8 @@ atlas_add_library( RingerSelectorToolsLib
 if( NOT XAOD_STANDALONE )
   atlas_add_component( RingerSelectorTools
                        src/components/*.cxx
-                       INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS}
-                       LINK_LIBRARIES ${ONNXRUNTIME_LIBRARIES} ${Boost_LIBRARIES} ${ROOT_LIBRARIES} AthenaKernel AthContainers GaudiKernel TrkTrackSummary RingerSelectorToolsLib )
+                       INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${ONNXRUNTIME_INCLUDE_DIRS}
+                       LINK_LIBRARIES ${ONNXRUNTIME_LIBRARIES} ${Boost_LIBRARIES} ${ROOT_LIBRARIES} AthenaKernel AthContainers GaudiKernel TrkTrackSummary RingerSelectorToolsLib AthOnnxruntimeServiceLib )
 endif()
 
 
diff --git a/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/AsgRingerSelectorTool.h b/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/AsgRingerSelectorTool.h
new file mode 100644
index 000000000000..739e76616307
--- /dev/null
+++ b/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/AsgRingerSelectorTool.h
@@ -0,0 +1,90 @@
+// Dear emacs, this is -*- c++ -*-
+/*
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+*/
+#ifndef RINGERSELECTORTOOLS_ASGRINGERSELECTORTOOL_H
+#define RINGERSELECTORTOOLS_ASGRINGERSELECTORTOOL_H
+
+// STL includes:
+#include <string>
+
+// Athena includes
+#include "PATCore/AcceptData.h"
+#include "PATCore/AcceptInfo.h"
+#include "AsgTools/AsgTool.h"
+
+// xAOD includes:
+#include "RingerSelectorTools/IAsgRingerSelectorTool.h"
+#include "RingerSelectorTools/tools/onnx/RingerSelector.h"
+#include "AthOnnxruntimeService/IONNXRuntimeSvc.h"
+
+
+
+namespace Ringer {
+  
+  class AsgRingerSelectorTool : public asg::AsgTool,
+                                  virtual public IAsgRingerSelectorTool
+  {
+
+  public:
+
+    // Use ASG_TOOL macro for 2 interface base classes.
+    ASG_TOOL_CLASS2(AsgRingerSelectorTool,
+                    IAsgRingerSelectorTool,
+                    IAsgSelectionTool)
+
+
+    /** Standard constructor */
+    AsgRingerSelectorTool(std::string name);
+
+    /** Standard destructor */
+    virtual ~AsgRingerSelectorTool();
+
+    /** Gaudi Service Interface method implementations */
+    virtual StatusCode initialize() override;
+
+    /** Gaudi Service Interface method implementations */
+    virtual StatusCode finalize() override;
+
+
+    /**
+     * @brief Method to get the plain TAccept for the last particle.
+     **/
+    virtual const asg::AcceptInfo& getAcceptInfo() const override{ return m_accept; };
+
+
+
+    /**
+     * @brief Prepare the input model
+     **/
+    virtual std::vector<std::vector<float>> prepare_inputs( const xAOD::TrigRingerRings*, const xAOD::TrigElectron* ) const override;
+
+
+
+    /**
+     * @briel Calculation of model output for fast calorimetry step
+     **/
+    virtual float predict(const xAOD::TrigRingerRings *, std::vector<std::vector<float>> &) const override;
+          
+
+    /**
+     * @brief Accept method
+     **/
+    virtual asg::AcceptData  accept(const xAOD::TrigRingerRings *, float discr, float mu ) const override;
+    
+    
+    virtual asg::AcceptData  accept(const xAOD::IParticle *) const override;
+
+
+  private:
+
+    asg::AcceptInfo m_accept;
+    onnx::RingerSelector m_selector;
+
+    Gaudi::Property<std::string>              m_configFile{this, "ConfigFile", "", "Ringer Run3 Calib Path"};  
+    ServiceHandle< AthONNX::IONNXRuntimeSvc > m_onnxSvc{ this, "ONNXRuntimeSvc", "AthONNX::ONNXRuntimeSvc", "Name of the service to use" };
+
+};
+
+}
+#endif 
diff --git a/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/IAsgRingerSelectorTool.h b/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/IAsgRingerSelectorTool.h
new file mode 100644
index 000000000000..30569962f931
--- /dev/null
+++ b/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/IAsgRingerSelectorTool.h
@@ -0,0 +1,60 @@
+// Dear emacs, this is -*- c++ -*-
+/*
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+*/
+#ifndef RINGERSELECTORTOOLS_IASGRINGERSELECTORTOOL_H
+#define RINGERSELECTORTOOLS_IASGRINGERSELECTORTOOL_H
+
+
+#include "PATCore/IAsgSelectionTool.h"
+#include "PATCore/AcceptData.h"
+#include "PATCore/AcceptInfo.h"
+
+#include "xAODTrigEgamma/TrigElectron.h"
+#include "xAODTrigRinger/TrigRingerRings.h"
+
+
+namespace Ringer {
+  
+  class IAsgRingerSelectorTool : virtual public IAsgSelectionTool
+  {
+
+    ASG_TOOL_INTERFACE(IAsgRingerSelectorTool)
+
+    public:
+
+
+      /** Standard destructor */
+      virtual ~IAsgRingerSelectorTool() {};
+
+      /**
+       * @brief Method to get the plain TAccept for the last particle.
+       **/
+      virtual const asg::AcceptInfo& getAcceptInfo() const = 0;
+
+
+      /**
+       * @brief Prepare the input model
+       **/
+      virtual std::vector<std::vector<float>> prepare_inputs( const xAOD::TrigRingerRings*, const xAOD::TrigElectron* ) const = 0;
+
+
+      /**
+       * @briel Calculation of model output for fast calorimetry step
+       **/
+      virtual float predict(const xAOD::TrigRingerRings *, std::vector<std::vector<float>> &) const = 0;
+            
+
+
+      /**
+       * @brief Accept method
+       **/
+      virtual asg::AcceptData  accept(const xAOD::TrigRingerRings *, float discriminant, float mu ) const=0;
+
+
+
+      virtual asg::AcceptData accept( const xAOD::IParticle* part ) const = 0;
+  };
+}
+
+#endif 
diff --git a/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/Model.h b/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/Model.h
index 4a03db02abb8..4cf107740ece 100644
--- a/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/Model.h
+++ b/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/Model.h
@@ -18,7 +18,7 @@ namespace Ringer{
 
   namespace onnx{
 
-    class Model/*public asg::AsgMessaging*/
+    class Model
     {
       public:
         
diff --git a/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/RingerSelectorTool.h b/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/RingerSelector.h
similarity index 62%
rename from PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/RingerSelectorTool.h
rename to PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/RingerSelector.h
index 9a5f91160ad1..9ba2ba982f81 100644
--- a/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/RingerSelectorTool.h
+++ b/PhysicsAnalysis/RingerSelectorTools/RingerSelectorTools/tools/onnx/RingerSelector.h
@@ -1,8 +1,8 @@
 /*
   Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
-#ifndef RingerSelectorTools_tools_onnx_RingerSelectorTool_h 
-#define RingerSelectorTools_tools_onnx_RingerSelectorTool_h 
+#ifndef RingerSelectorTools_tools_onnx_RingerSelector_h 
+#define RingerSelectorTools_tools_onnx_RingerSelector_h 
 
 
 
@@ -17,7 +17,6 @@
 #include "xAODTrigCalo/TrigEMCluster.h"
 #include "xAODTrigEgamma/TrigElectron.h"
 #include "GaudiKernel/SystemOfUnits.h"
-#include "AthenaMonitoringKernel/MonitoredTimer.h"
 #include <memory>
 #include "TEnv.h"
 
@@ -25,41 +24,40 @@ namespace Ringer {
 
   namespace onnx{
 
-    class RingerSelectorTool : public asg::AsgMessaging
+    class RingerSelector : public asg::AsgMessaging
 
     {
       public:
     
         /** Standard constructor */
-        RingerSelectorTool();
+        RingerSelector( std::string name );
     
         /** Standard destructor */
-        ~RingerSelectorTool()=default;
+        ~RingerSelector()=default;
 
 
         /**
          * @brief read tunings from configuration file
          **/
         StatusCode read_from( std::string, AthONNX::IONNXRuntimeSvc *);
-        
+
+
         /**
-         * @briel Calculation of model output for fast calorimetry step
+         * @brief prepare all inputs
          **/
-        float predict(const xAOD::TrigRingerRings *,
-                      Monitored::Timer<> &propagate_time, Monitored::Timer<> &preproc_time) const;
-              
- 
+        std::vector<std::vector<float>>  prepare_inputs( const xAOD::TrigRingerRings *, const xAOD::TrigElectron *) const;
+
+
         /**
          * @briel Calculation of model output for fast calorimetry step
          **/
-        float predict(const xAOD::TrigRingerRings *, const xAOD::TrigElectron *, 
-                      Monitored::Timer<> &propagate_time, Monitored::Timer<> &preproc_time) const;
+        float predict(const xAOD::TrigRingerRings *, std::vector< std::vector< float > > & ) const;
 
 
         /**
          * @brief Accept method
          **/
-        bool accept(const xAOD::TrigRingerRings *, float discriminant, float mu ) const;
+        bool accept(const xAOD::TrigRingerRings *, float discr, float mu ) const;
     
 
       private:
@@ -68,14 +66,12 @@ namespace Ringer {
         std::vector< Ringer::onnx::Model > m_models;
         /// @brief hold all thresholds definitions
         std::vector< Ringer::onnx::Threshold > m_thresholds;
-
+        /// @brief use shower shapes as second inpit
         bool m_useShowerShapes;
-
+        /// @brief use track as thrird output
         bool m_useTrackVariables;
 
-        /// @brief prepare inputs to apply into the model
-        void prepare_inputs( const xAOD::TrigRingerRings *, const xAOD::TrigElectron * , std::vector< std::vector<float> > &) const;
-        /// @brief parse tenv string into list with type T
+       /// @brief parse tenv string into list with type T
         template <typename T> bool strtof(const std::string& input, T& f);
         /// @brief Get the list of values inside of tenv
         template <typename T>  std::vector<T> GetValues (const std::string& input,  TEnv& env);
diff --git a/PhysicsAnalysis/RingerSelectorTools/Root/AsgRingerSelectorTool.cxx b/PhysicsAnalysis/RingerSelectorTools/Root/AsgRingerSelectorTool.cxx
new file mode 100644
index 000000000000..dbbc7668067e
--- /dev/null
+++ b/PhysicsAnalysis/RingerSelectorTools/Root/AsgRingerSelectorTool.cxx
@@ -0,0 +1,84 @@
+/*
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+*/
+
+
+// Local includes:
+#include "RingerSelectorTools/AsgRingerSelectorTool.h"
+#include "RingerSelectorTools/tools/onnx/RingerSelector.h"
+
+
+namespace Ringer {
+
+
+
+//==============================================================================
+// Standard constructor
+//==============================================================================
+AsgRingerSelectorTool::AsgRingerSelectorTool(std::string name) :
+  AsgTool( name ),
+  m_selector( name )
+{}
+
+AsgRingerSelectorTool::~AsgRingerSelectorTool()
+{}
+
+
+
+//==============================================================================
+// Athena initialize method
+//==============================================================================
+StatusCode AsgRingerSelectorTool::initialize()
+{
+  
+  if( m_selector.read_from( m_configFile, &*m_onnxSvc ).isFailure() ){
+      ATH_MSG_ERROR( "It's not possible to read all tuning files from " << m_configFile );
+      return StatusCode::FAILURE;
+  } 
+  
+  m_accept.addCut("Pass", "Aproved by ringer");
+  return StatusCode::SUCCESS;
+}
+
+
+//==============================================================================
+StatusCode AsgRingerSelectorTool::finalize()
+{
+  return StatusCode::SUCCESS;
+}
+
+
+//==============================================================================
+asg::AcceptData  AsgRingerSelectorTool::accept(const xAOD::IParticle *) const
+{
+  asg::AcceptData acceptData(&m_accept);
+  return acceptData; 
+}
+
+
+// =============================================================================
+asg::AcceptData AsgRingerSelectorTool::accept( const xAOD::TrigRingerRings *ringerShape, float discr, float mu ) const
+{
+  asg::AcceptData acceptData(&m_accept);
+  bool pass = m_selector.accept( ringerShape, discr, mu );
+  acceptData.setCutResult("Pass", pass); 
+  return acceptData;
+}
+
+
+// =============================================================================
+float AsgRingerSelectorTool::predict( const xAOD::TrigRingerRings* ringerShape, std::vector<std::vector<float>> &inputs ) const 
+{
+  return m_selector.predict( ringerShape , inputs);
+}
+
+
+std::vector< std::vector<float> > AsgRingerSelectorTool::prepare_inputs( const xAOD::TrigRingerRings* ringerShape,
+                                                                         const xAOD::TrigElectron *el) const
+{
+  return m_selector.prepare_inputs( ringerShape, el );
+}
+
+
+
+}// namespace
diff --git a/PhysicsAnalysis/RingerSelectorTools/src/onnx/Model.cxx b/PhysicsAnalysis/RingerSelectorTools/Root/tools/onnx/Model.cxx
similarity index 98%
rename from PhysicsAnalysis/RingerSelectorTools/src/onnx/Model.cxx
rename to PhysicsAnalysis/RingerSelectorTools/Root/tools/onnx/Model.cxx
index 7850f3be74b4..9a25d310923c 100644
--- a/PhysicsAnalysis/RingerSelectorTools/src/onnx/Model.cxx
+++ b/PhysicsAnalysis/RingerSelectorTools/Root/tools/onnx/Model.cxx
@@ -11,7 +11,6 @@ namespace Ringer{
 
     Model::Model( std::string modelPath, AthONNX::IONNXRuntimeSvc *svc,
                   float etmin, float etmax, float etamin, float etamax):
-      //asg::AsgMessaging("Model"),
       m_etmin(etmin),
       m_etmax(etmax),
       m_etamin(etamin),
diff --git a/PhysicsAnalysis/RingerSelectorTools/src/onnx/RingerSelectorTool.cxx b/PhysicsAnalysis/RingerSelectorTools/Root/tools/onnx/RingerSelector.cxx
similarity index 69%
rename from PhysicsAnalysis/RingerSelectorTools/src/onnx/RingerSelectorTool.cxx
rename to PhysicsAnalysis/RingerSelectorTools/Root/tools/onnx/RingerSelector.cxx
index 0197c97c7ade..5d33a4afbcf7 100644
--- a/PhysicsAnalysis/RingerSelectorTools/src/onnx/RingerSelectorTool.cxx
+++ b/PhysicsAnalysis/RingerSelectorTools/Root/tools/onnx/RingerSelector.cxx
@@ -3,12 +3,11 @@
 */
 
 // Local includes:
-#include "RingerSelectorTools/tools/onnx/RingerSelectorTool.h"
+#include "RingerSelectorTools/tools/onnx/RingerSelector.h"
 #include "PathResolver/PathResolver.h"
 #include <algorithm>
 #include "TEnv.h"
 
-using namespace Monitored;
 
 
 namespace Ringer{
@@ -17,13 +16,13 @@ namespace Ringer{
 
 
     //==============================================================================
-    RingerSelectorTool::RingerSelectorTool():
-      asg::AsgMessaging("RingerSelectorTool")
+    RingerSelector::RingerSelector(std::string name):
+      asg::AsgMessaging(name)
     {;}
     
 
     //==============================================================================
-    StatusCode RingerSelectorTool::read_from( std::string path , AthONNX::IONNXRuntimeSvc *svc )
+    StatusCode RingerSelector::read_from( std::string path , AthONNX::IONNXRuntimeSvc *svc )
     {
 
       std::string configFile = PathResolverFindCalibFile( path );
@@ -61,8 +60,7 @@ namespace Ringer{
         // Loop over all models
         for ( unsigned idx = 0; idx < size; ++idx ){
           std::string modelPath = PathResolverFindCalibFile( basepath+"/"+model_paths[idx] );
-          //std::string modelPath = basepath+"/"+model_paths[idx];
-          ATH_MSG_INFO( "Reading Onnx model from: " << modelPath );
+          ATH_MSG_DEBUG( "Reading Onnx model from: " << modelPath );
           auto model = Ringer::onnx::Model( modelPath, svc, etmin[idx], etmax[idx], etamin[idx], etamax[idx]) ;
           
           // Compile the model
@@ -108,91 +106,18 @@ namespace Ringer{
     }
 
 
-    //==============================================================================
-    float RingerSelectorTool::predict(const xAOD::TrigRingerRings *ringerShape, const xAOD::TrigElectron *el ,
-                                      Monitored::Timer<> &propagate_time, Monitored::Timer<> &preproc_time) const
-    {
-      float et = ringerShape->emCluster()->et()/Gaudi::Units::GeV;
-      float eta = std::min( std::abs(ringerShape->emCluster()->eta()), float(2.5) );
- 
-      // Find the correct model and predict
-      for( auto& model : m_models ){
-        
-        ATH_MSG_DEBUG("model_Etmin: "<<model.etMin()<<" model_Etmax: "<<model.etMax());
-        if(et<=model.etMin() || et > model.etMax()) continue;
-        if(eta<=model.etaMin() || eta > model.etaMax()) continue;
-        
-        ATH_MSG_DEBUG("Event Et: "<< et <<" is between model Et_min: "<< model.etMin() <<" and model Et_max: "<<model.etMax());
-        ATH_MSG_DEBUG("Event eta: "<< eta <<" is between model eta_min: "<< model.etaMin() <<" and model eta_max: "<<model.etaMax());
-        std::vector< std::vector<float> > inputs;
-                    
-        preproc_time.start();
-        prepare_inputs( ringerShape, el, inputs );
-        preproc_time.stop();
-
-        propagate_time.start();
-        auto output = model.predict( inputs );       
-        propagate_time.stop();
-        
-        ATH_MSG_DEBUG( "The current model predict with output: " << output );
-        return output;
-      }
-
-      return -999;
-    }
-
-
-
-    //==============================================================================
-    float RingerSelectorTool::predict(const xAOD::TrigRingerRings *ringerShape , Monitored::Timer<> &propagate_time, 
-                                      Monitored::Timer<> &preproc_time ) const
-    {
-      float et = ringerShape->emCluster()->et()/Gaudi::Units::GeV;
-      float eta = std::min( std::abs(ringerShape->emCluster()->eta()), float(2.5));
- 
-      // Find the correct model and predict
-      for( auto& model : m_models ){
-        ATH_MSG_DEBUG("model_Etmin: "<<model.etMin()<<" model_Etmax: "<<model.etMax());
-        
-        if(et<=model.etMin() || et > model.etMax()) continue;
-        if(eta<=model.etaMin() || eta > model.etaMax()) continue;
- 
-        
-        ATH_MSG_DEBUG("Event Et: "<< et <<" is between model Et_min: "<< model.etMin() <<" and model Et_max: "<<model.etMax());
-        ATH_MSG_DEBUG("Event eta: "<< eta <<" is between model eta_min: "<< model.etaMin() <<" and model eta_max: "<<model.etaMax());
-        std::vector< std::vector<float> > inputs;
-        
-        preproc_time.start();
-        prepare_inputs( ringerShape, nullptr, inputs );
-        preproc_time.stop();
-
-        propagate_time.start();
-        auto output = model.predict( inputs );       
-        propagate_time.stop();
-
-        ATH_MSG_DEBUG( "The current model predict with output: " << output );
-        return output;
-      }
-
-      return -999;
-    }
-
-
-
    
     //==============================================================================
-    bool RingerSelectorTool::accept( const xAOD::TrigRingerRings *ringerShape, float discriminant, float avgmu ) const 
+    bool RingerSelector::accept( const xAOD::TrigRingerRings *ringerShape, float discr, float avgmu ) const 
     {
       float et = ringerShape->emCluster()->et()/Gaudi::Units::GeV;
       float eta = std::min( std::abs(ringerShape->emCluster()->eta()), float(2.5));
     
-      ATH_MSG_DEBUG( "Event et = "<< et << ", eta = " << eta );
+      ATH_MSG_INFO( "Event et = "<< et << ", eta = " << eta );
       for( auto& cutDef : m_thresholds ){
         if ( et <= cutDef.etMin() || et > cutDef.etMax() ) continue;
         if ( eta <= cutDef.etaMin() || eta > cutDef.etaMax() ) continue;
-        ATH_MSG_DEBUG( "Output = " << discriminant << " Avgmu = " << avgmu );
-        ATH_MSG_DEBUG( "Passed ? " << cutDef.accept( discriminant, avgmu ) );
-        return cutDef.accept( discriminant, avgmu );
+        return cutDef.accept( discr, avgmu );
       }// loop over all thresholds
     
       return false;
@@ -200,10 +125,10 @@ namespace Ringer{
 
 
     //==============================================================================
-    void RingerSelectorTool::prepare_inputs(  const xAOD::TrigRingerRings *ringerShape, 
-                                              const xAOD::TrigElectron *el, 
-                                              std::vector<std::vector<float>>&inputs ) const
+    std::vector<std::vector<float>> RingerSelector::prepare_inputs(  const xAOD::TrigRingerRings *ringerShape, 
+                                                                     const xAOD::TrigElectron *el ) const
     {
+      std::vector< std::vector< float > > inputs;
       const std::vector<float> rings = ringerShape->rings();
       std::vector<float> refRings(rings.size());
       refRings.assign(rings.begin(), rings.end());
@@ -256,11 +181,36 @@ namespace Ringer{
         inputs.push_back( refTrack );
       }
 
+      return inputs;
     }
 
 
     //==============================================================================
-    template <typename T> bool RingerSelectorTool::strtof(const std::string& input, T& f)
+    float RingerSelector::predict(const xAOD::TrigRingerRings *ringerShape , std::vector<std::vector<float>> &inputs ) const
+    {
+      float et = ringerShape->emCluster()->et()/Gaudi::Units::GeV;
+      float eta = std::min( std::abs(ringerShape->emCluster()->eta()), float(2.5));
+ 
+      // Find the correct model and predict
+      for( auto& model : m_models ){
+        
+        if(et<=model.etMin() || et > model.etMax()) continue;
+        if(eta<=model.etaMin() || eta > model.etaMax()) continue;
+
+        auto output = model.predict( inputs );       
+
+        ATH_MSG_INFO( "The current model predict with output: " << output );
+        return output;
+      }
+
+      return -999;
+    }
+
+
+
+
+    //==============================================================================
+    template <typename T> bool RingerSelector::strtof(const std::string& input, T& f)
     {  
       int diff = 0 ;
       std::string tmp = input;
@@ -291,7 +241,7 @@ namespace Ringer{
 
 
     //==============================================================================
-    template <typename T>  std::vector<T> RingerSelectorTool::GetValues (const std::string& input,  TEnv& env)
+    template <typename T>  std::vector<T> RingerSelector::GetValues (const std::string& input,  TEnv& env)
     {    
       std::vector<T> CutVector;    
       std::string env_input(env.GetValue(input.c_str(), ""));
@@ -313,7 +263,7 @@ namespace Ringer{
 
 
     //==============================================================================
-    std::vector<std::string> RingerSelectorTool::GetPaths(const std::string& input, TEnv& env)
+    std::vector<std::string> RingerSelector::GetPaths(const std::string& input, TEnv& env)
     {
       std::vector<std::string> CutVector;    
       std::string env_input(env.GetValue(input.c_str(), ""));
diff --git a/PhysicsAnalysis/RingerSelectorTools/src/onnx/Threshold.cxx b/PhysicsAnalysis/RingerSelectorTools/Root/tools/onnx/Threshold.cxx
similarity index 100%
rename from PhysicsAnalysis/RingerSelectorTools/src/onnx/Threshold.cxx
rename to PhysicsAnalysis/RingerSelectorTools/Root/tools/onnx/Threshold.cxx
diff --git a/PhysicsAnalysis/RingerSelectorTools/src/components/RingerSelectorTools_entries.cxx b/PhysicsAnalysis/RingerSelectorTools/src/components/RingerSelectorTools_entries.cxx
index d946cebf44eb..b744897d18c1 100644
--- a/PhysicsAnalysis/RingerSelectorTools/src/components/RingerSelectorTools_entries.cxx
+++ b/PhysicsAnalysis/RingerSelectorTools/src/components/RingerSelectorTools_entries.cxx
@@ -1,7 +1,9 @@
 #include "RingerSelectorTools/AsgElectronRingerSelector.h"
+#include "RingerSelectorTools/AsgRingerSelectorTool.h"
 
 using namespace Ringer;
 
 DECLARE_COMPONENT( AsgElectronRingerSelector )
-//DECLARE_COMPONENT( AsgPhotonRingerSelector )
+DECLARE_COMPONENT( AsgRingerSelectorTool )
+
 
diff --git a/Trigger/TrigHypothesis/TrigEgammaHypo/python/TrigEgammaFastCaloHypoTool.py b/Trigger/TrigHypothesis/TrigEgammaHypo/python/TrigEgammaFastCaloHypoTool.py
index b3da03b4d471..674b4921e4d9 100644
--- a/Trigger/TrigHypothesis/TrigEgammaHypo/python/TrigEgammaFastCaloHypoTool.py
+++ b/Trigger/TrigHypothesis/TrigEgammaHypo/python/TrigEgammaFastCaloHypoTool.py
@@ -239,9 +239,13 @@ class TrigEgammaFastCaloHypoToolConfig:
        raise RuntimeError( "Bad selection name: %s" % self.pidname() )
     
     if self.__useRun3:
+      from RingerSelectorTools.RingerSelectorToolsConf import Ringer__AsgRingerSelectorTool
       basepath = 'RingerSelectorTools/TrigL2_20210227_r3'
       self.__log.info('Ringer version: %s', basepath)
-      return basepath+ '/ElectronRinger{OP}TriggerConfig.conf'.format(OP=possibleSel[self.pidname()] )
+      basepath += basepath+ '/ElectronRinger{OP}TriggerConfig.conf'.format(OP=possibleSel[self.pidname()] )
+      selector = Ringer__AsgRingerSelectorTool( "Ringer"+possibleSel[self.pidname()] )
+      selector.ConfigFile = basepath
+      self.tool().RingerSelector = selector
 
     else:
       basepath = 'RingerSelectorTools/TrigL2_20180903_v9'
diff --git a/Trigger/TrigHypothesis/TrigEgammaHypo/src/TrigEgammaFastCaloHypoToolInc.cxx b/Trigger/TrigHypothesis/TrigEgammaHypo/src/TrigEgammaFastCaloHypoToolInc.cxx
index c13dc6cb356d..435234bb5c7e 100644
--- a/Trigger/TrigHypothesis/TrigEgammaHypo/src/TrigEgammaFastCaloHypoToolInc.cxx
+++ b/Trigger/TrigHypothesis/TrigEgammaHypo/src/TrigEgammaFastCaloHypoToolInc.cxx
@@ -19,7 +19,6 @@ TrigEgammaFastCaloHypoToolInc::TrigEgammaFastCaloHypoToolInc( const std::string&
   : base_class( type, name, parent ),
     m_decisionId( HLT::Identifier::fromToolName( name ) ) ,
     m_selectorTool(),
-    m_onnxSelectorTool(),
     m_lumiBlockMuTool("LumiBlockMuTool/LumiBlockMuTool")
 {
   declareProperty("LumiBlockMuTool", m_lumiBlockMuTool, "Luminosity Tool" );
@@ -78,10 +77,7 @@ StatusCode TrigEgammaFastCaloHypoToolInc::initialize()  {
 
     if( m_useRun3 ){
       ATH_MSG_INFO( "Using the new Onnx ringer selector for Run3" );
-      if( m_onnxSelectorTool.read_from( m_configFile, &*m_onnxSvc ).isFailure() ){
-        ATH_MSG_ERROR( "It's not possible to read all tuning files from " << m_configFile );
-        return StatusCode::FAILURE;
-      } 
+      CHECK( m_ringerTool.retrieve() );
 
     }else{// Run2
       m_selectorTool.setConstantsCalibPath( m_constantsCalibPath ); 
@@ -373,11 +369,8 @@ bool TrigEgammaFastCaloHypoToolInc::decide_ringer ( const ITrigEgammaFastCaloHyp
     return false;
   }
 
-  float eta     = std::fabs(emCluster->eta());
   float et      = emCluster->et() / Gaudi::Units::GeV;
   float avgmu   = m_lumiBlockMuTool->averageInteractionsPerCrossing();
-  
-  if(eta>2.50) eta=2.50;///fix for events out of the ranger
 
   // make sure that monitoring histogram will plotting only the events of chain.
   ///Et threshold
@@ -392,7 +385,15 @@ bool TrigEgammaFastCaloHypoToolInc::decide_ringer ( const ITrigEgammaFastCaloHyp
   float output;
 
   if (m_useRun3){
-    output = m_onnxSelectorTool.predict( ringerShape, propagate_time, preproc_time );
+    
+    preproc_time.start();
+    auto inputs = m_ringerTool->prepare_inputs( ringerShape , nullptr);
+    preproc_time.stop();
+    
+    propagate_time.start();
+    output = m_ringerTool->predict( ringerShape, inputs );
+    propagate_time.stop();
+
   }else{
     const std::vector<float> rings = ringerShape->rings();
     std::vector<float> refRings(rings.size());
@@ -407,9 +408,10 @@ bool TrigEgammaFastCaloHypoToolInc::decide_ringer ( const ITrigEgammaFastCaloHyp
 
   decide_time.start();
   if (m_useRun3){
-    accept = m_onnxSelectorTool.accept(ringerShape, output, avgmu);
+    accept = bool( m_ringerTool->accept(ringerShape, output, avgmu) );
+    ATH_MSG_DEBUG(name()<< " Accept? " <<  (accept?"Yes":"No") );
   }else{
-    accept = m_selectorTool.accept(output, emCluster->et(),emCluster->eta(),avgmu);
+    accept = m_selectorTool.accept(output, emCluster->et(),emCluster->eta(),avgmu) ;
   }
   decide_time.stop();
 
diff --git a/Trigger/TrigHypothesis/TrigEgammaHypo/src/TrigEgammaFastCaloHypoToolInc.h b/Trigger/TrigHypothesis/TrigEgammaHypo/src/TrigEgammaFastCaloHypoToolInc.h
index 80837eb30355..991098412b64 100644
--- a/Trigger/TrigHypothesis/TrigEgammaHypo/src/TrigEgammaFastCaloHypoToolInc.h
+++ b/Trigger/TrigHypothesis/TrigEgammaHypo/src/TrigEgammaFastCaloHypoToolInc.h
@@ -5,14 +5,13 @@
 #define TRIGEGAMMAHYPO_TRIGEGAMMAFASTCALOHYPOTOOLINC_H 1
 
 #include "xAODTrigCalo/TrigEMCluster.h"
-
 #include "xAODTrigRinger/TrigRingerRings.h"
+#include "TrigSteeringEvent/TrigRoiDescriptor.h"
+
 #include "TrigMultiVarHypo/tools/RingerSelectorTool.h"
-#include "RingerSelectorTools/tools/onnx/RingerSelectorTool.h"
-#include "AthOnnxruntimeService/IONNXRuntimeSvc.h"
+#include "RingerSelectorTools/IAsgRingerSelectorTool.h"
 #include "LumiBlockComps/ILumiBlockMuTool.h"
 
-#include "TrigSteeringEvent/TrigRoiDescriptor.h"
 #include "AthenaBaseComps/AthAlgTool.h"
 #include "AthenaMonitoringKernel/GenericMonitoringTool.h"
 #include "TrigCompositeUtils/HLTIdentifier.h"
@@ -50,7 +49,6 @@ class TrigEgammaFastCaloHypoToolInc : public extends<AthAlgTool, ITrigEgammaFast
 
     HLT::Identifier m_decisionId;
     Ringer::RingerSelectorTool        m_selectorTool;
-    Ringer::onnx::RingerSelectorTool  m_onnxSelectorTool;
     ToolHandle<ILumiBlockMuTool>      m_lumiBlockMuTool;
 
     
@@ -80,8 +78,8 @@ class TrigEgammaFastCaloHypoToolInc : public extends<AthAlgTool, ITrigEgammaFast
  
 
     ToolHandle< GenericMonitoringTool >       m_monTool{ this, "MonTool", "", "Monitoring tool" };
-    ServiceHandle< AthONNX::IONNXRuntimeSvc > m_onnxSvc{ this, "ONNXRuntimeSvc", "AthONNX::ONNXRuntimeSvc", "Name of the service to use" };
-    
+    ToolHandle<Ringer::IAsgRingerSelectorTool>m_ringerTool{ this, "RingerSelector", "", "Ringer tool" };
+
 
 }; 
 
-- 
GitLab