Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Smoothing.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_spectrum
3/// \notebook
4/// Example to illustrate smoothing using Markov algorithm (class TSpectrum).
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Miroslav Morhac
10
11void Smoothing()
12{
13 Int_t i;
14 const Int_t nbins = 1024;
15 Double_t xmin = 0;
16 Double_t xmax = nbins;
17 Double_t source[nbins];
18 gROOT->ForceStyle();
19
20 TString dir = gROOT->GetTutorialDir();
21 TString file = dir + "/legacy/spectrum/TSpectrum.root";
22 TFile *f = new TFile(file.Data());
23 TH1F *h = (TH1F *)f->Get("back1");
24 h->SetTitle("Smoothed spectrum for m=3");
25
26 for (i = 0; i < nbins; i++)
27 source[i] = h->GetBinContent(i + 1);
28 h->SetAxisRange(1, 1024);
29 h->Draw("L");
30
31 TSpectrum *s = new TSpectrum();
32
33 TH1F *smooth = new TH1F("smooth", "smooth", nbins, 0., nbins);
34 smooth->SetLineColor(kRed);
35
36 s->SmoothMarkov(source, 1024, 3); // 3, 7, 10
37 for (i = 0; i < nbins; i++)
38 smooth->SetBinContent(i + 1, source[i]);
39 smooth->Draw("L SAME");
40}
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
float xmin
float xmax
#define gROOT
Definition TROOT.h:406
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:42
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:634
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6734
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3055
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition TH1.cxx:9242
Advanced Spectra Processing.
Definition TSpectrum.h:18
const char * SmoothMarkov(Double_t *source, Int_t ssize, Int_t averWindow)
One-dimensional markov spectrum smoothing function.
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376