Skip to content

Commit

Permalink
add the option to select a subset of observables
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Nov 13, 2024
1 parent 4412890 commit 4473435
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
24 changes: 19 additions & 5 deletions src/pinefarm/cli/autogen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Autogenerate pinecards from NNPDF metadata."""
"""Autogenerate pinecardsfrom NNPDF metadata."""

import click
import rich
Expand All @@ -15,13 +15,27 @@
help="Target program. Currently only NNLOJET supported",
default="NNLOJET",
)
def runcards(dataset, target):
@click.option(
"--name", help="Name of the pinecard (NNLOJET_<name>), defaults to name=dataset"
)
@click.option(
"--select-obs",
help="Observables to select from the NNPDF available kinematics (max. 2D distributions)",
type=str,
nargs=2,
)
def runcards(dataset, target, select_obs=None, name=None):
"""Generate a runcard from an NNPDF dataset."""
output = configs.configs["paths"]["runcards"] / f"{target}_{dataset.upper()}"
if name is None:
name = dataset.upper()

output = configs.configs["paths"]["runcards"] / f"{target}_{name}"

if target == "NNLOJET":
output_runcards = generate_pinecard_from_nnpdf(dataset, output_path=output)
output_runcards = generate_pinecard_from_nnpdf(
dataset, output_path=output, observables=select_obs
)

rich.print("Runcards written to: ")
rich.print("Pinecards written to: ")
rich.print(" " + "\n".join(str(i) for i in output_runcards))
rich.print("metadata.txt might be empty or incomplete, please modifiy it manually")
23 changes: 20 additions & 3 deletions src/pinefarm/external/nnlojet/nnpdf_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _nnlojet_observable(observable, process):
return "ptz"
if process.upper().startswith("W"):
return "ptw"
if observable == "M" and process.upper().startswith("Z"):
if observable == "m" and process.upper().startswith("Z"):
return "mll"

raise ValueError(f"Observable {observable} not recognized for process {process}")
Expand Down Expand Up @@ -226,14 +226,31 @@ def _generate_nnlojet_pinecard(runname, process, energy, experiment, histograms)
return ret


def generate_pinecard_from_nnpdf(nnpdf_dataset, scale="mz", output_path="."):
"""Generate a NNLOJET pinecard from an NNPDF dataset."""
def generate_pinecard_from_nnpdf(
nnpdf_dataset, scale="mz", output_path=".", observables=None
):
"""Generate a NNLOJET pinecard from an NNPDF dataset.
Takes as input an NNPDF dataset, which will be loaded with the
nnpdf_data package.
If a list of observables is provided, only those in the list will be loaded
from the dataframe.
"""
# Load the NNPDF dataset
from validphys.api import API

commondata = API.commondata(dataset_input={"dataset": nnpdf_dataset})
metadata = commondata.metadata
kin_df = metadata.load_kinematics(drop_minmax=False)

if observables is not None:
# If a list of observables is provided, select them from the dataframe
# list in case they enter as a tuple
kin_df = kin_df.loc[:, list(observables)]

# Change some variable names:
kin_df.rename(columns={"m_ll2": "M2"}, inplace=True)
output_runcards = []

# Put all the information we might need in nicely organized variables
Expand Down

0 comments on commit 4473435

Please sign in to comment.