Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
mathStudent.C File Reference

Detailed Description

View in nbviewer Open in SWAN
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);
gPad->SetFrameFillColor(19);
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);
leg->AddEntry(fgaus->DrawCopy(), "Normal(0,1)", "l");
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);
gPad->SetGrid();
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);
gPad->SetGrid();
fDist->SetParameters(1, 1);
fDist->SetLineColor(1);
legF1->AddEntry(fDist->DrawCopy(), "N=1 M=1", "l");
fDist->SetParameter(1, 10);
fDist->SetLineColor(2);
legF1->AddEntry(fDist->DrawCopy("lsame"), "N=1 M=10", "l");
fDist->SetParameters(10, 1);
fDist->SetLineColor(8);
legF1->AddEntry(fDist->DrawCopy("lsame"), "N=10 M=1", "l");
fDist->SetParameters(10, 10);
fDist->SetLineColor(4);
legF1->AddEntry(fDist->DrawCopy("lsame"), "N=10 M=10", "l");
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);
gPad->SetGrid();
fDistI->SetParameters(1, 1);
fDistI->SetLineColor(1);
legF2->AddEntry(fDistI->DrawCopy(), "N=1 M=1", "l");
fDistI->SetParameters(1, 10);
fDistI->SetLineColor(2);
legF2->AddEntry(fDistI->DrawCopy("lsame"), "N=1 M=10", "l");
fDistI->SetParameters(10, 1);
fDistI->SetLineColor(8);
legF2->AddEntry(fDistI->DrawCopy("lsame"), "N=10 M=1", "l");
fDistI->SetParameters(10, 10);
fDistI->SetLineColor(4);
legF2->AddEntry(fDistI->DrawCopy("lsame"), "N=10 M=10", "l");
legF2->Draw();
DistCanvas->cd();
}
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define gPad
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
void SetFrameFillColor(Color_t color=1)
Definition TAttPad.h:73
The Canvas class.
Definition TCanvas.h:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition TCanvas.cxx:716
1-Dim function class
Definition TF1.h:214
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:3552
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition TF1.cxx:1365
virtual void SetParameters(const Double_t *params)
Definition TF1.h:650
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:640
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:317
void Draw(Option_t *option="") override
Draw this legend with its current attributes.
Definition TLegend.cxx:422
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
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)=0
leg
Definition legend1.C:34
Author
Anna Kreshuk

Definition in file mathStudent.C.