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