// root.cern.ch/root/htmldoc/guides/spectrum/Spectrum.html#dimensional-spectra
// root.cern.ch/doc/master/Background__decr_8C.html
// "The function allows to separate useless spectrum information
// (continuous background) from peaks, based on Sensitive Nonlinear Iterative
// Peak (SNIP) Clipping Algorithm. In fact, it represents the second order
// difference filter (-1,2,-1)."
// See: M.Morhac et al., Nucl. Instr. Meth. A 401, 113 (1997)
// Example to illustrate the background estimator (class TSpectrum).
//
// Authors: Miroslav Morhac, Olivier Couet
void Background_decr ()
{
Int_t i;
Int_t nbins = 1024;
Double_t xmin = 0;
Double_t xmax = nbins;
Double_t* source = new Double_t [nbins];
gROOT->ForceStyle();
TFile* f = new TFile ("TSpectrum.root");
TH1F* hdata = (TH1F*) f->Get ("back1");
hdata->SetTitle ("Estimation of background with decreasing window");
hdata->GetXaxis()->SetRange (1, nbins);
hdata->Draw ("L");
TSpectrum* Analyser1dim = new TSpectrum ();
for (i = 0; i < nbins; i++) source[i] = hdata->GetBinContent (i+1);
// Estimate the Background
Analyser1dim->Background (
source, nbins, 6, TSpectrum::kBackDecreasingWindow,
TSpectrum::kBackOrder2, kFALSE,
TSpectrum::kBackSmoothing3, kFALSE);
/*
const char* TSpectrum::Background (
Double_t* spectrum, pointer to the vector of source spectrum
Int_t ssize, length of the spectrum vector
Int_t numberIterations, maximal width of clipping window,
Int_t direction, direction of change of clipping window.
Possible values: kBackIncreasingWindow, kBackDecreasingWindow
Int_t filterOrder, order of clipping filter. Possible values:
kBackOrder2, kBackOrder4, kBackOrder6, kBackOrder8
bool smoothing, logical variable whether the smoothing operation in the
estimation of background will be included. (0/1)
Int_t smoothWindow, width of smoothing window. Possible values:
kBackSmoothing3, kBackSmoothing5, ..., kBackSmoothing15
bool compton whether the estimation of Compton edge will be included. (0/1)
)
See: root.cern.ch/doc/v608/classTSpectrum.html#a7830480612d1ee301964e6c79319f444
*/
// Draw the estimated background
TH1F* hbkgnd = new TH1F ("hbkgnd", "", nbins, xmin, xmax);
for (i = 0; i < nbins; i++) hbkgnd->SetBinContent (i+1, source[i]);
hbkgnd->SetLineColor (kRed);
hbkgnd->Draw ("SAME L");
}