ATLAS Offline Software
TileDQstatusAlgTestConfig.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/python/TileDQstatusAlgTestConfig.py
5 # Author: sss
6 # Date: Sep, 2018
7 # Brief: Test for TileDQstatusAlg.
8 #
9 
10 
11 import ROOT
12 ROOT.TH1F
13 
14 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
15 from TileConfiguration.TileConfigFlags import TileRunType
16 from 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 
38 BEAM_TDC_FRAG = 0x000
39 BEAM_ADC_FRAG = 0x001
40 MUON_ADC_FRAG = 0x002
41 ADDR_ADC_FRAG = 0x003
42 LASE_PTN_FRAG = 0x004
43 LASE_ADC_FRAG = 0x005
44 ADD_FADC_FRAG = 0x006
45 ECAL_ADC_FRAG = 0x007
46 DIGI_PAR_FRAG = 0x0ff
47 LASER_OBJ_FRAG = 0x016
48 
49 
50 hits_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.
113 class 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,
145  self.digits_incomplete,
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 
180  cont.addCollection (coll, ROOT.IdentifierHash(icoll))
181  ROOT.SetOwnership (coll, False)
182 
183  return self.evtStore.record (cont, key, False)
184 
185 
186  def record_digits (self, key, incomplete, isCalib):
187  cont = ROOT.TileDigitsContainer()
188  hashFunc = cont.hashFunc()
189  hwidHelper = self.detStore['TileHWID']
190 
191  emptyfrag = (3, 13) # ros, drawer
192  for frag in [(1, 3), emptyfrag]:
193  id = hwidHelper.frag (*frag)
194  coll = ROOT.TileDigitsCollection (id)
195 
196  if frag == emptyfrag:
197  v = getattr(ROOT,'vector<unsigned>')()
198  v.resize(16)
199  v[3] = 0xffffffff
200  v[9] = 0xffffffff
201  v[12] = 0xffffffff
202  coll.setFragChipHeaderWords (v)
203 
204 
205  if frag == emptyfrag and incomplete:
206  ndig = 10
207  elif frag == emptyfrag and isCalib:
208  ndig = 96
209  else:
210  ndig = 48
211 
212  digits = getattr(ROOT,'vector<float>')()
213  digits.resize (12)
214  for idig in range(ndig):
215  dig = ROOT.TileDigits(ROOT.HWIdentifier(), digits)
216  coll.push_back (dig)
217 
218  cont.addCollection (coll, ROOT.IdentifierHash (hashFunc(id)))
219  ROOT.SetOwnership (coll, False)
220  return self.evtStore.record (cont, key, False)
221 
222 
223  def record_beamelem (self, key, frag):
224  cont = ROOT.TileBeamElemContainer()
225 
226  coll = ROOT.TileBeamElemCollection (frag)
227  coll.setLvl1Type (123)
228 
229  if frag == LASE_PTN_FRAG:
230  v = getattr(ROOT,'vector<unsigned>')()
231  v.resize(16)
232  v[0] = (23 << 8)
233  elem = ROOT.TileBeamElem (ROOT.Identifier(), v)
234  coll.push_back (elem)
235 
236  elif frag == DIGI_PAR_FRAG:
237  coll.setRODBCID (11)
238  hwidHelper = self.detStore['TileHWID']
239 
240  def id (cha):
241  ros = 1
242  drawer = 1
243  adc = 0
244  return hwidHelper.adc_id (ros, drawer, cha, adc)
245 
246  for cha in range(15):
247  hwid = id(cha)
248  elem = ROOT.TileBeamElem (hwid, cha + 100)
249  coll.push_back (elem)
250 
251  hwid = id(15)
252  v = getattr(ROOT,'vector<unsigned>')()
253  v.resize(10)
254  for i in range(10):
255  v[i] = 111 + i
256  v[1] = 2
257  v[2] = 0x08070605
258  elem = ROOT.TileBeamElem (hwid, v)
259  coll.push_back (elem)
260 
261  elif frag == LASER_OBJ_FRAG:
262  coll.setRODBCID (11)
263 
264 
265  cont.addCollection (coll, ROOT.IdentifierHash (frag))
266  ROOT.SetOwnership (coll, False)
267 
268  return self.evtStore.record (cont, key, False)
269 
270 
271 
272 
273 
274 # Check results.
275 class CheckAlg (Alg):
276  def __init__ (self, name, dq_key):
277  Alg.__init__ (self, name)
278  self.dq_key = dq_key
279  return
280 
281 
282  def initialize (self):
283  return StatusCode.Success
284 
285 
286  def execute (self):
287  dq = self.evtStore[self.dq_key]
288 
289  assert dq.isFilled() is True
290  assert dq.isBiGain() is False
291  assert dq.nonZeroCounter() is True
292  assert dq.incompleteDigits() is False
293  assert dq.calibMode() == 0
294  assert dq.trigType() == 0
295 
296  self.check_empty (dq)
297 
298  return StatusCode.Success
299 
300 
301  def check_empty (self, dq):
302  for part in range(5):
303  for drawer in range(64):
304  for dmu in range (16):
305  is_empty = (part==3 and drawer==13 and
306  dmu in [3, 9, 12])
307  assert dq.checkEmptyEvent(part, drawer, dmu) == is_empty
308  return
309 
310 
311 
312 
314 
315  acc = ComponentAccumulator()
316 
317  acc.addEventAlgo( RecordAlg('record1', 'RC1', 'Dig1') )
318 
319  from TileRecUtils.TileDQstatusConfig import TileDQstatusAlgCfg
320  acc.merge(TileDQstatusAlgCfg(flags, name='alg1',
321  TileRawChannelContainer='RC1',
322  TileDigitsContainer='Dig1',
323  TileDQstatus='DQ1'))
324 
325  acc.addEventAlgo( CheckAlg('check1', 'DQ1') )
326 
327  return acc
328 
329 
330 if __name__ == "__main__":
331 
332  from AthenaConfiguration.AllConfigFlags import initConfigFlags
333  from AthenaConfiguration.TestDefaults import defaultTestFiles
334  from AthenaCommon.Logging import log
335  from AthenaCommon.Constants import INFO
336 
337  # Test setup
338  log.setLevel(INFO)
339 
340  flags = initConfigFlags()
341  flags.Input.Files = defaultTestFiles.ESD
342  flags.Tile.RunType = TileRunType.PHY
343  flags.Exec.MaxEvents = 2
344  flags.fillFromArgs()
345 
346  flags.lock()
347 
348  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
349  cfg = MainServicesCfg(flags)
350 
351  # Configure reading POOL files
352  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
353  cfg.merge(PoolReadCfg(flags))
354 
355  cfg.merge( TileDQstatusAlgTestCfg(flags) )
356 
357  flags.dump()
358  cfg.printConfig(withDetails=True)
359  cfg.store( open('TileDQstatusTest.pkl', 'wb') )
360 
361  sc = cfg.run()
362 
363  import sys
364  # Success should be 0
365  sys.exit(not sc.isSuccess())
TileDQstatusAlgTestConfig.CheckAlg.__init__
def __init__(self, name, dq_key)
Definition: TileDQstatusAlgTestConfig.py:276
TileDQstatusAlgTestConfig.TileDQstatusAlgTestCfg
def TileDQstatusAlgTestCfg(flags)
Definition: TileDQstatusAlgTestConfig.py:313
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
TileDQstatusAlgTestConfig.RecordAlg.rc_key
rc_key
Definition: TileDQstatusAlgTestConfig.py:116
TileDQstatusAlgTestConfig.CheckAlg.initialize
def initialize(self)
Definition: TileDQstatusAlgTestConfig.py:282
TileDQstatusAlgTestConfig.RecordAlg.record_raw_data
def record_raw_data(self, key, hits, typ, baddq)
Definition: TileDQstatusAlgTestConfig.py:155
TileDQstatusAlgTestConfig.RecordAlg
Definition: TileDQstatusAlgTestConfig.py:113
TileDQstatusAlgTestConfig.RecordAlg.rc_baddq
rc_baddq
Definition: TileDQstatusAlgTestConfig.py:120
TileDQstatusAlgTestConfig.RecordAlg.rc_typ
rc_typ
Definition: TileDQstatusAlgTestConfig.py:118
TileDQstatusConfig.TileDQstatusAlgCfg
def TileDQstatusAlgCfg(flags, **kwargs)
Definition: TileDQstatusConfig.py:31
TileDQstatusAlgTestConfig.RecordAlg.record_digits
def record_digits(self, key, incomplete, isCalib)
Definition: TileDQstatusAlgTestConfig.py:186
TileDQstatusAlgTestConfig.RecordAlg.digits_isCalib
digits_isCalib
Definition: TileDQstatusAlgTestConfig.py:125
TileDQstatusAlgTestConfig.RecordAlg.be_frag
be_frag
Definition: TileDQstatusAlgTestConfig.py:128
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
Constants
some useful constants -------------------------------------------------—
TileDQstatusAlgTestConfig.CheckAlg.dq_key
dq_key
Definition: TileDQstatusAlgTestConfig.py:278
TileDQstatusAlgTestConfig.RecordAlg.digits_key
digits_key
Definition: TileDQstatusAlgTestConfig.py:123
TileDQstatusAlgTestConfig.RecordAlg.__init__
def __init__(self, name, rc_key, digits_key, be_key='')
Definition: TileDQstatusAlgTestConfig.py:114
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
TileDQstatusAlgTestConfig.CheckAlg
Definition: TileDQstatusAlgTestConfig.py:275
Trk::open
@ open
Definition: BinningType.h:40
TileDQstatusAlgTestConfig.RecordAlg.record_beamelem
def record_beamelem(self, key, frag)
Definition: TileDQstatusAlgTestConfig.py:223
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
TileDQstatusAlgTestConfig.CheckAlg.execute
def execute(self)
Definition: TileDQstatusAlgTestConfig.py:286
TileDQstatusAlgTestConfig.RecordAlg.rc_hits
rc_hits
Definition: TileDQstatusAlgTestConfig.py:117
TileDQstatusAlgTestConfig.RecordAlg.digits_incomplete
digits_incomplete
Definition: TileDQstatusAlgTestConfig.py:124
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
TileDQstatusAlgTestConfig.RecordAlg.execute
def execute(self)
Definition: TileDQstatusAlgTestConfig.py:137
TileDQstatusAlgTestConfig.TileFragHash
Definition: TileDQstatusAlgTestConfig.py:23
TileDQstatusAlgTestConfig.RecordAlg.be_key
be_key
Definition: TileDQstatusAlgTestConfig.py:127
TileDQstatusAlgTestConfig.RecordAlg.initialize
def initialize(self)
Definition: TileDQstatusAlgTestConfig.py:133
TileDQstatusAlgTestConfig.CheckAlg.check_empty
def check_empty(self, dq)
Definition: TileDQstatusAlgTestConfig.py:301