Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the toyFF and add tests #70

Merged
merged 5 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pytest = "^7.1.3"
pytest-cov = "4.0.0"
pylint = "^3.1.0"
pyfakefs = "^5.2.3"
scipy = "^1.11.1"

[tool.poetry.group.dev.dependencies]
pdbpp = "^0.10.3"
Expand Down
26 changes: 13 additions & 13 deletions src/banana/toy.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,22 @@ class toyFF_unpolarized(MockPDF):
"""ToyFF from 1501.00494, Eqn. 3.3 and 3.4"""

def __init__(self):
N_v = 0.401
N_s = 0.094
N_g = 0.238
N_v = 1.00881
N_s = 17.6255
N_g = 438.189

D_u = lambda x: N_v * x ** (-0.963) * (1 - x) ** 1.370
D_ub = lambda x: N_s * x**0.718 * (1 - x) ** 6.266
D_g = lambda x: N_g * x**1.943 * (1 - x) ** 8
xD_u = lambda x: x * N_v * x ** (-0.963) * (1 - x) ** 1.370
xD_ub = lambda x: x * N_s * x**0.718 * (1 - x) ** 6.266
xD_g = lambda x: x * N_g * x**1.943 * (1 - x) ** 8

self.xpdf = {}
self.xpdf[-3] = D_ub
self.xpdf[-2] = D_ub
self.xpdf[-1] = D_u
self.xpdf[0] = D_g
self.xpdf[1] = D_ub
self.xpdf[2] = D_u
self.xpdf[3] = D_ub
self.xpdf[-3] = xD_ub
self.xpdf[-2] = xD_ub
self.xpdf[-1] = xD_u
self.xpdf[0] = xD_g
self.xpdf[1] = xD_ub
self.xpdf[2] = xD_u
self.xpdf[3] = xD_ub
self.xpdf[21] = self.xpdf[0]
self.name = "ToyFF_unpolarized"

Expand Down
16 changes: 16 additions & 0 deletions tests/test_toy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import numpy as np
from scipy.integrate import quad

from banana import toy

pdf = toy.mkPDF("", 0)
Expand All @@ -24,3 +27,16 @@ def test_xf():
for x in [0.1, 0.2]:
assert pdf.xfxQ2(pid, x, Q2) == pdf.xfxQ(pid, x, Q2)
assert pdf.xfxQ2(pid, 2, Q2) == 0


def test_toyFF():
"""Test the ToyFF_unpolarized with Eqn. 3.4 from 1501.00494."""
ff = toy.mkPDF("ToyFF_unpolarized", 0)

val_u = quad(lambda x: ff.xfxQ2(2, x, 1), 0, 1)[0]
val_d = quad(lambda x: ff.xfxQ2(1, x, 1), 0, 1)[0]
val_g = quad(lambda x: ff.xfxQ2(21, x, 1), 0, 1)[0]

np.testing.assert_allclose(val_u, 0.401, atol=1e-4)
np.testing.assert_allclose(val_d, 0.094, atol=1e-4)
np.testing.assert_allclose(val_g, 0.238, atol=1e-4)
Loading