How to get a simple integral of a RooAbsPdf

I have a simple pdf defined for a variable x, in the range [x_min,x_max].
How can I easily find the pdf integral over a subrange, e.g. in [x0,x_max] with x0 > x_min? How over the entire range?

What if I’m working with a workspace?
So I can get variable and pdf like:

I’ve tried creating a RooRealIntegral from the pdf but I don’t find how to use it, and how it can be useful in any way.

It seems to me incredible that such a simple thing requires so much effort… :confused:


Hi Marco,

Try this approach and let me know if it solves your problem.

RooRealVar* x = w->var(“x”);
RooAbsPdf* pdf = w->pdf(“pdf”);
Double_t x0 = …;
Double_t x_max = …;

x->setRange(“my_range”, x0, x_max); // create range to integrate over
RooAbsReal* i = pdf->createIntegral(*x, RooFit::NormSet(x), RooFit::Range(“my_range”));
// alternatively: RooAbsReal
i = pdf->createIntegral(*x, *x, “my_range”);

// in my example, I am also using RooArgSet(*x) as a normalisation set; you might want to use a different one; be sure to check out the documentation for RooAbsReal::createIntegral

std::cout << "Integral value: " << i->getVal() << std::endl;