Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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"
{
//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->SetGrid();
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->SetFrameFillColor(19);
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->SetFrameFillColor(19);
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->SetFrameFillColor(19);
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:93
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gPad
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
1-Dim function class
Definition TF1.h:233
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:3558
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition TF1.cxx:1363
virtual void SetParameters(const Double_t *params)
Definition TF1.h:677
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:667
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
leg
Definition legend1.C:34
Author
Anna Kreshuk

Definition in file mathStudent.C.