ATLAS Offline Software
Loading...
Searching...
No Matches
TileDQstatusToolTestConfig.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/TileDQstatusToolTestConfig.py
5# Author: scott snyder
6# Date: Nov, 2018
7# Brief: Test for TileDQstatusTool.
8#
9
10
11import ROOT
12ROOT.TH1F
13
14from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
15from AthenaConfiguration.ComponentAccumulator import CompFactory
16from TileConfiguration.TileConfigFlags import TileRunType
17from AthenaPython.PyAthenaComps import Alg, StatusCode
18
19import sys
20
21
22
23
24# TileFragHash::TYPE
26 Beam = 255
27 Default = 0
28 Digitizer = 0
29 OptFilterDsp = 1
30 OptFilterOffline = 2
31 OptFilterDspCompressed = 3
32 ManyAmps = 4
33 MF = 5
34 FitFilter = 6
35 FitFilterCool = 7
36 FlatFilter = 8
37 WienerFilterOffline = 9
38
39
40BEAM_TDC_FRAG = 0x000
41BEAM_ADC_FRAG = 0x001
42MUON_ADC_FRAG = 0x002
43ADDR_ADC_FRAG = 0x003
44LASE_PTN_FRAG = 0x004
45LASE_ADC_FRAG = 0x005
46ADD_FADC_FRAG = 0x006
47ECAL_ADC_FRAG = 0x007
48DIGI_PAR_FRAG = 0x0ff
49LASER_OBJ_FRAG = 0x016
50
51
52hits_0 = [
53 # (sec, side, mod, tow, samp, pmt, adc), [adc, time, qual, ped]
54 [0, [
55 [(1, 1, 0, 1, 1, 0, 1), [ 0.2, 22.1, 2.4, 42.9]],
56 [(1, 1, 0, 1, 1, 1, 1), [-0.4, 75.0, 2.7, 31.4]],
57 [(1, 1, 0, 1, 0, 0, 1), [-0.9, -13.3, 1.5, 37.4]],
58 [(1, 1, 0, 2, 0, 1, 1), [41.8, 0.1, 2.5, 45.7]],
59 [(1, 1, 0, 2, 0, 0, 1), [30.6, -0.4, 2.0, 33.1]],
60 [(1, 1, 0, 2, 1, 1, 1), [ 1.4, 12.9, 4.7, 43.1]],
61 [(1, 1, 0, 2, 1, 0, 1), [ 3.4, 3.5, 1.9, 54.2]],
62 ]],
63
64 [136, [
65 [(3, 1, 8, 13, 3, 0, 1), [26.9, 4.8, 5.2, 45.4]],
66 ]],
67
68 [146, [
69 [(3, 1, 18, 13, 3, 0, 1), [ 4.4, -26.5, 23.9, 51.2]],
70 [(3, 1, 18, 15, 3, 0, 1), [-0.1, -75.0, 3.7, 51.0]],
71 [(3, 1, 18, 8, 2, 0, 1), [-0.1, 75.0, 4.2, 41.7]],
72 [(3, 1, 18, 8, 2, 1, 1), [ 3.5, -11.9, 2.6, 44.7]],
73 [(3, 1, 18, 9, 1, 0, 1), [ 0.8, -17.6, 1.8, 49.2]],
74 [(3, 1, 18, 9, 1, 1, 1), [ 0.1, -75.0, 3.4, 48.4]],
75 [(2, 1, 18, 11, 0, 0, 1), [ 8.7, 0.4, 2.7, 50.2]],
76 [(2, 1, 18, 11, 0, 1, 1), [ 6.3, 1.9, 1.6, 48.6]],
77 [(2, 1, 18, 10, 1, 0, 1), [53.3, 1.3, 3.8, 38.4]],
78 [(2, 1, 18, 10, 1, 1, 1), [64.1, 1.0, 3.5, 36.9]],
79 [(2, 1, 18, 12, 0, 0, 1), [-0.2, -75.0, 2.8, 38.1]],
80 [(2, 1, 18, 12, 0, 1, 1), [ 0.5, -32.7, 1.9, 40.3]],
81 [(3, 1, 18, 10, 3, 0, 1), [ 5.4, 7.7, 8.2, 57.0]],
82 [(3, 1, 18, 11, 3, 0, 1), [48.9, 0.4, 4.0, 32.3]],
83 [(2, 1, 18, 11, 1, 0, 1), [38.5, 0.5, 1.7, 46.8]],
84 [(2, 1, 18, 11, 1, 1, 1), [48.1, 0.3, 1.6, 46.3]],
85 [(2, 1, 18, 10, 2, 0, 1), [ 0.3, 75.0, 2.0, 34.9]],
86 [(2, 1, 18, 10, 2, 1, 1), [0.1, -75.0, 3.7, 54.7]],
87 ]],
88
89 # Some MBTS cells.
90 [135, [ [(4, 1, 0, 1, 0, 0, 0), [ 59.1, 2.8, 6.9, 56.2]] ]],
91 [181, [ [(4, 1, 6, 1, 0, 0, 0), [ 56.4, 1.2, 2.9, 39.9]] ]],
92 [182, [ [(4, 1, 6, 0, 0, 0, 0), [ 44.9, 0.5, 1.4, 42.1]] ]],
93 [231, [ [(4, -1, 3, 0, 0, 0, 0), [107.9, 1.7, 7.8, 47.8]] ]],
94
95 # Some E4 cells.
96 [220, [ [(4, -1, 0, 2, 0, 0, 0), [ 2.3, 3.2, 2.5, 44.4]] ]],
97 [223, [ [(4, -1, 1, 2, 0, 0, 0), [ 3.1, -5.3, 2.4, 44.4]] ]],
98 [225, [ [(4, -1, 2, 2, 0, 0, 0), [ -0.4, 27.6, 1.3, 32.5]] ]],
99 [228, [ [(4, -1, 3, 2, 0, 0, 0), [ 0.2, -75.0, 2.4, 35.4]] ]],
100
101 # Some disconnected cells.
102 [253, [
103 [4706026383833300992, [ 0, 0, 0, 50000]],
104 [4706027483344928768, [ 0, 0, 0, 50000]] ], ],
105 [255, [
106 [4706157225717006336, [ 0, 0, 0, 80000]],
107 [4706158325228634112, [ 0, 0, 0, 80000]] ], ],
108]
109
110
111
112
113
114def compare_args (args, pat):
115 if len(args) != len(pat): return False
116 for i in range(len(args)):
117 if args[i] != pat[i] and pat[i] != -1:
118 return False
119 return True
120def check_exc (args, exclist):
121 for exc in exclist:
122 if compare_args (args, exc): return True
123 return False
124def check_flag (dq, mname, exp, exc, *args):
125 ret = getattr(dq, mname)(*args)
126 if bool(ret) == bool(exp): return
127 if check_exc (args, exc.get(mname, [])): return
128 print ('xxx', mname, ret, exp, *args)
129 assert 0
130 return
131
132
133class TestAlg (Alg):
134 def __init__ (self, name):
135 Alg.__init__ (self, name)
136 return
137
138
139 def initialize (self):
140 ROOT.ICaloCellMakerTool
141
142 def gettool (name):
143 tool = ROOT.ToolHandle(ROOT.ITileDQstatusTool)('TileDQstatusTool/' + name)
144 if not tool.retrieve():
145 assert 0
146 return tool
147
148 self.tool1 = gettool ('tool1')
149 self.tool2 = gettool ('tool2')
150
151 return StatusCode.Success
152
153
154 def execute (self):
155 self.test1()
156 self.test2()
157 self.test3()
158 self.test4()
159 self.test5()
160 self.test6()
161 self.test7()
162 self.test8()
163 return StatusCode.Success
164
165
166 def test1 (self):
167 print ('*** Starting test1')
168 sys.stdout.flush()
169
170 flag_exc = {'checkEmptyEvent' :
171 [(3,13,3), (3,13,9), (3,13,12)],
172 }
173
174 rctype = TileFragHash.OptFilterOffline
175 self.do_test (rctype, flag_exc)
176 return
177
178
179 def test2 (self):
180 print ('*** Starting test2')
181 sys.stdout.flush()
182
183 flag_exc = {'checkEmptyEvent' :
184 [(3,13,3), (3,13,9), (3,13,12)],
185 'checkMemoryParityErr' :
186 [(3,18,0,-1), (3,18,3,-1)],
187 'isAdcDQgood' :
188 [(3,18,0,-1), (3,18,1,-1), (3,18,2,-1),
189 (3,18,9,-1), (3,18,10,-1), (3,18,11,-1),],
190 'isChanDQgood' :
191 [(3,18,0), (3,18,1), (3,18,2),
192 (3,18,9), (3,18,10), (3,18,11),],
193 }
194
195 rctype = TileFragHash.OptFilterDsp
196 rc_baddq = {146 : [('setFragMemoryPar', 0x09)]}
197 self.do_test (rctype, flag_exc, rc_baddq = rc_baddq)
198 return
199
200
201 def test3 (self):
202 print ('*** Starting test3')
203 sys.stdout.flush()
204
205 flag_exc = {'checkEmptyEvent' :
206 [(3,13,3), (3,13,9), (3,13,12)],
207 'isAdcDQgood' : [(3,18,-1,-1)],
208 'isChanDQgood' : [(3,18,-1)],
209 'checkBCIDErr' : [(3,18,-1,-1)],
210 'checkBCIDErrDetail' : [(3,18,-1,-1)],
211 }
212
213 rctype = TileFragHash.OptFilterDsp
214 rc_baddq = {146 : [('setFragBCID', 0x6565)]}
215 self.do_test (rctype, flag_exc, rc_baddq = rc_baddq)
216 return
217
218
219 def test4 (self):
220 print ('*** Starting test4')
221 sys.stdout.flush()
222
223 flag_exc = {'checkEmptyEvent' :
224 [(3,13,3), (3,13,9), (3,13,12)],
225 }
226
227 rctype = TileFragHash.OptFilterOffline
228 self.do_test (rctype, flag_exc, isCalib = True)
229 return
230
231
232 def test5 (self):
233 print ('*** Starting test5')
234 sys.stdout.flush()
235
236 flag_exc = {'checkEmptyEvent' :
237 [(3,13,3), (3,13,9), (3,13,12)],
238 }
239
240 rctype = TileFragHash.OptFilterOffline
241 self.do_test (rctype, flag_exc, incomplete = True)
242 return
243
244
245 def test6 (self):
246 print ('*** Starting test6')
247 sys.stdout.flush()
248
249 flag_exc = {'checkEmptyEvent' :
250 [(3,13,3), (3,13,9), (3,13,12)],
251 }
252
253 rctype = TileFragHash.OptFilterOffline
254 self.do_test (rctype, flag_exc, beamfrag = DIGI_PAR_FRAG)
255 return
256
257
258 def test7 (self):
259 print ('*** Starting test7')
260 sys.stdout.flush()
261
262 flag_exc = {'checkEmptyEvent' :
263 [(3,13,3), (3,13,9), (3,13,12)],
264 }
265
266 rctype = TileFragHash.OptFilterOffline
267 self.do_test (rctype, flag_exc, beamfrag = LASER_OBJ_FRAG)
268 return
269
270
271 def test8 (self):
272 print ('*** Starting test8')
273 sys.stdout.flush()
274
275 flag_exc = {'checkEmptyEvent' :
276 [(3,13,3), (3,13,9), (3,13,12)],
277 }
278
279 rctype = TileFragHash.OptFilterOffline
280 self.do_test (rctype, flag_exc, tool = self.tool2)
281 return
282
283
284 def do_test (self, rctype, flag_exc, rc_baddq={},
285 isCalib = False,
286 incomplete = False,
287 beamfrag = LASE_PTN_FRAG,
288 tool = None):
289 rc = self.make_raw_data (hits_0, rctype, rc_baddq)
290 digits = self.make_digits (incomplete, isCalib)
291 be = self.make_beamelem (beamfrag)
292
293 dq = ROOT.TileDQstatus()
294
295 eid = ROOT.EventIDBase()
296 eid.set_bunch_crossing_id (1234)
297 eid.set_run_number(self.getContext().eventID().run_number())
298 eid.set_lumi_block(0)
299 ctx = ROOT.EventContext()
300 ctx.setEventID (eid)
301 ctx.setSlot (0)
302 ctx.setExtension(ROOT.Atlas.ExtendedEventContext())
303
304 trigType = -123
305 cispar = 110*[0]
306 bcid = 1234
307 if beamfrag == LASE_PTN_FRAG:
308 trigType = 23
309
310 elif beamfrag == DIGI_PAR_FRAG:
311 cispar = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
312 110, 111, 112, 113, 114, 111, 2, 5, 6, 7,
313 8, 117, 118, 119, 120] + 85*[0]
314 bcid = 11
315
316 elif beamfrag == LASER_OBJ_FRAG:
317 bcid = 22
318
319 if not tool:
320 tool = self.tool1
321 assert tool.makeStatus (ctx, rc, digits, be, dq).isSuccess()
322
323 assert dq.isFilled() is True
324 assert dq.isBiGain() == isCalib
325 assert dq.nonZeroCounter() is True
326 assert dq.incompleteDigits() == incomplete
327 assert dq.calibMode() == isCalib
328 assert dq.trigType() == trigType
329 assert dq.RODBCID() == bcid
330
331 dq_cispar = [dq.cispar()[i] for i in range(110)]
332 assert dq_cispar == cispar
333
334
335 for partition in range(5):
336 for drawer in range(64):
337 for gain in range(2):
338 check_flag (dq, 'checkGlobalErr', False, flag_exc,
339 partition, drawer, gain)
340 check_flag (dq, 'checkGlobalCRCErr', False, flag_exc,
341 partition, drawer, gain)
342 for ch in range(48):
343 for gain in range(2):
344 check_flag (dq, 'isAdcDQgood', True, flag_exc,
345 partition, drawer, ch, gain)
346 check_flag (dq, 'isChanDQgood', True, flag_exc,
347 partition, drawer, ch)
348 for dmu in range(16):
349 check_flag (dq, 'checkEmptyEvent', False, flag_exc,
350 partition, drawer, dmu)
351 for gain in range(2):
352 check_flag (dq, 'checkROD_CRCErr', False, flag_exc,
353 partition, drawer, dmu, gain)
354 check_flag (dq, 'checkFE_CRCErr', False, flag_exc,
355 partition, drawer, dmu, gain)
356 check_flag (dq, 'checkBCIDErr', False, flag_exc,
357 partition, drawer, dmu, gain)
358 check_flag (dq, 'checkBCIDErrDetail', False, flag_exc,
359 partition, drawer, dmu, gain)
360 check_flag (dq, 'checkHeaderFormatErr', False, flag_exc,
361 partition, drawer, dmu, gain)
362 check_flag (dq, 'checkHeaderParityErr', False, flag_exc,
363 partition, drawer, dmu, gain)
364 check_flag (dq, 'checkSampleFormatErr', False, flag_exc,
365 partition, drawer, dmu, gain)
366 check_flag (dq, 'checkSampleParityErr', False, flag_exc,
367 partition, drawer, dmu, gain)
368 check_flag (dq, 'checkMemoryParityErr', False, flag_exc,
369 partition, drawer, dmu, gain)
370 check_flag (dq, 'checkSingleStrobeErr', False, flag_exc,
371 partition, drawer, dmu, gain)
372 check_flag (dq, 'checkDoubleStrobeErr', False, flag_exc,
373 partition, drawer, dmu, gain)
374
375 return StatusCode.Success
376
377
378 def make_raw_data (self, hits, typ, baddq):
379 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
380
381 unit = 0 # TileRawChannelUnit::ADCcounts
382 cont = ROOT.TileRawChannelContainer (False, typ, unit)
383 cont.set_bsflags (0x32002000)
384 hashFunc = cont.hashFunc()
385
386 for icoll, colldata in hits:
387 coll = ROOT.TileRawChannelCollection (hashFunc.identifier(icoll))
388 coll.setFragFEChipMask (0)
389
390 for func, mask in baddq.get (icoll, []):
391 getattr(coll, func)(mask)
392
393 for addr, data in colldata:
394 if isinstance(addr, tuple):
395 adc_id = idHelper.adc_id (*addr)
396 chan = ROOT.TileRawChannel (adc_id, *data)
397 else:
398 hwid = ROOT.HWIdentifier (addr)
399 chan = ROOT.TileRawChannel (hwid, *data)
400 coll.push_back (chan)
401
402 cont.addCollection (coll, ROOT.IdentifierHash(icoll))
403 ROOT.SetOwnership (coll, False)
404
405 return cont
406
407
408 def make_digits (self, incomplete, isCalib):
409 cont = ROOT.TileDigitsContainer()
410 hashFunc = cont.hashFunc()
411 hwidHelper = self.detStore['TileHWID']
412
413 emptyfrag = (3, 13) # ros, drawer
414 for frag in [(1, 3), emptyfrag]:
415 id = hwidHelper.frag (*frag)
416 coll = ROOT.TileDigitsCollection (id)
417
418 if frag == emptyfrag:
419 v = getattr(ROOT,'vector<unsigned>')()
420 v.resize(16)
421 v[3] = 0xffffffff
422 v[9] = 0xffffffff
423 v[12] = 0xffffffff
424 coll.setFragChipHeaderWords (v)
425
426
427 if frag == emptyfrag and incomplete:
428 ndig = 10
429 elif frag == emptyfrag and isCalib:
430 ndig = 96
431 else:
432 ndig = 48
433
434 digits = getattr(ROOT,'vector<float>')()
435 digits.resize (12)
436 for idig in range(ndig):
437 dig = ROOT.TileDigits(ROOT.HWIdentifier(), digits)
438 coll.push_back (dig)
439
440 cont.addCollection (coll, ROOT.IdentifierHash (hashFunc(id)))
441 ROOT.SetOwnership (coll, False)
442
443 return cont
444
445
446 def make_beamelem (self, frag):
447 cont = ROOT.TileBeamElemContainer()
448
449 coll = ROOT.TileBeamElemCollection (frag)
450 coll.setLvl1Type (123)
451
452 if frag == LASE_PTN_FRAG:
453 v = getattr(ROOT,'vector<unsigned>')()
454 v.resize(16)
455 v[0] = (23 << 8)
456 elem = ROOT.TileBeamElem (ROOT.HWIdentifier(), v)
457 coll.push_back (elem)
458
459 elif frag == DIGI_PAR_FRAG:
460 coll.setRODBCID (11)
461 hwidHelper = self.detStore['TileHWID']
462
463 def id (cha):
464 ros = 1
465 drawer = 1
466 adc = 0
467 return hwidHelper.adc_id (ros, drawer, cha, adc)
468
469 for cha in range(15):
470 hwid = id(cha)
471 elem = ROOT.TileBeamElem (hwid, cha + 100)
472 coll.push_back (elem)
473
474 hwid = id(15)
475 v = getattr(ROOT,'vector<unsigned>')()
476 v.resize(10)
477 for i in range(10):
478 v[i] = 111 + i
479 v[1] = 2
480 v[2] = 0x08070605
481 elem = ROOT.TileBeamElem (hwid, v)
482 coll.push_back (elem)
483
484 elif frag == LASER_OBJ_FRAG:
485 coll.setRODBCID (22)
486
487
488 cont.addCollection (coll, ROOT.IdentifierHash (frag))
489 ROOT.SetOwnership (coll, False)
490
491 return cont
492
493
494
495
496
498
499 acc = ComponentAccumulator()
500
501 from TileGeoModel.TileGMConfig import TileGMCfg
502 acc.merge(TileGMCfg(flags))
503
504 from RngComps.RngCompsConfig import AthRNGSvcCfg
505 acc.merge( AthRNGSvcCfg(flags) )
506
507 from TileConditions.TileBadChannelsConfig import TileBadChannelsCondAlgCfg
508 acc.merge( TileBadChannelsCondAlgCfg(flags) )
509
510 TileDQstatusTool = CompFactory.TileDQstatusTool
511 acc.addPublicTool( TileDQstatusTool('tool1') )
512 acc.addPublicTool( TileDQstatusTool('tool2', SimulateTrips=True) )
513
514 acc.addEventAlgo( TestAlg('test1') )
515
516 return acc
517
518
519if __name__ == "__main__":
520
521 from AthenaConfiguration.AllConfigFlags import initConfigFlags
522 from AthenaConfiguration.TestDefaults import defaultTestFiles
523 from AthenaCommon.Logging import log
524 from AthenaCommon.Constants import INFO
525
526 # Test setup
527 log.setLevel(INFO)
528
529 flags = initConfigFlags()
530 flags.Input.Files = defaultTestFiles.ESD
531 flags.Tile.RunType = TileRunType.PHY
532 flags.Exec.MaxEvents = 1
533 flags.fillFromArgs()
534
535 flags.lock()
536
537 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
538 cfg = MainServicesCfg(flags)
539
540 # Configure reading POOL files
541 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
542 cfg.merge(PoolReadCfg(flags))
543
544 cfg.merge( TileDQstatusToolTestCfg(flags) )
545
546 flags.dump()
547 cfg.printConfig(withDetails=True)
548 cfg.store( open('TileDQstatusToolTest.pkl', 'wb') )
549
550 sc = cfg.run()
551
552 # Success should be 0
553 sys.exit(not sc.isSuccess())
do_test(self, rctype, flag_exc, rc_baddq={}, isCalib=False, incomplete=False, beamfrag=LASE_PTN_FRAG, tool=None)
check_flag(dq, mname, exp, exc, *args)
void initialize()