Home | News | Documentation | Download

RooAddPdf::evaluateSpan breaks if it contains a RooUniform

I am in a situation in which I need to extract the values out of RooFit objects as a contiguous sequence. The newly introduced batch interface is perfect for this.

However, I noticed that when my model (a RooAddPdf) contains a RooUnifom, getValues crashes inside RooAddPdf::evaluateSpans, either with an assertion (if they are enabled) or with a segfault.

By looking inside I noticed that RooUniform in case of multiple observables creates a span of size nData^dims instead of just nData, which breaks the assumptions of RooAddPdf.

Since batchmode fits actually work, I investigated a bit and it appears that in fits this works due to const pdf optimization, which bypasses RooUniform::evaluateSpan and fills the datastore with cached values. A fit using Optimize(false) confirmed that this is the case.

A possible very bad workaround that I found is to create a nll, call constOptimizeTestStatistic on it without actually minimizing and then extract the cloned dataset and pdf from there for computation.

I attach here a short script which triggers the failure both on 6.24 and on master (or, to be more precise, dev4 and dev3 from lcg).

testUniformBatch.C (1.7 KB)

Is this a bug? Or am I using the batch interface in the wrong way?

Thank you in advance,

@jonas can you help?

Hi @elusian,

thanks for reporting this problem in the forum! I think this is a bug. The size of the output span of RooUniform should correspond to the size of the inputs, not to the product of all the input sizes.

I made a PR to fix this in ROOT master, and the fix will also be backported to the next 6.24 patch release, which should be released soon.

I hope this solution is good for you! Is it okay for you to use the workaround until the next patch release?

Let me know if you have any further questions or comments!


Hello @jonas

thank you for the fix. For now I can live with the workaround, the main issue with it is that it ties a single pdf with a single dataset, so if you have multiples it starts being a bit unwieldy.

For the future, is this the right place to report such a bug? Or should I have used the issue feature of GitHub?


Hi @elusian,

you’re welcome! There are also other workarounds that might be more convenient for you. For example, you could also take the fixed RooUniform code from the ROOT master branch on GitHub, rename the class and use it in your project.

Yes, and in the future, consider that the right way to report bugs is to open an issue on GitHub. The forum is mainly for questions on ROOT usage, not for reporting bugs.