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