Skip to content

Commit 9594042

Browse files
Python functions that would be useful for pineako #183
1 parent 147d3c9 commit 9594042

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

pineappl_py/src/fk_table.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
33
use super::convolutions::PyConv;
44
use super::grid::PyGrid;
5+
use super::pids::PyPidBasis;
56
use numpy::{IntoPyArray, PyArray1, PyArrayDyn};
67
use pineappl::convolutions::ConvolutionCache;
78
use pineappl::fk_table::{FkAssumptions, FkTable};
89
use pineappl::grid::Grid;
10+
use pineappl::pids::PidBasis;
911
use pyo3::prelude::*;
1012
use std::collections::BTreeMap;
1113
use std::fs::File;
@@ -206,6 +208,30 @@ impl PyFkTable {
206208
self.fk_table.x_grid().into_pyarray(py)
207209
}
208210

211+
/// Return the convention by which the channels' PIDS are encoded.
212+
#[getter]
213+
#[must_use]
214+
pub const fn pid_basis(&self) -> PyPidBasis {
215+
match self.fk_table.grid().pid_basis() {
216+
PidBasis::Pdg => PyPidBasis::Pdg,
217+
PidBasis::Evol => PyPidBasis::Evol,
218+
}
219+
}
220+
221+
/// Rotate the F Table into the specified basis.
222+
///
223+
/// Parameters
224+
/// ----------
225+
/// pid_basis: PyPidBasis
226+
/// PID basis of the resulting FK Table
227+
pub fn rotate_pid_basis(&mut self, pid_basis: PyPidBasis) -> PyGrid {
228+
let mut grid_mut = self.fk_table.grid().clone();
229+
grid_mut.rotate_pid_basis(pid_basis.into());
230+
PyGrid {
231+
grid: grid_mut.clone(),
232+
}
233+
}
234+
209235
/// Write to file.
210236
///
211237
/// # Panics

pineappl_py/src/grid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ impl PyGrid {
696696
self.grid.dedup_channels(ulps);
697697
}
698698

699-
/// Rotate the Grid into the specified basis
699+
/// Rotate the Grid into the specified basis.
700700
///
701701
/// Parameters
702702
/// ----------

pineappl_py/tests/test_fk_table.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pineappl.convolutions import Conv, ConvType
1212
from pineappl.fk_table import FkAssumptions, FkTable
1313
from pineappl.subgrid import ImportSubgridV1
14+
from pineappl.pids import PidBasis
1415

1516

1617
class TestFkTable:
@@ -78,7 +79,7 @@ def test_fktable(
7879

7980
assert fk.table().shape == (1, 51, 34, 34)
8081
np.testing.assert_allclose(fk.fac0(), 2.7224999999999997)
81-
assert fk.frg0() == None
82+
assert fk.frg0() is None
8283

8384
# Check the various aspects of the Bins
8485
assert fk.bins() == 1
@@ -110,6 +111,11 @@ def test_fktable(
110111
assumption = FkAssumptions("Nf6Sym")
111112
fk.optimize(assumption)
112113

114+
# Check that FK table is in the Evolution basis and rotate into PDG
115+
assert fk.pid_basis == PidBasis.Evol
116+
new_fk = fk.rotate_pid_basis(PidBasis.Pdg)
117+
assert new_fk.pid_basis == PidBasis.Pdg
118+
113119
def test_unpolarized_convolution(
114120
self,
115121
pdf,

0 commit comments

Comments
 (0)