ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
PhysicsValidation
PhysValMonitoring
python
PhysValUtils.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
# Defining a python module with helpers for Physics Validation
3
4
from
AthenaCommon.Logging
import
logging
5
logger = logging.getLogger(
'PhysValUtils'
)
6
7
8
9
10
def
getHistogramDefinitions
(fileName, usage, use_group):
11
import
os.path
12
import
json
13
14
# vars required in the input json
15
requiredKeys = [
'title'
,
'xtitle'
,
'ytitle'
,
'path'
,
'xbins'
,
'xmin'
,
'xmax'
,
'type'
]
16
# define a order for the keys in the output list
17
position = {
'name'
: 0,
'title'
: 1,
'path'
: 2,
'xbins'
: 3,
'xmin'
: 4,
'xmax'
: 5,
'type'
: 6,
'ymin'
: 7,
'ymax'
: 8}
18
19
# check if the path exists
20
if
not
os.path.isfile(fileName):
21
raise
IOError(
"This path to the file does not exist:"
+ fileName)
22
23
# read file
24
file_dict = {}
25
with
open(fileName)
as
json_file:
26
file_dict = json.load(json_file)
27
28
# check if the file has the right keys in the dict
29
for
group
in
file_dict:
30
for
var
in
file_dict[group]:
31
for
required_key
in
requiredKeys:
32
if
required_key
not
in
file_dict[group][var]:
33
raise
IOError(
"The key "
+ required_key +
" is missing in the dict for the variable "
+ var +
"."
)
34
35
# read the right parts of the dict
36
list = []
37
# loop over all groups
38
for
group
in
file_dict:
39
# skip that group if it is not asked for
40
if
not
(use_group ==
'ALL'
or
group == use_group)
or
group ==
'template'
:
41
continue
42
# loop over all vars
43
for
var
in
file_dict[group]:
44
# only fill the usage dict with this var if the usage exists in the 'path' dict
45
if
usage
in
file_dict[group][var][
'path'
]:
46
# if the dict has the key forEachTruthType -> expand the one dict into one for each type
47
if
'forEach'
in
file_dict[group][var]:
48
for
type
in
file_dict[group][var][
'forEach'
]:
49
var_list = [
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
]
50
# adapt the new variable name
51
new_var_name = var +
'_'
+ type
52
# fill the name
53
var_list[position[
'name'
]] = str(new_var_name)
54
# merge the tile keys
55
var_list[position[
'title'
]] = str(file_dict[group][var][
'title'
] +
' '
+ type +
';'
+ file_dict[group][var][
'xtitle'
] +
';'
+ file_dict[group][var][
'ytitle'
])
56
# get the right path
57
var_list[position[
'path'
]] = str(file_dict[group][var][
'path'
][usage])
58
# just copy the rest
59
for
key
in
[
'xbins'
,
'xmin'
,
'xmax'
,
'type'
]:
60
var_list[position[key]] = str(file_dict[group][var][key])
61
if
(file_dict[group][var][
'type'
] ==
'TProfile'
):
62
var_list[position[
'ymin'
]] = str(file_dict[group][var][
'ymin'
])
63
var_list[position[
'ymax'
]] = str(file_dict[group][var][
'ymax'
])
64
# append the current variable to the list
65
list.append(var_list)
66
else
:
67
var_list = [
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
,
''
]
68
# fill the name
69
var_list[position[
'name'
]] = str(var)
70
# merge the tile keys
71
var_list[position[
'title'
]] = str(file_dict[group][var][
'title'
] +
';'
+ file_dict[group][var][
'xtitle'
] +
';'
+ file_dict[group][var][
'ytitle'
])
72
# get the right path
73
var_list[position[
'path'
]] = str(file_dict[group][var][
'path'
][usage])
74
# just copy the rest
75
for
key
in
[
'xbins'
,
'xmin'
,
'xmax'
,
'type'
]:
76
var_list[position[key]] = str(file_dict[group][var][key])
77
if
(file_dict[group][var][
'type'
] ==
'TProfile'
):
78
var_list[position[
'ymin'
]] = str(file_dict[group][var][
'ymin'
])
79
var_list[position[
'ymax'
]] = str(file_dict[group][var][
'ymax'
])
80
# append the current variable to the list
81
list.append(var_list)
82
83
return
list
84
85
86
if
if(pathvar)
Definition
SealSharedLib.cxx:168
PhysValUtils.getHistogramDefinitions
getHistogramDefinitions(fileName, usage, use_group)
Definition
PhysValUtils.py:10
Generated on
for ATLAS Offline Software by
1.17.0