# Get normalization factor of the plotted PDF

Dear experts,

I would like to know how many events Roofit used to renormalize the PDF when plotted, or I want to get directly the normalization factor. I don’t know how to get this information, and I explain below the case I am dealing with, which is not trivial.

I have a simple TDCPV example, using a `RooBCPGenDecay` to model the signal, and a simple gaussian for the background. I combined them using `RooAddPdf`:

``````# Background PDF
mgBkg = r.RooRealVar("mgBkgB", "mg", 0)
sgBkg = r.RooRealVar("sgBkg1", "sg2", 4.3)
bkgPDF = r.RooGaussian("bkgPDF", "gauss", dt, mgBkg, sgBkg)

# BCPGenDecay model
BCPGenDecayPDF = r.RooBCPGenDecay("BCPGenDecayPDF", "BCPGenDecayPDF", dt, q, tau, dm, w, Agen, Sgen, dw, effR, signalRes, r.RooBCPGenDecay.DoubleSided)

# Combined PDF
combinedPDF = r.RooAddPdf("combinedPDF", "combinedPDF", r.RooArgList(BCPGenDecayPDF, bkgPDF), r.RooArgList(fsig))
``````

Now, I generate from this combination 100000 events, which depend on the flavor `q` (a category, `B0` or `B0bar`):

``````nevents = 100000
data_set = combinedPDF.generate(r.RooArgSet(dt, q), nevents)
``````

and then I only plot the `B0` category:

``````frame = dt.frame(nbins)
data_set.plotOn(frame, Cut="q==q::B0", MarkerColor=r.kBlue)
combinedPDF.plotOn(frame, Slice=(q, "B0"), Components="BCPGenDecayPDF", LineStyle=r.kDashed, LineColor=r.kGreen)
combinedPDF.plotOn(frame, Slice=(q, "B0"), Components="bkgPDF", LineStyle=r.kDashed, LineColor=r.kRed)
``````

Now, the renormalization used by the `Slice` method of `plotOn` is trivial for the gaussian background component, but not for the CP asymmetry part.

For the background component, which doesn’t depend on the flavor, I get the correct normalization value with:

``````q.setLabel("B0")
xlim = (dt.getMin(), dt.getMax())
x = np.linspace(*xlim, 10000)
for i in range(len(x)):
var.setVal(x[i])
bkgPDF.getVal(var)*norm
``````

with

``````norm = n_expected_events_for_bkgPDF * bin_width / bkgPDF_integral
= (n_B0_events * (1 - f_sig))  * bin_width / 1
= (nevents/2 * (1 - f_sig))    * bin_width / 1
``````

This was tested and works wonderfully.

For `BCPGenDecayPDF`, this is not trivial, as we don’t have

``````n_expected_events_for_BCPGenDecayPDF = nevents/2 * f_sig
``````

The dependencies on the miss-tagging `w`, the asymmetry parameters `A` and `S` or the misstag rate `dw` makes `n_expected_events_for_BCPGenDecayPDF` go a bit higher or lower. All those parameters are fixed before using the same method to get the correct values for the gaussian background, and somehow it is always a bit off by a factor between 0.8 and 1.1 from my tests.

I tried to get information on normalization using `combinedPDF.getComponents()`, or I tried to get information of the `RooPlot` output when I plot `BCPGenDecayPDF` (`plot.getHist(plot.nameOf(1))` returns a null pointer, or `plot.getFitRangeNEvt()` returns 10000) without any success.

Any suggestions on how to get this correct normalization factor?

Best regards

1 Like

Small update: I managed to correctly get the correct number for `n_expected_events_for_BCPGenDecayPDF`, which is:

``````n_expected_events_for_BCPGenDecayPDF = n_true_B0_events - n_expected_events_for_bkgPDF
``````

with `n_true_B0_events` equal to the number of `B0` events actually generated in the `data_set`. It differs from the `n_B0_events` defined in my first post, which is the theoretical number of `B0` generated (without CP asymmetry) equal to `nevents/2`.

This solution gives in the end the correct normalization factor. It works because the background component doesn’t depend on the CP asymmetry.

For more complex examples, I still don’t know how I can get the normalization (or just the integral) of the plotted function by `plotOn`.

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