GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TRWPeak.cxx
Go to the documentation of this file.
1#include "TRWPeak.h"
2
3#include "TH1.h"
4
5void TRWPeak::Centroid(const Double_t& centroid)
6{
7 SetFitFunction(new TF1("rw_total", this, &TRWPeak::TotalFunction, 0, 1, 6, "TRWPeak", "TotalFunction"));
8 SetPeakFunction(new TF1("rw_peak", this, &TRWPeak::PeakFunction, 0, 1, 5, "TRWPeak", "PeakFunction"));
10 GetFitFunction()->SetParameter(1, centroid);
11 SetListOfBGPar(std::vector<bool>{false, false, false, false, false, true});
12 GetFitFunction()->SetLineColor(kMagenta);
13}
14
16{
17 GetFitFunction()->SetParName(0, "Height");
18 GetFitFunction()->SetParName(1, "centroid");
19 GetFitFunction()->SetParName(2, "sigma");
20 GetFitFunction()->SetParName(3, "beta");
21 GetFitFunction()->SetParName(4, "R");
22 GetFitFunction()->SetParName(5, "step");
23}
24
25void TRWPeak::InitializeParameters(TH1* fit_hist, const double& rangeLow, const double& rangeHigh)
26{
27 /// Makes initial guesses at parameters for the fit base on the histogram.
28 // Make initial guesses
29 // Actually set the parameters in the photopeak function
30 // Fixing has to come after setting
31 // Might have to include bin widths eventually
32 // The centroid should already be set by this point in the ctor
33 Int_t bin = fit_hist->FindBin(GetFitFunction()->GetParameter(1));
34 if(!ParameterSetByUser(0)) {
35 GetFitFunction()->SetParameter("Height", fit_hist->GetBinContent(bin));
36 GetFitFunction()->SetParLimits(0, 0, fit_hist->GetMaximum() * 2.);
37 }
38 if(!ParameterSetByUser(1)) {
39 GetFitFunction()->SetParLimits(1, rangeLow, rangeHigh);
40 }
41 if(!ParameterSetByUser(2)) {
42 GetFitFunction()->SetParameter("sigma", TMath::Sqrt(5 + 1.33 * GetFitFunction()->GetParameter("centroid") / 1000. + 0.9 * TMath::Power(GetFitFunction()->GetParameter("centroid") / 1000., 2)) / 2.35);
43 GetFitFunction()->SetParLimits(2, 0.01, 10.);
44 }
45 if(!ParameterSetByUser(3)) {
46 GetFitFunction()->SetParameter("beta", GetFitFunction()->GetParameter("sigma") / 2.0);
47 // GetFitFunction()->SetParLimits(3, 0.000001, 10);
48 GetFitFunction()->FixParameter(3, GetFitFunction()->GetParameter("beta"));
49 }
50 if(!ParameterSetByUser(4)) {
51 GetFitFunction()->SetParameter("R", 0.001);
52 GetFitFunction()->SetParLimits(4, 0.000001, 100); // this is a percentage. no reason for it to go to 500% - JKS
53 GetFitFunction()->FixParameter(4, 0.00);
54 }
55 // Step size is allow to vary to anything. If it goes below 0, the code will fix it to 0
56 if(!ParameterSetByUser(5)) {
57 GetFitFunction()->SetParameter("step", 0.1);
58 GetFitFunction()->SetParLimits(5, 0.0, 1.0E2);
59 }
60}
61
62Double_t TRWPeak::Centroid() const
63{
64 return GetFitFunction()->GetParameter("centroid");
65}
66
67Double_t TRWPeak::CentroidErr() const
68{
69 return GetFitFunction()->GetParError(1);
70}
71
72Double_t TRWPeak::PeakFunction(Double_t* dim, Double_t* par)
73{
74 Double_t x = dim[0]; // channel number used for fitting
75 Double_t height = par[0]; // height of photopeak
76 Double_t centroid = par[1]; // Peak Centroid of non skew gaus
77 Double_t sigma = par[2]; // standard deviation of gaussian
78 Double_t beta = par[3]; // Skewness parameter
79 Double_t relative = par[4]; // relative height of skewed gaussian
80
81 Double_t gauss = height * (1.0 - relative / 100.0) * TMath::Gaus(x, centroid, sigma);
82
83 if(beta == 0.0) { return gauss; }
84
85 return gauss + relative * height / 100.0 * (TMath::Exp((x - centroid) / beta)) *
86 (TMath::Erfc(((x - centroid) / (TMath::Sqrt(2.0) * sigma)) + sigma / (TMath::Sqrt(2.0) * beta)));
87}
88
89Double_t TRWPeak::BackgroundFunction(Double_t* dim, Double_t* par)
90{
91 Double_t x = dim[0]; // channel number used for fitting
92 Double_t height = par[0]; // height of photopeak
93 Double_t centroid = par[1]; // Peak Centroid of non skew gaus
94 Double_t sigma = par[2]; // standard deviation of gaussian
95 Double_t step = par[5]; // Size of the step function;
96
97 Double_t step_func = TMath::Abs(step) * height / 100.0 * TMath::Erfc((x - centroid) / (TMath::Sqrt(2.0) * sigma));
98
99 return step_func;
100}
void InitializeParameters(TH1 *hist, const double &rangeLow, const double &rangeHigh) override
Definition TRWPeak.cxx:25
Double_t CentroidErr() const override
Definition TRWPeak.cxx:67
Double_t BackgroundFunction(Double_t *dim, Double_t *par) override
Definition TRWPeak.cxx:89
Double_t PeakFunction(Double_t *dim, Double_t *par) override
Definition TRWPeak.cxx:72
Double_t Centroid() const override
Definition TRWPeak.cxx:62
void InitParNames() override
Definition TRWPeak.cxx:15
TF1 * GetFitFunction() const
Definition TSinglePeak.h:72
void SetPeakFunction(TF1 *function)
bool ParameterSetByUser(int par)
Double_t TotalFunction(Double_t *dim, Double_t *par)
void SetFitFunction(TF1 *function)
void SetListOfBGPar(const std::vector< bool > &list_of_bg_par)
Definition TSinglePeak.h:45