]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSComparisonV2.C
Several patches were done to adapt the ITS reconstruction version V2 to the multi...
[u/mrichter/AliRoot.git] / ITS / AliITSComparisonV2.C
CommitLineData
006b5f7f 1#ifndef __CINT__
2 #include <iostream.h>
3 #include <fstream.h>
4
5 #include "AliRun.h"
6 #include "AliITS.h"
7 #include "AliITSgeom.h"
8 #include "AliITStrackerV2.h"
9 #include "AliITStrackV2.h"
10 #include "AliITSclusterV2.h"
11
12 #include "TFile.h"
13 #include "TTree.h"
14 #include "TH1.h"
15 #include "TObjArray.h"
16 #include "TStyle.h"
17 #include "TCanvas.h"
18 #include "TLine.h"
19 #include "TText.h"
20 #include "TParticle.h"
21#endif
22
c7ee21ca 23struct GoodTrackITS {
24 Int_t event;
006b5f7f 25 Int_t lab;
26 Int_t code;
27 Float_t px,py,pz;
28 Float_t x,y,z;
29};
006b5f7f 30
31Int_t AliITSComparisonV2() {
c7ee21ca 32 Int_t good_tracks_its(GoodTrackITS *gt, Int_t max);
33
006b5f7f 34 cerr<<"Doing comparison...\n";
35
36 TFile *cf=TFile::Open("AliITSclustersV2.root");
37 if (!cf->IsOpen()) {cerr<<"Can't open AliITSclustersV2.root !\n"; return 1;}
38 AliITSgeom *geom=(AliITSgeom*)cf->Get("AliITSgeom");
39 if (!geom) { cerr<<"Can't get the ITS geometry !\n"; return 2; }
40 AliITStrackerV2 tracker(geom);
41
42// Load tracks
43 TFile *tf=TFile::Open("AliITStracksV2.root");
44 if (!tf->IsOpen()) {cerr<<"Can't open AliITStracksV2.root !\n"; return 3;}
45 TObjArray tarray(2000);
c7ee21ca 46 TTree *tracktree=(TTree*)tf->Get("TreeT_ITS_0");
14825d5a 47 if (!tracktree) {cerr<<"Can't get a tree with ITS tracks !\n"; return 4;}
006b5f7f 48 TBranch *tbranch=tracktree->GetBranch("tracks");
49 Int_t nentr=(Int_t)tracktree->GetEntries(),i;
50 for (i=0; i<nentr; i++) {
51 AliITStrackV2 *iotrack=new AliITStrackV2;
52 tbranch->SetAddress(&iotrack);
53 tracktree->GetEvent(i);
54
55 Int_t tpcLabel=iotrack->GetLabel();
56 tracker.CookLabel(iotrack,0.);
57 Int_t itsLabel=iotrack->GetLabel();
58 if (itsLabel != tpcLabel) iotrack->SetLabel(-TMath::Abs(itsLabel));
59 if (tpcLabel < 0) iotrack->SetLabel(-TMath::Abs(itsLabel));
60 /*
61 if (itsLabel==1234) {
62 Int_t nc=iotrack->GetNumberOfClusters();
63 for (Int_t k=0; k<nc; k++) {
64 Int_t index=iotrack->GetClusterIndex(k);
65 AliITSclusterV2 *c=tracker.GetCluster(index);
66 cout<<c->GetLabel(0)<<' '<<c->GetLabel(1)<<' '<<c->GetLabel(2)<<endl;
67 }
68 }
69 */
70 tarray.AddLast(iotrack);
c7ee21ca 71 }
72 delete tracktree; //Thanks to Mariana Bondila
006b5f7f 73 tf->Close();
c7ee21ca 74 delete geom; //Thanks to Mariana Bondila
006b5f7f 75 cf->Close();
76
77/////////////////////////////////////////////////////////////////////////
c7ee21ca 78 const Int_t MAX=15000;
79 GoodTrackITS gt[MAX];
006b5f7f 80 Int_t ngood=0;
81 ifstream in("good_tracks_its");
82 if (in) {
83 cerr<<"Reading good tracks...\n";
c7ee21ca 84 while (in>>gt[ngood].event>>gt[ngood].lab>>gt[ngood].code>>
006b5f7f 85 gt[ngood].px>>gt[ngood].py>>gt[ngood].pz>>
86 gt[ngood].x >>gt[ngood].y >>gt[ngood].z) {
87 ngood++;
88 cerr<<ngood<<'\r';
c7ee21ca 89 if (ngood==MAX) {
006b5f7f 90 cerr<<"Too many good tracks !\n";
91 break;
92 }
93 }
94 if (!in.eof()) cerr<<"Read error (good_tracks_its) !\n";
95 } else {
96 cerr<<"Marking good tracks (this will take a while)...\n";
c7ee21ca 97 ngood=good_tracks_its(gt,MAX);
006b5f7f 98 ofstream out("good_tracks_its");
99 if (out) {
c7ee21ca 100 for (Int_t ngd=0; ngd<ngood; ngd++)
101 out<<gt[ngd].event<<' '<<gt[ngd].lab<<' '<<gt[ngd].code<<' '
102 <<gt[ngd].px<<' '<<gt[ngd].py<<' '<<gt[ngd].pz<<' '
103 <<gt[ngd].x <<' '<<gt[ngd].y <<' '<<gt[ngd].z <<endl;
006b5f7f 104 } else cerr<<"Can not open file (good_tracks_its) !\n";
105 out.close();
106 }
107 cerr<<"Number of good tracks : "<<ngood<<endl;
108
109 TH1F *hp=new TH1F("hp","PHI resolution",50,-20.,20.); hp->SetFillColor(4);
110 TH1F *hl=new TH1F("hl","LAMBDA resolution",50,-20,20);hl->SetFillColor(4);
111 TH1F *hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
112 hpt->SetFillColor(2);
113 TH1F *hmpt=new TH1F("hmpt","Transverse impact parameter",30,-300,300);
114 hmpt->SetFillColor(6);
115 TH1F *hz=new TH1F("hz","Longitudinal impact parameter",30,-300,300);
116 //hmpt->SetFillColor(6);
117
14825d5a 118 AliITStrackV2 *trk=(AliITStrackV2*)tarray.UncheckedAt(0);
119 Double_t pmin=0.1*(100/0.299792458/0.2/trk->GetConvConst());
120 Double_t pmax=6.0+pmin;
121
122 TH1F *hgood=new TH1F("hgood","Good tracks",30,pmin,pmax);
123 TH1F *hfound=new TH1F("hfound","Found tracks",30,pmin,pmax);
124 TH1F *hfake=new TH1F("hfake","Fake tracks",30,pmin,pmax);
125 TH1F *hg=new TH1F("hg","",30,pmin,pmax); //efficiency for good tracks
006b5f7f 126 hg->SetLineColor(4); hg->SetLineWidth(2);
14825d5a 127 TH1F *hf=new TH1F("hf","Efficiency for fake tracks",30,pmin,pmax);
006b5f7f 128 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
129
14825d5a 130 TH1F *hptw=new TH1F("hptw","Weghted pt",30,pmax,pmin);
006b5f7f 131
132 while (ngood--) {
133 Int_t lab=gt[ngood].lab, tlab=-1;
134 Double_t pxg=gt[ngood].px, pyg=gt[ngood].py, pzg=gt[ngood].pz;
135 Double_t ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
136
14825d5a 137 if (ptg<pmin) continue;
138
006b5f7f 139 hgood->Fill(ptg);
140
141 AliITStrackV2 *track=0;
142 Int_t j;
143 for (j=0; j<nentr; j++) {
144 track=(AliITStrackV2*)tarray.UncheckedAt(j);
145 tlab=track->GetLabel();
146 if (lab==TMath::Abs(tlab)) break;
147 }
148 if (j==nentr) {
149 cerr<<"Track "<<lab<<" was not found !\n";
150 continue;
151 }
152 track->Propagate(track->GetAlpha(),3.,0.1/65.19*1.848,0.1*1.848);
153 track->PropagateToVertex();
154
155 if (lab==tlab) hfound->Fill(ptg);
156 else { hfake->Fill(ptg); cerr<<lab<<" fake\n";}
157
158 Double_t xv,par[5]; track->GetExternalParameters(xv,par);
159 Float_t phi=TMath::ASin(par[2]) + track->GetAlpha();
160 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
161 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
162 Float_t lam=TMath::ATan(par[3]);
163 Float_t pt_1=TMath::Abs(par[4]);
164
165 Double_t phig=TMath::ATan2(pyg,pxg);
166 hp->Fill((phi - phig)*1000.);
167
168 Double_t lamg=TMath::ATan2(pzg,ptg);
169 hl->Fill((lam - lamg)*1000.);
170
171 Double_t d=10000*track->GetD();
172 hmpt->Fill(d);
173
174 hptw->Fill(ptg,TMath::Abs(d));
175
176 Double_t z=10000*track->GetZ();
177 hz->Fill(z);
178
179//if (TMath::Abs(gt[ngood].code)==11 && ptg>4.)
180 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
181
182 }
183
184 Stat_t ng=hgood->GetEntries(); cerr<<"Good tracks "<<ng<<endl;
185 Stat_t nf=hfound->GetEntries();
186 if (ng!=0)
187 cerr<<"Integral efficiency is about "<<nf/ng*100.<<" %\n";
188
189 gStyle->SetOptStat(111110);
190 gStyle->SetOptFit(1);
191
192 TCanvas *c1=new TCanvas("c1","",0,0,700,850);
193
194 TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
195 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
196 hp->SetFillColor(4); hp->SetXTitle("(mrad)"); hp->Fit("gaus"); c1->cd();
197
198 TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw();
199 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
200 hl->SetXTitle("(mrad)"); hl->Fit("gaus"); c1->cd();
201
202 TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
203 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
204 hpt->SetXTitle("(%)"); hpt->Fit("gaus"); c1->cd();
205
206 TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
207 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
208 hmpt->SetXTitle("(micron)"); hmpt->Fit("gaus"); hz->Draw("same"); c1->cd();
209 //hfound->Sumw2();
210 //hptw->Sumw2();
211 //hg->SetMaximum(333);
212 //hg->SetYTitle("Impact Parameter Resolution (micron)");
213 //hg->SetXTitle("Pt (GeV/c)");
214 //hg->GetXaxis()->SetRange(0,10);
215 //hg->Divide(hptw,hfound,1,1.);
216 //hg->DrawCopy(); c1->cd();
217
218
219 TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd();
220 p5->SetFillColor(41); p5->SetFrameFillColor(10);
221 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
222 hg->Divide(hfound,hgood,1,1.,"b");
223 hf->Divide(hfake,hgood,1,1.,"b");
224 hg->SetMaximum(1.4);
225 hg->SetYTitle("Tracking efficiency");
226 hg->SetXTitle("Pt (GeV/c)");
227 hg->Draw();
228
14825d5a 229 TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
006b5f7f 230 line1->Draw("same");
14825d5a 231 TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
006b5f7f 232 line2->Draw("same");
233
234 hf->SetFillColor(1);
235 hf->SetFillStyle(3013);
236 hf->SetLineColor(2);
237 hf->SetLineWidth(2);
238 hf->Draw("histsame");
239 TText *text = new TText(0.461176,0.248448,"Fake tracks");
240 text->SetTextSize(0.05);
241 text->Draw();
242 text = new TText(0.453919,1.11408,"Good tracks");
243 text->SetTextSize(0.05);
244 text->Draw();
245
246 return 0;
247}
248
c7ee21ca 249Int_t good_tracks_its(GoodTrackITS *gt, Int_t max) {
006b5f7f 250 if (gAlice) {delete gAlice; gAlice=0;}
251
252 TFile *file=TFile::Open("galice.root");
253 if (!file->IsOpen()) {cerr<<"Can't open galice.root !\n"; exit(4);}
254 if (!(gAlice=(AliRun*)file->Get("gAlice"))) {
255 cerr<<"gAlice have not been found on galice.root !\n";
256 exit(5);
257 }
258
259 Int_t np=gAlice->GetEvent(0);
260
261 Int_t *good=new Int_t[np];
262 Int_t k;
263 for (k=0; k<np; k++) good[k]=0;
264
265 AliITS *ITS=(AliITS*)gAlice->GetDetector("ITS");
266 if (!ITS) {
267 cerr<<"can't get ITS !\n"; exit(8);
268 }
269 AliITSgeom *geom=ITS->GetITSgeom();
270 if (!geom) {
c7ee21ca 271 cerr<<"can't get ITS geometry !\n"; exit(9);
006b5f7f 272 }
273
274 TFile *cf=TFile::Open("AliITSclustersV2.root");
275 if (!cf->IsOpen()){
276 cerr<<"Can't open AliITSclustersV2.root !\n"; exit(6);
277 }
c7ee21ca 278 TTree *cTree=(TTree*)cf->Get("TreeC_ITS_0");
006b5f7f 279 if (!cTree) {
280 cerr<<"Can't get cTree !\n"; exit(7);
281 }
282 TBranch *branch=cTree->GetBranch("Clusters");
283 if (!branch) {
284 cerr<<"Can't get clusters branch !\n"; exit(8);
285 }
286 TClonesArray *clusters=new TClonesArray("AliITSclusterV2",10000);
287 branch->SetAddress(&clusters);
288
289 Int_t entr=(Int_t)cTree->GetEntries();
290 for (k=0; k<entr; k++) {
c7ee21ca 291 cTree->GetEvent(k);
292 Int_t ncl=clusters->GetEntriesFast(); if (ncl==0) continue;
14825d5a 293 Int_t lay,lad,det; geom->GetModuleId(k,lay,lad,det);
006b5f7f 294 if (lay<1 || lay>6) {
295 cerr<<"wrong layer !\n"; exit(10);
296 }
006b5f7f 297 while (ncl--) {
298 AliITSclusterV2 *pnt=(AliITSclusterV2*)clusters->UncheckedAt(ncl);
299 Int_t l0=pnt->GetLabel(0);
300 Int_t l1=pnt->GetLabel(1);
301 Int_t l2=pnt->GetLabel(2);
302 Int_t mask=1<<(lay-1);
303 if (l0>=0) good[l0]|=mask;
304 if (l1>=0) good[l1]|=mask;
305 if (l2>=0) good[l2]|=mask;
306 }
307 }
308 clusters->Delete(); delete clusters;
c7ee21ca 309 delete cTree; //Thanks to Mariana Bondila
006b5f7f 310 cf->Close();
311
312 ifstream in("good_tracks_tpc");
313 if (!in) {
314 cerr<<"can't get good_tracks_tpc !\n"; exit(11);
315 }
316 Int_t nt=0;
317 Double_t px,py,pz,x,y,z;
c7ee21ca 318 Int_t code,lab,event;
319 while (in>>event>>lab>>code>>px>>py>>pz>>x>>y>>z) {
006b5f7f 320 if (good[lab] != 0x3F) continue;
321 TParticle *p = (TParticle*)gAlice->Particle(lab);
c7ee21ca 322 gt[nt].event=event;
006b5f7f 323 gt[nt].lab=lab;
324 gt[nt].code=p->GetPdgCode();
325//**** px py pz - in global coordinate system
326 gt[nt].px=p->Px(); gt[nt].py=p->Py(); gt[nt].pz=p->Pz();
327 gt[nt].x=gt[nt].y=gt[nt].z=0.;
328 nt++;
329 if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
330 }
331
332 delete[] good;
333
334 delete gAlice; gAlice=0;
335 file->Close();
336
337 return nt;
338}
339
340