Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- added a `fix_convolution` method to integrate out one of the convolution
dimensions in a grid by convolving it with a non-perturbative function

## [1.3.0] - 06/12/2025

### Added
Expand Down
6 changes: 5 additions & 1 deletion examples/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ PROGRAMS = \
display-orders \
display-orders-deprecated \
merge-grids \
modify-grid
modify-grid \
fix-convolution

all: $(PROGRAMS)

Expand All @@ -47,6 +48,9 @@ convolve-grid-deprecated: convolve-grid-deprecated.cpp
convolve-grid: convolve-grid.cpp
$(CXX) $(CXXFLAGS) $< $(LHAPDF_DEPS) $(PINEAPPL_DEPS) -o $@

fix-convolution: fix-convolution.cpp
$(CXX) $(CXXFLAGS) $< $(LHAPDF_DEPS) $(PINEAPPL_DEPS) -o $@

deprecated: deprecated.cpp
$(CXX) $(CXXFLAGS) $< $(LHAPDF_DEPS) $(PINEAPPL_DEPS) -o $@

Expand Down
101 changes: 101 additions & 0 deletions examples/cpp/fix-convolution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include <cassert>
#include <cmath>
#include <cstddef>
#include <iomanip>
#include <ios>
#include <iostream>
#include <memory>
#include <string>
#include <vector>

#include <LHAPDF/LHAPDF.h>
#include <pineappl_capi.h>

void print_results(const std::vector<double>& r1, const std::vector<double>& r2) {
std::cout << std::scientific << std::setprecision(6);
std::cout << "Bin | Original Grid | Fixed Grid | Rel. Diff." << std::endl;
std::cout << "--- | --------------- | --------------- | -----------------" << std::endl;
for (size_t i = 0; i < r1.size(); ++i) {
double rel_diff = 0.0;
if (r1[i] != 0.0) {
rel_diff = std::abs((r1[i] - r2[i]) / r1[i]);
}
std::cout << std::setw(3) << i << " | "
<< std::setw(15) << r1[i] << " | "
<< std::setw(15) << r2[i] << " | "
<< std::setw(17) << rel_diff << std::endl;
assert(rel_diff < 1e-9);
}
}

int main() {
// Grid with 3 convolutions (2x pol PDF, 1x unpol FF)
const std::string filename = "../../test-data/SIHP-PP-POLARIZED-STAR-NLO.pineappl.lz4";
const std::string pol_pdf_set = "NNPDFpol11_100";
const std::string ff_set = "MAPFF10NLOPIsum";

LHAPDF::setVerbosity(0);
auto pol_pdf = std::unique_ptr<LHAPDF::PDF>(LHAPDF::mkPDF(pol_pdf_set, 0));
auto ff = std::unique_ptr<LHAPDF::PDF>(LHAPDF::mkPDF(ff_set, 0));

pineappl_grid* grid = pineappl_grid_read(filename.c_str());
assert(grid != nullptr);

auto xfx = [](int32_t id, double x, double q2, void* pdf) {
return static_cast <LHAPDF::PDF*> (pdf)->xfxQ2(id, x, q2);
};
auto alphas = [](double q2, void* pdf) {
return static_cast <LHAPDF::PDF*> (pdf)->alphasQ2(q2);
};

// Convolve original grid
size_t bins = pineappl_grid_bin_count(grid);
std::vector<double> results_orig(bins);
std::vector<LHAPDF::PDF*> pdfs_orig_vec = { pol_pdf.get(), pol_pdf.get(), ff.get() };
void** pdfs_orig = reinterpret_cast<void**>(pdfs_orig_vec.data());
std::vector<double> mu_scales = { 1.0, 1.0, 1.0 };
pineappl_grid_convolve(
grid,
xfx,
alphas,
pdfs_orig,
pol_pdf.get(),
nullptr,
nullptr,
nullptr,
1,
mu_scales.data(),
results_orig.data()
);

// Fix the third convolution (fragmentation function)
pineappl_grid* grid_fixed = pineappl_grid_fix_convolution(grid, 2, xfx, ff.get(), 1.0);
assert(grid_fixed != nullptr);

// Convolve the new grid
std::vector<double> results_fixed(bins);
std::vector<LHAPDF::PDF*> pdfs_fixed_vec = { pol_pdf.get(), pol_pdf.get() };
void** pdfs_fixed = reinterpret_cast<void**>(pdfs_fixed_vec.data());
pineappl_grid_convolve(
grid_fixed,
xfx,
alphas,
pdfs_fixed,
pol_pdf.get(),
nullptr,
nullptr,
nullptr,
1,
mu_scales.data(),
results_fixed.data()
);

print_results(results_orig, results_fixed);

std::cout << "\nSuccess: results from original and fixed grid match." << std::endl;

pineappl_grid_delete(grid);
pineappl_grid_delete(grid_fixed);

return 0;
}
10 changes: 10 additions & 0 deletions examples/cpp/fix-convolution.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Bin | Original Grid | Fixed Grid | Rel. Diff.
--- | --------------- | --------------- | -----------------
0 | 2.260512e+03 | 2.260512e+03 | 1.207021e-15
1 | 1.036130e+03 | 1.036130e+03 | 1.097226e-15
2 | 4.894751e+02 | 4.894751e+02 | 1.045182e-15
3 | 2.402394e+02 | 2.402394e+02 | 2.011198e-15
4 | 1.246446e+02 | 1.246446e+02 | 7.980768e-16
5 | 5.268035e+01 | 5.268035e+01 | 8.092688e-16

