# Not sure how to use ROOT's Landau Gaussian convolution Fit

**URL:** <https://root-forum.cern.ch/t/not-sure-how-to-use-roots-landau-gaussian-convolution-fit/35693>\
**Category:** Newbie\
**Created:** [August 19, 2019, 3:11pm UTC](https://root-forum.cern.ch/t/not-sure-how-to-use-roots-landau-gaussian-convolution-fit/35693 "2019-08-19T15:11:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaylmao](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@aaylmao](https://root-forum.cern.ch/u/aaylmao)\
**Post date:** [August 19, 2019, 3:11pm UTC](https://root-forum.cern.ch/t/not-sure-how-to-use-roots-landau-gaussian-convolution-fit/35693/1 "2019-08-19T15:11:36Z")

</div>

Hi everyone, I’m new to ROOT and I’m trying to fit histogram data using the Landau Gaussian convolution fit found in: [https://root.cern.ch/doc/v614/langaus\_8C\_source.html](https://root.cern.ch/doc/v614/langaus_8C_source.html). My data is in a text file with each row containing the histogram count data with a total of 150 lines. e.g.:  
256  
8716  
13051  
8921  
6527  
…  
23  
16  
33

How do I allow the ROOT program to read the data inside the text file and then what kind of command should I input inside the ROOT session to successfully output the fit graph? Please explain it step by step, as I’m very new to ROOT. Thanks for the help in advance.

---

<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:** [August 20, 2019, 12:32pm UTC](https://root-forum.cern.ch/t/not-sure-how-to-use-roots-landau-gaussian-convolution-fit/35693/2 "2019-08-20T12:32:11Z")

</div>

Something like that:

```auto
void ascii2hist()
{
   int i=0;
   FILE *fp;
   fp = fopen("ascii2hist.dat","r");

   float x;
   auto h = new TH1F("h","h",150,0.,150);
   while (!feof(fp)) {
      fscanf(fp,"%g\n",&x);
      i++;
      h->SetBinContent(i,x);
   }
   h->Fit("...");
}

```

---

<div class="post-metadata">

**Author:** ![aaylmao](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@aaylmao](https://root-forum.cern.ch/u/aaylmao)\
**Post date:** [August 20, 2019, 9:51pm UTC](https://root-forum.cern.ch/t/not-sure-how-to-use-roots-landau-gaussian-convolution-fit/35693/3 "2019-08-20T21:51:53Z")

</div>

Hey, thanks for the help. Do I add this line of code in the .C file? Could you tell me what I’m supposed to do? Cheers.

---

<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:** [August 21, 2019, 6:48am UTC](https://root-forum.cern.ch/t/not-sure-how-to-use-roots-landau-gaussian-convolution-fit/35693/4 "2019-08-21T06:48:50Z")

</div>

This is a C++ macro. You should create a file `ascii2hist.C` and put this code inside. Then you execute it in `root` by typing `.x ascii2hist.C`. Of course the file name containing your data should be changed to the real name of your file.
