Loop variable declared once (HP, Sun)
[u/mrichter/AliRoot.git] / TPC / AliTPCComparison.C
CommitLineData
be9c5115 1#ifndef __CINT__
2 #include "alles.h"
3#endif
4
cc80f89e 5struct GoodTrack {
6 Int_t lab;
7 Int_t code;
8 Float_t px,py,pz;
9 Float_t x,y,z;
10};
11Int_t good_tracks(GoodTrack *gt, Int_t max);
12
73042f01 13Int_t AliTPCComparison() {
9b280d80 14 cerr<<"Doing comparison...\n";
15 Int_t i;
cf98c13f 16 gBenchmark->Start("AliTPCComparison");
8c555625 17
73042f01 18 TFile *cf=TFile::Open("AliTPCclusters.root");
19 if (!cf->IsOpen()) {cerr<<"Can't open AliTPCclusters.root !\n"; return 1;}
20 AliTPCParam *digp= (AliTPCParam*)cf->Get("75x40_100x60");
21 if (!digp) { cerr<<"TPC parameters have not been found !\n"; return 2; }
22
23// Load clusters
24 AliTPCClustersArray *ca=new AliTPCClustersArray;
25 ca->Setup(digp);
26 ca->SetClusterType("AliTPCcluster");
27 ca->ConnectTree("Segment Tree");
28 Int_t nentr=Int_t(ca->GetTree()->GetEntries());
be9c5115 29 for (i=0; i<nentr; i++) ca->LoadEntry(i);
8c555625 30
73042f01 31// Load tracks
32 TFile *tf=TFile::Open("AliTPCtracks.root");
33 if (!tf->IsOpen()) {cerr<<"Can't open AliTPCtracks.root !\n"; return 3;}
34 TObjArray tarray(2000);
35 TTree *tracktree=(TTree*)tf->Get("TreeT");
36 TBranch *tbranch=tracktree->GetBranch("tracks");
cf98c13f 37 nentr=(Int_t)tracktree->GetEntries();
38
be9c5115 39 AliTPCtrack *iotrack=0;
73042f01 40 for (i=0; i<nentr; i++) {
be9c5115 41 iotrack=new AliTPCtrack;
73042f01 42 tbranch->SetAddress(&iotrack);
43 tracktree->GetEvent(i);
44 iotrack->CookLabel(ca);
45 tarray.AddLast(iotrack);
46 }
47 tf->Close();
48
49 delete ca;
50 cf->Close();
8c555625 51
52/////////////////////////////////////////////////////////////////////////
c9b22865 53 GoodTrack gt[15000];
cc80f89e 54 Int_t ngood=0;
be9c5115 55 ifstream in("good_tracks_tpc");
cc80f89e 56 if (in) {
57 cerr<<"Reading good tracks...\n";
be9c5115 58 while (in>>gt[ngood].lab>>gt[ngood].code>>
59 gt[ngood].px>>gt[ngood].py>>gt[ngood].pz>>
60 gt[ngood].x >>gt[ngood].y >>gt[ngood].z) {
cc80f89e 61 ngood++;
62 cerr<<ngood<<'\r';
c9b22865 63 if (ngood==15000) {
cc80f89e 64 cerr<<"Too many good tracks !\n";
65 break;
66 }
67 }
be9c5115 68 if (!in.eof()) cerr<<"Read error (good_tracks_tpc) !\n";
cc80f89e 69 } else {
70 cerr<<"Marking good tracks (this will take a while)...\n";
c9b22865 71 ngood=good_tracks(gt,15000);
be9c5115 72 ofstream out("good_tracks_tpc");
cc80f89e 73 if (out) {
74 for (Int_t ngd=0; ngd<ngood; ngd++)
be9c5115 75 out<<gt[ngd].lab<<' '<<gt[ngd].code<<' '<<
76 gt[ngd].px<<' '<<gt[ngd].py<<' '<<gt[ngd].pz<<' '<<
77 gt[ngd].x <<' '<<gt[ngd].y <<' '<<gt[ngd].z <<endl;
78 } else cerr<<"Can not open file (good_tracks_tpc) !\n";
cc80f89e 79 out.close();
be9c5115 80
81 cerr<<"Preparing tracks for matching with the ITS...\n";
82 tarray.Sort();
83 tf=TFile::Open("AliTPCtracks.root","recreate");
84 tracktree=new TTree("TreeT","Tree with TPC tracks");
85 tracktree->Branch("tracks","AliTPCtrack",&iotrack,32000,0);
86 for (i=0; i<nentr; i++) {
87 iotrack=(AliTPCtrack*)tarray.UncheckedAt(i);
88 tracktree->Fill();
89 }
90 tracktree->Write();
91 tf->Close();
92
cc80f89e 93 }
94 cerr<<"Number of good tracks : "<<ngood<<endl;
95
cc80f89e 96 TH1F *hp=new TH1F("hp","PHI resolution",50,-20.,20.); hp->SetFillColor(4);
97 TH1F *hl=new TH1F("hl","LAMBDA resolution",50,-20,20);hl->SetFillColor(4);
8c555625 98 TH1F *hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
99 hpt->SetFillColor(2);
cc80f89e 100 TH1F *hmpt=new TH1F("hmpt","Relative Pt resolution (pt>4GeV/c)",30,-60,60);
101 hmpt->SetFillColor(6);
8c555625 102
be9c5115 103 TH1F *hgood=new TH1F("hgood","Good tracks",30,0.1,6.1);
104 TH1F *hfound=new TH1F("hfound","Found tracks",30,0.1,6.1);
105 TH1F *hfake=new TH1F("hfake","Fake tracks",30,0.1,6.1);
106 TH1F *hg=new TH1F("hg","",30,0.1,6.1); //efficiency for good tracks
8c555625 107 hg->SetLineColor(4); hg->SetLineWidth(2);
be9c5115 108 TH1F *hf=new TH1F("hf","Efficiency for fake tracks",30,0.1,6.1);
8c555625 109 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
110
cc80f89e 111 TH1F *he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,100.);
9b280d80 112 TH2F *hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,250.);
be9c5115 113 hep->SetMarkerStyle(8);
114 hep->SetMarkerSize(0.4);
8c555625 115
cf98c13f 116 Int_t mingood = ngood; //MI change
117 Int_t * track_notfound = new Int_t[ngood];
118 Int_t itrack_notfound =0;
119 Int_t * track_fake = new Int_t[ngood];
120 Int_t itrack_fake = 0;
121 Int_t * track_multifound = new Int_t[ngood];
122 Int_t * track_multifound_n = new Int_t[ngood];
123 Int_t itrack_multifound =0;
124
cc80f89e 125 while (ngood--) {
cf98c13f 126 Int_t lab=gt[ngood].lab,tlab=-1;
cc80f89e 127 Float_t ptg=
128 TMath::Sqrt(gt[ngood].px*gt[ngood].px + gt[ngood].py*gt[ngood].py);
8c555625 129
130 hgood->Fill(ptg);
cc80f89e 131
cf98c13f 132 AliTPCtrack *track=0;
73042f01 133 for (i=0; i<nentr; i++) {
cf98c13f 134 track=(AliTPCtrack*)tarray.UncheckedAt(i);
73042f01 135 tlab=track->GetLabel();
cc80f89e 136 if (lab==TMath::Abs(tlab)) break;
8c555625 137 }
73042f01 138 if (i==nentr) {
be9c5115 139 //cerr<<"Track "<<lab<<" was not found !\n";
cf98c13f 140 track_notfound[itrack_notfound++]=lab;
cc80f89e 141 continue;
142 }
cf98c13f 143
144 //MI change - addition
145 Int_t micount=0;
146 Int_t mi;
147 AliTPCtrack * mitrack;
148 for (mi=0; mi<nentr; mi++) {
149 mitrack=(AliTPCtrack*)tarray.UncheckedAt(mi);
150 if (lab==TMath::Abs(mitrack->GetLabel())) micount++;
151 }
152 if (micount>1) {
153 //cout<<"Track no. "<<lab<<" found "<<micount<<" times\n";
154 track_multifound[itrack_multifound]=lab;
155 track_multifound_n[itrack_multifound]=micount;
156 itrack_multifound++;
157 }
158
159
160 //
cc80f89e 161 Double_t xk=gt[ngood].x;//digp->GetPadRowRadii(0,0);
162 track->PropagateTo(xk);
3c0f9266 163
cc80f89e 164 if (lab==tlab) hfound->Fill(ptg);
cf98c13f 165 else {
166 track_fake[itrack_fake++]=lab;
167 hfake->Fill(ptg);
168 //cerr<<lab<<" fake\n";
169 }
cc80f89e 170
be9c5115 171 Double_t par[5]; track->GetExternalParameters(xk,par);
172 Float_t phi=TMath::ASin(par[2]) + track->GetAlpha();
173 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
174 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
175 Float_t lam=TMath::ATan(par[3]);
176 Float_t pt_1=TMath::Abs(par[4]);
cc80f89e 177
178 if (TMath::Abs(gt[ngood].code)==11 && ptg>4.) {
be9c5115 179 hmpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
cc80f89e 180 } else {
181 Float_t phig=TMath::ATan2(gt[ngood].py,gt[ngood].px);
cc80f89e 182 hp->Fill((phi - phig)*1000.);
3c0f9266 183
cc80f89e 184 Float_t lamg=TMath::ATan2(gt[ngood].pz,ptg);
cc80f89e 185 hl->Fill((lam - lamg)*1000.);
186
be9c5115 187 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
cc80f89e 188 }
73042f01 189
be9c5115 190 Float_t mom=1./(pt_1*TMath::Cos(lam));
73042f01 191 Float_t dedx=track->GetdEdx();
cc80f89e 192 hep->Fill(mom,dedx,1.);
193 if (TMath::Abs(gt[ngood].code)==211)
194 if (mom>0.4 && mom<0.5) {
195 he->Fill(dedx,1.);
196 }
73042f01 197
cc80f89e 198 }
199
cf98c13f 200
cc80f89e 201 Stat_t ng=hgood->GetEntries(); cerr<<"Good tracks "<<ng<<endl;
202 Stat_t nf=hfound->GetEntries();
203 if (ng!=0)
cf98c13f 204 cerr<<"\n\n\nIntegral efficiency is about "<<nf/ng*100.<<" %\n";
205
206 //MI change - addition
207 cout<<"Total number of found tracks ="<<nentr<<"\n";
208 cout<<"Total number of \"good\" tracks ="<<mingood<<"\n";
209
210
211 cout<<"\nList of Not found tracks :\n";
212 // Int_t i;
213 for ( i = 0; i< itrack_notfound; i++){
214 cout<<track_notfound[i]<<"\t";
215 if ((i%5)==4) cout<<"\n";
216 }
217 cout<<"\nList of fake tracks :\n";
218 for ( i = 0; i< itrack_fake; i++){
219 cout<<track_fake[i]<<"\t";
220 if ((i%5)==4) cout<<"\n";
221 }
222 cout<<"\nList of multiple found tracks :\n";
223 for ( i=0; i<itrack_multifound; i++) {
224 cout<<"id. "<<track_multifound[i]<<" found - "<<track_multifound_n[i]<<"times\n";
225 }
226 cout<<"\n\n\n";
8c555625 227
cf98c13f 228
8c555625 229 gStyle->SetOptStat(111110);
230 gStyle->SetOptFit(1);
231
232 TCanvas *c1=new TCanvas("c1","",0,0,700,850);
233
234 TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
235 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
236 hp->SetFillColor(4); hp->SetXTitle("(mrad)"); hp->Fit("gaus"); c1->cd();
237
238 TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw();
239 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
240 hl->SetXTitle("(mrad)"); hl->Fit("gaus"); c1->cd();
241
242 TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
243 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
244 hpt->SetXTitle("(%)"); hpt->Fit("gaus"); c1->cd();
245
246 TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
247 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
cc80f89e 248 hmpt->SetXTitle("(%)"); hmpt->Fit("gaus"); c1->cd();
8c555625 249
250 TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd();
3c0f9266 251 p5->SetFillColor(41); p5->SetFrameFillColor(10);
8c555625 252 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
253 hg->Divide(hfound,hgood,1,1.,"b");
254 hf->Divide(hfake,hgood,1,1.,"b");
255 hg->SetMaximum(1.4);
256 hg->SetYTitle("Tracking efficiency");
257 hg->SetXTitle("Pt (GeV/c)");
258 hg->Draw();
259
9b280d80 260 TLine *line1 = new TLine(0.1,1.0,6.1,1.0); line1->SetLineStyle(4);
8c555625 261 line1->Draw("same");
9b280d80 262 TLine *line2 = new TLine(0.1,0.9,6.1,0.9); line2->SetLineStyle(4);
8c555625 263 line2->Draw("same");
264
265 hf->SetFillColor(1);
266 hf->SetFillStyle(3013);
267 hf->SetLineColor(2);
268 hf->SetLineWidth(2);
269 hf->Draw("histsame");
270 TText *text = new TText(0.461176,0.248448,"Fake tracks");
271 text->SetTextSize(0.05);
272 text->Draw();
273 text = new TText(0.453919,1.11408,"Good tracks");
274 text->SetTextSize(0.05);
275 text->Draw();
3c0f9266 276
277
278
279 TCanvas *c2=new TCanvas("c2","",320,32,530,590);
280
281 TPad *p6=new TPad("p6","",0.,0.,1.,.5); p6->Draw();
282 p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10);
283 he->SetFillColor(2); he->SetFillStyle(3005);
284 he->SetXTitle("Arbitrary Units");
285 he->Fit("gaus"); c2->cd();
286
287 TPad *p7=new TPad("p7","",0.,0.5,1.,1.); p7->Draw();
288 p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
289 hep->SetXTitle("p (Gev/c)"); hep->SetYTitle("dE/dX (Arb. Units)");
290 hep->Draw(); c1->cd();
291
cf98c13f 292 gBenchmark->Stop("AliTPCComparison");
293 gBenchmark->Show("AliTPCComparison");
294
295
73042f01 296 return 0;
cc80f89e 297}
3c0f9266 298
cc80f89e 299
300Int_t good_tracks(GoodTrack *gt, Int_t max) {
cc80f89e 301 Int_t nt=0;
302
9b280d80 303 //TFile *file=TFile::Open("rfio:galice.root");
304 TFile *file=TFile::Open("galice.root");
73042f01 305 if (!file->IsOpen()) {cerr<<"Can't open galice.root !\n"; exit(4);}
306
307 if (!(gAlice=(AliRun*)file->Get("gAlice"))) {
308 cerr<<"gAlice have not been found on galice.root !\n";
309 exit(5);
310 }
311
be9c5115 312 Int_t np=gAlice->GetEvent(0);
cc80f89e 313
73042f01 314 AliTPC *TPC=(AliTPC*)gAlice->GetDetector("TPC");
315 Int_t ver = TPC->IsVersion();
316 cerr<<"TPC version "<<ver<<" has been found !\n";
317
318 AliTPCParam *digp=(AliTPCParam*)file->Get("75x40_100x60");
319 if (!digp) { cerr<<"TPC parameters have not been found !\n"; exit(6); }
320 TPC->SetParam(digp);
321
322 Int_t nrow_up=digp->GetNRowUp();
323 Int_t nrows=digp->GetNRowLow()+nrow_up;
324 Int_t zero=digp->GetZeroSup();
cc80f89e 325 Int_t gap=Int_t(0.125*nrows);
326 Int_t good_number=Int_t(0.4*nrows);
327
cc80f89e 328 Int_t *good=new Int_t[np];
329 for (Int_t ii=0; ii<np; ii++) good[ii]=0;
330
cf98c13f 331
332 //MI change to be possible compile macro
333 //definition out of the swith statemnet
334 Int_t sectors_by_rows=0;
335 TTree *TD=0;
336 AliSimDigits da, *digits=&da;
337 Int_t *count=0;
cc80f89e 338 switch (ver) {
339 case 1:
73042f01 340 {
341 TFile *cf=TFile::Open("AliTPCclusters.root");
342 if (!cf->IsOpen()){cerr<<"Can't open AliTPCclusters.root !\n";exit(5);}
343 AliTPCClustersArray *ca=new AliTPCClustersArray;
344 ca->Setup(digp);
345 ca->SetClusterType("AliTPCcluster");
346 ca->ConnectTree("Segment Tree");
347 Int_t nrows=Int_t(ca->GetTree()->GetEntries());
348 for (Int_t n=0; n<nrows; n++) {
349 AliSegmentID *s=ca->LoadEntry(n);
350 Int_t sec,row;
351 digp->AdjustSectorRow(s->GetID(),sec,row);
352 AliTPCClustersRow &clrow = *ca->GetRow(sec,row);
353 Int_t ncl=clrow.GetArray()->GetEntriesFast();
354 while (ncl--) {
355 AliTPCcluster *c=(AliTPCcluster*)clrow[ncl];
b7239550 356 Int_t lab=c->GetLabel(0);
73042f01 357 if (lab<0) continue; //noise cluster
358 lab=TMath::Abs(lab);
359 if (sec>=digp->GetNInnerSector())
360 if (row==nrow_up-1 ) good[lab]|=0x1000;
361 if (sec>=digp->GetNInnerSector())
362 if (row==nrow_up-1-gap) good[lab]|=0x800;
363 good[lab]++;
364 }
365 ca->ClearRow(sec,row);
cc80f89e 366 }
73042f01 367 cf->Close();
368 }
cc80f89e 369 break;
370 case 2:
cf98c13f 371 TD=(TTree*)gDirectory->Get("TreeD_75x40_100x60");
cc80f89e 372 TD->GetBranch("Segment")->SetAddress(&digits);
cf98c13f 373 count = new Int_t[np];
cc80f89e 374 Int_t i;
375 for (i=0; i<np; i++) count[i]=0;
cf98c13f 376 sectors_by_rows=(Int_t)TD->GetEntries();
cc80f89e 377 for (i=0; i<sectors_by_rows; i++) {
378 if (!TD->GetEvent(i)) continue;
379 Int_t sec,row;
380 digp->AdjustSectorRow(digits->GetID(),sec,row);
381 cerr<<sec<<' '<<row<<" \r";
382 digits->First();
9b280d80 383 do { //Many thanks to J.Chudoba who noticed this
cc80f89e 384 Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn();
385 Short_t dig = digits->GetDigit(it,ip);
386 Int_t idx0=digits->GetTrackID(it,ip,0);
387 Int_t idx1=digits->GetTrackID(it,ip,1);
388 Int_t idx2=digits->GetTrackID(it,ip,2);
389 if (idx0>=0 && dig>=zero) count[idx0]+=1;
390 if (idx1>=0 && dig>=zero) count[idx1]+=1;
391 if (idx2>=0 && dig>=zero) count[idx2]+=1;
9b280d80 392 } while (digits->Next());
cc80f89e 393 for (Int_t j=0; j<np; j++) {
394 if (count[j]>1) {
395 if (sec>=digp->GetNInnerSector())
cf98c13f 396 if (row==nrow_up-1 ) good[j]|=0x1000;
cc80f89e 397 if (sec>=digp->GetNInnerSector())
cf98c13f 398 if (row==nrow_up-1-gap) good[j]|=0x800;
cc80f89e 399 good[j]++;
400 }
401 count[j]=0;
402 }
403 }
404 delete[] count;
405 break;
406 default:
407 cerr<<"Invalid TPC version !\n";
73042f01 408 file->Close();
409 exit(7);
cc80f89e 410 }
411
412 TTree *TH=gAlice->TreeH();
cf98c13f 413 Int_t npart=(Int_t)TH->GetEntries();
cc80f89e 414
415 while (npart--) {
cf98c13f 416 AliTPChit *hit0=0;
417
cc80f89e 418 TPC->ResetHits();
419 TH->GetEvent(npart);
cf98c13f 420 AliTPChit * hit = (AliTPChit*) TPC->FirstHit(-1);
421 while (hit){
422 if (hit->fQ==0.) break;
423 hit = (AliTPChit*) TPC->NextHit();
424 }
425 if (hit) {
426 hit0 = new AliTPChit(*hit); //Make copy of hit
427 hit = hit0;
428 }
429 else continue;
430 AliTPChit *hit1=(AliTPChit*)TPC->NextHit();
431 if (hit1==0) continue;
cc80f89e 432 if (hit1->fQ != 0.) continue;
10e5e16f 433 Int_t i=hit->Track();
c9b22865 434 TParticle *p = (TParticle*)gAlice->Particle(i);
435
cc80f89e 436 if (p->GetFirstMother()>=0) continue; //secondary particle
437 if (good[i] < 0x1000+0x800+2+good_number) continue;
438 if (p->Pt()<0.100) continue;
439 if (TMath::Abs(p->Pz()/p->Pt())>0.999) continue;
440
441 gt[nt].lab=i;
442 gt[nt].code=p->GetPdgCode();
443//**** px py pz - in global coordinate system, x y z - in local !
10e5e16f 444 gt[nt].px=hit->X(); gt[nt].py=hit->Y(); gt[nt].pz=hit->Z();
cc80f89e 445 Float_t cs,sn; digp->AdjustCosSin(hit1->fSector,cs,sn);
10e5e16f 446 gt[nt].x = hit1->X()*cs + hit1->Y()*sn;
447 gt[nt].y =-hit1->X()*sn + hit1->Y()*cs;
448 gt[nt].z = hit1->Z();
cf98c13f 449 nt++;
450 if (hit0) delete hit0;
cc80f89e 451 cerr<<i<<" \r";
452 if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
453 }
454 delete[] good;
73042f01 455
be9c5115 456 delete gAlice; gAlice=0;
73042f01 457
458 file->Close();
cf98c13f 459 gBenchmark->Stop("AliTPCComparison");
460 gBenchmark->Show("AliTPCComparison");
cc80f89e 461 return nt;
8c555625 462}
463
73042f01 464
465