a19c5742 |
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. |
4 | |
5 | // open input file and get the TTree |
6 | TFile orgFile(orgFileName, "READ"); |
7 | // get original TTree |
8 | TTree *orgAodTree = (TTree*)orgFile.Get("aodTree"); |
315526f3 |
9 | // switch off one branch (and its subbranches!) |
10 | orgAodTree->SetBranchStatus("tracks*", 0); |
a19c5742 |
11 | |
12 | // open new output file |
13 | TFile *newFile = new TFile(newFileName, "RECREATE"); |
14 | // clone old TTree (only clones branches that are switched on) |
15 | TTree *newAodTree = orgAodTree->CloneTree(); |
16 | |
389c0b8b |
17 | // get the event within the new TTree |
18 | AliAODEvent *evNew = new AliAODEvent(); |
19 | evNew->ReadFromTree(newAodTree); |
20 | |
389c0b8b |
21 | // remove TObject from the list |
22 | evNew->RemoveObject(evNew->GetTracks()); |
23 | |
24 | // delete old and write new UserInfo |
25 | newAodTree->GetUserInfo()->Clear(); |
26 | newAodTree->GetUserInfo()->Add(evNew); |
27 | |
a19c5742 |
28 | // write new TTree to file |
29 | newAodTree->Write(); |
30 | |
31 | // close files |
32 | newFile->Close(); |
33 | delete newFile; |
34 | |
35 | orgFile.Close(); |
36 | } |