ATLAS Offline Software
IsolationTools.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
8 #include "TopEvent/EventTools.h"
9 #include "xAODEgamma/Photon.h"
10 #include "xAODEgamma/Electron.h"
11 #include "xAODMuon/Muon.h"
12 
14 using namespace TopObjectSelectionTools;
15 
16 namespace top {
17  IsolationBase::IsolationBase() {
18  }
19 
20  IsolationBase::~IsolationBase() {
21  }
22 
23  AbsoluteIsolationDC14::AbsoluteIsolationDC14(const xAOD::Iso::IsolationType type, double cutvalue) :
24  m_type(type),
25  m_cutvalue(cutvalue) {
26  }
27 
29  //electrons
30  if (p.type() == xAOD::Type::Electron) {
31  float iso = 0.;
32  const xAOD::Electron* el = dynamic_cast<const xAOD::Electron*>(&p);
33  bool exists = el->isolationValue(iso, m_type);
34  return exists && iso > m_cutvalue;
35  }
36 
37  //muons
38  if (p.type() == xAOD::Type::Muon) {
39  float iso = 0.;
40  const xAOD::Muon* mu = dynamic_cast<const xAOD::Muon*>(&p);
41  bool exists = mu->isolation(iso, m_type);
42  return exists && iso > m_cutvalue;
43  }
44 
45  throw std::runtime_error("TopObjectSelectionTools::IsolationTools::AbsoluteIsolationDC14: Not an electron or muon");
46  }
47 
50  return true;
51  }
52 
53  void AbsoluteIsolationDC14::print(std::ostream& os) const {
54  os << " * AbsoluteIsolationDC14\n";
55  os << " * " << m_type << " > " << m_cutvalue << " MeV\n";
56  //missing in xaodprimities-00-00-02 os << " * " << xAOD::Iso::toString(m_type) << " > " << m_cutvalue << "
57  // MeV\n";
58  }
59 
60  RelativePTVarCone::RelativePTVarCone(unsigned int size, double fraction, unsigned int sizeLoose,
61  double fractionLoose) :
62  m_fraction(fraction),
63  m_fractionLoose(fractionLoose) {
64  if (size != 20 && size != 30 && size != 40) {
65  throw std::runtime_error("TopObjectSelectionTools::IsolationTools::RelativePTVarCone: "
66  "ptvarcone only supports cone sizes of 20, 30, 40\n and you asked for " + std::to_string (size));
67  }
68 
69  std::stringstream ss;
70  ss << "ptvarcone" << size;
71  m_size = ss.str();
72 
73  ss.str("");
74  ss << "ptvarcone" << sizeLoose;
75  m_sizeLoose = ss.str();
76  }
77 
79  return(p.auxdataConst<float>(m_size) / p.pt() < m_fraction);
80  }
81 
83  return(p.auxdataConst<float>(m_sizeLoose) / p.pt() < m_fractionLoose);
84  }
85 
86  void RelativePTVarCone::print(std::ostream& os) const {
87  os << " * RelativePTVarCone\n";
88  os << " * " << m_size << " /pT > " << m_fraction << "\n";
89  }
90 
91  ApproxPTVarCone::ApproxPTVarCone(double fraction, double fractionLoose) :
92  m_fraction(fraction),
93  m_fractionLoose(fractionLoose) {
94  }
95 
97  return(p.auxdataConst<float>("miniIso") / p.pt() < m_fraction);
98  }
99 
101  return(p.auxdataConst<float>("miniIso") / p.pt() < m_fractionLoose);
102  }
103 
104  void ApproxPTVarCone::print(std::ostream& os) const {
105  os << " * Approximate Mini Isolation\n";
106  os << " * iso/pT > " << m_fraction << "\n";
107  }
108 
109  AntiMuonIsolation::AntiMuonIsolation(const std::string& workingPoint) :
110  m_workingPoint(workingPoint) {
111  if (m_workingPoint.substr(0,9) != "AntiMuon_") {
112  ATH_MSG_WARNING("Ignoring isolation working point \""
113  << workingPoint
114  << "\" which is not appropriate for AntiMuons.\n"
115  << "Will use \"AntiMuon_nominal\" instead.");
116  m_workingPoint = "AntiMuon_nominal";
117  }
118  else if (m_workingPoint != "AntiMuon_nominal"
119  && m_workingPoint != "AntiMuon_shapeSyst1"
120  && m_workingPoint != "AntiMuon_shapeSyst2") {
121  ATH_MSG_ERROR("Cannot use undefined isolation working point "
122  << workingPoint
123  << " for AntiMuons.\n"
124  << "Should be one of \"AntiMuon_nominal\", \"AntiMuon_shapeSyst1\", \"AntiMuon_shapeSyst2\".");
125  throw std::runtime_error("Attempt to use inappropriate isolation working point for AntiMuons");
126  }
127  }
128 
130  //muons
131  if (p.type() != xAOD::Type::Muon) {
132  ATH_MSG_ERROR("Cannot use this function for anything else but muons");
133  throw std::runtime_error("Cannot use this function for anything else but muons");
134  }
135 
136  const xAOD::Muon* mu = dynamic_cast<const xAOD::Muon*>(&p);
137  if (mu == nullptr) {
138  ATH_MSG_ERROR("Impossible to cast pointer to xAOD::IParticle into pointer to xAOD::Muon");
139  throw std::runtime_error("Impossible to cast pointer to xAOD::IParticle into pointer to xAOD::Muon");
140  }
141 
142  if (mu->energyLossType() != xAOD::Muon::NotIsolated) return false;
143 
144  float eloss = 0;
145  bool ok = mu->parameter(eloss, xAOD::Muon::EnergyLoss);
146  if (ok && eloss > 6000) return false;
147 
148  float etcone20 = 0, ptvarcone40 = 0;
149  ok = mu->isolation(etcone20, xAOD::Iso::etcone20);
150  if (ok && etcone20 / mu->pt() < 0.03) return false;
151 
152  ok = mu->isolation(ptvarcone40, xAOD::Iso::ptvarcone40);
153  if (m_workingPoint == "AntiMuon_nominal") {
154  if (ok && ptvarcone40 / mu->pt() > 0.1) return false;
155  }
156  else if (m_workingPoint == "AntiMuon_shapeSyst1") {
157  if (ok && ptvarcone40 / mu->pt() > 0.05) return false;
158  }
159  else if (m_workingPoint == "AntiMuon_shapeSyst2") {
160  if (ok && (ptvarcone40 / mu->pt() <= 0.05 || ptvarcone40 / mu->pt() > 0.1)) return false;
161  }
162 
163  return true;
164  }
165 
166  void AntiMuonIsolation::print(std::ostream& os) const {
167  os << " * AntiMuon Isolation : " << m_workingPoint << "\n";
168  os << " * energyLossType : NotIsolated\n";
169  os << " * EnergyLoss <= 6 GeV\n";
170  os << " * etcone20/pT > 0.03\n";
171  if (m_workingPoint == "AntiMuon_nominal") {
172  os << " * ptvarcone40/pT <= 0.1\n";
173  }
174  else if (m_workingPoint == "AntiMuon_shapeSyst1") {
175  os << " * ptvarcone40/pT <= 0.05\n";
176  }
177  else if (m_workingPoint == "AntiMuon_shapeSyst2") {
178  os << " * 0.05 < ptvarcone40/pT <= 0.1\n";
179  }
180  }
181 
182  StandardIsolation::StandardIsolation(const std::string& tightLeptonIsolation,
183  const std::string& looseLeptonIsolation) :
184  m_tightLeptonDecoration("AnalysisTop_Isol_" + tightLeptonIsolation),
185  m_looseLeptonDecoration("AnalysisTop_Isol_" + looseLeptonIsolation),
186  m_tightLeptonIsolation(tightLeptonIsolation),
187  m_looseLeptonIsolation(looseLeptonIsolation),
188  m_doTightIsolation(true),
189  m_doLooseIsolation(true),
190  m_doTightPromptLeptonIso(false),
191  m_doLoosePromptLeptonIso(false),
192  m_skipUnavailable(!ConfigurationSettings::get()->feature("AbortOnUnavailableIsolation")) {
193  if (tightLeptonIsolation == "PromptLepton") m_doTightPromptLeptonIso = true;
194  if (looseLeptonIsolation == "PromptLepton") m_doLoosePromptLeptonIso = true;
195 
196  if (tightLeptonIsolation == "None") m_doTightIsolation = false;
197 
198  if (looseLeptonIsolation == "None") m_doLooseIsolation = false;
199 
200  if ( tightLeptonIsolation == "AntiMuon_nominal"
201  || tightLeptonIsolation == "AntiMuon_shapeSyst1"
202  || tightLeptonIsolation == "AntiMuon_shapeSyst2" ) {
203  ATH_MSG_ERROR("Cannot use isolation working point "
205  << " which is suitable for AntiMuons only.");
206  throw std::runtime_error("Attempt to use inappropriate isolation working point, suitable for AntiMuons only");
207  }
208  if ( looseLeptonIsolation == "AntiMuon_nominal"
209  || looseLeptonIsolation == "AntiMuon_shapeSyst1"
210  || looseLeptonIsolation == "AntiMuon_shapeSyst2" ) {
211  ATH_MSG_ERROR("Cannot use isolation working point "
213  << " which is suitable for AntiMuons only.");
214  throw std::runtime_error("Attempt to use inappropriate isolation working point, suitable for AntiMuons only");
215  }
216  }
217 
219  // Are we doing isolation?
220  if (!m_doTightIsolation) return true;
221 
222  // If we get this far then we are doing isolation
223  if (p.type() == xAOD::Type::Photon ||
224  p.type() == xAOD::Type::Electron ||
225  p.type() == xAOD::Type::Muon) {
227  if (!m_skipUnavailable || p.isAvailable<char>(m_tightLeptonDecoration)) {
228  if (p.auxdataConst<char>(m_tightLeptonDecoration) == 1) {
229  return true;
230  }
231  }
232  } else {
233  // Hardcoded a bit - With PLI we need to check that it passes Loose isolation AND passes the BDT cut
234  if (!m_skipUnavailable ||
235  (p.isAvailable<char>(m_tightLeptonDecoration) && p.isAvailable<char>("AnalysisTop_Isol_Loose"))) {
236  if (p.auxdataConst<char>(m_tightLeptonDecoration) == 1 &&
237  p.auxdataConst<char>("AnalysisTop_Isol_Loose") == 1) {
238  return true;
239  }
240  }
241  }
242  }
243 
244  // Not a photon, electron or muon?
245  // Didn't pass isolation?
246  return false;
247  }
248 
250  // Are we doing isolation?
251  if (!m_doLooseIsolation) return true;
252 
253  // If we get this far then we are doing isolation
254  if (p.type() == xAOD::Type::Photon ||
255  p.type() == xAOD::Type::Electron ||
256  p.type() == xAOD::Type::Muon) {
258  if (!m_skipUnavailable || p.isAvailable<char>(m_looseLeptonDecoration)) {
259  if (p.auxdataConst<char>(m_looseLeptonDecoration) == 1) {
260  return true;
261  }
262  }
263  } else {
264  // Hardcoded a bit - With PLI we need to check that it passes Loose isolation AND passes the BDT cut
265  if (!m_skipUnavailable ||
266  (p.isAvailable<char>(m_looseLeptonDecoration) && p.isAvailable<char>("AnalysisTop_Isol_Loose"))) {
267  if (p.auxdataConst<char>(m_looseLeptonDecoration) == 1 &&
268  p.auxdataConst<char>("AnalysisTop_Isol_Loose") == 1) {
269  return true;
270  }
271  }
272  }
273  }
274 
275  // Not a photon, electron or muon?
276  // Didn't pass isolation?
277  return false;
278  }
279 
280  void StandardIsolation::print(std::ostream& os) const {
281  os << " * Standard Isolation\n";
282  os << " * Tight lepton isolation = " << m_tightLeptonDecoration << "\n";
283  os << " * Loose lepton isolation = " << m_looseLeptonDecoration << "\n";
284  }
285 }
top::AntiMuonIsolation::print
virtual void print(std::ostream &os) const override
Come on, you really need me to tell you what this does?
Definition: IsolationTools.cxx:166
top::RelativePTVarCone::print
virtual void print(std::ostream &os) const override
Come on, you really need me to tell you what this does?
Definition: IsolationTools.cxx:86
top::RelativePTVarCone::passSelectionLoose
virtual bool passSelectionLoose(const xAOD::IParticle &p) const override
Does this particle pass the isolation cuts for the loose analysis definitions (useful for background ...
Definition: IsolationTools.cxx:82
top::RelativePTVarCone::m_size
std::string m_size
The name of the variable to access, e.g. ptvarcone20 formed in the constructor.
Definition: IsolationTools.h:132
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
top::AntiMuonIsolation::AntiMuonIsolation
AntiMuonIsolation(const std::string &workingPoint="AntiMuon_Nominal")
Applies the cuts to etcone and ptcone like we used to in Run-I.
Definition: IsolationTools.cxx:109
top::AntiMuonIsolation::passSelection
virtual bool passSelection(const xAOD::IParticle &p) const override
Does this particle pass the anti-muon isolation cuts?
Definition: IsolationTools.cxx:129
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
top::StandardIsolation::passSelectionLoose
virtual bool passSelectionLoose(const xAOD::IParticle &p) const override
Does this particle pass the isolation cuts for the loose analysis definitions (useful for background ...
Definition: IsolationTools.cxx:249
Muon.h
top::StandardIsolation::tightLeptonIsolation
std::string tightLeptonIsolation()
Definition: IsolationTools.h:259
top::StandardIsolation::m_tightLeptonDecoration
std::string m_tightLeptonDecoration
Definition: IsolationTools.h:265
top::AntiMuonIsolation::m_workingPoint
std::string m_workingPoint
Definition: IsolationTools.h:225
top::StandardIsolation::passSelection
virtual bool passSelection(const xAOD::IParticle &p) const override
Does this particle pass the isolation cuts for the main analysis definitions?
Definition: IsolationTools.cxx:218
top::ApproxPTVarCone::passSelectionLoose
virtual bool passSelectionLoose(const xAOD::IParticle &p) const override
Does this particle pass the isolation cuts for the loose analysis definitions (useful for background ...
Definition: IsolationTools.cxx:100
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
xAOD::Iso::ptvarcone40
@ ptvarcone40
Definition: IsolationType.h:57
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
top::StandardIsolation::looseLeptonIsolation
std::string looseLeptonIsolation()
Definition: IsolationTools.h:260
MsgCategory.h
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
top::AbsoluteIsolationDC14::passSelection
virtual bool passSelection(const xAOD::IParticle &p) const override
For applying isolation cuts to the analysis (tight) lepton.
Definition: IsolationTools.cxx:28
top::StandardIsolation::m_doLooseIsolation
bool m_doLooseIsolation
Definition: IsolationTools.h:270
top::AbsoluteIsolationDC14::print
virtual void print(std::ostream &os) const override
Because people like to know what isolation cuts they're applying.
Definition: IsolationTools.cxx:53
top::ApproxPTVarCone::m_fraction
double m_fraction
For the main analysis object selection.
Definition: IsolationTools.h:188
top::ApproxPTVarCone::ApproxPTVarCone
ApproxPTVarCone(double fraction, double fractionLoose)
An approximation of mini-isolation.
Definition: IsolationTools.cxx:91
m_type
TokenType m_type
the type
Definition: TProperty.cxx:44
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
IsolationTools.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::Iso::etcone20
@ etcone20
Calorimeter isolation.
Definition: IsolationType.h:32
top::ApproxPTVarCone::passSelection
virtual bool passSelection(const xAOD::IParticle &p) const override
Does this particle pass the isolation cuts for the main analysis definitions?
Definition: IsolationTools.cxx:96
Photon.h
top::StandardIsolation::StandardIsolation
StandardIsolation(const std::string &tightLeptonIsolation, const std::string &looseLeptonIsolation)
Applies the cuts to etcone and ptcone like we used to in Run-I.
Definition: IsolationTools.cxx:182
xAOD::Iso::IsolationType
IsolationType
Overall enumeration for isolation types in xAOD files.
Definition: IsolationType.h:26
top::StandardIsolation::m_doTightIsolation
bool m_doTightIsolation
Definition: IsolationTools.h:269
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
ConfigurationSettings.h
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
top::RelativePTVarCone::passSelection
virtual bool passSelection(const xAOD::IParticle &p) const override
Does this particle pass the isolation cuts for the main analysis definitions?
Definition: IsolationTools.cxx:78
top::StandardIsolation::m_looseLeptonDecoration
std::string m_looseLeptonDecoration
Definition: IsolationTools.h:266
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
top::RelativePTVarCone::m_sizeLoose
std::string m_sizeLoose
Name of the variable to access for the loose object definition.
Definition: IsolationTools.h:138
top::ApproxPTVarCone::m_fractionLoose
double m_fractionLoose
For the objects used in the looser object selection (e.g. matrix method fakes)
Definition: IsolationTools.h:191
top::AbsoluteIsolationDC14::m_cutvalue
double m_cutvalue
The value, in MeV, to cut.
Definition: IsolationTools.h:90
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
top::StandardIsolation::print
virtual void print(std::ostream &os) const override
Come on, you really need me to tell you what this does?
Definition: IsolationTools.cxx:280
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
top::StandardIsolation::m_skipUnavailable
bool m_skipUnavailable
Definition: IsolationTools.h:273
Electron.h
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
top::StandardIsolation::m_doLoosePromptLeptonIso
bool m_doLoosePromptLeptonIso
Definition: IsolationTools.h:272
top::RelativePTVarCone::RelativePTVarCone
RelativePTVarCone(unsigned int size, double fraction, unsigned int sizeLoose, double fractionLoose)
Cut on the mini-isolation (aka ptvarcone) as a fraction of the pt of the lepton.
Definition: IsolationTools.cxx:60
top::ConfigurationSettings
Hold the configuration information for the whole run.
Definition: ConfigurationSettings.h:21
top::RelativePTVarCone::m_fractionLoose
double m_fractionLoose
For the objects used in the looser object selection (e.g. matrix method fakes)
Definition: IsolationTools.h:141
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
top::RelativePTVarCone::m_fraction
double m_fraction
For the main analysis object selection.
Definition: IsolationTools.h:135
top::AbsoluteIsolationDC14::m_type
xAOD::Iso::IsolationType m_type
What to cut on (topoetcone20, 30, 40 or ptcone20, 30, 40).
Definition: IsolationTools.h:87
top::StandardIsolation::m_doTightPromptLeptonIso
bool m_doTightPromptLeptonIso
Definition: IsolationTools.h:271
top::AbsoluteIsolationDC14::passSelectionLoose
virtual bool passSelectionLoose(const xAOD::IParticle &p) const override
Implement me!
Definition: IsolationTools.cxx:49
top::ApproxPTVarCone::print
virtual void print(std::ostream &os) const override
Come on, you really need me to tell you what this does?
Definition: IsolationTools.cxx:104