Error in pyroot using Fit.FitFCN

Hello,

I am working with the fitting tutorial, combinedFit.C and trying to move it over to python/pyroot. I have other code in python I want to combine it with. Everything seems to be working up until I attempt to set the fit function for the fitter:

fitter.FitFCN(8,globalChi2,0,datanear.Size()+datafar.Size(),1)

The structure, globalChi2, is created using the following.

ROOT.gInterpreter.Declare(struct GlobalChi2{...};)

The two functions that are used to create the structure are TF1’s in both the tutorial and mine, however in the tutorial the TF1’s are built with standard function types (gaus,expo, etc.). Mine are defined with python functions:

def func1(x, par):
    return stuff

I am not sure if the functions are the cause or not, but this is the error that I get from pyroot:

TypeError: Template method resolution failed:
  none of the 6 overloaded methods succeeded. Full details:
  bool ROOT::Fit::Fitter::FitFCN() =>
    TypeError: takes at most 0 arguments (5 given)
  bool ROOT::Fit::Fitter::FitFCN(const ROOT::Math::BasicFitMethodFunction<ROOT::Math::IBaseFunctionMultiDimTempl<double> >& fcn, const double* params = 0) =>
    TypeError: takes at most 2 arguments (5 given)
  bool ROOT::Fit::Fitter::FitFCN(const ROOT::Math::IGradientFunctionMultiDimTempl<double>& fcn, const double* params = 0, unsigned int dataSize = 0, bool chi2fit = false) =>
    TypeError: takes at most 4 arguments (5 given)
  bool ROOT::Fit::Fitter::FitFCN(const ROOT::Math::BasicFitMethodFunction<ROOT::Math::IGradientFunctionMultiDimTempl<double> >& fcn, const double* params = 0) =>
    TypeError: takes at most 2 arguments (5 given)
  bool ROOT::Fit::Fitter::FitFCN(ROOT::Math::IBaseFunctionMultiDimTempl<double>& fcn, const double* params = 0, unsigned int dataSize = 0, bool chi2fit = false) =>
    TypeError: takes at most 4 arguments (5 given)
  bool ROOT::Fit::Fitter::FitFCN(void(*)(int&,double*,double&,double*,int) fcn, int npar = 0, const double* params = 0, unsigned int dataSize = 0, bool chi2fit = false) =>
    TypeError: could not convert argument 1
  Failed to instantiate "FitFCN(int,GlobalChi2&,int,int,int)"
  Failed to instantiate "FitFCN(int,GlobalChi2*,int,int,int)"
  Failed to instantiate "FitFCN(int,GlobalChi2,int,int,int)"

This is my first time working with ROOT.Fit methods and I am too unfamiliar to see what has gone wrong, aside from the issue of what complication could be arising from taking this into python from C++.

Any help would be greatly appreciated.

EDIT: I have attached the tutorial combinedFit.C but moved over to python/pyroot as example code that shows the problem I have. combined.py (3.1 KB)


Please read tips for efficient and successful posting and posting code

_ROOT Version:6.24/00
_Platform:Mac OSX 11.4
_Compiler:


Hi,
This is a PyROOT problem to finc the right overload. You can use this signature for FitFCN, which will work. The draback is that you will need to compute yourself the resulting chi2 of the fit.

fitter.FitFCN(6,globalChi2)

Note your script does not work for other errors. You have also modified the implementation of the globalchi2 function w.r.t the tutorial

Cheers

Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.