AliESD changed to AliESDEvent (Andrea)
[u/mrichter/AliRoot.git] / STEER / ReadESDfriend.C
CommitLineData
6bc5f287 1//********************************************************************
2// Example of accessing the information stored in ESD friends
3// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
4//********************************************************************
5
6#if !defined( __CINT__) || defined(__MAKECINT__)
7 #include <Riostream.h>
8 #include <TFile.h>
500d54ab 9 #include <TChain.h>
6bc5f287 10
bd23a74c 11 #include "AliESDEvent.h"
6bc5f287 12 #include "AliESDfriend.h"
500d54ab 13 #include "AliTrackPointArray.h"
6bc5f287 14#endif
15
16void ReadESDfriend(Bool_t readFriend=kTRUE) {
500d54ab 17 Char_t *name[]={
18 //Put here the names of the ESD files to be chained
19 "AliESDs.root"
20 };
21 Int_t n=sizeof(name)/sizeof(Char_t *);
22 TChain *esdTree=new TChain("esdTree");
23 for (Int_t i=0; i<n; i++) esdTree->AddFile(name[i]);
24
bd23a74c 25 AliESDEvent *ev= new AliESDEvent();
26 ev->ReadFromTree(esdTree);
6bc5f287 27
500d54ab 28 // Attach the branch with ESD friends
6bc5f287 29 AliESDfriend *evf=0;
30 if (readFriend) {
500d54ab 31 esdTree->SetBranchStatus("ESDfriend*",1);
bd23a74c 32 evf = (AliESDfriend*)ev->FindListObject("AliESDfriend");
6bc5f287 33 }
34
35 Int_t nev=esdTree->GetEntries();
36 for (Int_t i=0; i<nev; i++) {
6bc5f287 37 esdTree->GetEntry(i);
6bc5f287 38
bd23a74c 39
40 cout<<endl<<"Event number: "<<i<<endl;
41 Int_t ntr=ev->GetNumberOfTracks();
42 cout<<"Number of tracks: "<<ntr<<endl;
43 // Now the attached information can be accessed via pointer to ESD.
44 // Example: indices of the TPC clusters associated with the track number 0.
45 if (ntr > 0) {
46 ev->SetESDfriend(evf); //Attach the friend to the ESD
9fd6b54e 47 const AliESDtrack *t=ev->GetTrack(0);
48 Int_t idx[AliESDfriendTrack::kMaxTPCcluster];
49 n=t->GetTPCclusters(idx);
50 cout<<"Track number 0"<<endl;
51 cout<<" Number of TPC clusters: "<<n<<endl;
bd23a74c 52 cout<<" Index of the 150th TPC cluster: "<<idx[7]<<endl;
62665e7f 53 UChar_t map=t->GetITSClusterMap();
54 cout<<" ITS cluster map (from SPDs to SSDs): ";
bd23a74c 55 for (Int_t i=0; i<6; i++) printf(" Bit %d: %d\n",i,(map&(1<<i))==(1<<i)) <<' ';
56
500d54ab 57 // Example: track points associated with the track number 0.
9fd6b54e 58 const AliTrackPointArray *pa=t->GetTrackPointArray();
59 if (pa != 0) {
60 n=pa->GetNPoints();
61 const Float_t *x=pa->GetX();
62 cout<<" Number of track points: "<<n<<endl;
63 if (n>7)
64 cout<<" X coordinate of the 7th track point: "<<x[7]<<endl;
65 }
66 }
bd23a74c 67
6bc5f287 68 }
bd23a74c 69 delete ev;
6bc5f287 70 delete esdTree;
71}