Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JMATH::JGauss< ID_t, normalised > Struct Template Reference

Gauss function object. More...

#include <JGauss.hh>

Inheritance diagram for JMATH::JGauss< ID_t, normalised >:
JMATH::JGauss_t JMATH::JMathlib< JGauss< ID_t > > JMATH::JCalculus< JGauss< ID_t > > JMATH::JMath< JGauss_t > JLANG::JEquals< JFirst_t, JSecond_t >

Public Types

typedef double JGauss_t::* parameter_type
 Type definition of fit parameter.
 

Public Member Functions

 JGauss ()
 Default constructor.
 
 JGauss (const JGauss_t &gauss)
 Copy constructor.
 
 JGauss (const double mean, const double sigma, const double signal=1.0, const double background=0.0)
 Constructor.
 
double getValue (const double x) const
 Function value.
 
double getDerivative (const double x) const
 Derivative value.
 
double getIntegral (const double xmin, const double xmax) const
 Integral value.
 
double operator() (const double x) const
 Function value.
 
const JGauss_tgetGradient (const double x) const
 Get gradient.
 
 JGauss ()
 Default constructor.
 
 JGauss (const double center, const double sigma)
 Constructor.
 
double getValue (const double x) const
 Function value.
 
double getDerivative (const double x) const
 Derivative value.
 
JGauss getGradient (const double x) const
 Get gradient.
 
bool equals (const JGauss_t &gauss, const double eps=std::numeric_limits< double >::min()) const
 Equality.
 
JGauss_tadd (const JGauss_t &gauss)
 Add gauss.
 
JGauss_tsub (const JGauss_t &gauss)
 Subtract gauss.
 
JGauss_tmul (const double factor)
 Scale gauss.
 
JGauss_tmul (const JSecond_t &object)
 Multiply with object.
 
double operator() (const Args &...args) const
 Function value.
 
double operator[] (const size_t i) const
 Get value of parameter at given index.
 
double & operator[] (const size_t i)
 Get value of parameter at given index.
 
JGauss< ID_t > & negate ()
 Negate function.
 
JGauss< ID_t > & add (const JGauss< ID_t > &f1)
 Add function.
 
JGauss< ID_t > & sub (const JGauss< ID_t > &f1)
 Subtract function.
 
JGauss< ID_t > & mul (const double factor)
 Scale function.
 
JGauss< ID_t > & div (const double factor)
 Scale function.
 

Static Public Member Functions

static size_t size ()
 Get size of parameter.
 

Public Attributes

double center
 center
 
double sigma
 sigma
 
double mean
 
double signal
 
double background
 

Static Public Attributes

static const int ID = ID_t
 
static constexpr parameter_list< JGauss, 2 > parameters { &JGauss::center, &JGauss::sigma }
 

Private Member Functions

double get (const double u) const
 Get ordinate value.
 
double get (const double u) const
 Get ordinate value.
 

Private Attributes

JGauss_t gradient
 

Detailed Description

template<int ID_t, bool normalised = false>
struct JMATH::JGauss< ID_t, normalised >

Gauss function object.

Gauss function.

Evaluates function, derivative and gradient values.

Definition at line 1997 of file JMathlib.hh.

Member Typedef Documentation

◆ parameter_type

template<int ID_t, bool normalised = false>
double JGauss_t::* JMATH::JGauss< ID_t, normalised >::parameter_type

Type definition of fit parameter.

Definition at line 182 of file JGauss.hh.

Constructor & Destructor Documentation

◆ JGauss() [1/5]

template<int ID_t, bool normalised = false>
JMATH::JGauss< ID_t, normalised >::JGauss ( )
inline

Default constructor.

Definition at line 188 of file JGauss.hh.

188 :
189 JGauss_t()
190 {}
JGauss_t()
Default constructor.
Definition JGauss.hh:37

◆ JGauss() [2/5]

