ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellBuilderFromHitTestConfig.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/TileCellBuilderFromHitTestConfig.py
5# Author: scott snyder
6# Date: Nov, 2018
7# Brief: Test for TileCellBuilderFromHit.
8#
9
10
11import ROOT
12ROOT.TH1F
13
14from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
15from AthenaConfiguration.ComponentFactory import CompFactory
16from TileConfiguration.TileConfigFlags import TileRunType
17
18hits_0 = [
19 # (sec, side, mod, tow, samp, pmt, adc), [energy, time]
20 [0, [
21 [(1, 1, 0, 1, 1, 0, 1), [ 0.2, 22.1]],
22 [(1, 1, 0, 1, 1, 1, 1), [-0.4, 75.0]],
23 [(1, 1, 0, 1, 0, 0, 1), [-0.9, -13.3]],
24 [(1, 1, 0, 2, 0, 1, 1), [41.8, 0.1]],
25 [(1, 1, 0, 2, 0, 0, 1), [30.6, -0.4]],
26 [(1, 1, 0, 2, 1, 1, 1), [ 1.4, 12.9]],
27 [(1, 1, 0, 2, 1, 0, 1), [ 3.4, 3.5]],
28 ]],
29
30 [136, [
31 [(3, 1, 8, 13, 3, 0, 1), [26.9, 4.8]],
32 ]],
33
34 [146, [
35 [(3, 1, 18, 13, 3, 0, 1), [ 4.4, -26.5]],
36 [(3, 1, 18, 15, 3, 0, 1), [-0.1, -75.0]],
37 [(3, 1, 18, 8, 2, 0, 1), [-0.1, 75.0]],
38 [(3, 1, 18, 8, 2, 1, 1), [ 3.5, -11.9]],
39 [(3, 1, 18, 9, 1, 0, 1), [ 0.8, -17.6]],
40 [(3, 1, 18, 9, 1, 1, 1), [ 0.1, -75.0]],
41 [(2, 1, 18, 11, 0, 0, 1), [ 8.7, 0.4]],
42 [(2, 1, 18, 11, 0, 1, 1), [ 6.3, 1.9]],
43 [(2, 1, 18, 10, 1, 0, 1), [53.3, 1.3]],
44 [(2, 1, 18, 10, 1, 1, 1), [64.1, 1.0]],
45 [(2, 1, 18, 12, 0, 0, 1), [-0.2, -75.0]],
46 [(2, 1, 18, 12, 0, 1, 1), [ 0.5, -32.7]],
47 [(3, 1, 18, 10, 3, 0, 1), [ 5.4, 7.7]],
48 [(3, 1, 18, 11, 3, 0, 1), [48.9, 0.4]],
49 [(2, 1, 18, 11, 1, 0, 1), [38.5, 0.5]],
50 [(2, 1, 18, 11, 1, 1, 1), [48.1, 0.3]],
51 [(2, 1, 18, 10, 2, 0, 1), [ 0.3, 75.0]],
52 [(2, 1, 18, 10, 2, 1, 1), [0.1, -75.0]],
53 ]],
54
55 # Some MBTS cells.
56 [135, [ [(4, 1, 0, 1, 0, 0, 0), [ 59.1, 2.8]] ]],
57 [181, [ [(4, 1, 6, 1, 0, 0, 0), [ 56.4, 1.2]] ]],
58 [182, [ [(4, 1, 6, 0, 0, 0, 0), [ 44.9, 0.5]] ]],
59 [231, [ [(4, -1, 3, 0, 0, 0, 0), [107.9, 1.7]] ]],
60
61 # Some E4 cells.
62 [220, [ [(4, -1, 0, 2, 0, 0, 0), [ 2.3, 3.2]] ]],
63 [223, [ [(4, -1, 1, 2, 0, 0, 0), [ 3.1, -5.3]] ]],
64 [225, [ [(4, -1, 2, 2, 0, 0, 0), [ -0.4, 3.6]] ]],
65 [228, [ [(4, -1, 3, 2, 0, 0, 0), [ 0.2, -3.0]] ]],
66
67
74]
75
76
77exp_cells_0 = {
78 (1, 1, 0, 1, 0) : [ -30.6, 0.0, -13.3, -13.3, 0, 0, 128, 0, 1, -1],
79 (1, 1, 0, 1, 1) : [ 6.8, 0.0, 22.1, 0.0, 0, 0, 128, 0, 1, 1],
80 (1, 1, 0, 2, 0) : [1040.4, 1421.2, -0.4, 0.1, 0, 0, 160, 160, 1, 1],
81 (1, 1, 0, 2, 1) : [ 115.6, 47.6, 3.5, 12.9, 0, 0, 160, 160, 1, 1],
82
83 (2, 1, 18, 10, 1):[1812.2, 2179.4, 1.3, 1.0, 0, 0, 160, 160, 1, 1],
84 (2, 1, 18, 10, 2):[ 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 1, 1],
85 (2, 1, 18, 11, 0):[ 295.8, 214.2, 0.4, 1.9, 0, 0, 160, 160, 1, 1],
86 (2, 1, 18, 11, 1):[1309.0, 1635.4, 0.5, 0.3, 0, 0, 160, 160, 1, 1],
87 (2, 1, 18, 12, 0):[ 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 1, 1],
88 (3, 1, 18, 8, 2):[ 0.0, 119.0, 0.0, -11.9, 0, 0, 0, 160, 1, 1],
89 (3, 1, 18, 9, 1):[ 27.2, 0.0, -17.6, 0.0, 0, 0, 128, 0, 1, 1],
90 (3, 1, 18, 10, 3):[ 675.0, 0.0, 7.7, 7.7, 0, 0, 160, 0, 1, -1],
91 (3, 1, 18, 11, 3):[5232.3, 0.0, 0.4, 0.4, 0, 0, 160, 0, 1, -1],
92 (3, 1, 18, 13, 3):[ 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 1, -1],
93 (3, 1, 18, 15, 3):[ 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 1, -1],
94
95 # coll 136
96 (3, 1, 8, 13, 3) :[2609.3, 0.0, 4.8, 4.8, 0, 0, 160, 0, 1, -1],
97}
98
99
100exp_mbts_0 = {
101 (4, 1, 0, 1, 0) : [0.0931, 0.0, 2.8, 2.8, 0, 0, 160, 0, 1, -1],
102 (4, 1, 6, 1, 0) : [0.0888, 0.0, 1.2, 1.2, 0, 0, 160, 0, 1, -1],
103 (4, 1, 6, 0, 0) : [0.0566, 0.0, 0.5, 0.5, 0, 0, 160, 0, 1, -1],
104 (4, -1, 3, 0, 0) : [0.1360, 0.0, 1.7, 1.7, 0, 0, 160, 0, 1, -1],
105}
106
107
108exp_e4_0 = {
109 (4, -1, 0, 2, 0) : [172.5, 0.0, 3.2, 3.2, 0, 0, 160, 0, 1, -1],
110 (4, -1, 1, 2, 0) : [232.5, 0.0, -5.3, -5.3, 0, 0, 160, 0, 1, -1],
111 (4, -1, 2, 2, 0) : [-30.0, 0.0, 3.6, 3.6, 0, 0, 128, 0, 1, -1],
112 (4, -1, 3, 2, 0) : [ 15.0, 0.0, -3.0, -3.0, 0, 0, 128, 0, 1, -1],
113}
114
115
116def exp_merge (base, d):
117 new = base.copy()
118 new.update (d)
119 return new
120
121
122# TileBadChan errors.
123exp_cells_1 = exp_merge (exp_cells_0, {
124 (1, 1, 0, 1, 0) : [-30.6, -30.6, -13.3, -13.3, 0, 0, 128, 136, 1, 1],
125 (2, 1, 18, 11, 0) : [295.8, 214.2, 1.9, 1.9, 0, 0, 32, 160, 1, 1],
126 (2, 1, 18, 12, 0) : [ 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 8, 1, 1],
127 (3, 1, 18, 8, 2) : [119.0, 119.0, -11.9, -11.9, 0, 0, 168, 160, 1, 1],
128})
129exp_mbts_1 = exp_merge (exp_mbts_0, {
130 (4, 1, 0, 1, 0) : [0.0, 0.0, -100.0, -100.0, 255, 0, 8, 8, 1, -1],
131 (4, 1, 6, 1, 0) : [0.0888, 0.0, 0.0, 0.0, 0, 0, 32, 0, 1, -1],
132})
133
134
135# TileFragHash::TYPE
137 Beam = 255
138 Default = 0
139 Digitizer = 0
140 OptFilterDsp = 1
141 OptFilterOffline = 2
142 OptFilterDspCompressed = 3
143 ManyAmps = 4
144 MF = 5
145 FitFilter = 6
146 FitFilterCool = 7
147 FlatFilter = 8
148
149
150from AthenaPython.PyAthenaComps import Alg, StatusCode
151
152
153
154
155
156class TestAlg (Alg):
157 def __init__ (self, name):
158 Alg.__init__ (self, name)
159 return
160
161 def initialize (self):
162 ROOT.ICaloCellMakerTool
163
164 def gettool (name):
165 tool = ROOT.ToolHandle(ROOT.ICaloCellMakerTool)('TileCellBuilderFromHit/' + name)
166 if not tool.retrieve():
167 assert 0
168 return tool
169
170 self.tool1 = gettool ('tool1')
171 self.tool2 = gettool ('tool2')
172 self.tool3 = gettool ('tool3')
173
174 return StatusCode.Success
175
176
177 def execute (self):
178 iev = self.getContext().evt()
179
180 rctype = TileFragHash.OptFilterOffline
181 bsflags = 0x32002000
182 hits = hits_0
183 exp_cells = exp_cells_0
184 exp_mbts = exp_mbts_0
185 noise_thresh = 0
186
187 if iev == 0:
188 tool = self.tool1
189
190 elif iev == 1:
191 tool = self.tool2
192 exp_cells = exp_cells_1
193 exp_mbts = exp_mbts_1
194
195 elif iev == 2:
196 tool = self.tool3
197 noise_thresh = 0.5
198
199 else:
200 assert 0
201
202 self.record_hits (hits, rctype, bsflags, 'TileHitCnt')
203
204 ccc = ROOT.CaloCellContainer(ROOT.SG.VIEW_ELEMENTS)
205 if not tool.process (ccc, self.getContext()):
206 return StatusCode.Failure
207
208 self.compare_cells (ccc, exp_cells, noise_thresh)
209 self.compare_cells (self.evtStore['MBTSContainer'], exp_mbts)
210 self.compare_cells (self.evtStore['E4prContainer'], exp_e4_0)
211
212 return StatusCode.Success
213
214
215 def record_hits (self, hits, typ, bsflags, key):
216 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
217
218 unit = 0 # TileRawChannelUnit::ADCcounts
219 cont = ROOT.TileHitContainer (False, typ, unit)
220 cont.set_bsflags (bsflags)
221 hashFunc = cont.hashFunc()
222
223 for icoll, colldata in hits:
224 coll = ROOT.TileHitCollection (hashFunc.identifier(icoll))
225
226 for addr, data in colldata:
227 adc_id = idHelper.adc_id (*addr)
228 hit = ROOT.TileHit (adc_id, *data)
229 coll.push_back (hit)
230 ROOT.SetOwnership (hit, False)
231
232 cont.addCollection (coll, ROOT.IdentifierHash(icoll))
233 ROOT.SetOwnership (coll, False)
234
235 self.evtStore.record (cont, key, False)
236 return
237
238
239 def compare_cells (self, ccc, exp_cells, noise_thresh=0):
240 exp_cells = exp_cells.copy()
241 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
242
243 for c in ccc:
244 lcell = [c.ene1(), c.ene2(), c.time1(), c.time2(),
245 c.qual1(), c.qual2(),
246 c.qbit1(), c.qbit2(),
247 c.gain1(), c.gain2()]
248
249 cid = c.ID()
250 addr = (idHelper.section(cid),
251 idHelper.side(cid),
252 idHelper.module(cid),
253 idHelper.tower(cid),
254 idHelper.sampling(cid))
255 l = exp_cells.get (addr)
256 if not l:
257 if abs(lcell[0]) > noise_thresh:
258 print ('xxx unexpected cell', addr, lcell, flush=True)
259 assert 0
260 continue
261
262 l = l[:]
263
264 thr = max (1e-3, noise_thresh)
265 if (abs (lcell[0] - l[0]) > thr or
266 abs (lcell[1] - l[1]) > thr or
267 abs (lcell[2] - l[2]) > thr or
268 abs (lcell[3] - l[3]) > thr or
269 abs (lcell[4] != l[4]) or
270 abs (lcell[5] != l[5]) or
271 abs (lcell[6] != l[6]) or
272 abs (lcell[7] != l[7]) or
273 abs (lcell[8] != l[8]) or
274 abs (lcell[9] != l[9])):
275 print ('xxx cell mismatch: ', addr, lcell, l, flush=True)
276 assert 0
277 del exp_cells[addr]
278
279 for extra in exp_cells:
280 print ('xxx unfound cell', extra, flush=True)
281 assert 0
282 return
283
284
285
286
287
288baddefs = {}
289BAD_LOW = [1<<1, 0, 0] # AdcDead
290BAD_HIGH = [ 0, 1<<1, 0] # AdcDead
291BAD_BOTH = [ 0, 0, 1<<1] # NoHV
292BADTIMING = [ 0, 0, 1<<9] # BadTiming
293
294def TileBadChannelsCfg(flags, badChannels, chans=[], lines=''):
295
296 """
297
298 chans: [(sec, side, mod, tow, samp, pmt), [DATA0, DATA1, DATA2]]
299 We'd like to specify cells using offline addressing, but the bad cell
300 file uses online addressing. We can convert, but that requires
301 idhelpers, etc, that aren't available until after initialization.
302 So we pass in both representations; in finalize(), we'll check
303 that they match and print out the correct bad cell lines
304 if they do not.
305
306 File data line format:
307 frag channel dummy adcStatus0 adcStatus1 chnStatus
308 chnStatus + adcStatusN are given to TileBchDecoder.
309 Offline problem masks:
310 chn adc
311 0 GeneralMaskChannel GeneralMaskAdc
312 1 NoPmt AdcDead
313 2 NoHV StuckBit
314 3 WrongHV DataCorruption
315 4 NoLaser VeryLargeHfNoise
316 5 BadLaser NoData
317 6 NoCesium WrongDspConfig
318 7 BadCesium LargeHfNoise
319 8 NoTiming CorrelatedNoise
320 9 BadTiming LargeLfNoise
321 10 TrigGeneralMask NoCis
322 11 TrigNoGain BadCis
323 12 TrigHalfGain SevereStuckBit
324 13 TrigNoisy SevereDataCorruption
325 14 Emergency IgnoredByDQV
326 15 HVReadoutPb
327 16 BrokenClearFibre
328 17 IgnoreCs
329 18 UnstableCs
330
331
332 Online problem masks:
333 chn adc
334 0 IgnoredInDsp OnlineGeneralMaskAdc
335 1 IgnoredInHlt
336 2 DisableForL1
337 3 TrigGeneralMask
338 4 TrigNoGain
339 5 TrigHalfGain
340 6 TrigNoisy
341 7 OnlineBadTiming
342 """
343
344 if not chans:
345 TileBchList = 'TileNoBad.oflBch'
346 else:
347 TileBchList = badChannels + '.bch'
348 f = open (TileBchList, 'w')
349 print ('OBJVERSION 0', file=f)
350 print ('0x000 0 0 0 0 0', file=f)
351 f.write (lines)
352 f.close()
353 baddefs[badChannels] = (chans, lines)
354
355
356 TileCondProxyFileBch = CompFactory.getComp("TileCondProxyFile<TileCalibDrawerBch>")
357 onlineBadChannelsProxy = TileCondProxyFileBch('TileCondProxyFile_OnlBch', Source=TileBchList)
358 offlineBadChannelsProxy = TileCondProxyFileBch('TileCondProxyFile_OflBch', Source='TileNoBad.oflBch')
359
360 TileBadChannelsCondAlg = CompFactory.TileBadChannelsCondAlg
361 badChannelsCondAlg = TileBadChannelsCondAlg(name=f'{badChannels}_CondAlg',
362 OnlBchProxy=onlineBadChannelsProxy,
363 OflBchProxy=offlineBadChannelsProxy,
364 TileBadChannels=badChannels)
365
366 acc = ComponentAccumulator()
367 acc.addCondAlgo(badChannelsCondAlg)
368
369 return acc
370
371
372badChannelsLines = """
3730x312 2 0 0 2 0
3740x312 4 0 2 0 0
3750x312 11 0 0 0 2
3760x312 6 0 0 0 512
3770x307 12 0 0 0 2
3780x335 12 0 0 0 512
379"""
380
381
382def maketool (name, badChannels, noise=0, **kw):
383 TileBadChanTool = CompFactory.TileBadChanTool
384 bct = TileBadChanTool(TileBadChannels=badChannels)
385
386 TileCellBuilderFromHit = CompFactory.TileCellBuilderFromHit
387 return TileCellBuilderFromHit(name,
388 TileBadChanTool=bct,
389 CaloNoise='',
390 TileHitContainer='TileHitCnt',
391 NoiseSigma=noise,
392 **kw)
393
394
396
397 acc = ComponentAccumulator()
398
399 from TileGeoModel.TileGMConfig import TileGMCfg
400 acc.merge( TileGMCfg(flags) )
401
402 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
403 acc.merge(LArGMCfg(flags))
404
405 from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg
406 acc.merge( TileCablingSvcCfg(flags) )
407
408 from TileConditions.TileInfoLoaderConfig import TileInfoLoaderCfg
409 acc.merge( TileInfoLoaderCfg(flags) )
410
411 from TileConditions.TileEMScaleConfig import TileEMScaleCondAlgCfg
412 acc.merge( TileEMScaleCondAlgCfg(flags) )
413
414 from RngComps.RngCompsConfig import AthRNGSvcCfg
415 acc.merge( AthRNGSvcCfg(flags) )
416
417 from TileConditions.TileSamplingFractionConfig import TileSamplingFractionCondAlgCfg
418 acc.merge( TileSamplingFractionCondAlgCfg(flags, Source='FILE') )
419 acc.getCondAlgo('TileSamplingFractionCondAlg').G4Version=-1
420
421 bc1 = 'tilecellbuilder_bc1'
422 acc.merge( TileBadChannelsCfg(flags, bc1) )
423
424 bc2 = 'tilecellbuilder_bc2'
425 acc.merge( TileBadChannelsCfg(flags, bc2,
426 [[(3, 1, 18, 8, 2, 0), BAD_HIGH],
427 [(2, 1, 18, 9, 1, 0), BAD_LOW],
428 [(2, 1, 18, 12, 0, 1), BAD_BOTH],
429 [(2, 1, 18, 11, 0, 0), BADTIMING],
430 [(4, 1, 0, 1, 0, 0), BAD_BOTH],
431 [(4, 1, 6, 1, 0, 0), BADTIMING],
432 ], badChannelsLines) )
433
434
435 acc.addPublicTool( maketool ('tool1', bc1) )
436 acc.addPublicTool( maketool ('tool2', bc2, maskBadChannels=True) )
437 acc.addPublicTool( maketool ('tool3', bc1, noise=0.1) )
438
439 acc.addEventAlgo( TestAlg('testalg1') )
440
441 return acc
442
443
444if __name__ == "__main__":
445
446 from AthenaConfiguration.AllConfigFlags import initConfigFlags
447 from AthenaConfiguration.TestDefaults import defaultConditionsTags, defaultTestFiles
448 from AthenaCommon.Logging import log
449 from AthenaCommon.Constants import INFO
450
451 # Test setup
452 log.setLevel(INFO)
453
454 flags = initConfigFlags()
455 flags.Input.Files = defaultTestFiles.HITS_RUN2
456 flags.Input.ConditionsRunNumber = 1
457 flags.Input.OverrideRunNumber = True
458 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN2_MC
459 flags.Tile.RunType = TileRunType.PHY
460 flags.Exec.MaxEvents = 3
461 flags.fillFromArgs()
462
463 flags.lock()
464
465 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
466 cfg = MainServicesCfg(flags)
467
468 # Configure reading POOL files
469 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
470 cfg.merge(PoolReadCfg(flags))
471
472 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
473 cfg.merge (EventInfoCnvAlgCfg (flags, disableBeamSpot = True))
474
475 cfg.merge( TileRawChannelBuilderFromHitTestCfg(flags) )
476
477 flags.dump()
478 cfg.printConfig(withDetails=True)
479 cfg.store( open('TileCellBuilderFromHitTest.pkl', 'wb') )
480
481 sc = cfg.run()
482
483 import sys
484 # Success should be 0
485 sys.exit(not sc.isSuccess())
The tool to get Tile channel and ADC status.
Condition algorithm to prepare TileBadChannels and put it into condition store.
compare_cells(self, ccc, exp_cells, noise_thresh=0)
This class creates Cells from RawChannels and stores them in a container.
TileBadChannelsCfg(flags, badChannels, chans=[], lines='')
void initialize()