ATLAS Offline Software
Loading...
Searching...
No Matches
PhotonBDTCalculator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "xAODEgamma/Photon.h"
7#include <limits>
8
9namespace {
10 // Internal helper function
11 inline StatusCode getShowerShape(const xAOD::Photon& ph,
13 float& out)
14 {
15 if (!ph.showerShapeValue(out, t)) { return StatusCode::FAILURE; }
16 return StatusCode::SUCCESS;
17 }
18} // end anonymous namespace
19
20namespace PhotonIDBDT {
21
23 : asg::AsgTool(name)
24{}
25
27
29 // Base tools for BDT evaluation
30 ATH_CHECK(m_toolConv.retrieve());
31 ATH_CHECK(m_toolUnconv.retrieve());
32
33 return StatusCode::SUCCESS;
34}
35
36// Helpers to compute input variables for converted photons
37StatusCode PhotonBDTCalculator::fillVariablesConv(const xAOD::Photon& ph, std::vector<float>& vars) const {
38 vars.clear();
39 vars.reserve(m_reserveVarsConv.value());
40 // Get photon kinematics
41 const float eta = ph.eta();
42 const float ptGeV = ph.pt() * 1e-3f; // convert to GeV
43 const float ptGeV_capped = std::min(ptGeV, 700.f); // Cap pt at 700 GeV
44 // Get shower shape variables
45 float reta = 0.f, rphi = 0.f, weta2 = 0.f, fracs1 = 0.f, weta1 = 0.f, wtots1 = 0.f, rhad = 0.f, rhad1 = 0.f, eratio = 0.f, deltaE = 0.f;
46 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::Reta, reta));
47 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::Rphi, rphi));
48 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::weta2, weta2));
49 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::fracs1, fracs1));
50 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::weta1, weta1));
51 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::wtots1, wtots1));
52 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::Rhad, rhad));
53 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::Rhad1, rhad1));
54 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::Eratio, eratio));
55 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::DeltaE, deltaE));
56 // Fill variables in the order expected by the BDT tool
57 vars.push_back(ptGeV_capped);
58 vars.push_back(eta);
59 vars.push_back(reta);
60 vars.push_back(rphi);
61 vars.push_back(weta2);
62 vars.push_back(fracs1);
63 vars.push_back(weta1);
64 vars.push_back(wtots1);
65 vars.push_back(rhad);
66 vars.push_back(rhad1);
67 vars.push_back(eratio);
68 vars.push_back(deltaE);
69 // The end!
70 return StatusCode::SUCCESS;
71}
72
73StatusCode PhotonBDTCalculator::fillVariablesUnconv(const xAOD::Photon& ph, std::vector<float>& vars) const {
74 vars.clear();
75 vars.reserve(m_reserveVarsUnconv.value());
76 // Get photon kinematics
77 const float eta = ph.eta();
78 const float ptGeV = ph.pt() * 1e-3f; // convert to GeV
79 const float ptGeV_capped = std::min(ptGeV, 700.f); // Cap pt at 700 GeV
80 // Get shower shape variables
81 float reta = 0.f, rphi = 0.f, weta2 = 0.f, fracs1 = 0.f, weta1 = 0.f, wtots1 = 0.f, rhad = 0.f, rhad1 = 0.f, eratio = 0.f, deltaE = 0.f;
82 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::Reta, reta));
83 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::Rphi, rphi));
84 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::weta2, weta2));
85 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::fracs1, fracs1));
86 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::weta1, weta1));
87 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::wtots1, wtots1));
88 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::Rhad, rhad));
89 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::Rhad1, rhad1));
90 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::Eratio, eratio));
91 ATH_CHECK(getShowerShape(ph, xAOD::EgammaParameters::DeltaE, deltaE));
92 // Fill variables in the order expected by the BDT tool
93 vars.push_back(ptGeV_capped);
94 vars.push_back(eta);
95 vars.push_back(reta);
96 vars.push_back(rphi);
97 vars.push_back(weta2);
98 vars.push_back(fracs1);
99 vars.push_back(weta1);
100 vars.push_back(wtots1);
101 vars.push_back(rhad);
102 vars.push_back(rhad1);
103 vars.push_back(eratio);
104 vars.push_back(deltaE);
105 // The end!
106 return StatusCode::SUCCESS;
107}
108
112
113StatusCode PhotonBDTCalculator::decorate(const xAOD::Photon& ph) const {
115 float score = 0.f;
116 ATH_CHECK(getScore(ph, score));
117 decScore(ph) = score;
118 return StatusCode::SUCCESS;
119}
120
121StatusCode PhotonBDTCalculator::getScore(const xAOD::Photon& ph, float& score) const {
123 if (!m_forceRecompute && accScore.isAvailable(ph)) {
124 score = accScore(ph);
125 return StatusCode::SUCCESS;
126 }
127 std::vector<float> vars;
128 if (isConverted(ph)) {
129 ATH_CHECK(fillVariablesConv(ph, vars));
130 ATH_CHECK(m_toolConv->computeScore(vars, score));
131 } else {
133 ATH_CHECK(m_toolUnconv->computeScore(vars, score));
134 }
135 return StatusCode::SUCCESS;
136}
137
139{
140 if (!photon) {
141 throw std::invalid_argument("PhotonBDTCalculator::evaluate called with nullptr photon");
142 }
143
144 float score = 0.f;
145 const StatusCode sc = getScore(*photon, score);
146 if (sc.isFailure()) {
147 // Fails loudly if it cannot be computed
148 throw std::runtime_error("PhotonBDTCalculator::evaluate failed to compute BDT score");
149 }
150 return static_cast<double>(score);
151}
152
153} // namespace PhotonIDBDT
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t sc
StatusCode getScore(const xAOD::Photon &ph, float &score) const
Return the score (computes if needed if m_forceRecompute is true)
Gaudi::Property< bool > m_excludeTRT
StatusCode fillVariablesConv(const xAOD::Photon &ph, std::vector< float > &vars) const
virtual double evaluate(const xAOD::Photon *photon) const override
virtual ~PhotonBDTCalculator() override
Gaudi::Property< bool > m_forceRecompute
bool isConverted(const xAOD::Photon &ph) const
Gaudi::Property< unsigned > m_reserveVarsConv
StatusCode fillVariablesUnconv(const xAOD::Photon &ph, std::vector< float > &vars) const
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Gaudi::Property< std::string > m_decorationName
ToolHandle< PhotonSingleBDTCalculator > m_toolConv
ToolHandle< PhotonSingleBDTCalculator > m_toolUnconv
StatusCode decorate(const xAOD::Photon &ph) const
Compute and decorate the photon with the BDT score.
Gaudi::Property< unsigned > m_reserveVarsUnconv
PhotonBDTCalculator(const std::string &name)
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:576
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:573
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition Egamma_v1.cxx:66
bool showerShapeValue(float &value, const EgammaParameters::ShowerShapeType information) const
Accessor for ShowerShape values.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition Egamma_v1.cxx:71
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
@ wtots1
shower width is determined in a window detaxdphi = 0,0625 ×~0,2, corresponding typically to 20 strips...
@ Eratio
(emaxs1-e2tsts1)/(emaxs1+e2tsts1)
@ DeltaE
e2tsts1-emins1
@ fracs1
shower shape in the shower core : [E(+/-3)-E(+/-1)]/E(+/-1), where E(+/-n) is the energy in ± n strip...
@ weta2
the lateral width is calculated with a window of 3x5 cells using the energy weighted sum over all cel...
@ weta1
shower width using +/-3 strips around the one with the maximal energy deposit: w3 strips = sqrt{sum(E...
Definition EgammaEnums.h:98
Photon_v1 Photon
Definition of the current "egamma version".