ATLAS Offline Software
Loading...
Searching...
No Matches
CaloEstimatedGainTool_test.py
Go to the documentation of this file.
2# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration.
3#
4# File: CaloTools/python/CaloEstimatedGainTool_test.py
5# Author: scott snyder
6# Date: Aug, 2019
7# Brief: Test for CaloEstimatedGainTool.
8#
9
10from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
11from AthenaPython.PyAthenaComps import Alg, StatusCode
12from AthenaCommon.Logging import logging
13import ROOT
14
15
16def i32(x):
17 if x >= (1<<31):
18 x -= (1<<32)
19 return x
20
21
22class TestAlg (Alg):
23 def __init__ (self, name):
24 Alg.__init__ (self, name)
25 return
26
27 def initialize (self):
28 ROOT.ICaloEstimatedGainTool
29
30 self.tool = ROOT.ToolHandle(ROOT.ICaloEstimatedGainTool)('CaloEstimatedGainTool')
31 if not self.tool.retrieve():
32 assert 0
33 return StatusCode.Success
34
35
36 def testcell (self, elt, elist):
37 ctx = self.getContext()
38 for (e, gain) in elist:
39 if isinstance(e, type(())):
40 cell = ROOT.TileCell(elt, e[0])
41 cell.setEnergy (e[0], e[1], 0, 0)
42 else:
43 cell = ROOT.CaloCell (elt, e, 0, 0, 0)
44 g = i32(self.tool.estimatedGain (ctx, elt, e, 0))
45 assert g == gain, (e, g, gain)
46 g = i32(self.tool.estimatedGain (ctx, elt, e, 1))
47 assert g == gain, (e, g, gain)
48
49 g = i32(self.tool.estimatedGain (ctx, cell, 0))
50 assert g == gain, (e, g, gain)
51 g = i32(self.tool.estimatedGain (ctx, cell, elt, 0))
52 assert g == gain, (e, g, gain)
53 g = i32(self.tool.estimatedGain (ctx, cell, 1))
54 assert g == gain, (e, g, gain)
55 g = i32(self.tool.estimatedGain (ctx, cell, elt, 1))
56 assert g == gain, (e, g, gain)
57 return
58
59 def execute (self):
60 log = logging.getLogger ('TestAlg')
61 ctx = self.getContext()
62 mgr = self.condStore['CaloDetDescrManager'].find (ctx.eventID())
63 elt1 = mgr.get_element (ROOT.CaloCell_ID.LAREM,
64 2, True, 0.5, 0.1)
65 self.testcell (elt1, [(1000, 0), (50000, 1), (300000, 2)])
66
67 elt2 = mgr.get_element (ROOT.CaloCell_ID.LARHEC,
68 2, False, 2.1, 0.1)
69 self.testcell (elt2, [(1000, 1), (50000, 1), (300000, 2)])
70
71 elt3 = mgr.get_element (ROOT.CaloCell_ID.LARFCAL,
72 1, False, 4.9, 0.1)
73 self.testcell (elt3, [(1000, 0), (50000, 1), (800000, 2)])
74
75 elt4 = mgr.get_element (ROOT.CaloCell_ID.TileBar1, 0.3, 0.1)
76 self.testcell (elt4, [((1000, 1000), i32(ROOT.CaloGain.TILEHIGHHIGH)),
77 ((1000, 50000), i32(ROOT.CaloGain.TILEHIGHLOW)),
78 ((50000, 1000), i32(ROOT.CaloGain.TILEHIGHLOW)),
79 ((50000, 50000), i32(ROOT.CaloGain.TILELOWLOW)),
80 ])
81 log.info ('finished')
82 return StatusCode.Success
83
84
85def testCfg (flags):
86 result = ComponentAccumulator()
87
88 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
89 from TileGeoModel.TileGMConfig import TileGMCfg
90 result.merge(LArGMCfg(flags))
91 result.merge(TileGMCfg(flags))
92
93 from CaloTools.CaloEstimatedGainToolConfig import CaloEstimatedGainToolCfg
94 acc = CaloEstimatedGainToolCfg (flags)
95 acc.popPrivateTools()
96 result.merge (acc)
97
98 result.addEventAlgo (TestAlg ('TestAlg'))
99 return result
100
101
102from AthenaConfiguration.AllConfigFlags import initConfigFlags
103from AthenaConfiguration.TestDefaults import defaultTestFiles
104flags = initConfigFlags()
105flags.Input.Files = defaultTestFiles.RDO_RUN2
106flags.Detector.GeometryLAr = True
107flags.Detector.GeometryTile = True
108flags.needFlagsCategory('Tile')
109flags.needFlagsCategory('LAr')
110
111flags.lock()
112from AthenaConfiguration.MainServicesConfig import MainServicesCfg
113acc = MainServicesCfg(flags)
114
115acc.merge (testCfg (flags))
116acc.run(1)
void initialize()