-
Notifications
You must be signed in to change notification settings - Fork 3
/
boc.rs
144 lines (134 loc) · 3.82 KB
/
boc.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! Interface for bins, orders and channels.
use numpy::{IntoPyArray, PyArray1};
use pineappl::boc::{Channel, Order};
use pyo3::prelude::*;
/// PyO3 wrapper to :rustdoc:`pineappl::boc::Channel <boc/struct.Channel.html>`.
///
/// Each entry consists of a tuple, which contains, in the following order:
///
/// 1. the PDG id of the first incoming parton
/// 2. the PDG id of the second parton
/// 3. a numerical factor that will multiply the result for this specific combination.
#[pyclass(name = "Channel")]
#[repr(transparent)]
pub struct PyChannel {
pub(crate) entry: Channel,
}
#[pymethods]
impl PyChannel {
/// Constructor.
///
/// Parameters
/// ----------
/// entry: list(tuple(int, int, float))
/// channel configuration
#[new]
pub fn new(entry: Vec<(i32, i32, f64)>) -> Self {
Self {
entry: Channel::new(entry),
}
}
/// Get list representation.
///
/// Returns
/// -------
/// list(tuple(int,int,float)) :
/// list representation
pub fn into_array(&self) -> Vec<(i32, i32, f64)> {
self.entry.entry().to_vec()
}
}
/// Register submodule in parent.
pub fn register(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
let m = PyModule::new_bound(parent_module.py(), "boc")?;
m.setattr(
pyo3::intern!(m.py(), "__doc__"),
"Interface for bins, orders and channels.",
)?;
pyo3::py_run!(
parent_module.py(),
m,
"import sys; sys.modules['pineappl.channel'] = m"
);
m.add_class::<PyChannel>()?;
parent_module.add_submodule(&m)
}
/// PyO3 wrapper to :rustdoc:`pineappl::boc::Order <boc/struct.Order.html>`.
#[pyclass(name = "Order")]
#[repr(transparent)]
pub struct PyOrder {
pub(crate) order: Order,
}
impl PyOrder {
pub(crate) fn new(order: Order) -> Self {
Self { order }
}
}
#[pymethods]
impl PyOrder {
/// Constructor.
///
/// Parameters
/// ----------
/// alphas : int
/// power of :math:`\alpha_s`
/// alpha : int
/// power of :math:`\alpha`
/// logxir : int
/// power of :math:`\ln(\xi_r)`
/// logxif : int
/// power of :math:`\ln(\xi_f)`
#[new]
pub fn new_order(alphas: u32, alpha: u32, logxir: u32, logxif: u32) -> Self {
Self::new(Order::new(alphas, alpha, logxir, logxif))
}
/// Tuple representation.
///
/// Returns
/// -------
/// alphas : int
/// power of :math:`\alpha_s`
/// alpha : int
/// power of :math:`\alpha`
/// logxir : int
/// power of :math:`\ln(\xi_r)`
/// logxif : int
/// power of :math:`\ln(\xi_f)`
pub fn as_tuple(&self) -> (u32, u32, u32, u32) {
(
self.order.alphas,
self.order.alpha,
self.order.logxir,
self.order.logxif,
)
}
/// Return a mask suitable to pass as the `order_mask` parameter of [`Grid::convolve`].
///
/// The selection of `orders` is controlled using the `max_as` and `max_al` parameters, for
/// instance setting `max_as = 1` and `max_al = 0` selects the LO QCD only, `max_as = 2` and
/// `max_al = 0` the NLO QCD; setting `max_as = 3` and `max_al = 2` would select all NLOs, and
/// the NNLO QCD.
///
/// See `pineappl` crate docs for more examples.
///
/// Returns
/// -------
/// numpy.ndarray(bool)
/// boolean array, to be used as orders' mask
#[staticmethod]
pub fn create_mask<'py>(
orders: Vec<PyRef<Self>>,
max_as: u32,
max_al: u32,
logs: bool,
py: Python<'py>,
) -> Bound<'py, PyArray1<bool>> {
Order::create_mask(
&orders.iter().map(|o| o.order.clone()).collect::<Vec<_>>(),
max_as,
max_al,
logs,
)
.into_pyarray_bound(py)
}
}