Unreasonable TH1F::Chi2Test

Hi all,

I have been fighting today with the TH1::Chi2Test, trying to perform a classical chi2 between 2 histograms. I get unreasonable results, and I think I reproduced the problem with this piece of code:


	TH1F* th1 = new TH1F("th1", "", 4, 0, 4);
	th1->SetBinContent(1,3.73998);
	th1->SetBinContent(2,3.58733);
	th1->SetBinContent(3,3.89375);
	th1->SetBinContent(4,3.75991);
	th1->SetBinError(1,1.43919e-01);
	th1->SetBinError(2,1.38841e-01);
	th1->SetBinError(3,1.42339e-01);
	th1->SetBinError(4,1.41206e-01);

	TH1F* th2 = new TH1F("th2", "", 4, 0, 4);
	th2->SetBinContent(1,2.206);
	th2->SetBinContent(2,2.721);
	th2->SetBinContent(3,2.723);
	th2->SetBinContent(4,2.848);
	th2->SetBinError(1,2.915e-01);
	th2->SetBinError(2,1.489e-01);
	th2->SetBinError(3,1.566e-01);
	th2->SetBinError(4,2.163e-01);

	TH1F* th3 = new TH1F("th3", "", 4, 0, 4);
	th3->SetBinContent(1,1.2206e1);
	th3->SetBinContent(2,1.2721e1);
	th3->SetBinContent(3,1.2723e1);
	th3->SetBinContent(4,1.2848e1);
	th3->SetBinError(1,2.915e-01);
	th3->SetBinError(2,1.489e-01);
	th3->SetBinError(3,1.566e-01);
	th3->SetBinError(4,2.163e-01);


	th1->Chi2Test(th2,"P");
	th1->Chi2Test(th3,"P");
	

Essentially, I get significantly higher probabilities with a histogram that is way “farther away” from the points:

Chi2 = 3.969444, Prob = 0.264783, NDF = 3, igood = 0
Chi2 = 2.886155, Prob = 0.409513, NDF = 3, igood = 0

Is there something I don’t understand? Or the behaviour is not reasonable?

I’m using ROOT 5-34-32. Thank you for your help in advance!

Hi,

Chi2Test does not just compare the raw histograms but looks if the underlying
distributions are the same or not.
To roughly see what happens you should normalize your hists and draw it
in the same plot (see att pdf).
From this its clear that “th3” is much more alike to “th1” than “th2”.
To understand how it really works you need to consult the detailed documentation:
https://root.cern.ch/root/html534/TH1.html#TH1:Chi2Test

Cheers
Otto
cc.pdf (14.5 KB)