Hello,
I would like to fit some data. I have defined model function and also chi-square (“FCN” - I want to customize chi-squere litle bit) on C++ side. If I run this short script:
import ROOT
from array import array
ROOT.gROOT.ProcessLine(".L mymodel.C+g")
ROOT.gROOT.ProcessLine(".L myfcn.C+g")
x = array('d',[1.])
p = array('d',[1,2])
fitter = ROOT.Fit.Fitter()
fitdata = ROOT.Fit.BinData(1000,1,ROOT.Fit.BinData.kNoError)
datasize = 15
ci = array('d',[0]*datasize)
for i in range(datasize):
fitdata.Add(i,i)
fitter.Config().MinimizerOptions().SetMinimizerType("Minuit2")
fitter.Config().MinimizerOptions().SetMinimizerAlgorithm("Minimize")
fitter.Config().MinimizerOptions().SetPrintLevel(2)
mymodel = ROOT.MyModel()
myfcn = ROOT.MyFCN(fitdata,mymodel)
# Is it possible to define myfun on python side and not on C++ side?
# Something like
#
# def mycn(params,...):
# return ...
#
fitter.FitFCN(myfcn,p,datasize)
fitter.Result().Print(ROOT.cout,True)
then everything work without any problem. I just wonder if there is any way how to define “myfcn” purely on python side and then pass it somehow (magic goes here) to fitter.FitFCN(myfcn,p,datasize). How can I achieve that? Using a wrapper defined on C++ side for python myfun function/class? How it should be implemented?
Thank you in advance for your help,
Jiri
test.py (990 Bytes)
mymodel.C (1.08 KB)
myfcn.C (455 Bytes)