Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Functions | Variables
ComboHypoHandling Namespace Reference

Functions

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

Variables

 log
 
 topoLegIndices
 
 anomdetWPIndices
 
 allowed_obs
 
 comboConfigurator
 

Function Documentation

◆ addTopoInfo()

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

Definition at line 216 of file ComboHypoHandling.py.

216 def addTopoInfo(theChainConfig, mainChainDict, listOfChainDefs, lengthOfChainConfigs):
217  log.debug("[addTopoInfo] Adding topo info to chain %s", theChainConfig)
218 
219  def findStepIndexInChain(chain, step):
220  for istep,chainstep in enumerate(chain.steps):
221  if chainstep.name==step:
222  return istep
223  return None
224 
225  for step,(topoCfg,topoExpr) in theChainConfig.topoMap.items():
226  thestep = theChainConfig.steps[-1] if step=="last" else theChainConfig.steps[findStepIndexInChain(theChainConfig,step)]
227  log.debug("[addTopoInfo] Adding %s to step %s",topoExpr,thestep)
228 
229  if thestep is None:
230  log.error("Failed to find step %s in Chain! ChainDict follows:", step)
231  log.error(mainChainDict)
232  raise RuntimeError("Step not found when adding topo to chain")
233 
234  bonus_debug = False
235 
236  if bonus_debug:
237  log.debug("[addTopoInfo] theChainConfig %s", theChainConfig)
238  log.debug("[addTopoInfo] listOfChainDefs %s", listOfChainDefs)
239  log.debug("[addTopoInfo] theTopoInfo being added is %s",topoExpr)
240 
241  # No need to add if it has been added previously
242  # Handle better and avoid doing this repeatedly on the same steps?
243  if topoCfg not in thestep.comboToolConfs:
244  if len(thestep.comboToolConfs) > 0:
245  log.warning("[addTopoInfo] step %s already has ComboHypo tools %s",thestep,thestep.comboToolConfs)
246  log.warning("[addTopoInfo] these will be added to, make sure this is the behaviour you want.")
247 
248  thestep.name = thestep.name+'_combo_'+topoExpr
249  thestep.addComboHypoTools(topoCfg)
250  thestep.makeCombo()
251 
252  if bonus_debug:
253  log.debug("[addTopoInfo] new theChainConfig %s", theChainConfig)

◆ TrigComboHypoToolFromDict()

def ComboHypoHandling.TrigComboHypoToolFromDict (   flags,
  chainDict 
)

Definition at line 58 of file ComboHypoHandling.py.

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

Variable Documentation

◆ allowed_obs

ComboHypoHandling.allowed_obs

Definition at line 21 of file ComboHypoHandling.py.

◆ anomdetWPIndices

ComboHypoHandling.anomdetWPIndices

Definition at line 16 of file ComboHypoHandling.py.

◆ comboConfigurator

ComboHypoHandling.comboConfigurator

Definition at line 204 of file ComboHypoHandling.py.

◆ log

ComboHypoHandling.log

Definition at line 8 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:58
GenericMonitoringTool
Definition: GenericMonitoringTool.h:53
ComboHypoHandling.addTopoInfo
def addTopoInfo(theChainConfig, mainChainDict, listOfChainDefs, lengthOfChainConfigs)
Definition: ComboHypoHandling.py:216
python.LArMinBiasAlgConfig.int
int
Definition: LArMinBiasAlgConfig.py:59
HLTUtils.string2hash
def string2hash(string)
Definition: HLTUtils.py:5
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65