ATLAS Offline Software
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 
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 
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 
46 float 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.;
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 }
xAOD::PFODetails::cellBased_NPosECells_EM1
@ cellBased_NPosECells_EM1
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:134
TauPi0ScoreCalculator::m_mvaBDT
std::unique_ptr< tauRecTools::BDTHelper > m_mvaBDT
Definition: TauPi0ScoreCalculator.h:44
xAOD::PFODetails::cellBased_SECOND_R
@ cellBased_SECOND_R
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:119
xAOD::TauJet_v3::nProtoNeutralPFOs
size_t nProtoNeutralPFOs() const
Get the number of cellbased_neutral PFO particles associated with this tau.
Definition: TauJet_v3.cxx:904
TauPi0ScoreCalculator::m_weightfile
Gaudi::Property< std::string > m_weightfile
Definition: TauPi0ScoreCalculator.h:39
xAOD::PFO_v1::attribute
bool attribute(PFODetails::PFOAttributes AttributeType, T &anAttribute) const
get a PFO Variable via enum
TauRecToolBase
The base class for all tau tools.
Definition: TauRecToolBase.h:21
xAOD::PFODetails::cellBased_DELTA_THETA
@ cellBased_DELTA_THETA
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:122
xAOD::PFODetails::cellBased_firstEtaWRTClusterPosition_EM1
@ cellBased_firstEtaWRTClusterPosition_EM1
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:136
PFO.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::PFODetails::cellBased_secondEtaWRTClusterPosition_EM2
@ cellBased_secondEtaWRTClusterPosition_EM2
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:139
tauRecTools::doPi0andShots
bool doPi0andShots(const xAOD::TauJet &tau)
Determines whether pi0s and shots should be built for a tau candidate.
Definition: Reconstruction/tauRecTools/Root/HelperFunctions.cxx:93
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TauPi0ScoreCalculator::calculateScore
float calculateScore(const xAOD::PFO *neutralPFO) const
Calculate pi0 BDT score.
Definition: TauPi0ScoreCalculator.cxx:46
xAOD::PFODetails::cellBased_FIRST_ETA
@ cellBased_FIRST_ETA
These variables belong to the cell-based particle flow algorithm.
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:118
xAOD::PFO_v1::setBDTPi0Score
void setBDTPi0Score(float BDTPi0Score)
set BDT Score used to classify clusters as Pi0 like or not
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::PFO_v1
Class describing a particle flow object.
Definition: PFO_v1.h:35
TauPi0ScoreCalculator.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TauPi0ScoreCalculator::initialize
virtual StatusCode initialize() override
Tool initializer.
Definition: TauPi0ScoreCalculator.cxx:17
TauRecToolBase::find_file
std::string find_file(const std::string &fname) const
Definition: TauRecToolBase.cxx:19
TauGNNUtils::Variables::Cluster::SECOND_R
bool SECOND_R(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:841
xAOD::PFODetails::cellBased_ENG_FRAC_CORE
@ cellBased_ENG_FRAC_CORE
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:128
xAOD::PFODetails::cellBased_EM1CoreFrac
@ cellBased_EM1CoreFrac
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:130
TauPi0ScoreCalculator::TauPi0ScoreCalculator
TauPi0ScoreCalculator(const std::string &name)
Definition: TauPi0ScoreCalculator.cxx:11
xAOD::score
@ score
Definition: TrackingPrimitives.h:514
xAOD::PFODetails::cellBased_SECOND_ENG_DENS
@ cellBased_SECOND_ENG_DENS
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:129
xAOD::PFODetails::cellBased_NPosECells_EM2
@ cellBased_NPosECells_EM2
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:135
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::PFODetails::cellBased_CENTER_LAMBDA
@ cellBased_CENTER_LAMBDA
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:123
xAOD::PFODetails::cellBased_LONGITUDINAL
@ cellBased_LONGITUDINAL
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:125
HelperFunctions.h
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TauPi0ScoreCalculator::executePi0nPFO
virtual StatusCode executePi0nPFO(xAOD::TauJet &pTau, xAOD::PFOContainer &pNeutralPFOContainer) const override
Definition: TauPi0ScoreCalculator.cxx:28
xAOD::PFODetails::cellBased_ENG_FRAC_EM
@ cellBased_ENG_FRAC_EM
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:126
xAOD::TauJet_v3::protoNeutralPFO
const PFO * protoNeutralPFO(size_t i) const
Get the pointer to a given cellbased_neutral PFO associated with this tau.
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.