ATLAS Offline Software
DiTauDiscriminantTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 // Core include(s):
8 #include "AthLinks/ElementLink.h"
9 
10 // EDM include(s):
11 #include "xAODTau/DiTauJet.h"
13 
17 
18 
19 using namespace DiTauRecTools;
20 
21 //=================================PUBLIC-PART==================================
22 //______________________________________________________________________________
23 DiTauDiscriminantTool::DiTauDiscriminantTool( const std::string& name )
24  : AsgTool(name)
25  , m_bdt()
26 {
27  declareProperty( "WeightsFile", m_sWeightsFile = "tauRecTools/R22_preprod/DiTau_JetBDT_winter2024.weights.root");
28  declareProperty( "BDTScoreName", m_sBDTScoreName = "JetBDT");
29 }
30 
31 //______________________________________________________________________________
32 DiTauDiscriminantTool::~DiTauDiscriminantTool( )
33 = default;
34 
35 //______________________________________________________________________________
37 {
38  ATH_MSG_INFO( "Initializing DiTauDiscriminantTool" );
39  ATH_MSG_DEBUG( "path to weights file: " << m_sWeightsFile );
40 
41  m_mIDSpectators = {
42  {"ditau_pt", new float(0)},
43  {"mu", new float(0)},
44  {"pt_weight", new float(0)},
45  {"isSignal", new float(0)}
46  };
47 
48  m_mIDVariables = {
49  {"f_core_lead", new float(0)}, // used
50  {"f_core_subl", new float(0)}, // used
51  {"f_subjet_lead", new float(0)},
52  {"f_subjet_subl", new float(0)}, // used
53  {"f_subjets", new float(0)}, // used
54  {"f_track_lead", new float(0)},
55  {"f_track_subl", new float(0)},
56  {"R_max_lead", new float(0)}, // used
57  {"R_max_subl", new float(0)}, // used
58  {"n_Subjets", new float(0)},
59  {"n_track", new float(0)}, // used
60  {"n_tracks_lead", new float(0)}, // used
61  {"n_tracks_subl", new float(0)},
62  {"n_isotrack", new float(0)},
63  {"R_track", new float(0)},
64  {"R_track_core", new float(0)},
65  {"R_track_all", new float(0)},
66  {"R_isotrack", new float(0)}, // used
67  {"R_core_lead", new float(0)},
68  {"R_core_subl", new float(0)},
69  {"R_tracks_lead", new float(0)},
70  {"R_tracks_subl", new float(0)}, // used
71  {"m_track", new float(0)},
72  {"m_track_core", new float(0)},
73  {"m_core_lead", new float(0)},
74  {"log(m_core_lead)", new float(0)}, // used
75  {"m_core_subl", new float(0)},
76  {"log(m_core_subl)", new float(0)}, // used
77  {"m_track_all", new float(0)},
78  {"m_tracks_lead", new float(0)},
79  {"log(m_tracks_lead)", new float(0)}, // used
80  {"m_tracks_subl", new float(0)},
81  {"log(m_tracks_subl)", new float(0)}, // used
82  {"E_frac_subl", new float(0)},
83  {"E_frac_subsubl", new float(0)},
84  {"R_subjets_subl", new float(0)},
85  {"R_subjets_subsubl", new float(0)},
86  {"d0_leadtrack_lead", new float(0)},
87  {"log(abs(d0_leadtrack_lead))", new float(0)}, // used
88  {"d0_leadtrack_subl", new float(0)},
89  {"log(abs(d0_leadtrack_subl))", new float(0)}, // used
90  {"f_isotracks", new float(0)},
91  {"log(f_isotracks)", new float(0)}, // used
92  };
93 
94  ATH_CHECK(parseWeightsFile());
95 
96  // m_bIsInitialized = true;
97  return StatusCode::SUCCESS;
98 }
99 
101 // Wrapper functions //
104 
105  setIDVariables(xDiTau);
106 
107  double bdtScore = m_bdt->GetClassification();
108 
109  const static SG::AuxElement::Decorator<double> decBDTScore(m_sBDTScoreName);
110  decBDTScore(xDiTau) = bdtScore;
111 
112  ATH_MSG_DEBUG("Jet BDT score: " << bdtScore);
113  return StatusCode::SUCCESS;
114 }
115 
116 //=================================PRIVATE-PART=================================
117 //______________________________________________________________________________
118 
119 StatusCode DiTauDiscriminantTool::parseWeightsFile()
120 {
121  std::string weight_file = PathResolverFindCalibFile(m_sWeightsFile);
122 
123  ATH_MSG_DEBUG("InputWeightsPath: " << weight_file);
124 
125  m_bdt = DiTauRecTools::configureMVABDT( m_mIDVariables, weight_file.c_str() );
126  if(!m_bdt) {
127  ATH_MSG_FATAL("Couldn't configure MVA");
128  return StatusCode::FAILURE;
129  }
130  return StatusCode::SUCCESS;
131 }
132 
133 // ----------------------------------------------------------------------------
134 void DiTauDiscriminantTool::setIDVariables(const xAOD::DiTauJet& xDiTau)
135 {
136  SG::ConstAccessor<float> f_core_leadAcc("f_core_lead");
137  SG::ConstAccessor<float> f_core_sublAcc("f_core_subl");
138  SG::ConstAccessor<float> f_subjet_leadAcc("f_subjet_lead");
139  SG::ConstAccessor<float> f_subjet_sublAcc("f_subjet_subl");
140  SG::ConstAccessor<float> f_subjetsAcc("f_subjets");
141  SG::ConstAccessor<float> f_track_leadAcc("f_track_lead");
142  SG::ConstAccessor<float> f_track_sublAcc("f_track_subl");
143  SG::ConstAccessor<float> R_max_leadAcc("R_max_lead");
144  SG::ConstAccessor<float> R_max_sublAcc("R_max_subl");
145  SG::ConstAccessor<int> n_subjetsAcc("n_subjets");
146  SG::ConstAccessor<int> n_trackAcc("n_track");
147  SG::ConstAccessor<int> n_tracks_leadAcc("n_tracks_lead");
148  SG::ConstAccessor<int> n_tracks_sublAcc("n_tracks_subl");
149  SG::ConstAccessor<int> n_isotrackAcc("n_isotrack");
150  SG::ConstAccessor<float> R_trackAcc("R_track");
151  SG::ConstAccessor<float> R_track_coreAcc("R_track_core");
152  SG::ConstAccessor<float> R_track_allAcc("R_track_all");
153  SG::ConstAccessor<float> R_isotrackAcc("R_isotrack");
154  SG::ConstAccessor<float> R_core_leadAcc("R_core_lead");
155  SG::ConstAccessor<float> R_core_sublAcc("R_core_subl");
156  SG::ConstAccessor<float> R_tracks_leadAcc("R_tracks_lead");
157  SG::ConstAccessor<float> R_tracks_sublAcc("R_tracks_subl");
158  SG::ConstAccessor<float> M_trackAcc("m_track");
159  SG::ConstAccessor<float> M_track_coreAcc("m_track_core");
160  SG::ConstAccessor<float> M_core_leadAcc("m_core_lead");
161  SG::ConstAccessor<float> M_core_sublAcc("m_core_subl");
162  SG::ConstAccessor<float> M_track_allAcc("m_track_all");
163  SG::ConstAccessor<float> M_tracks_leadAcc("m_tracks_lead");
164  SG::ConstAccessor<float> M_tracks_sublAcc("m_tracks_subl");
165  SG::ConstAccessor<float> E_frac_sublAcc("E_frac_subl");
166  SG::ConstAccessor<float> E_frac_subsublAcc("E_frac_subsubl");
167  SG::ConstAccessor<float> R_subjets_sublAcc("R_subjets_subl");
168  SG::ConstAccessor<float> R_subjets_subsublAcc("R_subjets_subsubl");
169  SG::ConstAccessor<float> d0_leadtrack_leadAcc("d0_leadtrack_lead");
170  SG::ConstAccessor<float> d0_leadtrack_sublAcc("d0_leadtrack_subl");
171  SG::ConstAccessor<float> f_isotracksAcc("f_isotracks");
172 
173  setVar("f_core_lead") = f_core_leadAcc(xDiTau);
174  setVar("f_core_subl") = f_core_sublAcc(xDiTau);
175  setVar("f_subjet_lead") = f_subjet_leadAcc(xDiTau);
176  setVar("f_subjet_subl") = f_subjet_sublAcc(xDiTau);
177  setVar("f_subjets") = f_subjetsAcc(xDiTau);
178  setVar("f_track_lead") = f_track_leadAcc(xDiTau);
179  setVar("f_track_subl") = f_track_sublAcc(xDiTau);
180  setVar("R_max_lead") = R_max_leadAcc(xDiTau);
181  setVar("R_max_subl") = R_max_sublAcc(xDiTau);
182  setVar("n_Subjets") = (float) n_subjetsAcc(xDiTau);
183  setVar("n_track") = (float) n_trackAcc(xDiTau);
184  setVar("n_tracks_lead") = (float) n_tracks_leadAcc(xDiTau);
185  setVar("n_tracks_subl") = (float) n_tracks_sublAcc(xDiTau);
186  setVar("n_isotrack") = (float) n_isotrackAcc(xDiTau);
187  setVar("R_track") = R_trackAcc(xDiTau);
188  setVar("R_track_core") = R_track_coreAcc(xDiTau);
189  setVar("R_track_all") = R_track_allAcc(xDiTau);
190  setVar("R_isotrack") = R_isotrackAcc(xDiTau);
191  setVar("R_core_lead") = R_core_leadAcc(xDiTau);
192  setVar("R_core_subl") = R_core_sublAcc(xDiTau);
193  setVar("R_tracks_lead") = R_tracks_leadAcc(xDiTau);
194  setVar("R_tracks_subl") = R_tracks_sublAcc(xDiTau);
195  setVar("m_track") = M_trackAcc(xDiTau);
196  setVar("m_track_core") = M_track_coreAcc(xDiTau);
197  setVar("m_core_lead") = M_core_leadAcc(xDiTau);
198  setVar("log(m_core_lead)") = log(*m_mIDVariables["m_core_lead"]);
199  setVar("m_core_subl") = M_core_sublAcc(xDiTau);
200  setVar("log(m_core_subl)") = log(*m_mIDVariables["m_core_subl"]);
201  setVar("m_track_all") = M_track_allAcc(xDiTau);
202  setVar("m_tracks_lead") = M_tracks_leadAcc(xDiTau);
203  setVar("log(m_tracks_lead)") = log(*m_mIDVariables["m_tracks_lead"]);
204  setVar("m_tracks_subl") = M_tracks_sublAcc(xDiTau);
205  setVar("log(m_tracks_subl)") = log(*m_mIDVariables["m_tracks_subl"]);
206  setVar("E_frac_subl") = E_frac_sublAcc(xDiTau);
207  setVar("E_frac_subsubl") = E_frac_subsublAcc(xDiTau);
208  setVar("R_subjets_subl") = R_subjets_sublAcc(xDiTau);
209  setVar("R_subjets_subsubl") = R_subjets_subsublAcc(xDiTau);
210  setVar("d0_leadtrack_lead") = d0_leadtrack_leadAcc(xDiTau);
211  setVar("log(abs(d0_leadtrack_lead))") = log(fabs(*m_mIDVariables["d0_leadtrack_lead"]));
212  setVar("d0_leadtrack_subl") = d0_leadtrack_sublAcc(xDiTau);
213  setVar("log(abs(d0_leadtrack_subl))") = log(fabs(*m_mIDVariables["d0_leadtrack_subl"]));
214  setVar("f_isotracks") = f_isotracksAcc(xDiTau);
215  setVar("log(f_isotracks)") = log(*m_mIDVariables["f_isotracks"]);
216 
217  for (const auto &var: m_vVarNames)
218  {
219  ATH_MSG_DEBUG(var << ": " << m_mIDVariables[var]);
220  }
221 }
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::float
float
Definition: BTagging_v1.cxx:168
initialize
void initialize()
Definition: run_EoverP.cxx:894
DiTauRecTools::configureMVABDT
std::unique_ptr< MVAUtils::BDT > configureMVABDT(std::map< TString, float * > &availableVars, const TString &weightFile)
Definition: Reconstruction/DiTauRecTools/Root/HelperFunctions.cxx:46
DiTauJetContainer.h
SG::ConstAccessor< float >
HelperFunctions.h
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DiTauJet.h
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DiTauRecTools
Implementation of boosted di-tau ID.
Definition: DiTauDiscriminantTool.h:36
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
xAOD::DiTauJet_v1
Definition: DiTauJet_v1.h:31
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
DiTauDiscriminantTool.h