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 
23 # --------------------------------------------------------------------------------------------------
24 
25  nLEDs = 3
26  nSides = 2
27  nModules = 4
28  nChannels = 16
29 
30  n_energy_bins_default = 200
31  n_time_bins_default = 150
32  n_sample_bins_default = 25
33  lumi_block_max = 2000
34  bcid_max = 3564
35  l1TriggerType_max = 256
36  adc_sum_max = 8192.0
37  max_adc_max = 4096.0
38  nsamples_max = 25.0
39  time_max = 75.0
40 
41 # --------------------------------------------------------------------------------------------------
42  zdcLEDAllEventsDiagMonTool = helper.addGroup(zdcLEDMonAlg, 'ZdcLEDAllEventsDiagnosis','ZDC/AllLEDEventsDiagnosis/')
43 
44  zdcModLEDMonToolArr = helper.addArray([nLEDs,nSides,nModules],zdcLEDMonAlg,'ZdcModLEDMonitor', topPath='ZDC/ZDCLED/')
45  rpdChanLEDMonToolArr = helper.addArray([nLEDs,nSides,nChannels],zdcLEDMonAlg,'RPDChanLEDMonitor', topPath='ZDC/RPDLED/')
46 
47 # ------------------------- All-event (including bad events) diagnostic histograms -------------------------
48 
49 
50  zdcLEDAllEventsDiagMonTool.defineHistogram('bcid', title=';BCID;Events',
51  path='BCID',
52  xbins=bcid_max,xmin=0.0,xmax=bcid_max)
53 
54  zdcLEDAllEventsDiagMonTool.defineHistogram('l1TriggerType', title=';L1TriggerType;Events',
55  path='L1TriggerType',
56  xbins=l1TriggerType_max,xmin=0.0,xmax=l1TriggerType_max)
57 
58  zdcLEDAllEventsDiagMonTool.defineHistogram('lumiBlock, bcid', type='TH2F', title=';lumi block;BCID',
59  path='BCID',
60  xbins=int(lumi_block_max/10),xmin=0.0,xmax=lumi_block_max,
61  ybins=bcid_max,ymin=0.0,ymax=bcid_max)
62 
63  zdcLEDAllEventsDiagMonTool.defineHistogram('lumiBlock, l1TriggerType', type='TH2F', title=';lumi block;L1TriggerType',
64  path='L1TriggerType',
65  xbins=int(lumi_block_max/10),xmin=0.0,xmax=lumi_block_max,
66  ybins=l1TriggerType_max,ymin=0.0,ymax=l1TriggerType_max)
67 
68 
69 # -------------------------------------------- Observables ------------------------------------------------------
70 
71  zdcModLEDMonToolArr.defineHistogram('zdcLEDADCSum', title='LED ADC Sum [ADC Counts];Events',
72  path='zdcLEDADCSum',
73  xbins=n_energy_bins_default,xmin=0.0,xmax=adc_sum_max)
74  zdcModLEDMonToolArr.defineHistogram('zdcLEDMaxADC', title='LED Max ADC [ADC Counts];Events',
75  path='zdcLEDMaxADC',
76  xbins=n_energy_bins_default,xmin=0.0,xmax=max_adc_max)
77  zdcModLEDMonToolArr.defineHistogram('zdcLEDMaxSample', title='LED Max Sample [ADC Counts];Events',
78  path='zdcLEDMaxSample',
79  xbins=n_sample_bins_default,xmin=0.0,xmax=nsamples_max)
80  zdcModLEDMonToolArr.defineHistogram('zdcLEDAvgTime', title='LED Average Time [ns];Events',
81  path='zdcLEDAvgTime',
82  xbins=n_time_bins_default,xmin=0.0,xmax=time_max)
83  rpdChanLEDMonToolArr.defineHistogram('rpdLEDADCSum', title='LED ADC Sum [ADC Counts];Events',
84  path='rpdLEDADCSum',
85  xbins=n_energy_bins_default,xmin=0.0,xmax=adc_sum_max)
86  rpdChanLEDMonToolArr.defineHistogram('rpdLEDMaxADC', title='LED Max ADC [ADC Counts];Events',
87  path='rpdLEDMaxADC',
88  xbins=n_energy_bins_default,xmin=0.0,xmax=max_adc_max)
89  rpdChanLEDMonToolArr.defineHistogram('rpdLEDMaxSample', title='LED Max Sample [ADC Counts];Events',
90  path='rpdLEDMaxSample',
91  xbins=n_sample_bins_default,xmin=0.0,xmax=nsamples_max)
92  rpdChanLEDMonToolArr.defineHistogram('rpdLEDAvgTime', title='LED Average Time [ns];Events',
93  path='rpdLEDAvgTime',
94  xbins=n_time_bins_default,xmin=0.0,xmax=time_max)
95 
96 # -------------------------------------------- lumi block dependence ------------------------------------------------------
97 
98  zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDADCSum;zdcLEDADCSum_vs_lb', type='TH2F', title=';lumi block;LED ADC Sum [ADC Counts]',
99  path='zdcLEDADCSumLBdep',
100  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
101  ybins=n_energy_bins_default,ymin=0.0,ymax=adc_sum_max)
102  zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDMaxADC;zdcLEDMaxADC_vs_lb', type='TH2F', title=';lumi block;LED Max ADC [ADC Counts]',
103  path='zdcLEDMaxADCLBdep',
104  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
105  ybins=n_energy_bins_default,ymin=0.0,ymax=max_adc_max)
106  zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDMaxSample;zdcLEDMaxSample_vs_lb', type='TH2F', title=';lumi block;LED Max Sample [ADC Counts]',
107  path='zdcLEDMaxSampleLBdep',
108  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
109  ybins=n_sample_bins_default,ymin=0.0,ymax=nsamples_max)
110  zdcModLEDMonToolArr.defineHistogram('lumiBlock, zdcLEDAvgTime;zdcLEDAvgTime_vs_lb', type='TH2F', title=';lumi block;LED Average Time [ns]',
111  path='zdcLEDAvgTimeLBdep',
112  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
113  ybins=n_time_bins_default,ymin=0.0,ymax=time_max)
114  rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDADCSum;rpdLEDADCSum_vs_lb', type='TH2F', title=';lumi block;LED ADC Sum [ADC Counts]',
115  path='rpdLEDADCSumLBdep',
116  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
117  ybins=n_energy_bins_default,ymin=0.0,ymax=adc_sum_max)
118  rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDMaxADC;rpdLEDMaxADC_vs_lb', type='TH2F', title=';lumi block;LED Max ADC [ADC Counts]',
119  path='rpdLEDMaxADCLBdep',
120  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
121  ybins=n_energy_bins_default,ymin=0.0,ymax=max_adc_max)
122  rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDMaxSample;rpdLEDMaxSample_vs_lb', type='TH2F', title=';lumi block;LED Max Sample [ADC Counts]',
123  path='rpdLEDMaxSampleLBdep',
124  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
125  ybins=n_sample_bins_default,ymin=0.0,ymax=nsamples_max)
126  rpdChanLEDMonToolArr.defineHistogram('lumiBlock, rpdLEDAvgTime;rpdLEDAvgTime_vs_lb', type='TH2F', title=';lumi block;LED Average Time [ns]',
127  path='rpdLEDAvgTimeLBdep',
128  xbins=lumi_block_max,xmin=0.0,xmax=lumi_block_max,
129  ybins=n_time_bins_default,ymin=0.0,ymax=time_max)
130 
131 
132 # -------------------------------------------- BCID dependence ------------------------------------------------------
133 
134  zdcModLEDMonToolArr.defineHistogram('bcid, zdcLEDADCSum', type='TH2F', title=';BCID;LED ADC Sum [ADC Counts]',
135  path='zdcLEDADCSumBCIDdep',
136  xbins=bcid_max,xmin=0.0,xmax=bcid_max,
137  ybins=n_energy_bins_default,ymin=0.0,ymax=adc_sum_max)
138  zdcModLEDMonToolArr.defineHistogram('bcid, zdcLEDMaxADC', type='TH2F', title=';BCID;LED Max ADC [ADC Counts]',
139  path='zdcLEDMaxADCBCIDdep',
140  xbins=bcid_max,xmin=0.0,xmax=bcid_max,
141  ybins=n_energy_bins_default,ymin=0.0,ymax=max_adc_max)
142  zdcModLEDMonToolArr.defineHistogram('bcid, zdcLEDMaxSample', type='TH2F', title=';BCID;LED Max Sample [ADC Counts]',
143  path='zdcLEDMaxSampleBCIDdep',
144  xbins=bcid_max,xmin=0.0,xmax=bcid_max,
145  ybins=n_sample_bins_default,ymin=0.0,ymax=nsamples_max)
146  zdcModLEDMonToolArr.defineHistogram('bcid, zdcLEDAvgTime', type='TH2F', title=';BCID;LED Average Time [ns]',
147  path='zdcLEDAvgTimeBCIDdep',
148  xbins=bcid_max,xmin=0.0,xmax=bcid_max,
149  ybins=n_time_bins_default,ymin=0.0,ymax=time_max)
150  rpdChanLEDMonToolArr.defineHistogram('bcid, rpdLEDADCSum', type='TH2F', title=';BCID;LED ADC Sum [ADC Counts]',
151  path='rpdLEDADCSumBCIDdep',
152  xbins=bcid_max,xmin=0.0,xmax=bcid_max,
153  ybins=n_energy_bins_default,ymin=0.0,ymax=adc_sum_max)
154  rpdChanLEDMonToolArr.defineHistogram('bcid, rpdLEDMaxADC', type='TH2F', title=';BCID;LED Max ADC [ADC Counts]',
155  path='rpdLEDMaxADCBCIDdep',
156  xbins=bcid_max,xmin=0.0,xmax=bcid_max,
157  ybins=n_energy_bins_default,ymin=0.0,ymax=max_adc_max)
158  rpdChanLEDMonToolArr.defineHistogram('bcid, rpdLEDMaxSample', type='TH2F', title=';BCID;LED Max Sample [ADC Counts]',
159  path='rpdLEDMaxSampleBCIDdep',
160  xbins=bcid_max,xmin=0.0,xmax=bcid_max,
161  ybins=n_sample_bins_default,ymin=0.0,ymax=nsamples_max)
162  rpdChanLEDMonToolArr.defineHistogram('bcid, rpdLEDAvgTime', type='TH2F', title=';BCID;LED Average Time [ns]',
163  path='rpdLEDAvgTimeBCIDdep',
164  xbins=bcid_max,xmin=0.0,xmax=bcid_max,
165  ybins=n_time_bins_default,ymin=0.0,ymax=time_max)
166 
167 
168  return helper.result()
169 
170 
171 if __name__=='__main__':
172  # Setup logs
173  from AthenaCommon.Logging import log
174  from AthenaCommon.Constants import WARNING
175  log.setLevel(WARNING)
176 
177  # Set the Athena configuration flags
178  from AthenaConfiguration.AllConfigFlags import initConfigFlags
179  flags = initConfigFlags()
180  directory = ''
181  inputfile = 'myLEDAOD.pool.root'
182  flags.Input.Files = [directory+inputfile]
183  flags.Input.isMC = False
184  flags.Output.HISTFileName = 'ZdcLEDMonitorOutput_2018PbPb.root'
185  parser = flags.getArgumentParser()
186  parser.add_argument('--runNumber',default=None,help="specify to select a run number")
187  parser.add_argument('--outputHISTFile',default=None,help="specify output HIST file name")
188  args = flags.fillFromArgs(parser=parser)
189  if args.runNumber is not None: # streamTag has default but runNumber doesn't
190  flags.Output.HISTFileName = f'ZdcLEDMonitorOutput_HI2023_{args.runNumber}.root'
191  else:
192  flags.Output.HISTFileName = 'ZdcLEDMonitorOutput_HI2023.root'
193 
194  if args.outputHISTFile is not None: # overwrite the output HIST file name to be match the name set in the grid job
195  flags.Output.HISTFileName = f'{args.outputHISTFile}'
196  flags.lock()
197 
198  # Initialize configuration object, add accumulator, merge, and run.
199  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
200  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
201  cfg = MainServicesCfg(flags)
202  cfg.merge(PoolReadCfg(flags))
203 
204  run_type = "pbpb"
205 
206  zdcLEDMonitorAcc = ZdcLEDMonitoringConfig(flags, run_type)
207  cfg.merge(zdcLEDMonitorAcc)
208 
209  # If you want to turn on more detailed messages ...
210  zdcLEDMonitorAcc.getEventAlgo('ZdcLEDMonAlg').OutputLevel = 2 # DEBUG
211  # If you want fewer messages ...
212 
213  cfg.printConfig(withDetails=False) # set True for exhaustive info
214 
215  cfg.run(20) #use cfg.run(20) to only run on first 20 events
216 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ZdcLEDMonitorAlgorithm.ZdcLEDMonitoringConfig
def ZdcLEDMonitoringConfig(inputFlags, run_type)
Definition: ZdcLEDMonitorAlgorithm.py:14
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:252
Constants
some useful constants -------------------------------------------------—
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69