Skip to content

Commit 84dc918

Browse files
committed
Add --fk-table-{fac0,frg0} switches to pineappl read
1 parent 12afc60 commit 84dc918

File tree

7 files changed

+96
-31
lines changed

7 files changed

+96
-31
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ the old file format can still be read with this new version.
2323
- the CLI now allows the user to mark convolution functions as polarized
2424
by adding `+p` to its LHAPDF name, as a fragmentation function by adding
2525
`+f` and both by adding `+pf` or `+fp`
26+
- added switches `--fk-table-fac0` and `--fk-table-frg0` to `pineappl read` to
27+
read out the squared factorization and fragmentation scales of FK-tables
2628

2729
### Changed
2830

@@ -51,6 +53,7 @@ the old file format can still be read with this new version.
5153
`--set-bins`, `--remap-norm-ignore` to `--div-bin-norm-dims` and
5254
`--remap-norm` to `--mul-bin-norm`. These names should reflect the
5355
corresponding operations
56+
- renamed the switch `--fktable` to `--fk-table` of `pineappl read`
5457

5558
### Removed
5659

Diff for: pineappl/src/fk_table.rs

+23-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::grid::Grid;
88
use super::pids::OptRules;
99
use super::subgrid::{self, Subgrid};
1010
use ndarray::{s, ArrayD};
11+
use std::collections::BTreeMap;
1112
use std::fmt::{self, Display, Formatter};
1213
use std::iter;
1314
use std::str::FromStr;
@@ -189,24 +190,32 @@ impl FkTable {
189190

190191
/// Returns the single `muf2` scale of this `FkTable`.
191192
#[must_use]
192-
pub fn muf2(&self) -> f64 {
193-
let [muf2] = self.grid.evolve_info(&[true]).fac1[..]
194-
.try_into()
195-
// UNWRAP: every `FkTable` has only a single factorization scale
196-
.unwrap_or_else(|_| unreachable!());
197-
198-
muf2
193+
pub fn fac0(&self) -> Option<f64> {
194+
let fac1 = self.grid.evolve_info(&[true]).fac1;
195+
196+
if let [fac0] = fac1[..] {
197+
Some(fac0)
198+
} else if fac1.is_empty() {
199+
None
200+
} else {
201+
// UNWRAP: every `FkTable` has either a single factorization scale or none
202+
unreachable!()
203+
}
199204
}
200205

201206
/// Return the initial fragmentation scale.
202207
#[must_use]
203-
pub fn frg0(&self) -> f64 {
204-
let [frg0] = self.grid.evolve_info(&[true]).frg1[..]
205-
.try_into()
206-
// UNWRAP: every `FkTable` has only a single fragmentation scale
207-
.unwrap_or_else(|_| unreachable!());
208-
209-
frg0
208+
pub fn frg0(&self) -> Option<f64> {
209+
let frg1 = self.grid.evolve_info(&[true]).frg1;
210+
211+
if let [frg0] = frg1[..] {
212+
Some(frg0)
213+
} else if frg1.is_empty() {
214+
None
215+
} else {
216+
// UNWRAP: every `FkTable` has either a single fragmentation scale or none
217+
unreachable!()
218+
}
210219
}
211220

212221
/// Set a metadata key-value pair for this FK table.

Diff for: pineappl_cli/src/read.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ struct Group {
2929
channels: bool,
3030
/// Check if input is an FK table.
3131
#[arg(long)]
32-
fktable: bool,
33-
32+
fk_table: bool,
33+
/// Return the (squared) factorization scale of the FK-table.
34+
#[arg(long)]
35+
fk_table_fac0: bool,
36+
/// Return the (squared) fragmentation scale of the FK-table.
37+
#[arg(long)]
38+
fk_table_frg0: bool,
3439
/// For each order print a list of the largest EW order.
3540
#[arg(long)]
3641
ew: bool,
@@ -88,13 +93,33 @@ impl Subcommand for Opts {
8893

8994
row.add_cell(cell!(r->bin.normalization().to_string()));
9095
}
91-
} else if self.group.fktable {
96+
} else if self.group.fk_table {
9297
if let Err(err) = FkTable::try_from(grid) {
9398
println!("no\n{err}");
9499
return Ok(ExitCode::FAILURE);
95100
}
96101

97102
println!("yes");
103+
return Ok(ExitCode::SUCCESS);
104+
} else if self.group.fk_table_fac0 {
105+
let fk_table = FkTable::try_from(grid)?;
106+
107+
if let Some(fac0) = fk_table.fac0() {
108+
println!("{fac0}");
109+
} else {
110+
println!("None");
111+
}
112+
113+
return Ok(ExitCode::SUCCESS);
114+
} else if self.group.fk_table_frg0 {
115+
let fk_table = FkTable::try_from(grid)?;
116+
117+
if let Some(frg0) = fk_table.frg0() {
118+
println!("{frg0}");
119+
} else {
120+
println!("None");
121+
}
122+
98123
return Ok(ExitCode::SUCCESS);
99124
} else if self.group.channels {
100125
let mut titles = row![c => "c"];

Diff for: pineappl_cli/tests/import.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -705,18 +705,32 @@ fn import_dis_fktable() {
705705

706706
Command::cargo_bin("pineappl")
707707
.unwrap()
708-
.args(["read", "--fktable", output.path().to_str().unwrap()])
708+
.args(["read", "--fk-table", output.path().to_str().unwrap()])
709709
.assert()
710710
.success()
711711
.stdout("yes\n");
712712

713+
Command::cargo_bin("pineappl")
714+
.unwrap()
715+
.args(["read", "--fk-table-fac0", output.path().to_str().unwrap()])
716+
.assert()
717+
.success()
718+
.stdout("2.7224999999999997\n");
719+
720+
Command::cargo_bin("pineappl")
721+
.unwrap()
722+
.args(["read", "--fk-table-frg0", output.path().to_str().unwrap()])
723+
.assert()
724+
.success()
725+
.stdout("None\n");
726+
713727
let fk_table =
714728
FkTable::try_from(Grid::read(File::open(output.path()).unwrap()).unwrap()).unwrap();
715729

716730
// TODO: this should ideally be a unit test, but we need an FK table that we don't convert
717731

718732
assert_eq!(fk_table.grid().kinematics().len(), 2);
719-
assert_approx_eq!(f64, fk_table.muf2(), 1.65 * 1.65, ulps = 2);
733+
assert_approx_eq!(f64, fk_table.fac0().unwrap(), 1.65 * 1.65, ulps = 2);
720734
assert_eq!(
721735
fk_table.x_grid(),
722736
[
@@ -985,7 +999,7 @@ fn import_hadronic_fktable() {
985999
[115, 115]
9861000
]
9871001
);
988-
assert_approx_eq!(f64, fk_table.muf2(), 1.65 * 1.65, ulps = 2);
1002+
assert_approx_eq!(f64, fk_table.fac0().unwrap(), 1.65 * 1.65, ulps = 2);
9891003
assert_eq!(
9901004
fk_table.x_grid(),
9911005
[

Diff for: pineappl_cli/tests/read.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use assert_cmd::Command;
44

55
const HELP_STR: &str = "Read out information of a grid
66
7-
Usage: pineappl read <--orders|--orders-spaces|--orders-long|--bins|--channels|--fktable|--ew|--get <KEY>|--keys|--qcd|--show> <INPUT>
7+
Usage: pineappl read <--orders|--orders-spaces|--orders-long|--bins|--channels|--fk-table|--fk-table-fac0|--fk-table-frg0|--ew|--get <KEY>|--keys|--qcd|--show> <INPUT>
88
99
Arguments:
1010
<INPUT> Path to the input grid
@@ -15,7 +15,9 @@ Options:
1515
--orders-long Show the orders of a grid, including zero powers
1616
-b, --bins Show the bins of a grid
1717
--channels Show the channel definition of a grid
18-
--fktable Check if input is an FK table
18+
--fk-table Check if input is an FK table
19+
--fk-table-fac0 Return the (squared) factorization scale of the FK-table
20+
--fk-table-frg0 Return the (squared) fragmentation scale of the FK-table
1921
--ew For each order print a list of the largest EW order
2022
--get <KEY> Gets an internal key-value pair
2123
--keys Show all keys stored in the grid
@@ -78,7 +80,7 @@ multiple orders detected
7880

7981
const WRONG_ORDERS_STR: &str = "error: the argument '--orders' cannot be used with '--orders-long'
8082
81-
Usage: pineappl read <--orders|--orders-spaces|--orders-long|--bins|--channels|--fktable|--ew|--get <KEY>|--keys|--qcd|--show> <INPUT>
83+
Usage: pineappl read <--orders|--orders-spaces|--orders-long|--bins|--channels|--fk-table|--fk-table-fac0|--fk-table-frg0|--ew|--get <KEY>|--keys|--qcd|--show> <INPUT>
8284
8385
For more information, try '--help'.
8486
";
@@ -545,7 +547,7 @@ y_unit: pb
545547

546548
const WRONG_ARGUMENTS_STR: &str = "error: the argument '--ew' cannot be used with '--qcd'
547549
548-
Usage: pineappl read <--orders|--orders-spaces|--orders-long|--bins|--channels|--fktable|--ew|--get <KEY>|--keys|--qcd|--show> <INPUT>
550+
Usage: pineappl read <--orders|--orders-spaces|--orders-long|--bins|--channels|--fk-table|--fk-table-fac0|--fk-table-frg0|--ew|--get <KEY>|--keys|--qcd|--show> <INPUT>
549551
550552
For more information, try '--help'.
551553
";
@@ -631,12 +633,12 @@ fn orders_spaces() {
631633
}
632634

633635
#[test]
634-
fn fktable() {
636+
fn fk_table() {
635637
Command::cargo_bin("pineappl")
636638
.unwrap()
637639
.args([
638640
"read",
639-
"--fktable",
641+
"--fk-table",
640642
"../test-data/LHCB_WP_7TEV_opt.pineappl.lz4",
641643
])
642644
.assert()

Diff for: pineappl_py/src/fk_table.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,26 @@ impl PyFkTable {
173173
self.fk_table.channels()
174174
}
175175

176-
/// Get reference (fitting) scale.
176+
/// Get squared factorization scale.
177177
///
178178
/// Returns
179179
/// -------
180180
/// float :
181-
/// reference scale
181+
/// squared factorization scale
182182
#[must_use]
183-
pub fn muf2(&self) -> f64 {
184-
self.fk_table.muf2()
183+
pub fn fac0(&self) -> Option<f64> {
184+
self.fk_table.fac0()
185+
}
186+
187+
/// Get squared fragmentation scale.
188+
///
189+
/// Returns
190+
/// -------
191+
/// float :
192+
/// squared fragmentation scale
193+
#[must_use]
194+
pub fn frg0(&self) -> Option<f64> {
195+
self.fk_table.frg0()
185196
}
186197

187198
/// Get (unique) interpolation grid.

Diff for: pineappl_py/tests/test_fk_table.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def test_fktable(
7777
fk = FkTable.read(fk_table)
7878

7979
assert fk.table().shape == (1, 51, 34, 34)
80-
np.testing.assert_allclose(fk.muf2(), 2.7224999999999997)
80+
np.testing.assert_allclose(fk.fac0(), 2.7224999999999997)
81+
assert fk.frg0() == None
8182

8283
# Check the various aspects of the Bins
8384
assert fk.bins() == 1

0 commit comments

Comments
 (0)