Jpp 21.0.0-rc.1-88-g0130508c4
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 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.
 

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 1945 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 179 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 185 of file JGauss.hh.

185 :
186 JGauss_t()
187 {}
JGauss_t()
Default constructor.
Definition JGauss.hh:36

◆ 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 195 of file JGauss.hh.

195 :
197 {}
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 208 of file JGauss.hh.

211 :
213 {}
double background
Definition JGauss.hh:164
double signal
Definition JGauss.hh:163
double sigma
sigma
Definition JMathlib.hh:2024

◆ JGauss() [4/5]

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

Default constructor.

Definition at line 1955 of file JMathlib.hh.

1955 :
1956 center(0.0),
1957 sigma (0.0)
1958 {}
double center
center
Definition JMathlib.hh:2023

◆ 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 1967 of file JMathlib.hh.

1968 :
1969 center(center),
1970 sigma (sigma)
1971 {}

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.

Parameters
xabscissa value
Returns
function value

Definition at line 222 of file JGauss.hh.

223 {
224 const double u = (x - mean) / sigma;
225
226 return signal * get(u) + background;
227 }
double get(const double u) const
Get ordinate value.
Definition JGauss.hh:284

◆ getDerivative() [1/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 236 of file JGauss.hh.

237 {
238 const double u = (x - mean) / sigma;
239
240 return signal * get(u) * -u / sigma;
241 }

◆ 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 250 of file JGauss.hh.

251 {
252 return getValue(x);
253 }
double getValue(const double x) const
Function value.
Definition JGauss.hh:222

◆ 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.

Parameters
xabscissa value
Returns
gradient

Definition at line 262 of file JGauss.hh.

263 {
264 const double w = 1.0 / sigma;
265 const double u = (x - mean) * w;
266 const double f0 = get(u);
267 const double fs = signal * f0;
268
269 gradient.mean = fs * (u) * w; // d(f)/d(mean)
270 gradient.sigma = fs * (u + 1.0) * (u - 1.0) * w; // d(f)/d(sigma)
271 gradient.signal = f0; // d(f)/d(signal)
272 gradient.background = 1.0; // d(f)/d(background)
273
274 return gradient;
275 }
JGauss_t gradient
Definition JGauss.hh:289

◆ 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.

Parameters
uabscissa value
Returns
ordinate value

Definition at line 284 of file JGauss.hh.

285 {
286 return exp(-0.5*u*u) / (sqrt(2.0*PI) * sigma);
287 }

◆ 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 1980 of file JMathlib.hh.

1981 {
1982 const double u = (x - center) / sigma;
1983
1984 return get(u);
1985 }

◆ 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 1994 of file JMathlib.hh.

1995 {
1996 const double w = 1.0 / sigma;
1997 const double u = (x - center) / sigma;
1998
1999 return get(u) * -u * w;
2000 }

◆ 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 2009 of file JMathlib.hh.

2010 {
2011 JGauss gradient;
2012
2013 const double w = 1.0 / sigma;
2014 const double u = (x - center) * w;
2015 const double f0 = get(u);
2016
2017 gradient.center = f0 * u * w; // d(f)/d(center)
2018 gradient.sigma = f0 * u * u * w; // d(f)/d(sigma)
2019
2020 return gradient;
2021 }

◆ 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 2035 of file JMathlib.hh.

2036 {
2037 return exp(-0.5*u*u);
2038 }

◆ 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 70 of file JGauss.hh.

72 {
73 return (fabs(mean - gauss.mean) <= eps &&
74 fabs(sigma - gauss.sigma) <= eps &&
75 fabs(signal - gauss.signal) <= eps &&
76 fabs(background - gauss.background) <= eps);
77 }

◆ add() [1/2]

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

Add gauss.

Parameters
gaussgauss
Returns
this gauss

Definition at line 86 of file JGauss.hh.

87 {
88 mean += gauss.mean;
89 sigma += gauss.sigma;
90 signal += gauss.signal;
91 background += gauss.background;
92
93 return *this;
94 }

◆ sub() [1/2]

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

Subtract gauss.

Parameters
gaussgauss
Returns
this gauss

Definition at line 103 of file JGauss.hh.

104 {
105 mean -= gauss.mean;
106 sigma -= gauss.sigma;
107 signal -= gauss.signal;
108 background -= gauss.background;
109
110 return *this;
111 }

◆ mul() [1/3]

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

Scale gauss.

Parameters
factormultiplication factor
Returns
this gauss

Definition at line 120 of file JGauss.hh.

121 {
122 mean *= factor;
123 sigma *= factor;
124 signal *= factor;
125 background *= factor;
126
127 return *this;
128 }

◆ 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 330 of file JMathlib.hh.

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

◆ 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 538 of file JMathlib.hh.

539 {
540 return static_cast<const JF1_t&>(*this).*JF1_t::parameters[i];
541 }

◆ 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 550 of file JMathlib.hh.

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

◆ negate()

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

Negate function.

Returns
this function

Definition at line 169 of file JMathlib.hh.

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

◆ 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 185 of file JMathlib.hh.

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

◆ 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 201 of file JMathlib.hh.

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

◆ 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 217 of file JMathlib.hh.

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

◆ div()

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

Scale function.

Parameters
factorfactor
Returns
this function

Definition at line 233 of file JMathlib.hh.

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

Member Data Documentation

◆ gradient

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

Definition at line 289 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 1949 of file JMathlib.hh.

◆ center

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

center

Definition at line 2023 of file JMathlib.hh.

◆ sigma

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

sigma

Definition at line 2024 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 2026 of file JMathlib.hh.

◆ mean

double JMATH::JGauss_t::mean
inherited

Definition at line 161 of file JGauss.hh.

◆ signal

double JMATH::JGauss_t::signal
inherited

Definition at line 163 of file JGauss.hh.

◆ background

double JMATH::JGauss_t::background
inherited

Definition at line 164 of file JGauss.hh.


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