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