GooFit  v2.1.3
ArgusPdf.cu
Go to the documentation of this file.
1 #include <goofit/PDFs/basic/ArgusPdf.h>
2 #include <goofit/Variable.h>
3 
4 namespace GooFit {
5 
6 __device__ fptype device_Argus_Upper(fptype *evt, fptype *p, unsigned int *indices) {
7  fptype x = evt[indices[2 + indices[0]]];
8  fptype m0 = p[indices[1]];
9 
10  double t = x / m0;
11 
12  if(t >= 1)
13  return 0;
14 
15  fptype slope = p[indices[2]];
16  fptype power = p[indices[3]];
17  t = 1 - t * t;
18  // printf("device_Argus_Upper %f %f %f %f %f\n", x, m0, slope, t, x * pow(t, power) * exp(slope * t));
19 
20  return x * pow(t, power) * exp(slope * t);
21 }
22 
23 __device__ fptype device_Argus_Lower(fptype *evt, fptype *p, unsigned int *indices) {
24  fptype x = evt[indices[2 + indices[0]]];
25  fptype m0 = p[indices[1]];
26 
27  // printf("Argus: %i %i %f %f\n", indices[0], indices[2 + indices[0]], x, m0);
28  // printf("Argus: %i %i\n", indices[0], indices[2 + indices[0]]);
29  // return 1;
30 
31  fptype t = x / m0;
32 
33  if(t <= 1)
34  return 0;
35 
36  t *= t;
37  t -= 1;
38 
39  fptype slope = p[indices[2]];
40  fptype power = p[indices[3]];
41  fptype ret = x * pow(t, power) * exp(slope * t);
42  // if ((0 == THREADIDX) && (0 == BLOCKIDX) && (callnumber < 1)) cuPrintf("device_Argus_Lower %i %i %f %f %f %f
43  // %f\n", indices[1], indices[2], x, m0, slope, t, ret);
44  // if (isnan(ret)) printf("NaN Argus: %f %f %f %f %f %f %f\n", x, m0, t, slope, power, pow(t, power), exp(slope*t));
45  // if ((0 == THREADIDX) && (0 == BLOCKIDX) && (gpuDebug & 1))
46  // printf("(%i, %i) device_Argus_Lower %f %f %f %f %f\n", BLOCKIDX, THREADIDX, x, m0, slope, t, x * pow(t, power) *
47  // exp(slope * t));
48 
49  return ret;
50 }
51 
52 __device__ device_function_ptr ptr_to_Argus_Upper = device_Argus_Upper;
53 __device__ device_function_ptr ptr_to_Argus_Lower = device_Argus_Lower;
54 
55 __host__ ArgusPdf::ArgusPdf(std::string n, Observable _x, Variable m0, Variable slope, bool upper)
56  : ArgusPdf(n, _x, m0, slope, upper, Variable(n + "powervar", 0.5)) {}
57 
58 __host__ ArgusPdf::ArgusPdf(std::string n, Observable _x, Variable m0, Variable slope, bool upper, Variable power)
59  : GooPdf(n, _x) {
60  registerParameter(m0);
61  registerParameter(slope);
62  registerParameter(power);
63 
64  std::vector<unsigned int> pindices;
65  pindices.push_back(m0.getIndex());
66  pindices.push_back(slope.getIndex());
67  pindices.push_back(power.getIndex());
68 
69  if(upper) {
70  GET_FUNCTION_ADDR(ptr_to_Argus_Upper);
71  } else {
72  GET_FUNCTION_ADDR(ptr_to_Argus_Lower);
73  }
74 
75  initialize(pindices);
76 }
77 
78 fptype argus_lower_helper(fptype x, fptype m0, fptype slope, fptype power) {
79  fptype t = x / m0;
80 
81  if(t <= 1)
82  return 0;
83 
84  t *= t;
85  t -= 1;
86 
87  fptype ret = x * pow(t, power) * exp(slope * t);
88 
89  return ret;
90 }
91 
92 __host__ double ArgusPdf::integrate(fptype lo, fptype hi) const {
93  double norm = 0;
94  unsigned int *indices = host_indices + parameters;
95  fptype m0 = host_params[indices[1]];
96  fptype slope = host_params[indices[2]];
97  fptype power = host_params[indices[3]];
98 
99  for(int j = 0; j < integrationBins; ++j) {
100  double x = hi;
101  x -= lo;
102  x /= integrationBins;
103  x *= j;
104  x += lo;
105  norm += argus_lower_helper(x, m0, slope, power);
106  }
107 
108  norm *= ((hi - lo) / integrationBins);
109  return norm;
110 }
111 } // namespace GooFit