How to plot two variables from one root file


I have a root file from which I have to plot two variables against each other, for example, velocity on y axis and momentum on the x axis.

How would I proceed with this?

Any help would be greatly appreciated!

Thank you.


What type of data do you have?

In general, a TGraph is useful to plot two arrays of values (in your case here the velocity and the momentum, see first example of the link)


Thank you for your reply!

The data file in question contains kinematic variables produced at the generator level. (px,py,pz,en,ma).

I want to draw beta(v/c) on the y axis and momentum on the x axis, however, I can’t seem to change the y axis to beta as it only seems to plot the number of events.

Should I still process with the link you kindly provided?

Thank you!

If your data are stored in a tree, I would suggest TChain to read the values of your variables per event, then you can use TGraph to plot

Hi try like tree->Draw(“y:x”), where tree is your own tree name.


Thank you @ROOTer1 and @renqipan your help!

I learned two ways to solve my problem !

Kind regards