Skip to content

Commit

Permalink
Merge pull request #216 from NNPDF/fix-pineappl-xs
Browse files Browse the repository at this point in the history
Expose correct bins for XS
  • Loading branch information
felixhekhorn committed Aug 2, 2023
2 parents 6330a3b + 34ad49a commit ac0363b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/yadbox/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np

import yadism
from yadism import observable_name


def dump_pineappl_to_file(output, filename, obsname):
Expand Down Expand Up @@ -45,6 +46,8 @@ def dump_pineappl_to_file(output, filename, obsname):

grid = pineappl.grid.Grid.create(lumi_entries, orders, bin_limits, params)
limits = []
on = observable_name.ObservableName(obsname)
is_xs = on.kind in observable_name.xs

# add each ESF as a bin
for bin_, obs in enumerate(output[obsname]):
Expand All @@ -53,6 +56,8 @@ def dump_pineappl_to_file(output, filename, obsname):

limits.append((Q2, Q2))
limits.append((x, x))
if is_xs:
limits.append((obs.y, obs.y))

# add all orders
for o, (v, _e) in obs.orders.items():
Expand Down Expand Up @@ -92,6 +97,10 @@ def dump_pineappl_to_file(output, filename, obsname):
grid.set_key_value("x2_label", "x")
grid.set_key_value("x2_label_tex", "$x$")
grid.set_key_value("x2_unit", "")
if is_xs:
grid.set_key_value("x3_label", "y")
grid.set_key_value("x3_label_tex", "$y$")
grid.set_key_value("x3_unit", "")
grid.set_key_value("y_label", obsname)

# dump file
Expand Down
21 changes: 20 additions & 1 deletion tests/yadbox/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from yadmark.data.observables import default_card as obs_card


def test_pineappl(tmp_path: pathlib.Path):
def test_pineappl_sf(tmp_path: pathlib.Path):
pl = tmp_path / "light.pineappl.lz4"
oo = copy.deepcopy(obs_card)
oo["observables"] = {
Expand All @@ -27,3 +27,22 @@ def test_pineappl(tmp_path: pathlib.Path):
np.testing.assert_allclose(g.bin_left(k), g.bin_right(k))
np.testing.assert_allclose(g.bin_left(0), np.array([10.0]))
np.testing.assert_allclose(g.bin_left(1), np.array([0.1]))


def test_pineappl_xs(tmp_path: pathlib.Path):
pl = tmp_path / "light.pineappl.lz4"
oo = copy.deepcopy(obs_card)
oo["observables"] = {
"XSCHORUSCC": [{"x": 0.1, "Q2": 10.0, "y": 0.3}],
}
out = run_yadism(theory_card, oo)
dump_pineappl_to_file(out, pl, "XSCHORUSCC")
# try read
assert pl.exists()
g = pineappl.grid.Grid.read(pl)
assert g.bin_dimensions() == 3
for k in range(1 + 1):
np.testing.assert_allclose(g.bin_left(k), g.bin_right(k))
np.testing.assert_allclose(g.bin_left(0), np.array([10.0]))
np.testing.assert_allclose(g.bin_left(1), np.array([0.1]))
np.testing.assert_allclose(g.bin_left(2), np.array([0.3]))

0 comments on commit ac0363b

Please sign in to comment.