Skip to content

Commit

Permalink
g1f1 polarized flag fix and kfactors
Browse files Browse the repository at this point in the history
  • Loading branch information
toonhasenack committed Dec 11, 2023
1 parent 0d43d7b commit 359b37d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 180 deletions.
149 changes: 0 additions & 149 deletions data/kfactors/generate.py

This file was deleted.

15 changes: 8 additions & 7 deletions data/kfactors/generate_g1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import List, Tuple


def get_prediction(folder: str, pdf_name: str) -> np.ndarray:
def get_prediction(folder: str) -> np.ndarray:
"""
Get predictions by convoluting a PineAPPL grid with a LHAPDF PDF.
Expand Down Expand Up @@ -79,16 +79,13 @@ def save_data(
)

os.makedirs(output_name, exist_ok=True)
dataset_name = list(dataset_name)
dataset_name[-2] = "G"
dataset_name = "".join(dataset_name)
with open(output_name + f"/CF_NRM_{dataset_name}.dat", "w") as file:
with open(output_name + f"/CF_NRM_{dataset_name}_G1.dat", "w") as file:
file.write(string)


# Create an argument parser
parser = argparse.ArgumentParser()
parser.add_argument("folder", help="The folder name of the F1 pineapple grids")
parser.add_argument("folder", help="The folder name of the commondata set")
parser.add_argument("--author", help="The name of the author", default="A.J. Hasenack")
parser.add_argument(
"--theory", help="The theory used, formatted as 'theory_'+int", default="theory_800"
Expand All @@ -102,6 +99,10 @@ def save_data(
theory = args.theory
output = args.output

dataset_name = os.path.splitext(
os.path.splitext(os.path.basename(os.path.normpath(folder_name)))[0]
)[0]

# Get predictions and save data
data = get_prediction(folder_name)
save_data(data, folder_name, author, theory, output)
save_data(data, dataset_name, author, theory, output)
37 changes: 13 additions & 24 deletions data/kfactors/generate_g1f1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
from typing import List, Tuple


def get_gpaths(folder: str) -> Tuple[str, List[str]]:
def get_gpaths(folder: str, data: str) -> Tuple[str, List[str]]:
"""
Get a list of paths to PineAPPL grids in the specified folder.
Parameters
----------
folder : str
The folder path where PineAPPL grids are located.
data : str
Name of the commondata set.
Returns
-------
Expand All @@ -24,15 +26,15 @@ def get_gpaths(folder: str) -> Tuple[str, List[str]]:
gpaths : List[str]
List of paths to PineAPPL grid files.
"""
paths = glob(folder + "/*F1*") # Find grids with "_F1" in the filename
paths = glob(folder + f"/*{data}*F1*") # Find the grids
gpaths = []
for p in paths:
gpaths.append(glob(p + "/*.pineappl.lz4")[0])
print(f"Found {len(gpaths)} pineapple grids.")
return gpaths


def get_prediction(gpath: str, pdf_name: str, target: str) -> np.ndarray:
def get_prediction(gpath: str, pdf_name: str) -> np.ndarray:
"""
Get predictions by convoluting a PineAPPL grid with a LHAPDF PDF.
Expand All @@ -54,13 +56,8 @@ def get_prediction(gpath: str, pdf_name: str, target: str) -> np.ndarray:
# Load the LHAPDF
pdf = lhapdf.mkPDF(pdf_name)

# Make case distinction for target cases
if target == "proton":
nr = 2212
elif target == "neutron":
nr = 2112
else:
pass
# Proton reference number
nr = 2212

# Perform the convolution
prediction = grid.convolute_with_one(
Expand Down Expand Up @@ -117,11 +114,7 @@ def save_data(
"""
+ strf_data
)

os.makedirs(output_name, exist_ok=True)
dataset_name = list(dataset_name)
dataset_name[-2] = "G"
dataset_name = "".join(dataset_name)
dataset_name += "_G1"
with open(output_name + f"/CF_NRM_{dataset_name}.dat", "w") as file:
file.write(string)

Expand All @@ -130,7 +123,7 @@ def save_data(
parser = argparse.ArgumentParser()
parser.add_argument("pdf", help="The name of the PDF dataset of LHAPDF")
parser.add_argument("folder", help="The folder name of the F1 pineapple grids")
parser.add_argument("target", help="Add the target type")
parser.add_argument("data", help="Name of the commondata set")
parser.add_argument("--author", help="The name of the author", default="A.J. Hasenack")
parser.add_argument(
"--theory", help="The theory used, formatted as 'theory_'+int", default="theory_800"
Expand All @@ -141,20 +134,16 @@ def save_data(
# Extract command line arguments
pdf_name = args.pdf
folder_name = args.folder
target = args.target
data = args.data
author = args.author
theory = args.theory
output = args.output

# Get PineAPPL grid paths and PDF name
gpaths = get_gpaths(folder_name)
gpaths = get_gpaths(folder_name, data)

# Process each PineAPPL grid
for gpath in gpaths:
dataset_name = os.path.splitext(
os.path.splitext(os.path.basename(os.path.normpath(gpath)))[0]
)[0]

# Get predictions and save data
data = get_prediction(gpath, pdf_name, target)
save_data(data, dataset_name, pdf_name, author, theory, output)
df = get_prediction(gpath, pdf_name)
save_data(df, data, pdf_name, author, theory, output)
2 changes: 2 additions & 0 deletions src/pineko/scale_variations.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def construct_and_dump_order_exists_grid(ori_grid, to_construct_order):
remap_obj = pineappl.bin.BinRemapper(norma, limits)
new_grid.set_remapper(remap_obj)
new_grid.set_key_value("initial_state_2", ori_grid.key_values()["initial_state_2"])
if "polarized" in ori_grid.key_values():
new_grid.set_key_value("polarized", ori_grid.key_values()["polarized"])
return new_grid


Expand Down

0 comments on commit 359b37d

Please sign in to comment.