|
1 | 1 | """ |
2 | | -
|
| 2 | +This file contains the piece of code needed to implement the ATLAS ZpT |
| 3 | +measurement at 13 TeV. We consider the combined electron-muon measurement, for |
| 4 | +which a total uncorrelated and a total correlated ucnertainties are given. The |
| 5 | +measurement is normalised to the fiducial cross section, therefore there is no |
| 6 | +luminosity ucnertainty. The first three bins in pT are cropped, because of |
| 7 | +the impossiblity of producing theoretical predictions. |
3 | 8 | """ |
4 | 9 |
|
5 | | -from filter_utils import get_data_values, get_kinematics, get_systematics |
6 | 10 | import yaml |
7 | 11 |
|
8 | | -UNCORRELATED_SYS = ["Stat (Data)", "Stat (MC)", "Efficiencies (Uncorellated)"] |
9 | | - |
10 | | - |
11 | | -def filter_ATLAS_Z_13TEV_PT_data_kinetic(): |
| 12 | +def get_tables(): |
12 | 13 | """ |
13 | | - writes data central values and kinematics |
14 | | - to respective .yaml file |
| 14 | + Get the Hepdata table |
15 | 15 | """ |
16 | | - with open("metadata.yaml", "r") as file: |
17 | | - metadata = yaml.safe_load(file) |
18 | | - |
19 | | - version = metadata["hepdata"]["version"] |
20 | | - |
21 | | - # tables for Z->l+l- observable |
22 | | - tables = metadata["implemented_observables"][0]["tables"] |
| 16 | + hepdata_tables = ["rawdata/HEPData-ins1768911-v3-Table_4a.yaml"] |
23 | 17 |
|
24 | | - kin = get_kinematics(tables, version) |
25 | | - central_values = get_data_values(tables, version) |
| 18 | + return hepdata_tables |
26 | 19 |
|
| 20 | +def get_all(): |
| 21 | + """ |
| 22 | + Returns data, kinematics and uncertainties for dumping in the .yaml files |
| 23 | + """ |
| 24 | + data_central = [] |
| 25 | + kinematics = [] |
| 26 | + uncertainties = [] |
| 27 | + |
| 28 | + hepdata_tables = get_tables() |
| 29 | + for table in hepdata_tables: |
| 30 | + with open(table, 'r') as f: |
| 31 | + input = yaml.safe_load(f) |
| 32 | + |
| 33 | + # Central values |
| 34 | + data_values = input["dependent_variables"][0]["values"] |
| 35 | + for data_value in data_values: |
| 36 | + data_central.append(data_value["value"]) |
| 37 | + # Kinematic bins |
| 38 | + kin_values = input["independent_variables"][0]["values"] |
| 39 | + for kin_value in kin_values: |
| 40 | + kin = { |
| 41 | + 'pT': {'min': kin_value['low'], |
| 42 | + 'mid': 0.5 * (kin_value['low'] + kin_value['high']), |
| 43 | + 'max': kin_value['high']}, |
| 44 | + 'm_Z2': {'min': 'null', 'mid': '8317.44', 'max': 'null'}, |
| 45 | + 'sqrts': {'min': 'null', 'mid': '13000', 'max': 'null'}} |
| 46 | + |
| 47 | + kinematics.append(kin) |
| 48 | + # Uncertainties |
| 49 | + i = 0 |
| 50 | + for data_value in data_values: |
| 51 | + errors = data_value["errors"] |
| 52 | + uncertainty = {} |
| 53 | + for error in errors: |
| 54 | + uncertainty[error["label"]] = float(error["symerror"].replace('%',''))*data_central[i]/100. |
| 55 | + uncertainty.update(uncertainty) |
| 56 | + |
| 57 | + uncertainties.append(uncertainty) |
| 58 | + i = i+1 |
| 59 | + |
| 60 | + n=3 |
| 61 | + return (data_central[n:], kinematics[n:], uncertainties[n:]) |
| 62 | + |
| 63 | +def filter_ATLAS_Z0J_13TEV_PT(): |
| 64 | + """ |
| 65 | + Dumps data, kinematics, and uncertainties on .yaml files |
| 66 | + """ |
| 67 | + central_values, kinematics, uncertainties = get_all() |
| 68 | + # Central values |
27 | 69 | data_central_yaml = {"data_central": central_values} |
28 | | - kinematics_yaml = {"bins": kin} |
| 70 | + # Kinematics |
| 71 | + kinematics_yaml = {"bins": kinematics} |
| 72 | + # Uncertainties |
| 73 | + treatment = {"correlated uncertainty": "ADD", |
| 74 | + "uncorrelated uncertainty": "ADD",} |
| 75 | + correlation = {"correlated uncertainty": "CORR", |
| 76 | + "uncorrelated uncertainty": "UNCORR",} |
| 77 | + definitions = {} |
| 78 | + for key,value in uncertainties[0].items(): |
| 79 | + definition = {key : |
| 80 | + {"description": key, |
| 81 | + "treatment": treatment[key], |
| 82 | + "type": correlation[key]}} |
| 83 | + definitions.update(definition) |
| 84 | + uncertainties_yaml = {"definitions": definitions,"bins": uncertainties} |
29 | 85 |
|
30 | | - # write central values and kinematics to yaml file |
31 | 86 | with open("data.yaml", "w") as file: |
32 | 87 | yaml.dump(data_central_yaml, file, sort_keys=False) |
33 | | - |
34 | 88 | with open("kinematics.yaml", "w") as file: |
35 | 89 | yaml.dump(kinematics_yaml, file, sort_keys=False) |
36 | | - |
37 | | - |
38 | | -def filter_ATLAS_Z_13TEV_PT_uncertainties(): |
39 | | - """ |
40 | | - writes uncertainties to respective .yaml file |
41 | | - """ |
42 | | - |
43 | | - with open("metadata.yaml", "r") as file: |
44 | | - metadata = yaml.safe_load(file) |
45 | | - |
46 | | - version = metadata["hepdata"]["version"] |
47 | | - # tables for Z->l+l- observable |
48 | | - tables = metadata["implemented_observables"][0]["tables"] |
49 | | - |
50 | | - systematics_LL = get_systematics(tables, version) |
51 | | - |
52 | | - systematics = {"LL": systematics_LL} |
53 | | - |
54 | | - # error definition |
55 | | - error_definitions = {} |
56 | | - errors = {} |
57 | | - |
58 | | - for obs in ["LL"]: |
59 | | - |
60 | | - error_definitions[obs] = {} |
61 | | - |
62 | | - for sys in systematics[obs]: |
63 | | - |
64 | | - if sys[0]['name'] in UNCORRELATED_SYS: |
65 | | - error_definitions[obs][sys[0]['name']] = { |
66 | | - "description": f"{sys[0]['name']} from HEPDATA", |
67 | | - "treatment": "ADD", |
68 | | - "type": "UNCORR", |
69 | | - } |
70 | | - |
71 | | - else: |
72 | | - error_definitions[obs][sys[0]['name']] = { |
73 | | - "description": f"{sys[0]['name']} from HEPDATA", |
74 | | - "treatment": "ADD", |
75 | | - "type": "CORR", |
76 | | - } |
77 | | - |
78 | | - # TODO: |
79 | | - # store error in dict |
80 | | - errors[obs] = [] |
81 | | - |
82 | | - central_values = get_data_values(tables, version) |
83 | | - |
84 | | - for i in range(len(central_values)): |
85 | | - error_value = {} |
86 | | - |
87 | | - for sys in systematics[obs]: |
88 | | - error_value[sys[0]['name']] = float(sys[0]['values'][i]) |
89 | | - |
90 | | - errors[obs].append(error_value) |
91 | | - |
92 | | - uncertainties_yaml = {"definitions": error_definitions[obs], "bins": errors[obs]} |
93 | | - |
94 | | - # write uncertainties |
95 | | - with open(f"uncertainties.yaml", 'w') as file: |
96 | | - yaml.dump(uncertainties_yaml, file, sort_keys=False) |
97 | | - |
98 | | - |
| 90 | + with open("uncertainties.yaml", "w") as file: |
| 91 | + yaml.dump(uncertainties_yaml, file, sort_keys=False) |
| 92 | + |
99 | 93 | if __name__ == "__main__": |
100 | | - filter_ATLAS_Z_13TEV_PT_data_kinetic() |
101 | | - filter_ATLAS_Z_13TEV_PT_uncertainties() |
| 94 | + filter_ATLAS_Z0J_13TEV_PT() |
0 commit comments