Logo ROOT  
Reference Guide
fillrandom.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_hist
3## \notebook
4## Fill a 1-D histogram from a parametric function. Original tutorial by Rene Brun.
5##
6## \macro_image
7## \macro_code
8##
9## \author Alberto Ferro
10
11import ROOT
12
13c1 = ROOT.TCanvas("c1","The FillRandom example",200,10,700,900)
14pad1 = ROOT.TPad("pad1","The pad with the function",0.05,0.50,0.95,0.95)
15pad2 = ROOT.TPad("pad2","The pad with the histogram",0.05,0.05,0.95,0.45)
16pad1.Draw()
17pad2.Draw()
18pad1.cd()
19ROOT.gBenchmark.Start("fillrandom")
20
21form1 = ROOT.TFormula("form1","abs(sin(x)/x)")
22sqroot = ROOT.TF1("sqroot","x*gaus(0) + [3]*form1",0,10)
23sqroot.SetParameters(10,4,1,20)
24pad1.SetGridx()
25pad1.SetGridy()
26pad1.GetFrame().SetBorderMode(-1)
27pad1.GetFrame().SetBorderSize(5)
28sqroot.SetLineColor(4)
29sqroot.SetLineWidth(6)
30sqroot.Draw()
31lfunction = ROOT.TPaveLabel(5,39,9.8,46,"The sqroot function")
32lfunction.Draw()
33c1.Update()
34
35pad2.cd()
36pad2.GetFrame().SetBorderMode(-1)
37pad2.GetFrame().SetBorderSize(5)
38h1f = ROOT.TH1F("h1f","Test random numbers",200,0,10)
39h1f.SetFillColor(45)
40h1f.FillRandom("sqroot",10000)
41h1f.Draw()
42c1.Update()
43
44f = ROOT.TFile("fillrandom-py.root","RECREATE")
45form1.Write()
46sqroot.Write()
47h1f.Write()
48ROOT.gBenchmark.Show("fillrandom")
c SetBorderSize(2)