Success: results from original and fixed grid match.
29 changes: 27 additions & 2 deletions examples/object-oriented-cpp/PineAPPL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <cstdio>
#include <string>
#include <vector>
#include <memory>

/** @brief Object oriented interface to PineAPPL.*/
namespace PineAPPL {
Expand Down Expand Up @@ -123,8 +124,7 @@ struct Grid {
/** @brief Underlying raw object. */
pineappl_grid *raw;

/** @brief Constructor (protected to avoid direct instantiation). */
protected:
/** @brief Constructor. */
Grid(pineappl_grid *grid) : raw(grid) {}

/** @brief Deleted copy/move semantics. */
Expand Down Expand Up @@ -320,6 +320,31 @@ struct Grid {
raw_mu_scales.data(), results.data());
return results;
}

/**
* @brief Fix one of the convolutions in the Grid and return a new Grid with
* lower dimension.
*
* @param conv_idx index of the convolution to fix
* @param pdf the PDF set to use for the convolution
* @param xi the scale factor (xif or xia)
* @return a new grid with one less convolution
*/
std::unique_ptr<Grid> fix_convolution(std::size_t conv_idx, LHAPDF::PDF *pdf,
double xi) const {
auto xfx = [](std::int32_t id, double x, double q2, void *pdf_ptr) {
return static_cast<LHAPDF::PDF *>(pdf_ptr)->xfxQ2(id, x, q2);
};

pineappl_grid *new_raw_grid =
pineappl_grid_fix_convolution(this->raw, conv_idx, xfx, pdf, xi);

if (new_raw_grid == nullptr) {
return nullptr;
}

return std::unique_ptr<Grid>(new Grid(new_raw_grid));
}
};

} // namespace PineAPPL
Expand Down
6 changes: 6 additions & 0 deletions pineappl/src/convolutions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ impl ConvType {
pub const fn is_pdf(&self) -> bool {
matches!(self, Self::UnpolPDF | Self::PolPDF)
}

/// TODO
#[must_use]
pub const fn is_ff(&self) -> bool {
matches!(self, Self::UnpolFF | Self::PolFF)
}
}

/// Data type that indentifies different types of convolutions.
Expand Down
Loading