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