ATLAS Offline Software
TrigSPTRKMonitoringMT.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 @brief configuration for the min bias monitoring
6 """
7 
8 import math
9 
10 from .utils import getMinBiasChains
11 from AthenaCommon.Logging import logging
12 
13 log = logging.getLogger('TrigSPTRKMonitoringMT')
14 
15 
16 def TrigSPTRK(configFlags, highGranularity=False):
17 
18  from AthenaMonitoring import AthMonitorCfgHelper
19 
20  monConfig = AthMonitorCfgHelper(configFlags, "HLTMBSPTRKMonAlg")
21 
22  from AthenaConfiguration.ComponentFactory import CompFactory
23 
24  alg = monConfig.addAlgorithm(CompFactory.HLTMinBiasTrkMonAlg, "HLTMBSPTRKMonAlg")
25 
26  from InDetConfig.InDetTrackSelectionToolConfig import InDetTrackSelectionTool_LoosePrimary_Cfg
27  trkSel = monConfig.resobj.popToolsAndMerge(InDetTrackSelectionTool_LoosePrimary_Cfg(configFlags))
28  alg.TrackSelectionTool = trkSel
29 
30  ZFinderCollection = 'HLT_vtx_z'
31  if ZFinderCollection in configFlags.Input.Collections:
32  log.info("Enabled z finder data reading")
33  alg.zFinderDataKey = ZFinderCollection
34 
35  from TrigConfigSvc.TriggerConfigAccess import getHLTMonitoringAccess
36  monAccess = getHLTMonitoringAccess(configFlags)
37 
38  spChains = getMinBiasChains(monAccess, '(pix|hmt)')
39  spTrkChains = getMinBiasChains(monAccess, '(sptrk|excl|hmt|_mb_sp_)')
40 
41  log.info(f'Monitoring {len(spChains)} SpacePoints chains')
42  log.debug([name for name, _ in spChains])
43  log.info(f'Monitoring {len(spTrkChains)} Tracking chains')
44  log.debug([name for name, _ in spTrkChains])
45 
46  alg.triggerListTrackingMon = [name for name, _ in spTrkChains]
47  alg.triggerListSpacePointsMon = [name for name, _ in spChains]
48 
49  # Set track and cluster multiplicity histograms binning
50  nbins = 400 if highGranularity else 50
51  nTrkMax = 400
52  nSctCl = 5000
53  nPixBar = 2000
54  nPixEC = 500
55 
56  for chain, group in spChains:
57  mbSpGroup = monConfig.addGroup(alg, f'{chain}_SpacePoints', topPath=f"HLT/MinBiasMon/{group}/SpacePoints/{chain}/")
58 
59  mbSpGroup.defineHistogram("PixelCL;PixelCLNarrowRange", title="Number of SP in whole Pixels detector for all events", xbins=100, xmin=0, xmax=100)
60  mbSpGroup.defineHistogram("PixelCL;PixelCLWideRange", title="Number of SP in whole Pixels detector for all events", xbins=250, xmin=0, xmax=nPixBar)
61  mbSpGroup.defineHistogram("PixBarr_SP", title="Number of SP for all events in Barrel", xbins=250, xmin=0, xmax=nPixBar)
62  mbSpGroup.defineHistogram("PixECA_SP", title="Number of SP for all events in ECA", xbins=250, xmin=0, xmax=nPixEC)
63  mbSpGroup.defineHistogram("PixECC_SP", title="Number of SP for all events in ECC", xbins=250, xmin=0, xmax=nPixEC)
64  mbSpGroup.defineHistogram("SctTot;SctTotNarrowRange", title="Number of SP in whole SCT detector for all events", xbins=100, xmin=0, xmax=100)
65  mbSpGroup.defineHistogram("SctTot;SctTotWideRange", title="Number of SP in whole SCT detector for all events", xbins=250, xmin=0, xmax=nSctCl)
66  mbSpGroup.defineHistogram("SctBarr_SP", title="Number of SCT_SP for all events in Barrel", xbins=250, xmin=0, xmax=nSctCl)
67  mbSpGroup.defineHistogram("SctECA_SP", title="Number of SCT_SP for all events in ECA", xbins=250, xmin=0, xmax=nSctCl)
68  mbSpGroup.defineHistogram("SctECC_SP", title="Number of SCT_SP for all events in ECC", xbins=250, xmin=0, xmax=nSctCl)
69  mbSpGroup.defineHistogram("SctECA_SP,SctECC_SP", type="TH2F", title=";SctECA_SP;SctECC_SP", xbins=nbins, xmin=0, xmax=nSctCl, ybins=nbins, ymin=0, ymax=nSctCl)
70  mbSpGroup.defineHistogram("PixECA_SP,PixECC_SP", type="TH2F", title=";PixECA_SP;PixECC_SP", xbins=nbins, xmin=0, xmax=nPixEC, ybins=nbins, ymin=0, ymax=nPixEC)
71  mbSpGroup.defineHistogram("SctBarr_SP,PixBarr_SP", type="TH2F", title=";SctBarr_SP;PixBarr_SP", xbins=nbins, xmin=0, xmax=nSctCl, ybins=nbins, ymin=0, ymax=nPixBar)
72  mbSpGroup.defineHistogram("SctECA_SP,PixECA_SP", type="TH2F", title=";SctECA_SP;PixECA_SP", xbins=nbins, xmin=0, xmax=nSctCl, ybins=nbins, ymin=0, ymax=nPixEC)
73  mbSpGroup.defineHistogram("SctECC_SP,PixECC_SP", type="TH2F", title=";SctECC_SP;PixECC_SP", xbins=nbins, xmin=0, xmax=nSctCl, ybins=nbins, ymin=0, ymax=nPixEC)
74  mbSpGroup.defineHistogram("SctTot,PixelCL", type="TH2F", title=";Number of SP in whole SCT detector for all events;Number of SP in whole Pixels detector for all events", xbins=nbins, xmin=0, xmax=4000, ybins=nbins, ymin=0, ymax=4000)
75 
76  for chain, group in spTrkChains:
77  mbSpTrkGroup = monConfig.addGroup(alg, f'{chain}_Tracking', topPath=f"HLT/MinBiasMon/{group}/Tracking/{chain}/")
78 
79  # 1D distributions
80  mbSpTrkGroup.defineHistogram("nTrkOffline", title="Number of tracks reconstructed offline;track counts", xbins=200, xmin=-1, xmax=400)
81  mbSpTrkGroup.defineHistogram("nTrkOffline;nTrkOfflineLowMult", title="Number of tracks reconstructed offline;track counts", xbins=50, xmin=-1, xmax=50)
82  mbSpTrkGroup.defineHistogram("nTrkOnline;nTrkOnlineLowMult", title="Number of tracks reconstructed online;track counts", xbins=50, xmin=-1, xmax=50)
83 
84  mbSpTrkGroup.defineHistogram("trkPt", cutmask="trkMask", title="Offline selected tracks pt;p_{T} [GeV]", xbins=100, xmin=0, xmax=5)
85  mbSpTrkGroup.defineHistogram("trkEta", cutmask="trkMask", title="Offline selected tracks eta;#eta", xbins=50, xmin=-2.5, xmax=2.5)
86  mbSpTrkGroup.defineHistogram("trkPhi", cutmask="trkMask", title="Offline selected tracks phi;#phi", xbins=64, xmin=-math.pi, xmax=math.pi)
87  mbSpTrkGroup.defineHistogram("trkHits", title="Offline selected tracks, hits per track;number of hits", xbins=15, xmin=-0.5, xmax=15 - 0.5)
88 
89  mbSpTrkGroup.defineHistogram("onlTrkPt", title="Online tracks pt;p_{T} [GeV]", xbins=100, xmin=0, xmax=5)
90  mbSpTrkGroup.defineHistogram("onlTrkEta", title="Online tracks eta;#eta", xbins=50, xmin=-2.5, xmax=2.5)
91  mbSpTrkGroup.defineHistogram("onlTrkPhi", title="Online tracks phi;#phi", xbins=64, xmin=-math.pi, xmax=math.pi)
92  mbSpTrkGroup.defineHistogram("onlTrkHits", title="Online hits per track;number of hits", xbins=15, xmin=-0.5, xmax=15 - 0.5)
93  mbSpTrkGroup.defineHistogram("onlTrkZ0", title="Online track z_{0};z_{0}[mm]", xbins=40, xmin=-200, xmax=200)
94  mbSpTrkGroup.defineHistogram("onlTrkD0", title="Online track d_{0};d_{0}[mm]", xbins=40, xmin=-20, xmax=20)
95 
96  mbSpTrkGroup.defineHistogram("trkD0", cutmask="trkMask", title="Offline selected tracks D0;d_{0} [mm]", xbins=40, xmin=-20, xmax=20)
97  mbSpTrkGroup.defineHistogram("trkZ0wrtPV", cutmask="trkMask", title="Offline selected tracks Z0 wrt PV;z_{0}[mm]", xbins=40, xmin=-20, xmax=20)
98  mbSpTrkGroup.defineHistogram("trkZ0", cutmask="trkMask", title="Offline selected tracks Z0;z_{0}[mm]", xbins=40, xmin=-200, xmax=200)
99 
100  mbSpTrkGroup.defineHistogram("onlineOfflineVtxDelta", title=";(offline - online) vertex z[mm]", xbins=200, xmin=-200, xmax=200)
101 
102  # 2D maps
103  mbSpTrkGroup.defineHistogram('trkEta,trkPt', cutmask='trkMask', type='TH2F', title='Offline selected tracks pT/eta correlation;#eta;p_{T} [GeV]', xbins=50, xmin=-2.5, xmax=2.5, ybins=50, ymin=0, ymax=5)
104  mbSpTrkGroup.defineHistogram('onlTrkEta,onlTrkPt', type='TH2F', title='Online tracks pT/eta correlation;#eta;p_{T} [GeV]', xbins=50, xmin=-2.5, xmax=2.5, ybins=50, ymin=0, ymax=5)
105 
106  mbSpTrkGroup.defineHistogram('trkEta,trkPhi', cutmask='trkMask', type='TH2F', title='Offline selected tracks eta/phi correlation;#eta;#varphi', xbins=50, xmin=-2.5, xmax=2.5, ybins=50, ymin=-math.pi, ymax=math.pi)
107  mbSpTrkGroup.defineHistogram('onlTrkEta,onlTrkPhi', type='TH2F', title='Online tracks eta/phi correlation;#eta;#varphi', xbins=50, xmin=-2.5, xmax=2.5, ybins=50, ymin=-math.pi, ymax=math.pi)
108 
109  mbSpTrkGroup.defineHistogram("nTrkOnline,nTrkOffline", type="TH2F", title=";N online tracks;N offline tracks", xbins=nbins, xmin=0, xmax=nTrkMax, ybins=nbins, ymin=0, ymax=nTrkMax)
110  mbSpTrkGroup.defineHistogram("nTrkOfflineVtx,nTrkOffline", type="TH2F", title=";N offline tracks with Vtx cut;N offline tracks", xbins=nbins, xmin=0, xmax=nTrkMax, ybins=nbins, ymin=0, ymax=nTrkMax)
111  mbSpTrkGroup.defineHistogram("nTrkOnline,zFinderWeight", type="TH2F", title=";N online tracks;ZFinder weight", xbins=nbins, xmin=0, xmax=nTrkMax, ybins=nbins, ymin=0, ymax=nTrkMax)
112  mbSpTrkGroup.defineHistogram("nTrkOffline,zFinderWeight", type="TH2F", title=";N online tracks;ZFinder weight", xbins=nbins, xmin=0, xmax=nTrkMax, ybins=nbins, ymin=0, ymax=nTrkMax)
113  mbSpTrkGroup.defineHistogram("nTrkOfflineVtx,zFinderWeight", type="TH2F", title=";N offline tracks with Vtx cut;ZFinder weight", xbins=nbins, xmin=0, xmax=nTrkMax, ybins=nbins, ymin=0, ymax=nTrkMax)
114  mbSpTrkGroup.defineHistogram("nTrkOfflineVtx,nTrkOnlineVtx", type="TH2F", title=";N offline tracks with Vtx cut;N online tracks with Vtx cut;", xbins=nbins, xmin=0, xmax=nTrkMax, ybins=nbins, ymin=0, ymax=nTrkMax)
115 
116  # Ratios
117  mbSpTrkGroup.defineHistogram("nTrkOnline", title="Number of tracks reconstructed online;track counts", xbins=200, xmin=-1, xmax=400)
118  mbSpTrkGroup.defineHistogram("nTrkRatio", title="Number of tracks reconstructed online/offline;track counts online/offline", xbins=200, xmin=-1, xmax=4)
119  mbSpTrkGroup.defineHistogram("trkSelOfflineRatio", title="Number of tracks reconstructed offline(selected)/offline; N sel/all", xbins=200, xmin=0.1, xmax=1.9)
120 
121  return monConfig.result()
122 
123 
124 if __name__ == "__main__":
125  # Set the Athena configuration flags
126  from AthenaConfiguration.AllConfigFlags import initConfigFlags
127  flags = initConfigFlags()
128  flags.DQ.Environment = "AOD"
129  flags.Concurrency.NumConcurrentEvents = 5
130 
131  flags.Output.HISTFileName = "TestMonitorOutput.root"
132  flags.fillFromArgs()
133  from AthenaCommon.Logging import logging
134  log = logging.getLogger(__name__)
135  log.info("Input %s", str(flags.Input.Files))
136  flags.lock()
137 
138  # Initialize configuration object, add accumulator, merge, and run.
139  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
140  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
141 
142  cfg = MainServicesCfg(flags)
143 
144  cfg.merge(PoolReadCfg(flags))
145  cfg.merge(TrigSPTRK(flags, highGranularity=True)) # for local testing have very granular histograms
146 
147  # If you want to turn on more detailed messages ...
148  # from AthenaCommon.Constants import DEBUG
149  # cfg.getEventAlgo("HLTMBSPTRKMonAlg").OutputLevel = DEBUG
150  cfg.printConfig(withDetails=True) # set True for exhaustive info
151  with open("cfg.pkl", "wb") as f:
152  cfg.store(f)
153 
154  cfg.run() # use cfg.run(20) to only run on first 20 events
155  # to run:
156  # python -m TrigMinBiasMonitoring.TrigMinBiasMonitoringMT --filesInput=
python.TriggerConfigAccess.getHLTMonitoringAccess
HLTMonitoringAccess getHLTMonitoringAccess(flags=None)
Definition: TriggerConfigAccess.py:256
python.InDetTrackSelectionToolConfig.InDetTrackSelectionTool_LoosePrimary_Cfg
def InDetTrackSelectionTool_LoosePrimary_Cfg(flags, name="InDetTrackSelectionTool_LoosePrimary", **kwargs)
Configs based on CutLevel LoosePrimary #####.
Definition: InDetTrackSelectionToolConfig.py:54
TrigSPTRKMonitoringMT.TrigSPTRK
def TrigSPTRK(configFlags, highGranularity=False)
Definition: TrigSPTRKMonitoringMT.py:16
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
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
str
Definition: BTagTrackIpAccessor.cxx:11
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69