ATLAS Offline Software
TauPi0ScoreCalculator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "xAODPFlow/PFO.h"
8 
9 
10 
13  declareProperty("BDTWeightFile", m_weightfile = "");
14 }
15 
16 
17 
19  std::string weightFile = find_file(m_weightfile);
20 
21  m_mvaBDT = std::make_unique<tauRecTools::BDTHelper>();
22  ATH_CHECK(m_mvaBDT->initialize(weightFile));
23 
24  return StatusCode::SUCCESS;
25 }
26 
27 
28 
30  // Only run on 0-5 prong taus
31  if (!tauRecTools::doPi0andShots(pTau)) {
32  return StatusCode::SUCCESS;
33  }
34 
35  // retrieve neutral PFOs from tau, calculate BDT scores and store them in PFO
36  for(size_t i=0; i<pTau.nProtoNeutralPFOs(); i++) {
37  xAOD::PFO* neutralPFO = neutralPFOContainer.at( pTau.protoNeutralPFO(i)->index() );
38  float BDTScore = calculateScore(neutralPFO);
39  neutralPFO->setBDTPi0Score(BDTScore);
40  }
41 
42  return StatusCode::SUCCESS;
43 }
44 
45 
46 
47 float TauPi0ScoreCalculator::calculateScore(const xAOD::PFO* neutralPFO) const {
48 
49  std::map<TString, float> availableVariables;
50 
51  float Abs_FIRST_ETA = 0.;
52  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_FIRST_ETA, Abs_FIRST_ETA) == false) {
53  ATH_MSG_WARNING("Can't find FIRST_ETA. Set it to 0.");
54  }
55  Abs_FIRST_ETA = std::abs(Abs_FIRST_ETA);
56  availableVariables.insert(std::make_pair("Pi0Cluster_Abs_FIRST_ETA", Abs_FIRST_ETA));
57 
58  float SECOND_R = 0.;
60  ATH_MSG_WARNING("Can't find SECOND_R. Set it to 0.");
61  }
62  availableVariables.insert(std::make_pair("Pi0Cluster_SECOND_R", SECOND_R));
63 
64  float Abs_DELTA_THETA = 0.;
65  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_DELTA_THETA, Abs_DELTA_THETA) == false) {
66  ATH_MSG_WARNING("Can't find DELTA_THETA. Set it to 0.");
67  }
68  Abs_DELTA_THETA = std::abs(Abs_DELTA_THETA);
69  availableVariables.insert(std::make_pair("Pi0Cluster_Abs_DELTA_THETA", Abs_DELTA_THETA));
70 
71  float CENTER_LAMBDA_helped = 0.;
72  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_CENTER_LAMBDA, CENTER_LAMBDA_helped) == false) {
73  ATH_MSG_WARNING("Can't find CENTER_LAMBDA. Set it to 0.");
74  }
75  CENTER_LAMBDA_helped = fmin(CENTER_LAMBDA_helped, 1000.);
76  availableVariables.insert(std::make_pair("Pi0Cluster_CENTER_LAMBDA_helped", CENTER_LAMBDA_helped));
77 
78  float LONGITUDINAL = 0.;
79  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_LONGITUDINAL, LONGITUDINAL) == false) {
80  ATH_MSG_WARNING("Can't find LONGITUDINAL. Set it to 0.");
81  }
82  availableVariables.insert(std::make_pair("Pi0Cluster_LONGITUDINAL", LONGITUDINAL));
83 
84  float ENG_FRAC_EM = 0.;
85  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_ENG_FRAC_EM, ENG_FRAC_EM) == false) {
86  ATH_MSG_WARNING("Can't find ENG_FRAC_EM. Set it to 0.");
87  }
88  availableVariables.insert(std::make_pair("Pi0Cluster_ENG_FRAC_EM", ENG_FRAC_EM));
89 
90  float ENG_FRAC_CORE = 0.;
91  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_ENG_FRAC_CORE, ENG_FRAC_CORE) == false) {
92  ATH_MSG_WARNING("Can't find ENG_FRAC_CORE. Set it to 0.");
93  }
94  availableVariables.insert(std::make_pair("Pi0Cluster_ENG_FRAC_CORE", ENG_FRAC_CORE));
95 
96  float log_SECOND_ENG_DENS = 0.;
97  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_SECOND_ENG_DENS, log_SECOND_ENG_DENS) == false) {
98  ATH_MSG_WARNING("Can't find SECOND_ENG_DENS. Set it to 0.");
99  }
100  if(log_SECOND_ENG_DENS==0.) {
101  log_SECOND_ENG_DENS=-50.;
102  }
103  else {
104  log_SECOND_ENG_DENS = log(log_SECOND_ENG_DENS);
105  }
106  availableVariables.insert(std::make_pair("Pi0Cluster_log_SECOND_ENG_DENS", log_SECOND_ENG_DENS));
107 
108  float EcoreOverEEM1 = 0.;
109  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_EM1CoreFrac, EcoreOverEEM1) == false) {
110  ATH_MSG_WARNING("Can't find EM1CoreFrac. Set it to 0.");
111  }
112  availableVariables.insert(std::make_pair("Pi0Cluster_EcoreOverEEM1", EcoreOverEEM1));
113 
114  int NPosECells_EM1 = 0;
115  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_NPosECells_EM1, NPosECells_EM1) == false) {
116  ATH_MSG_WARNING("Can't find NPosECells_EM1. Set it to 0.");
117  }
118  availableVariables.insert(std::make_pair("Pi0Cluster_NPosECells_EM1", static_cast<float>(NPosECells_EM1)));
119 
120  int NPosECells_EM2 = 0;
121  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_NPosECells_EM2, NPosECells_EM2) == false) {
122  ATH_MSG_WARNING("Can't find NPosECells_EM2. Set it to 0.");
123  }
124  availableVariables.insert(std::make_pair("Pi0Cluster_NPosECells_EM2", static_cast<float>(NPosECells_EM2)));
125 
126  float AbsFirstEtaWRTClusterPosition_EM1 = 0.;
127  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_firstEtaWRTClusterPosition_EM1, AbsFirstEtaWRTClusterPosition_EM1) == false) {
128  ATH_MSG_WARNING("Can't find firstEtaWRTClusterPosition_EM1. Set it to 0.");
129  }
130  AbsFirstEtaWRTClusterPosition_EM1 = std::abs(AbsFirstEtaWRTClusterPosition_EM1);
131  availableVariables.insert(std::make_pair("Pi0Cluster_AbsFirstEtaWRTClusterPosition_EM1", AbsFirstEtaWRTClusterPosition_EM1));
132 
133  float secondEtaWRTClusterPosition_EM2 = 0.;
134  if(neutralPFO->attribute(xAOD::PFODetails::PFOAttributes::cellBased_secondEtaWRTClusterPosition_EM2, secondEtaWRTClusterPosition_EM2) == false) {
135  ATH_MSG_WARNING("Can't find secondEtaWRTClusterPosition_EM2. Set it to 0.");
136  }
137  availableVariables.insert(std::make_pair("Pi0Cluster_secondEtaWRTClusterPosition_EM2", secondEtaWRTClusterPosition_EM2));
138 
139  // Calculate BDT score, will be -999 when availableVariables lack variables
140  float score = m_mvaBDT->getGradBoostMVA(availableVariables);
141 
142  return score;
143 }
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:42
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:944
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
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
TauPi0ScoreCalculator::m_weightfile
std::string m_weightfile
Definition: TauPi0ScoreCalculator.h:41
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:92
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:47
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:581
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:192
TauPi0ScoreCalculator::initialize
virtual StatusCode initialize() override
Tool initializer.
Definition: TauPi0ScoreCalculator.cxx:18
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:821
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:513
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:29
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.