Skip to content

Commit c0f00bc

Browse files
andrpieachiefa
authored andcommitted
initial implementation
1 parent 43a4fa6 commit c0f00bc

23 files changed

+7003
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
data_central:
2+
- 133028.4
3+
- 65424.69
4+
- 32184.565
5+
- 15508.665
6+
- 6929.4305
7+
- 2953.2690000000002
8+
- 1335.78105
9+
- 639.31735
10+
- 311.22885
11+
- 161.26548
12+
- 85.440625
13+
- 46.12412500000001
14+
- 24.90702
15+
- 13.953918499999999
16+
- 7.8356555000000006
17+
- 4.4873655
18+
- 2.62893
19+
- 1.5238954
20+
- 0.87663425
21+
- 0.51637855
22+
- 0.3088446
23+
- 0.1813905
24+
- 0.107358825
25+
- 0.064056495
26+
- 0.037641245000000004
27+
- 0.022154590000000002
28+
- 0.0131474275
29+
- 0.007515096
30+
- 0.0042382505000000004
31+
- 0.0023162765
32+
- 0.001479684
33+
- 0.00080651855
34+
- 0.0003330529
35+
- 124990.9
36+
- 60192.09
37+
- 29561.59
38+
- 14894.62
39+
- 6680.1565
40+
- 2799.6155
41+
- 1229.82535
42+
- 576.0116
43+
- 286.699
44+
- 146.18525
45+
- 76.11559
46+
- 40.519945
47+
- 22.31715
48+
- 12.4270435
49+
- 6.989143
50+
- 3.9380905
51+
- 2.2736349999999996
52+
- 1.3016353999999999
53+
- 0.74941965
54+
- 0.4246726
55+
- 0.24525160000000001
56+
- 0.14281038999999998
57+
- 0.08300146
58+
- 0.047785060000000004
59+
- 0.027622405
60+
- 0.015534824999999999
61+
- 0.0083614125
62+
- 0.004397193
63+
- 0.002400696
64+
- 0.0014339545
65+
- 0.0007708299000000001
66+
- 0.00032298115
67+
- 0.0001540647
68+
- 106001.85
69+
- 51459.58
70+
- 25500.23
71+
- 12842.787
72+
- 5689.5275
73+
- 2351.125
74+
- 1032.87005
75+
- 476.55859999999996
76+
- 230.03785
77+
- 117.05122
78+
- 61.171135
79+
- 31.907865
80+
- 16.5701565
81+
- 9.0991505
82+
- 4.9939
83+
- 2.7480735
84+
- 1.52631545
85+
- 0.83555045
86+
- 0.4604848
87+
- 0.2546981
88+
- 0.13994145
89+
- 0.07495685
90+
- 0.040092575
91+
- 0.021179149999999997
92+
- 0.010701724000000001
93+
- 0.005330658
94+
- 0.0026574930000000004
95+
- 0.0012888560000000001
96+
- 0.0005364438
97+
- 0.0002587899
98+
- 92793.05
99+
- 44133.74
100+
- 20980.655
101+
- 10224.237
102+
- 4458.4075
103+
- 1824.0725
104+
- 798.7361500000001
105+
- 355.31155
106+
- 167.7876
107+
- 83.147695
108+
- 40.312630000000006
109+
- 21.334575
110+
- 10.545282499999999
111+
- 5.5819435
112+
- 2.8101975
113+
- 1.4301964999999999
114+
- 0.74639455
115+
- 0.36604785
116+
- 0.18549759999999998
117+
- 0.086206375
118+
- 0.039591520000000005
119+
- 0.018171475000000003
120+
- 0.008225115
121+
- 0.003620559
122+
- 0.0014617690000000001
123+
- 0.000520213
124+
- 66790.205
125+
- 32723.79
126+
- 15790.925
127+
- 7222.7775
128+
- 3027.986
129+
- 1221.273
130+
- 512.21385
131+
- 222.50975
132+
- 101.20700000000001
133+
- 44.18917
134+
- 20.625805
135+
- 9.451005
136+
- 4.073024
137+
- 1.801326
138+
- 0.7855935000000001
139+
- 0.32102845
140+
- 0.12287545
141+
- 0.04706562
142+
- 0.01631914
143+
- 0.005333325
144+
- 0.001682455
145+
- 43656.2
146+
- 20568.53
147+
- 9748.619999999999
148+
- 4532.305
149+
- 1810.682
150+
- 650.3615
151+
- 244.64194999999998
152+
- 100.5681
153+
- 35.74785
154+
- 13.19904
155+
- 4.873749999999999
156+
- 1.8669375000000001
157+
- 0.661853
158+
- 0.1753632
159+
- 0.04648735
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import yaml
2+
import numpy as np
3+
from nnpdf_data.filter_utils.utils import prettify_float
4+
5+
yaml.add_representer(float, prettify_float)
6+
7+
def read_metadata():
8+
'''
9+
this function reads metadata
10+
and returns the list of tables used
11+
in the implementation
12+
'''
13+
temp_dict = {}
14+
with open('metadata.yaml', 'r') as file:
15+
temp_dict = yaml.safe_load(file)
16+
observable = temp_dict['implemented_observables'][0]
17+
return observable['tables']
18+
19+
def read_table(table_no: int):
20+
'''
21+
this function takes the table number and
22+
returns the corresponding:
23+
kinematic bins
24+
central values corrected as per eq 28
25+
uncertainties corrected as per eq 29
26+
in paper https://arxiv.org/pdf/physics/0403086
27+
'''
28+
temp_dict = dict()
29+
with open(f'rawdata/Table{table_no}.yaml', 'r') as file:
30+
temp_dict = yaml.safe_load(file)
31+
32+
# sort out kinematic bins:
33+
sqrts_val = float(temp_dict['dependent_variables'][0]['qualifiers'][1]['value'])
34+
ybin = temp_dict['dependent_variables'][0]['qualifiers'][0]['value']
35+
ymin, ymax = float(ybin[:3]), float(ybin[4:7])
36+
ymid = (ymin+ymax)/2
37+
bins_in_table = list()
38+
for ptbin in temp_dict['independent_variables'][0]['values']:
39+
y_dict = {'y': {'min': ymin, 'mid': ymid, 'max': ymax}}
40+
sqrts_dict = {'sqrts': {'min': None, 'mid': sqrts_val, 'max': None}}
41+
pT_dict = {'pT': {'min': ptbin['low'], 'mid': (ptbin['low']+ptbin['high'])/2, 'max': ptbin['high']}}
42+
bins_in_table.append(y_dict | sqrts_dict | pT_dict)
43+
44+
# read the central values and the uncertainties
45+
central_values = list()
46+
stat = list()
47+
sys = list()
48+
for dep_var in temp_dict['dependent_variables']:
49+
if dep_var['header']['name'] == 'D2(SIG)/DPT/DABS(YRAP)':
50+
for bin_val in dep_var['values']:
51+
central_values.append(bin_val['value'])
52+
for err in bin_val['errors']:
53+
if err['label'] == 'stat':
54+
stat.append(err['symerror'])
55+
elif err['label'] == 'sys':
56+
sys.append((np.abs(err['asymerror']['minus']), err['asymerror']['plus']))
57+
58+
# process the asymmetric uncertainties
59+
sys_processed = list()
60+
shifts_in_central = list()
61+
for (del_minus, del_plus) in sys:
62+
# calculating delta and Deltabar as per eqs 23, 24
63+
delta = (del_plus-del_minus)/2
64+
Deltabar = float((del_plus+del_minus)/2)
65+
# each delta/Deltabar is of order 0.02, so using eq 28, 29 is justified
66+
shifts_in_central.append(delta)
67+
sys_processed.append(Deltabar)
68+
69+
corrected_centrals_in_table = list(np.array(central_values)+np.array(shifts_in_central))
70+
uncertainties_in_table = list()
71+
for i in range(len(stat)):
72+
unc_dict = {'stat': stat[i], 'sys': sys_processed[i]}
73+
uncertainties_in_table.append(unc_dict)
74+
75+
return bins_in_table, corrected_centrals_in_table, uncertainties_in_table
76+
77+
def main_filter() -> None:
78+
'''
79+
main filter that reads all the tables and saves the dataset in .yaml files
80+
'''
81+
82+
tables = read_metadata()
83+
kinematics = list()
84+
data_central = list()
85+
uncertainties = list()
86+
for table_no in tables:
87+
current_bins, current_central, current_unc = read_table(table_no)
88+
kinematics += current_bins
89+
data_central += current_central
90+
uncertainties += current_unc
91+
92+
with open('kinematics_R07.yaml', 'w') as file:
93+
yaml.safe_dump({'bins': kinematics}, file, sort_keys=False)
94+
95+
data_central_float = [float(central_value) for central_value in data_central]
96+
with open('data_R07.yaml', 'w') as file:
97+
yaml.safe_dump({'data_central': data_central_float}, file, sort_keys=False)
98+
99+
unc_definitions = {'definitions': {'sys': {'description': 'combined systematic ucertainties (symmetrised), including JES correction, pT resolution, luminosity', 'treatment': 'MULT', 'type': 'CORR'}, 'stat': {'description': 'combined statistical uncertainties', 'treatment': 'MULT', 'type': 'CORR'}}}
100+
101+
with open('uncertainties_R07.yaml', 'w') as file:
102+
yaml.safe_dump(unc_definitions | {'bins': uncertainties}, file, sort_keys=False)
103+
104+
105+
if __name__ == '__main__':
106+
main_filter()

0 commit comments

Comments
 (0)