Skip to content

Commit

Permalink
Added uncertainties
Browse files Browse the repository at this point in the history
  • Loading branch information
ecole41 committed Dec 18, 2024
1 parent 6f023aa commit be7d560
Show file tree
Hide file tree
Showing 4 changed files with 506 additions and 1 deletion.
66 changes: 65 additions & 1 deletion nnpdf_data/nnpdf_data/commondata/ATLAS_Z0_7TEV_36PB/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import yaml
from filter_utils import get_data_values, get_kinematics
from filter_utils import get_data_values, get_kinematics, get_systematics

from nnpdf_data.filter_utils.utils import prettify_float

Expand Down Expand Up @@ -32,5 +32,69 @@ def filter_ATLAS_Z0_7TEV_36FB_data_kinematic():
yaml.dump(kinematics_yaml, file, sort_keys=False)


def filter_ATLAS_Z0_7TEV_36FB_systematics():
"""
This function writes the systematics to a yaml file.
"""

with open("metadata.yaml", "r") as file:
metadata = yaml.safe_load(file)

systematics = get_systematics()

# error definition
error_definitions = {}
errors = []
counter_1 = 1
counter_2 = 0
for sys in systematics:
if sys[0]['name'] == 'stat':
error_definitions[sys[0]['name']] = {
"description": "Uncorrelated statistical uncertainties",
"treatment": "ADD",
"type": "UNCORR",
}

elif sys[0]['name'] == 'uncor':
error_definitions[sys[0]['name']] = {
"description": f"Sys uncertainty idx: {counter_1}",
"treatment": "MULT",
"type": "UNCORR",
}
counter_1 += 1

elif sys[0]['name'] == 'atlaslumi10':
error_definitions[sys[0]['name']] = {
"description": f"Sys uncertainty idx: {counter_1}",
"treatment": "MULT",
"type": "ATLASLUMI10",
}
counter_1 += 1

else:
error_definitions[sys[0]['name']] = {
"description": f"Sys uncertainty idx: {counter_1}",
"treatment": "MULT",
"type": f"ATLASWZRAP36PB_{counter_2}",
}
counter_1 += 1
counter_2 += 1

for i in range(metadata['implemented_observables'][0]['ndata']):
error_value = {}

for sys in systematics:
error_value[sys[0]['name']] = float(sys[0]['values'][i])

errors.append(error_value)

uncertainties_yaml = {"definitions": error_definitions, "bins": errors}

# write uncertainties
with open(f"uncertainties.yaml", 'w') as file:
yaml.dump(uncertainties_yaml, file, sort_keys=False)


if __name__ == "__main__":
filter_ATLAS_Z0_7TEV_36FB_data_kinematic()
filter_ATLAS_Z0_7TEV_36FB_systematics()
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,40 @@ def get_kinematics():
return kin


def get_systematics_dataframe():
"""
returns the absolute systematic uncertainties in the form of a pandas dataframe.
"""
sys_rawdata_path = "rawdata/ATLAS-36PB_Z.csv"

abs_unc_df_arr = []

data_central = get_data_values()

df = pd.read_csv(sys_rawdata_path)

# convert (MULT) percentage unc to absolute unc
abs_unc_df = (df.T[2:] * data_central).T / 100
abs_unc_df_arr.append(abs_unc_df)

return abs_unc_df


def get_systematics():
""" """
abs_unc_df = get_systematics_dataframe()

uncertainties = []

for i, unc_dp in enumerate(abs_unc_df.values.T):
name = f"{abs_unc_df.columns[i]}"
values = [unc_dp[j] for j in range(len(unc_dp))]
uncertainties.append([{"name": name, "values": values}])

return uncertainties


