ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellBuilderTestConfig.py
Go to the documentation of this file.
2# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
3#
4# File: TileRecUtils/share/TileCellBuilder_test.py
5# Author: sss
6# Date: Aug, 2018
7# Brief: Test for TileCellBuilder.
8#
9
10
11import ROOT
12ROOT.TH1F
13
14from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
15from AthenaConfiguration.ComponentFactory import CompFactory
16from TileConfiguration.TileConfigFlags import TileRunType
17
18
19hits_0 = [
20 # (sec, side, mod, tow, samp, pmt, adc), [adc, time, qual, ped]
21 [0, [
22 [(1, 1, 0, 1, 1, 0, 1), [ 0.2, 22.1, 2.4, 42.9]],
23 [(1, 1, 0, 1, 1, 1, 1), [-0.4, 75.0, 2.7, 31.4]],
24 [(1, 1, 0, 1, 0, 0, 1), [-0.9, -13.3, 1.5, 37.4]],
25 [(1, 1, 0, 2, 0, 1, 1), [41.8, 0.1, 2.5, 45.7]],
26 [(1, 1, 0, 2, 0, 0, 1), [30.6, -0.4, 2.0, 33.1]],
27 [(1, 1, 0, 2, 1, 1, 1), [ 1.4, 12.9, 4.7, 43.1]],
28 [(1, 1, 0, 2, 1, 0, 1), [ 3.4, 3.5, 1.9, 54.2]],
29 ]],
30
31 [136, [
32 [(3, 1, 8, 13, 3, 0, 1), [26.9, 4.8, 5.2, 45.4]],
33 ]],
34
35 [146, [
36 [(3, 1, 18, 13, 3, 0, 1), [ 4.4, -26.5, 23.9, 51.2]],
37 [(3, 1, 18, 15, 3, 0, 1), [-0.1, -75.0, 3.7, 51.0]],
38 [(3, 1, 18, 8, 2, 0, 1), [-0.1, 75.0, 4.2, 41.7]],
39 [(3, 1, 18, 8, 2, 1, 1), [ 3.5, -11.9, 2.6, 44.7]],
40 [(3, 1, 18, 9, 1, 0, 1), [ 0.8, -17.6, 1.8, 49.2]],
41 [(3, 1, 18, 9, 1, 1, 1), [ 0.1, -75.0, 3.4, 48.4]],
42 [(2, 1, 18, 11, 0, 0, 1), [ 8.7, 0.4, 2.7, 50.2]],
43 [(2, 1, 18, 11, 0, 1, 1), [ 6.3, 1.9, 1.6, 48.6]],
44 [(2, 1, 18, 10, 1, 0, 1), [53.3, 1.3, 3.8, 38.4]],
45 [(2, 1, 18, 10, 1, 1, 1), [64.1, 1.0, 3.5, 36.9]],
46 [(2, 1, 18, 12, 0, 0, 1), [-0.2, -75.0, 2.8, 38.1]],
47 [(2, 1, 18, 12, 0, 1, 1), [ 0.5, -32.7, 1.9, 40.3]],
48 [(3, 1, 18, 10, 3, 0, 1), [ 5.4, 7.7, 8.2, 57.0]],
49 [(3, 1, 18, 11, 3, 0, 1), [48.9, 0.4, 4.0, 32.3]],
50 [(2, 1, 18, 11, 1, 0, 1), [38.5, 0.5, 1.7, 46.8]],
51 [(2, 1, 18, 11, 1, 1, 1), [48.1, 0.3, 1.6, 46.3]],
52 [(2, 1, 18, 10, 2, 0, 1), [ 0.3, 75.0, 2.0, 34.9]],
53 [(2, 1, 18, 10, 2, 1, 1), [0.1, -75.0, 3.7, 54.7]],
54 ]],
55
56 # Some MBTS cells.
57 [135, [ [(4, 1, 0, 1, 0, 0, 0), [ 59.1, 2.8, 6.9, 56.2]] ]],
58 [181, [ [(4, 1, 6, 1, 0, 0, 0), [ 56.4, 1.2, 2.9, 39.9]] ]],
59 [182, [ [(4, 1, 6, 0, 0, 0, 0), [ 44.9, 0.5, 1.4, 42.1]] ]],
60 [231, [ [(4, -1, 3, 0, 0, 0, 0), [107.9, 1.7, 7.8, 47.8]] ]],
61
62 # Some E4 cells.
63 [220, [ [(4, -1, 0, 2, 0, 0, 0), [ 2.3, 3.2, 2.5, 44.4]] ]],
64 [223, [ [(4, -1, 1, 2, 0, 0, 0), [ 3.1, -5.3, 2.4, 44.4]] ]],
65 [225, [ [(4, -1, 2, 2, 0, 0, 0), [ -0.4, 27.6, 1.3, 32.5]] ]],
66 [228, [ [(4, -1, 3, 2, 0, 0, 0), [ 0.2, -75.0, 2.4, 35.4]] ]],
67
68 # Some disconnected cells.
69 [253, [
70 [4706026383833300992, [ 0, 0, 0, 50000]],
71 [4706027483344928768, [ 0, 0, 0, 50000]] ], ],
72 [255, [
73 [4706157225717006336, [ 0, 0, 0, 80000]],
74 [4706158325228634112, [ 0, 0, 0, 80000]] ], ],
75]
76
77
78# Add an offset to one pedestal value.
79def add_pedestal (offs_addr, offs):
80 out = []
81 for icoll, colldata in hits_0:
82 colldata_out = []
83 for addr, data in colldata:
84 if addr == offs_addr:
85 data = data[:]
86 data[3] += offs
87 colldata_out.append ([addr, data])
88 out.append ([icoll, colldata_out])
89 return out
90
91
92exp_cells_0 = {
93 (1, 1, 0, 1, 0) : [-10.4734, -10.4734, -13.3, -13.3, 1, 1, 130, 138, 1, 1],
94 (1, 1, 0, 1, 1) : [ 2.3274, -4.6548, 22.1, 75.0, 2, 2, 130, 130, 1, 1],
95 (1, 1, 0, 2, 0) : [356.0956, 486.4312, -0.4, 0.1, 2, 2, 162, 162, 1, 1],
96 (1, 1, 0, 2, 1) : [ 39.5662, 16.2920, 3.5, 12.9, 1, 4, 162, 130, 1, 1],
97
98 (2, 1, 18, 10, 1):[620.25793, 745.93872, 1.3, 1.0, 3, 3, 162, 162, 1, 1],
99 (2, 1, 18, 10, 2):[ 3.49113, 1.16371, 75.0, -75.0, 2, 3, 130, 130, 1, 1],
100 (2, 1, 18, 11, 0):[101.24284, 73.31380, 0.4, 1.9, 2, 1, 162, 162, 1, 1],
101 (2, 1, 18, 11, 1):[448.02869, 559.74500, 0.5, 0.3, 1, 1, 162, 162, 1, 1],
102 (2, 1, 18, 12, 0):[ -2.32742, 5.81855,-75.0, -32.7, 2, 1, 130, 130, 1, 1],
103 (3, 1, 18, 8, 2):[ -0.96976, 33.94157, 75.0, -11.9, 4, 2, 130, 130, 1, 1],
104 (3, 1, 18, 9, 1):[ 7.75807, 0.96976,-17.6, -75.0, 1, 3, 130, 130, 1, 1],
105 (3, 1, 18, 10, 3):[ 41.89359, 0.0, 7.7, 7.7, 8, 0, 162, 0, 1,-1],
106 (3, 1, 18, 11, 3):[379.36975, 0.0, 0.4, 0.4, 4, 0, 162, 0, 1,-1],
107 (3, 1, 18, 13, 3):[ 34.13552, 0.0, -26.5, -26.5,23, 0, 130, 0, 1,-1],
108 (3, 1, 18, 15, 3):[ -0.77581, 0.0, -75.0, -75.0, 3, 0, 130, 0, 1, -1],
109
110 # coll 136
111 (3, 1, 8, 13, 3) : [208.6922, 0.0, 4.8, 4.8, 5, 0, 162, 0, 1, -1],
112}
113
114
115exp_mbts_0 = {
116 (4, 1, 0, 1, 0) : [0.7221, 0.0, 2.8, 2.8, 6, 0, 162, 0, 1, -1],
117 (4, 1, 6, 1, 0) : [0.6891, 0.0, 1.2, 1.2, 2, 0, 162, 0, 1, -1],
118 (4, 1, 6, 0, 0) : [0.5486, 0.0, 0.5, 0.5, 1, 0, 162, 0, 1, -1],
119 (4, -1, 3, 0, 0) : [1.318, 0.0, 1.7, 1.7, 7, 0, 162, 0, 1, -1],
120}
121
122
123exp_e4_0 = {
124 (4, -1, 0, 2, 0) : [17.84357, 0.0, 3.2, 3.2, 2, 0, 130, 0, 1, -1],
125 (4, -1, 1, 2, 0) : [24.05003, 0.0, -5.3, -5.3, 2, 0, 130, 0, 1, -1],
126 (4, -1, 2, 2, 0) : [-3.10323, 0.0, 27.6, 27.6, 1, 0, 130, 0, 1, -1],
127 (4, -1, 3, 2, 0) : [1.551615, 0.0, -75.0, -75.0, 2, 0, 130, 0, 1, -1],
128}
129
130
131def exp_merge (base, d):
132 new = base.copy()
133 new.update (d)
134 return new
135
136
137# Underflow.
138hits_1 = add_pedestal ((3, 1, 18, 15, 3, 0, 1), 10000)
139exp_cells_1 = exp_merge (exp_cells_0, {
140 (3, 1, 18, 15, 3) : [-0.7758, 0.0, -75.0, -75.0, 3, 0, 146, 0, 1, -1],
141})
142
143# Overflow.
144hits_2 = add_pedestal ((3, 1, 18, 15, 3, 0, 1), 20000)
145exp_cells_2 = exp_merge (exp_cells_0, {
146 (3, 1, 18, 15, 3) : [-0.7758, 0.0, -75.0, -75.0, 3, 0, 146, 0, 1, -1],
147})
148
149# TileBadChan errors.
150exp_cells_3 = exp_merge (exp_cells_0, {
151 (3, 1, 18, 8, 2) : [ 33.9416, 33.9416, -11.9, -11.9, 2, 2, 138, 130, 1, 1],
152 (2, 1, 18, 11, 0) : [101.2428, 73.3138, 1.9, 1.9, 2, 1, 34, 162, 1, 1],
153 (2, 1, 18, 12, 0) : [ -2.3274, -2.3274, -75.0, -75.0, 2, 2, 130, 138, 1, 1],
154})
155exp_mbts_3 = exp_merge (exp_mbts_0, {
156 (4, 1, 0, 1, 0) : [ 0.0, 0.0, -100.0,-100.0,255,0, 10, 8, 1,-1],
157 (4, 1, 6, 1, 0) : [ 0.6891, 0.0, 0.0, 0.0, 2, 0, 34, 0, 1,-1],
158})
159
160# TileDQstatus errors
161exp_cells_4 = exp_merge (exp_cells_0, {
162 (2, 1, 18, 10, 1):[620.2579,620.2579, 1.3, 1.3, 3, 3, 161, 169, 1, 1],
163 (2, 1, 18, 12, 0):[ 0.5, 0.5, 0.0, 0.0, 255, 255, 9, 9, 1, 1],
164 (3, 1, 18, 8, 2):[ 33.9416, 33.9416,-11.9,-11.9, 2, 2, 137, 129, 1, 1],
165 (3, 1, 18, 13, 3):[ 0.5, 0.0, 0.0, 0.0, 255, 0, 9, 8, 1,-1],
166 (3, 1, 18, 15, 3):[ 0.5, 0.0, 0.0, 0.0, 255, 0, 9, 8, 1,-1],
167})
168
169
170# fakeCrackCells
171exp_cells_5 = exp_merge (exp_cells_0, {
172 (3, 1, 8, 8, 2) : [0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0],
173 (3, 1, 8, 9, 1) : [0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0],
174 (3, 1, 8, 10, 3) : [0.0, 0.0, 0.0, 0.0, 0, 0, 8, 8, 0, -1],
175 (3, 1, 8, 11, 3) : [0.0, 0.0, 0.0, 0.0, 0, 0, 8, 8, 0, -1],
176 (3, 1, 8, 15, 3) : [0.0, 0.0, 0.0, 0.0, 0, 0, 8, 8, 0, -1],
177})
178
179
180def filter_e (base, thresh):
181 out = {}
182 for addr, l in base.items():
183 if l[0] >= thresh or l[1] >= thresh:
184 out[addr] = l
185 return out
186
187# EThreshold
188exp_cells_6 = filter_e (exp_cells_0, 300)
189
190
191
192# corrections
193exp_cells_7 = exp_merge (exp_cells_0, {
194 (1, 1, 0, 2, 0) : [356.1491, 486.4361, -0.4, 0.1, 2, 2, 162, 162, 1, 1],
195 (2, 1, 18, 10, 1) : [621.3283, 746.7004, 1.3, 1.0, 3, 3, 162, 162, 1, 1],
196 (2, 1, 18, 11, 1) : [448.1431, 559.7963, 0.5, 0.3, 1, 1, 162, 162, 1, 1],
197 (3, 1, 8, 13, 3) : [213.6019, 0.0, 4.8, 4.8, 5, 0, 162, 0, 1,-1],
198 (3, 1, 18, 11, 3) : [379.4317, 0.0, 0.4, 0.4, 4, 0, 162, 0, 1,-1],
199})
200exp_mbts_7 = exp_merge (exp_mbts_0, {
201 (4, 1, 0, 1, 0) : [0.7279, 0.0, 2.8, 2.8, 6, 0, 162, 0, 1, -1],
202 (4, 1, 6, 1, 0) : [0.6902, 0.0, 1.2, 1.2, 2, 0, 162, 0, 1, -1],
203 (4, -1, 3, 0, 0) : [1.3223, 0.0, 1.7, 1.7, 7, 0, 162, 0, 1, -1],
204})
205
206
207# noisefilter
208exp_cells_8 = exp_merge (exp_cells_0, {
209 (1, 1, 0, 1, 0) : [-11.3462, -11.3462, -13.3, -13.3, 1, 1, 130, 138, 1, 1],
210 (1, 1, 0, 1, 1) : [ 1.4546, -5.5276, 22.1, 75.0, 2, 2, 130, 130, 1, 1],
211 (1, 1, 0, 2, 0) : [355.2228, 485.5583, -0.4, 0.1, 2, 2, 162, 162, 1, 1],
212 (1, 1, 0, 2, 1) : [ 39.5662, 15.4192, 3.5, 12.9, 1, 4, 162, 130, 1, 1],
213})
214
215
216# DSP w/corrrections
217exp_cells_10 = exp_merge (exp_cells_7, {
218 (1, 1, 0, 2, 0) : [356.1227, 486.4159, -0.4, 0.1, 2, 2, 162, 162, 1, 1],
219})
220
221
222
223# TileFragHash::TYPE
225 Beam = 255
226 Default = 0
227 Digitizer = 0
228 OptFilterDsp = 1
229 OptFilterOffline = 2
230 OptFilterDspCompressed = 3
231 ManyAmps = 4
232 MF = 5
233 FitFilter = 6
234 FitFilterCool = 7
235 FlatFilter = 8
236 WienerFilterOffline = 9
237
238
239from AthenaPython.PyAthenaComps import Alg, StatusCode
240
241
242
243
244class PrepareDataAlg (Alg):
245 def __init__ (self, name):
246 Alg.__init__ (self, name)
247 return
248
249 def initialize (self):
250 return StatusCode.Success
251
252 def execute (self):
253 iev = self.getContext().evt()
254
255 hits = hits_0
256 self.exp_cells = exp_cells_0
257 self.exp_mbts = exp_mbts_0
259 self.tool = 'tool1'
260 baddq = {}
261 bsflags = 0x32002000
262 dspbsflags = 0x32002000
263 self.rctype = TileFragHash.OptFilterOffline
264 dspcolls = set()
265 dqhits = {}
266
267 if iev == 0:
268 # Event 0: nominal
269 pass
270
271 elif iev == 1:
272 # Event 1: Add an underflow.
273 hits = hits_1
274 self.extra_ei_flags = 0x40
275 self.exp_cells = exp_cells_1
276
277 elif iev == 2:
278 # Event 2: Add an overflow.
279 hits = hits_2
280 self.extra_ei_flags = 0x400
281 self.exp_cells = exp_cells_2
282
283 elif iev == 3:
284 # Event 3: Bad channels
285 self.tool = 'tool2'
286 self.exp_cells = exp_cells_3
287 self.exp_mbts = exp_mbts_3
288
289 elif iev == 4:
290 # Event 4: Bad channels from TileDQstatus
291 self.rctype = TileFragHash.OptFilterDsp
292 baddq = {146 : [2, 10]}
293 self.exp_cells = exp_cells_4
294 dqhits = hits
295
296 elif iev == 5:
297 # Event 5: fakeCrackCells
298 self.tool = 'tool5'
299 self.exp_cells = exp_cells_5
300
301 elif iev == 6:
302 # Event 6: Threshold.
303 self.tool = 'tool6'
304 self.exp_cells = exp_cells_6
305
306 elif iev == 7:
307 # Event 7: Corrections
308 self.tool = 'tool7'
309 bsflags = 0x32000000
310 self.exp_cells = exp_cells_7
311 self.exp_mbts = exp_mbts_7
312
313 elif iev == 8:
314 # Event 8: noise filter
315 self.tool = 'tool8'
316 self.exp_cells = exp_cells_8
317
318 elif iev == 9:
319 # Event 9: dsp container
320 self.tool = 'tool9'
321 dspcolls.add (0)
322
323 elif iev == 10:
324 # Event 10: dsp container + corrections
325 self.tool = 'tool10'
326 dspcolls.add (0)
327 bsflags = 0x32000000
328 dspbsflags = 0x20000000
329 self.exp_cells = exp_cells_10
330 self.exp_mbts = exp_mbts_7
331
332 else:
333 # Event 11: dsp container + noise filter
334 self.tool = 'tool11'
335 dspcolls.add (0)
336 self.exp_cells = exp_cells_8
337
338
339 self.record_raw_data (hits, self.rctype, baddq, bsflags, dspbsflags, dspcolls)
340
341 self.record_raw_data (dqhits, self.rctype, baddq, bsflags,
342 rawname = 'TRCDQ')
343
344 return StatusCode.Success
345
346
347 def record_raw_data (self, hits, typ, baddq, bsflags,
348 dspbsflags=0, dspcolls=set(),
349 rawname = 'TileRawChannelCnt'):
350 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
351
352 unit = 0 # TileRawChannelUnit::ADCcounts
353 cont = ROOT.TileRawChannelContainer (False, typ, unit)
354 cont.set_bsflags (bsflags)
355 hashFunc = cont.hashFunc()
356
357 dspcont = None
358 if dspcolls:
359 dspcont = ROOT.TileRawChannelContainer (False, typ, unit)
360 dspcont.set_bsflags (dspbsflags)
361
362 for icoll, colldata in hits:
363 coll = ROOT.TileRawChannelCollection (hashFunc.identifier(icoll))
364
365 mask = 0
366 for chan in baddq.get (icoll, []):
367 mask |= (1<<(chan//3))
368 coll.setFragMemoryPar(mask)
369
370 for addr, data in colldata:
371 if isinstance(addr, tuple):
372 adc_id = idHelper.adc_id (*addr)
373 chan = ROOT.TileRawChannel (adc_id, *data)
374 else:
375 hwid = ROOT.HWIdentifier (addr)
376 chan = ROOT.TileRawChannel (hwid, *data)
377 coll.push_back (chan)
378 ROOT.SetOwnership (chan, False)
379
380 if icoll in dspcolls:
381 thiscont = dspcont
382 else:
383 thiscont = cont
384 thiscont.addCollection (coll, ROOT.IdentifierHash(icoll))
385 ROOT.SetOwnership (coll, False)
386
387 self.evtStore.record (cont, rawname, False)
388 if dspcont:
389 self.evtStore.record (dspcont, 'TileRawChannelCntDsp', False)
390 return
391
392
393
394
395
396class TestAlg (Alg):
397 def __init__ (self, name, prepAlg):
398 Alg.__init__ (self, name)
399 self.prepAlg = prepAlg
400 return
401
402 def initialize (self):
403 ROOT.ICaloCellMakerTool
404
405 def gettool (name):
406 tool = ROOT.ToolHandle(ROOT.ICaloCellMakerTool)('TileCellBuilder/' + name)
407 if not tool.retrieve():
408 assert 0
409 return tool
410
411 self.tool1 = gettool ('tool1')
412 self.tool2 = gettool ('tool2')
413 self.tool5 = gettool ('tool5')
414 self.tool6 = gettool ('tool6')
415 self.tool7 = gettool ('tool7')
416 self.tool8 = gettool ('tool8')
417 self.tool9 = gettool ('tool9')
418 self.tool10 = gettool ('tool10')
419 self.tool11 = gettool ('tool11')
420
421 return StatusCode.Success
422
423
424 def finalize (self):
426 return StatusCode.Success
427
428
429 def execute (self):
430 tool = getattr (self, self.prepAlg.tool)
431
432 ccc = ROOT.CaloCellContainer(ROOT.SG.VIEW_ELEMENTS)
433 if not tool.process (ccc, self.getContext()):
434 return StatusCode.Failure
435
436 rctype = self.prepAlg.rctype
437 self.compare_cells (ccc, self.prepAlg.exp_cells, rctype)
438 self.compare_cells (self.evtStore['MBTSContainer'], self.prepAlg.exp_mbts, rctype)
439 self.compare_cells (self.evtStore['E4prContainer'], exp_e4_0, rctype)
440
441 self.check_ei (self.prepAlg.extra_ei_flags)
442 return StatusCode.Success
443
444
445 @staticmethod
446 def update_qbit (qb, rctype):
447 if qb == 0: return 0
448 return qb&(~7) | rctype
449
450
451 def compare_cells (self, ccc, exp_cells, rctype):
452 exp_cells = exp_cells.copy()
453 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
454
455 for c in ccc:
456 lcell = [c.ene1(), c.ene2(), c.time1(), c.time2(),
457 c.qual1(), c.qual2(),
458 c.qbit1(), c.qbit2(),
459 c.gain1(), c.gain2()]
460
461 cid = c.ID()
462 addr = (idHelper.section(cid),
463 idHelper.side(cid),
464 idHelper.module(cid),
465 idHelper.tower(cid),
466 idHelper.sampling(cid))
467 l = exp_cells.get (addr)
468 if not l:
469 print ('xxx unexpected cell', addr, lcell)
470 assert 0
471 continue
472
473 l = l[:]
474
475 # Low 3 bits of qbit correspond to rctype, unless cell was masked.
476 if l[0] != 0: l[6] = TestAlg.update_qbit (l[6], rctype)
477 if l[1] != 0: l[7] = TestAlg.update_qbit (l[7], rctype)
478
479 if (abs (lcell[0] - l[0]) > 1e-3 or
480 abs (lcell[1] - l[1]) > 1e-3 or
481 abs (lcell[2] - l[2]) > 1e-3 or
482 abs (lcell[3] - l[3]) > 1e-3 or
483 abs (lcell[4] != l[4]) or
484 abs (lcell[5] != l[5]) or
485 abs (lcell[6] != l[6]) or
486 abs (lcell[7] != l[7]) or
487 abs (lcell[8] != l[8]) or
488 abs (lcell[9] != l[9])):
489 print ('xxx cell mismatch: ', addr, lcell, l)
490 assert 0
491 del exp_cells[addr]
492
493 for extra in exp_cells:
494 print ('xxx unfound cell', extra)
495 assert 0
496 return
497
498
499 def check_ei (self, extra_flags):
500 ei = self.evtStore['EventInfo']
501 assert ei.eventFlags (ROOT.xAOD.EventInfo.Tile) == (0xf0f0005 | extra_flags)
502 assert ei.errorState (ROOT.xAOD.EventInfo.Tile) == ROOT.xAOD.EventInfo.Error
503 return
504
505
506 def make_bad_chan_lines (self, chans):
507 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
508 hwidHelper = self.detStore['TileHWID']
509 cabling = ROOT.TileCablingService.getInstance()
510
511 lines = []
512 for addr, data in chans:
513 pmt_id = idHelper.pmt_id (*addr)
514 channel_id = cabling.s2h_channel_id (pmt_id)
515 frag = hwidHelper.frag (channel_id)
516 channel = hwidHelper.channel (channel_id)
517 line = '0x%03x %d 0 %d %d %d' % (frag, channel, data[0], data[1], data[2])
518 lines.append (line)
519
520 return '\n'.join (lines)
521
522
524 for name, (chans, lines) in baddefs.items():
525 xlines = self.make_bad_chan_lines (chans)
526 if xlines.strip() != lines.strip():
527 print ('xxx Bad chan lines need updating: ', name)
528 print (xlines)
529 return
530
531
532
533
534
535baddefs = {}
536BAD_LOW = [1<<1, 0, 0] # AdcDead
537BAD_HIGH = [ 0, 1<<1, 0] # AdcDead
538BAD_BOTH = [ 0, 0, 1<<1] # NoHV
539BADTIMING = [ 0, 0, 1<<9] # BadTiming
540
541def TileBadChannelsCfg(flags, badChannels, chans=[], lines=''):
542
543 """
544
545 chans: [(sec, side, mod, tow, samp, pmt), [DATA0, DATA1, DATA2]]
546 We'd like to specify cells using offline addressing, but the bad cell
547 file uses online addressing. We can convert, but that requires
548 idhelpers, etc, that aren't available until after initialization.
549 So we pass in both representations; in finalize(), we'll check
550 that they match and print out the correct bad cell lines
551 if they do not.
552
553 File data line format:
554 frag channel dummy adcStatus0 adcStatus1 chnStatus
555 chnStatus + adcStatusN are given to TileBchDecoder.
556 Offline problem masks:
557 chn adc
558 0 GeneralMaskChannel GeneralMaskAdc
559 1 NoPmt AdcDead
560 2 NoHV StuckBit
561 3 WrongHV DataCorruption
562 4 NoLaser VeryLargeHfNoise
563 5 BadLaser NoData
564 6 NoCesium WrongDspConfig
565 7 BadCesium LargeHfNoise
566 8 NoTiming CorrelatedNoise
567 9 BadTiming LargeLfNoise
568 10 TrigGeneralMask NoCis
569 11 TrigNoGain BadCis
570 12 TrigHalfGain SevereStuckBit
571 13 TrigNoisy SevereDataCorruption
572 14 Emergency IgnoredByDQV
573 15 HVReadoutPb
574 16 BrokenClearFibre
575 17 IgnoreCs
576 18 UnstableCs
577
578
579 Online problem masks:
580 chn adc
581 0 IgnoredInDsp OnlineGeneralMaskAdc
582 1 IgnoredInHlt
583 2 DisableForL1
584 3 TrigGeneralMask
585 4 TrigNoGain
586 5 TrigHalfGain
587 6 TrigNoisy
588 7 OnlineBadTiming
589 """
590
591 if not chans:
592 TileBchList = 'TileNoBad.oflBch'
593 else:
594 TileBchList = badChannels + '.bch'
595 f = open (TileBchList, 'w')
596 print ('OBJVERSION 0', file=f)
597 print ('0x000 0 0 0 0 0', file=f)
598 f.write (lines)
599 f.close()
600 baddefs[badChannels] = (chans, lines)
601
602
603 TileCondProxyFileBch = CompFactory.getComp("TileCondProxyFile<TileCalibDrawerBch>")
604 onlineBadChannelsProxy = TileCondProxyFileBch('TileCondProxyFile_OnlBch', Source=TileBchList)
605 offlineBadChannelsProxy = TileCondProxyFileBch('TileCondProxyFile_OflBch', Source='TileNoBad.oflBch')
606
607 TileBadChannelsCondAlg = CompFactory.TileBadChannelsCondAlg
608 badChannelsCondAlg = TileBadChannelsCondAlg(name=f'{badChannels}_CondAlg',
609 OnlBchProxy=onlineBadChannelsProxy,
610 OflBchProxy=offlineBadChannelsProxy,
611 TileBadChannels=badChannels)
612
613 acc = ComponentAccumulator()
614 acc.addCondAlgo(badChannelsCondAlg)
615
616 return acc
617
618
619badChannelsLines = """
6200x312 2 0 0 2 0
6210x312 4 0 2 0 0
6220x312 11 0 0 0 2
6230x312 6 0 0 0 512
6240x307 12 0 0 0 2
6250x335 12 0 0 0 512
626"""
627
628def maketool (name, badChannels, **kw):
629 TileCellBuilder = CompFactory.TileCellBuilder
630 return TileCellBuilder(name, TileBadChannels=badChannels, **kw)
631
632
634
635 acc = ComponentAccumulator()
636
637 from TileGeoModel.TileGMConfig import TileGMCfg
638 acc.merge( TileGMCfg(flags) )
639
640 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
641 acc.merge(LArGMCfg(flags))
642
643 from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg
644 acc.merge( TileCablingSvcCfg(flags) )
645
646 from TileConditions.TileInfoLoaderConfig import TileInfoLoaderCfg
647 acc.merge( TileInfoLoaderCfg(flags) )
648
649 from TileConditions.TileEMScaleConfig import TileEMScaleCondAlgCfg
650 acc.merge( TileEMScaleCondAlgCfg(flags) )
651
652 from TileConditions.TileTimingConfig import TileTimingCondAlgCfg
653 acc.merge( TileTimingCondAlgCfg(flags) )
654
655 from TileConditions.TileSampleNoiseConfig import TileSampleNoiseCondAlgCfg
656 acc.merge( TileSampleNoiseCondAlgCfg(flags) )
657
658 bc1 = 'tilecellbuilder_bc1'
659 acc.merge( TileBadChannelsCfg(flags, bc1) )
660
661 bc2 = 'tilecellbuilder_bc2'
662 acc.merge( TileBadChannelsCfg(flags, bc2,
663 [[(3, 1, 18, 8, 2, 0), BAD_HIGH],
664 [(2, 1, 18, 9, 1, 0), BAD_LOW],
665 [(2, 1, 18, 12, 0, 1), BAD_BOTH],
666 [(2, 1, 18, 11, 0, 0), BADTIMING],
667 [(4, 1, 0, 1, 0, 0), BAD_BOTH],
668 [(4, 1, 6, 1, 0, 0), BADTIMING],
669 ], badChannelsLines) )
670
671
672 TileRawChannelNoiseFilter = CompFactory.TileRawChannelNoiseFilter
673 noisefilter = TileRawChannelNoiseFilter('noisefilter')
674
675 acc.addPublicTool( maketool ('tool1', bc1) )
676 acc.addPublicTool( maketool ('tool2', bc2) )
677 acc.addPublicTool( maketool ('tool5', bc1, fakeCrackCells=True) )
678 acc.addPublicTool( maketool ('tool6', bc1, EThreshold=300) )
679 acc.addPublicTool( maketool ('tool7', bc1, correctAmplitude=True, correctTime=True) )
680 acc.addPublicTool( maketool ('tool8', bc1, NoiseFilterTools=[noisefilter]) )
681 acc.addPublicTool( maketool ('tool9', bc1, TileDSPRawChannelContainer='TileRawChannelCntDsp') )
682 acc.addPublicTool( maketool ('tool10', bc1, TileDSPRawChannelContainer = 'TileRawChannelCntDsp',
683 correctTime=True, correctAmplitude=True) )
684 acc.addPublicTool( maketool ('tool11', bc1, TileDSPRawChannelContainer='TileRawChannelCntDsp',
685 NoiseFilterTools=[noisefilter]) )
686
687 acc.addEventAlgo( PrepareDataAlg('prepalg1') )
688 prepalg1 = acc.getEventAlgo('prepalg1')
689
690 from TileRecUtils.TileDQstatusConfig import TileDQstatusAlgCfg
691 acc.merge(TileDQstatusAlgCfg(flags, name='dqstat1',
692 TileRawChannelContainer='TRCDQ',
693 TileDigitsContainer=''))
694
695
696 acc.addEventAlgo( TestAlg('testalg1', prepalg1) )
697
698 return acc
699
700
701
702if __name__ == "__main__":
703
704 from AthenaConfiguration.AllConfigFlags import initConfigFlags
705 from AthenaConfiguration.TestDefaults import defaultConditionsTags, defaultTestFiles
706 from AthenaCommon.Logging import log
707 from AthenaCommon.Constants import INFO
708
709 # Test setup
710 log.setLevel(INFO)
711
712 flags = initConfigFlags()
713 flags.Input.Files = defaultTestFiles.HITS_RUN2
714 flags.Input.ConditionsRunNumber = 1
715 flags.Input.OverrideRunNumber = True
716 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN2_MC
717 flags.Tile.RunType = TileRunType.PHY
718 flags.Exec.MaxEvents = 12
719 flags.fillFromArgs()
720
721 flags.lock()
722
723 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
724 cfg = MainServicesCfg(flags)
725
726 # Configure reading POOL files
727 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
728 cfg.merge(PoolReadCfg(flags))
729
730 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
731 cfg.merge (EventInfoCnvAlgCfg (flags, disableBeamSpot = True))
732
733 cfg.merge( TileRawChannelBuilderTestCfg(flags) )
734
735 flags.dump()
736 cfg.printConfig(withDetails=True)
737 cfg.store( open('TileCellBuilderTest.pkl', 'wb') )
738
739 sc = cfg.run()
740
741 import sys
742 # Success should be 0
743 sys.exit(not sc.isSuccess())
Condition algorithm to prepare TileBadChannels and put it into condition store.
record_raw_data(self, hits, typ, baddq, bsflags, dspbsflags=0, dspcolls=set(), rawname='TileRawChannelCnt')
compare_cells(self, ccc, exp_cells, rctype)
This class creates Cells from RawChannels and stores them in a container.
This tool subtracts common-mode noise from all TileRawChannels in one container.
STL class.
maketool(name, badChannels, **kw)
TileBadChannelsCfg(flags, badChannels, chans=[], lines='')
void initialize()