Renaming a TTree and subsequent hadd


I have a pyroot script wich renames a TTree. The part of it which does that I copied here:

for file in files: f=TFile(path+file,'UPDATE') for i,tree in enumerate(oldTrees): t=f.Get(oldTrees[i]) if not t: print 'Could not find tree '+oldTrees[i]+'. Skipping...' continue t.Write(newTrees[i]) gDirectory.Delete(oldTrees[i]+';*') del t f.Write() f.Close() del f print 'Renamed trees for '+file+'.'

Everything seems to work fine, but when I subsequently use hadd to merge the root files, suddenly the old Trees appear again (together with the new trees). For example I am calling the useless command

I would expect x.root and y.root being exactly the same, but unfortunately this is not the case. I guess I am not properly deleting the trees in my root file but I don’t know what I am doing wrong.

Any help is much appreciated. Thanks.

Hi all

It’s not like I haven’t tried before, but I think I just found the solution. Somehow I am confusing hadd and it loops over the TKey and the TName. When I use t.SetNameTitle() and set name, title and subsequently the key to the same value, it works. I cannot say I fully understood the issue, but it works now.

Thanks anyway.