Skip to content

Commit 85bf72b

Browse files
Allow a generic number of EKOs to be passed to pineappl evolve
1 parent 40cadc0 commit 85bf72b

File tree

4 files changed

+70
-22
lines changed

4 files changed

+70
-22
lines changed

pineappl_cli/src/evolve.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use super::helpers::{self, ConvFuns, ConvoluteMode};
1+
use super::helpers::{self, ConvFuns, ConvoluteMode, EkoNames};
22
use super::{GlobalConfiguration, Subcommand};
33
use anyhow::{anyhow, Result};
44
use clap::{Parser, ValueHint};
55
use lhapdf::Pdf;
66
use pineappl::fk_table::FkTable;
77
use pineappl::grid::Grid;
8-
use std::path::{Path, PathBuf};
8+
use std::path::PathBuf;
99
use std::process::ExitCode;
1010

1111
#[cfg(feature = "evolve")]
@@ -438,7 +438,7 @@ mod eko {
438438
#[cfg(feature = "evolve")]
439439
fn evolve_grid(
440440
grid: &Grid,
441-
ekos: &[&Path],
441+
ekos: &[PathBuf],
442442
use_alphas_from: &Pdf,
443443
orders: &[(u8, u8)],
444444
xir: f64,
@@ -461,7 +461,7 @@ fn evolve_grid(
461461

462462
let mut eko_slices: Vec<_> = ekos
463463
.iter()
464-
.map(|eko| EkoSlices::new(eko))
464+
.map(|eko| EkoSlices::new(eko.as_path()))
465465
.collect::<Result<_, _>>()?;
466466
let eko_slices: Vec<_> = eko_slices.iter_mut().collect();
467467
let alphas_table = AlphasTable::from_grid(grid, xir, &|q2| use_alphas_from.alphas_q2(q2));
@@ -490,17 +490,14 @@ pub struct Opts {
490490
/// Path to the input grid.
491491
#[arg(value_hint = ValueHint::FilePath)]
492492
input: PathBuf,
493-
/// Path to the evolution kernel operator.
494-
#[arg(value_hint = ValueHint::FilePath)]
495-
eko: PathBuf,
493+
/// Path to the evolution kernel operator(s).
494+
#[arg(value_name = "EKOs")]
495+
ekos: EkoNames,
496496
/// Path to the converted grid.
497497
#[arg(value_hint = ValueHint::FilePath)]
498498
output: PathBuf,
499499
/// LHAPDF ID(s) or name of the PDF(s)/FF(s).
500500
conv_funs: ConvFuns,
501-
/// Additional path to the 2nd evolution kernel operator.
502-
#[arg(value_hint = ValueHint::FilePath, long)]
503-
ekob: Option<PathBuf>,
504501
/// Relative threshold between the table and the converted grid when comparison fails.
505502
#[arg(default_value = "1e-3", long)]
506503
accuracy: f64,
@@ -548,12 +545,10 @@ impl Subcommand for Opts {
548545
cfg,
549546
);
550547

548+
let ekonames = helpers::create_eko_paths(&self.ekos, &self.conv_funs.conv_types);
551549
let fk_table = evolve_grid(
552550
&grid,
553-
&self.ekob.as_ref().map_or_else(
554-
|| vec![self.eko.as_path()],
555-
|ekob| vec![self.eko.as_path(), ekob],
556-
),
551+
&ekonames,
557552
&conv_funs[cfg.use_alphas_from],
558553
&self.orders,
559554
self.xir,

pineappl_cli/src/helpers.rs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,62 @@ use prettytable::Table;
1010
use std::fs::{File, OpenOptions};
1111
use std::iter;
1212
use std::ops::RangeInclusive;
13-
use std::path::Path;
13+
use std::path::{Path, PathBuf};
1414
use std::process::ExitCode;
1515
use std::str::FromStr;
1616

17+
#[derive(Clone, Debug, Eq, PartialEq)]
18+
pub struct EkoNames {
19+
pub eko_names: Vec<String>,
20+
pub conv_types: Vec<ConvType>,
21+
}
22+
23+
impl FromStr for EkoNames {
24+
type Err = Error;
25+
26+
fn from_str(arg: &str) -> std::result::Result<Self, Self::Err> {
27+
let (eko_names, conv_types) = arg
28+
.split(',')
29+
.map(|fun| {
30+
let (name, typ) = fun.split_once('+').unwrap_or((fun, ""));
31+
let name = name.to_owned();
32+
33+
let typ = match typ {
34+
"" => ConvType::UnpolPDF,
35+
"p" => ConvType::PolPDF,
36+
"f" => ConvType::UnpolFF,
37+
"pf" | "fp" => ConvType::PolFF,
38+
_ => bail!("unknown convolution type '{typ}'"),
39+
};
40+
Ok::<_, Error>((name, typ))
41+
})
42+
.collect::<Result<Vec<(String, ConvType)>>>()?
43+
.into_iter()
44+
.multiunzip();
45+
46+
Ok(Self {
47+
eko_names,
48+
conv_types,
49+
})
50+
}
51+
}
52+
53+
pub fn create_eko_paths(eko_obj: &EkoNames, conv_types: &[ConvType]) -> Vec<PathBuf> {
54+
let vec_ekonames: Vec<String> = conv_types
55+
.iter()
56+
.map(|convtype| {
57+
let eko_cv_idx = eko_obj
58+
.conv_types
59+
.iter()
60+
.position(|&x| x == *convtype)
61+
.unwrap_or(0);
62+
eko_obj.eko_names[eko_cv_idx].clone()
63+
})
64+
.collect();
65+
66+
vec_ekonames.iter().map(PathBuf::from).collect()
67+
}
68+
1769
#[derive(Clone, Debug, Eq, PartialEq)]
1870
pub struct ConvFuns {
1971
pub lhapdf_names: Vec<String>,
@@ -269,7 +321,8 @@ pub fn convolve_scales(
269321
// TODO: promote this to an error
270322
assert!(
271323
cfg.use_alphas_from < conv_funs.len(),
272-
"expected `use_alphas_from` to be `0` or `1`, is `{}`",
324+
"expected `use_alphas_from` to be an integer within `[0, {})`, but got `{}`",
325+
conv_funs.len(),
273326
cfg.use_alphas_from
274327
);
275328

pineappl_cli/tests/convolve.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const DEFAULT_STR: &str = "b etal dsig/detal
3636
7 4 4.5 2.7517266e1
3737
";
3838

39-
const USE_ALPHAS_FROM_ERROR_STR: &str = "expected `use_alphas_from` to be `0` or `1`, is `2`
39+
const USE_ALPHAS_FROM_ERROR_STR: &str =
40+
"expected `use_alphas_from` to be an integer within `[0, 2)`, but got `2`
4041
";
4142

4243
const FORCE_POSITIVE_STR: &str = "b etal dsig/detal

pineappl_cli/tests/evolve.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ use assert_fs::NamedTempFile;
66

77
const HELP_STR: &str = "Evolve a grid with an evolution kernel operator to an FK table
88
9-
Usage: pineappl evolve [OPTIONS] <INPUT> <EKO> <OUTPUT> <CONV_FUNS>
9+
Usage: pineappl evolve [OPTIONS] <INPUT> <EKOs> <OUTPUT> <CONV_FUNS>
1010
1111
Arguments:
1212
<INPUT> Path to the input grid
13-
<EKO> Path to the evolution kernel operator
13+
<EKOs> Path to the evolution kernel operator(s)
1414
<OUTPUT> Path to the converted grid
1515
<CONV_FUNS> LHAPDF ID(s) or name of the PDF(s)/FF(s)
1616
1717
Options:
18-
--ekob <EKOB> Additional path to the 2nd evolution kernel operator
1918
--accuracy <ACCURACY> Relative threshold between the table and the converted grid when comparison fails [default: 1e-3]
2019
--digits-abs <ABS> Set the number of fractional digits shown for absolute numbers [default: 7]
2120
--digits-rel <REL> Set the number of fractional digits shown for relative numbers [default: 7]
@@ -428,15 +427,15 @@ fn cms_ttb_8tev_2d_ttm_trap_tot() {
428427
fn star_wmwp_510gev_wm_al_pol() {
429428
let output = NamedTempFile::new("fktable6.lz4").unwrap();
430429

430+
// Here the order of the EKOs are swapped to check that mapping convtype is working
431431
Command::cargo_bin("pineappl")
432432
.unwrap()
433433
.args([
434434
"evolve",
435435
"../test-data/STAR_WMWP_510GEV_WM-AL-POL.pineappl.lz4",
436-
"../test-data/STAR_WMWP_510GEV_WM-AL-POL_PolPDF.tar",
436+
"../test-data/STAR_WMWP_510GEV_WM-AL-POL_UnpolPDF.tar,../test-data/STAR_WMWP_510GEV_WM-AL-POL_PolPDF.tar+p",
437437
output.path().to_str().unwrap(),
438438
"240608-tr-pol-nlo-100+p,NNPDF40_nlo_pch_as_01180",
439-
"--ekob=../test-data/STAR_WMWP_510GEV_WM-AL-POL_UnpolPDF.tar",
440439
])
441440
.assert()
442441
.success()

0 commit comments

Comments
 (0)