# Fit Line Is Not Shown

**URL:** <https://root-forum.cern.ch/t/fit-line-is-not-shown/58519>\
**Category:** ROOT\
**Tags:** roofit\
**Created:** [March 13, 2024, 1:09pm UTC](https://root-forum.cern.ch/t/fit-line-is-not-shown/58519 "2024-03-13T13:09:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sinem\_Anil](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sinem_anil/32/35923_2.png) [@Sinem\_Anil](https://root-forum.cern.ch/u/Sinem_Anil)\
**Post date:** [March 13, 2024, 1:09pm UTC](https://root-forum.cern.ch/t/fit-line-is-not-shown/58519/1 "2024-03-13T13:09:59Z")

</div>

My one fitline is shown on graph and another is not .Why ?

```cpp
 void fits()
{

   const int ndata = 19; // Adjusted to match the new number of data points

   float x[ndata] = {0.0, 0.0754, 0.1471, 0.2207, 0.2941, 0.3778, 0.4600, 0.5790, 0.7500, 0.8950,
                     1.065, 1.204, 1.350, 1.510, 1.712, 1.933, 2.121, 2.463, 2.765};

   float y[ndata] = {410.0e-12, 295.0e-12, 194.0e-12, 124.6e-12, 70.0e-12, 27.5e-12, 1.0e-12,
                     -23.0e-12, -37.0e-12, -46.0e-12, -50.0e-12, -52.0e-12, -54.0e-12, -55.0e-12,
                     -56.5e-12, -59.0e-12, -60.5e-12, -63.0e-12, -65.0e-12};

   float sx[ndata] = {0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};

   float sy[ndata] = {1e-12, 1e-12, 1e-12, 1e-12, 1e-12, 1e-12, 1e-12, 1e-12, 1e-12, 1e-12,
                      1e-12, 1e-12, 1e-12, 1e-12, 1e-12, 1e-12, 1e-12, 1e-12, 1e-12};

   TCanvas *c1 = new TCanvas("c1", "Fit Subranges", 200, 10, 700, 500);

   gStyle->SetOptFit(1111);

   TGraphErrors *graph = new TGraphErrors(ndata, x, y, sx, sy);

   graph->SetTitle("Green Light;X;Y");

   graph->SetMarkerStyle(21);

   graph->Draw("AP");

   // Define fits with clear distinction

   TF1 *fit1 = new TF1("fit1", "pol1", x[0], x[18]); // Adjust the drawing range to be more visible

   fit1->SetLineColor(kBlue);

   fit1->Draw("L SAME");

   TF1 *fit2 = new TF1("fit2", "pol1", x[0], x[18]); // Adjust the drawing range

   fit2->SetLineColor(kRed);

   fit2->Draw("L SAME");

   // Perform the fits

   graph->Fit(fit1, "R", "", x[0], x[5]); // First subrange

   graph->Fit(fit2, "R+", "", x[14], x[18]); // Second subrange

   // Intersection calculation remains unchanged

   double m1 = fit1->GetParameter(1); // Slope of the first fit

   double b1 = fit1->GetParameter(0); // Intercept of the first fit

   double m2 = fit2->GetParameter(1); // Slope of the second fit

   double b2 = fit2->GetParameter(0); // Intercept of the second fit

   double x_intercept = (b2 - b1) / (m1 - m2);

   double y_intercept = m1 * x_intercept + b1;

   std::cout << "Intersection point: (" << x_intercept << ", " << y_intercept << ")" << std::endl;

   // Draw a marker at the intersection point

   TGraph *intPoint = new TGraph(1, &x_intercept, &y_intercept);

   intPoint->SetMarkerStyle(29);

   intPoint->SetMarkerColor(kGreen);

   intPoint->Draw("P SAME");

   double x_intersect_zero = (b1 - b2) / (m2 - m1);

   std::cout << "Intersection point where y = 0: (" << x_intersect_zero << ", 0)" << std::endl;

   // Draw a marker at the intersection point where y = 0

   TMarker *intPointZero = new TMarker(x_intersect_zero, 0, 29);

   intPointZero->SetMarkerColor(kMagenta);

   intPointZero->Draw();

   c1->Update();
}

```

---

<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 13, 2024, 1:24pm UTC](https://root-forum.cern.ch/t/fit-line-is-not-shown/58519/2 "2024-03-13T13:24:54Z")

</div>

Dear Sinem,

Welcome to the ROOT community!  
Thanks for sharing this reproducer.  
Are you sure the second fit is succeeding? This is the output I get:

```auto
Minimizer is Minuit2 / Migrad
Chi2 = 0.29687
NDf = 3
Edm = 7.84439e-08
NCalls = 189
p0 = -4.33796e-11 +/- 3.88521e-12 
p1 = -7.92264e-12 +/- 1.74188e-12 

```

Best,  
D

---

<div class="post-metadata">

**Author:** ![Shiva\_Prasad\_Nayak](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/shiva_prasad_nayak/32/36391_2.png) [@Shiva\_Prasad\_Nayak](https://root-forum.cern.ch/u/Shiva_Prasad_Nayak)\
**Post date:** [March 15, 2024, 4:39am UTC](https://root-forum.cern.ch/t/fit-line-is-not-shown/58519/3 "2024-03-15T04:39:24Z")

</div>

```auto
   graph->Fit(fit1, "R EX0", "", x[0], x[5]); // First subrange

   graph->Fit(fit2, "R EX0 +", "", x[14], x[18]); // Second subrange

```

Read [here](https://root.cern/doc/master/classTGraph.html#TGraph:Fit:~:text=Fit()%20%5B2,TGraph.cxx.) this might help.
