# Number of entries in histogram bin with weighted submisisons?

**URL:** <https://root-forum.cern.ch/t/number-of-entries-in-histogram-bin-with-weighted-submisisons/44423>\
**Category:** Newbie\
**Created:** [April 15, 2021, 12:06pm UTC](https://root-forum.cern.ch/t/number-of-entries-in-histogram-bin-with-weighted-submisisons/44423 "2021-04-15T12:06:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggsAndCoffee](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/ecb155/32.png) [@eggsAndCoffee](https://root-forum.cern.ch/u/eggsAndCoffee)\
**Post date:** [April 15, 2021, 12:06pm UTC](https://root-forum.cern.ch/t/number-of-entries-in-histogram-bin-with-weighted-submisisons/44423/1 "2021-04-15T12:06:40Z")

</div>

Hello,

Is there a way to figure out the number of entries in a bin of a histogram that has had its entries weighted? For example, is there a way to do something like:

```auto
TH1D *myHisto = new TH1D("myHisto","myHisto",5,0,5);
myHisto->Fill(1,0.2);
myHisto->Fill(1,0.23);
myHisto->Fill(1,0.9);
myHisto->FunctionThatReturnsNumberOfEntriesInBin(); // THIS IS WHAT I NEED

```

Is there something like FunctionThatReturnsNumberOfEntriesInBin() that would tell me that the bin containing 1 had 3 entries placed in it, even though the bin content is 0.2+0.23+0.9=1.33?

Thank you.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [April 16, 2021, 12:14pm UTC](https://root-forum.cern.ch/t/number-of-entries-in-histogram-bin-with-weighted-submisisons/44423/2 "2021-04-16T12:14:34Z")

</div>

Hi @eggsAndCoffee ,  
I think TH1 does not store an entry count for each bin separately from the bin contents, you might want to use a second histogram for that.

@moneta please correct me if I’m wrong.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [April 16, 2021, 1:49pm UTC](https://root-forum.cern.ch/t/number-of-entries-in-histogram-bin-with-weighted-submisisons/44423/3 "2021-04-16T13:49:17Z")

</div>

Hi,  
The histogram does not collect that information, but a `TProfile` does it in order to compute the bin statistics, (see `TProfile::GetBinEntries()`). However, it will compute in `Profile::GetBinContent` the average of the second variable, in your case the weights.

Lorenzo

---

<div class="post-metadata">

**Author:** ![eggsAndCoffee](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/ecb155/32.png) [@eggsAndCoffee](https://root-forum.cern.ch/u/eggsAndCoffee)\
**Post date:** [April 17, 2021, 7:44pm UTC](https://root-forum.cern.ch/t/number-of-entries-in-histogram-bin-with-weighted-submisisons/44423/4 "2021-04-17T19:44:31Z")

</div>

Thank you!
