Writing TPads into a root file

ROHLFS Reiner (Reiner.Rohlfs@obs.unige.ch)
Mon, 14 Sep 1998 11:31:13 +0200 (MET DST)


Hi ROOters,

please have a look to these two ROOT macros:

1) MakePads.C:
{
gROOT->Reset();

// Create a new canvas.
c1 = new TCanvas("Display","Display",10,10,300,200);

// make the first pad
pad1 = new TPad("Pad", "Pad", 0.1, 0.1, 0.5, 0.9);
pad1->SetFillColor(3);
pad1->Draw();
pad1->cd();

// make the second pad
pad2 = new TPad("Pad", "Pad", 0.6, 0.4, 0.9, 0.7);
pad2->SetFillColor(4);
pad2->Draw();

c1->SaveAs("pads.root");
}

and ReadPads.C:
{
gROOT->Reset();

TCanvas * c2;
file = new TFile("pads.root", "READ", "no", 1);
c2 = (TCanvas*)file->Get("Display");
c2->Draw();

file->Close();
}

That is the sequence I call these macros:
root [1] .x MakePads.C
ROOT file: pads.root has been created
root [2] delete c1
root [3] .x ReadPads.C

But now the pad2 is displayed beside the pad1 directly on the canvas c2. The
coordinates of pad2 (0.6, 0.4, 0.9, 0.7) are now relative to the canvas c2 and
not any more relative to the pad1 as defined in the MakePads.C macro.
Beside that the ExecuteEvent() - function of pad2 does not work any more after
reading the pads from the root file. ( The pad2 cannot be resized and removed
using the mouse and the menu of the right mouse button is lost.)

Cheers Reiner.