]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/ReadESDfriend.C
Writing the ESDfriends to a separate branch of the ESD tree.
[u/mrichter/AliRoot.git] / STEER / ReadESDfriend.C
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;