GooFit  v2.1.3
BinTransformPdf.cu
Go to the documentation of this file.
1 #include <goofit/PDFs/basic/BinTransformPdf.h>
2 
3 namespace GooFit {
4 
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]];
8  int ret = 0;
9  int previousSize = 1;
10 
11  // printf("[%i, %i] Bin Transform: %i %i %f %f\n", THREADIDX, BLOCKIDX, numObservables, previousSize, evt[0],
12  // evt[1]);
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];
18 
19  auto localBin = static_cast<int>(floor((obsValue - lowerLimit) / binSize));
20  ret += localBin * previousSize;
21  previousSize *= numBins;
22  }
23 
24  return fptype(ret);
25 }
26 
27 __device__ device_function_ptr ptr_to_BinTransform = device_BinTransform;
28 
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)
35  : GooPdf(n) {
36  cIndex = registerConstants(2 * obses.size());
37  auto *host_constants = new fptype[2 * obses.size()];
38  std::vector<unsigned int> pindices;
39 
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]);
45 
46  host_constants[2 * i] = limits[i]; // cIndex will be accounted for by offset in memcpy
47  host_constants[2 * i + 1] = binSizes[i];
48  }
49 
50  MEMCPY_TO_SYMBOL(functorConstants,
51  host_constants,
52  2 * obses.size() * sizeof(fptype),
53  cIndex * sizeof(fptype),
54  cudaMemcpyHostToDevice);
55  delete[] host_constants;
56 
57  GET_FUNCTION_ADDR(ptr_to_BinTransform);
58  initialize(pindices);
59 }
60 
61 } // namespace GooFit