# Why does this bug occur during Fit fitting

**URL:** <https://root-forum.cern.ch/t/why-does-this-bug-occur-during-fit-fitting/58384>\
**Category:** Newbie\
**Tags:** root\
**Created:** [March 5, 2024, 1:44am UTC](https://root-forum.cern.ch/t/why-does-this-bug-occur-during-fit-fitting/58384 "2024-03-05T01:44:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sun](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/49beb7/32.png) [@Sun](https://root-forum.cern.ch/u/Sun)\
**Post date:** [March 5, 2024, 1:44am UTC](https://root-forum.cern.ch/t/why-does-this-bug-occur-during-fit-fitting/58384/1 "2024-03-05T01:44:34Z")

</div>

```auto
  void plot102() {
  TFile * f = new TFile("spectra.root");
  TCanvas * c = new TCanvas("C","distri",100,100,1600,1200);
  c->DrawFrame(0,0,140,2.5);
  c->SetGrid();
  TH1F * h = (TH1F *)f->Get("h1000");
  TH1F * h1 = (TH1F *)f->Get("h1001");
  TH1F * h102 = new TH1F("h102","C distribution",150,0,150);
  h102->Divide(h1,h);
  h102->SetLineColor(kWhite);
  h102->SetMarkerStyle(20);
  h102->SetMarkerSize(1);
  h102->SetMarkerColor(kBlue);
  h102->Draw("same");
  TF1 * func = new TF1("func","1 + [0] * exp(-x * x * [1] * [1]/(0.1973 * 0.1973))",0,150);
  func->SetParNames("lamda","Radius");
  func->SetParameters(1,5);
  h102->Fit(func,"r");
  c->Print("fig102.jpg");
}

```

 ![微信图片_20240305093951](https://root-forum.cern.ch/uploads/default/original/3X/b/e/be83c09e217663e23385d2d482bf0111def01712.png)

This is the image that will come out

 ![微信图片_20240305093959](https://root-forum.cern.ch/uploads/default/original/3X/6/4/644f65347f6f0347030d466d8fcbd882248200d5.jpeg)  
I want to know why it hasn’t been fitted out yet

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [March 5, 2024, 6:44am UTC](https://root-forum.cern.ch/t/why-does-this-bug-occur-during-fit-fitting/58384/2 "2024-03-05T06:44:50Z")

</div>

Dear Sun,

Welcome to the ROOT community.  
It is hard to say, your model is not fitting well your data. Perhaps try to change the range in which you are fitting to accommodate your function, which looks like a Gaussian?

Best,  
D

---

<div class="post-metadata">

**Author:** ![Sun](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/49beb7/32.png) [@Sun](https://root-forum.cern.ch/u/Sun)\
**Post date:** [March 5, 2024, 10:35am UTC](https://root-forum.cern.ch/t/why-does-this-bug-occur-during-fit-fitting/58384/3 "2024-03-05T10:35:49Z")

</div>

Dear Danilo,

Yes, this is half a Gaussian function.  
I’ve tried changing the fitting parameters, but it fails. I get the same result and graph. Do you know why "Invaild Fitresult (status = 2) " appears in general? Or what is the meaning of " status = 2 " ?

Best,  
S

---

<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:** [March 5, 2024, 9:37pm UTC](https://root-forum.cern.ch/t/why-does-this-bug-occur-during-fit-fitting/58384/4 "2024-03-05T21:37:25Z")

</div>

Hi,

status=2 means that the Hessian is invalid. This is likely caused by the fact that the points closer to 0 have a very large spread. Do you have an uncertainty in the point that you can use for fitting ? If not, maybe you should average neighbouring points (e.g. using a TProfile class) before fitting ?

Lorenzo
