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 if(TPeakFitter::VerboseLevel() >= EVerbosity::kSubroutines) { std::cout << __PRETTY_FUNCTION__ << std::endl; } // NOLINT(cppcoreguidelines-pro-type-const-cast, cppcoreguidelines-pro-bounds-array-to-pointer-decay)
14 SetFitFunction(new TF1("gauss_total", this, &TGauss::TotalFunction, 0, 1, 3, "TGauss", "TotalFunction"));
15 SetPeakFunction(new TF1("gauss_peak", this, &TGauss::PeakFunction, 0, 1, 3, "TGauss", "TotalFunction")); // peak = total function
16 if(TPeakFitter::VerboseLevel() >= EVerbosity::kSubroutines) { std::cout << "Set the fit and peak functions" << std::endl; }
18 GetFitFunction()->SetParameter(1, centroid);
19 if(TPeakFitter::VerboseLevel() >= EVerbosity::kSubroutines) { std::cout << "Set the centroid to " << centroid << std::endl; }
20 SetListOfBGPar(std::vector<bool>{false, false, false, false, false, true});
21 GetFitFunction()->SetLineColor(kMagenta);
22 if(TPeakFitter::VerboseLevel() >= EVerbosity::kSubroutines) { std::cout << __PRETTY_FUNCTION__ << ": done" << std::endl; } // NOLINT(cppcoreguidelines-pro-type-const-cast, cppcoreguidelines-pro-bounds-array-to-pointer-decay)
23}
24
26{
27 if(TPeakFitter::VerboseLevel() >= EVerbosity::kSubroutines) { std::cout << __PRETTY_FUNCTION__ << std::endl; } // NOLINT(cppcoreguidelines-pro-type-const-cast, cppcoreguidelines-pro-bounds-array-to-pointer-decay)
28 GetFitFunction()->SetParName(0, "height");
29 GetFitFunction()->SetParName(1, "centroid");
30 GetFitFunction()->SetParName(2, "sigma");
31 if(TPeakFitter::VerboseLevel() >= EVerbosity::kSubroutines) { std::cout << __PRETTY_FUNCTION__ << ": done" << std::endl; } // NOLINT(cppcoreguidelines-pro-type-const-cast, cppcoreguidelines-pro-bounds-array-to-pointer-decay)
32}
33
34void TGauss::InitializeParameters(TH1* fit_hist, const double& rangeLow, const double& rangeHigh)
35{
36 /// Makes initial guesses at parameters for the fit base on the histogram.
37 // Make initial guesses
38 // Actually set the parameters in the photopeak function
39 // Fixing has to come after setting
40 // Might have to include bin widths eventually
41 // The centroid should already be set by this point in the ctor
42 // We need to set the limits after setting the parameter otherwise we might get a warning
43 // that the parameter (which is zero at this time) is outside the limits.
44 Int_t bin = fit_hist->FindBin(GetFitFunction()->GetParameter(1));
45 if(!ParameterSetByUser(0)) {
46 GetFitFunction()->SetParameter("height", fit_hist->GetBinContent(bin));
47 GetFitFunction()->SetParLimits(0, 0, fit_hist->GetMaximum() * 2.);
48 }
49 if(!ParameterSetByUser(1)) {
50 GetFitFunction()->SetParLimits(1, rangeLow, rangeHigh);
51 }
52 if(!ParameterSetByUser(2)) {
53 GetFitFunction()->SetParameter("sigma", TMath::Sqrt(5 + 1.33 * GetFitFunction()->GetParameter("centroid") / 1000. + 0.9 * TMath::Power(GetFitFunction()->GetParameter("centroid") / 1000., 2)) / 2.35);
54 GetFitFunction()->SetParLimits(2, 0.01, 10.);
55 }
56}
57
58Double_t TGauss::Centroid() const
59{
60 return GetFitFunction()->GetParameter("centroid");
61}
62
63Double_t TGauss::CentroidErr() const
64{
65 return GetFitFunction()->GetParError(1);
66}
67
68Double_t TGauss::PeakFunction(Double_t* dim, Double_t* par)
69{
70 Double_t x = dim[0]; // channel number used for fitting
71 Double_t height = par[0]; // height of photopeak
72 Double_t c = par[1]; // centroid of gaussian
73 Double_t sigma = par[2]; // standard deviation of gaussian
74
75 Double_t gauss = height * TMath::Gaus(x, c, sigma);
76
77 return gauss;
78}
@ kSubroutines
Definition Globals.h:146
TGauss()=default
Double_t PeakFunction(Double_t *dim, Double_t *par) override
Definition TGauss.cxx:68
void InitParNames() override
Definition TGauss.cxx:25
void InitializeParameters(TH1 *hist, const double &rangeLow, const double &rangeHigh) override
Definition TGauss.cxx:34
Double_t CentroidErr() const override
Definition TGauss.cxx:63
Double_t Centroid() const override
Definition TGauss.cxx:58
static EVerbosity VerboseLevel()
Definition TPeakFitter.h:88
TF1 * GetFitFunction() const
Definition TSinglePeak.h:78
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