Skip to content

Fix CAPI #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 24, 2025
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
22 changes: 12 additions & 10 deletions examples/cpp/advanced-filling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ int main() {
// Construct the channel object based on the nb of convolutions
std::size_t nb_convolutions = 2;
std::size_t nb_channels = 2;
auto* channels = pineappl_channels_new();
auto* channels = pineappl_channels_new(nb_convolutions);
int32_t pids[] = { 2, -2, 4, -4 };
double factors[] = { 1.0, 1.0 };
pineappl_channels_add(channels, nb_channels, nb_convolutions, pids, factors);
pineappl_channels_add(channels, nb_channels, pids, factors);

std::size_t channel_count = 1;

Expand All @@ -37,10 +37,10 @@ int main() {
// hadrons. Then we add the corresponding PID of each of the hadrons, and finally define the
// Basis onto which the partons are mapped.
pineappl_pid_basis pid_basis = PINEAPPL_PID_BASIS_EVOL;
int32_t pdg_ids[2] = { 2212, 2212};
pineappl_conv_type h1 = PINEAPPL_CONV_TYPE_UNPOL_PDF;
pineappl_conv_type h2 = PINEAPPL_CONV_TYPE_UNPOL_PDF;
pineappl_conv_type convolution_types[2] = { h1, h2 };
pineappl_conv convs[] = {
{ PINEAPPL_CONV_TYPE_UNPOL_PDF, 2212 },
{ PINEAPPL_CONV_TYPE_UNPOL_PDF, 2212 },
};

// Define the kinematics required for this process. In the following example we have ONE
// single scale and two momentum fractions (corresponding to the two initial-state hadrons).
Expand All @@ -56,23 +56,25 @@ int main() {
pineappl_map scales_mapping = PINEAPPL_MAP_APPL_GRID_H0; // Mapping method
pineappl_map moment_mapping = PINEAPPL_MAP_APPL_GRID_F2;
pineappl_interp_meth interpolation_meth = PINEAPPL_INTERP_METH_LAGRANGE;
pineappl_interp_tuples interpolations[3] = {
pineappl_interp interpolations[3] = {
{ 1e2, 1e8, 40, 3, scales_reweight, scales_mapping, interpolation_meth }, // Interpolation fo `scales`
{ 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x1`
{ 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x2`
};

// Define the unphysical scale objecs
size_t mu_scales[] = { 1, 1, 0 };
pineappl_scale_func_form scale_mu = { PINEAPPL_SCALE_FUNC_FORM_SCALE, 0 };
pineappl_scale_func_form no_scale_mu = { PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0 }; // Here `.scale=0` is dummy value
pineappl_scale_func_form mu_scales[3] = { scale_mu, scale_mu, no_scale_mu };

// ---
// Create the grid using the previously set information about orders, bins and channels

// create a new grid with the previously defined channels, 3 perturbative orders defined by the
// exponents in `orders`, 24 bins given as the 25 limits in `bins` and potential extra
// parameters in `keyval`.
auto* grid = pineappl_grid_new2(pid_basis, channels, orders.size() / 5, orders.data(), bins.size() - 1,
bins.data(), nb_convolutions, convolution_types, pdg_ids, kinematics, interpolations, mu_scales);
auto* grid = pineappl_grid_new2(bins.size() - 1, bins.data(), orders.size() / 5, orders.data(),
channels, pid_basis, convs, 3, interpolations, kinematics, mu_scales);

// now we no longer need `channels`
pineappl_channels_delete(channels);
Expand Down
28 changes: 14 additions & 14 deletions examples/cpp/fill-grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,9 @@ int main() {
// ---
// Create all channels

// this object will contain all channels (initial states) that we define
auto* channels = pineappl_channels_new();

// Specify the dimension of the channel, ie the number of convolutions required
// this object will contain all channels (for two initial states) that we define
std::size_t nb_convolutions = 2;
auto* channels = pineappl_channels_new(nb_convolutions);

// photon-photon initial state, where `22` is the photon (PDG MC ids)
int32_t pids1[] = { 22, 22 };
Expand All @@ -128,7 +126,7 @@ int main() {
double factors1[] = { 1.0 };

// define the channel #0
pineappl_channels_add(channels, 1, nb_convolutions, pids1, factors1);
pineappl_channels_add(channels, 1, pids1, factors1);

// create another channel, which we won't fill, however

Expand All @@ -143,7 +141,7 @@ int main() {
// can also pass `nullptr`

// define the channel #1
pineappl_channels_add(channels, 3, nb_convolutions, pids2, nullptr);
pineappl_channels_add(channels, 3, pids2, nullptr);

// ---
// Specify the perturbative orders that will be filled into the grid
Expand Down Expand Up @@ -182,10 +180,10 @@ int main() {
// hadrons. Then we add the corresponding PID of each of the hadrons, and finally define the
// Basis onto which the partons are mapped.
pineappl_pid_basis pid_basis = PINEAPPL_PID_BASIS_EVOL;
int32_t pdg_ids[2] = { 2212, 2212};
pineappl_conv_type h1 = PINEAPPL_CONV_TYPE_UNPOL_PDF;
pineappl_conv_type h2 = PINEAPPL_CONV_TYPE_UNPOL_PDF;
pineappl_conv_type convolution_types[2] = { h1, h2 };
pineappl_conv convs[] = {
{ PINEAPPL_CONV_TYPE_UNPOL_PDF, 2212 },
{ PINEAPPL_CONV_TYPE_UNPOL_PDF, 2212 },
};

// Define the kinematics required for this process. In the following example we have ONE
// single scale and two momentum fractions (corresponding to the two initial-state hadrons).
Expand All @@ -201,23 +199,25 @@ int main() {
pineappl_map scales_mapping = PINEAPPL_MAP_APPL_GRID_H0; // Mapping method
pineappl_map moment_mapping = PINEAPPL_MAP_APPL_GRID_F2;
pineappl_interp_meth interpolation_meth = PINEAPPL_INTERP_METH_LAGRANGE;
pineappl_interp_tuples interpolations[3] = {
pineappl_interp interpolations[3] = {
{ 1e2, 1e8, 40, 3, scales_reweight, scales_mapping, interpolation_meth }, // Interpolation fo `scales`
{ 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x1`
{ 2e-7, 1.0, 50, 3, moment_reweight, moment_mapping, interpolation_meth }, // Interpolation fo `x2`
};

// Define the unphysical scale objecs
size_t mu_scales[] = { 1, 1, 0 };
pineappl_scale_func_form scale_mu = { PINEAPPL_SCALE_FUNC_FORM_SCALE, 0 };
pineappl_scale_func_form no_scale_mu = { PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, 0 }; // Here `.scale=0` is dummy value
pineappl_scale_func_form mu_scales[3] = { scale_mu, scale_mu, no_scale_mu };

// ---
// Create the grid using the previously set information about orders, bins and channels

// create a new grid with the previously defined channels, 3 perturbative orders defined by the
// exponents in `orders`, 24 bins given as the 25 limits in `bins` and potential extra
// parameters in `keyval`.
auto* grid = pineappl_grid_new2(pid_basis, channels, orders.size() / 5, orders.data(), bins.size() - 1,
bins.data(), nb_convolutions, convolution_types, pdg_ids, kinematics, interpolations, mu_scales);
auto* grid = pineappl_grid_new2(bins.size() - 1, bins.data(), orders.size() / 5, orders.data(),
channels, pid_basis, convs, 3, interpolations, kinematics, mu_scales);

// now we no longer need `keyval` and `channels`
pineappl_channels_delete(channels);
Expand Down
38 changes: 26 additions & 12 deletions examples/fortran/lhapdf_example.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ program lhapdf_example

integer, parameter :: dp = kind(0.0d0)

type(pineappl_grid) :: grid
type(pineappl_channels) :: channels
type(pineappl_kinematics) :: kinematics(3)
type(pineappl_interp_tuples) :: interpolations(3)
type(pineappl_grid) :: grid
type(pineappl_channels) :: channels
type(pineappl_kinematics) :: kinematics(3)
type(pineappl_scale_func_form) :: mu_scales_form(3)
type(pineappl_interp) :: interp_info(3)
type(pineappl_conv) :: convolutions(2)

type(pineappl_xfx) :: xfx
type(pineappl_alphas) :: alphas
Expand All @@ -25,8 +27,8 @@ program lhapdf_example
integer(c_int), target :: pdfs_array(2,2)
character(len=30) :: pdfset1, pdfset2

channels = pineappl_channels_new()
call pineappl_channels_add(channels, 3, 2, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp])
channels = pineappl_channels_new(2) ! The argument is the number of convolutions
call pineappl_channels_add(channels, 3, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp])

kinematics = [&
pineappl_kinematics(pineappl_scale, 0), &
Expand All @@ -39,14 +41,26 @@ program lhapdf_example
q2_mapping = pineappl_applgrid_h0
x_mapping = pineappl_applgrid_f2
interpolation_meth = pineappl_lagrange
interpolations = [ &
pineappl_interp_tuples(1e2_dp, 1e8_dp, 40, 3, q2_reweight, q2_mapping, interpolation_meth), &
pineappl_interp_tuples(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth), &
pineappl_interp_tuples(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) &
interp_info = [ &
pineappl_interp(1e2_dp, 1e8_dp, 40, 3, q2_reweight, q2_mapping, interpolation_meth), &
pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth), &
pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) &
]

grid = pineappl_grid_new2(pineappl_pdg, channels, 1, [2_1, 0_1, 0_1, 0_1, 0_1], 2, &
[0.0_dp, 1.0_dp, 2.0_dp], 2, [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], kinematics, interpolations, [1, 1, 0])
! The `pineappl_scale_func_form_body` objects have to defined with two fields - if not required, the value(s) will be ignored
mu_scales_form = [ &
pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), &
pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), &
pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, pineappl_scale_func_form_body(0, 0)) &
]

convolutions = [ &
pineappl_conv(pineappl_unpol_pdf, 2212), &
pineappl_conv(pineappl_unpol_pdf, 2212) &
]

grid = pineappl_grid_new2(2, [0.0_dp, 1.0_dp, 2.0_dp], 1, [2_1, 0_1, 0_1, 0_1, 0_1], channels, pineappl_pdg, &
convolutions, 3, interp_info, kinematics, mu_scales_form)

call pineappl_grid_fill_all2(grid, 0, 0.5_dp, [100.0_dp, 0.5_dp, 0.5_dp], [0.5_dp, 0.5_dp, 0.5_dp])
call pineappl_grid_fill_all2(grid, 0, 1.5_dp, [100.0_dp, 0.5_dp, 0.5_dp], [1.5_dp, 1.5_dp, 1.5_dp])
Expand Down
Loading