ATLAS Offline Software
StandardJetContext.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 """
3 This module defines the standard 'jet contexts'.
4 A jet context is a set of options (mainly related to Tracks) shared by several
5 components (modifier tools, input tools/algs, ...).
6 
7 Other contexts are expected to be defined, for example in the trigger to deal with oher track collection, or for
8 analysis having non-default PV0 choices.
9 
10 Setting a context to a JetDefinition ensures identical properties are consistently set across the components configured by the JetDefinition.
11 
12 Contexts are defined as dictionaries and are centralized under the AthConfigFlags used to configure the jobs under 'flags.Jet.Context'.
13 """
14 from JetRecConfig.Utilities import ldict
15 from AthenaConfiguration.Enums import LHCPeriod
16 from PyUtils.moduleExists import moduleExists
17 
18 from AthenaConfiguration.AthConfigFlags import AthConfigFlags
19 
21  flags = AthConfigFlags()
22 
23  #***********************
24  run3context=ldict(
25  Tracks = "InDetTrackParticles",
26  JetTracks = "JetSelectedTracks", #used for e.g. ghost tracks (no track quality criteria applied)
27  JetTracksQualityCuts = "JetSelectedTracks_trackSelOpt", #used for track-jets (trackSelOpt quality criteria applied)
28  Vertices = "PrimaryVertices",
29  TVA = "JetTrackVtxAssoc",
30  GhostTracks = "PseudoJetGhostTrack",
31  GhostTracksLabel = "GhostTrack",
32  EventDensity = "EventDensity",
33  GhostTrackCutLevel = 'NoCut', # The track selection level for ghost-associated tracks. This is different from the cutlevel we apply when performing actual calculations such as JVT or tack moments.
34 
35  # options passed to InDet::InDetTrackSelectionTool.
36  # Note : these are the standard options used for track calculations. Tracks selected for ghost-associaton have CutLevel=NoCut by default : see ghostTrackCutLevel above
37  trackSelOptions = ldict( CutLevel = "Loose", minPt=500, maxAbsEta=2.5 ),
38  )
39 
40  flags.addFlag("Jet.Context.Run3" , run3context)
41  #***********************
42  flags.addFlag("Jet.Context.Run4" , run3context.clone(
43  trackSelOptions = run3context["trackSelOptions"].clone(maxAbsEta=4.0) # set range of track selection up to eta=4
44  ))
45  flags.addFlag("Jet.Context.HL_LHC", flags.Jet.Context.Run4)
46 
47  #***********************
48  # The default context is Run3 or Run4 according to other global flags :
49  def _defaultFlag(prevFlags):
50  try:
51  run = prevFlags.GeoModel.Run
52  except (ValueError, RuntimeError) : # several exceptions can be thrown... catch any of them
53  # No GeoModel.Run -> we are in a Truth job, return an empty context.
54  return {}
55  return prevFlags.Jet.Context.Run3 if run <= LHCPeriod.Run3 else prevFlags.Jet.Context.Run4
56  flags.addFlag("Jet.Context.default", _defaultFlag)
57 
58 
59 
60 
61  #***********************
62  # Alternative context for AntiKt4LCTopo_EleRM jets used for the electron removed tau reconstruction
63  flags.addFlag("Jet.Context.EleRM" , run3context.clone(
64  Tracks = "InDetTrackParticles_EleRM",
65  TVA = "JetTrackVtxAssoc_EleRM",
66  JetTracks = "JetSelectedTracks_EleRM",
67  GhostTracks = "PseudoJetGhostTrack_EleRM",
68  EventDensity = "EleRM_EventDensity",
69  ))
70 
71 
72  #**********************************
73  # This is not a jet context, but the list of keys related to track (Used in trigger config).
74  # We store it under Context since it is a related central place.
75  flags.addFlag("Jet.Context.CommonTrackKeys",["Tracks", "Vertices", "TVA", "GhostTracks", "GhostTracksLabel", "JetTracks", "JetTracksQualityCuts"],)
76 
77 
78  # ****************
79  # Add Jet trigger context :
80  if moduleExists("TriggerMenuMT"):
81  from TriggerMenuMT.HLT.Jet.JetRecoCommon import addJetContextFlags
82  addJetContextFlags(flags)
83 
84  # ****************
85  # Add HIGG1D1 context :
86  if moduleExists("DerivationFrameworkHiggs"):
87  from DerivationFrameworkHiggs.HIGG1D1CustomJetsConfig import addJetContextFlags
88  addJetContextFlags(flags)
89 
90  return flags
91 
92 
93 
94 def propFromContext(propName):
95  """Some properties might depend on the context for which jets are configured.
96  This function returns a helper function which gives the value of the property propName according to the jet context.
97  """
98  def getProp(jetdef, spec):
99  contextDic = jetdef._contextDic
100  if isinstance(spec, str):
101  # user may have passed explicitly a str : allow to force an other context if jetdef.context if non void
102  contextDic = jetdef._cflags.Jet.Context[spec or jetdef.context]
103  return contextDic[propName]
104  return getProp
105 
106 def inputsFromContext(inputKey, prefix="", suffix=""):
107  """Some prerequisites might depend on the context for which jets are configured.
108  This function returns a helper function which gives a list of input prerequisites according to 'inputKey' in the current jetdef.context.
109  """
110  def getPrereqs(jetdef):
111  return f"input:{prefix}{jetdef._contextDic[inputKey]}{suffix}"
112  return getPrereqs
python.StandardJetContext.createJetContextFlags
def createJetContextFlags()
Definition: StandardJetContext.py:20
python.Utilities.clone
clone
Definition: Utilities.py:134
python.StandardJetContext.inputsFromContext
def inputsFromContext(inputKey, prefix="", suffix="")
Definition: StandardJetContext.py:106
python.HIGG1D1CustomJetsConfig.addJetContextFlags
def addJetContextFlags(flags)
Definition: HIGG1D1CustomJetsConfig.py:12
python.StandardJetContext.propFromContext
def propFromContext(propName)
Definition: StandardJetContext.py:94
python.moduleExists.moduleExists
def moduleExists(modName)
Definition: moduleExists.py:13