ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
egammaMVASvc Class Reference

#include <egammaMVASvc.h>

Inheritance diagram for egammaMVASvc:
Collaboration diagram for egammaMVASvc:

Public Member Functions

virtual ~egammaMVASvc () override
 
virtual StatusCode initialize () override
 
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. More...
 
StatusCode getEnergy (const xAOD::CaloCluster &cluster, const xAOD::EgammaParameters::EgammaType egType, double &mvaE, const egammaMVACalib::GlobalEventInfo &gei=egammaMVACalib::GlobalEventInfo()) const override final
 Compute the calibrated energy when the full egamma object is not available. More...
 
StatusCode execute (xAOD::CaloCluster &cluster, const xAOD::Egamma &eg, const egammaMVACalib::GlobalEventInfo &gei=egammaMVACalib::GlobalEventInfo()) const override final
 Main execute. More...
 
StatusCode execute (xAOD::CaloCluster &cluster, const xAOD::EgammaParameters::EgammaType egType, const egammaMVACalib::GlobalEventInfo &gei=egammaMVACalib::GlobalEventInfo()) const override final
 Calibrate the cluster, when the full egamma object is not available. More...
 

Private Member Functions

bool isConvCalib (const xAOD::Photon &ph) const
 Decide if the photon is converted or not. More...
 
StatusCode resolve_flags ()
 

Private Attributes

ToolHandle< IegammaMVACalibToolm_mvaElectron
 MVA tool for electron. More...
 
ToolHandle< IegammaMVACalibToolm_mvaFwdElectron
 MVA tool for forward electron. More...
 
ToolHandle< IegammaMVACalibToolm_mvaUnconvertedPhoton
 MVA tool for unconverted photon. More...
 
ToolHandle< IegammaMVACalibToolm_mvaConvertedPhoton
 MVA tool for converted photon. More...
 
Gaudi::Property< float > m_maxConvR
 
Gaudi::Property< int > m_removeTRTConvBarrel
 
Gaudi::Property< std::string > m_folder
 

Detailed Description

Definition at line 23 of file egammaMVASvc.h.

Constructor & Destructor Documentation

◆ ~egammaMVASvc()

virtual egammaMVASvc::~egammaMVASvc ( )
inlineoverridevirtual

Definition at line 28 of file egammaMVASvc.h.

28 {};

Member Function Documentation

◆ execute() [1/2]

StatusCode egammaMVASvc::execute ( xAOD::CaloCluster cluster,
const xAOD::Egamma eg,
const egammaMVACalib::GlobalEventInfo gei = egammaMVACalib::GlobalEventInfo() 
) const
finaloverride

Main execute.

We need to calibrate the cluster. Use full egamma object instead of Type As we employ further variables than the ones present in the cluster This method needs to be valid also for reconstruction

Definition at line 202 of file egammaMVASvc.cxx.

205 {
206  double mvaE = 0.;
207 
208  ATH_CHECK(getEnergy(cluster, eg, mvaE, gei));
209 
210  if (mvaE > eg.m()) {
211  cluster.setCalE(mvaE);
212  }
213  else {
214  ATH_MSG_DEBUG("MVA energy (" << mvaE << ") < particle mass ("
215  << eg.m() << "), setting e = cluster energy (" << cluster.e() << ")");
216  cluster.setCalE(cluster.e());
217  }
218  return StatusCode::SUCCESS;
219 }

◆ execute() [2/2]

StatusCode egammaMVASvc::execute ( xAOD::CaloCluster cluster,
const xAOD::EgammaParameters::EgammaType  egType,
const egammaMVACalib::GlobalEventInfo gei = egammaMVACalib::GlobalEventInfo() 
) const
finaloverride

Calibrate the cluster, when the full egamma object is not available.

Only variables related to the cluster are used (e.g. no conversion are used here) If the full egamma object use the other version.

Definition at line 221 of file egammaMVASvc.cxx.

