ATLAS Offline Software
TrigTLAMonitorAlgorithm.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 TrigTLAMonitorAlgorithm.py
6 @author E. Nagy
7 @author K. Krizka
8 @date 2022-06-14
9 @brief Example trigger python configuration for the Run III AthenaMonitoring package, based on the example by C Burton and P Onyisi
10 '''
11 
12 def tla_chains(inputFlags,log=None):
13  '''
14  Read in the TLA trigger chain names as submitted to the MonGroups
15  '''
16  tla_triglist = []
17  # Trigger list from monitoring groups: signatures = TLAMon to be agreed w/ MonGroups management
18  from TrigConfigSvc.TriggerConfigAccess import getHLTMonitoringAccess
19  moniAccess=getHLTMonitoringAccess(inputFlags)
20  TLAChainsE=moniAccess.monitoredChains(signatures="tlaMon",monLevels=["t0"])
21  if log is not None:
22  log.info (" ==> tla_chainlist t0: %s", TLAChainsE)
23  for chain in TLAChainsE:
24  chain = "E_"+chain
25  tla_triglist.append(chain)
26  TLAChainsS=moniAccess.monitoredChains(signatures="tlaMon",monLevels=["shifter"])
27  if log is not None:
28  log.info (" ==> tla_chainlist shifter: %s", TLAChainsS)
29  for chain in TLAChainsS:
30  chain = "S_"+chain
31  tla_triglist.append(chain)
32  if log is not None:
33  log.info (" ==> tla_triglist: %s", tla_triglist)
34  return tla_triglist
35 
36 
37 def TrigTLAMonConfig(inputFlags, tdt):
38  '''Function to configures some algorithms in the monitoring system.'''
39 
40  from AthenaCommon.Logging import logging
41  log = logging.getLogger( 'TrigTLAMonitorAlgorithm.py' )
42 
43 
49 
50  # The following class will make a sequence, configure algorithms, and link
51  # them to GenericMonitoringTools
52  from AthenaMonitoring import AthMonitorCfgHelper
53  helper = AthMonitorCfgHelper(inputFlags,'TrigTLAAthMonitorCfg')
54 
55 
57 
58  from AthenaConfiguration.ComponentFactory import CompFactory
59  trigTLAMonAlg = helper.addAlgorithm(CompFactory.TrigTLAMonitorAlgorithm,'TrigTLAMonAlg')
60 
61 
66  trigTLAMonAlg.TriggerChain = ''
67  trigTLAMonAlg.TriggerDecisionTool = tdt
68 
69 
70  tla_triglist=tla_chains(inputFlags,log=None)
71 
72  # Add a generic monitoring tool (a "group" in old language). The returned
73  # object here is the standard GenericMonitoringTool.
74  TLAMonGroup = helper.addGroup(trigTLAMonAlg,'TrigTLAMonitor','HLT/TLAMon/')
75 
76 
77  from TrigTLAMonitoring.TrigTLAMonitorHistograms import (
78  histdefs_eventinfo, histdefs_particle, histdefs_tracks, histdefs_dR, histdefs_jetcalibscales, histdefs_jetvariables
79  )
80  # Configure histograms
81  #NB! The histograms defined here must match the ones in the cxx file exactly
82  histdefs_global=[]
83  histdefs_global+=histdefs_eventinfo('eventInfo')
84  histdefs=[]
85  histdefs+=histdefs_particle('jet' ,'jet')
86  histdefs+=histdefs_particle('pfjet','particle-flow jet')
87  histdefs+=histdefs_particle('ph' ,'photon')
88  histdefs+=histdefs_particle('muon' ,'muon')
89  histdefs+=histdefs_tracks ('trk' ,'track')
90  histdefs+=histdefs_dR ('jet0' ,'jet1' , 'leading jet' ,'subleading jet' )
91  histdefs+=histdefs_dR ('pfjet0','pfjet1', 'leading pf jet','subleading pf jet')
92  histdefs+=histdefs_dR ('jet0' ,'ph0' , 'leading jet' ,'leading photon' )
93  histdefs+=histdefs_dR ('pfjet0','ph0' , 'leading pf jet','leading photon' )
94  histdefs+=histdefs_jetcalibscales('jet' ,'jet')
95  histdefs+=histdefs_jetcalibscales('pfjet','particle-flow jet', True)
96  histdefs+=histdefs_jetvariables('jet', 'jet')
97  histdefs+=histdefs_jetvariables('pfjet', 'particle-flow jet', True)
98 
99 
100  AllChains = []
101  for chain in tla_triglist :
102  AllChains.append(chain[2:])
103 
104  for histdef in histdefs:
105  HistName = histdef['name'] + '_' + chain[2:]
106 
107  xlabel=histdef.get('xlabel',histdef['name' ])
108  if 'xunit' in histdef:
109  xlabel+=f' [{histdef["xunit"]}'
110  ylabel=histdef.get('ylabel',histdef['ylabel'])
111 
112  if chain[0:1] == "E" :
113  TLAMonGroup.defineHistogram(HistName, title=f'Distribution of {histdef["name"]};{xlabel};{ylabel}',
114  path='Expert/' +chain[2:],xbins=histdef['xbins'],xmin=histdef['xmin'],xmax=histdef['xmax'])
115  if chain[0:1] == "S" :
116  TLAMonGroup.defineHistogram(HistName, title=f'Distribution of {histdef["name"]};{xlabel};{ylabel}',
117  path='Shifter/'+chain[2:],xbins=histdef['xbins'],xmin=histdef['xmin'],xmax=histdef['xmax'])
118 
119  # global histograms added here
120  for histdef in histdefs_global:
121  HistName = histdef['name']
122  xlabel=histdef.get('xlabel',histdef['name' ])
123  if 'xunit' in histdef:
124  xlabel+=f' [{histdef["xunit"]}'
125  ylabel=histdef.get('ylabel',histdef['ylabel'])
126  TLAMonGroup.defineHistogram(HistName, title=f'Distribution of {histdef["name"]};{xlabel};{ylabel}',
127  path='Expert/EventInfo',xbins=histdef['xbins'],xmin=histdef['xmin'],xmax=histdef['xmax'])
128 
129  log.info (" ==> In TrigTLAMonitorAlgorithm.py: AllChains list: %s", AllChains)
130  trigTLAMonAlg.AllChains = AllChains
131 
132 
137  return helper.result()
138 
139 
140 if __name__=='__main__':
141  # Get run options
142  import argparse
143  parser = argparse.ArgumentParser()
144  # AOD file copied from Bjets, just to avoid compilation warning, for TLA need to be changed!!!!
145  parser.add_argument('input',nargs='?',default='/afs/cern.ch/work/e/enagy/public/ARTfiles/MCtest160322.AOD.pool.root')
146  parser.add_argument('--data',action='store_true',help='Input file is data.')
147  parser.add_argument('--nevents',type=int,default=-1,help='Number of events to process.')
148  args = parser.parse_args()
149 
150  # Setup logs
151  from AthenaCommon.Logging import log
152  from AthenaCommon.Constants import DEBUG
153  log.setLevel(DEBUG)
154  # from AthenaCommon.Constants import INFO
155  # log.setLevel(INFO)
156 
157  # Set the Athena configuration flags
158  from AthenaConfiguration.AllConfigFlags import initConfigFlags
159  flags = initConfigFlags()
160 
161  # Set execute flags (number of events to process)
162  flags.Exec.MaxEvents = args.nevents
163 
164  # Input files (AOD or other files, e.g. costumized RAW file, to be defined
165  flags.Input.Files = [args.input]
166  flags.Input.isMC = not args.data
167 
168  # Output file (root)
169  flags.Output.HISTFileName = 'TrigTLAMonitorOutput.root'
170 
171  # flags.Trigger.triggerMenuSetup="Physics_pp_v7_primaries"
172  flags.Trigger.triggerMenuSetup = 'Physics_pp_run3_v1'
173  flags.Trigger.triggerConfig = 'DB'
174 
175  flags.lock()
176 
177  # Initialize configuration object, add accumulator, merge, and run.
178  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
179  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
180  cfg = MainServicesCfg(flags)
181  cfg.merge(PoolReadCfg(flags))
182 
183  # initialize the trigger decision tool
184  from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
185  tdt = cfg.getPrimaryAndMerge(TrigDecisionToolCfg(flags))
186 
187  # Use sequeces to handle algorithms dependencies
188  from AthenaCommon.CFElements import seqAND, seqOR
189  cfg.addSequence( seqOR("monSeq") )
190 
191  # Sequence for augmenting tracks - needs to run only for pflow chains
192  cfg.addSequence( seqAND("trackAugmentSeq"), parentName="monSeq")
193  pfChains=[trig[2:] for trig in tla_chains(flags) if 'pf_ftf' in trig]
194  from AthenaConfiguration.ComponentFactory import CompFactory
195  cfg.addEventAlgo(
196  CompFactory.CP.TrigEventSelectionAlg(triggers=pfChains,tool=tdt,noL1=True),
197  sequenceName="trackAugmentSeq",
198  )
199  from BTagging.BTagTrackAugmenterAlgConfig import BTagTrackAugmenterAlgCfg
200  cfg.merge(
202  flags,
203  TrackCollection='HLT_IDTrack_FS_FTF',
204  PrimaryVertexCollectionName='HLT_IDVertex_FS',
205  ),
206  sequenceName="trackAugmentSeq"
207  )
208 
209  # Add Monitoring Algorithm, after augmentations
210  trigTLAMonitorAcc = TrigTLAMonConfig(flags,tdt)
211  cfg.merge(
212  trigTLAMonitorAcc,
213  sequenceName="monSeq"
214  )
215 
216  # If you want to turn on more detailed messages ...
217  #trigTLAMonitorAcc.getEventAlgo('TrigTLAMonAlg').OutputLevel = 2 # DEBUG
218  #cfg.getService("MessageSvc").debugLimit=100000 # for extensive print outs
219  cfg.printConfig(withDetails=False) # set True for exhaustive info
220 
221  cfg.run()
python.TrigTLAMonitorAlgorithm.tla_chains
def tla_chains(inputFlags, log=None)
Definition: TrigTLAMonitorAlgorithm.py:12
python.TrigTLAMonitorHistograms.histdefs_jetcalibscales
def histdefs_jetcalibscales(pprefix, plabel, pflow=False)
Definition: TrigTLAMonitorHistograms.py:172
python.TrigTLAMonitorAlgorithm.TrigTLAMonConfig
def TrigTLAMonConfig(inputFlags, tdt)
Definition: TrigTLAMonitorAlgorithm.py:37
python.TriggerConfigAccess.getHLTMonitoringAccess
HLTMonitoringAccess getHLTMonitoringAccess(flags=None)
Definition: TriggerConfigAccess.py:256
python.BTagTrackAugmenterAlgConfig.BTagTrackAugmenterAlgCfg
def BTagTrackAugmenterAlgCfg(flags, TrackCollection='InDetTrackParticles', PrimaryVertexCollectionName='PrimaryVertices', prefix=None)
Definition: BTagTrackAugmenterAlgConfig.py:9
python.CFElements.seqAND
def seqAND(name, subs=[])
Definition: CFElements.py:25
python.CFElements.seqOR
def seqOR(name, subs=[])
Definition: CFElements.py:33
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:252
Constants
some useful constants -------------------------------------------------—
python.TriggerInterface.TrigDecisionToolCfg
def TrigDecisionToolCfg(flags)
Definition: TriggerInterface.py:14
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.TrigTLAMonitorHistograms.histdefs_eventinfo
def histdefs_eventinfo(pprefix)
Definition: TrigTLAMonitorHistograms.py:11
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
python.TrigTLAMonitorHistograms.histdefs_particle
def histdefs_particle(pprefix, plabel)
Definition: TrigTLAMonitorHistograms.py:215
python.TrigTLAMonitorHistograms.histdefs_jetvariables
def histdefs_jetvariables(pprefix, plabel, pflow=False)
Definition: TrigTLAMonitorHistograms.py:45