Home | News | Documentation | Download

Error while creating subsample from RooDataSet

Hello,
Following is the code that takes input as weighted RooDataSet and tries to create a reduced dataset by picking random events from that dataset.

import ROOT
f = ROOT.TFile("inputfile.root")
dataset = f.Get("sigMCReader.2016.Fit")
sumEntries = int(dataset.sumEntries())
outputBits = ROOT.TBits(int(sumEntries))
for entry in range(100):
    rnd = ROOT.gRandom.Integer(sumEntries)
    outputBits.SetBitNumber(rnd)
     
output = dataset.emptyClone("subset")
startBit = outputBits.FirstSetBit(0)
while startBit < sumEntries:
    output.Print()
    output.add(dataset.get(startBit), dataset.weight(), dataset.weightError())                                                                 
    startBit = outputBits.FirstSetBit(startBit + 1)
print("Execution successful without any runtime error!")

If I run it, gives the following error. The point to be noted is that error occurs randomly. Please let me know the bug in the code with some explanation.

  void RooDataSet::add(const RooArgSet& row, double weight = 1., double weightError = 0) =>
    SegmentationViolation: segfault in C++; program state was reset

Input root file: https://cernbox.cern.ch/index.php/s/KAvFtRS474b226p or /eos/user/p/pkalbhor/Videos/inputfile.root

I can reproduce the segfault, getting this stack trace

#6  0x00007fc074c8c4af in RooAbsCollection::tryFastFind(TNamed const*) const () from /install-debug/lib/libRooFitCore.so
#7  0x00007fc074c8c678 in RooAbsCollection::find(RooAbsArg const&) const () from /install-debug/lib/libRooFitCore.so
#8  0x00007fc074c8c97f in RooAbsCollection::operator=(RooAbsCollection const&) () from /install-debug/lib/libRooFitCore.so
#9  0x00007fc074d5a7f9 in RooDataSet::add(RooArgSet const&, double, double) () from /install-debug/lib/libRooFitCore.so

@moneta can you help?

@StephanH Please have a look.