I Have a question regarding how the chi2 of a fit is calculated in RooFit.
Here is my set-up:
- model: two CBs and a Chebychev
- fit: weighted least squares (minimum chi-square)
- binned, weighted data supplied through a RooDataHist
The crux of the code is:
RooRealVar x("x","Mass", 1000.0, 5000.0); ... TFile f(fileName.c_str()); TH1F *h = (TH1F*) f.Get(("eeMass_h_pt" + histName + "_y00_075_w").c_str()); h->Sumw2(); //should already have been done h->Rebin(2); RooDataHist d("data","data",x,h); RooChi2Var chi2("chi2","chi2", tot, d,Extended(),DataError(RooAbsData::SumW2)); RooMinuit minuit(chi2); minuit.migrad(); minuit.minos();
Which works fine and converges successfully. The model (‘tot’ in code) has 10 free parameters and the fit is on a histogram with 40 bins = 30 degrees of freedom.
My issue is this:
When I do chi2.getVal() I get values like ~500
When I do xframe->chiSquare(10); I get values like ~2.8
Clearly, calculating the chi2/ndof from method 1 gives ~500/30 = 17, NOT 2.8.
I know exactly how the xframe->chiSquare(10) method works and from a visual inspection of the fit the value seems about right.
Can anyone tell me how chi2.getVal() works, and why it is so different to the xframe->chiSquare(10) method?