How can use chisquare fit in roofit?

Hello, all

I would like to use chisquare fit in roofit.
I couln’t find it in user guild.
Could anyone show some example code?

Hi,

you can use the chi2 fit in Roofit by using the RooChi2Var class.
Attached is an example to perfrom a Gaussian Chi2 fit to an histogram.

However, if you have an unweighted histogram the recommended way (and default in RooFit) is to do a binned likelihood fit.
I would use the Chi2 only when the bins represent a set of points with gaussian distributed errors

Cheers,

Lorenzo
testRooFitChi2.C (1.12 KB)

Thank you very much, moneta

And I have a further question.

When I fill a histogram, I use user-defined bin contents and errors like this

In such case, I think the error of each bin should be user-defined error not the poisson error given by default.
To do so, the code should be modified as follows.

Is it right?

Thanks in advance