Skip to content

Commit

Permalink
Fix minor issues during merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Radonirinaunimi committed Dec 1, 2024
1 parent 8855dab commit fa46e44
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 75 deletions.
14 changes: 7 additions & 7 deletions examples/fortran/pineappl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ end function strlen

subroutine channels_add(lumi, combinations, nb_combinations, pdg_id_combinations, factors) &
bind(c, name = 'pineappl_channels_add')

use iso_c_binding
type (c_ptr), value :: lumi
integer (c_size_t), value :: combinations, nb_combinations
Expand Down Expand Up @@ -173,7 +173,7 @@ type (c_ptr) function grid_clone(grid) bind(c, name = 'pineappl_grid_clone')
subroutine grid_convolve(grid, xfxs, alphas, state, order_mask, channel_mask, &
bin_indices, nb_scales, mu_scales, results) &
bind(c, name = 'pineappl_grid_convolve')

use iso_c_binding
type (c_ptr), value :: grid, state
type (c_funptr) :: xfxs(*)
Expand Down Expand Up @@ -526,7 +526,7 @@ function c_f_string(c_str) result(f_str)

type (pineappl_lumi) function pineappl_channels_new()
implicit none

pineappl_channels_new = pineappl_lumi(channels_new())
end function

Expand Down Expand Up @@ -673,11 +673,11 @@ function pineappl_grid_convolve_with_two(grid, pdg_id1, xfx1, pdg_id2, xfx2, alp

function pineappl_grid_convolve(grid, xfxs, alphas, order_mask, channel_mask, bin_indices, &
nb_scales, mu_scales, state) result(res)

use iso_c_binding

implicit none

type (pineappl_grid), intent(in) :: grid
type (pineappl_xfx) :: xfxs(:)
type (pineappl_alphas) :: alphas
Expand All @@ -686,7 +686,7 @@ function pineappl_grid_convolve(grid, xfxs, alphas, order_mask, channel_mask, bi
real (dp), intent(in) :: mu_scales(:)
type (c_ptr), optional, intent(in) :: state
real (dp), allocatable :: res(:)

integer :: i
type (c_ptr) :: state_

Expand All @@ -700,7 +700,7 @@ function pineappl_grid_convolve(grid, xfxs, alphas, order_mask, channel_mask, bi
if (.not. c_associated(c_funloc(alphas%proc))) then
error stop "alphas%proc is null"
end if

if (present(state)) then
state_ = state
else
Expand Down
12 changes: 3 additions & 9 deletions pineappl_cli/src/convolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ pub struct Opts {
value_delimiter = ',',
value_parser = helpers::parse_order
)]
orders: Vec<(u32, u32)>,
/// Set the variation of the renormalization scale.
#[arg(default_value = "1.0", long, num_args = 1)]
xir: f64,
/// Set the variation of the factorization scale.
#[arg(default_value = "1.0", long, num_args = 1)]
xif: f64,
orders: Vec<(u8, u8)>,
/// Set the number of fractional digits shown for absolute numbers.
#[arg(default_value_t = 7, long, value_name = "ABS")]
digits_abs: usize,
Expand All @@ -58,13 +52,13 @@ impl Subcommand for Opts {
let mut conv_funs_0 = helpers::create_conv_funs(&self.conv_funs[0])?;
let bins: Vec<_> = self.bins.iter().cloned().flatten().collect();

let results = helpers::convolve_scales(
let results = helpers::convolve(
&grid,
&mut conv_funs_0,
&self.orders,
&bins,
&[],
&[(self.xir, self.xif)],
1,
if self.integrated {
ConvoluteMode::Integrated
} else {
Expand Down
7 changes: 1 addition & 6 deletions pineappl_cli/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,7 @@ fn map_format_e_join_repeat_last(slice: &[f64]) -> String {
}

/// Convert a channel to a good Python string representation.
fn map_format_channel(
channel: &Channel,
has_pdf1: bool,
has_pdf2: bool,
pid_basis: PidBasis,
) -> String {
fn map_format_channel(channel: &Channel, grid: &Grid) -> String {
channel
.entry()
.iter()
Expand Down
31 changes: 0 additions & 31 deletions pineappl_cli/tests/convolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Options:
-b, --bins <BINS> Selects a subset of bins
-i, --integrated Show integrated numbers (without bin widths) instead of differential ones
-o, --orders <ORDERS> Select orders manually
--xir <XIR> Set the variation of the renormalization scale [default: 1.0]
--xif <XIF> Set the variation of the factorization scale [default: 1.0]
--digits-abs <ABS> Set the number of fractional digits shown for absolute numbers [default: 7]
--digits-rel <REL> Set the number of fractional digits shown for relative numbers [default: 2]
-h, --help Print help
Expand Down Expand Up @@ -172,19 +170,6 @@ const WRONG_ORDERS_STR: &str = "error: invalid value 'a2a2as2' for '--orders <OR
For more information, try '--help'.
";

const XIR_XIF_STR: &str = "b etal dsig/detal
[] [pb]
-+----+----+-----------
0 2 2.25 7.6241231e2
1 2.25 2.5 6.9755130e2
2 2.5 2.75 6.0636076e2
3 2.75 3 4.9019741e2
4 3 3.25 3.6518490e2
5 3.25 3.5 2.4783934e2
6 3.5 4 1.1656958e2
7 4 4.5 2.7565811e1
";

#[test]
fn help() {
Command::cargo_bin("pineappl")
Expand Down Expand Up @@ -392,19 +377,3 @@ fn wrong_orders() {
.failure()
.stderr(WRONG_ORDERS_STR);
}

#[test]
fn xir_xif() {
Command::cargo_bin("pineappl")
.unwrap()
.args([
"convolve",
"--xir=2.34",
"--xif=1.79",
"../test-data/LHCB_WP_7TEV_opt.pineappl.lz4",
"NNPDF31_nlo_as_0118_luxqed",
])
.assert()
.success()
.stdout(XIR_XIF_STR);
}
8 changes: 7 additions & 1 deletion pineappl_py/docs/source/advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@
" q2 = 90.0 * 90.0\n",
"\n",
" # fill the interpolation grid\n",
" n_tuple = [q2, x1, x2] # Pass kinematics as list; order has to follow `[q2, x1, x2, ..., xn]`\n",
" n_tuple = [\n",
" q2,\n",
" x1,\n",
" x2,\n",
" ] # Pass kinematics as list; order has to follow `[q2, x1, x2, ..., xn]`\n",
" grid.fill(\n",
" order=0,\n",
" observable=np.abs(yll),\n",
Expand Down Expand Up @@ -337,6 +341,7 @@
")\n",
"from pineappl.pids import PidBasis\n",
"\n",
"\n",
"def grid_specs(\n",
" orders: list[Order],\n",
" channels: list[Channel],\n",
Expand Down Expand Up @@ -407,6 +412,7 @@
" scale_funcs=scale_funcs,\n",
" )\n",
"\n",
"\n",
"def generate_grid(calls: int) -> Grid:\n",
" \"\"\"Generate the grid.\"\"\"\n",
" # create a new luminosity function for the $\\gamma\\gamma$ initial state\n",
Expand Down
73 changes: 52 additions & 21 deletions pineappl_py/docs/source/introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"# We first need to load the PDF set with LHAPDF\n",
"import lhapdf\n",
"import numpy as np\n",
"\n",
"# `Polars` is a better alternative to Pandas (written in Rust!)\n",
"import polars as pl\n",
"\n",
Expand Down Expand Up @@ -214,14 +215,16 @@
],
"source": [
"predictions = grid.convolve(\n",
" pdg_convs=[conv_object, conv_object], # Similar convolutions for symmetric protons\n",
" pdg_convs=[conv_object, conv_object], # Similar convolutions for symmetric protons\n",
" xfxs=[pdf.xfxQ2, pdf.xfxQ2], # Similar PDF sets for symmetric protons\n",
" alphas=pdf.alphasQ2,\n",
")\n",
"df_preds = pl.DataFrame({\n",
" \"bins\": range(predictions.size),\n",
" \"predictions\": predictions,\n",
"})\n",
"df_preds = pl.DataFrame(\n",
" {\n",
" \"bins\": range(predictions.size),\n",
" \"predictions\": predictions,\n",
" }\n",
")\n",
"df_preds"
]
},
Expand Down Expand Up @@ -289,17 +292,42 @@
"import matplotlib.pyplot as plt\n",
"\n",
"# Experimental central values as provided by HepData\n",
"data_central = np.array([\n",
" 1223.0, 3263.0, 4983.0, 6719.0, 8051.0, 8967.0, 9561.0, 9822.0, 9721.0, 9030.0, 7748.0, 6059.0, 4385.0, 2724.0, 1584.0, 749.0, 383.0, 11.0\n",
"])\n",
"data_central = np.array(\n",
" [\n",
" 1223.0,\n",
" 3263.0,\n",
" 4983.0,\n",
" 6719.0,\n",
" 8051.0,\n",
" 8967.0,\n",
" 9561.0,\n",
" 9822.0,\n",
" 9721.0,\n",
" 9030.0,\n",
" 7748.0,\n",
" 6059.0,\n",
" 4385.0,\n",
" 2724.0,\n",
" 1584.0,\n",
" 749.0,\n",
" 383.0,\n",
" 11.0,\n",
" ]\n",
")\n",
"\n",
"# Normalization for each bin. See Section below for more details.\n",
"bin_norm = np.array([0.125 for _ in range(predictions.size - 2)] + [0.250, 0.250])\n",
"\n",
"fig, ax = plt.subplots(figsize=(5.6, 3.9))\n",
"# Factor of `1e3` takes into account the unit conversion into `fb`\n",
"ax.plot(df_preds[\"bins\"], 1e3 * bin_norm * df_preds[\"predictions\"], 's', markersize=8, label=\"theory\")\n",
"ax.plot(df_preds[\"bins\"], data_central, 'o', markersize=8, label=\"data\")\n",
"ax.plot(\n",
" df_preds[\"bins\"],\n",
" 1e3 * bin_norm * df_preds[\"predictions\"],\n",
" \"s\",\n",
" markersize=8,\n",
" label=\"theory\",\n",
")\n",
"ax.plot(df_preds[\"bins\"], data_central, \"o\", markersize=8, label=\"data\")\n",
"ax.grid(True, alpha=0.5)\n",
"ax.set_yscale(\"log\")\n",
"ax.set_xlabel(\"bins\")\n",
Expand Down Expand Up @@ -487,10 +515,7 @@
"for idx, o in enumerate(grid.orders()):\n",
" orders.append(o.as_tuple())\n",
"\n",
"df_orders = pl.DataFrame(\n",
" np.array(orders),\n",
" schema=[\"as\", \"a\", \"lf\", \"lr\", \"la\"]\n",
")\n",
"df_orders = pl.DataFrame(np.array(orders), schema=[\"as\", \"a\", \"lf\", \"lr\", \"la\"])\n",
"df_orders.with_row_index()"
]
},
Expand Down Expand Up @@ -577,10 +602,18 @@
"# an associated bin normalization.\n",
"df = pl.DataFrame({})\n",
"for bin_dim in range(bin_dims):\n",
" df = pl.concat([df,pl.DataFrame({\n",
" f\"dim {bin_dim} left\": grid.bin_left(bin_dim),\n",
" f\"dim {bin_dim} right\": grid.bin_right(bin_dim),\n",
" })],how=\"vertical\",)\n",
" df = pl.concat(\n",
" [\n",
" df,\n",
" pl.DataFrame(\n",
" {\n",
" f\"dim {bin_dim} left\": grid.bin_left(bin_dim),\n",
" f\"dim {bin_dim} right\": grid.bin_right(bin_dim),\n",
" }\n",
" ),\n",
" ],\n",
" how=\"vertical\",\n",
" )\n",
"df"
]
},
Expand Down Expand Up @@ -669,9 +702,7 @@
"# Extract the left & right bin limits\n",
"bin_limits = [\n",
" (left, right)\n",
" for left, right in zip(\n",
" grid.bin_left(bin_dims - 1), grid.bin_right(bin_dims - 1)\n",
" )\n",
" for left, right in zip(grid.bin_left(bin_dims - 1), grid.bin_right(bin_dims - 1))\n",
"]\n",
"\n",
"# Multiply the normalization by a factor of `2`\n",
Expand Down

0 comments on commit fa46e44

Please sign in to comment.