ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Calorimeter
CaloClusterCorrection
python
StandardCellWeightCalib.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3
#--
4
#-- Configures standard cell weight calibration tools (extracted from JetGetter)
5
#--
6
#-- Note the input for this calibration is jet driven. The fitted default
7
8
from
AthenaConfiguration.ComponentAccumulator
import
ComponentAccumulator
9
from
AthenaConfiguration.ComponentFactory
import
CompFactory
10
from
AthenaCommon.Logging
import
logging
11
12
_logger = logging.getLogger(
'Calorimeter::StandardCellWeightCalibration'
)
13
14
def
editParm
(param):
15
numStr = str(param)
16
posDec = numStr.find(
"."
)
17
lenStr = len(numStr)
18
if
posDec == 0:
19
if
lenStr >= 1:
20
selStr = numStr[1:]
21
else
:
22
selStr =
"_"
23
else
:
24
if
posDec > 0:
25
if
lenStr < posDec+1:
26
selStr = numStr[0:posDec-1]
27
else
:
28
selStr = numStr[0:posDec-1] + numStr[posDec+1:]
29
else
:
30
selStr = numStr
31
return
selStr
32
33
class
H1Calibration
(object):
34
#--
35
#-- Calibration dictionaries. Note that DB folders are truncated from the usual
36
#-- jet naming conventions! The code here deals with this.
37
#--
38
calibdicV14 = {
39
"Cone4Topo"
:
"CaloH1WeightsCone4Topo-02-000"
,
40
"Cone4Tower"
:
"CaloH1WeightsCone4Tower-02-000"
,
41
"ConeTopo"
:
"CaloH1WeightsConeTopo-02-000"
,
42
"ConeTower"
:
"CaloH1WeightsConeTower-02-000"
,
43
"Kt4Topo"
:
"CaloH1WeightsKt4Topo-02-000"
,
44
"Kt4Tower"
:
"CaloH1WeightsKt4Tower-02-000"
,
45
"Kt6Topo"
:
"CaloH1WeightsKt6Topo-02-000"
,
46
"Kt6Tower"
:
"CaloH1WeightsKt6Tower-02-000"
,
47
"Cone4TopoAtlFastII"
:
"CaloH1WeightsCone4TopoAtlFastII-02-000"
,
48
"Cone4TowerAtlFastII"
:
"CaloH1WeightsCone4TowerAtlFastII-02-000"
,
49
"ConeTopoAtlFastII"
:
"CaloH1WeightsConeTopoAtlFastII-02-000"
,
50
"ConeTowerAtlFastII"
:
"CaloH1WeightsConeTowerAtlFastII-02-000"
,
51
"Kt4TopoAtlFastII"
:
"CaloH1WeightsKt4TopoAtlFastII-02-000"
,
52
"Kt4TowerAtlFastII"
:
"CaloH1WeightsKt4TowerAtlFastII-02-000"
,
53
"Kt6TopoAtlFastII"
:
"CaloH1WeightsKt6TopoAtlFastII-02-000"
,
54
"Kt6TowerAtlFastII"
:
"CaloH1WeightsKt6TowerAtlFastII-02-000"
,
55
}
56
calibdicV13 = {
57
"Cone4Topo"
:
"CaloH1WeightsCone4Topo-01-000"
,
58
"Cone4Tower"
:
"CaloH1WeightsCone4Tower-01-000"
,
59
"ConeTopo"
:
"CaloH1WeightsConeTopo-01-000"
,
60
"ConeTower"
:
"CaloH1WeightsConeTower-01-000"
,
61
"Kt4Topo"
:
"CaloH1WeightsKt4Topo-01-000"
,
62
"Kt4Tower"
:
"CaloH1WeightsKt4Tower-01-000"
,
63
"Kt6Topo"
:
"CaloH1WeightsKt6Topo-01-000"
,
64
"Kt6Tower"
:
"CaloH1WeightsKt6Tower-01-000"
,
65
"Cone4TopoAtlFastII"
:
"CaloH1WeightsCone4TopoAtlFastII-01-000"
,
66
"Cone4TowerAtlFastII"
:
"CaloH1WeightsCone4TowerAtlFastII-01-000"
,
67
"ConeTopoAtlFastII"
:
"CaloH1WeightsConeTopoAtlFastII-01-000"
,
68
"ConeTowerAtlFastII"
:
"CaloH1WeightsConeTowerAtlFastII-01-000"
,
69
"Kt4TopoAtlFastII"
:
"CaloH1WeightsKt4TopoAtlFastII-01-000"
,
70
"Kt4TowerAtlFastII"
:
"CaloH1WeightsKt4TowerAtlFastII-01-000"
,
71
"Kt6TopoAtlFastII"
:
"CaloH1WeightsKt6TopoAtlFastII-01-000"
,
72
"Kt6TowerAtlFastII"
:
"CaloH1WeightsKt6TowerAtlFastII-01-000"
,
73
}
74
calibdicV12 = {
75
"Cone4Topo"
:
"CaloH1WeightsCone4Topo-00-000"
,
76
"Cone4Tower"
:
"CaloH1WeightsCone4Tower-00-000"
,
77
"ConeTopo"
:
"CaloH1WeightsConeTopo-00-000"
,
78
"ConeTower"
:
"CaloH1WeightsConeTower-00-000"
,
79
"Kt4Topo"
:
"CaloH1WeightsKt4Topo-00-000"
,
80
"Kt4Tower"
:
"CaloH1WeightsKt4Tower-00-000"
,
81
"Kt6Topo"
:
"CaloH1WeightsKt6Topo-00-000"
,
82
"Kt6Tower"
:
"CaloH1WeightsKt6Tower-00-000"
,
83
"Cone4TopoAtlFastII"
:
"CaloH1WeightsCone4TopoAtlFastII-00-000"
,
84
"Cone4TowerAtlFastII"
:
"CaloH1WeightsCone4TowerAtlFastII-00-000"
,
85
"ConeTopoAtlFastII"
:
"CaloH1WeightsConeTopoAtlFastII-00-000"
,
86
"ConeTowerAtlFastII"
:
"CaloH1WeightsConeTowerAtlFastII-00-000"
,
87
"Kt4TopoAtlFastII"
:
"CaloH1WeightsKt4TopoAtlFastII-00-000"
,
88
"Kt4TowerAtlFastII"
:
"CaloH1WeightsKt4TowerAtlFastII-00-000"
,
89
"Kt6TopoAtlFastII"
:
"CaloH1WeightsKt6TopoAtlFastII-00-000"
,
90
"Kt6TowerAtlFastII"
:
"CaloH1WeightsKt6TowerAtlFastII-00-000"
,
91
}
92
93
#--
94
loaded_folder = []
95
96
# folder overriding -----------------------
97
forceOverrideFolder =
False
98
@staticmethod
99
def
overrideFolder
(flags):
100
return
H1Calibration.forceOverrideFolder
or
flags.Input.isMC
101
102
#--
103
#-- Helper functions to access DB parameters. Note that providing a dbtag (like from JetCalibrationDBTag)
104
#-- overwrites the default tag extracted from the detector description version
105
#--
106
@staticmethod
107
def
calibration_dict
(flags, dbtag=""):
108
#-- DB tag provided
109
if
dbtag !=
""
:
110
calibdic = {
111
"Cone4Topo"
:
"CaloH1WeightsCone4Topo-"
+dbtag,
112
"Cone4Tower"
:
"CaloH1WeightsCone4Tower-"
+dbtag,
113
"ConeTopo"
:
"CaloH1WeightsConeTopo-"
+dbtag,
114
"ConeTower"
:
"CaloH1WeightsConeTower-"
+dbtag,
115
"Kt4Topo"
:
"CaloH1WeightsKt4Topo-"
+dbtag,
116
"Kt4Tower"
:
"CaloH1WeightsKt4Tower-"
+dbtag,
117
"Kt6Topo"
:
"CaloH1WeightsKt6Topo-"
+dbtag,
118
"Kt6Tower"
:
"CaloH1WeightsKt6Tower-"
+dbtag
119
}
120
return
calibdic
121
#-- default extraction
122
else
:
123
ddv = flags.GeoModel.AtlasVersion
124
#-- establish relation between detector description and calibration
125
if
ddv.startswith(
"ATLAS-CSC"
):
126
if
ddv >=
"ATLAS-CSC-01-00-01"
:
127
return
H1Calibration.calibdicV13
128
else
:
129
return
H1Calibration.calibdicV12
130
elif
ddv.startswith(
"ATLAS-Comm"
):
131
return
H1Calibration.calibdicV13
132
else
:
133
return
H1Calibration.calibdicV14
134
#-- get calibration parameters
135
@staticmethod
136
def
getCalibDBParams
(flags, finder, mainparam, input, onlyCellWeight=False, isMC=False):
137
""" Retrieves calibration DB parameters from jet finder specs, returns a triplet (key,folder,tag)
138
"""
139
#-- adapt to DB convention
140
input = input.replace(
'H1'
,
''
)
141
param =
editParm
(mainparam)
142
if
param ==
'7'
:
143
param =
''
144
#-- get dictionary
145
caldict = H1Calibration.calibration_dict(flags)
146
147
calibtype = finder+param+input
148
#-- specific calibration
149
if
calibtype
in
caldict:
150
key =
'H1Weights'
+ calibtype
151
tag = caldict[calibtype]
152
if
isMC:
153
folder =
'/CALO/Ofl/'
154
tag =
"CALOOfl"
+tag[4:]
155
else
:
156
folder =
'/CALO/'
157
folder +=
'H1Weights/'
+ key
158
key = folder
159
return
(key,folder,tag)
160
#-- default calibration
161
else
:
162
if
onlyCellWeight:
163
# then we don't really care : just give back Cone4Tower or Cone4Topo
164
# and avoid the warning below.
165
if
'Topo'
in
input:
return
H1Calibration.getCalibDBParams(flags,
'Cone'
,0.4,
'H1Topo'
,onlyCellWeight,isMC)
166
else
:
return
H1Calibration.getCalibDBParams(flags,
'Cone'
,0.4,
'H1Tower'
,onlyCellWeight,isMC)
167
# else try to find a good fall back
168
_logger.warning(
"getCalibDBParams: no dedicated calibration for %s %s %s"
, finder,mainparam,input)
169
if
finder
not
in
[
'Kt'
,
'Cone'
] : finder =
'Cone'
# fall back to ATLAS Cone
170
if
input
not
in
[
'Topo'
,
'Tower'
] : input =
'Tower'
# fall back to Tower
171
if
finder ==
'Kt'
: l = [ 0.4, 0.6 ]
172
else
: l = [ 0.4, 0.7 ]
173
(m,mainparam) =
min
( [ (abs(p-mainparam),p)
for
p
in
l ] )
# main parameter optimization (??)
174
_logger.warning(
"getCalibDBParams: defaulted calibration to %s %s %s"
, finder,mainparam,input)
175
return
H1Calibration.getCalibDBParams(flags,finder,mainparam,input,onlyCellWeight,isMC)
176
177
178
def
getCellWeightTool
(flags, finder="Cone", mainparam=0.4, input="Topo", onlyCellWeight=False):
179
"""
180
Returns a fully configured H1-style cell weighting calibration tool. This tool only uses cell weights!
181
Parameters/type:
182
finder/str : name of jet finder
183
input/str : input objects triggers calibration weights
184
mainparam/float: size parameter for jet
185
"""
186
result = ComponentAccumulator()
187
(key,folder,tag) = H1Calibration.getCalibDBParams(flags,finder,mainparam,input, onlyCellWeight, flags.Input.isMC)
188
from
IOVDbSvc.IOVDbSvcConfig
import
addFolders
189
result.merge(addFolders(flags,folder,
'CALO_OFL'
if
flags.Input.isMC
else
'CALO'
,className =
'CaloRec::ToolConstants'
,
190
tag=tag
if
H1Calibration.overrideFolder(flags)
else
None
))
191
192
#-- configure tool
193
toolName = finder +
editParm
(mainparam) + input
194
cellcalibtool = CompFactory.H1WeightToolCSC12Generic(
"H1Weight"
+toolName,
195
DBHandleKey = key)
196
result.setPrivateTools(cellcalibtool)
197
return
result
min
#define min(a, b)
Definition
cfImp.cxx:40
StandardCellWeightCalib.H1Calibration
Definition
StandardCellWeightCalib.py:33
StandardCellWeightCalib.H1Calibration.overrideFolder
overrideFolder(flags)
Definition
StandardCellWeightCalib.py:99
StandardCellWeightCalib.H1Calibration.getCalibDBParams
getCalibDBParams(flags, finder, mainparam, input, onlyCellWeight=False, isMC=False)
Definition
StandardCellWeightCalib.py:136
StandardCellWeightCalib.H1Calibration.calibration_dict
calibration_dict(flags, dbtag="")
Definition
StandardCellWeightCalib.py:107
StandardCellWeightCalib.editParm
editParm(param)
Definition
StandardCellWeightCalib.py:14
StandardCellWeightCalib.getCellWeightTool
getCellWeightTool(flags, finder="Cone", mainparam=0.4, input="Topo", onlyCellWeight=False)
Definition
StandardCellWeightCalib.py:178
Generated on
for ATLAS Offline Software by
1.17.0