template<int ID_t, bool normalised = false>
JMATH::JGauss< ID_t, normalised >::JGauss ( const JGauss_t & gauss)
inline

Copy constructor.

Parameters
gaussgauss

Definition at line 198 of file JGauss.hh.

198 :
200 {}
double gauss(const double x, const double sigma)
Gauss function (normalised to 1 at x = 0).

◆ JGauss() [3/5]

template<int ID_t, bool normalised = false>
JMATH::JGauss< ID_t, normalised >::JGauss ( const double mean,
const double sigma,
const double signal = 1.0,
const double background = 0.0 )
inline

Constructor.

Parameters
meanmean
sigmasigma
signalsignal
backgroundbackground

Definition at line 211 of file JGauss.hh.

214 :
216 {}
double background
Definition JGauss.hh:167
double signal
Definition JGauss.hh:166
double sigma
sigma
Definition JMathlib.hh:2076

◆ JGauss() [4/5]

template<int ID_t, bool normalised = false>
JMATH::JGauss< ID_t, normalised >::JGauss ( )
inline

Default constructor.

Definition at line 2007 of file JMathlib.hh.

2007 :
2008 center(0.0),
2009 sigma (0.0)
2010 {}
double center
center
Definition JMathlib.hh:2075

◆ JGauss() [5/5]

template<int ID_t, bool normalised = false>
JMATH::JGauss< ID_t, normalised >::JGauss ( const double center,
const double sigma )
inline

Constructor.

Parameters
centercenter
sigmasigma

Definition at line 2019 of file JMathlib.hh.

2020 :
2021 center(center),
2022 sigma (sigma)
2023 {}

Member Function Documentation

◆ getValue() [1/2]

template<int ID_t, bool normalised = false>
double JMATH::JGauss< ID_t, normalised >::getValue ( const double x) const
inline

Function value.

Note that an error will be thrown if sigma <= 0.0.

Parameters
xabscissa value
Returns
function value

Definition at line 227 of file JGauss.hh.

