Calling root file in TPad

Hello ROOTer,

In multi pad canvas, I have divided canvas into four pads (by using Divide(2,2)).
I have four root files. How can I call (or introduce) these four root files into pads.

Any suggestion please…

Thanks in advances,

Summit

You can draw whatever you like from any of your opened root files in any of your pads.
And vice versa. You can save any drawn object from any of your pads in any of your root files.
Use “MyCanvas->cd(1234);” to switch to one of your pads http://root.cern.ch/root/html/TCanvas.html#TCanvas:cd
Use “MyFile1234->cd();” to switch to one of your files http://root.cern.ch/root/html/TDirectoryFile.html#TDirectoryFile:cd
Search for “GetObject” in http://root.cern.ch/root/html/TDirectoryFile.html
Try also something like ‘MyFile1234->Write(“MyObject”)’ http://root.cern.ch/root/html/TFile.html#TFile:Write
See also, for example, “Input/Output” tutorials http://root.cern.ch/root/html/tutorials/io/index.html and HowTo’s http://root.cern.ch/drupal/content/howtos#io and the chapter in the User’s Guide http://root.cern.ch/drupal/content/users-guide

Hello

Thanks for reply
Can you suggest me something more please

I have divided the canvas as

TCanvas *myfile = new TCanvas(“myfile”,“can1”,1);
myfile->Divide(2,2);
myfile->cd(1);

How can I draw graph1.root in the pad 1?

Thanks
Summit
graph1.root (218 Bytes)

You cannot draw a root file (additionally, your “graph1.root” is empty inside).
Read my post again, see the User’s Guide.

Hello

extremely sorry for that
there was mistake in saving the file

now I have attached root file grph1.root
please guide me more to plot this

Thanks in advance,

Summit
grph1.root (14.6 KB)

TFile *f1 = new TFile("grph1.root"); // open the root file for reading f1->ls(); // see what's inside TCanvas *c1 = ((TCanvas *)0); // there's a "KEY: TCanvas c1;1 c1" inside f1->GetObject("c1", c1); // retrieve the object from the file c1->Draw(); // draw it

Thanks,

It is plotted in another Canvas and not in that pad of canvas which I want.

See what TCanvas means http://root.cern.ch/root/html/TCanvas.html and what TPad means http://root.cern.ch/root/html/TPad.html

Hello
extremely sorry.
I am trying to explain it in detail.

I have seen the links which you have sent.

In the first link there was an image. In canvas, there are four pads. I have made the empty pads in canvas by using the code
TCanvas *myfile = new TCanvas(“myfile”,“can1”,1);
myfile->Divide(2,2);

I have four different root files one of which is grph1.root. How can I use that root files in these four pads of pad1.root so that it look like as shown in image on root.cern.ch/root/html/TCanvas.html.

I hope you can understand my problem.

Thanks,

regards,

Summit
pad1.root (10.7 KB)

root [0] TFile *f1 = new TFile("pad1.root"); root [1] f1->ls(); TFile** pad1.root TFile* pad1.root KEY: TCanvas myfile;1 can1

Try this in one root session:

[code]{
TCanvas *c0 = new TCanvas(“c0”, “c0”);
c0->Divide(2,2);
c0->Modified();
c0->Update();

c0->cd(1);
// … draw anything you like in the pad 1 here …
(new TText(0.5, 0.5, “pad 1”))->Draw();
gPad->Modified();
gPad->Update();
gPad->SaveAs(“pad1.root”);

c0->cd(2);
// … draw anything you like in the pad 2 here …
(new TText(0.5, 0.5, “pad 2”))->Draw();
gPad->Modified();
gPad->Update();
gPad->SaveAs(“pad2.root”);

c0->cd(3);
// … draw anything you like in the pad 3 here …
(new TText(0.5, 0.5, “pad 3”))->Draw();
gPad->Modified();
gPad->Update();
gPad->SaveAs(“pad3.root”);

c0->cd(4);
// … draw anything you like in the pad 4 here …
(new TText(0.5, 0.5, “pad 4”))->Draw();
gPad->Modified();
gPad->Update();
gPad->SaveAs(“pad4.root”);

c0->cd(0);
}[/code]

Then try this in another root session:

[code]{
TCanvas *c1 = new TCanvas(“c1”, “c1”);

TFile *f1 = new TFile(“pad1.root”);
// f1->ls();
TPad *c0_1 = ((TPad *)0);
f1->GetObject(“c0_1”, c0_1);
if (c0_1) c0_1->Draw();

TFile *f2 = new TFile(“pad2.root”);
// f2->ls();
TPad *c0_2 = ((TPad *)0);
f2->GetObject(“c0_2”, c0_2);
if (c0_2) c0_2->Draw();

TFile *f3 = new TFile(“pad3.root”);
// f3->ls();
TPad *c0_3 = ((TPad *)0);
f3->GetObject(“c0_3”, c0_3);
if (c0_3) c0_3->Draw();

TFile *f4 = new TFile(“pad4.root”);
// f4->ls();
TPad *c0_4 = ((TPad *)0);
f4->GetObject(“c0_4”, c0_4);
if (c0_4) c0_4->Draw();

c1->cd();
c1->Modified();
c1->Update();
}[/code]

