hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
FunctionMath.cxx
Go to the documentation of this file.
1#include "FunctionMath.h"
2#include <TMath.h>
3
4double FunctionMath::ChebyshevFunction(double x, double* p, int order) {
5 double total = p[0];
6 if(order >= 1) { total += p[1] * x; }
7 if(order >= 2) { total += p[2] * (2 * x * x - 1); }
8 if(order >= 3) { total += p[3] * (4 * x * x * x - 3 * x); }
9 if(order >= 4) { total += p[4] * (8 * x * x * x * x - 8 * x * x + 1); }
10 if(order >= 5) { total += p[5] * (16 * x * x * x * x * x - 20 * x * x * x + 5 * x); }
11 if(order >= 6) { total += p[6] * (32 * x * x * x * x * x * x - 48 * x * x * x * x + 18 * x * x - 1); }
12 if(order >= 7) { total += p[7] * (64 * x * x * x * x * x * x * x - 112 * x * x * x * x * x + 56 * x * x * x - 7 * x); }
13
14 return total;
15}
16
17double FunctionMath::LegendreFunction(double x, double* p, int order) {
18 double total = p[0];
19 if(order >= 1) { total += p[1] * x; }
20 if(order >= 2) { total += p[2] * (3 * x * x - 1) / 2; }
21 if(order >= 3) { total += p[3] * (5 * x * x * x - 3 * x) / 2; }
22 if(order >= 4) { total += p[4] * (35 * x * x * x * x - 30 * x * x - 3) / 8; }
23 if(order >= 5) { total += p[5] * (63 * x * x * x * x * x - 70 * x * x * x + 15 * x) / 8; }
24 if(order >= 6) { total += p[6] * (231 * x * x * x * x * x * x - 315 * x * x * x * x + 105 * x * x - 5) / 16; }
25 if(order >= 7) { total += p[7] * (429 * x * x * x * x * x * x * x - 693 * x * x * x * x * x + 315 * x * x * x - 35 * x) / 16; }
26
27 return total;
28}
29
30double FunctionMath::Gaussian(double x, double amplitude, double mean, double stddev) {
31 return amplitude * 1.0 / (sqrt(2.0 * TMath::Pi() * pow(stddev, 2))) * TMath::Exp(-pow((x - mean), 2) / (2.0 * pow(stddev, 2)));
32}
33
34double FunctionMath::CrystalBall(double x, double amplitude, double mean, double stddev, double alpha, double n) {
35 // The crystal ball function differs based on the value of x.
36 double differentiator = (x - mean) / stddev;
37 if(differentiator > -alpha) {
38 // Return the functional value.
39 return amplitude * exp(-pow(x - mean, 2) / (2 * pow(stddev, 2)));
40 } else {
41 // Calculate the derived parameters A and B.
42 double absAlpha = fabs(alpha);
43 double A = calcA(n, absAlpha);
44 double B = calcB(n, absAlpha);
45
46 // Return the functional value.
47 return amplitude * A * pow(B - ((x - mean) / stddev), -n);
48 }
49}
50
51double FunctionMath::calcA(double n, double absAlpha) {
52 return pow(n / absAlpha, n) * exp(-pow(absAlpha, 2) / 2);
53}
54
55double FunctionMath::calcB(double n, double absAlpha) {
56 return (n / absAlpha) - absAlpha;
57}
static double calcA(double n, double absAlpha)
Calculates a portion of the crystal ball function.
static double calcB(double n, double absAlpha)
Calculates a portion of the crystal ball function.
static double ChebyshevFunction(double x, double *p, int order)
Defines a Chebyshev polynomial function.
static double CrystalBall(double x, double amplitude, double mean, double stddev, double alpha, double n)
Defines a crystal ball function for signal-fitting.
static double Gaussian(double x, double amplitude, double mean, double stddev)
Defines a Gaussian function for signal-fitting.
static double LegendreFunction(double x, double *p, int order)
Define a Legendre polynomial function.