Analysis-Utilities 26.9.9
C++/ROOT utilities for nuclear measurement data analysis
Loading...
Searching...
No Matches
FittingUtils Class Reference

Binned chi-squared photopeak fitting over a TH1. More...

#include <FittingUtils.hpp>

Public Member Functions

 FittingUtils (TH1 *working_hist, Float_t fit_range_low, Float_t fit_range_high, Bool_t use_flat_background=kFALSE, Bool_t use_step=kFALSE, Bool_t use_low_exp_tail=kFALSE, Bool_t use_low_lin_tail=kFALSE, Bool_t use_high_exp_tail=kFALSE)
 Build a fitter for one histogram and range.
 ~FittingUtils ()
 Releases the fit function this object owns.
void SetBackgroundModel (Bool_t use_flat_background)
 Choose the background shape.
void SetStep (Bool_t use_step=kTRUE)
 Offer the step shelf to the component search.
void SetLowExpTail (Bool_t use_low_exp_tail=kTRUE)
 Offer the low-energy exponential tail.
void SetLowLinTail (Bool_t use_low_lin_tail=kTRUE)
 Offer the low-energy linear tail.
void SetHighExpTail (Bool_t use_high_exp_tail=kTRUE)
 Offer the high-energy exponential tail.
void SetInteractive (Bool_t interactive=kTRUE)
 Open the GUI editor after the automated fit.
void SetTailRatioMax (Double_t ratio_max)
 Cap the tail decay constants during fitting.
void SetManualParameters (const std::vector< Double_t > &params)
 Supply explicit starting values for every parameter.
void SetManualParameter (Int_t index, Double_t value)
 Override one starting value.
void ClearManualParameters ()
 Discard manual starting values and return to automatic guesses.
TF1 * GetFitFunction ()
 The fit function, for inspection or manual adjustment.
void SetFitFunction (TF1 *func)
 Substitute a fit function of your own.
void PlotFitSinglePeak (const TString input_name, const TString peak_name, const TString label="")
 Draw and save the single-peak fit with its residual panel.
void PlotFitDoublePeak (const TString input_name, const TString peak_name, const TString label="")
 Draw and save the double-peak fit with its residual panel.
void PlotFitTriplePeak (const TString input_name, const TString peak_name, const TString label="")
 Draw and save the triple-peak fit with its residual panel.
FitResult FitSinglePeak (const TString input_name, const TString peak_name)
 Fit one peak, pruning components that do not earn their place.
FitResult FitDoublePeak (const TString input_name, const TString peak_name, Double_t mu1_init, Double_t mu2_init)
 Fit two peaks from centroid guesses.
FitResult FitDoublePeak (const TString input_name, const TString peak_name, const PeakFitResult &constrained_peak, Double_t mu2_init)
 Fit two peaks with the first constrained by an earlier fit.
FitResult FitTriplePeak (const TString input_name, const TString peak_name, const FitResult &constrained_peaks, Double_t mu3_init)
 Fit three peaks with the first two constrained by an earlier fit.

Detailed Description

Binned chi-squared photopeak fitting over a TH1.

Construct with the histogram, the fit range, and which optional components the model should offer, then call one of the Fit* methods. Component selection is not final: the fitter tests the low-side components as a group and prunes those that do not improve the reduced chi-squared, and tests the high-energy tail separately.

Note
Does not take ownership of the histogram passed to the constructor, but does own the TF1 it builds. See GetFitFunction() and SetFitFunction() for the ownership caveat when substituting your own.

Definition at line 242 of file FittingUtils.hpp.

Constructor & Destructor Documentation

◆ FittingUtils()

FittingUtils::FittingUtils ( TH1 * working_hist,
Float_t fit_range_low,
Float_t fit_range_high,
Bool_t use_flat_background = kFALSE,
Bool_t use_step = kFALSE,
Bool_t use_low_exp_tail = kFALSE,
Bool_t use_low_lin_tail = kFALSE,
Bool_t use_high_exp_tail = kFALSE )

Build a fitter for one histogram and range.

