diff --git a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/CMakeLists.txt b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/CMakeLists.txt index 3648b959f98aa285643b28494819e280efee3dbb..81b9390700f4ab38b685d60532cdcb14dd4bac7b 100644 --- a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/CMakeLists.txt +++ b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/CMakeLists.txt @@ -11,14 +11,13 @@ endif() # External dependencies: find_package( ROOT COMPONENTS Core Hist RIO Matrix) -find_package( Boost ) atlas_add_library( IsolationCorrectionsLib IsolationCorrections/*.h Root/*.cxx PUBLIC_HEADERS IsolationCorrections INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} - PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} - LINK_LIBRARIES ${ROOT_LIBRARIES} AsgMessagingLib AsgTools xAODEgamma xAODEventInfo xAODEventShape + LINK_LIBRARIES ${ROOT_LIBRARIES} AsgMessagingLib AsgDataHandlesLib AsgTools + xAODEgamma xAODEventInfo xAODEventShape xAODPrimitives xAODTracking PATInterfaces PATCoreAcceptLib PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} PathResolver ${extra_libs} ) diff --git a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/IsolationCorrections/IsolationCorrection.h b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/IsolationCorrections/IsolationCorrection.h index b84ae5695db3b9340336ad5529c00bd73ffc455f..db47354048e440385d3d28280b55b6df42e2ad1f 100644 --- a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/IsolationCorrections/IsolationCorrection.h +++ b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/IsolationCorrections/IsolationCorrection.h @@ -24,21 +24,20 @@ class IsolationCorrection : public asg::AsgMessaging{ // Create a proper constructor for Athena public: - IsolationCorrection(std::string name); + IsolationCorrection(const std::string& name); ~IsolationCorrection(); StatusCode initialize(); - StatusCode finalize(); typedef enum { ELECTRON=0, PHOTON=1 } ParticleType; typedef enum { REL17=1, REL17_2=2, REL20=6, REL20_2=7, REL21=8 } Version; - void SetCorrectionFile( std::string corr_file, std::string corr_ddshift_file, std::string corr_ddsmearing_file); + void SetCorrectionFile( const std::string& corr_file, const std::string& corr_ddshift_file, const std::string& corr_ddsmearing_file); void SetToolVer(CP::IsolationCorrection::Version); - float GetPtCorrectedIsolation(const xAOD::Egamma&, const xAOD::Iso::IsolationType); + float GetPtCorrectedIsolation(const xAOD::Egamma&, const xAOD::Iso::IsolationType) const; float GetPtCorrection(const xAOD::Egamma&, const xAOD::Iso::IsolationType) const; - float GetDDCorrection(const xAOD::Egamma&, const xAOD::Iso::IsolationType, std::string year); + float GetDDCorrection(const xAOD::Egamma&, const xAOD::Iso::IsolationType, const std::string& year); float GetEtaPointing(const xAOD::Egamma*); void SetDataMC(bool is_mc); @@ -68,7 +67,7 @@ class IsolationCorrection : public asg::AsgMessaging{ std::vector<float> m_feta_bins_dd_2015; std::vector<float> m_feta_bins_dd_2017; - StatusCode setupDD(std::string year); + StatusCode setupDD(const std::string& year); bool m_is_mc; bool m_AFII_corr; diff --git a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/IsolationCorrections/IsolationCorrectionTool.h b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/IsolationCorrections/IsolationCorrectionTool.h index d99f8aa5f3c8601e7fe79b927fe39b3d25c949f3..ab65190d52277dea3b2eef899f493e926c07ed0c 100644 --- a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/IsolationCorrections/IsolationCorrectionTool.h +++ b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/IsolationCorrections/IsolationCorrectionTool.h @@ -5,84 +5,118 @@ #ifndef ISOLATIONCORRECTION_ISOLATIONCORRECTIONTOOL_H #define ISOLATIONCORRECTION_ISOLATIONCORRECTIONTOOL_H -#include "AsgTools/AsgTool.h" -#include "AsgTools/AsgMetadataTool.h" -#include "AsgMessaging/AsgMessaging.h" #include "IsolationCorrections/IIsolationCorrectionTool.h" #include "IsolationCorrections/IsolationCorrection.h" +// +#include "AsgDataHandles/ReadHandleKey.h" +#include "AsgDataHandles/ReadHandle.h" +#include "AsgMessaging/AsgMessaging.h" +#include "AsgTools/AsgMetadataTool.h" +#include "AsgTools/AsgTool.h" +// +#include "xAODEventInfo/EventInfo.h" +#include "xAODEventShape/EventShape.h" +// #include "TGraph.h" namespace CP { -class IsolationCorrectionTool : virtual public IIsolationCorrectionTool, - public asg::AsgMetadataTool { - // Create a proper constructor for Athena - ASG_TOOL_CLASS3( IsolationCorrectionTool, IIsolationCorrectionTool, CP::ISystematicsTool, CP::IReentrantSystematicsTool) - - public: - IsolationCorrectionTool( const std::string& name ); - virtual ~IsolationCorrectionTool(); - - virtual StatusCode initialize() override; - virtual StatusCode finalize() -#ifndef XAOD_STANDALONE - override -#endif - ; - - // Apply correction to a modifyable Egamma object - virtual CP::CorrectionCode applyCorrection(xAOD::Egamma&) override; - - // This helps to correct for the (wrong) leakage at the analysis level - virtual CP::CorrectionCode CorrectLeakage(xAOD::Egamma&) override; - - // Create a corrected copy from a const Egamma object - virtual CP::CorrectionCode correctedCopy( const xAOD::Egamma&, xAOD::Egamma*&) override; - - //systematics - // Which systematics have an effect on the tool's behaviour? - virtual CP::SystematicSet affectingSystematics() const override; - // Is the tool affected by a specific systematic? - virtual bool isAffectedBySystematic( const CP::SystematicVariation& systematic ) const override; - //Systematics to be used for physics analysis - virtual CP::SystematicSet recommendedSystematics() const override; - //Use specific systematic - virtual StatusCode applySystematicVariation ( const CP::SystematicSet& systConfig ) override; - - virtual float GetPtCorrectedIsolation(const xAOD::Egamma&, xAOD::Iso::IsolationType) override; - virtual float GetPtCorrection(const xAOD::Egamma&, xAOD::Iso::IsolationType) const override; - virtual float GetDDCorrection(const xAOD::Egamma&, xAOD::Iso::IsolationType) override; - //void setDDVer(std::string a) { m_ddVersion = a; }; //temporary for test - void Print() { m_isol_corr->Print(); }; - - private: - float GetEtaPointing(const xAOD::Egamma* input) {return m_isol_corr->GetEtaPointing(input);}; - - std::string m_corr_file; - std::string m_corr_ddshift_file; - std::string m_corr_ddsmearing_file; - IsolationCorrection* m_isol_corr; - std::string m_tool_ver_str; - - bool m_apply_SC_leak_corr; - bool m_apply_etaEDParPU_corr; - bool m_apply_etaEDParPU_mc_corr; - std::string m_corr_etaEDParPU_file; - std::string m_corr_etaEDPar_mc_corr_file; - std::map<xAOD::Iso::IsolationType,std::unique_ptr<TGraph>> m_map_isotype_zetaPU; - std::map<xAOD::Iso::IsolationType,std::unique_ptr<TGraph>> m_map_isotype_zeta_mc_corr; - - bool m_is_mc; - bool m_AFII_corr; - std::string m_ddVersion; - bool m_apply_dd, m_apply_ddDefault; - bool m_correct_etcone; - bool m_trouble_categories; - bool m_useLogLogFit; - bool m_forcePartType; - - // For systematcis - CP::SystematicVariation m_systDDonoff; +class IsolationCorrectionTool + : virtual public IIsolationCorrectionTool + , public asg::AsgMetadataTool +{ + // Create a proper constructor for Athena + ASG_TOOL_CLASS3(IsolationCorrectionTool, + IIsolationCorrectionTool, + CP::ISystematicsTool, + CP::IReentrantSystematicsTool) + +public: + IsolationCorrectionTool(const std::string& name); + virtual ~IsolationCorrectionTool(); + + virtual StatusCode initialize() override final; + + // Apply correction to a modifyable Egamma object + virtual CP::CorrectionCode applyCorrection(xAOD::Egamma&) override final; + + // This helps to correct for the (wrong) leakage at the analysis level + virtual CP::CorrectionCode CorrectLeakage(xAOD::Egamma&) override final; + + // Create a corrected copy from a const Egamma object + virtual CP::CorrectionCode correctedCopy(const xAOD::Egamma&, + xAOD::Egamma*&) override final; + + // systematics + // Which systematics have an effect on the tool's behaviour? + virtual CP::SystematicSet affectingSystematics() const override final; + // Is the tool affected by a specific systematic? + virtual bool isAffectedBySystematic( + const CP::SystematicVariation& systematic) const override final; + // Systematics to be used for physics analysis + virtual CP::SystematicSet recommendedSystematics() const override final; + // Use specific systematic + virtual StatusCode applySystematicVariation( + const CP::SystematicSet& systConfig) override final; + + virtual float GetPtCorrectedIsolation(const xAOD::Egamma&, + xAOD::Iso::IsolationType) override; + virtual float GetPtCorrection(const xAOD::Egamma&, + xAOD::Iso::IsolationType) const override final; + virtual float GetDDCorrection(const xAOD::Egamma&, + xAOD::Iso::IsolationType) override final; + void Print() { m_isol_corr->Print(); }; + +private: + float GetEtaPointing(const xAOD::Egamma* input) + { + return m_isol_corr->GetEtaPointing(input); + }; + + SG::ReadHandleKey<xAOD::EventInfo> m_eventInfoKey{ this, + "EventInfoKey", + "EventInfo", + "" }; + SG::ReadHandleKey<xAOD::EventShape> m_centralEventShapeKey{ + this, + "CentralEventShapeKey", + "TopoClusterIsoCentralEventShape", + "" + }; + + SG::ReadHandleKey<xAOD::EventShape> m_forwardEventShapeKey{ + this, + "ForwardEventShape", + "TopoClusterIsoForwardEventShape", + "" + }; + + std::string m_corr_file; + std::string m_corr_ddshift_file; + std::string m_corr_ddsmearing_file; + IsolationCorrection* m_isol_corr; + std::string m_tool_ver_str; + + std::string m_corr_etaEDParPU_file; + std::string m_corr_etaEDPar_mc_corr_file; + std::map<xAOD::Iso::IsolationType, std::unique_ptr<TGraph>> + m_map_isotype_zetaPU; + std::map<xAOD::Iso::IsolationType, std::unique_ptr<TGraph>> + m_map_isotype_zeta_mc_corr; + std::string m_ddVersion; + bool m_apply_SC_leak_corr; + bool m_apply_etaEDParPU_corr; + bool m_apply_etaEDParPU_mc_corr; + bool m_is_mc; + bool m_AFII_corr; + bool m_apply_dd, m_apply_ddDefault; + bool m_correct_etcone; + bool m_trouble_categories; + bool m_useLogLogFit; + bool m_forcePartType; + + // For systematcis + CP::SystematicVariation m_systDDonoff; }; } diff --git a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/IsolationCorrection.cxx b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/IsolationCorrection.cxx index 65f19e57409c80bac51f431ca646fca919200132..c2e742fc906c3554498bf33af95e0d7b76ce4859 100644 --- a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/IsolationCorrection.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/IsolationCorrection.cxx @@ -20,6 +20,8 @@ #include "PathResolver/PathResolver.h" #include <typeinfo> +#include <utility> + namespace{ const float GeV(1000); @@ -27,7 +29,7 @@ const float GeV(1000); namespace CP { - IsolationCorrection::IsolationCorrection(std::string name) + IsolationCorrection::IsolationCorrection(const std::string& name) : asg::AsgMessaging(name), m_tool_ver(REL21), m_nBinsEtaFine(10), @@ -53,7 +55,7 @@ namespace CP { } } - void IsolationCorrection::SetCorrectionFile(std::string corr_file, std::string corr_ddshift_file, std::string corr_ddsmearing_file) { + void IsolationCorrection::SetCorrectionFile(const std::string& corr_file, const std::string& corr_ddshift_file, const std::string& corr_ddsmearing_file) { // the leakage parameterisation m_corr_file = PathResolverFindCalibFile(corr_file); // the DD shifts (for photons) @@ -76,11 +78,8 @@ namespace CP { m_tool_ver = ver; } - StatusCode IsolationCorrection::finalize() { - return StatusCode::SUCCESS; - } - float IsolationCorrection::GetPtCorrectedIsolation(const xAOD::Egamma& input, const xAOD::Iso::IsolationType isol){ + float IsolationCorrection::GetPtCorrectedIsolation(const xAOD::Egamma& input, const xAOD::Iso::IsolationType isol) const{ float corrected_isolation = input.isolationValue(isol) - GetPtCorrection(input, isol); return corrected_isolation; @@ -186,7 +185,7 @@ namespace CP { if (!etaPointing.has_value()) return 0.; float radius = xAOD::Iso::coneSize(isol); - bool is_topo = xAOD::Iso::isolationFlavour(isol) == xAOD::Iso::topoetcone ? true : false; + bool is_topo = xAOD::Iso::isolationFlavour(isol) == xAOD::Iso::topoetcone; if(is_topo){ @@ -227,9 +226,9 @@ namespace CP { } // I also include the DD from 2015 study because it is done in the same way as 2015-2016 or 2017 -StatusCode IsolationCorrection::setupDD(std::string year) { +StatusCode IsolationCorrection::setupDD(const std::string& year) { - if (m_corr_ddshift_file == ""){ + if (m_corr_ddshift_file.empty()){ ATH_MSG_WARNING("IsolationCorrection::GetDDCorrection " << year << ", unknown correction file name.\nNo correction is applied.\n"); return StatusCode::FAILURE; } @@ -283,8 +282,8 @@ StatusCode IsolationCorrection::setupDD(std::string year) { m_feta_bins_dd->resize(veta->GetNrows()); for (int ieta = 0; ieta < veta->GetNrows(); ieta++) m_feta_bins_dd->at(ieta) = (*veta)[ieta]; TTree *tbinLabel = (TTree*)file_ptleakagecorr->Get(baseN+"tbinLabel"); - TBranch *bbinLabel(0); - TString *binLabel(0); tbinLabel->SetBranchAddress("binLabel",&binLabel,&bbinLabel); + TBranch *bbinLabel(nullptr); + TString *binLabel(nullptr); tbinLabel->SetBranchAddress("binLabel",&binLabel,&bbinLabel); for (unsigned int ieta = 0; ieta < m_feta_bins_dd->size()-2; ieta++) { tbinLabel->GetEntry(ieta); TString gN = "topoETcone40_DataDriven_unconverted_photon_eta_"; @@ -314,7 +313,7 @@ StatusCode IsolationCorrection::setupDD(std::string year) { return StatusCode::SUCCESS; } - float IsolationCorrection::GetDDCorrection(const xAOD::Egamma& input, const xAOD::Iso::IsolationType isol, std::string year) { + float IsolationCorrection::GetDDCorrection(const xAOD::Egamma& input, const xAOD::Iso::IsolationType isol, const std::string& year) { ATH_MSG_VERBOSE("Getting DD correction"); if (setupDD(year) == StatusCode::FAILURE) { @@ -488,7 +487,7 @@ StatusCode IsolationCorrection::setupDD(std::string year) { } void IsolationCorrection::set2012Corr() { - if( m_corr_file != ""){ + if( !m_corr_file.empty()){ load2012Corr(); }else{ ATH_MSG_WARNING("Correction file for 2017 data/mc not specified, tool not initialized for 2017 corrections\n"); @@ -606,7 +605,7 @@ StatusCode IsolationCorrection::setupDD(std::string year) { } void IsolationCorrection::set2015Corr() { - if( m_corr_file != ""){ + if( !m_corr_file.empty()){ load2015Corr(); }else{ ATH_MSG_WARNING("Correction file for 2015 data/mc not specified, tool not initialized for 2015 corrections\n"); @@ -771,7 +770,7 @@ StatusCode IsolationCorrection::setupDD(std::string year) { } void IsolationCorrection::setDDCorr() { - if( m_corr_ddshift_file != "" && m_corr_ddsmearing_file != ""){ + if( !m_corr_ddshift_file.empty() && !m_corr_ddsmearing_file.empty()){ loadDDCorr(); }else{ ATH_MSG_WARNING("Data-driven correction files not specified, tool not initialized for data-driven corrections\n"); @@ -857,11 +856,11 @@ StatusCode IsolationCorrection::setupDD(std::string year) { m_graph_dd_cone40_photon_smearing.push_back( graph_smearing.at(12)->GetFunction("f_3") ); m_graph_dd_cone40_photon_smearing.push_back( graph_smearing.at(13)->GetFunction("f_3") ); - for (auto gr : graph_shift) { + for (const auto& gr : graph_shift) { if (gr == nullptr) ATH_MSG_ERROR("Null pointer for one of the DD correction graphs"); } - for (auto gr : graph_smearing) { + for (const auto& gr : graph_smearing) { if (gr == nullptr) ATH_MSG_ERROR("Null pointer for one of the smearing graphs"); } @@ -948,13 +947,13 @@ StatusCode IsolationCorrection::setupDD(std::string year) { } - if (m_graph_dd_2015_2016_cone40_unconv_photon_shift.size()) { + if (!m_graph_dd_2015_2016_cone40_unconv_photon_shift.empty()) { FreeClear(m_graph_dd_2015_2016_cone40_unconv_photon_shift); FreeClear(m_graph_dd_2015_2016_cone40_conv_photon_shift); FreeClear(m_graph_dd_2015_2016_cone20_unconv_photon_shift); FreeClear(m_graph_dd_2015_2016_cone20_conv_photon_shift); } - if (m_graph_dd_2017_cone40_unconv_photon_shift.size()) { + if (!m_graph_dd_2017_cone40_unconv_photon_shift.empty()) { FreeClear(m_graph_dd_2017_cone40_unconv_photon_shift); FreeClear(m_graph_dd_2017_cone40_conv_photon_shift); FreeClear(m_graph_dd_2017_cone20_unconv_photon_shift); @@ -1259,7 +1258,7 @@ StatusCode IsolationCorrection::setupDD(std::string year) { double etaForPt = ((fabs(etaPointing - etaCluster) < 0.15) ? etaPointing : etaCluster); double et = (fabs(etaForPt)<99.) ? energy/cosh(etaForPt) : 0.; int etabin = GetEtaBinFine(etaS2); - if( m_corr_file == "" ){ + if( m_corr_file.empty() ){ ATH_MSG_WARNING("IsolationCorrection::GetPtCorrection_FromGraph: the file containing the isolation leakage corrections is not initialized.\nNo correction is applied.\n"); return 0; } @@ -1327,7 +1326,7 @@ StatusCode IsolationCorrection::setupDD(std::string year) { // for test if (m_forcePartType && parttype == PHOTON) conversion_type = conv_radius > 800 ? 0 : (conv_radius > 140 ? 1 : 2); - if( m_corr_file == "" ){ + if( m_corr_file.empty() ){ ATH_MSG_WARNING("In IsolationCorrection::GetPtCorrection_FromGraph_2015: the file containing the isolation leakage corrections is not initialized.\nNo correction is applied.\n"); return 0; } @@ -1403,7 +1402,7 @@ StatusCode IsolationCorrection::setupDD(std::string year) { void IsolationCorrection::Print() { ATH_MSG_INFO("Print properties of the parametrisation"); - for (auto i : m_function_2015_cone20_photon_unconverted) { + for (auto *i : m_function_2015_cone20_photon_unconverted) { ATH_MSG_INFO("ptr = " << i); if (i) { ATH_MSG_INFO(typeid(i).name()); @@ -1413,4 +1412,4 @@ StatusCode IsolationCorrection::setupDD(std::string year) { } -} \ No newline at end of file +} diff --git a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/IsolationCorrectionTool.cxx b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/IsolationCorrectionTool.cxx index b591e126eb264074c3800fcd8086c8d23e80533a..d53a94c2618413a3a2ad25e55c78f5e7e8f3dc7b 100644 --- a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/IsolationCorrectionTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/IsolationCorrectionTool.cxx @@ -9,7 +9,6 @@ #include "xAODEventInfo/EventInfo.h" #include "PATInterfaces/SystematicRegistry.h" #include "PathResolver/PathResolver.h" -#include <boost/algorithm/string.hpp> #include "xAODPrimitives/IsolationHelpers.h" #ifndef ROOTCORE @@ -18,7 +17,6 @@ #endif //ROOTCORE #include "TFile.h" -#include "xAODEventShape/EventShape.h" namespace CP { @@ -26,7 +24,7 @@ namespace CP { : asg::AsgMetadataTool(name), m_systDDonoff("PH_Iso_DDonoff") { declareProperty("CorrFile", m_corr_file = "IsolationCorrections/v5/isolation_ptcorrections_rel20_2.root"); declareProperty("CorrFile_ddshift", m_corr_ddshift_file = "IsolationCorrections/v3/isolation_ddcorrection_shift.root"); - declareProperty("CorrFile_ddsmearing", m_corr_ddsmearing_file = "IsolationCorrections/v1/isolation_ddcorrection_smearing.root", "a run I smearing for MC calo iso"); + declareProperty("CorrFile_ddsmearing", m_corr_ddsmearing_file = "IsolationCorrections/v1/isolation_ddcorrection_smearing.root", "a run I smearing for MC calo iso"); declareProperty("ToolVer", m_tool_ver_str = "REL21"); declareProperty("DataDrivenVer", m_ddVersion = "2017"); declareProperty("AFII_corr", m_AFII_corr = false); @@ -48,8 +46,13 @@ namespace CP { StatusCode IsolationCorrectionTool::initialize() { ATH_MSG_INFO( "in initialize of " << name() << "..." ); - m_isol_corr->msg().setLevel(this->msg().level()); + //ReadHandles + ASG_CHECK(m_eventInfoKey.initialize()); + ASG_CHECK(m_centralEventShapeKey.initialize(m_apply_etaEDParPU_corr)); + ASG_CHECK(m_forwardEventShapeKey.initialize(m_apply_etaEDParPU_corr)); + // + m_isol_corr->msg().setLevel(this->msg().level()); // // Resolve the paths to the input files std::vector < std::string > corrFileNameList; @@ -58,7 +61,7 @@ namespace CP { corrFileNameList.push_back(m_corr_ddsmearing_file); for ( unsigned int i=0; i<corrFileNameList.size(); ++i ){ - + //First try the PathResolver std::string filename = PathResolverFindCalibFile( corrFileNameList.at(i) ); if (filename.empty()){ @@ -67,13 +70,13 @@ namespace CP { } else{ ATH_MSG_INFO(" Path found = "<<filename); } - corrFileNameList.at(i) = filename; + corrFileNameList.at(i) = filename; } // CP::IsolationCorrection::Version tool_ver; - - if (m_tool_ver_str == "REL21") tool_ver = CP::IsolationCorrection::REL21; + + if (m_tool_ver_str == "REL21") tool_ver = CP::IsolationCorrection::REL21; else if (m_tool_ver_str == "REL20_2") tool_ver = CP::IsolationCorrection::REL20_2; else if (m_tool_ver_str == "REL17_2") tool_ver = CP::IsolationCorrection::REL17_2; else { @@ -97,10 +100,10 @@ namespace CP { m_isol_corr->FitType(m_useLogLogFit); m_isol_corr->ForcePartType(m_forcePartType); - // Note that systematics in Rel 21 are NOT done with the DD-Corr ON/OFF method! + // Note that systematics in Rel 21 are NOT done with the DD-Corr ON/OFF method! if (m_apply_ddDefault) { if (m_ddVersion == "2015" || m_ddVersion == "2015_2016" || m_ddVersion == "2017") { - //if not REL21, register ourselves with the systematic registry! + //if not REL21, register ourselves with the systematic registry! if (m_tool_ver_str!="REL21") { CP::SystematicRegistry& registry = CP::SystematicRegistry::getInstance(); if( registry.registerSystematics( *this ) != StatusCode::SUCCESS ) return StatusCode::FAILURE; @@ -153,10 +156,6 @@ namespace CP { return m_isol_corr->initialize(); } - StatusCode IsolationCorrectionTool::finalize() { - ATH_MSG_INFO( "in finalize" ); - return m_isol_corr->finalize(); - } // this will correct a corrected topoetcone : replace a (old) leakage by another (new) one // This is not for photon, as it does not consider DD @@ -164,7 +163,7 @@ namespace CP { static const std::vector<xAOD::Iso::IsolationType> topoisolation_types = {xAOD::Iso::topoetcone20, xAOD::Iso::topoetcone40}; - + for (auto type : topoisolation_types) { float oldleak = 0.; if (eg.isolationCaloCorrection(oldleak, type, xAOD::Iso::ptCorrection)) { @@ -185,7 +184,7 @@ namespace CP { return CP::CorrectionCode::Error; } } - + if (m_correct_etcone){ // this is supposed to correct an uncorrected etcone static const std::vector<xAOD::Iso::IsolationType> isolation_types = {xAOD::Iso::etcone20, @@ -221,24 +220,18 @@ namespace CP { ATH_MSG_VERBOSE("SC based core correction value: " << topoetconecoreConeEnergyCorrection); SCsub = - topoetconecoreConeEnergyCorrection + core57cells; } - + float centralDensity = 0.; float forwardDensity = 0.; if(m_apply_etaEDParPU_corr){ - const xAOD::EventShape* evtShapeCentral; - const xAOD::EventShape* evtShapeForward; - if(evtStore()->retrieve(evtShapeCentral, "TopoClusterIsoCentralEventShape").isFailure()){ - ATH_MSG_WARNING("Cannot retrieve density container " << "TopoClusterIsoCentralEventShape" << " for isolation correction."); - return CP::CorrectionCode::Error; - } - if(evtStore()->retrieve(evtShapeForward, "TopoClusterIsoForwardEventShape").isFailure()){ - ATH_MSG_WARNING("Cannot retrieve density container " << "TopoClusterIsoForwardEventShape" << " for isolation correction."); - return CP::CorrectionCode::Error; - } + SG::ReadHandle<xAOD::EventShape> shapeCentral (m_centralEventShapeKey); + SG::ReadHandle<xAOD::EventShape> shapeForward (m_forwardEventShapeKey); + const xAOD::EventShape* evtShapeCentral = shapeCentral.ptr(); + const xAOD::EventShape* evtShapeForward = shapeForward.ptr(); centralDensity = evtShapeCentral->getDensity(xAOD::EventShape::Density); forwardDensity = evtShapeForward->getDensity(xAOD::EventShape::Density); } - + static const std::vector<xAOD::Iso::IsolationType> topoisolation_types = {xAOD::Iso::topoetcone20, xAOD::Iso::topoetcone40}; for (auto type : topoisolation_types) { @@ -251,23 +244,26 @@ namespace CP { bool gotIso = eg.isolationValue(oldiso,type); if (!gotIso) continue; - // Use the Random Run Number from the Event Info to check which year's DD-Corrections to use - // If the RandomRunNo can't be obtained, then default to what is set by either the default choice or by the AuxData check - unsigned int theRunNumber = 0 ; - const xAOD::EventInfo *eventInfo = evtStore()->retrieve< const xAOD::EventInfo>("EventInfo"); - if (eventInfo) { - static const SG::AuxElement::Accessor<unsigned int> randomrunnumber("RandomRunNumber"); - if (randomrunnumber.isAvailable(*eventInfo)) - theRunNumber = randomrunnumber(*(eventInfo)) ; - } else - ATH_MSG_WARNING("Could not retrieve EventInfo object"); + // Use the Random Run Number from the Event Info to check which year's DD-Corrections to use + // If the RandomRunNo can't be obtained, then default to what is set by either the default choice or by the AuxData check + unsigned int theRunNumber = 0 ; + SG::ReadHandle<xAOD::EventInfo> evtInfo (m_eventInfoKey); + const xAOD::EventInfo* eventInfo = evtInfo.ptr(); + if (eventInfo) { + static const SG::AuxElement::Accessor<unsigned int> randomrunnumber("RandomRunNumber"); + if (randomrunnumber.isAvailable(*eventInfo)){ + theRunNumber = randomrunnumber(*(eventInfo)) ; + } + } else{ + ATH_MSG_WARNING("Could not retrieve EventInfo object"); + } if (theRunNumber >= 320000) - m_ddVersion = "2017" ; // RunNo found, and is in 2017 range + m_ddVersion = "2017" ; // RunNo found, and is in 2017 range else if (theRunNumber > 0) m_ddVersion = "2015_2016" ; // RunNo found, but less than 2017 range // otherwise, stick with default (m_ddVersion is already assigned) - // Don't use DD Corrections for AFII if not rel21 ? (I do not know what was done for rel20.7 !!!) + // Don't use DD Corrections for AFII if not rel21 ? (I do not know what was done for rel20.7 !!!) if (m_tool_ver_str != "REL21" && m_AFII_corr) m_apply_dd = false; float iso = oldiso; @@ -340,7 +336,7 @@ namespace CP { float IsolationCorrectionTool::GetPtCorrection(const xAOD::Egamma& input, xAOD::Iso::IsolationType isol) const { return m_isol_corr->GetPtCorrection(input, isol); } - + float IsolationCorrectionTool::GetDDCorrection(const xAOD::Egamma& input, xAOD::Iso::IsolationType isol){ return m_isol_corr->GetDDCorrection(input, isol, m_ddVersion); } diff --git a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/ShowerDepthTool.cxx b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/ShowerDepthTool.cxx index 5001b62ca9435ee617b53f59afc3c7b18f01da4c..3441325bfa9e573dbefc0a5fc4d6696ef65d69c1 100644 --- a/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/ShowerDepthTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/IsolationCorrections/Root/ShowerDepthTool.cxx @@ -8,9 +8,11 @@ #include <TH1.h> #include <TSystem.h> -#include <string> #include <cmath> -#include <stdlib.h> + +#include <cmath> +#include <cstdlib> +#include <string> #include <map> @@ -45,10 +47,7 @@ namespace CP{ m_hData = getHistoFromFile( Tfilename , m_dataHistoName ); m_hMC = getHistoFromFile( Tfilename , m_mcHistoName ); - if( m_hData == nullptr || m_hMC == nullptr ){ - return false; - } - return true; + return !(m_hData == nullptr || m_hMC == nullptr); } /** Shower depth (in mm) on EM1 vs. eta, considering misalignments **/ @@ -67,7 +66,7 @@ namespace CP{ https://svnweb.cern.ch/trac/atlasoff/browser/Calorimeter/CaloDetDescr/trunk/src/CaloDepthTool.cxx#L347 **/ float ShowerDepthTool::getShowerDepthEM1(const float& etas1) const { - float radius, aetas1 = fabs(etas1); + float radius, aetas1 = std::fabs(etas1); if (aetas1 < 0.8) radius = (1558.859292 - 4.990838*aetas1 - 21.144279*aetas1*aetas1); else if (aetas1<1.5) @@ -83,7 +82,7 @@ namespace CP{ https://svnweb.cern.ch/trac/atlasoff/browser/Calorimeter/CaloDetDescr/trunk/src/CaloDepthTool.cxx#L347 **/ float ShowerDepthTool::getShowerDepthEM2(const float& etas2) const { - float radius, aetas2 = fabs(etas2); + float radius, aetas2 = std::fabs(etas2); if (aetas2 < 1.425) // Barrel, my definition radius = (1698.990944 - 49.431767*aetas2 - 24.504976*aetas2*aetas2); else if (aetas2 < 1.5) // EME2 in tool @@ -108,15 +107,15 @@ namespace CP{ std::pair<float,float> ShowerDepthTool::getRZ(const float& eta,const int& sampling) const { - if ((sampling != 1 && sampling != 2) || (fabs(eta)>10)) + if ((sampling != 1 && sampling != 2) || (std::fabs(eta)>10)) { // ATH_MSG_INFO( "Invalid sampling: " << sampling ); return std::make_pair(0., 0.); } float depth = (sampling == 1 ? getShowerDepthEM1(eta) : getShowerDepthEM2(eta) ); - if (fabs(eta) < 1.5) - return std::make_pair( depth, depth*sinh(eta) ); - return std::make_pair( depth/sinh(eta), depth ); + if (std::fabs(eta) < 1.5) + return std::make_pair( depth, depth*std::sinh(eta) ); + return std::make_pair( depth/std::sinh(eta), depth ); } @@ -129,7 +128,7 @@ namespace CP{ constexpr float epsilon=1e-6; if (std::fabs(RZ2.first - RZ1.first) < epsilon) return std::nullopt; - return std::optional<float>(asinh( (RZ2.second - RZ1.second) / (RZ2.first - RZ1.first))); + return std::optional<float>(std::asinh( (RZ2.second - RZ1.second) / (RZ2.first - RZ1.first))); } @@ -139,16 +138,16 @@ namespace CP{ const bool& isData, const int& sampling) const { - if ((sampling != 1 && sampling != 2) || (fabs(eta)>10)) + if ((sampling != 1 && sampling != 2) || (std::fabs(eta)>10)) { // ATH_MSG_INFO( "Invalid sampling: " << sampling ); return std::make_pair(0., 0.); } float depth = (sampling == 1 ? getCorrectedShowerDepthEM1(eta, phi, isData) : getCorrectedShowerDepthEM2(eta, phi, isData) ); - if (fabs(eta) < 1.5) - return std::make_pair( depth, depth*sinh(eta) ); - return std::make_pair( depth/sinh(eta), depth ); + if (std::fabs(eta) < 1.5) + return std::make_pair( depth, depth*std::sinh(eta) ); + return std::make_pair( depth/std::sinh(eta), depth ); } @@ -163,7 +162,7 @@ namespace CP{ float ShowerDepthTool::getEtaDirection(const float& zvertex,const float& R,const float& z) const { - return asinh( (z- zvertex)/R ); + return std::asinh( (z- zvertex)/R ); } @@ -171,15 +170,15 @@ namespace CP{ { std::unique_ptr<TFile> f(TFile::Open(fileName)); if (!f.get()){ - return 0; + return nullptr; } TH1 *h = dynamic_cast<TH1*>( f->Get(histoName) ); if (!h){ f.get()->Close(); - return 0; + return nullptr; } //The file we be deleted so use SetDirectory - h->SetDirectory(0); + h->SetDirectory(nullptr); f.get()->Close(); return h; }