Skip to content

Commit 1a43bc5

Browse files
Replace OperatorCallback.ConvType in favor of OperatorCallback.usize
1 parent 14ba72b commit 1a43bc5

3 files changed

Lines changed: 41 additions & 11 deletions

File tree

examples/cpp/evolve-grid-identity.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
// NOTE: Uses the scale of the Grid as the starting scale such that we can use an IDENTITY EKO.
1414
double FAC0 = 6456.44;
1515

16+
/** @brief This struct can contain arbitrary parameters that need to be passed to Evolution
17+
* Operator Callback (`generated_fake_ekos`).
18+
*/
19+
struct OperatorParams {
20+
std::vector<pineappl_conv_type> conv_types;
21+
};
22+
1623
std::vector<std::size_t> unravel_index(std::size_t flat_index, const std::vector<std::size_t>& shape) {
1724
std::size_t ndim = shape.size();
1825
std::vector<std::size_t> coords(ndim);
@@ -26,7 +33,7 @@ std::vector<std::size_t> unravel_index(std::size_t flat_index, const std::vector
2633
}
2734

2835
extern "C" void generate_fake_ekos(
29-
pineappl_conv_type /*conv_type*/,
36+
std::size_t op_index,
3037
double /*fac1*/,
3138
const int* /*pids_in*/,
3239
const double* /*x_in*/,
@@ -36,8 +43,9 @@ extern "C" void generate_fake_ekos(
3643
double* eko_buffer,
3744
void* params_state
3845
) {
39-
// Check to get the μ0 of the PDF from the `params_state`
40-
const double _ = static_cast<LHAPDF::PDF*> (params_state)->q2Min();
46+
// select the type of convolution based on the Operator index
47+
OperatorParams* op_params = static_cast<OperatorParams*>(params_state);
48+
pineappl_conv_type _ = op_params->conv_types[op_index];
4149

4250
// NOTE: This has to work because the Evolution Operator is always 4D
4351
std::vector<std::size_t> shape(eko_shape, eko_shape + 4);
@@ -152,6 +160,7 @@ int main() {
152160
// ------------------ Construct the Operator Info ------------------
153161
// The Operator Info is a vector with length `N_conv * N_Q2_slices` whose
154162
// elements are `OperatorInfo` objects.
163+
std::vector<pineappl_conv_type> convtypes(unique_convs.size());
155164
std::vector<pineappl_operator_info> opinfo_slices(unique_convs.size() * fac1.size());
156165
for (std::size_t i = 0; i != unique_convs.size(); i++) {
157166
for (std::size_t j = 0; j != fac1.size(); j++) {
@@ -163,6 +172,7 @@ int main() {
163172
};
164173
opinfo_slices[i * fac1.size() + j] = opinfo;
165174
}
175+
conv_types[i] = unique_convs[i];
166176
}
167177

168178
// ------------------ Construct the Evolution Operator ------------------
@@ -177,6 +187,11 @@ int main() {
177187
alphas_table.push_back(alpha);
178188
}
179189

190+
// Construct the Parameters that will get passed to the Callback
191+
OperatorParams* op_params = new OperatorParams;
192+
op_params->conv_types = convtypes;
193+
void* params = static_cast<void*>(op_params);
194+
180195
std::vector<double> xi = {1.0, 1.0, 1.0};
181196
// NOTE: The EKO has to have as shape: (pids_in, x_in, pids_out, x_out)
182197
std::vector<std::size_t> tensor_shape = {pids_in.size(), x_in.size(), pids_out.size(), x_in.size()};
@@ -207,7 +222,7 @@ int main() {
207222
pids_out.data(), // `pids_out`
208223
x_in.data(), // `x_out`
209224
tensor_shape.data(), // `eko_shape`
210-
pdf.get(), // `state`
225+
params, // `state`
211226
nullptr, // `order_mask`
212227
xi.data(), // `xi`
213228
ren1.data(), // `ren1`

examples/cpp/evolve-grid.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ std::vector<double> XGRID = {
7070
// Particle PIDs for both `in` and `out`
7171
std::vector<int> PIDS = {- 22 , -6 , -5 , -4 , -3 , -2 , -1 , 21 , 1 , 2 , 3 , 4 , 5 , 6};
7272

73+
/** @brief This struct can contain arbitrary parameters that need to be passed to Evolution
74+
* Operator Callback (`generated_fake_ekos`).
75+
*/
76+
struct OperatorParams {
77+
std::vector<pineappl_conv_type> conv_types;
78+
};
79+
7380
std::vector<std::size_t> unravel_index(std::size_t flat_index, const std::vector<std::size_t>& shape) {
7481
std::size_t ndim = shape.size();
7582
std::vector<std::size_t> coords(ndim);
@@ -83,7 +90,7 @@ std::vector<std::size_t> unravel_index(std::size_t flat_index, const std::vector
8390
}
8491

8592
extern "C" void generate_fake_ekos(
86-
pineappl_conv_type /*conv_type*/,
93+
std::size_t op_index,
8794
double /*fac1*/,
8895
const int* /*pids_in*/,
8996
const double* /*x_in*/,
@@ -93,8 +100,9 @@ extern "C" void generate_fake_ekos(
93100
double* eko_buffer,
94101
void* params_state
95102
) {
96-
// Check to get the μ0 from the PDF
97-
const double _ = static_cast<LHAPDF::PDF*> (params_state)->q2Min();
103+
// select the type of convolution based on the Operator index
104+
OperatorParams* op_params = static_cast<OperatorParams*>(params_state);
105+
pineappl_conv_type _ = op_params->conv_types[op_index];
98106

99107
std::ifstream input_file("../../test-data/EKO_LHCB_WP_7TEV.txt");
100108
double weight_value;
@@ -203,6 +211,7 @@ int main() {
203211
// ------------------ Construct the Operator Info ------------------
204212
// The Operator Info is a vector with length `N_conv * N_Q2_slices` whose
205213
// elements are `OperatorInfo` objects.
214+
std::vector<pineappl_conv_type> convtypes(unique_convs.size());
206215
std::vector<pineappl_operator_info> opinfo_slices(unique_convs.size() * fac1.size());
207216
for (std::size_t i = 0; i != unique_convs.size(); i++) {
208217
for (std::size_t j = 0; j != fac1.size(); j++) {
@@ -214,6 +223,7 @@ int main() {
214223
};
215224
opinfo_slices[i * fac1.size() + j] = opinfo;
216225
}
226+
conv_types[i] = unique_convs[i];
217227
}
218228

219229
// ------------------ Construct the Evolution Operator ------------------
@@ -228,6 +238,11 @@ int main() {
228238
alphas_table.push_back(alpha);
229239
}
230240

241+
// Construct the Parameters that will get passed to the Callback
242+
OperatorParams* op_params = new OperatorParams;
243+
op_params->conv_types = convtypes;
244+
void* params = static_cast<void*>(op_params);
245+
231246
std::vector<double> xi = {1.0, 1.0, 1.0};
232247
// NOTE: The EKO has to have as shape: (pids_in, x_in, pids_out, x_out)
233248
std::vector<std::size_t> tensor_shape = {pids_in.size(), XGRID.size(), pids_out.size(), XGRID.size()};
@@ -258,7 +273,7 @@ int main() {
258273
pids_out.data(), // `pids_out`
259274
XGRID.data(), // `x_out`
260275
tensor_shape.data(), // `eko_shape`
261-
pdf.get(), // `state`
276+
params, // `state`
262277
nullptr, // `order_mask`
263278
xi.data(), // `xi`
264279
ren1.data(), // `ren1`

pineappl_capi/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,7 @@ pub unsafe extern "C" fn pineappl_grid_evolve_info(
21392139

21402140
/// Type alias for the operator callback
21412141
pub type OperatorCallback = unsafe extern "C" fn(
2142-
ConvType, // Convolution type
2142+
usize, // index which selects Evolution parameters
21432143
f64, // fac1
21442144
*const i32, // `pids_in`
21452145
*const f64, // `x_in`
@@ -2228,7 +2228,7 @@ pub unsafe extern "C" fn pineappl_grid_evolve(
22282228

22292229
let op_slices = operator_info
22302230
.map(|op_infos| {
2231-
op_infos.iter().map(|op_info| {
2231+
op_infos.iter().enumerate().map(|(op_index, op_info)| {
22322232
let operator_slice_info = OperatorSliceInfo {
22332233
pid_basis: op_info.pid_basis,
22342234
fac0: op_info.fac0,
@@ -2244,7 +2244,7 @@ pub unsafe extern "C" fn pineappl_grid_evolve(
22442244

22452245
unsafe {
22462246
slices(
2247-
op_info.conv_type,
2247+
op_index,
22482248
op_info.fac1,
22492249
pids_in.as_ptr(),
22502250
x_in.as_ptr(),

0 commit comments

Comments
 (0)