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.
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:
tree->Draw("v");
You can find examples here: ROOT: Tree tutorials
Hi Couet,
Thank you for your message.
I tried the following macro:
void mymacro () {
TFile *f = new TFile(âmyrootfile.rootâ,âREADâ);
f->Draw(âleafnameâ);
}
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â);
tree->Draw(âbranchname.leafnameâ);
}
in terminal load, .x mymacro.C, it should at least give a histogram filling the leaf contents.
It gives:
bash: .x: command not found
and,
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.