ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
ElectronPhotonID
ElectronPhotonSelectorTools
Root
PhotonSingleBDTCalculator.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
ElectronPhotonSelectorTools/PhotonSingleBDTCalculator.h
"
6
7
#include "
PathResolver/PathResolver.h
"
8
#include "
xAODEgamma/EgammaDefs.h
"
9
#include "
xAODEgamma/Photon.h
"
10
#include "
xAODCaloEvent/CaloCluster.h
"
11
12
#include "TFile.h"
13
#include "TTree.h"
14
15
#include "
MVAUtils/BDT.h
"
16
17
#include <algorithm>
18
#include <cmath>
19
20
namespace
PhotonIDBDT
{
21
22
PhotonSingleBDTCalculator::PhotonSingleBDTCalculator
(
const
std::string& name)
23
:
asg
::
AsgTool
(name) {}
24
25
PhotonSingleBDTCalculator::~PhotonSingleBDTCalculator
() =
default
;
26
27
StatusCode
PhotonSingleBDTCalculator::initialize
() {
28
ATH_CHECK
(
loadBDT
());
29
return
StatusCode::SUCCESS;
30
}
31
32
StatusCode
PhotonSingleBDTCalculator::loadBDT
() {
33
if
(
m_modelFile
.empty()) {
34
ATH_MSG_ERROR
(
"ModelFile property is empty."
);
35
return
StatusCode::FAILURE;
36
}
37
38
const
std::string resolved =
PathResolver::find_calib_file
(
m_modelFile
);
39
if
(resolved.empty()) {
40
ATH_MSG_ERROR
(
"Could not resolve model file: "
<<
m_modelFile
);
41
return
StatusCode::FAILURE;
42
}
43
std::unique_ptr<TFile>
file
;
44
file
.reset(TFile::Open(resolved.c_str(),
"READ"
));
45
if
(!
file
||
file
->IsZombie()) {
46
ATH_MSG_ERROR
(
"Failed to open model file: "
<< resolved);
47
return
StatusCode::FAILURE;
48
}
49
50
TTree*
tree
=
dynamic_cast<
TTree*
>
(
file
->Get(
m_bdtTreeName
.value().c_str()));
51
if
(!
tree
) {
52
ATH_MSG_ERROR
(
"Could not find TTree '"
<<
m_bdtTreeName
<<
"' in file "
<< resolved);
53
return
StatusCode::FAILURE;
54
}
55
tree
->SetCacheSize(0);
56
m_bdt
= std::make_unique<MVAUtils::BDT>(
tree
);
57
58
ATH_MSG_DEBUG
(
"Loaded BDT from "
<< resolved <<
" tree="
<<
m_bdtTreeName
);
59
// --- MEMORY OPTIMIZATION ---
60
// Close the TFile and cleanly destroy the TTree since MVAUtils has copied the data.
61
file
.reset();
62
return
StatusCode::SUCCESS;
63
}
64
65
StatusCode
PhotonSingleBDTCalculator::computeScore
(
const
std::vector<float>& vars,
float
& score)
const
{
66
if
(!
m_bdt
) {
67
ATH_MSG_ERROR
(
"BDT not loaded (nullptr)."
);
68
return
StatusCode::FAILURE;
69
}
70
71
// Classification score
72
score =
m_bdt
->GetClassification(vars);
73
74
return
StatusCode::SUCCESS;
75
}
76
77
}
// namespace PhotonIDBDT
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
EgammaDefs.h
CaloCluster.h
Photon.h
PathResolver.h
PhotonSingleBDTCalculator.h
BDT.h
PathResolver::find_calib_file
static std::string find_calib_file(const std::string &logical_file_name)
Definition
PathResolver.cxx:272
PhotonIDBDT::PhotonSingleBDTCalculator::m_bdtTreeName
Gaudi::Property< std::string > m_bdtTreeName
Definition
PhotonSingleBDTCalculator.h:64
PhotonIDBDT::PhotonSingleBDTCalculator::loadBDT
StatusCode loadBDT()
Definition
PhotonSingleBDTCalculator.cxx:32
PhotonIDBDT::PhotonSingleBDTCalculator::m_modelFile
Gaudi::Property< std::string > m_modelFile
Definition
PhotonSingleBDTCalculator.h:60
PhotonIDBDT::PhotonSingleBDTCalculator::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition
PhotonSingleBDTCalculator.cxx:27
PhotonIDBDT::PhotonSingleBDTCalculator::~PhotonSingleBDTCalculator
virtual ~PhotonSingleBDTCalculator() override
PhotonIDBDT::PhotonSingleBDTCalculator::computeScore
StatusCode computeScore(const std::vector< float > &vars, float &score) const
Evaluate the BDT score for a photon.
Definition
PhotonSingleBDTCalculator.cxx:65
PhotonIDBDT::PhotonSingleBDTCalculator::m_bdt
std::unique_ptr< MVAUtils::BDT > m_bdt
Definition
PhotonSingleBDTCalculator.h:69
PhotonIDBDT::PhotonSingleBDTCalculator::PhotonSingleBDTCalculator
PhotonSingleBDTCalculator(const std::string &name)
Definition
PhotonSingleBDTCalculator.cxx:22
asg::AsgTool::AsgTool
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition
AsgTool.cxx:58
PhotonIDBDT
Definition
AsgPhotonBDTSelector.h:55
asg
Definition
DataHandleTestTool.h:28
tree
TChain * tree
Definition
tile_monitor.h:30
file
TFile * file
Definition
tile_monitor.h:29
Generated on
for ATLAS Offline Software by
1.17.0