Logo ROOT  
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
19from ROOT import TH1D, TF1, TCanvas, kRed, kBlue
20import ROOT
21import numpy as np
22
23
24# This is the way to force load of MathMore in Cling
25ROOT.Math.MathMoreLibrary.Load()
26
27# Create the pdf and the cumulative distributions
28n = 100
29a = -5.
30b = 5.
31pdf = TF1("pdf", "ROOT::Math::tdistribution_pdf(x,3.0)", a, b)
32cum = TF1("cum", "ROOT::Math::tdistribution_cdf(x,3.0)", a, b)
33
34# Create the histogram and fill it with the quantiles
35quant = TH1D("quant", "", 9, 0, 0.9)
36
37quant.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
43xx = []
44xx.append(-1.5)
45for i in range(1, 9):
46 xx.append(quant.GetBinContent(i))
47xx.append(1.5)
48
49pdfq = []
50for 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.
60Canvas = TCanvas("DistCanvas", "Student Distribution graphs", 10, 10, 800, 700)
61pdf.SetTitle("Student t distribution function")
62cum.SetTitle("Cumulative for Student t")
63quant.SetTitle("10-quantiles for Student t")
64Canvas.Divide(2, 2)
65Canvas.cd(1)
66pdf.SetLineWidth(2)
67pdf.DrawCopy()
68Canvas.cd(2)
69cum.SetLineWidth(2)
70cum.SetLineColor(kRed)
71cum.Draw()
72Canvas.cd(3)
73quant.Draw()
74quant.SetLineWidth(2)
75quant.SetLineColor(kBlue)
76quant.SetStats(0)
77Canvas.cd(4)
78pdfq[0].SetTitle("Student t & its quantiles")
79pdf.SetTitle("")
80pdf.Draw()
81pdfq[0].SetTitle("Student t & its quantiles")
82
83# Set the colors in every quantile.
84i = 1
85for pd in pdfq[1:]:
86 pd.SetStats(0)
87 i += 1
88 pd.SetFillColor(i)
89 pd.Draw("same")
90Canvas.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:682
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...