ATLAS Offline Software
Loading...
Searching...
No Matches
TauPi0ScoreCalculator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "xAODPFlow/PFO.h"
8
9
10
12 TauRecToolBase(name) {
13}
14
15
16
18 std::string weightFile = find_file(m_weightfile);
19
20 m_mvaBDT = std::make_unique<tauRecTools::BDTHelper>();
21 ATH_CHECK(m_mvaBDT->initialize(weightFile));
22
23 return StatusCode::SUCCESS;
24}
25
26
27
28StatusCode TauPi0ScoreCalculator::executePi0nPFO(xAOD::TauJet& pTau, xAOD::PFOContainer& neutralPFOContainer) const {
29 // Only run on 0-5 prong taus
30 if (!tauRecTools::doPi0andShots(pTau)) {
31 return StatusCode::SUCCESS;
32 }
33
34 // retrieve neutral PFOs from tau, calculate BDT scores and store them in PFO
35 for(size_t i=0; i<pTau.nProtoNeutralPFOs(); i++) {
36 xAOD::PFO* neutralPFO = neutralPFOContainer.at( pTau.protoNeutralPFO(i)->index() );
37 float BDTScore = calculateScore(neutralPFO);
38 neutralPFO->setBDTPi0Score(BDTScore);
39 }
40
41 return StatusCode::SUCCESS;
42}
43
44
45
46float TauPi0ScoreCalculator::calculateScore(const xAOD::PFO* neutralPFO) const {
47
48 std::map<TString, float> availableVariables;
49
50 float Abs_FIRST_ETA = 0.;
51 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_FIRST_ETA, Abs_FIRST_ETA) == false) {
52 ATH_MSG_WARNING("Can't find FIRST_ETA. Set it to 0.");
53 }
54 Abs_FIRST_ETA = std::abs(Abs_FIRST_ETA);
55 availableVariables.insert(std::make_pair("Pi0Cluster_Abs_FIRST_ETA", Abs_FIRST_ETA));
56
57 float SECOND_R = 0.;
58 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_SECOND_R, SECOND_R) == false) {
59 ATH_MSG_WARNING("Can't find SECOND_R. Set it to 0.");
60 }
61 availableVariables.insert(std::make_pair("Pi0Cluster_SECOND_R", SECOND_R));
62
63 float Abs_DELTA_THETA = 0.;
64 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_DELTA_THETA, Abs_DELTA_THETA) == false) {
65 ATH_MSG_WARNING("Can't find DELTA_THETA. Set it to 0.");
66 }
67 Abs_DELTA_THETA = std::abs(Abs_DELTA_THETA);
68 availableVariables.insert(std::make_pair("Pi0Cluster_Abs_DELTA_THETA", Abs_DELTA_THETA));
69
70 float CENTER_LAMBDA_helped = 0.;
71 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_CENTER_LAMBDA, CENTER_LAMBDA_helped) == false) {
72 ATH_MSG_WARNING("Can't find CENTER_LAMBDA. Set it to 0.");
73 }
74 CENTER_LAMBDA_helped = fmin(CENTER_LAMBDA_helped, 1000.);
75 availableVariables.insert(std::make_pair("Pi0Cluster_CENTER_LAMBDA_helped", CENTER_LAMBDA_helped));
76
77 float LONGITUDINAL = 0.;
78 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_LONGITUDINAL, LONGITUDINAL) == false) {
79 ATH_MSG_WARNING("Can't find LONGITUDINAL. Set it to 0.");
80 }
81 availableVariables.insert(std::make_pair("Pi0Cluster_LONGITUDINAL", LONGITUDINAL));
82
83 float ENG_FRAC_EM = 0.;
84 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_ENG_FRAC_EM, ENG_FRAC_EM) == false) {
85 ATH_MSG_WARNING("Can't find ENG_FRAC_EM. Set it to 0.");
86 }
87 availableVariables.insert(std::make_pair("Pi0Cluster_ENG_FRAC_EM", ENG_FRAC_EM));
88
89 float ENG_FRAC_CORE = 0.;
90 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_ENG_FRAC_CORE, ENG_FRAC_CORE) == false) {
91 ATH_MSG_WARNING("Can't find ENG_FRAC_CORE. Set it to 0.");
92 }
93 availableVariables.insert(std::make_pair("Pi0Cluster_ENG_FRAC_CORE", ENG_FRAC_CORE));
94
95 float log_SECOND_ENG_DENS = 0.;
96 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_SECOND_ENG_DENS, log_SECOND_ENG_DENS) == false) {
97 ATH_MSG_WARNING("Can't find SECOND_ENG_DENS. Set it to 0.");
98 }
99 if(log_SECOND_ENG_DENS==0.) {
100 log_SECOND_ENG_DENS=-50.;
101 }
102 else {
103 log_SECOND_ENG_DENS = log(log_SECOND_ENG_DENS);
104 }
105 availableVariables.insert(std::make_pair("Pi0Cluster_log_SECOND_ENG_DENS", log_SECOND_ENG_DENS));
106
107 float EcoreOverEEM1 = 0.;
108 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_EM1CoreFrac, EcoreOverEEM1) == false) {
109 ATH_MSG_WARNING("Can't find EM1CoreFrac. Set it to 0.");
110 }
111 availableVariables.insert(std::make_pair("Pi0Cluster_EcoreOverEEM1", EcoreOverEEM1));
112
113 int NPosECells_EM1 = 0;
114 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_NPosECells_EM1, NPosECells_EM1) == false) {
115 ATH_MSG_WARNING("Can't find NPosECells_EM1. Set it to 0.");
116 }
117 availableVariables.insert(std::make_pair("Pi0Cluster_NPosECells_EM1", static_cast<float>(NPosECells_EM1)));
118
119 int NPosECells_EM2 = 0;
120 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_NPosECells_EM2, NPosECells_EM2) == false) {
121 ATH_MSG_WARNING("Can't find NPosECells_EM2. Set it to 0.");
122 }
123 availableVariables.insert(std::make_pair("Pi0Cluster_NPosECells_EM2", static_cast<float>(NPosECells_EM2)));
124
125 float AbsFirstEtaWRTClusterPosition_EM1 = 0.;
126 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_firstEtaWRTClusterPosition_EM1, AbsFirstEtaWRTClusterPosition_EM1) == false) {
127 ATH_MSG_WARNING("Can't find firstEtaWRTClusterPosition_EM1. Set it to 0.");
128 }
129 AbsFirstEtaWRTClusterPosition_EM1 = std::abs(AbsFirstEtaWRTClusterPosition_EM1);
130 availableVariables.insert(std::make_pair("Pi0Cluster_AbsFirstEtaWRTClusterPosition_EM1", AbsFirstEtaWRTClusterPosition_EM1));
131
132 float secondEtaWRTClusterPosition_EM2 = 0.;
133 if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_secondEtaWRTClusterPosition_EM2, secondEtaWRTClusterPosition_EM2) == false) {
134 ATH_MSG_WARNING("Can't find secondEtaWRTClusterPosition_EM2. Set it to 0.");
135 }
136 availableVariables.insert(std::make_pair("Pi0Cluster_secondEtaWRTClusterPosition_EM2", secondEtaWRTClusterPosition_EM2));
137
138 // Calculate BDT score, will be -999 when availableVariables lack variables
139 float score = m_mvaBDT->getGradBoostMVA(availableVariables);
140
141 return score;
142}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
const T * at(size_type n) const
Access an element, as an rvalue.
size_t index() const
Return the index of this element within its container.
virtual StatusCode executePi0nPFO(xAOD::TauJet &pTau, xAOD::PFOContainer &pNeutralPFOContainer) const override
std::unique_ptr< tauRecTools::BDTHelper > m_mvaBDT
float calculateScore(const xAOD::PFO *neutralPFO) const
Calculate pi0 BDT score.
virtual StatusCode initialize() override
Tool initializer.
Gaudi::Property< std::string > m_weightfile
TauPi0ScoreCalculator(const std::string &name)
TauRecToolBase(const std::string &name)
std::string find_file(const std::string &fname) const
bool attribute(PFODetails::PFOAttributes AttributeType, T &anAttribute) const
get a PFO Variable via enum
void setBDTPi0Score(float BDTPi0Score)
set BDT Score used to classify clusters as Pi0 like or not
const PFO * protoNeutralPFO(size_t i) const
Get the pointer to a given cellbased_neutral PFO associated with this tau.
size_t nProtoNeutralPFOs() const
Get the number of cellbased_neutral PFO particles associated with this tau.
bool doPi0andShots(const xAOD::TauJet &tau)
Determines whether pi0s and shots should be built for a tau candidate.
PFO_v1 PFO
Definition of the current "pfo version".
Definition PFO.h:17
PFOContainer_v1 PFOContainer
Definition of the current "pfo container version".
TauJet_v3 TauJet
Definition of the current "tau version".