I’ve created a RooAddPdf containing a Gaussian and an exponential to fit to an invariant mass. When I perform the fit and plot the RooAddPdf, I see good agreement. However, if I just try to plot the exponential
Did you use the Components() notation as in the tutorial rf201?
If you just plot the PDF, it will try to normalise the background PDF to the integral of signal+background (the data that’s in the plot), and that will obviously not work.
Instead, you should plot the sum, and select a component. This way, the total sum is normalised to the data, and the component is plotted afterwards.
I see that works for plotting, but how can I grab the function and evaluate it. I’m trying to implement a simple background subtraction by hand to help debug things.
You can directly use the function, it also has the correct parameters. What you need to do, though, is to scale it correctly. The scale factor is N_evt * background fraction. For an AddPdf, you either gave a coefficient to the background, so that’s the fraction, or it’s 1 - Sum (coeffs) if you didn’t give it a coefficient.
What I wound up doing was loading the model, plotting just the component I wanted, and then using the getCurve function: auto model = (RooAddPdf*)w->pdf("model"); model->plotOn(frame, RooFit::Components("expo"), RooFit::Binning(60)); auto ex = frame->getCurve();
I could then use ex like a T1F, invoking Eval(mass). This gives a slightly different answer than: nbkg>setVal(mass); float bkg = expo->getVal() * nbkg->getVal();