Tree print and show in python

_Hi
i want to show and print tree but i do same as codes that i see in forum but i get error.


what’s my wrong?

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Well, you create an empty tree and then you ask for the second entry, and also ask for a leaf, still on an empty tree. What do you expect?

i want Print baranch of tree.
How can i get the "LHEF" tree ?
i do this in c++ by TTree *tree = (TTree *) myfile->Get("LHEF");

In your code, you an empty file (with the RECREATE) flag, and then create an empty tree. So here is what happens:

root [1] TFile *f = TFile::Open("ttbar.root", "RECREATE")
(TFile *) 0x104d3538
root [2] TTree *tree = new TTree();
root [3] tree->Print()
******************************************************************************
*Tree    :          :                                                        *
*Entries :        0 : Total =             267 bytes  File  Size =          0 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************
root [4]

i mean i want do this in python. TTree *tree = (TTree *) myfile->Get("LHEF"); didn’t work in python.

So the code should be something like this:

myfile = ROOT.TFile('ttbar.root', 'READ')
tree = ROOT.gROOT.FindObject('LHEF')

But since you wrote ROOT.TFile('ttbar.root', 'RECREATE'), you deleted the content of the ttbar.root file, which is now empty

very good that’s work.