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 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;
}