ATLAS Offline Software
Loading...
Searching...
No Matches
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
6
9#include "xAODEgamma/Photon.h"
11
12#include "TFile.h"
13#include "TTree.h"
14
15#include "MVAUtils/BDT.h"
16
17#include <algorithm>
18#include <cmath>
19
20namespace PhotonIDBDT {
21
24
26
29 return StatusCode::SUCCESS;
30}
31
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
44 m_file.reset(TFile::Open(resolved.c_str(), "READ"));
45 if (!m_file || m_file->IsZombie()) {
46 ATH_MSG_ERROR("Failed to open model file: " << resolved);
47 return StatusCode::FAILURE;
48 }
49
50 m_tree = dynamic_cast<TTree*>(m_file->Get(m_bdtTreeName.value().c_str()));
51 if (!m_tree) {
52 ATH_MSG_ERROR("Could not find TTree '" << m_bdtTreeName << "' in file " << resolved);
53 return StatusCode::FAILURE;
54 }
55 m_tree->SetCacheSize(0);
56 m_bdt = std::make_unique<MVAUtils::BDT>(m_tree);
57
58 ATH_MSG_DEBUG("Loaded BDT from " << resolved << " tree=" << m_bdtTreeName);
59 return StatusCode::SUCCESS;
60}
61
62StatusCode PhotonSingleBDTCalculator::computeScore(const std::vector<float>& vars, float& score) const {
63 if (!m_bdt) {
64 ATH_MSG_ERROR("BDT not loaded (nullptr).");
65 return StatusCode::FAILURE;
66 }
67
68 // Classification score
69 score = m_bdt->GetClassification(vars);
70
71 return StatusCode::SUCCESS;
72}
73
74} // namespace PhotonIDBDT
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
static std::string find_calib_file(const std::string &logical_file_name)
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual ~PhotonSingleBDTCalculator() override
StatusCode computeScore(const std::vector< float > &vars, float &score) const
Evaluate the BDT score for a photon.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58