Issue using Chi2Test() regarding a bin with less than 1 event

Hi All,

I am currently attempting to use the Chi2Test() method to compare two normalized histograms. Upon execution I received the following message:

Info in <TH1F::Chi2TestX>: There is a bin in h1 with less than 1 event.

as well as an igood value of 1, which I think says the same thing as the above message.

I at first thought that maybe this was due to one of the bins of the histogram that calls the method being empty, so I searched each bin to determine which were empty, and then if its content was empty/zero, I set it’s value to 0.001 as a test to see if it cleared up the issue. It did not.

Any and all help, suggestions, questions to resolve this are greatly appreciated.

-Frank

ROOT Version: 6.22/06
Platform: MacOS Big Sur
Compiler: gcc


Are you using TH1::Chi2Test options appropriate for weighted / scaled histograms?

Hi @Wile_E_Coyote,

Thank you so much for your quick response.

I originally was calling via:

h2->Chi2Test(h3,"UW P");

Since my h2 is the experimental data, and h3 is the simulated/monte carlo data.

I then reviewed the link you dent and tried:

h2->Chi2Test(h3,"UW NORM P");

and still obtained the same message regarding the bin having less than 1 event. I assume I am not passing the options correctly.

-Frank

I guess "NORM" needs "UU".

@Wile_E_Coyote ,

Thank you again for your quick response.

I have now tried:

h2->Chi2Test(h3,"UU NORM P");

and received the message:

Error in <TH1F::Chi2TestX>: Cannot use option NORM when one histogram has all zero errors
Chi2 = 0.000000, Prob = 0, NDF = 49, igood = 0

I find this odd since using:

numbins = h2->GetNbinsX();
   	for(int i = 0; i<= numbins+1; i++)
   	{
   		hsim = h2->GetBinContent(i);
   		cout << "bin: " << i << " = " << hsim << endl;

   	}

I obtain for h2:

bin: 0 = 0.001
bin: 1 = 0.000401078
bin: 2 = 0.00466253
bin: 3 = 0.00244407
bin: 4 = 0.0116814
bin: 5 = 0.0071066
bin: 6 = 0.0112302
bin: 7 = 0.0228113
bin: 8 = 0.0263207
bin: 9 = 0.0239769
bin: 10 = 0.0471141
bin: 11 = 0.110096
bin: 12 = 0.16839
bin: 13 = 0.16463
bin: 14 = 0.104919
bin: 15 = 0.0529924
bin: 16 = 0.0182616
bin: 17 = 0.00744501
bin: 18 = 0.00551482
bin: 19 = 0.00572789
bin: 20 = 0.00671805
bin: 21 = 0.00723194
bin: 22 = 0.00804663
bin: 23 = 0.00807169
bin: 24 = 0.00942533
bin: 25 = 0.0123707
bin: 26 = 0.0178981
bin: 27 = 0.0218211
bin: 28 = 0.0241148
bin: 29 = 0.0236636
bin: 30 = 0.0172714
bin: 31 = 0.0126089
bin: 32 = 0.00765808
bin: 33 = 0.00426145
bin: 34 = 0.00270728
bin: 35 = 0.00208059
bin: 36 = 0.00188005
bin: 37 = 0.00204299
bin: 38 = 0.00225606
bin: 39 = 0.00184245
bin: 40 = 0.00147897
bin: 41 = 0.00129097
bin: 42 = 0.0011155
bin: 43 = 0.00116563
bin: 44 = 0.00136617
bin: 45 = 0.00105283
bin: 46 = 0.0011531
bin: 47 = 0.00109043
bin: 48 = 0.000589083
bin: 49 = 0.001
bin: 50 = 0.001
bin: 51 = 0.001

and for h3:

bin: 0 = 0
bin: 1 = 0.0145783
bin: 2 = 0.0149254
bin: 3 = 0.00902464
bin: 4 = 0.00833044
bin: 5 = 0.0114544
bin: 6 = 0.022041
bin: 7 = 0.0180493
bin: 8 = 0.0216939
bin: 9 = 0.0258591
bin: 10 = 0.0468587
bin: 11 = 0.0911142
bin: 12 = 0.086949
bin: 13 = 0.0987504
bin: 14 = 0.0517182
bin: 15 = 0.0322805
bin: 16 = 0.0315863
bin: 17 = 0.011975
bin: 18 = 0.0147518
bin: 19 = 0.0098924
bin: 20 = 0.00971885
bin: 21 = 0.0156196
bin: 22 = 0.0128428
bin: 23 = 0.0225616
bin: 24 = 0.017008
bin: 25 = 0.0183964
bin: 26 = 0.0209997
bin: 27 = 0.017008
bin: 28 = 0.0236029
bin: 29 = 0.0206526
bin: 30 = 0.0194377
bin: 31 = 0.0197848
bin: 32 = 0.0175286
bin: 33 = 0.0178757
bin: 34 = 0.0123221
bin: 35 = 0.00937175
bin: 36 = 0.0112808
bin: 37 = 0.00642138
bin: 38 = 0.00885109
bin: 39 = 0.00780979
bin: 40 = 0.00624783
bin: 41 = 0.0126692
bin: 42 = 0.00780979
bin: 43 = 0.0104131
bin: 44 = 0.00711558
bin: 45 = 0.00624783
bin: 46 = 0.00607428
bin: 47 = 0.00399167
bin: 48 = 0.00485942
bin: 49 = 0.00173551
bin: 50 = 0.00190906
bin: 51 = 0.132072

I include the contents of the histograms in case anyone wanted to try to replicate or experiment with this issue.

If the full macro script is of interest please let me know and I will share it.

Thanks again for all of your help.

-Frank

TH1::GetBinContent returns “bin content”.
TH1::GetBinError returns “bin error”.

Hi @Wile_E_Coyote ,

Thanks for pointing that out, I am not sure how I missed that.

I have now used:

numbins = h2->GetNbinsX();
for(int i = 0; i<= numbins+1; i++)
{
    hsim = h2->GetBinContent(i);
    hsim = sqrt(hsim);
    h2->SetBinError(i,hsim);
}

to set the bin error, I also check the other histogram and found that it did have bin errors assigned.

Now when using:

h2->Chi2Test(h3,"UU NORM P");

I receive the message:

Error in <TH1F::Chi2TestX>: one histogram is empty
Chi2 = 0.000000, Prob = 0, NDF = 49, igood = 0

Which is perplexing given that I when I print the contents of the bins they are non-zero.

Thanks again for all of your help.