3 """ Helper functions for configuring MET chains"""
5 from __future__
import annotations
6 from typing
import Any, Optional
8 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
9 from AthenaConfiguration.ComponentFactory
import CompFactory
10 from ..Menu.SignatureDicts
import METChainParts_Default, METChainParts
11 from ..Config.MenuComponents
import (
17 from .StepOutput
import StepOutput
19 from ..CommonSequences.FullScanDefs
import trkFSRoI
20 from AthenaCommon.Logging
import logging
21 from TrigEFMissingET.TrigEFMissingETConfig
import getMETMonTool
22 from abc
import ABC, abstractmethod
23 from string
import ascii_uppercase
24 from TrigMissingETHypo.TrigMissingETHypoConfig
import TrigMETHypoToolFromDict
25 from DecisionHandling.DecisionHandlingConfig
import ComboHypoCfg
29 return CompFactory.TrigStreamerHypoTool(chainDict[
"chainName"])
32 log = logging.getLogger(__name__)
46 metFSRoIs: list[str |
None] = [
"",
None, trkFSRoI]
50 """Convert a dictionary containing reconstruction keys to a string
52 Any key (from recoKeys) missing will just be skipped.
56 recoDict : dict[str, str]
57 The reconstruction dictionary
58 skipDefaults : bool, optional
59 If true, skip any values that match the default, by default True
64 The fixed string representation
70 and (
not skipDefaults
or recoDict[k] != METChainParts_Default[k])
75 """Convert a string to a MET reco dict. Optionally only keep entries contained in recoKeys.
76 Necessary for correctly configuring algorithms as inputs to NN.
78 defaults =
copy(METChainParts_Default)
80 defaults = {key: defaults[key]
for key
in recoKeys}
82 for part
in string.split(
"_"):
83 for key, values
in METChainParts.items():
84 if not isinstance(values, list):
87 if isinstance(defaults[key], list):
95 """Base class to describe algorithm configurations
97 Each individual 'EFrecoAlg' should be described by *one* AlgConfig subclass.
98 It must provide its list of required inputs to the constructor and override
101 The name of fexAlg *must* be self.fexName and the METContainerKey property
102 *must* be set to self.outputKey (but this class usually should take care of
105 The subclass must also implement the @classmethod 'algType' which returns
106 the EFrecoAlg string that it describes.
111 """The algorithm that this object configures - this corresponds to the
112 EFrecoAlg in the METChainParts dictionary
114 Note that no two subclasses of AlgConfig can describe the same algorithm
115 (as identified by this string).
117 raise NotImplementedError(
"algType not implemented by subclass!")
120 """Initialise the base class
125 recoDict: Pass *all* the keys required for the recoDict
131 assert all(k
in recoDict
for k
in recoKeys), (
132 f
"AlgConfig.__init__ for {alg_type} did not receive all the recoKeys"
133 " - this suggests a problem in the subclass __init__ method!"
140 """The MET container object produced by this algorithm"""
141 from TrigEDMConfig.TriggerEDM
import recordable
147 """The name of the algorithm made by this configuration"""
151 """Return a version of the reco dict with any necessary post-processing"""
155 """Create the monitoring tool"""
159 return f
"step{ascii_uppercase[idx]}_{self._suffix}"
163 """Create the reconstruction sequences including the FEX
165 Returns a list of CAs split by step
168 def _append_fex(self, flags, fex, inputs: Optional[StepOutput] =
None) ->
None:
169 """Append the FEX to the output object
171 Finalizes the FEX by setting the monitoring tool and output name.
173 fex.MonTool = self.getMonTool(flags)
174 fex.METContainerKey = self.outputKey
176 acc.addEventAlgo(fex, primary=
True)
177 return StepOutput.create(acc, inputs, MET=self.outputKey)
180 """Make the reconstruction sequences for the new JO style"""
182 log.verbose(
"Create inputs for %s", self.
_suffix)
183 steps, inputs = self.inputRegistry.build_steps(
184 flags, self._inputs, metFSRoIs, self.
recoDict, return_ca=
True
187 fex = self.make_fex_accumulator(flags, self.
fexName, inputs)
190 steps[-1].addEventAlgo(fex)
194 """Make the full accumulator steps"""
202 for step_idx, reco_sequence
in enumerate(reco_sequences):
205 step_name = f
"Empty_METStep{step_idx}"
209 if step_idx == len(reco_sequences) - 1:
212 hypo_tool = TrigMETHypoToolFromDict
216 hypo_tool = streamer_hypo_tool
219 reco_acc.mergeReco(reco_sequence)
222 sel_acc = SelectionCA(
"METAthSeq_" + self.
name_step(step_idx))
224 sel_acc.mergeReco(reco_acc)
226 sel_acc.addHypoAlgo(hypo_alg)
233 step_name = sel_acc.name
239 chainDicts=[chainDict],
243 functools.partial(make_MET_menu_sequenceGenCfg, flags, sel_acc, hypo_tool)
245 comboHypoCfg=ComboHypoCfg,
246 isEmpty=
True if sel_acc
is None else False
254 """The hypo alg used for this configuration"""
255 return CompFactory.TrigMissingETHypoAlg(
256 f
"METHypoAlg_{self._suffix}", METContainerKey=self.
outputKey
260 return CompFactory.TrigStreamerHypoAlg(
261 "METPassThroughHypo_" + self.
name_step(step)
265 """Get the InEventRecoCA for the given step index"""
266 from TrigT2CaloCommon.CaloDef
import clusterFSInputMaker
267 from AthenaConfiguration.ComponentFactory
import CompFactory
268 from ..CommonSequences.FullScanDefs
import trkFSRoI
276 return InEventRecoCA(
278 inputMaker=CompFactory.InputMakerForRoI(
279 "IM_Jet_TrackingStep",
280 RoITool=CompFactory.ViewCreatorInitialROITool(),
285 raise KeyError(f
"No input maker for step {idx}")
289 """Provides a way to iterate over all subclasses of this class"""
290 for subcls
in cls.__subclasses__():
291 for subsubcls
in subcls.__subclasses__():
298 if subcls.algType() == EFrecoAlg:
299 return subcls(EFrecoAlg=EFrecoAlg, **recoDict)
301 raise ValueError(
"Unknown EFrecoAlg '{}' requested".
format(EFrecoAlg))
304 return MenuSequence(flags, selectionCA=sel_acc, HypoToolGen=hypo_tool)
307 from .
import AlgConfigs
310 AlgConfigs.test_configs()