Home | News | Documentation | Download

How to use a histogram pdf in Roofit

Dear Expert,

I am trying to use a histogram pdf (RooHistPdf) for pi0_ErrM in a 2D fit as given in this link ROOT: tutorials/roofit/rf307_fullpereventerrors.C File Reference.
But in my case, it’s taking too much time (about 1 hour) to run. Here is the folder that I am using: 2D_fit.zip (207.9 KB)

Can you please tell me why this is taking time to run?

Regards
Chanchal

Hi @chanchal!

This is taking a long time to run because of 1) numerical integration and 2) you forgot to add the ProjWData(*dataxy) argument to your plotOn commands.

Adding the ProjWData is trivial, but the numerical integration is a bit more specific. Since your Gaussian is conditional on sigma which depends on an observable from the data via some RooFormulaVar, RooFit will do a numeric integration for each event to normalize the Gaussian.

The problem with RooGaussian in your application is that it doesn’t normalize itself to save computation time. But if the normalization factor is different for every event because it’s a conditional fit, this optimization is not meaningful anymore. What I would do is to implement a little self-normalized Gaussian class for this fit to avoid integrals altogether.

I implemented this in a modified version of your script, also adding the missing ProjWData(*dataxy) in the plotting:
unbinned_2D_fit_Kpipi0_RS_pi0M_conv_new_histo_v2.C (6.2 KB)

I hope this helps! If you have any further questions, please let me know.

Cheers,
Jonas

Hii @jonas,

Thanks a lot for your help.
However, I have one more question regarding this.

If you check here: https://root-forum.cern.ch/t/how-to-use-a-histogram-pdf-in-roofit/44560, in the macro, she has used a conditional Pdf as well, but in this case, you have not added the patch of code to normalize.

Why is this so?
Is it because , here she is measuring the yield, and the fit if Extended (true)?

Regards
Chanchal

Hi @chanchal,

thanks for your answer! Your link points back to this exact thread :smiley: Can you please fix it so I can see which post your are talking about?

Thanks!

Hii @jonas,

Sorry, I am talking about this below post:

Regards
Chanchal

Hi @chanchal, thanks for correcting the link.

The problem reported in that other post was about making the RooProdPdf work with a RooPolyVar, so I only focused on that issue and didn’t make any further comments. But yes, now that I try to run it I agree with you: that fit would also benefit from some patching to avoid the numerical integrals.

You on the other hand asked more specifically why your script runs so slow, so I took a deeper look.

If you have further questions, please let me know!

Jonas

Hii,

Thanks for your answer.

Regards
Chanchal