Skip to content

Commit

Permalink
Allow convolution functions being marked as polarized or fragmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
t7phy committed Jan 27, 2025
1 parent 84d7381 commit 12f27b2
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 52 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`--delete-orders` in the subcommand `write` of the CLI
- added the switches `--xir` and `--xif`, which allow varying the
renormalization and factorization scales with a custom factor in the
subcommand `convolve`.
subcommand `convolve`
- the CLI now allows the user to mark convolution functions as polarized
by adding `+p` to its LHAPDF name, as a fragmentation function by adding
`+f` and both by adding `+pf` or `+fp`

### Changed

Expand Down
2 changes: 2 additions & 0 deletions pineappl_cli/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl Subcommand for CkfOpts {
helpers::convolve(
&grid,
&mut conv_funs,
&self.conv_funs.conv_types,
&[self.order],
&[],
&lumi_mask,
Expand All @@ -103,6 +104,7 @@ impl Subcommand for CkfOpts {
helpers::convolve(
&grid,
&mut conv_funs,
&self.conv_funs.conv_types,
&orders_den,
&[],
&lumi_mask,
Expand Down
1 change: 1 addition & 0 deletions pineappl_cli/src/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl Subcommand for Opts {
helpers::convolve(
&grid,
&mut conv_funs,
&self.conv_funs.conv_types,
&self.orders,
&[],
&channel_mask,
Expand Down
3 changes: 3 additions & 0 deletions pineappl_cli/src/convolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl Subcommand for Opts {
let results = helpers::convolve_scales(
&grid,
&mut conv_funs_0,
&self.conv_funs[0].conv_types,
&self.orders,
&bins,
&[],
Expand All @@ -89,10 +90,12 @@ impl Subcommand for Opts {
let other_results: Vec<_> = self.conv_funs[1..]
.iter()
.flat_map(|conv_funs| {
let conv_types = &conv_funs.conv_types;
let mut conv_funs = helpers::create_conv_funs(conv_funs).unwrap();
helpers::convolve(
&grid,
&mut conv_funs,
conv_types,
&self.orders,
&bins,
&[],
Expand Down
4 changes: 4 additions & 0 deletions pineappl_cli/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl Subcommand for Opts {
let results1 = helpers::convolve(
&grid1,
&mut conv_funs,
&self.conv_funs.conv_types,
&orders1,
&[],
&[],
Expand All @@ -159,6 +160,7 @@ impl Subcommand for Opts {
let results2 = helpers::convolve(
&grid2,
&mut conv_funs,
&self.conv_funs.conv_types,
&orders2,
&[],
&[],
Expand Down Expand Up @@ -213,6 +215,7 @@ impl Subcommand for Opts {
helpers::convolve(
&grid1,
&mut conv_funs,
&self.conv_funs.conv_types,
&[order],
&[],
&[],
Expand All @@ -228,6 +231,7 @@ impl Subcommand for Opts {
helpers::convolve(
&grid2,
&mut conv_funs,
&self.conv_funs.conv_types,
&[order],
&[],
&[],
Expand Down
2 changes: 2 additions & 0 deletions pineappl_cli/src/evolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ impl Subcommand for Opts {
let results = helpers::convolve_scales(
&grid,
&mut conv_funs,
&self.conv_funs.conv_types,
&self.orders,
&[],
&[],
Expand All @@ -563,6 +564,7 @@ impl Subcommand for Opts {
let evolved_results = helpers::convolve_scales(
fk_table.grid(),
&mut conv_funs,
&self.conv_funs.conv_types,
&[],
&[],
&[],
Expand Down
1 change: 1 addition & 0 deletions pineappl_cli/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl Subcommand for Opts {
let reference_results = helpers::convolve(
&grid,
&mut conv_funs,
&self.conv_funs.conv_types,
&orders,
&[],
&[],
Expand Down
87 changes: 49 additions & 38 deletions pineappl_cli/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::GlobalConfiguration;
use anyhow::{anyhow, ensure, Context, Error, Result};
use anyhow::{anyhow, bail, ensure, Context, Error, Result};
use itertools::Itertools;
use lhapdf::{Pdf, PdfSet};
use ndarray::{Array3, Ix3};
use pineappl::boc::{ScaleFuncForm, Scales};
Expand All @@ -18,6 +19,7 @@ use std::str::FromStr;
pub struct ConvFuns {
pub lhapdf_names: Vec<String>,
pub members: Vec<Option<usize>>,
pub conv_types: Vec<ConvType>,
pub label: String,
}

Expand All @@ -26,22 +28,38 @@ impl FromStr for ConvFuns {

fn from_str(arg: &str) -> std::result::Result<Self, Self::Err> {
let (names, label) = arg.split_once('=').unwrap_or((arg, arg));
let (lhapdf_names, members) = names
let (lhapdf_names, members, conv_types) = names
.split(',')
.map(|fun| {
Ok::<_, Error>(if let Some((name, mem)) = fun.split_once('/') {
(name.to_owned(), Some(mem.parse()?))
} else {
(fun.to_owned(), None)
})
let (name, typ) = fun.split_once('+').unwrap_or((fun, ""));
let (name, mem) = name.split_once('/').map_or((name, None), |(name, mem)| {
(
name,
Some(
mem.parse()
// TODO: do proper error handling
.unwrap(),
),
)
});
let name = name.to_owned();
let typ = match typ {
"" => ConvType::UnpolPDF,
"p" => ConvType::PolPDF,
"f" => ConvType::UnpolFF,
"pf" | "fp" => ConvType::PolFF,
_ => bail!("unknown convolution type '{typ}'"),
};
Ok::<_, Error>((name, mem, typ))
})
.collect::<Result<Vec<(_, _)>, _>>()?
.collect::<Result<Vec<(_, _, _)>, _>>()?
.into_iter()
.unzip();
.multiunzip();

Ok(Self {
lhapdf_names,
members,
conv_types,
label: label.to_owned(),
})
}
Expand Down Expand Up @@ -224,6 +242,7 @@ pub enum ConvoluteMode {
pub fn convolve_scales(
grid: &Grid,
conv_funs: &mut [Pdf],
conv_types: &[ConvType],
orders: &[(u8, u8)],
bins: &[usize],
channels: &[bool],
Expand Down Expand Up @@ -282,8 +301,8 @@ pub fn convolve_scales(
.collect();
let convolutions: Vec<_> = conv_funs
.iter()
.zip(grid.convolutions())
.map(|(fun, convolution)| {
.zip(conv_types)
.map(|(fun, &conv_type)| {
let pid = fun
.set()
.entry("Particle")
Expand All @@ -292,17 +311,7 @@ pub fn convolve_scales(
// UNWRAP: if this fails, there's a non-integer string in the LHAPDF info file
.unwrap();

match fun.set().entry("SetType").unwrap_or_default().as_str() {
"fragfn" => Conv::new(ConvType::UnpolFF, pid),
"" => {
// if we can not figure out the type of the convolution from the PDF set, we
// assume it from the grid convolution at the same index
convolution.with_pid(pid)
}
// TODO: convince the LHAPDF maintainers to make SetType necessary for polarized
// PDFs and all FFs
_ => unimplemented!(),
}
Conv::new(conv_type, pid)
})
.collect();

Expand Down Expand Up @@ -367,6 +376,7 @@ pub fn scales_vector(grid: &Grid, scales: usize) -> &[(f64, f64, f64)] {
pub fn convolve(
grid: &Grid,
conv_funs: &mut [Pdf],
conv_types: &[ConvType],
orders: &[(u8, u8)],
bins: &[usize],
lumis: &[bool],
Expand All @@ -377,6 +387,7 @@ pub fn convolve(
convolve_scales(
grid,
conv_funs,
conv_types,
orders,
bins,
lumis,
Expand Down Expand Up @@ -405,6 +416,7 @@ pub fn convolve_limits(grid: &Grid, bins: &[usize], mode: ConvoluteMode) -> Vec<
pub fn convolve_subgrid(
grid: &Grid,
conv_funs: &mut [Pdf],
conv_types: &[ConvType],
order: usize,
bin: usize,
lumi: usize,
Expand Down Expand Up @@ -450,8 +462,8 @@ pub fn convolve_subgrid(
.collect();
let convolutions: Vec<_> = conv_funs
.iter()
.zip(grid.convolutions())
.map(|(fun, convolution)| {
.zip(conv_types)
.map(|(fun, &conv_type)| {
let pid = fun
.set()
.entry("Particle")
Expand All @@ -460,17 +472,7 @@ pub fn convolve_subgrid(
// UNWRAP: if this fails, there's a non-integer string in the LHAPDF info file
.unwrap();

match fun.set().entry("SetType").unwrap_or_default().as_str() {
"fragfn" => Conv::new(ConvType::UnpolFF, pid),
"" => {
// if we can not figure out the type of the convolution from the PDF set, we
// assume it from the grid convolution at the same index
convolution.with_pid(pid)
}
// TODO: convince the LHAPDF maintainers to make SetType necessary for polarized
// PDFs and all FFs
_ => unimplemented!(),
}
Conv::new(conv_type, pid)
})
.collect();

Expand Down Expand Up @@ -538,19 +540,28 @@ pub fn parse_order(order: &str) -> Result<(u8, u8)> {
#[cfg(test)]
mod test {
use super::ConvFuns;
use pineappl::convolutions::ConvType;

#[test]
fn conv_fun_from_str() {
assert_eq!(
"A/2,B/1,C/0,D=X".parse::<ConvFuns>().unwrap(),
"A/2+p,B/1+f,C/0+fp,D+pf,E=X".parse::<ConvFuns>().unwrap(),
ConvFuns {
lhapdf_names: vec![
"A".to_owned(),
"B".to_owned(),
"C".to_owned(),
"D".to_owned()
"D".to_owned(),
"E".to_owned()
],
members: vec![Some(2), Some(1), Some(0), None, None],
conv_types: vec![
ConvType::PolPDF,
ConvType::UnpolFF,
ConvType::PolFF,
ConvType::PolFF,
ConvType::UnpolPDF
],
members: vec![Some(2), Some(1), Some(0), None],
label: "X".to_owned()
}
);
Expand Down
1 change: 1 addition & 0 deletions pineappl_cli/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ impl Subcommand for Opts {
let results = helpers::convolve(
&grid,
&mut conv_funs,
&self.conv_funs.conv_types,
&[],
&[],
&[],
Expand Down
1 change: 1 addition & 0 deletions pineappl_cli/src/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Subcommand for Opts {
helpers::convolve(
&grid,
&mut conv_funs,
&self.conv_funs.conv_types,
&[(order.alphas, order.alpha)],
&[],
&[],
Expand Down
10 changes: 10 additions & 0 deletions pineappl_cli/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ impl Subcommand for Opts {
let results = helpers::convolve(
&grid,
&mut conv_funs,
&self.conv_funs[0].conv_types,
&[],
&bins,
&[],
Expand All @@ -245,6 +246,7 @@ impl Subcommand for Opts {
helpers::convolve(
&grid,
&mut conv_funs,
&self.conv_funs[0].conv_types,
&qcd_orders,
&bins,
&[],
Expand Down Expand Up @@ -274,11 +276,13 @@ impl Subcommand for Opts {
.par_iter()
.map(|conv_funs| {
if self.no_conv_fun_unc {
let conv_types = &conv_funs.conv_types;
let mut conv_funs = helpers::create_conv_funs(conv_funs)?;

let results = helpers::convolve(
&grid,
&mut conv_funs,
conv_types,
&[],
&bins,
&[],
Expand All @@ -300,6 +304,7 @@ impl Subcommand for Opts {
helpers::convolve(
&grid,
&mut funs,
&conv_funs.conv_types,
&[],
&bins,
&[],
Expand Down Expand Up @@ -396,6 +401,7 @@ impl Subcommand for Opts {
helpers::convolve(
&grid,
&mut conv_funs,
&self.conv_funs[0].conv_types,
&[],
&bins,
&channel_mask,
Expand Down Expand Up @@ -605,6 +611,7 @@ metadata = {{
let values = helpers::convolve(
&grid,
conv_funs,
&self.conv_funs[0].conv_types,
&[],
&[bin],
&[],
Expand All @@ -622,6 +629,7 @@ metadata = {{
let values = helpers::convolve(
&grid,
conv_funs,
&self.conv_funs[1].conv_types,
&[],
&[bin],
&[],
Expand Down Expand Up @@ -660,6 +668,7 @@ metadata = {{
let res1 = helpers::convolve_subgrid(
&grid,
&mut conv_funs1[member1.unwrap_or(0)],
&self.conv_funs[0].conv_types,
order,
bin,
channel,
Expand All @@ -669,6 +678,7 @@ metadata = {{
let res2 = helpers::convolve_subgrid(
&grid,
&mut conv_funs2[member2.unwrap_or(0)],
&self.conv_funs[1].conv_types,
order,
bin,
channel,
Expand Down
Loading

0 comments on commit 12f27b2

Please sign in to comment.