ATLAS Offline Software
TLABuildingSequences.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 #
4 import functools
5 from TriggerMenuMT.HLT.Config.MenuComponents import ChainStep
6 from AthenaCommon.Logging import logging
7 from ..Jet.JetChainConfiguration import JetChainConfiguration
8 from ..Photon.PrecisionPhotonTLAMenuSequenceConfig import PhotonTLAMenuSequenceGenCfg
9 from ..Jet.JetTLASequenceConfig import JetTLAMenuSequenceGenCfg
10 from ..Muon.MuonTLASequenceConfig import MuonTLAMenuSequenceGenCfg
11 log = logging.getLogger(__name__)
12 
13 
14 def addTLAStep(flags, chain, chainDict):
15  '''
16  Add one extra chain step for TLA Activities
17  '''
18 
19  tlaSequencesList = []
20  log.debug("addTLAStep: processing chain: %s", chainDict['chainName'])
21 
22 
23  for cPart in chainDict['chainParts']:
24 
25  log.debug("addTLAStep: processing signature: %s", cPart['signature'] )
26  # call the sequence from their respective signatures
27  tlaSequencesList.append(functools.partial(getTLASignatureSequenceGenCfg, flags, chainDict=chainDict, chainPart=cPart))
28 
29  log.debug("addTLAStep: About to add a step with: %d parallel sequences.", len(tlaSequencesList))
30 
31  # we add one step per TLA chain, with sequences matching the list of signatures
32  # and multiplicities matching those of the previous step of the chain (already merged if combined)
33  prevStep = chain.steps[-1]
34  stepName = 'TLAStep_{:s}'.format(prevStep.name)
35  step = ChainStep(name = stepName,
36  Sequences = tlaSequencesList,
37  multiplicity = prevStep.multiplicity,
38  chainDicts = prevStep.stepDicts)
39 
40  log.debug("addTLAStep: About to add step %s ", stepName)
41  chain.steps.append(step)
42 
43 
44 
45 def getTLASignatureSequenceGenCfg(flags, chainDict, chainPart):
46  # Here we simply retrieve the TLA sequence from the existing signature code
47  signature= chainPart['signature']
48 
49  if signature == 'Photon':
50  photonOutCollectionName = "HLT_egamma_Photons"
51  return PhotonTLAMenuSequenceGenCfg(flags, photonsIn=photonOutCollectionName)
52 
53  elif signature == 'Muon':
54  return MuonTLAMenuSequenceGenCfg(flags, muChainPart=chainPart)
55 
56  elif signature == 'Jet' or signature == 'Bjet':
57  # Use the jet reco machinery to define the jet collection
58  jetChainConfig = JetChainConfiguration(chainDict)
59  jetChainConfig.prepareDataDependencies(flags)
60  jetInputCollectionName = jetChainConfig.jetName
61  log.debug(f"TLA jet input collection = {jetInputCollectionName}")
62 
63  # Turn off b-tagging for jets that have no tracks anyway - we want to avoid
64  # adding a TLA AntiKt4EMTopoJets_subjetsIS BTagging container in the EDM.
65  # We do not switch off BTag recording for Jet signatures as both Jet and Bjet signature
66  # will use the same hypo alg, so it needs to be configured the same!
67  # Thus, BTag recording will always run for PFlow jets, creating an empty container if no btagging exists.
68  attachBtag = True
69  if jetChainConfig.recoDict["trkopt"] == "notrk": attachBtag = False
70  return JetTLAMenuSequenceGenCfg(flags, jetsIn=jetInputCollectionName, attachBtag=attachBtag)
71 
72 
73 def findTLAStep(chainConfig):
74  tlaSteps = [s for s in chainConfig.steps if 'TLAStep' in s.name and 'EmptyPEBAlign' not in s.name and 'EmptyTLAAlign' not in s.name and 'PEBInfoWriter' not in s.name]
75  if len(tlaSteps) == 0:
76  return None
77  elif len(tlaSteps) > 1:
78  raise RuntimeError('Multiple TLA steps in one chain are not supported. ', len(tlaSteps), ' were found in chain ' + chainConfig.name)
79  return tlaSteps[0]
80 
81 
82 def alignTLASteps(chain_configs, chain_dicts):
83 
84  all_tla_chain_configs = [ch for ch in chain_configs if 'PhysicsTLA' in chain_dicts[ch.name]['eventBuildType']]
85 
86  def getTLAStepPosition(chainConfig):
87  tlaStep = findTLAStep(chainConfig)
88  log.debug('getTLAStepPosition found step %s and return %d',tlaStep,chainConfig.steps.index(tlaStep) + 1)
89  return chainConfig.steps.index(tlaStep) + 1
90 
91  # First loop to find the maximal TLA step positions to which we need to align
92  maxTLAStepPosition = 0 # {eventBuildType: N}
93  for chain in all_tla_chain_configs:
94  tlaStepPosition = getTLAStepPosition(chain)
95  if tlaStepPosition > maxTLAStepPosition:
96  maxTLAStepPosition = tlaStepPosition
97 
98  log.debug('maxTLAStepPosition=%d',maxTLAStepPosition)
99 
100  # Second loop to insert empty steps before the TLA steps where needed
101  for chain in all_tla_chain_configs:
102  tlaStepPosition = getTLAStepPosition(chain)
103  log.debug('Aligning TLA step at step %d for chain %s ', tlaStepPosition, chain.name)
104  if tlaStepPosition < maxTLAStepPosition:
105  numStepsNeeded = maxTLAStepPosition - tlaStepPosition
106  log.debug('Aligning TLA step for chain %s by adding %d empty steps', chain.name, numStepsNeeded)
107  chain.insertEmptySteps('EmptyTLAAlign', numStepsNeeded, tlaStepPosition-1)
108  chain.numberAllSteps()
vtune_athena.format
format
Definition: vtune_athena.py:14
python.HLT.Jet.JetTLASequenceConfig.JetTLAMenuSequenceGenCfg
def JetTLAMenuSequenceGenCfg(flags, jetsIn, attachBtag=True)
Definition: JetTLASequenceConfig.py:32
PrecisionPhotonTLAMenuSequenceConfig.PhotonTLAMenuSequenceGenCfg
def PhotonTLAMenuSequenceGenCfg(flags, photonsIn)
Definition: PrecisionPhotonTLAMenuSequenceConfig.py:26
python.HLT.CommonSequences.TLABuildingSequences.addTLAStep
def addTLAStep(flags, chain, chainDict)
Definition: TLABuildingSequences.py:14
python.HLT.Jet.JetChainConfiguration.JetChainConfiguration
Definition: JetChainConfiguration.py:32
python.HLT.CommonSequences.TLABuildingSequences.getTLASignatureSequenceGenCfg
def getTLASignatureSequenceGenCfg(flags, chainDict, chainPart)
Definition: TLABuildingSequences.py:45
python.HLT.CommonSequences.TLABuildingSequences.alignTLASteps
def alignTLASteps(chain_configs, chain_dicts)
Definition: TLABuildingSequences.py:82
python.HLT.CommonSequences.TLABuildingSequences.findTLAStep
def findTLAStep(chainConfig)
Definition: TLABuildingSequences.py:73
python.HLT.Muon.MuonTLASequenceConfig.MuonTLAMenuSequenceGenCfg
def MuonTLAMenuSequenceGenCfg(flags, muChainPart)
Definition: MuonTLASequenceConfig.py:40