Parameters
working_histHistogram to fit. Borrowed, not owned; it must outlive this object.
fit_range_lowLower fit bound, in the histogram's x units.
fit_range_highUpper fit bound, in the histogram's x units.
use_flat_backgroundkTRUE for a constant background, kFALSE (default) for a linear one.
use_stepEnable the step shelf.
use_low_exp_tailEnable the low-energy exponential tail.
use_low_lin_tailEnable the low-energy linear tail.
use_high_exp_tailEnable the high-energy exponential tail.

Definition at line 331 of file FittingUtils.cpp.

◆ ~FittingUtils()

FittingUtils::~FittingUtils ( )

Releases the fit function this object owns.

Definition at line 453 of file FittingUtils.cpp.

Member Function Documentation

◆ ClearManualParameters()

void FittingUtils::ClearManualParameters ( )
inline

Discard manual starting values and return to automatic guesses.

Definition at line 356 of file FittingUtils.hpp.

◆ FitDoublePeak() [1/2]

FitResult FittingUtils::FitDoublePeak ( const TString input_name,
const TString peak_name,
const PeakFitResult & constrained_peak,
Double_t mu2_init )

Fit two peaks with the first constrained by an earlier fit.

Useful when one peak is well measured in isolation and the other is not: the known shape anchors the fit instead of floating freely.

Parameters
input_nameInput identifier.
peak_namePeak identifier.
constrained_peakPreviously fitted peak supplying the constraint.
mu2_initStarting centroid for the free peak.
Returns
The fitted result, with peaks sorted by centroid.

Definition at line 1765 of file FittingUtils.cpp.

◆ FitDoublePeak() [2/2]

FitResult FittingUtils::FitDoublePeak ( const TString input_name,
const TString peak_name,
Double_t mu1_init,
Double_t mu2_init )

Fit two peaks from centroid guesses.

Parameters
input_nameInput identifier.
peak_namePeak identifier.
mu1_initStarting centroid for the first peak.
mu2_initStarting centroid for the second.
Returns
The fitted result, with peaks sorted by centroid.

Definition at line 1222 of file FittingUtils.cpp.

◆ FitSinglePeak()

FitResult FittingUtils::FitSinglePeak ( const TString input_name,
const TString peak_name )

Fit one peak, pruning components that do not earn their place.

Parameters
input_nameInput identifier, used for saved parameters and output filenames.
peak_namePeak identifier, used the same way.
Returns
The fitted result; check FitResult::valid, since a failed fit returns -1 in every parameter.

Definition at line 850 of file FittingUtils.cpp.

◆ FitTriplePeak()

FitResult FittingUtils::FitTriplePeak ( const TString input_name,
const TString peak_name,
const FitResult & constrained_peaks,
Double_t mu3_init )

Fit three peaks with the first two constrained by an earlier fit.

Parameters
input_nameInput identifier.
peak_namePeak identifier.
constrained_peaksPrevious result supplying the two constraints.
mu3_initStarting centroid for the free peak.
Returns
The fitted result, with peaks sorted by centroid.

Definition at line 2167 of file FittingUtils.cpp.

◆ GetFitFunction()

TF1 * FittingUtils::GetFitFunction ( )
inline

The fit function, for inspection or manual adjustment.

Returns
The owned TF1, or null before a fit has built one.

Definition at line 363 of file FittingUtils.hpp.

◆ PlotFitDoublePeak()

void FittingUtils::PlotFitDoublePeak ( const TString input_name,
const TString peak_name,
const TString label = "" )

Draw and save the double-peak fit with its residual panel.

Parameters
input_nameInput identifier, used in the output filename.
peak_namePeak identifier, used in the output filename.
labelOptional annotation drawn on the plot.

Definition at line 732 of file FittingUtils.cpp.

Referenced by FitDoublePeak(), and FitDoublePeak().

◆ PlotFitSinglePeak()

void FittingUtils::PlotFitSinglePeak ( const TString input_name,
const TString peak_name,
const TString label = "" )

Draw and save the single-peak fit with its residual panel.

