Crashes when using RooDataSet on PyROOT

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

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

python3 -i test.py

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

data.binnedClone()

It threw me

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

data.reduce(RooFit.SelectVars(bmass))

It threw me

# 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

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

Hi,

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