224 {
225 
226  double mvaE = 0.;
227 
228  ATH_CHECK(getEnergy(cluster, egType, mvaE, gei));
229 
230  if (mvaE > 0) {
231  cluster.setCalE(mvaE);
232  }
233  else {
234  ATH_MSG_DEBUG("MVA energy (" << mvaE << ") < 0, setting e = cluster energy ("
235  << cluster.e() << ")");
236  cluster.setCalE(cluster.e());
237  }
238  return StatusCode::SUCCESS;
239 }

◆ getEnergy() [1/2]

StatusCode egammaMVASvc::getEnergy ( const xAOD::CaloCluster cluster,
const xAOD::Egamma eg,
double &  mvaE,
const egammaMVACalib::GlobalEventInfo gei = egammaMVACalib::GlobalEventInfo() 
) const
finaloverride

Compute the calibrated energy.

Definition at line 105 of file egammaMVASvc.cxx.

109 {
110 
111  ATH_MSG_DEBUG("calling egammaMVASvc::getEnergy with cluster and eg");
112 
113  mvaE = 0.;
114 
116  if (!m_mvaElectron.empty()) {
117  mvaE = m_mvaElectron->getEnergy(cluster, &eg, gei);
118  } else {
119  ATH_MSG_FATAL("Trying to calibrate an electron, but disabled");
120  return StatusCode::FAILURE;
121  }
122  } else if (xAOD::EgammaHelpers::isFwdElectron(&eg)) {
123  if (!m_mvaFwdElectron.empty()) {
124  mvaE = m_mvaFwdElectron->getEnergy(cluster, &eg, gei);
125  } else {
126  ATH_MSG_FATAL("Trying to calibrate a forward electron, but disabled");
127  return StatusCode::FAILURE;
128  }
129  } else if (xAOD::EgammaHelpers::isPhoton(&eg)) {
130  const xAOD::Photon* ph = static_cast<const xAOD::Photon*>(&eg);
131  const bool is_conv_calib = isConvCalib(*ph);
132  if (is_conv_calib) {
133  if (!m_mvaConvertedPhoton.empty()) {
134  mvaE = m_mvaConvertedPhoton->getEnergy(cluster, &eg, gei);
135  } else {
136  ATH_MSG_FATAL("Trying to calibrate a converted photon, but disabled");
137  return StatusCode::FAILURE;
138  }
139  } else {
140  if (!m_mvaUnconvertedPhoton.empty()) {
141  mvaE = m_mvaUnconvertedPhoton->getEnergy(cluster, &eg, gei);
142  } else {
143  ATH_MSG_FATAL("Trying to calibrate an unconverted photon, but disabled");
144  return StatusCode::FAILURE;
145  }
146  }
147  } else {
148  ATH_MSG_FATAL("Egamma object is of unsupported type");
149  return StatusCode::FAILURE;
150  }
151 
152  ATH_MSG_DEBUG( "Calculated MVA calibrated energy = " << mvaE );
153  return StatusCode::SUCCESS;
154 }

◆ getEnergy() [2/2]

StatusCode egammaMVASvc::getEnergy ( const xAOD::CaloCluster cluster,
const xAOD::EgammaParameters::EgammaType  egType,
double &  mvaE,
const egammaMVACalib::GlobalEventInfo gei = egammaMVACalib::GlobalEventInfo() 
) const
finaloverride

Compute the calibrated energy when the full egamma object is not available.

Definition at line 156 of file egammaMVASvc.cxx.

