# Discontinuity in distribution of fit values

**URL:** <https://root-forum.cern.ch/t/discontinuity-in-distribution-of-fit-values/33465>\
**Category:** Newbie\
**Tags:** roofit, hist\
**Created:** [April 5, 2019, 5:43am UTC](https://root-forum.cern.ch/t/discontinuity-in-distribution-of-fit-values/33465 "2019-04-05T05:43:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [April 5, 2019, 5:43am UTC](https://root-forum.cern.ch/t/discontinuity-in-distribution-of-fit-values/33465/1 "2019-04-05T05:43:53Z")

</div>

I am plotting a histogram with the results of fitting 81233 TGraph objects.

For the fit I define the function `TF1 *Cosine = new TF1("Cosine", "[0]*cos([1]*x*1.e6 + [2])+[3]", 0., tmax)` and then

```auto
Cosine->SetParameters(A0, omega*1.e-6, phi0, 0.);
Cosine->SetParLimits(0, -1., 1.);
Cosine->SetParLimits(2, 0., M_PI); //acos have a range of 0,pi

gr->Fit("Cosine", "WRM");

```

The problem is that as you can see in the plot attached, there are almost no values around -0.3. This does not makes sense physically (the distribution should be smooth and continuous), and I checked that the data I am fitting is correct. I suspect that there is a problem when I do the fit, but I can’t think of anything.

![delta_omega](https://root-forum.cern.ch/uploads/default/original/3X/6/b/6bca8599b5e397b6ca9c31c0723ab0a61ceb86b9.png)

---

<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:** [April 5, 2019, 6:57am UTC](https://root-forum.cern.ch/t/discontinuity-in-distribution-of-fit-values/33465/2 "2019-04-05T06:57:14Z")

</div>

You fit the “gr” graph and get the “htemp” histogram?

```auto
{
  Double_t x[100], y[100];
  Int_t n = 20;
  for (Int_t i=0;i<n;i++) {
    x[i] = i*0.1;
    y[i] = 10*sin(x[i]+0.2);
  }
  gr = new TGraph(n,x,y);
  
  TF1 *Cosine = new TF1("Cosine", "[0] * cos([1] * x + [2]) + [3]",
                        gr->GetXaxis()->GetXmin(), gr->GetXaxis()->GetXmax());
  Cosine->SetParameters(1., 2., 3., 4.);
  Cosine->SetParLimits(2, 0., TMath::TwoPi());
  gr->Fit("Cosine", "WRM");
  
  gStyle->SetOptFit(112);
  gr->Draw("A*");
}

```

---

<div class="post-metadata">

**Author:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [April 5, 2019, 7:10pm UTC](https://root-forum.cern.ch/t/discontinuity-in-distribution-of-fit-values/33465/3 "2019-04-05T19:10:14Z")

</div>

I store the values of the parameter [1] in a TTree, and the histogram I attached is the histogram produced by the TBrowser when I open that TTree.

---

<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:** [April 5, 2019, 7:28pm UTC](https://root-forum.cern.ch/t/discontinuity-in-distribution-of-fit-values/33465/4 "2019-04-05T19:28:37Z")

</div>

I guess you could draw this parameter ([1]) versus the chi^2 of the fit, versus another parameters, versus the graph number and see if you find any unexpected / strange “correlations”.

---

<div class="post-metadata">

**Author:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [April 6, 2019, 5:25pm UTC](https://root-forum.cern.ch/t/discontinuity-in-distribution-of-fit-values/33465/5 "2019-04-06T17:25:29Z")

</div>

I did what you suggested, but I can´t find any strange correlation. I tried to give the -0.3e-6 as initial value, and as you can see in the plot attached, the gap is displaced now to -0.5e-6.  
 ![delta_omega_ap_Apr6](https://root-forum.cern.ch/uploads/default/original/3X/3/c/3c77d09c6b750aa5675c16b0199c58d0d26c36e9.png)

Giving now -0.5e-6 as initial value, the gap is displaced and a new ones appear. I am using the same data all the time. I believe this is a problem of the precision when fitting.

![delta_omega_ap_Apr6_2](https://root-forum.cern.ch/uploads/default/original/3X/d/c/dce7984b21cfa20b83ccd06dc97dae14c5ef53a3.png)

---

<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:** [April 7, 2019, 10:41am UTC](https://root-forum.cern.ch/t/discontinuity-in-distribution-of-fit-values/33465/6 "2019-04-07T10:41:49Z")

</div>

You can also try to inspect the: `Int_t fitStatus = gr->Fit("Cosine", "WRM");`  
Search for “Access to the fit” (“result” and “status”) in the [TGraph::Fit](https://root.cern.ch/doc/master/classTGraph.html#aa978c8ee0162e661eae795f6f3a35589) method description.
