ROOT   Reference Guide
Searching...
No Matches
tStudent.C File Reference

## Detailed Description

Example macro describing the student t distribution

root[0]: .x tStudent.C

It draws the pdf, the cdf and then 10 quantiles of the t Student distribution

#include "TH1.h"
#include "TF1.h"
#include "TCanvas.h"
#include "TSystem.h"
#include "TLegend.h"
#include "TLegendEntry.h"
#include "Math/DistFunc.h"
void tStudent()
{
// this is the way to force load of MathMore in Cling
int n=100;
double a=-5.;
double b=5.;
//double r = 3;
TF1* pdf = new TF1("pdf", "ROOT::Math::tdistribution_pdf(x,3.0)", a,b);
TF1* cum = new TF1("cum", "ROOT::Math::tdistribution_cdf(x,3.0)", a,b);
TH1D* quant = new TH1D("quant", "", 9, 0, 0.9);
for(int i=1; i < 10; i++)
quant->Fill((i-0.5)/10.0, ROOT::Math::tdistribution_quantile((1.0*i)/10, 3.0 ) );
double xx[10];
xx[0] = -1.5;
for(int i=1; i<9; i++)
xx[i]= quant->GetBinContent(i);
xx[9] = 1.5;
TH1D* pdfq[10];
//int nbin = n/10.0;
for(int i=0; i < 9; i++) {
int nbin = n * (xx[i+1]-xx[i])/3.0 + 1.0;
TString name = "pdf";
name += i;
pdfq[i]= new TH1D(name, "", nbin,xx[i],xx[i+1] );
for(int j=1; j<nbin; j++) {
double x= j*(xx[i+1]-xx[i])/nbin + xx[i];
}
}
TCanvas *Canvas = new TCanvas("DistCanvas", "Student Distribution graphs", 10, 10, 800, 700);
pdf->SetTitle("Student t distribution function");
cum->SetTitle("Cumulative for Student t");
quant->SetTitle("10-quantiles for Student t");
Canvas->Divide(2, 2);
Canvas->cd(1);
pdf->SetLineWidth(2);
pdf->DrawCopy();
Canvas->cd(2);
cum->SetLineWidth(2);
cum->Draw();
Canvas->cd(3);
quant->Draw();
quant->SetLineWidth(2);
quant->SetStats(0);
Canvas->cd(4);
pdfq[0]->SetTitle("Student t & its quantiles");
pdf->SetTitle("");
pdf->Draw();
//pdfq[0]->SetAxisRange(-1.5, 0, 1.5,1.0);
pdfq[0]->SetTitle("Student t & its quantiles");
for(int i=0; i < 9; i++) {
pdfq[i]->SetStats(0);
pdfq[i]->SetFillColor(i+1);
pdfq[i]->Draw("same");
}
Canvas->Modified();
Canvas->cd();
}
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
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
Definition TCanvas.cxx:708
1-Dim function class
Definition TF1.h:213
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:3562
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition TF1.cxx:1322
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition TF1.cxx:1352
1-D histogram with a double per channel (see TH1 documentation)}
Definition TH1.h:618
virtual void SetTitle(const char *title)
Definition TH1.cxx:6678
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3350
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:9062
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3073
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:4993
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8830
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
void Modified(Bool_t flag=1) override