From fa46e4493c3a06bd3f43dfe55432a25858c8b4f4 Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Sun, 1 Dec 2024 23:00:01 +0100 Subject: [PATCH] Fix minor issues during merge --- examples/fortran/pineappl.f90 | 14 ++--- pineappl_cli/src/convolve.rs | 12 +--- pineappl_cli/src/plot.rs | 7 +-- pineappl_cli/tests/convolve.rs | 31 --------- pineappl_py/docs/source/advanced.ipynb | 8 ++- pineappl_py/docs/source/introduction.ipynb | 73 +++++++++++++++------- 6 files changed, 70 insertions(+), 75 deletions(-) diff --git a/examples/fortran/pineappl.f90 b/examples/fortran/pineappl.f90 index f972cf8c..d0812996 100644 --- a/examples/fortran/pineappl.f90 +++ b/examples/fortran/pineappl.f90 @@ -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 @@ -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(*) @@ -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 @@ -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 @@ -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_ @@ -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 diff --git a/pineappl_cli/src/convolve.rs b/pineappl_cli/src/convolve.rs index b7a9d76a..466e286e 100644 --- a/pineappl_cli/src/convolve.rs +++ b/pineappl_cli/src/convolve.rs @@ -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, @@ -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 { diff --git a/pineappl_cli/src/plot.rs b/pineappl_cli/src/plot.rs index d94757bb..c381f0c6 100644 --- a/pineappl_cli/src/plot.rs +++ b/pineappl_cli/src/plot.rs @@ -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() diff --git a/pineappl_cli/tests/convolve.rs b/pineappl_cli/tests/convolve.rs index 411a4e04..54be75c0 100644 --- a/pineappl_cli/tests/convolve.rs +++ b/pineappl_cli/tests/convolve.rs @@ -15,8 +15,6 @@ Options: -b, --bins Selects a subset of bins -i, --integrated Show integrated numbers (without bin widths) instead of differential ones -o, --orders Select orders manually - --xir Set the variation of the renormalization scale [default: 1.0] - --xif Set the variation of the factorization scale [default: 1.0] --digits-abs Set the number of fractional digits shown for absolute numbers [default: 7] --digits-rel Set the number of fractional digits shown for relative numbers [default: 2] -h, --help Print help @@ -172,19 +170,6 @@ const WRONG_ORDERS_STR: &str = "error: invalid value 'a2a2as2' for '--orders Grid:\n", " \"\"\"Generate the grid.\"\"\"\n", " # create a new luminosity function for the $\\gamma\\gamma$ initial state\n", diff --git a/pineappl_py/docs/source/introduction.ipynb b/pineappl_py/docs/source/introduction.ipynb index 6e0a705f..7b51ae33 100644 --- a/pineappl_py/docs/source/introduction.ipynb +++ b/pineappl_py/docs/source/introduction.ipynb @@ -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", @@ -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" ] }, @@ -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", @@ -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()" ] }, @@ -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" ] }, @@ -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",