ATLAS Offline Software
Loading...
Searching...
No Matches
TileTBMonitorAlgorithm.py
Go to the documentation of this file.
2# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3#
4'''
5@file TileTBMonitorAlgorithm.py
6@brief Python configuration of TileTBMonitorAlgorithm algorithm for the Run III
7'''
8
9from AthenaConfiguration.Enums import Format
10from AthenaCommon.SystemOfUnits import GeV
11
12def TileTBMonitoringConfig(flags, fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], **kwargs):
13
14 ''' Function to configure TileTBMonitorAlgorithm algorithm in the monitoring system.'''
15
16 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
17 result = ComponentAccumulator()
18
19 from TileGeoModel.TileGMConfig import TileGMCfg
20 result.merge(TileGMCfg(flags))
21
22 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
23 result.merge(LArGMCfg(flags))
24
25 from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg
26 result.merge(TileCablingSvcCfg(flags))
27
28 from AthenaMonitoring import AthMonitorCfgHelper
29 helper = AthMonitorCfgHelper(flags, 'TileTBMonitoring')
30
31 from AthenaConfiguration.ComponentFactory import CompFactory
32 tileTBMonAlg = helper.addAlgorithm(CompFactory.TileTBMonitorAlgorithm, 'TileTBMonAlg')
33
34 tileTBMonAlg.TriggerChain = ''
35
36 kwargs.setdefault('BeamEnergy', flags.Beam.Energy)
37 kwargs.setdefault('CellEnergyThreshold', 0.1 * GeV)
38 energyThreshold = kwargs['CellEnergyThreshold']
39
40 masked = ['LBA01 0 ' + ",".join([str(channel) for channel in range(0, 48)]),
41 'LBA01 1 ' + ",".join([str(channel) for channel in range(0, 48)]),
42 'LBC01 0 36,37,38,39,40,41',
43 'LBC01 1 36,37,38,39,40,41']
44 kwargs.setdefault('Masked', masked)
45
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 fragIDs += [(ros << 8) | drawer]
58 modules += [Tile.getDrawerString(ros, drawer)]
59
60 tileTBMonAlg.TileFragIDs = fragIDs
61
62 for k, v in kwargs.items():
63 setattr(tileTBMonAlg, k, v)
64
65 run = str(flags.Input.RunNumbers[0])
66
67 # Configure histogram with TileTBMonAlg algorithm execution time
68 executeTimeGroup = helper.addGroup(tileTBMonAlg, 'TileTBMonExecuteTime', 'TestBeam')
69 executeTimeGroup.defineHistogram('TIME_execute', path='', type='TH1F',
70 title='Time for execute TileTBMonAlg algorithm;time [#mus]',
71 xbins=100, xmin=0, xmax=10000)
72
73 totalEnergyGroup = helper.addGroup(tileTBMonAlg, 'TileTBTotalEventEnergy', 'TestBeam')
74 totalEnergyGroup.defineHistogram('energy;TileTBTotalEventEnergy', path='', type='TH1F',
75 title=f'Run {run}: Total TileCal Event Energy;Event Energy [pC]',
76 xbins=400, xmin=-2, xmax=200)
77
78 hotCellAGroup = helper.addGroup(tileTBMonAlg, 'TileTBHotCellA_LBC02', 'TestBeam')
79 hotCellAGroup.defineHistogram('tower;TileTBHotCellA_LBC02', path='', type='TH1F',
80 title=f'Run {run} LBC02: Tile TB Hot Cell A;Tower',
81 xbins=10, xmin=-0.5, xmax=9.5)
82
83 CtotGroup = helper.addGroup(tileTBMonAlg, 'TileTBCtot', 'TestBeam')
84 CtotGroup.defineHistogram('Ctot;TileTBCtot', path='', type='TH1F',
85 title=f'Run {run} LBC02: Tile TB Ctot;Ctot',
86 xbins=100, xmin=0.03, xmax=0.22)
87
88 ClongGroup = helper.addGroup(tileTBMonAlg, 'TileTBClong', 'TestBeam')
89 ClongGroup.defineHistogram('Clong;TileTBClong', path='', type='TH1F',
90 title=f'Run {run} LBC02: Tile TB Clong;Clong',
91 xbins=100, xmin=0., xmax=1.8)
92
93 CtotVsClongGroup = helper.addGroup(tileTBMonAlg, 'TileTBCtotVsClong', 'TestBeam')
94 CtotVsClongGroup.defineHistogram('Clong,Ctot;TileTBCtotVsClong', path='', type='TH2F',
95 title=f'Run {run} LBC02: Tile TB Ctot Vs Clong;Clong;Ctot',
96 xbins=100, xmin=0., xmax=1.8, ybins=100, ymin=0.03, ymax=0.22)
97
98
99 maxTotalEnergy = 150
100 nCellsVsEnergyGroup = helper.addGroup(tileTBMonAlg, 'TileTBCellsNumberVsTotalEnergy', 'TestBeam')
101 nCellsVsEnergyGroup.defineHistogram('nCells,energy;TileTBCellsNumberVsTotalEnergy', path='', type='TH2F',
102 title=f'Run {run}: Tile Event energy [C side] vs # cells with energy > {energyThreshold} pC;# Cells;Energy [pC]',
103 xbins=25, xmin=-0.5, xmax=24.5, ybins=maxTotalEnergy, ymin=0.0, ymax=maxTotalEnergy)
104
105 hitMapGroup = helper.addGroup(tileTBMonAlg, 'TileTBHitMap', 'TestBeam')
106 hitMapGroup.defineHistogram('side,module,energy;TileTBHitMap', path='', type='TProfile2D',
107 title=f'Run {run}: Tile TB setup map with average energy',
108 xlabels=['A Side', 'C side'], ylabels=['LB01', 'LB02', 'EB03'],
109 xbins=2, xmin=-0.5, xmax=1.5, ybins=3, ymin=-0.5, ymax=2.5)
110
111 timeArray = helper.addArray([modules], tileTBMonAlg, 'TileTBChannelTime', topPath='TestBeam')
112 for postfix, tool in timeArray.Tools.items():
113 moduleName = postfix[1:]
114 name = f'channel,time;TileTBChannelTime_{moduleName}'
115 fullTitle = f'Run {run} {moduleName}: Tile TB channel average time from cells;Channel;Time [ns]'
116 tool.defineHistogram(name, title=fullTitle, path='', type='TProfile',
117 xbins=Tile.MAX_CHAN, xmin=-0.5, xmax=Tile.MAX_CHAN-0.5)
118
119 maxSample = 3
120 maxTowerLB = 10
121 xCellLB = [[[] for tower in range(0, maxTowerLB)] for sample in range(0, maxSample)]
122 yCellLB = [[[] for tower in range(0, maxTowerLB)] for sample in range(0, maxSample)]
123
124 periodWidthLB = 18.22
125 # Approximate number of periods in Tile Cells in LB per sampling and tower
126 nPeriodsLB = [[14, 13, 14, 14, 15, 16, 16, 17, 19, 16], # A1-A10
127 [16, 15, 16, 16, 17, 18, 18, 20, 18], # B1-B9
128 [18, 18, 18, 19, 19, 20, 22, 20], # C1-C8
129 [20, 0, 41, 0, 43, 0, 50]] # D0-D3
130
131 yLB = [0, 300, 690, 1140, 1520]
132 for sampleIndex in range(0, len(nPeriodsLB)):
133 sample = sampleIndex if sampleIndex < 2 else sampleIndex - 1
134 cellOffsetX = 0.0
135 for tower in range(0, len(nPeriodsLB[sampleIndex])):
136 cellWidth = nPeriodsLB[sampleIndex][tower] * periodWidthLB
137 x1 = cellOffsetX + 9 # Approximate center of the period
138 x2 = cellOffsetX + cellWidth
139 while x1 < x2:
140 xCellLB[sample][tower] += [x1]
141 yCellLB[sample][tower] += [yLB[sampleIndex]]
142 x1 += periodWidthLB
143
144 cellOffsetX += cellWidth
145
146 tileTBMonAlg.xCellLongBarrelSampleA = xCellLB[0]
147 tileTBMonAlg.xCellLongBarrelSampleBC = xCellLB[1]
148 tileTBMonAlg.xCellLongBarrelSampleD = xCellLB[2]
149
150 tileTBMonAlg.yCellLongBarrelSampleA = yCellLB[0]
151 tileTBMonAlg.yCellLongBarrelSampleBC = yCellLB[1]
152 tileTBMonAlg.yCellLongBarrelSampleD = yCellLB[2]
153
154 maxTowerEB = 16
155 periodWidthEB = 18.28
156 xCellEB = [[[] for tower in range(0, maxTowerEB)] for sample in range(0, maxSample)]
157 yCellEB = [[[] for tower in range(0, maxTowerEB)] for sample in range(0, maxSample)]
158
159 yEB = [0, 300, 690, 840, 840, 1140, 1520]
160 # Approximate number of periods in Tile Cells in EB per sampling and tower
161 nPeriodsEB = [[17, 0, 0, 9, 25, 28, 30, 48], # A12-A16
162 [17, 0, 16, 27, 30, 32, 35], # B11-B15
163 [12, 5, 16, 27, 30, 32, 35], # C10, B11-B15
164 [12, 5], # C10
165 [0, 17, 65, 0, 75], # D5,D6
166 [17, 0, 65, 0, 75]] # D4,D5,D6
167
168 samples = [0, 1, 1, 1, 2, 2]
169 for sampleIndex in range(0, len(nPeriodsEB)):
170 sample = samples[sampleIndex]
171 cellOffsetX = 0.0
172 for tower in range(0, len(nPeriodsEB[sampleIndex])):
173 cellWidth = nPeriodsEB[sampleIndex][tower] * periodWidthEB
174 x1 = cellOffsetX + 9 # Approximate center of the period
175 x2 = cellOffsetX + cellWidth
176 while x1 < x2:
177 xCellEB[sample][tower + 8] += [x1]
178 yCellEB[sample][tower + 8] += [yEB[sampleIndex]]
179 x1 += periodWidthEB
180
181 cellOffsetX += cellWidth
182
183 tileTBMonAlg.xCellExtendedBarrelSampleA = xCellEB[0]
184 tileTBMonAlg.xCellExtendedBarrelSampleBC = xCellEB[1]
185 tileTBMonAlg.xCellExtendedBarrelSampleD = xCellEB[2]
186
187 tileTBMonAlg.yCellExtendedBarrelSampleA = yCellEB[0]
188 tileTBMonAlg.yCellExtendedBarrelSampleBC = yCellEB[1]
189 tileTBMonAlg.yCellExtendedBarrelSampleD = yCellEB[2]
190
191 xBinsLB = [x * periodWidthLB for x in range(0, sum(nPeriodsLB[0]) + 1)]
192 yBinsLB = [0, 300, 690, 1140, 1520]
193
194 xBinsEB = [x * periodWidthEB for x in range(0, sum(nPeriodsEB[0]) + 1)]
195 yBinsEB = [0, 300, 690, 840, 1140, 1520]
196 cellMapArray = helper.addArray([modules], tileTBMonAlg, 'TileTBCellMap', topPath='TestBeam')
197 for postfix, tool in cellMapArray.Tools.items():
198 moduleName = postfix[1:]
199 name = f'x,y,energy;TileTBCellMap_{moduleName}'
200 fullTitle = f'Run {run} {moduleName}: Tile TB cell map with average energy;z [mm];x [mm];Energy [pc]'
201 tool.defineHistogram(name, title=fullTitle, path='', type='TProfile2D',
202 xbins=xBinsLB if moduleName.startswith('LB') else xBinsEB,
203 ybins=yBinsLB if moduleName.startswith('LB') else yBinsEB)
204
205 accumalator = helper.result()
206 result.merge(accumalator)
207 return result
208
209
210if __name__ == '__main__':
211
212 # Setup logs
213 from AthenaCommon.Logging import log
214 from AthenaCommon.Constants import INFO
215 log.setLevel(INFO)
216
217 # Set the Athena configuration flags
218 from AthenaConfiguration.AllConfigFlags import initConfigFlags
219 from AthenaConfiguration.TestDefaults import defaultTestFiles
220
221 flags = initConfigFlags()
222 parser = flags.getArgumentParser()
223 parser.add_argument('--postExec', help='Code to execute after setup')
224 parser.add_argument('--digits', default="TileDigitsCnt", help='Tile digits container')
225 parser.add_argument('--channels', default="TileRawChannelCnt",
226 help='Tile raw channel container, if empty they will be reconstructed from digits')
227 parser.add_argument('--cells', default="AllCalo",
228 help='Calo Cells container, if empty they will be reconstructed from channels')
229 parser.add_argument('--frag-ids', dest='fragIDs', nargs="*", default=['0x100', '0x101', '0x200', '0x201', '0x402'],
230 help='Tile Frag IDs of modules to be monitored. Empty=ALL')
231 parser.add_argument('--demo-cabling', dest='demoCabling', type=int, default=2018, help='Time Demonatrator cabling to be used')
232 parser.add_argument('--nsamples', type=int, default=15, help='Number of samples')
233 parser.add_argument('--use-sqlite', dest='useSqlite', default='/afs/cern.ch/user/t/tiledemo/public/efmon/condb/tileSqlite.db',
234 help='Providing local SQlite file, conditions constants will be used from it')
235 args, _ = parser.parse_known_args()
236
237 fragIDs = [int(fragID, base=16) for fragID in args.fragIDs]
238
239 flags.Input.Files = defaultTestFiles.ESD
240 flags.Output.HISTFileName = 'TileTBMonitorOutput.root'
241 flags.DQ.useTrigger = False
242 flags.DQ.enableLumiAccess = False
243 flags.Exec.MaxEvents = 3
244 flags.Common.isOnline = True
245
246 flags.Tile.doFit = True
247 flags.Tile.useDCS = False
248 flags.Tile.NoiseFilter = 0
249 flags.Tile.correctTime = False
250 flags.Tile.correctTimeJumps = False
251 flags.Tile.BestPhaseFromCOOL = False
252 flags.Tile.doOverflowFit = False
253
254
255 flags.fillFromArgs(parser=parser)
256 flags.lock()
257
258 flags.dump(pattern='Tile.*|Input.*|Exec.*|IOVDb.[D|G].*', evaluate=True)
259
260 # Initialize configuration object, add accumulator, merge, and run.
261 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
262 cfg = MainServicesCfg(flags)
263
264 rawChannels = args.channels
265 cells = args.cells
266 if flags.Input.Format is Format.BS:
267 readDigitsFlx = 'Flx' in args.digits
268 from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
269 cfg.merge( TileRawDataReadingCfg(flags, readMuRcv=False,
270 readDigits=(not readDigitsFlx),
271 readDigitsFlx=readDigitsFlx) )
272
273 else:
274 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
275 cfg.merge(PoolReadCfg(flags))
276
277 if not rawChannels:
278 # Run reconstruction to produce Tile raw channels
279 rawChannels = flags.Tile.RawChannelContainer
280
281 from TileRecUtils.TileRawChannelMakerConfig import TileRawChannelMakerCfg
282 cfg.merge(TileRawChannelMakerCfg(flags))
283 if args.threads and (args.threads > 1):
284 rawChMaker = cfg.getEventAlgo('TileRChMaker')
285 rawChMaker.Cardinality = args.threads
286
287 if args.useSqlite:
288 cfg.getService('IOVDbSvc').overrideTags += [
289 f'<prefix>/TILE</prefix> <db>sqlite://;schema={args.useSqlite};dbname={flags.IOVDb.DatabaseInstance}</db>'
290 ]
291
292 if not cells:
293 # Run reconstruction to produce Tile cells
294 cells = 'AllCalo'
295 from TileRecUtils.TileCellMakerConfig import TileCellMakerCfg
296 cfg.merge(TileCellMakerCfg(flags, maskBadChannels=False, mergeChannels=False, UseDemoCabling=args.demoCabling))
297
298 cfg.merge(TileTBMonitoringConfig(flags, fragIDs=fragIDs, CaloCellContainer=cells))
299
300 from TileConditions.TileInfoLoaderConfig import TileInfoLoaderCfg
301 cfg.merge(TileInfoLoaderCfg(flags))
302 tileInfoLoader = cfg.getService('TileInfoLoader')
303 tileInfoLoader.NSamples = args.nsamples
304 tileInfoLoader.TrigSample = (args.nsamples - 1) // 2 # Floor division
305
306 # Any last things to do?
307 if args.postExec:
308 log.info('Executing postExec: %s', args.postExec)
309 exec(args.postExec)
310
311 cfg.printConfig(withDetails=True, summariseProps=True)
312
313 cfg.store(open('TileTBMonitorAlgorithm.pkl', 'wb'))
314
315 sc = cfg.run()
316
317 import sys
318 # Success should be 0
319 sys.exit(not sc.isSuccess())
TileTBMonitoringConfig(flags, fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], **kwargs)