How to properly redefine pdf in RooWorkspace?

ROOT version:6.24/06
Platform: lxplus7

Dear ROOT experts,

I encounter the following error when attempting to redefine existing pdfs in RooWorkspace.

The error message:

Error in <ROOT::Math::Fitter::SetFCN>: FCN function has zero parameters 
python3: /home/conda/feedstock_root/build_artifacts/root_base_1654795774398/work/root-source/math/mathcore/inc/Fit/Fitter.h:385: const ROOT::Fit::FitResul
t& ROOT::Fit::Fitter::Result() const: Assertion `fResult.get()' failed.
 *** Break *** abort

...(some segfault error messages)

Traceback (most recent call last):
  File "/afs/", line 77, in <module>
    r = pdf.fitTo(data, ROOT.RooFit.Save(True))
  File "/cvmfs/", line0, in fitTo
    return self._fitTo(*args, **kwargs)
TypeError: none of the 2 overloaded methods succeeded. Full details:
  RooFitResult* RooAbsPdf::fitTo(RooAbsData& data, const RooCmdArg& arg1 = RooCmdArg::none(), const RooCmdArg& arg2 = RooCmdArg::none(), const RooCmdArgarg3 = 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()) =>
    AbortSignal: abort from C++; program state was reset
  RooFitResult* RooAbsPdf::fitTo(RooAbsData& data, const RooLinkedList& cmdList) =>
    TypeError: could not convert argument 2

I made the following minimal code example for you to reproduce the problem.

  • The file
    1. create a new RooWorkspace
    2. import RooDataSet from RDataFrame
    3. define pdf model
    4. perform fitTo
    5. save everything to a .root file.
  • The file
    1. import RooWorkspace from that saved .root file
    2. remove all vars, pdfs, formulas and objects
    3. define new pdf model
    4. perform fitTo → where the error is triggered

Hopefully with attached files, you can reproduce my error by running

python3 # -> should run successfully
python3  # -> show the error above

PS. maybe redefining existing pdfs in RooWorkspace doesn’t require the removal of them in the first place. In RooWorkspace::factory, it seems to me that one can use the expression “EDIT:name” to redefine objects but with the given description in the webpage I don’t know how to do it. (1.1 KB) (1.6 KB)
demo.root (249.2 KB)

I’m sure @jonas can help you

Hi @Patrick_Wu,

the crash is because you forgot to define n2 in the script. This line is missing:


Furthermore, there are problems because the workspace is not fully cleared. There are still some internal caching sets left (you can see them with ws.Print("v")). You have to remove these too:


Of course, the user should not have to bother with the details of the caching, so it is a bug that these now invalid cached sets are still there. I have opened a PR to remove the cached sets when they get invalidated automatically:

I hope this helps, let me know if you have further questions!


Silly me! Thanks for not only identifying the missing line but also offering extra explanation.

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