Logo ROOT  
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
26void 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}
@ kRed
Definition: Rtypes.h:66
@ kBlue
Definition: Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
char name[80]
Definition: TGX11.cxx:110
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition: TCanvas.cxx:711
1-Dim function class
Definition: TF1.h:213
void SetTitle(const char *title="") override
Set function title if title has the form "fffffff;xxxx;yyyy", it is assumed that the function title i...
Definition: TF1.cxx:3596
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition: TF1.cxx:1343
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition: TF1.cxx:1373
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:620
void SetTitle(const char *title) override
Change (i.e.
Definition: TH1.cxx:6700
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3338
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition: TH1.cxx:3060
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:9089
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:5025
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8857
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition: TPad.cxx:1153
void Modified(Bool_t flag=1) override
Definition: TPad.h:417
Basic string class.
Definition: TString.h:136
double tdistribution_pdf(double x, double r, double x0=0)
Probability density function of Student's t-distribution.
double tdistribution_quantile(double z, double r)
Inverse ( ) of the cumulative distribution function of the lower tail of Student's t-distribution (td...
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
TArc a
Definition: textangle.C:12