GooFit  v2.1.3
ExpPdf.cu
Go to the documentation of this file.
1 #include <goofit/Error.h>
2 #include <goofit/PDFs/basic/ExpPdf.h>
3 
4 namespace GooFit {
5 
6 __device__ fptype device_Exp(fptype *evt, fptype *p, unsigned int *indices) {
7  fptype x = evt[indices[2 + indices[0]]];
8  fptype alpha = p[indices[1]];
9 
10  fptype ret = exp(alpha * x);
11  return ret;
12 }
13 
14 __device__ fptype device_ExpOffset(fptype *evt, fptype *p, unsigned int *indices) {
15  fptype x = evt[indices[2 + indices[0]]];
16  x -= p[indices[1]];
17  fptype alpha = p[indices[2]];
18 
19  fptype ret = exp(alpha * x);
20  return ret;
21 }
22 
23 __device__ fptype device_ExpPoly(fptype *evt, fptype *p, unsigned int *indices) {
24  fptype x = evt[indices[2 + indices[0]]];
25 
26  fptype exparg = 0;
27 
28  for(int i = 0; i <= indices[0]; ++i) {
29  exparg += pow(x, i) * p[indices[i + 1]];
30  }
31 
32  fptype ret = exp(exparg);
33  return ret;
34 }
35 
36 __device__ fptype device_ExpPolyOffset(fptype *evt, fptype *p, unsigned int *indices) {
37  fptype x = evt[indices[2 + indices[0]]];
38  x -= p[indices[1]];
39 
40  fptype exparg = 0;
41 
42  for(int i = 0; i <= indices[0]; ++i) {
43  exparg += pow(x, i) * p[indices[i + 2]];
44  }
45 
46  fptype ret = exp(exparg);
47  return ret;
48 }
49 
50 __device__ device_function_ptr ptr_to_Exp = device_Exp;
51 __device__ device_function_ptr ptr_to_ExpPoly = device_ExpPoly;
52 __device__ device_function_ptr ptr_to_ExpOffset = device_ExpOffset;
53 __device__ device_function_ptr ptr_to_ExpPolyOffset = device_ExpPolyOffset;
54 
55 __host__ ExpPdf::ExpPdf(std::string n, Observable _x, Variable alpha)
56  : GooPdf(n, _x) {
57  std::vector<unsigned int> pindices;
58 
59  pindices.push_back(registerParameter(alpha));
60  GET_FUNCTION_ADDR(ptr_to_Exp);
61  initialize(pindices);
62 }
63 
64 __host__ ExpPdf::ExpPdf(std::string n, Observable _x, Variable alpha, Variable offset)
65  : GooPdf(n, _x) {
66  std::vector<unsigned int> pindices;
67 
68  pindices.push_back(registerParameter(offset));
69  pindices.push_back(registerParameter(alpha));
70  GET_FUNCTION_ADDR(ptr_to_ExpOffset);
71  initialize(pindices);
72 }
73 
74 __host__ ExpPdf::ExpPdf(std::string n, Observable _x, std::vector<Variable> &weights)
75  : GooPdf(n, _x) {
76  std::vector<unsigned int> pindices;
77 
78  if(weights.empty())
79  throw GooFit::GeneralError("Weights are empty!");
80 
81  for(Variable &w : weights)
82  pindices.push_back(registerParameter(w));
83 
84  GET_FUNCTION_ADDR(ptr_to_ExpPoly);
85 
86  initialize(pindices);
87 }
88 
89 __host__ ExpPdf::ExpPdf(std::string n, Observable _x, std::vector<Variable> &weights, Variable offset)
90  : GooPdf(n, _x) {
91  std::vector<unsigned int> pindices;
92 
93  pindices.push_back(registerParameter(offset));
94 
95  if(weights.empty())
96  throw GooFit::GeneralError("Weights are empty!");
97 
98  for(Variable &w : weights)
99  pindices.push_back(registerParameter(w));
100 
101  GET_FUNCTION_ADDR(ptr_to_ExpPolyOffset);
102 
103  initialize(pindices);
104 }
105 
106 __host__ fptype ExpPdf::integrate(fptype lo, fptype hi) const {
107  fptype alpha = host_params[host_indices[parameters + 1]];
108 
109  if(0 == alpha) {
110  // This gives a constant 1 all across the range
111  return (hi - lo);
112  }
113 
114  fptype ret = exp(alpha * hi) - exp(alpha * lo);
115  ret /= alpha;
116  return ret;
117 }
118 
119 } // namespace GooFit