ATLAS Offline Software
Loading...
Searching...
No Matches
TileDQstatusAlgTestConfig.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/TileDQstatusAlgTestConfig.py
5# Author: sss
6# Date: Sep, 2018
7# Brief: Test for TileDQstatusAlg.
8#
9
10
11import ROOT
12ROOT.TH1F
13
14from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
15from TileConfiguration.TileConfigFlags import TileRunType
16from AthenaPython.PyAthenaComps import Alg, StatusCode
17
18
19
20
21
22# TileFragHash::TYPE
24 Beam = 255
25 Default = 0
26 Digitizer = 0
27 OptFilterDsp = 1
28 OptFilterOffline = 2
29 OptFilterDspCompressed = 3
30 ManyAmps = 4
31 MF = 5
32 FitFilter = 6
33 FitFilterCool = 7
34 FlatFilter = 8
35 WienerFilterOffline = 9
36
37
38BEAM_TDC_FRAG = 0x000
39BEAM_ADC_FRAG = 0x001
40MUON_ADC_FRAG = 0x002
41ADDR_ADC_FRAG = 0x003
42LASE_PTN_FRAG = 0x004
43LASE_ADC_FRAG = 0x005
44ADD_FADC_FRAG = 0x006
45ECAL_ADC_FRAG = 0x007
46DIGI_PAR_FRAG = 0x0ff
47LASER_OBJ_FRAG = 0x016
48
49
50hits_0 = [
51 # (sec, side, mod, tow, samp, pmt, adc), [adc, time, qual, ped]
52 [0, [
53 [(1, 1, 0, 1, 1, 0, 1), [ 0.2, 22.1, 2.4, 42.9]],
54 [(1, 1, 0, 1, 1, 1, 1), [-0.4, 75.0, 2.7, 31.4]],
55 [(1, 1, 0, 1, 0, 0, 1), [-0.9, -13.3, 1.5, 37.4]],
56 [(1, 1, 0, 2, 0, 1, 1), [41.8, 0.1, 2.5, 45.7]],
57 [(1, 1, 0, 2, 0, 0, 1), [30.6, -0.4, 2.0, 33.1]],
58 [(1, 1, 0, 2, 1, 1, 1), [ 1.4, 12.9, 4.7, 43.1]],
59 [(1, 1, 0, 2, 1, 0, 1), [ 3.4, 3.5, 1.9, 54.2]],
60 ]],
61
62 [136, [
63 [(3, 1, 8, 13, 3, 0, 1), [26.9, 4.8, 5.2, 45.4]],
64 ]],
65
66 [146, [
67 [(3, 1, 18, 13, 3, 0, 1), [ 4.4, -26.5, 23.9, 51.2]],
68 [(3, 1, 18, 15, 3, 0, 1), [-0.1, -75.0, 3.7, 51.0]],
69 [(3, 1, 18, 8, 2, 0, 1), [-0.1, 75.0, 4.2, 41.7]],
70 [(3, 1, 18, 8, 2, 1, 1), [ 3.5, -11.9, 2.6, 44.7]],
71 [(3, 1, 18, 9, 1, 0, 1), [ 0.8, -17.6, 1.8, 49.2]],
72 [(3, 1, 18, 9, 1, 1, 1), [ 0.1, -75.0, 3.4, 48.4]],
73 [(2, 1, 18, 11, 0, 0, 1), [ 8.7, 0.4, 2.7, 50.2]],
74 [(2, 1, 18, 11, 0, 1, 1), [ 6.3, 1.9, 1.6, 48.6]],
75 [(2, 1, 18, 10, 1, 0, 1), [53.3, 1.3, 3.8, 38.4]],
76 [(2, 1, 18, 10, 1, 1, 1), [64.1, 1.0, 3.5, 36.9]],
77 [(2, 1, 18, 12, 0, 0, 1), [-0.2, -75.0, 2.8, 38.1]],
78 [(2, 1, 18, 12, 0, 1, 1), [ 0.5, -32.7, 1.9, 40.3]],
79 [(3, 1, 18, 10, 3, 0, 1), [ 5.4, 7.7, 8.2, 57.0]],
80 [(3, 1, 18, 11, 3, 0, 1), [48.9, 0.4, 4.0, 32.3]],
81 [(2, 1, 18, 11, 1, 0, 1), [38.5, 0.5, 1.7, 46.8]],
82 [(2, 1, 18, 11, 1, 1, 1), [48.1, 0.3, 1.6, 46.3]],
83 [(2, 1, 18, 10, 2, 0, 1), [ 0.3, 75.0, 2.0, 34.9]],
84 [(2, 1, 18, 10, 2, 1, 1), [0.1, -75.0, 3.7, 54.7]],
85 ]],
86
87 # Some MBTS cells.
88 [135, [ [(4, 1, 0, 1, 0, 0, 0), [ 59.1, 2.8, 6.9, 56.2]] ]],
89 [181, [ [(4, 1, 6, 1, 0, 0, 0), [ 56.4, 1.2, 2.9, 39.9]] ]],
90 [182, [ [(4, 1, 6, 0, 0, 0, 0), [ 44.9, 0.5, 1.4, 42.1]] ]],
91 [231, [ [(4, -1, 3, 0, 0, 0, 0), [107.9, 1.7, 7.8, 47.8]] ]],
92
93 # Some E4 cells.
94 [220, [ [(4, -1, 0, 2, 0, 0, 0), [ 2.3, 3.2, 2.5, 44.4]] ]],
95 [223, [ [(4, -1, 1, 2, 0, 0, 0), [ 3.1, -5.3, 2.4, 44.4]] ]],
96 [225, [ [(4, -1, 2, 2, 0, 0, 0), [ -0.4, 27.6, 1.3, 32.5]] ]],
97 [228, [ [(4, -1, 3, 2, 0, 0, 0), [ 0.2, -75.0, 2.4, 35.4]] ]],
98
99 # Some disconnected cells.
100 [253, [
101 [4706026383833300992, [ 0, 0, 0, 50000]],
102 [4706027483344928768, [ 0, 0, 0, 50000]] ], ],
103 [255, [
104 [4706157225717006336, [ 0, 0, 0, 80000]],
105 [4706158325228634112, [ 0, 0, 0, 80000]] ], ],
106]
107
108
109
110
111
112# Record test data to SG.
113class RecordAlg (Alg):
114 def __init__ (self, name,
115 rc_key, digits_key, be_key=''):
116 Alg.__init__ (self, name)
117 self.rc_key = rc_key
118 self.rc_hits = hits_0
119 self.rc_typ = TileFragHash.OptFilterOffline
120 #self.rc_typ = TileFragHash.OptFilterDsp
121 self.rc_baddq = {}
122 #self.rc_baddq = {146 : [2, 10]}
123
124 self.digits_key = digits_key
125 self.digits_incomplete = False
126 self.digits_isCalib = False
127
128 self.be_key = be_key
129 self.be_frag = LASE_PTN_FRAG
130 return
131
132
133 def initialize (self):
134 return StatusCode.Success
135
136
137 def execute (self):
138 if not self.record_raw_data (self.rc_key,
139 self.rc_hits,
140 self.rc_typ,
141 self.rc_baddq):
142 return StatusCode.Failure
143
144 if not self.record_digits (self.digits_key,
146 self.digits_isCalib):
147 return StatusCode.Failure
148
149 if self.be_key != '':
150 if not self.record_beamelem (self.be_key, self.be_frag):
151 return StatusCode.Failure
152 return StatusCode.Success
153
154
155 def record_raw_data (self, key, hits, typ, baddq):
156 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
157
158 unit = 0 # TileRawChannelUnit::ADCcounts
159 cont = ROOT.TileRawChannelContainer (False, typ, unit)
160 cont.set_bsflags (0x32002000)
161 hashFunc = cont.hashFunc()
162
163 for icoll, colldata in hits:
164 coll = ROOT.TileRawChannelCollection (hashFunc.identifier(icoll))
165
166 mask = 0
167 for chan in baddq.get (icoll, []):
168 mask |= (1<<(chan/3))
169 coll.setFragMemoryPar(mask)
170
171 for addr, data in colldata:
172 if isinstance(addr, tuple):
173 adc_id = idHelper.adc_id (*addr)
174 chan = ROOT.TileRawChannel (adc_id, *data)
175 else:
176 hwid = ROOT.HWIdentifier (addr)
177 chan = ROOT.TileRawChannel (hwid, *data)
178 coll.push_back (chan)
179 ROOT.SetOwnership (chan, False)
180
181 cont.addCollection (coll, ROOT.IdentifierHash(icoll))
182 ROOT.SetOwnership (coll, False)
183
184 return self.evtStore.record (cont, key, False)
185
186
187 def record_digits (self, key, incomplete, isCalib):
188 cont = ROOT.TileDigitsContainer()
189 hashFunc = cont.hashFunc()
190 hwidHelper = self.detStore['TileHWID']
191
192 emptyfrag = (3, 13) # ros, drawer
193 for frag in [(1, 3), emptyfrag]:
194 id = hwidHelper.frag (*frag)
195 coll = ROOT.TileDigitsCollection (id)
196
197 if frag == emptyfrag:
198 v = getattr(ROOT,'vector<unsigned>')()
199 v.resize(16)
200 v[3] = 0xffffffff
201 v[9] = 0xffffffff
202 v[12] = 0xffffffff
203 coll.setFragChipHeaderWords (v)
204
205
206 if frag == emptyfrag and incomplete:
207 ndig = 10
208 elif frag == emptyfrag and isCalib:
209 ndig = 96
210 else:
211 ndig = 48
212
213 digits = getattr(ROOT,'vector<float>')()
214 digits.resize (12)
215 for idig in range(ndig):
216 dig = ROOT.TileDigits(ROOT.HWIdentifier(), digits)
217 coll.push_back (dig)
218 ROOT.SetOwnership (dig, False)
219
220 cont.addCollection (coll, ROOT.IdentifierHash (hashFunc(id)))
221 ROOT.SetOwnership (coll, False)
222 return self.evtStore.record (cont, key, False)
223
224
225 def record_beamelem (self, key, frag):
226 cont = ROOT.TileBeamElemContainer()
227
228 coll = ROOT.TileBeamElemCollection (frag)
229 coll.setLvl1Type (123)
230
231 if frag == LASE_PTN_FRAG:
232 v = getattr(ROOT,'vector<unsigned>')()
233 v.resize(16)
234 v[0] = (23 << 8)
235 elem = ROOT.TileBeamElem (ROOT.Identifier(), v)
236 coll.push_back (elem)
237 ROOT.SetOwnership (elem, False)
238
239 elif frag == DIGI_PAR_FRAG:
240 coll.setRODBCID (11)
241 hwidHelper = self.detStore['TileHWID']
242
243 def id (cha):
244 ros = 1
245 drawer = 1
246 adc = 0
247 return hwidHelper.adc_id (ros, drawer, cha, adc)
248
249 for cha in range(15):
250 hwid = id(cha)
251 elem = ROOT.TileBeamElem (hwid, cha + 100)
252 coll.push_back (elem)
253 ROOT.SetOwnership (elem, False)
254
255 hwid = id(15)
256 v = getattr(ROOT,'vector<unsigned>')()
257 v.resize(10)
258 for i in range(10):
259 v[i] = 111 + i
260 v[1] = 2
261 v[2] = 0x08070605
262 elem = ROOT.TileBeamElem (hwid, v)
263 coll.push_back (elem)
264 ROOT.SetOwnership (elem, False)
265
266 elif frag == LASER_OBJ_FRAG:
267 coll.setRODBCID (11)
268
269
270 cont.addCollection (coll, ROOT.IdentifierHash (frag))
271 ROOT.SetOwnership (coll, False)
272
273 return self.evtStore.record (cont, key, False)
274
275
276
277
278
279# Check results.
280class CheckAlg (Alg):
281 def __init__ (self, name, dq_key):
282 Alg.__init__ (self, name)
283 self.dq_key = dq_key
284 return
285
286
287 def initialize (self):
288 return StatusCode.Success
289
290
291 def execute (self):
292 dq = self.evtStore[self.dq_key]
293
294 assert dq.isFilled() is True
295 assert dq.isBiGain() is False
296 assert dq.nonZeroCounter() is True
297 assert dq.incompleteDigits() is False
298 assert dq.calibMode() == 0
299 assert dq.trigType() == 0
300
301 self.check_empty (dq)
302
303 return StatusCode.Success
304
305
306 def check_empty (self, dq):
307 for part in range(5):
308 for drawer in range(64):
309 for dmu in range (16):
310 is_empty = (part==3 and drawer==13 and
311 dmu in [3, 9, 12])
312 assert dq.checkEmptyEvent(part, drawer, dmu) == is_empty
313 return
314
315
316
317
319
320 acc = ComponentAccumulator()
321
322 acc.addEventAlgo( RecordAlg('record1', 'RC1', 'Dig1') )
323
324 from TileRecUtils.TileDQstatusConfig import TileDQstatusAlgCfg
325 acc.merge(TileDQstatusAlgCfg(flags, name='alg1',
326 TileRawChannelContainer='RC1',
327 TileDigitsContainer='Dig1',
328 TileDQstatus='DQ1'))
329
330 acc.addEventAlgo( CheckAlg('check1', 'DQ1') )
331
332 return acc
333
334
335if __name__ == "__main__":
336
337 from AthenaConfiguration.AllConfigFlags import initConfigFlags
338 from AthenaConfiguration.TestDefaults import defaultTestFiles
339 from AthenaCommon.Logging import log
340 from AthenaCommon.Constants import INFO
341
342 # Test setup
343 log.setLevel(INFO)
344
345 flags = initConfigFlags()
346 flags.Input.Files = defaultTestFiles.ESD
347 flags.Tile.RunType = TileRunType.PHY
348 flags.Exec.MaxEvents = 2
349 flags.fillFromArgs()
350
351 flags.lock()
352
353 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
354 cfg = MainServicesCfg(flags)
355
356 # Configure reading POOL files
357 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
358 cfg.merge(PoolReadCfg(flags))
359
360 cfg.merge( TileDQstatusAlgTestCfg(flags) )
361
362 flags.dump()
363 cfg.printConfig(withDetails=True)
364 cfg.store( open('TileDQstatusTest.pkl', 'wb') )
365
366 sc = cfg.run()
367
368 import sys
369 # Success should be 0
370 sys.exit(not sc.isSuccess())
__init__(self, name, rc_key, digits_key, be_key='')
record_digits(self, key, incomplete, isCalib)
void initialize()