RooFit PDF from a TKDE

Dear experts,

I have used a TKDE ( to describe an invariant mass distribution in Monte Carlo which is not easily described by analytical PDFs in RooFit. This has the advantage over a RooKeysPdf that one can bin internally, which greatly increases the speed.

I am wondering whether it is possible in some way to form a RooFit PDF (preferably a parametric one) from a TKDE? It was suggested in this post that it may be possible:

but I am not exactly sure how to do it. Any help would be greatly appreciated!

Many thanks,


If you want a KDE sampled in n points, you should call the TKDE::GetFunction method to return the TKDE as a TF1. You can then transform the TF1 in a RooAbsPdf using the RooTfnPdfBinding class
(see )

If you want to use directly the TKDE, without sampling it, but re-computing it every time, you can then first use the ROOT::Math::Functor1D class to transform the TKDE in a 1D function interface ( ROOT::Math::IBaseFunctionOneDim),
which can then be used by the class RooFunctor1DPdfBinding to be transformed in a RooAbsPdf.

If you need I could you provide an example on how to do this,

Best Regards



If you need I could you provide an example on how to do this,

Best Regards


Hi Lorenzo, could you indeed do that?



Hi Antonio,

could you manage to do this? I am having the same issue and wondering how this can be done.

Thank you very much!

Hi Francisco,

Here is an example where you can use TKDE to build a RooAbsPdf.
If you have any question please let me know,
test_RooKeys.C (1.6 KB)



1 Like

Hi Lorenzo,

thank you very much!