ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
normalDist.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_math
3 /// Tutorial illustrating the new statistical distributions functions (pdf, cdf and quantile)
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Anna Kreshuk
9 
10 #ifndef __CINT__
11 #include "Math/DistFunc.h"
12 #include "TF1.h"
13 #include "TCanvas.h"
14 #include "TSystem.h"
15 #include "TLegend.h"
16 #include "TAxis.h"
17 #endif
18 
19 void normalDist() {
20 
21  TF1 *pdfunc = new TF1("pdf","ROOT::Math::normal_pdf(x, [0],[1])",-5,5);
22  TF1 *cdfunc = new TF1("cdf","ROOT::Math::normal_cdf(x, [0],[1])",-5,5);
23  TF1 *ccdfunc = new TF1("cdf_c","ROOT::Math::normal_cdf_c(x, [0])",-5,5);
24  TF1 *qfunc = new TF1("quantile","ROOT::Math::normal_quantile(x, [0])",0,1);
25  TF1 *cqfunc = new TF1("quantile_c","ROOT::Math::normal_quantile_c(x, [0])",0,1);
26 
27  pdfunc->SetParameters(1.0,0.0); // set sigma to 1 and mean to zero
28  pdfunc->SetTitle("");
29  pdfunc->SetLineColor(kBlue);
30 
31  pdfunc->GetXaxis()->SetLabelSize(0.06);
32  pdfunc->GetXaxis()->SetTitle("x");
33  pdfunc->GetXaxis()->SetTitleSize(0.07);
34  pdfunc->GetXaxis()->SetTitleOffset(0.55);
35  pdfunc->GetYaxis()->SetLabelSize(0.06);
36 
37  cdfunc->SetParameters(1.0,0.0); // set sigma to 1 and mean to zero
38  cdfunc->SetTitle("");
39  cdfunc->SetLineColor(kRed);
40 
41  cdfunc->GetXaxis()->SetLabelSize(0.06);
42  cdfunc->GetXaxis()->SetTitle("x");
43  cdfunc->GetXaxis()->SetTitleSize(0.07);
44  cdfunc->GetXaxis()->SetTitleOffset(0.55);
45 
46  cdfunc->GetYaxis()->SetLabelSize(0.06);
47  cdfunc->GetYaxis()->SetTitle("p");
48  cdfunc->GetYaxis()->SetTitleSize(0.07);
49  cdfunc->GetYaxis()->SetTitleOffset(0.55);
50 
51  ccdfunc->SetParameters(1.0,0.0); // set sigma to 1 and mean to zero
52  ccdfunc->SetTitle("");
53  ccdfunc->SetLineColor(kGreen);
54 
55  qfunc->SetParameter(0, 1.0); // set sigma to 1
56  qfunc->SetTitle("");
57  qfunc->SetLineColor(kRed);
58  qfunc->SetNpx(1000); // to get more precision for p close to 0 or 1
59 
60  qfunc->GetXaxis()->SetLabelSize(0.06);
61  qfunc->GetXaxis()->SetTitle("p");
62  qfunc->GetYaxis()->SetLabelSize(0.06);
63  qfunc->GetXaxis()->SetTitleSize(0.07);
64  qfunc->GetXaxis()->SetTitleOffset(0.55);
65  qfunc->GetYaxis()->SetTitle("x");
66  qfunc->GetYaxis()->SetTitleSize(0.07);
67  qfunc->GetYaxis()->SetTitleOffset(0.55);
68 
69  cqfunc->SetParameter(0, 1.0); // set sigma to 1
70  cqfunc->SetTitle("");
71  cqfunc->SetLineColor(kGreen);
72  cqfunc->SetNpx(1000);
73 
74  TCanvas * c1 = new TCanvas("c1","Normal Distributions",100,10,600,800);
75 
76  c1->Divide(1,3);
77  c1->cd(1);
78 
79  pdfunc->Draw();
80  TLegend *legend1 = new TLegend(0.583893,0.601973,0.885221,0.854151);
81  legend1->AddEntry(pdfunc,"normal_pdf","l");
82  legend1->Draw();
83 
84  c1->cd(2);
85  cdfunc->Draw();
86  ccdfunc->Draw("same");
87  TLegend *legend2 = new TLegend(0.585605,0.462794,0.886933,0.710837);
88  legend2->AddEntry(cdfunc,"normal_cdf","l");
89  legend2->AddEntry(ccdfunc,"normal_cdf_c","l");
90  legend2->Draw();
91 
92  c1->cd(3);
93  qfunc->Draw();
94  cqfunc->Draw("same");
95  TLegend *legend3 = new TLegend(0.315094,0.633668,0.695179,0.881711);
96  legend3->AddEntry(qfunc,"normal_quantile","l");
97  legend3->AddEntry(cqfunc,"normal_quantile_c","l");
98  legend3->Draw();
99 }
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:245
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:432
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3116
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
Definition: Rtypes.h:61
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:373
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1052
Definition: Rtypes.h:61
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:187
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:255
TAxis * GetYaxis() const
Get y axis of the function.
Definition: TF1.cxx:2083
virtual void SetTitle(const char *title="")
Set function title if title has the form "fffffff;xxxx;yyyy", it is assumed that the function title i...
Definition: TF1.cxx:3227
The Canvas class.
Definition: TCanvas.h:48
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:280
TAxis * GetXaxis() const
Get x axis of the function.
Definition: TF1.cxx:2072
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
1-Dim function class
Definition: TF1.h:149
Definition: Rtypes.h:61
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:424
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152