Chi2test

HI,
I am looking at the chi2test.C code given in the root tutorial directory.

I see that for the histogram h1 there are clearly bins with 0 events. But the igood is returned to be 0. I dont understand why does it not have a non-zero value when there are bins with 0 values.

The chi2test command is as follows:
h1->Chi2Test(h2,"UW P ",res)

Here, why are we taking h1 to be “unweighted” when there are error bars assigned to each bin ?

                                                                                                             -thanks debdatta.

Hi,

thanks for reporting this. I see there are some problem with the code, it should set an igood value = 1. I will investigate i and fix it.

The histogram is unweighted because the error bars are exactly equal to the square root of the bin content. But you are right, in the eample is not necessary to set the bin errors. I will remove these setting functions,

Thank you and best regards

Lorenzo

HI Lorenzo,
thanks. In general, if I have a histogram that has its error as the “sqrt of the bin content” should I treat it as a weighted or unweighted histogram ?
-regards Debdatta.

Yes, if the error is the sqrt of the bin content, the histogram can be treated as unweighted, i.e. has been filled with weights = 1.

This is due to the fact that the bin error is the sqrt of the sum of the weight square:

e = Sqrt( Sum( w(ibin)^2) )

and the bin content, y, is the sum of the weights:

y = Sum( w(ibin) )

So the case e = sqrt(y) is equivalent to all the w(ibin) equal to 1 (unweighted histogram).

Cheers

Lorenzo

HI Lorenzo,
thanks again. I am still a little confused about what is considered to be weighted/unweighted. Basically I have two histograms. One is the usual one which is filled with sqrt(bincontent) as the error and you said that this one could be considered as unweighted.
I am comparing this with another histogram which has been rewt. in the following manner:

for(int k=0;k<nbins;k++){
h2->SetBinContent( k+1, h1->SetBinContent(k+1) * const ) ;
h2->SetBinError( k+1, (h2->GetBinContent(k+1) * h1->GetBinError(k+1)) / h1->GetBinContent(k+1) ) ;
}

So I am rewt. h2 with a constant number but instead of setting its error as sqrt(N) I am doing :
% error on h2 = %error on h1.

So in this case, shall h2 be an unweighted histogram ?

                                                                    -thanks Debdatta.

Hi,
In principle the histogram h2 should be treated as weighted histogram.
However, I don’t understand the meaning of h2. If you scale h2 by a constant number you should scale also the errors, by the same number.

Keep in mind that the chi2 test is statistically correct only when the data are gaussian distributed.

Cheers

Lorenzo

HI Lorenzo,

However, I don’t understand the meaning of h2. If you scale h2 by a constant number
you should scale also the errors, by the same number.

I am doing that in the line:

h2->SetBinError( k+1,
(h2->GetBinContent(k+1)* h1->GetBinError(k+1))/h1->GetBinContent(k+1) ) ;

Here basically:

h2->GetBinContent(k+1)/h1->GetBinContent(k+1) = const (the scaling factor)

If h2 is a scaled h1, it does not make much sense to perform a chi2 test with h1, since it is the same statistics.

However, if you are comparing the scaled histogram, h2, with another unweighted histogram, you can treat it as uweighted and use the option
"NORM". See :

root.cern.ch/root/htmldoc/TH1.html#TH1:Chi2TestX

Lorenzo