Changes for Root6 (Mikolaj)
[u/mrichter/AliRoot.git] / macros / TestVertexerTracks.C
CommitLineData
84d7440d 1#if !defined(__CINT__) || defined(__MAKECINT__)
2#include<Riostream.h>
3#include<AliRun.h>
4#include<TTree.h>
5#include<AliRunLoader.h>
6#include<AliESD.h>
7#include<TMath.h>
8#include<AliHeader.h>
9#include<AliGenEventHeader.h>
10#include<AliVertexerTracks.h>
11#include<AliITSVertexerTracks.h>
12#include<AliVertex.h>
13#include<AliESDVertex.h>
14#include<TFile.h>
15#endif
16
17void TestVertexerTracks(){
18 if (gAlice) {
33c3c91a 19 delete AliRunLoader::Instance();
84d7440d 20 delete gAlice;
21 gAlice = 0x0;
22 }
23
24 AliRunLoader *rl = AliRunLoader::Open("galice.root");
25 if (rl == 0x0) {
26 cerr<<"Can not open session"<<endl;
27 return;
28 }
29
30 rl->LoadgAlice();
31 AliMagF * magf = gAlice->Field();
32 AliTracker::SetFieldMap(magf,kTRUE);
33 printf("MagneticField=%f\n",AliTracker::GetBz());
34
35 rl->LoadHeader();
36 rl->LoadKinematics();
37 Int_t totev=rl->GetNumberOfEvents();
38 cout<<"Number of events="<<totev<<endl;
39
40 TFile *ef=TFile::Open("AliESDs.root");
41 if (!ef || !ef->IsOpen()) {cerr<<"Can't AliESDs.root !n";}
42 AliESD* event = new AliESD;
43 TTree* tree = (TTree*) ef->Get("esdTree");
44 if (!tree) {cerr<<"no ESD tree foundn";};
45 tree->SetBranchAddress("ESD", &event);
46
47 Int_t e=0;
48 tree->GetEvent(e);
49 Int_t ntrk=event->GetNumberOfTracks();
50 cout<<"Number of ESD tracks : "<<ntrk<<endl;
51
52 rl->GetEvent(e);
53 AliESDVertex *vertESD = event->GetVertex();
8aac1c41 54 Double_t recVertex[3];
55 AliGenEventHeader *header=rl->GetHeader()->GenEventHeader();
56 TArrayF mcVertex(3);
57 header->PrimaryVertex(mcVertex);
84d7440d 58 cout<<"Primary vertex (MC) ";
59 for(Int_t kk=0;kk<3;kk++)cout<<mcVertex[kk]<<" ";
60 cout<<endl;
61 vertESD->GetXYZ(recVertex);
62 cout<<"Primary vertex (from SPD clusters) ";
63 for(Int_t kk=0;kk<3;kk++)cout<<recVertex[kk]<<" ";
64 cout<<endl;
65 TObjArray *trkarr=new TObjArray();
66 trkarr->Expand(3);
67
68 TTree *trkTree = new TTree("TreeT","tracks");
69 AliESDtrack *esdTrack = 0;
70 trkTree->Branch("tracks","AliESDtrack",&esdTrack);
71
72 esdTrack=(AliESDtrack*)event->GetTrack(2);
73 trkarr->AddLast(esdTrack);
74 trkTree->Fill();
75
76 esdTrack=(AliESDtrack*)event->GetTrack(3);
77 trkarr->AddLast(esdTrack);
78 trkTree->Fill();
79
80 esdTrack=(AliESDtrack*)event->GetTrack(4);
81 trkarr->AddLast(esdTrack);
82 trkTree->Fill();
83
84 // BEWARE: the method VertexForSelectedTracks returns the address of the data member fVert
85 // which is always the same for all calls to VertexForSelectedTracks.
86
87 printf("\n*****************************\n");
88 printf("Call VertexForSelectedTracks with different arguments\n");
89 printf("*****************************\n");
90 AliVertexerTracks *vtx=new AliVertexerTracks();
91 AliVertex *vert=vtx->VertexForSelectedTracks(trkarr);
92 vert->Print();
93 AliVertex *vert2=vtx->VertexForSelectedTracks(trkTree);
94 vert->Print();
95 vert2->Print();
96
97 printf("\n*****************************\n");
98 printf("Use different finder algorithms\n");
99 printf("*****************************\n");
100 vtx->SetFinderAlgorithm(1);
101 AliVertex *v1=vtx->VertexForSelectedTracks(trkarr);
102 v1->Print();
103 vtx->SetFinderAlgorithm(2);
104 AliVertex *v2=vtx->VertexForSelectedTracks(trkarr);
105 v2->Print();
106 vtx->SetFinderAlgorithm(3);
107 AliVertex *v3=vtx->VertexForSelectedTracks(trkarr);
108 v3->Print();
109 vtx->SetFinderAlgorithm(4);
110 AliVertex *v4=vtx->VertexForSelectedTracks(trkarr);
111 v4->Print();
112 vtx->SetFinderAlgorithm(5);
113 AliVertex *v5=vtx->VertexForSelectedTracks(trkarr);
114 v5->Print();
115 delete vtx;
116
117 printf("\n*****************************\n");
118 printf("Call AliITSVertexerTracks::VertexForSelected Tracks\n");
119 printf("*****************************\n");
120 Int_t trkPos[3]={0,1,2};
121 AliITSVertexerTracks *itsvtx=new AliITSVertexerTracks();
122 itsvtx->SetDebug(0);
123 AliVertex *vert3=itsvtx->VertexForSelectedTracks(event,3,trkPos,1);
124 vert3->Print();
125 delete itsvtx;
126
127 printf("\n*****************************\n");
128 printf("Find Primary Vertex\n");
129 printf("*****************************\n");
130 AliITSVertexerTracks *itsvtx2=new AliITSVertexerTracks();
131 itsvtx2->SetDebug(0);
132 AliESDVertex* evert=itsvtx2->FindPrimaryVertexForCurrentEvent(event);
133 evert->Print();
134 delete itsvtx2;
135}
136
137
138