Skip to content

Commit a1614db

Browse files
authored
Merge pull request #364 from NNPDF/mucol_dis_with_powheg
Add delete_bins to C API
2 parents 65eb260 + 7188e8a commit a1614db

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

examples/cpp/advanced-filling.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,37 @@ int main() {
173173

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

176+
//-----------------------------------------------------------------------//
177+
178+
// Remove the bins for which the convolution is zero.
179+
std::vector<uintptr_t> zero_indices;
180+
zero_indices.reserve(dxsec.size());
181+
for (size_t i = 0; i < dxsec.size(); ++i) {
182+
if (dxsec[i] == 0.0) {
183+
zero_indices.push_back(static_cast<uintptr_t>(i));
184+
}
185+
}
186+
pineappl_grid_delete_bins(grid, zero_indices.data(), zero_indices.size());
187+
188+
std::vector<double> dxsec_no_zeros(pineappl_grid_bin_count(grid));
189+
pineappl_grid_convolve(grid, xfx, alphas, pdf_states, pdf.get(), order_mask, channel_mask,
190+
nullptr, 1, mmu_scales.data(), dxsec_no_zeros.data());
191+
192+
// Print table header
193+
std::cout << " " << std::endl;
194+
std::cout << std::setw(10) << "bin left"
195+
<< std::setw(12) << "bin right"
196+
<< std::setw(15) << "dsig/dx" << std::endl;
197+
std::cout << std::string(37, '-') << std::endl;
198+
199+
// Loop through bins and print results
200+
for (size_t i = 0; i < dxsec_no_zeros.size(); ++i) {
201+
std::cout << std::setw(10) << bins[i]
202+
<< std::setw(12) << bins[i + 1]
203+
<< std::setw(15) << std::scientific << std::setprecision(3) << dxsec_no_zeros[i]
204+
<< std::endl;
205+
}
206+
176207
// release memory
177208
pineappl_grid_delete(grid);
178209
}

examples/cpp/advanced-filling.output

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@
2424
2.100e+00 2.200e+00 0.000e+00
2525
2.200e+00 2.300e+00 0.000e+00
2626
2.300e+00 2.400e+00 0.000e+00
27+
28+
bin left bin right dsig/dx
29+
-------------------------------------
30+
0.000e+00 1.000e-01 6.683e+03

pineappl_capi/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,29 @@ pub unsafe extern "C" fn pineappl_grid_merge_bins(grid: *mut Grid, from: usize,
860860
grid.merge_bins(from..to).unwrap();
861861
}
862862

863+
/// Deletes bins with the corresponding `bin_indices`. Repeated indices and indices larger or
864+
/// equal the bin length are ignored.
865+
///
866+
/// # Safety
867+
///
868+
/// The parameter `grid` must be valid `Grid` object created by either `pineappl_grid_new` or
869+
/// `pineappl_grid_read`.
870+
/// The parameter `bin_indices_ptr` must be an array of size `bin_indices_len`.
871+
///
872+
/// # Panics
873+
///
874+
/// TODO
875+
#[no_mangle]
876+
pub unsafe extern "C" fn pineappl_grid_delete_bins(
877+
grid: *mut Grid,
878+
bin_indices_ptr: *const usize,
879+
bin_indices_len: usize,
880+
) {
881+
let grid = unsafe { &mut *grid };
882+
let bin_indices = unsafe { std::slice::from_raw_parts(bin_indices_ptr, bin_indices_len) };
883+
grid.delete_bins(bin_indices);
884+
}
885+
863886
/// Merges `other` into `grid` and subsequently deletes `other`.
864887
///
865888
/// # Safety

0 commit comments

Comments
 (0)