I called the KolmogorovTest on 2 histograms, the original histogram and the histogram of the fit, but I the binning differs. I wonder how I can set the bins of the histogram of the fitted.
- if I use Rebin(), it will lower more the bin of the fit histo, and I do not want to change the binning of the initial histogram.
using the piece of code [*], I have the error message:
Error in TH1F::KolmogorovTest: Number of channels is different, 250 and 100
Do you know how I can solve this?
// histogram has 1000 bins, range[0,2]
hist->Rebin(4); // now 250 bins
myfit = new TF1(“myfit”, myfit_fnc, 0, 2, maxPar);
double ks=hist->KolmogorovTest(myfit->GetHistogram()); // error message
you can create an empty histogram with the same binning and set the bin content according to the value of the fit function calculated at the bin centres.
Try (assuming that your “hist” is a simple “fix bin size” one):
TF1 *myfit = new TF1("myfit", myfit_fnc,
hist->GetXaxis()->GetXmin(), // use the same "xlow"
hist->GetXaxis()->GetXmax(), // use the same "xup"
myfit->SetNpx(hist->GetNbinsX()); // use the same "nbins"
I wonder how to get the fit function value calculated at the bin center?
I tried: fit->GetHistogram()->GetBinContent(i);
but the return values are not correct.
If one reads the manual (which is always a good idea), one can see that TF1 has an Eval() function:
Dear experts, Coyote,
the myfit->SetNpx(hist->GetNbinsX()); works fine.