import ROOT # open a ROOT file file = ROOT.TFile.Open("myrootfile.root") # get the top level directory top_dir = file.GetDirectory("/") print(top_dir.GetName())
import ROOT # open a ROOT file file = ROOT.TFile.Open("myrootfile.root") # get a pointer to a subdirectory subdir = file.GetDirectory("/level1/level2") # iterate over histograms in that directory for key in subdir.GetListOfKeys(): hist = key.ReadObj() # do something with histogramIn this example, we open a ROOT file and use the GetDirectory method to get a pointer to a subdirectory ("level1/level2"). We then iterate over the histograms in that directory and perform some operation on them. The above examples use the ROOT package/library.