Question about adding two graphs on the same canvas

I am a sophomore student who just starts learning root. My question is: if I have two TTree objects, which are in two different files, how can I draw these two histograms based on the structure of the TTree objects and put them on the same canvass?
(I know I can use TFIle:: Open to open each one of the root files and then use T->Draw() method to plot two histograms on two separated canvass)

It would be best if you can explain this question in detail/or tell me any instruction I should read on User’s Manual(I am currently learning root through the User’s Guide.)
Thanks a lot!

When drawing the second histogram, in the TTree::Draw call, set the “option” parameter to “SAME”.

Note that “SAME” should be present but can be combined with other drawing options.

Thank you, I figure that out on the Draw Option of Histogram part!

Thanks a lot, i work that out!

Here is the list of draw options for histograms if you haven’t found it yet:

Not to be confused with the graph options:

Thanks for all previous support. I know how to superimpose two histograms of two TTree objects on the same canvas now. Followed by that, I still have some questions in order to improve the appearance of the two histograms.

First, how can I set different colors to different histograms and add legends for both of them as a short description?

Second, if the peak, the highest frequency, of one histogram goes beyond the current scope of the Y-axis (for a 1D histogram the y-axis stands for the frequency of the x-axis variable) whereas the peak of the other one stays within, how can i adjust the range of the Y-axis so that I can view the actual peaks for both histograms on the canvas? (Or alternatively, is there a way that I can set a limit for the highest frequency for both?)

Finally, is there a way that I can apply some function to the x-axis variable and plot a corresponding histogram? For instance, can I plot the frequency distribution of the log(original x-axis variable)?

Also, it would be best if you guys can point out a link/reference for me to read. As the User’s Manual has a lot of ‘redundant’ information related to my current questions.

Thanks a lot!!!

Try to play with the ${ROOTSYS}/tutorials/tree/cernstaff.C macro but, for your purposes, replace hGrades->Draw(); with hGrades->Draw("nostack");.

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