160 {
161 
162  ATH_MSG_DEBUG("calling egammaMVASvc::getEnergy with cluster and egType (" << egType <<")");
163 
164  mvaE = 0.0;
165  switch (egType) {
167  if (!m_mvaElectron.empty()) {
168  mvaE = m_mvaElectron->getEnergy(cluster,nullptr, gei);
169  } else {
170  ATH_MSG_FATAL("Trying to calibrate an electron, but disabled");
171  return StatusCode::FAILURE;
172  }
173  break;
175  if (!m_mvaFwdElectron.empty()) {
176  mvaE = m_mvaFwdElectron->getEnergy(cluster,nullptr, gei);
177  } else {
178  ATH_MSG_FATAL("Trying to calibrate a forward electron, but disabled");
179  return StatusCode::FAILURE;
180  }
181  break;
184  // treat converted photons like unconverted photons since don't have access to vertex
185  if (!m_mvaUnconvertedPhoton.empty()) {
186  mvaE = m_mvaUnconvertedPhoton->getEnergy(cluster,nullptr, gei);
187  } else {
188  ATH_MSG_FATAL("Trying to calibrate an unconverted photon, but disabled");
189  return StatusCode::FAILURE;
190  }
191  break;
192  default:
193  ATH_MSG_FATAL("Egamma object " << egType << " is of unsupported type");
194  return StatusCode::FAILURE;
195  }
196 
197  ATH_MSG_DEBUG( "Calculated MVA calibrated energy = " << mvaE );
198  return StatusCode::SUCCESS;
199 }

◆ initialize()

StatusCode egammaMVASvc::initialize ( )
overridevirtual

Definition at line 18 of file egammaMVASvc.cxx.

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");
48  ATH_CHECK(m_mvaConvertedPhoton.retrieve());
49  } else {
50  ATH_MSG_DEBUG("Disabling mvaConvertedPhoton");
51  m_mvaConvertedPhoton.disable();
52  }
53 
55 
58 
59  return StatusCode::SUCCESS;
60 }

◆ isConvCalib()

bool egammaMVASvc::isConvCalib ( const xAOD::Photon ph) const
private

Decide if the photon is converted or not.

Definition at line 94 of file egammaMVASvc.cxx.

95 {
99  // special case in Run3 to avoid TRT converted photons in the barrel
101  }
102  return isConvCalib;
103 }

◆ resolve_flags()

StatusCode egammaMVASvc::resolve_flags ( )
private

Definition at line 62 of file egammaMVASvc.cxx.

63 {
64  if (m_removeTRTConvBarrel == -1) {
65  const bool removeTRTConvBarrelDefault = false;
66  if (!m_mvaConvertedPhoton.empty() and !m_folder.empty()) {
67  const std::string mva_filename = PathResolverFindCalibFile(m_folder + "/MVACalib_convertedPhoton.weights.root");
68  std::unique_ptr<TFile> f(TFile::Open(mva_filename.c_str()));
69  if (!f || f->IsZombie()) {
70  ATH_MSG_ERROR("Could not open file: " << mva_filename);
71  m_removeTRTConvBarrel = removeTRTConvBarrelDefault;
72  }
73  else { // we have the MVA for converted photons
74  TObjString* conversionDefinitionObj = nullptr;
75  f->GetObject("conversionDefinition", conversionDefinitionObj);
76  if (conversionDefinitionObj) {
77  m_removeTRTConvBarrel = (conversionDefinitionObj->GetString() == "removeTRTConvBarrel");
78  } else {
79  // the conversion definition is not encoded in the file, this is true for the old ones
80  m_removeTRTConvBarrel = removeTRTConvBarrelDefault;
81  }
82  }
83  } else { // we are running without converted
84  m_removeTRTConvBarrel = removeTRTConvBarrelDefault;
85  }
86  }
87  if (m_removeTRTConvBarrel == -1) {
88  ATH_MSG_ERROR("Could not determine if TRT converted photons should be removed in the barrel");
89  return StatusCode::FAILURE;
90  }
91  return StatusCode::SUCCESS;
92 }

Member Data Documentation

◆ m_folder

Gaudi::Property<std::string> egammaMVASvc::m_folder
private
Initial value:
{this,
"folder", "", "folder for weight files"}

Definition at line 88 of file egammaMVASvc.h.

◆ m_maxConvR

Gaudi::Property<float> egammaMVASvc::m_maxConvR
private
Initial value:
{this,
"MaxConvRadius", 800.0,
"The maximum conversion radius for a photon to be considered converted"}

