# Gaussian Fit in a Histogram

**URL:** <https://root-forum.cern.ch/t/gaussian-fit-in-a-histogram/40593>\
**Category:** Newbie\
**Created:** [July 23, 2020, 7:19pm UTC](https://root-forum.cern.ch/t/gaussian-fit-in-a-histogram/40593 "2020-07-23T19:19:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheScientist](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@TheScientist](https://root-forum.cern.ch/u/TheScientist)\
**Post date:** [July 23, 2020, 7:19pm UTC](https://root-forum.cern.ch/t/gaussian-fit-in-a-histogram/40593/1 "2020-07-23T19:19:36Z")

</div>

I am trying to put Gaussian fit in my histogram. I tried several method, but was unable to do it. Here is my code.

```auto
TTree t;
t.ReadFile("NP02_HVCurrent_10-09-2019_11-09-2019.txt", "Unix_Time:Current");
TH1F h1("Current_Hist", "Current Vs Events; Current (micro amps); Events", 10, -5, 25);
t.Fit("gaus");
t.Draw("Current>>Current_Hist");

```

---

<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:** [July 24, 2020, 7:23am UTC](https://root-forum.cern.ch/t/gaussian-fit-in-a-histogram/40593/2 "2020-07-24T07:23:47Z")

</div>

Hi,  
you need to fill the histogram before you fit it:

```auto
TTree t;
t.ReadFile("NP02_HVCurrent_10-09-2019_11-09-2019.txt", "Unix_Time:Current");
TH1F h1("Current_Hist", "Current Vs Events; Current (micro amps); Events", 10, -5, 25);
t.Draw("Current>>Current_Hist");
h1.Fit("gaus");

```

Cheers,  
Enrico
