ATLAS Offline Software
Loading...
Searching...
No Matches
ZdcLEDMonitorAlgorithm.py
Go to the documentation of this file.
1#!/usr/bin/env python
2#
3# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4#
5
6'''@file ZdcLEDMonitorAlgorithm.py
7@author Y. Guo
8@author S. Mohapatra
9@date 2023-08-01
10@brief python configuration for ZDC LED monitoring under the Run III DQ framework
11 will be run in the ZDC LED calibration stream
12 see ExampleMonitorAlgorithm.py in AthenaMonitoring package for detailed step explanations
13'''
14def ZdcLEDMonitoringConfig(inputFlags, run_type):
15
16 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
17 result = ComponentAccumulator()
18
19#---------------------------------------------------------------------------------------
20 from AthenaMonitoring import AthMonitorCfgHelper
21 helper = AthMonitorCfgHelper(inputFlags,'ZdcAthMonitorCfg')
22
23 from AthenaConfiguration.ComponentFactory import CompFactory
24 zdcLEDMonAlg = helper.addAlgorithm(CompFactory.ZdcLEDMonitorAlgorithm,'ZdcLEDMonAlg')
25
26 zdcLEDMonAlg.EnableZDC = inputFlags.Detector.EnableZDC_ZDC
27 zdcLEDMonAlg.EnableRPD = inputFlags.Detector.EnableZDC_RPD
28# --------------------------------------------------------------------------------------------------
29
30 LEDs = ["Blue1", "Green", "Blue2"]
31 sides = ["C","A"]
32 modules = ["0","1","2","3"]
33 channels = ["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"]
34
35 n_energy_bins_default = 200
36 n_adc_sum_fine_bins = 800
37 n_time_bins_default = 150
38 n_sample_bins_default = 25
39 lumi_block_max = 2000
40 l1TriggerType_max = 256
41 adc_sum_max = 40000.0
42 max_adc_max = 4096.0
43 nsamples_max = 25.0
44 time_max = 75.0
45
46 nDecodingErrorBits = 3
47
48# --------------------------------------------------------------------------------------------------
49 zdcLEDAllEventsDiagMonTool = helper.addGroup(zdcLEDMonAlg, 'ZdcLEDAllEventsDiagnosis','ZDC/AllLEDEventsDiagnosis/')
50
51 zdcModLEDMonToolArr = helper.addArray([LEDs,sides,modules],zdcLEDMonAlg,'ZdcModLEDMonitor', topPath='ZDC/ZDCLED/')
52 rpdChanLEDMonToolArr = helper.addArray([LEDs,sides,channels],zdcLEDMonAlg,'RPDChanLEDMonitor', topPath='ZDC/RPDLED/')
53
54# ------------------------- All-event (including bad events) diagnostic histograms -------------------------
55
56
57 zdcLEDAllEventsDiagMonTool.defineHistogram('decodingErrorBits',title=';;Events',
58 xbins=nDecodingErrorBits,xmin=0.0,xmax=nDecodingErrorBits,opt='kVec',
59 xlabels=['No Decoding Error', 'ZDC Decoding Error', 'RPD Decoding Error'])
60
61 zdcLEDAllEventsDiagMonTool.defineHistogram('l1TriggerType', title=';L1TriggerType;Events',
62 xbins=l1TriggerType_max,xmin=0.0,xmax=l1TriggerType_max)
63
64 # zdcLEDAllEventsDiagMonTool.defineHistogram('lumiBlock, l1TriggerType', type='TH2F', title=';lumi block;L1TriggerType',
65 # path='L1TriggerType',
66 # xbins=int(lumi_block_max/10),xmin=0.0,xmax=lumi_block_max,
67 # ybins=l1TriggerType_max,ymin=0.0,ymax=l1TriggerType_max)
68
69
70# -------------------------------------------- Observables ------------------------------------------------------
71
72 zdcModLEDMonToolArr.defineHistogram('zdcLEDADCSum', title=';LED ADC Sum [ADC Counts];Events',
73 path='zdcLEDADCSum',
74 xbins=n_adc_sum_fine_bins,xmin=0.0,xmax=adc_sum_max)
75 zdcModLEDMonToolArr.defineHistogram('zdcLEDMaxADC', title=';LED Max ADC [ADC Counts];Events',
76 path='zdcLEDMaxADC',
77 xbins=n_energy_bins_default,xmin=0.0,xmax=max_adc_max)
78 zdcModLEDMonToolArr.defineHistogram('zdcLEDMaxSample', title=';LED Max Sample [ADC Counts];Events',
79 path='zdcLEDMaxSample',
80 xbins=n_sample_bins_default,xmin=0.0,xmax=nsamples_max)
81 zdcModLEDMonToolArr.defineHistogram('zdcLEDAvgTime', title=';LED Average Time [ns];Events',
82 path='zdcLEDAvgTime',
83 xbins=n_time_bins_default,xmin=0.0,xmax=time_max)
84 rpdChanLEDMonToolArr.defineHistogram('rpdLEDADCSum', title=';LED ADC Sum [ADC Counts];Events',
85 cutmask='rpdLEDPassFireCriteria',
86 path='rpdLEDADCSum',
87 xbins=n_adc_sum_fine_bins,xmin=0.0,xmax=adc_sum_max)
88 rpdChanLEDMonToolArr.defineHistogram('rpdLEDMaxADC', title=';LED Max ADC [ADC Counts];Events',
89 cutmask='rpdLEDPassFireCriteria',
90 path='rpdLEDMaxADC',
91 xbins=n_energy_bins_default,xmin=0.0,xmax=max_adc_max)
92 rpdChanLEDMonToolArr.defineHistogram('rpdLEDMaxSample', title=';LED Max Sample [ADC Counts];Events',
93 cutmask='rpdLEDPassFireCriteria',
94 path='rpdLEDMaxSample',
95 xbins=n_sample_bins_default,xmin=0.0,xmax=nsamples_max)
96 rpdChanLEDMonToolArr.defineHistogram('rpdLEDAvgTime', title=';LED Average Time [ns];Events',
97 cutmask='rpdLEDPassFireCriteria',
98 path='rpdLEDAvgTime',
99 xbins=n_time_bins_default,xmin=0.0,xmax=time_max)
100
101# -------------------------------------------- lumi block dependence ------------------------------------------------------
102
103 zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDADCSum;zdcLEDADCSum_vs_lb', type='TH2F', title=';lumi block;LED ADC Sum [ADC Counts]',
104 path='zdcLEDADCSumLBdep',
105 xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
106 ybins=n_adc_sum_fine_bins,ymin=0.0,ymax=adc_sum_max)
107 zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDMaxADC;zdcLEDMaxADC_vs_lb', type='TH2F', title=';lumi block;LED Max ADC [ADC Counts]',
108 path='zdcLEDMaxADCLBdep',
109 xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
110 ybins=n_energy_bins_default,ymin=0.0,ymax=max_adc_max)
111 zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDMaxSample;zdcLEDMaxSample_vs_lb', type='TH2F', title=';lumi block;LED Max Sample [ADC Counts]',
112 path='zdcLEDMaxSampleLBdep',
113 xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
114 ybins=n_sample_bins_default,ymin=0.0,ymax=nsamples_max)
115 zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDAvgTime;zdcLEDAvgTime_vs_lb', type='TH2F', title=';lumi block;LED Average Time [ns]',
116 path='zdcLEDAvgTimeLBdep',
117 xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
118 ybins=n_time_bins_default,ymin=0.0,ymax=time_max)
119 rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDADCSum;rpdLEDADCSum_vs_lb', type='TH2F', title=';lumi block;LED ADC Sum [ADC Counts]',
120 cutmask='rpdLEDPassFireCriteria',
121 path='rpdLEDADCSumLBdep',
122 xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
123 ybins=n_adc_sum_fine_bins,ymin=0.0,ymax=adc_sum_max)
124 rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDMaxADC;rpdLEDMaxADC_vs_lb', type='TH2F', title=';lumi block;LED Max ADC [ADC Counts]',
125 cutmask='rpdLEDPassFireCriteria',
126 path='rpdLEDMaxADCLBdep',
127 xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
128 ybins=n_energy_bins_default,ymin=0.0,ymax=max_adc_max)
129 rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDADCSum;rpdLEDADCSum_vs_lb_profile', type='TProfile', title=';lumi block;LED ADC Sum [ADC Counts]',
130 cutmask='rpdLEDPassFireCriteria',
131 path='rpdLEDADCSumLBdep',
132 xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
133 ybins=n_adc_sum_fine_bins,ymin=0.0,ymax=adc_sum_max)
134 rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDMaxADC;rpdLEDMaxADC_vs_lb_profile', type='TProfile', title=';lumi block;LED Max ADC [ADC Counts]',
135 cutmask='rpdLEDPassFireCriteria',
136 path='rpdLEDMaxADCLBdep',
137 xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
138 ybins=n_energy_bins_default,ymin=0.0,ymax=max_adc_max)
139 rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDMaxSample;rpdLEDMaxSample_vs_lb', type='TH2F', title=';lumi block;LED Max Sample [ADC Counts]',
140 cutmask='rpdLEDPassFireCriteria',
141 path='rpdLEDMaxSampleLBdep',
142 xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
143 ybins=n_sample_bins_default,ymin=0.0,ymax=nsamples_max)
144 rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDAvgTime;rpdLEDAvgTime_vs_lb', type='TH2F', title=';lumi block;LED Average Time [ns]',
145 cutmask='rpdLEDPassFireCriteria',
146 path='rpdLEDAvgTimeLBdep',
147 xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
148 ybins=n_time_bins_default,ymin=0.0,ymax=time_max)
149
150
151 acc = helper.result()
152 result.merge(acc)
153 return result
154
155
156if __name__=='__main__':
157 # Setup logs
158 from AthenaCommon.Logging import log
159 from AthenaCommon.Constants import WARNING
160 log.setLevel(WARNING)
161
162 # Set the Athena configuration flags
163 from AthenaConfiguration.AllConfigFlags import initConfigFlags
164 flags = initConfigFlags()
165 directory = ''
166 inputfile = 'myLEDAOD.pool.root'
167 flags.Input.Files = [directory+inputfile]
168 flags.Input.isMC = False
169 flags.Output.HISTFileName = 'ZdcLEDMonitorOutput_2018PbPb.root'
170 parser = flags.getArgumentParser()
171 parser.add_argument('--runNumber',default=None,help="specify to select a run number")
172 parser.add_argument('--outputHISTFile',default=None,help="specify output HIST file name")
173 args = flags.fillFromArgs(parser=parser)
174 if args.runNumber is not None: # streamTag has default but runNumber doesn't
175 flags.Output.HISTFileName = f'ZdcLEDMonitorOutput_HI2023_{args.runNumber}.root'
176 else:
177 flags.Output.HISTFileName = 'ZdcLEDMonitorOutput_HI2023.root'
178
179 if args.outputHISTFile is not None: # overwrite the output HIST file name to be match the name set in the grid job
180 flags.Output.HISTFileName = f'{args.outputHISTFile}'
181 flags.lock()
182
183 # Initialize configuration object, add accumulator, merge, and run.
184 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
185 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
186 cfg = MainServicesCfg(flags)
187 cfg.merge(PoolReadCfg(flags))
188
189 run_type = "pbpb"
190
191 zdcLEDMonitorAcc = ZdcLEDMonitoringConfig(flags, run_type)
192 cfg.merge(zdcLEDMonitorAcc)
193
194 # If you want to turn on more detailed messages ...
195 zdcLEDMonitorAcc.getEventAlgo('ZdcLEDMonAlg').OutputLevel = 2 # DEBUG
196 # If you want fewer messages ...
197
198 cfg.printConfig(withDetails=False) # set True for exhaustive info
199
200 cfg.run(20) #use cfg.run(20) to only run on first 20 events
201
ZdcLEDMonitoringConfig(inputFlags, run_type)