diff --git a/src/pinefarm/cli/autogen.py b/src/pinefarm/cli/autogen.py index 76a31a7..c850c0e 100644 --- a/src/pinefarm/cli/autogen.py +++ b/src/pinefarm/cli/autogen.py @@ -1,4 +1,4 @@ -"""Autogenerate pinecards from NNPDF metadata.""" +"""Autogenerate pinecardsfrom NNPDF metadata.""" import click import rich @@ -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_), 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") diff --git a/src/pinefarm/external/nnlojet/nnpdf_interface.py b/src/pinefarm/external/nnlojet/nnpdf_interface.py index 19e1833..7819081 100755 --- a/src/pinefarm/external/nnlojet/nnpdf_interface.py +++ b/src/pinefarm/external/nnlojet/nnpdf_interface.py @@ -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}") @@ -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