# Sum of TF1 in a loop

**URL:** <https://root-forum.cern.ch/t/sum-of-tf1-in-a-loop/39276>\
**Category:** Newbie\
**Created:** [May 6, 2020, 1:37am UTC](https://root-forum.cern.ch/t/sum-of-tf1-in-a-loop/39276 "2020-05-06T01:37:47Z")\
**Posts on this page:** 1\
**Showing post:** 7

<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, 2:28pm UTC](https://root-forum.cern.ch/t/sum-of-tf1-in-a-loop/39276/7 "2020-05-08T14:28:42Z")

</div>

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 histogram, peaks are appearing, which is due to accumulating events that doesn’t fall out the range. Any idea how to fix that?

---

_[View the full topic](https://root-forum.cern.ch/t/sum-of-tf1-in-a-loop/39276)._
