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