Logo ROOT   6.10/09
Reference Guide
tStudent.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_math
3 /// \notebook
4 /// Example macro describing the student t distribution
5 ///
6 /// ~~~{.cpp}
7 /// root[0]: .x tStudent.C
8 /// ~~~
9 ///
10 /// It draws the pdf, the cdf and then 10 quantiles of the t Student distribution
11 ///
12 /// \macro_image
13 /// \macro_code
14 ///
15 /// \author Magdalena Slawinska
16 
17 #include "TH1.h"
18 #include "TF1.h"
19 #include "TCanvas.h"
20 #include "TSystem.h"
21 #include "TLegend.h"
22 #include "TLegendEntry.h"
23 #include "Math/DistFunc.h"
24 
25 
26 void tStudent()
27 {
28 
29  /* gSystem->Load("libMathMore");*/
30 
31  // this is the way to force load of MathMore in Cling
33 
34  int n=100;
35  double a=-5.;
36  double b=5.;
37  //double r = 3;
38  TF1* pdf = new TF1("pdf", "ROOT::Math::tdistribution_pdf(x,3.0)", a,b);
39  TF1* cum = new TF1("cum", "ROOT::Math::tdistribution_cdf(x,3.0)", a,b);
40 
41  TH1D* quant = new TH1D("quant", "", 9, 0, 0.9);
42 
43  for(int i=1; i < 10; i++)
44  quant->Fill((i-0.5)/10.0, ROOT::Math::tdistribution_quantile((1.0*i)/10, 3.0 ) );
45 
46  double xx[10];
47  xx[0] = -1.5;
48  for(int i=1; i<9; i++)
49  xx[i]= quant->GetBinContent(i);
50  xx[9] = 1.5;
51  TH1D* pdfq[10];
52  //int nbin = n/10.0;
53  for(int i=0; i < 9; i++) {
54  int nbin = n * (xx[i+1]-xx[i])/3.0 + 1.0;
55  TString name = "pdf";
56  name += i;
57  pdfq[i]= new TH1D(name, "", nbin,xx[i],xx[i+1] );
58  for(int j=1; j<nbin; j++) {
59  double x= j*(xx[i+1]-xx[i])/nbin + xx[i];
61  }
62  }
63 
64  TCanvas *Canvas = new TCanvas("DistCanvas", "Student Distribution graphs", 10, 10, 800, 700);
65  pdf->SetTitle("Student t distribution function");
66  cum->SetTitle("Cumulative for Student t");
67  quant->SetTitle("10-quantiles for Student t");
68  Canvas->Divide(2, 2);
69  Canvas->cd(1);
70  pdf->SetLineWidth(2);
71  pdf->DrawCopy();
72  Canvas->cd(2);
73  cum->SetLineWidth(2);
74  cum->SetLineColor(kRed);
75  cum->Draw();
76  Canvas->cd(3);
77  quant->Draw();
78  quant->SetLineWidth(2);
79  quant->SetLineColor(kBlue);
80  quant->SetStats(0);
81  Canvas->cd(4);
82  pdfq[0]->SetTitle("Student t & its quantiles");
83  pdf->SetTitle("");
84  pdf->Draw();
85  //pdfq[0]->SetAxisRange(-1.5, 0, 1.5,1.0);
86  pdfq[0]->SetTitle("Student t & its quantiles");
87  for(int i=0; i < 9; i++) {
88  pdfq[i]->SetStats(0);
89  pdfq[i]->SetFillColor(i+1);
90  pdfq[i]->Draw("same");
91  }
92  Canvas->Modified();
93  Canvas->cd();
94 }
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3126
double tdistribution_pdf(double x, double r, double x0=0)
Probability density function of Student&#39;s t-distribution.
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition: TF1.cxx:1115
Definition: Rtypes.h:56
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4639
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:679
Basic string class.
Definition: TString.h:129
TArc * a
Definition: textangle.C:12
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1087
Double_t x[n]
Definition: legend1.C:17
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
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:8325
tomato 1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:594
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:3315
The Canvas class.
Definition: TCanvas.h:31
double tdistribution_quantile(double z, double r)
Inverse ( ) of the cumulative distribution function of the lower tail of Student&#39;s t-distribution (td...
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:1135
1-Dim function class
Definition: TF1.h:150
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
Definition: THist.hxx:310
Definition: Rtypes.h:56
virtual void SetTitle(const char *title)
Change (i.e.
Definition: TH1.cxx:6028
const Int_t n
Definition: legend1.C:16
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8103
void Modified(Bool_t flag=1)
Definition: TPad.h:410