ATLAS Offline Software
ParticleLevelOverlapRemovalAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 
13 
14 namespace CP {
15 
17 
18  ANA_CHECK(m_jetsKey.initialize());
22 
23  if (!m_electronsKey.empty())
24  m_decORelectron = m_electronsKey.key() + "." + m_decLabelOR.value();
25  if (!m_muonsKey.empty())
26  m_decORmuon = m_muonsKey.key() + "." + m_decLabelOR.value();
27  if (!m_photonsKey.empty())
28  m_decORphoton = m_photonsKey.key() + "." + m_decLabelOR.value();
29  m_decORjet = m_jetsKey.key() + "." + m_decLabelOR.value();
30 
34  ANA_CHECK(m_decORjet.initialize());
35 
36  if (!m_jetSelection.empty())
40  if (!m_muonSelection.empty())
42  if (!m_photonSelection.empty())
44 
45  return StatusCode::SUCCESS;
46 }
47 
49  TLorentzVector& p2,
50  bool useRapidity) {
51  if (useRapidity)
52  return xAOD::P4Helpers::deltaR(p1->rapidity(), p1->phi(), p2.Rapidity(),
53  p2.Phi());
54  else
55  return xAOD::P4Helpers::deltaR(p1->eta(), p1->phi(), p2.Eta(), p2.Phi());
56 }
57 
59  const EventContext& ctx = Gaudi::Hive::currentContext();
60 
64  if (m_doJetMuonOR)
65  muons = SG::makeHandle(m_muonsKey, ctx);
66  if (m_doJetPhotonOR)
67  photons = SG::makeHandle(m_photonsKey, ctx);
69 
71  m_decORelectron, ctx);
73  m_decORmuon, ctx);
75  m_decORphoton, ctx);
77 
78  // accessors
79  static const SG::AuxElement::ConstAccessor<float> acc_pt_dressed(
80  "pt_dressed");
81  static const SG::AuxElement::ConstAccessor<float> acc_eta_dressed(
82  "eta_dressed");
83  static const SG::AuxElement::ConstAccessor<float> acc_phi_dressed(
84  "phi_dressed");
85  static const SG::AuxElement::ConstAccessor<float> acc_e_dressed("e_dressed");
86 
87  // Default decorations: all objects pass!
88  for (const auto* jet : *jets) {
89  if (m_jetSelection)
90  dec_jets_OR(*jet) = m_jetSelection.getBool(*jet);
91  else
92  dec_jets_OR(*jet) = true;
93  }
94  if (m_doJetElectronOR) {
95  for (const auto* electron : *electrons) {
97  dec_electrons_OR(*electron) = m_electronSelection.getBool(*electron);
98  else
99  dec_electrons_OR(*electron) = true;
100  }
101  }
102  if (m_doJetMuonOR) {
103  for (const auto* muon : *muons) {
104  if (m_muonSelection)
105  dec_muons_OR(*muon) = m_muonSelection.getBool(*muon);
106  else
107  dec_muons_OR(*muon) = true;
108  }
109  }
110  if (m_doJetPhotonOR) {
111  for (const auto* photon : *photons) {
112  if (m_photonSelection)
113  dec_photons_OR(*photon) = m_photonSelection.getBool(*photon);
114  else
115  dec_photons_OR(*photon) = true;
116  }
117  }
118 
119  // ----------------------
120  // OVERLAP REMOVAL
121  // ----------------------
122  // Removal Steps:
123  // 1. Jets & Muons:
124  // Remove Muons with dR < 0.4
125  // 2. Jets & Electrons:
126  // Remove Electrons with dR < 0.4
127  // 3. Photons & Jets:
128  // Remove Jets with dR < 0.4
129 
130  for (const auto* jet : *jets) {
132  continue;
133  if (m_doJetMuonOR) {
134  for (const auto* muon : *muons) {
136  continue;
137  if (dec_muons_OR(*muon)) {
139  TLorentzVector dressed_muon;
140  dressed_muon.SetPtEtaPhiE(
141  acc_pt_dressed(*muon), acc_eta_dressed(*muon),
142  acc_phi_dressed(*muon), acc_e_dressed(*muon));
143  if (dressedDeltaR(jet, dressed_muon, m_useRapidity) < 0.4)
144  dec_muons_OR(*muon) = false;
145  } else {
147  dec_muons_OR(*muon) = false;
148  }
149  }
150  }
151  }
152  if (m_doJetElectronOR) {
153  for (const auto* electron : *electrons) {
155  continue;
156  if (dec_electrons_OR(*electron)) {
158  TLorentzVector dressed_electron;
159  dressed_electron.SetPtEtaPhiE(
160  acc_pt_dressed(*electron), acc_eta_dressed(*electron),
161  acc_phi_dressed(*electron), acc_e_dressed(*electron));
162  if (dressedDeltaR(jet, dressed_electron, m_useRapidity) < 0.4)
163  dec_electrons_OR(*electron) = false;
164  } else {
166  dec_electrons_OR(*electron) = false;
167  }
168  }
169  }
170  }
171  if (m_doJetPhotonOR) {
172  for (const auto* photon : *photons) {
174  continue;
175  if (dec_photons_OR(*photon)) {
176  if (xAOD::P4Helpers::deltaR(jet, photon) < 0.4)
177  dec_jets_OR(*jet) = false;
178  }
179  }
180  }
181  }
182 
183  return StatusCode::SUCCESS;
184 }
185 
186 } // namespace CP
CP::SelectionReadHandle::initialize
StatusCode initialize()
initialize the accessor
Definition: SelectionReadHandle.cxx:39
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
CP::ParticleLevelOverlapRemovalAlg::m_doJetPhotonOR
Gaudi::Property< bool > m_doJetPhotonOR
Definition: ParticleLevelOverlapRemovalAlg.h:65
CP::ParticleLevelOverlapRemovalAlg::m_decORelectron
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_decORelectron
Definition: ParticleLevelOverlapRemovalAlg.h:36
CurrentContext.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODP4Helpers.h
CP::ParticleLevelOverlapRemovalAlg::m_photonSelection
CP::SelectionReadHandle m_photonSelection
Definition: ParticleLevelOverlapRemovalAlg.h:49
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
CP::ParticleLevelOverlapRemovalAlg::m_muonsKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_muonsKey
Definition: ParticleLevelOverlapRemovalAlg.h:30
CP::ParticleLevelOverlapRemovalAlg::dressedDeltaR
float dressedDeltaR(const xAOD::Jet *p1, TLorentzVector &p2, bool useRapidity)
Definition: ParticleLevelOverlapRemovalAlg.cxx:48
CP::ParticleLevelOverlapRemovalAlg::m_jetsKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetsKey
Definition: ParticleLevelOverlapRemovalAlg.h:26
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
CP::ParticleLevelOverlapRemovalAlg::m_muonSelection
CP::SelectionReadHandle m_muonSelection
Definition: ParticleLevelOverlapRemovalAlg.h:47
ParticleLevelOverlapRemovalAlg.h
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
CP::SelectionReadHandle::empty
bool empty() const noexcept
whether we have a name configured
Definition: SelectionReadHandle.cxx:23
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
xAOD::P4Helpers::deltaR
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Definition: xAODP4Helpers.h:150
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
CP::ParticleLevelOverlapRemovalAlg::m_decORphoton
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_decORphoton
Definition: ParticleLevelOverlapRemovalAlg.h:40
CP::ParticleLevelOverlapRemovalAlg::m_doJetElectronOR
Gaudi::Property< bool > m_doJetElectronOR
Definition: ParticleLevelOverlapRemovalAlg.h:59
CP::ParticleLevelOverlapRemovalAlg::m_electronSelection
CP::SelectionReadHandle m_electronSelection
Definition: ParticleLevelOverlapRemovalAlg.h:44
CP::ParticleLevelOverlapRemovalAlg::m_decLabelOR
Gaudi::Property< std::string > m_decLabelOR
Definition: ParticleLevelOverlapRemovalAlg.h:68
CP::ParticleLevelOverlapRemovalAlg::m_doJetMuonOR
Gaudi::Property< bool > m_doJetMuonOR
Definition: ParticleLevelOverlapRemovalAlg.h:62
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
CP::ParticleLevelOverlapRemovalAlg::m_jetSelection
CP::SelectionReadHandle m_jetSelection
Definition: ParticleLevelOverlapRemovalAlg.h:42
CP::ParticleLevelOverlapRemovalAlg::m_useRapidity
Gaudi::Property< bool > m_useRapidity
Definition: ParticleLevelOverlapRemovalAlg.h:51
WriteDecorHandle.h
Handle class for adding a decoration to an object.
CP::SelectionReadHandle::getBool
bool getBool(const SG::AuxElement &element) const
get the selection as a bool
CP::ParticleLevelOverlapRemovalAlg::m_electronsKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_electronsKey
Definition: ParticleLevelOverlapRemovalAlg.h:28
ReadHandle.h
Handle class for reading from StoreGate.
CP::ParticleLevelOverlapRemovalAlg::execute
virtual StatusCode execute() final
Definition: ParticleLevelOverlapRemovalAlg.cxx:58
CP::ParticleLevelOverlapRemovalAlg::m_useDressedProperties
Gaudi::Property< bool > m_useDressedProperties
Definition: ParticleLevelOverlapRemovalAlg.h:55
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
CP::ParticleLevelOverlapRemovalAlg::m_photonsKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_photonsKey
Definition: ParticleLevelOverlapRemovalAlg.h:32
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:199
CP::ParticleLevelOverlapRemovalAlg::initialize
virtual StatusCode initialize() final
Definition: ParticleLevelOverlapRemovalAlg.cxx:16
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
CP::ParticleLevelOverlapRemovalAlg::m_decORmuon
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_decORmuon
Definition: ParticleLevelOverlapRemovalAlg.h:38
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
CP::ParticleLevelOverlapRemovalAlg::m_decORjet
SG::WriteDecorHandleKey< xAOD::JetContainer > m_decORjet
Definition: ParticleLevelOverlapRemovalAlg.h:34
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17