Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
egammaMVASvc.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 #include "xAODEgamma/Egamma.h"
9 #include "xAODEgamma/Electron.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_mvaUnconvertedPhoton.empty()) {
31  ATH_MSG_DEBUG("Retrieving mvaUnconvertedPhoton");
33  } else {
34  ATH_MSG_DEBUG("Disabling mvaUnconvertedPhoton");
35  m_mvaUnconvertedPhoton.disable();
36  }
37 
38  if (!m_mvaConvertedPhoton.empty()) {
39  ATH_MSG_DEBUG("Retrieving mvaConvertedPhoton");
40  ATH_CHECK(m_mvaConvertedPhoton.retrieve());
41  } else {
42  ATH_MSG_DEBUG("Disabling mvaConvertedPhoton");
43  m_mvaConvertedPhoton.disable();
44  }
45 
47 
50 
51  return StatusCode::SUCCESS;
52 }
53 
55 {
56  if (m_removeTRTConvBarrel == -1) {
57  const bool removeTRTConvBarrelDefault = false;
58  if (!m_mvaConvertedPhoton.empty() and !m_folder.empty()) {
59  const std::string mva_filename = PathResolverFindCalibFile(m_folder + "/MVACalib_convertedPhoton.weights.root");
60  std::unique_ptr<TFile> f(TFile::Open(mva_filename.c_str()));
61  if (!f || f->IsZombie()) {
62  ATH_MSG_ERROR("Could not open file: " << mva_filename);
63  m_removeTRTConvBarrel = removeTRTConvBarrelDefault;
64  }
65  else { // we have the MVA for converted photons
66  TObjString* conversionDefinitionObj = nullptr;
67  f->GetObject("conversionDefinition", conversionDefinitionObj);
68  if (conversionDefinitionObj) {
69  m_removeTRTConvBarrel = (conversionDefinitionObj->GetString() == "removeTRTConvBarrel");
70  } else {
71  // the conversion definition is not encoded in the file, this is true for the old ones
72  m_removeTRTConvBarrel = removeTRTConvBarrelDefault;
73  }
74  }
75  } else { // we are running without converted
76  m_removeTRTConvBarrel = removeTRTConvBarrelDefault;
77  }
78  }
79  if (m_removeTRTConvBarrel == -1) {
80  ATH_MSG_ERROR("Could not determine if TRT converted photons should be removed in the barrel");
81  return StatusCode::FAILURE;
82  }
83  return StatusCode::SUCCESS;
84 }
85 
87 {
91  // special case in Run3 to avoid TRT converted photons in the barrel
93  }
94  return isConvCalib;
95 }
96 
98  const xAOD::Egamma& eg,
99  double& mvaE) const
100 {
101 
102  ATH_MSG_DEBUG("calling egammaMVASvc::getEnergy with cluster and eg");
103 
104  mvaE = 0.;
105 
107  if (!m_mvaElectron.empty()) {
108  mvaE = m_mvaElectron->getEnergy(cluster, &eg);
109  } else {
110  ATH_MSG_FATAL("Trying to calibrate an electron, but disabled");
111  return StatusCode::FAILURE;
112  }
113  } else if (xAOD::EgammaHelpers::isPhoton(&eg)) {
114  const xAOD::Photon* ph = static_cast<const xAOD::Photon*>(&eg);
115  const bool is_conv_calib = isConvCalib(*ph);
116  if (is_conv_calib) {
117  if (!m_mvaConvertedPhoton.empty()) {
118  mvaE = m_mvaConvertedPhoton->getEnergy(cluster, &eg);
119  } else {
120  ATH_MSG_FATAL("Trying to calibrate a converted photon, but disabled");
121  return StatusCode::FAILURE;
122  }
123  } else {
124  if (!m_mvaUnconvertedPhoton.empty()) {
125  mvaE = m_mvaUnconvertedPhoton->getEnergy(cluster, &eg);
126  } else {
127  ATH_MSG_FATAL("Trying to calibrate an unconverted photon, but disabled");
128  return StatusCode::FAILURE;
129  }
130  }
131  } else {
132  ATH_MSG_FATAL("Egamma object is of unsupported type");
133  return StatusCode::FAILURE;
134  }
135 
136  ATH_MSG_DEBUG( "Calculated MVA calibrated energy = " << mvaE );
137  return StatusCode::SUCCESS;
138 }
139 
142  double& mvaE) const
143 {
144 
145  ATH_MSG_DEBUG("calling egammaMVASvc::getEnergy with cluster and egType (" << egType <<")");
146 
147  mvaE = 0.0;
148  switch (egType) {
150  if (!m_mvaElectron.empty()) {
151  mvaE = m_mvaElectron->getEnergy(cluster,nullptr);
152  } else {
153  ATH_MSG_FATAL("Trying to calibrate an electron, but disabled");
154  return StatusCode::FAILURE;
155  }
156  break;
159  // treat converted photons like unconverted photons since don't have access to vertex
160  if (!m_mvaUnconvertedPhoton.empty()) {
161  mvaE = m_mvaUnconvertedPhoton->getEnergy(cluster,nullptr);
162  } else {
163  ATH_MSG_FATAL("Trying to calibrate an unconverted photon, but disabled");
164  return StatusCode::FAILURE;
165  }
166  break;
167  default:
168  ATH_MSG_FATAL("Egamma object is of unsupported type");
169  return StatusCode::FAILURE;
170  }
171 
172  ATH_MSG_DEBUG( "Calculated MVA calibrated energy = " << mvaE );
173  return StatusCode::SUCCESS;
174 }
175 
176 
178  const xAOD::Egamma& eg) const
179 {
180  double mvaE = 0.;
181 
182  ATH_CHECK(getEnergy(cluster, eg, mvaE));
183 
184  if (mvaE > eg.m()) {
185  cluster.setCalE(mvaE);
186  }
187  else {
188  ATH_MSG_DEBUG("MVA energy (" << mvaE << ") < particle mass ("
189  << eg.m() << "), setting e = cluster energy (" << cluster.e() << ")");
190  cluster.setCalE(cluster.e());
191  }
192  return StatusCode::SUCCESS;
193 }
194 
196  const xAOD::EgammaParameters::EgammaType egType) const
197 {
198 
199  double mvaE = 0.;
200 
201  ATH_CHECK(getEnergy(cluster, egType, mvaE));
202 
203  if (mvaE > 0) {
204  cluster.setCalE(mvaE);
205  }
206  else {
207  ATH_MSG_DEBUG("MVA energy (" << mvaE << ") < 0, setting e = cluster energy ("
208  << cluster.e() << ")");
209  cluster.setCalE(cluster.e());
210  }
211  return StatusCode::SUCCESS;
212 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
egammaMVASvc::initialize
virtual StatusCode initialize() override
Definition: egammaMVASvc.cxx:18
egammaMVASvc::m_folder
Gaudi::Property< std::string > m_folder
Definition: egammaMVASvc.h:80
egammaMVASvc::m_removeTRTConvBarrel
Gaudi::Property< int > m_removeTRTConvBarrel
Definition: egammaMVASvc.h:76
xAOD::EgammaParameters::convertedPhoton
@ convertedPhoton
Definition: EgammaEnums.h:20
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ParticleTest.eg
eg
Definition: ParticleTest.py:29
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
egammaMVASvc::resolve_flags
StatusCode resolve_flags()
Definition: egammaMVASvc.cxx:54
xAOD::EgammaParameters::EgammaType
EgammaType
Definition: EgammaEnums.h:17
Egamma.h
egammaMVASvc::m_maxConvR
Gaudi::Property< float > m_maxConvR
Definition: egammaMVASvc.h:72
egammaMVASvc::m_mvaElectron
ToolHandle< IegammaMVACalibTool > m_mvaElectron
MVA tool for electron.
Definition: egammaMVASvc.h:61
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
EgammaxAODHelpers.h
xAOD::EgammaHelpers::isConvertedPhoton
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
Definition: EgammaxAODHelpers.cxx:25
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloCluster.h
Photon.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:141
egammaMVASvc::getEnergy
StatusCode getEnergy(const xAOD::CaloCluster &cluster, const xAOD::Egamma &eg, double &mvaE) const override final
Compute the calibrated energy.
Definition: egammaMVASvc.cxx:97
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
xAOD::EgammaHelpers::conversionRadius
float conversionRadius(const xAOD::Vertex *vx)
return the conversion radius or 9999.
Definition: PhotonxAODHelpers.cxx:77
egammaMVASvc::isConvCalib
bool isConvCalib(const xAOD::Photon &ph) const
Decide if the photon is converted or not.
Definition: egammaMVASvc.cxx:86
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
egammaMVASvc.h
xAOD::Photon_v1
Definition: Photon_v1.h:37
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
EgammaDefs.h
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
Electron.h
egammaMVASvc::m_mvaUnconvertedPhoton
ToolHandle< IegammaMVACalibTool > m_mvaUnconvertedPhoton
MVA tool for unconverted photon.
Definition: egammaMVASvc.h:65
egammaMVASvc::execute
StatusCode execute(xAOD::CaloCluster &cluster, const xAOD::Egamma &eg) const override final
Main execute.
Definition: egammaMVASvc.cxx:177
egammaMVASvc::m_mvaConvertedPhoton
ToolHandle< IegammaMVACalibTool > m_mvaConvertedPhoton
MVA tool for converted photon.
Definition: egammaMVASvc.h:69
xAOD::EgammaParameters::unconvertedPhoton
@ unconvertedPhoton
Definition: EgammaEnums.h:19