Issue with RooDataSet

I’m encountering a TypeError when creating a RooDataSet from a TTree, using code that previously worked without issues a few months ago.

The problematic line seems to be:

R.RooDataSet('data', 'data', t_data, vars)

where

vars = R.RooArgList( mass, mva_score )
...
f_data = R.TFile.Open(file_path)
t_data = f_data.Get("DecayTree")

This used to run fine, but now I get the following error:

Traceback (most recent call last):
  File "/data/bfys/mgalati/RapidSim/scripts/PDFandMC.py", line 191, in <module>
    pdf_list, N_list = pdfmaker.make_PDFandYields(PDFdecays, vars)
  File "/data/bfys/mgalati/RapidSim/scripts/PDFandMC.py", line 152, in make_PDFandYields
    pdf_model_X = self.make_PDF(decay, vars)
  File "/data/bfys/mgalati/RapidSim/scripts/PDFandMC.py", line 132, in make_PDF
    data = R.RooDataSet('data', 'data', t_data, vars) # RooDataSet: holds unbinned data
  File "/data/bfys/mgalati/RapidSim/miniforge/envs/bc2taunu/lib/python3.9/site-packages/ROOT/_pythonization/_roofit/_roodataset.py", line 43, in __init__
    self._init(*args, **kwargs)
TypeError: none of the 5 overloaded methods succeeded. Full details:
  RooDataSet::RooDataSet(RooStringView name, RooStringView title, const RooArgSet& vars, const RooCmdArg& arg1 = {}, const RooCmdArg& arg2 = {}, const RooCmdArg& arg3 = {}, const RooCmdArg& arg4 = {}, const RooCmdArg& arg5 = {}, const RooCmdArg& arg6 = {}, const RooCmdArg& arg7 = {}, const RooCmdArg& arg8 = {}) =>
    TypeError: could not convert argument 1
  RooDataSet::RooDataSet(RooStringView name, RooStringView title, RooDataSet* data, const RooArgSet& vars, const RooFormulaVar& cutVar, const char* wgtVarName = nullptr) =>
    TypeError: takes at least 5 arguments (4 given)
  RooDataSet::RooDataSet(RooStringView name, RooStringView title, RooDataSet* data, const RooArgSet& vars, const char* cuts = nullptr, const char* wgtVarName = nullptr) =>
    TypeError: could not convert argument 1
  RooDataSet::RooDataSet(const RooDataSet& other, const char* newname = nullptr) =>
    TypeError: takes at most 2 arguments (4 given)
  RooDataSet::RooDataSet() =>
    TypeError: takes at most 0 arguments (4 given)

Has something changed recently in PyROOT or ROOT that would explain this?

Incredibly, Gemini managed to solve the issue (see below). I still don’t get why my code was working before and suddenly not anymore?

Gemini’s answer:
The error message TypeError: none of the 5 overloaded methods succeeded for RooDataSet::RooDataSet indicates that the constructor call at line 132 in PDFandMC.py:

data = R.RooDataSet('data', 'data', t_data, vars)

does not match any of the valid RooDataSet constructors. Let’s break down why and how to fix it.

Understanding the RooDataSet Constructors:

The error output lists several overloaded constructors for RooDataSet. The most relevant ones for creating a dataset from a TTree (which t_data likely is) are usually:

  1. RooDataSet::RooDataSet(RooStringView name, RooStringView title, const RooArgSet& vars, const RooCmdArg& arg1 = {}, ...): This constructor is for creating a dataset from a TTree when you explicitly provide the RooArgSet of variables. The RooCmdArg parameters are for optional arguments like Import or Store.

  2. RooDataSet::RooDataSet(RooStringView name, RooStringView title, RooDataSet* data, const RooArgSet& vars, ...): This is for creating a new dataset from an existing RooDataSet with potential cuts or weight variables. This doesn’t seem to be your intent.

Why Your Call Fails:

Your call R.RooDataSet('data', 'data', t_data, vars) provides four arguments:

  • 'data' (string for name)
  • 'data' (string for title)
  • t_data (presumably a ROOT.TTree or similar object)
  • vars (presumably a ROOT.RooArgSet or similar object)

Looking at the first relevant constructor: RooDataSet::RooDataSet(RooStringView name, RooStringView title, const RooArgSet& vars, const RooCmdArg& arg1 = {}, ...), it expects a RooArgSet as the third argument, not a TTree.

The Correct Way to Create a RooDataSet from a TTree:

When creating a RooDataSet from a TTree, you typically use the Import command argument. The structure is usually:

R.RooDataSet(name, title, ttree_object, variables_RooArgSet, RooFit.Import(ttree_object_again))

Proposed Solution:

Modify line 132 in PDFandMC.py from:

data = R.RooDataSet('data', 'data', t_data, vars)

to:

data = R.RooDataSet('data', 'data', vars, R.RooFit.Import(t_data))

Explanation of the fix:

  • 'data', 'data': These are the name and title of the RooDataSet.
  • vars: This is the RooArgSet containing the RooRealVar objects that define the variables you want to include in your dataset. This must be the third argument when using RooFit.Import.
  • R.RooFit.Import(t_data): This is the crucial part. RooFit.Import() is a RooCmdArg that tells RooDataSet to populate itself with data from the specified TTree (t_data).

This corrected call aligns with the expected signature for creating a RooDataSet from a TTree.

Hi Maria Domenica,

Thanks for the report and the solution!
I am adding in the loop @jonas , the RooFit expert, for his information.

Best,
D

1 Like

Hi @mdgalati,

thanks for asking and sharing the solution! Indeed, it’s expected that it doesn’t work. I’m making an effort to reduce the RooFit interface a bit such that there won’t be two interfaces to do the same thing anymore, if there is not a good reason. Some RooDataSet constructors are gone, as you noticed. This is also mentioned in the release notes for 6.32. They were deprecated in 6.32 and removed in 6.34, which is the release that is now in Conda. That’s probably why you got the error now.

Hope that makes it a bit clearer and sorry for the inconvenience! Reducing duplicate interfaces also helps to keep bugs out of RooFit, since there is no duplicate code.

Cheers,
Jonas

2 Likes