ATLAS Offline Software
Loading...
Searching...
No Matches
TileRawChannelBuilderTestConfig.py
Go to the documentation of this file.
2# Copyright (C) 2002-2024 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
229 return coll
230
231
232 def make_bad_rc (self, baddq):
233 cont = ROOT.TileRawChannelContainer (False, TileFragHash.OptFilterDsp, 0)
234 hashFunc = cont.hashFunc()
235 for icoll, chans in baddq.items():
236 coll = ROOT.TileRawChannelCollection (hashFunc.identifier (icoll))
237 mask = 0
238 for chan in chans:
239 mask |= (1<<(chan//3))
240 coll.setFragMemoryPar(mask)
241 cont.addCollection (coll, ROOT.IdentifierHash(icoll))
242 ROOT.SetOwnership (coll, False)
243 return cont
244
245
246
247
248
249
250class TestAlg (Alg):
251 def __init__ (self, name):
252 Alg.__init__ (self, name)
253 return
254
255 def initialize (self):
256 ROOT.ICaloCellMakerTool
257
258 def gettool (name):
259 tool = ROOT.ToolHandle(ROOT.TileRawChannelBuilder)('TileRawChannelBuilderTest/' + name)
260 if not tool.retrieve():
261 assert 0
262 return tool
263
264 self.tool1 = gettool ('tool1')
265 self.tool2 = gettool ('tool2')
266
267 return StatusCode.Success
268
269
270 def finalize (self):
271 # self.check_bad_chan_lines()
272 return StatusCode.Success
273
274
275 def execute (self):
276 ctx = self.getContext()
277 iev = ctx.evt()
278
279 if iev == 3:
280 return StatusCode.Success
281
282 tool = self.tool1
283 exp_chans = exp_chans_0
284
285 if iev == 0:
286 # Event 0: nominal
287 pass
288
289 elif iev == 1:
290 # Event 1: DQstatus bad channels
291 exp_chans = exp_chans_1
292
293 elif iev == 2:
294 # Event 2: noise filter
295 tool = self.tool2
296 exp_chans = exp_chans_2
297
298 else:
299 # Event 3: noise filter + dsp
300 exp_chans = exp_chans_3
301
302 digits = self.make_digits (digits_0)
303
304 if not tool.createContainer(ctx):
305 return StatusCode.Failure
306
307 for coll in digits:
308 if not tool.build (coll, ctx):
309 return StatusCode.Failure
310
311 if not tool.commitContainer(ctx):
312 return StatusCode.Failure
313
314 chans = self.evtStore['TileRawChannelFiltered']
315 self.compare_chans (chans, exp_chans)
316
317 return StatusCode.Success
318
319
320 @staticmethod
321 def make_vec (data):
322 v = getattr(ROOT, 'std::vector<float>')()
323 v.reserve (len (data))
324 for x in data:
325 v.push_back (x)
326 return v
327
328
329 def make_digits (self, digits):
330 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
331
332 unit = 0 # TileRawChannelUnit::ADCcounts
333 typ = TileFragHash.Default
334 cont = ROOT.TileDigitsContainer (False, typ, unit)
335 hashFunc = cont.hashFunc()
336
337 for icoll, colldata in digits:
338
339 coll = self.make_digit_coll (idHelper, hashFunc, icoll, colldata)
340 cont.addCollection (coll, ROOT.IdentifierHash(icoll))
341 ROOT.SetOwnership (coll, False)
342
343 return cont
344
345
346 def make_digit_coll (self, idHelper, hashFunc, icoll, colldata):
347 coll = ROOT.TileDigitsCollection (hashFunc.identifier(icoll))
348
349 for addr, data in colldata:
350 if isinstance(addr, tuple):
351 adc_id = idHelper.adc_id (*addr)
352 chan = ROOT.TileDigits (adc_id, TestAlg.make_vec (data))
353 else:
354 hwid = ROOT.HWIdentifier (addr)
355 chan = ROOT.TileDigits (hwid, TestAlg.make_vec (data))
356 coll.push_back (chan)
357
358 return coll
359
360
361 def compare_chans (self, chans, exp_chans):
362 assert chans.get_type() == 0
363 assert chans.get_unit() == 0
364 assert chans.get_bsflags() == (3<<28)
365
366 exp_chans = exp_chans.copy()
367 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
368
369 for coll in chans:
370 for c in coll:
371 lchan = [c.amplitude(),
372 c.time(),
373 c.quality(),
374 c.pedestal()]
375
376 cid = c.identify()
377 addr = (idHelper.section(cid),
378 idHelper.side(cid),
379 idHelper.module(cid),
380 idHelper.tower(cid),
381 idHelper.sampling(cid),
382 idHelper.pmt(cid))
383
384 l = exp_chans.get (addr)
385 if not l:
386 print ('xxx unexpected chan', addr, lchan)
387 assert 0
388 continue
389
390 l = l[:]
391
392 if (reldiff (lchan[0], l[0]) > 1e-3 or
393 reldiff (lchan[1], l[1]) > 1e-3 or
394 reldiff (lchan[2], l[2]) > 1e-3 or
395 reldiff (lchan[3], l[3]) > 1e-3):
396 print ('xxx chan mismatch: ', addr, lchan, l)
397 assert 0
398 del exp_chans[addr]
399
400 for extra in exp_chans:
401 print ('xxx unfound chan', extra)
402 assert 0
403 return
404
405
406
407
408
410
411 acc = ComponentAccumulator()
412
413 from TileConditions.TileInfoLoaderConfig import TileInfoLoaderCfg
414 acc.merge( TileInfoLoaderCfg(flags) )
415
416 from TileConditions.TileEMScaleConfig import TileEMScaleCondAlgCfg
417 acc.merge( TileEMScaleCondAlgCfg(flags) )
418
419 from TileConditions.TileSampleNoiseConfig import TileSampleNoiseCondAlgCfg
420 acc.merge( TileSampleNoiseCondAlgCfg(flags) )
421
422 TileRawChannelBuilderTest = CompFactory.TileRawChannelBuilderTest
423 acc.addPublicTool( TileRawChannelBuilderTest('tool1') )
424
425 TileRawChannelNoiseFilter = CompFactory.TileRawChannelNoiseFilter
426 noisefilter = TileRawChannelNoiseFilter('noisefilter')
427 acc.addPublicTool( TileRawChannelBuilderTest('tool2', NoiseFilterTools=[noisefilter]) )
428
429 acc.addEventAlgo( PrepareDataAlg('prepalg1') )
430
431 from TileRecUtils.TileDQstatusConfig import TileDQstatusAlgCfg
432 acc.merge(TileDQstatusAlgCfg(flags, name='dqstat1',
433 TileRawChannelContainer='TRCDQ'))
434
435 acc.addEventAlgo( TestAlg('testalg1') )
436
437 return acc
438
439
440if __name__ == "__main__":
441
442 from AthenaConfiguration.AllConfigFlags import initConfigFlags
443 from AthenaConfiguration.TestDefaults import defaultTestFiles
444 from AthenaCommon.Logging import log
445 from AthenaCommon.Constants import INFO
446
447 # Test setup
448 log.setLevel(INFO)
449
450 flags = initConfigFlags()
451 flags.Input.Files = defaultTestFiles.ESD_RUN2_MC
452 flags.Tile.RunType = TileRunType.PHY
453 flags.Exec.MaxEvents = 4
454 flags.fillFromArgs()
455
456 flags.lock()
457
458 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
459 cfg = MainServicesCfg(flags)
460
461 # Configure reading POOL files
462 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
463 cfg.merge(PoolReadCfg(flags))
464
465 cfg.merge( TileRawChannelBuilderTestCfg(flags) )
466
467 flags.dump()
468 cfg.printConfig(withDetails=True)
469 cfg.store( open('TileRawChannelBuilderTest.pkl', 'wb') )
470
471 sc = cfg.run()
472
473 import sys
474 # Success should be 0
475 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()