diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGElectronLikelihoodToolWrapper.cxx b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGElectronLikelihoodToolWrapper.cxx index 0f8597c70b146223145eb505bc301d6d4d1ad2bf..a54cc16316e660ffd5f289700ea534ffc255217e 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGElectronLikelihoodToolWrapper.cxx +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGElectronLikelihoodToolWrapper.cxx @@ -126,7 +126,7 @@ EGElectronLikelihoodToolWrapper::addBranches() const } } // compute the output of the selector - asg::AcceptData theAccept(m_tool->accept(pCopy)); + asg::AcceptData theAccept(m_tool->accept(ctx,pCopy)); const unsigned int isEM = (unsigned int)theAccept.getCutResultInvertedBitSet() .to_ulong(); // this should work for both the diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGSelectionToolWrapper.cxx b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGSelectionToolWrapper.cxx index fc594a66e0816965960876ac3fff577f090d3992..4d5262baa4def39d65cc1d55ee2f4a950f7c9ec7 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGSelectionToolWrapper.cxx +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGSelectionToolWrapper.cxx @@ -101,9 +101,7 @@ EGSelectionToolWrapper::addBranches() const } } // compute the output of the selector - asg::AcceptData theAccept(m_tool->accept(pCopy)); - // unsigned int isEM = m_tool->IsemValue(); // this one should be done only - // for IsEM selectors.. + asg::AcceptData theAccept(m_tool->accept(ctx,pCopy)); unsigned int isEM = (unsigned int)theAccept.getCutResultInvertedBitSet() .to_ulong(); // this should work for both the // cut-based and the LH selectors diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronChargeIDSelectorTool.h b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronChargeIDSelectorTool.h index f63f32b9b51488bb43a7bdc89e9ed74f86df59c0..baf8e11dd2cbbc3c79a92efb73fd175310e21b85 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronChargeIDSelectorTool.h +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronChargeIDSelectorTool.h @@ -6,114 +6,126 @@ #ifndef __ASGELECTRONCHARGEIDSELECTORTOOL__ #define __ASGELECTRONCHARGEIDSELECTORTOOL__ - // Atlas includes +#include "AsgDataHandles/ReadHandleKey.h" #include "AsgTools/AsgTool.h" -#include "MVAUtils/BDT.h" #include "EgammaAnalysisInterfaces/IAsgElectronLikelihoodTool.h" #include "ElectronPhotonSelectorTools/AsgElectronLikelihoodTool.h" +#include "MVAUtils/BDT.h" #include "PATCore/AcceptData.h" -#include "AsgDataHandles/ReadHandleKey.h" #include <unordered_map> -class AsgElectronChargeIDSelectorTool : public asg::AsgTool, - virtual public IAsgElectronLikelihoodTool +class AsgElectronChargeIDSelectorTool + : public asg::AsgTool + , virtual public IAsgElectronLikelihoodTool { - ASG_TOOL_CLASS2(AsgElectronChargeIDSelectorTool, IAsgElectronLikelihoodTool, IAsgSelectionTool) + ASG_TOOL_CLASS2(AsgElectronChargeIDSelectorTool, + IAsgElectronLikelihoodTool, + IAsgSelectionTool) public: /** Standard constructor */ - AsgElectronChargeIDSelectorTool( const std::string& myname); - + AsgElectronChargeIDSelectorTool(const std::string& myname); /** Standard destructor */ virtual ~AsgElectronChargeIDSelectorTool(); + public: - /** Gaudi Service Interface method implementations */ // /** Gaudi Service Interface method implementations */ - virtual StatusCode initialize() override; // virtual StatusCode finalize(); + /** Gaudi Service Interface method implementations */ // /** Gaudi Service + // Interface method + // implementations */ + virtual StatusCode initialize() override; // virtual StatusCode finalize(); // Main methods for IAsgSelectorTool interface /** Method to get the plain AcceptInfo. - This is needed so that one can already get the AcceptInfo - and query what cuts are defined before the first object + This is needed so that one can already get the AcceptInfo + and query what cuts are defined before the first object is passed to the tool. */ - //virtual const asg::AcceptInfo& getAcceptInfo() const override; KM: inlined blow + // virtual const asg::AcceptInfo& getAcceptInfo() const override; KM: inlined + // blow /** The main accept method: using the generic interface */ - asg::AcceptData accept( const xAOD::IParticle* part ) const override; - asg::AcceptData accept( const EventContext& ctx, const xAOD::IParticle* part ) const override; - - /** The main accept method: the actual cuts are applied here */ - asg::AcceptData accept( const xAOD::Electron* eg ) const { - return accept (eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object - } - asg::AcceptData accept( const EventContext& ctx, const xAOD::Electron* eg ) const override { - return accept (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object + virtual asg::AcceptData accept( + const xAOD::IParticle* part) const override final; + virtual asg::AcceptData accept( + const EventContext& ctx, + const xAOD::IParticle* part) const override final; + + virtual asg::AcceptData accept(const EventContext& ctx, + const xAOD::Electron* eg) const override final + { + return accept(ctx, eg, -99); // mu = -99 as input will force accept to grab + // the pileup variable from the xAOD object } - /** The main accept method: the actual cuts are applied here */ - asg::AcceptData accept( const xAOD::Egamma* eg ) const { - return accept (eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object - } - asg::AcceptData accept(const EventContext& ctx, const xAOD::Egamma* eg ) const override{ - return accept (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object + virtual asg::AcceptData accept(const EventContext& ctx, + const xAOD::Egamma* eg) const override final + { + return accept(ctx, eg, -99); // mu = -99 as input will force accept to grab + // the pileup variable from the xAOD object } /** The main accept method: in case mu not in EventInfo online */ - asg::AcceptData accept( const xAOD::Electron* eg, double mu ) const; - asg::AcceptData accept( const EventContext& ctx, const xAOD::Electron* eg, double mu ) const override; + virtual asg::AcceptData accept(const EventContext& ctx, + const xAOD::Electron* eg, + double mu) const override final; /** The main accept method: in case mu not in EventInfo online */ - asg::AcceptData accept( const xAOD::Egamma* eg, double mu ) const; - asg::AcceptData accept( const EventContext& ctx, const xAOD::Egamma* eg, double mu ) const override; - - // Main methods for IAsgCalculatorTool interface - public: - /** The main result method: the actual likelihood is calculated here */ - double calculate( const xAOD::IParticle* part ) const; - double calculate( const EventContext& ctx, const xAOD::IParticle* part ) const override; - - /** The main result method: the actual likelihood is calculated here */ - double calculate( const xAOD::Electron* eg ) const { - return calculate (eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object - } - double calculate( const EventContext& ctx, const xAOD::Electron* eg ) const override { - return calculate (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object - } + virtual asg::AcceptData accept(const EventContext& ctx, + const xAOD::Egamma* eg, + double mu) const override final; + // Main methods for IAsgCalculatorTool interface +public: /** The main result method: the actual likelihood is calculated here */ - double calculate( const xAOD::Egamma* eg ) const { - return calculate (eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object + virtual double calculate(const EventContext& ctx, + const xAOD::IParticle* part) const override final; + + virtual double calculate(const EventContext& ctx, + const xAOD::Electron* eg) const override final + { + return calculate( + ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup + // variable from the xAOD object } - double calculate( const EventContext &ctx, const xAOD::Egamma* eg ) const override { - return calculate (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object + virtual double calculate(const EventContext& ctx, + const xAOD::Egamma* eg) const override final + { + return calculate( + ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup + // variable from the xAOD object } /** The main result method: the actual likelihood is calculated here */ - double calculate( const xAOD::Electron* eg, double mu ) const; - double calculate( const EventContext &ctx, const xAOD::Electron* eg, double mu ) const override; + virtual double calculate(const EventContext& ctx, + const xAOD::Electron* eg, + double mu) const override final; /** The main result method: the actual likelihood is calculated here */ - double calculate( const xAOD::Egamma* eg, double mu ) const; - double calculate( const EventContext &ctx, const xAOD::Egamma* eg, double mu ) const override; - - //=========================================================================================== same until here - inline virtual std::string getOperatingPointName( ) const override - { return m_WorkingPoint; }; - - inline virtual const asg::AcceptInfo& getAcceptInfo() const override - { return m_acceptInfo; }; - - asg::AcceptData accept() const { return asg::AcceptData(&m_acceptInfo); } - + virtual double calculate(const EventContext& ctx, + const xAOD::Egamma* eg, + double mu) const override final; + + //=========================================================================================== + // same until here + inline virtual std::string getOperatingPointName() const override final + { + return m_WorkingPoint; + }; + + inline virtual const asg::AcceptInfo& getAcceptInfo() const override final + { + return m_acceptInfo; + }; // Private methods private: /// Get the number of primary vertices unsigned int getNPrimVertices(const EventContext& ctx) const; - //BDT instances for different ID operating points (Tight, Medium, Loose) and the vector corresponds to n-fold + // BDT instances for different ID operating points (Tight, Medium, Loose) and + // the vector corresponds to n-fold std::vector<MVAUtils::BDT*> m_v_bdts; TString m_pid_name; @@ -121,9 +133,9 @@ private: int m_cutPosition_bdt; asg::AcceptInfo m_acceptInfo; - + // Private member variables -private: +private: /** Working Point */ std::string m_WorkingPoint; @@ -134,9 +146,12 @@ private: unsigned int m_nPVdefault; /// The primary vertex container name - SG::ReadHandleKey<xAOD::VertexContainer> m_primVtxContKey { - this, "primaryVertexContainer", "PrimaryVertices", - "The primary vertex container name"}; + SG::ReadHandleKey<xAOD::VertexContainer> m_primVtxContKey{ + this, + "primaryVertexContainer", + "PrimaryVertices", + "The primary vertex container name" + }; /// The input ROOT file name that holds the PDFs std::string m_trainingFile; @@ -146,9 +161,5 @@ private: }; // End: class definition - - - - #endif diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronIsEMSelector.h b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronIsEMSelector.h index b964df708a5ae78cd1da4f92a8776f7367d2fe18..97e0afc315b8692350cac697b0a727b551e801b7 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronIsEMSelector.h +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronIsEMSelector.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ // Dear emacs, this is -*-c++-*- @@ -29,19 +29,21 @@ class EventContext; -namespace Root{ - class TElectronIsEMSelector; +namespace Root { +class TElectronIsEMSelector; } - -class AsgElectronIsEMSelector : public asg::AsgTool, - virtual public IAsgElectronIsEMSelector +class AsgElectronIsEMSelector + : public asg::AsgTool + , virtual public IAsgElectronIsEMSelector { - ASG_TOOL_CLASS3(AsgElectronIsEMSelector, IAsgElectronIsEMSelector, - IAsgEGammaIsEMSelector, IAsgSelectionTool) + ASG_TOOL_CLASS3(AsgElectronIsEMSelector, + IAsgElectronIsEMSelector, + IAsgEGammaIsEMSelector, + IAsgSelectionTool) - public: +public: /** Standard constructor */ AsgElectronIsEMSelector(const std::string& myname); @@ -49,52 +51,59 @@ class AsgElectronIsEMSelector : public asg::AsgTool, virtual ~AsgElectronIsEMSelector(); /** Gaudi Service Interface method implementations */ - virtual StatusCode initialize(); + virtual StatusCode initialize() override; /// @name Methods from the IAsgSelectionTool interface /// @{ /** Method to get the plain AcceptInfo. - This is needed so that one can already get the AcceptInfo - and query what cuts are defined before the first object + This is needed so that one can already get the AcceptInfo + and query what cuts are defined before the first object is passed to the tool. */ - virtual const asg::AcceptInfo& getAcceptInfo() const; - + virtual const asg::AcceptInfo& getAcceptInfo() const override final; /** Accept with generic interface */ - virtual asg::AcceptData accept( const xAOD::IParticle* part ) const ; - virtual asg::AcceptData accept( const EventContext& ctx, const xAOD::IParticle* part ) const ; + virtual asg::AcceptData accept(const xAOD::IParticle* part) const override final; + virtual asg::AcceptData accept(const EventContext& ctx, + const xAOD::IParticle* part) const override final; ///@} /** Accept with Egamma objects */ - virtual asg::AcceptData accept( const EventContext& ctx, const xAOD::Egamma* part) const ; + virtual asg::AcceptData accept(const EventContext& ctx, + const xAOD::Egamma* part) const override final; /** Method to get the operating point */ - virtual std::string getOperatingPointName( ) const; + virtual std::string getOperatingPointName() const override final; ///@} /// @name Methods from the IAsgElectronIsEMSelectorinterface /// @{ /** Accept with Photon objects */ - virtual asg::AcceptData accept( const EventContext& ctx, const xAOD::Photon* part ) const ; + virtual asg::AcceptData accept(const EventContext& ctx, + const xAOD::Photon* part) const override final; /** Accept with Electron objects */ - virtual asg::AcceptData accept( const EventContext& ctx, const xAOD::Electron* part ) const ; - //The main execute method - StatusCode execute(const EventContext& ctx, const xAOD::Egamma* eg, unsigned int& isEM) const; + virtual asg::AcceptData accept(const EventContext& ctx, + const xAOD::Electron* part) const override final; + // The main execute method + virtual StatusCode execute(const EventContext& ctx, + const xAOD::Egamma* eg, + unsigned int& isEM) const override final; /// @} // Private member variables private: - - unsigned int calocuts_electrons(const xAOD::Egamma* eg, - float eta2, double et, - double trigEtTh, - unsigned int iflag) const; - - unsigned int TrackCut(const xAOD::Electron* eg, - float eta2, double et, double energy, - unsigned int iflag) const; + unsigned int calocuts_electrons(const xAOD::Egamma* eg, + float eta2, + double et, + double trigEtTh, + unsigned int iflag) const; + + unsigned int TrackCut(const xAOD::Electron* eg, + float eta2, + double et, + double energy, + unsigned int iflag) const; /** Working Point */ std::string m_WorkingPoint; @@ -108,12 +117,11 @@ private: /** @brief use f3core or f3 (default: use f3)*/ bool m_useF3core; - /// Flag for calo only cut-base - bool m_caloOnly; + /// Flag for calo only cut-base + bool m_caloOnly; float m_trigEtTh; }; // End: class definition - #endif diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronLikelihoodTool.h b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronLikelihoodTool.h index b7279e7fbddc7f68e78cc824836f14573979fd82..2baf1181da1302502d5e63bc27a53c68ba52d22c 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronLikelihoodTool.h +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronLikelihoodTool.h @@ -85,8 +85,6 @@ public: // Main methods for IAsgCalculatorTool interface public: - /** The main result method: the actual likelihood is calculated here */ - double calculate(const xAOD::IParticle* part) const; virtual double calculate(const EventContext& ctx, const xAOD::IParticle* part) const override final; diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronChargeIDSelectorTool.cxx b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronChargeIDSelectorTool.cxx index 3b37442b26611df232ea94eeb59ca34f9a562c3a..4608eca604a080093c9e689b3e37841759dd0f92 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronChargeIDSelectorTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronChargeIDSelectorTool.cxx @@ -4,251 +4,276 @@ /** @class AsgElectronChargeIDSelectorTool - @brief Electron selector tool to select objects in Asgena using an underlying pure ROOT tool. - + @brief Electron selector tool to select objects in Asgena using an underlying + pure ROOT tool. + @author Karsten Koeneke @date October 2012 09-APR-2014, convert to ASGTool (Jovan Mitrevski) - 22-AUG-2016, copied from AsgElectronLikelihoodTool (Kazuya Mochizuki) + 22-AUG-2016, copied from AsgElectronLikelihoodTool (Kazuya Mochizuki) */ // Include this class's header #include "ElectronPhotonSelectorTools/AsgElectronChargeIDSelectorTool.h" - - - // STL includes -#include <string> -#include <cstdint> #include <cmath> +#include <cstdint> +#include <string> -//EDM includes -#include "xAODEgamma/Electron.h" -#include "xAODTracking/Vertex.h" -#include "xAODTracking/VertexContainer.h" -#include "xAODCaloEvent/CaloCluster.h" -#include "xAODEventInfo/EventInfo.h" -#include "TROOT.h" -#include "TKey.h" +// EDM includes #include "TClass.h" #include "TEnv.h" #include "TFile.h" -#include "TObjString.h" +#include "TKey.h" #include "TObjArray.h" +#include "TObjString.h" +#include "TROOT.h" +#include "xAODCaloEvent/CaloCluster.h" +#include "xAODEgamma/Electron.h" +#include "xAODEventInfo/EventInfo.h" +#include "xAODTracking/Vertex.h" +#include "xAODTracking/VertexContainer.h" #include "AsgDataHandles/ReadHandle.h" #include "AsgTools/CurrentContext.h" #include "PathResolver/PathResolver.h" - //============================================================================= // Standard constructor //============================================================================= -AsgElectronChargeIDSelectorTool::AsgElectronChargeIDSelectorTool(const std::string& myname) : - AsgTool(myname) //,m_cutOnBDT(0)//,m_configFile("")//,m_rootTool(0) +AsgElectronChargeIDSelectorTool::AsgElectronChargeIDSelectorTool( + const std::string& myname) + : AsgTool(myname) //,m_cutOnBDT(0)//,m_configFile("")//,m_rootTool(0) { // Declare the needed properties - declareProperty("WorkingPoint",m_WorkingPoint="","The Working Point"); - //declareProperty("ConfigFile",m_configFile="","The config file to use"); - declareProperty("usePVContainer", m_usePVCont=true, "Whether to use the PV container"); - declareProperty("nPVdefault", m_nPVdefault = 0, "The default number of PVs if not counted"); - //declareProperty("primaryVertexContainer", m_primVtxContKey="PrimaryVertices", "The primary vertex container name" ); - - declareProperty("TrainingFile", m_trainingFile="", "The input ROOT file name holding training" ); - declareProperty("CutOnBDT",m_cutOnBDT=0,"Cut on BDT discriminant"); - m_pid_name=myname.data(); + declareProperty("WorkingPoint", m_WorkingPoint = "", "The Working Point"); + // declareProperty("ConfigFile",m_configFile="","The config file to use"); + declareProperty( + "usePVContainer", m_usePVCont = true, "Whether to use the PV container"); + declareProperty( + "nPVdefault", m_nPVdefault = 0, "The default number of PVs if not counted"); + // declareProperty("primaryVertexContainer", + // m_primVtxContKey="PrimaryVertices", "The primary vertex container name" ); + + declareProperty("TrainingFile", + m_trainingFile = "", + "The input ROOT file name holding training"); + declareProperty("CutOnBDT", m_cutOnBDT = 0, "Cut on BDT discriminant"); + m_pid_name = myname.data(); } - //============================================================================= // Standard destructor //============================================================================= AsgElectronChargeIDSelectorTool::~AsgElectronChargeIDSelectorTool() { - for (auto *bdt: m_v_bdts) if (bdt) delete bdt; + for (auto* bdt : m_v_bdts) + if (bdt) + delete bdt; } - //============================================================================= // Asgena initialize method //============================================================================= -StatusCode AsgElectronChargeIDSelectorTool::initialize() +StatusCode +AsgElectronChargeIDSelectorTool::initialize() { - m_pid_name.ToLower(); //KM: List of 97% OPs with different PIDs below - std::string op_name="loose"; - bool op_isUserSpecified=false; - if (m_cutOnBDT==0) { //when cutOnBDT is unmodified, adjust it to the 97% OP in each PID menu - if (m_pid_name.Contains("tight") ) op_name="tight" , m_cutOnBDT=-0.109249;//Tight (with data): -0.109249 - else if (m_pid_name.Contains("medium")) op_name="medium", m_cutOnBDT=-0.257081;//Medium (with data): -0.257081 - else m_cutOnBDT=-0.337671;//Loose (with data): -0.337671 - } - else op_isUserSpecified=true; - m_pid_name="loose";//Now only one training is provided, using loose PID but OP varies for differnt PID - - std::string display= op_isUserSpecified ? "user specified":"97% signal-eff"; - ATH_MSG_INFO("OP to use: " << op_name <<", with cut on BDT: "<<m_cutOnBDT<<", which corresponds to "<<display<<" working point."); - + m_pid_name.ToLower(); // KM: List of 97% OPs with different PIDs below + std::string op_name = "loose"; + bool op_isUserSpecified = false; + if (m_cutOnBDT == 0) { // when cutOnBDT is unmodified, adjust it to the 97% OP + // in each PID menu + if (m_pid_name.Contains("tight")) + op_name = "tight", m_cutOnBDT = -0.109249; // Tight (with data): + // -0.109249 + else if (m_pid_name.Contains("medium")) + op_name = "medium", + m_cutOnBDT = -0.257081; // Medium (with data): -0.257081 + else + m_cutOnBDT = -0.337671; // Loose (with data): -0.337671 + } else + op_isUserSpecified = true; + m_pid_name = "loose"; // Now only one training is provided, using loose PID + // but OP varies for differnt PID + + std::string display = + op_isUserSpecified ? "user specified" : "97% signal-eff"; + ATH_MSG_INFO("OP to use: " << op_name << ", with cut on BDT: " << m_cutOnBDT + << ", which corresponds to " << display + << " working point."); + std::string TrainingFile; - if (!m_trainingFile.empty()) { //If the property was set by the user, take that. - - TrainingFile= PathResolverFindCalibFile( m_trainingFile ); - if(TrainingFile.empty()){//Error if it cant find the conf - ATH_MSG_ERROR("Could not locate " << m_trainingFile ); + if (!m_trainingFile + .empty()) { // If the property was set by the user, take that. + + TrainingFile = PathResolverFindCalibFile(m_trainingFile); + if (TrainingFile.empty()) { // Error if it cant find the conf + ATH_MSG_ERROR("Could not locate " << m_trainingFile); return StatusCode::FAILURE; - } - else ATH_MSG_INFO("trainingfile loaded from: " << TrainingFile ); + } else + ATH_MSG_INFO("trainingfile loaded from: " << TrainingFile); - } - else { - ATH_MSG_ERROR("Could not find configuration file: \""<< m_trainingFile<<"\""); + } else { + ATH_MSG_ERROR("Could not find configuration file: \"" << m_trainingFile + << "\""); return StatusCode::FAILURE; } - - unsigned nfold=1; + + unsigned nfold = 1; TFile* bdtfile = TFile::Open(TrainingFile.data()); if (!bdtfile) { - ATH_MSG_ERROR("Input file found to be empty!! "<< TrainingFile); + ATH_MSG_ERROR("Input file found to be empty!! " << TrainingFile); return StatusCode::FAILURE; - } - else { + } else { TIter next(bdtfile->GetListOfKeys()); - TKey *key; + TKey* key; while ((key = (TKey*)next())) { - TClass *clas = gROOT->GetClass(key->GetClassName()); - if (!clas->InheritsFrom("TDirectoryFile")) continue; - TDirectory *td = (TDirectoryFile*)key->ReadObj(); - std::string dirName =td->GetName(); - if (dirName.find(m_pid_name)!=std::string::npos) { - std::string foldconf=dirName.substr(dirName.rfind('_')+1,-1); + TClass* clas = gROOT->GetClass(key->GetClassName()); + if (!clas->InheritsFrom("TDirectoryFile")) + continue; + TDirectory* td = (TDirectoryFile*)key->ReadObj(); + std::string dirName = td->GetName(); + if (dirName.find(m_pid_name) != std::string::npos) { + std::string foldconf = dirName.substr(dirName.rfind('_') + 1, -1); // std::string f_index=foldconf.substr(0,foldconf.find("o")); - std::string s_nfold=foldconf.substr(foldconf.find('o')+1,-1); - nfold=atoi(s_nfold.data()); + std::string s_nfold = foldconf.substr(foldconf.find('o') + 1, -1); + nfold = atoi(s_nfold.data()); break; } } } - - ATH_MSG_INFO("ECIDS nfold configuration: "<<nfold); - - TObjArray* toa= (TObjArray*) bdtfile->Get("/ECIDS_"+m_pid_name+TString::Format("_0o%d",nfold)+"/variables"); - std::string commaSepVars=""; + + ATH_MSG_INFO("ECIDS nfold configuration: " << nfold); + + TObjArray* toa = (TObjArray*)bdtfile->Get( + "/ECIDS_" + m_pid_name + TString::Format("_0o%d", nfold) + "/variables"); + std::string commaSepVars = ""; if (toa) { - TObjString *tos= nullptr; - if (toa->GetEntries()>0) tos= (TObjString*) toa->At(0); - commaSepVars=tos->GetString().Data(); - ATH_MSG_INFO("Variables for ECIDS= "<<commaSepVars); - } - else ATH_MSG_FATAL("Cannot access the list of input variables @"<<bdtfile->GetName()<<":/ECIDS_"+m_pid_name+TString::Format("_0o%d",nfold)+"/variables"); - - //prepare m_inputVars + TObjString* tos = nullptr; + if (toa->GetEntries() > 0) + tos = (TObjString*)toa->At(0); + commaSepVars = tos->GetString().Data(); + ATH_MSG_INFO("Variables for ECIDS= " << commaSepVars); + } else + ATH_MSG_FATAL("Cannot access the list of input variables @" + << bdtfile->GetName() + << ":/ECIDS_" + m_pid_name + TString::Format("_0o%d", nfold) + + "/variables"); + + // prepare m_inputVars m_inputVars.clear(); - while (commaSepVars.find(',')!=std::string::npos) { - m_inputVars.push_back(commaSepVars.substr(0,commaSepVars.find(','))); - commaSepVars.erase(0,commaSepVars.find(',')+1); + while (commaSepVars.find(',') != std::string::npos) { + m_inputVars.push_back(commaSepVars.substr(0, commaSepVars.find(','))); + commaSepVars.erase(0, commaSepVars.find(',') + 1); } - m_inputVars.push_back(commaSepVars.substr(0,-1));//push back the last element + m_inputVars.push_back( + commaSepVars.substr(0, -1)); // push back the last element - for (unsigned i_fold=0; i_fold<nfold; i_fold++) { - TString treename="/ECIDS_"+m_pid_name+TString::Format("_%do%d",i_fold,nfold)+"/BDT"; - //std::cout<<"Trying to access a ttree with name: "<<treename<<std::endl; + for (unsigned i_fold = 0; i_fold < nfold; i_fold++) { + TString treename = "/ECIDS_" + m_pid_name + + TString::Format("_%do%d", i_fold, nfold) + "/BDT"; + // std::cout<<"Trying to access a ttree with name: "<<treename<<std::endl; TTree* tree = (TTree*)bdtfile->Get(treename); m_v_bdts.push_back(new MVAUtils::BDT(tree)); } - + ///-----------End of text config---------------------------- // Setup primary vertex key handle - ATH_CHECK( m_primVtxContKey.initialize(m_usePVCont) ); - - m_cutPosition_bdt = m_acceptInfo.addCut( "bdt", "pass bdt" ); - - return StatusCode::SUCCESS ; + ATH_CHECK(m_primVtxContKey.initialize(m_usePVCont)); + + m_cutPosition_bdt = m_acceptInfo.addCut("bdt", "pass bdt"); + + return StatusCode::SUCCESS; } //============================================================================= // The main accept method: the actual cuts are applied here //============================================================================= -asg::AcceptData AsgElectronChargeIDSelectorTool::accept(const xAOD::Electron* el, double mu ) const +asg::AcceptData +AsgElectronChargeIDSelectorTool::accept(const EventContext& ctx, + const xAOD::Electron* eg, + double mu) const { - //Backwards compatibility - return accept(Gaudi::Hive::currentContext(), el, mu ); -} -asg::AcceptData AsgElectronChargeIDSelectorTool::accept(const EventContext& ctx, const xAOD::Electron* eg, double mu ) const -{ - - double bdt=calculate(ctx,eg,mu); - ATH_MSG_VERBOSE("\t accept( ctx, el, mu ), bdt="<<bdt); + double bdt = calculate(ctx, eg, mu); + + ATH_MSG_VERBOSE("\t accept( ctx, el, mu ), bdt=" << bdt); asg::AcceptData acceptBDT(&m_acceptInfo); acceptBDT.clear(); - acceptBDT.setCutResult(m_cutPosition_bdt,bdt>m_cutOnBDT); - + acceptBDT.setCutResult(m_cutPosition_bdt, bdt > m_cutOnBDT); + return acceptBDT; } //============================================================================= // Accept method for EFCaloLH in the trigger; do full LH if !CaloCutsOnly //============================================================================= -asg::AcceptData AsgElectronChargeIDSelectorTool::accept(const xAOD::Egamma* eg, double mu ) const -{ - //Backwards compatibility - return accept(Gaudi::Hive::currentContext(), eg, mu ); -} -asg::AcceptData AsgElectronChargeIDSelectorTool::accept(const EventContext& ctx, const xAOD::Egamma* eg, double mu) const +asg::AcceptData +AsgElectronChargeIDSelectorTool::accept(const EventContext& ctx, + const xAOD::Egamma* eg, + double mu) const { - double bdt=calculate(ctx,eg,mu); - - ATH_MSG_VERBOSE("\t accept( ctx, eg, mu ), bdt="<<bdt); + double bdt = calculate(ctx, eg, mu); - asg::AcceptData acceptBDT(&m_acceptInfo); + ATH_MSG_VERBOSE("\t accept( ctx, eg, mu ), bdt=" << bdt); + + asg::AcceptData acceptBDT(&m_acceptInfo); acceptBDT.clear(); - - acceptBDT.setCutResult(m_cutPosition_bdt,bdt>m_cutOnBDT); - + + acceptBDT.setCutResult(m_cutPosition_bdt, bdt > m_cutOnBDT); + return acceptBDT; } //============================================================================= // The main result method: the actual likelihood is calculated here //============================================================================= -double AsgElectronChargeIDSelectorTool::calculate( const EventContext& ctx, const xAOD::Electron* eg, double mu ) const +double +AsgElectronChargeIDSelectorTool::calculate(const EventContext& ctx, + const xAOD::Electron* eg, + double mu) const { - - ATH_MSG_VERBOSE("\t AsgElectronChargeIDSelectorTool::calculate( &ctx, *eg, mu= "<<(&ctx)<<", "<<eg<<", "<<mu<<" )"); - - if ( !eg ) { - ATH_MSG_ERROR ("Failed, no egamma object."); + + ATH_MSG_VERBOSE( + "\t AsgElectronChargeIDSelectorTool::calculate( &ctx, *eg, mu= " + << (&ctx) << ", " << eg << ", " << mu << " )"); + + if (!eg) { + ATH_MSG_ERROR("Failed, no egamma object."); return -1; } - + const xAOD::CaloCluster* cluster = eg->caloCluster(); - if ( !cluster ) { - ATH_MSG_ERROR ("Failed, no cluster."); + if (!cluster) { + ATH_MSG_ERROR("Failed, no cluster."); return -1; } - - const double energy = cluster->e(); + + const double energy = cluster->e(); const float eta = cluster->etaBE(2); - if ( fabs(eta) > 300.0 ) { - ATH_MSG_ERROR ("Failed, eta range."); + if (fabs(eta) > 300.0) { + ATH_MSG_ERROR("Failed, eta range."); return -1; } - - double et = 0.;// transverse energy of the electron (using the track eta) - if (eg->trackParticle() ) - et = ( cosh(eg->trackParticle()->eta()) != 0.) ? energy/cosh(eg->trackParticle()->eta()) : 0.; - else et = ( cosh(eta) != 0.) ? energy/cosh(eta) : 0.; - - + + double et = 0.; // transverse energy of the electron (using the track eta) + if (eg->trackParticle()) + et = (cosh(eg->trackParticle()->eta()) != 0.) + ? energy / cosh(eg->trackParticle()->eta()) + : 0.; + else + et = (cosh(eta) != 0.) ? energy / cosh(eta) : 0.; + // number of track hits and other track quantities uint8_t nSCT(0); float trackqoverp(0.0); float trackqoverpsig(0.0); - int charge(0.0); - int lifeSign(0.0); + int charge(0.0); + int lifeSign(0.0); float trackchi2(0.0); float avgCharge_SCTw(0.0); float d0(0.0); @@ -259,246 +284,381 @@ double AsgElectronChargeIDSelectorTool::calculate( const EventContext& ctx, cons float d0sigma(0.0); double dpOverp(0.0); float TRT_PID(0.0); - //double trans_TRT_PID(0.0); - float deltaPhi1=0, deltaPhi2=0; - float deltaPhiFromLM=0; - float deltaPhiRescaled2=0;//deltaEta=0, - //double rTRT(0.0); - - TVector2 el_cluster; el_cluster.SetMagPhi(cluster->energyBE(2)/cosh(eta),cluster->phiBE(2)); - + // double trans_TRT_PID(0.0); + float deltaPhi1 = 0, deltaPhi2 = 0; + float deltaPhiFromLM = 0; + float deltaPhiRescaled2 = 0; // deltaEta=0, + // double rTRT(0.0); + + TVector2 el_cluster; + el_cluster.SetMagPhi(cluster->energyBE(2) / cosh(eta), cluster->phiBE(2)); + bool allFound = true; // retrieve associated TrackParticle const xAOD::TrackParticle* t = eg->trackParticle(); if (t) { trackqoverp = t->qOverP(); - charge= t->charge(); + charge = t->charge(); d0 = t->d0(); - if(std::find(m_inputVars.begin(),m_inputVars.end(), "z0sinTheta" )!= m_inputVars.end()) { + if (std::find(m_inputVars.begin(), m_inputVars.end(), "z0sinTheta") != + m_inputVars.end()) { z0 = t->z0(); theta = t->theta(); } - if(std::find(m_inputVars.begin(),m_inputVars.end(), "chi2oftrackfit" )!= m_inputVars.end()) + if (std::find(m_inputVars.begin(), m_inputVars.end(), "chi2oftrackfit") != + m_inputVars.end()) trackchi2 = t->chiSquared(); - - phi0 = t->phi() + (d0>=0? M_PI/2 : -M_PI/2); - TVector2 d0_direction; d0_direction.SetMagPhi(fabs(d0),phi0); - float inner_product = el_cluster.X()*d0_direction.X() + el_cluster.Y()*d0_direction.Y(); - lifeSign = inner_product>=0? 1 : -1; - - EoverP = energy * fabs(t->qOverP()); - if(std::find(m_inputVars.begin(),m_inputVars.end(), "d0Err" )!= m_inputVars.end() or - std::find(m_inputVars.begin(),m_inputVars.end(), "d0Sig" )!= m_inputVars.end()) { - float vard0 = t->definingParametersCovMatrix()(0,0); + + phi0 = t->phi() + (d0 >= 0 ? M_PI / 2 : -M_PI / 2); + TVector2 d0_direction; + d0_direction.SetMagPhi(fabs(d0), phi0); + float inner_product = + el_cluster.X() * d0_direction.X() + el_cluster.Y() * d0_direction.Y(); + lifeSign = inner_product >= 0 ? 1 : -1; + + EoverP = energy * fabs(t->qOverP()); + if (std::find(m_inputVars.begin(), m_inputVars.end(), "d0Err") != + m_inputVars.end() or + std::find(m_inputVars.begin(), m_inputVars.end(), "d0Sig") != + m_inputVars.end()) { + float vard0 = t->definingParametersCovMatrix()(0, 0); if (vard0 > 0) { - d0sigma=sqrtf(vard0); + d0sigma = sqrtf(vard0); } } - - //KM: calculation of SCT-weighted charge + + // KM: calculation of SCT-weighted charge float charge = 0, SCT = 0; for (unsigned TPit = 0; TPit < eg->nTrackParticles(); TPit++) { uint8_t temp_NSCTHits; - if(eg->trackParticle(TPit)) { - eg->trackParticle(TPit)->summaryValue(temp_NSCTHits, xAOD::numberOfSCTHits); - - SCT += temp_NSCTHits; - charge += temp_NSCTHits*eg->trackParticle(TPit)->charge(); - } - else ATH_MSG_WARNING("This electron has no track particle associated!!! Assigning #SCT-hits= 0!!! " ); + if (eg->trackParticle(TPit)) { + eg->trackParticle(TPit)->summaryValue(temp_NSCTHits, + xAOD::numberOfSCTHits); + + SCT += temp_NSCTHits; + charge += temp_NSCTHits * eg->trackParticle(TPit)->charge(); + } else + ATH_MSG_WARNING("This electron has no track particle associated!!! " + "Assigning #SCT-hits= 0!!! "); } - avgCharge_SCTw= SCT!=0 ? eg->charge()*charge/SCT : 0; - - const std::vector<float>&cov= t->definingParametersCovMatrixVec(); - trackqoverpsig= cov[14]; - - if(std::find(m_inputVars.begin(),m_inputVars.end(), "nSctHits" )!= m_inputVars.end() ) + avgCharge_SCTw = SCT != 0 ? eg->charge() * charge / SCT : 0; + + const std::vector<float>& cov = t->definingParametersCovMatrixVec(); + trackqoverpsig = cov[14]; + + if (std::find(m_inputVars.begin(), m_inputVars.end(), "nSctHits") != + m_inputVars.end()) allFound = allFound && t->summaryValue(nSCT, xAOD::numberOfSCTHits); - - //Transform the TRT PID output for use in the LH tool. - double fEpsilon = 1.0e-30; // to avoid zero division + + // Transform the TRT PID output for use in the LH tool. + double fEpsilon = 1.0e-30; // to avoid zero division double pid_tmp = TRT_PID; - if (pid_tmp >= 1.0) pid_tmp = 1.0 - 1.0e-15; //this number comes from TMVA - else if (pid_tmp <= fEpsilon) pid_tmp = fEpsilon; - - if(std::find(m_inputVars.begin(),m_inputVars.end(), "deltaPoverP" )!= m_inputVars.end() ) { + if (pid_tmp >= 1.0) + pid_tmp = 1.0 - 1.0e-15; // this number comes from TMVA + else if (pid_tmp <= fEpsilon) + pid_tmp = fEpsilon; + + if (std::find(m_inputVars.begin(), m_inputVars.end(), "deltaPoverP") != + m_inputVars.end()) { unsigned int index; - if( t->indexOfParameterAtPosition(index, xAOD::LastMeasurement) ) { - - double refittedTrack_LMqoverp = + if (t->indexOfParameterAtPosition(index, xAOD::LastMeasurement)) { + + double refittedTrack_LMqoverp = t->charge() / sqrt(std::pow(t->parameterPX(index), 2) + std::pow(t->parameterPY(index), 2) + std::pow(t->parameterPZ(index), 2)); - - dpOverp = 1 - trackqoverp/(refittedTrack_LMqoverp); + + dpOverp = 1 - trackqoverp / (refittedTrack_LMqoverp); } } - - } - else { - allFound=false; - ATH_MSG_WARNING ( "Failed, no track particle: et= " << et << "eta= " << eta ); + + } else { + allFound = false; + ATH_MSG_WARNING("Failed, no track particle: et= " << et << "eta= " << eta); } - - float Rphi(0);//float Reta(0), Rphi(0), Rhad1(0), Rhad(0), ws3(0), w2(0), f1(0), Eratio(0), f3(0); - allFound = allFound && eg->showerShapeValue(Rphi, xAOD::EgammaParameters::Rphi);// rphi e233/e237 - // allFound = allFound && eg->trackCaloMatchValue(deltaEta, xAOD::EgammaParameters::deltaEta1); - - // difference between the cluster phi (sampling 2) and the eta of the track extrapolated from the last measurement point. - allFound = allFound && eg->trackCaloMatchValue(deltaPhiRescaled2, xAOD::EgammaParameters::deltaPhiRescaled2); - - //if(m_map_inputs.find("deltaphi1" )!= m_map_inputs.end()) - if(std::find(m_inputVars.begin(),m_inputVars.end(), "deltaphi1" )!= m_inputVars.end() ) - allFound = allFound && eg->trackCaloMatchValue(deltaPhi1, xAOD::EgammaParameters::deltaPhi1); + + float Rphi(0); // float Reta(0), Rphi(0), Rhad1(0), Rhad(0), ws3(0), w2(0), + // f1(0), Eratio(0), f3(0); + allFound = + allFound && + eg->showerShapeValue(Rphi, xAOD::EgammaParameters::Rphi); // rphi e233/e237 + // allFound = allFound && eg->trackCaloMatchValue(deltaEta, + // xAOD::EgammaParameters::deltaEta1); + + // difference between the cluster phi (sampling 2) and the eta of the track + // extrapolated from the last measurement point. + allFound = allFound && + eg->trackCaloMatchValue(deltaPhiRescaled2, + xAOD::EgammaParameters::deltaPhiRescaled2); + + // if(m_map_inputs.find("deltaphi1" )!= m_map_inputs.end()) + if (std::find(m_inputVars.begin(), m_inputVars.end(), "deltaphi1") != + m_inputVars.end()) + allFound = allFound && eg->trackCaloMatchValue( + deltaPhi1, xAOD::EgammaParameters::deltaPhi1); // if(m_map_inputs.find("deltaphi2" )!= m_map_inputs.end() or // m_map_inputs.find("deltaDeltaPhiFirstAndLM")!= m_map_inputs.end()) - if(std::find(m_inputVars.begin(),m_inputVars.end(), "deltaphi2" )!= m_inputVars.end() or - std::find(m_inputVars.begin(),m_inputVars.end(), "deltaDeltaPhiFirstAndLM")!= m_inputVars.end() ) - allFound = allFound && eg->trackCaloMatchValue(deltaPhi2, xAOD::EgammaParameters::deltaPhi2); - //if(m_map_inputs.find("deltaDeltaPhiFirstAndLM")!= m_map_inputs.end()) - if(std::find(m_inputVars.begin(),m_inputVars.end(), "deltaDeltaPhiFirstAndLM" )!= m_inputVars.end() ) - allFound = allFound && eg->trackCaloMatchValue(deltaPhiFromLM, xAOD::EgammaParameters::deltaPhiFromLastMeasurement); - + if (std::find(m_inputVars.begin(), m_inputVars.end(), "deltaphi2") != + m_inputVars.end() or + std::find(m_inputVars.begin(), + m_inputVars.end(), + "deltaDeltaPhiFirstAndLM") != m_inputVars.end()) + allFound = allFound && eg->trackCaloMatchValue( + deltaPhi2, xAOD::EgammaParameters::deltaPhi2); + // if(m_map_inputs.find("deltaDeltaPhiFirstAndLM")!= m_map_inputs.end()) + if (std::find(m_inputVars.begin(), + m_inputVars.end(), + "deltaDeltaPhiFirstAndLM") != m_inputVars.end()) + allFound = + allFound && + eg->trackCaloMatchValue( + deltaPhiFromLM, xAOD::EgammaParameters::deltaPhiFromLastMeasurement); + // Get the number of primary vertices in this event // double ip = static_cast<double>(m_nPVdefault); // if(mu < 0) // use npv if mu is negative (not given) - // ip = static_cast<double>(m_usePVCont ? this->getNPrimVertices() : m_nPVdefault); + // ip = static_cast<double>(m_usePVCont ? this->getNPrimVertices() : + // m_nPVdefault); // else ip = mu; - - if (!allFound) ATH_MSG_FATAL("Missing input variable for ECIDS BDT calculation"); - + + if (!allFound) + ATH_MSG_FATAL("Missing input variable for ECIDS BDT calculation"); + const xAOD::EventInfo* eventInfo = nullptr; - if (evtStore()->retrieve(eventInfo,"EventInfo").isFailure()) ATH_MSG_WARNING ( " Cannot access to event info " ); - // lumiBlock = eventInfo->lumiBlock(), runNumber = eventInfo->runNumber(), eventNumber=eventInfo->eventNumber(); - //ATH_MSG_DEBUG("event_num%bdt_size="<<eventInfo->eventNumber()<<"%"<<unsigned(m_v_bdts.size())<<"= "<<eventInfo->eventNumber()%unsigned(m_v_bdts.size())); - unsigned bdt_index=eventInfo->eventNumber()%unsigned(m_v_bdts.size()); - + if (evtStore()->retrieve(eventInfo, "EventInfo").isFailure()) + ATH_MSG_WARNING(" Cannot access to event info "); + // lumiBlock = eventInfo->lumiBlock(), runNumber = eventInfo->runNumber(), + // eventNumber=eventInfo->eventNumber(); + // ATH_MSG_DEBUG("event_num%bdt_size="<<eventInfo->eventNumber()<<"%"<<unsigned(m_v_bdts.size())<<"= + // "<<eventInfo->eventNumber()%unsigned(m_v_bdts.size())); + unsigned bdt_index = eventInfo->eventNumber() % unsigned(m_v_bdts.size()); + std::vector<float> v_inputs; - for (const auto& var: m_inputVars) { - if (var == "pt" ) v_inputs.push_back(et ); - if (var == "eta" ) v_inputs.push_back(eta ); - if (var == "abs_eta" ) v_inputs.push_back(fabs(eta) ); - if (var == "avgCharge_SCTw" ) v_inputs.push_back(avgCharge_SCTw ); - if (var == "d0" ) v_inputs.push_back(d0 ); - if (var == "ld0" ) v_inputs.push_back(lifeSign*d0 ); - if (var == "cd0" ) v_inputs.push_back(charge*d0 ); - if (var == "EoverP" ) v_inputs.push_back(EoverP ); - if (var == "deltaphi1" ) v_inputs.push_back(deltaPhi1 ); - if (var == "deltaphiRes" ) v_inputs.push_back(deltaPhiRescaled2 ); - if (var == "Rphi" ) v_inputs.push_back(Rphi ); - if (var == "qoverpSig" ) v_inputs.push_back(trackqoverpsig ); - if (var == "nSctHits" ) v_inputs.push_back(nSCT ); - if (var == "z0sinTheta" ) v_inputs.push_back(z0*sin(theta) ); - if (var == "d0Err" ) v_inputs.push_back(d0sigma ); - if (var == "d0Sig" ) v_inputs.push_back(d0/d0sigma ); - if (var == "deltaphi2" ) v_inputs.push_back(deltaPhi2 ); - if (var == "chi2oftrackfit" ) v_inputs.push_back(trackchi2 ); - if (var == "deltaPoverP" ) v_inputs.push_back(dpOverp ); - if (var == "deltaDeltaPhiFirstAndLM") v_inputs.push_back(deltaPhi2-deltaPhiFromLM); + for (const auto& var : m_inputVars) { + if (var == "pt") + v_inputs.push_back(et); + if (var == "eta") + v_inputs.push_back(eta); + if (var == "abs_eta") + v_inputs.push_back(fabs(eta)); + if (var == "avgCharge_SCTw") + v_inputs.push_back(avgCharge_SCTw); + if (var == "d0") + v_inputs.push_back(d0); + if (var == "ld0") + v_inputs.push_back(lifeSign * d0); + if (var == "cd0") + v_inputs.push_back(charge * d0); + if (var == "EoverP") + v_inputs.push_back(EoverP); + if (var == "deltaphi1") + v_inputs.push_back(deltaPhi1); + if (var == "deltaphiRes") + v_inputs.push_back(deltaPhiRescaled2); + if (var == "Rphi") + v_inputs.push_back(Rphi); + if (var == "qoverpSig") + v_inputs.push_back(trackqoverpsig); + if (var == "nSctHits") + v_inputs.push_back(nSCT); + if (var == "z0sinTheta") + v_inputs.push_back(z0 * sin(theta)); + if (var == "d0Err") + v_inputs.push_back(d0sigma); + if (var == "d0Sig") + v_inputs.push_back(d0 / d0sigma); + if (var == "deltaphi2") + v_inputs.push_back(deltaPhi2); + if (var == "chi2oftrackfit") + v_inputs.push_back(trackchi2); + if (var == "deltaPoverP") + v_inputs.push_back(dpOverp); + if (var == "deltaDeltaPhiFirstAndLM") + v_inputs.push_back(deltaPhi2 - deltaPhiFromLM); } - ATH_MSG_VERBOSE("\t\t event# " <<eventInfo->eventNumber() <<std::endl<< - "xAOD variables: pt = "<< et <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"pt" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: eta = "<< eta <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"eta" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: abs_eta = "<< fabs(eta) <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"abs_eta" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: avgCharge_SCTw = "<< avgCharge_SCTw <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"avgCharge_SCTw" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: d0 = "<< d0 <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"d0" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: ld0 = "<< lifeSign*d0 <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"ld0" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: cd0 = "<< charge*d0 <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"cd0" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: EoverP = "<< EoverP <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"EoverP" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: deltaphi1 = "<< deltaPhi1 <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"deltaphi1" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: deltaphiRes = "<< deltaPhiRescaled2 <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"deltaphiRes" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: Rphi = "<< Rphi <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"Rphi" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: qoverpSig = "<< trackqoverpsig <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"qoverpSig" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: nSctHits = "<< unsigned(nSCT) <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"nSctHits" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: z0sinTheta = "<< z0*sin(theta) <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"z0sinTheta" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: d0Err = "<< d0sigma <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"d0Err" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: d0Sig = "<< d0/d0sigma <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"d0Sig" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: deltaphi2 = "<< deltaPhi2 <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"deltaphi2" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: chi2oftrackfit = "<< trackchi2 <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"chi2oftrackfit" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: deltaPoverP = "<< dpOverp <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"deltaPoverP" )!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: deltaDeltaPhiFirstandLM = "<< deltaPhi2-deltaPhiFromLM <<",\t isRequested= "<<(std::find(m_inputVars.begin(),m_inputVars.end(),"deltaDeltaPhiFirstAndLM")!=m_inputVars.end() )<<std::endl<< - "\t\t xAOD variables: AllFound = "<<allFound ); - + ATH_MSG_VERBOSE( + "\t\t event# " + << eventInfo->eventNumber() << std::endl + << "xAOD variables: pt = " << et + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "pt") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: eta = " << eta + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "eta") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: abs_eta = " << fabs(eta) + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "abs_eta") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: avgCharge_SCTw = " << avgCharge_SCTw + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "avgCharge_SCTw") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: d0 = " << d0 + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "d0") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: ld0 = " << lifeSign * d0 + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "ld0") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: cd0 = " << charge * d0 + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "cd0") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: EoverP = " << EoverP + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "EoverP") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: deltaphi1 = " << deltaPhi1 + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "deltaphi1") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: deltaphiRes = " << deltaPhiRescaled2 + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "deltaphiRes") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: Rphi = " << Rphi + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "Rphi") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: qoverpSig = " << trackqoverpsig + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "qoverpSig") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: nSctHits = " << unsigned(nSCT) + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "nSctHits") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: z0sinTheta = " << z0 * sin(theta) + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "z0sinTheta") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: d0Err = " << d0sigma + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "d0Err") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: d0Sig = " << d0 / d0sigma + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "d0Sig") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: deltaphi2 = " << deltaPhi2 + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "deltaphi2") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: chi2oftrackfit = " << trackchi2 + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "chi2oftrackfit") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: deltaPoverP = " << dpOverp + << ",\t isRequested= " + << (std::find(m_inputVars.begin(), m_inputVars.end(), "deltaPoverP") != + m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: deltaDeltaPhiFirstandLM = " + << deltaPhi2 - deltaPhiFromLM << ",\t isRequested= " + << (std::find(m_inputVars.begin(), + m_inputVars.end(), + "deltaDeltaPhiFirstAndLM") != m_inputVars.end()) + << std::endl + << "\t\t xAOD variables: AllFound = " << allFound); + ////KM: dumping variables, only variables used by BDT // std::cout<<"\t\t event# "<<eventInfo->eventNumber()<<std::endl; // unsigned i=0; // for (auto inputVar: m_inputVars) { - // std::cout<<"\t kmdebug: "<<inputVar<<"\t = "<<v_inputs[i]<<std::endl; i++; + // std::cout<<"\t kmdebug: "<<inputVar<<"\t = "<<v_inputs[i]<<std::endl; + // i++; // } - - //double bdt_output = m_v_bdts.at(bdt_index)->GetGradBoostMVA(m_v_bdts.at(bdt_index)->GetPointers()); + + // double bdt_output = + // m_v_bdts.at(bdt_index)->GetGradBoostMVA(m_v_bdts.at(bdt_index)->GetPointers()); double bdt_output = m_v_bdts.at(bdt_index)->GetGradBoostMVA(v_inputs); - ATH_MSG_DEBUG("ECIDS-BDT= "<<bdt_output); - //std::cout<<"\t kmdebug: \t ECIDS-BDT= "<<bdt_output<<std::endl; + ATH_MSG_DEBUG("ECIDS-BDT= " << bdt_output); + // std::cout<<"\t kmdebug: \t ECIDS-BDT= "<<bdt_output<<std::endl; return bdt_output; } -//============================================================================= -// Calculate method for EFCaloLH in the trigger; do full LH if !CaloCutsOnly -//============================================================================= -double AsgElectronChargeIDSelectorTool::calculate( const xAOD::Egamma* eg, double mu ) const -{ - //Backward compatibility - return calculate(Gaudi::Hive::currentContext(), eg, mu); -} - -double AsgElectronChargeIDSelectorTool::calculate( const EventContext& ctx, const xAOD::Egamma* eg, double mu ) const +double +AsgElectronChargeIDSelectorTool::calculate(const EventContext& ctx, + const xAOD::Egamma* eg, + double mu) const { - ATH_MSG_VERBOSE("AsgElectronChargeIDSelectorTool::calculate( &ctx ="<<(&ctx)<<", *eg "<<eg<<", mu= "<<mu<< " )"); - ATH_MSG_WARNING("Method not implemented for egamma object! Reurning -1!!"); - - return -9; + if (eg->type() == xAOD::Type::Electron) { + const xAOD::Electron* el = static_cast<const xAOD::Electron*>(eg); + return calculate(ctx, el, mu); + } + ATH_MSG_ERROR("Input is not an electron!!"); + return -19; } //============================================================================= -asg::AcceptData AsgElectronChargeIDSelectorTool::accept(const xAOD::IParticle* part) const +asg::AcceptData +AsgElectronChargeIDSelectorTool::accept(const xAOD::IParticle* part) const { - //Backward compatibility + // Backward compatibility return accept(Gaudi::Hive::currentContext(), part); } -asg::AcceptData AsgElectronChargeIDSelectorTool::accept(const EventContext& ctx, const xAOD::IParticle* part) const +asg::AcceptData +AsgElectronChargeIDSelectorTool::accept(const EventContext& ctx, + const xAOD::IParticle* part) const { - if(part->type() == xAOD::Type::Electron){ + if (part->type() == xAOD::Type::Electron) { const xAOD::Electron* el = static_cast<const xAOD::Electron*>(part); return accept(ctx, el); } - ATH_MSG_ERROR("Input is not an electron"); return asg::AcceptData(&m_acceptInfo); } -double AsgElectronChargeIDSelectorTool::calculate(const xAOD::IParticle* part) const -{ - //Backward compatibility - return calculate(Gaudi::Hive::currentContext(), part); -} - -double AsgElectronChargeIDSelectorTool::calculate(const EventContext& ctx, const xAOD::IParticle* part) const +double +AsgElectronChargeIDSelectorTool::calculate(const EventContext& ctx, + const xAOD::IParticle* part) const { - if(part->type() == xAOD::Type::Electron){ + if (part->type() == xAOD::Type::Electron) { const xAOD::Electron* el = static_cast<const xAOD::Electron*>(part); return calculate(ctx, el); } - - ATH_MSG_ERROR ( "Input is not an electron!!" ); + ATH_MSG_ERROR("Input is not an electron!!"); return -19; } //============================================================================= // Helper method to get the number of primary vertices -// We don't want to iterate over all vertices in the event for each electron!!! +// We don't want to iterate over all vertices in the event for each electron!!! //============================================================================= -unsigned int AsgElectronChargeIDSelectorTool::getNPrimVertices(const EventContext& ctx) const +unsigned int +AsgElectronChargeIDSelectorTool::getNPrimVertices(const EventContext& ctx) const { unsigned int nVtx(0); - SG::ReadHandle<xAOD::VertexContainer> vtxCont (m_primVtxContKey, ctx); - for ( unsigned int i = 0; i < vtxCont->size(); i++ ) { - const xAOD::Vertex* vxcand = vtxCont->at(i); - if ( vxcand->nTrackParticles() >= 2 ) nVtx++; + SG::ReadHandle<xAOD::VertexContainer> vtxCont(m_primVtxContKey, ctx); + for (unsigned int i = 0; i < vtxCont->size(); i++) { + const xAOD::Vertex* vxcand = vtxCont->at(i); + if (vxcand->nTrackParticles() >= 2) + nVtx++; } return nVtx; } diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronLikelihoodTool.cxx b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronLikelihoodTool.cxx index 2490d3e1df54ff86dff5473c4adb2ea28616d9b5..e8764eb48697a68a1e3e778d3a2fe7b5dce3b059 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronLikelihoodTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronLikelihoodTool.cxx @@ -1076,13 +1076,6 @@ AsgElectronLikelihoodTool::accept(const EventContext& ctx, return m_rootTool->accept(); } -// Calculate with IParticle and no EventContext, backwards compatibility -double -AsgElectronLikelihoodTool::calculate(const xAOD::IParticle* part) const -{ - // Backward compatibility - return calculate(Gaudi::Hive::currentContext(), part); -} double AsgElectronLikelihoodTool::calculate(const EventContext& ctx, const xAOD::IParticle* part) const diff --git a/PhysicsAnalysis/TauID/TauAnalysisTools/Root/TauOverlappingElectronLLHDecorator.cxx b/PhysicsAnalysis/TauID/TauAnalysisTools/Root/TauOverlappingElectronLLHDecorator.cxx index b63e4b01b5a53b37760a20a0d8d0d2f5fd6d9102..10eee0ab747f79297edc94cb0e66957403114812 100644 --- a/PhysicsAnalysis/TauID/TauAnalysisTools/Root/TauOverlappingElectronLLHDecorator.cxx +++ b/PhysicsAnalysis/TauID/TauAnalysisTools/Root/TauOverlappingElectronLLHDecorator.cxx @@ -13,6 +13,7 @@ #include "TauAnalysisTools/SharedFilesVersion.h" // Framework include(s): +#include "AsgTools/CurrentContext.h" #include "PathResolver/PathResolver.h" // Root include(s) @@ -117,9 +118,14 @@ StatusCode TauOverlappingElectronLLHDecorator::decorate(const xAOD::TauJet& xTau if (m_bEleOLRMatchAvailable) return StatusCode::SUCCESS; - SG::ReadHandle<xAOD::ElectronContainer> h_ElectronContainer(m_sElectronContainerName); + const EventContext& ctx = Gaudi::Hive::currentContext(); + SG::ReadHandle<xAOD::ElectronContainer> h_ElectronContainer(m_sElectronContainerName,ctx); if (!h_ElectronContainer.isValid()) { - ATH_MSG_FATAL("Electron container with name " << m_sElectronContainerName << " was not found in event store, but is needed for electron OLR. Ensure that it is there with the correct name"); + ATH_MSG_FATAL( + "Electron container with name " + << m_sElectronContainerName + << " was not found in event store, but is needed for electron OLR. " + "Ensure that it is there with the correct name"); return StatusCode::FAILURE; } @@ -141,7 +147,7 @@ StatusCode TauOverlappingElectronLLHDecorator::decorate(const xAOD::TauJet& xTau // compute the LH score if there is a match if(xEleMatch!=0) - fLHScore = m_tEMLHTool->calculate(xEleMatch); + fLHScore = m_tEMLHTool->calculate(ctx,xEleMatch); // static SG::AuxElement::Decorator< ElementLink< xAOD::ElectronContainer > > decElectronLink("electronLink"); // // create link to the matched electron