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