6 @brief configuration for the trigger efficiency monitoring
9 from .utils
import getMinBiasChains
10 from AthenaCommon.Logging
import logging
11 from AthenaConfiguration.ComponentFactory
import CompFactory
13 log = logging.getLogger(
'TrigMinBiasEffMonitoring')
16 def _TrigEff(flags, triggerAndRef, algname='HLTMinBiasEffMonitoringAlg'):
17 from AthenaMonitoring
import AthMonitorCfgHelper
18 monConfig = AthMonitorCfgHelper(flags, algname)
20 alg = monConfig.addAlgorithm(
21 CompFactory.HLTMinBiasEffMonitoringAlg, algname)
23 from InDetConfig.InDetTrackSelectionToolConfig
import InDetTrackSelectionTool_LoosePrimary_Cfg
25 alg.TrackSelectionTool = trkSel
27 alg.triggerList = [ el[
"chain"]
for el
in triggerAndRef ]
28 alg.refTriggerList = [ el[
"refchain"]
for el
in triggerAndRef ]
30 length = len(alg.triggerList)
32 mainGroup = monConfig.addGroup(alg,
'TrigAll', topPath=
'HLT/MinBiasMon/Counts/')
34 alreadyConfigured =
set()
35 for cdef
in triggerAndRef:
37 refchain = cdef[
'refchain']
42 effGroup = monConfig.addGroup(alg, chain+refchain, topPath=f
'HLT/MinBiasMon/{level}/EffAll/')
44 whichcounter=
'nTrkOffline'
46 if '_sptrk_pt' in chain:
47 effGroup.defineHistogram(f
'EffPassed,leadingTrackPt;{chain}_ref_{refchain}_pt', type=
'TEfficiency',
48 title=chain+
';Leading track pt;Efficiency', xbins=50, xmin=0.0, xmax=10)
51 whichcounter +=
'_'+chain.split(
'_')[3]
52 elif '_excl_' in chain:
53 effGroup.defineHistogram(f
'EffPassed,nTrkOffline;{chain}_ref_{refchain}_exclusivity', type=
'TEfficiency',
54 title=chain+
';Offline Good nTrk (low pt);Efficiency', xbins=30, xmin=-0.5, xmax=30-0.5)
55 effGroup.defineHistogram(f
'EffPassed,leadingTrackPt;{chain}_ref_{refchain}_pt', type=
'TEfficiency',
56 title=chain+
';Leading track pt;Efficiency', xbins=50, xmin=0.0, xmax=10)
58 whichcounter +=
'_'+chain.split(
'_')[4]
60 if '_pusup' in chain
or '_hmt_' in chain:
61 whichcounter =
'nTrkOfflineVtx'
62 effGroup.defineHistogram(f
'EffPassed,{whichcounter};{chain}_ref_{refchain}', type=
'TEfficiency',
63 title=f
'{chain} ref: {refchain} ;Offline Good nTrk {whichcounter};Efficiency', xbins=xbins, xmin=xmin, xmax=xmax)
67 if chain
not in alreadyConfigured:
68 alreadyConfigured.add(chain)
70 mainGroup.defineHistogram(
'nTrkOffline_counts_' + chain, type=
'TH1F',
71 title=chain+
';Offline Good nTrk;Events', xbins=xmax-xmin, xmin=xmin, xmax=xmax)
73 mainGroup.defineHistogram(
'TrigCounts', title=
'Trigger counts;;Event rate',
74 xbins=length, xmin=0, xmax=len(alreadyConfigured), xlabels=
list(alreadyConfigured))
76 return monConfig.result()
80 from TrigConfigSvc.TriggerConfigAccess
import getHLTMonitoringAccess
87 log.info(f
'Monitoring {len(mbNames)} MinBias chains')
91 def _c(chain, refchain, level, **kwargs):
92 conf = {
"chain": chain,
"refchain": refchain,
"level": level,
"xmin": 0,
"xmax": 20}
98 return "_EMPTY" not in name
and "_UNPAIRED_ISO" not in name
101 filledChains =
list(
filter(_isFilled, spTrkChains))
102 emptyChains = [chain
for chain
in spTrkChains
if "_EMPTY" in chain[0]]
103 unpairedChains = [chain
for chain
in spTrkChains
if "_UNPAIRED_ISO" in chain[0]]
108 triggerAndRef += [_c(name,
"HLT_noalg_L1RD0_FILLED", level)
for name, level
in filledChains]
109 triggerAndRef += [_c(name,
"HLT_noalg_L1RD0_EMPTY", level)
for name, level
in emptyChains]
110 triggerAndRef += [_c(name,
"HLT_noalg_L1RD0_UNPAIRED_ISO", level)
for name, level
in unpairedChains]
113 triggerAndRef += [_c(name,
"HLT_noalg_mb_L1RD0_FILLED", level)
for name, level
in filledChains]
114 triggerAndRef += [_c(name,
"HLT_noalg_mb_L1RD0_EMPTY", level)
for name, level
in emptyChains]
115 triggerAndRef += [_c(name,
"HLT_noalg_mb_L1RD0_UNPAIRED_ISO", level)
for name, level
in unpairedChains]
118 triggerAndRef += [_c(
"HLT_mb_sptrk_L1RD0_FILLED",
"HLT_mb_sp_L1RD0_FILLED",
'Shifter')]
122 nonPusupChains = [chain
for chain
in hmtChains
if '_pusup' not in chain[0]]
123 if len(nonPusupChains) != 0:
127 part = name.split(
"_")
129 if el.startswith(
"trk"):
130 return int(el.strip(
"trk"))
131 raise RuntimeError(f
"Chain {name} is not the hmt chain")
133 nonPusupChains.sort(key=
lambda chain:
int(_trk(chain)))
136 first = nonPusupChains[0]
137 triggerAndRef += [_c(first[0],
"HLT_mb_sptrk_L1RD0_FILLED", first[1], xmax=_trk(first) + 30)]
140 triggerAndRef += [_c(chain[0],
"HLT_mb_sptrk_L1RD0_FILLED", chain[1], xmin=_trk(chain) - 20, xmax=_trk(chain) + 50)
for chain
in nonPusupChains[1:]]
143 pusupChains = [chain
for chain
in hmtChains
if '_pusup' in chain[0]]
147 return "_".
join(s[:3] + s[4:])
149 triggerAndRef += [_c(chain[0], _dropsup(chain[0]), chain[1], xmin=_trk(chain) - 20, xmax=_trk(chain) + 50)
for chain
in pusupChains]
153 for name, level
in exclChains:
154 triggerAndRef.append(_c(name,
'HLT_mb_sptrk_L1RD0_FILLED', level))
155 triggerAndRef.append(_c(name,
'HLT_mb_sp_L1RD0_FILLED', level))
159 triggerAndRef += [_c(name,
'HLT_mb_sptrk_L1RD0_FILLED', level)
for name, level
in noalgMbtsChains]
162 mbtsL1Chains = [
"L1_MBTS_A",
"L1_MBTS_C",
"L1_MBTS_1",
"L1_MBTS_2",
"L1_MBTS_1_1"]
163 triggerAndRef += [_c(chain,
'HLT_mb_sptrk_L1RD0_FILLED',
'Expert')
for chain
in mbtsL1Chains]
166 triggerAndRef += [_c(
"L1_TE{}".
format(i),
'HLT_mb_sptrk_L1RD0_FILLED',
'Expert', xmin=0, xmax=100)
for i
in [3, 5, 10, 40]]
169 def _find_noalg(chain):
170 pos = chain.find(
'L1')
171 return 'HLT_noalg_' + chain[pos:]
173 def _chains_with_noalg_ref():
176 for name, level
in filledChains:
178 if 'L1RD0_FILLED' in name:
181 noalg = _find_noalg(name)
182 if noalg
not in mbNames:
185 chains.append(_c(name, noalg, level))
189 triggerAndRef += _chains_with_noalg_ref()
195 def _hi_chain_with_mb_ref():
198 for name, level
in hiChains:
199 split = name.split(
'_hi_')
204 split = hi_l1.split(
'L1')
210 if ref
not in mbNames:
213 chains.append(_c(name, ref, level))
217 triggerAndRef += _hi_chain_with_mb_ref()
221 triggerAndRef.append(_c(
'HLT_mb_excl_1trk4_pt1_hi_FgapAC5_L12eEM1_VjTE200',
'HLT_mb_excl_1trk4_pt1_L12eEM1_VjTE200_GAP_AANDC',
'Expert'))
223 return _TrigEff(flags, triggerAndRef)
226 if __name__ ==
'__main__':
228 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
230 flags.Output.HISTFileName =
'TestMinBiasMonitorOutput.root'
235 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
236 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
243 cfg.printConfig(withDetails=
True)
244 with open(
"cfg.pkl",
"wb")
as f: