I have a root file containing 2 duplicate root TTrees, meaning I have 2 identical root trees called “Name1” and 2 identical root trees called “Name2”. How can I delete one of each trees? I want to end up with root file containing 1 tree called “Name1” and 1 tree called “Name2”.
Thank you in advance!
Could you clarify what you mean by “2 duplicate ROOT trees” ?
In case you mean 2 tree headers in your file name;1 and name;2, it means that the TTree::AutoSave function has been called during the filling of your Trees. each AutoSave writes a new key for the current version of the header. In case your job crashes you can always recover all entries up the last Autosave. If you are not interested by this feature, you can modify the frequency at which AutoSave is called via TTree::SetAutoSave.
See the doc of these 2 functions for more information.
thank you for your reply.
What I mean by “duplicate ROOT trees” is the following. When I open root file in root I get the following:
root  gDirectory->ls();
KEY: TTree allMuons;86 all muons in event
KEY: TTree allMuons;85 all muons in event
KEY: TTree Event;19 muons in event
KEY: TTree Event;18 muons in event
I do not understand. Does it mean that I really have 2 identical root TTrees in my root file? When I open TBrowser I see that “Event;19” and “Event;18” have the same number of events, and when I do the following I get the same number of events:
root  TTree tree = (TTree)f.Get(“Event”);
root  Int_t nentries = (Int_t)tree->GetEntries();
root  cout << nentries<< endl;
Am I reading only one root TTree in this way (if I really have 2 root TTrees in my file)?
Actually the motivation for this question was the problem I had with trying to sort root trees. I thought the problem was that I have “duplicate root trees” in file, but it turned out problem was caused by the fact that I have more then 1000000 entries in my tree. This is working now and I am sorting tree in the following way suggested on Root Talk:
TTree *tree = (TTree*)f.Get("Event");
Int_t nentries = (Int_t)tree->GetEntries();
Int_t *index = new Int_t[nentries];
If you have the same number of entries, it means that somewhere in your code you are saving the tree header twice. Check for statements like
in my code I have only once Write(), and that is:
I can only repeat what I said. You are writing twice the header. I cannot tell you more without inspecting your code.
thank you for the reply. The most important thing for me is that the problem with sorting trees which was the main motivation is solved.