Reading a file with multiple subdirectories

Hello! I have a root file with the following structure in TBrowser: file.root -> tree -> events. And in the events I have all the variable I want to analyze. I tried this piece of code in jupyter to read the file (I am completely new to root and PyRoot):

import ROOT as root

f = root.TFile(“file.root”)
t = f.Get(“tree”)
entries = t.GetEntriesFast()

If I print the entries, I get the right number of entries but I don’t know how to access the data in the file. If I didn’t have that events subdirectory, I would have just said t.variable, but now if I do this, the kernel crushes and I have to restart the program. Please any help?

Hi,

welcome to ROOT!
Here you can find the material we suggest to ROOT beginners: root.cern.ch/getting-started .
For this particular case, the simplest is to do:

f = root.TFile("file.root")

for event in f.tree.events:
   # Your analysis here, suppose each event has a collection of jets with their kinematic properties
   for jet in event.jets:
       print jet.pt()

Danilo