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

**URL:** <https://root-forum.cern.ch/t/issue-using-chi2test-regarding-a-bin-with-less-than-1-event/50266>\
**Category:** Newbie\
**Created:** [June 4, 2022, 12:32pm UTC](https://root-forum.cern.ch/t/issue-using-chi2test-regarding-a-bin-with-less-than-1-event/50266 "2022-06-04T12:32:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fr4nk](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fr4nk/32/24294_2.png) [@Fr4nk](https://root-forum.cern.ch/u/Fr4nk)\
**Post date:** [June 4, 2022, 12:32pm UTC](https://root-forum.cern.ch/t/issue-using-chi2test-regarding-a-bin-with-less-than-1-event/50266/1 "2022-06-04T12:32:13Z")

</div>

Hi All,

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

```auto
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

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 4, 2022, 2:43pm UTC](https://root-forum.cern.ch/t/issue-using-chi2test-regarding-a-bin-with-less-than-1-event/50266/2 "2022-06-04T14:43:04Z")

</div>

Are you using [TH1::Chi2Test options appropriate for weighted / scaled histograms](https://root.cern/doc/master/classTH1.html#a6c281eebc0c0a848e7a0d620425090a5)?

---

<div class="post-metadata">

**Author:** ![Fr4nk](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fr4nk/32/24294_2.png) [@Fr4nk](https://root-forum.cern.ch/u/Fr4nk)\
**Post date:** [June 4, 2022, 6:28pm UTC](https://root-forum.cern.ch/t/issue-using-chi2test-regarding-a-bin-with-less-than-1-event/50266/3 "2022-06-04T18:28:26Z")

</div>

Hi @Wile_E_Coyote,

Thank you so much for your quick response.

I originally was calling via:

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 4, 2022, 8:38pm UTC](https://root-forum.cern.ch/t/issue-using-chi2test-regarding-a-bin-with-less-than-1-event/50266/4 "2022-06-04T20:38:49Z")

</div>

I guess `"NORM"` needs `"UU"`.

---

<div class="post-metadata">

**Author:** ![Fr4nk](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fr4nk/32/24294_2.png) [@Fr4nk](https://root-forum.cern.ch/u/Fr4nk)\
**Post date:** [June 4, 2022, 8:57pm UTC](https://root-forum.cern.ch/t/issue-using-chi2test-regarding-a-bin-with-less-than-1-event/50266/5 "2022-06-04T20:57:02Z")

</div>

@Wile_E_Coyote ,

Thank you again for your quick response.

I have now tried:

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

```

and received the message:

```auto
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:

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

   	}

```

I obtain for h2:

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 4, 2022, 9:07pm UTC](https://root-forum.cern.ch/t/issue-using-chi2test-regarding-a-bin-with-less-than-1-event/50266/6 "2022-06-04T21:07:21Z")

</div>

[TH1::GetBinContent](https://root.cern/doc/master/classTH1.html#ac70dcb4082bd510f5aa3e6efeb043f39) returns “bin content”.  
[TH1::GetBinError](https://root.cern/doc/master/classTH1.html#a3af6cc15ab6c2490428c9b691885d919) returns “bin error”.

---

<div class="post-metadata">

**Author:** ![Fr4nk](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fr4nk/32/24294_2.png) [@Fr4nk](https://root-forum.cern.ch/u/Fr4nk)\
**Post date:** [June 4, 2022, 10:52pm UTC](https://root-forum.cern.ch/t/issue-using-chi2test-regarding-a-bin-with-less-than-1-event/50266/7 "2022-06-04T22:52:27Z")

</div>

Hi @Wile_E_Coyote ,

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

I have now used:

```auto
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:

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

```

I receive the message:

```auto
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.
