Obtaining chisquare/NDF by fitting a unbinned data

Hii all,

I have generated some toy events of gaussian and fitted with a gaussian PDF. I want to find out the goodness of the fit. I tried to find out the chisquare/NDF of the fit. I was not able to get it. How can I get the Number of degrees of freedom here?? .

There is a method also to get chisquare
Double_t chi2Val = xframe->chiSquare();

Please clarify it.

I guess you fitted an histogram using something like histo->Fit(“gaus”)

What you should do is

TFitResultPtr fit_res =histo->Fit("gaus","S");

The S option let you save the result of the fit in the TFitResultPtr variable, you can find other option looking the Fit method on the TH1 page


Then to get the Chi2 you should do


and for the NDF



Hii stefano,

Thank you for your kind reply.
The thing is that, I am using a RooFit. I am generating 10000 gaussian toy events and fitting it to a gaussian PDF. These are unbinned data.

I am doing like this:

RooRealVar x(“x”,“x”, -5,5);
RooRealVar mean(“mean”,“mean of Gaussian”,0,-5,5) ;
RooRealVar sigma(“sigma”,“sigma of Gaussian”,1,0,5) ;
RooGaussian Gauss(“Gauss”,“Gaussian PDF”,x,mean,sigma);
RooDataSet *data = Gauss.generate(x,100000);

RooPlot* xframe = x.frame() ;
Gauss.plotOn(xframe) ;

How can I get the chi2/NDF here???

Ok, sorry if I didn’t understand your problem.

I’m not so used to RooFit, but I know that for have the Chi2 you should use the following lines

RooChi2Var chi2(“chi2”,“chi2”,Gauss,*data) ;

But I what you should do for what concerns the NdF, probably you have to found by hand. Using the number of parameters of the pdf, and the number of data.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.