Delete duplicate TTrees

Greetings,
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!

Senka

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.

Rene

Hi,
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 [2] gDirectory->ls();
TFile** /dat/rivendell/senka/cosmic_muon/CRAFT09/superPointing_327skim/CRAFT09_327reprocess_lhcCollections_noTiming_10.root
TFile* /dat/rivendell/senka/cosmic_muon/CRAFT09/superPointing_327skim/CRAFT09_327reprocess_lhcCollections_noTiming_10.root
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 [5] TTree tree = (TTree)f.Get(“Event”);
root [6] Int_t nentries = (Int_t)tree->GetEntries();
root [7] 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();
tree->SetEstimate(tree->GetEntries());
tree->Draw("orbitNumber*3564+bxNumber","","goff");
Int_t *index = new Int_t[nentries];
TMath::Sort(nentries,tree->GetV1(),index, false);

Greetings,
Senka

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
mytree.Write()
or
myfile.Write();

Rene

Hi,
in my code I have only once Write(), and that is:

theFile->Write();

I can only repeat what I said. You are writing twice the header. I cannot tell you more without inspecting your code.

Rene

Hi,
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.

Greetings,
Senka