import ROOT file = ROOT.TFile.Open("myrootfile.root") keys = file.GetListOfKeys() print("Keys in file:") for key in keys: print(key.GetName())
import ROOT file = ROOT.TFile.Open("myotherfile.root") keys = file.GetListOfKeys() for key in keys: obj = key.ReadObj() if isinstance(obj, ROOT.TH1): # Do something with the TH1 histogram pass elif isinstance(obj, ROOT.TTree): # Do something with the TTree passThis code opens a different ROOT file and loops over its keys. For each key, it calls ReadObj() to read the object from the file. It then checks if the object is a TH1 histogram or a TTree and performs some action based on the object type. This example is also using the ROOT package library.