This question is specific to the roofit modeling toolkit. I would like to compare the goodness of fit of two different composite model PDF’s to data.
I have found examples of how to print a plot of the NLL distribution or to print a summary of the fit results, but is there some way to extract one value for each fit that can be used for this purpose? Could anyone provide a snippet of code to show how it can be done?
PS Sorry if this sounds like a dumb question, I’m an undergraduate just trying to get started!
You can do one of the following two things:
- Make sure you save a RooFitResult object of your fit, e.g.
using namespace RooFit ;
RooFitResult* r = pdf.fitTo(*data,Save(kTRUE),Minos(kFALSE)) ;
cout << "nll = " << r->minNll() << endl ;
Alternatively construct the -log(L) explicitly and do the fit through the
RooNLLVar nll(“nll”,“nll”,pdf,data) ;
RooMinuit m(nll) ;
and query the likelihood valye from nll, which is a regular RooFit function
cout << " nll = " << nll.getVal() << endl ;