if __name__ == "__main__":
get_data_values()
get_kinematics()
get_systematics()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
y_min,y_max,stat,uncor,atlaslumi10,ATLASWZRAP36PB_0,ATLASWZRAP36PB_1,ATLASWZRAP36PB_2,ATLASWZRAP36PB_3,ATLASWZRAP36PB_4,ATLASWZRAP36PB_5,ATLASWZRAP36PB_6,ATLASWZRAP36PB_7,ATLASWZRAP36PB_8,ATLASWZRAP36PB_9,ATLASWZRAP36PB_10,ATLASWZRAP36PB_11,ATLASWZRAP36PB_12,ATLASWZRAP36PB_13,ATLASWZRAP36PB_14,ATLASWZRAP36PB_15,ATLASWZRAP36PB_16,ATLASWZRAP36PB_17,ATLASWZRAP36PB_18,ATLASWZRAP36PB_19,ATLASWZRAP36PB_20,ATLASWZRAP36PB_21,ATLASWZRAP36PB_22,ATLASWZRAP36PB_23,ATLASWZRAP36PB_24,ATLASWZRAP36PB_25,ATLASWZRAP36PB_26,ATLASWZRAP36PB_27,ATLASWZRAP36PB_28,ATLASWZRAP36PB_29
0.0,0.4,1.46,0.59,0.35,0.29,0.09,0.04,0.19,0.07,-0.13,0.05,-0.07,-0.03,0.12,-0.1,0.06,-0.28,-0.02,0.07,-0.1,-0.53,0.07,-0.16,0.34,-0.15,-0.1,0.05,0.22,0.17,0.18,0.0,0.5,0.17,-0.12
0.4,0.8,1.47,0.5,0.35,0.29,0.09,0.04,0.19,0.07,-0.1,0.04,-0.09,-0.02,0.13,-0.1,0.06,-0.29,0.01,0.06,-0.08,-0.55,0.02,-0.16,0.32,-0.17,-0.15,0.02,0.23,0.16,0.25,-0.01,0.47,0.18,-0.11
0.8,1.2,1.5,0.47,0.35,0.29,0.09,0.04,0.19,0.05,-0.08,0.05,-0.07,-0.05,0.11,-0.1,0.06,-0.17,-0.03,0.01,-0.08,-0.43,0.03,-0.13,0.22,-0.15,0.0,0.0,0.23,0.12,0.28,-0.04,0.45,0.16,-0.14
1.2,1.6,1.61,0.45,0.35,0.29,0.09,0.04,0.19,0.04,-0.05,0.04,-0.09,0.01,0.08,-0.05,0.15,-0.15,0.05,0.03,-0.03,-0.37,0.07,-0.06,0.3,-0.09,-0.25,-0.23,0.16,0.14,0.18,-0.04,0.52,0.13,-0.12
1.6,2.0,1.84,0.63,0.35,0.29,0.09,0.04,0.19,0.01,-0.04,0.05,-0.08,0.05,0.03,0.01,0.33,0.15,-0.01,0.02,-0.09,-0.37,0.17,-0.07,0.41,0.04,-0.45,-0.49,0.0,0.08,0.24,-0.06,0.66,-0.06,-0.11
2.0,2.4,2.57,1.37,0.35,0.29,0.09,0.04,0.19,0.0,-0.07,0.09,-0.19,0.18,-0.05,0.13,0.76,0.18,0.23,0.23,0.04,-0.58,0.17,-0.06,0.66,0.13,-1.15,-0.85,0.15,0.01,0.69,-0.2,0.62,-0.14,-0.2
2.4,2.8,3.24,3.81,0.35,0.29,0.09,0.04,0.19,0.06,-0.06,0.58,-0.42,0.61,-0.4,0.63,2.26,0.11,1.16,1.18,0.23,-0.82,0.45,0.03,-0.03,0.04,-0.28,-0.09,0.49,0.26,0.03,-0.19,0.7,-1.68,-0.21
2.8,3.6,4.21,4.37,0.35,0.29,0.09,0.04,0.18,0.18,-0.03,1.76,-1.16,1.28,-0.93,1.87,4.97,-0.39,3.19,2.7,1.64,-1.95,0.56,0.37,-0.83,-0.03,1.39,0.78,0.28,0.26,-1.13,-0.04,0.26,-0.46,-0.21
Loading

0 comments on commit be7d560

Please sign in to comment.