// root.cern.ch/root/htmldoc/guides/spectrum/Spectrum.html#dimensional-spectra // root.cern.ch/doc/master/Background__width_8C.html // See: M.Morhac et al., Nucl. Instr. Meth. A 401, 113 (1997) // Example to illustrate the influence of the clipping window width on the // // Authors: Miroslav Morhac, Olivier Couet void Background_width () { 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->GetXaxis()->SetRange (1, nbins); hdata->SetTitle ("Influence of clipping window width on the estimated background"); hdata->SetLineColor (kBlack); hdata->Draw ("L"); TSpectrum *Analyser1dim = new TSpectrum (); /** Case for numberIterations = 4 (numberIterations = max width of clipping window) **/ for (i = 0; i < nbins; i++) source[i] = hdata->GetBinContent (i+1); // Estimate the Background Analyser1dim->Background ( source, nbins, 4, 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 */ TH1F* hbkgnd1 = new TH1F ("hbkgnd1", "", nbins, xmin, xmax); for (i = 0; i < nbins; i++) hbkgnd1->SetBinContent (i+1, source[i]); hbkgnd1->SetLineColor (kRed); hbkgnd1->Draw ("SAME L"); /** Case for numberIterations = 6 (numberIterations = max width of clipping window) **/ for (i = 0; i < nbins; i++) source[i] = hdata->GetBinContent (i+1); Analyser1dim->Background ( source, nbins, 6, TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder2, kFALSE, TSpectrum::kBackSmoothing3, kFALSE); TH1F* hbkgnd2 = new TH1F ("hbkgnd2", "", nbins, xmin, xmax); for (i = 0; i < nbins; i++) hbkgnd2->SetBinContent (i+1, source[i]); hbkgnd2->SetLineColor (kGreen); hbkgnd2->Draw( "SAME L"); /** Case for numberIterations = 8 (numberIterations = max width of clipping window) **/ for (i = 0; i < nbins; i++) source[i] = hdata->GetBinContent (i+1); Analyser1dim->Background ( source, nbins, 8, TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder2, kFALSE, TSpectrum::kBackSmoothing3, kFALSE); TH1F* hbkgnd3 = new TH1F ("hbkgnd3", "", nbins, xmin, xmax); for (i = 0; i < nbins; i++) hbkgnd3->SetBinContent (i+1, source[i]); hbkgnd3->SetLineColor (kBlue); hbkgnd3->Draw ("SAME L"); gStyle->SetOptStat (0); TLegend* legend = new TLegend (0.1, 0.7, 0.48, 0.9); legend->AddEntry (hdata , "Data" , "l"); legend->AddEntry (hbkgnd1, "Width = 4", "l"); legend->AddEntry (hbkgnd2, "Width = 6", "l"); legend->AddEntry (hbkgnd3, "Width = 8", "l"); legend->Draw(); }