Logo ROOT   6.10/09
Reference Guide
fillrandom.py
Go to the documentation of this file.
1 ## \file
2 ## \ingroup tutorial_pyroot
3 ## \notebook
4 ## FillRandom example
5 ##
6 ## \macro_image
7 ## \macro_output
8 ## \macro_code
9 ##
10 ## \author Wim Lavrijsen
11 
12 from ROOT import TCanvas, TPad, TFormula, TF1, TPaveLabel, TH1F, TFile
13 from ROOT import gROOT, gBenchmark
14 
15 
16 
17 c1 = TCanvas( 'c1', 'The FillRandom example', 200, 10, 700, 900 )
18 c1.SetFillColor( 18 )
19 
20 pad1 = TPad( 'pad1', 'The pad with the function', 0.05, 0.50, 0.95, 0.95, 21 )
21 pad2 = TPad( 'pad2', 'The pad with the histogram', 0.05, 0.05, 0.95, 0.45, 21 )
22 pad1.Draw()
23 pad2.Draw()
24 pad1.cd()
25 
26 gBenchmark.Start( 'fillrandom' )
27 #
28 # A function (any dimension) or a formula may reference
29 # an already defined formula
30 #
31 form1 = TFormula( 'form1', 'abs(sin(x)/x)' )
32 sqroot = TF1( 'sqroot', 'x*gaus(0) + [3]*form1', 0, 10 )
33 sqroot.SetParameters( 10, 4, 1, 20 )
34 pad1.SetGridx()
35 pad1.SetGridy()
36 pad1.GetFrame().SetFillColor( 42 )
37 pad1.GetFrame().SetBorderMode( -1 )
38 pad1.GetFrame().SetBorderSize( 5 )
39 sqroot.SetLineColor( 4 )
40 sqroot.SetLineWidth( 6 )
41 sqroot.Draw()
42 lfunction = TPaveLabel( 5, 39, 9.8, 46, 'The sqroot function' )
43 lfunction.SetFillColor( 41 )
44 lfunction.Draw()
45 c1.Update()
46 
47 #
48 # Create a one dimensional histogram (one float per bin)
49 # and fill it following the distribution in function sqroot.
50 #
51 pad2.cd();
52 pad2.GetFrame().SetFillColor( 42 )
53 pad2.GetFrame().SetBorderMode( -1 )
54 pad2.GetFrame().SetBorderSize( 5 )
55 h1f = TH1F( 'h1f', 'Test random numbers', 200, 0, 10 )
56 h1f.SetFillColor( 45 )
57 h1f.FillRandom( 'sqroot', 10000 )
58 h1f.Draw()
59 c1.Update()
60 #
61 # Open a ROOT file and save the formula, function and histogram
62 #
63 myfile = TFile( 'py-fillrandom.root', 'RECREATE' )
64 form1.Write()
65 sqroot.Write()
66 h1f.Write()
67 myfile.Close()
68 gBenchmark.Show( 'fillrandom' )
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:551
c SetBorderSize(2)
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:20
The Formula class.
Definition: TFormula.h:83
h1 SetFillColor(kGreen)
The most important graphics class in the ROOT system.
Definition: TPad.h:29
The Canvas class.
Definition: TCanvas.h:31
1-Dim function class
Definition: TF1.h:150