ATLAS Offline Software
Loading...
Searching...
No Matches
TileDigitsFlxMonitorAlgorithm.py
Go to the documentation of this file.
2# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3#
4
5'''
6@file TileDigitsFlxMonitorAlgorithm.py
7@brief Python configuration of TileDigitsFlxMonitorAlgorithm algorithm for the Run III
8'''
9
10def TileDigitsFlxMonitoringConfig(flags, fragIDs=[0x201, 0x402], topPath='TestBeam', **kwargs):
11 '''Function to configures TileDigitsFlxMonAlg algorithms in the monitoring system.'''
12
13 kwargs.setdefault('TileDigitsContainerLegacy', 'TileDigitsCnt')
14 kwargs.setdefault('TileDigitsContainerFlx', 'TileDigitsFlxCnt')
15 kwargs.setdefault('FirstSample', 0)
16 kwargs.setdefault('LastSample', 15)
17 kwargs.setdefault('FelixOffset', 0)
18 kwargs.setdefault('FelixScale', 4)
19
20 felixScale = kwargs['FelixScale']
21
22 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
23 result = ComponentAccumulator()
24
25 from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg
26 result.merge( TileCablingSvcCfg(flags) )
27
28 from AthenaMonitoring import AthMonitorCfgHelper
29 helper = AthMonitorCfgHelper(flags, 'TileDigitsFlxMonitoring')
30
31 from AthenaConfiguration.ComponentFactory import CompFactory
32 TileDigitsFlxMonitorAlgorithm = CompFactory.TileDigitsFlxMonitorAlgorithm
33 tileDigitsFlxMonAlg = helper.addAlgorithm(TileDigitsFlxMonitorAlgorithm, 'TileDigitsFlxMonAlg')
34 tileDigitsFlxMonAlg.TriggerChain = ''
35
36 for k, v in kwargs.items():
37 setattr(tileDigitsFlxMonAlg, k, v)
38
39 # Configure histogram with TileDigitsFlxMonAlg algorithm execution time
40 executeTimeGroup = helper.addGroup(tileDigitsFlxMonAlg, 'TileDigitsFlxMonExecuteTime', f'{topPath}/Felix')
41 executeTimeGroup.defineHistogram('TIME_execute', path = 'Digits', type='TH1F',
42 title = 'Time for execute TileDigitsFlxMonAlg algorithm;time [#mus]',
43 xbins = 300, xmin = 0, xmax = 300000)
44
45 runNumber = flags.Input.RunNumbers[0]
46 from TileCalibBlobObjs.Classes import TileCalibUtils as Tile
47
48 modules = []
49 if fragIDs:
50 for fragID in fragIDs:
51 ros = fragID >> 8
52 drawer = fragID & 0x3F
53 modules += [Tile.getDrawerString(ros, drawer)]
54 else:
55 for ros in range(1, Tile.MAX_ROS):
56 for drawer in range(0, Tile.MAX_DRAWER):
57 modules += [Tile.getDrawerString(ros, drawer)]
58
59 channelHFNGroup = helper.addGroup(tileDigitsFlxMonAlg, 'TileFlxMonHFN', f'{topPath}/Felix/Digits')
60 for moduleName in modules:
61 for gainName in ['HG', 'LG']:
62 title = f'Run {runNumber} {moduleName} {gainName}: Mean RMS in event (HFN)-FELIX;Channel;HFN'
63 name = f'{moduleName}_{gainName}_channel,{moduleName}_{gainName}_HFN;{moduleName}_HFN_{gainName}'
64 path = moduleName
65 channelHFNGroup.defineHistogram(name, title = title, path = path, type = 'TProfile',
66 xbins = 48, xmin = -0.5, xmax = 47.5)
67
68 channelPedGroup = helper.addGroup(tileDigitsFlxMonAlg, 'TileFlxMonPed', f'{topPath}/Felix/Digits')
69 for moduleName in modules:
70 for gainName in ['HG', 'LG']:
71 title = f'Run {runNumber} {moduleName} {gainName}: Pedestal, sample[0]-FELIX;Channel;ADC'
72 name = f'{moduleName}_{gainName}_channel,{moduleName}_{gainName}_Pedestal;{moduleName}_Pedestal_{gainName}'
73 path = moduleName
74 channelPedGroup.defineHistogram(name, title = title, path = path, type = 'TProfile',
75 xbins = 48, xmin = -0.5, xmax = 47.5)
76
77 channelHFNGroup = helper.addGroup(tileDigitsFlxMonAlg, 'TileLegacyMonHFN', f'{topPath}/Legacy/Digits')
78 for moduleName in modules:
79 for gainName in ['HG', 'LG']:
80 title = f'Run {runNumber} {moduleName} {gainName}: Mean RMS in event (HFN);Channel;HFN'
81 name = f'{moduleName}_{gainName}_channel,{moduleName}_{gainName}_HFN;{moduleName}_HFN_{gainName}'
82 path = moduleName
83 channelHFNGroup.defineHistogram(name, title = title, path = path, type = 'TProfile',
84 xbins = 48, xmin = -0.5, xmax = 47.5)
85
86 channelPedGroup = helper.addGroup(tileDigitsFlxMonAlg, 'TileLegacyMonPed', f'{topPath}/Legacy/Digits')
87 for moduleName in modules:
88 for gainName in ['HG', 'LG']:
89 title = f'Run {runNumber} {moduleName} {gainName}: Pedestal, sample[0];Channel;ADC'
90 name = f'{moduleName}_{gainName}_channel,{moduleName}_{gainName}_Pedestal;{moduleName}_Pedestal_{gainName}'
91 path = moduleName
92 channelPedGroup.defineHistogram(name, title = title, path = path, type = 'TProfile',
93 xbins = 48, xmin = -0.5, xmax = 47.5)
94
95 channelSamplesFlxGroup = helper.addGroup(tileDigitsFlxMonAlg, 'TileFlxMonSamples', f'{topPath}/Felix/Digits')
96 for moduleName in modules:
97 for channel in range(0, Tile.MAX_CHAN):
98 for gainName in ['HG', 'LG']:
99 title = (f'Run {runNumber} {moduleName} channel {channel} {gainName}: Samples-FELIX;Sample [ADC];N')
100 name = f'{moduleName}_ch_{str(channel)}_{gainName}_samples'
101 path = moduleName
102 channelSamplesFlxGroup.defineHistogram(name, title = title, path = path, type = 'TH1F',
103 xbins = 4096, xmin = -0.5, xmax = 4095.5)
104
105
106 channelSamplesLegacyGroup = helper.addGroup(tileDigitsFlxMonAlg, 'TileLegacyMonSamples', f'{topPath}/Legacy/Digits')
107 for moduleName in modules:
108 for channel in range(0, Tile.MAX_CHAN):
109 for gainName in ['HG', 'LG']:
110 title = (f'Run {runNumber} {moduleName} channel {channel} {gainName}: Samples;Sample [ADC];N')
111 name = f'{moduleName}_ch_{str(channel)}_{gainName}_samples'
112 path = moduleName
113 channelSamplesLegacyGroup.defineHistogram(name, title = title, path = path, type = 'TH1F',
114 xbins = 1024, xmin = -0.5, xmax = 1023.5)
115
116 channelAllSamplesDiffGroup = helper.addGroup(tileDigitsFlxMonAlg, 'TileChannelAllSamplesDiff', f'{topPath}/Compare/Digits')
117 for moduleName in modules:
118 for channel in range(0, Tile.MAX_CHAN):
119 for gainName in ['HG', 'LG']:
120 title = (f'Run {runNumber} {moduleName} channel {channel} {gainName}: Samples difference (FELIX-Legacy*{felixScale});Sample [ADC];N')
121 name = f'{moduleName}_ch_{str(channel)}_{gainName}_samples_diff'
122 path = moduleName
123 channelAllSamplesDiffGroup.defineHistogram(name, title = title, path = path, type = 'TH1F',
124 xbins = 200, xmin = -100, xmax = 100)
125
126 moduleAllSamplesGroup = helper.addGroup(tileDigitsFlxMonAlg, 'TileModuleAllSamplesDiff', f'{topPath}/Compare/Digits')
127 for moduleName in modules:
128 for gainName in ['HG', 'LG']:
129 title = (f'Run {runNumber} {moduleName} {gainName}: All channels samples difference (FELIX-Legacy*{felixScale});Sample [ADC];N')
130 name = f'{moduleName}_{gainName}_samples_diff;{moduleName}_{gainName}_all_channels_samples_diff'
131 path = moduleName
132 moduleAllSamplesGroup.defineHistogram(name, title = title, path = path, type = 'TH1F',
133 xbins = 200, xmin = -100, xmax = 100)
134
135 moduleSamplesDiffGroup = helper.addGroup(tileDigitsFlxMonAlg, 'TileModuleSamplesDiff', f'{topPath}/Compare/Digits')
136 for moduleName in modules:
137 for gainName in ['HG', 'LG']:
138 title = f'Run {runNumber} {moduleName} {gainName}: Samples difference (FELIX-Legacy*{felixScale});Channel;ADC'
139 name = f'{moduleName}_{gainName}_channel,{moduleName}_{gainName}_samples_diff;{moduleName}_{gainName}_samples_diff'
140 path = moduleName
141 moduleSamplesDiffGroup.defineHistogram(name, title = title, path = path, type = 'TProfile',
142 xbins = 48, xmin = -0.5, xmax = 47.5)
143
144
145 accumalator = helper.result()
146 result.merge(accumalator)
147 return result
148
149
150if __name__=='__main__':
151 # Setup logs
152 from AthenaCommon.Logging import log
153 from AthenaCommon.Constants import INFO
154 log.setLevel(INFO)
155
156 # Set the Athena configuration flags
157 from AthenaConfiguration.AllConfigFlags import initConfigFlags
158 flags = initConfigFlags()
159 parser = flags.getArgumentParser()
160 parser.add_argument('--postExec', help='Code to execute after setup')
161 parser.add_argument('--digits', default="TileDigitsCnt", help='Tile digits container to be monitored')
162 parser.add_argument('--frag-ids', dest='fragIDs', nargs="*", default=['0x201','0x402'], help='Tile Frag IDs of modules to be monitored. Empty=ALL')
163 args, _ = parser.parse_known_args()
164
165 fragIDs = [int(fragID, base=16) for fragID in args.fragIDs]
166
167 from AthenaConfiguration.TestDefaults import defaultGeometryTags, defaultTestFiles
168 flags.Input.Files = defaultTestFiles.RAW_RUN2
169 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN2
170 flags.Output.HISTFileName = 'TileDigitsFlxMonitorOutput.root'
171 flags.DQ.useTrigger = False
172 flags.DQ.enableLumiAccess = False
173 flags.Exec.MaxEvents = 3
174 flags.fillFromArgs(parser=parser)
175 flags.lock()
176
177 # Initialize configuration object, add accumulator, merge, and run.
178 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
179 cfg = MainServicesCfg(flags)
180
181 from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
182 cfg.merge( TileRawDataReadingCfg(flags, readDigits=True, readRawChannel=False, readMuRcv=False,
183 readDigitsFlx=(True if 'Flx' in args.digits else False)) )
184
185 tileDigitsFlxMonitorAccumulator = TileDigitsFlxMonitoringConfig(flags,
186 fragIDs = fragIDs,
187 TileDigitsContainerLegacy="TileDigitsCnt",
188 TileDigitsContainerFlx=args.digits)
189
190 cfg.merge(tileDigitsFlxMonitorAccumulator)
191
192 # Any last things to do?
193 if args.postExec:
194 log.info('Executing postExec: %s', args.postExec)
195 exec(args.postExec)
196
197 cfg.printConfig(withDetails = True, summariseProps = True)
198 flags.dump()
199
200 cfg.store( open('TileDigitsFlxMonitorAlgorithm.pkl','wb') )
201
202 sc = cfg.run()
203
204 import sys
205 # Success should be 0
206 sys.exit(not sc.isSuccess())
207
TileDigitsFlxMonitoringConfig(flags, fragIDs=[0x201, 0x402], topPath='TestBeam', **kwargs)