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