Combining two root files

Dear ROOTers,
I have simple two root files,r1.root and r2.root which I have attached with this. r1 is simple sin(x) and r2 is sin(x)/x. If I want to display these two together then what will I do. I tried the command hadd as
hadd r3.root r1.root r2.root
but it gives error as:
Error: Symbol haddr3 is not defined in current scope (tmpfile):1:
Error: Failed to evaluate haddr3.rootr1
Error: Failed to evaluate haddr3.rootr1.rootr2
Error: Failed to evaluate haddr3.rootr1.rootr2.root

Please tell me how can I display these two functions in same canvas.
Thanks in advance.
Summitr2.root (13.1 KB)r1.root (13.1 KB)

Several problems with your post:
-you do not seem to have the program hadd in $ROOTSYS/bin or $ROOTSYS/bin is not in your PATH.
-hadd is not assumed to combine the content of canvases.
-I propose the following script to do what you want

Rene

void c12() { TFile *f1 = TFile::Open("r1.root"); TCanvas *c1 = (TCanvas*)f1->Get("c1"); c1->Draw(); TFile *f2 = TFile::Open("r2.root"); TCanvas *c2 = (TCanvas*)f2->Get("c1"); TF1 *func = (TF1*)c2->GetPrimitive("fun1"); c1->cd(); func->Draw("same"); }

Thanks for reply.
This code works.
I really want this what you send me,
but actually when I tried this on the root files z.root and y.root then it is not working.
Please tell me what will I do in this case. I have attached these files with this.
Thanks in advance,
Summit
z.root (80.9 KB)
y.root (41.3 KB)

see below

Rene

void yz() { TFile *f1 = TFile::Open("y.root"); TCanvas *c1 = (TCanvas*)f1->Get("c1"); c1->Draw(); TFile *f2 = TFile::Open("z.root"); TCanvas *c2 = (TCanvas*)f2->Get("c1"); TH1 *h2 = (TH1*)c2->GetPrimitive("h1__1"); c1->cd(); h2->Draw("same"); }

Thanks for reply
it is working
but I want to know…about this TH1 h2 = (TH1)c2->GetPrimitive(“h1__1”);
Sir, When I tried this on others then it creates an error.
And if I want to do same process with more than two files then what will I do?
Thanks in Advance,
Summit

I am not sure to understand what you want to do.
If you have more files to read, simply make a loop using as a model the few lines of code that I posted earlier.
In general it does not make any sense to combine many canvases on the same picture.
May be (but please explain your problem very clearly), you simply want to add ROOT files containing histograms and trees. In this case $ROOTSYS/bin/hadd is the program to use.

I strongly recommend to read at least a few pages of the documentation and the tutorials.

Rene

Dear ROOTer,
How can I multiply Y axis by a constant factor 0.08 without doing any change in X-axis?
I have attached a root file.
Thanks in advance,
t1.root (44.6 KB)


Rene

Rene

Dear ROOTers,
In t1.root file, there are number of points. If I want to join the points by a line(curve) or by average line then what will I do?
Thanks in advance,
Summit

Hello

How can I calculate FWHM for t1.root???

thanks,
Summit

As this is an old thread and your question seems somewhat different, can you open a new post which a fresh presentation of your issue?

Thanks,
Philippe.