This program creates :
- a one dimensional histogram
- a two dimensional histogram
- a profile histogram
- a memory-resident ntuple
These objects are filled with some random numbers and saved on a file.
2 from ROOT
import TCanvas, TFile, TProfile, TNtuple, TH1F, TH2F
3 from ROOT
import gROOT, gBenchmark, gRandom, gSystem, Double
6 c1 =
TCanvas(
'c1',
'Dynamic Filling Example', 200, 10, 700, 500 )
10 c1.GetFrame().SetBorderMode( -1 )
17 hfile = gROOT.FindObject(
'py-hsimple.root' )
20 hfile =
TFile(
'py-hsimple.root',
'RECREATE',
'Demo ROOT file with histograms' )
23 hpx =
TH1F(
'hpx',
'This is the px distribution', 100, -4, 4 )
24 hpxpy =
TH2F(
'hpxpy',
'py vs px', 40, -4, 4, 40, -4, 4 )
25 hprof =
TProfile(
'hprof',
'Profile of pz versus px', 100, -4, 4, 0, 20 )
26 ntuple =
TNtuple(
'ntuple',
'Demo ntuple',
'px:py:pz:random:i' )
29 hpx.SetFillColor( 48 )
31 gBenchmark.Start(
'hsimple' )
35 rannor, rndm = gRandom.Rannor, gRandom.Rndm
38 histos = [
'hpx',
'hpxpy',
'hprof',
'ntuple' ]
40 exec(
'%sFill = %s.Fill' % (name,name))
45 for i
in range( 25000 ):
55 ntuple.Fill( px, py, pz, random, i )
58 if i
and i%kUPDATE == 0:
65 if gSystem.ProcessEvents():
70 exec(
'del %sFill' % name)
73 gBenchmark.Show(
'hsimple' )
78 hpx.SetFillColor( 48 )
- Author
- Wim Lavrijsen
Definition in file hsimple.py.