# Rebin TH1D with average

**URL:** <https://root-forum.cern.ch/t/rebin-th1d-with-average/53263>\
**Category:** Newbie\
**Tags:** root\
**Created:** [January 25, 2023, 9:39am UTC](https://root-forum.cern.ch/t/rebin-th1d-with-average/53263 "2023-01-25T09:39:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [January 25, 2023, 9:39am UTC](https://root-forum.cern.ch/t/rebin-th1d-with-average/53263/1 "2023-01-25T09:39:44Z")

</div>

Hi everbody,  
I would like to rein a histogram filled with percentages (like 0.45 and so on). Therefor I do not want the bins to be added up when rebinning but rather averaged. Is there an option to do this?  
Thanks,  
Emil

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 25, 2023, 10:17am UTC](https://root-forum.cern.ch/t/rebin-th1d-with-average/53263/2 "2023-01-25T10:17:55Z")

</div>

I guess @moneta can help you

---

<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:** [January 25, 2023, 11:01am UTC](https://root-forum.cern.ch/t/rebin-th1d-with-average/53263/3 "2023-01-25T11:01:16Z")

</div>

Hi,  
If you are plotting averages, maybe what you want to look is the `TProfile` class. See [ROOT: TProfile Class Reference](https://root.cern.ch/doc/master/classTProfile.html).  
Otherwise, please be more specific and possibly provide an example

Best

Lorenzo

---

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [January 25, 2023, 12:30pm UTC](https://root-forum.cern.ch/t/rebin-th1d-with-average/53263/4 "2023-01-25T12:30:35Z")

</div>

Thank you for your answer. I do not think the TProfile class is right for my problem. I have several histograms which I would like to divide, scale and add. All of them are “normal” histograms but one is filled with values from 0 to 1. I have to rebin all histograms, but the one with values between 0 and 1 should not be added up as usual but rather averaged over the bin merged together. Until now I simply do this “per hand” but was wondering whether there was an option in the “rebin” function to do this

---

<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:** [January 25, 2023, 12:47pm UTC](https://root-forum.cern.ch/t/rebin-th1d-with-average/53263/5 "2023-01-25T12:47:57Z")

</div>

`Int_t n = 5; myhisto->Rebin(n); myhisto->Scale(1. / n);`

---

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [January 25, 2023, 2:49pm UTC](https://root-forum.cern.ch/t/rebin-th1d-with-average/53263/6 "2023-01-25T14:49:19Z")

</div>

Thank you for your reply. I need to calculate the error weighted average, which makes things more complicated. But I have now simply written a short function myself. Still thanks for your help!
