ATLAS Offline Software
Loading...
Searching...
No Matches
TileRawChannelBuilderTestConfig.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/python/TileRawChannelBuilderTestConfig.py
5# Author: sss
6# Date: Aug, 2018
7# Brief: Test for TileRawChannelBuilder.
8#
9
10
11import ROOT
12ROOT.TH1F
13
14from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
15from AthenaConfiguration.ComponentFactory import CompFactory
16from TileConfiguration.TileConfigFlags import TileRunType
17
18def reldiff (a, b):
19 den = abs(a)+abs(b)
20 if den == 0: den = 1
21 return abs(a-b)/den
22
23
24
25digits_0 = [
26 # (sec, side, mod, tow, samp, pmt, adc), [adc, time, qual, ped]
27 [0, [
28 [(1, 1, 0, 1, 1, 0, 1), [ 0.2, 22.1, 2.4, 42.9]],
29 [(1, 1, 0, 1, 1, 1, 1), [-0.4, 75.0, 2.7, 31.4]],
30 [(1, 1, 0, 1, 0, 0, 1), [-0.9, -13.3, 1.5, 37.4]],
31 [(1, 1, 0, 2, 0, 1, 1), [41.8, 0.1, 2.5, 45.7]],
32 [(1, 1, 0, 2, 0, 0, 1), [30.6, -0.4, 2.0, 33.1]],
33 [(1, 1, 0, 2, 1, 1, 1), [ 1.4, 12.9, 4.7, 43.1]],
34 [(1, 1, 0, 2, 1, 0, 1), [ 3.4, 3.5, 1.9, 54.2]],
35 ]],
36
37 [136, [
38 [(3, 1, 8, 13, 3, 0, 1), [26.9, 4.8, 5.2, 45.4]],
39 ]],
40
41 [146, [
42 [(3, 1, 18, 13, 3, 0, 1), [ 4.4, -26.5, 23.9, 51.2]],
43 [(3, 1, 18, 15, 3, 0, 1), [-0.1, -75.0, 3.7, 51.0]],
44 [(3, 1, 18, 8, 2, 0, 1), [-0.1, 75.0, 4.2, 41.7]],
45 [(3, 1, 18, 8, 2, 1, 1), [ 3.5, -11.9, 2.6, 44.7]],
46 [(3, 1, 18, 9, 1, 0, 1), [ 0.8, -17.6, 1.8, 49.2]],
47 [(3, 1, 18, 9, 1, 1, 1), [ 0.1, -75.0, 3.4, 48.4]],
48 [(2, 1, 18, 11, 0, 0, 1), [ 8.7, 0.4, 2.7, 50.2]],
49 [(2, 1, 18, 11, 0, 1, 1), [ 6.3, 1.9, 1.6, 48.6]],
50 [(2, 1, 18, 10, 1, 0, 1), [53.3, 1.3, 3.8, 38.4]],
51 [(2, 1, 18, 10, 1, 1, 1), [64.1, 1.0, 3.5, 36.9]],
52 [(2, 1, 18, 12, 0, 0, 1), [-0.2, -75.0, 2.8, 38.1]],
53 [(2, 1, 18, 12, 0, 1, 1), [ 0.5, -32.7, 1.9, 40.3]],
54 [(3, 1, 18, 10, 3, 0, 1), [ 5.4, 7.7, 8.2, 57.0]],
55 [(3, 1, 18, 11, 3, 0, 1), [48.9, 0.4, 4.0, 32.3]],
56 [(2, 1, 18, 11, 1, 0, 1), [38.5, 0.5, 1.7, 46.8]],
57 [(2, 1, 18, 11, 1, 1, 1), [48.1, 0.3, 1.6, 46.3]],
58 [(2, 1, 18, 10, 2, 0, 1), [ 0.3, 75.0, 2.0, 34.9]],
59 [(2, 1, 18, 10, 2, 1, 1), [0.1, -75.0, 3.7, 54.7]],
60 ]],
61
62 # Some MBTS cells.
63 [135, [ [(4, 1, 0, 1, 0, 0, 0), [ 59.1, 2.8, 6.9, 56.2]] ]],
64 [181, [ [(4, 1, 6, 1, 0, 0, 0), [ 56.4, 1.2, 2.9, 39.9]] ]],
65 [182, [ [(4, 1, 6, 0, 0, 0, 0), [ 44.9, 0.5, 1.4, 42.1]] ]],
66 [231, [ [(4, -1, 3, 0, 0, 0, 0), [107.9, 1.7, 7.8, 47.8]] ]],
67
68 # Some E4 cells.
69 [220, [ [(4, -1, 0, 2, 0, 0, 0), [ 2.3, 3.2, 2.5, 44.4]] ]],
70 [223, [ [(4, -1, 1, 2, 0, 0, 0), [ 3.1, -5.3, 2.4, 44.4]] ]],
71 [225, [ [(4, -1, 2, 2, 0, 0, 0), [ -0.4, 27.6, 1.3, 32.5]] ]],
72 [228, [ [(4, -1, 3, 2, 0, 0, 0), [ 0.2, -75.0, 2.4, 35.4]] ]],
73]
74
75
76exp_chans_0 = {
77 (1, 1, 0, 1, 1, 0) : [ 0.2, 22.1, 2.4, 42.9],
78 (1, 1, 0, 1, 1, 1) : [ -0.4, 75.0, 2.7, 120031.4],
79 (1, 1, 0, 1, 0, 0) : [ -0.9, -13.3, 1.5, 120037.4],
80 (1, 1, 0, 2, 0, 1) : [ 41.8, 0.1, 2.5, 45.7],
81 (1, 1, 0, 2, 0, 0) : [ 30.6, -0.4, 2.0, 120033.1],
82 (1, 1, 0, 2, 1, 1) : [ 1.4, 12.9, 4.7, 43.1],
83 (1, 1, 0, 2, 1, 0) : [ 3.4, 3.5, 1.9, 54.2],
84 (4, 1, 0, 1, 0, 0) : [ 59.1, 2.8, 6.9, 56.2],
85 (3, 1, 8, 13, 3, 0) : [ 26.9, 4.8, 5.2, 45.4],
86 (3, 1, 18, 13, 3, 0) : [ 4.4, -26.5, 23.9, 60051.2],
87 (3, 1, 18, 15, 3, 0) : [ -0.1, -75.0, 3.7, 120051.0],
88 (3, 1, 18, 8, 2, 0) : [ -0.1, 75.0, 4.2, 120041.7],
89 (3, 1, 18, 8, 2, 1) : [ 3.5, -11.9, 2.6, 120044.7],
90 (3, 1, 18, 9, 1, 0) : [ 0.8, -17.6, 1.8, 120049.2],
91 (3, 1, 18, 9, 1, 1) : [ 0.1, -75.0, 3.4, 120048.4],
92 (2, 1, 18, 11, 0, 0) : [ 8.7, 0.4, 2.7, 60050.2],
93 (2, 1, 18, 11, 0, 1) : [ 6.3, 1.9, 1.6, 60048.6],
94 (2, 1, 18, 10, 1, 0) : [ 53.3, 1.3, 3.8, 60038.4],
95 (2, 1, 18, 10, 1, 1) : [ 64.1, 1.0, 3.5, 60036.9],
96 (2, 1, 18, 12, 0, 0) : [ -0.2, -75.0, 2.8, 120038.1],
97 (2, 1, 18, 12, 0, 1) : [ 0.5, -32.7, 1.9, 120040.3],
98 (3, 1, 18, 10, 3, 0) : [ 5.4, 7.7, 8.2, 60057.0],
99 (3, 1, 18, 11, 3, 0) : [ 48.9, 0.4, 4.0, 60032.3],
100 (2, 1, 18, 11, 1, 0) : [ 38.5, 0.5, 1.7, 60046.8],
101 (2, 1, 18, 11, 1, 1) : [ 48.1, 0.3, 1.6, 60046.3],
102 (2, 1, 18, 10, 2, 0) : [ 0.3, 75.0, 2.0, 170034.9],
103 (2, 1, 18, 10, 2, 1) : [ 0.1, -75.0, 3.7, 120054.7],
104 (4, 1, 6, 1, 0, 0) : [ 56.4, 1.2, 2.9, 39.9],
105 (4, 1, 6, 0, 0, 0) : [ 44.9, 0.5, 1.4, 42.1],
106 (4, -1, 0, 2, 0, 0) : [ 2.3, 3.2, 2.5, 44.4],
107 (4, -1, 1, 2, 0, 0) : [ 3.1, -5.3, 2.4, 10044.4],
108 (4, -1, 2, 2, 0, 0) : [ -0.4, 27.6, 1.3, 10032.5],
109 (4, -1, 3, 2, 0, 0) : [ 0.2, -75.0, 2.4, 10035.4],
110 (4, -1, 3, 0, 0, 0) : [107.9, 1.7, 7.8, 47.8],
111}
112
113
114def exp_merge (base, d):
115 new = base.copy()
116 new.update (d)
117 return new
118
119
120# TileDQstatus errors
121exp_chans_1 = exp_merge (exp_chans_0, {
122 (3, 1, 18, 13, 3, 0) : [ 4.4, -26.5, 23.9, 70051.2],
123 (3, 1, 18, 15, 3, 0) : [ -0.1, -75.0, 3.7, 70051.0],
124 (3, 1, 18, 8, 2, 0) : [ -0.1, 75.0, 4.2, 70041.7],
125 (2, 1, 18, 10, 1, 1) : [ 64.1, 1.0, 3.5, 70036.9],
126 (2, 1, 18, 12, 0, 0) : [ -0.2, -75.0, 2.8, 70038.1],
127 (2, 1, 18, 12, 0, 1) : [ 0.5, -32.7, 1.9, 70040.3],
128 })
129
130
131# Noise filter
132exp_chans_2 = exp_merge (exp_chans_0, {
133 (1, 1, 0, 1, 1, 0) : [ -0.6, 22.1, 2.4, 43.7],
134 (1, 1, 0, 2, 0, 1) : [ 41.0, 0.1, 2.5, 46.5],
135 (1, 1, 0, 2, 1, 1) : [ 0.6, 12.9, 4.7, 43.9],
136})
137
138
139# Noise filter+dsp
140exp_chans_3 = exp_merge (exp_chans_0, {
141 (1, 1, 0, 1, 1, 0) : [ 0.125, 22.1, 2.4, 42.975],
142 (1, 1, 0, 1, 1, 1) : [ -0.475, 75.0, 2.7, 120031.477],
143 (1, 1, 0, 1, 0, 0) : [ -0.975, -13.3, 1.5, 120037.477],
144 (1, 1, 0, 2, 0, 1) : [ 41.725, 0.1, 2.5, 45.775],
145 (1, 1, 0, 2, 0, 0) : [ 30.525, -0.4, 2.0, 120033.180],
146 (1, 1, 0, 2, 1, 1) : [ 1.325, 12.9, 4.7, 43.175],
147})
148
149
150
151# TileFragHash::TYPE
153 Beam = 255
154 Default = 0
155 Digitizer = 0
156 OptFilterDsp = 1
157 OptFilterOffline = 2
158 OptFilterDspCompressed = 3
159 ManyAmps = 4
160 MF = 5
161 FitFilter = 6
162 FitFilterCool = 7
163 FlatFilter = 8
164 WienerFilterOffline = 9
165
166
167from AthenaPython.PyAthenaComps import Alg, StatusCode
168
169
170
171class PrepareDataAlg (Alg):
172 def __init__ (self, name):
173 Alg.__init__ (self, name)
174 return
175
176
177 def initialize (self):
178 return StatusCode.Success
179
180
181 def execute (self):
182 iev = self.getContext().evt()
183
184 if iev == 1:
185 baddq = {146: (2, 10)}
186 rc = self.make_bad_rc (baddq)
187 elif iev == 3:
188 rc = self.make_rc (digits_0)
189 else:
190 rc = self.make_rc ({})
191
192 self.evtStore.record (rc, 'TRCDQ', False)
193
194 return StatusCode.Success
195
196
197 def make_rc (self, digits):
198 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
199
200 unit = 0 # TileRawChannelUnit::ADCcounts
201 typ = TileFragHash.Default
202 cont = ROOT.TileRawChannelContainer (False, typ, unit)
203 hashFunc = cont.hashFunc()
204
205 digits = dict (digits)
206 for icoll in range(256):
207 colldata = digits.get (icoll, [])
208
209 coll = self.make_rc_coll (idHelper, hashFunc, icoll, colldata)
210 cont.addCollection (coll, ROOT.IdentifierHash(icoll))
211 ROOT.SetOwnership (coll, False)
212
213 return cont
214
215
216 def make_rc_coll (self, idHelper, hashFunc, icoll, colldata):
217 coll = ROOT.TileRawChannelCollection (hashFunc.identifier(icoll))
218
219 for addr, data in colldata:
220 if isinstance(addr, tuple):
221 adc_id = idHelper.adc_id (*addr)
222 chan = ROOT.TileRawChannel (adc_id, *data)
223 else:
224 hwid = ROOT.HWIdentifier (addr)
225 chan = ROOT.TileRawChannel (hwid, *data)
226 chan.setPedestal (0)
227 coll.push_back (chan)
228 ROOT.SetOwnership (chan, False)
229
230 return coll
231
232
233 def make_bad_rc (self, baddq):
234 cont = ROOT.TileRawChannelContainer (False, TileFragHash.OptFilterDsp, 0)
235 hashFunc = cont.hashFunc()
236 for icoll, chans in baddq.items():
237 coll = ROOT.TileRawChannelCollection (hashFunc.identifier (icoll))
238 mask = 0
239 for chan in chans:
240 mask |= (1<<(chan//3))
241 coll.setFragMemoryPar(mask)
242 cont.addCollection (coll, ROOT.IdentifierHash(icoll))
243 ROOT.SetOwnership (coll, False)
244 return cont
245
246
247
248
249
250
251class TestAlg (Alg):
252 def __init__ (self, name):
253 Alg.__init__ (self, name)
254 return
255
256 def initialize (self):
257 ROOT.ICaloCellMakerTool
258
259 def gettool (name):
260 tool = ROOT.ToolHandle(ROOT.TileRawChannelBuilder)('TileRawChannelBuilderTest/' + name)
261 if not tool.retrieve():
262 assert 0
263 return tool
264
265 self.tool1 = gettool ('tool1')
266 self.tool2 = gettool ('tool2')
267
268 return StatusCode.Success
269
270
271 def finalize (self):
272 # self.check_bad_chan_lines()
273 return StatusCode.Success
274
275
276 def execute (self):
277 ctx = self.getContext()
278 iev = ctx.evt()
279
280 if iev == 3:
281 return StatusCode.Success
282
283 tool = self.tool1
284 exp_chans = exp_chans_0
285
286 if iev == 0:
287 # Event 0: nominal
288 pass
289
290 elif iev == 1:
291 # Event 1: DQstatus bad channels
292 exp_chans = exp_chans_1
293
294 elif iev == 2:
295 # Event 2: noise filter
296 tool = self.tool2
297 exp_chans = exp_chans_2
298
299 else:
300 # Event 3: noise filter + dsp
301 exp_chans = exp_chans_3
302
303 digits = self.make_digits (digits_0)
304
305 if not tool.createContainer(ctx):
306 return StatusCode.Failure
307
308 for coll in digits:
309 if not tool.build (coll, ctx):
310 return StatusCode.Failure
311
312 if not tool.commitContainer(ctx):
313 return StatusCode.Failure
314
315 chans = self.evtStore['TileRawChannelFiltered']
316 self.compare_chans (chans, exp_chans)
317
318 return StatusCode.Success
319
320
321 @staticmethod
322 def make_vec (data):
323 v = getattr(ROOT, 'std::vector<float>')()
324 v.reserve (len (data))
325 for x in data:
326 v.push_back (x)
327 return v
328
329
330 def make_digits (self, digits):
331 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
332
333 unit = 0 # TileRawChannelUnit::ADCcounts
334 typ = TileFragHash.Default
335 cont = ROOT.TileDigitsContainer (False, typ, unit)
336 hashFunc = cont.hashFunc()
337
338 for icoll, colldata in digits:
339
340 coll = self.make_digit_coll (idHelper, hashFunc, icoll, colldata)
341 cont.addCollection (coll, ROOT.IdentifierHash(icoll))
342 ROOT.SetOwnership (coll, False)
343
344 return cont
345
346
347 def make_digit_coll (self, idHelper, hashFunc, icoll, colldata):
348 coll = ROOT.TileDigitsCollection (hashFunc.identifier(icoll))
349
350 for addr, data in colldata:
351 if isinstance(addr, tuple):
352 adc_id = idHelper.adc_id (*addr)
353 chan = ROOT.TileDigits (adc_id, TestAlg.make_vec (data))
354 else:
355 hwid = ROOT.HWIdentifier (addr)
356 chan = ROOT.TileDigits (hwid, TestAlg.make_vec (data))
357 coll.push_back (chan)
358 ROOT.SetOwnership (chan, False)
359
360 return coll
361
362
363 def compare_chans (self, chans, exp_chans):
364 assert chans.get_type() == 0
365 assert chans.get_unit() == 0
366 assert chans.get_bsflags() == (3<<28)
367
368 exp_chans = exp_chans.copy()
369 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
370
371 for coll in chans:
372 for c in coll:
373 lchan = [c.amplitude(),
374 c.time(),
375 c.quality(),
376 c.pedestal()]
377
378 cid = c.identify()
379 addr = (idHelper.section(cid),
380 idHelper.side(cid),
381 idHelper.module(cid),
382 idHelper.tower(cid),
383 idHelper.sampling(cid),
384 idHelper.pmt(cid))
385
386 l = exp_chans.get (addr)
387 if not l:
388 print ('xxx unexpected chan', addr, lchan)
389 assert 0
390 continue
391
392 l = l[:]
393
394 if (reldiff (lchan[0], l[0]) > 1e-3 or
395 reldiff (lchan[1], l[1]) > 1e-3 or
396 reldiff (lchan[2], l[2]) > 1e-3 or
397 reldiff (lchan[3], l[3]) > 1e-3):
398 print ('xxx chan mismatch: ', addr, lchan, l)
399 assert 0
400 del exp_chans[addr]
401
402 for extra in exp_chans:
403 print ('xxx unfound chan', extra)
404 assert 0
405 return
406
407
408
409
410
412
413 acc = ComponentAccumulator()
414
415 from TileConditions.TileInfoLoaderConfig import TileInfoLoaderCfg
416 acc.merge( TileInfoLoaderCfg(flags) )
417
418 from TileConditions.TileEMScaleConfig import TileEMScaleCondAlgCfg
419 acc.merge( TileEMScaleCondAlgCfg(flags) )
420
421 from TileConditions.TileSampleNoiseConfig import TileSampleNoiseCondAlgCfg
422 acc.merge( TileSampleNoiseCondAlgCfg(flags) )
423
424 TileRawChannelBuilderTest = CompFactory.TileRawChannelBuilderTest
425 acc.addPublicTool( TileRawChannelBuilderTest('tool1') )
426
427 TileRawChannelNoiseFilter = CompFactory.TileRawChannelNoiseFilter
428 noisefilter = TileRawChannelNoiseFilter('noisefilter')
429 acc.addPublicTool( TileRawChannelBuilderTest('tool2', NoiseFilterTools=[noisefilter]) )
430
431 acc.addEventAlgo( PrepareDataAlg('prepalg1') )
432
433 from TileRecUtils.TileDQstatusConfig import TileDQstatusAlgCfg
434 acc.merge(TileDQstatusAlgCfg(flags, name='dqstat1',
435 TileRawChannelContainer='TRCDQ'))
436
437 acc.addEventAlgo( TestAlg('testalg1') )
438
439 return acc
440
441
442if __name__ == "__main__":
443
444 from AthenaConfiguration.AllConfigFlags import initConfigFlags
445 from AthenaConfiguration.TestDefaults import defaultTestFiles
446 from AthenaCommon.Logging import log
447 from AthenaCommon.Constants import INFO
448
449 # Test setup
450 log.setLevel(INFO)
451
452 flags = initConfigFlags()
453 flags.Input.Files = defaultTestFiles.ESD_RUN2_MC
454 flags.Tile.RunType = TileRunType.PHY
455 flags.Exec.MaxEvents = 4
456 flags.fillFromArgs()
457
458 flags.lock()
459
460 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
461 cfg = MainServicesCfg(flags)
462
463 # Configure reading POOL files
464 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
465 cfg.merge(PoolReadCfg(flags))
466
467 cfg.merge( TileRawChannelBuilderTestCfg(flags) )
468
469 flags.dump()
470 cfg.printConfig(withDetails=True)
471 cfg.store( open('TileRawChannelBuilderTest.pkl', 'wb') )
472
473 sc = cfg.run()
474
475 import sys
476 # Success should be 0
477 sys.exit(not sc.isSuccess())
make_rc_coll(self, idHelper, hashFunc, icoll, colldata)
make_digit_coll(self, idHelper, hashFunc, icoll, colldata)
This tool subtracts common-mode noise from all TileRawChannels in one container.
void initialize()