From 869aba38334aaca25996ddc3be3423d7be15ea22 Mon Sep 17 00:00:00 2001
From: Ryan Mackenzie White <ryan.white@cern.ch>
Date: Tue, 21 Jul 2015 16:02:10 +0200
Subject: [PATCH] no trigemcluster for rootcore
 (TrigEgammaMatchingTool-00-00-07)

---
 .../Root/TrigEgammaMatchingTool.cxx           | 515 ++++++++++++++++++
 .../ITrigEgammaMatchingTool.h                 |  45 ++
 .../TrigEgammaMatchingTool.h                  |  61 +++
 .../cmt/Makefile.RootCore                     |  17 +
 .../TrigEgammaMatchingTool/cmt/requirements   |  30 +
 .../share/testTrigEgammaMatchingTool.py       |  95 ++++
 .../src/TrigEgammaMatchingToolTest.cxx        | 165 ++++++
 .../src/TrigEgammaMatchingToolTest.h          |  50 ++
 .../TrigEgammaMatchingTool_entries.cxx        |  12 +
 .../TrigEgammaMatchingTool_load.cxx           |   3 +
 10 files changed, 993 insertions(+)
 create mode 100644 Trigger/TrigAnalysis/TrigEgammaMatchingTool/Root/TrigEgammaMatchingTool.cxx
 create mode 100644 Trigger/TrigAnalysis/TrigEgammaMatchingTool/TrigEgammaMatchingTool/ITrigEgammaMatchingTool.h
 create mode 100644 Trigger/TrigAnalysis/TrigEgammaMatchingTool/TrigEgammaMatchingTool/TrigEgammaMatchingTool.h
 create mode 100644 Trigger/TrigAnalysis/TrigEgammaMatchingTool/cmt/Makefile.RootCore
 create mode 100644 Trigger/TrigAnalysis/TrigEgammaMatchingTool/cmt/requirements
 create mode 100755 Trigger/TrigAnalysis/TrigEgammaMatchingTool/share/testTrigEgammaMatchingTool.py
 create mode 100644 Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/TrigEgammaMatchingToolTest.cxx
 create mode 100644 Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/TrigEgammaMatchingToolTest.h
 create mode 100644 Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/components/TrigEgammaMatchingTool_entries.cxx
 create mode 100644 Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/components/TrigEgammaMatchingTool_load.cxx

