# Crashes when using RooDataSet on PyROOT

**URL:** <https://root-forum.cern.ch/t/crashes-when-using-roodataset-on-pyroot/43411>\
**Category:** Newbie\
**Tags:** roofit, python\
**Created:** [February 5, 2021, 2:38pm UTC](https://root-forum.cern.ch/t/crashes-when-using-roodataset-on-pyroot/43411 "2021-02-05T14:38:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrli](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@mrli](https://root-forum.cern.ch/u/mrli)\
**Post date:** [February 5, 2021, 2:38pm UTC](https://root-forum.cern.ch/t/crashes-when-using-roodataset-on-pyroot/43411/1 "2021-02-05T14:38:47Z")

</div>

Dear all,  
I’m using PyROOT and met a strange problem. Here I post my test code.

```auto
bmass = RooRealVar('bmass', 'bmass', 0)
bpx = RooRealVar('bpx', 'bpx', 0)
bpy = RooRealVar('bpy', 'bpy', 0)
bpz = RooRealVar('bpz', 'bpz', 0)
bpe = RooRealVar('bpe', 'bpe', 0)

data = RooDataSet('data', 'data', RooArgSet(bmass, bpx, bpy, bpz, bpe), RooFit.ImportFromFile("file","Tree")
# This tree contains 5 branches named bmass,bpx,bpy,bpz,bpe

```

I ran these codes by

```auto
python3 -i test.py

```

At first I want to get a binned dataset, so I ran

```auto
data.binnedClone()

```

It threw me

```auto
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cppyy.gbl.std.bad_alloc: RooDataHist* RooDataSet::binnedClone(const char* newName = 0, const char* newTitle = 0) =>
    bad_alloc: std::bad_alloc

```

The same crash would also occure on ROOT, which seems due to too many branches. So I tried to reduce other variables and made a little mistake ( Used an improper method):

```auto
data.reduce(RooFit.SelectVars(bmass))

```

It threw me

```auto
# Preceding report has been omitted

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: none of the 5 overloaded methods succeeded. Full details:
  RooAbsData* RooAbsData::reduce(const RooArgSet& varSubset, const RooFormulaVar& cutVar) =>
    TypeError: takes at least 2 arguments (1 given)
  RooAbsData* RooAbsData::reduce(const RooCmdArg& arg1, const RooCmdArg& arg2 = RooCmdArg(), const RooCmdArg& arg3 = RooCmdArg(), const RooCmdArg& arg4 = RooCmdArg(), const RooCmdArg& arg5 = RooCmdArg(), const RooCmdArg& arg6 = RooCmdArg(), const RooCmdArg& arg7 = RooCmdArg(), const RooCmdArg& arg8 = RooCmdArg()) =>
    SegmentationViolation: segfault in C++; program state was reset
  RooAbsData* RooAbsData::reduce(const RooFormulaVar& cutVar) =>
    TypeError: could not convert argument 1
  RooAbsData* RooAbsData::reduce(const char* cut) =>
    TypeError: could not convert argument 1 (bad argument type for built-in operation)
  RooAbsData* RooAbsData::reduce(const RooArgSet& varSubset, const char* cut = 0) =>
    TypeError: could not convert argument 1

```

Although I finally got back to the right way ( Use RooDataSet() to create another single-variable dataset and make it binned), I’m confused why these happened ( Or whether I should report these?)

Thanks all!

_ROOT Version:_ 6.22.02  
_Platform:_ Ubuntu 20.04

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [February 8, 2021, 8:53am UTC](https://root-forum.cern.ch/t/crashes-when-using-roodataset-on-pyroot/43411/2 "2021-02-08T08:53:42Z")

</div>

Hi,  
Can you please post your full code and file so we can run it and see exactly what the issue is ?  
Thank you

Lorenzo

---

<div class="post-metadata">

**Author:** ![mrli](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@mrli](https://root-forum.cern.ch/u/mrli)\
**Post date:** [February 8, 2021, 10:27am UTC](https://root-forum.cern.ch/t/crashes-when-using-roodataset-on-pyroot/43411/3 "2021-02-08T10:27:24Z")

</div>

Hi,

```auto
from ROOT import *

# Generate a data
obsDict = dict()
modelDict = dict()
tmpDataDict = dict()
dimension = 5

mean = RooRealVar('mean', 'mean', 3000)
sigma = RooRealVar('sigma', 'sigma', 20)

for i in range(0, dimension):
    obsDict[i] = RooRealVar('gauss%d' % i, 'obs%d' % i, 0)

    modelDict[i] = RooGaussian('model%d' % i,
                               'model',
                               obsDict[i],
                               mean,
                               sigma)

    tmpDataDict[i] = modelDict[i].generate(obsDict[i], 200000)

data = tmpDataDict[0]
for i in range(1, dimension):
    data.merge(tmpDataDict[i])

# Crash 1:
# data.binnedClone()

# Crash 2:
# data.reduce(RooFit.SelectVars(obsDict[0]))

```

For Crash1, it seems that it would threw me crash when dimension \> 4, and Python would be dirrectly killed when dimension = 4.

For Crash 2, no matter how much the dimension is, it would always threw the crash.

Thanks
