ATLAS Offline Software
Functions | Variables
ComboHypoHandling Namespace Reference

Functions

def TrigComboHypoToolFromDict (flags, chainDict)
 
def Trig3VarComboHypoToolFromDict (flags, chainDict)
 
def addTopoInfo (theChainConfig, mainChainDict, listOfChainDefs, lengthOfChainConfigs)
 

Variables

 log
 
 topoLegIndices
 
 anomdetWPIndices
 
 topo3VarLegIndices
 
 allowed_obs
 
 allowed_3var_obs
 
 comboConfigurator
 

Function Documentation

◆ addTopoInfo()

def ComboHypoHandling.addTopoInfo (   theChainConfig,
  mainChainDict,
  listOfChainDefs,
  lengthOfChainConfigs 
)

Definition at line 353 of file ComboHypoHandling.py.

353 def addTopoInfo(theChainConfig, mainChainDict, listOfChainDefs, lengthOfChainConfigs):
354  log.debug("[addTopoInfo] Adding topo info to chain %s", theChainConfig)
355 
356  def findStepIndexInChain(chain, step):
357  for istep,chainstep in enumerate(chain.steps):
358  if chainstep.name==step:
359  return istep
360  return None
361 
362  for step,(topoCfg,topoExpr) in theChainConfig.topoMap.items():
363  thestep = theChainConfig.steps[-1] if step=="last" else theChainConfig.steps[findStepIndexInChain(theChainConfig,step)]
364  log.debug("[addTopoInfo] Adding %s to step %s",topoExpr,thestep)
365 
366  if thestep is None:
367  log.error("Failed to find step %s in Chain! ChainDict follows:", step)
368  log.error(mainChainDict)
369  raise RuntimeError("Step not found when adding topo to chain")
370 
371  bonus_debug = False
372 
373  if bonus_debug:
374  log.debug("[addTopoInfo] theChainConfig %s", theChainConfig)
375  log.debug("[addTopoInfo] listOfChainDefs %s", listOfChainDefs)
376  log.debug("[addTopoInfo] theTopoInfo being added is %s",topoExpr)
377 
378  # No need to add if it has been added previously
379  # Handle better and avoid doing this repeatedly on the same steps?
380  if topoCfg not in thestep.comboToolConfs:
381  if len(thestep.comboToolConfs) > 0:
382  log.warning("[addTopoInfo] step %s already has ComboHypo tools %s",thestep,thestep.comboToolConfs)
383  log.warning("[addTopoInfo] these will be added to, make sure this is the behaviour you want.")
384 
385  thestep.name = thestep.name+'_combo_'+topoExpr
386  thestep.addComboHypoTools(topoCfg)
387  thestep.makeCombo()
388 
389  if bonus_debug:
390  log.debug("[addTopoInfo] new theChainConfig %s", theChainConfig)

◆ Trig3VarComboHypoToolFromDict()

def ComboHypoHandling.Trig3VarComboHypoToolFromDict (   flags,
  chainDict 
)

Definition at line 215 of file ComboHypoHandling.py.

