Skip to content

Commit

Permalink
Fix more compilation errors when features are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Aug 5, 2024
1 parent 0d360b4 commit 87b3bf3
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 68 deletions.
57 changes: 31 additions & 26 deletions pineappl_cli/src/export/applgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,43 @@ pub fn convert_into_applgrid(
bail!("grid has non-consecutive bin limits, which APPLgrid does not support");
}

if grid.convolutions().len() > 2 {
bail!("APPLgrid does not support grids with more than two convolutions");
}

let lumis = grid.channels().len();
let has_pdf1 = grid.convolutions()[0] != Convolution::None;
let has_pdf2 = grid.convolutions()[1] != Convolution::None;

// TODO: check that PDG MC IDs are used

let combinations: Vec<_> = iter::once(lumis.try_into().unwrap())
.chain(
grid.channels()
.iter()
.enumerate()
.flat_map(|(index, entry)| {
[
index.try_into().unwrap(),
entry.entry().len().try_into().unwrap(),
]
.into_iter()
.chain(entry.entry().iter().flat_map(|&(a, b, factor)| {
// TODO: if the factors aren't trivial, we have to find some other way to
// propagate them
assert_eq!(factor, 1.0);

match (has_pdf1, has_pdf2) {
(true, true) => [a, b],
(true, false) => [a, 0],
(false, true) => [b, 0],
(false, false) => unreachable!(),
}
}))
}),
)
.collect();
let combinations: Vec<_> =
iter::once(lumis.try_into().unwrap())
.chain(
grid.channels()
.iter()
.enumerate()
.flat_map(|(index, entry)| {
[
index.try_into().unwrap(),
entry.entry().len().try_into().unwrap(),
]
.into_iter()
.chain(entry.entry().iter().flat_map(|&(ref pids, factor)| {
// TODO: if the factors aren't trivial, we have to find some other way to
// propagate them
assert_eq!(factor, 1.0);

match (has_pdf1, has_pdf2) {
(true, true) => [pids[0], pids[1]],
(true, false) => [pids[0], 0],
(false, true) => [pids[1], 0],
(false, false) => unreachable!(),
}
}))
}),
)
.collect();

// `id` must end with '.config' for APPLgrid to know its type is `lumi_pdf`
let id = "PineAPPL-Lumi.config";
Expand Down
37 changes: 23 additions & 14 deletions pineappl_cli/src/import/applgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ fn convert_to_pdg_id(pid: usize) -> i32 {
}
}

fn reconstruct_luminosity_function(grid: &grid, order: i32, dis_pid: i32) -> Vec<Channel> {
fn reconstruct_channels(grid: &grid, order: i32, dis_pid: i32) -> Vec<Channel> {
let pdf = unsafe { &*grid.genpdf(order, false) };
let nproc: usize = pdf.Nproc().try_into().unwrap();

let mut lumis = vec![Vec::new(); nproc];
let mut channels = vec![Vec::new(); nproc];
let mut xfx1 = [0.0; 14];
let mut xfx2 = [0.0; 14];
let mut results = vec![0.0; nproc];
Expand All @@ -41,7 +41,7 @@ fn reconstruct_luminosity_function(grid: &grid, order: i32, dis_pid: i32) -> Vec

for i in 0..nproc {
if results[i] != 0.0 {
lumis[i].push((convert_to_pdg_id(a), dis_pid, results[i]));
channels[i].push((vec![convert_to_pdg_id(a), dis_pid], results[i]));
}
}
} else {
Expand All @@ -54,7 +54,8 @@ fn reconstruct_luminosity_function(grid: &grid, order: i32, dis_pid: i32) -> Vec

for i in 0..nproc {
if results[i] != 0.0 {
lumis[i].push((convert_to_pdg_id(a), convert_to_pdg_id(b), results[i]));
channels[i]
.push((vec![convert_to_pdg_id(a), convert_to_pdg_id(b)], results[i]));
}
}

Expand All @@ -65,7 +66,7 @@ fn reconstruct_luminosity_function(grid: &grid, order: i32, dis_pid: i32) -> Vec
xfx1[a] = 0.0;
}

lumis.into_iter().map(Channel::new).collect()
channels.into_iter().map(Channel::new).collect()
}

