GausRmsFitter.h
Go to the documentation of this file.
1 // GausRmsFitter.h
2 
3 #ifndef GausRmsFitter_H
4 #define GausRmsFitter_H
5 
6 // David Adams
7 // December 2018
8 //
9 // Utility to evaluate the mean and RMS for a peak in a histogram and
10 // return those and the selected range in an attached gaus function with
11 // fitted height.
12 //
13 // There are two configuration parameters: sigma0 and nsigma.
14 // Calls to fit a histogram add a starting mean, mean0.
15 //
16 // If both sigma0 and nsigma are valid (i.e. are > 0), then the RMS is
17 // evaluated iteratively over the range (mean-nsigma*sigma, mean+nsigma*sigma)
18 // until it coverges on a value for sigma. The range is restricted to that of
19 // the input, i.e. its default or the value set with axis SetRange or SetRangeUser.
20 // The starting values for the iteration are mean0 and sigma0 and the iteration
21 // stops when the evaluated value for sigma is less or close to that used to
22 // define the range.
23 //
24 // If sigma0 is valid and nsigma is not, then those are used for the
25 // corresponding function values.
26 //
27 // If both are invalid, mean0 is ignored and man and RMS for the full range
28 // are used to construct the function.
29 //
30 // Any other configuration results in a fit error.
31 
32 #include <string>
33 class TH1;
34 
36 
37 public:
38 
39  using Name = std::string;
40  using Index = unsigned int;
41 
42  // Ctor for fit of full histogram.
43  GausRmsFitter(Name fnam);
44 
45  // Ctor to fit range of n-sigma starting with sigma0.
46  GausRmsFitter(double sigma0, double nsigma, Name fnam);
47 
48  // Fit a histogram with the provided starting mean.
49  // Returns 0 for success.
50  // If successful, a gaus function is attached to the histogram.
51  // This function has the assigned mean, sigma and fit range and the fitted height.
52  int fit(TH1* ph, double mean0) const;
53 
54  // Set the log level.
55  void setLogLevel(Index lev) { m_LogLevel = lev; }
56 
57 private:
58 
59  double m_sigma0;
60  double m_nsigma;
63 
64 };
65 
66 #endif
std::string Name
Definition: GausRmsFitter.h:39
std::string string
Definition: nybbler.cc:12
GausRmsFitter(Name fnam)
int fit(TH1 *ph, double mean0) const
unsigned int Index
Definition: GausRmsFitter.h:40
void setLogLevel(Index lev)
Definition: GausRmsFitter.h:55