Logo ROOT  
Reference Guide
fit1.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_pyroot
3## \notebook
4## Fit example.
5##
6## \macro_image
7## \macro_output
8## \macro_code
9##
10## \author Wim Lavrijsen
11
12from os import path
13from ROOT import TCanvas, TFile, TPaveText
14from ROOT import gROOT, gBenchmark
15
16c1 = TCanvas( 'c1', 'The Fit Canvas', 200, 10, 700, 500 )
17c1.SetGridx()
18c1.SetGridy()
19c1.GetFrame().SetFillColor( 21 )
20c1.GetFrame().SetBorderMode(-1 )
21c1.GetFrame().SetBorderSize( 5 )
22
23gBenchmark.Start( 'fit1' )
24#
25# We connect the ROOT file generated in a previous tutorial
26#
27fill = TFile( 'py-fillrandom.root' )
28
29#
30# The function "ls()" lists the directory contents of this file
31#
32fill.ls()
33
34#
35# Get object "sqroot" from the file.
36#
37
38sqroot = gROOT.FindObject( 'sqroot' )
39sqroot.Print()
40
41#
42# Now fit histogram h1f with the function sqroot
43#
44h1f = gROOT.FindObject( 'h1f' )
45h1f.SetFillColor( 45 )
46h1f.Fit( 'sqroot' )
47
48# We now annotate the picture by creating a PaveText object
49# and displaying the list of commands in this macro
50#
51fitlabel = TPaveText( 0.6, 0.3, 0.9, 0.80, 'NDC' )
52fitlabel.SetTextAlign( 12 )
53fitlabel.SetFillColor( 42 )
54fitlabel.ReadFile(path.join(str(gROOT.GetTutorialDir()), 'pyroot', 'fit1_py.py'))
55fitlabel.Draw()
56c1.Update()
57gBenchmark.Show( 'fit1' )
The Canvas class.
Definition: TCanvas.h:27
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:53
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
c SetBorderSize(2)
h1 SetFillColor(kGreen)