ATLAS Offline Software
egammaMVASvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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"
12 
13 
14 egammaMVASvc::egammaMVASvc(const std::string& name, ISvcLocator* svc) :
15  asg::AsgService( name, svc )
16 {
17  declareServiceInterface<IegammaMVASvc>();
18 }
19 
21 {
22  ATH_MSG_DEBUG("In initialize of " << name() << "..." );
23 
24  if (!m_mvaElectron.empty()) {
25  ATH_MSG_DEBUG("Retrieving mvaElectron");
26  ATH_CHECK(m_mvaElectron.retrieve());
27  } else {
28  ATH_MSG_DEBUG("Disabling mvaElectron");
29  m_mvaElectron.disable();
30  }
31 
32  if (!m_mvaUnconvertedPhoton.empty()) {
33  ATH_MSG_DEBUG("Retrieving mvaUnconvertedPhoton");
35  } else {
36  ATH_MSG_DEBUG("Disabling mvaUnconvertedPhoton");
37  m_mvaUnconvertedPhoton.disable();
38  }
39 
40  if (!m_mvaConvertedPhoton.empty()) {
41  ATH_MSG_DEBUG("Retrieving mvaConvertedPhoton");
42  ATH_CHECK(m_mvaConvertedPhoton.retrieve());
43  } else {
44  ATH_MSG_DEBUG("Disabling mvaConvertedPhoton");
45  m_mvaConvertedPhoton.disable();
46  }
47 
48  return StatusCode::SUCCESS;
49 }
50 
52  const xAOD::Egamma& eg,
53  double& mvaE) const
54 {
55 
56  ATH_MSG_DEBUG("calling egammaMVASvc::getEnergy with cluster and eg");
57 
58  mvaE = 0.;
59 
61  if (!m_mvaElectron.empty()) {
62  mvaE = m_mvaElectron->getEnergy(cluster, &eg);
63  } else {
64  ATH_MSG_FATAL("Trying to calibrate an electron, but disabled");
65  return StatusCode::FAILURE;
66  }
67  } else if (xAOD::EgammaHelpers::isPhoton(&eg)) {
68  const xAOD::Photon* ph = static_cast<const xAOD::Photon*>(&eg);
69  bool isConvCalib = xAOD::EgammaHelpers::isConvertedPhoton(ph) &&
72  // special case in Run3 to avoid TRT converted photons in the barrel
75  const bool isTRTConv = (conversionType == singleTRT) || (conversionType == doubleTRT); // 2 or 4
76  const bool isTRTEndcap = std::abs(ph->eta()) > 0.8;
77  isConvCalib = isConvCalib && (isTRTEndcap || !isTRTConv);
78  }
79  if (isConvCalib) {
80  if (!m_mvaConvertedPhoton.empty()) {
81  mvaE = m_mvaConvertedPhoton->getEnergy(cluster, &eg);
82  } else {
83  ATH_MSG_FATAL("Trying to calibrate a converted photon, but disabled");
84  return StatusCode::FAILURE;
85  }
86  } else {
87  if (!m_mvaUnconvertedPhoton.empty()) {
88  mvaE = m_mvaUnconvertedPhoton->getEnergy(cluster, &eg);
89  } else {
90  ATH_MSG_FATAL("Trying to calibrate an unconverted photon, but disabled");
91  return StatusCode::FAILURE;
92  }
93  }
94  } else {
95  ATH_MSG_FATAL("Egamma object is of unsupported type");
96  return StatusCode::FAILURE;
97  }
98 
99  ATH_MSG_DEBUG( "Calculated MVA calibrated energy = " << mvaE );
100  return StatusCode::SUCCESS;
101 }
102 
105  double& mvaE) const
106 {
107 
108  ATH_MSG_DEBUG("calling egammaMVASvc::getEnergy with cluster and egType (" << egType <<")");
109 
110  mvaE = 0.0;
111  switch (egType) {
113  if (!m_mvaElectron.empty()) {
114  mvaE = m_mvaElectron->getEnergy(cluster,nullptr);
115  } else {
116  ATH_MSG_FATAL("Trying to calibrate an electron, but disabled");
117  return StatusCode::FAILURE;
118  }
119  break;
122  // treat converted photons like unconverted photons since don't have access to vertex
123  if (!m_mvaUnconvertedPhoton.empty()) {
124  mvaE = m_mvaUnconvertedPhoton->getEnergy(cluster,nullptr);
125  } else {
126  ATH_MSG_FATAL("Trying to calibrate an unconverted photon, but disabled");
127  return StatusCode::FAILURE;
128  }
129  break;
130  default:
131  ATH_MSG_FATAL("Egamma object is of unsupported type");
132  return StatusCode::FAILURE;
133  }
134 
135  ATH_MSG_DEBUG( "Calculated MVA calibrated energy = " << mvaE );
136  return StatusCode::SUCCESS;
137 }
138 
139 
141  const xAOD::Egamma& eg) const
142 {
143  double mvaE = 0.;
144 
145  ATH_CHECK(getEnergy(cluster, eg, mvaE));
146 
147  if (mvaE > eg.m()) {
148  cluster.setCalE(mvaE);
149  }
150  else {
151  ATH_MSG_DEBUG("MVA energy (" << mvaE << ") < particle mass ("
152  << eg.m() << "), setting e = cluster energy (" << cluster.e() << ")");
153  cluster.setCalE(cluster.e());
154  }
155  return StatusCode::SUCCESS;
156 }
157 
159  const xAOD::EgammaParameters::EgammaType egType) const
160 {
161 
162  double mvaE = 0.;
163 
164  ATH_CHECK(getEnergy(cluster, egType, mvaE));
165 
166  if (mvaE > 0) {
167  cluster.setCalE(mvaE);
168  }
169  else {
170  ATH_MSG_DEBUG("MVA energy (" << mvaE << ") < 0, setting e = cluster energy ("
171  << cluster.e() << ")");
172  cluster.setCalE(cluster.e());
173  }
174  return StatusCode::SUCCESS;
175 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
egammaMVASvc::initialize
virtual StatusCode initialize() override
set up/tear down functions
Definition: egammaMVASvc.cxx:20
xAOD::EgammaParameters::convertedPhoton
@ convertedPhoton
Definition: EgammaEnums.h:20
ParticleTest.eg
eg
Definition: ParticleTest.py:29
asg
Definition: DataHandleTestTool.h:28
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
xAOD::EgammaParameters::ConversionType
ConversionType
Definition: EgammaEnums.h:268
xAOD::EgammaParameters::EgammaType
EgammaType
Definition: EgammaEnums.h:17
Egamma.h
egammaMVASvc::m_maxConvR
Gaudi::Property< float > m_maxConvR
Definition: egammaMVASvc.h:67
egammaMVASvc::m_mvaElectron
ToolHandle< IegammaMVACalibTool > m_mvaElectron
MVA tool for electron.
Definition: egammaMVASvc.h:56
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
EgammaxAODHelpers.h
xAOD::EgammaHelpers::isConvertedPhoton
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
Definition: EgammaxAODHelpers.cxx:26
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:13
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
xAOD::EgammaParameters::singleTRT
@ singleTRT
one track only, no Si hits (TRT only)
Definition: EgammaEnums.h:276
egammaMVASvc::getEnergy
StatusCode getEnergy(const xAOD::CaloCluster &cluster, const xAOD::Egamma &eg, double &mvaE) const override final
Compute the calibrated energy.
Definition: egammaMVASvc.cxx:51
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::EgammaHelpers::conversionRadius
float conversionRadius(const xAOD::Vertex *vx)
return the conversion radius or 9999.
Definition: PhotonxAODHelpers.cxx:76
xAOD::CaloCluster_v1::setCalE
void setCalE(flt_t)
Set Energy for signal state CALIBRATED.
Definition: CaloCluster_v1.cxx:306
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:22
egammaMVASvc::egammaMVASvc
egammaMVASvc(const std::string &name, ISvcLocator *svc)
Definition: egammaMVASvc.cxx:14
EgammaDefs.h
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
xAOD::EgammaHelpers::conversionType
xAOD::EgammaParameters::ConversionType conversionType(const xAOD::Photon *ph)
return the photon conversion type (see EgammaEnums)
Definition: PhotonxAODHelpers.cxx:26
xAOD::Egamma_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: Egamma_v1.cxx:70
xAOD::EgammaParameters::doubleTRT
@ doubleTRT
two tracks, none with Si hits (TRT only)
Definition: EgammaEnums.h:282
Electron.h
egammaMVASvc::m_removeTRTConvBarrel
Gaudi::Property< bool > m_removeTRTConvBarrel
Definition: egammaMVASvc.h:71
egammaMVASvc::m_mvaUnconvertedPhoton
ToolHandle< IegammaMVACalibTool > m_mvaUnconvertedPhoton
MVA tool for unconverted photon.
Definition: egammaMVASvc.h:60
egammaMVASvc::execute
StatusCode execute(xAOD::CaloCluster &cluster, const xAOD::Egamma &eg) const override final
Main execute.
Definition: egammaMVASvc.cxx:140
xAOD::CaloCluster_v1::e
virtual double e() const
The total energy of the particle.
Definition: CaloCluster_v1.cxx:265
egammaMVASvc::m_mvaConvertedPhoton
ToolHandle< IegammaMVACalibTool > m_mvaConvertedPhoton
MVA tool for converted photon.
Definition: egammaMVASvc.h:64
xAOD::EgammaParameters::unconvertedPhoton
@ unconvertedPhoton
Definition: EgammaEnums.h:19