Histogram removal

I have generate a number of histograms within a root file and have determined some needed to be changed. After changing the histogram it was updated to myrootfile.root but was saved as another histogram with an index.



TH1F hist1;1
TH1F hist2;1
TH1F hist2;2

When trying to view hist2, it gives me hist2;1 and not the one most reciently generated (hist;2).

How do I remove hist2;1 from the root file?

I have tried several delete commands but none have removed any files from myrootfile.root.

You do not indicate your list of actions.
If you have two cycles for “hist” in the file, by default doing
will shop the top level cycle. If you are in the TBrowser, you can view
the cycle you want.

Now, to delete hist;1, open the file in update mode and do:
TFile f(“myfile.root”,“update”);

see doc of TFile/TDirectory


I have a very similar problem, is there a way to delete at once all the cycles exept the last one ?
or at least is there a method to get the latest cycle number of an object ? (so i can perform a dynamic loop to remove them…)

because doing

f->Delete(h1;145) by hand, would be an unaffordable waiste of time :open_mouth:

many thanks in advance


Use f->Purge(“h1”);


thanx a lot i can breath easier now :smiley:
i may add that the command
deletes old cycles for every histograms in the file.
thank you again