Fit drawing bug when TGraph cloned?

Hello Folks,

I have a TGraphErrors with a fit. If I DrawClone or copy then Draw, the fit is not drawn the first time on a new canvas, then subsequently drawn incorrectly.

The original graph and fit, plotted correctly, are in the left pad of the attached figure. The middle pad is the result of DrawClone; the right comes from TGraphErrors *gc = new TGraphErrors(*g1); gc->Draw("AP");

I expected DrawCopy and the copy constructor to copy the fit as well, and draw it correctly, unless I’m doing something weird?

I haven’t had a chance yet to stare at the DrawClone or copy constructor code to see if the problem is obvious. (2.96 KB)
DrawFitBug2.cxx (3.84 KB)


the porblem is due to the cloning of TF1 objects. The Clone() method of TF1 does not copy the function formula, when is written as C++ code, but uses
a set of tabulated points which approximate the function. This should maybe be improved in the case of log scale.

In addition, when copying a TGraph, we should use the copy constructor of TF1 and not TF1::Clone() as it is done now.
A possible workaround, when copying the TGraph is

  TGraphErrors *gc = new TGraphErrors(*g1);
  // copy also the function  
  TF1 * f2 = gc->GetFunction("Fit");

where “Fit” is the name of the function.

Thank you for reporting this problem