# Possible to convert a RooFitResult to a TFitResult?

**URL:** <https://root-forum.cern.ch/t/possible-to-convert-a-roofitresult-to-a-tfitresult/28153>\
**Category:** Roofit and RooStats\
**Tags:** graphics\
**Created:** [March 2, 2018, 12:02pm UTC](https://root-forum.cern.ch/t/possible-to-convert-a-roofitresult-to-a-tfitresult/28153 "2018-03-02T12:02:58Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![feickert](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/cc9497/32.png) [@feickert](https://root-forum.cern.ch/u/feickert)\
**Post date:** [March 13, 2018, 4:28pm UTC](https://root-forum.cern.ch/t/possible-to-convert-a-roofitresult-to-a-tfitresult/28153/4 "2018-03-13T16:28:24Z")

</div>

@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](https://root-forum.cern.ch/t/problem-with-creating-tf1-from-roofitresult/17240) as [`RooAbsReal::asTF()`](https://root.cern.ch/doc/master/classRooAbsReal.html#a5b1ad5b6d761c664adc2434689ef8f99) returns a pdf, not the fit you want.

In the more general case where one has a [RooFitResult](https://root.cern.ch/doc/v608/classRooFitResult.html) then (in PyROOT) you’re suggesting to do this?

```auto
# 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](https://root-forum.cern.ch/t/difference-in-how-chi-square-is-calculated-in-roofit-and-root/28158)). Do you have advice here?

---

_[View the full topic](https://root-forum.cern.ch/t/possible-to-convert-a-roofitresult-to-a-tfitresult/28153)._
