From 93437718a927aa76e488d7f2a99e27b4a2b7b1c6 Mon Sep 17 00:00:00 2001 From: christos <christos@cern.ch> Date: Mon, 14 Nov 2022 19:52:01 +0100 Subject: [PATCH 1/2] Isolation selection 1st pass --- .../IIsolationCloseByCorrectionTool.h | 4 +-- .../IsolationCloseByCorrectionTool.h | 4 +-- .../Root/IsolationCloseByCorrectionTool.cxx | 4 +-- .../src/TestIsolationCloseByCorrAlg.cxx | 35 ++++++++++++------- .../src/TestIsolationCloseByCorrAlg.h | 9 +++-- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/IIsolationCloseByCorrectionTool.h b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/IIsolationCloseByCorrectionTool.h index 4b5bc8067be6..2076cc598e83 100644 --- a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/IIsolationCloseByCorrectionTool.h +++ b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/IIsolationCloseByCorrectionTool.h @@ -35,8 +35,8 @@ namespace CP { const std::vector<xAOD::Iso::IsolationType>& types, const xAOD::IParticleContainer& closePar) const = 0; - virtual CorrectionCode getCloseByIsoCorrection(const xAOD::ElectronContainer* Electrons = nullptr, const xAOD::MuonContainer* Muons = nullptr, - const xAOD::PhotonContainer* Photons = nullptr) const = 0; + virtual CorrectionCode getCloseByIsoCorrection(xAOD::ElectronContainer* Electrons = nullptr, xAOD::MuonContainer* Muons = nullptr, + xAOD::PhotonContainer* Photons = nullptr) const = 0; virtual CorrectionCode subtractCloseByContribution(xAOD::IParticle& x, const xAOD::IParticleContainer& closebyPar) const = 0; virtual float getOriginalIsolation(const xAOD::IParticle& P, IsoType type) const = 0; diff --git a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/IsolationCloseByCorrectionTool.h b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/IsolationCloseByCorrectionTool.h index 92805fe3a596..6764b6e9f68f 100644 --- a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/IsolationCloseByCorrectionTool.h +++ b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/IsolationCloseByCorrectionTool.h @@ -57,8 +57,8 @@ namespace CP { virtual asg::AcceptData acceptCorrected(const xAOD::IParticle& x, const xAOD::IParticleContainer& closePar) const override; - virtual CorrectionCode getCloseByIsoCorrection(const xAOD::ElectronContainer* Electrons, const xAOD::MuonContainer* Muons, - const xAOD::PhotonContainer* Photons) const override; + virtual CorrectionCode getCloseByIsoCorrection(xAOD::ElectronContainer* Electrons, xAOD::MuonContainer* Muons, + xAOD::PhotonContainer* Photons) const override; virtual CorrectionCode subtractCloseByContribution(xAOD::IParticle& x, const xAOD::IParticleContainer& closebyPar) const override; virtual float getOriginalIsolation(const xAOD::IParticle& P, IsoType type) const override; diff --git a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/Root/IsolationCloseByCorrectionTool.cxx b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/Root/IsolationCloseByCorrectionTool.cxx index dc4857aa9139..3efbe8d0f571 100644 --- a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/Root/IsolationCloseByCorrectionTool.cxx +++ b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/Root/IsolationCloseByCorrectionTool.cxx @@ -180,8 +180,8 @@ namespace CP { } } } - CorrectionCode IsolationCloseByCorrectionTool::getCloseByIsoCorrection(const xAOD::ElectronContainer* Electrons, const xAOD::MuonContainer* Muons, - const xAOD::PhotonContainer* Photons) const { + CorrectionCode IsolationCloseByCorrectionTool::getCloseByIsoCorrection(xAOD::ElectronContainer* Electrons, xAOD::MuonContainer* Muons, + xAOD::PhotonContainer* Photons) const { if (!m_isInitialised) { ATH_MSG_ERROR("The IsolationCloseByCorrectionTool was not initialised!!!"); return CorrectionCode::Error; diff --git a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.cxx b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.cxx index a6ca42888c6a..b6dc64495a86 100644 --- a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.cxx +++ b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.cxx @@ -58,8 +58,10 @@ namespace CP { return StatusCode::SUCCESS; } template <class CONT_TYPE> - StatusCode TestIsolationCloseByCorrAlg::loadContainer(const EventContext& ctx, const SG::ReadHandleKey<CONT_TYPE>& key, - const CONT_TYPE*& cont) const { + StatusCode TestIsolationCloseByCorrAlg::loadContainer(const EventContext& ctx, + const SG::ReadHandleKey<CONT_TYPE>& key, + std::pair<std::unique_ptr<CONT_TYPE>, + std::unique_ptr<xAOD::ShallowAuxContainer>>& cont) const { if (key.empty()) { ATH_MSG_DEBUG("No key given. Assume it's no required to load the container"); return StatusCode::SUCCESS; @@ -69,9 +71,10 @@ namespace CP { ATH_MSG_FATAL("Failed to load container " << key.fullKey()); return StatusCode::FAILURE; } - cont = readHandle.ptr(); + cont = xAOD::shallowCopyContainer(*readHandle,ctx); if (!m_selDecorator && !m_isoDecorator) return StatusCode::SUCCESS; - for (const auto part : *cont) { + std::unique_ptr<CONT_TYPE>& elems = cont.first; + for (auto part : *(elems.get()) ) { if (m_selDecorator) (*m_selDecorator)(*part) = passSelection(ctx, part); if (m_isoDecorator) (*m_isoDecorator)(*part) = true && m_isoSelectorTool->accept(*part); } @@ -95,15 +98,21 @@ namespace CP { StatusCode TestIsolationCloseByCorrAlg::execute() { const EventContext& ctx = Gaudi::Hive::currentContext(); - const xAOD::ElectronContainer* Electrons{nullptr}; - const xAOD::MuonContainer* Muons{nullptr}; - const xAOD::PhotonContainer* Photons{nullptr}; - const xAOD::EgammaContainer* Egamma{nullptr}; - ATH_CHECK(loadContainer(ctx, m_elecKey, Egamma)); - Electrons = dynamic_cast<const xAOD::ElectronContainer*>(Egamma); - ATH_CHECK(loadContainer(ctx, m_photKey, Egamma)); - Photons = dynamic_cast<const xAOD::PhotonContainer*>(Egamma); - ATH_CHECK(loadContainer(ctx, m_muonKey, Muons)); + // + xAOD::ElectronContainer* Electrons = nullptr; + std::pair<std::unique_ptr<xAOD::ElectronContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> ElShallow; + ATH_CHECK(loadContainer(ctx, m_elecKey, ElShallow)); + Electrons = ElShallow.first.get(); + // + xAOD::PhotonContainer* Photons = nullptr; + std::pair<std::unique_ptr<xAOD::PhotonContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> PhShallow; + ATH_CHECK(loadContainer(ctx, m_photKey, PhShallow)); + Photons = PhShallow.first.get(); + // + xAOD::MuonContainer* Muons = nullptr; + std::pair<std::unique_ptr<xAOD::MuonContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> MuonsShallow; + ATH_CHECK(loadContainer(ctx, m_muonKey, MuonsShallow)); + Muons = MuonsShallow.first.get(); // Okay everything is defined for the preselection of the algorithm. lets pass the things towards the IsoCorrectionTool if (m_isoCloseByCorrTool->getCloseByIsoCorrection(Electrons, Muons, Photons).code() == CorrectionCode::Error) { diff --git a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.h b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.h index 076c8b25a8ae..6052b57e9ce5 100644 --- a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.h +++ b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.h @@ -25,6 +25,7 @@ #include "xAODEgamma/PhotonContainer.h" #include "xAODEventInfo/EventInfo.h" #include "xAODMuon/MuonContainer.h" +#include "xAODCore/ShallowCopy.h" /** * @brief Simple algorithm to check the performance of the IsolationCloseByCorrectionTool. The algorithm writes TTrees that can be analyzed @@ -48,15 +49,17 @@ namespace CP { private: template <class CONT_TYPE> - StatusCode loadContainer(const EventContext& ctx, const SG::ReadHandleKey<CONT_TYPE>& key, const CONT_TYPE*& cont) const; + StatusCode loadContainer(const EventContext& ctx, const SG::ReadHandleKey<CONT_TYPE>& key, + std::pair<std::unique_ptr<CONT_TYPE>, + std::unique_ptr<xAOD::ShallowAuxContainer>>& cont) const; bool passSelection(const EventContext& ctx, const xAOD::Muon* muon) const; bool passSelection(const EventContext& ctx, const xAOD::Egamma* egamm) const; /// Input containers SG::ReadHandleKey<xAOD::MuonContainer> m_muonKey{this, "MuonContainer", ""}; - SG::ReadHandleKey<xAOD::EgammaContainer> m_elecKey{this, "EleContainer", ""}; - SG::ReadHandleKey<xAOD::EgammaContainer> m_photKey{this, "PhotContainer", ""}; + SG::ReadHandleKey<xAOD::ElectronContainer> m_elecKey{this, "EleContainer", ""}; + SG::ReadHandleKey<xAOD::PhotonContainer> m_photKey{this, "PhotContainer", ""}; /// Optionally the algorithm can test the behaviour of the tracks selected by the IsoCloseByCorrectionTrkSelAlg SG::ReadHandleKey<xAOD::TrackParticleContainer> m_polTrkKey{this, "TrackKey", ""}; -- GitLab From c76e96c1ed6b060f4d54f4eef31bed97227e0923 Mon Sep 17 00:00:00 2001 From: christos <christos@cern.ch> Date: Mon, 14 Nov 2022 20:48:38 +0100 Subject: [PATCH 2/2] try to retain the test --- .../src/TestIsolationCloseByCorrAlg.cxx | 15 ++++++++------- .../src/TestIsolationCloseByCorrAlg.h | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.cxx b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.cxx index b6dc64495a86..9b2b8d4eb376 100644 --- a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.cxx +++ b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.cxx @@ -57,10 +57,10 @@ namespace CP { ATH_CHECK(m_tree.write()); return StatusCode::SUCCESS; } - template <class CONT_TYPE> + template <class TARGET_TYPE, class CONT_TYPE, class COPY_TYPE> StatusCode TestIsolationCloseByCorrAlg::loadContainer(const EventContext& ctx, const SG::ReadHandleKey<CONT_TYPE>& key, - std::pair<std::unique_ptr<CONT_TYPE>, + std::pair<std::unique_ptr<COPY_TYPE>, std::unique_ptr<xAOD::ShallowAuxContainer>>& cont) const { if (key.empty()) { ATH_MSG_DEBUG("No key given. Assume it's no required to load the container"); @@ -71,9 +71,10 @@ namespace CP { ATH_MSG_FATAL("Failed to load container " << key.fullKey()); return StatusCode::FAILURE; } - cont = xAOD::shallowCopyContainer(*readHandle,ctx); + + cont = xAOD::shallowCopyContainer(dynamic_cast<const TARGET_TYPE&> (*readHandle),ctx); if (!m_selDecorator && !m_isoDecorator) return StatusCode::SUCCESS; - std::unique_ptr<CONT_TYPE>& elems = cont.first; + std::unique_ptr<COPY_TYPE>& elems = cont.first; for (auto part : *(elems.get()) ) { if (m_selDecorator) (*m_selDecorator)(*part) = passSelection(ctx, part); if (m_isoDecorator) (*m_isoDecorator)(*part) = true && m_isoSelectorTool->accept(*part); @@ -101,17 +102,17 @@ namespace CP { // xAOD::ElectronContainer* Electrons = nullptr; std::pair<std::unique_ptr<xAOD::ElectronContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> ElShallow; - ATH_CHECK(loadContainer(ctx, m_elecKey, ElShallow)); + ATH_CHECK(loadContainer<xAOD::ElectronContainer>(ctx, m_elecKey, ElShallow)); Electrons = ElShallow.first.get(); // xAOD::PhotonContainer* Photons = nullptr; std::pair<std::unique_ptr<xAOD::PhotonContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> PhShallow; - ATH_CHECK(loadContainer(ctx, m_photKey, PhShallow)); + ATH_CHECK(loadContainer<xAOD::PhotonContainer>(ctx, m_photKey, PhShallow)); Photons = PhShallow.first.get(); // xAOD::MuonContainer* Muons = nullptr; std::pair<std::unique_ptr<xAOD::MuonContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> MuonsShallow; - ATH_CHECK(loadContainer(ctx, m_muonKey, MuonsShallow)); + ATH_CHECK(loadContainer<xAOD::MuonContainer>(ctx, m_muonKey, MuonsShallow)); Muons = MuonsShallow.first.get(); // Okay everything is defined for the preselection of the algorithm. lets pass the things towards the IsoCorrectionTool diff --git a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.h b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.h index 6052b57e9ce5..918d8003ff00 100644 --- a/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.h +++ b/PhysicsAnalysis/AnalysisCommon/IsolationSelection/src/TestIsolationCloseByCorrAlg.h @@ -48,9 +48,9 @@ namespace CP { unsigned int cardinality() const override { return 1; } private: - template <class CONT_TYPE> + template <class TARGET_TYPE, class CONT_TYPE, class COPY_TYPE> StatusCode loadContainer(const EventContext& ctx, const SG::ReadHandleKey<CONT_TYPE>& key, - std::pair<std::unique_ptr<CONT_TYPE>, + std::pair<std::unique_ptr<COPY_TYPE>, std::unique_ptr<xAOD::ShallowAuxContainer>>& cont) const; bool passSelection(const EventContext& ctx, const xAOD::Muon* muon) const; @@ -58,8 +58,8 @@ namespace CP { /// Input containers SG::ReadHandleKey<xAOD::MuonContainer> m_muonKey{this, "MuonContainer", ""}; - SG::ReadHandleKey<xAOD::ElectronContainer> m_elecKey{this, "EleContainer", ""}; - SG::ReadHandleKey<xAOD::PhotonContainer> m_photKey{this, "PhotContainer", ""}; + SG::ReadHandleKey<xAOD::EgammaContainer> m_elecKey{this, "EleContainer", ""}; + SG::ReadHandleKey<xAOD::EgammaContainer> m_photKey{this, "PhotContainer", ""}; /// Optionally the algorithm can test the behaviour of the tracks selected by the IsoCloseByCorrectionTrkSelAlg SG::ReadHandleKey<xAOD::TrackParticleContainer> m_polTrkKey{this, "TrackKey", ""}; -- GitLab