ATLAS Offline Software
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 '''
14 def 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  path='rpdLEDADCSum',
86  xbins=n_adc_sum_fine_bins,xmin=0.0,xmax=adc_sum_max)
87  rpdChanLEDMonToolArr.defineHistogram('rpdLEDMaxADC', title=';LED Max ADC [ADC Counts];Events',
88  path='rpdLEDMaxADC',
89  xbins=n_energy_bins_default,xmin=0.0,xmax=max_adc_max)
90  rpdChanLEDMonToolArr.defineHistogram('rpdLEDMaxSample', title=';LED Max Sample [ADC Counts];Events',
91  path='rpdLEDMaxSample',
92  xbins=n_sample_bins_default,xmin=0.0,xmax=nsamples_max)
93  rpdChanLEDMonToolArr.defineHistogram('rpdLEDAvgTime', title=';LED Average Time [ns];Events',
94  path='rpdLEDAvgTime',
95  xbins=n_time_bins_default,xmin=0.0,xmax=time_max)
96 
97 # -------------------------------------------- lumi block dependence ------------------------------------------------------
98 
99  zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDADCSum;zdcLEDADCSum_vs_lb', type='TH2F', title=';lumi block;LED ADC Sum [ADC Counts]',
100  path='zdcLEDADCSumLBdep',
101  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
102  ybins=n_adc_sum_fine_bins,ymin=0.0,ymax=adc_sum_max)
103  zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDMaxADC;zdcLEDMaxADC_vs_lb', type='TH2F', title=';lumi block;LED Max ADC [ADC Counts]',
104  path='zdcLEDMaxADCLBdep',
105  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
106  ybins=n_energy_bins_default,ymin=0.0,ymax=max_adc_max)
107  zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDMaxSample;zdcLEDMaxSample_vs_lb', type='TH2F', title=';lumi block;LED Max Sample [ADC Counts]',
108  path='zdcLEDMaxSampleLBdep',
109  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
110  ybins=n_sample_bins_default,ymin=0.0,ymax=nsamples_max)
111  zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDAvgTime;zdcLEDAvgTime_vs_lb', type='TH2F', title=';lumi block;LED Average Time [ns]',
112  path='zdcLEDAvgTimeLBdep',
113  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
114  ybins=n_time_bins_default,ymin=0.0,ymax=time_max)
115  rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDADCSum;rpdLEDADCSum_vs_lb', type='TH2F', title=';lumi block;LED ADC Sum [ADC Counts]',
116  path='rpdLEDADCSumLBdep',
117  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
118  ybins=n_adc_sum_fine_bins,ymin=0.0,ymax=adc_sum_max)
119  rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDMaxADC;rpdLEDMaxADC_vs_lb', type='TH2F', title=';lumi block;LED Max ADC [ADC Counts]',
120  path='rpdLEDMaxADCLBdep',
121  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
122  ybins=n_energy_bins_default,ymin=0.0,ymax=max_adc_max)
123  rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDMaxSample;rpdLEDMaxSample_vs_lb', type='TH2F', title=';lumi block;LED Max Sample [ADC Counts]',
124  path='rpdLEDMaxSampleLBdep',
125  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
126  ybins=n_sample_bins_default,ymin=0.0,ymax=nsamples_max)
127  rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDAvgTime;rpdLEDAvgTime_vs_lb', type='TH2F', title=';lumi block;LED Average Time [ns]',
128  path='rpdLEDAvgTimeLBdep',
129  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
130  ybins=n_time_bins_default,ymin=0.0,ymax=time_max)
131 
132 
133  acc = helper.result()
134  result.merge(acc)
135  return result
136 
137 
138 if __name__=='__main__':
139  # Setup logs
140  from AthenaCommon.Logging import log
141  from AthenaCommon.Constants import WARNING
142  log.setLevel(WARNING)
143 
144  # Set the Athena configuration flags
145  from AthenaConfiguration.AllConfigFlags import initConfigFlags
146  flags = initConfigFlags()
147  directory = ''
148  inputfile = 'myLEDAOD.pool.root'
149  flags.Input.Files = [directory+inputfile]
150  flags.Input.isMC = False
151  flags.Output.HISTFileName = 'ZdcLEDMonitorOutput_2018PbPb.root'
152  parser = flags.getArgumentParser()
153  parser.add_argument('--runNumber',default=None,help="specify to select a run number")
154  parser.add_argument('--outputHISTFile',default=None,help="specify output HIST file name")
155  args = flags.fillFromArgs(parser=parser)
156  if args.runNumber is not None: # streamTag has default but runNumber doesn't
157  flags.Output.HISTFileName = f'ZdcLEDMonitorOutput_HI2023_{args.runNumber}.root'
158  else:
159  flags.Output.HISTFileName = 'ZdcLEDMonitorOutput_HI2023.root'
160 
161  if args.outputHISTFile is not None: # overwrite the output HIST file name to be match the name set in the grid job
162  flags.Output.HISTFileName = f'{args.outputHISTFile}'
163  flags.lock()
164 
165  # Initialize configuration object, add accumulator, merge, and run.
166  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
167  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
168  cfg = MainServicesCfg(flags)
169  cfg.merge(PoolReadCfg(flags))
170 
171  run_type = "pbpb"
172 
173  zdcLEDMonitorAcc = ZdcLEDMonitoringConfig(flags, run_type)
174  cfg.merge(zdcLEDMonitorAcc)
175 
176  # If you want to turn on more detailed messages ...
177  zdcLEDMonitorAcc.getEventAlgo('ZdcLEDMonAlg').OutputLevel = 2 # DEBUG
178  # If you want fewer messages ...
179 
180  cfg.printConfig(withDetails=False) # set True for exhaustive info
181 
182  cfg.run(20) #use cfg.run(20) to only run on first 20 events
183 
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
ZdcLEDMonitorAlgorithm.ZdcLEDMonitoringConfig
def ZdcLEDMonitoringConfig(inputFlags, run_type)
Definition: ZdcLEDMonitorAlgorithm.py:14
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:312
Constants
some useful constants -------------------------------------------------—
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:71