diff --git a/nnpdf31_proc/NNPDF_POS_ANTI_DOWN_40/metadata.txt b/nnpdf31_proc/NNPDF_POS_ANTI_DOWN_40/metadata.txt new file mode 100644 index 00000000..d2058577 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_ANTI_DOWN_40/metadata.txt @@ -0,0 +1,10 @@ +description=Anti-down quark positivity +x1_label=Q2 +x1_label_tex=$Q^2$ +x1_unit=GeV^2 +x2_label=x +x2_label_tex=$x$ +x2_unit= +y_label=xfx +y_label_tex=$xf(x)$ +y_unit= diff --git a/nnpdf31_proc/NNPDF_POS_ANTI_DOWN_40/positivity.yaml b/nnpdf31_proc/NNPDF_POS_ANTI_DOWN_40/positivity.yaml new file mode 100644 index 00000000..9cab05d8 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_ANTI_DOWN_40/positivity.yaml @@ -0,0 +1,25 @@ +hadron_pid: 2212 +lepton_pid: 11 +pid: -1 +q2: 5.0 +xgrid: + - 4.9999999999999998e-07 + - 1.9407667236782136e-06 + - 7.5331509514733370e-06 + - 2.9240177382128657e-05 + - 1.1349672651536727e-04 + - 4.4054134013486355e-04 + - 1.7099759466766963e-03 + - 6.6373288312005724e-03 + - 2.5763013859408150e-02 + - 1.0000000000000001e-01 + - 1.7999999999999999e-01 + - 2.6000000000000001e-01 + - 3.3999999999999997e-01 + - 4.2000000000000004e-01 + - 5.0000000000000000e-01 + - 5.7999999999999996e-01 + - 6.6000000000000003e-01 + - 7.3999999999999999e-01 + - 8.1999999999999995e-01 + - 9.0000000000000002e-01 diff --git a/nnpdf31_proc/NNPDF_POS_ANTI_STRANGE_40/metadata.txt b/nnpdf31_proc/NNPDF_POS_ANTI_STRANGE_40/metadata.txt new file mode 100644 index 00000000..f6fd0349 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_ANTI_STRANGE_40/metadata.txt @@ -0,0 +1,10 @@ +description=Anti-strange quark positivity +x1_label=Q2 +x1_label_tex=$Q^2$ +x1_unit=GeV^2 +x2_label=x +x2_label_tex=$x$ +x2_unit= +y_label=xfx +y_label_tex=$xf(x)$ +y_unit= diff --git a/nnpdf31_proc/NNPDF_POS_ANTI_STRANGE_40/positivity.yaml b/nnpdf31_proc/NNPDF_POS_ANTI_STRANGE_40/positivity.yaml new file mode 100644 index 00000000..b43cdd24 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_ANTI_STRANGE_40/positivity.yaml @@ -0,0 +1,25 @@ +hadron_pid: 2212 +lepton_pid: 11 +pid: -3 +q2: 5.0 +xgrid: + - 4.9999999999999998e-07 + - 1.9407667236782136e-06 + - 7.5331509514733370e-06 + - 2.9240177382128657e-05 + - 1.1349672651536727e-04 + - 4.4054134013486355e-04 + - 1.7099759466766963e-03 + - 6.6373288312005724e-03 + - 2.5763013859408150e-02 + - 1.0000000000000001e-01 + - 1.7999999999999999e-01 + - 2.6000000000000001e-01 + - 3.3999999999999997e-01 + - 4.2000000000000004e-01 + - 5.0000000000000000e-01 + - 5.7999999999999996e-01 + - 6.6000000000000003e-01 + - 7.3999999999999999e-01 + - 8.1999999999999995e-01 + - 9.0000000000000002e-01 diff --git a/nnpdf31_proc/NNPDF_POS_ANTI_UP_40/metadata.txt b/nnpdf31_proc/NNPDF_POS_ANTI_UP_40/metadata.txt new file mode 100644 index 00000000..b30bff90 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_ANTI_UP_40/metadata.txt @@ -0,0 +1,10 @@ +description=Anti-up quark positivity +x1_label=Q2 +x1_label_tex=$Q^2$ +x1_unit=GeV^2 +x2_label=x +x2_label_tex=$x$ +x2_unit= +y_label=xfx +y_label_tex=$xf(x)$ +y_unit= diff --git a/nnpdf31_proc/NNPDF_POS_ANTI_UP_40/positivity.yaml b/nnpdf31_proc/NNPDF_POS_ANTI_UP_40/positivity.yaml new file mode 100644 index 00000000..afd7be39 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_ANTI_UP_40/positivity.yaml @@ -0,0 +1,25 @@ +hadron_pid: 2212 +lepton_pid: 11 +pid: -2 +q2: 5.0 +xgrid: + - 4.9999999999999998e-07 + - 1.9407667236782136e-06 + - 7.5331509514733370e-06 + - 2.9240177382128657e-05 + - 1.1349672651536727e-04 + - 4.4054134013486355e-04 + - 1.7099759466766963e-03 + - 6.6373288312005724e-03 + - 2.5763013859408150e-02 + - 1.0000000000000001e-01 + - 1.7999999999999999e-01 + - 2.6000000000000001e-01 + - 3.3999999999999997e-01 + - 4.2000000000000004e-01 + - 5.0000000000000000e-01 + - 5.7999999999999996e-01 + - 6.6000000000000003e-01 + - 7.3999999999999999e-01 + - 8.1999999999999995e-01 + - 9.0000000000000002e-01 diff --git a/nnpdf31_proc/NNPDF_POS_CHARM_40/metadata.txt b/nnpdf31_proc/NNPDF_POS_CHARM_40/metadata.txt new file mode 100644 index 00000000..d09c5f93 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_CHARM_40/metadata.txt @@ -0,0 +1,10 @@ +description=Charm quark positivity +x1_label=Q2 +x1_label_tex=$Q^2$ +x1_unit=GeV^2 +x2_label=x +x2_label_tex=$x$ +x2_unit= +y_label=xfx +y_label_tex=$xf(x)$ +y_unit= diff --git a/nnpdf31_proc/NNPDF_POS_CHARM_40/positivity.yaml b/nnpdf31_proc/NNPDF_POS_CHARM_40/positivity.yaml new file mode 100644 index 00000000..fdee4a31 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_CHARM_40/positivity.yaml @@ -0,0 +1,25 @@ +hadron_pid: 2212 +lepton_pid: 11 +pid: 4 +q2: 5.0 +xgrid: + - 4.9999999999999998e-07 + - 1.9407667236782136e-06 + - 7.5331509514733370e-06 + - 2.9240177382128657e-05 + - 1.1349672651536727e-04 + - 4.4054134013486355e-04 + - 1.7099759466766963e-03 + - 6.6373288312005724e-03 + - 2.5763013859408150e-02 + - 1.0000000000000001e-01 + - 1.7999999999999999e-01 + - 2.6000000000000001e-01 + - 3.3999999999999997e-01 + - 4.2000000000000004e-01 + - 5.0000000000000000e-01 + - 5.7999999999999996e-01 + - 6.6000000000000003e-01 + - 7.3999999999999999e-01 + - 8.1999999999999995e-01 + - 9.0000000000000002e-01 diff --git a/nnpdf31_proc/NNPDF_POS_DOWN_40/metadata.txt b/nnpdf31_proc/NNPDF_POS_DOWN_40/metadata.txt new file mode 100644 index 00000000..173d291e --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_DOWN_40/metadata.txt @@ -0,0 +1,10 @@ +description=Down quark positivity +x1_label=Q2 +x1_label_tex=$Q^2$ +x1_unit=GeV^2 +x2_label=x +x2_label_tex=$x$ +x2_unit= +y_label=xfx +y_label_tex=$xf(x)$ +y_unit= diff --git a/nnpdf31_proc/NNPDF_POS_DOWN_40/positivity.yaml b/nnpdf31_proc/NNPDF_POS_DOWN_40/positivity.yaml new file mode 100644 index 00000000..3d8901c7 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_DOWN_40/positivity.yaml @@ -0,0 +1,25 @@ +hadron_pid: 2212 +lepton_pid: 11 +pid: 1 +q2: 5.0 +xgrid: + - 4.9999999999999998e-07 + - 1.9407667236782136e-06 + - 7.5331509514733370e-06 + - 2.9240177382128657e-05 + - 1.1349672651536727e-04 + - 4.4054134013486355e-04 + - 1.7099759466766963e-03 + - 6.6373288312005724e-03 + - 2.5763013859408150e-02 + - 1.0000000000000001e-01 + - 1.7999999999999999e-01 + - 2.6000000000000001e-01 + - 3.3999999999999997e-01 + - 4.2000000000000004e-01 + - 5.0000000000000000e-01 + - 5.7999999999999996e-01 + - 6.6000000000000003e-01 + - 7.3999999999999999e-01 + - 8.1999999999999995e-01 + - 9.0000000000000002e-01 diff --git a/nnpdf31_proc/NNPDF_POS_GLUON_40/metadata.txt b/nnpdf31_proc/NNPDF_POS_GLUON_40/metadata.txt new file mode 100644 index 00000000..49a0dc72 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_GLUON_40/metadata.txt @@ -0,0 +1,10 @@ +description=Gluon positivity +x1_label=Q2 +x1_label_tex=$Q^2$ +x1_unit=GeV^2 +x2_label=x +x2_label_tex=$x$ +x2_unit= +y_label=xfx +y_label_tex=$xf(x)$ +y_unit= diff --git a/nnpdf31_proc/NNPDF_POS_GLUON_40/positivity.yaml b/nnpdf31_proc/NNPDF_POS_GLUON_40/positivity.yaml new file mode 100644 index 00000000..e2316324 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_GLUON_40/positivity.yaml @@ -0,0 +1,25 @@ +hadron_pid: 2212 +lepton_pid: 11 +pid: 21 +q2: 5.0 +xgrid: + - 4.9999999999999998e-07 + - 1.9407667236782136e-06 + - 7.5331509514733370e-06 + - 2.9240177382128657e-05 + - 1.1349672651536727e-04 + - 4.4054134013486355e-04 + - 1.7099759466766963e-03 + - 6.6373288312005724e-03 + - 2.5763013859408150e-02 + - 1.0000000000000001e-01 + - 1.7999999999999999e-01 + - 2.6000000000000001e-01 + - 3.3999999999999997e-01 + - 4.2000000000000004e-01 + - 5.0000000000000000e-01 + - 5.7999999999999996e-01 + - 6.6000000000000003e-01 + - 7.3999999999999999e-01 + - 8.1999999999999995e-01 + - 9.0000000000000002e-01 diff --git a/nnpdf31_proc/NNPDF_POS_STRANGE_40/metadata.txt b/nnpdf31_proc/NNPDF_POS_STRANGE_40/metadata.txt new file mode 100644 index 00000000..8128fd74 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_STRANGE_40/metadata.txt @@ -0,0 +1,10 @@ +description=Strange quark positivity +x1_label=Q2 +x1_label_tex=$Q^2$ +x1_unit=GeV^2 +x2_label=x +x2_label_tex=$x$ +x2_unit= +y_label=xfx +y_label_tex=$xf(x)$ +y_unit= diff --git a/nnpdf31_proc/NNPDF_POS_STRANGE_40/positivity.yaml b/nnpdf31_proc/NNPDF_POS_STRANGE_40/positivity.yaml new file mode 100644 index 00000000..d42357a8 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_STRANGE_40/positivity.yaml @@ -0,0 +1,25 @@ +hadron_pid: 2212 +lepton_pid: 11 +pid: 3 +q2: 5.0 +xgrid: + - 4.9999999999999998e-07 + - 1.9407667236782136e-06 + - 7.5331509514733370e-06 + - 2.9240177382128657e-05 + - 1.1349672651536727e-04 + - 4.4054134013486355e-04 + - 1.7099759466766963e-03 + - 6.6373288312005724e-03 + - 2.5763013859408150e-02 + - 1.0000000000000001e-01 + - 1.7999999999999999e-01 + - 2.6000000000000001e-01 + - 3.3999999999999997e-01 + - 4.2000000000000004e-01 + - 5.0000000000000000e-01 + - 5.7999999999999996e-01 + - 6.6000000000000003e-01 + - 7.3999999999999999e-01 + - 8.1999999999999995e-01 + - 9.0000000000000002e-01 diff --git a/nnpdf31_proc/NNPDF_POS_UP_40/metadata.txt b/nnpdf31_proc/NNPDF_POS_UP_40/metadata.txt new file mode 100644 index 00000000..64bdc173 --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_UP_40/metadata.txt @@ -0,0 +1,10 @@ +description=Up-quark positivity +x1_label=Q2 +x1_label_tex=$Q^2$ +x1_unit=GeV^2 +x2_label=x +x2_label_tex=$x$ +x2_unit= +y_label=xfx +y_label_tex=$xf(x)$ +y_unit= diff --git a/nnpdf31_proc/NNPDF_POS_UP_40/positivity.yaml b/nnpdf31_proc/NNPDF_POS_UP_40/positivity.yaml new file mode 100644 index 00000000..e5646a9e --- /dev/null +++ b/nnpdf31_proc/NNPDF_POS_UP_40/positivity.yaml @@ -0,0 +1,25 @@ +hadron_pid: 2212 +lepton_pid: 11 +pid: 2 +q2: 5.0 +xgrid: + - 4.9999999999999998e-07 + - 1.9407667236782136e-06 + - 7.5331509514733370e-06 + - 2.9240177382128657e-05 + - 1.1349672651536727e-04 + - 4.4054134013486355e-04 + - 1.7099759466766963e-03 + - 6.6373288312005724e-03 + - 2.5763013859408150e-02 + - 1.0000000000000001e-01 + - 1.7999999999999999e-01 + - 2.6000000000000001e-01 + - 3.3999999999999997e-01 + - 4.2000000000000004e-01 + - 5.0000000000000000e-01 + - 5.7999999999999996e-01 + - 6.6000000000000003e-01 + - 7.3999999999999999e-01 + - 8.1999999999999995e-01 + - 9.0000000000000002e-01 diff --git a/runcardsrunner/cli/run.py b/runcardsrunner/cli/run.py index a3475dd7..93e7b44a 100644 --- a/runcardsrunner/cli/run.py +++ b/runcardsrunner/cli/run.py @@ -7,7 +7,7 @@ import yaml from .. import install, log, table, tools -from ..external import mg5, yad +from ..external import mg5, positivity, yad from ._base import command @@ -62,11 +62,17 @@ def main(dataset, theory, pdf): rich.print(dataset) if yad.is_dis(dataset): - rich.print(f"Computing [red]{dataset}[/]...") - runner = yad.Yadism(dataset, theory, pdf, timestamp=timestamp) + color = "red" + external = yad.Yadism + elif positivity.is_positivity(dataset): + color = "yellow" + external = positivity.Positivity else: - rich.print(f"Computing [blue]{dataset}[/]...") - runner = mg5.Mg5(dataset, theory, pdf, timestamp=timestamp) + color = "blue" + external = mg5.Mg5 + + rich.print(f"Computing [{color}]{dataset}[/]...") + runner = external(dataset, theory, pdf, timestamp=timestamp) install_reqs(runner, pdf) run_dataset(runner) diff --git a/runcardsrunner/external/positivity.py b/runcardsrunner/external/positivity.py new file mode 100644 index 00000000..985ae79e --- /dev/null +++ b/runcardsrunner/external/positivity.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +import json + +import lhapdf +import numpy as np +import pandas as pd +import pineappl +import yaml + +from .. import paths +from . import interface + + +def is_positivity(name): + """ + Is this a positivity dataset? + + The decision is based on the existance of the `positivity.yaml` file. + + Parameters + ---------- + name : str + dataset name + """ + return (paths.runcards / name / "positivity.yaml").exists() + + +class Positivity(interface.External): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def run(self): + with open(paths.runcards / self.name / "positivity.yaml") as o: + self.runcard = yaml.safe_load(o) + + def generate_pineappl(self): + self.xgrid = self.runcard['xgrid'] + self.lepton_pid = self.runcard['lepton_pid'] + self.pid = self.runcard['pid'] + self.q2 = self.runcard['q2'] + self.hadron_pid = self.runcard['hadron_pid'] + + # init pineappl objects + lumi_entries = [pineappl.lumi.LumiEntry([(self.pid, self.lepton_pid, 1.0)])] + orders = [pineappl.grid.Order(0, 0, 0, 0)] + bins = len(self.xgrid) + bin_limits = list(map(float, range(0, bins + 1))) + # subgrid params - default is just sufficient + params = pineappl.subgrid.SubgridParams() + # inti grid + grid = pineappl.grid.Grid.create(lumi_entries, orders, bin_limits, params) + limits = [] + # add each point as a bin + for bin_, x in enumerate(self.xgrid): + # keep DIS bins + limits.append((self.q2, self.q2)) + limits.append((x, x)) + # delta function + array = np.zeros(len(self.xgrid)) + array[bin_] = x + # create and set + subgrid = pineappl.import_only_subgrid.ImportOnlySubgridV1( + array[np.newaxis, :, np.newaxis], + [self.q2], + self.xgrid, + [1.0], + ) + grid.set_subgrid(0, bin_, 0, subgrid) + # set the correct observables + normalizations = [1.0] * bins + remapper = pineappl.bin.BinRemapper(normalizations, limits) + grid.set_remapper(remapper) + + # set the initial state PDF ids for the grid + grid.set_key_value("initial_state_1", str(self.hadron_pid)) + grid.set_key_value("initial_state_2", str(self.lepton_pid)) + grid.set_key_value("runcard", json.dumps(self.runcard)) + grid.set_key_value("lumi_id_types", "pdg_mc_ids") + grid.optimize() + grid.write(str(self.grid)) + + + def results(self): + pdf = lhapdf.mkPDF(self.pdf) + d = { + 'result': [pdf.xfxQ2(self.pid, x, self.q2) for x in self.xgrid], + 'error': [1e-15] * len(self.xgrid), + 'sv_min': [np.amin([pdf.xfxQ2(self.pid, x, 0.25 * self.q2), pdf.xfxQ2(self.pid, x, self.q2), pdf.xfxQ2(self.pid, x, 4.0 * self.q2)]) for x in self.xgrid], + 'sv_max': [np.amax([pdf.xfxQ2(self.pid, x, 0.25 * self.q2), pdf.xfxQ2(self.pid, x, self.q2), pdf.xfxQ2(self.pid, x, 4.0 * self.q2)]) for x in self.xgrid], + } + results = pd.DataFrame(data=d) + + return results + + def collect_versions(self): + return {} diff --git a/runcardsrunner/table.py b/runcardsrunner/table.py index 3a279d24..3a988727 100644 --- a/runcardsrunner/table.py +++ b/runcardsrunner/table.py @@ -65,7 +65,7 @@ def print_table(pineappl_results, external_results, dest): comparison["PineAPPL"] = pineappl_results["integ"] comparison["MC"] = external_results["result"] comparison["sigma 1/100"] = ( - external_results["error"] / external_results["result"] * 1e2 + external_results["error"] / abs(external_results["result"]) * 1e2 ) # ratios