ATLAS Offline Software
TrigGeneralMonitorAlgorithm.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 '''@file TrigHLTMonitorAlgorithm.py
6 @date 2020-09-18
7 @brief TrigHLTMonitoring general monitoring
8 '''
9 
10 
11 def TrigGeneralMonConfig(inputFlags):
12  '''Function to configure general HLT algorithms in the monitoring system.'''
13 
14 
15 
16  from AthenaCommon.Logging import logging
17  log_trighlt = logging.getLogger( 'TrigGeneralMonitorAlgorithm' )
18 
19 
20 
21  from TrigConfigSvc.TriggerConfigAccess import getHLTMenuAccess
22  from TrigConfigSvc.TriggerConfigAccess import getL1MenuAccess
23 
24 
26 
27  # The following class will make a sequence, configure algorithms, and link
28  # them to GenericMonitoringTools
29  from AthenaMonitoring import AthMonitorCfgHelper
30  helper = AthMonitorCfgHelper(inputFlags,'TrigHLTAthMonitorCfg')
31 
32 
33 
34  # Adding algorithms to the helper.
35  # The added algorithm must exist as a .h file
36 
37  from AthenaConfiguration.ComponentFactory import CompFactory
38  cfgsvc = CompFactory.TrigConf.xAODConfigSvc('xAODConfigSvc')
39  helper.resobj.addService(cfgsvc)
40  trigHLTMonAlg = helper.addAlgorithm(CompFactory.TrigHLTMonitorAlgorithm,'TrigHLTMonAlg')
41  trigHLTMonAlg.TrigConfigSvc = cfgsvc
42 
43 
44 
45 
46  signature_names_regexes = [('HLT_AllChains','HLT_.*'), #0
47  ('HLT_Electrons','HLT_[0-9]*e[0-9]+.*'), #1
48  ('HLT_Gamma','HLT_[0-9]*g[0-9]+.*'), #2
49  ('HLT_Muons','HLT_[0-9]*mu[0-9]+.*'), #3
50  ('HLT_Taus','HLT_(tau[0-9]*|trk.*Tau).*'), #4
51  ('HLT_MissingET','HLT_(t|x)e[0-9]+.*'), #5
52  ('HLT_Jets','HLT_[0-9]*j[0-9]+.*'), #6
53  ('HLT_MinBias','HLT_mb.*')] #7
54 
55 
56  #top level group
57  hltGroup = helper.addGroup(
58  trigHLTMonAlg,
59  'TrigHLTMonitor',
60  'HLT/ResultMon/'
61  )
62 
63 
64  # Configure histograms
65  #NB! The histograms defined here must match the ones in the cxx file exactly
66 
67 
69 
70  hltGroup.defineHistogram('HLTEvents', title='HLT events;HLT;Events',
71  path='',xbins=2,xmin=0,xmax=2)
72 
73  consistency_names=['SMK DB NULL','SMK BS NULL','SMK Inconsistent','HLT Prescale DB NULL',
74  'HLT Prescale BS NULL','HLT Prescale Inconsistent',
75  'No onlineKeys','No eventKeys']
76  hltGroup.defineHistogram('ConfigConsistency_HLT', title='ConfigConsistency_HLT;;Events',
77  path='',xbins=8,xmin=1,xmax=9,xlabels=consistency_names,
78  opt='kAlwaysCreate')
79 
80 
81 
83 
84 
85 
87  ListOf_HLT_names = []
88  HLT_names_signature = []
89  ListOf_signatures = []
90 
91  import re
92  for signame, m_this_regex in signature_names_regexes:
93  log_trighlt.debug('Signature: %s', signame)
94  ListOf_signatures.append(signame)
95  this_regex = re.compile(m_this_regex)
96  HLT_names_signature.clear() #re-use the list
97  for chain_name in getHLTMenuAccess(inputFlags):
98  if this_regex.match(chain_name):
99  log_trighlt.debug('chain name %s matches regex %s',chain_name,m_this_regex)
100  HLT_names_signature.append(chain_name)
101  ListOf_HLT_names.append(list(HLT_names_signature))
102 
103 
104  #Sort HLT names alphabetically, to make the HLT histograms have the same
105  #x axes for different runs and reprocessings
106  ListOf_HLT_names_sorted = []
107  HLT_names_signature_sorted = []
108  for i in range(len(ListOf_HLT_names)):
109  HLT_names_signature.clear()
110  HLT_names_signature=ListOf_HLT_names[i]
111 
112  HLT_names_signature_sorted.clear()
113  HLT_names_signature_sorted = sorted(HLT_names_signature)
114  ListOf_HLT_names_sorted.append(list(HLT_names_signature_sorted))
115  for chain in HLT_names_signature_sorted:
116 
117  log_trighlt.debug('sorted HLT chain: %s',chain)
118 
119 
121  L1_names =[]
122  log_trighlt.debug('L1 items: ')
123  for item_name in getL1MenuAccess(inputFlags):
124  L1_names.append(item_name)
125  max_L1_items = len(L1_names)
126  log_trighlt.debug('max_L1_items = %i', max_L1_items)
127 
128  #Sort L1 names alphabetically, to make the L1 histograms have the same
129  #x axes for different runs and reprocessings
130  L1_names_sorted = sorted(L1_names)
131  #Print the L1 items in the menu
132  for item_name in L1_names_sorted:
133  log_trighlt.debug('L1 item: = %s',item_name)
134 
135 
136 
137 
138  hltGroup.defineHistogram('L1Events',title='Events per Item at L1;;Events',
139  path='',xbins=len(L1_names_sorted), xmin=0,
140  xmax=len(L1_names_sorted), xlabels=L1_names_sorted)
141 
142 
143 
144  triggerstatus = ['RAW','PS'] #all chains or prescaled chains
145 
146  for i, pair in enumerate(signature_names_regexes):
147  sig = pair[0]
148  m_this_regex = pair[1]
149  log_trighlt.debug("Signature %s, pattern %s:",sig, m_this_regex)
150 
151 
152  titlename = sig+";;"+"Events"
153  HLT_names_signature_sorted.clear()
154  HLT_names_signature_sorted = ListOf_HLT_names_sorted[i]
155 
156  Xmax=len(HLT_names_signature_sorted)
157  if Xmax<1:
158  Xmax = 1 #Avoid error messages if there are no chains in this signature
159  log_trighlt.debug('Xmax= %i', Xmax)
160 
161  for trigstatus in triggerstatus: #loop over RAW/PS
162  histname = sig+trigstatus
163  titlename = sig+trigstatus+";;"+"Events"
164  hltGroup.defineHistogram(histname,title=titlename,
165  path=sig,xbins=len(HLT_names_signature_sorted),
166  xmin=0,xmax=Xmax,
167  xlabels=HLT_names_signature_sorted,opt='kAlwaysCreate')
168 
169  #eta and phi, 1D
170  histname = sig+"_eta"
171  titlename = histname+";#eta;"+"Events"
172  hltGroup.defineHistogram(histname,title=titlename,
173  path=sig,xbins=64,xmin=-3.2,xmax=3.2)
174 
175  histname = sig+"_phi"
176  titlename = histname+";#phi;"+"Events"
177  hltGroup.defineHistogram(histname,title=titlename,
178  path=sig,xbins=64,xmin=-3.2,xmax=3.2)
179 
180  #RoI count
181  histname = sig+"RoI_N"
182  titlename = histname+";Number of RoIs;"+"Events"
183  hltGroup.defineHistogram(histname,title=titlename,
184  path=sig,xbins=100,xmin=0,xmax=500)
185 
186 
187 
188 
190  listOfSignatureGroups =[]
191  for signame in ListOf_signatures:
192  thistoolname = 'Trig'+signame+'Monitor'
193  thisGroup = helper.addGroup(
194  trigHLTMonAlg,
195  thistoolname,
196  'HLT/ResultMon/'+signame
197  )
198  listOfSignatureGroups.append(thisGroup)
199 
200 
201  #Creating the RoI histograms
202  log_trighlt.debug('Creating RoI histograms...')
203  for i, thisGroup in enumerate(listOfSignatureGroups):
204  thispair = signature_names_regexes[i]
205  thissigname = thispair[0] #first item in the pair is the signature name
206  histname = "eta,phi;"+thissigname+"RoIs"
207 
208  titlename = thissigname+"RoIs;#eta;#phi"
209  thisGroup.defineHistogram(histname,type='TH2F',title=titlename,
210  path='',xbins=64,xmin=-3.2,xmax=3.2,
211  ybins=64,ymin=-3.2,ymax=3.2)
212 
213 
214 
215 
217  return helper.result()
218 
219 
220 if __name__=='__main__':
221  # Setup logs
222  from AthenaCommon.Logging import log
223  from AthenaCommon.Constants import DEBUG
224  log.setLevel(DEBUG)
225 
226  # Set the Athena configuration flags
227  from AthenaConfiguration.AllConfigFlags import initConfigFlags
228  flags = initConfigFlags()
229  flags.Input.isMC = False
230  flags.Output.HISTFileName = 'TrigHLTMonitorOutput.root'
231 
232  flags.lock()
233 
234  # Initialize configuration object, add accumulator, merge, and run.
235  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
236  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
237  cfg = MainServicesCfg(flags)
238  cfg.merge(PoolReadCfg(flags))
239 
240  trigHLTMonitorAcc = TrigGeneralMonConfig(flags)
241  cfg.merge(trigHLTMonitorAcc)
242 
243  # If you want to turn on more detailed messages ...
244  #trigHLTMonitorAcc.getEventAlgo('TrigHLTMonAlg').OutputLevel = 2 # DEBUG
245  cfg.printConfig(withDetails=True) # set True for exhaustive info
246 
247  cfg.run() #use cfg.run(20) to only run on first 20 events
248 
TrigGeneralMonitorAlgorithm.TrigGeneralMonConfig
def TrigGeneralMonConfig(inputFlags)
Definition: TrigGeneralMonitorAlgorithm.py:11
python.TriggerConfigAccess.getL1MenuAccess
L1MenuAccess getL1MenuAccess(flags=None)
Definition: TriggerConfigAccess.py:129
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
Constants
some useful constants -------------------------------------------------—
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.TriggerConfigAccess.getHLTMenuAccess
HLTMenuAccess getHLTMenuAccess(flags=None)
Definition: TriggerConfigAccess.py:196
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69