Dear experts,
I am fitting a distribution with Landau-Gauss conv function in Roofit and would like to calculate the chi2 value of the fit. I managed to get some value using frame.chiSquare() method, but it seems the number is questionable.
Here is the snippet of the code:
hist = f.Get(hn)
nbins = hist.GetSize()-2
# Get mean and standard deviation for Gauss - Landau initial parameterization
mean = hist.GetMean()
sigma = hist.GetStdDev()
## Construct observable
minX,maxX = hist.GetXaxis().GetBinLowEdge(1), hist.GetXaxis().GetBinUpEdge(nbins)
t = RooRealVar("t","t", minX, maxX)
## Construct gauss(t,mg,sg)
mg = RooRealVar ("Gauss - mean","mg",0)
sg = RooRealVar ("Gauss - sigma","sg",sigma,0.1*sigma,5.*sigma)
gauss = RooGaussian ("gauss","gauss",t,mg,sg)
## Construct landau(t,ml,sl)
ml = RooRealVar ("Landau - mean","mean landau",mean,mean-sigma,mean+sigma)
sl = RooRealVar ("Landau - sigma","sigma landau",0.04,0.,0.2)
landau = RooLandau ("lx","lx",t,ml,sl)
## C o n s t r u c t c o n v o l u t i o n p d f
## ---------------------------------------
## Set #bins to be used for FFT sampling
t.setBins(5000,"cache")
## Construct landau (x) gauss
lxg = RooFFTConvPdf ("lxg","landau (X) gauss",t,landau,gauss)
## S a m p l e , f i t a n d p l o t c o n v o l u t e d p d f
## ----------------------------------------------------------------------
tofit = RooDataHist("dh", "dh", RooArgList(t), hist) ;
## Fit lxg to data
lxg.fitTo(tofit);
## Plot data, landau pdf, landau (X) gauss pdf
xframe = t.frame()
tofit.plotOn(xframe)
lxg.plotOn(xframe)
xframe.GetYaxis().SetTitle('au')
xframe.GetXaxis().SetTitle('#DeltaE/#Deltax [MeV/mm]')
xframe.GetYaxis().SetTitleOffset(1.4)
## Calculate chi2
chi2 = xframe.chiSquare(3)
print 'chi2 =', chi2
I get a result of chi2 = 17.27, which I think is too big especially when looking at the fit result below.
Note:
When calling chiSquare I use nFitParam=3 considering 3 floating parameters of the fit = Gauss - sigma, Landau - mean, Landau - sigma. Is this correct?
Best,
Yosse