ATLAS Offline Software
IsoCloseByCorrectionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
5 
7 
8 #include <algorithm>
9 
12 #include "StoreGate/ReadHandle.h"
15 
16 namespace CP {
17 
18  IsoCloseByCorrectionAlg::IsoCloseByCorrectionAlg(const std::string& name, ISvcLocator* svcLoc) :
19  AthReentrantAlgorithm(name, svcLoc) {}
21 
22  ATH_MSG_INFO("Initialize IsoCloseByCorrectionAlg " );
23 
24 
26  ATH_MSG_INFO("Initialize " << contKey.key());
27  }
28  if (!m_muonSelKey.empty()) ATH_MSG_INFO("Initialize muon sel " << m_muonSelKey.key() << ", " << m_muonSelKey.isEventStore() );
29  if (!m_elecSelKey.empty()) ATH_MSG_INFO("Initialize elec sel " << m_elecSelKey.key() << ", " << m_elecSelKey.isEventStore() );
30  if (!m_photSelKey.empty()) ATH_MSG_INFO("Initialize phot sel " << m_photSelKey.key() << ", " << m_photSelKey.isEventStore() );
31  ATH_MSG_INFO("Initialize MinMuonPt " << m_minMuonPt.value());
32  ATH_MSG_INFO("Initialize MinElecPt " << m_minElecPt.value());
33  ATH_MSG_INFO("Initialize MinPhotPt " << m_minPhotPt.value());
34  if (m_muonSelTool.isEnabled()) ATH_MSG_INFO("Initialize muon sel tool " << m_muonSelTool.name());
35  if (m_elecSelTool.isEnabled()) ATH_MSG_INFO("Initialize elec sel tool " << m_elecSelTool.name());
36  if (m_photSelTool.isEnabled()) ATH_MSG_INFO("Initialize phot sel tool " << m_photSelTool.name());
37 
38  ATH_CHECK(m_contKeys.initialize(!m_contKeys.empty()));
39  ATH_CHECK(m_muonSelKey.initialize(!m_muonSelKey.empty()));
40  ATH_CHECK(m_elecSelKey.initialize(!m_elecSelKey.empty()));
41  ATH_CHECK(m_photSelKey.initialize(!m_photSelKey.empty()));
42  return StatusCode::SUCCESS;
43  }
44 
45  StatusCode IsoCloseByCorrectionAlg::execute(const EventContext& ctx) const {
46 
47  ATH_MSG_DEBUG("execute: entering " );
48 
49  // Loop over input IParticleContainer, and fill different ConstDataVectors for muons, electrons and photons.
50  // There may be more than one container for each.
51  // Then apply selections of objects, decorating with "isoSelIsOK" for the IsoCloseByTool, and then pass the ConstDataVectors to the tool.
52 
53  // Use isLRT decoration for LLP particles to avoid looking for tracks from the primary vertex in the closeBy tool
55 
56 
60 
63  for ( const xAOD::IParticle* part : *parts ) {
64 
65  // flag LLP particles
66  isLRT(*part) = (contKey.key().find("LRT") != std::string::npos);
67 
68  // Check type of container and apply selection as appropriate
69  if (part->type() == xAOD::Type::Muon) {
70  // cast to muon container
71  const xAOD::Muon* muon = static_cast<const xAOD::Muon*>(part);
72  muons.push_back(muon);
73  }
74  else if (part->type() == xAOD::Type::Electron) {
75  // cast to electron container
76  const xAOD::Electron* electron = static_cast<const xAOD::Electron*>(part);
77  electrons.push_back(electron);
78  }
79  else if (part->type() == xAOD::Type::Photon) {
80  // cast to photon container
81  const xAOD::Photon* photon = static_cast<const xAOD::Photon*>(part);
82  photons.push_back(photon);
83  }
84  }
85  }
86 
87  ATH_MSG_DEBUG("execute: apply selections " );
88 
92  ATH_CHECK(selectLeptonsAndPhotons(ctx, photons));
93 
94  ATH_MSG_DEBUG("execute: apply closeBy correction " );
95 
97  if (m_closeByCorrTool->getCloseByIsoCorrection(ctx, electrons.asDataVector(), muons.asDataVector(), photons.asDataVector()) == CorrectionCode::Error) {
98  ATH_MSG_FATAL("Failed to do close by iso correction ");
99  return StatusCode::FAILURE;
100  }
101 
102  ATH_MSG_DEBUG("execute: after closeBy correction " );
103 
104  return StatusCode::SUCCESS;
105  }
106 
107  template <class CONT_TYPE>
109  CONT_TYPE particles) const {
110 
111  ATH_MSG_DEBUG("selectLeptonsAndPhotons: entering" );
112 
113  for ( auto particle : particles ) {
114  ATH_MSG_DEBUG("selectLeptonsAndPhotons: pt, eta, ph " << particle->pt()/1000. << ", " << particle->eta() << ", " << particle->phi() );
116  }
117  return StatusCode::SUCCESS;
118  }
119 
120  StatusCode IsoCloseByCorrectionAlg::applySelection(const EventContext& ctx, const xAOD::Muon* muon) const {
121 
122  // outgoing selection decorator
123  SG::AuxElement::Decorator<char> isOK("isoSelIsOK");
124 
125  // Check incoming selection decorator
126  if (!m_muonSelKey.empty()) {
128  if (!decor(*muon)) {
129  ATH_MSG_VERBOSE("applySelection: muon fails " << m_muonSelKey.key());
130  isOK(*muon) = false;
131  return StatusCode::SUCCESS;
132  }
133  }
134 
135  // Check incoming selection tool
136  if (!m_muonSelTool.empty()) {
137  if (!m_muonSelTool->accept(*muon)) {
138  ATH_MSG_VERBOSE("applySelection: muon fails Loose cut");
139  isOK(*muon) = false;
140  return StatusCode::SUCCESS;
141  }
142  }
143  // Check pt
144  if (muon->pt() < m_minMuonPt) {
145  ATH_MSG_VERBOSE("applySelection: muon fails pt cut: " << muon->pt() << ", " << m_minMuonPt);
146  isOK(*muon) = false;
147  return StatusCode::SUCCESS;
148  }
149 
150  isOK(*muon) = true;
151  ATH_MSG_VERBOSE("applySelection: " << muon->type() << ", " << muon->pt() << ", " << muon->eta() << ", " << muon->phi() << ", " << (int)isOK(*muon));
152 
153  return StatusCode::SUCCESS;
154  }
155 
156  StatusCode IsoCloseByCorrectionAlg::applySelection(const EventContext& ctx, const xAOD::Electron* elec) const {
157 
158  // outgoing selection decorator
159  SG::AuxElement::Decorator<char> isOK("isoSelIsOK");
160 
161  // Check incoming selection decorator
162  if (!m_elecSelKey.empty()) {
164  if (!decor(*elec)) {
165  ATH_MSG_VERBOSE("applySelection: electron fails " << m_elecSelKey.key());
166  isOK(*elec) = false;
167  return StatusCode::SUCCESS;
168  }
169  }
170  // Check incoming selection tool
171  if (!m_elecSelTool.empty()) {
172  if (!m_elecSelTool->accept(ctx, elec)) {
173  ATH_MSG_VERBOSE("applySelection: electron fails VeryLooseLH cut");
174  isOK(*elec) = false;
175  return StatusCode::SUCCESS;
176  }
177  }
178  // Check pt
179  if (elec->pt() < m_minElecPt) {
180  ATH_MSG_VERBOSE("applySelection: electron fails pt cut: " << elec->pt() << ", " << m_minElecPt);
181  isOK(*elec) = false;
182  return StatusCode::SUCCESS;
183  }
184  isOK(*elec) = true;
185 
186  ATH_MSG_VERBOSE("applySelection: " << elec->type() << ", " << elec->pt() << ", " << elec->eta() << ", " << elec->phi() << ", " << (int)isOK(*elec));
187 
188  return StatusCode::SUCCESS;
189  }
190 
191  StatusCode IsoCloseByCorrectionAlg::applySelection(const EventContext& ctx, const xAOD::Photon* phot) const {
192 
193  // outgoing selection decorator
194  SG::AuxElement::Decorator<char> isOK("isoSelIsOK");
195 
196  // Check incoming selection decorator
197  if (!m_photSelKey.empty()) {
199  if (!decor(*phot)) {
200  ATH_MSG_VERBOSE("applySelection: photon fails " << m_photSelKey.key());
201  isOK(*phot) = false;
202  return StatusCode::SUCCESS;
203  }
204  }
205 
206  // Check incoming selection tool
207  if (!m_photSelTool.empty()) {
208  if (!m_photSelTool->accept(ctx, phot)) {
209  ATH_MSG_VERBOSE("applySelection: photon fails IsEMLoose cut");
210  isOK(*phot) = false;
211  return StatusCode::SUCCESS;
212  }
213  }
214 
215  // Check pt
216  if (phot->pt() < m_minPhotPt) {
217  ATH_MSG_VERBOSE("applySelection: photon fails pt cut: " << phot->pt() << ", " << m_minPhotPt);
218  isOK(*phot) = false;
219  return StatusCode::SUCCESS;
220  }
221 
222  isOK(*phot) = true;
223 
224  ATH_MSG_VERBOSE("applySelection: " << phot->type() << ", " << phot->pt() << ", " << phot->eta() << ", " << phot->phi() << ", " << (int)isOK(*phot));
225 
226  return StatusCode::SUCCESS;
227  }
228 
229 } // 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:55
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CP::IsoCloseByCorrectionAlg::m_minMuonPt
Gaudi::Property< float > m_minMuonPt
Definition: IsoCloseByCorrectionAlg.h:66
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
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:70
xAODP4Helpers.h
CP::IsoCloseByCorrectionAlg::m_contKeys
SG::ReadHandleKeyArray< xAOD::IParticleContainer > m_contKeys
Input containers to retrieve from the storegate.
Definition: IsoCloseByCorrectionAlg.h:44
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:50
CP::IsoCloseByCorrectionAlg::m_minElecPt
Gaudi::Property< float > m_minElecPt
Kinematic cuts - if needed.
Definition: IsoCloseByCorrectionAlg.h:64
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
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:57
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::IsoCloseByCorrectionAlg::IsoCloseByCorrectionAlg
IsoCloseByCorrectionAlg(const std::string &name, ISvcLocator *svcLoc)
Definition: IsoCloseByCorrectionAlg.cxx:18
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:83
CP::IsoCloseByCorrectionAlg::m_photSelKey
SG::ReadDecorHandleKey< xAOD::PhotonContainer > m_photSelKey
Definition: IsoCloseByCorrectionAlg.h:52
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
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
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:45
CP::IsoCloseByCorrectionAlg::initialize
StatusCode initialize() override
Definition: IsoCloseByCorrectionAlg.cxx:20
IsoCloseByCorrectionAlg.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CP::IsoCloseByCorrectionAlg::m_minPhotPt
Gaudi::Property< float > m_minPhotPt
Definition: IsoCloseByCorrectionAlg.h:68
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:199
CP::IsoCloseByCorrectionAlg::selectLeptonsAndPhotons
StatusCode selectLeptonsAndPhotons(const EventContext &ctx, CONT_TYPE particles) const
Definition: IsoCloseByCorrectionAlg.cxx:108
python.HLT.Muon.MuonRecoSequences.isLRT
def isLRT(name)
Definition: MuonRecoSequences.py:65
xAOD::Photon_v1
Definition: Photon_v1.h:37
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
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:60
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
ReadHandle.h
Handle class for reading from StoreGate.
CP::IsoCloseByCorrectionAlg::m_elecSelTool
ToolHandle< IAsgElectronLikelihoodTool > m_elecSelTool
Definition: IsoCloseByCorrectionAlg.h:56
CP::IsoCloseByCorrectionAlg::m_elecSelKey
SG::ReadDecorHandleKey< xAOD::ElectronContainer > m_elecSelKey
Definition: IsoCloseByCorrectionAlg.h:51
CP::IsoCloseByCorrectionAlg::applySelection
StatusCode applySelection(const EventContext &ctx, const xAOD::Electron *elec) const
Definition: IsoCloseByCorrectionAlg.cxx:156
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17