"Merge" two pads in one canvas

Dear rooters.

I have saved the results of some code in a TFile as TCanvas (which contains several histograms).
Now I would like to display this results with other histograms.
If I had only histograms I would just divide the main TCanvas (call “mc” below) and plot each histogram in a sub-pad.
Now, since I have a TCanvas as “result” (let’s call it “c”) I tried different approaches:
[ol]
[li] directly print the corresponding TPad of interested via c->GetPad(0), but this creates another TCanvas[/li]
[li] paint the primitives of “c” in the subpad of “mc”. Results in only the border of the pad being drawn.[/li]
[li] I though above “replacing” the subpad by a clone of c->GetPad(0) but don’t know how to do that.[/li][/ol]

Is there any “simple” way of doing this ?

Thank you in advance
Julien

May be you should have saved the histograms and not the canvases…
Try to get the the histogram in the canvas and draw it
c1->GetListOfPrimitives()->FindObject(…)

Dear Olivier,

Thank you for the suggestion.
I did not write it in my first post but I did try this method, in a little more complex way since I have more
than an object in my canvas (this is one of the reason I saved the canvas not the object).
For a simple object it works (although I loose the canvas formatting). But for all primitives, it does not work.
Here is the minimal code I used to plot all :

TList *l = c->GetListOfPrimitives(); TIter next(l); TObject *obj; mc->cd(2); while (( obj= next())){ obj->Draw(next.GetOption()); cout << obj << endl; }

Although l->Print() give me something the loop does not work.
Can you help me here ?

Regards
Julien

Ok … so let my try to understand what you need.

0) start root
1) create two TCanvas c1 and c2
2) save them in the root file f.root
3) quit root
4) re-start root
5) open f.root
6) create the main canvas C
7) divide C in 2 pads
8) draw c1 in the 1st subpad
9) draw c2 in the 2nd subpad

is that what I should try to simulate ?

Dear Olivier,

Yes. Exactly.

Julien

Hi Julien,

  1. create the file with two canvases:
{
   TCanvas *c1 = new TCanvas();
   c1->Draw();
   hpx->Draw();
   TCanvas *c2 = new TCanvas();
   c2->Draw();
   hpxpy->Draw();
   TFile *fm = new TFile("fm.root","RECREATE");
   c1->Write();
   c2->Write();
}
  1. Draw the two canvases in the same canvas:
{
   TFile *fm = new TFile("fm.root");
   TCanvas *p1 =  (TCanvas *)fm->Get("c1");
   TCanvas *p2 =  (TCanvas *)fm->Get("c1_n2");
   TCanvas *C = new TCanvas();
   C->Divide(2,1);
   C->cd(1);
   p1->DrawClonePad();
   C->cd(2);
   p2->DrawClonePad();
}

Olivier

1 Like

Olivier,

Thank you: DrawClonePad() did the job.

Regards
Julien