Integrating a RooAbsPdf compoment from RooAddPdf


I have two RooFit question which I have not been able to solve.

  1. Is it at all possible to obtain from a RooAddPdf one of its RooAbsPdf components and then intergate under this curve; after performing a fit to data?

From the following Code:

 RooRealVar sigmean("#mu","mass", fpar, fmin, fmax);
  RooRealVar sigwidth("#sigma","width",fw, fwmin, fwmax);
  RooGaussian sig("sig","signal", fit_var,sigmean,sigwidth);

  // --- Build Expo background PDF ---
  RooRealVar a("#tau_{bkg}", "a", -1e-3, -1.0, 0.0);
  RooExponential bkg("bkg", "expo", fit_var, a);

   // --- Construct composite PDF --- 
  RooRealVar nsig("nS","number of signal events",500, 0.,15000);
  RooRealVar nbkg("B","number of background events",(exsig), 0.,15000);
  RooAddPdf sum("sum","gauss",RooArgList(sig, bkg),RooArgList(nsig, nbkg));

  RooFitResult* r = sum.fitTo(*data,"ehr");

Is it possible to then get the sig pdf like:
RooAbsPdf *signal = sum.Component->Find(“sig”);

And then integrate it:
signal->Integrate(fit_var_min, fit_var_max); ???

Not at all obvious to me how you integrate a RooAbsPdf?
With a RooCurve, on a RooPlot, it was easy to obtain the integral, since the curves value at a given point, could be extracted with Eval() and then the integration could proceed using a simple integration method.

  1. Is there a way of obtaining the bin content of a RooPlot. If I do
    Im returned zero?

Any help is appreciated.



Hi Colin,

Here are some answers:

  1. The member function RooAddPdf::pdfList() retursn a RooArgList with the components p.d.f.s of the RooAddPdf so you can e.g. do sum.pdfList().find(“sig”) to get the signal
    component out

On your aside: any RooAbsPdf can be integrated using

RooAbsReal* RooAbsPdf::createIntegral(const RooArgSet& intVars, const RooArgSet& normVars, const char* rangeName)

(In RooFit you think of an integral as a function object rather than as an action)

Note that your example ‘signal->Integrate(fit_var_min, fit_var_max)’ always returns
a trivial result of 1.0 because a probability density function is normalized by construction
over the fit range.

To do a meaningful integration over a subrange, you can e.g. do this

x.setRange(“SIGREGION”,-5,5) ;
RooAbsReal* intSig = sig.createIntegral(x,x,“SIGREGION”) ;

which returns the integral of sig over x in “SIGREGION” where sig is normalized over X.
This will return a number between 0 and 1.

The above technique works for integration in any number of dimensions and will return analytically calculated integrals if those are implemented by the p.d.f. (such as RooGaussian)

  1. A RooPlot is not a histogram, it rather is a view of one or more datasets
    and p.d.f projections on the same observable. Thus, if you want to retrieve
    the bin content of e.g. a histogram shown in a RooPlot you have to specify
    which one you mean. You can inspect the contents of a RooPlot using a
    Print(“v”) call which will list its contents along with the object names. You
    can access any contained object by name or index using

    TObject* obj = frame->findObject(const char* name) ; // or
    TObject* obj = frame->getObject(Int_t index) ;

Histogram objects are of type RooHist which is a derived class of TGraphAsymErrors,
function objects are of type RooCurve which is a derived class of TGraph. You
can use the interface methods in the TGraph* classes to retrieve their contents.
Note that point spacing in RooCurve objects is not uniform, but spacing is adaptively calculated to achieve a accuracy of 0.1% between the curve and the true p.d.f at any
midpoint between to RooCurve points.