Simple problem, can't seem to get this to work

Hi there, I have TCanvas graphs I’ve made and I want to display them all on a single graph that’s been partitioned.
I’ve tried a lot of variations but basically this is the code I’ve been writting:

{
TCanvas *C = new TCanvas(“C”,“All Equilibrium Graphs”,1100,800); // This is the canvas I want to have all the graphs drawn in
C->Divide(2,2);
TFile *f1 = new TFile(“537Equilibrium.root”); // this file contains the graphs of interest
f1->ReadAll();
TCanvas *C1 = f1->Get(“c1”); //c1 is the graph I’m interested in placing on pad0 of the C canvas.
TVirtualPad *P1 = C1->GetPad(0);
C->GetPad(0) = P1;
C->GetPad(0)->Draw();
}

What am I doing wrong? Any help would be greatly appreciated! Thanks!

When you divide a canvas using C->Divide(2,2) you should use the TPad method “cd” to define in which pad you want to draw the next plot. So if “g” is the graph you want to draw simply do:

C->cd(1); // make the 1st C’s sub-pad the current one
g->Draw();

I hope this answer your question. As you do not have sent the file containing your graphs it is not possible to try your macro.

Thanks but no that doesn’t help. I tried the cd command earlier and again but it just doesn’t seem to draw the graph.
Here’s the file,
537Equilibrium.root (14 KB)

The way to do it would be:

{
   TCanvas *C = new TCanvas("C","All Equilibrium Graphs",1100,800);        
   C->Divide(2,2);
   TFile *f1 = new TFile("537Equilibrium.root"); 
   C->cd(1);
   C->Update();
   c1->DrawClonePad();
}

But I get a wrong picture (markers and text go away). I will investigate.

I ran your code snippet and it pops up a new window with the proper graph but the divided canvas is still empty. Did you get it to draw in the divided canvas?
Thanks for investigating!

Yes I get this:


Hmm… maybe it has to do with the version of root, I’m running 5.04 which isn’t the most up-to-date but pretty close.

I am using the latest version.

I guess what I’m after is a simple work-around to the problem. I went with using the cd command then Draw and when that initially failed to work I thought about accessing the pads directly, which should in theory be possible. Can you get my initial code to work in the new version? I get a “wrong l-value” error.

The error you get is normal. You should do at least:

{
   TCanvas *C = new TCanvas("C","All Equilibrium Graphs",1100,800);
   C->Divide(2,2);
   TFile *f1 = new TFile("537Equilibrium.root");
   f1->ReadAll();
   TCanvas *C1 = f1->Get("c1");
   TVirtualPad *P1 = C1->GetPad(0);
   TVirtualPad *C2 = C->GetPad(0);
   C2 = P1;
   C2->Draw();
}

With this you get no error but that does not solve your problem.

The problem was due to the fact that the Draw option in the original TGraphErrors was not set correctly. Here is a way to repair the original problem:

{ TFile *f1 = new TFile("537Equilibrium.root"); TCanvas *c1 = (TCanvas*)f1->Get("c1"); TCanvas *C = new TCanvas("C","All Equilibrium Graphs",1100,800); C->Divide(2,2); TPad *pad = (TPad*)C->cd(1); c1->DrawClonePad(); pad->GetListOfPrimitives()->FindObject("Graph")->SetDrawOption("alp"); pad->Modified(); }

Rene

Thanks for the help, but it still isn’t working. I get the graph in a different pop-up window and not in the intended split canvas. What draw option in TGraphErrors would be proper? Because I can re-generate the original graph easily. Here’s the code that produces the TGraph of interest.
The draw options I’m using are ALP, LP and LP.
Equilibrium.C (3.11 KB)

I understand the problem now. It is fixed in the development release 5.15/02 now in CVS.
Thanks for this reporting this problem.

Rene