# Fitting Poisson

**URL:** <https://root-forum.cern.ch/t/fitting-poisson/50374>\
**Category:** Newbie\
**Created:** [June 12, 2022, 2:36am UTC](https://root-forum.cern.ch/t/fitting-poisson/50374 "2022-06-12T02:36:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gec](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@Gec](https://root-forum.cern.ch/u/Gec)\
**Post date:** [June 12, 2022, 2:36am UTC](https://root-forum.cern.ch/t/fitting-poisson/50374/1 "2022-06-12T02:36:38Z")

</div>

Getting memory leak after trying to fit histogram data to poisson function  
{

f=new TF1(“f”, “TMath::Poisson(x,[0])”, 0, 16);

```
h=new TH1D("h", "Histogram", 100, 0, 16);
h->Fill(2,3);
h->Fill(3, 13);
h->Fill(4, 22);
h->Fill(5, 26);
h->Fill(6, 31);
h->Fill(7, 45);
h->Fill(8, 46);
h->Fill(9, 42);
h->Fill(10, 26);
h->Fill(11, 18);
h->Fill(12, 14);
h->Fill(13, 8);
h->Fill(14, 5);
h->Fill(15, 2);	

c= new TCanvas();
h->Draw("hist");
h->Fit("f", "R");
f->Draw("SAME");

```

}

* * *

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [June 12, 2022, 6:45am UTC](https://root-forum.cern.ch/t/fitting-poisson/50374/2 "2022-06-12T06:45:00Z")

</div>

You need to give an initial value to the parameter/s of the fit function. Search for SetParameter in [ROOT: TF1 Class Reference](https://root.cern/doc/master/classTF1.html)  
Also, your data are not normalised, so you should multiply `f` by an additional (‘amplitude’) parameter, of course giving it an initial value too.

---

<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 12, 2022, 8:42am UTC](https://root-forum.cern.ch/t/fitting-poisson/50374/3 "2022-06-12T08:42:52Z")

</div>

> [@Poisson distribution for a given mean](https://root-forum.cern.ch/t/poisson-distribution-for-a-given-mean/33945/2):
>
> Some ideas:

---

<div class="post-metadata">

**Author:** ![Gec](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@Gec](https://root-forum.cern.ch/u/Gec)\
**Post date:** [June 14, 2022, 1:23pm UTC](https://root-forum.cern.ch/t/fitting-poisson/50374/4 "2022-06-14T13:23:15Z")

</div>

Thank you.
