ROOT
v6-36
Reference Guide
Loading...
Searching...
No Matches
pdf012_tStudent.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_pdf
3
## \notebook
4
## Example macro describing the student t distribution
5
##
6
## ~~~{.cpp}
7
## root[0]: .x tStudent.C
8
## ~~~
9
##
10
## It draws the pdf, the cdf and then 10 quantiles of the t Student distribution
11
##
12
## based on Magdalena Slawinska's tStudent.C
13
##
14
## \macro_image
15
## \macro_code
16
##
17
## \author Juan Fernando Jaramillo Botero
18
19
from
ROOT
import
TH1D, TF1, TCanvas, kRed, kBlue
20
import
ROOT
21
import
numpy
as
np
22
23
24
# This is the way to force load of MathMore in Cling
25
ROOT.Math.MathMoreLibrary.Load
()
26
27
# Create the pdf and the cumulative distributions
28
n = 100
29
a = -5.
30
b = 5.
31
pdf =
TF1
(
"pdf"
,
"ROOT::Math::tdistribution_pdf(x,3.0)"
, a, b)
32
cum =
TF1
(
"cum"
,
"ROOT::Math::tdistribution_cdf(x,3.0)"
, a, b)
33
34
# Create the histogram and fill it with the quantiles
35
quant =
TH1D
(
"quant"
,
""
, 9, 0, 0.9)
36
37
quant.Fill
(
38
np.array
([(i - 0.5) / 10.0
for
i
in
range
(1, 10)]),
39
np.array
([
ROOT.Math.tdistribution_quantile
(0.1 * i, 3.0)
for
i
in
range
(1, 10)]),
40
)
41
42
# For each quantile fill with the pdf
43
xx = []
44
xx.append
(-1.5)
45
for
i
in
range
(1, 9):
46
xx.append
(
quant.GetBinContent
(i))
47
xx.append
(1.5)
48
49
pdfq = []
50
for
i
in
range
(9):
51
nbin =
int
(n * (xx[i+1] - xx[i]) / 3.0 + 1.0)
52
name =
"pdf%d"
% i
53
pdfq.append
(
TH1D
(name,
""
, nbin, xx[i], xx[i+1]))
54
for
j
in
range
(1, nbin):
55
x = j * (xx[i+1] - xx[i]) / nbin + xx[i]
56
pdfq[i].SetBinContent(j,
ROOT.Math.tdistribution_pdf
(x, 3))
57
58
# Create the Canvas and divide in four draws, for every draw set the line width
59
# the title, and the line color.
60
Canvas =
TCanvas
(
"DistCanvas"
,
"Student Distribution graphs"
, 10, 10, 800, 700)
61
pdf.SetTitle
(
"Student t distribution function"
)
62
cum.SetTitle
(
"Cumulative for Student t"
)
63
quant.SetTitle
(
"10-quantiles for Student t"
)
64
Canvas.Divide
(2, 2)
65
Canvas.cd
(1)
66
pdf.SetLineWidth
(2)
67
pdf.DrawCopy
()
68
Canvas.cd
(2)
69
cum.SetLineWidth
(2)
70
cum.SetLineColor
(kRed)
71
cum.Draw
()
72
Canvas.cd
(3)
73
quant.Draw
()
74
quant.SetLineWidth
(2)
75
quant.SetLineColor
(kBlue)
76
quant.SetStats
(0)
77
Canvas.cd
(4)
78
pdfq[0].SetTitle(
"Student t & its quantiles"
)
79
pdf.SetTitle
(
""
)
80
pdf.Draw
()
81
pdfq[0].SetTitle(
"Student t & its quantiles"
)
82
83
# Set the colors in every quantile.
84
i = 1
85
for
pd
in
pdfq[1:]:
86
pd.SetStats
(0)
87
i += 1
88
pd.SetFillColor
(i)
89
pd.Draw
(
"same"
)
90
Canvas.Modified
()
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TF1
1-Dim function class
Definition
TF1.h:234
TH1D
1-D histogram with a double per channel (see TH1 documentation)
Definition
TH1.h:925
int
tutorials
math
pdf
pdf012_tStudent.py
ROOT v6-36 - Reference Guide Generated on Thu Aug 21 2025 04:30:47 (GVA Time) using Doxygen 1.10.0