1 #include <goofit/PDFs/basic/BinTransformPdf.h>
5 __device__ fptype device_BinTransform(fptype *evt, fptype *p, unsigned int *indices) {
6 // Index structure: nP lim1 bin1 lim2 bin2 ... nO o1 o2
7 int numObservables = indices[1 + indices[0]];
11 // printf("[%i, %i] Bin Transform: %i %i %f %f\n", THREADIDX, BLOCKIDX, numObservables, previousSize, evt[0],
13 for(int i = 0; i < numObservables; ++i) {
14 fptype obsValue = evt[indices[2 + indices[0] + i]];
15 fptype lowerLimit = functorConstants[indices[i * 3 + 1]];
16 fptype binSize = functorConstants[indices[i * 3 + 2]];
17 int numBins = indices[i * 3 + 3];
19 auto localBin = static_cast<int>(floor((obsValue - lowerLimit) / binSize));
20 ret += localBin * previousSize;
21 previousSize *= numBins;
27 __device__ device_function_ptr ptr_to_BinTransform = device_BinTransform;
29 // Notice that bin sizes and limits can be different, for this purpose, than what's implied by the Variable members.
30 __host__ BinTransformPdf::BinTransformPdf(std::string n,
31 std::vector<Observable> obses,
32 std::vector<fptype> limits,
33 std::vector<fptype> binSizes,
34 std::vector<int> numBins)
36 cIndex = registerConstants(2 * obses.size());
37 auto *host_constants = new fptype[2 * obses.size()];
38 std::vector<unsigned int> pindices;
40 for(unsigned int i = 0; i < obses.size(); ++i) {
41 registerObservable(obses[i]);
42 pindices.push_back(cIndex + 2 * i);
43 pindices.push_back(cIndex + 2 * i + 1);
44 pindices.push_back(numBins[i]);
46 host_constants[2 * i] = limits[i]; // cIndex will be accounted for by offset in memcpy
47 host_constants[2 * i + 1] = binSizes[i];
50 MEMCPY_TO_SYMBOL(functorConstants,
52 2 * obses.size() * sizeof(fptype),
53 cIndex * sizeof(fptype),
54 cudaMemcpyHostToDevice);
55 delete[] host_constants;
57 GET_FUNCTION_ADDR(ptr_to_BinTransform);