Hello,
I want to plot two graph from two separate root files into one canvas. I am able to get one plot but I could not able to plot two in one canvas. The key of the plot in the root file is canvas.
I have attached my code here.
I would be very grateful if anyone helps me.
Thanks! first.root (11.7 KB) second.root (11.7 KB)
void readplot(){
TFile* f1 = new TFile("first.root","READ");
TFile* f2 = new TFile("second.root","READ");
TCanvas* h1;
TCanvas* h2;
f1->GetObject("c",h1);
f2->GetObject("c",h2);
h1->Draw();
//h1->SetLineColor(kRed);
//h2->SetLineColor(kBlue);
h2->Draw("same");
}
You access TCanvas. You cannot superimpose TCanavs like histograms.
Moreover your canvases do not contain histograms they contains TGraphAsymmErrors
You can try to get them from the canvas with:
You should not stored the canvases. You should store the TGraphs. Storing the canvases is not practical at all !
Any way with these two files you can do some tricks… but that’s really not straight forward:
Processing Lumi.C...
Error in <TFile::TFile>: file /Users/couet/Downloads/2_Y_0190_PLT.root does not exist
Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments
Execution of your code was aborted.
In file included from input_line_9:1:
/Users/couet/Downloads/Lumi.C:4:28: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
TCanvas *c1 = (TCanvas*)f1->Get("c");
^~
root [0]
Processing Lumi.C...
Error in <TFile::TFile>: file /Users/couet/Downloads/2_Y_0190_PLT.root does not exist
Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments
Execution of your code was aborted.
In file included from input_line_9:1:
/Users/couet/Downloads/Lumi.C:4:28: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
TCanvas *c1 = (TCanvas*)f1->Get("c");
^~
You’re welcome. But it would be much better to store directly the TGraphs instead of the TCanvas and the TPad, The way you proceed is really not practical.