Problem in plotting two histograms on one canvas

I have a problem in drawing two histograms in the same canvas. I use the .Draw() function:
hist1.Draw();
hist2.Draw(“SAME”);
canvas.SaveAs(“name.eps”);

What I get is the first histogram “run over” by the second: I can have a glimpse of the first one, and then I get the second histogram on-top, and I can’t see the first one anymore. I attach my code, and the ps file I get.
Thank you very much, Ayeleth.
2_Fast_Muons.ps (14.4 KB)
muon_manipulation.C (4.51 KB)

You forgot to send your input data file. I cannot run your test.
It would be better if you could save your 2 histograms in a small ROOT file
and send a short macro plotting these two histos.
I do not understand what can be wrong by just looking at your code.

Rene

This is the really weird thing: When I do as you said (see attached), I can actually get the right thing…
Also, I have a problem with attaching my data file: it is 7.7MB .root file… If you have any suggestions, I ready.
Thank you again,
Aye.
problem.C (1.97 KB)
2_Fast_Muons.ps (10 KB)

[quote]This is the really weird thing: When I do as you said (see attached), I can actually get the right thing…
[/quote]
so what is the problem if it works?

[quote]Also, I have a problem with attaching my data file: it is 7.7MB .root file… If you have any suggestions, I ready.
[/quote]
You cannot attach files greater than 50Kb. Post them in some public area
or reproduce the problem with a very small file.

Rene

The problem is that I want to get my two histogram together on the same canvas within the scope of a bigger code, and I wouldn’t like to run a special code, that I have to create, anytime that I want to get two histograms on the same canvas.
Aye.

I put the data file in my public folder, I hope it may help you to tell me why I have this problem.

/afs/cern.ch/user/a/adevir/public/jpsi_test.root

Could you reformulate your problem?
What you get in the ps file is correct. Is your problem with the ps file or with the graphics on screen.
Note that with your example, you will not see any pictures on teh screen
because all your objects (canvas and histograms) are created on the stack.
They will be automatically destroyed when leaving the scope of the function.
Use new instead to create your objects.

Rene

My problem is that I can’t use the Draw(“SAME”) function as it is supposed to work in my long code (see past attachment - muon_manipulation.C). It seem only to work in a small code (see past attachment - problem.C), that only draw the specific histogram with which I have the problem. Unfortunately, I want to use the Draw(“same”) in the scope of the long code.
I also tried using the new to creat my objects, but again it didn’t help.
Aye.

see attachment. I have modified your code in muon_manipulation.C
-to create all objects with new (such that you see the result on the screen)
-fixed your problem with option “same”

Rene
muon_manipulation.C (4.89 KB)

Thank you!