Comparing 2 histograms using chi2test

I produced, by GEANT4, the interaction point distributions as a function of the cross-section to compare with GEANT3 results.

Now I should check the agreement between each one of the GEANT4 distribution with the one called GEANT3 full.

I’m trying to do that by using the Chi2Test() function. I found this example ROOT: tutorials/math/chi2test.C File Reference made by @moneta et al. and I’m trying to write this macro

chi2test.cpp (3.1 KB)

but I’ve some doubts.

  1. According to the documentation, the “P” option should return chi2, ndf, p_value, igood, but I don’t get the p_value, indeed I got

Chi2 = 1739.425216, Prob = 7.91802e-194, NDF = 319, igood = 3

  1. The Chi2 is very high…does it depend on mistakes in the code or is it due to the data?

  2. Even if I get both the residual and qq plots, I get segmentation violation error (See attachment)

nohup.txt (5.4 KB)

  1. I get these residual and qq plots

but I’m not sure that I wrote the right settings (actually, very likely, I’m not using the right settings).

For example I set n=500 (i.e. bin number) but I’m not sure that n should be the bin number. Moreover, in the ROOT: tutorials/math/chi2test.C File Reference example, the authors set

x[i]= 4.+i*12./20.+12./40.;

but given that I binned htempt1 and htempt2 1bin=1mm, I set

x[i]= i,
but again, I’m not sure that it is correct, indeed, the residual graph doesn’t look like fine to me.

PS. If needed here the ROOT files:

I think @moneta can help

Hello, any news please?

The files are not available anymore, if they ar not too big, they just should contain the histograms please upload in the Forum.

However, the big chi2 value indicate a big discrepancy of the histograms, and the obtained p-value (Prob) is almost zero.

The crash is probably caused by the fact you are deleting the canvas but not some of the other objects and this confuses ROOT.


Hi @moneta,
I commented the delete commands,
chi2test.cpp (3.2 KB)

but I still get these plots

Chi2 = 1739.425216, Prob = 7.91802e-194, NDF = 319, igood = 3

I uploaded the files again

Thank you for the file, Next time, it is easier if you just upload a ROOT file containing the two histograms you would like to compare.

I am not sure what the problem is, the result is what it is given the histogram. You are not correctly plotting the resiual, you can use the corrected code (attached) to visualise them.


chi2test.cpp (3.1 KB)

1 Like

Thank you @moneta
With your fix I got better plots, but still high X^2 e small Probability. Do you think they really depend on the data?

Just look at the plot of the two histograms, you see in some regions very big difference that is also shown in the normalised residuals, and that results as well in a very small chi2 probability

Thank you @moneta!

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