Home | News | Documentation | Download

chi2FitTo methods not exposed to pyroot

Using ROOT 6.18.04, it seems as though all the implemented methods for chi2FitTo are not exposed to all PDFs, but rather only the one used in the tutorial rf609_xychi2fit.

Python 3.7.4 (default, Sep  7 2019, 18:27:02) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT as R
>>> R.RooPolyVar.chi2FitTo()

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: none of the 4 overloaded methods succeeded. Full details:
  RooFitResult* RooAbsReal::chi2FitTo(RooDataHist& data, const RooCmdArg& arg1 = RooCmdArg::none(), const RooCmdArg& arg2 = RooCmdArg::none(), const RooCmdArg& arg3 = RooCmdArg::none(), const RooCmdArg& arg4 = RooCmdArg::none(), const RooCmdArg& arg5 = RooCmdArg::none(), const RooCmdArg& arg6 = RooCmdArg::none(), const RooCmdArg& arg7 = RooCmdArg::none(), const RooCmdArg& arg8 = RooCmdArg::none()) =>
    unbound method RooAbsReal::chi2FitTo must be called with a RooAbsReal instance as first argument
  RooFitResult* RooAbsReal::chi2FitTo(RooDataHist& data, const RooLinkedList& cmdList) =>
    unbound method RooAbsReal::chi2FitTo must be called with a RooAbsReal instance as first argument
  RooFitResult* RooAbsReal::chi2FitTo(RooDataSet& xydata, const RooCmdArg& arg1 = RooCmdArg::none(), const RooCmdArg& arg2 = RooCmdArg::none(), const RooCmdArg& arg3 = RooCmdArg::none(), const RooCmdArg& arg4 = RooCmdArg::none(), const RooCmdArg& arg5 = RooCmdArg::none(), const RooCmdArg& arg6 = RooCmdArg::none(), const RooCmdArg& arg7 = RooCmdArg::none(), const RooCmdArg& arg8 = RooCmdArg::none()) =>
    unbound method RooAbsReal::chi2FitTo must be called with a RooAbsReal instance as first argument
  RooFitResult* RooAbsReal::chi2FitTo(RooDataSet& xydata, const RooLinkedList& cmdList) =>
    unbound method RooAbsReal::chi2FitTo must be called with a RooAbsReal instance as first argument
>>> R.RooGaussian.chi2FitTo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: RooFitResult* RooAbsPdf::chi2FitTo(RooDataHist& data, const RooLinkedList& cmdList) =>
    unbound method RooAbsPdf::chi2FitTo must be called with a RooAbsPdf instance as first argument
>>> R.RooGenericPdf.chi2FitTo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: RooFitResult* RooAbsPdf::chi2FitTo(RooDataHist& data, const RooLinkedList& cmdList) =>
    unbound method RooAbsPdf::chi2FitTo must be called with a RooAbsPdf instance as first argument
>>> 

Is there a way to make these exposed in user code?

Hi @adam.davis,

thanks for reporting that. Can you reach the different overloads if you actually pass the mandatory first argument? Without arguments, none of the function calls can work.

I agree that the reporting might be broken, but we are working on a new PyROOT where this hopefully will work in a more consistent way.

I actually tried reaching the different overloads first with a full blown analysis, but actually couldn’t reach them at all, so tried to get the minimal working example. Here’s a reproduction:

Python 3.7.4 (default, Sep  7 2019, 18:27:02) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT as R
>>> mu = R.RooRealVar("mu","mu",-1.0,1.0)

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

>>> sig = R.RooRealVar("sig","sig",0.1,1.0)
>>> x = R.RooRealVar(
... "x","x",-5,5)
>>> g = R.RooGaussian("g","g",x,mu,sig)
>>> ds = R.RooDataSet("ds","ds",R.RooArgSet(x,mu,sig))
>>> g.chi2FitTo(ds)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: RooFitResult* RooAbsPdf::chi2FitTo(RooDataHist& data, const RooLinkedList& cmdList) =>
    takes at least 2 arguments (1 given)
>>> 

Ok, that’s indeed a shortcoming of PyROOT. It doesn’t understand if a function overload comes into a derived class with using.
I can write an explicit python function for that. I will track the progress here:
https://sft.its.cern.ch/jira/browse/ROOT-10503

Update

Tomorrow (Tue 14th), they should work in ROOT’s nightly:
https://root.cern/nightlies

Workaround for old ROOT versions

As a temporary workaround, call it with an empty RooLinkedList as second argument as suggested in the first mention of this problem:
https://sft.its.cern.ch/jira/browse/ROOT-7938

arglist = R.RooLinkedList()
testfunc.chi2FitTo(testdata, arglist)

Note that if you want to put items into the list, you need to keep a python object alive:

arglist = R.RooLinkedList()
saveArg = R.RooFit.Save()
arglist.add(saveArg)
testfunc.chi2FitTo(testdata, arglist)

If you don’t keep saveArg, python will just delete it because it doesn’t know that this object is also being used in C++.

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