Problem in extracting a TF1 from RooAbsPdf


I have encountered the following issue.
I performed a fit using RooFit and wanted to extract the TF1 function from the RooAbsPdf.

TF1* func = (TF1*) model->asTF( RooArgList(*OneOverPt), RooArgList(*dy_yield,*p0,*p1,*p2,*p3) );
  • OneOverPt is my observable.
  • p0,p1,p2,p3 are the parameters defining the shape of the fit.
  • dy_yield is the normalization.

I plotted the TF1 and compared it to the RooAbsPdf to find out they look discrepant (see attached images).
For instance you can check the point at 0.00795 to see that the blue curve (RooAbsPdf) is above the data point, while the red one (TF1) is below the data point.

I decided to printout the value in the bin centers of the RooAbsPdf using the following routine

RooRealVar *var = (RooRealVar*)model->getObservables(RooArgSet(*OneOverPt))->first();
  double binWidth = (high-low)/nbins;
  for (int i=1; i<=hOneOverPt->GetNbinsX(); i++) {
    double dataCount  = hOneOverPt->GetBinContent(i);
    var -> setVal(hOneOverPt->GetBinCenter(i));

    //std::cout << "var=" << var->getVal() << std::endl;

    std::cout << var->getVal() << " -- " << dataCount << " -- " 
                   << model->getVal(&RooArgSet(*var))*dy_yield->getVal()*binWidth 
                    << " -- "<< model->getVal() << std::endl;

It is my understanding that model->getVal() would return the value of the pdf normalized to dy_yield while model->getVal(&RooArgSet(*var)) would return the value of the pdf normalized to 1. I corrected the latter by the normalization and the bin-width and found that:

  • model->getVal() is compatible with the plot from the TF1
  • model->getVal(&RooArgSet(*var))*dy_yield->getVal()*binWidth is compatible with the plot from RooAbsPdf

Let’s take the last bin as an example again. From the output I get

0.00795 -- 97 -- 102.273 -- 94.9068

Can someone explain what’s happening and more important which are the correct values to consider?

I put my complete macro with the “data” file in /afs/
I am using privately compiled with the --enable roofit option.

Thanks a lot,
– Gian Piero


If you want to represent a normalized pdf as a TFx you should also supply the 3rd argument of the RooAbsReal::asTF() method - which defines the normalization observables, i.e.


if x is your observable and pvec is your set of parameters.


1 Like

Thanks, @Wouter_Verkerke for the reply!
I tried the same thing

model.plotOn(xframe,Normalization(1.0,RooAbsReal::RelativeExpected)) ;

TF1* func = (TF1*)model.asTF(x,RooArgList(a0,a1,sig1frac,nbkg,nsig),x);

but func is not normalized to the number of events…