Strange behaviour in TH1::Chi2Test

From: Tobias Raufer <T.Raufer1_at_physics.ox.ac.uk>
Date: Fri, 20 Apr 2007 10:38:06 +0100


Dear Roottalk,

I am using root version 5.15/05 on SL 3.

I am seeing some strange behaviour in the function TH1::Chi2Test. Please consider the following macro:

void debugChi2(){  

  gStyle->SetOptStat(111111);

  TH1F* h2 = new TH1F("h2","h2",10,-3,3);
  TH1F* h1 = new TH1F("h1","h1",10,-3,3);
  h1->FillRandom("gaus");
  h2->FillRandom("gaus");

  h1->Draw();
  h2->Draw("sames");   
  h1->Chi2Test(h2,"UUP");
  h1->Chi2Test(h2,"UUPOF");   // use overflow bin
  h1->Chi2Test(h2,"UUPUF");   // use underflow bin
  h1->Chi2Test(h2,"UUPOFUF"); // use both over- and underflow

}

As you can see I am testing two randomly filled gaussian histograms. In both cases, the overflow and underflow bins are empty. The difference between the four calls to TH1::Chi2Test is whether or not these overflow and underflow bins should be included in the test. The output of the macro looks like this:

Processing debugChi2.C...
<TCanvas::MakeDefCanvas>: created default TCanvas with name c1

Chi2 = 8.935781, Prob = 0.443223, NDF = 9, igood = 0
Chi2 = 35.743124, Prob = 0.0164853, NDF = 20, igood = 0
Chi2 = 35.743124, Prob = 0.00496242, NDF = 17, igood = 0
Chi2 = 80.422029, Prob = 6.86344e-09, NDF = 21, igood = 0 

As you can see, both the chi2 values and the ndf numbers are different in the four cases. Looking at the documentation, I thought empty bins (such as the overflow) will be automatically removed from the calculation of chi2 and ndf. How can the options "OF" and "UF" change the result then?

You will also notice that, in the second and third case, the chi2 value is exactly 4 times that of the first one and in the last case, it's 9 times that.

Am I misunderstanding the way the function works? I suspect, this has something to do with the handling of the y- and z-axis of the TH1.

Thanks for your help.

        Tobi

---
Tobias Raufer
Denys Wilkinson Building
Keble Road, Oxford OX1 3RH, UK

Tel. +44 (0)1865 273409
Fax. +44 (0)1865 273418
tobias.raufer_at_physics.ox.ac.uk
Received on Fri Apr 20 2007 - 11:38:16 CEST

This archive was generated by hypermail 2.2.0 : Fri Apr 20 2007 - 23:50:02 CEST