Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HERMES SIDIS per scattering #2211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
data_central:
- 0.3039
- 0.2876
- 0.2773
- 0.2337
- 0.2437
- 0.235
- 0.2587
- 0.2673
- 0.3101
- 0.2095
- 0.2068
- 0.1914
- 0.1718
- 0.1658
- 0.1733
- 0.1745
- 0.1936
- 0.1622
- 0.1147
- 0.1111
- 0.1107
- 0.1128
- 0.1052
- 0.1079
- 0.1069
- 0.1203
- 0.1007
- 0.0495
- 0.0469
- 0.0503
- 0.0521
- 0.053
- 0.0473
- 0.0487
- 0.0494
- 0.0372
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import yaml
import os

ECM = 10.3 # sqrt(s)=sqrt(2p_lep*m_hadron+m_hadron^2)=sqrt(2*27.6*1.876+1.876^2)= 10.3 in GeV


def read_data(folder_path: str, tables: list, htype: int):
"""
htype: 0 for proton, 1 for deutron
"""
collected_data = dict()
collected_data["values"] = list()
collected_data["errors_stat"] = list()
collected_data["errors_sys"] = list()
collected_data["kinematics_x"] = list()
collected_data["kinematics_z"] = list()

metadata_dict = {"htype": htype, "tables": tables, "ndata_points": list()}

for table in tables:
with open(folder_path + f"Table{table}.yaml", "r", encoding="utf-8") as file:
file_dict = yaml.safe_load(file)
z_str = file_dict["dependent_variables"][htype]["qualifiers"][2]["value"]
z_min, z_max = map(float, z_str.split("-"))
values = file_dict["dependent_variables"][htype]["values"]
n_values = len(values)
metadata_dict["ndata_points"].append(n_values)
for i in range(n_values):
collected_data["values"] = collected_data["values"] + [values[i]["value"]]
collected_data["errors_stat"] = collected_data["errors_stat"] + [
values[i]["errors"][0]["symerror"]
]
collected_data["errors_sys"] = collected_data["errors_sys"] + [
values[i]["errors"][1]["symerror"]
]
collected_data["kinematics_x"] = collected_data["kinematics_x"] + [
file_dict["independent_variables"][htype]["values"][i]["value"]
]
collected_data["kinematics_z"] = collected_data["kinematics_z"] + [
[
z_min,
z_max,
]
]
return collected_data, metadata_dict


def write_data(collected_data: dict, folder_path: str):
data_central_yaml = {"data_central": collected_data["values"]}
with open(folder_path + f"data.yaml", "w", encoding="utf-8") as file:
yaml.dump(data_central_yaml, file, sort_keys=False)

n_items = len(collected_data["values"])

# Write kin file
kin = []
for i in range(n_items):
kin_value = {
"z": {
"min": collected_data["kinematics_z"][i][0],
"mid": None,
"max": collected_data["kinematics_z"][i][1],
},
"x": {"min": None, "mid": collected_data["kinematics_x"][i], "max": None},
"sqrts": {"min": None, "mid": ECM, "max": None},
}
kin.append(kin_value)
kinematics_yaml = {"bins": kin}

with open(folder_path + f"kinematics.yaml", "w", encoding="utf-8") as file:
yaml.dump(kinematics_yaml, file, sort_keys=False)

# Write unc file
error = []
for i in range(n_items):
# here uncertainties are symmetric
e = {
"stat": collected_data["errors_stat"][i],
"sys": collected_data["errors_sys"][i],
}
error.append(e)

error_definition = {
"stat": {
"description": "statistical uncertainty",
"treatment": "ADD",
"type": "UNCORR",
},
"sys": {
"description": "systematic uncertainty",
"treatment": "ADD",
"type": "UNCORR",
},
}

uncertainties_yaml = {"definitions": error_definition, "bins": error}

with open(folder_path + f"uncertainties.yaml", "w", encoding="utf-8") as file:
yaml.dump(uncertainties_yaml, file, sort_keys=False)


if __name__ == "__main__":

# Get the path of the current file
folder_path = os.path.dirname(os.path.abspath(__file__)) + "/"

# TODO Create a dict for easy running
naming_dict = {
# "PiPProton-MLTP": [33, 34, 35, 36],
# "PiPDeutron-MLTP": [33, 34, 35, 36],
# "PiMProton-MLTP": [37, 38, 39, 40],
# "PiMDeutron-MLTP": [37, 38, 39, 40],
# "KaMProton-MLTP": [45, 46, 47, 48],
# "KaMDeutron-MLTP": [45, 46, 47, 48],
# "KaPProton-MLTP": [41, 42, 43, 44],
"KaPDeutron-MLTP": [41, 42, 43, 44],
}

# Wp
for name, tables in naming_dict.items():
if "Proton" in name:
htype = 0
else:
htype = 1

if name.upper() in folder_path:
a = 1

collected_data, metadata_dict = read_data(
folder_path + "rawdata/", tables, htype
)
print(name.split("-")[0].lower(), metadata_dict)
write_data(
collected_data,
folder_path=folder_path,
)
Loading
Loading