ATLAS Offline Software
ParticleLevelPhotonObjectSelector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
9 
10 namespace top {
12  : m_opt(opt) { /* Deliberately Empty */}
13 
15  double etaMax /* = 2.5 */,
16  const std::string& Origin /* = "" */,
17  const std::string& Isolation /* = "" */) :
18  pt_min(ptMin),
19  eta_max(etaMax),
20  origin(),
21  isolationVar(""),
22  isolationCut() {
23  // =========================================================
24  // Parse the TruthOrigin Configuration Parameter.
25  if (Origin == "" || Origin == " " || Origin == "False" || Origin == "None") {
26  // Deliberately Empty
27  } else {
28  // This allows us to convert from string name to enum value.
29  MCTruthPartClassifier::ParticleDef def;
30 
31  // Tokenize at comma.
32  std::vector<std::string> tokens;
33  tokenize(Origin, tokens, ",");
34 
35  while (tokens.size()) {
36  const auto& token = tokens.back();
37 
38  auto it = std::find(def.sParticleOrigin.begin(),
39  def.sParticleOrigin.end(),
40  token);
41 
42  top::check(it != def.sParticleOrigin.end(),
43  "[ParticleLevelPhotonObjectSelector] Invalid particle origin '" + token + "'");
44 
45  origin.push_back(
47  std::distance(def.sParticleOrigin.begin(),
48  it)));
49 
50  tokens.pop_back();
51  }
52  }
53 
54  // =========================================================
55  // Parse the TruthIsolation Configuration Parameter
56  if (Isolation == "" || Isolation == " " || Isolation == "False" || Isolation == "None") {
57  isolationVar = "";
58  } else {
59  // Split at space, should be exactly 2 tokens.
60  std::vector<std::string> tokens;
61  tokenize(Isolation, tokens, " ");
62  top::check(tokens.size() == 2,
63  "[ParticleLevelPhotonObjectSelector] Invalid input for isolation parameter (expected 2 tokens).");
64 
65  isolationVar = tokens.at(0);
66  isolationCut = std::stof(tokens.at(1));
67  }
68  }
69 
70  /* virtual */ bool ParticleLevelPhotonObjectSelector::apply(const xAOD::TruthParticle& truthParticle) {
71  // --------------------------------------------------
72  // Require that the photon is status=1 (stable)
73  // TODO: Should we include other statuses?
74  if (!MC::isStable(&truthParticle)) {
75  return false;
76  }
77 
78  // --------------------------------------------------
79  // Apply kinematic cut on the pT:
80  // must exceed 25 GeV
81  if (truthParticle.pt() < m_opt.pt_min) {
82  return false;
83  }
84 
85  // --------------------------------------------------
86  // Apply kinematic cut on the eta:
87  // must be less than or equal to 2.5
88  if (std::abs(truthParticle.eta()) > m_opt.eta_max) {
89  return false;
90  }
91 
92  // --------------------------------------------------
93  // Apply particle origin cut.
94  if (m_opt.origin.size()) {
95  unsigned int origin = 0;
96  if (truthParticle.isAvailable<unsigned int>("particleOrigin")) {
97  origin = truthParticle.auxdata<unsigned int>("particleOrigin");
98  } else if (truthParticle.isAvailable<unsigned int>("classifierParticleOrigin")) {
99  origin = truthParticle.auxdata<unsigned int>("classifierParticleOrigin");
100  } else {
101  top::check(false, "Could not obtain MCTruthClassifier result decoration.");
102  }
103 
104  if (std::find(m_opt.origin.begin(), m_opt.origin.end(), origin) == m_opt.origin.end()) {
105  return false;
106  }
107  }
108 
109  // --------------------------------------------------
110  // Apply isolation cut
111  if (m_opt.isolationVar.size()) {
112  top::check(truthParticle.isAvailable<float>(m_opt.isolationVar),
113  "[ParticleLevelPhotonObjectSelector] Selected isolation variable not available!");
114  if (m_opt.isolationCut <= truthParticle.auxdata<float>(m_opt.isolationVar) / truthParticle.pt()) {
115  return false;
116  }
117  }
118 
119  // --------------------------------------------------
120  // Everything that reaches this point has passed the selection
121  return true;
122  }
123 }
top::ParticleLevelPhotonObjectSelector::Options::origin
std::vector< MCTruthPartClassifier::ParticleOrigin > origin
Definition: ParticleLevelPhotonObjectSelector.h:41
top::ParticleLevelPhotonObjectSelector::apply
virtual bool apply(const xAOD::TruthParticle &truthParticle)
Definition: ParticleLevelPhotonObjectSelector.cxx:70
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
top::ParticleLevelPhotonObjectSelector::Options::isolationVar
std::string isolationVar
Definition: ParticleLevelPhotonObjectSelector.h:42
top::tokenize
void tokenize(const std::string &input, Container &output, const std::string &delimiters=" ", bool trim_empty=false)
Tokenize an input string using a set of delimiters.
Definition: Tokenize.h:24
skel.it
it
Definition: skel.GENtoEVGEN.py:423
top::ParticleLevelPhotonObjectSelector::Options::pt_min
double pt_min
Definition: ParticleLevelPhotonObjectSelector.h:39
xAOD::etaMax
etaMax
Definition: HIEventShape_v2.cxx:46
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
top::ParticleLevelPhotonObjectSelector::ParticleLevelPhotonObjectSelector
ParticleLevelPhotonObjectSelector(Options cuts=Options())
Definition: ParticleLevelPhotonObjectSelector.cxx:11
ParticleOrigin
ParticleOrigin
Definition: TruthClasses.h:51
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
top::ParticleLevelPhotonObjectSelector::Options::isolationCut
float isolationCut
Definition: ParticleLevelPhotonObjectSelector.h:43
ParticleLevelPhotonObjectSelector.h
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
top::ParticleLevelPhotonObjectSelector::Options::eta_max
double eta_max
Definition: ParticleLevelPhotonObjectSelector.h:40
pmontree.opt
opt
Definition: pmontree.py:16
xAOD::TruthParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:174
xAOD::IParticle::isAvailable
bool isAvailable(const std::string &name, const std::string &clsname="") const
Check if a user property is available for reading or not.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:131
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
Tokenize.h
PhysDESDM_SmpCaloId.ptMin
ptMin
Definition: PhysDESDM_SmpCaloId.py:90
xAOD::IParticle::auxdata
T & auxdata(const std::string &name, const std::string &clsname="")
Fetch an aux data variable, as a non-const reference.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:96
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TruthParticle_v1.cxx:166
top::ParticleLevelPhotonObjectSelector::Options::Options
Options(double ptMin=25.e3, double etaMax=2.5, const std::string &Origin="", const std::string &Isolation="")
Definition: ParticleLevelPhotonObjectSelector.cxx:14
top::ParticleLevelPhotonObjectSelector::Options
Definition: ParticleLevelPhotonObjectSelector.h:33
top::ParticleLevelPhotonObjectSelector::m_opt
Options m_opt
Definition: ParticleLevelPhotonObjectSelector.h:49
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
HepMCHelpers.h