chi2FitTo does not take arguments in pyroot

I have used FitTo to perform fits on a roofit extended pdf, using the syntax below.

self.fitresult = self.func_pdf.chi2FitTo( self.datahist,
                                 RooFit.Range("runfit"),
                                 RooFit.SumCoefRange("runfit"),
                                 RooFit.SumW2Error(True), 
                                 ROOT.RooCmdArg( 'Strategy', 3 ) ,   
                                 RooFit.Save(ROOT.kTRUE))

I try to switch to chi2 fit by only changing FitTo to chi2FitTo and it gives me the following error. It seems that the pyroot method is bound to the C method that takes a RooLinkedList instead of several option arguments. i.e. RooAbsPdf::chi2FitTo(RooDataHist& data, const RooLinkedList& cmdList) I checked that chi2FitTo and FitTo are overloaded in the same way in the C++ source code so I am surprised they have different behavior.

I wonder if there is any workaround. If the only way is to use RooLinkedList, how do I do that?
root version: 6.06.00

Traceback (most recent call last):
  File "./MakeZFit.py", line 608, in <module>
    main()
  File "./MakeZFit.py", line 161, in main
    basesel=baseeta+failpix+ltmet,tag="regB"+tbase,ic = ic,maxtimes=150,doData=doData)
  File "./MakeZFit.py", line 231, in makevariableplots_simultaneous
    tag=tag, ic = ic, xbins=(200,0,200), dobkgd =dobkgd, maxtimes = maxtimes, doData=doData)
  File "./MakeZFit.py", line 296, in fitting_simultaneous
    tag=tag,ic = ic, maxtimes =maxtimes)
  File "./MakeZFit.py", line 352, in corefitting_simultaneous
    froo_dcb = fm.run_fit_chi2(fr)
  File "/home/kakw/efake/WG_Analysis/Plotting/FitManager.py", line 406, in run_fit_chi2
    RooFit.Save(ROOT.kTRUE))
TypeError: RooFitResult* RooAbsPdf::chi2FitTo(RooDataHist& data, const RooLinkedList& cmdList) =>
    takes at most 2 arguments (6 given)

Hello @sciencecw,

chi2FitTo with >2 arguments is not reimplemented for RooAbsPdf, and that’s apparently why pyroot does not call it:
https://root.cern.ch/doc/master/classRooAbsPdf.html#a386ac5a52a6fcac9b2c5d80743ad6309

The base class RooAbsReal does have the overload you are looking for
https://root.cern.ch/doc/master/classRooAbsReal.html#ab4fd4f71f1cee1f8bce9811801f7c40f
and we should find out how to call it.

@etejedor might know how we can convince pyroot to do that.

HI @sciencecw

This indeed looks like a bug in the overload resolution of PyROOT, could you try with a newer ROOT version (6.14) to see if the problem is there?

Also, could you post here a minimal reproducer that we can run to check the issue?

Thank you,
Enric

You can set up a new ROOT version from cvmfs. You can find instructions on the following page under CVMFS:
https://root.cern.ch/content/release-61406

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