-
Notifications
You must be signed in to change notification settings - Fork 7
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
Reimplement hera datasets #2175
Open
peterkrack
wants to merge
22
commits into
master
Choose a base branch
from
reimplement-HERA-datasets
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3298bb0
initial commit for HERA dataset reimplementation
8430f56
initial commit for HERA dataset reimplementation
c32641b
add reimplementation of HERA beauty and charm QCD analysis and combin…
66d5101
small improvements in filter script.
386d497
Add check for covmat, remove total uncertainty before procedural unce…
127822f
Change process type, fix typo in metadata
3bad329
change names of kinematic varibles from k1, k2, k3 to x, Q2, y.
96311ee
Add files containing the reimplemented variant of the uncertainties t…
79a0990
replace Q2bins6 by k2bins6.
720e8b2
add reimplemented uncertainties for HERA_NC300GEV.
ca03af7
fix labels in metadata, remove legacy variants.
peterkrack 89adf40
Merge branch 'master' into reimplement-HERA-datasets
peterkrack f05a592
fix typo in metadata.
peterkrack a3a958b
fix missing labels
peterkrack 87108f8
commondata test fail when importing validphys
peterkrack fcd4cda
remove import of covmat_is_close from filter scripts
peterkrack 4e7e907
remove covmat_is_close import from filter script.
peterkrack 63c3f5b
fix in metadata
peterkrack 0e6736a
clean up some files
peterkrack 895ce1c
set kinematics_override back to dis_sqrt_scale to fix plots.
peterkrack c778061
Merge branch 'master' into reimplement-HERA-datasets
peterkrack b33f457
fix metadata file for HERA_NC_318GEV.
peterkrack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
166 changes: 166 additions & 0 deletions
166
nnpdf_data/nnpdf_data/commondata/HERA_CC_318GEV/filter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
from pathlib import Path | ||
from dataclasses import dataclass | ||
import typing | ||
from typing import List | ||
import numpy as np | ||
import pandas as pd | ||
from os import PathLike | ||
from fortranformat import FortranRecordWriter | ||
import yaml | ||
|
||
@dataclass | ||
class commondata: | ||
central_values: np.ndarray | ||
kinematics: np.ndarray | ||
statistical_uncertainties: np.ndarray | ||
systematic_uncertainties: np.ndarray | ||
systypes: List[tuple[str, str]] | ||
process: str | ||
dataset_name: str | ||
kinematic_quantities: List[str] | ||
|
||
|
||
# Procedure to create data_*.yaml, kinematics_*.yaml and uncertainties_*.yaml | ||
def write_new_commondata(self, data_filename: str | PathLike, | ||
kinematics_filename: str | PathLike, | ||
uncertainties_filename: str | PathLike): | ||
# central data values | ||
data = {"data_central": self.central_values.tolist()} | ||
with data_filename.open("w+") as f: | ||
yaml.dump(data, f, default_flow_style=False, sort_keys=False) | ||
|
||
# kinematic quantieties | ||
# TODO add arrays for min and max values to derived type? | ||
bins = [] | ||
for kin in self.kinematics.tolist(): | ||
bins.append( | ||
{self.kinematic_quantities[0]: | ||
{ | ||
"min": None, | ||
"mid": kin[0], | ||
"max": None | ||
}, | ||
self.kinematic_quantities[1]: | ||
{ | ||
"min": None, | ||
"mid": kin[1], | ||
"max": None | ||
}, | ||
self.kinematic_quantities[2]: | ||
{ | ||
"min": None, | ||
"mid": kin[2], | ||
"max": None | ||
} | ||
}) | ||
data = {"bins": bins} | ||
with kinematics_filename.open("w+") as f: | ||
yaml.dump(data, f, default_flow_style=False, sort_keys=False) | ||
|
||
# uncertainties | ||
# There is only one statistical uncertainty per datapoint. | ||
definitions = {"stat": | ||
{ | ||
"description": "Statistical uncertainty.", | ||
"treatment": "ADD", | ||
"type": "UNCORR" | ||
} | ||
} | ||
for isys, sys in enumerate(self.systypes): | ||
definitions.update( | ||
{f"sys_corr_{isys}": | ||
{ | ||
"description": f"Systematic uncertainty {isys}", | ||
"treatment": sys[0], | ||
"type": sys[1] | ||
} | ||
}) | ||
bins = {"bins": [] } | ||
for i, _ in enumerate(self.central_values): | ||
systematics = {"stat": self.statistical_uncertainties.tolist()[i]} | ||
for isys, sys in enumerate(self.systematic_uncertainties[i].tolist()): | ||
systematics.update({f"sys_corr_{isys}": sys}) | ||
bins["bins"].append(systematics) | ||
data = {"definitions": definitions } | ||
# TODO Notation of reals is inconsistent from yaml.safe_dump | ||
# sometimes it is in scientific notation sometimes not... | ||
with uncertainties_filename.open("w+") as f: | ||
yaml.safe_dump(data, f, default_flow_style=False, sort_keys=False) | ||
yaml.safe_dump(bins, f, default_flow_style=False, sort_keys=False) | ||
|
||
|
||
|
||
|
||
|
||
# TODO: old commondata format stores the uncertainties as | ||
# both additive and multiplicative. | ||
def write_old_commondata(self, data_filename: str | PathLike, | ||
systype_filename: str | PathLike): | ||
with data_filename.open("w+") as f: | ||
f.write( | ||
f"{self.dataset_name} {len(self.systypes)} {len(self.central_values)} \n") | ||
FMT = "(I4,A10,"+str(3+1+1+len(self.systypes))+"E23.15)" | ||
print(FMT) | ||
line = FortranRecordWriter(FMT) | ||
for i in range(len(self.central_values)): | ||
l = ([i+1]+self.kinematics[i].tolist()+ | ||
[self.central_values[i].tolist()]+ | ||
[self.statistical_uncertainties[i].tolist()]+ | ||
self.systematic_uncertainties[i].tolist()) | ||
f.write(line.write(l)+"\n") | ||
|
||
@dataclass | ||
class hera_commondata(commondata): | ||
def __init__(self, filename: str | PathLike, dataset_name: str, | ||
process: str): | ||
# Read the data. | ||
file = Path(filename) | ||
df = pd.read_table(file, sep=r"\s+") | ||
|
||
# Kinematic quantieties. | ||
self.central_values = df["Sigma"].to_numpy() | ||
self.kinematics = df[["x", "Q2", "y"]].to_numpy() | ||
self.kinematic_quantities = ["x", "Q2", "y"] | ||
|
||
# Statistical uncertainties. | ||
statistical_uncertainties = df["stat"].to_numpy() | ||
for iunc,unc in enumerate(statistical_uncertainties): | ||
unc = self.central_values[iunc]*unc/100 | ||
statistical_uncertainties[iunc] = unc | ||
self.statistical_uncertainties = statistical_uncertainties | ||
|
||
# Systematic uncertainties. | ||
sys_uncert_col_names = list(df.columns.values)[5:] | ||
self.systematic_uncertainties = df[sys_uncert_col_names].to_numpy() | ||
systematic_uncertainties = df[sys_uncert_col_names].to_numpy() | ||
for iunc,unc in enumerate(systematic_uncertainties): | ||
unc = self.central_values[iunc]*unc/100 | ||
systematic_uncertainties[iunc] = unc | ||
self.systematic_uncertainties = systematic_uncertainties | ||
|
||
# All uncertainties are treated as multiplicative. | ||
systypes = [] | ||
for name in sys_uncert_col_names: | ||
if(name == "uncor"): | ||
systypes.append(("MULT", "UNCORR")) | ||
else: | ||
systypes.append(("MULT", "HC_" + name)) | ||
self.systypes = systypes | ||
self.process = process | ||
self.dataset_name = dataset_name | ||
|
||
def main(): | ||
print(" Reimplementing the HERA commondata") | ||
hera_em = hera_commondata("./rawdata/HERA1+2_CCem.dat","HERACOMBCCEM", "DIS_CCE") | ||
hera_em.write_new_commondata(Path("data_reimplemented_EM-SIGMARED.yaml"), | ||
Path("kinematics_reimplemented_EM-SIGMARED.yaml"), | ||
Path("uncertainties_reimplemented_EM-SIGMARED.yaml")) | ||
hera_ep = hera_commondata("./rawdata/HERA1+2_CCep.dat","HERACOMBCCEP", "DIS_CCE") | ||
hera_ep.write_new_commondata(Path("data_reimplemented_EP-SIGMARED.yaml"), | ||
Path("kinematics_reimplemented_EP-SIGMARED.yaml"), | ||
Path("uncertainties_reimplemented_EP-SIGMARED.yaml")) | ||
if __name__ == "__main__": | ||
main() | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the filters share similar or even identical parts, you can consider to place it in the
filter_utils
folder and store common parts there. For ex: