2009年7月10日金曜日

How to use pyROOT 応用編 その3

任意関数での ヒストグラムの fitting


#/bin/usr/env python

import sys, math
import ROOT


class Linear:
def __call__(self, x, par):
return par[0] + x[0] * par[1]

if __name__=='__main__':

cv = ROOT.TCanvas("cv", "Fitting Example", 200, 10, 700, 500)

# create a linear function for fitting
f = ROOT.TF1('f', Linear(), -1., 1., 2)

# create histogram ( identify, Title, ?, xmin, xmax )
h = ROOT.TH1F('h', 'px', 100, -1., 1.)
f2= ROOT.TF1('f2', '6. + x * 4.5', -1, 1.)

h.FillRandom('f2', 10000)


# fits the hitstogram with the 'Linear' function
h.Fit(f)

# export
cv.Print("graphtest4.png")

# print results
par = f.GetParameters()
print 'fitting result: const = ', par[0], ', pitch = ', par[1]


実行結果


$ python graphtest4.py
FCN=101.388 FROM MIGRAD STATUS=CONVERGED 29 CALLS 30 TOTAL
EDM=2.65063e-16 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 9.89861e+01 9.94918e-01 4.29016e-03 -2.65160e-08
2 p1 7.57130e+01 1.55891e+00 6.72214e-03 8.21832e-09
Info in : file graphtest4.png has been created
fitting result: const = 98.9861239576 , pitch = 75.7130326833



0 件のコメント:

コメントを投稿