Opening two .root file in the same canvas

Hi Every Body,

I have two .root files including histograms. I got them from AIDA in geant4. For opening these files I need root.
I need to open these two files in one canvas in order to be able to compare them.
I am wondering should I write a c++ code for that or can I do it easily from the browser?
Really thank for your help

What do you have in these root files ? Histograms ? trees ? Canvases ?..
I would say you should create a canvas, divide it using Divide(), do one plot in the first pad and the other in the pad next to it. For instance like in :
root.cern.ch/root/html/tutorials … opt.C.html
root.cern.ch/root/html/tutorials … dom.C.html
etc …

Hej,

I have histograms in those root files that I have to compare them.

No, I think using Divide() just put them close to each other .

I need something like: root.cern.ch/drupal/category/ima … ualization

The first screenshot from the left shows an Exclusion graph in ATLAS. You see there are more than one graphs in one canvas.

Thank you

You plot the first histogram then the 2nd one using the option SAME.

Hi again,

Can I ask you a very beginner question.
I need to create a script to type those codes, Could you please kindly tell me how I can create a script in root ?
Thank you again

In a file called simple.C you put:

{
   TFile f1("f1.root");
   h1->Draw();  // h1 is the first histogram to draw sitting in f1.root
   TFile f2("f2.root");
   h2->Draw("same");  // h2 is the 2nd histogram to draw sitting in f2.root
}

Then you enter root and you type “.x simple.C”

Aha Thanks :blush:

I have enclosed my two files,
By looking at the Superimposing Histograms with Different Scales script, I see that I only need to do

                                                             [code]2__2->Draw("same");[/code]

So I just combined the C code for two histograms and added the line above.

  1. I don’t think that I can see the file essai2_2.C in TBrowser :frowning:

2.I am just wondering that when I change a script, I don’t need to compile it in root! just execute it?

Thanks again
essai1_2.C (15.2 KB)
essai2_2.C (7.6 KB)

I think you should spend a bit of time reading the doc…
What you did cannot work … you cannot combine macros like that … [-X
do you have the root files with the histograms what to plot ? i will try to make a macro …

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)

Hello,

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 ?

Yes,

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

Sorry,

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] f.ls()
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:
    slac.stanford.edu/BFROOT/www … 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");
   
   h2->SetLineColor(kRed);
   h3->SetLineColor(kGreen);
   
   h1->Draw("l");
   h2->Draw("same");
   h3->Draw("same");
   
   gPad->BuildLegend();
}

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)