import ROOT #Open the ROOT file file = ROOT.TFile("myrootfile.root", "READ") #Retrieve the histogram object hist = file.Get("histogram") #Delete the histogram object hist.Delete() #Save the changes made to the file file.Write() file.Close()
import ROOT #Open the ROOT file file = ROOT.TFile("myrootfile.root", "READ") #Retrieve the directory object dir = file.Get("directory") #Delete the directory object dir.Delete() #Save the changes made to the file file.Write() file.Close()In both examples, we are importing the ROOT package and opening a ROOT file named "myrootfile.root". We are then retrieving the respective objects (histogram or directory) using the Get() method and deleting them using the Delete() method. Finally, we are saving the changes made to the file using the Write() method and closing the file using the Close() method. The package library used for these examples is ROOT.