Fitting data set using Jaida
Code: "fit_jaida2.py". Programming language: Python DMelt Version 1. Last modified: 12/08/2015. License: Pro
https://datamelt.org/code/cache/fit_jaida2_7276.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



from hep.aida import IAnalysisFactory
from java.util import Random
from jhplot import *

af   = IAnalysisFactory.create();
tree = af.createTreeFactory().create();
hf   = af.createHistogramFactory(tree);

r = Random()

dpf = af.createDataPointSetFactory(tree)
dataPointSet = dpf.create("dataPointSet","two dimensional IDataPointSet",2)

for i in range(20):
    dataPointSet.addPoint()
    dp = dataPointSet.point(i)
    dp.coordinate(0).setValue(i)
    dp.coordinate(1).setValue(i+r.nextDouble()-0.5)
    dp.coordinate(1).setErrorPlus(1)
    dp.coordinate(1).setErrorMinus(1)

functionfact = af.createFunctionFactory(tree)
line = functionfact.createFunctionByName("line","p1")

ff = af.createFitFactory()
fitter = ff.createFitter("Chi2","jminuit")
result = fitter.fit(dataPointSet,line)
print "Chi2 = ", result.quality()

c1=HPlotter("ComplexFit",700,600)
c1.visible()
c1.draw(dataPointSet)
c1.draw(result.fittedFunction())

You see the box below because you did not login.