ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellBuilderFromHitTestConfig.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/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()
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
231 cont.addCollection (coll, ROOT.IdentifierHash(icoll))
232 ROOT.SetOwnership (coll, False)
233
234 self.evtStore.record (cont, key, False)
235 return
236
237
238 def compare_cells (self, ccc, exp_cells, noise_thresh=0):
239 exp_cells = exp_cells.copy()
240 idHelper = self.detStore['CaloCell_ID'].tile_idHelper()
241
242 for c in ccc:
243 lcell = [c.ene1(), c.ene2(), c.time1(), c.time2(),
244 c.qual1(), c.qual2(),
245 c.qbit1(), c.qbit2(),
246 c.gain1(), c.gain2()]
247
248 cid = c.ID()
249 addr = (idHelper.section(cid),
250 idHelper.side(cid),
251 idHelper.module(cid),
252 idHelper.tower(cid),
253 idHelper.sampling(cid))
254 l = exp_cells.get (addr)
255 if not l:
256 if abs(lcell[0]) > noise_thresh:
257 print ('xxx unexpected cell', addr, lcell, flush=True)
258 assert 0
259 continue
260
261 l = l[:]
262
263 thr = max (1e-3, noise_thresh)
264 if (abs (lcell[0] - l[0]) > thr or
265 abs (lcell[1] - l[1]) > thr or
266 abs (lcell[2] - l[2]) > thr or
267 abs (lcell[3] - l[3]) > thr or
268 abs (lcell[4] != l[4]) or
269 abs (lcell[5] != l[5]) or
270 abs (lcell[6] != l[6]) or
271 abs (lcell[7] != l[7]) or
272 abs (lcell[8] != l[8]) or
273 abs (lcell[9] != l[9])):
274 print ('xxx cell mismatch: ', addr, lcell, l, flush=True)
275 assert 0
276 del exp_cells[addr]
277
278 for extra in exp_cells:
279 print ('xxx unfound cell', extra, flush=True)
280 assert 0
281 return
282
283
284
285
286
287baddefs = {}
288BAD_LOW = [1<<1, 0, 0] # AdcDead
289BAD_HIGH = [ 0, 1<<1, 0] # AdcDead
290BAD_BOTH = [ 0, 0, 1<<1] # NoHV
291BADTIMING = [ 0, 0, 1<<9] # BadTiming
292
293def TileBadChannelsCfg(flags, badChannels, chans=[], lines=''):
294
295 """
296
297 chans: [(sec, side, mod, tow, samp, pmt), [DATA0, DATA1, DATA2]]
298 We'd like to specify cells using offline addressing, but the bad cell
299 file uses online addressing. We can convert, but that requires
300 idhelpers, etc, that aren't available until after initialization.
301 So we pass in both representations; in finalize(), we'll check
302 that they match and print out the correct bad cell lines
303 if they do not.
304
305 File data line format:
306 frag channel dummy adcStatus0 adcStatus1 chnStatus
307 chnStatus + adcStatusN are given to TileBchDecoder.
308 Offline problem masks:
309 chn adc
310 0 GeneralMaskChannel GeneralMaskAdc
311 1 NoPmt AdcDead
312 2 NoHV StuckBit
313 3 WrongHV DataCorruption
314 4 NoLaser VeryLargeHfNoise
315 5 BadLaser NoData
316 6 NoCesium WrongDspConfig
317 7 BadCesium LargeHfNoise
318 8 NoTiming CorrelatedNoise
319 9 BadTiming LargeLfNoise
320 10 TrigGeneralMask NoCis
321 11 TrigNoGain BadCis
322 12 TrigHalfGain SevereStuckBit
323 13 TrigNoisy SevereDataCorruption
324 14 Emergency IgnoredByDQV
325 15 HVReadoutPb
326 16 BrokenClearFibre
327 17 IgnoreCs
328 18 UnstableCs
329
330
331 Online problem masks:
332 chn adc
333 0 IgnoredInDsp OnlineGeneralMaskAdc
334 1 IgnoredInHlt
335 2 DisableForL1
336 3 TrigGeneralMask
337 4 TrigNoGain
338 5 TrigHalfGain
339 6 TrigNoisy
340 7 OnlineBadTiming
341 """
342
343 if not chans:
344 TileBchList = 'TileNoBad.oflBch'
345 else:
346 TileBchList = badChannels + '.bch'
347 f = open (TileBchList, 'w')
348 print ('OBJVERSION 0', file=f)
349 print ('0x000 0 0 0 0 0', file=f)
350 f.write (lines)
351 f.close()
352 baddefs[badChannels] = (chans, lines)
353
354
355 TileCondProxyFileBch = CompFactory.getComp("TileCondProxyFile<TileCalibDrawerBch>")
356 onlineBadChannelsProxy = TileCondProxyFileBch('TileCondProxyFile_OnlBch', Source=TileBchList)
357 offlineBadChannelsProxy = TileCondProxyFileBch('TileCondProxyFile_OflBch', Source='TileNoBad.oflBch')
358
359 TileBadChannelsCondAlg = CompFactory.TileBadChannelsCondAlg
360 badChannelsCondAlg = TileBadChannelsCondAlg(name=f'{badChannels}_CondAlg',
361 OnlBchProxy=onlineBadChannelsProxy,
362 OflBchProxy=offlineBadChannelsProxy,
363 TileBadChannels=badChannels)
364
365 acc = ComponentAccumulator()
366 acc.addCondAlgo(badChannelsCondAlg)
367
368 return acc
369
370
371badChannelsLines = """
3720x312 2 0 0 2 0
3730x312 4 0 2 0 0
3740x312 11 0 0 0 2
3750x312 6 0 0 0 512
3760x307 12 0 0 0 2
3770x335 12 0 0 0 512
378"""
379
380
381def maketool (name, badChannels, noise=0, **kw):
382 TileBadChanTool = CompFactory.TileBadChanTool
383 bct = TileBadChanTool(TileBadChannels=badChannels)
384
385 TileCellBuilderFromHit = CompFactory.TileCellBuilderFromHit
386 return TileCellBuilderFromHit(name,
387 TileBadChanTool=bct,
388 CaloNoise='',
389 TileHitContainer='TileHitCnt',
390 NoiseSigma=noise,
391 **kw)
392
393
395
396 acc = ComponentAccumulator()
397
398 from TileGeoModel.TileGMConfig import TileGMCfg
399 acc.merge( TileGMCfg(flags) )
400
401 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
402 acc.merge(LArGMCfg(flags))
403
404 from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg
405 acc.merge( TileCablingSvcCfg(flags) )
406
407 from TileConditions.TileInfoLoaderConfig import TileInfoLoaderCfg
408 acc.merge( TileInfoLoaderCfg(flags) )
409
410 from TileConditions.TileEMScaleConfig import TileEMScaleCondAlgCfg
411 acc.merge( TileEMScaleCondAlgCfg(flags) )
412
413 from RngComps.RngCompsConfig import AthRNGSvcCfg
414 acc.merge( AthRNGSvcCfg(flags) )
415
416 from TileConditions.TileSamplingFractionConfig import TileSamplingFractionCondAlgCfg
417 acc.merge( TileSamplingFractionCondAlgCfg(flags, Source='FILE') )
418 acc.getCondAlgo('TileSamplingFractionCondAlg').G4Version=-1
419
420 bc1 = 'tilecellbuilder_bc1'
421 acc.merge( TileBadChannelsCfg(flags, bc1) )
422
423 bc2 = 'tilecellbuilder_bc2'
424 acc.merge( TileBadChannelsCfg(flags, bc2,
425 [[(3, 1, 18, 8, 2, 0), BAD_HIGH],
426 [(2, 1, 18, 9, 1, 0), BAD_LOW],
427 [(2, 1, 18, 12, 0, 1), BAD_BOTH],
428 [(2, 1, 18, 11, 0, 0), BADTIMING],
429 [(4, 1, 0, 1, 0, 0), BAD_BOTH],
430 [(4, 1, 6, 1, 0, 0), BADTIMING],
431 ], badChannelsLines) )
432
433
434 acc.addPublicTool( maketool ('tool1', bc1) )
435 acc.addPublicTool( maketool ('tool2', bc2, maskBadChannels=True) )
436 acc.addPublicTool( maketool ('tool3', bc1, noise=0.1) )
437
438 acc.addEventAlgo( TestAlg('testalg1') )
439
440 return acc
441
442
443if __name__ == "__main__":
444
445 from AthenaConfiguration.AllConfigFlags import initConfigFlags
446 from AthenaConfiguration.TestDefaults import defaultConditionsTags, defaultTestFiles
447 from AthenaCommon.Logging import log
448 from AthenaCommon.Constants import INFO
449
450 # Test setup
451 log.setLevel(INFO)
452
453 flags = initConfigFlags()
454 flags.Input.Files = defaultTestFiles.HITS_RUN2
455 flags.Input.ConditionsRunNumber = 1
456 flags.Input.OverrideRunNumber = True
457 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN2_MC
458 flags.Tile.RunType = TileRunType.PHY
459 flags.Exec.MaxEvents = 3
460 flags.fillFromArgs()
461
462 flags.lock()
463
464 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
465 cfg = MainServicesCfg(flags)
466
467 # Configure reading POOL files
468 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
469 cfg.merge(PoolReadCfg(flags))
470
471 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
472 cfg.merge (EventInfoCnvAlgCfg (flags, disableBeamSpot = True))
473
474 cfg.merge( TileRawChannelBuilderFromHitTestCfg(flags) )
475
476 flags.dump()
477 cfg.printConfig(withDetails=True)
478 cfg.store( open('TileCellBuilderFromHitTest.pkl', 'wb') )
479
480 sc = cfg.run()
481
482 import sys
483 # Success should be 0
484 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()