diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetParticleCenterOfMassAssociation.cxx b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetParticleCenterOfMassAssociation.cxx index c5a3d0433c6713efbcf9819dc2f27ed779d668e5..8fac4226cfaa6e0d8cb353ee071438f721dcf66f 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetParticleCenterOfMassAssociation.cxx +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetParticleCenterOfMassAssociation.cxx @@ -1,11 +1,12 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ // author: jie.yu@cern.ch #include "ParticleJetTools/JetParticleCenterOfMassAssociation.h" #include "AsgMessaging/Check.h" +#include "AthContainers/ConstAccessor.h" #include "TLorentzVector.h" using namespace std; @@ -35,17 +36,18 @@ JetParticleCenterOfMassAssociation::match(const JetContainer& jets, const xAOD:: const IParticle& part = **part_itr; + static const SG::ConstAccessor< ElementLink< JetContainer > > ParentAcc ("Parent"); double deltaAngleMatch = 999.; int matchjetidx = -1; for (unsigned int iJet = 0; iJet < jets.size(); iJet++) { const Jet& jet = *jets[iJet]; - bool foundEL = jet.isAvailable< ElementLink< JetContainer > >("Parent"); + bool foundEL = ParentAcc.isAvailable (jet); if ( ! foundEL ){ ATH_MSG_WARNING("PARTICLE to JET center-of-mass Associator: PARENT jet not available."); continue; } - ElementLink< JetContainer > assoParentJet = jet.auxdata< ElementLink< JetContainer > >("Parent"); + ElementLink< JetContainer > assoParentJet = ParentAcc (jet); if ( ! assoParentJet.isValid()){ ATH_MSG_WARNING("PARTICLE to JET center-of-mass Associator: Unable to get parent link Null ptr is returned."); continue; diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTruthLabelingTool.cxx b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTruthLabelingTool.cxx index 07a44dd704ab9b40f0c1773bda3c3bb11820a04f..5d7f89c429fd3012710f4f1490acc37ded6f27e6 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTruthLabelingTool.cxx +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetTruthLabelingTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "ParticleJetTools/JetTruthLabelingTool.h" @@ -8,6 +8,7 @@ #include "AsgDataHandles/ReadDecorHandle.h" #include "AsgDataHandles/WriteDecorHandle.h" #include "AsgTools/CurrentContext.h" +#include "AthContainers/ConstAccessor.h" JetTruthLabelingTool::JetTruthLabelingTool(const std::string& name) : asg::AsgTool(name) @@ -326,12 +327,13 @@ StatusCode JetTruthLabelingTool::labelRecoJets(DecorHandles& dh, truthGroomedJets = SG::makeHandle(m_truthGroomedJetCollectionName, ctx); } const SG::AuxElement::Accessor<int> nbAcc (m_truthLabelName + "_NB"); + static const SG::ConstAccessor< ElementLink< xAOD::JetContainer > > ParentAcc ("Parent"); for(const xAOD::Jet *jet : jets) { /// Get parent ungroomed reco jet for matching const xAOD::Jet* parent = nullptr; if ( m_matchUngroomedParent ){ - ElementLink<xAOD::JetContainer> element_link = jet->auxdata<ElementLink<xAOD::JetContainer> >("Parent"); + ElementLink<xAOD::JetContainer> element_link = ParentAcc (*jet); if ( element_link.isValid() ) { parent = *element_link; } @@ -405,7 +407,7 @@ StatusCode JetTruthLabelingTool::labelRecoJets(DecorHandles& dh, if ( m_getTruthGroomedJetValues ) { if ( matchTruthJet ) { for ( const xAOD::Jet* truthGroomedJet : *truthGroomedJets ) { - ElementLink<xAOD::JetContainer> element_link = truthGroomedJet->auxdata<ElementLink<xAOD::JetContainer> >("Parent"); + ElementLink<xAOD::JetContainer> element_link = ParentAcc (*truthGroomedJet); if ( !element_link.isValid() ) { continue; } if ( matchTruthJet == *element_link ) { matchTruthGroomedJet = truthGroomedJet; diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonFourMomentumCorrection/ElectronPhotonFourMomentumCorrection/EgammaCalibrationAndSmearingTool.h b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonFourMomentumCorrection/ElectronPhotonFourMomentumCorrection/EgammaCalibrationAndSmearingTool.h index 949fa8b118291acac849a557975bdbb0f90f502b..b3bdda61dca13c2ffee6c7a0e538875ac1086977 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonFourMomentumCorrection/ElectronPhotonFourMomentumCorrection/EgammaCalibrationAndSmearingTool.h +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonFourMomentumCorrection/ElectronPhotonFourMomentumCorrection/EgammaCalibrationAndSmearingTool.h @@ -25,6 +25,7 @@ #include "xAODCaloEvent/CaloCluster.h" #include "xAODEventInfo/EventInfo.h" #include "AsgServices/ServiceHandle.h" +#include "AthContainers/ConstAccessor.h" #include "ElectronPhotonFourMomentumCorrection/egammaEnergyCorrectionTool.h" @@ -36,13 +37,14 @@ namespace egGain { class GainTool; } namespace xAOD { inline float get_phi_calo(const xAOD::CaloCluster& cluster, int author, bool do_throw=false) { + static const SG::ConstAccessor<float> phiCaloAcc ("phiCalo"); double phi_calo; if(author== xAOD::EgammaParameters::AuthorFwdElectron){ phi_calo = cluster.phi(); } else if (cluster.retrieveMoment(xAOD::CaloCluster::PHICALOFRAME, phi_calo)) { } - else if (cluster.isAvailable<float>("phiCalo")) { - phi_calo = cluster.auxdata<float>("phiCalo"); + else if (phiCaloAcc.isAvailable(cluster)) { + phi_calo = phiCaloAcc(cluster); } else { asg::AsgMessaging msg("get_phi_calo"); @@ -57,13 +59,14 @@ namespace xAOD { inline float get_eta_calo(const xAOD::CaloCluster& cluster, int author, bool do_throw=false) { double eta_calo; + static const SG::ConstAccessor<float> etaCaloAcc ("etaCalo"); if(author== xAOD::EgammaParameters::AuthorFwdElectron){ eta_calo = cluster.eta(); } else if (cluster.retrieveMoment(xAOD::CaloCluster::ETACALOFRAME, eta_calo)) { } - else if (cluster.isAvailable<float>("etaCalo")) { - eta_calo = cluster.auxdata<float>("etaCalo"); + else if (etaCaloAcc.isAvailable(cluster)) { + eta_calo = etaCaloAcc(cluster); } else { asg::AsgMessaging msg("get_eta_calo"); diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonFourMomentumCorrection/Root/EgammaCalibrationAndSmearingTool.cxx b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonFourMomentumCorrection/Root/EgammaCalibrationAndSmearingTool.cxx index a5c3e5b72648aaf09d0a3c51e5a294acdc30f289..8610a2478dc608bcc35bb33fbe1a3e03402f20b1 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonFourMomentumCorrection/Root/EgammaCalibrationAndSmearingTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonFourMomentumCorrection/Root/EgammaCalibrationAndSmearingTool.cxx @@ -19,6 +19,7 @@ #include "xAODTracking/TrackParticle.h" #include "xAODTracking/TrackingPrimitives.h" #include "xAODEventInfo/EventInfo.h" +#include "AthContainers/ConstAccessor.h" #include "PATInterfaces/SystematicRegistry.h" #include "PathResolver/PathResolver.h" #include <algorithm> @@ -688,6 +689,11 @@ CP::CorrectionCode EgammaCalibrationAndSmearingTool::applyCorrection(xAOD::Egamm setRandomSeed(m_set_seed_function(*this, input, event_info)); } + static const SG::ConstAccessor<double> Es0Acc ("correctedcl_Es0"); + static const SG::ConstAccessor<double> Es1Acc ("correctedcl_Es1"); + static const SG::ConstAccessor<double> Es2Acc ("correctedcl_Es2"); + static const SG::ConstAccessor<double> Es3Acc ("correctedcl_Es3"); + if (dataType == PATCore::ParticleDataType::Data and m_layer_recalibration_tool) { // if data apply energy recalibration ATH_MSG_DEBUG("applying energy recalibration before E0|E1|E2|E3 = " @@ -700,12 +706,12 @@ CP::CorrectionCode EgammaCalibrationAndSmearingTool::applyCorrection(xAOD::Egamm ATH_MSG_DEBUG("eta|phi = " << input.eta() << "|" << input.phi()); if (status_layer_recalibration == CP::CorrectionCode::Ok) { ATH_MSG_DEBUG("decoration E0|E1|E2|E3 = " - << input.caloCluster()->auxdataConst<double>("correctedcl_Es0") << "|" - << input.caloCluster()->auxdataConst<double>("correctedcl_Es1") << "|" - << input.caloCluster()->auxdataConst<double>("correctedcl_Es2") << "|" - << input.caloCluster()->auxdataConst<double>("correctedcl_Es3") << "|"); - if (input.caloCluster()->auxdataConst<double>("correctedcl_Es2") == 0 and input.caloCluster()->auxdataConst<double>("correctedcl_Es1") == 0 and - input.caloCluster()->auxdataConst<double>("correctedcl_Es3") == 0 and input.caloCluster()->auxdataConst<double>("correctedcl_Es0") == 0 and + << Es0Acc(*input.caloCluster()) << "|" + << Es1Acc(*input.caloCluster()) << "|" + << Es2Acc(*input.caloCluster()) << "|" + << Es3Acc(*input.caloCluster()) << "|"); + if (Es2Acc(*input.caloCluster()) == 0 and Es1Acc(*input.caloCluster()) == 0 and + Es3Acc(*input.caloCluster()) == 0 and Es0Acc(*input.caloCluster()) == 0 and (std::abs(input.eta()) < 1.37 or (std::abs(input.eta()) > 1.55 and std::abs(input.eta()) < 2.47))) { ATH_MSG_WARNING("all layer energies are zero"); @@ -748,16 +754,16 @@ CP::CorrectionCode EgammaCalibrationAndSmearingTool::applyCorrection(xAOD::Egamm if (dataType == PATCore::ParticleDataType::Data and m_gain_tool) { const auto cl_eta = input.caloCluster()->eta(); - const auto es2 = input.caloCluster()->isAvailable<double>("correctedcl_Es2") ? input.caloCluster()->auxdataConst<double>("correctedcl_Es2") : input.caloCluster()->energyBE(2); + const auto es2 = Es2Acc.isAvailable(*input.caloCluster()) ? Es2Acc(*input.caloCluster()) : input.caloCluster()->energyBE(2); if ((std::abs(cl_eta) >= 1.52 || std::abs(cl_eta) <= 1.37) and std::abs(cl_eta) < 2.4) energy = m_gain_tool->CorrectionGainTool(cl_eta, energy / GeV, es2 / GeV, xAOD2ptype(input)); // cl_eta ok, TODO: check corrected E2 ATH_MSG_DEBUG("energy after gain correction = " << boost::format("%.2f") % energy); } - const double eraw = ((input.caloCluster()->isAvailable<double>("correctedcl_Es0") ? input.caloCluster()->auxdataConst<double>("correctedcl_Es0") : input.caloCluster()->energyBE(0)) + - (input.caloCluster()->isAvailable<double>("correctedcl_Es1") ? input.caloCluster()->auxdataConst<double>("correctedcl_Es1") : input.caloCluster()->energyBE(1)) + - (input.caloCluster()->isAvailable<double>("correctedcl_Es2") ? input.caloCluster()->auxdataConst<double>("correctedcl_Es2") : input.caloCluster()->energyBE(2)) + - (input.caloCluster()->isAvailable<double>("correctedcl_Es3") ? input.caloCluster()->auxdataConst<double>("correctedcl_Es3") : input.caloCluster()->energyBE(3))); + const double eraw = ((Es0Acc.isAvailable(*input.caloCluster()) ? Es0Acc(*input.caloCluster()) : input.caloCluster()->energyBE(0)) + + (Es1Acc.isAvailable(*input.caloCluster()) ? Es1Acc(*input.caloCluster()) : input.caloCluster()->energyBE(1)) + + (Es2Acc.isAvailable(*input.caloCluster()) ? Es2Acc(*input.caloCluster()) : input.caloCluster()->energyBE(2)) + + (Es3Acc.isAvailable(*input.caloCluster()) ? Es3Acc(*input.caloCluster()) : input.caloCluster()->energyBE(3))); unsigned int runNumber_for_tool = 0; @@ -791,7 +797,7 @@ CP::CorrectionCode EgammaCalibrationAndSmearingTool::applyCorrection(xAOD::Egamm input.caloCluster()->eta(), xAOD::get_eta_calo(*input.caloCluster(), input.author(), false), energy, - input.caloCluster()->isAvailable<double>("correctedcl_Es2") ? input.caloCluster()->auxdataConst<double>("correctedcl_Es2") : input.caloCluster()->energyBE(2), + Es2Acc.isAvailable(*input.caloCluster()) ? Es2Acc(*input.caloCluster()) : input.caloCluster()->energyBE(2), eraw, oldtool_scale_flag_this_event(input, event_info), oldtool_resolution_flag_this_event(input, event_info), diff --git a/Reconstruction/egamma/egammaMVACalib/egammaMVACalib/egammaMVAFunctions.h b/Reconstruction/egamma/egammaMVACalib/egammaMVACalib/egammaMVAFunctions.h index ab45d27311f838d1d854df00583a6c7272e3c089..d735c6bdab34cb99431a6019f8b5776dbcbdd891 100644 --- a/Reconstruction/egamma/egammaMVACalib/egammaMVACalib/egammaMVAFunctions.h +++ b/Reconstruction/egamma/egammaMVACalib/egammaMVACalib/egammaMVAFunctions.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef EGAMMAMVACALIB_EGAMMAMVAFUNCTIONS @@ -12,6 +12,7 @@ #include "xAODEgamma/PhotonxAODHelpers.h" #include "xAODCaloEvent/CaloCluster.h" #include "egammaMVALayerDepth.h" +#include "AthContainers/ConstAccessor.h" #include "TLorentzVector.h" @@ -73,10 +74,22 @@ namespace egammaMVAFunctions inline float compute_rawcl_Es2(const xAOD::CaloCluster& cl) { return cl.energyBE(2); } inline float compute_rawcl_Es3(const xAOD::CaloCluster& cl) { return cl.energyBE(3); } - inline float compute_correctedcl_Es0(const xAOD::CaloCluster& cl) { return cl.isAvailable<double>("correctedcl_Es0") ? cl.auxdataConst<double>("correctedcl_Es0") : cl.energyBE(0); } - inline float compute_correctedcl_Es1(const xAOD::CaloCluster& cl) { return cl.isAvailable<double>("correctedcl_Es1") ? cl.auxdataConst<double>("correctedcl_Es1") : cl.energyBE(1); } - inline float compute_correctedcl_Es2(const xAOD::CaloCluster& cl) { return cl.isAvailable<double>("correctedcl_Es2") ? cl.auxdataConst<double>("correctedcl_Es2") : cl.energyBE(2); } - inline float compute_correctedcl_Es3(const xAOD::CaloCluster& cl) { return cl.isAvailable<double>("correctedcl_Es3") ? cl.auxdataConst<double>("correctedcl_Es3") : cl.energyBE(3); } + inline float compute_correctedcl_Es0(const xAOD::CaloCluster& cl) { + static const SG::ConstAccessor<double> acc ("correctedcl_Es0"); + return acc.isAvailable(cl) ? acc(cl) : cl.energyBE(0); + } + inline float compute_correctedcl_Es1(const xAOD::CaloCluster& cl) { + static const SG::ConstAccessor<double> acc ("correctedcl_Es1"); + return acc.isAvailable(cl) ? acc(cl) : cl.energyBE(1); + } + inline float compute_correctedcl_Es2(const xAOD::CaloCluster& cl) { + static const SG::ConstAccessor<double> acc ("correctedcl_Es2"); + return acc.isAvailable(cl) ? acc(cl) : cl.energyBE(2); + } + inline float compute_correctedcl_Es3(const xAOD::CaloCluster& cl) { + static const SG::ConstAccessor<double> acc ("correctedcl_Es3"); + return acc.isAvailable(cl) ? acc(cl) : cl.energyBE(3); + } inline float compute_rawcl_Eacc(const xAOD::CaloCluster& cl) { return cl.energyBE(1) + cl.energyBE(2) + cl.energyBE(3); } inline float compute_rawcl_f0(const xAOD::CaloCluster& cl) { return cl.energyBE(0) / (cl.energyBE(1) + cl.energyBE(2) + cl.energyBE(3)); } @@ -125,7 +138,10 @@ namespace egammaMVAFunctions inline float compute_el_trackpt(const xAOD::Electron& el) { return el.trackParticle()->pt(); } inline float compute_el_trackz0(const xAOD::Electron& el) { return el.trackParticle()->z0(); } inline float compute_el_refittedTrack_qoverp(const xAOD::Electron& el) { return el.trackParticle()->qOverP(); } - inline int compute_el_author(const xAOD::Electron& el) { return el.auxdata<unsigned short int>("author"); } + inline int compute_el_author(const xAOD::Electron& el) { + static const SG::ConstAccessor<unsigned short int> acc ("author"); + return acc (el); + } // photon functions