ROOT   Reference Guide
mathStudent.C File Reference

Detailed Description

Tutorial illustrating the use of the Student and F distributions

#include "TMath.h"
#include "TF1.h"
#include "TCanvas.h"
#include <Riostream.h>
#include "TLegend.h"
#include "TLegendEntry.h"
void mathStudent()
{
//drawing the set of student density functions
//normal(0, 1) density drawn for comparison
TCanvas *DistCanvas = new TCanvas("DistCanvas", "Distribution graphs", 10, 10, 800, 650);
DistCanvas->SetFillColor(17);
DistCanvas->Divide(2, 2);
DistCanvas->cd(1);
TLegend *leg = new TLegend(0.6, 0.7, 0.89, 0.89);
TF1* fgaus = new TF1("gaus", "TMath::Gaus(x, [0], [1], [2])", -5, 5);
fgaus->SetTitle("Student density");
fgaus->SetLineStyle(2);
fgaus->SetLineWidth(1);
fgaus->SetParameters(0, 1, kTRUE);
TF1* student = new TF1("student", "TMath::Student(x,[0])", -5, 5);
//student->SetTitle("Student density");
student->SetLineWidth(1);
student->SetParameter(0, 10);
student->SetLineColor(4);
leg->AddEntry(student->DrawCopy("lsame"), "10 degrees of freedom", "l");
student->SetParameter(0, 3);
student->SetLineColor(2);
leg->AddEntry(student->DrawCopy("lsame"), "3 degrees of freedom", "l");
student->SetParameter(0, 1);
student->SetLineColor(1);
leg->AddEntry(student->DrawCopy("lsame"), "1 degree of freedom", "l");
leg->Draw();
//drawing the set of student cumulative probability functions
DistCanvas->cd(2);
TF1 *studentI = new TF1("studentI", "TMath::StudentI(x, [0])", -5, 5);
studentI->SetTitle("Student cumulative dist.");
studentI->SetLineWidth(1);
TLegend *leg2 = new TLegend(0.6, 0.4, 0.89, 0.6);
studentI->SetParameter(0, 10);
studentI->SetLineColor(4);
leg2->AddEntry(studentI->DrawCopy(), "10 degrees of freedom", "l");
studentI->SetParameter(0, 3);
studentI->SetLineColor(2);
leg2->AddEntry(studentI->DrawCopy("lsame"), "3 degrees of freedom", "l");
studentI->SetParameter(0, 1);
studentI->SetLineColor(1);
leg2->AddEntry(studentI->DrawCopy("lsame"), "1 degree of freedom", "l");
leg2->Draw();
//drawing the set of F-dist. densities
TF1* fDist = new TF1("fDist", "TMath::FDist(x, [0], [1])", 0, 2);
fDist->SetTitle("F-Dist. density");
fDist->SetLineWidth(1);
TLegend* legF1 = new TLegend(0.7, 0.7, 0.89, 0.89);
DistCanvas->cd(3);
fDist->SetParameters(1, 1);
fDist->SetLineColor(1);
fDist->SetParameter(1, 10);
fDist->SetLineColor(2);
fDist->SetParameters(10, 1);
fDist->SetLineColor(8);
fDist->SetParameters(10, 10);
fDist->SetLineColor(4);
legF1->Draw();
//drawing the set of F cumulative dist.functions
TF1* fDistI = new TF1("fDist", "TMath::FDistI(x, [0], [1])", 0, 2);
fDistI->SetTitle("Cumulative dist. function for F");
fDistI->SetLineWidth(1);
TLegend* legF2 = new TLegend(0.7, 0.3, 0.89, 0.5);
DistCanvas->cd(4);
fDistI->SetParameters(1, 1);
fDistI->SetLineColor(1);
fDistI->SetParameters(1, 10);
fDistI->SetLineColor(2);
fDistI->SetParameters(10, 1);
fDistI->SetLineColor(8);
fDistI->SetParameters(10, 10);
fDistI->SetLineColor(4);
legF2->Draw();
DistCanvas->cd();
}
const Bool_t kTRUE
Definition: RtypesCore.h:91
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
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 TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition: TF1.cxx:1352
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:644
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:634
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:23
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:330
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:423
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