diff --git a/CHANGELOG.md b/CHANGELOG.md index bcb18d30..c20b2af5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- the macro `channel!` now accepts a channel specification that is of the + format `factor * (pid, ..) + ...` - Python API: dropped top-level Python interface layer - Python API: renamed `lumi` to `channel` in PyO3 Python interface. This concerns 1) the argument names of `convolute_with_one` and similar functions; diff --git a/pineappl/src/boc.rs b/pineappl/src/boc.rs index 1bbfe972..a5fe98b7 100644 --- a/pineappl/src/boc.rs +++ b/pineappl/src/boc.rs @@ -571,12 +571,12 @@ impl Channel { /// use pineappl::boc::Channel; /// use pineappl::channel; /// - /// let entry = channel![103, 11, 10.0].translate(&|evol_id| match evol_id { + /// let entry = channel![10.0 * (103, 11)].translate(&|evol_id| match evol_id { /// 103 => vec![(2, 1.0), (-2, -1.0), (1, -1.0), (-1, 1.0)], /// _ => vec![(evol_id, 1.0)], /// }); /// - /// assert_eq!(entry, channel![2, 11, 10.0; -2, 11, -10.0; 1, 11, -10.0; -1, 11, 10.0]); + /// assert_eq!(entry, channel![10.0 * (2, 11) + -10.0 * (-2, 11) + -10.0 * (1, 11) + 10.0 * (-1, 11)]); /// ``` #[must_use] pub fn translate(&self, translator: &dyn Fn(i32) -> Vec<(i32, f64)>) -> Self { @@ -606,7 +606,7 @@ impl Channel { /// use pineappl::channel; /// use pineappl::boc::Channel; /// - /// let entry = channel![4, 4, 1.0; 2, 2, 1.0]; + /// let entry = channel![1.0 * (4, 4) + 1.0 * (2, 2)]; /// /// assert_eq!(entry.entry(), [(vec![2, 2], 1.0), (vec![4, 4], 1.0)]); /// ``` @@ -639,11 +639,11 @@ impl Channel { /// ```rust /// use pineappl::channel; /// - /// let ch1 = channel![2, 2, 2.0; 4, 4, 2.0]; - /// let ch2 = channel![4, 4, 1.0; 2, 2, 1.0]; - /// let ch3 = channel![3, 4, 1.0; 2, 2, 1.0]; - /// let ch4 = channel![4, 3, 1.0; 2, 3, 2.0]; - /// let ch5 = channel![2, 2, 1.0; 4, 4, 2.0]; + /// let ch1 = channel![2.0 * (2, 2) + 2.0 * (4, 4)]; + /// let ch2 = channel![1.0 * (4, 4) + 1.0 * (2, 2)]; + /// let ch3 = channel![1.0 * (3, 4) + 1.0 * (2, 2)]; + /// let ch4 = channel![1.0 * (4, 3) + 2.0 * (2, 3)]; + /// let ch5 = channel![1.0 * (2, 2) + 2.0 * (4, 4)]; /// /// // ch1 is ch2 multiplied by two /// assert_eq!(ch1.common_factor(&ch2), Some(2.0)); @@ -741,16 +741,21 @@ impl FromStr for Channel { /// ```rust /// use pineappl::channel; /// -/// let entry1 = channel![2, 2, 1.0; 4, 4, 1.0]; -/// let entry2 = channel![4, 4, 1.0; 2, 2, 1.0]; +/// let entry1 = channel![1.0 * (2, 2) + 1.0 * (4, 4)]; +/// let entry2 = channel![1.0 * (4, 4) + 1.0 * (2, 2)]; /// /// assert_eq!(entry1, entry2); /// ``` #[macro_export] macro_rules! channel { - // TODO: generalize this to accept an arbitrary number of PIDs - ($a:expr, $b:expr, $factor:expr $(; $c:expr, $d:expr, $fac:expr)*) => { - $crate::boc::Channel::new(vec![(vec![$a, $b], $factor), $((vec![$c, $d], $fac)),*]) + ($factor:literal * ($($pids:expr),+) $(+ $more_factors:literal * ($($more_pids:expr),+))*) => { + $crate::boc::Channel::new( + vec![ + (vec![$($pids),+], $factor) $(, + (vec![$($more_pids),+], $more_factors) + )* + ] + ) }; } @@ -965,7 +970,7 @@ mod tests { fn channel_from_str() { assert_eq!( str::parse::(" 1 * ( 2 , -2) + 2* (4,-4)").unwrap(), - channel![2, -2, 1.0; 4, -4, 2.0] + channel![1.0 * (2, -2) + 2.0 * (4, -4)] ); assert_eq!( diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index bcc1f244..b9a5a924 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -1667,8 +1667,8 @@ mod tests { let mut grid = Grid::new( PidBasis::Pdg, vec![ - channel![2, 2, 1.0; 4, 4, 1.0], - channel![1, 1, 1.0; 3, 3, 1.0], + channel![1.0 * (2, 2) + 1.0 * (4, 4)], + channel![1.0 * (1, 1) + 1.0 * (3, 3)], ], vec![Order::new(0, 2, 0, 0, 0)], vec![0.0, 0.25, 0.5, 0.75, 1.0], @@ -1690,8 +1690,8 @@ mod tests { PidBasis::Pdg, vec![ // differently ordered than `grid` - channel![1, 1, 1.0; 3, 3, 1.0], - channel![2, 2, 1.0; 4, 4, 1.0], + channel![1.0 * (1, 1) + 1.0 * (3, 3)], + channel![1.0 * (2, 2) + 1.0 * (4, 4)], ], vec![Order::new(1, 2, 0, 0, 0), Order::new(1, 2, 0, 1, 0)], vec![0.0, 0.25, 0.5, 0.75, 1.0], @@ -1718,8 +1718,8 @@ mod tests { let mut grid = Grid::new( PidBasis::Pdg, vec![ - channel![2, 2, 1.0; 4, 4, 1.0], - channel![1, 1, 1.0; 3, 3, 1.0], + channel![1.0 * (2, 2) + 1.0 * (4, 4)], + channel![1.0 * (1, 1) + 1.0 * (3, 3)], ], vec![Order::new(0, 2, 0, 0, 0)], vec![0.0, 0.25, 0.5, 0.75, 1.0], @@ -1740,8 +1740,8 @@ mod tests { let mut other = Grid::new( PidBasis::Pdg, vec![ - channel![2, 2, 1.0; 4, 4, 1.0], - channel![1, 1, 1.0; 3, 3, 1.0], + channel![1.0 * (2, 2) + 1.0 * (4, 4)], + channel![1.0 * (1, 1) + 1.0 * (3, 3)], ], vec![ Order::new(1, 2, 0, 0, 0), @@ -1777,8 +1777,8 @@ mod tests { let mut grid = Grid::new( PidBasis::Pdg, vec![ - channel![2, 2, 1.0; 4, 4, 1.0], - channel![1, 1, 1.0; 3, 3, 1.0], + channel![1.0 * (2, 2) + 1.0 * (4, 4)], + channel![1.0 * (1, 1) + 1.0 * (3, 3)], ], vec![Order::new(0, 2, 0, 0, 0)], vec![0.0, 0.25, 0.5, 0.75, 1.0], @@ -1798,7 +1798,10 @@ mod tests { let mut other = Grid::new( PidBasis::Pdg, - vec![channel![22, 22, 1.0], channel![2, 2, 1.0; 4, 4, 1.0]], + vec![ + channel![1.0 * (22, 22)], + channel![1.0 * (2, 2) + 1.0 * (4, 4)], + ], vec![Order::new(0, 2, 0, 0, 0)], vec![0.0, 0.25, 0.5, 0.75, 1.0], vec![Conv::new(ConvType::UnpolPDF, 2212); 2], @@ -1826,8 +1829,8 @@ mod tests { let mut grid = Grid::new( PidBasis::Pdg, vec![ - channel![2, 2, 1.0; 4, 4, 1.0], - channel![1, 1, 1.0; 3, 3, 1.0], + channel![1.0 * (2, 2) + 1.0 * (4, 4)], + channel![1.0 * (1, 1) + 1.0 * (3, 3)], ], vec![Order::new(0, 2, 0, 0, 0)], vec![0.0, 0.25, 0.5], @@ -1849,8 +1852,8 @@ mod tests { PidBasis::Pdg, vec![ // channels are differently sorted - channel![1, 1, 1.0; 3, 3, 1.0], - channel![2, 2, 1.0; 4, 4, 1.0], + channel![1.0 * (1, 1) + 1.0 * (3, 3)], + channel![1.0 * (2, 2) + 1.0 * (4, 4)], ], vec![Order::new(0, 2, 0, 0, 0)], vec![0.5, 0.75, 1.0], @@ -1878,7 +1881,7 @@ mod tests { fn grid_convolutions() { let mut grid = Grid::new( PidBasis::Pdg, - vec![channel![21, 21, 1.0]], + vec![channel![1.0 * (21, 21)]], vec![Order { alphas: 0, alpha: 0, @@ -1923,8 +1926,8 @@ mod tests { let mut grid = Grid::new( PidBasis::Pdg, vec![ - channel![2, 2, 1.0; 4, 4, 1.0], - channel![1, 1, 1.0; 3, 3, 1.0], + channel![1.0 * (2, 2) + 1.0 * (4, 4)], + channel![1.0 * (1, 1) + 1.0 * (3, 3)], ], vec![Order::new(0, 2, 0, 0, 0)], vec![0.0, 0.25, 0.5, 0.75, 1.0], diff --git a/pineappl/src/pids.rs b/pineappl/src/pids.rs index 643725f8..e7453857 100644 --- a/pineappl/src/pids.rs +++ b/pineappl/src/pids.rs @@ -938,7 +938,7 @@ mod tests { #[test] fn inverse_inverse_evol() { for pid in [-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6] { - let result = &channel![pid, pid, 1.0] + let result = &channel![1.0 * (pid, pid)] .translate(&pdg_mc_pids_to_evol) .translate(&evol_to_pdg_mc_ids); @@ -1031,14 +1031,28 @@ mod tests { #[test] fn translate() { - let channel = PidBasis::Evol.translate(PidBasis::Pdg, channel![103, 203, 2.0]); + let channel = PidBasis::Evol.translate(PidBasis::Pdg, channel![2.0 * (103, 203)]); assert_eq!( channel, - channel![ 2, 2, 2.0; 2, -2, -2.0; 2, 1, -2.0; 2, -1, 2.0; - -2, 2, 2.0; -2, -2, -2.0; -2, 1, -2.0; -2, -1, 2.0; - 1, 2, -2.0; 1, -2, 2.0; 1, 1, 2.0; 1, -1, -2.0; - -1, 2, -2.0; -1, -2, 2.0; -1, 1, 2.0; -1, -1, -2.0] + channel![ + 2.0 * (2, 2) + + -2.0 * (2, -2) + + -2.0 * (2, 1) + + 2.0 * (2, -1) + + 2.0 * (-2, 2) + + -2.0 * (-2, -2) + + -2.0 * (-2, 1) + + 2.0 * (-2, -1) + + -2.0 * (1, 2) + + 2.0 * (1, -2) + + 2.0 * (1, 1) + + -2.0 * (1, -1) + + -2.0 * (-1, 2) + + 2.0 * (-1, -2) + + 2.0 * (-1, 1) + + -2.0 * (-1, -1) + ] ); } } diff --git a/pineappl/tests/drell_yan_lo.rs b/pineappl/tests/drell_yan_lo.rs index 62e9efaa..aa86a8d9 100644 --- a/pineappl/tests/drell_yan_lo.rs +++ b/pineappl/tests/drell_yan_lo.rs @@ -120,15 +120,15 @@ fn hadronic_pspgen(rng: &mut impl Rng, mmin: f64, mmax: f64) -> Psp2to2 { fn fill_drell_yan_lo_grid(rng: &mut impl Rng, calls: u32, dynamic: bool, reweight: bool) -> Grid { let channels = vec![ // photons - channel![22, 22, 1.0], + channel![1.0 * (22, 22)], // up-antiup - channel![2, -2, 1.0; 4, -4, 1.0], + channel![1.0 * (2, -2) + 1.0 * (4, -4)], // antiup-up - channel![-2, 2, 1.0; -4, 4, 1.0], + channel![1.0 * (-2, 2) + 1.0 * (-4, 4)], // down-antidown - channel![1, -1, 1.0; 3, -3, 1.0; 5, -5, 1.0], + channel![1.0 * (1, -1) + 1.0 * (3, -3) + 1.0 * (5, -5)], // antidown-down - channel![-1, 1, 1.0; -3, 3, 1.0; -5, 5, 1.0], + channel![1.0 * (-1, 1) + 1.0 * (-3, 3) + 1.0 * (-5, 5)], ]; let orders = vec![ diff --git a/pineappl_cli/src/import/fktable.rs b/pineappl_cli/src/import/fktable.rs index 1eb67282..6638d650 100644 --- a/pineappl_cli/src/import/fktable.rs +++ b/pineappl_cli/src/import/fktable.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, Context, Result}; use flate2::read::GzDecoder; use ndarray::s; -use pineappl::boc::{Channel, Kinematics, Order, ScaleFuncForm, Scales}; +use pineappl::boc::{Kinematics, Order, ScaleFuncForm, Scales}; use pineappl::channel; use pineappl::convolutions::{Conv, ConvType}; use pineappl::grid::Grid; @@ -86,14 +86,14 @@ fn read_fktable(reader: impl BufRead) -> Result { .iter() .enumerate() .filter(|&(_, &value)| value) - .map(|(index, _)| channel![basis[index / 14], basis[index % 14], 1.0]) + .map(|(index, _)| channel![1.0 * (basis[index / 14], basis[index % 14])]) .collect() } else { flavor_mask .iter() .enumerate() .filter(|&(_, &value)| value) - .map(|(index, _)| Channel::new(vec![(vec![basis[index]], 1.0)])) + .map(|(index, _)| channel![1.0 * (basis[index])]) .collect() };