Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions examples/cpp/advanced-filling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,37 @@ int main() {

pineappl_grid_write(grid, "advanced-filling.pineappl.lz4");

//-----------------------------------------------------------------------//

// Remove the bins for which the convolution is zero.
std::vector<uintptr_t> zero_indices;
zero_indices.reserve(dxsec.size());
for (size_t i = 0; i < dxsec.size(); ++i) {
if (dxsec[i] == 0.0) {
zero_indices.push_back(static_cast<uintptr_t>(i));
}
}
pineappl_grid_delete_bins(grid, zero_indices.data(), zero_indices.size());

std::vector<double> dxsec_no_zeros(pineappl_grid_bin_count(grid));
pineappl_grid_convolve(grid, xfx, alphas, pdf_states, pdf.get(), order_mask, channel_mask,
nullptr, 1, mmu_scales.data(), dxsec_no_zeros.data());

// Print table header
std::cout << " " << std::endl;
std::cout << std::setw(10) << "bin left"
<< std::setw(12) << "bin right"
<< std::setw(15) << "dsig/dx" << std::endl;
std::cout << std::string(37, '-') << std::endl;

// Loop through bins and print results
for (size_t i = 0; i < dxsec_no_zeros.size(); ++i) {
std::cout << std::setw(10) << bins[i]
<< std::setw(12) << bins[i + 1]
<< std::setw(15) << std::scientific << std::setprecision(3) << dxsec_no_zeros[i]
<< std::endl;
}

// release memory
pineappl_grid_delete(grid);
}
4 changes: 4 additions & 0 deletions examples/cpp/advanced-filling.output
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
2.100e+00 2.200e+00 0.000e+00
2.200e+00 2.300e+00 0.000e+00
2.300e+00 2.400e+00 0.000e+00

bin left bin right dsig/dx
-------------------------------------
0.000e+00 1.000e-01 6.683e+03
23 changes: 23 additions & 0 deletions pineappl_capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,29 @@ pub unsafe extern "C" fn pineappl_grid_merge_bins(grid: *mut Grid, from: usize,
grid.merge_bins(from..to).unwrap();
}

/// Deletes bins with the corresponding `bin_indices`. Repeated indices and indices larger or
/// equal the bin length are ignored.
///
/// # Safety
///
/// The parameter `grid` must be valid `Grid` object created by either `pineappl_grid_new` or
/// `pineappl_grid_read`.
/// The parameter `bin_indices_ptr` must be an array of size `bin_indices_len`.
///
/// # Panics
///
/// TODO
#[no_mangle]
pub unsafe extern "C" fn pineappl_grid_delete_bins(
grid: *mut Grid,
bin_indices_ptr: *const usize,
bin_indices_len: usize,
) {
let grid = unsafe { &mut *grid };
let bin_indices = unsafe { std::slice::from_raw_parts(bin_indices_ptr, bin_indices_len) };
grid.delete_bins(bin_indices);
}

/// Merges `other` into `grid` and subsequently deletes `other`.
///
/// # Safety
Expand Down