ATLAS Offline Software
TopoAlgos.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon.Logging import logging
4 import re
5 
6 from .ThresholdType import ThrType
7 
8 log = 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 
37  def isMultiplicityAlg(self):
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 
74 class Generic(object):
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 
190  def isMultiplicityAlg(self):
191  return True
192 
193  def configureFromThreshold(self, thr):
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 
259  def configureFromThreshold(self, thr):
260  pass
261 
262 class 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 
python.L1.Base.TopoAlgos.TopoAlgo
These classes are base classes for the auto-generated algorithm python representations.
Definition: TopoAlgos.py:17
python.L1.Base.TopoAlgos.SortingAlgo.__init__
def __init__(self, classtype, name, inputs, outputs)
Definition: TopoAlgos.py:86
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.L1.Base.TopoAlgos.SortingAlgo.inputvalue
inputvalue
Definition: TopoAlgos.py:90
python.L1.Base.TopoAlgos.MultiplicityAlgo.outputs
outputs
Definition: TopoAlgos.py:187
python.L1.Base.TopoAlgos.TopoAlgo.name
name
Definition: TopoAlgos.py:24
python.L1.Base.TopoAlgos.MultiplicityAlgo.__init__
def __init__(self, classtype, name, threshold, input, output, nbits)
Definition: TopoAlgos.py:183
python.L1.Base.TopoAlgos.JetMultiplicityAlgo
Definition: TopoAlgos.py:225
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
python.L1.Base.TopoAlgos.XEMultiplicityAlgo.flavour
flavour
Definition: TopoAlgos.py:244
python.L1.Base.TopoAlgos.LArSaturationAlgo.__init__
def __init__(self)
Definition: TopoAlgos.py:263
python.L1.Base.TopoAlgos.Variable.value
value
Definition: TopoAlgos.py:72
python.L1.Base.TopoAlgos.TopoAlgo.__init__
def __init__(self, classtype, name)
Definition: TopoAlgos.py:22
python.L1.Base.TopoAlgos.TopoAlgo.isDecisionAlg
def isDecisionAlg(self)
Definition: TopoAlgos.py:34
python.L1.Base.TopoAlgos.TopoAlgo.menuThr
menuThr
Definition: TopoAlgos.py:42
python.L1.Base.TopoAlgos.SortingAlgo.isSortingAlg
def isSortingAlg(self)
Definition: TopoAlgos.py:97
python.L1.Base.TopoAlgos.SortingAlgo.json
def json(self)
Definition: TopoAlgos.py:100
python.L1.Base.TopoAlgos.TauMultiplicityAlgo
Definition: TopoAlgos.py:215
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.L1.Base.TopoAlgos.XEMultiplicityAlgo
Definition: TopoAlgos.py:235
python.L1.Base.TopoAlgos.ZeroBiasAlgo
Definition: TopoAlgos.py:267
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.L1.Base.TopoAlgos.Generic
Definition: TopoAlgos.py:74
python.L1.Base.TopoAlgos.JetMultiplicityAlgo.__init__
def __init__(self, name, threshold, nbits, classtype)
Definition: TopoAlgos.py:226
python.L1.Base.TopoAlgos.MuMultiplicityAlgo
Definition: TopoAlgos.py:255
python.L1.Base.TopoAlgos.TopoAlgo.generics
generics
Definition: TopoAlgos.py:25
python.L1.Base.TopoAlgos.SortingAlgo.outputs
outputs
Definition: TopoAlgos.py:89
python.L1.Base.TopoAlgos.TopoAlgo._availableVars
_availableVars
Definition: TopoAlgos.py:19
python.L1.Base.TopoAlgos.SortingAlgo.inputs
inputs
Definition: TopoAlgos.py:88
python.L1.Base.TopoAlgos.DecisionAlgo.isDecisionAlg
def isDecisionAlg(self)
Definition: TopoAlgos.py:136
python.L1.Base.TopoAlgos.MultiplicityAlgo.isMultiplicityAlg
def isMultiplicityAlg(self)
Definition: TopoAlgos.py:190
python.L1.Base.TopoAlgos.MultiplicityAlgo.json
def json(self)
Definition: TopoAlgos.py:196
python.L1.Base.TopoAlgos.MuMultiplicityAlgo.__init__
def __init__(self, classtype, name, input, output, nbits)
Definition: TopoAlgos.py:256
python.L1.Base.TopoAlgos.TopoAlgo.addvariable
def addvariable(self, name, value, selection=-1)
Definition: TopoAlgos.py:44
python.L1.Base.TopoAlgos.MultiplicityAlgo.nbits
nbits
Definition: TopoAlgos.py:188
python.L1.Base.TopoAlgos.TopoAlgo.addgeneric
def addgeneric(self, name, value)
Definition: TopoAlgos.py:51
python.L1.Base.TopoAlgos.DecisionAlgo.__init__
def __init__(self, classtype, name, inputs, outputs)
Definition: TopoAlgos.py:131
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.L1.Base.TopoAlgos.DecisionAlgo.outputs
outputs
Definition: TopoAlgos.py:134
python.L1.Base.TopoAlgos.DecisionAlgo.inputs
inputs
Definition: TopoAlgos.py:133
python.L1.Base.TopoAlgos.TopoAlgo.setThresholds
def setThresholds(self, thresholds)
Definition: TopoAlgos.py:40
python.L1.Base.TopoAlgos.TauMultiplicityAlgo.__init__
def __init__(self, name, threshold, nbits, classtype)
Definition: TopoAlgos.py:216
python.L1.Base.TopoAlgos.MultiplicityAlgo.threshold
threshold
Definition: TopoAlgos.py:185
python.L1.Base.TopoAlgos.Generic.name
name
Definition: TopoAlgos.py:76
python.L1.Base.TopoAlgos.DecisionAlgo
Definition: TopoAlgos.py:129
python.L1.Base.TopoAlgos.TopoAlgo.isSortingAlg
def isSortingAlg(self)
Definition: TopoAlgos.py:31
python.L1.Base.TopoAlgos.TopoAlgo.variables
variables
Definition: TopoAlgos.py:26
python.L1.Base.TopoAlgos.EMMultiplicityAlgo.__init__
def __init__(self, name, threshold, nbits, classtype)
Definition: TopoAlgos.py:206
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.L1.Base.TopoAlgos.MultiplicityAlgo.configureFromThreshold
def configureFromThreshold(self, thr)
Definition: TopoAlgos.py:193
python.L1.Base.TopoAlgos.XEMultiplicityAlgo.__init__
def __init__(self, name, threshold, nbits, classtype="EnergyThreshold")
Definition: TopoAlgos.py:236
python.L1.Base.TopoAlgos.MultiplicityAlgo
Definition: TopoAlgos.py:181
python.L1.Base.TopoAlgos.TopoAlgo.json
def json(self)
Definition: TopoAlgos.py:58
python.L1.Base.TopoAlgos.TopoAlgo.getScaleToCountsEM
def getScaleToCountsEM(self)
Definition: TopoAlgos.py:64
python.L1.Base.TopoAlgos.Generic.value
value
Definition: TopoAlgos.py:79
python.L1.Base.TopoAlgos.Variable
Definition: TopoAlgos.py:68
python.L1.Base.TopoAlgos.SortingAlgo
Definition: TopoAlgos.py:84
pickleTool.object
object
Definition: pickleTool.py:29
python.L1.Base.TopoAlgos.ZeroBiasAlgo.__init__
def __init__(self, name)
Definition: TopoAlgos.py:268
str
Definition: BTagTrackIpAccessor.cxx:11
python.L1.Base.TopoAlgos.Variable.name
name
Definition: TopoAlgos.py:70
python.L1.Base.TopoAlgos.Generic.__init__
def __init__(self, name, value)
Definition: TopoAlgos.py:75
python.L1.Base.TopoAlgos.TopoAlgo.__str__
def __str__(self)
Definition: TopoAlgos.py:28
python.L1.Base.TopoAlgos.DecisionAlgo.json
def json(self)
Definition: TopoAlgos.py:139
python.L1.Base.TopoAlgos.MultiplicityAlgo.input
input
Definition: TopoAlgos.py:186
python.L1.Base.TopoAlgos.TopoAlgo.isMultiplicityAlg
def isMultiplicityAlg(self)
Definition: TopoAlgos.py:37
python.L1.Base.TopoAlgos.Variable.__init__
def __init__(self, name, selection, value)
Definition: TopoAlgos.py:69
python.L1.Base.TopoAlgos.EMMultiplicityAlgo
Definition: TopoAlgos.py:205
python.L1.Base.TopoAlgos.TopoAlgo.classtype
classtype
Definition: TopoAlgos.py:23
python.L1.Base.TopoAlgos.MuMultiplicityAlgo.configureFromThreshold
def configureFromThreshold(self, thr)
Definition: TopoAlgos.py:259
python.L1.Base.TopoAlgos.XEMultiplicityAlgo.json
def json(self)
Definition: TopoAlgos.py:246
python.L1.Base.TopoAlgos.Variable.selection
selection
Definition: TopoAlgos.py:71