A bug ?, extract a 2-D histogram based on Roofit

Hi all,

I found I extracted a 2-D histogram p·d·f based on Roofit(RooHistPdf), and drawed it

But there are some pits in the distributions.

If I change the variables range, the pit will change.

The following codes are used to check it.

code1(attachment 1) is used to generate a data sample.

code1(attachment 1) is used to draw a 2-D histo based on Roofit.

Thank you in advance.
draw.txt (766 Bytes)
toy.txt (989 Bytes)


The problem is due to the generation of events from a RooHistPdf where you have set an interpolation for the bins.
I would rather not use an interpolation (by passing 0 instead of 1 as the last parameter of the RoohistPdf constructor), in that case a binned generation is performed by default or do a binned generation of your data using RooAbsPdf::generateBinned.


A new JIRA issue has been added in JIRA for this problem


This is not a bug but it is caused by a wrong Foam configuration. By increasing the number of samples from 200 to 10000 fixes the problem.
The way to do it is to add this line before generate



Thank you for your suggestions.

Sorry, I still have the problem.
As you say, for the RooHistPdf, if I set the order as zero, the generated shape is smooth, is ok.

Now, I defined a pdfA, pdfA= pdfB*pdfC, where the pdfB is f(x,y),f(x,y) is constant plane, the pdfC is a RooHistPdf in Roofit.

The attachment is the code.

We use pdfA to generate a 2-D histo.
The histo still have a pit.

But for pdfB or pdfC sperately, the shape is smooth.

Could you help solve the problem?

I don’t know if the pdfA could be used to fit the data when the generated shape have a hole.

Do it have effect on our fitting result?

Thank you very much.

toymc.C (2.54 KB)

This problem is caused, as described before, by the small sample number used by default in Foam.
In this case, you can increase the value by default for all pdf’s used by doing


Best Regards


Thank you for your reply.

I have another question.

If we use the command “getValue” to obtain the value of the histpdf, and fill a histo. there is no pits,

TH2D * histpdf = new TH2D(“histpdf”,“HISTPDF”,200,x_min,x_max,200, x_min,x_max);
for (int i = 0; i < histpdf->GetXaxis()->GetNbins(); ++i) {
for (int j = 0; j < histpdf->GetYaxis()->GetNbins(); ++j) {
double xx = histpdf->GetXaxis()->GetBinCenter(i);
double yy = histpdf->GetYaxis()->GetBinCenter(j);
histpdf->SetBinContent(i,j, sigshape.getVal() );

does it mean that when we fit data with such histpdf, each time the histpdf is random sampled by getValue

command. In such way, the fitting precedure is ok since it will introduce no pits when fitting.

Did the histpdf influnce our fitting result ?



This effect (the pi in the histogram) is caused when generating data from the pdf. As I explained before the effect is caused by a wrong configuration used by Foam to generate events for that PDF. Incresing the number of Foam samples cure the effects.
The pdf is fine, there should be no problem to use it when fitting or getting its value