# Issue with RooDataSet

**URL:** <https://root-forum.cern.ch/t/issue-with-roodataset/63611>\
**Category:** ROOT\
**Tags:** python, root\
**Created:** [May 26, 2025, 11:25am UTC](https://root-forum.cern.ch/t/issue-with-roodataset/63611 "2025-05-26T11:25:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdgalati](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mdgalati/32/29563_2.png) [@mdgalati](https://root-forum.cern.ch/u/mdgalati)\
**Post date:** [May 26, 2025, 11:25am UTC](https://root-forum.cern.ch/t/issue-with-roodataset/63611/1 "2025-05-26T11:25:38Z")

</div>

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:

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

```

where

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![mdgalati](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mdgalati/32/29563_2.png) [@mdgalati](https://root-forum.cern.ch/u/mdgalati)\
**Post date:** [May 26, 2025, 11:35am UTC](https://root-forum.cern.ch/t/issue-with-roodataset/63611/2 "2025-05-26T11:35:01Z")

</div>

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`:

```python
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:

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

```

**Proposed Solution:**

Modify line 132 in `PDFandMC.py` from:

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

```

to:

```python
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`.

```auto

```

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 26, 2025, 4:17pm UTC](https://root-forum.cern.ch/t/issue-with-roodataset/63611/3 "2025-05-26T16:17:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [May 26, 2025, 5:33pm UTC](https://root-forum.cern.ch/t/issue-with-roodataset/63611/4 "2025-05-26T17:33:27Z")

</div>

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](https://root.cern/doc/v632/release-notes.html#deprecation-and-removal). 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

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [June 9, 2025, 5:33pm UTC](https://root-forum.cern.ch/t/issue-with-roodataset/63611/5 "2025-06-09T17:33:59Z")

</div>

Closed on June 9, 2025, 5:33pm UTC

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