ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalAlgorithm.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3from __future__ import annotations
4
5from abc import abstractmethod
6from enum import Enum
7from typing import TYPE_CHECKING, Self
8from AthenaCommon.Logging import logging
9
10if TYPE_CHECKING:
11 from .Thresholds import MenuThresholdsCollection
12 from .Typing import JSONType
13
14log = logging.getLogger(__name__)
15
16# There are different types of global algorithms which run on the Global Event Processor (GEP) in the L1Global Trigger. These algorithms can be categorized into three main types:
17# 1. Reconstruction Algorithms:
18# These algorithms are responsible for reconstructing trigger objects using the raw detector data to
19# refine objects arriving from the FEX-inputs. Examples are cluster makers, jet, met, electron and tau
20# reconstruction algorithms. In the simulation these are implemented as AthAlgorithms
21# 2. Multiplicity Algorithms:
22# These algorithms count the number of trigger objects of a certain type that pass a given threshold.
23# 3. Topological Algorithms:
24# These algorithms perform calculations on the trigger objects (like invariant mass, delta phi, etc.)
25# to determine if they satisfy certain topological conditions.
26# Type 2. and 3. algorithms run inside the GEP Hypothesis block, together they form the L1Global decision. In the simulation these are implemented as AthAlgoTools, all being called by a single AthAlgorithm which simulates the Hypothesis block.
27
28class GlobalAlgType(Enum):
29 RECONSTRUCTION = ('reconstructionAlgorithms')
30 MULTIPLICITY = ('multiplicityAlgorithms')
31 TOPOLOGICAL = ('topologicalAlgorithms')
32 def __init__(self, key: str):
33 self.key: str = key
34
36 """Base class for all global compute algorithms
37
38 These are
39 - the preprocessing algorithms
40 - the multiplicity algorithms (inside the GEP Hypo algorithm)
41 - the topological algorithms (inside the GEP Hypo algorithm)
42 """
43
44 def __init__(self, alg_type: GlobalAlgType, klass: str, name: str):
45 self._alg_type: GlobalAlgType = alg_type # the particular type of global algorithm, see GlobalAlgType
46 self._klass: str = klass # the C++ class name of the algorithm
47 self._name: str = name # the instance name of the algorithm as it appears in the python configuration
48
49 def __str__(self) -> str:
50 return f"{self._name}@{self._klass}"
51
52 @property
53 def name(self) -> str:
54 """The instance name of the algorithm as it appears in the python configuration."""
55 return self._name
56
57 @property
58 def alg_type(self) -> GlobalAlgType:
59 """The particular type of global algorithm, see GlobalAlgType."""
60 return self._alg_type
61
62 @property
63 def klass(self) -> str:
64 """The C++ class name of the algorithm."""
65 return self._klass
66
67 @abstractmethod
68 def json(self) -> JSONType: ...
69
70
72 """Concept of a variable parameter of a global algorithm was carried over from the old L1Topo configuration. This type of parameters can change between configurations without the need to rebuild the firmware. This is because these parameters
73 are loaded into registers in the firmware through the IPBUS.
74 If the Global algorithms will be described this way needs to be decided, but for now we keep this concept.
75 """
76 def __init__(self, name: str, selection, value: JSONType):
77 self.name = name
78 self.selection = int(selection)
79 self.value: JSONType = value
80
82 """Concept of a fixed parameter of a global algorithm was carried over from the old L1Topo configuration. Changing this type of parameters requires a rebuild of the firmware. This is because these parameters determine the firmware layout.
83 If the Global algorithms will be described this way needs to be decided, but for now we keep this concept.
84 """
85 def __init__(self, name: str, value):
86 self.name = name
87 self.value: JSONType
88 from L1TopoHardware.L1TopoHardware import HardwareConstrainedParameter
89 if isinstance(value,HardwareConstrainedParameter):
90 self.value = ":%s:" % value.name
91 else:
92 self.value = value
93
95 """
96 Base class for selection algorithms that run inside the GEP Hypothesis block
97 """
98 def __init__(self, alg_type: GlobalAlgType, klass: str, name: str, wiredInputs: list[list[str]], inputs: list[str], thresholds: list[str]):
99 super().__init__(alg_type=alg_type, klass=klass, name=name)
100 self._fixed_params: dict[str, FixedParam] = {}
101 self._var_params: dict[str, VarParam] = {}
102
103 self.wiredInputs: list[list[str]] = wiredInputs # wired inputs of the algorithm, see derived classes
104 self.add_fixed_parameter('wiredInputs', wiredInputs)
105 self.add_variable_parameter('inputs', inputs)
106 self.add_variable_parameter('thresholds', thresholds)
107
108 def vpar(self, name: str):
109 return self._var_params[name]
110
111 def add_variable_parameter(self, name, value, selection = -1) -> Self:
112 self._var_params[name] = VarParam(name, selection, value)
113 return self
114
115 def add_fixed_parameter(self, name, value) -> Self:
116 self._fixed_params[name] = FixedParam(name, value)
117 return self
118
119 @property
120 def inputs(self) -> list[str]:
121 """The input signals for this algorithm."""
122 return self.vpar('inputs').value # type: ignore
123
124 def json(self) -> JSONType:
125 confObj: JSONType = {
126 "klass": self.klass,
127 "fixedParameters": {
128 k: p.value for (k, p) in self._fixed_params.items()
129 },
130 "variableParameters": {
131 k: p.value for (k, p) in self._var_params.items()
132 }
133 }
134 return confObj
135
137 """
138 Class for describing multiplicity algorithms that run inside the GEP Hypothesis block
139 """
140 def __init__(self, threshold: str, input: str, output: str, nbits: int):
141 super().__init__(alg_type=GlobalAlgType.MULTIPLICITY, klass="GlobalMultiplicityAlgo",
142 name=f'Mult_{threshold}', wiredInputs=[[input]], inputs=[input], thresholds=[threshold])
143 self.menuThr: MenuThresholdsCollection # The collection of thresholds in the menu.
144 self.add_fixed_parameter('nbits', nbits)
145 self._output: str = output
146
147 def output(self) -> str | list[str]:
148 """The output signal for this algorithm."""
149 return self._output
150
151 def setThresholds(self, thresholds: MenuThresholdsCollection):
152 """Sets the link to all thresholds in the menu needed for configuration."""
153 self.menuThr: MenuThresholdsCollection = thresholds
154
156 """
157 Class for describing topological selection algorithms that run inside the GEP Hypothesis block
158 """
159 def __init__(self, name: str, wiredInputs: list[list[str]],
160 inputs: str | list[str], thresholds: str | list[str]):
161 super().__init__(alg_type=GlobalAlgType.TOPOLOGICAL, klass="GlobalDecisionAlgo", name=name, wiredInputs=wiredInputs,
162 inputs=[inputs] if isinstance(inputs, str) else inputs,
163 thresholds=[thresholds] if isinstance(thresholds, str) else thresholds )
164
nlohmann::json json
__init__(self, GlobalAlgType alg_type, str klass, str name)
__init__(self, GlobalAlgType alg_type, str klass, str name, list[list[str]] wiredInputs, list[str] inputs, list[str] thresholds)
Self add_variable_parameter(self, name, value, selection=-1)
__init__(self, str threshold, str input, str output, int nbits)
MenuThresholdsCollection # The collection of thresholds in the menu. menuThr
setThresholds(self, MenuThresholdsCollection thresholds)
__init__(self, str name, list[list[str]] wiredInputs, str|list[str] inputs, str|list[str] thresholds)
__init__(self, str name, selection, JSONType value)