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