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

3D correlated Gauss function. More...

#include <JMathlib3D.hh>

Inheritance diagram for JMATH::JGauss3D< ID_t, normalise >:
JMATH::JMathlib< JGauss3D< ID_t, false > > JMATH::JGauss< ID_t, false > 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

 JGauss3D ()
 Default constructor.
 
 JGauss3D (const double mean, const double sigma)
 Constructor.
 
double getValue (const double x, const double y, const double z) const
 Function value.
 
const JGauss3DgetGradient (const double x, const double y, const double z) const
 Get gradient.
 
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.
 
double getValue (const double x) const
 Function value.
 
double getDerivative (const double x) const
 Derivative 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.
 
double operator() (const Args &...args) const
 Function value.
 
const JGauss_tgetGradient (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< ID_t > & add (const JGauss< ID_t > &f1)
 Add function.
 
JGauss_tsub (const JGauss_t &gauss)
 Subtract gauss.
 
JGauss< ID_t > & sub (const JGauss< ID_t > &f1)
 Subtract function.
 
JGauss_tmul (const double factor)
 Scale gauss.
 
JGauss_tmul (const JSecond_t &object)
 Multiply with object.
 
JGauss< ID_t > & mul (const double factor)
 Scale function.
 
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 > & div (const double factor)
 Scale function.
 

Static Public Member Functions

static size_t size ()
 Get size of parameter.
 
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
 
static constexpr parameter_list< JGauss, 2 > parameters
 

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 normalise = false>
struct JMATH::JGauss3D< ID_t, normalise >

3D correlated Gauss function.

Definition at line 267 of file JMathlib3D.hh.

Member Typedef Documentation

◆ parameter_type

double JGauss_t::* JMATH::JGauss< ID_t, normalised >::parameter_type
inherited

Type definition of fit parameter.

Definition at line 182 of file JGauss.hh.

Constructor & Destructor Documentation

◆ JGauss3D() [1/2]

template<int ID_t, bool normalise = false>
JMATH::JGauss3D< ID_t, normalise >::JGauss3D ( )
inline

Default constructor.

Definition at line 277 of file JMathlib3D.hh.

278 {}

◆ JGauss3D() [2/2]

template<int ID_t, bool normalise = false>
JMATH::JGauss3D< ID_t, normalise >::JGauss3D ( const double mean,
const double sigma )
inline

Constructor.

Parameters
meanmean
sigmasigma

Definition at line 287 of file JMathlib3D.hh.

Member Function Documentation

◆ getValue() [1/2]

template<int ID_t, bool normalise = false>
double JMATH::JGauss3D< ID_t, normalise >::getValue ( const double x,
const double y,
const double z ) const
inline

Function value.

Parameters
xabscissa value
yabscissa value
zabscissa value
Returns
function value

Definition at line 301 of file JMathlib3D.hh.

302 {
303 typedef JGauss<ID_t, normalise> JGauss_t;
304
305 return (static_cast<const JGauss_t&>(*this).getValue(x) *
306 static_cast<const JGauss_t&>(*this).getValue(y) *
307 static_cast<const JGauss_t&>(*this).getValue(z));
308 }
JGauss_t()
Default constructor.
Definition JGauss.hh:37

◆ getGradient() [1/2]

template<int ID_t, bool normalise = false>
const JGauss3D & JMATH::JGauss3D< ID_t, normalise >::getGradient ( const double x,
const double y,
const double z ) const
inline

Get gradient.

Parameters
xabscissa value
yabscissa value
zabscissa value
Returns
gradient

Definition at line 319 of file JMathlib3D.hh.

320 {
321 static JGauss3D gradient;
322
323 typedef JGauss<ID_t, normalise> JGauss_t;
324
325 static_cast<JGauss_t&>(gradient) = JGauss_t(static_cast<const JGauss_t&>(*this).getGradient(x)).mul(static_cast<const JGauss_t&>(*this).getValue(y) * static_cast<const JGauss_t&>(*this).getValue(z));
326 static_cast<JGauss_t&>(gradient) += JGauss_t(static_cast<const JGauss_t&>(*this).getGradient(y)).mul(static_cast<const JGauss_t&>(*this).getValue(x) * static_cast<const JGauss_t&>(*this).getValue(z));
327 static_cast<JGauss_t&>(gradient) += JGauss_t(static_cast<const JGauss_t&>(*this).getGradient(z)).mul(static_cast<const JGauss_t&>(*this).getValue(x) * static_cast<const JGauss_t&>(*this).getValue(y));
328
329 return gradient;
330 }
JGauss3D()
Default constructor.
JGauss_t & mul(const double factor)
Scale gauss.
Definition JGauss.hh:123

◆ operator()() [1/3]

double JMATH::JMathlib< JGauss3D< ID_t, false > >::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() [1/2]

static size_t JMATH::JMathlib< JGauss3D< ID_t, false > >::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/4]

double JMATH::JMathlib< JGauss3D< ID_t, false > >::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/4]

double & JMATH::JMathlib< JGauss3D< ID_t, false > >::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 }

◆ getValue() [2/2]

double JMATH::JGauss< ID_t, normalised >::getValue ( const double x) const
inlineinherited

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 background
Definition JGauss.hh:167
double signal
Definition JGauss.hh:166

◆ getDerivative() [1/2]

double JMATH::JGauss< ID_t, normalised >::getDerivative ( const double x) const
inlineinherited

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 }

◆ getDerivative() [2/2]

double JMATH::JGauss< ID_t, normalised >::getDerivative ( const double x) const
inlineinherited

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 }

◆ getIntegral()

double JMATH::JGauss< ID_t, normalised >::getIntegral ( const double xmin,
const double xmax ) const
inlineinherited

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()() [2/3]

double JMATH::JGauss< ID_t, normalised >::operator() ( const double x) const
inlineinherited

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
Definition JGauss.hh:227

◆ operator()() [3/3]

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 }

◆ getGradient() [2/2]

const JGauss_t & JMATH::JGauss< ID_t, normalised >::getGradient ( const double x) const
inlineinherited

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 }

◆ get() [1/2]

double JMATH::JGauss< ID_t, normalised >::get ( const double u) const
inlineprivateinherited

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 }

◆ get() [2/2]

double JMATH::JGauss< ID_t, normalised >::get ( const double u) const
inlineprivateinherited

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 }
double gauss(const double x, const double sigma)
Gauss function (normalised to 1 at x = 0).

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

◆ 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() [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 }

◆ 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() [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 }

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

◆ size() [2/2]

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[]() [3/4]

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[]() [4/4]

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 }

◆ 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

JGauss_t JMATH::JGauss< ID_t, normalised >::gradient
mutableprivateinherited

Definition at line 364 of file JGauss.hh.

◆ ID

const int JMATH::JGauss< ID_t, normalised >::ID
staticinherited

Definition at line 2001 of file JMathlib.hh.

◆ center

double JMATH::JGauss< ID_t, normalised >::center
inherited

center

Definition at line 2075 of file JMathlib.hh.

◆ sigma

double JMATH::JGauss< ID_t, normalised >::sigma
inherited

sigma

Definition at line 2076 of file JMathlib.hh.

◆ parameters

parameter_list<JGauss, 2> JMATH::JGauss< ID_t, normalised >::parameters
staticconstexprinherited

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 file: