ATLAS Offline Software
TrigFwdAFPMonitoring.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 import math
4 
5 from AthenaConfiguration.ComponentFactory import CompFactory
6 from AthenaMonitoring import AthMonitorCfgHelper
7 from TrigConfigSvc.TriggerConfigAccess import getHLTMonitoringAccess
8 from AthenaCommon.Logging import logging
9 
10 from .utils import getMinBiasChains
11 
12 log = logging.getLogger('TrigFwdAFPMonitoring')
13 
14 jet_containers = {
15  'Topo': 'AntiKt4EMTopoJets',
16  'PFlow': 'AntiKt4EMPFlowJets',
17  'HLTTopo': 'HLT_AntiKt4EMTopoJets_subjesIS',
18  'HLTPFlow': 'HLT_AntiKt4EMPFlowJets_subjesIS_ftf'
19 }
20 
21 
23  """ Configure general AFP chains monitoring algs """
24 
25  monConfig = AthMonitorCfgHelper(flags, 'FwdAFPMonitoringAlgs')
26 
27  monAccess = getHLTMonitoringAccess(flags)
28  afp_chains = getMinBiasChains(monAccess, '(AFP|afp)')
29 
30  # Counting alg for all AFP triggers
31  algCount = monConfig.addAlgorithm(CompFactory.FwdAFPCountMonitoringAlg, 'FwdAFPCountMonitoringAlg')
32  algCount.chains = [name for name, _ in afp_chains]
33 
34  log.info(f'Monitoring {len(afp_chains)} AFP chains')
35 
36  afpCountGroup = monConfig.addGroup(algCount, 'AFPCount', topPath='HLT/FwdAFP/')
37  afpCountGroup.defineHistogram('counts', title='Trigger counts;;Counts', xbins=len(algCount.chains),
38  xmin=0, xmax=len(algCount.chains), xlabels=list(algCount.chains))
39 
40  return monConfig.result()
41 
42 
44  """ Configure AFP+jet chains monitoring algs """
45 
46  monConfig = AthMonitorCfgHelper(flags, 'FwdAFPJetMonitoringAlgs')
47  monAccess = getHLTMonitoringAccess(flags)
48 
49  # Select non-noalg AFP chains seeded from L1 jet
50  chains_afp = getMinBiasChains(monAccess, '(afpdijet)')
51  ref_chains = ['HLT_mb_sp_L1RD0_FILLED', 'HLT_mb_sptrk_L1RD0_FILLED', 'HLT_noalg_L1RD0_FILLED',
52  'HLT_noalg_L1AFP_A_OR_C', 'HLT_noalg_L1AFP_A_OR_C']
53 
54  log.info(f'Monitoring {len(chains_afp)} AFP+DiJet chains')
55  log.debug([name for name, _ in chains_afp])
56 
57  # Jet monitoring algs for different jet containers
58  for jet, container in jet_containers.items():
59  algEff = monConfig.addAlgorithm(CompFactory.FwdAFPJetMonitoringAlg, 'FwdAFP' + jet + 'JetMonitoringAlg')
60 
61  algEff.chains = [name for name, _ in chains_afp]
62  algEff.jetContainer = container
63 
64  for chain, level in chains_afp:
65  afpJetGroup = monConfig.addGroup(algEff, f'{chain}_{container}', topPath=f'HLT/FwdAFP/{level}/Jet/{chain}/{container}/')
66  afpJetGroup.defineHistogram('jetPt', title=f'{jet} jet pT;Jet pT [GeV];Entries', xbins=100, xmin=0, xmax=200)
67  afpJetGroup.defineHistogram('jetEta', title=f'{jet} jet eta;Jet #eta;Entries', xbins=100, xmin=-4.9, xmax=4.9)
68  afpJetGroup.defineHistogram('jetPhi', title=f'{jet} jet phi;Jet #varphi;Entries', xbins=100, xmin=-math.pi, xmax=math.pi)
69  afpJetGroup.defineHistogram('jetEta,jetPhi', type='TH2F', title=f'{jet} jet eta vs phi;Jet #eta;Jet #varphi;Entries',
70  xbins=40, xmin=-4.9, xmax=4.9, ybins=40, ymin=-math.pi, ymax=math.pi)
71  afpJetGroup.defineHistogram('jetEta,jetPt', type='TH2F', title=f'{jet} jet eta vs phi;Jet #eta;Jet pT [GeV];Entries',
72  xbins=40, xmin=-4.9, xmax=4.9, ybins=40, ymin=0, ymax=200)
73 
74  afpJetGroup.defineHistogram('leadingJetPt', title=f'Leading {jet} jet pT;Leading jet pT [GeV];Entries',
75  xbins=100, xmin=0, xmax=200)
76  afpJetGroup.defineHistogram('leadingJetEta', title=f'Leading {jet} jet eta;Leading jet #eta;Entries',
77  xbins=100, xmin=-4.9, xmax=4.9)
78  afpJetGroup.defineHistogram('leadingJetPhi', title=f'Leading {jet} jet phi;Leading jet #varphi;Entries',
79  xbins=100, xmin=-math.pi, xmax=math.pi)
80  afpJetGroup.defineHistogram('leadingJetEta,leadingJetPhi', type='TH2F',
81  title=f'Leading {jet} jet eta vs phi;Leading jet #eta;Leading jet #varphi;Entries',
82  xbins=40, xmin=-4.9, xmax=4.9, ybins=40, ymin=-math.pi, ymax=math.pi)
83  afpJetGroup.defineHistogram('leadingJetEta,leadingJetPt', type='TH2F',
84  title=f'Leading {jet} jet eta vs phi;Leading jet #eta;Leading jet pT [GeV];Entries',
85  xbins=40, xmin=-4.9, xmax=4.9, ybins=40, ymin=0, ymax=200)
86 
87  # Efficiency alg
88  algEff = monConfig.addAlgorithm(CompFactory.FwdAFPJetEffMonitoringAlg, 'FwdAFPJetEffMonitoringAlg')
89  algEff.chains = [name for name, _l in chains_afp for _r in range(len(ref_chains))]
90  algEff.references = ref_chains * len(chains_afp)
91 
92  for chain, level in chains_afp:
93  for ref in ref_chains:
94  afpJetEffGroup = monConfig.addGroup(algEff, f'{chain}_{ref}', topPath=f'HLT/FwdAFP/{level}/Jet/Eff/')
95  afpJetEffGroup.defineHistogram(f'effPassed,leadingJetPt;{chain}_vs_{ref}', type='TEfficiency',
96  title=f'{chain} vs {ref};Leading jet pT [GeV];Efficiency', xbins=100, xmin=0, xmax=200)
97 
98  return monConfig.result()
99 
100 
102  """ Collect all configured AFP chains algorithms """
103 
104  from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
105  acc = ComponentAccumulator()
106 
107  acc.merge(TrigFwdAFPMonitoringCfg(flags))
108  acc.merge(TrigFwdAFPJetMonitoringCfg(flags))
109 
110  return acc
111 
112 
113 if __name__ == '__main__':
114  """ Test AFP+jet monitoring by running: python -m TrigMinBiasMonitoring.TrigFwdAFPMonitoring --filesInput=... """
115 
116  from AthenaConfiguration.AllConfigFlags import initConfigFlags
117 
118  flags = initConfigFlags()
119  flags.Output.HISTFileName = 'TestFwdAfpMonitorOutput.root'
120  flags.fillFromArgs()
121  flags.lock()
122 
123  # Initialize configuration object, add accumulator, merge, and run.
124  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
125  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
126  cfg = MainServicesCfg(flags)
127  cfg.merge(PoolReadCfg(flags))
128  cfg.merge(TrigFwdAFPAllMonitoringCfg(flags))
129 
130  cfg.printConfig(withDetails=True)
131  with open('cfg.pkl', 'wb') as f:
132  cfg.store(f)
133 
134  cfg.run()
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.TriggerConfigAccess.getHLTMonitoringAccess
HLTMonitoringAccess getHLTMonitoringAccess(flags=None)
Definition: TriggerConfigAccess.py:256
TrigFwdAFPMonitoring.TrigFwdAFPAllMonitoringCfg
def TrigFwdAFPAllMonitoringCfg(flags)
Definition: TrigFwdAFPMonitoring.py:101
TrigFwdAFPMonitoring.TrigFwdAFPJetMonitoringCfg
def TrigFwdAFPJetMonitoringCfg(flags)
Definition: TrigFwdAFPMonitoring.py:43
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:256
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
TrigFwdAFPMonitoring.TrigFwdAFPMonitoringCfg
def TrigFwdAFPMonitoringCfg(flags)
Definition: TrigFwdAFPMonitoring.py:22
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
utils.getMinBiasChains
def getMinBiasChains(monAccess, wildcard='')
Definition: Trigger/TrigMonitoring/TrigMinBiasMonitoring/python/utils.py:7
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69