Possible to convert a RooFitResult to a TFitResult?

I would like to be able to make a ratio plot for the data and a fit in RooFit. It would of course be convenient to use TRatioPlot to do so, however the constructor for this

TRatioPlot::TRatioPlot(TH1* h1, Option_t* option = "", TFitResult* fitres = 0)

requires a TFitResult and RooFit’s RooAbsPdf::fitTo() returns a pointer to RooFitResult.

Is there any clean way to go from a RooFitResult object to a TFitResult object?

Additionally, if there is some very nice way to get a ratio plot in RooFit that I have missed that would be even better.

I think @moneta will know the answer.

Hi,

In principle this should be possible, almost all the information needed for TFitResult is in the RooFitResult, but
it might be not trivial.
Since you are doing a TRatioPlot for comparing an histogram with a function, this is a rather simple fit. The easiest solution is to convert your RooFit pdf to a TF1 using the asTF function and do a histogram fit to obtain a TFitResult

Lorenzo

@couet @moneta Thanks for the reply. I would like to try to follow up on this as it seems like this would also fix @poniatowska’s problem as RooAbsReal::asTF() returns a pdf, not the fit you want.

In the more general case where one has a RooFitResult then (in PyROOT) you’re suggesting to do this?

# model is our RooAbsPdf (let's say a RooGaussian)
# datahist is the RooDataHist that we fit model to
# x is our observable RooRealVar
# x_range is the fit range we care about

# roo_fit_result = model.fitTo(datahist, ...) # Assume something like this has been done
fit_result_func = model.asTF(ROOT.RooArgList(x))
hist = datahist.createHistogram('hist name', x)
# This gets us the TFitResult
fit_result = hist.Fit(fit_result_func.GetName(), 'ILS', '', x_range[0], x_range[1])

# Now fit_result_func should have the parameters of the fit
integral = fit_result_func.Integral(x_range[0], x_range[1])

If this is what you are suggesting, then I think this seems to work and can easily have a user wrapper function that handles all of this (however a quick test results in an error with illegal number of parameters from hist.Fit()). However, I am a bit concerned about the fact that RooFit and ROOT’s fits do NOT seem to give consistent results (c.f. my chi-square question). Do you have advice here?

See my answer in the other post.
Lorenzo

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