]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Example macros to extend or reduce the standard AOD content.
authormarkus <markus@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 29 Nov 2007 13:53:04 +0000 (13:53 +0000)
committermarkus <markus@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 29 Nov 2007 13:53:04 +0000 (13:53 +0000)
STEER/addObjectAndUpdateAOD.C [new file with mode: 0644]
STEER/addObjectDuringAODCreation.C [new file with mode: 0644]
STEER/cloneAODTreeAndAddObject.C [new file with mode: 0644]
STEER/cloneAODTreeAndRemoveObject.C [new file with mode: 0644]

diff --git a/STEER/addObjectAndUpdateAOD.C b/STEER/addObjectAndUpdateAOD.C
new file mode 100644 (file)
index 0000000..20e7a0f
--- /dev/null
@@ -0,0 +1,68 @@
+void addObjectAndUpdateAOD(const char *fileName = "AliAOD.root") {
+  // This little macro takes an already created AOD file and adds
+  // a new branch to it.
+  // Be aware that if something breaks, the content of the file will 
+  // be essentially lost, meaning WITH THIS UPDATE PROCEDURE YOU 
+  // HAVE THE POWER TO DESTROY DATA!
+  //
+  // To read back this data (including the newly updated branch), have
+  // a look at $ALICE_ROOT/STEER/ReadAOD.C and add one line
+  //       TClonesArray *esdTracks = 
+  //            (TClonesArray*)ev->GetList()->FindObject("esdTracks");
+  // after   
+  //       ev->ReadFromTree(aodTree);
+  //
+  // esdTracks will be 'filled' correctly after each call of
+  //       aodTree->GetEvent(nEv);
+  //
+
+
+  // open input file and get the TTree
+  TFile inFile(fileName, "UPDATE");
+
+  TTree *aodTree = (TTree*)inFile.Get("aodTree");
+  AliAODEvent *ev = new AliAODEvent();
+  ev->ReadFromTree(aodTree);
+
+  // add new information to the list (we use AliESDtracks as an example)
+  TClonesArray *tracks = new TClonesArray("AliESDtrack", 0);
+  ev->AddObject(tracks); // add new object to the list
+
+  // define a unique name
+  const char *name = "esdTracks";
+  tracks->SetName(name); // set this name to be the name of the TClonesArray
+  // create the new branch
+  TBranch *newBranch = aodTree->Branch(name, &tracks); // the branch gets the same name
+
+  // loop over events
+  Int_t nEvent = aodTree->GetEntries();
+
+  for(Int_t iEv = 0; iEv < nEvent; iEv++) {
+
+    /*
+    // read events (only necessary if you want to access the old data)
+    aodTree->GetEvent(nEv);
+    */
+
+    tracks->Delete(); // for each event delete old entries of new TClonesArray
+
+    Int_t nTracks = gRandom->Rndm() * 50; // randomize size of TClonesArray (just for this example)
+    tracks->Expand(nTracks); // expand container (just for speed)
+    
+    // fill TClonesArray
+    TClonesArray &rTracks = *tracks;
+    for (Int_t iTr = 0; iTr< nTracks; iTr++) {
+      new(rTracks[iTr]) AliESDtrack();
+    }
+    
+    // fill the new branch
+    newBranch->Fill();
+  }
+
+  // (over)write the tree (to the same file!)
+
+  aodTree->Write("", TObject::kOverwrite);
+  inFile.Close();
+
+  return;
+}
diff --git a/STEER/addObjectDuringAODCreation.C b/STEER/addObjectDuringAODCreation.C
new file mode 100644 (file)
index 0000000..3926fb8
--- /dev/null
@@ -0,0 +1,48 @@
+addObjectDuringAODCreation() {
+
+  // add an object to an aod and write it
+
+  TFile *aodFile = TFile::Open("addAOD.root", "RECREATE");
+
+    // create an AliAOD object 
+  AliAODEvent *aod = new AliAODEvent();
+  aod->CreateStdContent();
+  
+  // add new information, we use AliESDtracks for now
+  TClonesArray *tracks = new TClonesArray("AliESDtrack", 0);
+  aod->AddObject(tracks);
+
+  // go to the file
+  aodFile->cd();
+  
+  // create the tree
+  TTree *aodTree = new TTree("aodTree", "AliAOD tree");
+  aodTree->Branch(aod->GetList());
+
+  for (Int_t iEvent = 0; iEvent < 10; ++iEvent) {
+    // add (part of) standard information
+    AliAODHeader *header = aod->GetHeader();
+
+    tracks->Delete(); // delete old objects
+    tracks->Expand(iEvent+5/* just to make it a different number each time*/); // expand container (just for speed)
+    
+    // fill TClonesArray
+    TClonesArray &rTracks = *tracks;
+    for (Int_t i = 0; i< iEvent+5; i++) {
+      new(rTracks[i]) AliESDtrack();
+    }
+
+    // fill the tree for this event
+    aodTree->Fill();
+  } // end of event loop
+
+  aodTree->GetUserInfo()->Add(aod);
+
+  // write the tree to the specified file
+  aodFile = aodTree->GetCurrentFile();
+  aodFile->cd();
+  aodTree->Write();
+
+
+
+}
diff --git a/STEER/cloneAODTreeAndAddObject.C b/STEER/cloneAODTreeAndAddObject.C
new file mode 100644 (file)
index 0000000..7e6bfbe
--- /dev/null
@@ -0,0 +1,74 @@
+void cloneAODTreeAndAddObject(const char *newFileName = "AliAOD_new.root", const char *orgFileName = "AliAOD.root") {
+  // This little macro takes an already created AOD file and clones it.
+  // After adding a new brach, the new TTree is written to a new file.
+  //
+  // To read back this data (including the newly updated branch), have
+  // a look at $ALICE_ROOT/STEER/ReadAOD.C and add one line
+  //       TClonesArray *esdTracks = 
+  //            (TClonesArray*)ev->GetList()->FindObject("esdTracks");
+  // after   
+  //       ev->ReadFromTree(aodTree);
+  //
+  // esdTracks will be 'filled' correctly after each call of
+  //       aodTree->GetEvent(nEv);
+  //
+
+
+  // open input file and get the TTree
+  TFile orgFile(orgFileName, "READ");
+  // get original TTree
+  TTree *orgAodTree = (TTree*)orgFile.Get("aodTree");
+
+  // open new output file
+  TFile *newFile = new TFile(newFileName, "RECREATE");
+  // clone old TTree
+  TTree *newAodTree = orgAodTree->CloneTree();
+
+  // do your gymnastics with the new TTree
+  AliAODEvent *evNew = new AliAODEvent();
+  evNew->ReadFromTree(newAodTree);
+    
+  // add new information to the list (we use AliESDtracks as an example)
+  TClonesArray *tracks = new TClonesArray("AliESDtrack", 0);
+  evNew->AddObject(tracks); // add new object to the list
+
+  // define a unique name
+  const char *name = "esdTracks";
+  tracks->SetName(name); // set this name to be the name of the TClonesArray
+  // create the new branch
+  TBranch *newBranch = newAodTree->Branch(name, &tracks); // the branch gets the same name
+
+  // loop over events
+  Int_t nEvent = newAodTree->GetEntries();
+
+  for(Int_t iEv = 0; iEv < nEvent; iEv++) {
+
+    /*
+    // read events (only necessary if you want to access the old data)
+    newAodTree->GetEvent(nEv);
+    */
+
+    tracks->Delete(); // for each event delete old entries of new TClonesArray
+
+    Int_t nTracks = gRandom->Rndm() * 50; // randomize size of TClonesArray (just for this example)
+    tracks->Expand(nTracks); // expand container (just for speed)
+    
+    // fill TClonesArray
+    TClonesArray &rTracks = *tracks;
+    for (Int_t iTr = 0; iTr< nTracks; iTr++) {
+      new(rTracks[iTr]) AliESDtrack();
+    }
+    
+    // fill the new branch
+    newBranch->Fill();
+  }
+
+  // write new TTree to file
+  newAodTree->Write();
+
+  // close files
+  newFile->Close();
+  delete newFile;
+
+  orgFile.Close();
+}
diff --git a/STEER/cloneAODTreeAndRemoveObject.C b/STEER/cloneAODTreeAndRemoveObject.C
new file mode 100644 (file)
index 0000000..f7a911e
--- /dev/null
@@ -0,0 +1,31 @@
+void cloneAODTreeAndRemoveObject(const char *newFileName = "AliAOD_new.root", const char *orgFileName = "AliAOD.root") {
+  // This little macro takes an already created AOD file and clones it.
+  // After removing an old brach, the new TTree is written to a new file.
+
+  // open input file and get the TTree
+  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();
+
+  // write new TTree to file
+  newAodTree->Write();
+
+  // close files
+  newFile->Close();
+  delete newFile;
+
+  orgFile.Close();
+}