ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Calorimeter
CaloTools
python
CaloEstimatedGainTool_test.py
Go to the documentation of this file.
1
#
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
10
from
AthenaConfiguration.ComponentAccumulator
import
ComponentAccumulator
11
from
AthenaPython.PyAthenaComps
import
Alg, StatusCode
12
from
AthenaCommon.Logging
import
logging
13
import
ROOT
14
15
16
def
i32
(x):
17
if
x >= (1<<31):
18
x -= (1<<32)
19
return
x
20
21
22
class
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
85
def
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
102
from
AthenaConfiguration.AllConfigFlags
import
initConfigFlags
103
from
AthenaConfiguration.TestDefaults
import
defaultTestFiles
104
flags = initConfigFlags()
105
flags.Input.Files = defaultTestFiles.RDO_RUN2
106
flags.Detector.GeometryLAr =
True
107
flags.Detector.GeometryTile =
True
108
flags.needFlagsCategory(
'Tile'
)
109
flags.needFlagsCategory(
'LAr'
)
110
111
flags.lock()
112
from
AthenaConfiguration.MainServicesConfig
import
MainServicesCfg
113
acc = MainServicesCfg(flags)
114
115
acc.merge (testCfg (flags))
116
acc.run(1)
python.CaloEstimatedGainTool_test.TestAlg
Definition
CaloEstimatedGainTool_test.py:22
python.CaloEstimatedGainTool_test.TestAlg.execute
execute(self)
Definition
CaloEstimatedGainTool_test.py:59
python.CaloEstimatedGainTool_test.TestAlg.testcell
testcell(self, elt, elist)
Definition
CaloEstimatedGainTool_test.py:36
python.CaloEstimatedGainTool_test.TestAlg.__init__
__init__(self, name)
Definition
CaloEstimatedGainTool_test.py:23
python.CaloEstimatedGainTool_test.TestAlg.tool
tool
Definition
CaloEstimatedGainTool_test.py:30
python.CaloEstimatedGainTool_test.i32
i32(x)
Definition
CaloEstimatedGainTool_test.py:16
python.CaloEstimatedGainTool_test.testCfg
testCfg(flags)
Definition
CaloEstimatedGainTool_test.py:85
initialize
void initialize()
Definition
run_EoverP.cxx:894
type
Generated on
for ATLAS Offline Software by
1.17.0