# Evaluating PDF in extended x-range based on its parameters

Hi Experts,

I have a question regarding defining a PDF P(x) in extended range of x based on its parameters.

For example, for a function f(x) one can do TF1::Eval(x) for any real value of x, but in case of a PDF, Is there any method equivalent to Eval()? and how to take care of normalization after getting PDF in the extended range of x?

Actually, I have a PDF `P(-1 < x < 1)` and is there any way to get `P(-2 < x < 2)` based on its parameters?

Thanks and regards
Himanshu

Hi Hianshu,

With PDF you mean RooAbsPdf or whatâ€™s the type of `P`?

Axel

Hi @Axel

It is RooAddPdf with two RooGaussians and 1 RooGenericPdf.

Himanshu

Hi experts,
Is there any way to implement it?
Thank you!

Thanks a tricky thing, there is no easy way to do that in RooFit that generalized to all kinds of pdfs.

Without going too much into detail here, is is okay for you to just do the normalization by hand with some helper function where you are getting the correction factor?

``````double getRangeFactor(RooAbsPdf& pdf,
RooArgSet const& normSet,
const char* rangeName) {
// to get the correct result, the normalization set of the integral
// (2nd argument) has to be the same normalization set that you pass
// to pdf.getVal().
return 1./std::unique_ptr<RooAbsReal>{
pdf.createIntegral(normSet, &normSet, nullptr, rangeName)
}->getVal();
}

void demo() {

using namespace RooFit;

RooRealVar x("x", "x", 0., -1, 1);
x.setRange("r2", -2, 2);

RooGaussian g1("g1", "g1", x, RooConst(0), RooConst(1.0));
RooGaussian g2("g2", "g2", x, RooConst(0), RooConst(2.0));
RooAddPdf pdf("pdf", "pdf", {g1, g2}, {RooConst(0.5)});

double rangeFactor = getRangeFactor(pdf, x, "r2");

std::cout << pdf.getVal(x) << std::endl;
std::cout << (rangeFactor * pdf.getVal(x)) << std::endl;
}
``````

Hope this helps!
Cheers,
Jonas

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.