215 def Trig3VarComboHypoToolFromDict(flags, chainDict):
216  from AthenaMonitoringKernel.GenericMonitoringTool import GenericMonitoringTool
217 
218  chainName = chainDict['chainName']
219  log.debug("[Trig3VarComboHypoToolFromDict] chain %s, combo hypos to be processed: %s, t", chainName, chainDict['extraComboHypos'])
220  #define the list for housing all the info needed to initialize the TrigComboHypoTool module in the form of a dict
221  topoDefs = []
222 
223  # Define regex for parsing the topoInfo
224  # Pattern is: min cut, var, legA, legB, max cut
225  # Min and max are both optional, check afterwards that at least one is filled
226  # Only the allowed 3var vars and legs will be recognised, anything else fails to match
227  theregex = fr"(\d*)({'|'.join(allowed_3var_obs.keys())})([{topo3VarLegIndices}])([{topo3VarLegIndices}])([{topo3VarLegIndices}])(\d*)"
228  matcher = re.compile(theregex)
229 
230  for iTopo, topoInfo in enumerate(chainDict['extraComboHypos']):
231  log.debug("[Trig3VarComboHypoToolFromDict] new combo hypo for chain: %s, topoInfo = %s", chainName, topoInfo)
232  # Attempt to regex-match the topo specification
233  result = matcher.match(topoInfo)
234  if not result:
235  log.error("[Trig3VarComboHypoToolFromDict] Topo expression %s does not conform to format (min?)(var)(legA)(legB)(legC)(max?).",topoInfo)
236  log.error("[Trig3VarComboHypoToolFromDict] Must use leg IDs in %s, vars in {allowed_3var_obs.keys()}",topo3VarLegIndices)
237  raise ValueError(f"[Trig3VarComboHypoToolFromDict] Invalid topo expression {topoInfo} received in 'extraComboHypos'!")
238 
239  # Extract the matched info and validate
240  str_min, var, char_legA, char_legB, char_legC, str_max = result.groups()
241  # Manipulation of the cuts
242  # At least one must be filled
243  use_min = bool(str_min)
244  use_max = bool(str_max)
245  if not (use_min or use_max):
246  log.error("[Trig3VarComboHypoToolFromDict] Topo expression %s does not specify a min or max cut value.",topoInfo)
247  raise ValueError(f"[Trig3VarComboHypoToolFromDict] Invalid topo expression {topoInfo} received in 'extraComboHypos'!")
248  # Convert into float values
249  cut_min = float(str_min) if use_min else float('nan')
250  cut_max = float(str_max) if use_max else float('nan')
251 
252  # Convert char leg representation to int
253  i_legA = topo3VarLegIndices.find(char_legA)
254  i_legB = topo3VarLegIndices.find(char_legB)
255  i_legC = topo3VarLegIndices.find(char_legC)
256 
257  # Fill info for each leg, looking up in chainParts
258  # Convert leg name into HLT identifier for matching in the tool
259  legInfo = []
260  for ileg in [i_legA,i_legB,i_legC]:
261  cpart = chainDict['chainParts'][ileg]
262  legname = f"leg{ileg:03d}_{chainName}"
263  legInfo.append({
264  'index' : ileg,
265  'legname' : legname,
266  'HLTId' : string2hash(legname),
267  'isMET' : cpart['signature']=='MET',
268  'multiplicity': int(cpart['multiplicity'])
269  })
270 
271  # Count how many input legs are MET, for consistency checks
272  n_MET_legs = legInfo[0]['isMET'] + legInfo[1]['isMET'] + legInfo[2]['isMET']
273 
274  #now check that the variable we plan to use allows the use of the MET
275  if n_MET_legs not in allowed_3var_obs[var]['n_MET_legs']:
276  log.error("[Trig3VarComboHypoToolFromDict] Attempting var %s with %d MET legs, %s allowed", var, n_MET_legs, allowed_3var_obs[var]['n_MET_legs'])
277  raise Exception("[Trig3VarComboHypoToolFromDict] Attempting to use the MET leg in var")
278 
279  if len(chainDict['extraComboHypos'])==1:#to avoid breaking changes in the ref files
280  monToolName = "MonTool_"+chainName
281  else:
282  monToolName = f"MonTool_{chainName}_{chainDict['extraComboHypos'][iTopo]}"
283  histNameTag = var
284  monTool = GenericMonitoringTool(flags, monToolName)
285  monTool.defineHistogram(histNameTag+'OfAccepted', type='TH1F', path='EXPERT',
286  title=var+" in accepted combinations; {}".format(var),
287  xbins=allowed_3var_obs[var]['hist_nbins'],
288  xmin=allowed_3var_obs[var]['hist_min'],
289  xmax=allowed_3var_obs[var]['hist_max'])
290  monTool.defineHistogram(histNameTag+'OfProcessed', type='TH1F', path='EXPERT',
291  title=var+" in processed combinations; {}".format(var),
292  xbins=allowed_3var_obs[var]['hist_nbins'],
293  xmin=allowed_3var_obs[var]['hist_min'],
294  xmax=allowed_3var_obs[var]['hist_max'])
295  log.debug("[Trig3VarComboHypoToolFromDict] tool configured for hypo name: %s, topoInfo = %s", chainName, topoInfo)
296  log.debug("[Trig3VarComboHypoToolFromDict] histName = %s", histNameTag)
297 
298  if len(chainDict['extraComboHypos'])==1:#to avoid breaking changes in the ref files
299  monTool.HistPath = f'ComboHypo/{chainName}'
300  else:
301  subDirNameTag = f"{var}leg{i_legA:03d}leg{i_legB:03d}leg{i_legC:03d}"
302  monTool.HistPath = f'ComboHypo/{chainName}/detail_{subDirNameTag}'
303 
304  # Set keys of dict to match tool config properties
305  singleTopoDef = {
306  "Variables" : var,
307  "UseMinVec" : use_min,
308  "UseMaxVec" : use_max,
309  "LowerCutVec" : cut_min,
310  "UpperCutVec" : cut_max,
311  "LegAVec" : legInfo[0]["HLTId"],
312  "LegBVec" : legInfo[1]["HLTId"],
313  "LegCVec" : legInfo[2]["HLTId"],
314  "IsLegA_METVec": legInfo[0]["isMET"],
315  "IsLegB_METVec": legInfo[1]["isMET"],
316  "IsLegC_METVec": legInfo[2]["isMET"],
317  "MonTools" : monTool,
318  }
319  topoDefs.append(singleTopoDef)
320 
321  #some debug info
322  log.debug("[Trig3VarComboHypoToolFromDict] tool configured for hypo name: %s, topoInfo = %s", chainName, topoInfo)
323  log.debug("[Trig3VarComboHypoToolFromDict] var = %s", singleTopoDef['Variables'])
324  log.debug("[Trig3VarComboHypoToolFromDict] legA = %s", singleTopoDef['LegAVec'])
325  log.debug("[Trig3VarComboHypoToolFromDict] legB = %s", singleTopoDef['LegBVec'])
326  log.debug("[Trig3VarComboHypoToolFromDict] legC = %s", singleTopoDef['LegCVec'])
327  if use_min:
328  log.debug("[Trig3VarComboHypoToolFromDict] min = %10.3f", singleTopoDef['LowerCutVec'])
329  if use_max:
330  log.debug("[Trig3VarComboHypoToolFromDict] max = %10.3f", singleTopoDef['UpperCutVec'])
331 
332  #end of the loop over the hypos
333 
334  # convert list of dicts into dict of lists
335  toolProps = {k:[thedef[k] for thedef in topoDefs] for k in topoDefs[0]}
336  tool = CompFactory.Trig3VarComboHypoTool(chainName, **toolProps)
337 
338  return tool
339 

