Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
fit1.py File Reference

Namespaces

namespace  fit1
 

Detailed Description

View in nbviewer Open in SWAN
Fit example.

TFile** py-fillrandom.root
TFile* py-fillrandom.root
KEY: TFormula form1;1 abs(sin(x)/x)
KEY: TF1 sqroot;1 x*gaus(0) + [3]*form1
KEY: TH1F h1f;1 Test random numbers
Formula based function: sqroot
sqroot : x*gaus(0) + [3]*form1 Ndim= 1, Npar= 4, Number= 0
Formula expression:
x*[p0]*exp(-0.5*((x-[p1])/[p2])*((x-[p1])/[p2]))+[p3]*(abs(sin(x)/x))
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 198.935
NDf = 190
Edm = 1.49283e-07
NCalls = 149
p0 = 33.1658 +/- 0.545703
p1 = 4.00667 +/- 0.0165304
p2 = 0.984663 +/- 0.0128238
p3 = 63.4464 +/- 1.33233
fit1 : Real Time = 0.37 seconds Cpu Time = 0.37 seconds
import ROOT
from os import path
from ROOT import TCanvas, TFile, TPaveText
from ROOT import gROOT, gBenchmark
c1 = TCanvas( 'c1', 'The Fit Canvas', 200, 10, 700, 500 )
c1.SetGridx()
c1.SetGridy()
c1.GetFrame().SetFillColor( 21 )
c1.GetFrame().SetBorderMode(-1 )
c1.GetFrame().SetBorderSize( 5 )
gBenchmark.Start( 'fit1' )
#
# We connect the ROOT file generated in a previous tutorial
#
File = "py-fillrandom.root"
if (ROOT.gSystem.AccessPathName(File)) :
ROOT.Info("fit1.py", File+" does not exist")
exit()
fill = TFile(File)
#
# The function "ls()" lists the directory contents of this file
#
fill.ls()
#
# Get object "sqroot" from the file.
#
sqroot = gROOT.FindObject( 'sqroot' )
sqroot.Print()
#
# Now fit histogram h1f with the function sqroot
#
h1f = gROOT.FindObject( 'h1f' )
h1f.SetFillColor( 45 )
h1f.Fit( 'sqroot' )
# We now annotate the picture by creating a PaveText object
# and displaying the list of commands in this macro
#
fitlabel = TPaveText( 0.6, 0.3, 0.9, 0.80, 'NDC' )
fitlabel.SetTextAlign( 12 )
fitlabel.SetFillColor( 42 )
fitlabel.ReadFile(path.join(str(gROOT.GetTutorialDir()), 'pyroot', 'fit1_py.py'))
fitlabel.Draw()
c1.Update()
gBenchmark.Show( 'fit1' )
Option_t Option_t SetFillColor
The Canvas class.
Definition TCanvas.h:23
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
Definition TFile.h:53
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
c SetBorderSize(2)
Author
Wim Lavrijsen

Definition in file fit1.py.