Fix a problem with old UserInfo written to the cloned TTree.
authoroldi <oldi@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 18 Feb 2008 15:16:39 +0000 (15:16 +0000)
committeroldi <oldi@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 18 Feb 2008 15:16:39 +0000 (15:16 +0000)
STEER/cloneAODTreeAndAddObject.C
STEER/cloneAODTreeAndRemoveObject.C

index 7e6bfbe..46ff444 100644 (file)
@@ -45,7 +45,7 @@ void cloneAODTreeAndAddObject(const char *newFileName = "AliAOD_new.root", const
 
     /*
     // read events (only necessary if you want to access the old data)
-    newAodTree->GetEvent(nEv);
+    newAodTree->GetEvent(iEv);
     */
 
     tracks->Delete(); // for each event delete old entries of new TClonesArray
@@ -63,6 +63,10 @@ void cloneAODTreeAndAddObject(const char *newFileName = "AliAOD_new.root", const
     newBranch->Fill();
   }
 
+  // delete old and write new UserInfo
+  newAodTree->GetUserInfo()->Clear();
+  newAodTree->GetUserInfo()->Add(evNew);
+
   // write new TTree to file
   newAodTree->Write();
 
index f7a911e..456e260 100644 (file)
@@ -6,20 +6,25 @@ void cloneAODTreeAndRemoveObject(const char *newFileName = "AliAOD_new.root", co
   TFile orgFile(orgFileName, "READ");
   // get original TTree
   TTree *orgAodTree = (TTree*)orgFile.Get("aodTree");
-  // do your gymnastics with the old TTree
-  AliAODEvent *evOrg = new AliAODEvent();
-  evOrg->ReadFromTree(orgAodTree);
-
-  // switch off one branch (and its subbranches!)
-  orgAodTree->SetBranchStatus("tracks*", 0);
-  // remove TObject from the list
-  evOrg->RemoveObject(evOrg->GetTracks());
 
   // open new output file
   TFile *newFile = new TFile(newFileName, "RECREATE");
   // clone old TTree (only clones branches that are switched on)
   TTree *newAodTree = orgAodTree->CloneTree();
 
+  // get the event within the new TTree
+  AliAODEvent *evNew = new AliAODEvent();
+  evNew->ReadFromTree(newAodTree);
+
+  // switch off one branch (and its subbranches!)
+  newAodTree->SetBranchStatus("tracks*", 0);
+  // remove TObject from the list
+  evNew->RemoveObject(evNew->GetTracks());
+
+  // delete old and write new UserInfo
+  newAodTree->GetUserInfo()->Clear();
+  newAodTree->GetUserInfo()->Add(evNew);
+
   // write new TTree to file
   newAodTree->Write();