◆ TrigComboHypoToolFromDict()

def ComboHypoHandling.TrigComboHypoToolFromDict (   flags,
  chainDict 
)

Definition at line 69 of file ComboHypoHandling.py.

69 def TrigComboHypoToolFromDict(flags, chainDict):
70  from AthenaMonitoringKernel.GenericMonitoringTool import GenericMonitoringTool
71 
72  chainName = chainDict['chainName']
73  log.debug("[TrigComboHypoToolFromDict] chain %s, combo hypos to be processed: %s, t", chainName, chainDict['extraComboHypos'])
74  #define the list for housing all the info needed to initialize the TrigComboHypoTool module in the form of a dict
75  topoDefs = []
76 
77  # Define regex for parsing the topoInfo
78  # Pattern is: min cut, var, legA, legB, max cut
79  # Min and max are both optional, check afterwards that at least one is filled
80  # Only the allowed vars and legs will be recognised, anything else fails to match
81  theregex = fr"(\d*)({'|'.join(allowed_obs.keys())})([{topoLegIndices}])([{topoLegIndices}])(\d*)"
82  matcher = re.compile(theregex)
83 
84  for iTopo, topoInfo in enumerate(chainDict['extraComboHypos']):
85  log.debug("[TrigComboHypoToolFromDict] new combo hypo for chain: %s, topoInfo = %s", chainName, topoInfo)
86  # Attempt to regex-match the topo specification
87  result = matcher.match(topoInfo)
88  if not result:
89  log.error("[TrigComboHypoToolFromDict] Topo expression %s does not conform to format (min?)(var)(legA)(legB)(max?).",topoInfo)
90  log.error("[TrigComboHypoToolFromDict] Must use leg IDs in %s, vars in {allowed_obs.keys()}",topoLegIndices)
91  raise ValueError(f"[TrigComboHypoToolFromDict] Invalid topo expression {topoInfo} received in 'extraComboHypos'!")
92 
93  # Extract the matched info and validate
94  str_min, var, char_legA, char_legB, str_max = result.groups()
95  # Manipulation of the cuts
96  # At least one must be filled
97  use_min = bool(str_min)
98  use_max = bool(str_max)
99  if not (use_min or use_max):
100  log.error("[TrigComboHypoToolFromDict] Topo expression %s does not specify a min or max cut value.",topoInfo)
101  raise ValueError(f"[TrigComboHypoToolFromDict] Invalid topo expression {topoInfo} received in 'extraComboHypos'!")
102  # Convert into float values, dividing for 0.1 precision as needed
103  if var in ['dR','dphi','deta']:
104  cut_min = float(str_min)/10. if use_min else float('nan')
105  cut_max = float(str_max)/10. if use_max else float('nan')
106  else:
107  cut_min = float(str_min) if use_min else float('nan')
108  cut_max = float(str_max) if use_max else float('nan')
109 
110  # Convert char leg representation to int
111  i_legA = topoLegIndices.find(char_legA)
112  i_legB = topoLegIndices.find(char_legB)
113 
114  # Fill info for each leg, looking up in chainParts
115  # Convert leg name into HLT identifier for matching in the tool
116  legInfo = []
117  for ileg in [i_legA,i_legB]:
118  cpart = chainDict['chainParts'][ileg]
119  legname = f"leg{ileg:03d}_{chainName}"
120  legInfo.append({
121  'index' : ileg,
122  'legname' : legname,
123  'HLTId' : string2hash(legname),
124  'isMET' : cpart['signature']=='MET',
125  'multiplicity': int(cpart['multiplicity'])
126  })
127 
128  # Count how many input legs are MET, for consistency checks
129  n_MET_legs = legInfo[0]['isMET'] + legInfo[1]['isMET']
130 
131  # Check multiplicity of the configured legs
132  # For chains like "HLT_2muX_10invm70AA", no leg ID will be attached
133  # in which case set a flag to use all objects in the combination list
134  skipLegCheck = False
135  if i_legA==i_legB:
136  if legInfo[0]['multiplicity'] != 2:
137  log.error("[TrigComboHypoToolFromDict] Error configuring topo for chain %s!",chainName)
138  log.error("[TrigComboHypoToolFromDict] Topo selection %s requires multiplicity 2 on leg %d, found %d!",topoInfo,i_legA,legInfo[0]['multiplicity'])
139  raise Exception("[TrigComboHypoToolFromDict] Invalid multiplicity")
140  if n_MET_legs==2:
141  log.error("[TrigComboHypoToolFromDict] Configured with the same MET leg on both sides -- impossible to satisfy!")
142  raise Exception("[TrigComboHypoToolFromDict] Identical MET legs for topo selection")
143  if len(chainDict['chainParts'])==1:
144  skipLegCheck=True
145  else:
146  for li in legInfo:
147  if li['multiplicity'] != 1:
148  log.error("[TrigComboHypoToolFromDict] Error configuring topo for chain %s!",chainName)
149  log.error("[TrigComboHypoToolFromDict] Topo selection %s requires multiplicity 1 on leg %d, found %d!",topoInfo,li['index'],li['multiplicity'])
150  raise Exception("[TrigComboHypoToolFromDict] Invalid multiplicity")
151 
152  #now check that the variable we plan to use allows the use of the MET
153  if n_MET_legs not in allowed_obs[var]['n_MET_legs']:
154  log.error("[TrigComboHypoToolFromDict] Attempting var %s with %d MET legs, %s allowed", var, n_MET_legs, allowed_obs[var]['n_MET_legs'])
155  raise Exception("[TrigComboHypoToolFromDict] Attempting to use the MET leg in var")
156 
157  if len(chainDict['extraComboHypos'])==1:#to avoid breaking changes in the ref files
158  monToolName = "MonTool_"+chainName
159  else:
160  monToolName = f"MonTool_{chainName}_{chainDict['extraComboHypos'][iTopo]}"
161  histNameTag = var
162  monTool = GenericMonitoringTool(flags, monToolName)
163  monTool.defineHistogram(histNameTag+'OfAccepted', type='TH1F', path='EXPERT',
164  title=var+" in accepted combinations; {}".format(var),
165  xbins=allowed_obs[var]['hist_nbins'],
166  xmin=allowed_obs[var]['hist_min'],
167  xmax=allowed_obs[var]['hist_max'])
168  monTool.defineHistogram(histNameTag+'OfProcessed', type='TH1F', path='EXPERT',
169  title=var+" in processed combinations; {}".format(var),
170  xbins=allowed_obs[var]['hist_nbins'],
171  xmin=allowed_obs[var]['hist_min'],
172  xmax=allowed_obs[var]['hist_max'])
173  log.debug("[TrigComboHypoToolFromDict] tool configured for hypo name: %s, topoInfo = %s", chainName, topoInfo)
174  log.debug("[TrigComboHypoToolFromDict] histName = %s", histNameTag)
175 
176  if len(chainDict['extraComboHypos'])==1:#to avoid breaking changes in the ref files
177  monTool.HistPath = f'ComboHypo/{chainName}'
178  else:
179  subDirNameTag = f"{var}leg{i_legA:03d}leg{i_legB:03d}"
180  monTool.HistPath = f'ComboHypo/{chainName}/detail_{subDirNameTag}'
181 
182  # Set keys of dict to match tool config properties
183  singleTopoDef = {
184  "Variables" : var,
185  "UseMinVec" : use_min,
186  "UseMaxVec" : use_max,
187  "LowerCutVec" : cut_min,
188  "UpperCutVec" : cut_max,
189  "LegAVec" : legInfo[0]["HLTId"],
190  "LegBVec" : legInfo[1]["HLTId"],
191  "IsLegA_METVec": legInfo[0]["isMET"],
192  "IsLegB_METVec": legInfo[1]["isMET"],
193  "MonTools" : monTool,
194  }
195  topoDefs.append(singleTopoDef)
196 
197  #some debug info
198  log.debug("[TrigComboHypoToolFromDict] tool configured for hypo name: %s, topoInfo = %s", chainName, topoInfo)
199  log.debug("[TrigComboHypoToolFromDict] var = %s", singleTopoDef['Variables'])
200  log.debug("[TrigComboHypoToolFromDict] legA = %s", singleTopoDef['LegAVec'])
201  log.debug("[TrigComboHypoToolFromDict] legB = %s", singleTopoDef['LegBVec'])
202  if use_min:
203  log.debug("[TrigComboHypoToolFromDict] min = %10.3f", singleTopoDef['LowerCutVec'])
204  if use_max:
205  log.debug("[TrigComboHypoToolFromDict] max = %10.3f", singleTopoDef['UpperCutVec'])
206 
207  #end of the loop over the hypos
208 
209  # convert list of dicts into dict of lists
210  toolProps = {k:[thedef[k] for thedef in topoDefs] for k in topoDefs[0]}
211  tool = CompFactory.TrigComboHypoTool(chainName, SkipLegCheck=skipLegCheck, **toolProps)
212 
213  return tool
214 

