Hello,
I’ve encountered a problem recently. I don’t recall it in the past versions of root, but maybe it was there. It seems that TF2 drawn on top of TGraph2D does not adjust it ranges to the TGraph2D ranges, but thinks it is drawn over it’s original ranges. This is a sample code of a cone drawing and fitting:
auto g = new TGraph2D();
for(int x=0; x<100; ++x)
for(int y=0; y<100; ++y)
g->SetPoint(g->GetN(), x+50, y+50, sqrt(x*x+y*y)/2+10);
g->Draw("P0");
auto f5 = new TF2("f5", "sqrt((x-[0])^2+(y-[1])^2)/[2]+[3]", 0, 150, 0, 150);
f5->SetParameters(10, 0, 1, 0);
//f5->SetRange(0,0,150,150);
g->Fit(f5);
f5->Draw("same surf");
You can see that even though the function fits perfectly and should cover the points of the graph exactly, it is shifted. If I draw the function first, and then the TGraph2D on top of it, the graph adapts axes properly.
Perhaps it is just a missing feature, that I somehow have not missed before…
Btw. would you mind adding a method for TGraph and TGraph2D that calls SetPoint(this->GetN()…)? For me, and probably not only me, adding single points one by one is the most common scenario, so a method, for example AddPoint(x,y, (z)) that calls SetPoint(this->GetN(), x, y, (z)) would be really helpful.
ROOT Version: 6.22
Platform: Fedora 30
Compiler: Not Provided