1 void cloneAODTreeAndRemoveObject(const char *newFileName = "AliAOD_new.root", const char *orgFileName = "AliAOD.root") {
2 // This little macro takes an already created AOD file and clones it.
3 // After removing an old brach, the new TTree is written to a new file.
5 // open input file and get the TTree
6 TFile orgFile(orgFileName, "READ");
8 TTree *orgAodTree = (TTree*)orgFile.Get("aodTree");
9 // do your gymnastics with the old TTree
10 AliAODEvent *evOrg = new AliAODEvent();
11 evOrg->ReadFromTree(orgAodTree);
13 // switch off one branch (and its subbranches!)
14 orgAodTree->SetBranchStatus("tracks*", 0);
15 // remove TObject from the list
16 evOrg->RemoveObject(evOrg->GetTracks());
18 // open new output file
19 TFile *newFile = new TFile(newFileName, "RECREATE");
20 // clone old TTree (only clones branches that are switched on)
21 TTree *newAodTree = orgAodTree->CloneTree();
23 // write new TTree to file