Skip to content

Commit 2faed55

Browse files
Add tests to check merging of orders
1 parent 0c06d59 commit 2faed55

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

pineappl_py/tests/test_grid.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,80 @@ def test_fix_convolution(
600600
expected_results,
601601
)
602602

603+
def test_fix_convolution_dis(self, fake_grids, pdf):
604+
channels = [Channel([([i], 0.1)]) for i in range(-5, 5)]
605+
606+
g = fake_grids.grid_with_generic_convolution(
607+
nb_convolutions=1,
608+
channels=channels,
609+
orders=ORDERS,
610+
convolutions=[CONVOBJECT],
611+
)
612+
613+
with pytest.raises(BaseException) as err_func:
614+
g.fix_convolution(conv_idx=0, xfx=pdf.unpolarized_pdf)
615+
assert "cannot fix the last convolution" in str(err_func.value)
616+
617+
def test_fix_convolution_wrong_index(self, fake_grids, pdf):
618+
channels = [Channel([([i, -i], 0.1)]) for i in range(-5, 5)]
619+
620+
g = fake_grids.grid_with_generic_convolution(
621+
nb_convolutions=2,
622+
channels=channels,
623+
orders=ORDERS,
624+
convolutions=[CONVOBJECT, CONVOBJECT],
625+
)
626+
627+
with pytest.raises(BaseException) as err_func:
628+
g.fix_convolution(conv_idx=4, xfx=pdf.unpolarized_pdf)
629+
assert "convolution index 4 out of bounds (max: 1)" in str(err_func.value)
630+
631+
def test_fix_convolution_logxia(self, fake_grids, pdf):
632+
rndgen = Generator(PCG64(seed=1234))
633+
binning = [1e-2, 1e-1, 0.5, 1]
634+
635+
channels = [Channel([([i, -i, i], 0.1)]) for i in range(-5, 5)]
636+
orders = [Order(2, 0, 0, 0, 0), Order(2, 0, 0, 0, 1)]
637+
638+
convbools = [(False, False), (False, False), (False, True)]
639+
hpids = [2212, 2212, 211]
640+
convtypes = [ConvType(polarized=p, time_like=t) for p, t in convbools]
641+
convolutions = [
642+
Conv(convolution_types=c, pid=p) for c, p in zip(convtypes, hpids)
643+
]
644+
645+
g = fake_grids.grid_with_generic_convolution(
646+
nb_convolutions=len(convolutions),
647+
channels=channels,
648+
orders=orders,
649+
convolutions=convolutions,
650+
bins=binning,
651+
)
652+
653+
# Fill with non-empty subgrids
654+
_q2grid = np.geomspace(1e3, 1e5, 5)
655+
_xgrid = np.geomspace(1e-5, 1, 4)
656+
comb_nodes = [_q2grid] + [_xgrid for _ in convolutions]
657+
ntuples = [np.array(list(kins)) for kins in itertools.product(*comb_nodes)]
658+
obs = [rndgen.uniform(binning[0], binning[-1]) for _ in ntuples]
659+
for pto in range(len(ORDERS)):
660+
for channel_id in range(len(channels)):
661+
g.fill_array(
662+
order=pto,
663+
observables=obs,
664+
channel=channel_id,
665+
ntuples=ntuples,
666+
weights=np.repeat(1, len(obs)),
667+
)
668+
669+
# Fix the Fragmentation Function
670+
g_fix = g.fix_convolution(conv_idx=2, xfx=pdf.ff_set)
671+
orders_fix = g_fix.orders()
672+
673+
# Check that the orders have been merged
674+
assert len(orders_fix) == 1
675+
assert orders_fix[0].as_tuple() == (2, 0, 0, 0, 0)
676+
603677
def test_many_convolutions(self, fake_grids, pdf, nb_convolutions: int = 3):
604678
"""Test for fun many convolutions."""
605679
expected_results = [

0 commit comments

Comments
 (0)