Skip to content

Commit 8af86ee

Browse files
committed
Add code to convolve converted grid
1 parent 87b3ee3 commit 8af86ee

2 files changed

Lines changed: 51 additions & 22 deletions

File tree

pineappl_cli/src/export.rs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,61 @@ fn convert_into_applgrid(
4949
fn convert_into_fastnlo(
5050
output: &Path,
5151
grid: &Grid,
52-
conv_funs: &mut [Pdf],
53-
_: usize,
52+
fun_names: &ConvFuns,
53+
scales: usize,
5454
discard_non_matching_scales: bool,
5555
) -> Result<(&'static str, Vec<f64>, usize, Vec<bool>)> {
56-
// TODO: check also scale-varied results
56+
use pineappl_fastnlo::ffi;
57+
58+
// TODO: other cases NYI
59+
assert_eq!(scales, 1);
60+
61+
// TODO: convert this into an error?
62+
assert_eq!(fun_names.lhapdf_names.len(), 1);
63+
64+
// this creates a file, but doesn't give us an object that we can convolve with a function
65+
let order_mask = fastnlo::convert_into_fastnlo(grid, output, discard_non_matching_scales)?;
66+
67+
// so load this file, giving the right PDF set
68+
let mut file = ffi::make_fastnlo_lhapdf_with_name_file_set(
69+
output.to_str().unwrap(),
70+
&fun_names.lhapdf_names[0],
71+
// UNWRAP: this shouldn't be negative or overflow
72+
fun_names.members[0].unwrap_or(0).try_into().unwrap(),
73+
);
5774

58-
let (mut fastnlo, order_mask) =
59-
fastnlo::convert_into_fastnlo(grid, output, discard_non_matching_scales)?;
60-
let results = fastnlo::convolve_fastnlo(fastnlo.pin_mut(), conv_funs);
75+
let mut reader = ffi::downcast_lhapdf_to_reader_mut(file.as_mut().unwrap());
6176

62-
Ok(("fastNLO", results, 1, order_mask))
77+
// fastNLO does not support a fragmentation scale
78+
let unpermuted_results: Vec<_> = helpers::SCALES_VECTOR_REN_FAC[0..scales]
79+
.iter()
80+
.map(|&(xir, xif, _)| {
81+
if !reader.as_mut().SetScaleFactorsMuRMuF(xir, xif) {
82+
return None;
83+
}
84+
reader.as_mut().CalcCrossSection();
85+
Some(ffi::GetCrossSection(reader.as_mut(), false))
86+
})
87+
.take_while(Option::is_some)
88+
.map(Option::unwrap)
89+
.collect();
90+
91+
assert!(matches!(unpermuted_results.len(), 1 | 3 | 7 | 9));
92+
93+
let bins = unpermuted_results[0].len();
94+
95+
let results: Vec<_> = (0..bins)
96+
.flat_map(|bin| unpermuted_results.iter().map(move |r| r[bin]))
97+
.collect();
98+
99+
Ok(("fastNLO", results, scales, order_mask))
63100
}
64101

65102
#[cfg(not(feature = "fastnlo"))]
66103
fn convert_into_fastnlo(
67104
_: &Path,
68105
_: &Grid,
69-
_: &mut [Pdf],
106+
_: &ConvFuns,
70107
_: usize,
71108
_: bool,
72109
) -> Result<(&'static str, Vec<f64>, usize, Vec<bool>)> {
@@ -79,6 +116,7 @@ fn convert_into_grid(
79116
output: &Path,
80117
grid: &mut Grid,
81118
conv_funs: &mut [Pdf],
119+
fun_names: &ConvFuns,
82120
scales: usize,
83121
discard_non_matching_scales: bool,
84122
) -> Result<(&'static str, Vec<f64>, usize, Vec<bool>)> {
@@ -101,7 +139,7 @@ fn convert_into_grid(
101139
return convert_into_fastnlo(
102140
output,
103141
grid,
104-
conv_funs,
142+
fun_names,
105143
scales,
106144
discard_non_matching_scales,
107145
);
@@ -158,6 +196,7 @@ impl Subcommand for Opts {
158196
&self.output,
159197
&mut grid,
160198
&mut conv_funs,
199+
&self.conv_funs,
161200
self.scales,
162201
self.discard_non_matching_scales,
163202
)?;

pineappl_cli/src/export/fastnlo.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
use anyhow::{Result, bail};
2-
use cxx::UniquePtr;
32
use float_cmp::assert_approx_eq;
4-
use lhapdf::Pdf;
53
use pineappl::boc::Order;
64
use pineappl::grid::Grid;
7-
use pineappl_fastnlo::ffi::{self, fastNLOLHAPDF};
5+
use pineappl_fastnlo::ffi;
86
use std::path::Path;
9-
use std::pin::Pin;
107

118
pub fn convert_into_fastnlo(
129
grid: &Grid,
1310
output: &Path,
1411
_discard_non_matching_scales: bool,
15-
) -> Result<(UniquePtr<fastNLOLHAPDF>, Vec<bool>)> {
12+
) -> Result<Vec<bool>> {
1613
let bwfl = grid.bwfl();
1714
let dim = bwfl.dimensions();
1815

@@ -108,12 +105,5 @@ pub fn convert_into_fastnlo(
108105

109106
ffi::WriteTable(fastnlo.pin_mut(), &output);
110107

111-
todo!()
112-
}
113-
114-
pub fn convolve_fastnlo(_grid: Pin<&mut fastNLOLHAPDF>, conv_funs: &mut [Pdf]) -> Vec<f64> {
115-
// TODO: add support for convolving an fastNLO table with two functions
116-
assert_eq!(conv_funs.len(), 1);
117-
118-
todo!()
108+
Ok(order_mask)
119109
}

0 commit comments

Comments
 (0)