GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
GRootFunctions.cxx
Go to the documentation of this file.
1#include "GRootFunctions.h"
2#include "Rtypes.h"
3
5
6#define PI TMATH::Pi()
7
8Double_t GRootFunctions::PolyBg(Double_t* dim, Double_t* par, Int_t order) // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay, readability-non-const-parameter)
9{
10 Double_t result = 0.0;
11 int j = 0;
12 for(Int_t i = 0; i <= order; i++) {
13 result += *(par + j) * TMath::Power(dim[0], i);
14 j++;
15 }
16 // result += par[i]*TMath::Power(dim[0]-par[order+1],i);
17 return result;
18}
19
20Double_t GRootFunctions::LinFit(Double_t* dim, Double_t* par)
21{
22 return PolyBg(dim, par, 1);
23}
24
25Double_t GRootFunctions::QuadFit(Double_t* dim, Double_t* par)
26{
27 return PolyBg(dim, par, 2);
28}
29
30Double_t GRootFunctions::StepFunction(Double_t* dim, Double_t* par) // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay, readability-non-const-parameter)
31{
32 // -dim[0]: channels to fit
33 // -par[0]: height of peak
34 // -par[1]: centroid of peak
35 // -par[2]: sigma of peak
36 // -par[3]: size of step in step function.
37
38 Double_t x = dim[0];
39
40 Double_t height = par[0];
41 Double_t cent = par[1];
42 Double_t sigma = par[2];
43 // Double_t R = par[4];
44 Double_t step = par[3];
45
46 return height * (step / 100.0) * TMath::Erfc((x - cent) / (TMath::Sqrt(2.) * sigma));
47}
48
49Double_t GRootFunctions::StepBG(Double_t* dim, Double_t* par)
50{
51 return StepFunction(dim, par) + PolyBg(dim, (par + 4), 0);
52}
53
54Double_t GRootFunctions::Gaus(Double_t* dim, Double_t* par) // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay, readability-non-const-parameter)
55{
56 // - dim[0]: channels to fit
57 // - par[0]: height of peak
58 // - par[1]: cent of peak
59 // - par[2]: sigma
60 // - par[3]: relative height of skewed gaus to gaus
61
62 Double_t x = dim[0];
63 Double_t height = par[0];
64 Double_t cent = par[1];
65 Double_t sigma = par[2];
66 Double_t R = par[3];
67
68 return height * (1.0 - R / 100.0) * TMath::Gaus(x, cent, sigma);
69}
70
71Double_t GRootFunctions::SkewedGaus(Double_t* dim, Double_t* par) // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay, readability-non-const-parameter)
72{
73
74 // StepFunction(dim,par) + PolyBg
75 // - par[0]: height of peak
76 // - par[1]: cent of peak
77 // - par[2]: sigma
78 // - par[3]: relative height of skewed gaus to gaus
79 // - par[4]: "skewedness" of the skewed gaussin
80
81 Double_t x = dim[0]; // channel number used for fitting
82 Double_t height = par[0]; // height of photopeak
83 Double_t cent = par[1]; // Peak Centroid of non skew gaus
84 Double_t sigma = par[2]; // standard deviation of gaussian
85 Double_t R = par[3]; // relative height of skewed gaussian
86 Double_t beta = par[4]; //"skewedness" of the skewed gaussian
87
88 double scaling = R * height / 100.0;
89 // double x_rel = (x - cent)/sigma;
90
91 double fterm = (x - cent) / (sigma * TMath::Sqrt(2.));
92 double sterm = sigma / (beta * TMath::Sqrt(2.));
93
94 return scaling * TMath::Exp((x - cent) / beta) * TMath::Erfc(fterm + sterm);
95}
96
97Double_t GRootFunctions::PhotoPeak(Double_t* dim, Double_t* par)
98{
99 return Gaus(dim, par) + SkewedGaus(dim, par);
100}
101
102Double_t GRootFunctions::PhotoPeakBG(Double_t* dim, Double_t* par)
103{
104 // - dim[0]: channels to fit
105 // - par[0]: height of peak
106 // - par[1]: cent of peak
107 // - par[2]: sigma
108 // - par[3]: relative height of skewed gaus to gaus
109 // - par[4]: "skewedness" of the skewed gaussin
110 // - par[5]: size of stepfunction step.
111
112 // - par[6]: base bg height.
113 // - par[7]: slope of bg.
114
115 std::array<double, 4> spar = {par[0], par[1], par[2], par[5]};
116 return Gaus(dim, par) + SkewedGaus(dim, par) + StepFunction(dim, spar.data()) + PolyBg(dim, par + 6, 0);
117}
118
119// For fitting Ge detector efficiencies.
120Double_t GRootFunctions::Efficiency(Double_t* dim, Double_t* par) // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay, readability-non-const-parameter)
121{
122 // - dim[0]: energy.
123 // - par[0]: zeroth order
124 // - par[1]: first order
125 // - par[2]: second order
126 // - par[3]: inverse energy squared term.
127 // - Formula : 10**(0+1*Log(x)+2*Log(x)**2+3/x**2)
128
129 Double_t x = dim[0];
130 Double_t p0 = par[0];
131 Double_t p1 = par[1];
132 Double_t p2 = par[2];
133 Double_t p3 = par[3];
134
135 if(x != 0) {
136 return pow(10., p0 + p1 * TMath::Log10(x) + p2 * std::pow(TMath::Log10(x), 2.) + p3 / std::pow(x, 2.));
137 }
138 return 0;
139}
140
141Double_t GRootFunctions::GausExpo(Double_t* x, Double_t* pars) // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay, readability-non-const-parameter)
142{
143 // gaus + step*expo conv with a gaus.
144
145 // par[0] = height
146 // par[1] = cent
147 // par[2] = sigma
148 // par[3] = decay parameter
149
150 return TMath::Gaus(pars[0], pars[1], pars[2]) + static_cast<double>(x[0] > pars[1]) * pars[0] * TMath::Exp(-pars[3]);
151}
152
153Double_t GRootFunctions::LanGaus(Double_t* x, Double_t* pars)
154{
155 double conv = 0.;
156
157 for(int i = 0; i < 10; i++) {
158 double dy = 5 * pars[2] / 10.0; // truncate the convolution by decreasing number of evaluation points and decreasing
159 // range [2.5 sigma still covers 98.8% of gaussian]
160 double y = x[0] - 2.5 * pars[2] + dy * i;
161 double spec = pars[0] +
162 pars[1] * y; // define background SHOULD THIS BE CONVOLUTED ????? *************************************
163 // for( int n=0; n<(int)(pars[0]+0.5); n++) // the implementation of landau function should be done using the
164 // landau function
165 spec += pars[3] * TMath::Landau(-y, -pars[4], pars[5]) /
166 TMath::Landau(0, 0, 100); // add peaks, dividing by max height of landau
167 double gaus = TMath::Gaus(-x[0], -y, pars[2]) /
168 sqrt(2 * TMath::Pi() * pars[2] * pars[2]); // gaus must be normalisd so there is no sigma weighting
169 conv += gaus * spec * dy; // now convolve this [integrate the product] with a gaussian centered at x;
170 }
171
172 return conv;
173}
174
175Double_t GRootFunctions::LanGausHighRes(Double_t* x, Double_t* pars)
176{ // 5x more convolution points with 1.6x larger range
177 double conv = 0.;
178
179 for(int i = 0; i < 50; i++) {
180 double dy = 8 * pars[2] / 50.0; // 4 sigma covers 99.99% of gaussian
181 double y = x[0] - 4 * pars[2] + dy * i;
182
183 double spec = pars[0] + pars[1] * y;
184 // for( int n=0; n<(int)(pars[0]+0.5); n++)
185 spec += pars[3] * TMath::Landau(-y, -pars[4], pars[5]) / TMath::Landau(0, 0, 100);
186
187 double gaus = TMath::Gaus(-x[0], -y, pars[2]) / sqrt(2 * TMath::Pi() * pars[2] * pars[2]);
188 conv += gaus * spec * dy;
189 }
190 return conv;
191}
192
193Double_t GRootFunctions::GammaEff(Double_t* x, Double_t* par) // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay, readability-non-const-parameter)
194{
195 // LOG(EFF) = A0 + A1*LOG(E) + A2*LOG(E)^2 + A3/E^2
196
197 double logE = TMath::Log10(x[0]);
198 double temp = par[0] + par[1] * logE + par[2] * logE * logE + par[3] / (x[0] * x[0]);
199 return pow(10, temp);
200}
NamespaceImp(GRootFunctions) Double_t GRootFunctions
Double_t PhotoPeak(Double_t *dim, Double_t *par)
Double_t Gaus(Double_t *dim, Double_t *par)
Double_t StepFunction(Double_t *dim, Double_t *par)
Double_t LanGaus(Double_t *x, Double_t *pars)
Double_t StepBG(Double_t *dim, Double_t *par)
Double_t GammaEff(Double_t *x, Double_t *par)
Double_t LinFit(Double_t *dim, Double_t *par)
Double_t QuadFit(Double_t *dim, Double_t *par)
Double_t PolyBg(Double_t *dim, Double_t *par, Int_t order)
Double_t LanGausHighRes(Double_t *x, Double_t *pars)
Double_t Efficiency(Double_t *dim, Double_t *par)
Double_t SkewedGaus(Double_t *dim, Double_t *par)
Double_t PhotoPeakBG(Double_t *dim, Double_t *par)
Double_t GausExpo(Double_t *x, Double_t *pars)