Hi all, I am trying to draw a horizontal line ay y =0 in the bottom pad, below a TGraph pad. However I am not seeing the line being drawn.
Can anyone please help in this regard?
Going through
Need to add a horizontal line at y=1 - #2 by Wile_E_Coyote,
I understand that the pad needs to be updated beforeTLine *line = new TLine(gPad->GetUxmin(), 0, gPad->GetUxmin(), 0);
however the problem still seem to persist.
Thank You
{
TCanvas *c1 = new TCanvas("c1","c1",800,800);
TPad *pad1 = new TPad("pad1", "pad1",0,0.33,1,1);
TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.33);
pad1->Draw();
pad2->Draw();
pad1->cd();
TF1 *func = new TF1("fitf","[3] + [2]*x + [0]/TMath::Sqrt(x + [1])", 0, 1400);
func->SetParameter(0,-919446);
func->SetParameter(1, 10545.5 );
func->SetParameter(2, -0.357829);
func->SetParameter(3, 8935.6);
func->SetParNames("a","b","c", "d");
const int n = 5;
double offset = -4
double x[n]= {344, 411, 779, 1089, 1299};
double y[n]= {0, 6.49+offset, 16.53+offset, 21.335+offset, 22.8+offset};
auto g = new TGraph(n,x,y);
g->Draw("AP*");
g->SetMarkerStyle(53);
g->SetMarkerSize(1.2);
g->Draw("AP");
g->Fit(func);
pad2->cd();
TGraphErrors* residual = new TGraphErrors;
for (int i =0 ; i <n; i ++){
residual->SetPoint(i , x[i], y[i] - func->Eval(x[i]) );
}
residual->Draw("ape");
residual->SetMarkerStyle(53);
gPad->Update();
TLine *line = new TLine(gPad->GetUxmin(), 0, gPad->GetUxmin(), 0);
line->Draw();
cout << gPad->GetUxmin() << gPad->GetUxmax() << endl;
}