TClonesArrays deleted correctly
[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() {
cf98c13f 14 Int_t i;
15 gBenchmark->Start("AliTPCComparison");
8c555625 16
73042f01 17 TFile *cf=TFile::Open("AliTPCclusters.root");
18 if (!cf->IsOpen()) {cerr<<"Can't open AliTPCclusters.root !\n"; return 1;}
19 AliTPCParam *digp= (AliTPCParam*)cf->Get("75x40_100x60");
20 if (!digp) { cerr<<"TPC parameters have not been found !\n"; return 2; }
21
22// Load clusters
23 AliTPCClustersArray *ca=new AliTPCClustersArray;
24 ca->Setup(digp);
25 ca->SetClusterType("AliTPCcluster");
26 ca->ConnectTree("Segment Tree");
27 Int_t nentr=Int_t(ca->GetTree()->GetEntries());
be9c5115 28 for (i=0; i<nentr; i++) ca->LoadEntry(i);
8c555625 29
73042f01 30// Load tracks
31 TFile *tf=TFile::Open("AliTPCtracks.root");
32 if (!tf->IsOpen()) {cerr<<"Can't open AliTPCtracks.root !\n"; return 3;}
33 TObjArray tarray(2000);
34 TTree *tracktree=(TTree*)tf->Get("TreeT");
35 TBranch *tbranch=tracktree->GetBranch("tracks");
cf98c13f 36 nentr=(Int_t)tracktree->GetEntries();
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);
43 iotrack->CookLabel(ca);
44 tarray.AddLast(iotrack);
45 }
46 tf->Close();
47
48 delete ca;
49 cf->Close();
8c555625 50
51/////////////////////////////////////////////////////////////////////////
c9b22865 52 GoodTrack gt[15000];
cc80f89e 53 Int_t ngood=0;
be9c5115 54 ifstream in("good_tracks_tpc");
cc80f89e 55 if (in) {
56 cerr<<"Reading good tracks...\n";
be9c5115 57 while (in>>gt[ngood].lab>>gt[ngood].code>>
58 gt[ngood].px>>gt[ngood].py>>gt[ngood].pz>>
59 gt[ngood].x >>gt[ngood].y >>gt[ngood].z) {
cc80f89e 60 ngood++;
61 cerr<<ngood<<'\r';
c9b22865 62 if (ngood==15000) {
cc80f89e 63 cerr<<"Too many good tracks !\n";
64 break;
65 }
66 }
be9c5115 67 if (!in.eof()) cerr<<"Read error (good_tracks_tpc) !\n";
cc80f89e 68 } else {
69 cerr<<"Marking good tracks (this will take a while)...\n";
c9b22865 70 ngood=good_tracks(gt,15000);
be9c5115 71 ofstream out("good_tracks_tpc");
cc80f89e 72 if (out) {
73 for (Int_t ngd=0; ngd<ngood; ngd++)
be9c5115 74 out<<gt[ngd].lab<<' '<<gt[ngd].code<<' '<<
75 gt[ngd].px<<' '<<gt[ngd].py<<' '<<gt[ngd].pz<<' '<<
76 gt[ngd].x <<' '<<gt[ngd].y <<' '<<gt[ngd].z <<endl;
77 } else cerr<<"Can not open file (good_tracks_tpc) !\n";
cc80f89e 78 out.close();
be9c5115 79
80 cerr<<"Preparing tracks for matching with the ITS...\n";
81 tarray.Sort();
82 tf=TFile::Open("AliTPCtracks.root","recreate");
83 tracktree=new TTree("TreeT","Tree with TPC tracks");
84 tracktree->Branch("tracks","AliTPCtrack",&iotrack,32000,0);
85 for (i=0; i<nentr; i++) {
86 iotrack=(AliTPCtrack*)tarray.UncheckedAt(i);
87 tracktree->Fill();
88 }
89 tracktree->Write();
90 tf->Close();
91
cc80f89e 92 }
93 cerr<<"Number of good tracks : "<<ngood<<endl;
94
8c555625 95 cerr<<"Doing comparison...\n";
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.);
112 TH2F *hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,200.);
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
cc80f89e 260 TLine *line1 = new TLine(0,1.0,7,1.0); line1->SetLineStyle(4);
8c555625 261 line1->Draw("same");
cc80f89e 262 TLine *line2 = new TLine(0,0.9,7,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
be9c5115 303 TFile *file=TFile::Open("rfio:galice.root");
73042f01 304 if (!file->IsOpen()) {cerr<<"Can't open galice.root !\n"; exit(4);}
305
306 if (!(gAlice=(AliRun*)file->Get("gAlice"))) {
307 cerr<<"gAlice have not been found on galice.root !\n";
308 exit(5);
309 }
310
be9c5115 311 Int_t np=gAlice->GetEvent(0);
cc80f89e 312
73042f01 313 AliTPC *TPC=(AliTPC*)gAlice->GetDetector("TPC");
314 Int_t ver = TPC->IsVersion();
315 cerr<<"TPC version "<<ver<<" has been found !\n";
316
317 AliTPCParam *digp=(AliTPCParam*)file->Get("75x40_100x60");
318 if (!digp) { cerr<<"TPC parameters have not been found !\n"; exit(6); }
319 TPC->SetParam(digp);
320
321 Int_t nrow_up=digp->GetNRowUp();
322 Int_t nrows=digp->GetNRowLow()+nrow_up;
323 Int_t zero=digp->GetZeroSup();
cc80f89e 324 Int_t gap=Int_t(0.125*nrows);
325 Int_t good_number=Int_t(0.4*nrows);
326
cc80f89e 327 Int_t *good=new Int_t[np];
328 for (Int_t ii=0; ii<np; ii++) good[ii]=0;
329
cf98c13f 330
331 //MI change to be possible compile macro
332 //definition out of the swith statemnet
333 Int_t sectors_by_rows=0;
334 TTree *TD=0;
335 AliSimDigits da, *digits=&da;
336 Int_t *count=0;
cc80f89e 337 switch (ver) {
338 case 1:
73042f01 339 {
340 TFile *cf=TFile::Open("AliTPCclusters.root");
341 if (!cf->IsOpen()){cerr<<"Can't open AliTPCclusters.root !\n";exit(5);}
342 AliTPCClustersArray *ca=new AliTPCClustersArray;
343 ca->Setup(digp);
344 ca->SetClusterType("AliTPCcluster");
345 ca->ConnectTree("Segment Tree");
346 Int_t nrows=Int_t(ca->GetTree()->GetEntries());
347 for (Int_t n=0; n<nrows; n++) {
348 AliSegmentID *s=ca->LoadEntry(n);
349 Int_t sec,row;
350 digp->AdjustSectorRow(s->GetID(),sec,row);
351 AliTPCClustersRow &clrow = *ca->GetRow(sec,row);
352 Int_t ncl=clrow.GetArray()->GetEntriesFast();
353 while (ncl--) {
354 AliTPCcluster *c=(AliTPCcluster*)clrow[ncl];
b7239550 355 Int_t lab=c->GetLabel(0);
73042f01 356 if (lab<0) continue; //noise cluster
357 lab=TMath::Abs(lab);
358 if (sec>=digp->GetNInnerSector())
359 if (row==nrow_up-1 ) good[lab]|=0x1000;
360 if (sec>=digp->GetNInnerSector())
361 if (row==nrow_up-1-gap) good[lab]|=0x800;
362 good[lab]++;
363 }
364 ca->ClearRow(sec,row);
cc80f89e 365 }
73042f01 366 cf->Close();
367 }
cc80f89e 368 break;
369 case 2:
cf98c13f 370 TD=(TTree*)gDirectory->Get("TreeD_75x40_100x60");
cc80f89e 371 TD->GetBranch("Segment")->SetAddress(&digits);
cf98c13f 372 count = new Int_t[np];
cc80f89e 373 Int_t i;
374 for (i=0; i<np; i++) count[i]=0;
cf98c13f 375 sectors_by_rows=(Int_t)TD->GetEntries();
cc80f89e 376 for (i=0; i<sectors_by_rows; i++) {
377 if (!TD->GetEvent(i)) continue;
378 Int_t sec,row;
379 digp->AdjustSectorRow(digits->GetID(),sec,row);
380 cerr<<sec<<' '<<row<<" \r";
381 digits->First();
382 while (digits->Next()) {
383 Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn();
384 Short_t dig = digits->GetDigit(it,ip);
385 Int_t idx0=digits->GetTrackID(it,ip,0);
386 Int_t idx1=digits->GetTrackID(it,ip,1);
387 Int_t idx2=digits->GetTrackID(it,ip,2);
388 if (idx0>=0 && dig>=zero) count[idx0]+=1;
389 if (idx1>=0 && dig>=zero) count[idx1]+=1;
390 if (idx2>=0 && dig>=zero) count[idx2]+=1;
391 }
392 for (Int_t j=0; j<np; j++) {
393 if (count[j]>1) {
394 if (sec>=digp->GetNInnerSector())
cf98c13f 395 if (row==nrow_up-1 ) good[j]|=0x1000;
cc80f89e 396 if (sec>=digp->GetNInnerSector())
cf98c13f 397 if (row==nrow_up-1-gap) good[j]|=0x800;
cc80f89e 398 good[j]++;
399 }
400 count[j]=0;
401 }
402 }
403 delete[] count;
404 break;
405 default:
406 cerr<<"Invalid TPC version !\n";
73042f01 407 file->Close();
408 exit(7);
cc80f89e 409 }
410
411 TTree *TH=gAlice->TreeH();
cf98c13f 412 Int_t npart=(Int_t)TH->GetEntries();
cc80f89e 413
414 while (npart--) {
cf98c13f 415 AliTPChit *hit0=0;
416
cc80f89e 417 TPC->ResetHits();
418 TH->GetEvent(npart);
cf98c13f 419 AliTPChit * hit = (AliTPChit*) TPC->FirstHit(-1);
420 while (hit){
421 if (hit->fQ==0.) break;
422 hit = (AliTPChit*) TPC->NextHit();
423 }
424 if (hit) {
425 hit0 = new AliTPChit(*hit); //Make copy of hit
426 hit = hit0;
427 }
428 else continue;
429 AliTPChit *hit1=(AliTPChit*)TPC->NextHit();
430 if (hit1==0) continue;
cc80f89e 431 if (hit1->fQ != 0.) continue;
10e5e16f 432 Int_t i=hit->Track();
c9b22865 433 TParticle *p = (TParticle*)gAlice->Particle(i);
434
cc80f89e 435 if (p->GetFirstMother()>=0) continue; //secondary particle
436 if (good[i] < 0x1000+0x800+2+good_number) continue;
437 if (p->Pt()<0.100) continue;
438 if (TMath::Abs(p->Pz()/p->Pt())>0.999) continue;
439
440 gt[nt].lab=i;
441 gt[nt].code=p->GetPdgCode();
442//**** px py pz - in global coordinate system, x y z - in local !
10e5e16f 443 gt[nt].px=hit->X(); gt[nt].py=hit->Y(); gt[nt].pz=hit->Z();
cc80f89e 444 Float_t cs,sn; digp->AdjustCosSin(hit1->fSector,cs,sn);
10e5e16f 445 gt[nt].x = hit1->X()*cs + hit1->Y()*sn;
446 gt[nt].y =-hit1->X()*sn + hit1->Y()*cs;
447 gt[nt].z = hit1->Z();
cf98c13f 448 nt++;
449 if (hit0) delete hit0;
cc80f89e 450 cerr<<i<<" \r";
451 if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
452 }
453 delete[] good;
73042f01 454
be9c5115 455 delete gAlice; gAlice=0;
73042f01 456
457 file->Close();
cf98c13f 458 gBenchmark->Stop("AliTPCComparison");
459 gBenchmark->Show("AliTPCComparison");
cc80f89e 460 return nt;
8c555625 461}
462
73042f01 463
464