Jpp 19.3.0-rc.5
the software that should make you happy
Loading...
Searching...
No Matches
JBell.hh
Go to the documentation of this file.
1#ifndef __JMATH__JBELL__
2#define __JMATH__JBELL__
3
4#include <cmath>
5#include <limits>
6
7#include "JMath/JGauss.hh"
8
9/**
10 * \author mdejong
11 */
12
13namespace JMATH {}
14namespace JPP { using namespace JMATH; }
15
16namespace JMATH {
17
18 /**
19 * Type definition for Bell model.
20 */
22
23
24 /**
25 * Bell function object.\n
26 * This function object correspods to a Gauss with a different power (<tt>alpha</tt>) for the exponential term.
27 *
28 * Evaluates function, derivative and gradient values.
29 */
30 struct JBell :
31 public JBell_t
32 {
33 /**
34 * Type definition of fit parameter.
35 */
36 typedef double JBell_t::*parameter_type;
37
38
39 /**
40 * Default constructor.
41 */
43 JBell_t()
44 {}
45
46
47 /**
48 * Copy constructor.
49 *
50 * \param bell bell
51 * \param alpha alpha
52 */
53 JBell(const JBell_t& bell,
54 const double alpha = 2.0) :
55 JBell_t(bell),
56 alpha(alpha),
57 V(2.0 * pow(2.0,1.0/alpha) * tgamma(1.0/alpha) / alpha)
58 {}
59
60
61 /**
62 * Constructor.
63 *
64 * \param mean mean
65 * \param sigma sigma
66 * \param signal signal
67 * \param background background
68 * \param alpha alpha
69 */
70 JBell(const double mean,
71 const double sigma,
72 const double signal = 1.0,
73 const double background = 0.0,
74 const double alpha = 2.0) :
76 {}
77
78
79 /**
80 * Function value.
81 *
82 * \param x abscissa value
83 * \return function value
84 */
85 double getValue(const double x) const
86 {
87 const double u = (x - mean) / sigma;
88
89 return signal * get(u) + background;
90 }
91
92
93 /**
94 * Derivative value.
95 *
96 * \param x abscissa value
97 * \return derivative value
98 */
99 double getDerivative(const double x) const
100 {
101 const double u = (x - mean) / sigma;
102
103 return signal * get(u) * copysign(_f(u, alpha - 1.0), -u) * alpha / sigma;
104 }
105
106
107 /**
108 * Function value.
109 *
110 * \param x abscissa value
111 * \return function value
112 */
113 double operator()(const double x) const
114 {
115 return getValue(x);
116 }
117
118
119 /**
120 * Get gradient.
121 *
122 * \param x abscissa value
123 * \return gradient
124 */
125 const JBell_t& getGradient(const double x) const
126 {
127 const double w = 1.0 / sigma;
128 const double u = (x - mean) * w;
129 const double f0 = get(u);
130 const double fs = signal * f0;
131
132 gradient.mean = fs * copysign(_f(u, alpha - 1.0), u) * alpha * w; // d(f)/d(mean)
133 gradient.sigma = fs * -(_f(u, alpha) * alpha + 1.0) * w; // d(f)/d(sigma)
134 gradient.signal = f0; // d(f)/d(signal)
135 gradient.background = 1.0; // d(f)/d(background)
136
137 return gradient;
138 }
139
140 private:
141 double alpha; //!< power
142 double V; //!< normalisation constant
143
144 /**
145 * Power.
146 *
147 * \param x abscissa value
148 * \param a power
149 * \return ordinate value
150 */
151 static inline double _f(const double x, const double a)
152 {
153 return -0.5 * pow(fabs(x), a);
154 }
155
156
157 /**
158 * Get ordinate value.
159 *
160 * \param u abscissa value
161 * \return ordinate value
162 */
163 inline double get(const double u) const
164 {
165 const double v = _f(u, alpha);
166
167 return exp(v) / (sigma * V);
168 }
169
171 };
172}
173
174#endif
Auxiliary classes and methods for mathematical operations.
Definition JEigen3D.hh:88
JGauss_t JBell_t
Type definition for Bell model.
Definition JBell.hh:21
T pow(const T &x, const double y)
Power .
Definition JMath.hh:97
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Bell function object.
Definition JBell.hh:32
JBell(const JBell_t &bell, const double alpha=2.0)
Copy constructor.
Definition JBell.hh:53
const JBell_t & getGradient(const double x) const
Get gradient.
Definition JBell.hh:125
double V
normalisation constant
Definition JBell.hh:142
JBell(const double mean, const double sigma, const double signal=1.0, const double background=0.0, const double alpha=2.0)
Constructor.
Definition JBell.hh:70
double get(const double u) const
Get ordinate value.
Definition JBell.hh:163
JBell()
Default constructor.
Definition JBell.hh:42
JBell_t gradient
Definition JBell.hh:170
double getDerivative(const double x) const
Derivative value.
Definition JBell.hh:99
double operator()(const double x) const
Function value.
Definition JBell.hh:113
static double _f(const double x, const double a)
Power.
Definition JBell.hh:151
double JBell_t::* parameter_type
Type definition of fit parameter.
Definition JBell.hh:36
double alpha
power
Definition JBell.hh:141
double getValue(const double x) const
Function value.
Definition JBell.hh:85
Gauss model.
Definition JGauss.hh:32
double background
Definition JGauss.hh:164
double signal
Definition JGauss.hh:163