Hi all, I am using RooFit to fit a data histogram and I want to obtain the number of signal and background events in a small range around the invariant mass peak but fit in all the range. For what I read in the documentation this should be done with .createIntegral, but I don quite understand how it works because of the normalizations.
The model that I am using is an Hypatia for the signal and polynomial for the background and it would be nice to obtain the events in a range defined by something like abs(D_M-1869.65)<20.
model = RooAddPdf("model", "model", RooArgList(Hypatia,Poly), RooArgList(nsig, nbkg))
assuming the variable (RooRealVar) representing your observable is x, you can use createIntegral as following (using Python)
x.setRange("subrange",xmin,xmax)
ig = pdf.createIntegral(x,x,"subrange")
ntot = model.expectedEvents(ROOT.RooArgSet(x)) # this should be nsig+nbkg
print('number of events in range =', ig.getVal()*ntot )