use super::empty_subgrid::EmptySubgridV1;
use super::grid::Ntuple;
use super::import_only_subgrid::{ImportOnlySubgridV1, ImportOnlySubgridV2};
use super::lagrange_subgrid::{LagrangeSparseSubgridV1, LagrangeSubgridV1, LagrangeSubgridV2};
use super::ntuple_subgrid::NtupleSubgridV1;
use enum_dispatch::enum_dispatch;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
#[enum_dispatch(Subgrid)]
#[derive(Clone, Deserialize, Serialize)]
pub enum SubgridEnum {
LagrangeSubgridV1,
NtupleSubgridV1,
LagrangeSparseSubgridV1,
LagrangeSubgridV2,
ImportOnlySubgridV1,
EmptySubgridV1,
ImportOnlySubgridV2,
}
#[derive(Debug, Deserialize, Clone, PartialEq, PartialOrd, Serialize)]
pub struct Mu2 {
pub ren: f64,
pub fac: f64,
}
#[derive(Debug, Eq, PartialEq)]
pub struct Stats {
pub total: usize,
pub allocated: usize,
pub zeros: usize,
pub overhead: usize,
pub bytes_per_value: usize,
}
#[enum_dispatch]
pub trait Subgrid {
fn mu2_grid(&self) -> Cow<[Mu2]>;
fn x1_grid(&self) -> Cow<[f64]>;
fn x2_grid(&self) -> Cow<[f64]>;
fn convolute(
&self,
x1: &[f64],
x2: &[f64],
mu2: &[Mu2],
lumi: &mut dyn FnMut(usize, usize, usize) -> f64,
) -> f64;
fn fill(&mut self, ntuple: &Ntuple<f64>);
fn is_empty(&self) -> bool;
fn merge(&mut self, other: &mut SubgridEnum, transpose: bool);
fn scale(&mut self, factor: f64);
fn symmetrize(&mut self);
fn clone_empty(&self) -> SubgridEnum;
fn iter(&self) -> SubgridIter;
fn stats(&self) -> Stats;
}
pub type SubgridIter<'a> = Box<dyn Iterator<Item = ((usize, usize, usize), &'a f64)> + 'a>;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SubgridParams {
q2_bins: usize,
q2_max: f64,
q2_min: f64,
q2_order: usize,
reweight: bool,
x_bins: usize,
x_max: f64,
x_min: f64,
x_order: usize,
}
impl Default for SubgridParams {
fn default() -> Self {
Self {
q2_bins: 40,
q2_max: 1e8,
q2_min: 1e2,
q2_order: 3,
reweight: true,
x_bins: 50,
x_max: 1.0,
x_min: 2e-7,
x_order: 3,
}
}
}
impl SubgridParams {
#[must_use]
pub const fn q2_bins(&self) -> usize {
self.q2_bins
}
#[must_use]
pub const fn q2_max(&self) -> f64 {
self.q2_max
}
#[must_use]
pub const fn q2_min(&self) -> f64 {
self.q2_min
}
#[must_use]
pub const fn q2_order(&self) -> usize {
self.q2_order
}
#[must_use]
pub const fn reweight(&self) -> bool {
self.reweight
}
pub fn set_q2_bins(&mut self, q2_bins: usize) {
self.q2_bins = q2_bins;
}
pub fn set_q2_max(&mut self, q2_max: f64) {
self.q2_max = q2_max;
}
pub fn set_q2_min(&mut self, q2_min: f64) {
self.q2_min = q2_min;
}
pub fn set_q2_order(&mut self, q2_order: usize) {
self.q2_order = q2_order;
}
pub fn set_reweight(&mut self, reweight: bool) {
self.reweight = reweight;
}
pub fn set_x_bins(&mut self, x_bins: usize) {
self.x_bins = x_bins;
}
pub fn set_x_max(&mut self, x_max: f64) {
self.x_max = x_max;
}
pub fn set_x_min(&mut self, x_min: f64) {
self.x_min = x_min;
}
pub fn set_x_order(&mut self, x_order: usize) {
self.x_order = x_order;
}
#[must_use]
pub const fn x_bins(&self) -> usize {
self.x_bins
}
#[must_use]
pub const fn x_max(&self) -> f64 {
self.x_max
}
#[must_use]
pub const fn x_min(&self) -> f64 {
self.x_min
}
#[must_use]
pub const fn x_order(&self) -> usize {
self.x_order
}
}
#[derive(Deserialize, Serialize)]
pub struct ExtraSubgridParams {
reweight2: bool,
x2_bins: usize,
x2_max: f64,
x2_min: f64,
x2_order: usize,
}
impl Default for ExtraSubgridParams {
fn default() -> Self {
Self {
reweight2: true,
x2_bins: 50,
x2_max: 1.0,
x2_min: 2e-7,
x2_order: 3,
}
}
}
impl From<&SubgridParams> for ExtraSubgridParams {
fn from(subgrid_params: &SubgridParams) -> Self {
Self {
reweight2: subgrid_params.reweight(),
x2_bins: subgrid_params.x_bins(),
x2_max: subgrid_params.x_max(),
x2_min: subgrid_params.x_min(),
x2_order: subgrid_params.x_order(),
}
}
}
impl ExtraSubgridParams {
#[must_use]
pub const fn reweight2(&self) -> bool {
self.reweight2
}
pub fn set_reweight2(&mut self, reweight2: bool) {
self.reweight2 = reweight2;
}
pub fn set_x2_bins(&mut self, x_bins: usize) {
self.x2_bins = x_bins;
}
pub fn set_x2_max(&mut self, x_max: f64) {
self.x2_max = x_max;
}
pub fn set_x2_min(&mut self, x_min: f64) {
self.x2_min = x_min;
}
pub fn set_x2_order(&mut self, x_order: usize) {
self.x2_order = x_order;
}
#[must_use]
pub const fn x2_bins(&self) -> usize {
self.x2_bins
}
#[must_use]
pub const fn x2_max(&self) -> f64 {
self.x2_max
}
#[must_use]
pub const fn x2_min(&self) -> f64 {
self.x2_min
}
#[must_use]
pub const fn x2_order(&self) -> usize {
self.x2_order
}
}