Definition at line 80 of file egammaMVASvc.h.

◆ m_mvaConvertedPhoton

ToolHandle<IegammaMVACalibTool> egammaMVASvc::m_mvaConvertedPhoton
private
Initial value:
{this,
"ConvertedPhotonTool", "", "Tool to handle MVA trees for converted photons"}

MVA tool for converted photon.

Definition at line 77 of file egammaMVASvc.h.

◆ m_mvaElectron

ToolHandle<IegammaMVACalibTool> egammaMVASvc::m_mvaElectron
private
Initial value:
{this,
"ElectronTool", "", "Tool to handle MVA trees for electrons"}

MVA tool for electron.

Definition at line 65 of file egammaMVASvc.h.

◆ m_mvaFwdElectron

ToolHandle<IegammaMVACalibTool> egammaMVASvc::m_mvaFwdElectron
private
Initial value:
{this,
"FwdElectronTool", "", "Tool to handle MVA trees for forward electrons"}

MVA tool for forward electron.

Definition at line 69 of file egammaMVASvc.h.

◆ m_mvaUnconvertedPhoton

ToolHandle<IegammaMVACalibTool> egammaMVASvc::m_mvaUnconvertedPhoton
private
Initial value:
{this,
"UnconvertedPhotonTool", "", "Tool to handle MVA trees for unconverted photons"}

MVA tool for unconverted photon.

Definition at line 73 of file egammaMVASvc.h.

◆ m_removeTRTConvBarrel

Gaudi::Property<int> egammaMVASvc::m_removeTRTConvBarrel
private
Initial value:
{this,
"RemoveTRTConvBarrel", -1,
"Remove TRT converted photons in the barrel: no=0, yes=1, automatic=-1"}

Definition at line 84 of file egammaMVASvc.h.


The documentation for this class was generated from the following files:
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
egammaMVASvc::m_folder
Gaudi::Property< std::string > m_folder
Definition: egammaMVASvc.h:88
egammaMVASvc::m_removeTRTConvBarrel
Gaudi::Property< int > m_removeTRTConvBarrel
Definition: egammaMVASvc.h:84
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
egammaMVASvc::getEnergy
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.
Definition: egammaMVASvc.cxx:105
egammaMVASvc::m_mvaFwdElectron
ToolHandle< IegammaMVACalibTool > m_mvaFwdElectron
MVA tool for forward electron.
Definition: egammaMVASvc.h:69
egammaMVASvc::resolve_flags
StatusCode resolve_flags()
Definition: egammaMVASvc.cxx:62
egammaMVASvc::m_maxConvR
Gaudi::Property< float > m_maxConvR
Definition: egammaMVASvc.h:80
egammaMVASvc::m_mvaElectron
ToolHandle< IegammaMVACalibTool > m_mvaElectron
MVA tool for electron.
Definition: egammaMVASvc.h:65
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
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:140
xAOD::EgammaHelpers::isFwdElectron
bool isFwdElectron(const xAOD::Egamma *eg)
is the object a Fwd electron
Definition: EgammaxAODHelpers.cxx:17
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:58
xAOD::CaloCluster_v1::setCalE
void setCalE(flt_t)
Set Energy for signal state CALIBRATED.
Definition: CaloCluster_v1.cxx:306
egammaMVASvc::isConvCalib
bool isConvCalib(const xAOD::Photon &ph) const
Decide if the photon is converted or not.
Definition: egammaMVASvc.cxx:94
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:325
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
xAOD::EgammaParameters::forwardelectron
@ forwardelectron
Definition: EgammaEnums.h:21
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
egammaMVASvc::m_mvaUnconvertedPhoton
ToolHandle< IegammaMVACalibTool > m_mvaUnconvertedPhoton
MVA tool for unconverted photon.
Definition: egammaMVASvc.h:73
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:77
xAOD::EgammaParameters::unconvertedPhoton
@ unconvertedPhoton
Definition: EgammaEnums.h:19