diff --git a/Trigger/TrigAnalysis/TrigEgammaMatchingTool/Root/TrigEgammaMatchingTool.cxx b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/Root/TrigEgammaMatchingTool.cxx
new file mode 100644
index 00000000000..9f1720f3c47
--- /dev/null
+++ b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/Root/TrigEgammaMatchingTool.cxx
@@ -0,0 +1,515 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "TrigEgammaMatchingTool/TrigEgammaMatchingTool.h"
+
+
+#ifdef ROOTCORE
+#include "xAODRootAccess/Init.h"
+#include "xAODRootAccess/TEvent.h"
+#include "xAODRootAccess/tools/ReturnCheck.h"
+#endif // ROOTCORE
+
+
+namespace Trig {
+    TrigEgammaMatchingTool::TrigEgammaMatchingTool( const std::string& name )
+        : asg::AsgMetadataTool( name ),
+        m_trigDecTool("Trig::TrigDecisionTool/TrigDecisionTool")
+    {
+        declareProperty( "TriggerTool", m_trigDecTool);
+        declareProperty( "DeltaR", m_dR=0.07);
+        declareProperty( "L1DeltaR", m_dRL1=0.15);
+    }
+
+    TrigEgammaMatchingTool::~TrigEgammaMatchingTool(){
+    }
+
+    StatusCode TrigEgammaMatchingTool::finalize() {
+        return StatusCode::SUCCESS;
+    }
+
+    StatusCode TrigEgammaMatchingTool::execute() {
+        return StatusCode::SUCCESS;
+    }
+
+    StatusCode TrigEgammaMatchingTool::initialize() {
+        // Greet the user:
+        ATH_MSG_INFO( "Initialising... " );
+
+        ATH_CHECK(m_trigDecTool.retrieve());
+
+        return StatusCode::SUCCESS;
+    }
+
+    double TrigEgammaMatchingTool::dR(const double eta1, const double phi1, const double eta2, const double phi2){
+        double deta = fabs(eta1 - eta2);
+        double dphi = fabs(phi1 - phi2) < TMath::Pi() ? fabs(phi1 - phi2) : 2*TMath:: \
+                      Pi() - fabs(phi1 - phi2);
+        return sqrt(deta*deta + dphi*dphi);
+    }
+
+    /*! Calls match with a FeatureContainer for a given triggerfor HLT only 
+     * Note does not use DeactiviateTEs
+     * Returns closest EF object to offline object 
+     * Requires TrigPassBits only works in Athena*/ 
+    const xAOD::Egamma* TrigEgammaMatchingTool::closestHLTObject(const xAOD::Egamma *eg,const std::string trigger){
+
+        if(eg==NULL) {
+            ATH_MSG_DEBUG("NULL Offline object");
+            return false;
+        }
+        Trig::FeatureContainer fc = m_trigDecTool->features(trigger);
+        double deltaR=0.;
+        double dRMax = 100;
+        const xAOD::Electron *elEF = 0;
+        const xAOD::Photon *phEF = 0;
+        if(eg->type()==xAOD::Type::Electron){
+            const xAOD::Electron* elOff =static_cast<const xAOD::Electron*> (eg);
+            const std::vector< Trig::Feature<xAOD::ElectronContainer> > vec = fc.get<xAOD::ElectronContainer>("egamma_Electrons");
+            
+            for(auto feat : vec){
+                const xAOD::ElectronContainer *cont = feat.cptr();
+                if(cont == NULL) {
+                    ATH_MSG_DEBUG("Electron container from TE NULL");
+                    continue;
+                }
+                for(const auto& el : *cont){
+                    if(el == NULL) {
+                        ATH_MSG_DEBUG("Electron from TE NULL");
+                        continue;
+                    }
+                    deltaR = dR(elOff->trackParticle()->eta(),elOff->trackParticle()->phi(), el->trackParticle()->eta(),el->trackParticle()->phi()); 
+                    if (deltaR < dRMax) {
+                        dRMax = deltaR;
+                        elEF =el;
+                    }
+                }
+            }
+            if(dRMax < m_dR) return elEF;
+        }
+        else if(eg->type()==xAOD::Type::Photon){
+            const xAOD::Photon* phOff =static_cast<const xAOD::Photon*> (eg);
+            const std::vector< Trig::Feature<xAOD::PhotonContainer> > vec = fc.get<xAOD::PhotonContainer>("egamma_Photons");
+            for(auto feat : vec){
+                const xAOD::PhotonContainer *cont = feat.cptr();
+                if(cont == NULL) {
+                    ATH_MSG_DEBUG("Photon Container from TE NULL");
+                    continue;
+                }
+                for(const auto& ph : *cont){
+                    if(ph == NULL) {
+                        ATH_MSG_DEBUG("Photon from TE NULL");
+                        continue;
+                    }
+                    deltaR = dR(phOff->caloCluster()->eta(),phOff->caloCluster()->phi(), ph->caloCluster()->eta(),ph->caloCluster()->phi()); 
+                    if (deltaR < dRMax) {
+                        dRMax = deltaR;
+                        phEF =ph;
+                    }
+                }
+            }
+            if(dRMax < m_dR) return phEF;
+        }
+        return 0; // No match
+    }
+
+    /*! Calls match with a FeatureContainer for a given triggerfor HLT only 
+     * Note does not use DeactiviateTEs */ 
+    bool TrigEgammaMatchingTool::matchHLT(const xAOD::Egamma *eg,const std::string trigger){
+
+        Trig::FeatureContainer fc = m_trigDecTool->features(trigger);
+        double deltaR=0.; 
+        if(eg->type()==xAOD::Type::Electron){
+            const xAOD::Electron* elOff =static_cast<const xAOD::Electron*> (eg);
+#ifdef XAOD_ANALYSIS
+            const auto vec = fc.containerFeature<xAOD::ElectronContainer>("egamma_Electrons");
+#else
+            const auto vec = fc.get<xAOD::ElectronContainer>("egamma_Electrons");
+#endif // XAOD_ANALYSIS
+            for(auto feat : vec){
+                const xAOD::ElectronContainer *cont = feat.cptr();
+                if(cont == NULL) {
+                    ATH_MSG_DEBUG("Electron container from TE NULL");
+                    continue;
+                }
+                for(const auto& el : *cont){
+                    if(el == NULL) {
+                        ATH_MSG_WARNING("Electron from TE NULL");
+                        continue;
+                    }
+                    if(el->trackParticle() && elOff->trackParticle())
+                        deltaR = dR(elOff->trackParticle()->eta(),elOff->trackParticle()->phi(), el->trackParticle()->eta(),el->trackParticle()->phi()); 
+                    else
+                        deltaR = dR(elOff->eta(),elOff->phi(), el->eta(),el->phi());
+                    if(deltaR < m_dR){
+                        return true;
+                    }
+                }
+            }
+        }
+        else if(eg->type()==xAOD::Type::Photon){
+            const xAOD::Photon* phOff =static_cast<const xAOD::Photon*> (eg);
+#ifdef XAOD_ANALYSIS
+            const auto vec = fc.containerFeature<xAOD::PhotonContainer>("egamma_Photons");
+#else
+            const auto vec = fc.get<xAOD::PhotonContainer>("egamma_Photons");
+#endif // XAOD_ANALYSIS
+            for(auto feat : vec){
+                const xAOD::PhotonContainer *cont = feat.cptr();
+                if(cont == NULL) {
+                    ATH_MSG_DEBUG("Photon Container from TE NULL");
+                    continue;
+                }
+                for(const auto& ph : *cont){
+                    if(ph == NULL) {
+                        ATH_MSG_DEBUG("Photon from TE NULL");
+                        continue;
+                    }
+                    if(ph->caloCluster() && phOff->caloCluster())
+                        deltaR = dR(phOff->caloCluster()->eta(),phOff->caloCluster()->phi(), ph->caloCluster()->eta(),ph->caloCluster()->phi()); 
+                    else
+                        deltaR = dR(phOff->eta(),phOff->phi(), ph->eta(),ph->phi());
+                    if(deltaR < m_dR){
+                        return true;
+                    }
+                }
+            }
+        }
+        return false; // No match
+    }
+
+    bool TrigEgammaMatchingTool::matchHLTPhoton(const xAOD::Photon *eg,const std::string trigger,const HLT::TriggerElement*& finalFC){
+        finalFC=NULL;
+        ATH_MSG_DEBUG("Match HLT Photon");
+        // Get the container of online electrons associated to passed items
+        auto fc = (m_trigDecTool->features(trigger,TrigDefs::alsoDeactivateTEs));
+
+#ifdef XAOD_ANALYSIS
+        const auto vec = fc.containerFeature<xAOD::PhotonContainer>("egamma_Photons",TrigDefs::alsoDeactivateTEs);
+#else
+        const auto vec = fc.get<xAOD::PhotonContainer>("egamma_Photons",TrigDefs::alsoDeactivateTEs);
+#endif // XAOD_ANALYSIS
+        ATH_MSG_DEBUG("EF FC Size " << vec.size());
+        double deltaR=0.; 
+        for(auto feat : vec){
+            const xAOD::PhotonContainer *cont = feat.cptr();
+            if(cont == NULL) {
+                ATH_MSG_DEBUG("Photon Container from TE NULL");
+                continue;
+            }
+            ATH_MSG_DEBUG("EF Size " << cont->size());
+            for(const auto& ph : *cont){
+                if(ph == NULL) {
+                    ATH_MSG_DEBUG("Photon from TE NULL");
+                    continue;
+                }
+                deltaR = dR(eg->caloCluster()->eta(),eg->caloCluster()->phi(), ph->caloCluster()->eta(),ph->caloCluster()->phi()); 
+                if(deltaR < m_dR){
+                    finalFC = (feat.te());
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    bool TrigEgammaMatchingTool::matchHLTElectron(const xAOD::Electron *eg,const std::string trigger,const HLT::TriggerElement*& finalFC){
+        ATH_MSG_DEBUG("Match HLT electron");
+        finalFC=NULL;
+        // Get the container of online electrons associated to passed items
+        auto fc = (m_trigDecTool->features(trigger,TrigDefs::alsoDeactivateTEs));
+
+#ifdef XAOD_ANALYSIS
+            const auto vec = fc.containerFeature<xAOD::ElectronContainer>("egamma_Electrons",TrigDefs::alsoDeactivateTEs);
+#else
+            const auto vec = fc.get<xAOD::ElectronContainer>("egamma_Electrons",TrigDefs::alsoDeactivateTEs);
+#endif // XAOD_ANALYSIS
+        ATH_MSG_DEBUG("EF FC Size " << vec.size());
+        double deltaR=0.; 
+        for(auto feat : vec){
+            const xAOD::ElectronContainer *cont = feat.cptr();
+            if(cont == NULL) {
+                ATH_MSG_WARNING("Electron Container from TE NULL");
+                continue;
+            }
+            ATH_MSG_DEBUG("EF Size " << cont->size());
+            for(const auto& el : *cont){
+                if(el == NULL) {
+                    ATH_MSG_DEBUG("Electron from TE NULL");
+                    continue;
+                }
+                deltaR = dR(eg->trackParticle()->eta(),eg->trackParticle()->phi(), el->trackParticle()->eta(),el->trackParticle()->phi()); 
+                if(deltaR < m_dR){
+                    finalFC = (feat.te());
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    bool TrigEgammaMatchingTool::matchHLTCalo(const xAOD::Egamma *eg,const std::string trigger,const HLT::TriggerElement*& finalFC){
+        ATH_MSG_DEBUG("Match HLT CaloCluster");
+        finalFC=NULL;
+        auto fc = (m_trigDecTool->features(trigger,TrigDefs::alsoDeactivateTEs));
+#ifdef XAOD_ANALYSIS
+            const auto vec = fc.containerFeature<xAOD::CaloClusterContainer>("TrigEFCaloCalibFex",TrigDefs::alsoDeactivateTEs);
+#else
+             const auto vec = fc.get<xAOD::CaloClusterContainer>("TrigEFCaloCalibFex",TrigDefs::alsoDeactivateTEs);
+#endif // XAOD_ANALYSIS
+        
+        ATH_MSG_DEBUG("EFCal  FC Size " << vec.size());
+        double deltaR=0.;
+        for(auto feat : vec){
+            const xAOD::CaloClusterContainer *cont = feat.cptr();
+            ATH_MSG_DEBUG("EF Calo Size " << cont->size());
+            if(cont == NULL) {
+                ATH_MSG_DEBUG("CaloCluster Container from TE NULL");
+                continue;
+            }
+            for(const auto& clus : *cont){
+                if(clus == NULL) {
+                    ATH_MSG_DEBUG("CaloCluster from TE NULL");
+                    continue;
+                }
+                if(eg->type()==xAOD::Type::Electron){
+                    const xAOD::Electron* el =static_cast<const xAOD::Electron*> (eg);
+                    deltaR = dR(el->trackParticle()->eta(),el->trackParticle()->phi(), clus->eta(),clus->phi());
+                }
+                else if (eg->type()==xAOD::Type::Photon)
+                    deltaR = dR(eg->caloCluster()->eta(),eg->caloCluster()->phi(), clus->eta(),clus->phi());
+                if(deltaR < m_dR){
+                    finalFC = (feat.te());
+                    return true;
+                }
+            }
+        }
+        return false;
+
+    }
+
+    bool TrigEgammaMatchingTool::matchL2Photon(const xAOD::Photon *eg,const std::string trigger,const HLT::TriggerElement*& finalFC){
+        finalFC=NULL;
+        ATH_MSG_DEBUG("Match L2 Photon");
+        auto fc = (m_trigDecTool->features(trigger,TrigDefs::alsoDeactivateTEs));
+
+#ifdef XAOD_ANALYSIS
+        auto vec = fc.containerFeature<xAOD::TrigPhotonContainer>("",TrigDefs::alsoDeactivateTEs);
+#else
+        auto vec = fc.get<xAOD::TrigPhotonContainer>("",TrigDefs::alsoDeactivateTEs);
+#endif
+        ATH_MSG_DEBUG("L2 FC Size " << vec.size());
+        double deltaR=0.;
+        for(auto feat : vec){
+            const xAOD::TrigPhotonContainer *cont = feat.cptr();
+            if(cont == NULL) {
+                ATH_MSG_WARNING("TrigPhoton Container from TE NULL");
+                continue;
+            }
+            ATH_MSG_DEBUG("L2 Size " << cont->size());
+            for(const auto& l2 : *cont){
+                if(l2 == NULL) {
+                    ATH_MSG_DEBUG("TrigElectron from TE NULL");
+                    continue;
+                }
+                deltaR = dR(eg->caloCluster()->eta(),eg->caloCluster()->phi(), l2->eta(),l2->phi()); 
+                if(deltaR < m_dR){
+                    finalFC = (feat.te());
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    bool TrigEgammaMatchingTool::matchL2Electron(const xAOD::Electron *eg,const std::string trigger,const HLT::TriggerElement*& finalFC){
+        finalFC=NULL;
+        ATH_MSG_DEBUG("Match L2 Electron");
+        auto fc = (m_trigDecTool->features(trigger,TrigDefs::alsoDeactivateTEs));
+#ifdef XAOD_ANALYSIS
+        auto vec = fc.containerFeature<xAOD::TrigElectronContainer>("",TrigDefs::alsoDeactivateTEs);
+#else
+        auto vec = fc.get<xAOD::TrigElectronContainer>("",TrigDefs::alsoDeactivateTEs);
+#endif
+        ATH_MSG_DEBUG("L2 FC Size " << vec.size());
+        double deltaR=0.;
+        for(auto feat : vec){
+            const xAOD::TrigElectronContainer *cont = feat.cptr();
+            if(cont == NULL) {
+                ATH_MSG_DEBUG("TrigElectron Container from TE NULL");
+                continue;
+            }
+            ATH_MSG_DEBUG("L2 Size " << cont->size());
+            for(const auto& l2 : *cont){
+                if(l2 == NULL) {
+                    ATH_MSG_DEBUG("TrigElectron from TE NULL");
+                    continue;
+                }
+                deltaR = dR(eg->trackParticle()->eta(),eg->trackParticle()->phi(), l2->eta(),l2->phi()); 
+                if(deltaR < m_dR){
+                    finalFC = (feat.te());
+                    return true;
+                }
+            }
+        }
+        return false;
+
+    }
+
+    bool TrigEgammaMatchingTool::matchL2Calo(const xAOD::Egamma *eg,const std::string trigger,const HLT::TriggerElement*& finalFC){
+        finalFC=NULL;
+        auto fc = (m_trigDecTool->features(trigger,TrigDefs::alsoDeactivateTEs));
+#ifdef XAOD_ANALYSIS   
+        ATH_MSG_DEBUG("No matching for TrigEMCluster in AnalysisBase");
+        return false;
+#else
+        auto vec = fc.get<xAOD::TrigEMCluster>("",TrigDefs::alsoDeactivateTEs);
+
+        ATH_MSG_DEBUG("L2 FC Size " << vec.size());
+        for(auto feat : vec){
+            const xAOD::TrigEMCluster *em = feat.cptr();
+            if(em == NULL) {
+                ATH_MSG_DEBUG("TrigEMCluster from TE NULL");
+                continue;
+            }
+            ATH_MSG_DEBUG("TrigEMCluster << " << em->et() );
+            double deltaR=0.;
+            if(eg->type()==xAOD::Type::Electron){
+                const xAOD::Electron* el =static_cast<const xAOD::Electron*> (eg);
+                deltaR = dR(el->trackParticle()->eta(),el->trackParticle()->phi(), em->eta(),em->phi());
+            }
+            else if (eg->type()==xAOD::Type::Photon)
+                deltaR = dR(eg->caloCluster()->eta(),eg->caloCluster()->phi(), em->eta(),em->phi());
+            if(deltaR < m_dR){
+                finalFC = (feat.te());
+                return true;
+            }
+        }
+#endif
+        return false;
+
+    }
+
+    bool TrigEgammaMatchingTool::matchL1( const xAOD::Egamma* eg, const std::string trigger,const HLT::TriggerElement*& finalFC ){
+       finalFC=NULL;
+
+#ifdef XAOD_ANALYSIS   
+       if(m_trigDecTool->isPassed("L1_EM.*")) return true;
+#else
+        double deltaR=0.;
+        auto fc = (m_trigDecTool->features(trigger,TrigDefs::alsoDeactivateTEs));
+        auto initRois = fc.get<TrigRoiDescriptor>();
+        if ( initRois.size() < 1 ) return false;
+        auto itEmTau = m_trigDecTool->ancestor<xAOD::EmTauRoI>(initRois[0]);
+        const xAOD::EmTauRoI *l1 = itEmTau.cptr();
+        if(l1 == NULL) {
+            ATH_MSG_DEBUG("EMTauRoI from TE NULL");
+            return false;
+        }
+     
+        if(eg->type()==xAOD::Type::Electron){
+            const xAOD::Electron* el =static_cast<const xAOD::Electron*> (eg);
+            deltaR = dR(el->trackParticle()->eta(),el->trackParticle()->phi(), l1->eta(),l1->phi());
+        }
+        else if (eg->type()==xAOD::Type::Photon)
+            deltaR = dR(eg->caloCluster()->eta(),eg->caloCluster()->phi(), l1->eta(),l1->phi());
+
+        if(deltaR < m_dRL1){
+            finalFC = (itEmTau.te());
+            return true;
+        }
+#endif
+        return false; // otherwise, someone matched!*/
+
+    }
+
+    /*bool TrigEgammaMatchingTool::matchL1( const xAOD::Egamma* eg, const std::string trigger){
+       finalFC=NULL;
+
+#ifdef XAOD_ANALYSIS   
+       if(m_trigDecTool->isPassed("L1_EM.*")) return true;
+#else
+        double deltaR=0.;
+        auto fc = (m_trigDecTool->features(trigger));
+        auto initRois = fc.get<TrigRoiDescriptor>();
+        if ( initRois.size() < 1 ) return false;
+        auto cont = m_trigDecTool->ancestor<xAOD::EmTauRoIContainer>(initRois);
+        for(const auto &l1 : cont){
+            //const xAOD::EmTauRoI *l1 = feat.cptr();
+            if(l1 == NULL) {
+                ATH_MSG_DEBUG("EMTauRoI from TE NULL");
+                return false;
+            }
+
+            if(eg->type()==xAOD::Type::Electron){
+                const xAOD::Electron* el =static_cast<const xAOD::Electron*> (eg);
+                deltaR = dR(el->trackParticle()->eta(),el->trackParticle()->phi(), l1->eta(),l1->phi());
+            }
+            else if (eg->type()==xAOD::Type::Photon)
+                deltaR = dR(eg->caloCluster()->eta(),eg->caloCluster()->phi(), l1->eta(),l1->phi());
+
+            if(deltaR < m_dRL1){
+                finalFC = (itEmTau.te());
+                return true;
+            }
+        }
+#endif
+        return false; // otherwise, someone matched!
+
+    }*/
+    bool TrigEgammaMatchingTool::match(const xAOD::Egamma *eg,const std::string trigger,const HLT::TriggerElement*& finalFC){
+        // Set TE to NULL
+        // If no match easy check
+        finalFC=NULL;
+
+        ATH_MSG_DEBUG("Match objec with trigger " << trigger);
+        if(eg->type()==xAOD::Type::Electron){
+            const xAOD::Electron* el =static_cast<const xAOD::Electron*> (eg);
+            if( matchHLTElectron(el,trigger,finalFC) ) return true;
+        }
+        else if(eg->type()==xAOD::Type::Photon){
+            const xAOD::Photon* ph =static_cast<const xAOD::Photon*> (eg);
+            if( matchHLTPhoton(ph,trigger,finalFC) ) return true;
+        }
+        if( matchHLTCalo(eg,trigger,finalFC) ) return true;
+        if(eg->type()==xAOD::Type::Electron){
+            const xAOD::Electron* el =static_cast<const xAOD::Electron*> (eg);
+            if( matchL2Electron(el,trigger,finalFC) ) return true;
+        }
+        else if(eg->type()==xAOD::Type::Photon){
+            const xAOD::Photon* ph =static_cast<const xAOD::Photon*> (eg);
+            //if( matchL2Photon(ph,fc,trigger,finalFC) ) return true;
+            if( matchL2Photon(ph,trigger,finalFC) ) return true;
+        }
+        if( matchL2Calo(eg,trigger,finalFC) ) return true;
+        if( matchL1(eg,trigger,finalFC) ) return true;
+        return false;// otherwise, someone matched!*/
+    }
+
+    /*! Calls match with a TE, so recursive matching to L1 
+     * Check that the HLT Electron or Photon ancester passed */
+    bool TrigEgammaMatchingTool::match(const xAOD::Egamma *eg,const std::string trigger){
+        const HLT::TriggerElement* finalFC;
+        bool passed = false;
+        if( match(eg,trigger,finalFC) ){
+            if( finalFC == NULL) return false;
+            if(eg->type()==xAOD::Type::Electron){
+                if ( (m_trigDecTool->ancestor<xAOD::ElectronContainer>(finalFC)).te() != NULL){
+                    if( (m_trigDecTool->ancestor<xAOD::ElectronContainer>(finalFC)).te()->getActiveState())
+                        passed = true;
+                }
+            }
+            else if(eg->type()==xAOD::Type::Photon){
+                if ( (m_trigDecTool->ancestor<xAOD::PhotonContainer>(finalFC)).te() != NULL){
+                    if( (m_trigDecTool->ancestor<xAOD::PhotonContainer>(finalFC)).te()->getActiveState())
+                        passed = true;
+                }
+            }
+        }
+        return passed;
+    }
+
+} //namespace Trig
+
+
diff --git a/Trigger/TrigAnalysis/TrigEgammaMatchingTool/TrigEgammaMatchingTool/ITrigEgammaMatchingTool.h b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/TrigEgammaMatchingTool/ITrigEgammaMatchingTool.h
new file mode 100644
index 00000000000..eba9e3193d8
--- /dev/null
+++ b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/TrigEgammaMatchingTool/ITrigEgammaMatchingTool.h
@@ -0,0 +1,45 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef ITRIGEGAMMAMATCHINGTOOL_H_
+#define ITRIGEGAMMAMATCHINGTOOL_H_
+
+#include "AsgTools/IAsgTool.h"
+#include "TrigConfHLTData/HLTFrame.h"
+#include "TrigConfHLTData/HLTTriggerElement.h"
+#include "xAODEgamma/Egamma.h"
+#include "xAODEgamma/ElectronContainer.h"
+#include "xAODEgamma/PhotonContainer.h"
+#include "xAODEgamma/ElectronAuxContainer.h"
+#include "xAODEgamma/PhotonAuxContainer.h"
+#include "xAODTrigEgamma/TrigElectronContainer.h"
+#include "xAODTrigEgamma/TrigElectronAuxContainer.h"
+#include "xAODTrigEgamma/TrigPhotonContainer.h"
+#include "xAODTrigEgamma/TrigPhotonAuxContainer.h"
+#include "xAODTracking/TrackParticleContainer.h"
+#include "xAODTracking/TrackParticleAuxContainer.h"
+#include "xAODTrigCalo/TrigEMCluster.h"
+#include "xAODCaloEvent/CaloClusterContainer.h"
+#include "xAODCaloEvent/CaloClusterAuxContainer.h"
+#include "xAODTrigger/EmTauRoIContainer.h"
+#include "TrigDecisionTool/TrigDecisionTool.h"
+
+namespace Trig{
+    class ITrigEgammaMatchingTool : public virtual asg::IAsgTool {
+        ASG_TOOL_INTERFACE( Trig::ITrigEgammaMatchingTool )
+
+        public:
+            virtual StatusCode initialize(void) = 0;
+            virtual StatusCode execute()=0;
+            virtual StatusCode finalize()=0;
+            virtual bool match(const xAOD::Egamma *,const std::string,const HLT::TriggerElement*&)=0;
+            virtual bool match(const xAOD::Egamma *,const std::string)=0;
+            virtual bool matchHLT(const xAOD::Egamma *,const std::string)=0;
+            virtual const xAOD::Egamma* closestHLTObject(const xAOD::Egamma *,const std::string)=0;
+        protected:
+
+        private:
+    };
+}
+#endif
diff --git a/Trigger/TrigAnalysis/TrigEgammaMatchingTool/TrigEgammaMatchingTool/TrigEgammaMatchingTool.h b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/TrigEgammaMatchingTool/TrigEgammaMatchingTool.h
new file mode 100644
index 00000000000..3ea78c28ea9
--- /dev/null
+++ b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/TrigEgammaMatchingTool/TrigEgammaMatchingTool.h
@@ -0,0 +1,61 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef TRIGEGAMMAMATCHINGTOOL_H_
+#define TRIGEGAMMAMATCHINGTOOL_H_
+
+#include "TrigEgammaMatchingTool/ITrigEgammaMatchingTool.h"
+#include "AsgTools/AsgToolsConf.h"
+#include "AsgTools/AsgMetadataTool.h"
+#include "AsgTools/AsgTool.h"
+#include "AsgTools/ToolHandle.h"
+#include <iostream>
+
+#include "TrigDecisionTool/TrigDecisionTool.h"
+
+namespace Trig{
+class TrigEgammaMatchingTool : 
+    public asg::AsgMetadataTool,
+    public virtual ITrigEgammaMatchingTool
+{
+    ASG_TOOL_INTERFACE(Trig::TrigEgammaMatchingTool)
+        ASG_TOOL_CLASS2( TrigEgammaMatchingTool, Trig::ITrigEgammaMatchingTool,Trig::TrigEgammaMatchingTool)
+
+    public:
+
+        TrigEgammaMatchingTool( const std::string& name );
+
+        virtual ~TrigEgammaMatchingTool();
+
+        virtual StatusCode initialize(void);
+        virtual StatusCode execute();
+        virtual StatusCode finalize();
+        /*! Egamma trigger matching which returns TE */
+        bool match(const xAOD::Egamma *,const std::string,const HLT::TriggerElement*&);
+        /*! Egamma trigger matching to HLT Electron/Photon with DeactivatedTE*/
+        bool match(const xAOD::Egamma *,const std::string);
+        /*! Egamma trigger matching to HLT Electron/Photon Only */
+        bool matchHLT(const xAOD::Egamma *,const std::string);
+        /*! Egamma trigger matching to HLT Electron/Photon only -- returns nearest object */
+        const xAOD::Egamma* closestHLTObject(const xAOD::Egamma *,const std::string);
+        double dR(const double, const double, const double, const double);
+        double m_dR;
+        double m_dRL1;
+    protected:
+    private:
+        ToolHandle<Trig::TrigDecisionTool> m_trigDecTool;
+        
+        template<class T> const T* getFeature(const HLT::TriggerElement* te);
+        template<class T> bool ancestorPassed(const HLT::TriggerElement* te);
+        bool matchHLTElectron(const xAOD::Electron *,const std::string,const HLT::TriggerElement*&);
+        bool matchHLTPhoton(const xAOD::Photon *,const std::string,const HLT::TriggerElement*&);
+        bool matchHLTCalo(const xAOD::Egamma *,const std::string,const HLT::TriggerElement*&);
+        bool matchL2Electron(const xAOD::Electron *,const std::string,const HLT::TriggerElement*&);
+        bool matchL2Photon(const xAOD::Photon *,const std::string,const HLT::TriggerElement*&);
+        bool matchL2Calo(const xAOD::Egamma *,const std::string,const HLT::TriggerElement*&);
+        bool matchL1(const xAOD::Egamma *,const std::string,const HLT::TriggerElement*&);
+
+};
+}
+#endif
diff --git a/Trigger/TrigAnalysis/TrigEgammaMatchingTool/cmt/Makefile.RootCore b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/cmt/Makefile.RootCore
new file mode 100644
index 00000000000..1b71065a3db
--- /dev/null
+++ b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/cmt/Makefile.RootCore
@@ -0,0 +1,17 @@
+PACKAGE          = TrigEgammaMatchingTool
+PACKAGE_PRELOAD  =
+PACKAGE_CXXFLAGS =
+PACKAGE_OBJFLAGS =
+PACKAGE_LDFLAGS  =
+PACKAGE_BINFLAGS =
+PACKAGE_LIBFLAGS =
+PACKAGE_DEP      = AsgTools xAODRootAccess xAODTrigger xAODEgamma xAODTrigEgamma xAODCaloEvent xAODTrigCalo xAODTracking TrigDecisionTool TrigSteeringEvent
+PACKAGE_TRYDEP   =
+PACKAGE_CLEAN    =
+PACKAGE_NOGRID   =
+PACKAGE_PEDANTIC = 1
+PACKAGE_NOOPT    = 0
+PACKAGE_NOCC     = 0
+PACKAGE_REFLEX   = 0
+	
+include $(ROOTCOREDIR)/Makefile-common
diff --git a/Trigger/TrigAnalysis/TrigEgammaMatchingTool/cmt/requirements b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/cmt/requirements
new file mode 100644
index 00000000000..6818198e20f
--- /dev/null
+++ b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/cmt/requirements
@@ -0,0 +1,30 @@
+package TrigEgammaMatchingTool
+
+author Ryan Mackenzie White <ryan.white@cern.ch>
+public
+use AtlasPolicy                AtlasPolicy-*
+use AsgTools                   AsgTools-*                      Control/AthToolSupport
+use AtlasROOT                   AtlasROOT-*                     External
+
+use TrigDecisionTool            TrigDecisionTool-*              Trigger/TrigAnalysis
+use TrigConfHLTData             TrigConfHLTData-*               Trigger/TrigConfiguration
+use TrigSteeringEvent           TrigSteeringEvent-*             Trigger/TrigEvent
+
+use xAODTrigger                 xAODTrigger-*                   Event/xAOD
+use xAODEgamma                  xAODEgamma-*                    Event/xAOD
+use xAODEgammaCnv               xAODEgammaCnv-*                 Event/xAOD
+use xAODTrigEgamma              xAODTrigEgamma-*                Event/xAOD
+use xAODTracking                xAODTracking-*                  Event/xAOD
+use xAODTrigCalo                xAODTrigCalo-*                  Event/xAOD
+use xAODCaloEvent               xAODCaloEvent-*                 Event/xAOD
+
+private
+use AtlasROOT           AtlasROOT-*             External
+use TrigConfxAOD        TrigConfxAOD-*          Trigger/TrigConfiguration
+use GaudiInterface      GaudiInterface-*        External
+use AthenaBaseComps     AthenaBaseComps-*       Control
+use xAODTrigger         xAODTrigger-*           Event/xAOD
+end_private
+ 
+apply_pattern dual_use_library files="*.cxx ../Root/*.cxx"
+apply_pattern declare_joboptions files=../share/*.py
diff --git a/Trigger/TrigAnalysis/TrigEgammaMatchingTool/share/testTrigEgammaMatchingTool.py b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/share/testTrigEgammaMatchingTool.py
new file mode 100755
index 00000000000..92610b73ddc
--- /dev/null
+++ b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/share/testTrigEgammaMatchingTool.py
@@ -0,0 +1,95 @@
+# Default job options for TrigEgammaMatchingTool
+# Authors: 
+# Ryan Mackenzie White <ryan.white@cern.ch>
+# 
+
+from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
+from RecExConfig.RecFlags import rec
+from RecExConfig.RecAlgsFlags import recAlgs
+from InDetRecExample.InDetJobProperties import InDetFlags
+InDetFlags.doSecVertexFinder.set_Value_and_Lock(False)
+from AthenaCommon.AppMgr import ToolSvc
+
+import os
+
+if not 'DIR' in dir():
+     dirtouse='/afs/cern.ch/user/r/rwhite/workspace/public/validation/mc/DC14/valid1.147806.PowhegPythia8_AU2CT10_Zee.recon.AOD.e2658_s1967_s1964_r5787_tid01572823_00'
+else :
+     dirtouse=DIR
+
+outputName = 'Validation_asdf'
+
+# To run
+# athena -l DEBUG -c "DIR='/afs/cern.ch/user/r/rwhite/workspace/egamma/mc/DC14Val/mc14_13TeV.147406.PowhegPythia8_AZNLO_Zee.recon.AOD.e3059_s1982_s2008_r5787_tid01572494_00'" test_NavZeeTPAll.py
+listfiles=os.listdir(dirtouse)
+finallist=[]
+for ll in listfiles:
+      finallist.append(dirtouse+'/'+ll)
+#print finallist
+
+athenaCommonFlags.FilesInput=finallist
+athenaCommonFlags.EvtMax=100
+#athenaCommonFlags.EvtMax=-1
+rec.readAOD=True
+# switch off detectors
+rec.doForwardDet=False
+rec.doInDet=False
+rec.doCalo=False
+rec.doMuon=False
+rec.doEgamma=False
+rec.doTrigger = True; recAlgs.doTrigger=False # disable trigger (maybe necessary if detectors switched off)
+rec.doMuon=False
+rec.doMuonCombined=False
+rec.doWriteAOD=False
+rec.doWriteESD=False
+rec.doDPD=False
+rec.doTruth=False
+
+
+# autoconfiguration might trigger undesired feature
+rec.doESD.set_Value_and_Lock(False) # uncomment if do not run ESD making algorithms
+rec.doWriteESD.set_Value_and_Lock(False) # uncomment if do not write ESD
+rec.doAOD.set_Value_and_Lock(False) # uncomment if do not run AOD making algorithms
+rec.doWriteAOD.set_Value_and_Lock(False) # uncomment if do not write AOD
+rec.doWriteTAG.set_Value_and_Lock(False) # uncomment if do not write TAG
+# main jobOption
+triggerList = [
+                  #'e26_tight_iloose',
+                  #'e26_lhtight_iloose',
+                  #'e26_lhtight_cutd0dphideta_iloose',
+                  #'e26_lhtight_iloose_HLTCalo',
+                  #'e26_lhvloose_L1EM20VH',
+                  #'e26_vloose_L1EM20VH',
+                  #'e60_lhmedium',
+                  #'e60_lhmedium_HLTCalo',
+                  #'e60_lhmedium_cutd0dphideta',
+                  #'e60_lhvloose',
+                  'e17_lhloose',
+                  'e17_loose',
+                  #'e13_etcut_trkcut',
+                  #"g20_loose",
+                  #"g20_tight",
+                  "g25_loose",
+                  #"g25_medium",
+                  #"g35_loose",
+                  #"g35_medium",
+                  ]
+include ("RecExCommon/RecExCommon_topOptions.py")
+ToolSvc.TrigDecisionTool.TrigDecisionKey='xTrigDecision'
+from AthenaCommon.AlgSequence import AlgSequence
+theJob = AlgSequence()
+ 
+from TrigEgammaMatchingTool.TrigEgammaMatchingToolConf import Trig__TrigEgammaMatchingTool
+matchtool = Trig__TrigEgammaMatchingTool("MatchingTool");
+from AthenaCommon.AppMgr import ToolSvc
+ToolSvc += matchtool
+ 
+from TrigEgammaMatchingTool.TrigEgammaMatchingToolConf import Trig__TrigEgammaMatchingToolTest
+alg = Trig__TrigEgammaMatchingToolTest()
+alg.TrigEgammaMatchingTool = matchtool
+alg.TriggerList = triggerList
+alg.OutputLevel = DEBUG
+theJob += alg
+ 
+include("TriggerTest/TriggerTestCommon.py")
+
diff --git a/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/TrigEgammaMatchingToolTest.cxx b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/TrigEgammaMatchingToolTest.cxx
new file mode 100644
index 00000000000..f0510d46a58
--- /dev/null
+++ b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/TrigEgammaMatchingToolTest.cxx
@@ -0,0 +1,165 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+// TrigEgammaMatchingToolTest.cxx 
+
+#include "TrigEgammaMatchingToolTest.h"
+#include "GaudiKernel/Property.h"
+#include "xAODEgamma/ElectronContainer.h"
+#include "xAODEgamma/PhotonContainer.h"
+using std::string;
+
+//**********************************************************************
+namespace Trig{
+TrigEgammaMatchingToolTest::
+TrigEgammaMatchingToolTest(const std::string& name, 
+                    ISvcLocator* pSvcLocator )
+: ::AthAlgorithm( name, pSvcLocator ),
+    m_trigdec("Trig::TrigDecisionTool/TrigDecisionTool"),
+    m_matchTool("Trig::TrigEgammaMatchingTool/TrigEgammaMatchingTool",this)
+{
+    declareProperty("TrigEgammaMatchingTool",m_matchTool);
+    declareProperty("TriggerList",m_triggerList);
+}
+
+//**********************************************************************
+
+TrigEgammaMatchingToolTest::~TrigEgammaMatchingToolTest() { }
+
+//**********************************************************************
+
+StatusCode TrigEgammaMatchingToolTest::initialize() {
+  ATH_MSG_INFO("Initializing " << name() << "...");
+  ATH_MSG_INFO("Retrieving tools...");
+  if ( (m_trigdec.retrieve()).isFailure() ){
+      ATH_MSG_ERROR("Could not retrieve Trigger Decision Tool! Can't work");
+      return StatusCode::FAILURE;
+  }
+  StatusCode sc = service("StoreGateSvc", m_storeGate);
+  if(sc.isFailure()) {
+      ATH_MSG_ERROR( "Unable to locate Service StoreGateSvc" );
+      return sc;
+  }
+  return StatusCode::SUCCESS;
+}
+
+//**********************************************************************
+
+StatusCode TrigEgammaMatchingToolTest::finalize() {
+  ATH_MSG_INFO ("Finalizing " << name() << "...");
+  for (auto iter = m_counterBits.begin(); iter != m_counterBits.end(); iter++) {
+      ATH_MSG_INFO(iter->first << " == " << iter->second);
+  }
+  for (auto iter = m_counterMatch1Bits.begin(); iter != m_counterMatch1Bits.end(); iter++) {
+      ATH_MSG_INFO(iter->first << " " << iter->second << " " << m_counterMatch2Bits[iter->first] << " " <<  m_counterMatch3Bits[iter->first]); 
+  }
+
+  return StatusCode::SUCCESS;
+}
+
+//**********************************************************************
+
+StatusCode TrigEgammaMatchingToolTest::execute() {  
+  ATH_MSG_INFO ("Executing " << name() << "...");
+  ATH_MSG_INFO( "L1: " << m_trigdec->isPassed( "L1_.*" )
+          << ", L2: " << m_trigdec->isPassed( "L2_.*" )
+          << ", EF: " << m_trigdec->isPassed( "EF_.*" )
+          << ", HLT: " << m_trigdec->isPassed( "HLT_.*" ) );
+  auto chainGroups = m_trigdec->getChainGroup("HLT_e.*");
+     
+  for(auto &trig : chainGroups->getListOfTriggers()) {
+      if(m_trigdec->isPassed(trig))
+          ATH_MSG_INFO("Passed: " << trig);
+      m_counterBits[trig]+=m_trigdec->isPassed(trig);
+      
+  }
+
+  //Check Containers
+
+  const xAOD::ElectronContainer *offElectrons = 0;
+  const xAOD::ElectronContainer *onlElectrons = 0;
+  if ( (m_storeGate->retrieve(offElectrons,"Electrons")).isFailure() ){
+      ATH_MSG_ERROR("Failed to retrieve offline Electrons ");
+  }
+  ATH_MSG_INFO("Offline Electron container size " << offElectrons->size());
+  for(const auto& eg : *offElectrons){
+      if (eg) {
+          ATH_MSG_INFO(" REGTEST: egamma energy: " << eg->e());
+          ATH_MSG_INFO(" REGTEST: egamma eta: " << eg->eta() );
+          ATH_MSG_INFO(" REGTEST: egamma phi: " << eg->phi() );
+          for(unsigned int ilist = 0; ilist != m_triggerList.size(); ilist++) {
+              const HLT::TriggerElement *finalFC; 
+              std::string trigger = m_triggerList.at(ilist);
+              ATH_MSG_DEBUG("Test Matching Method 1");
+              if(m_matchTool->match(eg,trigger)){
+                  ATH_MSG_DEBUG("REGTEST:: Method 1 Matched Electron with tool for " << trigger);
+                  m_counterMatch1Bits[trigger]++;
+              }
+              else ATH_MSG_DEBUG("REGTEST::Fails method 3 " << trigger);
+              ATH_MSG_DEBUG("Test mathcing method 2");
+              if(m_matchTool->match(eg,trigger,finalFC)){
+                  ATH_MSG_DEBUG("REGTEST:: Method 2 Matched Electron with tool for " << trigger);
+                  if ( finalFC != NULL ){ 
+                      if ( (m_trigdec->ancestor<xAOD::ElectronContainer>(finalFC)).te() != NULL ){ 
+                          if( (m_trigdec->ancestor<xAOD::ElectronContainer>(finalFC)).te()->getActiveState()){
+                              ATH_MSG_DEBUG("REGTEST::Passed Matching " << trigger);
+                                m_counterMatch2Bits[trigger]++;
+                          }
+                          else ATH_MSG_DEBUG("REGTEST::Fails method 2");
+                      }
+                  }
+              }
+              ATH_MSG_DEBUG("REGTEST::Test Matching method 3");
+              if(m_matchTool->matchHLT(eg,trigger)){
+                  ATH_MSG_DEBUG("REGTEST:: Method 3 Matched Electron with tool for " << trigger);
+                  m_counterMatch3Bits[trigger]++;
+              }
+              else ATH_MSG_DEBUG("REGTEST::Fails method 3");
+          }
+      } else{
+          ATH_MSG_INFO(" REGTEST: problems with egamma pointer");
+      }
+      if(eg->trackParticle()){
+              ATH_MSG_INFO(" REGTEST: pt=  " << eg->trackParticle()->pt()); 
+              ATH_MSG_INFO(" REGTEST: charge=  " << eg->trackParticle()->charge()) ;
+              ATH_MSG_INFO(" REGTEST: eta=  " << eg->trackParticle()->eta()); 
+              ATH_MSG_INFO(" REGTEST: phi=  " << eg->trackParticle()->phi()) ;
+      }
+      if(eg->caloCluster()){
+              ATH_MSG_INFO(" REGTEST: et=  " << eg->caloCluster()->et()); 
+              ATH_MSG_INFO(" REGTEST: eta=  " << eg->caloCluster()->eta()); 
+              ATH_MSG_INFO(" REGTEST: phi=  " << eg->caloCluster()->phi()) ;
+      }
+      else ATH_MSG_INFO("No caloCluster");
+  } 
+  if ( (m_storeGate->retrieve(onlElectrons,"HLT_xAOD__ElectronContainer_egamma_Electrons")).isFailure() ){
+      ATH_MSG_ERROR("Failed to retrieve offline Electrons ");
+  }
+  ATH_MSG_INFO("Online Electron container size " << onlElectrons->size());
+  for(const auto& eg : *onlElectrons){
+      if (eg) {
+          ATH_MSG_INFO(" REGTEST: egamma energy: " << eg->e());
+          ATH_MSG_INFO(" REGTEST: egamma eta: " << eg->eta() );
+          ATH_MSG_INFO(" REGTEST: egamma phi: " << eg->phi() );
+
+      } else{
+          ATH_MSG_INFO(" REGTEST: problems with egamma pointer");
+      }
+      if(eg->trackParticle()){
+              ATH_MSG_INFO(" REGTEST: pt=  " << eg->trackParticle()->pt()); 
+              ATH_MSG_INFO(" REGTEST: charge=  " << eg->trackParticle()->charge()) ;
+              ATH_MSG_INFO(" REGTEST: eta=  " << eg->trackParticle()->eta()); 
+              ATH_MSG_INFO(" REGTEST: phi=  " << eg->trackParticle()->phi() );
+      }
+      if(eg->caloCluster()){
+              ATH_MSG_INFO(" REGTEST: et=  " << eg->caloCluster()->et()); 
+              ATH_MSG_INFO(" REGTEST: eta=  " << eg->caloCluster()->eta()); 
+              ATH_MSG_INFO(" REGTEST: phi=  " << eg->caloCluster()->phi()) ;
+      }
+      else ATH_MSG_INFO("No caloCluster");
+  } 
+  return StatusCode::SUCCESS;
+}
+}
+//**********************************************************************
diff --git a/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/TrigEgammaMatchingToolTest.h b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/TrigEgammaMatchingToolTest.h
new file mode 100644
index 00000000000..9bad575a66c
--- /dev/null
+++ b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/TrigEgammaMatchingToolTest.h
@@ -0,0 +1,50 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+// TrigEgammaMatchingToolTest.h 
+
+#ifndef TrigEgammaMatchingToolTest_H
+#define TrigEgammaMatchingToolTest_H
+
+#include "AthenaBaseComps/AthAlgorithm.h"
+#include "GaudiKernel/ToolHandle.h"
+
+#include "TrigDecisionTool/TrigDecisionTool.h"
+#include "TrigEgammaMatchingTool/ITrigEgammaMatchingTool.h"
+class IExecuteTool;
+
+namespace Trig{
+    class TrigEgammaMatchingToolTest : public AthAlgorithm { 
+
+        public: 
+
+            /// Constructor with parameters: 
+            TrigEgammaMatchingToolTest(const std::string& name, ISvcLocator* pSvcLocator);
+
+            /// Destructor: 
+            ~TrigEgammaMatchingToolTest(); 
+
+            /// Athena algorithm's Hooks
+            StatusCode  initialize();
+            StatusCode  execute();
+            StatusCode  finalize();
+
+        private: 
+
+            /// Default constructor: 
+            TrigEgammaMatchingToolTest();
+
+        private:
+            ToolHandle<Trig::TrigDecisionTool> m_trigdec;
+            ToolHandle<ITrigEgammaMatchingTool> m_matchTool;
+
+            std::vector<std::string> m_triggerList;
+            std::map<std::string,int> m_counterBits;
+            std::map<std::string,int> m_counterMatch1Bits;
+            std::map<std::string,int> m_counterMatch2Bits;
+            std::map<std::string,int> m_counterMatch3Bits;
+            StoreGateSvc * m_storeGate;
+    }; 
+}
+#endif
diff --git a/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/components/TrigEgammaMatchingTool_entries.cxx b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/components/TrigEgammaMatchingTool_entries.cxx
new file mode 100644
index 00000000000..8cecf2af3ba
--- /dev/null
+++ b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/components/TrigEgammaMatchingTool_entries.cxx
@@ -0,0 +1,12 @@
+#include "GaudiKernel/DeclareFactoryEntries.h"
+#include "TrigEgammaMatchingTool/TrigEgammaMatchingTool.h"
+#include "../TrigEgammaMatchingToolTest.h"
+
+DECLARE_NAMESPACE_TOOL_FACTORY(Trig,TrigEgammaMatchingTool)   
+DECLARE_NAMESPACE_ALGORITHM_FACTORY(Trig,TrigEgammaMatchingToolTest) 
+
+DECLARE_FACTORY_ENTRIES(TrigEgammaMatchingTool) {
+  DECLARE_NAMESPACE_TOOL(Trig,TrigEgammaMatchingTool)
+  DECLARE_NAMESPACE_ALGORITHM(Trig,TrigEgammaMatchingToolTest)
+}
+
diff --git a/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/components/TrigEgammaMatchingTool_load.cxx b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/components/TrigEgammaMatchingTool_load.cxx
new file mode 100644
index 00000000000..032e49951e8
--- /dev/null
+++ b/Trigger/TrigAnalysis/TrigEgammaMatchingTool/src/components/TrigEgammaMatchingTool_load.cxx
@@ -0,0 +1,3 @@
+#include "GaudiKernel/LoadFactoryEntries.h"
+
+LOAD_FACTORY_ENTRIES(TrigEgammaMatchingTool)
-- 
GitLab