ATLAS Offline Software
Loading...
Searching...
No Matches
egammaTransformerSvc.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/Egamma.h"
10#include "xAODEgamma/Photon.h"
13
14#include <TFile.h>
15#include <TObjString.h>
16
17
19{
20 ATH_MSG_DEBUG("In initialize of " << name() << "..." );
21
22 if (!m_mvaElectron.empty()) {
23 ATH_MSG_DEBUG("Retrieving mvaElectron");
24 ATH_CHECK(m_mvaElectron.retrieve());
25 } else {
26 ATH_MSG_DEBUG("Disabling mvaElectron");
27 m_mvaElectron.disable();
28 }
29
30 if (!m_mvaFwdElectron.empty()) {
31 ATH_MSG_DEBUG("Retrieving mvaFwdElectron");
32 ATH_CHECK(m_mvaFwdElectron.retrieve());
33 } else {
34 ATH_MSG_DEBUG("Disabling mvaFwdElectron");
35 m_mvaFwdElectron.disable();
36 }
37
38 if (!m_mvaUnconvertedPhoton.empty()) {
39 ATH_MSG_DEBUG("Retrieving mvaUnconvertedPhoton");
41 } else {
42 ATH_MSG_DEBUG("Disabling mvaUnconvertedPhoton");
43 m_mvaUnconvertedPhoton.disable();
44 }
45
46 if (!m_mvaConvertedPhoton.empty()) {
47 ATH_MSG_DEBUG("Retrieving mvaConvertedPhoton");
49 } else {
50 ATH_MSG_DEBUG("Disabling mvaConvertedPhoton");
51 m_mvaConvertedPhoton.disable();
52 }
53
55
58
59 return StatusCode::SUCCESS;
60}
61
63{
64 // For transformer, we always remove the TRT converted photons in the barrel to make it consistent with the training. Therefore we do not support other options for m_removeTRTConvBarrel and set it to true by default. If users set it to other values, we will print a warning and set it to true.
65 const bool removeTRTConvBarrelDefault = true;
66 if (m_removeTRTConvBarrel == -1) {
67 m_removeTRTConvBarrel = removeTRTConvBarrelDefault;
68 }
69 else if (!m_removeTRTConvBarrel) {
70 ATH_MSG_WARNING("m_removeTRTConvBarrel is set to " << m_removeTRTConvBarrel << " which is not supported for Transformer which excluded TRT conversion in the model training. Setting it to " << removeTRTConvBarrelDefault);
71 m_removeTRTConvBarrel = removeTRTConvBarrelDefault;
72 }
73 else {
74 ATH_MSG_DEBUG("TRT converted photons in the barrel will be removed for calibration, which is consistent with the training of the Transformer model.");
75 }
76
77 return StatusCode::SUCCESS;
78}
79
81{
85 // special case in Run3 to avoid TRT converted photons in the barrel
87 }
88 return isConvCalib;
89}
90
91// Note for both egammaTransformerSvc::getEnergy overloads below:
92// zero-response handling is delegated to the underlying calibration tools
93// (m_mvaElectron/m_mvaFwdElectron/m_mvaConvertedPhoton/m_mvaUnconvertedPhoton).
94// By default their property useClusterIf0 (m_clusterEif0) is true, so a zero
95// model response returns the uncalibrated cluster energy instead of 0.
96// Therefore mvaE is not expected to be 0 by default unless the user explicitly
97// changes that tool property in the calibration configuration.
98
100 const xAOD::Egamma& eg,
101 double& mvaE,
102 const egammaMVACalib::GlobalEventInfo& gei) const
103{
104
105 ATH_MSG_DEBUG("calling egammaTransformerSvc::getEnergy with cluster and eg");
106
107 mvaE = 0.;
108
110 if (!m_mvaElectron.empty()) {
111 mvaE = m_mvaElectron->getEnergy(cluster, &eg, gei);
112 } else {
113 ATH_MSG_FATAL("Trying to calibrate an electron, but disabled");
114 return StatusCode::FAILURE;
115 }
116 } else if (xAOD::EgammaHelpers::isFwdElectron(&eg)) {
117 if (!m_mvaFwdElectron.empty()) {
118 mvaE = m_mvaFwdElectron->getEnergy(cluster, &eg, gei);
119 } else {
120 ATH_MSG_FATAL("Trying to calibrate a forward electron, but disabled");
121 return StatusCode::FAILURE;
122 }
123 } else if (xAOD::EgammaHelpers::isPhoton(&eg)) {
124 const xAOD::Photon* ph = static_cast<const xAOD::Photon*>(&eg);
125 const bool is_conv_calib = isConvCalib(*ph);
126 if (is_conv_calib) {
127 if (!m_mvaConvertedPhoton.empty()) {
128 mvaE = m_mvaConvertedPhoton->getEnergy(cluster, &eg, gei);
129 } else {
130 ATH_MSG_FATAL("Trying to calibrate a converted photon, but disabled");
131 return StatusCode::FAILURE;
132 }
133 } else {
134 if (!m_mvaUnconvertedPhoton.empty()) {
135 mvaE = m_mvaUnconvertedPhoton->getEnergy(cluster, &eg, gei);
136 } else {
137 ATH_MSG_FATAL("Trying to calibrate an unconverted photon, but disabled");
138 return StatusCode::FAILURE;
139 }
140 }
141 } else {
142 ATH_MSG_FATAL("Egamma object is of unsupported type");
143 return StatusCode::FAILURE;
144 }
145
146 ATH_MSG_DEBUG( "Calculated MVA calibrated energy = " << mvaE );
147 return StatusCode::SUCCESS;
148}
149
152 double& mvaE,
153 const egammaMVACalib::GlobalEventInfo& gei) const
154{
155
156 ATH_MSG_DEBUG("calling egammaTransformerSvc::getEnergy with cluster and egType (" << egType <<")");
157
158 mvaE = 0.0;
159 switch (egType) {
161 if (!m_mvaElectron.empty()) {
162 mvaE = m_mvaElectron->getEnergy(cluster,nullptr, gei);
163 } else {
164 ATH_MSG_FATAL("Trying to calibrate an electron, but disabled");
165 return StatusCode::FAILURE;
166 }
167 break;
169 if (!m_mvaFwdElectron.empty()) {
170 mvaE = m_mvaFwdElectron->getEnergy(cluster,nullptr, gei);
171 } else {
172 ATH_MSG_FATAL("Trying to calibrate a forward electron, but disabled");
173 return StatusCode::FAILURE;
174 }
175 break;
178 // treat converted photons like unconverted photons since don't have access to vertex
179 if (!m_mvaUnconvertedPhoton.empty()) {
180 mvaE = m_mvaUnconvertedPhoton->getEnergy(cluster,nullptr, gei);
181 } else {
182 ATH_MSG_FATAL("Trying to calibrate an unconverted photon, but disabled");
183 return StatusCode::FAILURE;
184 }
185 break;
186 default:
187 ATH_MSG_FATAL("Egamma object " << egType << " is of unsupported type");
188 return StatusCode::FAILURE;
189 }
190
191 ATH_MSG_DEBUG( "Calculated MVA calibrated energy = " << mvaE );
192 return StatusCode::SUCCESS;
193}
194
195
197 const xAOD::Egamma& eg,
198 const egammaMVACalib::GlobalEventInfo& gei) const
199{
200 double mvaE = 0.;
201
202 ATH_CHECK(getEnergy(cluster, eg, mvaE, gei));
203
204 if (mvaE > eg.m()) {
205 cluster.setCalE(mvaE);
206 }
207 else {
208 ATH_MSG_DEBUG("MVA energy (" << mvaE << ") < particle mass ("
209 << eg.m() << "), setting e = cluster energy (" << cluster.e() << ")");
210 cluster.setCalE(cluster.e());
211 }
212 return StatusCode::SUCCESS;
213}
214
217 const egammaMVACalib::GlobalEventInfo& gei) const
218{
219
220 double mvaE = 0.;
221
222 ATH_CHECK(getEnergy(cluster, egType, mvaE, gei));
223
224 if (mvaE > 0) {
225 cluster.setCalE(mvaE);
226 }
227 else {
228 ATH_MSG_DEBUG("MVA energy (" << mvaE << ") < 0, setting e = cluster energy ("
229 << cluster.e() << ")");
230 cluster.setCalE(cluster.e());
231 }
232 return StatusCode::SUCCESS;
233}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
ToolHandle< IegammaMVACalibTool > m_mvaElectron
MVA tool for electron.
Gaudi::Property< int > m_removeTRTConvBarrel
ToolHandle< IegammaMVACalibTool > m_mvaFwdElectron
MVA tool for forward electron.
virtual StatusCode initialize() override
bool isConvCalib(const xAOD::Photon &ph) const
Decide if the photon is converted or not.
ToolHandle< IegammaMVACalibTool > m_mvaConvertedPhoton
MVA tool for converted photon.
StatusCode getEnergy(const xAOD::CaloCluster &cluster, const xAOD::Egamma &eg, double &mvaE, const egammaMVACalib::GlobalEventInfo &gei=egammaMVACalib::GlobalEventInfo()) const override final
Compute the calibrated energy.
ToolHandle< IegammaMVACalibTool > m_mvaUnconvertedPhoton
MVA tool for unconverted photon.
Gaudi::Property< float > m_maxConvR
StatusCode execute(xAOD::CaloCluster &cluster, const xAOD::Egamma &eg, const egammaMVACalib::GlobalEventInfo &gei=egammaMVACalib::GlobalEventInfo()) const override final
Main execute.
virtual double e() const
The total energy of the particle.
void setCalE(flt_t)
Set Energy for signal state CALIBRATED.
virtual double m() const =0
The invariant mass of the particle.
bool isFwdElectron(const xAOD::Egamma *eg)
is the object a Fwd electron
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
float conversionRadius(const xAOD::Vertex *vx)
return the conversion radius or 9999.
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Photon_v1 Photon
Definition of the current "egamma version".
A structure holding some global event information.