Fitting datas in multiple pads of the same canvas

Dear corooters, I want to plot on different pads but in the same canvas and get the results. This is my code that does’t work. Hope it’s not a problem for you!

    auto c1 = new TCanvas("c1", "Canvas", 200, 10, 1000, 600);
    c1->Divide(3, 1, 0.0002, 0.0002);
    
    //1 op
    c1->cd(1);

    TGraphErrors *fileInput = new TGraphErrors("../File/coniugati_fabio.txt", "%lg %lg %lg %lg");
    fileInput->Draw("AP");

    TF1 *line = new TF1("f1", func, 0.006, 0.0096, 2);
    line->SetParNames("b", "a");

    fileInput->Fit(line, "S");

    //2 op
    c1->cd(2);

    TGraphErrors *fileInput1 = new TGraphErrors("../File/coniugati_marco.txt", "%lg %lg %lg %lg");
    fileInput1->Draw("AP");

    TF1 *line = new TF1("f2", func, 0.006, 0.0096, 2);
    line->SetParNames("b", "a");

    fileInput1->Fit(line, "S");

    //3 op
    c1->cd(3);

    TGraphErrors *fileInput2 = new TGraphErrors("../File/coniugati_tommaso.txt", "%lg %lg %lg %lg");
    fileInput2->Draw("AP");

    TF1 *line = new TF1("f3", func, 0.006, 0.0096, 2);
    line->SetParNames("b", "a");

    fileInput2->Fit(line, "S");
}```

You are trying to create ‘line’ 3 times

TF1 *line = new TF1(...

(ROOT must have complained about this when you run the macro… check the errors you get). Also, in Fit() you should provide the name of the function (“f1”, “f2”…), not the “TF1 variable”; to avoid these confusions it’s safer to use the same name on both sides when creating the TF1, e.g.

TF1 *f1 = new TF1("f1", func, 0.006, 0.0096, 2);
//...
fileInput->Fit("f1", "S");
// ... and similar for f2, f3
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.