GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TGauss.cxx
Go to the documentation of this file.
1#include "TGauss.h"
2
3TGauss::TGauss(Double_t centroid, Double_t relativeLimit)
4{
5 Centroid(centroid);
6 if(relativeLimit >= 0) {
7 GetFitFunction()->SetParLimits(1, (1. - relativeLimit) * centroid, (1. + relativeLimit) * centroid);
8 }
9}
10
11void TGauss::Centroid(const Double_t& centroid)
12{
13 SetFitFunction(new TF1("gauss_total", this, &TGauss::TotalFunction, 0, 1, 3, "TGauss", "TotalFunction"));
14 SetPeakFunction(new TF1("gauss_peak", this, &TGauss::PeakFunction, 0, 1, 3, "TGauss", "TotalFunction")); // peak = total function
16 GetFitFunction()->SetParameter(1, centroid);
17 SetListOfBGPar(std::vector<bool>{false, false, false, false, false, true});
18 GetFitFunction()->SetLineColor(kMagenta);
19}
20
22{
23 GetFitFunction()->SetParName(0, "height");
24 GetFitFunction()->SetParName(1, "centroid");
25 GetFitFunction()->SetParName(2, "sigma");
26}
27
28void TGauss::InitializeParameters(TH1* fit_hist, const double& rangeLow, const double& rangeHigh)
29{
30 /// Makes initial guesses at parameters for the fit base on the histogram.
31 // Make initial guesses
32 // Actually set the parameters in the photopeak function
33 // Fixing has to come after setting
34 // Might have to include bin widths eventually
35 // The centroid should already be set by this point in the ctor
36 // We need to set the limits after setting the parameter otherwise we might get a warning
37 // that the parameter (which is zero at this time) is outside the limits.
38 Int_t bin = fit_hist->FindBin(GetFitFunction()->GetParameter(1));
39 if(!ParameterSetByUser(0)) {
40 GetFitFunction()->SetParameter("height", fit_hist->GetBinContent(bin));
41 GetFitFunction()->SetParLimits(0, 0, fit_hist->GetMaximum() * 2.);
42 }
43 if(!ParameterSetByUser(1)) {
44 GetFitFunction()->SetParLimits(1, rangeLow, rangeHigh);
45 }
46 if(!ParameterSetByUser(2)) {
47 GetFitFunction()->SetParameter("sigma", TMath::Sqrt(5 + 1.33 * GetFitFunction()->GetParameter("centroid") / 1000. + 0.9 * TMath::Power(GetFitFunction()->GetParameter("centroid") / 1000., 2)) / 2.35);
48 GetFitFunction()->SetParLimits(2, 0.01, 10.);
49 }
50}
51
52Double_t TGauss::Centroid() const
53{
54 return GetFitFunction()->GetParameter("centroid");
55}
56
57Double_t TGauss::CentroidErr() const
58{
59 return GetFitFunction()->GetParError(1);
60}
61
62Double_t TGauss::PeakFunction(Double_t* dim, Double_t* par)
63{
64 Double_t x = dim[0]; // channel number used for fitting
65 Double_t height = par[0]; // height of photopeak
66 Double_t c = par[1]; // centroid of gaussian
67 Double_t sigma = par[2]; // standard deviation of gaussian
68
69 Double_t gauss = height * TMath::Gaus(x, c, sigma);
70
71 return gauss;
72}
TGauss()=default
Double_t PeakFunction(Double_t *dim, Double_t *par) override
Definition TGauss.cxx:62
void InitParNames() override
Definition TGauss.cxx:21
void InitializeParameters(TH1 *hist, const double &rangeLow, const double &rangeHigh) override
Definition TGauss.cxx:28
Double_t CentroidErr() const override
Definition TGauss.cxx:57
Double_t Centroid() const override
Definition TGauss.cxx:52
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