Converting RooAbsReal to RooAbsPDF

I would like to use the “generateBinned” function from RooAbsPdf to generate random data on a histogram. However, the class that I have written is inherited from RooAbsReal instead. Is there a function that can convert RooAbsReal to RooAbsPdf?

Hi @delick ,

and welcome to the ROOT forum. We need @jonas 's help here, let’s ping him.

Cheers,
Enrico

Hi @delick, welcome to the ROOT forum!

For this usecase there is the RooWrapperPdf.

Cheers,
Jonas

Hi @Jonas, I think that solves the problem, many thanks!

Hi @Jonas, I realised that I am using roofit version 6.16. In that version, there isn’t RooWrapperPdf. Is there another function that allows me to do what I want?

ROOT 6.16 is already more than 3 years old, and it’s really worth to upgrade to newer versions because lots of things have improved in RooFit in the meantime.

But what you can do for 6.16 is also to use the RooWrapperPdf, you just need to copy-paste the RooWrapperPdf header file from ROOT master into your project and include it. When you update to a newer ROOT release eventually, you can remove the RooWrapperPdf.h from your own project again.

I did try to copy the RooWrapperPdf.h into the “include” folder of my program and then type #include <RooWrapperPdf.h> in my .cc file that uses RooWrapperPdf. However, it came back with some errors (see screenshot)

Do you need to save these RooWrapperPdf objects to a ROOT file? If not, the simplest solution is to remove this line from the header file:

ClassDefOverride(RooWrapperPdf,1)

If you need to write your models RooWrapperPdf to a file, let me know and I’ll think about what the right solution is then.

I don’t need to, I will try that method, thanks!