Unclear interplay between RooDataHist range and fit range

Dear RooFit experts,

lately I’ve been trying to understand how to correctly perform Chi-square-based goodness of fit with RooFit and faced a behavior I don’t fully understand regarding the usage of RooDataHist and RooAbsPdf::fitTo. If you want to reproduce my experiments, they’ve been performed through the small script I am attaching to this thread.

In short, I load a TH1F having range [0,6] and containing some Gaussian data, and use it to initialize a RooDataHist that I want to fit with a Gaussian shape.
I also initialize a RooRealVar called var that I use to manipulate the range of the RooDataHist.
I was expecting the boundaries defined by var to also define the fit range, but it appears not to be the case. In fact, I tried:

  1. To restrict the range of the RooDataHist, e.g., to [1,5] using var and to perform a fit with no range: RooFitResult * r = g.fitTo(dh, Save());.
  2. To restrict the range of the RooDataHist, e.g., to [1,5] using var and to perform a fit specifying the range: RooFitResult * r = g.fitTo(dh, Range(1,5), Save());.

and the resulting fitter parameters, along with the Chi2, are different in the two scenarios.
Can someone here explain me exactly what is the interplay between setting a range to the RooDataHist and setting a range to the fit? Also, what’s the way to get a correct Chi2/ndof?

Best regards,
rooDataHist_experiments.cpp (1.5 KB)
rooDataHist_experiments_input.root (3.9 KB)

Hi @Fabio_Iemmi,

which ROOT version are you using? I tried to reproduce the inconsistencies you were reporting with ROOT 6.26.10, but I couldn’t see them. The fit result and the chi-square only depends on the fit range, no matter is the range of the RooDataHist is identical to the fit subrange or identical to the TH1F range.

By the way, that the chi-square/ndf for the range [3.00, 3.12] is infinite is expected. You have two bins and two parameters, so zero degrees of freedom.

Maybe I misunderstood the question, but it could also be that the inconsistency you are reporting relates to a bug that was fixed in the newest ROOT version.


Hi @jonas,

thanks for your reply. I am using ROOT 6.24/02. Why do you say that that the fit results and the chi-suare only depend on the fit range?

  1. If I choose a given fit range in the fitTo() method, and then change the range of the RooDataHist, the results change quite a lot for me.
  2. Additionally, if I keep the range of the RooDataHist fixed and I change the fit range in fitTo(), the results change as well.

Point 2) is the most surprising to me. In fact, before spotting this behavior, I expected that setting the range of the RooDataHist would determine the number of bins in the fit and thus completely determine the fit and chi-square results. By setting the range to [3, 3.12], as you quoted before, I got to know that the number of bins in the fit is determined by the RooDataHist range. But then, what’s the point of the fit results and chi-square changing if I change the fitTo() range?

I hope my question is clear, please let me know if it is not, I am happy to further discuss.

Merry Christmas!

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