Skip to content

Commit c42b92a

Browse files
Merge pull request #343 from NNPDF/fix-capi
Fix CAPI
2 parents c14d948 + 49d99a2 commit c42b92a

10 files changed

Lines changed: 319 additions & 221 deletions

File tree

examples/cpp/advanced-filling.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ int main() {
1111
// Construct the channel object based on the nb of convolutions
1212
std::size_t nb_convolutions = 2;
1313
std::size_t nb_channels = 2;
14-
auto* channels = pineappl_channels_new();
14+
auto* channels = pineappl_channels_new(nb_convolutions);
1515
int32_t pids[] = { 2, -2, 4, -4 };
1616
double factors[] = { 1.0, 1.0 };
17-
pineappl_channels_add(channels, nb_channels, nb_convolutions, pids, factors);
17+
pineappl_channels_add(channels, nb_channels, pids, factors);
1818

1919
std::size_t channel_count = 1;
2020

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

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

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

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

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

7779
// now we no longer need `channels`
7880
pineappl_channels_delete(channels);

examples/cpp/fill-grid.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,9 @@ int main() {
115115
// ---
116116
// Create all channels
117117

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

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

130128
// define the channel #0
131-
pineappl_channels_add(channels, 1, nb_convolutions, pids1, factors1);
129+
pineappl_channels_add(channels, 1, pids1, factors1);
132130

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

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

145143
// define the channel #1
146-
pineappl_channels_add(channels, 3, nb_convolutions, pids2, nullptr);
144+
pineappl_channels_add(channels, 3, pids2, nullptr);
147145

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

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

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

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

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

222222
// now we no longer need `keyval` and `channels`
223223
pineappl_channels_delete(channels);

examples/fortran/lhapdf_example.f90

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ program lhapdf_example
66

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

9-
type(pineappl_grid) :: grid
10-
type(pineappl_channels) :: channels
11-
type(pineappl_kinematics) :: kinematics(3)
12-
type(pineappl_interp_tuples) :: interpolations(3)
9+
type(pineappl_grid) :: grid
10+
type(pineappl_channels) :: channels
11+
type(pineappl_kinematics) :: kinematics(3)
12+
type(pineappl_scale_func_form) :: mu_scales_form(3)
13+
type(pineappl_interp) :: interp_info(3)
14+
type(pineappl_conv) :: convolutions(2)
1315

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

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

3133
kinematics = [&
3234
pineappl_kinematics(pineappl_scale, 0), &
@@ -39,14 +41,26 @@ program lhapdf_example
3941
q2_mapping = pineappl_applgrid_h0
4042
x_mapping = pineappl_applgrid_f2
4143
interpolation_meth = pineappl_lagrange
42-
interpolations = [ &
43-
pineappl_interp_tuples(1e2_dp, 1e8_dp, 40, 3, q2_reweight, q2_mapping, interpolation_meth), &
44-
pineappl_interp_tuples(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth), &
45-
pineappl_interp_tuples(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) &
44+
interp_info = [ &
45+
pineappl_interp(1e2_dp, 1e8_dp, 40, 3, q2_reweight, q2_mapping, interpolation_meth), &
46+
pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth), &
47+
pineappl_interp(2e-7_dp, 1.0_dp, 50, 3, x_reweight, x_mapping, interpolation_meth) &
4648
]
4749

48-
grid = pineappl_grid_new2(pineappl_pdg, channels, 1, [2_1, 0_1, 0_1, 0_1, 0_1], 2, &
49-
[0.0_dp, 1.0_dp, 2.0_dp], 2, [pineappl_unpol_pdf, pineappl_unpol_pdf], [2212, 2212], kinematics, interpolations, [1, 1, 0])
50+
! The `pineappl_scale_func_form_body` objects have to defined with two fields - if not required, the value(s) will be ignored
51+
mu_scales_form = [ &
52+
pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), &
53+
pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_SCALE, pineappl_scale_func_form_body(0, 0)), &
54+
pineappl_scale_func_form(PINEAPPL_SCALE_FUNC_FORM_NO_SCALE, pineappl_scale_func_form_body(0, 0)) &
55+
]
56+
57+
convolutions = [ &
58+
pineappl_conv(pineappl_unpol_pdf, 2212), &
59+
pineappl_conv(pineappl_unpol_pdf, 2212) &
60+
]
61+
62+
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, &
63+
convolutions, 3, interp_info, kinematics, mu_scales_form)
5064

5165
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])
5266
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])

0 commit comments

Comments
 (0)