Chi2/ndf value

Deal All,
I use a Crystal Ball (CB) function to fit a histogram. The CB is fitted to the histogram in the range of [-2.0sigma,2.0sigma] around the peak. I use following piece of code snippet to compute the chi2/ndf to check the quality of the fit.

RooFitResult* fitResult;
fitResult = CB.fitTo(dh,Save(),Range((Mu-2.0sig),(Mu+2.0sig)));
RooPlot* frame = x.frame();
dh.plotOn(frame, Name(“dh”),DataError(RooAbsData::SumW2)) ;
CB.plotOn(frame,Name(“CB”)) ;

int nFree = fitResult->floatParsFinal().getSize();

int nBins = frame->GetNbinsX();
int ndf = nBins - nFree;

Double_t signalchi = frame->chiSquare(“CB”,“dh”,nFree);

Double_t chi2 = signalchi*ndf;

//Find the number of bins of the fit range

Int_t lower = rat->GetXaxis()->FindFixBin((Mu-2.0sig));
Int_t upper = rat->GetXaxis()->FindFixBin((Mu+1.6

Int_t range = upper-lower;
Double_t new_chi2 = chi2/(range - nFree);

Cout << "chi2/ndf = " << new_chi2 << endl;

Can anybody tell me whether this is a correct method or not? Thanks in advance.

with regards,