ATLAS Offline Software
Loading...
Searching...
No Matches
TestIsolationCloseByCorrAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4
5// Local include(s):
10
12
13namespace CP {
14
15 TestIsolationCloseByCorrAlg::TestIsolationCloseByCorrAlg(const std::string& name, ISvcLocator* svcLoc) :
16 AthHistogramAlgorithm(name, svcLoc) {}
17
19 ATH_CHECK(m_isoSelectorTool.retrieve());
21
22 ATH_CHECK(m_muonKey.initialize(!m_muonKey.empty()));
23 ATH_CHECK(m_elecKey.initialize(!m_elecKey.empty()));
24 ATH_CHECK(m_photKey.initialize(!m_photKey.empty()));
25 ATH_CHECK(m_polTrkKey.initialize(!m_polTrkKey.empty()));
27 unsigned int writeOpts = wOpts::writePileUp | wOpts::writeBeamSpot;
28 if (m_isMC) writeOpts |= wOpts::isMC;
29 m_tree.addBranch(std::make_shared<MuonVal::EventInfoBranch>(m_tree, writeOpts));
30
31 auto add_correctionHelper = [this](std::shared_ptr<IsoCorrectionTestHelper> helper) {
32 if (!m_selDecoration.empty()) helper->SetSelectionDecorator(m_selDecoration.value());
33 if (!m_isoDecoration.empty()) helper->SetIsolationDecorator(m_isoDecoration.value());
34 if (!m_backup_prefix.empty()) helper->SetBackupPreFix(m_backup_prefix.value());
35 if (!m_updatedIsoDeco.empty()) helper->SetUpdatedIsoDecorator(m_updatedIsoDeco.value());
36 m_tree.addBranch(helper);
37 };
38 if (!m_elecKey.empty()) {
39 m_ele_helper = std::make_shared<IsoCorrectionTestHelper>(m_tree, "Electrons", m_isoSelectorTool->getElectronWPs());
40 add_correctionHelper(m_ele_helper);
41 }
42 if (!m_muonKey.empty()) {
43 m_muo_helper = std::make_shared<IsoCorrectionTestHelper>(m_tree, "Muons", m_isoSelectorTool->getMuonWPs());
44 add_correctionHelper(m_muo_helper);
45 }
46 if (!m_photKey.empty()) {
47 m_pho_helper = std::make_shared<IsoCorrectionTestHelper>(m_tree, "Photons", m_isoSelectorTool->getPhotonWPs());
48 add_correctionHelper(m_pho_helper);
49 }
50 if (!m_muonSelTool.empty()) ATH_CHECK(m_muonSelTool.retrieve());
51 if (!m_elecSelTool.empty()) ATH_CHECK(m_elecSelTool.retrieve());
52 if (!m_photSelTool.empty()) ATH_CHECK(m_photSelTool.retrieve());
53 if (!m_selDecoration.empty()) m_selDecorator = std::make_unique<CharDecorator>(m_selDecoration);
54 if (!m_isoDecoration.empty()) m_isoDecorator = std::make_unique<CharDecorator>(m_isoDecoration);
55 ATH_CHECK(m_tree.init(this));
56 return StatusCode::SUCCESS;
57 }
59 ATH_CHECK(m_tree.write());
60 return StatusCode::SUCCESS;
61 }
62 template <class TARGET_TYPE, class CONT_TYPE, class COPY_TYPE>
63 StatusCode TestIsolationCloseByCorrAlg::loadContainer(const EventContext& ctx,
65 std::pair<std::unique_ptr<COPY_TYPE>,
66 std::unique_ptr<xAOD::ShallowAuxContainer>>& cont) const {
67 if (key.empty()) {
68 ATH_MSG_DEBUG("No key given. Assume it's no required to load the container");
69 return StatusCode::SUCCESS;
70 }
71 SG::ReadHandle<CONT_TYPE> readHandle{key, ctx};
72 if (!readHandle.isValid()) {
73 ATH_MSG_FATAL("Failed to load container " << key.fullKey());
74 return StatusCode::FAILURE;
75 }
76
77 cont = xAOD::shallowCopyContainer(dynamic_cast<const TARGET_TYPE&> (*readHandle),ctx);
78 if (!m_selDecorator && !m_isoDecorator) return StatusCode::SUCCESS;
79 std::unique_ptr<COPY_TYPE>& elems = cont.first;
80 for (auto part : *(elems.get()) ) {
81 if (m_selDecorator) (*m_selDecorator)(*part) = passSelection(ctx, part);
82 if (m_isoDecorator) (*m_isoDecorator)(*part) = true && m_isoSelectorTool->accept(*part);
83 }
84
85 return StatusCode::SUCCESS;
86 }
87
88 bool TestIsolationCloseByCorrAlg::passSelection(const EventContext&, const xAOD::Muon* muon) const {
89 return muon->pt() >= m_mu_min_pt && (m_mu_max_eta < 0. || std::abs(muon->eta()) < m_mu_max_eta) &&
90 (m_muonSelTool.empty() || m_muonSelTool->accept(*muon));
91 }
92 bool TestIsolationCloseByCorrAlg::passSelection(const EventContext& ctx, const xAOD::Egamma* egamm) const {
93 if (egamm->type() == xAOD::Type::ObjectType::Electron) {
94 return egamm->pt() >= m_el_min_pt && (m_el_max_eta < 0. || std::abs(egamm->eta()) < m_el_max_eta) &&
95 (m_elecSelTool.empty() || m_elecSelTool->accept(ctx, egamm));
96 }
98 return egamm->pt() >= m_ph_min_pt && (m_ph_max_eta < 0. || std::abs(egamm->eta()) < m_ph_max_eta) &&
99 (m_photSelTool.empty() || m_photSelTool->accept(ctx, egamm));
100 }
101
103 const EventContext& ctx = Gaudi::Hive::currentContext();
104 //
105 xAOD::ElectronContainer* Electrons = nullptr;
106 std::pair<std::unique_ptr<xAOD::ElectronContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> ElShallow;
108 Electrons = ElShallow.first.get();
109 //
110 xAOD::PhotonContainer* Photons = nullptr;
111 std::pair<std::unique_ptr<xAOD::PhotonContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> PhShallow;
113 Photons = PhShallow.first.get();
114 //
115 xAOD::MuonContainer* Muons = nullptr;
116 std::pair<std::unique_ptr<xAOD::MuonContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> MuonsShallow;
118 Muons = MuonsShallow.first.get();
119
120 // Okay everything is defined for the preselection of the algorithm. lets pass the things towards the IsoCorrectionTool
121 if (m_isoCloseByCorrTool->getCloseByIsoCorrection(ctx, Electrons, Muons, Photons).code() == CorrectionCode::Error) {
122 ATH_MSG_ERROR("Something weird happened with the tool");
123 return StatusCode::FAILURE;
124 }
125 // The isoCorrectionTool has now corrected everything using close-by objects satisfiyng the dec_PassQuality criteria
126 // The name of the decorator is set via the 'SelectionDecorator' property of the tool
127 // Optionally one can also define that the tool shall only objects surviving the overlap removal without changing the initial
128 // decorator Use therefore the 'PassOverlapDecorator' property to define the decorators name If you define the 'BackupPrefix'
129 // property then the original values are stored before correction <Prefix>_<IsolationCone> The final result whether the object
130 // passes the isolation criteria now can be stored in the 'IsolationSelectionDecorator' e.g. 'CorrectedIso'
131
132 // parse the associated muon clusters to the tool
133 ClusterSet muon_clusters;
134 PflowSet pflows;
135
136
138 TrackSet selected_trks{}, expected_trks{};
139 if (!m_polTrkKey.empty()) {
141 if (!closeTrkColl.isValid()) {
142 ATH_MSG_FATAL("Failed to load " << m_polTrkKey.fullKey() << " from storegate");
143 return StatusCode::FAILURE;
144 }
145 for (const xAOD::TrackParticle* trk : *closeTrkColl) { selected_trks.emplace(trk); }
147 correction_tool()->loadPrimaryParticles(Electrons, cache);
149 correction_tool()->loadPrimaryParticles(Photons, cache);
151 expected_trks = std::move(cache.tracks);
152 muon_clusters = std::move(cache.clusters);
153 pflows = std::move(cache.flows);
154 }
155
156 // Store everything in the final ntuples
157 auto fill_helper = [&](std::shared_ptr<IsoCorrectionTestHelper> helper, const xAOD::IParticleContainer* parts) -> StatusCode{
158 if (!helper) return StatusCode::SUCCESS;
159 helper->SetClusters(muon_clusters);
160 helper->SetFlowElements(pflows);
161 return helper->Fill(parts);
162 };
163 ATH_CHECK(fill_helper(m_ele_helper, Electrons));
164 ATH_CHECK(fill_helper(m_muo_helper, Muons));
165 ATH_CHECK(fill_helper(m_pho_helper, Photons));
166 ATH_CHECK(m_tree.fill(ctx));
167 return StatusCode::SUCCESS;
168 }
172} // namespace CP
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
AthHistogramAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
@ Error
Some error happened during the object correction.
void loadAssociatedObjects(const EventContext &ctx, ObjectCache &cache) const
Load all associated tracks / clusters / flow elements into the cache.
void loadPrimaryParticles(const xAOD::IParticleContainer *container, ObjectCache &cache) const
Filter all electrons/muons/photons from the collection which pass the selection decoration.
SG::ReadHandleKey< xAOD::MuonContainer > m_muonKey
Input containers.
TestIsolationCloseByCorrAlg(const std::string &name, ISvcLocator *svcLoc)
Gaudi::Property< std::string > m_updatedIsoDeco
ToolHandle< CP::IIsolationCloseByCorrectionTool > m_isoCloseByCorrTool
const CP::IsolationCloseByCorrectionTool * correction_tool() const
Gaudi::Property< std::string > m_backup_prefix
Gaudi::Property< std::string > m_selDecoration
StatusCode loadContainer(const EventContext &ctx, const SG::ReadHandleKey< CONT_TYPE > &key, std::pair< std::unique_ptr< COPY_TYPE >, std::unique_ptr< xAOD::ShallowAuxContainer > > &cont) const
std::shared_ptr< IsoCorrectionTestHelper > m_ele_helper
Gaudi::Property< std::string > m_isoDecoration
std::shared_ptr< IsoCorrectionTestHelper > m_pho_helper
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_polTrkKey
Optionally the algorithm can test the behaviour of the tracks selected by the IsoCloseByCorrectionTrk...
bool passSelection(const EventContext &ctx, const xAOD::Muon *muon) const
SG::ReadHandleKey< xAOD::EgammaContainer > m_photKey
ToolHandle< CP::IMuonSelectionTool > m_muonSelTool
Optionally the user can also parse the elec / muon / photon selection tools.
ToolHandle< CP::IIsolationSelectionTool > m_isoSelectorTool
ToolHandle< IAsgPhotonIsEMSelector > m_photSelTool
std::shared_ptr< IsoCorrectionTestHelper > m_muo_helper
SG::ReadHandleKey< xAOD::EgammaContainer > m_elecKey
ToolHandle< IAsgElectronLikelihoodTool > m_elecSelTool
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition Egamma_v1.cxx:66
virtual Type::ObjectType type() const override=0
The type of the object as a simple enumeration, remains pure virtual in e/gamma.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition Egamma_v1.cxx:71
Select isolated Photons, Electrons and Muons.
Definition Muons.py:1
@ Electron
The object is an electron.
Definition ObjectType.h:46
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant container.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.