228 {
229 if (sigma <= 0.0) { THROW(JValueOutOfRange, "JGauss::getValue: Invalid sigma " << sigma); }
230
231 const double u = (x - mean) / sigma;
232
233 return signal * get(u) + background;
234 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
double get(const double u) const
Get ordinate value.
Definition JGauss.hh:357

◆ getDerivative() [1/2]

template<int ID_t, bool normalised = false>
double JMATH::JGauss< ID_t, normalised >::getDerivative ( const double x) const
inline

Derivative value.

Note that an error will be thrown if sigma <= 0.0.

Parameters
xabscissa value
Returns
derivative value

Definition at line 245 of file JGauss.hh.

246 {
247 if (sigma <= 0.0) { THROW(JValueOutOfRange, "JGauss::getDerivative: Invalid sigma " << sigma); }
248
249 const double u = (x - mean) / sigma;
250
251 return signal * get(u) * -u / sigma;
252 }

◆ getIntegral()

template<int ID_t, bool normalised = false>
double JMATH::JGauss< ID_t, normalised >::getIntegral ( const double xmin,
const double xmax ) const
inline

Integral value.

Note that an error will be thrown if sigma <= 0.0. Note that zero will be returned if xmin is equal to xmax. Note that the integration limits can be set to infinity using std::numeric_limits<double>::inifinity().

Parameters
xminlower limit
xmaxupper limit

Definition at line 265 of file JGauss.hh.

266 {
267 if (sigma <= 0.0) { THROW(JValueOutOfRange, "JGauss::getIntegral: Invalid sigma " << sigma); }
268
269 double zmin = xmin;
270 double zmax = xmax;
271
272 if (xmax < xmin) {
273
274 zmin = xmax;
275 zmax = xmin;
276 }
277
278 if (zmin < zmax) {
279
280 const double umin = (zmin - mean) / sigma / sqrt(2.0);
281 const double umax = (zmax - mean) / sigma / sqrt(2.0);
282
283 double I;
284
285 if (std::isinf(zmin) && std::isinf(zmax)) {
286
287 I = 1.0;
288
289 } else if (std::isinf(zmin)) {
290
291 I = 0.5 * (1 + erf(umax));
292
293 } else if (std::isinf(zmax)) {
294
295 I = 0.5 * erfc(umin);
296
297 } else {
298
299 I = 0.5 * (erfc(umin) - erfc(umax));
300 }
301
302 return signal * I + background;
303
304 } else {
305
306 return 0.0;
307 }
308 }

◆ operator()() [1/2]

template<int ID_t, bool normalised = false>
double JMATH::JGauss< ID_t, normalised >::operator() ( const double x) const
inline

Function value.

Parameters
xabscissa value
Returns
function value

Definition at line 317 of file JGauss.hh.

318 {
319 return getValue(x);
320 }
double getValue(const double x) const
Function value.
Definition JGauss.hh:227

◆ getGradient() [1/2]

template<int ID_t, bool normalised = false>
const JGauss_t & JMATH::JGauss< ID_t, normalised >::getGradient ( const double x) const
inline

Get gradient.

Note that an error will be thrown if sigma <= 0.0.

Parameters
xabscissa value
Returns
gradient

Definition at line 331 of file JGauss.hh.

332 {
333 if (sigma <= 0.0) { THROW(JValueOutOfRange, "JGauss::getGradient: Invalid sigma " << sigma); }
334
335 const double w = 1.0 / sigma;
336 const double u = (x - mean) * w;
337 const double f0 = get(u);
338 const double fs = signal * f0;
339
340 gradient.mean = fs * (u) * w; // d(f)/d(mean)
341 gradient.sigma = fs * (u + 1.0) * (u - 1.0) * w; // d(f)/d(sigma)
342 gradient.signal = f0; // d(f)/d(signal)
343 gradient.background = 1.0; // d(f)/d(background)
344
345 return gradient;
346 }
JGauss_t gradient
Definition JGauss.hh:364

◆ get() [1/2]

template<int ID_t, bool normalised = false>
double JMATH::JGauss< ID_t, normalised >::get ( const double u) const
inlineprivate

Get ordinate value.

Note that an error will be thrown if sigma <= 0.0.

Parameters
uabscissa value
Returns
ordinate value

Definition at line 357 of file JGauss.hh.

358 {
359 if (sigma <= 0.0) { THROW(JValueOutOfRange, "JGauss::get: Invalid sigma " << sigma); }
360
361 return exp(-0.5*u*u) / (sqrt(2.0*PI) * sigma);
362 }

◆ getValue() [2/2]

template<int ID_t, bool normalised = false>
double JMATH::JGauss< ID_t, normalised >::getValue ( const double x) const
inline

Function value.

Parameters
xabscissa value
Returns
function value

Definition at line 2032 of file JMathlib.hh.

2033 {
2034 const double u = (x - center) / sigma;
2035
2036 return get(u);
2037 }

◆ getDerivative() [2/2]

template<int ID_t, bool normalised = false>
double JMATH::JGauss< ID_t, normalised >::getDerivative ( const double x) const
inline

Derivative value.

Parameters
xabscissa value
Returns
derivative value

Definition at line 2046 of file JMathlib.hh.

2047 {
2048 const double w = 1.0 / sigma;
2049 const double u = (x - center) / sigma;
2050
2051 return get(u) * -u * w;
2052 }

◆ getGradient() [2/2]

template<int ID_t, bool normalised = false>
JGauss JMATH::JGauss< ID_t, normalised >::getGradient ( const double x) const
inline

Get gradient.

Parameters
xabscissa value
Returns
gradient

Definition at line 2061 of file JMathlib.hh.

2062 {
2063 JGauss gradient;
2064
2065 const double w = 1.0 / sigma;
2066 const double u = (x - center) * w;
2067 const double f0 = get(u);
2068
2069 gradient.center = f0 * u * w; // d(f)/d(center)
2070 gradient.sigma = f0 * u * u * w; // d(f)/d(sigma)
2071
2072 return gradient;
2073 }

◆ get() [2/2]

template<int ID_t, bool normalised = false>
double JMATH::JGauss< ID_t, normalised >::get ( const double u) const
inlineprivate

Get ordinate value.

Parameters
uabscissa value
Returns
ordinate value

Definition at line 2087 of file JMathlib.hh.

2088 {
2089 return exp(-0.5*u*u);
2090 }

◆ equals()

bool JMATH::JGauss_t::equals ( const JGauss_t & gauss,
const double eps = std::numeric_limits<double>::min() ) const
inlineinherited

Equality.

Parameters
gaussgauss
epsnumerical precision
Returns
true if gauss's identical; else false

Definition at line 73 of file JGauss.hh.

75 {
76 return (fabs(mean - gauss.mean) <= eps &&
77 fabs(sigma - gauss.sigma) <= eps &&
78 fabs(signal - gauss.signal) <= eps &&
79 fabs(background - gauss.background) <= eps);
80 }

◆ add() [1/2]

JGauss_t & JMATH::JGauss_t::add ( const JGauss_t & gauss)
inlineinherited

Add gauss.

Parameters
gaussgauss
Returns
this gauss

Definition at line 89 of file JGauss.hh.

90 {
91 mean += gauss.mean;
92 sigma += gauss.sigma;
93 signal += gauss.signal;
94 background += gauss.background;
95
96 return *this;
97 }

◆ sub() [1/2]

JGauss_t & JMATH::JGauss_t::sub ( const JGauss_t & gauss)
inlineinherited

Subtract gauss.

Parameters
gaussgauss
Returns
this gauss

Definition at line 106 of file JGauss.hh.

107 {
108 mean -= gauss.mean;
109 sigma -= gauss.sigma;
110 signal -= gauss.signal;
111 background -= gauss.background;
112
113 return *this;
114 }

◆ mul() [1/3]

JGauss_t & JMATH::JGauss_t::mul ( const double factor)
inlineinherited

Scale gauss.

Parameters
factormultiplication factor
Returns
this gauss

Definition at line 123 of file JGauss.hh.

124 {
125 mean *= factor;
126 sigma *= factor;
127 signal *= factor;
128 background *= factor;
129
130 return *this;
131 }

◆ mul() [2/3]

JGauss_t & JMATH::JMath< JGauss_t, JSecond_t >::mul ( const JSecond_t & object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 354 of file JMath.hh.

355 {
356 return static_cast<JFirst_t&>(*this) = JFirst_t().mul(static_cast<const JFirst_t&>(*this), object);
357 }

◆ operator()() [2/2]

double JMATH::JMathlib< JGauss< ID_t > >::operator() ( const Args &... args) const
inlineinherited

Function value.

Parameters
argsabscissa value(s)
Returns
function value

Definition at line 331 of file JMathlib.hh.

332 {
333 return static_cast<const JF1_t&>(*this).getValue(args...);
334 }

◆ size()

static size_t JMATH::JMathlib< JGauss< ID_t > >::size ( )
inlinestaticinherited

Get size of parameter.

Returns
size

Definition at line 538 of file JMathlib.hh.

539 {
540 return JF1_t::parameters.size();
541 }

◆ operator[]() [1/2]

double JMATH::JMathlib< JGauss< ID_t > >::operator[] ( const size_t i) const
inlineinherited

Get value of parameter at given index.

Parameters
iindex
Returns
value

Definition at line 550 of file JMathlib.hh.

551 {
552 return static_cast<const JF1_t&>(*this).*JF1_t::parameters[i];
553 }

◆ operator[]() [2/2]

double & JMATH::JMathlib< JGauss< ID_t > >::operator[] ( const size_t i)
inlineinherited

Get value of parameter at given index.

Parameters
iindex
Returns
value

Definition at line 562 of file JMathlib.hh.

563 {
564 return static_cast<JF1_t&>(*this).*JF1_t::parameters[i];
565 }

◆ negate()

JGauss< ID_t > & JMATH::JCalculus< JGauss< ID_t > >::negate ( )
inlineinherited

Negate function.

Returns
this function

Definition at line 170 of file JMathlib.hh.

171 {
172 for (const auto& i : JF1_t::parameters) {
173 static_cast<JF1_t&>(*this).*i = -(static_cast<JF1_t&>(*this).*i);
174 }
175
176 return static_cast<JF1_t&>(*this);
177 }

◆ add() [2/2]

JGauss< ID_t > & JMATH::JCalculus< JGauss< ID_t > >::add ( const JGauss< ID_t > & f1)
inlineinherited

Add function.

Parameters
f1function
Returns
this function

Definition at line 186 of file JMathlib.hh.

187 {
188 for (const auto& i : JF1_t::parameters) {
189 static_cast<JF1_t&>(*this).*i += f1.*i;
190 }
191
192 return static_cast<JF1_t&>(*this);
193 }

◆ sub() [2/2]

JGauss< ID_t > & JMATH::JCalculus< JGauss< ID_t > >::sub ( const JGauss< ID_t > & f1)
inlineinherited

Subtract function.

Parameters
f1function
Returns
this function

Definition at line 202 of file JMathlib.hh.

203 {
204 for (const auto& i : JF1_t::parameters) {
205 static_cast<JF1_t&>(*this).*i -= f1.*i;
206 }
207
208 return static_cast<JF1_t&>(*this);
209 }

◆ mul() [3/3]

JGauss< ID_t > & JMATH::JCalculus< JGauss< ID_t > >::mul ( const double factor)
inlineinherited

Scale function.

Parameters
factorfactor
Returns
this function

Definition at line 218 of file JMathlib.hh.

219 {
220 for (const auto& i : JF1_t::parameters) {
221 static_cast<JF1_t&>(*this).*i *= factor;
222 }
223
224 return static_cast<JF1_t&>(*this);
225 }

◆ div()

JGauss< ID_t > & JMATH::JCalculus< JGauss< ID_t > >::div ( const double factor)
inlineinherited

Scale function.

Parameters
factorfactor
Returns
this function

Definition at line 234 of file JMathlib.hh.

235 {
236 for (const auto& i : JF1_t::parameters) {
237 static_cast<JF1_t&>(*this).*i /= factor;
238 }
239
240 return static_cast<JF1_t&>(*this);
241 }

Member Data Documentation

◆ gradient

template<int ID_t, bool normalised = false>
JGauss_t JMATH::JGauss< ID_t, normalised >::gradient
mutableprivate

Definition at line 364 of file JGauss.hh.

◆ ID

template<int ID_t, bool normalised = false>
const int JMATH::JGauss< ID_t, normalised >::ID = ID_t
static

Definition at line 2001 of file JMathlib.hh.

◆ center

template<int ID_t, bool normalised = false>
double JMATH::JGauss< ID_t, normalised >::center

center

Definition at line 2075 of file JMathlib.hh.

◆ sigma

template<int ID_t, bool normalised = false>
double JMATH::JGauss< ID_t, normalised >::sigma

sigma

Definition at line 2076 of file JMathlib.hh.

◆ parameters

template<int ID_t, bool normalised = false>
parameter_list<JGauss, 2> JMATH::JGauss< ID_t, normalised >::parameters { &JGauss::center, &JGauss::sigma }
staticconstexpr

Definition at line 2078 of file JMathlib.hh.

◆ mean

double JMATH::JGauss_t::mean
inherited

Definition at line 164 of file JGauss.hh.

◆ signal

double JMATH::JGauss_t::signal
inherited

Definition at line 166 of file JGauss.hh.

◆ background

double JMATH::JGauss_t::background
inherited

Definition at line 167 of file JGauss.hh.


The documentation for this struct was generated from the following files: