ATLAS Offline Software
Loading...
Searching...
No Matches
IsoCloseByCorrectionAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5
7
8#include <algorithm>
9
16
17namespace CP {
18
19 IsoCloseByCorrectionAlg::IsoCloseByCorrectionAlg(const std::string& name, ISvcLocator* svcLoc) :
20 AthReentrantAlgorithm(name, svcLoc) {}
22
23 ATH_MSG_INFO("Initialize IsoCloseByCorrectionAlg " );
24
25
27 ATH_MSG_INFO("Initialize " << contKey.key());
28 }
29 if (!m_muonSelKey.empty()) ATH_MSG_INFO("Initialize muon sel " << m_muonSelKey.key() << ", " << m_muonSelKey.isEventStore() );
30 if (!m_elecSelKey.empty()) ATH_MSG_INFO("Initialize elec sel " << m_elecSelKey.key() << ", " << m_elecSelKey.isEventStore() );
31 if (!m_photSelKey.empty()) ATH_MSG_INFO("Initialize phot sel " << m_photSelKey.key() << ", " << m_photSelKey.isEventStore() );
32 ATH_MSG_INFO("Initialize MinMuonPt " << m_minMuonPt.value());
33 ATH_MSG_INFO("Initialize MinElecPt " << m_minElecPt.value());
34 ATH_MSG_INFO("Initialize MinPhotPt " << m_minPhotPt.value());
35 if (m_muonSelTool.isEnabled()) ATH_MSG_INFO("Initialize muon sel tool " << m_muonSelTool.name());
36 if (m_elecSelTool.isEnabled()) ATH_MSG_INFO("Initialize elec sel tool " << m_elecSelTool.name());
37 if (m_photSelTool.isEnabled()) ATH_MSG_INFO("Initialize phot sel tool " << m_photSelTool.name());
38
39 ATH_CHECK(m_contKeys.initialize(!m_contKeys.empty()));
40 ATH_CHECK(m_muonSelKey.initialize(!m_muonSelKey.empty()));
41 ATH_CHECK(m_elecSelKey.initialize(!m_elecSelKey.empty()));
42 ATH_CHECK(m_photSelKey.initialize(!m_photSelKey.empty()));
43 return StatusCode::SUCCESS;
44 }
45
46 StatusCode IsoCloseByCorrectionAlg::execute(const EventContext& ctx) const {
47
48 ATH_MSG_DEBUG("execute: entering " );
49
50 // Loop over input IParticleContainer, and fill different ConstDataVectors for muons, electrons and photons.
51 // There may be more than one container for each.
52 // Then apply selections of objects, decorating with "isoSelIsOK" for the IsoCloseByTool, and then pass the ConstDataVectors to the tool.
53
57
59
62 for ( const xAOD::IParticle* part : *parts ) {
63
64 // Check type of container and apply selection as appropriate
65 if (part->type() == xAOD::Type::Muon) {
66 // cast to muon container
67 const xAOD::Muon* muon = static_cast<const xAOD::Muon*>(part);
68 muons.push_back(muon);
69 }
70 else if (part->type() == xAOD::Type::Electron) {
71 // cast to electron container
72 const xAOD::Electron* electron = static_cast<const xAOD::Electron*>(part);
73 electrons.push_back(electron);
74 }
75 else if (part->type() == xAOD::Type::Photon) {
76 // cast to photon container
77 const xAOD::Photon* photon = static_cast<const xAOD::Photon*>(part);
78 photons.push_back(photon);
79 }
80 }
81 }
82
83 ATH_MSG_DEBUG("execute: apply selections " );
84
86 ATH_CHECK(selectLeptonsAndPhotons(ctx, muons, isOK));
87 ATH_CHECK(selectLeptonsAndPhotons(ctx, electrons, isOK));
88 ATH_CHECK(selectLeptonsAndPhotons(ctx, photons, isOK));
89
90 ATH_MSG_DEBUG("execute: apply closeBy correction " );
91
93 if (m_closeByCorrTool->getCloseByIsoCorrection(ctx, electrons.asDataVector(), muons.asDataVector(), photons.asDataVector()) == CorrectionCode::Error) {
94 ATH_MSG_FATAL("Failed to do close by iso correction ");
95 return StatusCode::FAILURE;
96 }
97
98 // Make sure the isoSelIsOK decorations get locked.
99 // Unfortunately, we can't use decoration handles because we may
100 // be configured with view containers as input.
103 SG::ReadHandle<xAOD::IParticleContainer> parts (contKey, ctx);
104 for ( const xAOD::IParticle* part : *parts ) {
105 const SG::AuxVectorData* c = part->container();
106 if (conts.insert(c).second) {
108 const_cast<SG::AuxVectorData*> (c);
109 c_nc->lockDecoration (isOK.auxid());
110 }
111 }
112 }
113
114 ATH_MSG_DEBUG("execute: after closeBy correction " );
115
116 return StatusCode::SUCCESS;
117 }
118
119 template <class CONT_TYPE>
120 StatusCode IsoCloseByCorrectionAlg::selectLeptonsAndPhotons(const EventContext& ctx,
121 CONT_TYPE particles,
122 const SG::Decorator<char>& isOK) const
123 {
124
125 ATH_MSG_DEBUG("selectLeptonsAndPhotons: entering" );
126
127 for ( auto particle : particles ) {
128 ATH_MSG_DEBUG("selectLeptonsAndPhotons: pt, eta, ph " << particle->pt()/1000. << ", " << particle->eta() << ", " << particle->phi() );
129 ATH_CHECK(applySelection(ctx, particle, isOK));
130 }
131 return StatusCode::SUCCESS;
132 }
133
134 StatusCode IsoCloseByCorrectionAlg::applySelection(const EventContext& ctx,
135 const xAOD::Muon* muon,
136 const SG::Decorator<char>& isOK) const
137 {
138
139 // Check incoming selection decorator
140 if (!m_muonSelKey.empty()) {
142 if (!decor(*muon)) {
143 ATH_MSG_VERBOSE("applySelection: muon fails " << m_muonSelKey.key());
144 isOK(*muon) = false;
145 return StatusCode::SUCCESS;
146 }
147 }
148
149 // Check incoming selection tool
150 if (!m_muonSelTool.empty()) {
151 if (!m_muonSelTool->accept(*muon)) {
152 ATH_MSG_VERBOSE("applySelection: muon fails Loose cut");
153 isOK(*muon) = false;
154 return StatusCode::SUCCESS;
155 }
156 }
157 // Check pt
158 if (muon->pt() < m_minMuonPt) {
159 ATH_MSG_VERBOSE("applySelection: muon fails pt cut: " << muon->pt() << ", " << m_minMuonPt);
160 isOK(*muon) = false;
161 return StatusCode::SUCCESS;
162 }
163
164 isOK(*muon) = true;
165 ATH_MSG_VERBOSE("applySelection: " << muon->type() << ", " << muon->pt() << ", " << muon->eta() << ", " << muon->phi() << ", " << (int)isOK(*muon));
166
167 return StatusCode::SUCCESS;
168 }
169
170 StatusCode IsoCloseByCorrectionAlg::applySelection(const EventContext& ctx,
171 const xAOD::Electron* elec,
172 const SG::Decorator<char>& isOK) const
173 {
174
175 // Check incoming selection decorator
176 if (!m_elecSelKey.empty()) {
178 if (!decor(*elec)) {
179 ATH_MSG_VERBOSE("applySelection: electron fails " << m_elecSelKey.key());
180 isOK(*elec) = false;
181 return StatusCode::SUCCESS;
182 }
183 }
184 // Check incoming selection tool
185 if (!m_elecSelTool.empty()) {
186 if (!m_elecSelTool->accept(ctx, elec)) {
187 ATH_MSG_VERBOSE("applySelection: electron fails VeryLooseLH cut");
188 isOK(*elec) = false;
189 return StatusCode::SUCCESS;
190 }
191 }
192 // Check pt
193 if (elec->pt() < m_minElecPt) {
194 ATH_MSG_VERBOSE("applySelection: electron fails pt cut: " << elec->pt() << ", " << m_minElecPt);
195 isOK(*elec) = false;
196 return StatusCode::SUCCESS;
197 }
198 isOK(*elec) = true;
199
200 ATH_MSG_VERBOSE("applySelection: " << elec->type() << ", " << elec->pt() << ", " << elec->eta() << ", " << elec->phi() << ", " << (int)isOK(*elec));
201
202 return StatusCode::SUCCESS;
203 }
204
205 StatusCode IsoCloseByCorrectionAlg::applySelection(const EventContext& ctx,
206 const xAOD::Photon* phot,
207 const SG::Decorator<char>& isOK) const
208 {
209
210 // Check incoming selection decorator
211 if (!m_photSelKey.empty()) {
213 if (!decor(*phot)) {
214 ATH_MSG_VERBOSE("applySelection: photon fails " << m_photSelKey.key());
215 isOK(*phot) = false;
216 return StatusCode::SUCCESS;
217 }
218 }
219
220 // Check incoming selection tool
221 if (!m_photSelTool.empty()) {
222 if (!m_photSelTool->accept(ctx, phot)) {
223 ATH_MSG_VERBOSE("applySelection: photon fails IsEMLoose cut");
224 isOK(*phot) = false;
225 return StatusCode::SUCCESS;
226 }
227 }
228
229 // Check pt
230 if (phot->pt() < m_minPhotPt) {
231 ATH_MSG_VERBOSE("applySelection: photon fails pt cut: " << phot->pt() << ", " << m_minPhotPt);
232 isOK(*phot) = false;
233 return StatusCode::SUCCESS;
234 }
235
236 isOK(*phot) = true;
237
238 ATH_MSG_VERBOSE("applySelection: " << phot->type() << ", " << phot->pt() << ", " << phot->eta() << ", " << phot->phi() << ", " << (int)isOK(*phot));
239
240 return StatusCode::SUCCESS;
241 }
242
243} // namespace CP
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
An algorithm that can be simultaneously executed in multiple threads.
@ Error
Some error happened during the object correction.
Gaudi::Property< float > m_minElecPt
Kinematic cuts - if needed.
SG::ReadDecorHandleKey< xAOD::ElectronContainer > m_elecSelKey
SG::ReadHandleKeyArray< xAOD::IParticleContainer > m_contKeys
Input containers to retrieve from the storegate.
SG::ReadDecorHandleKey< xAOD::MuonContainer > m_muonSelKey
For lepton/photon selection, normally one uses either a decorator xxxSelKey, or a tool xxxSelTool,...
Gaudi::Property< std::string > m_quality_name
Gaudi::Property< float > m_minPhotPt
StatusCode selectLeptonsAndPhotons(const EventContext &ctx, CONT_TYPE particles, const SG::Decorator< char > &isOK) const
IsoCloseByCorrectionAlg(const std::string &name, ISvcLocator *svcLoc)
ToolHandle< CP::IIsolationCloseByCorrectionTool > m_closeByCorrTool
The closeBy isolation correction tool.
StatusCode execute(const EventContext &ctx) const override
StatusCode applySelection(const EventContext &ctx, const xAOD::Electron *elec, const SG::Decorator< char > &isOK) const
ToolHandle< IAsgPhotonIsEMSelector > m_photSelTool
ToolHandle< IAsgElectronLikelihoodTool > m_elecSelTool
SG::ReadDecorHandleKey< xAOD::PhotonContainer > m_photSelKey
ToolHandle< CP::IMuonSelectionTool > m_muonSelTool
tools for selection of incoming particles
Gaudi::Property< float > m_minMuonPt
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
Manage lookup of vectors of auxiliary data.
void lockDecoration(SG::auxid_t auxid)
Explicitly lock a decoration.
Helper class to provide type-safe access to aux data.
Definition Decorator.h:59
SG::auxid_t auxid() const
Return the aux id for this variable.
Handle class for reading a decoration on an object.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition Egamma_v1.cxx:66
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition Egamma_v1.cxx:71
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
Definition Egamma_v1.cxx:76
virtual Type::ObjectType type() const override final
The type of the object as a simple enumeration.
Class providing the definition of the 4-vector interface.
virtual Type::ObjectType type() const override final
The type of the object as a simple enumeration.
Definition Photon_v1.cxx:37
Select isolated Photons, Electrons and Muons.
std::unordered_set< const SG::AuxVectorData * > UnorderedContainerSet
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
@ Photon
The object is a photon.
Definition ObjectType.h:47
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46
Muon_v1 Muon
Reference the current persistent version:
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".