pub fn convert_applgrid(grid: Pin<&mut grid>, alpha: u32, dis_pid: i32) -> Result<Grid> {
Expand All @@ -80,21 +81,29 @@ pub fn convert_applgrid(grid: Pin<&mut grid>, alpha: u32, dis_pid: i32) -> Resul
if grid.calculation() == ffi::grid_CALCULATION::AMCATNLO {
alphas_factor = 2.0 * TAU;
orders = if grid.nloops() == 0 {
vec![Order::new(leading_order, alpha, 0, 0)]
vec![Order::new(leading_order, alpha, 0, 0, 0)]
} else if grid.nloops() == 1 {
vec![
Order::new(leading_order + 1, alpha, 0, 0), // NLO
Order::new(leading_order + 1, alpha, 1, 0), // NLO mur
Order::new(leading_order + 1, alpha, 0, 1), // NLO muf
Order::new(leading_order, alpha, 0, 0), // LO
Order::new(leading_order + 1, alpha, 0, 0, 0), // NLO
Order::new(leading_order + 1, alpha, 1, 0, 0), // NLO mur
Order::new(leading_order + 1, alpha, 0, 1, 0), // NLO muf
Order::new(leading_order, alpha, 0, 0, 0), // LO
]
} else {
unimplemented!("nloops = {} is not supported", grid.nloops());
};
} else if grid.calculation() == ffi::grid_CALCULATION::STANDARD {
alphas_factor = 1.0 / TAU;
orders = (0..=grid.nloops())
.map(|power| Order::new(leading_order + u32::try_from(power).unwrap(), alpha, 0, 0))
.map(|power| {
Order::new(
leading_order + u32::try_from(power).unwrap(),
alpha,
0,
0,
0,
)
})
.collect();
} else {
unimplemented!("calculation is not supported");
Expand All @@ -114,10 +123,10 @@ pub fn convert_applgrid(grid: Pin<&mut grid>, alpha: u32, dis_pid: i32) -> Resul
let mut grids = Vec::with_capacity(orders.len());

for (i, order) in orders.into_iter().enumerate() {
let lumis = reconstruct_luminosity_function(&grid, i.try_into().unwrap(), dis_pid);
let lumis_len = lumis.len();
let channels = reconstruct_channels(&grid, i.try_into().unwrap(), dis_pid);
let lumis_len = channels.len();
let mut pgrid = Grid::new(
lumis,
channels,
vec![order],
bin_limits.clone(),
SubgridParams::default(),
Expand Down
45 changes: 23 additions & 22 deletions pineappl_cli/src/import/fastnlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ fn pid_to_pdg_id(pid: i32) -> i32 {
}
}

fn create_lumi(
fn reconstruct_channels(
table: &fastNLOCoeffAddBase,
comb: &fastNLOPDFLinearCombinations,
dis_pid: i32,
) -> Vec<Channel> {
let dis_pid = if table.GetNPDF() == 2 { 0 } else { dis_pid };
let mut lumis = Vec::new();
let mut channels = Vec::new();

// if there's a (non-empty) PDF coefficient vector reconstruct the luminosity function; the
// advantage is that we preserve the order of the lumi entries in the PineAPPL grid
// if there's a (non-empty) PDF coefficient vector reconstruct the channels; the advantage is
// that we preserve the order of the channels in the PineAPPL grid
for pdf_entry in 0..ffi::GetPDFCoeffSize(table) {
let mut entries = Vec::new();

Expand All @@ -44,14 +44,14 @@ fn create_lumi(
};
let f = 1.0;

entries.push((a, b, f));
entries.push((vec![a, b], f));
}

lumis.push(Channel::new(entries));
channels.push(Channel::new(entries));
}

// if the PDF coefficient vector was empty, we must reconstruct the lumi function
if lumis.is_empty() {
// if the PDF coefficient vector was empty, we must reconstruct the channels in a different way
if channels.is_empty() {
let nsubproc = table.GetNSubproc().try_into().unwrap();

let mut xfx1 = [0.0; 13];
Expand All @@ -66,15 +66,15 @@ fn create_lumi(
for b in 0..13 {
xfx2[b] = 1.0;

let lumi = ffi::CalcPDFLinearCombination(comb, table, &xfx1, &xfx2, false);
let channel = ffi::CalcPDFLinearCombination(comb, table, &xfx1, &xfx2, false);

assert!(lumi.len() == nsubproc);
assert!(channel.len() == nsubproc);

for (i, l) in lumi.iter().copied().enumerate().filter(|(_, l)| *l != 0.0) {
for (i, &l) in channel.iter().enumerate().filter(|(_, &l)| l != 0.0) {
let ap = pid_to_pdg_id(i32::try_from(a).unwrap() - 6);
let bp = pid_to_pdg_id(i32::try_from(b).unwrap() - 6);

entries[i].push((ap, bp, l));
entries[i].push((vec![ap, bp], l));
}

xfx2[b] = 0.0;
Expand All @@ -83,10 +83,10 @@ fn create_lumi(
xfx1[a] = 0.0;
}

lumis = entries.into_iter().map(Channel::new).collect();
channels = entries.into_iter().map(Channel::new).collect();
}

lumis
channels
}

fn convert_coeff_add_fix(
Expand All @@ -99,12 +99,13 @@ fn convert_coeff_add_fix(
let table_as_add_base = ffi::downcast_coeff_add_fix_to_base(table);

let mut grid = Grid::new(
create_lumi(table_as_add_base, comb, dis_pid),
reconstruct_channels(table_as_add_base, comb, dis_pid),
vec![Order {
alphas: table_as_add_base.GetNpow().try_into().unwrap(),
alpha,
logxir: 0,
logxif: 0,
logxia: 0,
}],
(0..=bins)
.map(|limit| u16::try_from(limit).unwrap().into())
Expand Down Expand Up @@ -234,12 +235,12 @@ fn convert_coeff_add_flex(

let alphas = table_as_add_base.GetNpow().try_into().unwrap();
let orders: Vec<_> = [
Order::new(alphas, alpha, 0, 0),
Order::new(alphas, alpha, 1, 0),
Order::new(alphas, alpha, 0, 1),
Order::new(alphas, alpha, 2, 0),
Order::new(alphas, alpha, 0, 2),
Order::new(alphas, alpha, 1, 1),
Order::new(alphas, alpha, 0, 0, 0),
Order::new(alphas, alpha, 1, 0, 0),
Order::new(alphas, alpha, 0, 1, 0),
Order::new(alphas, alpha, 2, 0, 0),
Order::new(alphas, alpha, 0, 2, 0),
Order::new(alphas, alpha, 1, 1, 0),
]
.into_iter()
.take(match table.GetNScaleDep() {
Expand All @@ -253,7 +254,7 @@ fn convert_coeff_add_flex(
let orders_len = orders.len();

let mut grid = Grid::new(
create_lumi(table_as_add_base, comb, dis_pid),
reconstruct_channels(table_as_add_base, comb, dis_pid),
orders,
(0..=bins)
.map(|limit| u16::try_from(limit).unwrap().into())
Expand Down
7 changes: 1 addition & 6 deletions pineappl_cli/src/import/fktable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ fn read_fktable(reader: impl BufRead, dis_pid: i32) -> Result<Grid> {
// construct `Grid`
let mut fktable = Grid::new(
lumis,
vec![Order {
alphas: 0,
alpha: 0,
logxir: 0,
logxif: 0,
}],
vec![Order::new(0, 0, 0, 0, 0)],
(0..=ndata).map(Into::into).collect(),
SubgridParams::default(),
);
Expand Down

0 comments on commit 87b3bf3

Please sign in to comment.