Skip to content

Commit fb8955c

Browse files
authored
Merge pull request #2362 from NNPDF/ATLAS_ZPT_8TEV_variant
ATLAS ZpT 8 TeV uncertainty variant
2 parents 645b5d8 + 133487b commit fb8955c

7 files changed

Lines changed: 1885 additions & 1 deletion

File tree

nnpdf_data/nnpdf_data/commondata/ATLAS_Z0J_8TEV/filter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from filter_decorr_unc import filter_unc_ATLAS_Z0J_8TEV
34
from filter_utils import Extractor
45
import numpy as np
56
import yaml
@@ -75,6 +76,9 @@ def check_dat_with_legacy(observable, rtol=1e-03):
7576
ATLAS_Z0J_8TEV_PT_M.generate_uncertainties('./rawdata/hepdata/unnormalized/output')
7677
ATLAS_Z0J_8TEV_PT_M.generate_uncertainties('./rawdata/hepdata/unnormalized/output', True)
7778

79+
filter_unc_ATLAS_Z0J_8TEV(MC=False)
80+
filter_unc_ATLAS_Z0J_8TEV(MC=True)
81+
7882
# Comparing new anf legacy uncertainties
7983
# Deprecated
8084
if CHECK:
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
"""
2+
This piece of code generates a simplified variant of the uncertainties.yaml
3+
files in which the 99 correlated systematic uncertainties of the legacy
4+
version are replaced with two systematic uncertainties, one that is uncorrelated
5+
and that is correlated. Statistical, luminosity and )optional) Monte Carlo
6+
uncertainties are as in the legacy version.
7+
"""
8+
9+
import yaml
10+
11+
12+
def get_tables(observable):
13+
"""
14+
get the Hepdata tables, given the tables and version specified in metadata
15+
"""
16+
prefix = "rawdata/Table"
17+
with open("metadata.yaml", "r") as file:
18+
metadata = yaml.safe_load(file)
19+
20+
if observable == "PT-Y":
21+
tables = metadata["implemented_observables"][0]["tables"]
22+
elif observable == "PT-M":
23+
tables = metadata["implemented_observables"][1]["tables"]
24+
else:
25+
print("Data set not implemented")
26+
print("Available data sets are:")
27+
print("- ATLAS_Z0J_8TEV_PT-Y")
28+
print("- ATLAS_Z0J_8TEV_PT-M")
29+
exit()
30+
31+
hepdata_tables = []
32+
33+
for table in tables:
34+
hepdata_tables.append(f"{prefix}{table}.yaml")
35+
36+
return hepdata_tables
37+
38+
39+
def get_uncertainties(observable):
40+
"""
41+
Returns uncertainties for dumping in the -yaml file
42+
"""
43+
data_central = []
44+
uncertainties = []
45+
46+
hepdata_tables = get_tables(observable)
47+
for table in hepdata_tables:
48+
with open(table, 'r') as f:
49+
input = yaml.safe_load(f)
50+
# Central values
51+
data_values = input["dependent_variables"][5]["values"]
52+
for data_value in data_values:
53+
data_central.append(data_value["value"])
54+
55+
# Uncertainties
56+
for data_value in data_values:
57+
errors = data_value["errors"]
58+
uncertainty = {}
59+
for error in errors:
60+
uncertainty[error["label"]] = error["symerror"]
61+
uncertainty.update(uncertainty)
62+
63+
uncertainties.append(uncertainty)
64+
65+
return (data_central, uncertainties)
66+
67+
68+
def filter_unc_ATLAS_Z0J_8TEV(MC=False):
69+
"""
70+
Dumps uncertainties on .yaml files
71+
"""
72+
lumi_unc = 2.8 # %
73+
mc_unc = 1.0 # %
74+
observables = ["PT-Y", "PT-M"]
75+
for observable in observables:
76+
if MC == False:
77+
unc_file = "uncertainties_decorr_" + observable + ".yaml"
78+
else:
79+
unc_file = "uncertainties_decorr_sys_10_" + observable + ".yaml"
80+
central_values, uncertainties = get_uncertainties(observable)
81+
82+
for i in range(len(central_values)):
83+
for k in uncertainties[i]:
84+
uncertainties[i][k] = (
85+
float(uncertainties[i][k].replace("%", "")) / 100.0 * central_values[i] * 1000.0
86+
)
87+
uncertainties[i].update({"sys_lumi_corr": lumi_unc / 100 * central_values[i] * 1000.0})
88+
if MC == True:
89+
uncertainties[i].update(
90+
{"sys_mc_uncorr": mc_unc / 100 * central_values[i] * 1000.0}
91+
)
92+
93+
treatment = {
94+
"stat": "ADD",
95+
"sys,Uncorrelated": "ADD",
96+
"sys,Correlated": "MULT",
97+
"sys_lumi_corr": "MULT",
98+
}
99+
correlation = {
100+
"stat": "UNCORR",
101+
"sys,Uncorrelated": "UNCORR",
102+
"sys,Correlated": "CORR",
103+
"sys_lumi_corr": "ATLASLUMI12",
104+
}
105+
if MC == True:
106+
treatment.update({"sys_mc_uncorr": "ADD"})
107+
correlation.update({"sys_mc_uncorr": "UNCORR"})
108+
109+
definitions = {}
110+
for key, value in uncertainties[0].items():
111+
definition = {
112+
key: {
113+
"description": key + " unc. from HepData",
114+
"treatment": treatment[key],
115+
"type": correlation[key],
116+
}
117+
}
118+
definitions.update(definition)
119+
uncertainties_yaml = {"definitions": definitions, "bins": uncertainties}
120+
121+
if MC:
122+
uncertainties_yaml["definitions"][key][
123+
"description"
124+
] = "extra Monte Carlo statistical uncertainty"
125+
126+
with open(unc_file, "w") as file:
127+
yaml.dump(uncertainties_yaml, file, sort_keys=False)
128+
129+
130+
if __name__ == "__main__":
131+
filter_unc_ATLAS_Z0J_8TEV(MC=False)
132+
filter_unc_ATLAS_Z0J_8TEV(MC=True)

nnpdf_data/nnpdf_data/commondata/ATLAS_Z0J_8TEV/metadata.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ implemented_observables:
6969
legacy_10:
7070
data_uncertainties:
7171
- uncertainties_legacy_sys_10_PT-Y.yaml
72-
72+
decorr:
73+
data_uncertainties:
74+
- uncertainties_decorr_PT-Y.yaml
75+
decorr_sys_10:
76+
data_uncertainties:
77+
- uncertainties_decorr_sys_10_PT-Y.yaml
78+
7379
- observable_name: PT-M
7480
observable:
7581
description: Drell-Yan Transverse Momentum Distribution
@@ -143,3 +149,9 @@ implemented_observables:
143149
legacy_data_10:
144150
data_uncertainties:
145151
- uncertainties_legacy_sys_10_PT-M.yaml
152+
decorr:
153+
data_uncertainties:
154+
- uncertainties_decorr_PT-M.yaml
155+
decorr_sys_10:
156+
data_uncertainties:
157+
- uncertainties_decorr_sys_10_PT-M.yaml

0 commit comments

Comments
 (0)