GooFit  v2.1.3
VariableBinTransform1DPdf.cu
Go to the documentation of this file.
1 #include <goofit/PDFs/utility/VariableBinTransform1DPdf.h>
2 
3 using namespace std;
4 
5 namespace GooFit {
6 
7 __device__ fptype device_VarBinTransform1D(fptype *evt, fptype *p, unsigned int *indices) {
8  // Index structure: nP lim1 lim2 ...
9  int ret = 0;
10  // int previousSize = 1;
11  // printf("[%i, %i] Bin Transform: %i %i %f %f\n", THREADIDX, BLOCKIDX, numObservables, previousSize, evt[0],
12  // evt[1]);
13  fptype obsValue = evt[indices[2 + indices[0]]];
14  if(obsValue < 0)
15  obsValue = -obsValue;
16  int numLimits = indices[1];
17  for(int i = 0; i < numLimits; ++i) {
18  fptype lowerLimit = functorConstants[indices[i + 2]];
19  if(obsValue < lowerLimit)
20  break;
21  ret++;
22  }
23 
24  return fptype(ret);
25 }
26 
27 __device__ device_function_ptr ptr_to_VarBinTransform1D = device_VarBinTransform1D;
28 
29 // Notice that bin sizes and limits can be different, for this purpose, than what's implied by the Variable members.
30 __host__ VariableBinTransform1DPdf::VariableBinTransform1DPdf(std::string n, Observable _x, vector<fptype> binlimits)
31  : GooPdf(n, _x) {
32  unsigned int numLimits = binlimits.size(); // Excluding the min & max values for _x
33  cIndex = registerConstants(numLimits);
34  std::vector<fptype> host_constants;
35  std::vector<unsigned int> pindices{numLimits};
36  for(size_t i = 0; i < numLimits; ++i) {
37  pindices.push_back(cIndex + i);
38  host_constants.push_back(binlimits[i]); // cIndex will be accounted for by offset in memcpy
39  }
40 
41  MEMCPY_TO_SYMBOL(functorConstants,
42  host_constants.data(),
43  numLimits * sizeof(fptype),
44  cIndex * sizeof(fptype),
45  cudaMemcpyHostToDevice);
46 
47  GET_FUNCTION_ADDR(ptr_to_VarBinTransform1D);
48  initialize(pindices);
49 }
50 
51 } // namespace GooFit