GooFit  v2.1.3
LandauPdf.cu
Go to the documentation of this file.
1 #include <goofit/PDFs/basic/LandauPdf.h>
2 
3 namespace GooFit {
4 
5 // LANDAU pdf : algorithm from CERNLIB G110 denlan
6 // same algorithm is used in GSL
7 
8 __constant__ fptype p1[5] = {0.4259894875, -0.1249762550, 0.03984243700, -0.006298287635, 0.001511162253};
9 __constant__ fptype q1[5] = {1.0, -0.3388260629, 0.09594393323, -0.01608042283, 0.003778942063};
10 
11 __constant__ fptype p2[5] = {0.1788541609, 0.1173957403, 0.01488850518, -0.001394989411, 0.0001283617211};
12 __constant__ fptype q2[5] = {1.0, 0.7428795082, 0.3153932961, 0.06694219548, 0.008790609714};
13 
14 __constant__ fptype p3[5] = {0.1788544503, 0.09359161662, 0.006325387654, 0.00006611667319, -0.000002031049101};
15 __constant__ fptype q3[5] = {1.0, 0.6097809921, 0.2560616665, 0.04746722384, 0.006957301675};
16 
17 __constant__ fptype p4[5] = {0.9874054407, 118.6723273, 849.2794360, -743.7792444, 427.0262186};
18 __constant__ fptype q4[5] = {1.0, 106.8615961, 337.6496214, 2016.712389, 1597.063511};
19 
20 __constant__ fptype p5[5] = {1.003675074, 167.5702434, 4789.711289, 21217.86767, -22324.94910};
21 __constant__ fptype q5[5] = {1.0, 156.9424537, 3745.310488, 9834.698876, 66924.28357};
22 
23 __constant__ fptype p6[5] = {1.000827619, 664.9143136, 62972.92665, 475554.6998, -5743609.109};
24 __constant__ fptype q6[5] = {1.0, 651.4101098, 56974.73333, 165917.4725, -2815759.939};
25 
26 __constant__ fptype a1[3] = {0.04166666667, -0.01996527778, 0.02709538966};
27 __constant__ fptype a2[2] = {-1.845568670, -4.284640743};
28 
29 __device__ fptype device_Landau(fptype *evt, fptype *p, unsigned int *indices) {
30  fptype x = evt[indices[2 + indices[0]]];
31  fptype mpv = p[indices[1]];
32  fptype sigma = p[indices[2]];
33 
34  if(sigma <= 0)
35  return 0;
36 
37  fptype v = (x - mpv) / sigma;
38  fptype u, ue, us, denlan;
39 
40  if(v < -5.5) {
41  u = exp(v + 1.0);
42 
43  if(u < 1e-10)
44  return 0.0;
45 
46  ue = exp(-1 / u);
47  us = sqrt(u);
48  denlan = 0.3989422803 * (ue / us) * (1 + (a1[0] + (a1[1] + a1[2] * u) * u) * u);
49  } else if(v < -1) {
50  u = exp(-v - 1);
51  denlan = exp(-u) * sqrt(u) * (p1[0] + (p1[1] + (p1[2] + (p1[3] + p1[4] * v) * v) * v) * v)
52  / (q1[0] + (q1[1] + (q1[2] + (q1[3] + q1[4] * v) * v) * v) * v);
53  } else if(v < 1) {
54  denlan = (p2[0] + (p2[1] + (p2[2] + (p2[3] + p2[4] * v) * v) * v) * v)
55  / (q2[0] + (q2[1] + (q2[2] + (q2[3] + q2[4] * v) * v) * v) * v);
56  } else if(v < 5) {
57  denlan = (p3[0] + (p3[1] + (p3[2] + (p3[3] + p3[4] * v) * v) * v) * v)
58  / (q3[0] + (q3[1] + (q3[2] + (q3[3] + q3[4] * v) * v) * v) * v);
59  } else if(v < 12) {
60  u = 1 / v;
61  denlan = u * u * (p4[0] + (p4[1] + (p4[2] + (p4[3] + p4[4] * u) * u) * u) * u)
62  / (q4[0] + (q4[1] + (q4[2] + (q4[3] + q4[4] * u) * u) * u) * u);
63  } else if(v < 50) {
64  u = 1 / v;
65  denlan = u * u * (p5[0] + (p5[1] + (p5[2] + (p5[3] + p5[4] * u) * u) * u) * u)
66  / (q5[0] + (q5[1] + (q5[2] + (q5[3] + q5[4] * u) * u) * u) * u);
67  } else if(v < 300) {
68  u = 1 / v;
69  denlan = u * u * (p6[0] + (p6[1] + (p6[2] + (p6[3] + p6[4] * u) * u) * u) * u)
70  / (q6[0] + (q6[1] + (q6[2] + (q6[3] + q6[4] * u) * u) * u) * u);
71  } else {
72  u = 1 / (v - v * std::log(v) / (v + 1));
73  denlan = u * u * (1 + (a2[0] + a2[1] * u) * u);
74  }
75 
76  return denlan / sigma;
77 }
78 
79 __device__ device_function_ptr ptr_to_Landau = device_Landau;
80 
81 __host__ LandauPdf::LandauPdf(std::string n, Observable _x, Variable mpv, Variable sigma)
82  : GooPdf(n, _x) {
83  std::vector<unsigned int> pindices;
84  pindices.push_back(registerParameter(mpv));
85  pindices.push_back(registerParameter(sigma));
86  GET_FUNCTION_ADDR(ptr_to_Landau);
87  initialize(pindices);
88 }
89 
90 } // namespace GooFit