Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
12from ROOT import TCanvas, TPad, TFormula, TF1, TPaveLabel, TH1F, TFile
13from ROOT import gROOT, gBenchmark
14
15
16
17c1 = TCanvas( 'c1', 'The FillRandom example', 200, 10, 700, 900 )
19
20pad1 = TPad( 'pad1', 'The pad with the function', 0.05, 0.50, 0.95, 0.95, 21 )
21pad2 = TPad( 'pad2', 'The pad with the histogram', 0.05, 0.05, 0.95, 0.45, 21 )
24pad1.cd()
25
26gBenchmark.Start( 'fillrandom' )
27#
28# A function (any dimension) or a formula may reference
29# an already defined formula
30#
31form1 = TFormula( 'form1', 'abs(sin(x)/x)' )
32sqroot = TF1( 'sqroot', 'x*gaus(0) + [3]*form1', 0, 10 )
33sqroot.SetParameters( 10, 4, 1, 20 )
37pad1.GetFrame().SetBorderMode( -1 )
42lfunction = TPaveLabel( 5, 39, 9.8, 46, 'The sqroot function' )
46
47#
48# Create a one dimensional histogram (one float per bin)
49# and fill it following the distribution in function sqroot.
50#
51pad2.cd();
53pad2.GetFrame().SetBorderMode( -1 )
55h1f = TH1F( 'h1f', 'Test random numbers', 200, 0, 10 )
57h1f.FillRandom( 'sqroot', 10000 )
60#
61# Open a ROOT file and save the formula, function and histogram
62#
63myfile = TFile( 'py-fillrandom.root', 'RECREATE' )
68gBenchmark.Show( 'fillrandom' )
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t SetFillColor
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:233
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
The Formula class.
Definition TFormula.h:89
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:621
The most important graphics class in the ROOT system.
Definition TPad.h:28
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
c SetBorderSize(2)