Problem with number of bins when using generateBinned

Dear RooFitters,

I have an issue when trying to generate a distribution from a binned pdf. You will find an example of minimal code attached to this entry, as well as the necessary input files.

In a nutshell, I want to generate events from a pdf stored in a TH1 and save the results back to a TH1. Here’s how I am attempting to do this:
1- Build a distribution in a TH1D to be used as a pdf for the generation
2- Create a RooDataHist out of this TH1D
3- Create a RooHistPdf out of this RooDataHist (to be able to use the generate methods)
4- call generateBinned() on the resulting RooHistPdf
5- Create a TH1D out of the resulting RooDataHist (requesting there to have the same binning as for the TH1D in step 1)

I would naively expect from this to obtain a rather smooth distribution using the original binning. Turns out something goes wrong at step 4, where I am outputting the resulting RooDataHist to the RooFrame in the code and one can clearly see that roughly one bin out of 2 (sometimes 3) have 0 content. I am not sure to understand why that is. Can someone point me to what I am doing wrong?

Thanks in advance for your help,

Andrée
Test_RooFit_E.root (5.25 KB)
Test_RooFit_D.root (5.27 KB)
generate_test.c (1.8 KB)

Hello,

It will work if you also specify the binning of the obervable’s RooRealVar to match the one in the model.

    x = new RooRealVar("x","m_{ee} (GeV)",0.,25.);
    x->setBins(250);

Cheers,

– Gregory

Thanks a lot Gregory, it works like a charm now!!

Cheers,

Andrée

Dear RooFit Experts,

I have a similar problem, as already been discussed in this thread.
I am performing a chi2 fit using RooFit. However, I face an issue while trying to generate a distribution from a binned pdf.

What I am doing is as follows:

  1. Obtain a distribution in a TH1D to be used as a pdf for the generation
  2. Create a RooDataHist out of this TH1D using RooRealVar
  3. Create a RooHistPdf out of this RooDataHist
  4. Create a RooAddPdf using RooHistPdf and RooRealVar
  5. Create a TH1D out of the resulting RooAddPdf using the method createHistograms() (requesting it to have the same binning as for the TH1D in step 1)

No matter what I do, I always get number of bins = (original number - 1) in the last step. Clearly, there is something which I am not doing correctly. Can someone please help me to solve this problem?

I am attaching the code that I am using.

Thanks in advance!

Best Regards,
Ridhi

fitTemplates.C (9.3 KB)
<a class=“attachment” href="/uploads/default/original

Dear Experts,

Concerning the issue (posted above), I get the following message when I run my code:

[#1] INFO:InputArguments – RooAbsReal::createHistogram(model) INFO: Model has intrinsic binning definition, selecting that binning for the histogram

Is there any way to forcefully disable this intrinsic binning functionality and use some specific binning?

Best Regards,
Ridhi