80 if not config.getContainerMeta (
'EventInfo',
'OnnxEnabled'):
81 raise RuntimeError (
"You must enable ONNX in order to use HyPER. Please set 'setupONNX: True' in CommonServices.")
83 decorator_prefix = _resolve_reco_partons_prefix(self.
topology, self.outputName)
84 alg = config.createAlgorithm(
85 "EventReco::RunHyPERAlg", f
"RunHyPERAlg_{decorator_prefix}"
88 alg.btagger = self.btagger
89 alg.electrons, alg.electronSelection = config.readNameAndSelection(
92 alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
93 alg.jets, alg.jetSelection = config.readNameAndSelection(self.jets)
94 alg.met = config.readName(self.met)
95 alg.eventSelection = self.eventSelection
98 if self.fullLogEventNumber > 0:
99 if self.OutputLevel != 3:
101 "OutputLevel must be 3 (INFO) when tracing only one particular event!"
104 alg.OutputLevel = self.OutputLevel
105 alg.fullLogEventNumber = self.fullLogEventNumber
107 def form_even_odd_path(topology, run):
108 base_path =
"TopReconstruction/HyPERModels/" + topology
109 even_path = base_path +
"_" + run +
"_trained_on_even.onnx"
110 odd_path = base_path +
"_" + run +
"_trained_on_odd.onnx"
111 return even_path, odd_path
114 if config.geometry() == LHCPeriod.Run2:
116 even_path, odd_path = form_even_odd_path(
117 "TtbarAllHadronic",
"run2"
120 even_path, odd_path = form_even_odd_path(
123 elif self.
topology ==
"TtbarLJetsNoBTag":
124 even_path, odd_path = form_even_odd_path(
125 "TtbarLJetsNoBTag",
"run2"
127 elif self.
topology ==
"TtbarDiLepton":
128 even_path, odd_path = form_even_odd_path(
133 print(
"Not being able to set the model paths for the given topology.")
134 raise ValueError(
"Unknown topology: " + self.
topology)
135 elif config.geometry() == LHCPeriod.Run3:
136 if self.
topology ==
"TtbarAllHadronic":
137 even_path, odd_path = form_even_odd_path(
138 "TtbarAllHadronic",
"run3"
141 even_path, odd_path = form_even_odd_path(
144 elif self.
topology ==
"TtbarLJetsNoBTag":
145 even_path, odd_path = form_even_odd_path(
146 "TtbarLJetsNoBTag",
"run3"
148 elif self.
topology ==
"TtbarDiLepton":
149 even_path, odd_path = form_even_odd_path(
150 "TtbarDiLepton",
"run3"
153 print(
"Not being able to set the model paths for the given topology.")
154 raise ValueError(
"Unknown topology: " + self.
topology)
156 print(
"Not being able to set the model paths for the given run period.")
158 "HyPER models not available for run period: " + config.geometry()
164 for handle, model_path
in (
165 (
"onnxToolTrainedOnEven", even_path),
166 (
"onnxToolTrainedOnOdd", odd_path),
168 config.addPrivateTool(handle,
"AthOnnx::OnnxRuntimeInferenceTool")
169 config.addPrivateTool(
170 handle +
".ORTSessionTool",
"AthOnnx::OnnxRuntimeSessionToolCPU"
172 getattr(alg, handle).ORTSessionTool.ModelFileName = model_path
175 if self.
topology ==
"TtbarDiLepton":
176 alg.top_b_p4 = decorator_prefix +
"_Top_b_p4_%SYS%"
177 alg.topbar_bbar_p4 = decorator_prefix +
"_Topbar_bbar_p4_%SYS%"
178 alg.top_lep_p4 = decorator_prefix +
"_Top_lep_p4_%SYS%"
179 alg.topbar_lepbar_p4 = decorator_prefix +
"_Topbar_lepbar_p4_%SYS%"
180 if self.
topology ==
"TtbarAllHadronic":
181 alg.top_b_p4 = decorator_prefix +
"_Top_b_p4_%SYS%"
182 alg.topbar_bbar_p4 = decorator_prefix +
"_Topbar_bbar_p4_%SYS%"
183 alg.top_Wplus_decay0_p4 = (
184 decorator_prefix +
"_Top_Wplus_decay0_p4_%SYS%"
186 alg.top_Wplus_decay1_p4 = (
187 decorator_prefix +
"_Top_Wplus_decay1_p4_%SYS%"
189 alg.topbar_Wminus_decay0_p4 = (
190 decorator_prefix +
"_Topbar_Wminus_decay0_p4_%SYS%"
192 alg.topbar_Wminus_decay1_p4 = (
193 decorator_prefix +
"_Topbar_Wminus_decay1_p4_%SYS%"
195 if self.
topology in [
"TtbarLJets",
"TtbarLJetsNoBTag"]:
196 alg.toplep_b_p4 = decorator_prefix +
"_TopLep_b_p4_%SYS%"
197 alg.toplep_lep_p4 = decorator_prefix +
"_TopLep_lep_p4_%SYS%"
198 alg.tophad_b_p4 = decorator_prefix +
"_TopHad_b_p4_%SYS%"
199 alg.tophad_w_decay0_p4 = decorator_prefix +
"_TopHad_W_decay0_p4_%SYS%"
200 alg.tophad_w_decay1_p4 = decorator_prefix +
"_TopHad_W_decay1_p4_%SYS%"
203 if self.
topology ==
"TtbarAllHadronic":
206 "TtbarAllHadronic_HyPER_Top1_Indices_%SYS%",
207 f
"{decorator_prefix}_Top1_Indices",
208 auxType=
"vector_int",
212 "TtbarAllHadronic_HyPER_Top1_Score_%SYS%",
213 f
"{decorator_prefix}_Top1_Score",
218 "TtbarAllHadronic_HyPER_Top2_Indices_%SYS%",
219 f
"{decorator_prefix}_Top2_Indices",
220 auxType=
"vector_int",
224 "TtbarAllHadronic_HyPER_Top2_Score_%SYS%",
225 f
"{decorator_prefix}_Top2_Score",
230 "TtbarAllHadronic_HyPER_W1_Indices_%SYS%",
231 f
"{decorator_prefix}_W1_Indices",
232 auxType=
"vector_int",
236 "TtbarAllHadronic_HyPER_W1_Score_%SYS%",
237 f
"{decorator_prefix}_W1_Score",
242 "TtbarAllHadronic_HyPER_W2_Indices_%SYS%",
243 f
"{decorator_prefix}_W2_Indices",
244 auxType=
"vector_int",
248 "TtbarAllHadronic_HyPER_W2_Score_%SYS%",
249 f
"{decorator_prefix}_W2_Score",
254 (
"top_b_p4", decorator_prefix +
"_Top_b_p4"),
255 (
"topbar_bbar_p4", decorator_prefix +
"_Topbar_bbar_p4"),
257 "top_Wplus_decay0_p4",
258 decorator_prefix +
"_Top_Wplus_decay0_p4",
261 "top_Wplus_decay1_p4",
262 decorator_prefix +
"_Top_Wplus_decay1_p4",
265 "topbar_Wminus_decay0_p4",
266 decorator_prefix +
"_Topbar_Wminus_decay0_p4",
269 "topbar_Wminus_decay1_p4",
270 decorator_prefix +
"_Topbar_Wminus_decay1_p4",
275 getattr(alg, output_var[0]),
277 auxType=
"PtEtaPhiMVector",
283 "TtbarLJets_HyPER_Classification_Score_%SYS%",
284 f
"{decorator_prefix}_Classification_Score",
289 "TtbarLJets_HyPER_TopHad_Indices_%SYS%",
290 f
"{decorator_prefix}_TopHad_Indices",
291 auxType=
"vector_int",
295 "TtbarLJets_HyPER_TopHad_Score_%SYS%",
296 f
"{decorator_prefix}_TopHad_Score",
301 "TtbarLJets_HyPER_TopHad_IDs_%SYS%",
302 f
"{decorator_prefix}_TopHad_IDs",
303 auxType=
"vector_int",
307 "TtbarLJets_HyPER_TopLep_Indices_%SYS%",
308 f
"{decorator_prefix}_TopLep_Indices",
309 auxType=
"vector_int",
313 "TtbarLJets_HyPER_TopLep_Score_%SYS%",
314 f
"{decorator_prefix}_TopLep_Score",
319 "TtbarLJets_HyPER_TopLep_IDs_%SYS%",
320 f
"{decorator_prefix}_TopLep_IDs",
321 auxType=
"vector_int",
325 "TtbarLJets_HyPER_WHad_Indices_%SYS%",
326 f
"{decorator_prefix}_WHad_Indices",
327 auxType=
"vector_int",
331 "TtbarLJets_HyPER_WHad_Score_%SYS%",
332 f
"{decorator_prefix}_WHad_Score",
337 "TtbarLJets_HyPER_WLep_Indices_%SYS%",
338 f
"{decorator_prefix}_WLep_Indices",
339 auxType=
"vector_int",
343 "TtbarLJets_HyPER_WLep_Score_%SYS%",
344 f
"{decorator_prefix}_WLep_Score",
349 (
"toplep_b_p4", decorator_prefix +
"_TopLep_b_p4"),
350 (
"toplep_lep_p4", decorator_prefix +
"_TopLep_lep_p4"),
351 (
"tophad_b_p4", decorator_prefix +
"_TopHad_b_p4"),
353 "tophad_w_decay0_p4",
354 decorator_prefix +
"_TopHad_W_decay0_p4",
357 "tophad_w_decay1_p4",
358 decorator_prefix +
"_TopHad_W_decay1_p4",
363 getattr(alg, output_var[0]),
365 auxType=
"PtEtaPhiMVector",
368 elif self.
topology ==
"TtbarDiLepton":
371 "TtbarDiLepton_HyPER_Classification_Score_%SYS%",
372 f
"{decorator_prefix}_Classification_Score",
377 "TtbarDiLepton_HyPER_Top1_Indices_%SYS%",
378 f
"{decorator_prefix}_Top1_Indices",
379 auxType=
"vector_int",
383 "TtbarDiLepton_HyPER_Top1_IDs_%SYS%",
384 f
"{decorator_prefix}_Top1_IDs",
385 auxType=
"vector_int",
389 "TtbarDiLepton_HyPER_Top1_Score_%SYS%",
390 f
"{decorator_prefix}_Top1_Score",
395 "TtbarDiLepton_HyPER_Top2_Indices_%SYS%",
396 f
"{decorator_prefix}_Top2_Indices",
397 auxType=
"vector_int",
401 "TtbarDiLepton_HyPER_Top2_Score_%SYS%",
402 f
"{decorator_prefix}_Top2_Score",
407 "TtbarDiLepton_HyPER_Top2_IDs_%SYS%",
408 f
"{decorator_prefix}_Top2_IDs",
409 auxType=
"vector_int",
413 "TtbarDiLepton_HyPER_HE_Score_%SYS%",
414 f
"{decorator_prefix}_HE_Score",
420 (
"top_b_p4", decorator_prefix +
"_Top_b_p4"),
421 (
"topbar_bbar_p4", decorator_prefix +
"_Topbar_bbar_p4"),
424 decorator_prefix +
"_Top_lep_p4",
428 decorator_prefix +
"_Topbar_lepbar_p4",
433 getattr(alg, output_var[0]),
435 auxType=
"PtEtaPhiMVector",
439 raise ValueError(
"Unknown topology: " + self.
topology)