ATLAS Offline Software
Loading...
Searching...
No Matches
HID1.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2# ====================================================================
3# DAOD_HID1.py
4#
5# Unskimmed DAOD format for hadronic-identification studies on MC.
6#
7# HID1 is the union of the FTAG1 flavour-tagging content and the jet
8# content of JETM2, so that a single format serves flavour tagging, jet
9# and hadronic-tau studies. It is intended to supersede both of those
10# formats.
11# Requires the HID1 flag in Derivation_tf.py
12# ====================================================================
13
14from __future__ import annotations
15
16from typing import TYPE_CHECKING, Any
17
18from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
19from AthenaConfiguration.ComponentFactory import CompFactory
20from AthenaConfiguration.Enums import LHCPeriod, MetadataCategory
21from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper
22from DerivationFrameworkEGamma.ElectronsCPDetailedContent import ElectronsCPDetailedContent
23from DerivationFrameworkFlavourTag.FtagBaseContent import (
24 add_baseline_slimming_allvariables,
25 add_baseline_slimming_smartcollections,
26 add_common_augmentation,
27 add_extra_variables_to_slimming_helper,
28 add_truth_to_slimming_helper,
29 add_truth_vertex_decorations,
30 trigger_matching,
31 trigger_setup,
32 update_append_to_dictionary_in_slimming_helper,
33)
34from DerivationFrameworkFlavourTag.FtagDerivationConfig import (
35 HLTJetFTagDecorationCfg,
36)
37from DerivationFrameworkFlavourTag.FtagVRJetConfig import (
38 VR_JET_APPEND_TO_DICTIONARY,
39 VR_JET_TRUTH_VERTEX_DR,
40 VR_JETS,
41 VRFtagJetsCfg,
42 add_vr_jet_truth_augmentation,
43)
44from DerivationFrameworkJetEtMiss.CommonJETMXContent import (
45 ClusterVariables,
46 ExtraJSSVariables,
47 FELinks,
48 FlowElementVariables,
49 TrackingVariables,
50 TrackingVariablesHGTD,
51 UFOVariables,
52)
53from DerivationFrameworkJetEtMiss.JetCommonConfig import addOriginCorrectedClustersToSlimmingTool
54from DerivationFrameworkMCTruth.MCTruthCommonConfig import (
55 AddTopQuarkAndDownstreamParticlesCfg,
56 AddTruthCollectionNavigationDecorationsCfg,
57)
58from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg
59from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper
60from InDetConfig.InDetPoolReadConfig import InDetPoolReadCfg
61from JetRecConfig.JetRecConfig import JetRecCfg
62from JetRecConfig.StandardLargeRJets import AntiKt10TruthDressedWZSoftDrop
63from JetRecConfig.StandardSmallRJets import AntiKt4LCTopo
64from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
65from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg
66
67if TYPE_CHECKING:
68 from AthenaConfiguration.AthConfigFlags import AthConfigFlags
69
70
71LARGE_R_JETS = "AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets"
72
73# Written by the fast IP augmenter for the taggers run here, and recomputed by the
74# training-dataset-dumper, so they are kept transient
75POORMAN_IP_VARS = [
76 "poormanIp_d0Uncertainty",
77 "poormanIp_z0SinThetaUncertainty",
78 "poormanIp_trackDisplacement",
79 "poormanIp_trackMomentum",
80 "poormanIp_invalidIp",
81]
82
83GN3_LATENT_VARS = [
84 "GN3EPCLV01_Latent",
85 "GN3EPCLV01_Latent128",
86 "GN3EPCLV01_Latent64",
87 "GN3EPCLV01_Latent32",
88 "GN3EPCLV01SimpleFlip_Latent",
89 "GN3EPCLV01SimpleFlip_Latent128",
90 "GN3EPCLV01SimpleFlip_Latent64",
91 "GN3EPCLV01SimpleFlip_Latent32",
92]
93
94
96 flags: AthConfigFlags,
97 acc: ComponentAccumulator,
98 slimming_helper: SlimmingHelper,
99 keep_truth_collections: bool = True,
100 tau_as_smart_collection: bool = False,
101) -> None:
102 """Add the flavour-tagging content and augmentations to the slimming helper."""
103
104 # Baseline content
105 add_baseline_slimming_smartcollections(slimming_helper=slimming_helper)
106 add_baseline_slimming_allvariables(slimming_helper=slimming_helper)
107 add_truth_to_slimming_helper(slimming_helper=slimming_helper)
108
109 # Common FTAG augmentations
110 add_common_augmentation(
111 flags=flags,
112 acc=acc,
113 slimming_helper=slimming_helper,
114 )
115
116 # Truth vertex labeling for Maskformer (see https://gitlab.cern.ch/atlas/athena/-/blob/main/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/docs/TruthVertexLabelling.md?ref_type=heads)
117 # The VR jets are summarised at their Rmax, which over-associates the high-pT jets whose
118 # real radius has shrunk to Rmin; a shrinking-cone-aware summary is left to a follow-up.
119 add_truth_vertex_decorations(
120 flags=flags,
121 acc=acc,
122 slimming_helper=slimming_helper,
123 large_r_jet_collection=LARGE_R_JETS,
124 extra_jet_collections=[(VR_JETS, VR_JET_TRUTH_VERTEX_DR)],
125 )
126
127 add_vr_jet_truth_augmentation(
128 flags=flags,
129 acc=acc,
130 slimming_helper=slimming_helper,
131 )
132
133 slimming_helper.SmartCollections += [
134 LARGE_R_JETS,
135 "AntiKt4LCTopoJets",
136 ]
137
138 slimming_helper.AllVariables += [
139 "AntiKt4EMPFlowJets",
140 VR_JETS,
141 "CaloCalFwdTopoTowers",
142 LARGE_R_JETS,
143 "UFOCSSK",
144 "GlobalChargedParticleFlowObjects",
145 "GlobalNeutralParticleFlowObjects",
146 "CHSGChargedParticleFlowObjects",
147 "CHSGNeutralParticleFlowObjects",
148 "CSSKGChargedParticleFlowObjects",
149 "CSSKGNeutralParticleFlowObjects",
150 "CaloCalTopoClusters",
151 "JetAssociatedPixelClusters",
152 "JetAssociatedSCTClusters",
153 "PixelClusters",
154 "SCT_Clusters",
155 ]
156
157 if tau_as_smart_collection:
158 slimming_helper.SmartCollections += ["TauJets"]
159 else:
160 slimming_helper.AllVariables += [
161 "TauJets",
162 "TauNeutralParticleFlowObjects",
163 "TauShotParticleFlowObjects",
164 "TauTracks",
165 ]
166 if keep_truth_collections:
167 slimming_helper.AllVariables += [
168 "TruthEvents",
169 "TruthParticles",
170 "TruthVertices",
171 ]
172
173 # Extra variables from e/gamma and common FTAG content
174 slimming_helper.ExtraVariables += ElectronsCPDetailedContent
175 add_extra_variables_to_slimming_helper(
176 flags=flags,
177 slimming_helper=slimming_helper,
178 )
179
180 slimming_helper.ExtraVariables += ["AntiKt4TruthJets.constituentLinks"]
181
182 # Truth labelling for the topo-cluster jets, which are not smart-slimmed here
183 for jet_collection in ["AntiKt4EMTopoJets", "AntiKt4LCTopoJets"]:
184 slimming_helper.ExtraVariables.append(
185 ".".join(
186 [
187 jet_collection,
188 "HadronConeExclTruthLabelID",
189 "HadronGhostTruthLabelID",
190 "GhostBHadronsFinal",
191 "GhostCHadronsFinal",
192 "GhostTausFinal",
193 "ConeExclBHadronsFinal",
194 "ConeExclCHadronsFinal",
195 "ConeExclTausFinal",
196 ]
197 )
198 )
199
200 # Extra ITk, HGTD and EMTopo jet content available with Run-4 inputs
201 if flags.GeoModel.Run >= LHCPeriod.Run4:
202 slimming_helper.SmartCollections += ["MET_Baseline_AntiKt4EMTopo"]
203 slimming_helper.AllVariables += [
204 "AntiKt4EMTopoJets",
205 "AntiKt4TruthJets",
206 "ITkPixelMeasurements",
207 "ITkStripMeasurements",
208 "ITkPixelSpacePoints",
209 "ITkStripSpacePoints",
210 "ITkStripOverlapSpacePoints",
211 ]
212 slimming_helper.ExtraVariables += [
213 ".".join(["InDetTrackParticles"] + TrackingVariablesHGTD)
214 ]
215
216 # Needed for ITk space points
217 acc.merge(InDetPoolReadCfg(flags))
218
219 # Optional pseudotrack content
220 if flags.BTagging.Pseudotrack:
221 slimming_helper.AllVariables += ["InDetPseudoTrackParticles"]
222
223 # Run jet labelling for trigger jets
224 if flags.Trigger.EDMVersion == 3 and flags.Input.isMC:
225 acc.merge(HLTJetFTagDecorationCfg(flags))
226
227
229 flags: AthConfigFlags,
230 slimming_helper: SlimmingHelper,
231) -> None:
232 """Add the jet reconstruction and constituent content to the slimming helper."""
233
234 slimming_helper.SmartCollections += [
235 "EventInfo",
236 "Photons",
237 "AntiKt4EMTopoJets",
238 ]
239
240 # Low-level inputs
241 slimming_helper.ExtraVariables += [
242 ".".join(["CaloCalTopoClusters"] + ClusterVariables),
243 ".".join(["EMOriginTopoClusters"] + ["calM"]),
244 ".".join(
245 ["GlobalChargedParticleFlowObjects"] + FlowElementVariables + ["otherObjectWeights"]
246 ),
247 ".".join(
248 ["GlobalNeutralParticleFlowObjects"] + FlowElementVariables + ["otherObjectWeights"]
249 ),
250 ".".join(["UFOCSSK"] + UFOVariables),
251 ".".join(["InDetTrackParticles"] + TrackingVariables),
252 ]
253
254 # Links of physics objects to FlowElements
255 slimming_helper.ExtraVariables += FELinks
256
257 # Detailed substructure information
258 slimming_helper.ExtraVariables += [".".join([LARGE_R_JETS] + ExtraJSSVariables)]
259
260 slimming_helper.ExtraVariables += [
261 ".".join(
262 [
263 "AntiKt4EMPFlowJets",
264 "GhostTower",
265 "IsoFixedCone5Pt",
266 "IsoFixedCone5PtPUsub",
267 "constituentLinks",
268 ]
269 ),
270 "AntiKt4EMTopoJets.IsoFixedCone5Pt.IsoFixedCone5PtPUsub.constituentLinks",
271 f"{LARGE_R_JETS}.SizeParameter.GhostTrack.constituentLinks",
272 "GSFTrackParticles.particleHypothesis.vx.vy.vz",
273 "PrimaryVertices.x.y.z.covariance.trackWeights",
274 "TauJets.clusterLinks",
275 ".".join(
276 [
277 "Muons",
278 "energyLossType",
279 "EnergyLoss",
280 "ParamEnergyLoss",
281 "MeasEnergyLoss",
282 "EnergyLossSigma",
283 "MeasEnergyLossSigma",
284 "ParamEnergyLossSigmaPlus",
285 "ParamEnergyLossSigmaMinus",
286 "clusterLinks",
287 "FSR_CandidateEnergy",
288 ]
289 ),
290 "MuonSegments.x.y.z.px.py.pz",
291 ]
292
293 addOriginCorrectedClustersToSlimmingTool(slimming_helper, writeLC=True, writeEM=True)
294
295 if flags.Input.isMC:
296 slimming_helper.AllVariables += [
297 "TruthTopQuarkWithDecayParticles",
298 "TruthTopQuarkWithDecayVertices",
299 ]
300
301 slimming_helper.SmartCollections += [
302 "AntiKt4TruthWZJets",
303 "AntiKt10TruthJets",
304 "AntiKt10TruthDressedWZSoftDropBeta100Zcut10Jets",
305 ]
306
307 slimming_helper.ExtraVariables += [
308 "AntiKt10TruthSoftDropBeta100Zcut10Jets.SizeParameter.constituentLinks",
309 "AntiKt10TruthDressedWZSoftDropBeta100Zcut10Jets.constituentLinks",
310 "AntiKt10TruthDressedWZJets.constituentLinks",
311 "AntiKt10TruthJets.constituentLinks",
312 "AntiKt4TruthWZJets.IsoFixedCone5Pt.constituentLinks",
313 "AntiKt4TruthDressedWZJets.IsoFixedCone5Pt.constituentLinks",
314 ".".join(
315 [
316 LARGE_R_JETS,
317 "GhostTQuarksFinalCount",
318 "GhostHBosonsCount",
319 "GhostZBosonsCount",
320 "GhostWBosonsCount",
321 ]
322 ),
323 ".".join(
324 [
325 LARGE_R_JETS,
326 "GhostTQuarksFinalPt",
327 "GhostHBosonsPt",
328 "GhostZBosonsPt",
329 "GhostWBosonsPt",
330 ]
331 ),
332 f"{LARGE_R_JETS}.GhostBHadronsFinalPt.GhostCHadronsFinalPt",
333 ]
334
335
336def _drop_track_variables(item_list: list[str], variables: list[str]) -> list[str]:
337 """Drop aux variables from the InDetTrackParticles output item."""
338 dropped = ".".join("-" + variable for variable in variables)
339
340 def drop(item: str) -> str:
341 if "#InDetTrackParticlesAux." not in item:
342 return item
343 sep = "" if item.endswith("Aux.") else "."
344 return item + sep + dropped
345
346 return [drop(item) for item in item_list]
347
348
350 flags: AthConfigFlags,
351 name: str = "HID1Kernel",
352 **kwargs: Any,
353) -> ComponentAccumulator:
354 """Configure the derivation kernel for HID1."""
355 acc = ComponentAccumulator()
356
357 acc.merge(
358 PhysCommonAugmentationsCfg(
359 flags=flags,
360 TriggerListsHelper=kwargs["trigger_lists_helper"],
361 )
362 )
363
364 # Setup the derivation kernel
365 acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name=name))
366
367 # Configure extra reconstruction of jets
368 acc.merge(HID1ExtraContentCfg(flags))
369 return acc
370
371
373 flags: AthConfigFlags,
374 name_tag: str = "HID1",
375 extra_SmartCollections: list[str] | None = None,
376 extra_AllVariables: list[str] | None = None,
377 trigger_lists_helper: TriggerListsHelper | None = None,
378 keep_truth_collections: bool = True,
379 keep_track_covariance_offdiag: bool = True,
380 tau_as_smart_collection: bool = False,
381 compress_gn3_latent: bool = True,
382) -> ComponentAccumulator:
383 """Configure HID1 slimming and output content."""
384 if extra_SmartCollections is None:
385 extra_SmartCollections = []
386 if extra_AllVariables is None:
387 extra_AllVariables = []
388
389 acc = ComponentAccumulator()
390
391 slimming_helper = SlimmingHelper(
392 inputName=name_tag + "SlimmingHelper",
393 NamesAndTypes=flags.Input.TypedCollections,
394 flags=flags,
395 )
396
397 # Initialise explicit lists
398 slimming_helper.SmartCollections = []
399 slimming_helper.AllVariables = []
400 slimming_helper.ExtraVariables = []
401
403 flags=flags,
404 acc=acc,
405 slimming_helper=slimming_helper,
406 keep_truth_collections=keep_truth_collections,
407 tau_as_smart_collection=tau_as_smart_collection,
408 )
409
411 flags=flags,
412 slimming_helper=slimming_helper,
413 )
414
415 # User-provided extras
416 for container in extra_SmartCollections:
417 if container not in slimming_helper.SmartCollections:
418 slimming_helper.SmartCollections.append(container)
419
420 for container in extra_AllVariables:
421 if container not in slimming_helper.AllVariables:
422 slimming_helper.AllVariables.append(container)
423
424 # Append-to-dictionary updates
425 update_append_to_dictionary_in_slimming_helper(
426 flags=flags,
427 slimming_helper=slimming_helper,
428 extra_append_to_dictionary=VR_JET_APPEND_TO_DICTIONARY,
429 )
430
431 # Trigger content
432 trigger_setup(slimming_helper=slimming_helper)
433 trigger_matching(
434 flags=flags,
435 slimming_helper=slimming_helper,
436 trigger_lists_helper=trigger_lists_helper,
437 )
438
439 # Output stream
440 item_list = slimming_helper.GetItemList()
441 item_list = _drop_track_variables(item_list, POORMAN_IP_VARS)
442
443 if not keep_track_covariance_offdiag:
444 item_list = _drop_track_variables(item_list, ["definingParametersCovMatrixOffDiag"])
445
446 gn3_latent_compression = []
447 if compress_gn3_latent:
448 gn3_latent_compression = [
449 "xAOD::AuxContainerBase!#AntiKt4EMPFlowJetsAux." + ".".join(GN3_LATENT_VARS)
450 ]
451
452 acc.merge(
453 OutputStreamCfg(
454 flags=flags,
455 streamName="DAOD_" + name_tag,
456 ItemList=item_list,
457 AcceptAlgs=[name_tag + "Kernel"],
458 CompressionListHigh=gn3_latent_compression,
459 )
460 )
461
462 acc.merge(
463 SetupMetaDataForStreamCfg(
464 flags=flags,
465 streamName="DAOD_" + name_tag,
466 AcceptAlgs=[name_tag + "Kernel"],
467 createMetadata=[
468 MetadataCategory.CutFlowMetaData,
469 MetadataCategory.TruthMetaData,
470 ],
471 )
472 )
473
474 return acc
475
476
477def HID1ExtraContentCfg(flags: AthConfigFlags) -> ComponentAccumulator:
478 """Configure extra reconstructed jet content for HID1."""
479 acc = ComponentAccumulator()
480
481 jet_list = [AntiKt4LCTopo]
482 if flags.Input.isMC:
483 jet_list += [AntiKt10TruthDressedWZSoftDrop]
484
485 for jet_def in jet_list:
486 acc.merge(JetRecCfg(flags, jet_def))
487
488 # Variable-R EMPFlow jets (low-pT-wide, shrinking to 0.4) + soft-lepton association
489 acc.merge(VRFtagJetsCfg(flags))
490
491 # More detailed truth information
492 if flags.Input.isMC:
493 acc.merge(AddTopQuarkAndDownstreamParticlesCfg(flags))
494 acc.merge(
495 AddTruthCollectionNavigationDecorationsCfg(
496 flags,
497 TruthCollections=[
498 "TruthTopQuarkWithDecayParticles",
499 "TruthBosonsWithDecayParticles",
500 ],
501 prefix="Top",
502 )
503 )
504
505 return acc
506
507
509 flags: AthConfigFlags,
510 name_tag: str = "HID1",
511) -> ComponentAccumulator:
512 """Configure the full HID1 derivation."""
513 acc = ComponentAccumulator()
514
515 trigger_lists_helper = TriggerListsHelper(flags)
516
517 acc.merge(
519 flags=flags,
520 name=name_tag + "Kernel",
521 StreamName="StreamDAOD_" + name_tag,
522 trigger_lists_helper=trigger_lists_helper,
523 )
524 )
525
526 acc.merge(
528 flags=flags,
529 name_tag=name_tag,
530 trigger_lists_helper=trigger_lists_helper,
531 )
532 )
533
534 return acc
ComponentAccumulator HID1Cfg(AthConfigFlags flags, str name_tag="HID1")
Definition HID1.py:511
ComponentAccumulator HID1ExtraContentCfg(AthConfigFlags flags)
Definition HID1.py:477
None _add_ftag_content(AthConfigFlags flags, ComponentAccumulator acc, SlimmingHelper slimming_helper, bool keep_truth_collections=True, bool tau_as_smart_collection=False)
Definition HID1.py:101
None _add_jet_content(AthConfigFlags flags, SlimmingHelper slimming_helper)
Definition HID1.py:231
ComponentAccumulator HID1CoreCfg(AthConfigFlags flags, str name_tag="HID1", list[str]|None extra_SmartCollections=None, list[str]|None extra_AllVariables=None, TriggerListsHelper|None trigger_lists_helper=None, bool keep_truth_collections=True, bool keep_track_covariance_offdiag=True, bool tau_as_smart_collection=False, bool compress_gn3_latent=True)
Definition HID1.py:382
list[str] _drop_track_variables(list[str] item_list, list[str] variables)
Definition HID1.py:336
ComponentAccumulator HID1KernelCfg(AthConfigFlags flags, str name="HID1Kernel", **Any kwargs)
Definition HID1.py:353