]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Writing the ESDfriends to a separate branch of the ESD tree.
authorbelikov <belikov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 1 Nov 2006 14:16:30 +0000 (14:16 +0000)
committerbelikov <belikov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 1 Nov 2006 14:16:30 +0000 (14:16 +0000)
STEER/AliReconstruction.cxx
STEER/ReadESDfriend.C

index d18e8bcde108189878f17b007179826a44625126..f90f8891d087f0cc7743298f265099efd63f246b 100644 (file)
@@ -636,19 +636,13 @@ Bool_t AliReconstruction::Run(const char* input,
   delete esd; delete hltesd;
   esd = NULL; hltesd = NULL;
 
-  // create the file and tree with ESD additions
-  TFile *filef=0; TTree *treef=0; AliESDfriend *esdf=0;
+  // create the branch with ESD additions
+  AliESDfriend *esdf=0;
   if (fWriteESDfriend) {
-     filef = TFile::Open("AliESDfriends.root", "RECREATE");
-     if (!filef->IsOpen()) {
-        AliError("opening AliESDfriends.root failed");
-     }
-     treef = new TTree("esdFriendTree", "Tree with ESD friends");
-     treef->Branch("ESDfriend", "AliESDfriend", &esdf);
+     TBranch *br=tree->Branch("ESDfriend.", "AliESDfriend", &esdf);
+     br->SetFile("AliESDfriends.root");
   }
 
-  gROOT->cd();
-
   AliVertexerTracks tVertexer;
   if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
 
@@ -753,35 +747,29 @@ Bool_t AliReconstruction::Run(const char* input,
     esd->SetPrimaryVertex(tVertexer.FindPrimaryVertex(esd));
 
     // write ESD
-    tree->Fill();
-    // write HLT ESD
-    hlttree->Fill();
-
-    // write ESD friend
     if (fWriteESDfriend) {
        esdf=new AliESDfriend();
        esd->GetESDfriend(esdf);
-       treef->Fill();  
     }
+    tree->Fill();
+
+    // write HLT ESD
+    hlttree->Fill();
 
     if (fCheckPointLevel > 0)  WriteESD(esd, "final"); 
  
-    delete esd; delete hltesd;
-    esd = NULL; hltesd = NULL;
+    delete esd; delete esdf; delete hltesd;
+    esd = NULL; esdf=NULL; hltesd = NULL;
   }
 
   AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
               stopwatch.RealTime(),stopwatch.CpuTime()));
 
   file->cd();
+  tree->SetBranchStatus("ESDfriend*",0);
   tree->Write();
   hlttree->Write();
 
-  if (fWriteESDfriend) {
-     filef->cd();
-     treef->Write(); delete treef; filef->Close(); delete filef; 
-  }
-
   // Create tags for the events in the ESD tree (the ESD tree is always present)
   // In case of empty events the tags will contain dummy values
   CreateTag(file);
index 780bfe2aa349b64b968fad95c34554f6e4975135..03addf62abd3caa68561bf685ee472e4010f7c1e 100644 (file)
@@ -6,38 +6,61 @@
 #if !defined( __CINT__) || defined(__MAKECINT__)
   #include <Riostream.h>
   #include <TFile.h>
-  #include <TTree.h>
+  #include <TChain.h>
 
   #include "AliESD.h"
   #include "AliESDfriend.h"
+  #include "AliTrackPointArray.h"
 #endif
 
 void ReadESDfriend(Bool_t readFriend=kTRUE) {
-   TFile f("AliESDs.root");
-   TTree *esdTree=(TTree*)f.Get("esdTree");
+   Char_t *name[]={
+     //Put here the names of the ESD files to be chained
+     "AliESDs.root"
+   };
+   Int_t n=sizeof(name)/sizeof(Char_t *); 
+   TChain *esdTree=new TChain("esdTree");
+   for (Int_t i=0; i<n; i++) esdTree->AddFile(name[i]);
+
    AliESD *ev=0;
    esdTree->SetBranchAddress("ESD",&ev);
 
-   // Attach the tree with ESD friends
+   // Attach the branch with ESD friends
    AliESDfriend *evf=0;
    if (readFriend) {
-      esdTree->AddFriend("esdFriendTree","AliESDfriends.root");
-      esdTree->SetBranchAddress("ESDfriend",&evf);
+      esdTree->SetBranchStatus("ESDfriend*",1);
+      esdTree->SetBranchAddress("ESDfriend.",&evf);
    }
 
    Int_t nev=esdTree->GetEntries();
    for (Int_t i=0; i<nev; i++) {
-       cout<<"Event number: "<<i<<endl;
        esdTree->GetEntry(i);
         
+       cout<<endl<<"Event number: "<<i<<endl;
+       Int_t n=ev->GetNumberOfTracks();
+       cout<<"Number of tracks: "<<n<<endl;
+       if (n==0) continue;
+
        ev->SetESDfriend(evf); //Attach the friend to the ESD
 
     // Now the attached information can be accessed via pointer to ESD.
     // Example: indices of the TPC clusters associated with the track number 0.
        const AliESDtrack *t=ev->GetTrack(0);
-       Int_t idx[AliESDfriendTrack::kMaxTPCcluster], n=t->GetTPCclusters(idx);
-       cout<<"Number of TPC clusters: "<<n<<endl;
-       cout<<"Index of the 7th TPC cluster: "<<idx[7]<<endl<<endl; 
+       Int_t idx[AliESDfriendTrack::kMaxTPCcluster]; 
+       n=t->GetTPCclusters(idx);
+       cout<<"Track number 0"<<endl;
+       cout<<"   Number of TPC clusters: "<<n<<endl;
+       cout<<"   Index of the 7th TPC cluster: "<<idx[7]<<endl;
+
+    // Example: track points associated with the track number 0.
+       const AliTrackPointArray *pa=t->GetTrackPointArray();
+       if (pa==0) continue;
+       n=pa->GetNPoints();
+       const Float_t *x=pa->GetX();
+       cout<<"   Number of track points: "<<n<<endl;
+       if (n>7)
+       cout<<"   X coordinate of the 7th track point: "<<x[7]<<endl;
+       
    }
 
    delete esdTree;