Combining RooFormulaVar with RooAbsPdf

Hi all,

I have been trying to combine a RooFormulaVar with a RooAbsPdf. To do so I am using a RooEffProd which works fine when using my model for fitting. When I am trying to do a toy study of my model though I am not able to generate the events as I am getting the following error:

[#0] ERROR:Generation – RooEffGenContext::qcdCor_pdf_2b:generateEvent: value of efficiency is larger than assumed maximum of 1.

I have tried converting the RooFormulaVar to RooGenericPdf and then using RooProdPdf instead of the RooEffProd but I am not getting the same results during the fit.

I am attaching a simple code to show my problem.
Thank you in advance.

Best regards,
templates_Bkg_2016.root (13.5 KB)
ToyMCTest.cpp (608 Bytes)

Hi Ioannis,

what are you trying to do exactly? The EffProd, as the name indicates, is only for efficiencies. Is the formula an efficiency?
If you want to scale a PDF with an arbitrary scale factor, you can use the RooAddPdf, which implements something like
c1 * PDF1 + c2 * PDF2 + …

Hi Stephan,

thanks for the reply. I didn’t think of that, I will try to add my Formula in the scale factor and let you know if I face any problems.


Hi again,

I replace

RooEffProd pdf_qcdCor_2b(“qcdCor_pdf_2b”, “qcdCor_pdf_2b”, *pdf_qcd_2b, qcdCor_2b);


RooAddPdf addPdf(“model_2b”, “model_2b”, RooArgList(*pdf_qcd_2b), RooArgList(qcdCor_2b));

the problem I have now is that my variable mTop is both in the pdf and in the scale factor which from what I understand is not allowed. Any idea? The idea behind all this is that we want to apply a linear, x dependent correction to our pdf. I am attaching the modified code.
Thanks again for the help.

ToyMCTest.cpp (802 Bytes)

So in a sense you want to reweight the PDF, correct?

RooRealSumPdf( 1 * RooProduct( yourPdf, scaleFactor ) )

The realSumPdf will take care of correctly normalising the product such that it becomes a PDF. The product is just what the name says. :slight_smile:

In the newest RooFit, there is also the RooWrapperPdf. You can also put the product inside that, and it will start to normalise it correctly.

Hi Stephan,

I tried your solution but it does not seem to do exactly what I want. The thing it that RooEffProd and
RooProduct result in different things. The RooEffProd is with red and the RooProduct with blue

I guess this is normal but in my case even though it is not the correct way to get there. How can I get the RooEffProd result using RooProduct. I am also attaching my code in case I do something fundamentally wrong. Thank you again for the help.

ToyMCTest.cpp (925 Bytes)

This looks like normalisations are just different here. The question is presumably:

  1. Do you want to normalise the PDF first, and then multiply with the efficiency function?
  2. Do you want to take the unnormalised PDF function, and multiply with the efficiency function?
  3. Do you want to (re-)normalise 1. and/or 2.?

One of those three is different between the blue and the red curve.

Regarding the question if something can be done with the EffProd:
If your function is an efficiency, you can use the EffProd. If it is not, the EffProd cannot work, since it cannot generate events if the efficiency function is not within [0,1].

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