Opening two .root file in the same canvas

Thank you for your help

These three root files contain three histograms (1,2,3)
Let’s suppose that I want to compare all histograms number number 2 in these three files.
Best Regards
essai3.root (9.4 KB)
essai2.root (9.74 KB)
essai1.root (10 KB)

Here is the script:
essai.C (286 Bytes)


Thanks a lot for your script. Unfortunately here comes my weakness in pointers and c++.
I get illegal pointer error message by running your script.

Could you pls look at these two specific root files: I tried to replace 2__1 and 2__2 instead of h1 and h2 , but I got:

Again many thanks in advance
essai2_2.root (16.1 KB)
essai1_2.root (16.1 KB)

Have you run the macro I sent you ? it should work if you do not modify it… does it ?


and the result is:

No really sorry…

I opened a new root window. it works… :slight_smile:

Could u please also help me with the two recent files , I sent u.
Really thanks


I type the same as your script in my terminal…

e.g: TH1D *h1=f1.Get("2__1"); instead

But when I do h1->Draw("l"); or h1->SetLineColor(kRed); I receive:

These file contains Canvases not histrograms … You are mixing up many diferents things…

root [0] TFile f("essai1_2.root")
root [1]
TFile**		essai1_2.root	
 TFile*		essai1_2.root	
  KEY: TCanvas	Canvas 1;1	Canvas 1
root [2] TCanvas *c = f.Get("Canvas 1");
root [3] c.Draw()

Yes you are right. The problem is that I have sort of limited time and I am sort of stressed unfortunately.

I have enclosed my two files again asking you another question. I will really appreciate if you help me with them.

  1. in essai3.root, the histogram number 2 is sort of noisy, but it is not the case in essai2.root, Nevertheless while superimposing them, the green dots represents a line like y=0 , not the histogram 2 in essai3.root!

  2. I need to have a legend,naming both histograms. I found this link: … ml#compare
    in section comparing histograms:

leg_hist = new TLegend(0.5,0.6,0.79,0.79); leg_hist->SetHeader("Some histograms"); leg_hist->AddEntry(hist_1,"First histo","l"); leg_hist->AddEntry(hist_2,"Second histo","l"); leg_hist->Draw();

in my case i only changed hist_1 with h2 and hist_2 with h3 for my case, and you know that it didn’t work.

I am really thankful if you help me with this as well.
essai2.root (9.74 KB)
essai3.root (9.4 KB)

Try this:

   TFile f1("essai1.root");
   TH1D *h1=f1.Get("2");
   TFile f2("essai2.root");
   TH1D *h2=f2.Get("2");
   TFile f3("essai3.root");
   TH1D *h3=f3.Get("2");

Could you please kindly run the script as well and see if you get the same result as 1and2and3.root?
1and2and3.root (18.2 KB)
essai3.root (9.66 KB)
essai2.root (9.97 KB)
essai1.root (9.61 KB)

Try the attached macro. It gives the attached picture.

essai2.C (495 Bytes)

Sorry, in the previous macro you should do:


instead of:


You will get this:

Great Thanks for your Help

Hello again,

Could you please also kindly help me in how to put label for my axes in ur script?

Thank you in advance

You mean axis title ?
it is something like:
Check the doc …

Yes I meant axis titles.
Could you please have a look at the enclosed script. I added the axis titles as well as another box using

[code]pt = new TPaveText(0.20,0.7,0.5,0.87, “NDC”);

text = pt->AddText(“Energy Deposition”);[/code]

But while I run essai2.C no change is observable!
essai2.C (827 Bytes)

   TFile f1("essai1.root");
   TH1D *h1=f1.Get("2");
   TFile f2("essai2.root");
   TH1D *h2=f2.Get("2");
   TFile f3("essai3.root");
   TH1D *h3=f3.Get("2");

   h1->SetTitle("Galactic emlivermore and elastic");
   h2->SetTitle("water emlivermore and elastic");   
   h3->SetTitle("water emlivermore");

   THStack *st = new THStack();

   st->GetXaxis()->SetTitle("This is my X title");
   st->GetYaxis()->SetTitle("This is my Y title");

I have the same thing here … I would like to join two files together … I am using GAMOS and ROOT …

I actually have no knowledge about ROOT at all … I only get histograms from GAMOS …

GAMOS outputs histograms in ROOT format … Each run produces one histogram.root

I would really appreciate it if someone teaches me this step by step … The things said about are OK to me , but where do I type all of these lines ? Right in terminal ?

Also, I am not sure I should know how to code in C++ to do any of the things said above … Please advise …


ROOT User Guides and Manuals