ATLAS Offline Software
Loading...
Searching...
No Matches
TopoAlgos.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3from AthenaCommon.Logging import logging
4import re
5
6from .ThresholdType import ThrType
7
8log = logging.getLogger(__name__)
9
10
16
18
19 _availableVars = []
20
21 #__slots__ = ['_name', '_selection', '_value', '_generic']
22 def __init__(self, classtype, name):
23 self.classtype = classtype
24 self.name = name
25 self.generics = []
26 self.variables = []
27
28 def __str__(self):
29 return self.name
30
31 def isSortingAlg(self):
32 return False
33
34 def isDecisionAlg(self):
35 return False
36
38 return False
39
40 def setThresholds(self, thresholds):
41 # link to all thresholds in the menu need for configuration
42 self.menuThr = thresholds
43
44 def addvariable(self, name, value, selection = -1):
45 if name in self._availableVars:
46 self.variables += [ Variable(name, selection, value) ]
47 else:
48 raise RuntimeError("Variable parameter '%s' does not exist for algorithm %s of type %s,\navailable parameters are %r" % (name,self.name, self.classtype, self._availableVars))
49 return self
50
51 def addgeneric(self, name, value):
52 if name in self._availableVars:
53 self.generics += [ Generic(name, value) ]
54 else:
55 raise RuntimeError("Generic parameter '%s' does not exist for algorithm %s of type %s,\navailable parameters are %r" % (name,self.name, self.classtype, self._availableVars))
56 return self
57
58 def json(self):
59 confObj = {
60 "klass": self.classtype
61 }
62 return confObj
63
64 def getScaleToCountsEM(self): # legacy Et conversion!!
65 tw = self.menuThr.typeWideThresholdConfig(ThrType["EM"])
66 return 1000 // tw["resolutionMeV"]
67
69 def __init__(self, name, selection, value):
70 self.name = name
71 self.selection = int(selection)
72 self.value = int(value)
73
75 def __init__(self, name, value):
76 self.name = name
77 from L1TopoHardware.L1TopoHardware import HardwareConstrainedParameter
78 if isinstance(value,HardwareConstrainedParameter):
79 self.value = ":%s:" % value.name
80 else:
81 self.value = value
82
83
85
86 def __init__(self, classtype, name, inputs, outputs):
87 super(SortingAlgo, self).__init__(classtype=classtype, name=name)
88 self.inputs = inputs
89 self.outputs = outputs
90 self.inputvalue= self.inputs
91 if self.inputs.find("Cluster")>=0: # to extract inputvalue (for FW) from output name
92 if self.outputs.find("TAU")>=0:
93 self.inputvalue= self.inputvalue.replace("Cluster","Tau")
94 if self.outputs.find("EM")>=0:
95 self.inputvalue= self.inputvalue.replace("Cluster","Em")
96
97 def isSortingAlg(self):
98 return True
99
100 def json(self):
101 confObj = super(SortingAlgo, self).json()
102 confObj["input"] = self.inputvalue
103 confObj["output"] = self.outputs
104 confObj["fixedParameters"] = {}
105 confObj["fixedParameters"]["generics"] = {}
106 for (pos, genParm) in enumerate(self.generics):
107 confObj["fixedParameters"]["generics"][genParm.name] = {"value": genParm.value, "position": pos}
108
109 confObj["variableParameters"] = list()
110 _emscale_for_decision = self.getScaleToCountsEM() # for legacy algos
111 _mu_for_decision= 10 # MU4->3GeV, MU6->5GeV, MU10->9GeV because selection is done by pt>X in 100 MeV units for Run3 muons
112 if "MUCTP-" in self.name:
113 _mu_for_decision= 1
114 for (pos, variable) in enumerate(self.variables):
115 if variable.name == "MinET" or variable.name == "MinEtTGC" or variable.name == "MinEtRPC":
116 if "e" in self.outputs or "j" in self.outputs or "g" in self.outputs:
117 variable.value *= 1 # no conversion needed in Run3 algo
118 elif "TAU" in self.outputs or "EM" in self.outputs:
119 variable.value *= _emscale_for_decision
120 if "MU" in self.outputs:
121 variable.value = ((variable.value - _mu_for_decision ) if variable.value>0 else variable.value)
122 confObj["variableParameters"].append({"name": variable.name, "value": variable.value})
123
124 if type(variable.value) is float:
125 raise RuntimeError("In algorithm %s the variable %s with value %r is of type float but must be int" % (self.name,variable.name,variable.value))
126 return confObj
127
128
130
131 def __init__(self, classtype, name, inputs, outputs):
132 super(DecisionAlgo, self).__init__(classtype=classtype, name=name)
133 self.inputs = inputs if type(inputs)==list else [inputs]
134 self.outputs = outputs if type(outputs)==list else [outputs]
135
136 def isDecisionAlg(self):
137 return True
138
139 def json(self):
140 confObj = super(DecisionAlgo, self).json()
141 confObj["input"] = self.inputs # list of input names
142 confObj["output"] = self.outputs # list of output names
143 # fixed parameters
144 confObj["fixedParameters"] = {}
145 confObj["fixedParameters"]["generics"] = {}
146 for (pos, genParm) in enumerate(self.generics):
147 confObj["fixedParameters"]["generics"][genParm.name] = {"value": genParm.value, "position": pos}
148
149 # variable parameters
150 confObj["variableParameters"] = list()
151 _emscale_for_decision = self.getScaleToCountsEM() # for legacy algos
152 _mu_for_decision= 1 # MU4->3GeV, MU6->5GeV, MU10->9GeV because selection is done by pt>X in 100 MeV units for Run3 muons
153 if "MUCTP-" in self.name:
154 _mu_for_decision= 1
155 for (pos, variable) in enumerate(self.variables):
156 # scale MinET if inputs match with EM or TAU
157 for _minet in ["MinET"]:
158 if variable.name==_minet+"1" or variable.name==_minet+"2" or variable.name==_minet+"3" or variable.name==_minet:
159 for (tobid, _input) in enumerate(self.inputs):
160 if (_input.find("e")>=0 or _input.find("j")>=0 or _input.find("g")>=0):
161 variable.value *= 1 # no conversion needed in Run3 algo
162 elif (_input.find("TAU")>=0 or _input.find("EM")>=0):
163 if (len(self.inputs)>1 and (variable.name==_minet+str(tobid+1) or (tobid==0 and variable.name==_minet))) or (len(self.inputs)==1 and (variable.name.find(_minet)>=0)):
164 variable.value *= _emscale_for_decision
165
166 if _input.find("MU")>=0:
167 if (len(self.inputs)>1 and (variable.name==_minet+str(tobid+1) or (tobid==0 and variable.name==_minet))) or (len(self.inputs)==1 and (variable.name.find(_minet)>=0)):
168 variable.value = ((variable.value - _mu_for_decision ) if variable.value>0 else variable.value)
169
170 if type(variable.value) is float:
171 raise RuntimeError("In algorithm %s the variable %s with value %r is of type float but must be int" % (self.name,variable.name,variable.value))
172
173 if variable.selection >= 0:
174 confObj["variableParameters"].append({"name": variable.name, "selection": variable.selection, "value": variable.value})
175 else:
176 confObj["variableParameters"].append({"name": variable.name, "value": variable.value})
177
178 return confObj
179
180
182
183 def __init__(self, classtype, name, threshold, input, output, nbits):
184 super(MultiplicityAlgo, self).__init__(classtype=classtype, name=name)
185 self.threshold = threshold
186 self.input = input
187 self.outputs = output
188 self.nbits = nbits
189
191 return True
192
194 pass
195
196 def json(self):
197 confObj = super(MultiplicityAlgo, self).json()
198 confObj["threshold"] = self.threshold
199 confObj["input"] = self.input
200 confObj["output"] = self.outputs
201 confObj["nbits"] = self.nbits
202 return confObj
203
204# eEM and jEM
206 def __init__(self, name, threshold, nbits, classtype ):
207 super(EMMultiplicityAlgo, self).__init__(classtype=classtype, name=name,
208 threshold = threshold,
209 input=None, output="%s" % threshold,
210 nbits=nbits)
211 mres = re.match("(?P<type>[A-z]*)[0-9]*(?P<suffix>[VHILMT]*)",threshold).groupdict()
212 self.input = mres["type"].replace('SPARE','')
213
214# eTAU, jTAU, cTAU
216 def __init__(self, name, threshold, nbits, classtype ):
217 super(TauMultiplicityAlgo, self).__init__(classtype=classtype, name=name,
218 threshold = threshold,
219 input=None, output="%s" % threshold,
220 nbits=nbits)
221 mres = re.match("(?P<type>[A-z]*)[0-9]*(?P<suffix>[HLMT]*)",threshold).groupdict()
222 self.input = mres["type"].replace('SPARE','')
223
224# jJ, gJ and gLJ
226 def __init__(self, name, threshold, nbits, classtype ):
227 super(JetMultiplicityAlgo, self).__init__(classtype=classtype, name=name,
228 threshold = threshold,
229 input=None, output="%s" % threshold,
230 nbits=nbits)
231 mres = re.match("(?P<type>[A-z]*)[0-9]*(?P<suffix>[A-z]*)",threshold).groupdict()
232 self.input = mres["type"].replace('SPARE','')
233
234# all XE and TE flavours
236 def __init__(self, name, threshold, nbits, classtype = "EnergyThreshold"):
237 super(XEMultiplicityAlgo, self).__init__( classtype = classtype, name=name,
238 threshold = threshold,
239 input=None, output="%s" % threshold,
240 nbits=nbits)
241 mres = re.match("(?P<type>[A-z]*)[0-9]*(?P<suffix>[A-z]*)",threshold).groupdict()
242 mres["type"] = mres["type"].replace('SPARE','')
243 self.input = mres["type"]
244 self.flavour = mres["type"]
245
246 def json(self):
247 confObj = super(XEMultiplicityAlgo, self).json()
248 confObj["threshold"] = self.threshold
249 confObj["input"] = self.input
250 confObj["output"] = self.outputs
251 confObj["flavour"] = self.flavour
252 confObj["nbits"] = self.nbits
253 return confObj
254
256 def __init__(self, classtype, name, input, output, nbits):
257 super(MuMultiplicityAlgo, self).__init__(classtype=classtype, name=name, input=input, output=output, nbits=nbits)
258
260 pass
261
262class LArSaturationAlgo(MultiplicityAlgo):
263 def __init__(self):
264 name = 'LArSaturation'
265 super(LArSaturationAlgo, self).__init__(name=name, classtype=name, input='jTE', output=name, threshold=name, nbits=1)
266
268 def __init__(self, name):
269 super(ZeroBiasAlgo, self).__init__(name=name, classtype='ZeroBias', input=name, threshold=name, output=name, nbits=1)
270
271
nlohmann::json json
__init__(self, classtype, name, inputs, outputs)
Definition TopoAlgos.py:131
__init__(self, name, threshold, nbits, classtype)
Definition TopoAlgos.py:206
__init__(self, name, value)
Definition TopoAlgos.py:75
__init__(self, name, threshold, nbits, classtype)
Definition TopoAlgos.py:226
__init__(self, classtype, name, input, output, nbits)
Definition TopoAlgos.py:256
__init__(self, classtype, name, threshold, input, output, nbits)
Definition TopoAlgos.py:183
__init__(self, classtype, name, inputs, outputs)
Definition TopoAlgos.py:86
__init__(self, name, threshold, nbits, classtype)
Definition TopoAlgos.py:216
These classes are base classes for the auto-generated algorithm python representations.
Definition TopoAlgos.py:17
addvariable(self, name, value, selection=-1)
Definition TopoAlgos.py:44
__init__(self, classtype, name)
Definition TopoAlgos.py:22
setThresholds(self, thresholds)
Definition TopoAlgos.py:40
addgeneric(self, name, value)
Definition TopoAlgos.py:51
__init__(self, name, selection, value)
Definition TopoAlgos.py:69
__init__(self, name, threshold, nbits, classtype="EnergyThreshold")
Definition TopoAlgos.py:236
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138