# Avoiding accumulation out-of-range entries in the histogram's first and last bins

**URL:** <https://root-forum.cern.ch/t/avoiding-accumulation-out-of-range-entries-in-the-histograms-first-and-last-bins/39325>\
**Category:** ROOT\
**Created:** [May 8, 2020, 4:14pm UTC](https://root-forum.cern.ch/t/avoiding-accumulation-out-of-range-entries-in-the-histograms-first-and-last-bins/39325 "2020-05-08T16:14:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Newbie](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Newbie](https://root-forum.cern.ch/u/Newbie)\
**Post date:** [May 8, 2020, 4:14pm UTC](https://root-forum.cern.ch/t/avoiding-accumulation-out-of-range-entries-in-the-histograms-first-and-last-bins/39325/1 "2020-05-08T16:14:12Z")

</div>

Dear,

In the following piece of code, I’m converting Gaussians (TF1’s) to histograms (TH1D) in order to add them up in an eventloop. Adding up TF1’s failed since there is a limit on the number of iteration. With histograms, it works, however on the edges peaks are appearing that should be there, so I guess that out-of-range events are being added there. Is there a way to avoid that?

> Gaus\_tot = ROOT.TF1(“Gaus\_tot”,“gaus”,100, 200)  
> Hist\_tot = Gaus\_tot.GetHistogram()  
> Gaus\_i = ROOT.TF1(“Gaus\_i”,“gaus”,100, 200)  
> for iev in chain1:  
> Gaus\_i.Clear()  
> Gaus\_i = ROOT.TF1(“Gaus\_i”,“gaus”,100, 200)  
> Gaus\_i.SetParameters(1., iev.mean, iev.sigma)  
> Hist\_i = Gaus\_i.GetHistogram()  
> Hist\_tot.Add(Hist\_i, iev.weight)

---

<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:** [May 11, 2020, 7:49am UTC](https://root-forum.cern.ch/t/avoiding-accumulation-out-of-range-entries-in-the-histograms-first-and-last-bins/39325/2 "2020-05-11T07:49:26Z")

</div>

HI,

Can you please post a running script so we can understand where the problem is coming from ?  
I already answer in this related post

> [@Sum of TF1 in a loop](https://root-forum.cern.ch/t/sum-of-tf1-in-a-loop/39276/7):
>
> Hi Lorenzo, This solution looks promising (and efficient), do you need to pass a variable here? i.e. “par” in the definition I didn’t manage to run it In the meantime I figured out a way by basically converting TF1’s to TH1’s then add the histograms: for iev in chain1: Gaus\_i.Clear() Gaus\_i = ROOT.TF1(“Gaus\_i”,“gaus”,100, 200) Gaus\_i.SetParameters(1., iev.mean, iev.sigma) Hist\_i = Gaus\_i.GetHistogram() Hist\_tot.Add(Hist\_i, iev.weight) And this works, however on the edges of the histo…

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 25, 2020, 8:03am UTC](https://root-forum.cern.ch/t/avoiding-accumulation-out-of-range-entries-in-the-histograms-first-and-last-bins/39325/3 "2020-05-25T08:03:30Z")

</div>

Closed on May 25, 2020, 8:03am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
