ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
testSmooth.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// Histogram smoothing.
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Rene Brun
9 
10 int ipad = 1;
11 TCanvas * c1 = 0;
12 
13 void smooth_hist(const char * fname, double xmin, double xmax, int n1, int n2) {
14 
15  std::cout << "smoothing a " << fname << " histogram" << std::endl;
16 
17  TH1D * h1 = new TH1D("h1","h1",100,xmin,xmax);
18  TH1D * h2 = new TH1D("h2","h2",100,xmin,xmax);
19  h1->FillRandom(fname,n1);
20 
21  TH1D * h1_s = new TH1D(*h1);
22  h1_s->SetName("h1_s");
23  h1_s->Smooth();
24 
25  h2->FillRandom(fname,n2);
26 
27  double p1 = h1->Chi2Test(h2,"");
28  double p2 = h1_s->Chi2Test(h2,"UU");
29  if (p2 < p1) Error("testSmooth","TH1::Smooth is not working correctly - a worst chi2 is obtained");
30 
31  std::cout << " chi2 test non-smoothed histo " << p1 << std::endl;
32  std::cout << " chi2 test smoothed histo " << p2 << std::endl;
33 
34  double a1 = h1->AndersonDarlingTest(h2);
35  double a2 = h1_s->AndersonDarlingTest(h2);
36 
37  std::cout << " AD test non-smoothed histo " << a1 << std::endl;
38  std::cout << " AD test smoothed histo " << a2 << std::endl;
39 
40  double k1 = h1->KolmogorovTest(h2);
41  double k2 = h1_s->KolmogorovTest(h2);
42 
43  std::cout << " KS test non-smoothed histo " << k1 << std::endl;
44  std::cout << " KS test smoothed histo " << k2 << std::endl;
45 
46  c1->cd(ipad++);
47  h1->Draw("E");
48  h1_s->SetLineColor(kRed);
49  h1_s->Draw("same");
50  h2->Scale(double(n1)/n2);
51  h2->SetLineColor(kGreen);
52  h2->Draw("same");
53 }
54 
55 void testSmooth(int n1 = 1000, int n2 = 1000000) {
56 
57  TH1::AddDirectory(false);
58 
59  c1 = new TCanvas();
60  c1->Divide(1,3);
61 
62 
63  smooth_hist("gaus",-5,5,n1,n2);
64  smooth_hist("landau",-5,15,n1,n2);
65  smooth_hist("expo",-5,0,n1,n2);
66 
67 }
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition: TH1.cxx:6174
Definition: Rtypes.h:61
virtual Double_t Chi2Test(const TH1 *h2, Option_t *option="UU", Double_t *res=0) const
chi^{2} test for comparing weighted and unweighted histograms
Definition: TH1.cxx:1850
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual void Smooth(Int_t ntimes=1, Option_t *option="")
Smooth bin contents of this histogram.
Definition: TH1.cxx:6440
Definition: Rtypes.h:61
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition: TH1.cxx:1231
void Error(const char *location, const char *msgfmt,...)
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
virtual Double_t AndersonDarlingTest(const TH1 *h2, Option_t *option="") const
Statistical test of compatibility in shape between this histogram and h2, using the Anderson-Darling ...
Definition: TH1.cxx:7497
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3330
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const
Statistical test of compatibility in shape between this histogram and h2, using Kolmogorov test...
Definition: TH1.cxx:7610
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
virtual void SetName(const char *name)
Change the name of this histogram.
Definition: TH1.cxx:8288
The Canvas class.
Definition: TCanvas.h:48
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1073