Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tStudent.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_math
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
19from ROOT import TH1D, TF1, TCanvas, kRed, kBlue
20import ROOT
21
22
23# This is the way to force load of MathMore in Cling
24ROOT.Math.MathMoreLibrary.Load()
25
26# Create the pdf and the cumulative distributions
27n = 100
28a = -5.
29b = 5.
30pdf = TF1("pdf", "ROOT::Math::tdistribution_pdf(x,3.0)", a, b)
31cum = TF1("cum", "ROOT::Math::tdistribution_cdf(x,3.0)", a, b)
32
33# Create the histogram and fill it with the quantiles
34quant = TH1D("quant", "", 9, 0, 0.9)
35
36for i in range(1, 10):
37 quant.Fill((i-0.5)/10.0, ROOT.Math.tdistribution_quantile(0.1 * i,
38 3.0))
39
40# For each quantile fill with the pdf
41xx = []
42xx.append(-1.5)
43for i in range(1, 9):
44 xx.append(quant.GetBinContent(i))
45xx.append(1.5)
46
47pdfq = []
48for i in range(9):
49 nbin = int(n * (xx[i+1] - xx[i]) / 3.0 + 1.0)
50 name = "pdf%d" % i
51 pdfq.append(TH1D(name, "", nbin, xx[i], xx[i+1]))
52 for j in range(1, nbin):
53 x = j * (xx[i+1] - xx[i]) / nbin + xx[i]
54 pdfq[i].SetBinContent(j, ROOT.Math.tdistribution_pdf(x, 3))
55
56# Create the Canvas and divide in four draws, for every draw set the line width
57# the title, and the line color.
58Canvas = TCanvas("DistCanvas", "Student Distribution graphs", 10, 10, 800, 700)
59pdf.SetTitle("Student t distribution function")
60cum.SetTitle("Cumulative for Student t")
61quant.SetTitle("10-quantiles for Student t")
62Canvas.Divide(2, 2)
63Canvas.cd(1)
64pdf.SetLineWidth(2)
65pdf.DrawCopy()
66Canvas.cd(2)
67cum.SetLineWidth(2)
68cum.SetLineColor(kRed)
69cum.Draw()
70Canvas.cd(3)
71quant.Draw()
72quant.SetLineWidth(2)
73quant.SetLineColor(kBlue)
74quant.SetStats(0)
75Canvas.cd(4)
76pdfq[0].SetTitle("Student t & its quantiles")
77pdf.SetTitle("")
78pdf.Draw()
79pdfq[0].SetTitle("Student t & its quantiles")
80
81# Set the colors in every quantile.
82i = 1
83for pd in pdfq[1:]:
84 pd.SetStats(0)
85 i += 1
86 pd.SetFillColor(i)
87 pd.Draw("same")
88Canvas.Modified()
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:233
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:669
double tdistribution_pdf(double x, double r, double x0=0)
Probability density function of Student's t-distribution.
double tdistribution_quantile(double z, double r)
Inverse ( ) of the cumulative distribution function of the lower tail of Student's t-distribution (td...