|
Analysis-Utilities 26.9.9
C++/ROOT utilities for nuclear measurement data analysis
|
Unbinned extended maximum-likelihood photopeak fitting on RooFit. More...
#include <RooFitUtils.hpp>
Public Member Functions | |
| RooFitUtils () | |
| Construct in simultaneous mode. | |
| RooFitUtils (const std::vector< Double_t > &events, Float_t fit_range_low, Float_t fit_range_high, Float_t display_bin_width_kev, 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) | |
| Construct in single-channel mode. | |
| ~RooFitUtils () | |
| Destroys every RooFit object this instance created. | |
| 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 | SetFitDebug (Bool_t fit_debug=kTRUE) |
| Un-suppress RooFit evaluation errors during a simultaneous fit. | |
| void | SetRefitAfterLoad (Bool_t refit=kTRUE) |
| Treat saved interactive parameters as a seed, not as the answer. | |
| void | SetTailRatioMax (Double_t ratio_max) |
| Cap the dimensionless tail decay ratio tau / sigma. | |
| void | SetManualParameters (const std::vector< Double_t > ¶ms) |
| 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. | |
| 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, Bool_t link_sigma=kFALSE) |
| 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. | |
| void | AddChannel (const TString &name, const std::vector< Double_t > &events, Float_t fit_range_low, Float_t fit_range_high, Float_t display_bin_width_kev, Int_t num_peaks, const std::vector< Double_t > &mu_inits, 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, const std::vector< Bool_t > &mu_fixed=std::vector< Bool_t >(), Bool_t bkg_yield_fixed=kFALSE, Bool_t bkg_slope_fixed=kFALSE, Bool_t lock_shape_after_seed=kFALSE, const std::vector< Bool_t > &use_step_per_peak=std::vector< Bool_t >(), const std::vector< Bool_t > &shape_lock_per_peak=std::vector< Bool_t >()) |
| Register one spectrum as a channel of the simultaneous fit. | |
| void | LinkParameter (const TString &target, const TString &source) |
| Tie one parameter to another, fitting them as one degree of freedom. | |
| void | ConstrainPeakSeparation (const TString &channel, Int_t peak_hi, Int_t peak_lo, Double_t delta, Double_t sigma) |
| Constrain the spacing between two peaks to a known value. | |
| void | LinkPeakShape (const TString &target_channel, Int_t target_peak, const TString &source_channel, Int_t source_peak) |
| Tie a peak's whole shape to another peak's. | |
| void | SeedChannel (const TString &channel_name, const FitResult &result) |
| Use a prior single-channel fit as starting values for a channel. | |
| std::vector< FitResult > | FitSimultaneous (const TString &input_name, const TString &base_label) |
| Run one joint extended-likelihood fit across every channel. | |
| void | DumpChannelCSV (const TString &channel, const TString &csv_path, Int_t npts=1000) |
| Export a converged channel to CSV for plotting elsewhere. | |
Static Public Member Functions | |
| static std::vector< Double_t > | LoadEventsFromTree (TTree *tree, const TString &branch_name) |
| Read a branch into the event vector the constructor expects. | |
| static TH1F * | BuildDisplayHistogramFrom (const std::vector< Double_t > &events, Float_t fit_range_low, Float_t fit_range_high, Float_t display_bin_width_kev) |
| Bin events into a display histogram. | |
| static void | RefillDisplayHistogram (TH1 *hist, const std::vector< Double_t > &events, Float_t fit_range_low, Float_t fit_range_high, Float_t display_bin_width_kev) |
| Rebin an existing display histogram in place. | |
Static Public Attributes | |
| static constexpr const char * | kFitRangeName = "fitrange" |
| Name of the RooFit range this class fits over. | |
Unbinned extended maximum-likelihood photopeak fitting on RooFit.
The counterpart to FittingUtils, which fits the same model by binned chi-squared. Both take the same constructor arguments, expose the same Set* component flags, and return the same FitResult.
Two modes, selected by which constructor is used:
Input is an event-level std::vector<Double_t>. The bin width is used only for display and for the post-hoc reduced chi-squared that drives component pruning — the fit itself never bins.
Definition at line 280 of file RooFitUtils.hpp.
| RooFitUtils::RooFitUtils | ( | ) |
Construct in simultaneous mode.
Register spectra with AddChannel(), then call FitSimultaneous(). The single-channel Fit* methods do not apply to an instance built this way.
Definition at line 176 of file RooFitUtils.cpp.
| RooFitUtils::RooFitUtils | ( | const std::vector< Double_t > & | events, |
| Float_t | fit_range_low, | ||
| Float_t | fit_range_high, | ||
| Float_t | display_bin_width_kev, | ||
| 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 ) |
Construct in single-channel mode.
| events | Event-level observable values. Copied. |
| fit_range_low | Lower fit bound. |
| fit_range_high | Upper fit bound. |
| display_bin_width_kev | Bin width for the display histogram and the post-hoc reduced chi-squared. Does not affect the likelihood, which is unbinned. |
| use_flat_background | kTRUE for a constant background, kFALSE (default) for a linear one. |
| use_step | Enable the step shelf. |
| use_low_exp_tail | Enable the low-energy exponential tail. |
| use_low_lin_tail | Enable the low-energy linear tail. |
| use_high_exp_tail | Enable the high-energy exponential tail. |
Definition at line 181 of file RooFitUtils.cpp.
| RooFitUtils::~RooFitUtils | ( | ) |
Destroys every RooFit object this instance created.
Definition at line 218 of file RooFitUtils.cpp.
| void RooFitUtils::AddChannel | ( | const TString & | name, |
| const std::vector< Double_t > & | events, | ||
| Float_t | fit_range_low, | ||
| Float_t | fit_range_high, | ||
| Float_t | display_bin_width_kev, | ||
| Int_t | num_peaks, | ||
| const std::vector< Double_t > & | mu_inits, | ||
| 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, | ||
| const std::vector< Bool_t > & | mu_fixed = std::vector<Bool_t>(), | ||
| Bool_t | bkg_yield_fixed = kFALSE, | ||
| Bool_t | bkg_slope_fixed = kFALSE, | ||
| Bool_t | lock_shape_after_seed = kFALSE, | ||
| const std::vector< Bool_t > & | use_step_per_peak = std::vector<Bool_t>(), | ||
| const std::vector< Bool_t > & | shape_lock_per_peak = std::vector<Bool_t>() ) |
Register one spectrum as a channel of the simultaneous fit.
| name | Channel name, unique within the fit; used to address it from the linking methods. |
| events | Event-level observable values. Copied. |
| fit_range_low | Lower fit bound for this channel. |
| fit_range_high | Upper fit bound for this channel. |
| display_bin_width_kev | Display bin width; does not affect the likelihood. |
| num_peaks | Peaks in this channel. |
| mu_inits | Starting centroid per peak; num_peaks entries. |
| use_flat_background | kTRUE for constant, kFALSE for linear. |
| use_step | Enable the step shelf for this channel. |
| use_low_exp_tail | Enable the low-energy exponential tail. |
| use_low_lin_tail | Enable the low-energy linear tail. |
| use_high_exp_tail | Enable the high-energy exponential tail. |
| mu_fixed | Per-peak; where kTRUE, that centroid is held at its mu_inits value instead of floating. Empty means all float. |
| bkg_yield_fixed | Hold this channel's background yield constant. |
| bkg_slope_fixed | Hold this channel's background slope constant. |
| lock_shape_after_seed | After seeding, fix sigma, the Gaussian yield and every tail and step shape parameter, so only peak positions and normalisations float. |
| use_step_per_peak | Per-peak override of use_step, for a step on some peaks but not others sharing a channel. Empty means use_step applies to all. |
| shape_lock_per_peak | Per-peak refinement of lock_shape_after_seed: entry i controls whether peak i's shape locks. Empty locks every peak. |
Definition at line 2039 of file RooFitUtils.cpp.
|
static |
Bin events into a display histogram.
| events | Event-level values. |
| fit_range_low | Lower bound. |
| fit_range_high | Upper bound. |
| display_bin_width_kev | Bin width. |
Definition at line 107 of file RooFitUtils.cpp.
Referenced by AddChannel(), and FitSimultaneous().
|
inline |
Discard manual starting values and return to automatic guesses.
Definition at line 587 of file RooFitUtils.hpp.
| void RooFitUtils::ConstrainPeakSeparation | ( | const TString & | channel, |
| Int_t | peak_hi, | ||
| Int_t | peak_lo, | ||
| Double_t | delta, | ||
| Double_t | sigma ) |
Constrain the spacing between two peaks to a known value.
Imposes a Gaussian penalty on mu[peak_hi] - mu[peak_lo].
| channel | Channel holding both peaks. |
| peak_hi | Index of the upper peak. |
| peak_lo | Index of the lower peak. |
| delta | Known separation, in the observable's units. |
| sigma | Uncertainty on delta; set it to the literature error, and keep it positive. |
Definition at line 1922 of file RooFitUtils.cpp.
| void RooFitUtils::DumpChannelCSV | ( | const TString & | channel, |
| const TString & | csv_path, | ||
| Int_t | npts = 1000 ) |
Export a converged channel to CSV for plotting elsewhere.
Writes two tidy files that pandas.read_csv reads directly, using the same expectedEvents * getVal * bin_width convention as the plotted curve:
npts samples: energy_keV, fit_total, fit_background, in counts per bin.| channel | Channel to export. |
| csv_path | Output path base; a trailing .csv is stripped before the two suffixes are appended. |
| npts | Samples along the smooth overlay curve. |
Definition at line 2786 of file RooFitUtils.cpp.
| FitResult RooFitUtils::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.
| input_name | Input identifier. |
| peak_name | Peak identifier. |
| constrained_peak | Previously fitted peak supplying the constraint. |
| mu2_init | Starting centroid for the free peak. |
Definition at line 1625 of file RooFitUtils.cpp.
| FitResult RooFitUtils::FitDoublePeak | ( | const TString | input_name, |
| const TString | peak_name, | ||
| Double_t | mu1_init, | ||
| Double_t | mu2_init, | ||
| Bool_t | link_sigma = kFALSE ) |
Fit two peaks from centroid guesses.
| input_name | Input identifier. |
| peak_name | Peak identifier. |
| mu1_init | Starting centroid for the first peak. |
| mu2_init | Starting centroid for the second. |
| link_sigma | When kTRUE, ties both peaks to a single Gaussian width: the second peak's PDFs are rebuilt to reference the first's sigma and Sigma2 is frozen. Right for close, same-detector lines such as the Pb K-beta group, where a free second width would otherwise trade against the background. |
Definition at line 1390 of file RooFitUtils.cpp.
| std::vector< FitResult > RooFitUtils::FitSimultaneous | ( | const TString & | input_name, |
| const TString & | base_label ) |
Run one joint extended-likelihood fit across every channel.
Builds the RooSimultaneous, applies the links and separation constraints, and minimises. With SetInteractive() the simultaneous editor opens afterwards, and accepted parameters are saved and reloaded as for the single-channel editors.
| input_name | Input identifier, used for saved parameters and output filenames. |
| base_label | Base label for the per-channel outputs. |
Definition at line 2873 of file RooFitUtils.cpp.
| FitResult RooFitUtils::FitSinglePeak | ( | const TString | input_name, |
| const TString | peak_name ) |
Fit one peak, pruning components that do not earn their place.
Low-side components are enabled as a group and pruned individually; the high-energy tail is tested separately. A component is kept only if it improves the reduced chi-squared.
| input_name | Input identifier, used for saved parameters and output filenames. |
| peak_name | Peak identifier, used the same way. |
Definition at line 1268 of file RooFitUtils.cpp.
| FitResult RooFitUtils::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.
| input_name | Input identifier. |
| peak_name | Peak identifier. |
| constrained_peaks | Previous result supplying the two constraints. |
| mu3_init | Starting centroid for the free peak. |
Definition at line 1772 of file RooFitUtils.cpp.
| void RooFitUtils::LinkParameter | ( | const TString & | target, |
| const TString & | source ) |
Tie one parameter to another, fitting them as one degree of freedom.
| target | Parameter to tie, as "<channel>:<parameter>". |
| source | Parameter it follows, in the same form. |
Definition at line 2096 of file RooFitUtils.cpp.
Referenced by LinkPeakShape().
| void RooFitUtils::LinkPeakShape | ( | const TString & | target_channel, |
| Int_t | target_peak, | ||
| const TString & | source_channel, | ||
| Int_t | source_peak ) |
Tie a peak's whole shape to another peak's.
Links sigma and every tail and step shape parameter at once, leaving position and normalisation free.
| target_channel | Channel holding the peak to tie. |
| target_peak | Index of that peak. |
| source_channel | Channel holding the peak it follows. |
| source_peak | Index of that peak. |
Definition at line 2112 of file RooFitUtils.cpp.
|
static |
Read a branch into the event vector the constructor expects.
| tree | Tree to read. Must not be null. |
| branch_name | Branch holding one observable value per entry. |
Definition at line 78 of file RooFitUtils.cpp.
| void RooFitUtils::PlotFitDoublePeak | ( | const TString | input_name, |
| const TString | peak_name, | ||
| const TString | label = "" ) |
Draw and save the double-peak fit with its residual panel.
| input_name | Input identifier, used in the output filename. |
| peak_name | Peak identifier, used in the output filename. |
| label | Optional annotation drawn on the plot. |
Definition at line 1170 of file RooFitUtils.cpp.
Referenced by FitDoublePeak(), and FitDoublePeak().
| void RooFitUtils::PlotFitSinglePeak | ( | const TString | input_name, |
| const TString | peak_name, | ||
| const TString | label = "" ) |
Draw and save the single-peak fit with its residual panel.
| input_name | Input identifier, used in the output filename. |
| peak_name | Peak identifier, used in the output filename. |
| label | Optional annotation drawn on the plot. |
Definition at line 1124 of file RooFitUtils.cpp.
Referenced by FitSinglePeak().
| void RooFitUtils::PlotFitTriplePeak | ( | const TString | input_name, |
| const TString | peak_name, | ||
| const TString | label = "" ) |
Draw and save the triple-peak fit with its residual panel.
| input_name | Input identifier, used in the output filename. |
| peak_name | Peak identifier, used in the output filename. |
| label | Optional annotation drawn on the plot. |
Definition at line 1218 of file RooFitUtils.cpp.
Referenced by FitTriplePeak().
|
static |
Rebin an existing display histogram in place.
What the interactive editor uses when the range slider moves, so binning follows the zoom without reallocating.
| hist | Histogram to refill. Must not be null. |
| events | Event-level values. |
| fit_range_low | New lower bound. |
| fit_range_high | New upper bound. |
| display_bin_width_kev | Bin width. |
Definition at line 129 of file RooFitUtils.cpp.
| void RooFitUtils::SeedChannel | ( | const TString & | channel_name, |
| const FitResult & | result ) |
Use a prior single-channel fit as starting values for a channel.
| channel_name | Channel to seed. |
| result | Previous result supplying the starting values. |
Definition at line 2133 of file RooFitUtils.cpp.
|
inline |
Choose the background shape.
| use_flat_background | kTRUE for constant, kFALSE for linear. |
Definition at line 491 of file RooFitUtils.hpp.
|
inline |
Un-suppress RooFit evaluation errors during a simultaneous fit.
Also prints the seed NLL, so an invalid-NLL failure names the offending PDF instead of failing anonymously.
| fit_debug | kTRUE to enable. Off by default; set it before calling FitSimultaneous(). |
Definition at line 536 of file RooFitUtils.hpp.
|
inline |
Offer the high-energy exponential tail.
| use_high_exp_tail | kTRUE to enable. |
Definition at line 509 of file RooFitUtils.hpp.
|
inline |
Open the GUI editor after the automated fit.
Accepted parameters are saved to <plots_base>/fits/<peak_name>_<input_name>.roofits and reloaded on later runs, so the manual step happens once. Delete the file to redo it.
| interactive | kTRUE to enable. |
Definition at line 524 of file RooFitUtils.hpp.
|
inline |
Offer the low-energy exponential tail.
| use_low_exp_tail | kTRUE to enable. |
Definition at line 499 of file RooFitUtils.hpp.
|
inline |
Offer the low-energy linear tail.
| use_low_lin_tail | kTRUE to enable. |
Definition at line 504 of file RooFitUtils.hpp.
| void RooFitUtils::SetManualParameter | ( | Int_t | index, |
| Double_t | value ) |
Override one starting value.
| index | Parameter index in the active model. |
| value | Initial value. |
Definition at line 262 of file RooFitUtils.cpp.
| void RooFitUtils::SetManualParameters | ( | const std::vector< Double_t > & | params | ) |
Supply explicit starting values for every parameter.
| params | Initial values, in the model's parameter order. |
Definition at line 238 of file RooFitUtils.cpp.
|
inline |
Treat saved interactive parameters as a seed, not as the answer.
Interactive simultaneous fits have two historic modes. With a saved .simroofits file present, the parameters were loaded and adopted as the result, with no minimisation at all; without one, the GUI editor opened.
The first mode makes a re-run silently replay a previous session's answer: it still prints a chi-squared, redraws every plot and writes fresh output, while the fitted values cannot respond to anything upstream that has changed. Enabling this makes the saved parameters seed a real minimisation instead.
| refit | kTRUE to re-minimise after loading. |
Definition at line 556 of file RooFitUtils.hpp.
|
inline |
Offer the step shelf to the component search.
| use_step | kTRUE to enable. |
Definition at line 496 of file RooFitUtils.hpp.
|
inline |
Cap the dimensionless tail decay ratio tau / sigma.
Applies to both LowExpTailRatio and HighExpTailRatio.
| ratio_max | Upper bound, in units of sigma. |
Definition at line 573 of file RooFitUtils.hpp.
|
staticconstexpr |
Name of the RooFit range this class fits over.
Definition at line 417 of file RooFitUtils.hpp.
Referenced by FitDoublePeak(), FitDoublePeak(), FitSimultaneous(), FitSinglePeak(), and FitTriplePeak().