57 from AthenaMonitoringKernel.GenericMonitoringTool
import GenericMonitoringTool
59 chainName = chainDict[
'chainName']
60 log.debug(
"[TrigComboHypoToolFromDict] chain %s, combo hypos to be processed: %s, t", chainName, chainDict[
'extraComboHypos'])
68 theregex = fr
"(\d*)({'|'.join(allowed_obs.keys())})([{topoLegIndices}])([{topoLegIndices}])(\d*)"
69 matcher = re.compile(theregex)
71 for iTopo, topoInfo
in enumerate(chainDict[
'extraComboHypos']):
72 log.debug(
"[TrigComboHypoToolFromDict] new combo hypo for chain: %s, topoInfo = %s", chainName, topoInfo)
74 result = matcher.match(topoInfo)
76 log.error(
"[TrigComboHypoToolFromDict] Topo expression %s does not conform to format (min?)(var)(legA)(legB)(max?).",topoInfo)
77 log.error(
"[TrigComboHypoToolFromDict] Must use leg IDs in %s, vars in {allowed_obs.keys()}",topoLegIndices)
78 raise ValueError(f
"[TrigComboHypoToolFromDict] Invalid topo expression {topoInfo} received in 'extraComboHypos'!")
81 str_min, var, char_legA, char_legB, str_max = result.groups()
84 use_min =
bool(str_min)
85 use_max =
bool(str_max)
86 if not (use_min
or use_max):
87 log.error(
"[TrigComboHypoToolFromDict] Topo expression %s does not specify a min or max cut value.",topoInfo)
88 raise ValueError(f
"[TrigComboHypoToolFromDict] Invalid topo expression {topoInfo} received in 'extraComboHypos'!")
90 if var
in [
'dR',
'dphi',
'deta']:
91 cut_min =
float(str_min)/10.
if use_min
else float(
'nan')
92 cut_max =
float(str_max)/10.
if use_max
else float(
'nan')
94 cut_min =
float(str_min)
if use_min
else float(
'nan')
95 cut_max =
float(str_max)
if use_max
else float(
'nan')
98 i_legA = topoLegIndices.find(char_legA)
99 i_legB = topoLegIndices.find(char_legB)
104 for ileg
in [i_legA,i_legB]:
105 cpart = chainDict[
'chainParts'][ileg]
106 legname = f
"leg{ileg:03d}_{chainName}"
111 'isMET' : cpart[
'signature']==
'MET',
112 'multiplicity':
int(cpart[
'multiplicity'])
116 n_MET_legs = legInfo[0][
'isMET'] + legInfo[1][
'isMET']
123 if legInfo[0][
'multiplicity'] != 2:
124 log.error(
"[TrigComboHypoToolFromDict] Error configuring topo for chain %s!",chainName)
125 log.error(
"[TrigComboHypoToolFromDict] Topo selection %s requires multiplicity 2 on leg %d, found %d!",topoInfo,i_legA,legInfo[0][
'multiplicity'])
126 raise Exception(
"[TrigComboHypoToolFromDict] Invalid multiplicity")
128 log.error(
"[TrigComboHypoToolFromDict] Configured with the same MET leg on both sides -- impossible to satisfy!")
129 raise Exception(
"[TrigComboHypoToolFromDict] Identical MET legs for topo selection")
130 if len(chainDict[
'chainParts'])==1:
134 if li[
'multiplicity'] != 1:
135 log.error(
"[TrigComboHypoToolFromDict] Error configuring topo for chain %s!",chainName)
136 log.error(
"[TrigComboHypoToolFromDict] Topo selection %s requires multiplicity 1 on leg %d, found %d!",topoInfo,li[
'index'],li[
'multiplicity'])
137 raise Exception(
"[TrigComboHypoToolFromDict] Invalid multiplicity")
140 if n_MET_legs
not in allowed_obs[var][
'n_MET_legs']:
141 log.error(
"[TrigComboHypoToolFromDict] Attempting var %s with %d MET legs, %s allowed", var, n_MET_legs, allowed_obs[var][
'n_MET_legs'])
142 raise Exception(
"[TrigComboHypoToolFromDict] Attempting to use the MET leg in var")
144 if len(chainDict[
'extraComboHypos'])==1:
145 monToolName =
"MonTool_"+chainName
147 monToolName = f
"MonTool_{chainName}_{chainDict['extraComboHypos'][iTopo]}"
150 monTool.defineHistogram(histNameTag+
'OfAccepted', type=
'TH1F', path=
'EXPERT',
151 title=var+
" in accepted combinations; {}".
format(var),
152 xbins=allowed_obs[var][
'hist_nbins'],
153 xmin=allowed_obs[var][
'hist_min'],
154 xmax=allowed_obs[var][
'hist_max'])
155 monTool.defineHistogram(histNameTag+
'OfProcessed', type=
'TH1F', path=
'EXPERT',
156 title=var+
" in processed combinations; {}".
format(var),
157 xbins=allowed_obs[var][
'hist_nbins'],
158 xmin=allowed_obs[var][
'hist_min'],
159 xmax=allowed_obs[var][
'hist_max'])
160 log.debug(
"[TrigComboHypoToolFromDict] tool configured for hypo name: %s, topoInfo = %s", chainName, topoInfo)
161 log.debug(
"[TrigComboHypoToolFromDict] histName = %s", histNameTag)
163 if len(chainDict[
'extraComboHypos'])==1:
164 monTool.HistPath = f
'ComboHypo/{chainName}'
166 subDirNameTag = f
"{var}leg{i_legA:03d}leg{i_legB:03d}"
167 monTool.HistPath = f
'ComboHypo/{chainName}/detail_{subDirNameTag}'
172 "UseMinVec" : use_min,
173 "UseMaxVec" : use_max,
174 "LowerCutVec" : cut_min,
175 "UpperCutVec" : cut_max,
176 "LegAVec" : legInfo[0][
"HLTId"],
177 "LegBVec" : legInfo[1][
"HLTId"],
178 "IsLegA_METVec": legInfo[0][
"isMET"],
179 "IsLegB_METVec": legInfo[1][
"isMET"],
180 "MonTools" : monTool,
182 topoDefs.append(singleTopoDef)
185 log.debug(
"[TrigComboHypoToolFromDict] tool configured for hypo name: %s, topoInfo = %s", chainName, topoInfo)
186 log.debug(
"[TrigComboHypoToolFromDict] var = %s", singleTopoDef[
'Variables'])
187 log.debug(
"[TrigComboHypoToolFromDict] legA = %s", singleTopoDef[
'LegAVec'])
188 log.debug(
"[TrigComboHypoToolFromDict] legB = %s", singleTopoDef[
'LegBVec'])
190 log.debug(
"[TrigComboHypoToolFromDict] min = %10.3f", singleTopoDef[
'LowerCutVec'])
192 log.debug(
"[TrigComboHypoToolFromDict] max = %10.3f", singleTopoDef[
'UpperCutVec'])
197 toolProps = {k:[thedef[k]
for thedef
in topoDefs]
for k
in topoDefs[0]}
198 tool = CompFactory.TrigComboHypoTool(chainName, SkipLegCheck=skipLegCheck, **toolProps)