Variable Documentation

◆ allowed_3var_obs

ComboHypoHandling.allowed_3var_obs

Definition at line 55 of file ComboHypoHandling.py.

◆ allowed_obs

ComboHypoHandling.allowed_obs

Definition at line 22 of file ComboHypoHandling.py.

◆ anomdetWPIndices

ComboHypoHandling.anomdetWPIndices

Definition at line 16 of file ComboHypoHandling.py.

◆ comboConfigurator

ComboHypoHandling.comboConfigurator

Definition at line 340 of file ComboHypoHandling.py.

◆ log

ComboHypoHandling.log

Definition at line 8 of file ComboHypoHandling.py.

◆ topo3VarLegIndices

ComboHypoHandling.topo3VarLegIndices

Definition at line 17 of file ComboHypoHandling.py.

◆ topoLegIndices

ComboHypoHandling.topoLegIndices

Definition at line 15 of file ComboHypoHandling.py.

vtune_athena.format
format
Definition: vtune_athena.py:14
ComboHypoHandling.TrigComboHypoToolFromDict
def TrigComboHypoToolFromDict(flags, chainDict)
Definition: ComboHypoHandling.py:69
GenericMonitoringTool
Definition: GenericMonitoringTool.h:51
ComboHypoHandling.addTopoInfo
def addTopoInfo(theChainConfig, mainChainDict, listOfChainDefs, lengthOfChainConfigs)
Definition: ComboHypoHandling.py:353
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
HLTUtils.string2hash
def string2hash(string)
Definition: HLTUtils.py:5
ComboHypoHandling.Trig3VarComboHypoToolFromDict
def Trig3VarComboHypoToolFromDict(flags, chainDict)
Definition: ComboHypoHandling.py:215
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65