ATLAS Offline Software
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 
12 #include "StoreGate/ReadHandle.h"
16 
17 namespace 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));
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.
101  UnorderedContainerSet conts;
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>
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 
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 
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 
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
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
xAOD::Photon_v1::type
virtual Type::ObjectType type() const override final
The type of the object as a simple enumeration.
Definition: Photon_v1.cxx:36
CP::IsoCloseByCorrectionAlg::m_muonSelTool
ToolHandle< CP::IMuonSelectionTool > m_muonSelTool
tools for selection of incoming particles
Definition: IsoCloseByCorrectionAlg.h:61
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CP::IsoCloseByCorrectionAlg::m_minMuonPt
Gaudi::Property< float > m_minMuonPt
Definition: IsoCloseByCorrectionAlg.h:72
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:79
CP::IsoCloseByCorrectionAlg::m_quality_name
Gaudi::Property< std::string > m_quality_name
Definition: IsoCloseByCorrectionAlg.h:78
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
xAOD::Electron_v1::type
virtual Type::ObjectType type() const override final
The type of the object as a simple enumeration.
Definition: Electron_v1.cxx:35
CurrentContext.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
xAODP4Helpers.h
CP::IsoCloseByCorrectionAlg::m_contKeys
SG::ReadHandleKeyArray< xAOD::IParticleContainer > m_contKeys
Input containers to retrieve from the storegate.
Definition: IsoCloseByCorrectionAlg.h:50
CP::IsoCloseByCorrectionAlg::m_muonSelKey
SG::ReadDecorHandleKey< xAOD::MuonContainer > m_muonSelKey
For lepton/photon selection, normally one uses either a decorator xxxSelKey, or a tool xxxSelTool,...
Definition: IsoCloseByCorrectionAlg.h:56
CP::IsoCloseByCorrectionAlg::m_minElecPt
Gaudi::Property< float > m_minElecPt
Kinematic cuts - if needed.
Definition: IsoCloseByCorrectionAlg.h:70
SG::AuxVectorData::lockDecoration
void lockDecoration(SG::auxid_t auxid)
Explicitly lock a decoration.
Definition: AuxVectorData.cxx:687
CP::IsoCloseByCorrectionAlg::selectLeptonsAndPhotons
StatusCode selectLeptonsAndPhotons(const EventContext &ctx, CONT_TYPE particles, const SG::Decorator< char > &isOK) const
Definition: IsoCloseByCorrectionAlg.cxx:120
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
SG::Decorator::auxid
SG::auxid_t auxid() const
Return the aux id for this variable.
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
CP::IsoCloseByCorrectionAlg::m_photSelTool
ToolHandle< IAsgPhotonIsEMSelector > m_photSelTool
Definition: IsoCloseByCorrectionAlg.h:63
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
CP::IsoCloseByCorrectionAlg::IsoCloseByCorrectionAlg
IsoCloseByCorrectionAlg(const std::string &name, ISvcLocator *svcLoc)
Definition: IsoCloseByCorrectionAlg.cxx:19
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
CP::IsoCloseByCorrectionAlg::m_photSelKey
SG::ReadDecorHandleKey< xAOD::PhotonContainer > m_photSelKey
Definition: IsoCloseByCorrectionAlg.h:58
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
EgammaxAODHelpers.h
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
SG::Decorator< char >
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::Egamma_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
Definition: Egamma_v1.cxx:75
CP::IsoCloseByCorrectionAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: IsoCloseByCorrectionAlg.cxx:46
CP::IsoCloseByCorrectionAlg::initialize
StatusCode initialize() override
Definition: IsoCloseByCorrectionAlg.cxx:21
IsoCloseByCorrectionAlg.h
CP::IsoCloseByCorrectionAlg::applySelection
StatusCode applySelection(const EventContext &ctx, const xAOD::Electron *elec, const SG::Decorator< char > &isOK) const
Definition: IsoCloseByCorrectionAlg.cxx:170
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
CP::IsoCloseByCorrectionAlg::m_minPhotPt
Gaudi::Property< float > m_minPhotPt
Definition: IsoCloseByCorrectionAlg.h:74
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
Muon
struct TBPatternUnitContext Muon
IsolationCloseByCorrectionTool.h
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:200
xAOD::Photon_v1
Definition: Photon_v1.h:37
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
CP::UnorderedContainerSet
std::unordered_set< const SG::AuxVectorData * > UnorderedContainerSet
Definition: PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/Defs.h:78
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
CP::IsoCloseByCorrectionAlg::m_closeByCorrTool
ToolHandle< CP::IIsolationCloseByCorrectionTool > m_closeByCorrTool
The closeBy isolation correction tool.
Definition: IsoCloseByCorrectionAlg.h:66
xAOD::Egamma_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: Egamma_v1.cxx:65
doL1CaloHVCorrections.parts
parts
Definition: doL1CaloHVCorrections.py:334
ReadDecorHandle.h
Handle class for reading a decoration on an object.
xAOD::Egamma_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: Egamma_v1.cxx:70
SG::AuxVectorData
Manage lookup of vectors of auxiliary data.
Definition: AuxVectorData.h:168
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
ReadHandle.h
Handle class for reading from StoreGate.
CP::IsoCloseByCorrectionAlg::m_elecSelTool
ToolHandle< IAsgElectronLikelihoodTool > m_elecSelTool
Definition: IsoCloseByCorrectionAlg.h:62
checker_macros.h
Define macros for attributes used to control the static checker.
python.compressB64.c
def c
Definition: compressB64.py:93
CP::IsoCloseByCorrectionAlg::m_elecSelKey
SG::ReadDecorHandleKey< xAOD::ElectronContainer > m_elecSelKey
Definition: IsoCloseByCorrectionAlg.h:57
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17