From d755b1adcf428dc5f64df3bf40896693f247a51a Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Fri, 23 Feb 2024 14:09:11 +0100 Subject: [PATCH] Add `--allow-extrapolation` to switch off settting PDFs to zero --- pineappl_cli/src/analyze.rs | 4 +-- pineappl_cli/src/channels.rs | 2 +- pineappl_cli/src/convolute.rs | 4 +-- pineappl_cli/src/diff.rs | 8 ++--- pineappl_cli/src/evolve.rs | 4 +-- pineappl_cli/src/export.rs | 2 +- pineappl_cli/src/helpers.rs | 17 ++++++----- pineappl_cli/src/import.rs | 2 +- pineappl_cli/src/lib.rs | 3 ++ pineappl_cli/src/orders.rs | 2 +- pineappl_cli/src/plot.rs | 56 ++++++++--------------------------- pineappl_cli/src/pull.rs | 8 ++--- pineappl_cli/src/uncert.rs | 4 +-- pineappl_cli/tests/main.rs | 9 +++--- 14 files changed, 50 insertions(+), 75 deletions(-) diff --git a/pineappl_cli/src/analyze.rs b/pineappl_cli/src/analyze.rs index cebffb60..18f9a730 100644 --- a/pineappl_cli/src/analyze.rs +++ b/pineappl_cli/src/analyze.rs @@ -93,7 +93,7 @@ impl Subcommand for CkfOpts { &lumi_mask, 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ) }) .collect(); @@ -109,7 +109,7 @@ impl Subcommand for CkfOpts { &lumi_mask, 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ) }) .collect(); diff --git a/pineappl_cli/src/channels.rs b/pineappl_cli/src/channels.rs index 9d6191cd..a1d6f84d 100644 --- a/pineappl_cli/src/channels.rs +++ b/pineappl_cli/src/channels.rs @@ -99,7 +99,7 @@ impl Subcommand for Opts { } else { ConvoluteMode::Normal }, - cfg.force_positive, + cfg, ) }) .collect(); diff --git a/pineappl_cli/src/convolute.rs b/pineappl_cli/src/convolute.rs index 657b4fab..4e26f966 100644 --- a/pineappl_cli/src/convolute.rs +++ b/pineappl_cli/src/convolute.rs @@ -63,7 +63,7 @@ impl Subcommand for Opts { } else { ConvoluteMode::Normal }, - cfg.force_positive, + cfg, ); let limits = helpers::convolute_limits( &grid, @@ -92,7 +92,7 @@ impl Subcommand for Opts { } else { ConvoluteMode::Normal }, - cfg.force_positive, + cfg, ) }) .collect(); diff --git a/pineappl_cli/src/diff.rs b/pineappl_cli/src/diff.rs index d07c798d..b2bf2560 100644 --- a/pineappl_cli/src/diff.rs +++ b/pineappl_cli/src/diff.rs @@ -154,7 +154,7 @@ impl Subcommand for Opts { &[], 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ); let results2 = helpers::convolute( &grid2, @@ -164,7 +164,7 @@ impl Subcommand for Opts { &[], 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ); for (bin, (limits1, (result1, result2))) in limits1 @@ -210,7 +210,7 @@ impl Subcommand for Opts { &[], 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ) }) .collect(); @@ -225,7 +225,7 @@ impl Subcommand for Opts { &[], 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ) }) .collect(); diff --git a/pineappl_cli/src/evolve.rs b/pineappl_cli/src/evolve.rs index 5c79e869..f8bcf65a 100644 --- a/pineappl_cli/src/evolve.rs +++ b/pineappl_cli/src/evolve.rs @@ -289,7 +289,7 @@ impl Subcommand for Opts { &[], &[(self.xir, self.xif)], ConvoluteMode::Normal, - cfg.force_positive, + cfg, ); let fk_table = evolve_grid(&grid, &self.eko, &pdf, &self.orders, self.xir, self.xif)?; @@ -301,7 +301,7 @@ impl Subcommand for Opts { &[], &[(1.0, 1.0)], ConvoluteMode::Normal, - cfg.force_positive, + cfg, ); // if both grids don't have the same number of bins there's a bug in the program diff --git a/pineappl_cli/src/export.rs b/pineappl_cli/src/export.rs index 3b2584d7..a67c8a92 100644 --- a/pineappl_cli/src/export.rs +++ b/pineappl_cli/src/export.rs @@ -163,7 +163,7 @@ impl Subcommand for Opts { &[], scale_variations, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ); // if both grids don't have the same number of bins there's bug in the program diff --git a/pineappl_cli/src/helpers.rs b/pineappl_cli/src/helpers.rs index 575ca6aa..bfc5ecd8 100644 --- a/pineappl_cli/src/helpers.rs +++ b/pineappl_cli/src/helpers.rs @@ -1,3 +1,4 @@ +use super::GlobalConfiguration; use anyhow::{ensure, Context, Result}; use lhapdf::{Pdf, PdfSet}; use ndarray::Array3; @@ -132,7 +133,7 @@ pub fn convolute_scales( lumis: &[bool], scales: &[(f64, f64)], mode: ConvoluteMode, - force_positive: bool, + cfg: &GlobalConfiguration, ) -> Vec { let orders: Vec<_> = grid .orders() @@ -152,14 +153,14 @@ pub fn convolute_scales( .map_or(Ok(2212), |string| string.parse::()) .unwrap(); - if force_positive { + if cfg.force_positive { lhapdf.set_force_positive(1); } let x_max = lhapdf.x_max(); let x_min = lhapdf.x_min(); let mut pdf = |id, x, q2| { - if x < x_min || x > x_max { + if !cfg.allow_extrapolation && (x < x_min || x > x_max) { 0.0 } else { lhapdf.xfx_q2(id, x, q2) @@ -217,7 +218,7 @@ pub fn convolute( lumis: &[bool], scales: usize, mode: ConvoluteMode, - force_positive: bool, + cfg: &GlobalConfiguration, ) -> Vec { convolute_scales( grid, @@ -227,7 +228,7 @@ pub fn convolute( lumis, &SCALES_VECTOR[0..scales], mode, - force_positive, + cfg, ) } @@ -252,7 +253,7 @@ pub fn convolute_subgrid( order: usize, bin: usize, lumi: usize, - force_positive: bool, + cfg: &GlobalConfiguration, ) -> Array3 { // if the field 'Particle' is missing we assume it's a proton PDF let pdf_pdg_id = lhapdf @@ -261,14 +262,14 @@ pub fn convolute_subgrid( .map_or(Ok(2212), |string| string.parse::()) .unwrap(); - if force_positive { + if cfg.force_positive { lhapdf.set_force_positive(1); } let x_max = lhapdf.x_max(); let x_min = lhapdf.x_min(); let mut pdf = |id, x, q2| { - if x < x_min || x > x_max { + if !cfg.allow_extrapolation && (x < x_min || x > x_max) { 0.0 } else { lhapdf.xfx_q2(id, x, q2) diff --git a/pineappl_cli/src/import.rs b/pineappl_cli/src/import.rs index d9edc3cc..530d39f8 100644 --- a/pineappl_cli/src/import.rs +++ b/pineappl_cli/src/import.rs @@ -283,7 +283,7 @@ impl Subcommand for Opts { &[], scale_variations, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ); // if both grids don't have the same number of bins there's bug in the program diff --git a/pineappl_cli/src/lib.rs b/pineappl_cli/src/lib.rs index 0e049ca8..2b38eee4 100644 --- a/pineappl_cli/src/lib.rs +++ b/pineappl_cli/src/lib.rs @@ -30,6 +30,9 @@ pub struct GlobalConfiguration { /// Forces negative PDF values to zero. #[arg(long)] pub force_positive: bool, + /// Allow extrapolation of PDFs outside their region of validity. + #[arg(long)] + pub allow_extrapolation: bool, } #[enum_dispatch] diff --git a/pineappl_cli/src/orders.rs b/pineappl_cli/src/orders.rs index ed7d48ba..e5af3212 100644 --- a/pineappl_cli/src/orders.rs +++ b/pineappl_cli/src/orders.rs @@ -76,7 +76,7 @@ impl Subcommand for Opts { } else { ConvoluteMode::Normal }, - cfg.force_positive, + cfg, ) }) .collect(); diff --git a/pineappl_cli/src/plot.rs b/pineappl_cli/src/plot.rs index 80bbe6ba..052c2651 100644 --- a/pineappl_cli/src/plot.rs +++ b/pineappl_cli/src/plot.rs @@ -217,16 +217,8 @@ impl Subcommand for Opts { })) { let bins: Vec<_> = (slice.0..slice.1).collect(); - let results = helpers::convolute( - &grid, - &mut pdf, - &[], - &bins, - &[], - self.scales, - mode, - cfg.force_positive, - ); + let results = + helpers::convolute(&grid, &mut pdf, &[], &bins, &[], self.scales, mode, cfg); let qcd_results = { let mut orders = grid.orders().to_vec(); @@ -251,7 +243,7 @@ impl Subcommand for Opts { &[], self.scales, mode, - cfg.force_positive, + cfg, ) }; @@ -277,16 +269,8 @@ impl Subcommand for Opts { if self.no_pdf_unc { let mut pdf = helpers::create_pdf(pdfset).unwrap(); - let results = helpers::convolute( - &grid, - &mut pdf, - &[], - &bins, - &[], - 1, - mode, - cfg.force_positive, - ); + let results = + helpers::convolute(&grid, &mut pdf, &[], &bins, &[], 1, mode, cfg); vec![results; 3] } else { @@ -304,7 +288,7 @@ impl Subcommand for Opts { &[], 1, mode, - cfg.force_positive, + cfg, ) }) .collect(); @@ -403,7 +387,7 @@ impl Subcommand for Opts { &lumi_mask, 1, mode, - cfg.force_positive, + cfg, ), ) }) @@ -547,7 +531,7 @@ impl Subcommand for Opts { &[], 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ) .as_slice() { @@ -567,7 +551,7 @@ impl Subcommand for Opts { &[], 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ) .as_slice() { @@ -598,24 +582,10 @@ impl Subcommand for Opts { unc1.hypot(unc2) }; - let res1 = helpers::convolute_subgrid( - &grid, - &mut pdfset1[0], - order, - bin, - lumi, - cfg.force_positive, - ) - .sum_axis(Axis(0)); - let res2 = helpers::convolute_subgrid( - &grid, - &mut pdfset2[0], - order, - bin, - lumi, - cfg.force_positive, - ) - .sum_axis(Axis(0)); + let res1 = helpers::convolute_subgrid(&grid, &mut pdfset1[0], order, bin, lumi, cfg) + .sum_axis(Axis(0)); + let res2 = helpers::convolute_subgrid(&grid, &mut pdfset2[0], order, bin, lumi, cfg) + .sum_axis(Axis(0)); let subgrid = grid.subgrid(order, bin, lumi); //let q2 = subgrid.q2_grid(); diff --git a/pineappl_cli/src/pull.rs b/pineappl_cli/src/pull.rs index dea9f6bd..5b35a586 100644 --- a/pineappl_cli/src/pull.rs +++ b/pineappl_cli/src/pull.rs @@ -74,7 +74,7 @@ impl Subcommand for Opts { &[], 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ) }) .collect(); @@ -89,7 +89,7 @@ impl Subcommand for Opts { &[], 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ) }) .collect(); @@ -155,7 +155,7 @@ impl Subcommand for Opts { &lumi_mask, 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ) .as_slice() { @@ -180,7 +180,7 @@ impl Subcommand for Opts { &lumi_mask, 1, ConvoluteMode::Normal, - cfg.force_positive, + cfg, ) .as_slice() { diff --git a/pineappl_cli/src/uncert.rs b/pineappl_cli/src/uncert.rs index 10693d97..b08ecc99 100644 --- a/pineappl_cli/src/uncert.rs +++ b/pineappl_cli/src/uncert.rs @@ -131,7 +131,7 @@ impl Subcommand for Opts { } else { ConvoluteMode::Normal }, - cfg.force_positive, + cfg, ) }) .collect() @@ -160,7 +160,7 @@ impl Subcommand for Opts { } else { ConvoluteMode::Normal }, - cfg.force_positive, + cfg, ); let (x, y_label, y_unit) = helpers::labels_and_units(&grid, self.integrated); diff --git a/pineappl_cli/tests/main.rs b/pineappl_cli/tests/main.rs index b64d3f0f..66d67802 100644 --- a/pineappl_cli/tests/main.rs +++ b/pineappl_cli/tests/main.rs @@ -23,10 +23,11 @@ Commands: write Write a grid modified by various operations Options: - --silence-lhapdf Prevents LHAPDF from printing banners - --force-positive Forces negative PDF values to zero - -h, --help Print help - -V, --version Print version + --silence-lhapdf Prevents LHAPDF from printing banners + --force-positive Forces negative PDF values to zero + --allow-extrapolation Allow extrapolation of PDFs outside their region of validity + -h, --help Print help + -V, --version Print version "; #[test]