Skip to content

Commit

Permalink
adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomomagni committed May 3, 2024
1 parent 67cf374 commit c6f78bb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/yadism/coefficient_functions/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ def cc_weights_odd(coupling_constants, Q2, cc_mask, nf, is_pv):
tot_ch_sq += w
# add valence
for q in weights["ns"]:
weights["v"][q] = tot_ch_sq / norm / 2
weights["v"][-q] = -tot_ch_sq / norm / 2
weights["v"][sign * q] = tot_ch_sq / norm / 2
weights["v"][-sign * q] = -tot_ch_sq / norm / 2
return weights


Expand Down
103 changes: 56 additions & 47 deletions tests/yadism/cf/test_cc_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from yadism.coefficient_functions.heavy import kernels as hker
from yadism.coefficient_functions.light import kernels as lker

from .test_nc_kernels import check, mkpids
from .test_nc_kernels import mkpc as mkpc_even
from .test_nc_kernels import mkpv as mkpv_odd


class MockCouplingConstants:
def __init__(self, projectilePID):
Expand Down Expand Up @@ -32,65 +36,70 @@ def __init__(self, n, projectilePID):

class MockESF:
def __init__(self, sf, projectilePID, x, Q2):
self.sf = MockSF(sf, projectilePID)
self.info = MockSF(sf, projectilePID)
self.x = x
self.Q2 = Q2
self.process = "CC"


def mkpids(nf, sgn):
"""-+1, +-2, -+3, ... +-nf"""
return [(-1) ** (j + (0 if sgn else 1)) * j for j in range(1, nf + 1)]


def mkpc(nf, w, sgn): # pc = parity conserving
return dict(zip(mkpids(nf, sgn), [w] * nf))


def mkpv(nf, w, sgn): # pv = parity violating
def mkpc_odd(nf, w, sgn): # pc = parity conserving
return dict(
zip(mkpids(nf, sgn), [(-1) ** (j + (1 if sgn else 0)) * w for j in range(nf)])
zip(
mkpids(nf),
[(-1) ** (j + (1 if not sgn else 0)) * w for j in range(nf)]
+ [(-1) ** (j + (1 if sgn else 0)) * w for j in range(nf)],
)
)


def mksinglet(nf, w):
return dict(zip([i for i in range(-nf, nf + 1) if i != 0], [w] * (2 * nf)))


def check(ps, w):
assert len(w) == len(ps)
for e, k in zip(ps, w):
assert pytest.approx(e) == k.partons


# def test_generate_light_pc():
# for sgn in [True, False]:
# esf = MockESF("F2_light", 11 * (1 if sgn else -1), 0.1, 10)
# for nf in [3, 4, 5]:
# w = lker.generate(esf, nf)
# norm = {3: 1, 4: 3, 5: 7}[nf]
# # q, g
# ps = [
# mkpc(nf, norm, sgn),
# {21: (nf + 1) * norm / nf / 2.0},
# mksinglet(nf, (nf + 1) * norm / nf / 2.0),
# ]
# check(ps, w)
def mkpv_even(nf, w, sgn): # pv = parity violating
return dict(
zip(
mkpids(nf),
[(-1) ** (j + (1 if sgn else 0)) * w for j in range(nf)]
+ [(-1) ** (j + (1 if sgn else 0)) * w for j in range(nf)],
)
)

def mkpv_valence(nf, w): # pv = parity violating
return dict(
zip(
mkpids(nf),
[(-1) ** (j + 1) * w for j in range(nf)]
+ [(-1) ** (j) * w for j in range(nf)],
)
)

# def test_generate_light_pv():
# for sgn in [True, False]:
# esf = MockESF("F3_light", 11 * (1 if sgn else -1), 0.1, 10)
# for nf in [3, 4, 5]:
# w = lker.generate(esf, nf)
# norm = {3: 1, 4: 3, 5: 7}[nf]
# # q, g
# ps = [
# mkpv(nf, norm, sgn),
# {21: (-1 if sgn else 1) * (nf + 1) * norm / nf / 2.0},
# mksinglet(nf, (-1 if sgn else 1) * (nf + 1) * norm / nf / 2.0),
# ]
# check(ps, w)
def test_generate_light_pc():
for sgn in [True, False]:
esf = MockESF("F2_light", 11 * (1 if sgn else -1), 0.1, 10)
for nf in [3, 5]:
w = lker.generate(esf, nf)
norm = {3: 1, 4: 3, 5: 7}[nf]
# q, g
ps = [
mkpc_even(nf, 0.5 * norm),
{21: (nf + 1) * norm / nf / 2.0},
mkpc_even(nf, (nf + 1) * norm / nf / 2.0),
mkpc_odd(nf, 0.5 * norm, sgn),
]
check(ps, w)


def test_generate_light_pv():
for sgn in [True, False]:
esf = MockESF("F3_light", 11 * (1 if sgn else -1), 0.1, 10)
for nf in [3, 5]:
w = lker.generate(esf, nf)
norm = {3: 1, 4: 3, 5: 7}[nf]
# q, g
ps = [
mkpv_even(nf, 0.5 * norm, sgn),
mkpv_odd(nf, 0.5 * norm),
mkpv_valence(nf, (nf + 1) * norm / nf / 2.0),
]
check(ps, w)


# def test_generate_heavy_pc():
Expand Down

0 comments on commit c6f78bb

Please sign in to comment.