Parameters
input_nameInput identifier, used in the output filename.
peak_namePeak identifier, used in the output filename.
labelOptional annotation drawn on the plot.

Definition at line 616 of file FittingUtils.cpp.

Referenced by FitSinglePeak().

◆ PlotFitTriplePeak()

void FittingUtils::PlotFitTriplePeak ( const TString input_name,
const TString peak_name,
const TString label = "" )

Draw and save the triple-peak fit with its residual panel.

Parameters
input_nameInput identifier, used in the output filename.
peak_namePeak identifier, used in the output filename.
labelOptional annotation drawn on the plot.

Definition at line 778 of file FittingUtils.cpp.

Referenced by FitTriplePeak().

◆ SetBackgroundModel()

void FittingUtils::SetBackgroundModel ( Bool_t use_flat_background)
inline

Choose the background shape.

Parameters
use_flat_backgroundkTRUE for constant, kFALSE for linear.

Definition at line 298 of file FittingUtils.hpp.

◆ SetFitFunction()

void FittingUtils::SetFitFunction ( TF1 * func)
inline

Substitute a fit function of your own.

Parameters
funcReplacement function.
Warning
Overwrites the pointer without deleting the previous function, so the old one leaks unless you retrieved and freed it first. The replacement is destroyed with this object.

Definition at line 371 of file FittingUtils.hpp.

◆ SetHighExpTail()

void FittingUtils::SetHighExpTail ( Bool_t use_high_exp_tail = kTRUE)
inline

Offer the high-energy exponential tail.

Parameters
use_high_exp_tailkTRUE to enable.

Definition at line 316 of file FittingUtils.hpp.

◆ SetInteractive()

void FittingUtils::SetInteractive ( Bool_t interactive = kTRUE)
inline

Open the GUI editor after the automated fit.

On the first run the editor opens once the automated fit finishes, and the accepted parameters and range are written to <plots_base>/fits/<peak_name>_<input_name>.fits. On later runs that file is loaded and the editor is skipped, so the manual step happens once. Delete the file to redo it.

Parameters
interactivekTRUE to enable.
Note
Re-running the macro after an interactive session is worthwhile: the saved values are much better starting points and often give a lower chi-squared on the second pass.

Definition at line 334 of file FittingUtils.hpp.

◆ SetLowExpTail()

void FittingUtils::SetLowExpTail ( Bool_t use_low_exp_tail = kTRUE)
inline

Offer the low-energy exponential tail.

Parameters
use_low_exp_tailkTRUE to enable.

Definition at line 306 of file FittingUtils.hpp.

◆ SetLowLinTail()

void FittingUtils::SetLowLinTail ( Bool_t use_low_lin_tail = kTRUE)
inline

Offer the low-energy linear tail.

Parameters
use_low_lin_tailkTRUE to enable.

Definition at line 311 of file FittingUtils.hpp.

◆ SetManualParameter()

void FittingUtils::SetManualParameter ( Int_t index,
Double_t value )

Override one starting value.

Parameters
indexParameter index in the active model.
valueInitial value.

Definition at line 517 of file FittingUtils.cpp.

◆ SetManualParameters()

void FittingUtils::SetManualParameters ( const std::vector< Double_t > & params)

Supply explicit starting values for every parameter.

Parameters
paramsInitial values, in the parameter order documented on the matching FittingFunctions model. Switches the fitter off its automatic initial-guess path.

Definition at line 494 of file FittingUtils.cpp.

◆ SetStep()

void FittingUtils::SetStep ( Bool_t use_step = kTRUE)
inline

Offer the step shelf to the component search.

Parameters
use_stepkTRUE to enable.

Definition at line 303 of file FittingUtils.hpp.

◆ SetTailRatioMax()

void FittingUtils::SetTailRatioMax ( Double_t ratio_max)
inline

Cap the tail decay constants during fitting.

Parameters
ratio_maxUpper bound on any tail ratio, in units of sigma. Defaults to 100.

Definition at line 340 of file FittingUtils.hpp.


The documentation for this class was generated from the following files: