ATLAS Offline Software
MvaTESEvaluator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // local include(s)
8 
9 
11  : TauRecToolBase(name) {
12  declareProperty("WeightFileName", m_sWeightFileName = "");
13  declareProperty("WeightFileName0p", m_sWeightFileName0p = "");
14 }
15 
16 
18 
19  const std::string weightFile = find_file(m_sWeightFileName);
20  m_bdtHelper = std::make_unique<tauRecTools::BDTHelper>();
21  ATH_CHECK(m_bdtHelper->initialize(weightFile));
22 
23  if (!m_sWeightFileName0p.empty()) {
24  const std::string weightFile0p = find_file(m_sWeightFileName0p);
25  m_bdtHelper0p = std::make_unique<tauRecTools::BDTHelper>();
26  ATH_CHECK(m_bdtHelper0p->initialize(weightFile0p));
27  }
28 
29  return StatusCode::SUCCESS;
30 }
31 
32 
34 
35  std::map<TString, float*> availableVars;
36  MvaInputVariables vars;
37 
38  // Declare input variables to the reader
39  if (!inTrigger()) {
40  availableVars.insert( std::make_pair("TauJetsAuxDyn.mu", &vars.mu) );
41  availableVars.insert( std::make_pair("TauJetsAuxDyn.nVtxPU", &vars.nVtxPU) );
42  availableVars.insert( std::make_pair("TauJetsAuxDyn.rho", &vars.rho) );
43  availableVars.insert( std::make_pair("TauJetsAuxDyn.ClustersMeanCenterLambda", &vars.center_lambda) );
44  availableVars.insert( std::make_pair("TauJetsAuxDyn.ClustersMeanFirstEngDens", &vars.first_eng_dens) );
45  availableVars.insert( std::make_pair("TauJetsAuxDyn.ClustersMeanSecondLambda", &vars.second_lambda) );
46  availableVars.insert( std::make_pair("TauJetsAuxDyn.ClustersMeanPresamplerFrac", &vars.presampler_frac) );
47  availableVars.insert( std::make_pair("TauJetsAuxDyn.ClustersMeanEMProbability", &vars.eprobability) );
48  availableVars.insert( std::make_pair("TauJetsAuxDyn.ptIntermediateAxisEM/TauJetsAuxDyn.ptIntermediateAxis", &vars.ptEM_D_ptLC) );
49  availableVars.insert( std::make_pair("TauJetsAuxDyn.ptIntermediateAxis/TauJetsAuxDyn.ptCombined", &vars.ptLC_D_ptCombined) );
50  availableVars.insert( std::make_pair("TauJetsAuxDyn.etaPanTauCellBased", &vars.etaConstituent) );
51  if (m_bdtHelper0p && xTau.nTracks()==0) {
52  availableVars.insert( std::make_pair("log(TauJetsAuxDyn.ptCombined)", &vars.logPtCombined) );
53  availableVars.insert( std::make_pair("TauJetsAuxDyn.LeadClusterFrac", &vars.lead_cluster_frac) );
54  availableVars.insert( std::make_pair("TauJetsAuxDyn.centFrac", &vars.centFrac) );
55  availableVars.insert( std::make_pair("TauJetsAuxDyn.UpsilonCluster", &vars.upsilon_cluster) );
56  availableVars.insert( std::make_pair("TauJetsAuxDyn.ptJetSeed/TauJetsAuxDyn.ptCombined", &vars.ptSeed_D_ptCombined) );
57  }
58  else {
59  availableVars.insert( std::make_pair("TauJetsAuxDyn.ptPanTauCellBased/TauJetsAuxDyn.ptCombined", &vars.ptConstituent_D_ptCombined) );
60  availableVars.insert( std::make_pair("TauJetsAuxDyn.ptCombined", &vars.ptCombined) );
61  availableVars.insert( std::make_pair("TauJetsAuxDyn.PanTau_BDTValue_1p0n_vs_1p1n", &vars.PanTauBDT_1p0n_vs_1p1n) );
62  availableVars.insert( std::make_pair("TauJetsAuxDyn.PanTau_BDTValue_1p1n_vs_1pXn", &vars.PanTauBDT_1p1n_vs_1pXn) );
63  availableVars.insert( std::make_pair("TauJetsAuxDyn.PanTau_BDTValue_3p0n_vs_3pXn", &vars.PanTauBDT_3p0n_vs_3pXn) );
64  availableVars.insert( std::make_pair("TauJetsAuxDyn.nTracks", &vars.nTracks) );
65  availableVars.insert( std::make_pair("TauJetsAuxDyn.PFOEngRelDiff", &vars.PFOEngRelDiff) );
66  }
67  }
68  else {
69  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.mu", &vars.mu) );
70  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.ClustersMeanCenterLambda", &vars.center_lambda) );
71  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.ClustersMeanFirstEngDens", &vars.first_eng_dens) );
72  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.ClustersMeanSecondLambda", &vars.second_lambda) );
73  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.ClustersMeanPresamplerFrac", &vars.presampler_frac) );
74  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.ClustersMeanEMProbability", &vars.eprobability) );
75  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.LeadClusterFrac", &vars.lead_cluster_frac) );
76  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.SecondClusterFrac", &vars.second_cluster_frac) );
77  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.ThirdClusterFrac", &vars.third_cluster_frac) );
78  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.UpsilonCluster", &vars.upsilon_cluster) );
79  availableVars.insert( std::make_pair("log(TrigTauJetsAuxDyn.ptDetectorAxis)", &vars.logPtDetectorAxis) );
80  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.etaDetectorAxis", &vars.etaDetectorAxis) );
81  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.ptIntermediateAxisEM/TrigTauJetsAuxDyn.ptDetectorAxis", &vars.ptEM_D_ptLC) );
82  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.ptDetectorAxis/TrigTauJetsAuxDyn.ptJetSeed", &vars.ptDetectorAxis_D_ptJetSeed) );
83  availableVars.insert( std::make_pair("TrigTauJetsAuxDyn.centFrac", &vars.centFrac) );
84  }
85 
86  // Retrieve average pileup
87  static const SG::ConstAccessor<float> acc_mu("mu");
88  vars.mu = acc_mu(xTau);
89 
90  // Retrieve cluster moments
96 
97  static const SG::ConstAccessor<float> acc_ptIntermediateAxisEM("ptIntermediateAxisEM");
98  float ptEM = acc_ptIntermediateAxisEM(xTau);
99 
100  if (!inTrigger()) {
101  static const SG::ConstAccessor<float> acc_ptCombined("ptCombined");
102  float ptCombined = acc_ptCombined(xTau);
103 
104  if (ptCombined==0.) {
106  // apply MVA calibration as default
107  xTau.setP4(1., xTau.etaPanTauCellBased(), xTau.phiPanTauCellBased(), 0.);
108  return StatusCode::SUCCESS;
109  }
110 
111  static const SG::ConstAccessor<int> acc_nVtxPU("nVtxPU");
112  vars.nVtxPU = acc_nVtxPU(xTau);
113 
114  static const SG::ConstAccessor<float> acc_rho("rho");
115  vars.rho = acc_rho(xTau);
116 
117  float ptLC = xTau.ptIntermediateAxis();
118 
119  float ptConstituent = xTau.ptPanTauCellBased();
120  vars.etaConstituent = xTau.etaPanTauCellBased();
121 
122  vars.ptEM_D_ptLC = (ptLC != 0.) ? ptEM / ptLC : 0.;
123  vars.ptLC_D_ptCombined = ptLC / ptCombined;
124 
125  float ptMVA = 0.;
126 
127  if (m_bdtHelper0p && xTau.nTracks()==0) {
128  vars.logPtCombined = std::log(ptCombined);
129  vars.ptSeed_D_ptCombined = xTau.ptJetSeed() / ptCombined;
130 
131  static const SG::ConstAccessor<float> acc_UpsilonCluster("UpsilonCluster");
132  vars.upsilon_cluster = acc_UpsilonCluster(xTau);
133 
134  static const SG::ConstAccessor<float> acc_LeadClusterFrac("LeadClusterFrac");
135  vars.lead_cluster_frac = acc_LeadClusterFrac(xTau);
136 
138 
139  ptMVA = float( ptCombined * m_bdtHelper0p->getResponse(availableVars) );
140  }
141  else {
142  vars.ptCombined = ptCombined;
143  vars.ptConstituent_D_ptCombined = ptConstituent / ptCombined;
144 
145  // Retrieve substructure info
146  static const SG::ConstAccessor<float> acc_PanTauBDT_1p0n_vs_1p1n("PanTau_BDTValue_1p0n_vs_1p1n");
147  static const SG::ConstAccessor<float> acc_PanTauBDT_1p1n_vs_1pXn("PanTau_BDTValue_1p1n_vs_1pXn");
148  static const SG::ConstAccessor<float> acc_PanTauBDT_3p0n_vs_3pXn("PanTau_BDTValue_3p0n_vs_3pXn");
149  // BDT values are initialised to -1111, while actual scores (when evaluated) are within [-5,1], so take max between BDT score and -5-epsilon
150  vars.PanTauBDT_1p0n_vs_1p1n = std::max(acc_PanTauBDT_1p0n_vs_1p1n(xTau), -5.1f);
151  vars.PanTauBDT_1p1n_vs_1pXn = std::max(acc_PanTauBDT_1p1n_vs_1pXn(xTau), -5.1f);
152  vars.PanTauBDT_3p0n_vs_3pXn = std::max(acc_PanTauBDT_3p0n_vs_3pXn(xTau), -5.1f);
153  vars.nTracks = (float)xTau.nTracks();
155 
156  ptMVA = float( ptCombined * m_bdtHelper->getResponse(availableVars) );
157  }
158 
159  if (ptMVA<1.) ptMVA=1.;
161  // apply MVA calibration as default
162  xTau.setP4(ptMVA, vars.etaConstituent, xTau.phiPanTauCellBased(), 0.);
163  }
164  else {
165  // protection but should never happen
166  if (xTau.ptDetectorAxis()==0. || xTau.ptJetSeed()==0.) {
168  xTau.setP4(1., xTau.etaDetectorAxis(), xTau.phiDetectorAxis(), 0.);
169  return StatusCode::SUCCESS;
170  }
171 
173  vars.etaDetectorAxis = xTau.etaDetectorAxis();
174  vars.ptEM_D_ptLC = ptEM / xTau.ptDetectorAxis();
175  vars.ptDetectorAxis_D_ptJetSeed = xTau.ptDetectorAxis() / xTau.ptJetSeed();
176 
177  static const SG::ConstAccessor<float> acc_UpsilonCluster("UpsilonCluster");
178  static const SG::ConstAccessor<float> acc_LeadClusterFrac("LeadClusterFrac");
179  static const SG::ConstAccessor<float> acc_SecondClusterFrac("SecondClusterFrac");
180  static const SG::ConstAccessor<float> acc_ThirdClusterFrac("ThirdClusterFrac");
181 
182  vars.upsilon_cluster = acc_UpsilonCluster(xTau);
183  vars.lead_cluster_frac = acc_LeadClusterFrac(xTau);
184  vars.second_cluster_frac = acc_SecondClusterFrac(xTau);
185  vars.third_cluster_frac = acc_ThirdClusterFrac(xTau);
186 
188 
189  float ptMVA = float( xTau.ptDetectorAxis() * m_bdtHelper->getResponse(availableVars) );
190  if (ptMVA<1.) ptMVA=1.;
191 
193  // apply MVA calibration
194  xTau.setP4(ptMVA, vars.etaDetectorAxis, xTau.phiDetectorAxis(), 0.);
195  }
196 
197  ATH_MSG_DEBUG("final calib:" << xTau.pt() << " " << xTau.eta() << " " << xTau.phi() << " " << xTau.e());
198 
199  return StatusCode::SUCCESS;
200 }
xAOD::TauJet_v3::phiDetectorAxis
double phiDetectorAxis() const
MvaTESEvaluator::MvaInputVariables::first_eng_dens
float first_eng_dens
Definition: MvaTESEvaluator.h:35
xAOD::TauJetParameters::PFOEngRelDiff
@ PFOEngRelDiff
Definition: TauDefs.h:318
MvaTESEvaluator::MvaInputVariables::second_lambda
float second_lambda
Definition: MvaTESEvaluator.h:36
MvaTESEvaluator::MvaInputVariables::etaDetectorAxis
float etaDetectorAxis
Definition: MvaTESEvaluator.h:59
xAOD::TauJet_v3::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
xAOD::TauJet_v3::etaDetectorAxis
double etaDetectorAxis() const
xAOD::TauJetParameters::ClustersMeanSecondLambda
@ ClustersMeanSecondLambda
Definition: TauDefs.h:315
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
MvaTESEvaluator::m_bdtHelper
std::unique_ptr< tauRecTools::BDTHelper > m_bdtHelper
Definition: MvaTESEvaluator.h:67
MvaTESEvaluator::MvaInputVariables::upsilon_cluster
float upsilon_cluster
Definition: MvaTESEvaluator.h:60
MvaTESEvaluator.h
xAOD::TauJet_v3::nTracks
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Definition: TauJet_v3.cxx:526
MvaTESEvaluator::MvaInputVariables::mu
float mu
Definition: MvaTESEvaluator.h:30
MvaTESEvaluator::m_bdtHelper0p
std::unique_ptr< tauRecTools::BDTHelper > m_bdtHelper0p
Definition: MvaTESEvaluator.h:68
MvaTESEvaluator::MvaInputVariables::PanTauBDT_3p0n_vs_3pXn
float PanTauBDT_3p0n_vs_3pXn
Definition: MvaTESEvaluator.h:48
TauRecToolBase
The base class for all tau tools.
Definition: TauRecToolBase.h:21
xAOD::TauJetParameters::ClustersMeanPresamplerFrac
@ ClustersMeanPresamplerFrac
Definition: TauDefs.h:316
SG::ConstAccessor< float >
MvaTESEvaluator::MvaInputVariables::third_cluster_frac
float third_cluster_frac
Definition: MvaTESEvaluator.h:63
TauRecToolBase::inTrigger
bool inTrigger() const
Definition: TauRecToolBase.h:87
xAOD::TauJet_v3::ptJetSeed
double ptJetSeed() const
xAOD::TauJet_v3::e
virtual double e() const
The total energy of the particle.
Definition: TauJet_v3.cxx:88
xAOD::TauJet_v3::ptDetectorAxis
double ptDetectorAxis() const
MvaTESEvaluator::MvaInputVariables::ptDetectorAxis_D_ptJetSeed
float ptDetectorAxis_D_ptJetSeed
Definition: MvaTESEvaluator.h:64
xAOD::TauJet_v3::setP4
void setP4(double pt, double eta, double phi, double m)
Set methods for IParticle values.
Definition: TauJet_v3.cxx:172
MvaTESEvaluator::MvaInputVariables::eprobability
float eprobability
Definition: MvaTESEvaluator.h:38
xAOD::TauJetParameters::centFrac
@ centFrac
Get centrality fraction.
Definition: TauDefs.h:200
MvaTESEvaluator::MvaInputVariables::ptLC_D_ptCombined
float ptLC_D_ptCombined
Definition: MvaTESEvaluator.h:42
xAOD::TauJet_v3::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
MvaTESEvaluator::MvaInputVariables::etaConstituent
float etaConstituent
Definition: MvaTESEvaluator.h:44
xAOD::TauJet_v3::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
xAOD::TauJet_v3::etaPanTauCellBased
double etaPanTauCellBased() const
MvaTESEvaluator::MvaInputVariables
Definition: MvaTESEvaluator.h:29
MvaTESEvaluator::MvaInputVariables::logPtDetectorAxis
float logPtDetectorAxis
Definition: MvaTESEvaluator.h:58
MvaTESEvaluator::MvaTESEvaluator
MvaTESEvaluator(const std::string &name="MvaTESEvaluator")
Definition: MvaTESEvaluator.cxx:10
MvaTESEvaluator::MvaInputVariables::ptConstituent_D_ptCombined
float ptConstituent_D_ptCombined
Definition: MvaTESEvaluator.h:43
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MvaTESEvaluator::MvaInputVariables::second_cluster_frac
float second_cluster_frac
Definition: MvaTESEvaluator.h:62
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
MvaTESEvaluator::m_sWeightFileName
std::string m_sWeightFileName
Definition: MvaTESEvaluator.h:71
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:135
MvaTESEvaluator::MvaInputVariables::nVtxPU
float nVtxPU
Definition: MvaTESEvaluator.h:31
MvaTESEvaluator::MvaInputVariables::PanTauBDT_1p0n_vs_1p1n
float PanTauBDT_1p0n_vs_1p1n
Definition: MvaTESEvaluator.h:46
MvaTESEvaluator::MvaInputVariables::lead_cluster_frac
float lead_cluster_frac
Definition: MvaTESEvaluator.h:61
MvaTESEvaluator::MvaInputVariables::ptCombined
float ptCombined
Definition: MvaTESEvaluator.h:41
MvaTESEvaluator::MvaInputVariables::PFOEngRelDiff
float PFOEngRelDiff
Definition: MvaTESEvaluator.h:50
xAOD::TauJet_v3::detail
bool detail(TauJetParameters::Detail detail, int &value) const
Set veto flag.
Definition: TauJet_v3.cxx:292
xAOD::TauJet_v3::phiPanTauCellBased
double phiPanTauCellBased() const
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MvaTESEvaluator::MvaInputVariables::presampler_frac
float presampler_frac
Definition: MvaTESEvaluator.h:37
xAOD::TauJetParameters::ClustersMeanEMProbability
@ ClustersMeanEMProbability
Definition: TauDefs.h:313
TauRecToolBase::find_file
std::string find_file(const std::string &fname) const
Definition: TauRecToolBase.cxx:19
xAOD::TauJetParameters::ClustersMeanCenterLambda
@ ClustersMeanCenterLambda
Definition: TauDefs.h:312
MvaTESEvaluator::execute
virtual StatusCode execute(xAOD::TauJet &xTau) const override
Execute - called for each tau candidate.
Definition: MvaTESEvaluator.cxx:33
MvaTESEvaluator::initialize
virtual StatusCode initialize() override
Tool initializer.
Definition: MvaTESEvaluator.cxx:17
MvaTESEvaluator::MvaInputVariables::centFrac
float centFrac
Definition: MvaTESEvaluator.h:53
MvaTESEvaluator::MvaInputVariables::logPtCombined
float logPtCombined
Definition: MvaTESEvaluator.h:54
HelperFunctions.h
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
xAOD::TauJetParameters::ClustersMeanFirstEngDens
@ ClustersMeanFirstEngDens
Definition: TauDefs.h:314
MvaTESEvaluator::MvaInputVariables::PanTauBDT_1p1n_vs_1pXn
float PanTauBDT_1p1n_vs_1pXn
Definition: MvaTESEvaluator.h:47
MvaTESEvaluator::MvaInputVariables::ptSeed_D_ptCombined
float ptSeed_D_ptCombined
Definition: MvaTESEvaluator.h:55
xAOD::TauJet_v3::ptIntermediateAxis
double ptIntermediateAxis() const
MvaTESEvaluator::MvaInputVariables::center_lambda
float center_lambda
Definition: MvaTESEvaluator.h:34
MvaTESEvaluator::MvaInputVariables::ptEM_D_ptLC
float ptEM_D_ptLC
Definition: MvaTESEvaluator.h:40
xAOD::TauJetParameters::FinalCalib
@ FinalCalib
Definition: TauDefs.h:346
xAOD::TauJet_v3::ptPanTauCellBased
double ptPanTauCellBased() const
readCCLHist.float
float
Definition: readCCLHist.py:83
MvaTESEvaluator::MvaInputVariables::nTracks
float nTracks
Definition: MvaTESEvaluator.h:49
MvaTESEvaluator::m_sWeightFileName0p
std::string m_sWeightFileName0p
Definition: MvaTESEvaluator.h:72
MvaTESEvaluator::MvaInputVariables::rho
float rho
Definition: MvaTESEvaluator.h:32