# Multiple root files in same canvas

**URL:** <https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498>\
**Category:** Newbie\
**Created:** [January 9, 2020, 12:55pm UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498 "2020-01-09T12:55:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_Kumar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@A\_Kumar](https://root-forum.cern.ch/u/A_Kumar)\
**Post date:** [January 9, 2020, 12:55pm UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498/1 "2020-01-09T12:55:21Z")

</div>

I have 4 root files (2 root files are generated from .C macro 1.root & 2.root which have x and y-axis value ) and the other two are histogram root files(geant1.rrot and geant2.root). The second part is causing some problems and without this program is doing very well. How should it be modified

```auto
{

TFile *f1 = TFile::Open("1.root");
c1->Draw();
Graph->GetYaxis()->SetRangeUser(1,10000);
Graph->GetXaxis()->SetRangeUser(4,10);
c1->SetLogy();
Graph->SetMarkerStyle(23);

////////////////////////////2nd part/////////////////////////////////

TFile *f5 = TFile::Open("2.root");
TCanvas *c1->Draw();
c1->Draw("same");
Graph->SetMarkerStyle(25);

//////////////////////////////////////////////////////////////////

TFile *f2 = TFile::Open("geant1.root");
TCanvas *c2 = (TCanvas*)f2->Get("h16");
h16->Draw("hist same");
h16->SetName("a");
a->SetLineStyle(7);
a->SetMarkerStyle(26);
a->SetLineColor(12);
a->SetLineWidth(2);

TFile *f3 = TFile::Open("geant2.root");
TCanvas *c3 = (TCanvas*)f3->Get("h16");
h16->Draw("hist same");
h16->SetName("b");
b->SetLineStyle(10);
b->SetMarkerStyle(29);
b->SetLineColor(4);
b->SetLineWidth(2);

leg = new TLegend(0.51,0.69,0.9,0.9);
   leg->SetHeader("result");
   leg->AddEntry(a,"a","l");
   leg->AddEntry(b, "b","l");
   leg->AddEntry(Graph,"ref1","p");
   leg->AddEntry(Graph,"ref2","p");
   leg->SetFillColor(10);
   leg->Draw();

}

```

\_ROOT Version:\_6.14  
_Platform:_ Ubuntu  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 9, 2020, 2:17pm UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498/2 "2020-01-09T14:17:06Z")

</div>

Option “SAME” does not exist for canvases.

```auto
c1->Draw("same")

```

has no meaning

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 9, 2020, 2:18pm UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498/3 "2020-01-09T14:18:14Z")

</div>

Can you provide the data files ?

---

<div class="post-metadata">

**Author:** ![A\_Kumar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@A\_Kumar](https://root-forum.cern.ch/u/A_Kumar)\
**Post date:** [January 9, 2020, 7:29pm UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498/4 "2020-01-09T19:29:57Z")

</div>

These are the macro files from which first root two files are generated-  
[1.C](https://root-forum.cern.ch/uploads/short-url/6ObxOwvontbMlEo3kQb0mGBeE0v.C) (248 Bytes)  
[2.C](https://root-forum.cern.ch/uploads/short-url/n27gHDeLHbGuwUi4VazOyg38GrM.C) (247 Bytes)

Root files created from these two macro files:  
[1.root](https://root-forum.cern.ch/uploads/short-url/5Ad6DQAw3VpcU4UcIHna6S8FLUw.root) (8.1 KB)  
[2.root](https://root-forum.cern.ch/uploads/short-url/sDFvVpEoAGuMqzo1kmTPpYCGexy.root) (8.1 KB)

Root file from Geant4:  
[geant1.root](https://root-forum.cern.ch/uploads/short-url/zJ2Yyc1hQpg7HTA9v8XtWuHkZok.root) (47.3 KB) [geant2.root](https://root-forum.cern.ch/uploads/short-url/oOmqtKxfhGwXCXbtfmpoeg4E0I4.root) (47.5 KB)

---

<div class="post-metadata">

**Author:** ![A\_Kumar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@A\_Kumar](https://root-forum.cern.ch/u/A_Kumar)\
**Post date:** [January 10, 2020, 10:45am UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498/5 "2020-01-10T10:45:02Z")

</div>

Hey @couet,  
Did you get/know the answer how to perform ?

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [January 11, 2020, 12:16pm UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498/6 "2020-01-11T12:16:01Z")

</div>

Olivier will reply next week, he is unavailable yesterday and this weekend.  
Axel

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 13, 2020, 1:24pm UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498/7 "2020-01-13T13:24:01Z")

</div>

```auto
void kumar()
{

   TFile *f1 = TFile::Open("1.root");
   TCanvas *c = (TCanvas *)f1->Get("c1");
   TGraphErrors *g1 = (TGraphErrors *)c->GetListOfPrimitives()->FindObject("Graph");
   c->Close();
   g1->GetYaxis()->SetRangeUser(1,10000);
   g1->GetXaxis()->SetRangeUser(4,10);
   g1->SetMarkerStyle(23);
   g1->Draw("AP");
   gPad->SetLogy();

   TFile *f2 = TFile::Open("2.root");
   c = (TCanvas *)f2->Get("c1");
   TGraphErrors *g2 = (TGraphErrors *)c->GetListOfPrimitives()->FindObject("Graph");
   c->Close();
   g2->SetMarkerStyle(23);
   g2->Draw("P");
   g2->SetMarkerStyle(25);

   TFile *f3 = TFile::Open("geant1.root");
   TH1D* h1 = (TH1D*)f3->Get("h16");
   h1->Draw("hist same");
   h1->SetLineStyle(7);
   h1->SetMarkerStyle(26);
   h1->SetLineColor(12);
   h1->SetLineWidth(2);

   TFile *f4 = TFile::Open("geant2.root");
   TH1D* h2 = (TH1D*)f4->Get("h16");
   h2->Draw("hist same");
   h2->SetName("b");
   h2->SetLineStyle(10);
   h2->SetMarkerStyle(29);
   h2->SetLineColor(4);
   h2->SetLineWidth(2);

   auto leg = new TLegend(0.51,0.69,0.9,0.9);
   leg->SetHeader("result");
   leg->AddEntry(h1,"a","l");
   leg->AddEntry(h2, "b","l");
   leg->AddEntry(g1,"ref1","p");
   leg->AddEntry(g2,"ref2","p");
   leg->SetFillColor(10);
   leg->Draw();
}

```

 ![21](https://root-forum.cern.ch/uploads/default/original/3X/0/1/014f92717891b4fb56d5e636154d104333cd3b1a.jpeg)

---

<div class="post-metadata">

**Author:** ![A\_Kumar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@A\_Kumar](https://root-forum.cern.ch/u/A_Kumar)\
**Post date:** [January 13, 2020, 1:27pm UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498/8 "2020-01-13T13:27:20Z")

</div>

Thanks @couet 🙂

---

<div class="post-metadata">

**Author:** ![A\_Kumar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c67d28/32.png) [@A\_Kumar](https://root-forum.cern.ch/u/A_Kumar)\
**Post date:** [January 14, 2020, 11:42am UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498/9 "2020-01-14T11:42:09Z")

</div>

Hi @couet  
I do not want 5.5, 6.5, 7.5 & 8.5 on x-axis (no decimal values). I tried with TGaxis::SetMaxDigits but no change observed.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 14, 2020, 12:05pm UTC](https://root-forum.cern.ch/t/multiple-root-files-in-same-canvas/37498/10 "2020-01-14T12:05:00Z")

</div>

```auto
   g1->GetXaxis()->SetNdivisions(509);

```
