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.

example:

myrootfile.root

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
hist.Draw();
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”);
f.Delete(“hist;1”);

see doc of TFile/TDirectory

Rene

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;1)
f->Delete(h1;2)
f->Delete(h1;3)

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

many thanks in advance

Hi,

Use f->Purge(“h1”);

Cheers,
Philippe.

thanx a lot i can breath easier now :smiley:
i may add that the command
f->Purge();
deletes old cycles for every histograms in the file.
thank you again