// root.cern.ch/root/htmldoc/guides/spectrum/Spectrum.html#dimensional-spectra // root.cern.ch/doc/master/Background__order_8C.html // Example to illustrate the influence of the clipping filter difference order // on the estimated background. // // Authors Miroslav Morhac, Olivier Couet void Background_order () { Int_t i; Int_t nbins = 4096; Double_t xmin = 0; Double_t xmax = 4096; Double_t* source = new Double_t [nbins]; gROOT->ForceStyle (); TFile* f = new TFile ("TSpectrum.root"); TH1F* hdata = (TH1F*) f->Get("back2"); hdata->SetTitle ("Influence of clipping filter difference order on the estimated background"); hdata->SetAxisRange (1220, 1460); hdata->SetMaximum (3400); hdata->Draw ("L"); TSpectrum* Analyser1dim = new TSpectrum (); for (i = 0; i < nbins; i++) source[i] = hdata->GetBinContent (i+1); /*** Testing for filter order = 2 ***/ Analyser1dim->Background ( source, nbins, 40, TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder2, kFALSE, TSpectrum::kBackSmoothing3, kFALSE ); /* const char* TSpectrum::Background ( Double_t* spectrum, pointer to the array 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* horder2 = new TH1F ("horder2", "", nbins, xmin, xmax); for (i = 0; i < nbins; i++) horder2->SetBinContent (i+1, source[i]); horder2->SetLineColor(kRed); horder2->Draw("SAME L"); /*** Testing for filter order = 4 ***/ for (i = 0; i < nbins; i++) source[i] = hdata->GetBinContent (i+1); Analyser1dim->Background ( source, nbins, 40, TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder4, kFALSE, TSpectrum::kBackSmoothing3, kFALSE ); TH1F* horder4 = new TH1F ("horder4", "", nbins, xmin, xmax); for (i = 0; i < nbins; i++) horder4->SetBinContent (i+1, source[i]); horder4->SetLineColor (kBlue); horder4->Draw ("SAME L"); /*** Testing for filter order = 6 ***/ for (i = 0; i < nbins; i++) source[i] = hdata->GetBinContent (i+1); Analyser1dim->Background ( source, nbins, 40, TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder6, kFALSE, TSpectrum::kBackSmoothing3, kFALSE ); TH1F* horder6 = new TH1F ("horder6", "", nbins, xmin, xmax); for (i = 0; i < nbins; i++) horder6->SetBinContent (i+1, source[i]); horder6->SetLineColor (kGreen); horder6->Draw ("SAME L"); /*** Testing for filter order = 8 ***/ for (i = 0; i < nbins; i++) source[i] = hdata->GetBinContent (i+1); Analyser1dim->Background ( source, nbins, 40, TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder8, kFALSE, TSpectrum::kBackSmoothing3, kFALSE ); TH1F* horder8 = new TH1F ("horder8", "", nbins, xmin, xmax); for (i = 0; i < nbins; i++) horder8->SetBinContent (i+1, source[i]); horder8->SetLineColor (kMagenta); horder8->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 (horder2, "Order = 2", "l"); legend->AddEntry (horder4, "Order = 4", "l"); legend->AddEntry (horder6, "Order = 6", "l"); legend->AddEntry (horder8, "Order = 8", "l"); legend->Draw(); }