]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ReadESDfriend.C
minor bugfix in argument scanning
[u/mrichter/AliRoot.git] / STEER / ReadESDfriend.C
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>
9   #include <TChain.h>
10
11   #include "AliESDEvent.h"
12   #include "AliESDfriend.h"
13   #include "AliTrackPointArray.h"
14 #endif
15
16 void ReadESDfriend(Bool_t readFriend=kTRUE) {
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
25    AliESDEvent *ev= new AliESDEvent();
26    if(readFriend)esdTree->SetBranchStatus("ESDfriend*",1);
27    ev->ReadFromTree(esdTree);
28
29    // Attach the branch with ESD friends
30    AliESDfriend *evf=0;
31    if (readFriend) {
32      evf = (AliESDfriend*)ev->FindListObject("AliESDfriend");
33      if(!evf){
34        // works for both, we just want to avoid setting the branch adress twice
35        // in case of the new ESD
36        esdTree->SetBranchAddress("ESDfriend.",&evf); 
37      }
38    }
39
40    Int_t nev=esdTree->GetEntries();
41    for (Int_t i=0; i<nev; i++) {
42        esdTree->GetEntry(i);
43        if(ev->GetAliESDOld())ev->CopyFromOldESD();
44       
45        cout<<endl<<"Event number: "<<i<<endl;
46        Int_t ntr=ev->GetNumberOfTracks();
47        cout<<"Number of tracks: "<<ntr<<endl;
48        // Now the attached information can be accessed via pointer to ESD.
49        // Example: indices of the TPC clusters associated with the track number 0.
50        if (ntr > 0) {
51          ev->SetESDfriend(evf); //Attach the friend to the ESD
52          const AliESDtrack *t=ev->GetTrack(0);
53          Int_t idx[AliESDfriendTrack::kMaxTPCcluster]; 
54          n=t->GetTPCclusters(idx);
55          cout<<"Number of friend tracks: "<<evf->GetNumberOfTracks() <<endl;
56          cout<<"Track number 0"<<endl;
57          cout<<"   Number of TPC clusters: "<<n<<endl;
58          cout<<"   Index of the 1st TPC cluster: "  <<idx[1]<<endl;
59          UChar_t map=t->GetITSClusterMap();
60          cout<<"   ITS cluster map (from SPDs to SSDs):\n";
61          for (Int_t k=0; k<6; k++) printf(" Bit %d: %d\n",k,(map&(1<<k))==(1<<k)) <<' ';
62          
63          // Example: track points associated with the track number 0.
64          const AliTrackPointArray *pa=t->GetTrackPointArray();
65          if (pa != 0) {
66            n=pa->GetNPoints();
67            const Float_t *x=pa->GetX();
68            cout<<"   Number of track points: "<<n<<endl;
69            if (n>7)
70              cout<<"   X coordinate of the 7th track point: "<<x[7]<<endl;
71          }
72          
73        }
74        
75    }
76    delete ev;
77    delete esdTree;
78 }