Plot quantity stored in a leaf

Hi All,

How can I plot a quantity stored in a leaf of a root file by writing a macro?
Moreover, could you please point me to a basic guide with many examples of macros.

Thank you for your time.

If you speak about “leaf” it means you are using a TTree or a TNuple .
To draw a tree variable, v, simply do:


You can find examples here:

1 Like

Hi Couet,
Thank you for your message.
I tried the following macro:

void mymacro () {
TFile *f = new TFile(“myrootfile.root”,“READ”);

It gives no error but draws nothing. I would like to get a plot of the quantity stored in leafname.
Thank you for your time.

Hello John1,

Here, f is a TFile not a tree. It will work when there is tree instead of f and leafname is one of its leaf, for sure.

Hi NepNeeraj,
Could you please be more explicit?
If the name of my file is myrootfile.root, the name of the branch “branchname”, and the name of the leaf “leafname”, how should I proceed with a macro to plot the quantity stored in the leaf?
Thank you for your help.

I guess, your branchname is under tree, try this,

void mymacro(){
TFile *f = new TFile(“myrootfile.root”);

in terminal load, .x mymacro.C, it should at least give a histogram filling the leaf contents.

It gives:

bash: .x: command not found


error: use of undeclared identifier ‘tree’

. x is not a shell command. From the bash shell you can type:

$ root mymacro.C

or you can enter root just typing root and then type .x mymacro.C

$ root
root[0] .x mymacro.C

Now in your macro itself you attach the ROOT file myrootfile.root via the class TFile. That’s fine but as @NepNeeraj said that’s not your tree. The tree is inside this file. If you do not know the name of the tree you can type:

root [0] TFile *f = new TFile(“myrootfile.root”);
root [1] f->ls()

This will list the content or you file and you will see the name of the tree (if it exist) you want to access.

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