Hello
I’m writing a macro for fit a distriubtion.
I assume that the chi2/nDOF is given by chi2 divide by the numbers of bins of the fit range - the number of free parameters. In my macro I use a crystal ball for the fit and I think there are 4 parameters (mean, sigma,alpha,n) but I’m note sure. So how to get this number ?
thanks for your help
Here is the code
using namespace RooFit;
void FitCB(){
TFile *f = new TFile("Histos_merged.root","READ");
TH1 *t = (TH1*)f->Get("hInvMassRes");
Float_t begin = 2.7;
Float_t end = 3.4;
RooRealVar m("m","invariant mass (GeV/c2)",2.2,4);
RooDataHist *data = new RooDataHist("data","data x",m,t);
RooRealVar mean_cb("mean_cb","mean",t->GetMean(),2.9,3.2);
RooRealVar sigma_cb("sigma_cb","sigma",t->GetRMS(),0,1);
RooRealVar alpha("alpha","alpha",1.8);
RooRealVar n("n","n",1);
RooCBShape *crystalball = new RooCBShape("crystal ball","crystal ball PDF",m,mean_cb,sigma_cb,alpha,n);
crystalball->fitTo(*data,Range(begin,end));
RooPlot* mframe = m.frame(Title("Crystal ball fit of J/psi invariant mass"));
data->plotOn(mframe);
crystalball->plotOn(mframe);
crystalball->paramOn(mframe,Label("Fit result"),Layout(0.55,0.99,0.9));
data->statOn(mframe,Layout(0.55,0.99,0.7));
mframe->Draw();
//Find the Chi2/nDOF value
Double_t chi2 = mframe->chiSquare();
//Find the number of bins of the fit range
Int_t lower = t->GetXaxis()->FindFixBin(begin);
Int_t upper = t->GetXaxis()->FindFixBin(end);
Int_t range = upper-lower;
Double_t new_chi2 = chi2 / (range - 4); // 4 free parameters ???
cout << "" << endl;
cout << "Chi2 : " << chi2 << endl;
cout << "" << endl;
cout << "Number of bins : " << range << endl;
cout << "" << endl;
cout << "Chi2/nDOF for crystal ball fit : " << new_chi2 << endl;
}