Skip to content

Commit

Permalink
Add --allow-extrapolation to switch off settting PDFs to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Feb 23, 2024
1 parent b52c8ce commit d755b1a
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 75 deletions.
4 changes: 2 additions & 2 deletions pineappl_cli/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Subcommand for CkfOpts {
&lumi_mask,
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
)
})
.collect();
Expand All @@ -109,7 +109,7 @@ impl Subcommand for CkfOpts {
&lumi_mask,
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
)
})
.collect();
Expand Down
2 changes: 1 addition & 1 deletion pineappl_cli/src/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Subcommand for Opts {
} else {
ConvoluteMode::Normal
},
cfg.force_positive,
cfg,
)
})
.collect();
Expand Down
4 changes: 2 additions & 2 deletions pineappl_cli/src/convolute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Subcommand for Opts {
} else {
ConvoluteMode::Normal
},
cfg.force_positive,
cfg,
);
let limits = helpers::convolute_limits(
&grid,
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Subcommand for Opts {
} else {
ConvoluteMode::Normal
},
cfg.force_positive,
cfg,
)
})
.collect();
Expand Down
8 changes: 4 additions & 4 deletions pineappl_cli/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl Subcommand for Opts {
&[],
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
);
let results2 = helpers::convolute(
&grid2,
Expand All @@ -164,7 +164,7 @@ impl Subcommand for Opts {
&[],
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
);

for (bin, (limits1, (result1, result2))) in limits1
Expand Down Expand Up @@ -210,7 +210,7 @@ impl Subcommand for Opts {
&[],
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
)
})
.collect();
Expand All @@ -225,7 +225,7 @@ impl Subcommand for Opts {
&[],
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
)
})
.collect();
Expand Down
4 changes: 2 additions & 2 deletions pineappl_cli/src/evolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pineappl_cli/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions pineappl_cli/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::GlobalConfiguration;
use anyhow::{ensure, Context, Result};
use lhapdf::{Pdf, PdfSet};
use ndarray::Array3;
Expand Down Expand Up @@ -132,7 +133,7 @@ pub fn convolute_scales(
lumis: &[bool],
scales: &[(f64, f64)],
mode: ConvoluteMode,
force_positive: bool,
cfg: &GlobalConfiguration,
) -> Vec<f64> {
let orders: Vec<_> = grid
.orders()
Expand All @@ -152,14 +153,14 @@ pub fn convolute_scales(
.map_or(Ok(2212), |string| string.parse::<i32>())
.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)
Expand Down Expand Up @@ -217,7 +218,7 @@ pub fn convolute(
lumis: &[bool],
scales: usize,
mode: ConvoluteMode,
force_positive: bool,
cfg: &GlobalConfiguration,
) -> Vec<f64> {
convolute_scales(
grid,
Expand All @@ -227,7 +228,7 @@ pub fn convolute(
lumis,
&SCALES_VECTOR[0..scales],
mode,
force_positive,
cfg,
)
}

Expand All @@ -252,7 +253,7 @@ pub fn convolute_subgrid(
order: usize,
bin: usize,
lumi: usize,
force_positive: bool,
cfg: &GlobalConfiguration,
) -> Array3<f64> {
// if the field 'Particle' is missing we assume it's a proton PDF
let pdf_pdg_id = lhapdf
Expand All @@ -261,14 +262,14 @@ pub fn convolute_subgrid(
.map_or(Ok(2212), |string| string.parse::<i32>())
.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)
Expand Down
2 changes: 1 addition & 1 deletion pineappl_cli/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pineappl_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pineappl_cli/src/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Subcommand for Opts {
} else {
ConvoluteMode::Normal
},
cfg.force_positive,
cfg,
)
})
.collect();
Expand Down
56 changes: 13 additions & 43 deletions pineappl_cli/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -251,7 +243,7 @@ impl Subcommand for Opts {
&[],
self.scales,
mode,
cfg.force_positive,
cfg,
)
};

Expand All @@ -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 {
Expand All @@ -304,7 +288,7 @@ impl Subcommand for Opts {
&[],
1,
mode,
cfg.force_positive,
cfg,
)
})
.collect();
Expand Down Expand Up @@ -403,7 +387,7 @@ impl Subcommand for Opts {
&lumi_mask,
1,
mode,
cfg.force_positive,
cfg,
),
)
})
Expand Down Expand Up @@ -547,7 +531,7 @@ impl Subcommand for Opts {
&[],
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
)
.as_slice()
{
Expand All @@ -567,7 +551,7 @@ impl Subcommand for Opts {
&[],
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
)
.as_slice()
{
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions pineappl_cli/src/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Subcommand for Opts {
&[],
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
)
})
.collect();
Expand All @@ -89,7 +89,7 @@ impl Subcommand for Opts {
&[],
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
)
})
.collect();
Expand Down Expand Up @@ -155,7 +155,7 @@ impl Subcommand for Opts {
&lumi_mask,
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
)
.as_slice()
{
Expand All @@ -180,7 +180,7 @@ impl Subcommand for Opts {
&lumi_mask,
1,
ConvoluteMode::Normal,
cfg.force_positive,
cfg,
)
.as_slice()
{
Expand Down
4 changes: 2 additions & 2 deletions pineappl_cli/src/uncert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Subcommand for Opts {
} else {
ConvoluteMode::Normal
},
cfg.force_positive,
cfg,
)
})
.collect()
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions pineappl_cli/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit d755b1a

Please sign in to comment.