Another example …

Try this in one root session:

[code]{
TCanvas *c0 = new TCanvas(“c0”, “c0”);

TPad *p0 = new TPad(“p0”, “p0”, 0.0, 0.0, 1.0, 1.0);
p0->Draw();
p0->Modified();
p0->Update();

p0->cd();

gPad->Clear();
// … draw anything you like in the pad 1 here …
(new TText(0.5, 0.5, “pad 1”))->Draw();
gPad->Modified();
gPad->Update();
gPad->SaveAs(“pad1.root”);

gPad->Clear();
// … draw anything you like in the pad 2 here …
(new TText(0.5, 0.5, “pad 2”))->Draw();
gPad->Modified();
gPad->Update();
gPad->SaveAs(“pad2.root”);

gPad->Clear();
// … draw anything you like in the pad 3 here …
(new TText(0.5, 0.5, “pad 3”))->Draw();
gPad->Modified();
gPad->Update();
gPad->SaveAs(“pad3.root”);

gPad->Clear();
// … draw anything you like in the pad 4 here …
(new TText(0.5, 0.5, “pad 4”))->Draw();
gPad->Modified();
gPad->Update();
gPad->SaveAs(“pad4.root”);

c0->cd();
}[/code]

Then try this in another root session:

[code]{
TCanvas *c1 = new TCanvas(“c1”, “c1”);
c1->Divide(2,2);
c1->Modified();
c1->Update();

TFile *f1 = new TFile(“pad1.root”);
// f1->ls();
TPad *p0_1 = ((TPad *)0);
f1->GetObject(“p0”, p0_1);
c1->cd(1);
if (p0_1) p0_1->Draw();

TFile *f2 = new TFile(“pad2.root”);
// f2->ls();
TPad *p0_2 = ((TPad *)0);
f2->GetObject(“p0”, p0_2);
c1->cd(2);
if (p0_2) p0_2->Draw();

TFile *f3 = new TFile(“pad3.root”);
// f3->ls();
TPad *p0_3 = ((TPad *)0);
f3->GetObject(“p0”, p0_3);
c1->cd(3);
if (p0_3) p0_3->Draw();

TFile *f4 = new TFile(“pad4.root”);
// f4->ls();
TPad *p0_4 = ((TPad *)0);
f4->GetObject(“p0”, p0_4);
c1->cd(4);
if (p0_4) p0_4->Draw();

c1->cd(0);
c1->Modified();
c1->Update();
}[/code]

I’ve found “TCanvas::DrawClonePad()” … this should do exactly what you want …

Try this:

[code]{
TCanvas *c0 = new TCanvas(“c0”, “c0”);

c0->Clear();
// … draw anything you like in the pad 1 here …
(new TText(0.5, 0.5, “pad 1”))->Draw();
c0->Modified();
c0->Update();
c0->SaveAs(“pad1.root”);

c0->Clear();
// … draw anything you like in the pad 2 here …
(new TText(0.5, 0.5, “pad 2”))->Draw();
c0->Modified();
c0->Update();
c0->SaveAs(“pad2.root”);

c0->Clear();
// … draw anything you like in the pad 3 here …
(new TText(0.5, 0.5, “pad 3”))->Draw();
c0->Modified();
c0->Update();
c0->SaveAs(“pad3.root”);

c0->Clear();
// … draw anything you like in the pad 4 here …
(new TText(0.5, 0.5, “pad 4”))->Draw();
c0->Modified();
c0->Update();
c0->SaveAs(“pad4.root”);
}[/code]

Then try this:

[code]{
TCanvas *c1 = new TCanvas(“c1”, “c1”);
c1->Divide(2,2);
c1->Modified();
c1->Update();

TCanvas *c0 = ((TCanvas *)0);

TFile *f1 = new TFile(“pad1.root”);
// f1->ls();
f1->GetObject(“c0”, c0);
c1->cd(1);
if (c0) c0->DrawClonePad();

TFile *f2 = new TFile(“pad2.root”);
// f2->ls();
f2->GetObject(“c0”, c0);
c1->cd(2);
if (c0) c0->DrawClonePad();

TFile *f3 = new TFile(“pad3.root”);
// f3->ls();
f3->GetObject(“c0”, c0);
c1->cd(3);
if (c0) c0->DrawClonePad();

TFile *f4 = new TFile(“pad4.root”);
// f4->ls();
f4->GetObject(“c0”, c0);
c1->cd(4);
if (c0) c0->DrawClonePad();

c1->cd(0);
c1->Modified();
c1->Update();
}[/code]