Segfault in RooAbsReal::createIntegral() getVal() with 6.26

Hello,

I’m updating some statistics code to work with the various changes introduced to RooFit in 6.26 compare to 6.24. I’ve run into a segfault when calling getVal() after using RooAbsReal::createIntegral(). Any help or suggestions would be appreciated as I’m a bit stuck. The stack trace (below) isn’t making it obvious what is wrong and I’m not sure what exactly changed from 6.24 that broke this setup.

I’ve attached test.C where I have duplicated the calls leading to the segfault. The script does not crash with 6.24/00 using a workspace I made in 6.24/00 (test624.root), but reproduces the problem in 6.26/08 with a workspace made in 6.26/08 (test626.root). This code is filling a TH1 by integrating a PDF in each bin. (I saw that there are some changes to PDF normalization that I might need to take into account here, but hopefully that is a separate issue).
test.C (2.3 KB)
test624.root (35.8 KB)
test626.root (33.2 KB)

Stacktrace:

#6  0x00007fe1b4df1791 in ParamHistFunc::computeBatch(cudaStream_t*, double*, unsigned long, RooFit::Detail::DataMap const&) const () from 
#7  0x00007fe1b616886b in ROOT::Experimental::RooFitDriver::getVal() () from 
#8  0x00007fe1b6168930 in ROOT::Experimental::RooFitDriver::getValues() () from 
#9  0x00007fe1b600f14f in RooAbsReal::getValues(RooBatchCompute::RunContext&, RooArgSet const*) const () from 
#10 0x00007fe1b5ff8987 in RooAbsPdf::getValues(RooBatchCompute::RunContext&, RooArgSet const*) const () from 
#11 0x00007fe1b61b8261 in RooRealBinding::getValuesOfBoundFunction(RooBatchCompute::RunContext&) const () from 
#12 0x00007fe1b605f522 in RooBinIntegrator::integral(double const*) () from 
#13 0x00007fe1b5fe355a in RooAbsIntegrator::calculate(double const*) () from 
#14 0x00007fe1b61bb030 in RooRealIntegral::sum() const () from 
#15 0x00007fe1b61bc711 in RooRealIntegral::evaluate() const () from 
#16 0x00007fe1b6019877 in RooAbsReal::traceEval(RooArgSet const*) const () from 
#17 0x00007fe1b61b9c70 in RooRealIntegral::getValV(RooArgSet const*) const () from

Thanks,
Jonathan

Hi @longjon,

I very sorry you’re having these troubles! I know about this problem, and it will be fixed in the upcoming patch release ROOT 6.26.12 and also the upcoming ROOT release 6.28.

Fortunately, I think I see a way to circumvent the problem with the RooRealSumPdf integral for now.

Most of your code seems completely redundant: you are integrating a RooRealSumPdf over the exact bins that define it, only to divide by the bin width again, which is like undoing the integral. That’s a very expensive way of evaluating the RooRealSumPdf itself!

Probably this funny hack was done to circumvent another bug longstanding bug in RooFit: getPropagatedError() didn’t work for the RooRealSumPdf directly. This bug will also be fixed in ROOT 6.28 with a reimplementation of RooAbsReal::getPropagatedError().

So what I can suggest to you is to simply evaluate the PDF itself, and then do the error propagation with a copy-pasted version of the getPropagatedError() function from the ROOT 6.28 source code on GitHub.

I have attached an updated script:
testJonas.C (5.9 KB)

By the way, like this you also avoid a big memory leak, as you didn’t correctly delete the integral that was returned by createIntegral.

I hope this solution works for you, otherwise let me know!

PS: ROOT 6.28 will be out in late January probably, and the date for the 6.26.12 patch release still needs to be decided.

Cheers,
Jonas

Hi @jonas,

Thanks very much for the quick, thorough, and helpful reply! I’ll play around with your suggestion to make sure I can get everything working and I’ll keep an eye out for the new releases.

Yes there is some redundancy as I was trying to condense several layers of this framework’s calls into a smaller test. Though, the code has been around a while, so you’re right, there is probably some code bloat to simplify.

Thanks and happy holidays,
Jonathan

Hi!

Yes there is some redundancy as I was trying to condense several layers of this framework’s calls into a smaller test.

I assumed so. Thanks for setting up the reproducer! Maybe one method that can help when creating a more general workaround is RooAbsReal::isBinnedDistribution(), in case you are not aware of it. With this you can test is your PDF is a constant in each bin, and then you don’t need to integrate. Because it’s the integration of binned PDFs that is broken.

If this is not general enough and you need a fix before the new releases, you can in the worst case just swap out the broken RooBinIntegrator class with the one from ROOT 6.24. And then in your framework, you replace the default integrator for binned PDFs, kind of like it is described in this tutorial:

https://root.cern.ch/doc/master/rf901__numintconfig_8C.html

Happy holidays to you too!
Jonas

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