I want to compare two results in one canvas,

Hi Every Body,

I have two .root files including histograms. I got them from pythia8. 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.

Welcome to the ROOT forum.
At the ROOT prompt, you can do.:

auto c = new TCanvas();
TFile *f1 = TFile::Open("first.root");
c->cd(1); h1->Draw();
TFile *f2 = TFile::Open("second.root");
c->cd(2); h2->Draw();


actually, I have two root files and i want to compare the histogram in one graph.

Yes, the example I showed has two root files also.
It depends what you mean by “compare”?

I want to compare the results as shown in the attached image.

auto c = new TCanvas();
TFile *f1 = TFile::Open("first.root");
TFile *f2 = TFile::Open("second.root");

Thank you. It’s working.
how to add legend, xtitle, y title ?


h1->SetTitle("global title; X title; Y title");

Legend, see the doc:

okay. I got it.
Thank you. :blush:

why is it showing the information of the first root file? how to remove this?

Before drawing, execute: gStyle->SetOptStat(0);

If I have two root files and the plots are in the Tree format, then how to compare them?
and also how to normalize y axis?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.