ATLAS Offline Software
Loading...
Searching...
No Matches
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.
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.
StatusCode execute (xAOD::CaloCluster &cluster, const xAOD::Egamma &eg, const egammaMVACalib::GlobalEventInfo &gei=egammaMVACalib::GlobalEventInfo()) const override final
 Main execute.
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.

Private Member Functions

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

Private Attributes

ToolHandle< IegammaMVACalibToolm_mvaElectron
 MVA tool for electron.
ToolHandle< IegammaMVACalibToolm_mvaFwdElectron
 MVA tool for forward electron.
ToolHandle< IegammaMVACalibToolm_mvaUnconvertedPhoton
 MVA tool for unconverted photon.
ToolHandle< IegammaMVACalibToolm_mvaConvertedPhoton
 MVA tool for converted photon.
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
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.
virtual double e() const
The total energy of the particle.
void setCalE(flt_t)
Set Energy for signal state CALIBRATED.

◆ 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}
#define ATH_MSG_FATAL(x)
ToolHandle< IegammaMVACalibTool > m_mvaElectron
MVA tool for electron.
ToolHandle< IegammaMVACalibTool > m_mvaUnconvertedPhoton
MVA tool for unconverted photon.
ToolHandle< IegammaMVACalibTool > m_mvaConvertedPhoton
MVA tool for converted photon.
ToolHandle< IegammaMVACalibTool > m_mvaFwdElectron
MVA tool for forward electron.
bool isConvCalib(const xAOD::Photon &ph) const
Decide if the photon is converted or not.
bool isFwdElectron(const xAOD::Egamma *eg)
is the object a Fwd electron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Photon_v1 Photon
Definition of the current "egamma version".

◆ 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");
49 } else {
50 ATH_MSG_DEBUG("Disabling mvaConvertedPhoton");
51 m_mvaConvertedPhoton.disable();
52 }
53
55
58
59 return StatusCode::SUCCESS;
60}
#define ATH_MSG_INFO(x)
Gaudi::Property< float > m_maxConvR
StatusCode resolve_flags()
Gaudi::Property< int > m_removeTRTConvBarrel

◆ 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}
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.

◆ 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}
#define ATH_MSG_ERROR(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Gaudi::Property< std::string > m_folder

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.

88 {this,
89 "folder", "", "folder for weight files"};

◆ 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.

80 {this,
81 "MaxConvRadius", 800.0,
82 "The maximum conversion radius for a photon to be considered converted"};

◆ 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.

77 {this,
78 "ConvertedPhotonTool", "", "Tool to handle MVA trees for converted photons"};

◆ 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.

65 {this,
66 "ElectronTool", "", "Tool to handle MVA trees for electrons"};

◆ 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.

69 {this,
70 "FwdElectronTool", "", "Tool to handle MVA trees for forward electrons"};

◆ 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.

73 {this,
74 "UnconvertedPhotonTool", "", "Tool to handle MVA trees for unconverted photons"};

◆ 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.

84 {this,
85 "RemoveTRTConvBarrel", -1,
86 "Remove TRT converted photons in the barrel: no=0, yes=1, automatic=-1"};

The documentation for this class was generated from the following files: