Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
pdf011_Student.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_pdf
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 "TLegend.h"
15#include "TLegendEntry.h"
16
17void pdf011_Student()
18{
19 //drawing the set of student density functions
20 //normal(0, 1) density drawn for comparison
21 TCanvas *DistCanvas = new TCanvas("DistCanvas", "Distribution graphs", 10, 10, 800, 650);
22 DistCanvas->SetFillColor(17);
23 DistCanvas->Divide(2, 2);
24 DistCanvas->cd(1);
25 gPad->SetGrid();
26 gPad->SetFrameFillColor(19);
27 TLegend *leg = new TLegend(0.6, 0.7, 0.89, 0.89);
28
29
30 TF1* fgaus = new TF1("gaus", "TMath::Gaus(x, [0], [1], [2])", -5, 5);
31 fgaus->SetTitle("Student density");
32 fgaus->SetLineStyle(kDashed);
33 fgaus->SetLineWidth(1);
34 fgaus->SetParameters(0, 1, kTRUE);
35 leg->AddEntry(fgaus->DrawCopy(), "Normal(0,1)", "l");
36
37 TF1* student = new TF1("student", "TMath::Student(x,[0])", -5, 5);
38 //student->SetTitle("Student density");
39 student->SetLineWidth(1);
40 student->SetParameter(0, 10);
41 student->SetLineColor(4);
42 leg->AddEntry(student->DrawCopy("lsame"), "10 degrees of freedom", "l");
43
44 student->SetParameter(0, 3);
45 student->SetLineColor(2);
46 leg->AddEntry(student->DrawCopy("lsame"), "3 degrees of freedom", "l");
47
48 student->SetParameter(0, 1);
49 student->SetLineColor(1);
50 leg->AddEntry(student->DrawCopy("lsame"), "1 degree of freedom", "l");
51
52 leg->Draw();
53
54 //drawing the set of student cumulative probability functions
55 DistCanvas->cd(2);
56 gPad->SetFrameFillColor(19);
57 gPad->SetGrid();
58 TF1 *studentI = new TF1("studentI", "TMath::StudentI(x, [0])", -5, 5);
59 studentI->SetTitle("Student cumulative dist.");
60 studentI->SetLineWidth(1);
61 TLegend *leg2 = new TLegend(0.6, 0.4, 0.89, 0.6);
62
63 studentI->SetParameter(0, 10);
64 studentI->SetLineColor(4);
65 leg2->AddEntry(studentI->DrawCopy(), "10 degrees of freedom", "l");
66
67 studentI->SetParameter(0, 3);
68 studentI->SetLineColor(2);
69 leg2->AddEntry(studentI->DrawCopy("lsame"), "3 degrees of freedom", "l");
70
71 studentI->SetParameter(0, 1);
72 studentI->SetLineColor(1);
73 leg2->AddEntry(studentI->DrawCopy("lsame"), "1 degree of freedom", "l");
74 leg2->Draw();
75
76 //drawing the set of F-dist. densities
77 TF1* fDist = new TF1("fDist", "TMath::FDist(x, [0], [1])", 0, 2);
78 fDist->SetTitle("F-Dist. density");
79 fDist->SetLineWidth(1);
80 TLegend* legF1 = new TLegend(0.7, 0.7, 0.89, 0.89);
81
82 DistCanvas->cd(3);
83 gPad->SetFrameFillColor(19);
84 gPad->SetGrid();
85
86 fDist->SetParameters(1, 1);
87 fDist->SetLineColor(1);
88 legF1->AddEntry(fDist->DrawCopy(), "N=1 M=1", "l");
89
90 fDist->SetParameter(1, 10);
91 fDist->SetLineColor(2);
92 legF1->AddEntry(fDist->DrawCopy("lsame"), "N=1 M=10", "l");
93
94 fDist->SetParameters(10, 1);
95 fDist->SetLineColor(8);
96 legF1->AddEntry(fDist->DrawCopy("lsame"), "N=10 M=1", "l");
97
98 fDist->SetParameters(10, 10);
99 fDist->SetLineColor(4);
100 legF1->AddEntry(fDist->DrawCopy("lsame"), "N=10 M=10", "l");
101
102 legF1->Draw();
103
104 //drawing the set of F cumulative dist.functions
105 TF1* fDistI = new TF1("fDist", "TMath::FDistI(x, [0], [1])", 0, 2);
106 fDistI->SetTitle("Cumulative dist. function for F");
107 fDistI->SetLineWidth(1);
108 TLegend* legF2 = new TLegend(0.7, 0.3, 0.89, 0.5);
109
110 DistCanvas->cd(4);
111 gPad->SetFrameFillColor(19);
112 gPad->SetGrid();
113 fDistI->SetParameters(1, 1);
114 fDistI->SetLineColor(1);
115 legF2->AddEntry(fDistI->DrawCopy(), "N=1 M=1", "l");
116
117 fDistI->SetParameters(1, 10);
118 fDistI->SetLineColor(2);
119 legF2->AddEntry(fDistI->DrawCopy("lsame"), "N=1 M=10", "l");
120
121 fDistI->SetParameters(10, 1);
122 fDistI->SetLineColor(8);
123 legF2->AddEntry(fDistI->DrawCopy("lsame"), "N=10 M=1", "l");
124
125 fDistI->SetParameters(10, 10);
126 fDistI->SetLineColor(4);
127 legF2->AddEntry(fDistI->DrawCopy("lsame"), "N=10 M=10", "l");
128
129 legF2->Draw();
130 DistCanvas->cd();
131}
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
@ kDashed
Definition TAttLine.h:54
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:47
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:182
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:3614
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition TF1.cxx:1371
virtual void SetParameters(const Double_t *params)
Definition TF1.h:618
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:608
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
leg
Definition legend1.C:34