ATLAS Offline Software
TileCellBuilderTestConfig.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2024 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 
11 import ROOT
12 ROOT.TH1F
13 
14 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
15 from AthenaConfiguration.ComponentFactory import CompFactory
16 from TileConfiguration.TileConfigFlags import TileRunType
17 
18 
19 hits_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.
79 def 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 
92 exp_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 
115 exp_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 
123 exp_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 
131 def exp_merge (base, d):
132  new = base.copy()
133  new.update (d)
134  return new
135 
136 
137 # Underflow.
138 hits_1 = add_pedestal ((3, 1, 18, 15, 3, 0, 1), 10000)
139 exp_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.
144 hits_2 = add_pedestal ((3, 1, 18, 15, 3, 0, 1), 20000)
145 exp_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.
150 exp_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 })
155 exp_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
161 exp_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
171 exp_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 
180 def 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
188 exp_cells_6 = filter_e (exp_cells_0, 300)
189 
190 
191 
192 # corrections
193 exp_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 })
200 exp_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
208 exp_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
217 exp_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 
239 from AthenaPython.PyAthenaComps import Alg, StatusCode
240 
241 
242 
243 
244 class 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
258  self.extra_ei_flags = 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 
379  if icoll in dspcolls:
380  thiscont = dspcont
381  else:
382  thiscont = cont
383  thiscont.addCollection (coll, ROOT.IdentifierHash(icoll))
384  ROOT.SetOwnership (coll, False)
385 
386  self.evtStore.record (cont, rawname, False)
387  if dspcont:
388  self.evtStore.record (dspcont, 'TileRawChannelCntDsp', False)
389  return
390 
391 
392 
393 
394 
395 class TestAlg (Alg):
396  def __init__ (self, name, prepAlg):
397  Alg.__init__ (self, name)
398  self.prepAlg = prepAlg
399  return
400 
401  def initialize (self):
402  ROOT.ICaloCellMakerTool
403 
404  def gettool (name):
405  tool = ROOT.ToolHandle(ROOT.ICaloCellMakerTool)('TileCellBuilder/' + name)
406  if not tool.retrieve():
407  assert 0
408  return tool
409 
410  self.tool1 = gettool ('tool1')
411  self.tool2 = gettool ('tool2')
412  self.tool5 = gettool ('tool5')
413  self.tool6 = gettool ('tool6')
414  self.tool7 = gettool ('tool7')
415  self.tool8 = gettool ('tool8')
416  self.tool9 = gettool ('tool9')
417  self.tool10 = gettool ('tool10')
418  self.tool11 = gettool ('tool11')
419 
420  return StatusCode.Success
421 
422 
423  def finalize (self):
424  self.check_bad_chan_lines()
425  return StatusCode.Success
426 
427 
428  def execute (self):
429  tool = getattr (self, self.prepAlg.tool)
430 
431  ccc = ROOT.CaloCellContainer()
432  if not tool.process (ccc, self.getContext()):
433  return StatusCode.Failure
434 
435  rctype = self.prepAlg.rctype
436  self.compare_cells (ccc, self.prepAlg.exp_cells, rctype)
437  self.compare_cells (self.evtStore['MBTSContainer'], self.prepAlg.exp_mbts, rctype)
438  self.compare_cells (self.evtStore['E4prContainer'], exp_e4_0, rctype)
439 
440  self.check_ei (self.prepAlg.extra_ei_flags)
441  return StatusCode.Success
442 
443 
444  @staticmethod
445  def update_qbit (qb, rctype):
446  if qb == 0: return 0
447  return qb&(~7) | rctype
448 
449 
450  def compare_cells (self, ccc, exp_cells, rctype):
451  exp_cells = exp_cells.copy()
452  idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
453 
454  for c in ccc:
455  lcell = [c.ene1(), c.ene2(), c.time1(), c.time2(),
456  c.qual1(), c.qual2(),
457  c.qbit1(), c.qbit2(),
458  c.gain1(), c.gain2()]
459 
460  cid = c.ID()
461  addr = (idHelper.section(cid),
462  idHelper.side(cid),
463  idHelper.module(cid),
464  idHelper.tower(cid),
465  idHelper.sampling(cid))
466  l = exp_cells.get (addr)
467  if not l:
468  print ('xxx unexpected cell', addr, lcell)
469  assert 0
470  continue
471 
472  l = l[:]
473 
474  # Low 3 bits of qbit correspond to rctype, unless cell was masked.
475  if l[0] != 0: l[6] = TestAlg.update_qbit (l[6], rctype)
476  if l[1] != 0: l[7] = TestAlg.update_qbit (l[7], rctype)
477 
478  if (abs (lcell[0] - l[0]) > 1e-3 or
479  abs (lcell[1] - l[1]) > 1e-3 or
480  abs (lcell[2] - l[2]) > 1e-3 or
481  abs (lcell[3] - l[3]) > 1e-3 or
482  abs (lcell[4] != l[4]) or
483  abs (lcell[5] != l[5]) or
484  abs (lcell[6] != l[6]) or
485  abs (lcell[7] != l[7]) or
486  abs (lcell[8] != l[8]) or
487  abs (lcell[9] != l[9])):
488  print ('xxx cell mismatch: ', addr, lcell, l)
489  assert 0
490  del exp_cells[addr]
491 
492  for extra in exp_cells:
493  print ('xxx unfound cell', extra)
494  assert 0
495  return
496 
497 
498  def check_ei (self, extra_flags):
499  ei = self.evtStore['EventInfo']
500  assert ei.eventFlags (ROOT.xAOD.EventInfo.Tile) == (0xf0f0005 | extra_flags)
501  assert ei.errorState (ROOT.xAOD.EventInfo.Tile) == ROOT.xAOD.EventInfo.Error
502  return
503 
504 
505  def make_bad_chan_lines (self, chans):
506  idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
507  hwidHelper = self.detStore['TileHWID']
508  cabling = ROOT.TileCablingService.getInstance()
509 
510  lines = []
511  for addr, data in chans:
512  pmt_id = idHelper.pmt_id (*addr)
513  channel_id = cabling.s2h_channel_id (pmt_id)
514  frag = hwidHelper.frag (channel_id)
515  channel = hwidHelper.channel (channel_id)
516  line = '0x%03x %d 0 %d %d %d' % (frag, channel, data[0], data[1], data[2])
517  lines.append (line)
518 
519  return '\n'.join (lines)
520 
521 
523  for name, (chans, lines) in baddefs.items():
524  xlines = self.make_bad_chan_lines (chans)
525  if xlines.strip() != lines.strip():
526  print ('xxx Bad chan lines need updating: ', name)
527  print (xlines)
528  return
529 
530 
531 
532 
533 
534 baddefs = {}
535 BAD_LOW = [1<<1, 0, 0] # AdcDead
536 BAD_HIGH = [ 0, 1<<1, 0] # AdcDead
537 BAD_BOTH = [ 0, 0, 1<<1] # NoHV
538 BADTIMING = [ 0, 0, 1<<9] # BadTiming
539 
540 def TileBadChannelsCfg(flags, badChannels, chans=[], lines=''):
541 
542  """
543 
544  chans: [(sec, side, mod, tow, samp, pmt), [DATA0, DATA1, DATA2]]
545  We'd like to specify cells using offline addressing, but the bad cell
546  file uses online addressing. We can convert, but that requires
547  idhelpers, etc, that aren't available until after initialization.
548  So we pass in both representations; in finalize(), we'll check
549  that they match and print out the correct bad cell lines
550  if they do not.
551 
552  File data line format:
553  frag channel dummy adcStatus0 adcStatus1 chnStatus
554  chnStatus + adcStatusN are given to TileBchDecoder.
555  Offline problem masks:
556  chn adc
557  0 GeneralMaskChannel GeneralMaskAdc
558  1 NoPmt AdcDead
559  2 NoHV StuckBit
560  3 WrongHV DataCorruption
561  4 NoLaser VeryLargeHfNoise
562  5 BadLaser NoData
563  6 NoCesium WrongDspConfig
564  7 BadCesium LargeHfNoise
565  8 NoTiming CorrelatedNoise
566  9 BadTiming LargeLfNoise
567  10 TrigGeneralMask NoCis
568  11 TrigNoGain BadCis
569  12 TrigHalfGain SevereStuckBit
570  13 TrigNoisy SevereDataCorruption
571  14 Emergency IgnoredByDQV
572  15 HVReadoutPb
573  16 BrokenClearFibre
574  17 IgnoreCs
575  18 UnstableCs
576 
577 
578  Online problem masks:
579  chn adc
580  0 IgnoredInDsp OnlineGeneralMaskAdc
581  1 IgnoredInHlt
582  2 DisableForL1
583  3 TrigGeneralMask
584  4 TrigNoGain
585  5 TrigHalfGain
586  6 TrigNoisy
587  7 OnlineBadTiming
588  """
589 
590  if not chans:
591  TileBchList = 'TileNoBad.oflBch'
592  else:
593  TileBchList = badChannels + '.bch'
594  f = open (TileBchList, 'w')
595  print ('OBJVERSION 0', file=f)
596  print ('0x000 0 0 0 0 0', file=f)
597  f.write (lines)
598  f.close()
599  baddefs[badChannels] = (chans, lines)
600 
601 
602  TileCondProxyFileBch = CompFactory.getComp("TileCondProxyFile<TileCalibDrawerBch>")
603  onlineBadChannelsProxy = TileCondProxyFileBch('TileCondProxyFile_OnlBch', Source=TileBchList)
604  offlineBadChannelsProxy = TileCondProxyFileBch('TileCondProxyFile_OflBch', Source='TileNoBad.oflBch')
605 
606  TileBadChannelsCondAlg = CompFactory.TileBadChannelsCondAlg
607  badChannelsCondAlg = TileBadChannelsCondAlg(name=f'{badChannels}_CondAlg',
608  OnlBchProxy=onlineBadChannelsProxy,
609  OflBchProxy=offlineBadChannelsProxy,
610  TileBadChannels=badChannels)
611 
612  acc = ComponentAccumulator()
613  acc.addCondAlgo(badChannelsCondAlg)
614 
615  return acc
616 
617 
618 badChannelsLines = """
619 0x312 2 0 0 2 0
620 0x312 4 0 2 0 0
621 0x312 11 0 0 0 2
622 0x312 6 0 0 0 512
623 0x307 12 0 0 0 2
624 0x335 12 0 0 0 512
625 """
626 
627 def maketool (name, badChannels, **kw):
628  TileCellBuilder = CompFactory.TileCellBuilder
629  return TileCellBuilder(name, TileBadChannels=badChannels, **kw)
630 
631 
633 
634  acc = ComponentAccumulator()
635 
636  from TileGeoModel.TileGMConfig import TileGMCfg
637  acc.merge( TileGMCfg(flags) )
638 
639  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
640  acc.merge(LArGMCfg(flags))
641 
642  from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg
643  acc.merge( TileCablingSvcCfg(flags) )
644 
645  from TileConditions.TileInfoLoaderConfig import TileInfoLoaderCfg
646  acc.merge( TileInfoLoaderCfg(flags) )
647 
648  from TileConditions.TileEMScaleConfig import TileEMScaleCondAlgCfg
649  acc.merge( TileEMScaleCondAlgCfg(flags) )
650 
651  from TileConditions.TileTimingConfig import TileTimingCondAlgCfg
652  acc.merge( TileTimingCondAlgCfg(flags) )
653 
654  from TileConditions.TileSampleNoiseConfig import TileSampleNoiseCondAlgCfg
655  acc.merge( TileSampleNoiseCondAlgCfg(flags) )
656 
657  bc1 = 'tilecellbuilder_bc1'
658  acc.merge( TileBadChannelsCfg(flags, bc1) )
659 
660  bc2 = 'tilecellbuilder_bc2'
661  acc.merge( TileBadChannelsCfg(flags, bc2,
662  [[(3, 1, 18, 8, 2, 0), BAD_HIGH],
663  [(2, 1, 18, 9, 1, 0), BAD_LOW],
664  [(2, 1, 18, 12, 0, 1), BAD_BOTH],
665  [(2, 1, 18, 11, 0, 0), BADTIMING],
666  [(4, 1, 0, 1, 0, 0), BAD_BOTH],
667  [(4, 1, 6, 1, 0, 0), BADTIMING],
668  ], badChannelsLines) )
669 
670 
671  TileRawChannelNoiseFilter = CompFactory.TileRawChannelNoiseFilter
672  noisefilter = TileRawChannelNoiseFilter('noisefilter')
673 
674  acc.addPublicTool( maketool ('tool1', bc1) )
675  acc.addPublicTool( maketool ('tool2', bc2) )
676  acc.addPublicTool( maketool ('tool5', bc1, fakeCrackCells=True) )
677  acc.addPublicTool( maketool ('tool6', bc1, EThreshold=300) )
678  acc.addPublicTool( maketool ('tool7', bc1, correctAmplitude=True, correctTime=True) )
679  acc.addPublicTool( maketool ('tool8', bc1, NoiseFilterTools=[noisefilter]) )
680  acc.addPublicTool( maketool ('tool9', bc1, TileDSPRawChannelContainer='TileRawChannelCntDsp') )
681  acc.addPublicTool( maketool ('tool10', bc1, TileDSPRawChannelContainer = 'TileRawChannelCntDsp',
682  correctTime=True, correctAmplitude=True) )
683  acc.addPublicTool( maketool ('tool11', bc1, TileDSPRawChannelContainer='TileRawChannelCntDsp',
684  NoiseFilterTools=[noisefilter]) )
685 
686  acc.addEventAlgo( PrepareDataAlg('prepalg1') )
687  prepalg1 = acc.getEventAlgo('prepalg1')
688 
689  from TileRecUtils.TileDQstatusConfig import TileDQstatusAlgCfg
690  acc.merge(TileDQstatusAlgCfg(flags, name='dqstat1',
691  TileRawChannelContainer='TRCDQ',
692  TileDigitsContainer=''))
693 
694 
695  acc.addEventAlgo( TestAlg('testalg1', prepalg1) )
696 
697  return acc
698 
699 
700 
701 if __name__ == "__main__":
702 
703  from AthenaConfiguration.AllConfigFlags import initConfigFlags
704  from AthenaConfiguration.TestDefaults import defaultConditionsTags, defaultTestFiles
705  from AthenaCommon.Logging import log
706  from AthenaCommon.Constants import INFO
707 
708  # Test setup
709  log.setLevel(INFO)
710 
711  flags = initConfigFlags()
712  flags.Input.Files = defaultTestFiles.HITS_RUN2
713  flags.Input.ConditionsRunNumber = 1
714  flags.Input.OverrideRunNumber = True
715  flags.IOVDb.GlobalTag = defaultConditionsTags.RUN2_MC
716  flags.Tile.RunType = TileRunType.PHY
717  flags.Exec.MaxEvents = 12
718  flags.fillFromArgs()
719 
720  flags.lock()
721 
722  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
723  cfg = MainServicesCfg(flags)
724 
725  # Configure reading POOL files
726  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
727  cfg.merge(PoolReadCfg(flags))
728 
729  from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
730  cfg.merge (EventInfoCnvAlgCfg (flags, disableBeamSpot = True))
731 
732  cfg.merge( TileRawChannelBuilderTestCfg(flags) )
733 
734  flags.dump()
735  cfg.printConfig(withDetails=True)
736  cfg.store( open('TileCellBuilderTest.pkl', 'wb') )
737 
738  sc = cfg.run()
739 
740  import sys
741  # Success should be 0
742  sys.exit(not sc.isSuccess())
TileCellBuilderTestConfig.PrepareDataAlg.exp_mbts
exp_mbts
Definition: TileCellBuilderTestConfig.py:257
TileCellBuilderTestConfig.TestAlg.tool9
tool9
Definition: TileCellBuilderTestConfig.py:416
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
TileCellBuilderTestConfig.TestAlg.tool11
tool11
Definition: TileCellBuilderTestConfig.py:418
TileCellBuilderTestConfig.maketool
def maketool(name, badChannels, **kw)
Definition: TileCellBuilderTestConfig.py:627
TileCellBuilderTestConfig.TestAlg.update_qbit
def update_qbit(qb, rctype)
Definition: TileCellBuilderTestConfig.py:445
TileCellBuilderTestConfig.TestAlg
Definition: TileCellBuilderTestConfig.py:395
TileCellBuilderTestConfig.PrepareDataAlg.tool
tool
Definition: TileCellBuilderTestConfig.py:259
TileCellBuilderTestConfig.PrepareDataAlg.exp_cells
exp_cells
Definition: TileCellBuilderTestConfig.py:256
TileCellBuilderTestConfig.TestAlg.initialize
def initialize(self)
Definition: TileCellBuilderTestConfig.py:401
TileCellBuilderTestConfig.TestAlg.prepAlg
prepAlg
Definition: TileCellBuilderTestConfig.py:398
python.TileTimingConfig.TileTimingCondAlgCfg
def TileTimingCondAlgCfg(flags, **kwargs)
Definition: TileTimingConfig.py:9
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
TileBadChannelsCondAlg
Condition algorithm to prepare TileBadChannels and put it into condition store.
Definition: TileBadChannelsCondAlg.h:31
TileCellBuilderTestConfig.TestAlg.tool8
tool8
Definition: TileCellBuilderTestConfig.py:415
TileCellBuilderTestConfig.PrepareDataAlg
Definition: TileCellBuilderTestConfig.py:244
TileCellBuilderTestConfig.TestAlg.tool2
tool2
Definition: TileCellBuilderTestConfig.py:411
TileCellBuilderTestConfig.TileFragHash
Definition: TileCellBuilderTestConfig.py:224
TileCellBuilderTestConfig.TestAlg.compare_cells
def compare_cells(self, ccc, exp_cells, rctype)
Definition: TileCellBuilderTestConfig.py:450
python.TileInfoLoaderConfig.TileInfoLoaderCfg
def TileInfoLoaderCfg(flags, **kwargs)
Definition: TileInfoLoaderConfig.py:12
TileCellBuilderTestConfig.TileRawChannelBuilderTestCfg
def TileRawChannelBuilderTestCfg(flags)
Definition: TileCellBuilderTestConfig.py:632
TileCellBuilderTestConfig.TestAlg.check_ei
def check_ei(self, extra_flags)
Definition: TileCellBuilderTestConfig.py:498
TileDQstatusConfig.TileDQstatusAlgCfg
def TileDQstatusAlgCfg(flags, **kwargs)
Definition: TileDQstatusConfig.py:31
TileCellBuilderTestConfig.TestAlg.tool10
tool10
Definition: TileCellBuilderTestConfig.py:417
TileCellBuilderTestConfig.TestAlg.__init__
def __init__(self, name, prepAlg)
Definition: TileCellBuilderTestConfig.py:396
TileCellBuilderTestConfig.TileBadChannelsCfg
def TileBadChannelsCfg(flags, badChannels, chans=[], lines='')
Definition: TileCellBuilderTestConfig.py:540
TileCondProxyFile
The tool to get Tile conditions data from file.
Definition: TileCondProxyFile.h:28
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:256
Constants
some useful constants -------------------------------------------------—
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
TileCellBuilderTestConfig.PrepareDataAlg.initialize
def initialize(self)
Definition: TileCellBuilderTestConfig.py:249
TileCellBuilderTestConfig.TestAlg.finalize
def finalize(self)
Definition: TileCellBuilderTestConfig.py:423
TileCellBuilderTestConfig.PrepareDataAlg.__init__
def __init__(self, name)
Definition: TileCellBuilderTestConfig.py:245
python.TileEMScaleConfig.TileEMScaleCondAlgCfg
def TileEMScaleCondAlgCfg(flags, **kwargs)
Definition: TileEMScaleConfig.py:10
TileCellBuilderTestConfig.exp_merge
def exp_merge(base, d)
Definition: TileCellBuilderTestConfig.py:131
TileCellBuilderTestConfig.TestAlg.tool5
tool5
Definition: TileCellBuilderTestConfig.py:412
TileCellBuilderTestConfig.TestAlg.execute
def execute(self)
Definition: TileCellBuilderTestConfig.py:428
TileCellBuilderTestConfig.add_pedestal
def add_pedestal(offs_addr, offs)
Definition: TileCellBuilderTestConfig.py:79
TileCellBuilder
This class creates Cells from RawChannels and stores them in a container.
Definition: TileCellBuilder.h:109
Trk::open
@ open
Definition: BinningType.h:40
python.TileSampleNoiseConfig.TileSampleNoiseCondAlgCfg
def TileSampleNoiseCondAlgCfg(flags, **kwargs)
Definition: TileSampleNoiseConfig.py:8
TileCellBuilderTestConfig.filter_e
def filter_e(base, thresh)
Definition: TileCellBuilderTestConfig.py:180
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
TileCellBuilderTestConfig.PrepareDataAlg.execute
def execute(self)
Definition: TileCellBuilderTestConfig.py:252
TileRawChannelNoiseFilter
This tool subtracts common-mode noise from all TileRawChannels in one container.
Definition: TileRawChannelNoiseFilter.h:39
TileCellBuilderTestConfig.TestAlg.make_bad_chan_lines
def make_bad_chan_lines(self, chans)
Definition: TileCellBuilderTestConfig.py:505
TileCellBuilderTestConfig.TestAlg.tool1
tool1
Definition: TileCellBuilderTestConfig.py:410
TileCellBuilderTestConfig.PrepareDataAlg.rctype
rctype
Definition: TileCellBuilderTestConfig.py:263
TileCellBuilderTestConfig.TestAlg.tool7
tool7
Definition: TileCellBuilderTestConfig.py:414
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
TileCellBuilderTestConfig.PrepareDataAlg.record_raw_data
def record_raw_data(self, hits, typ, baddq, bsflags, dspbsflags=0, dspcolls=set(), rawname='TileRawChannelCnt')
Definition: TileCellBuilderTestConfig.py:347
TileCellBuilderTestConfig.TestAlg.tool6
tool6
Definition: TileCellBuilderTestConfig.py:413
TileCellBuilderTestConfig.PrepareDataAlg.extra_ei_flags
extra_ei_flags
Definition: TileCellBuilderTestConfig.py:258
python.TileCablingSvcConfig.TileCablingSvcCfg
def TileCablingSvcCfg(flags)
Definition: TileCablingSvcConfig.py:11
TileCellBuilderTestConfig.TestAlg.check_bad_chan_lines
def check_bad_chan_lines(self)
Definition: TileCellBuilderTestConfig.py:522
TileGMConfig.TileGMCfg
def TileGMCfg(flags)
Definition: TileGMConfig.py:7