ROOT   Reference Guide
mathStudent.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_math
3/// \notebook
4/// Tutorial illustrating the use of the Student and F distributions
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Anna Kreshuk
10
11#include "TMath.h"
12#include "TF1.h"
13#include "TCanvas.h"
14#include <Riostream.h>
15#include "TLegend.h"
16#include "TLegendEntry.h"
17
18void mathStudent()
19{
20 //drawing the set of student density functions
21 //normal(0, 1) density drawn for comparison
22 TCanvas *DistCanvas = new TCanvas("DistCanvas", "Distribution graphs", 10, 10, 800, 650);
23 DistCanvas->SetFillColor(17);
24 DistCanvas->Divide(2, 2);
25 DistCanvas->cd(1);
26 gPad->SetGrid();
27 gPad->SetFrameFillColor(19);
28 TLegend *leg = new TLegend(0.6, 0.7, 0.89, 0.89);
29
30
31 TF1* fgaus = new TF1("gaus", "TMath::Gaus(x, [0], [1], [2])", -5, 5);
32 fgaus->SetTitle("Student density");
33 fgaus->SetLineStyle(2);
34 fgaus->SetLineWidth(1);
35 fgaus->SetParameters(0, 1, kTRUE);
36 leg->AddEntry(fgaus->DrawCopy(), "Normal(0,1)", "l");
37
38 TF1* student = new TF1("student", "TMath::Student(x,[0])", -5, 5);
39 //student->SetTitle("Student density");
40 student->SetLineWidth(1);
41 student->SetParameter(0, 10);
42 student->SetLineColor(4);
43 leg->AddEntry(student->DrawCopy("lsame"), "10 degrees of freedom", "l");
44
45 student->SetParameter(0, 3);
46 student->SetLineColor(2);
47 leg->AddEntry(student->DrawCopy("lsame"), "3 degrees of freedom", "l");
48
49 student->SetParameter(0, 1);
50 student->SetLineColor(1);
51 leg->AddEntry(student->DrawCopy("lsame"), "1 degree of freedom", "l");
52
53 leg->Draw();
54
55 //drawing the set of student cumulative probability functions
56 DistCanvas->cd(2);
57 gPad->SetFrameFillColor(19);
58 gPad->SetGrid();
59 TF1 *studentI = new TF1("studentI", "TMath::StudentI(x, [0])", -5, 5);
60 studentI->SetTitle("Student cumulative dist.");
61 studentI->SetLineWidth(1);
62 TLegend *leg2 = new TLegend(0.6, 0.4, 0.89, 0.6);
63
64 studentI->SetParameter(0, 10);
65 studentI->SetLineColor(4);
66 leg2->AddEntry(studentI->DrawCopy(), "10 degrees of freedom", "l");
67
68 studentI->SetParameter(0, 3);
69 studentI->SetLineColor(2);
70 leg2->AddEntry(studentI->DrawCopy("lsame"), "3 degrees of freedom", "l");
71
72 studentI->SetParameter(0, 1);
73 studentI->SetLineColor(1);
74 leg2->AddEntry(studentI->DrawCopy("lsame"), "1 degree of freedom", "l");
75 leg2->Draw();
76
77 //drawing the set of F-dist. densities
78 TF1* fDist = new TF1("fDist", "TMath::FDist(x, [0], [1])", 0, 2);
79 fDist->SetTitle("F-Dist. density");
80 fDist->SetLineWidth(1);
81 TLegend* legF1 = new TLegend(0.7, 0.7, 0.89, 0.89);
82
83 DistCanvas->cd(3);
84 gPad->SetFrameFillColor(19);
85 gPad->SetGrid();
86
87 fDist->SetParameters(1, 1);
88 fDist->SetLineColor(1);
89 legF1->AddEntry(fDist->DrawCopy(), "N=1 M=1", "l");
90
91 fDist->SetParameter(1, 10);
92 fDist->SetLineColor(2);
93 legF1->AddEntry(fDist->DrawCopy("lsame"), "N=1 M=10", "l");
94
95 fDist->SetParameters(10, 1);
96 fDist->SetLineColor(8);
97 legF1->AddEntry(fDist->DrawCopy("lsame"), "N=10 M=1", "l");
98
99 fDist->SetParameters(10, 10);
100 fDist->SetLineColor(4);
101 legF1->AddEntry(fDist->DrawCopy("lsame"), "N=10 M=10", "l");
102
103 legF1->Draw();
104
105 //drawing the set of F cumulative dist.functions
106 TF1* fDistI = new TF1("fDist", "TMath::FDistI(x, [0], [1])", 0, 2);
107 fDistI->SetTitle("Cumulative dist. function for F");
108 fDistI->SetLineWidth(1);
109 TLegend* legF2 = new TLegend(0.7, 0.3, 0.89, 0.5);
110
111 DistCanvas->cd(4);
112 gPad->SetFrameFillColor(19);
113 gPad->SetGrid();
114 fDistI->SetParameters(1, 1);
115 fDistI->SetLineColor(1);
116 legF2->AddEntry(fDistI->DrawCopy(), "N=1 M=1", "l");
117
118 fDistI->SetParameters(1, 10);
119 fDistI->SetLineColor(2);
120 legF2->AddEntry(fDistI->DrawCopy("lsame"), "N=1 M=10", "l");
121
122 fDistI->SetParameters(10, 1);
123 fDistI->SetLineColor(8);
124 legF2->AddEntry(fDistI->DrawCopy("lsame"), "N=10 M=1", "l");
125
126 fDistI->SetParameters(10, 10);
127 fDistI->SetLineColor(4);
128 legF2->AddEntry(fDistI->DrawCopy("lsame"), "N=10 M=10", "l");
129
130 legF2->Draw();
131 DistCanvas->cd();
132}
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define gPad
Definition: TVirtualPad.h:288
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
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition: TCanvas.cxx:706
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:3600
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition: TF1.cxx:1377
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:649
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:639
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:1152
leg
Definition: legend1.C:34