Skip to content

Commit

Permalink
Add new methods ScaleFuncForm::calc and Scales::compatible_with
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Sep 20, 2024
1 parent aa4a097 commit 763906a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
40 changes: 40 additions & 0 deletions pineappl/src/boc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//!
//! [`Grid`]: super::grid::Grid

use super::subgrid::NodeValues;
use float_cmp::approx_eq;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -38,6 +39,24 @@ pub enum ScaleFuncForm {
QuadraticSum(usize, usize),
}

impl ScaleFuncForm {
/// TODO
pub fn calc(&self, node_values: &[NodeValues], kinematics: &[Kinematics]) -> Option<Vec<f64>> {
match self {
ScaleFuncForm::NoScale => None,
&ScaleFuncForm::Scale(index) => Some(
node_values[kinematics
.iter()
.position(|&kin| kin == Kinematics::Scale(index))
// UNWRAP: this should be guaranteed by `Grid::new`
.unwrap()]
.values(),
),
ScaleFuncForm::QuadraticSum(_, _) => todo!(),
}
}
}

/// TODO
#[derive(Clone, Deserialize, Serialize)]
pub struct Scales {
Expand All @@ -49,6 +68,27 @@ pub struct Scales {
pub frg: ScaleFuncForm,
}

impl Scales {
/// TODO
pub fn compatible_with(&self, kinematics: &[Kinematics]) -> bool {
for scale in [&self.ren, &self.fac, &self.frg].map(Clone::clone) {
match scale {
ScaleFuncForm::NoScale => {}
ScaleFuncForm::Scale(index)
if kinematics
.iter()
.any(|&kin| kin == Kinematics::Scale(index)) => {}
ScaleFuncForm::QuadraticSum(idx1, idx2)
if kinematics.iter().any(|&kin| kin == Kinematics::Scale(idx1))
&& kinematics.iter().any(|&kin| kin == Kinematics::Scale(idx2)) => {}
_ => return false,
}
}

true
}
}

/// Error type keeping information if [`Order::from_str`] went wrong.
#[derive(Debug, Error, Eq, PartialEq)]
#[error("{0}")]
Expand Down
10 changes: 8 additions & 2 deletions pineappl/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ impl Grid {
///
/// # Panics
///
/// Panics when the number of PIDs in `channels` is not equal to `convolutions.len()`, or if
/// `interps` and `kinematics` have different lengths.
/// Panics when the number of PIDs in `channels` is not equal to `convolutions.len()`, or
/// `interps` and `kinematics` have different lengths or if `kinematics` are not compatible
/// with `scales`.
#[must_use]
pub fn new(
pid_basis: PidBasis,
Expand Down Expand Up @@ -168,6 +169,11 @@ impl Grid {
"interps and kinematics have different lengths"
);

assert!(
scales.compatible_with(&kinematics),
"scales and kinematics are not compatible"
);

Self {
subgrids: Array3::from_shape_simple_fn(
(orders.len(), bin_limits.len() - 1, channels.len()),
Expand Down
2 changes: 1 addition & 1 deletion pineappl/tests/drell_yan_lo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn fill_drell_yan_lo_grid(

let scales = Scales {
ren: ScaleFuncForm::Scale(0),
fac: ScaleFuncForm::Scale(1),
fac: ScaleFuncForm::Scale(0),
frg: ScaleFuncForm::NoScale,
};

Expand Down

0 comments on commit 763906a

Please sign in to comment.