3 #include "AliTPCtracker.h"
11 Float_t pxg,pyg,pzg,ptg;
14 Int_t good_tracks(GoodTrack *gt, Int_t max);
18 gBenchmark->Start("AliTPCComparison");
20 AliKalmanTrack::SetConvConst(100/0.299792458/0.2/gAlice->Field()->Factor());
22 TFile *cf=TFile::Open("AliTPCclusters.root");
23 if (!cf->IsOpen()) {cerr<<"Can't open AliTPCclusters.root !\n"; return 1;}
24 AliTPCParam *digp= (AliTPCParam*)cf->Get("75x40_100x60");
25 if (!digp) { cerr<<"TPC parameters have not been found !\n"; return 2; }
26 AliTPCtracker *tracker = new AliTPCtracker(digp);
29 AliTPCClustersArray *ca=new AliTPCClustersArray;
31 ca->SetClusterType("AliTPCcluster");
32 ca->ConnectTree("Segment Tree");
33 Int_t nentr=Int_t(ca->GetTree()->GetEntries());
34 for (i=0; i<nentr; i++) ca->LoadEntry(i);
37 tracker->LoadInnerSectors();
38 tracker->LoadOuterSectors();
41 TFile *tf=TFile::Open("AliTPCtracks.root");
42 if (!tf->IsOpen()) {cerr<<"Can't open AliTPCtracks.root !\n"; return 3;}
43 TObjArray tarray(2000);
44 // TTree *tracktree=(TTree*)tf->Get("TreeT");
45 TTree *tracktree=(TTree*)tf->Get("TPCf");
46 if (!tracktree) {cerr<<"Can't get a tree with TPC tracks !\n"; return 4;}
47 TBranch *tbranch=tracktree->GetBranch("tracks");
48 nentr=(Int_t)tracktree->GetEntries();
50 AliTPCtrack *iotrack=0;
51 for (i=0; i<nentr; i++) {
52 iotrack=new AliTPCtrack;
53 tbranch->SetAddress(&iotrack);
54 tracktree->GetEvent(i);
55 //iotrack->CookLabel(ca);
56 tracker->CookLabel(iotrack,0.1);
57 tarray.AddLast(iotrack);
67 /////////////////////////////////////////////////////////////////////////
70 ifstream in("good_tracks_tpc");
72 cerr<<"Reading good tracks...\n";
73 while (in>>gt[ngood].lab>>gt[ngood].code>>
74 gt[ngood].px>>gt[ngood].py>>gt[ngood].pz>>
75 gt[ngood].x >>gt[ngood].y >>gt[ngood].z>>
76 gt[ngood].pxg>>gt[ngood].pyg>>gt[ngood].pzg>>
77 gt[ngood].ptg>>gt[ngood].flag) {
81 cerr<<"Too many good tracks !\n";
85 if (!in.eof()) cerr<<"Read error (good_tracks_tpc) !\n";
87 cerr<<"Marking good tracks (this will take a while)...\n";
88 ngood=good_tracks(gt,15000);
89 ofstream out("good_tracks_tpc");
91 for (Int_t ngd=0; ngd<ngood; ngd++)
92 out<<gt[ngd].lab<<' '<<gt[ngd].code<<' '<<
93 gt[ngd].px<<' '<<gt[ngd].py<<' '<<gt[ngd].pz<<' '<<
94 gt[ngd].x <<' '<<gt[ngd].y <<' '<<gt[ngd].z<<' '<<
95 gt[ngd].pxg<<' '<<gt[ngd].pyg<<' '<<gt[ngd].pzg<<' '<<' '
96 <<gt[ngd].ptg<<gt[ngd].flag<<endl;
97 } else cerr<<"Can not open file (good_tracks_tpc) !\n";
100 cerr<<"Preparing tracks for matching with the ITS...\n";
102 tf=TFile::Open("AliTPCtracks.root","recreate");
103 // tracktree=new TTree("TreeT","Tree with TPC tracks");
104 tracktree=new TTree("TPCf","Tree with TPC tracks");
105 tracktree->Branch("tracks","AliTPCtrack",&iotrack,32000,0);
106 for (i=0; i<nentr; i++) {
107 iotrack=(AliTPCtrack*)tarray.UncheckedAt(i);
114 cerr<<"Number of good tracks : "<<ngood<<endl;
116 cerr<<"Doing comparison...\n";
117 TH1F *hp=new TH1F("hp","PHI resolution",50,-20.,20.); hp->SetFillColor(4);
118 TH1F *hl=new TH1F("hl","LAMBDA resolution",50,-20,20);hl->SetFillColor(4);
119 TH1F *hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
120 hpt->SetFillColor(2);
121 TH1F *hmpt=new TH1F("hmpt","Relative Pt resolution (pt>4GeV/c)",30,-60,60);
122 hmpt->SetFillColor(6);
124 AliTPCtrack *trk=(AliTPCtrack*)tarray.UncheckedAt(0);
125 Double_t pmin=0.1*(100/0.299792458/0.2/trk->GetConvConst());
126 Double_t pmax=6.0+pmin;
128 TH1F *hgood=new TH1F("hgood","Good tracks",30,0.1,6.1);
129 TH1F *hfound=new TH1F("hfound","Found tracks",30,0.1,6.1);
130 TH1F *hfake=new TH1F("hfake","Fake tracks",30,0.1,6.1);
131 TH1F *hg=new TH1F("hg","",30,0.1,6.1); //efficiency for good tracks
132 hg->SetLineColor(4); hg->SetLineWidth(2);
133 TH1F *hf=new TH1F("hf","Efficiency for fake tracks",30,0.1,6.1);
134 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
136 TH1F *hgood=new TH1F("hgood","Good tracks",30,pmin,pmax);
137 TH1F *hfound=new TH1F("hfound","Found tracks",30,pmin,pmax);
138 TH1F *hfake=new TH1F("hfake","Fake tracks",30,pmin,pmax);
139 TH1F *hg=new TH1F("hg","",30,pmin,pmax); //efficiency for good tracks
140 hg->SetLineColor(4); hg->SetLineWidth(2);
141 TH1F *hf=new TH1F("hf","Efficiency for fake tracks",30,pmin,pmax);
142 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
144 TH1F *he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,100.);
145 TH2F *hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,200.);
146 hep->SetMarkerStyle(8);
147 hep->SetMarkerSize(0.4);
149 Int_t mingood = ngood; //MI change
150 Int_t * track_notfound = new Int_t[ngood];
151 Int_t itrack_notfound =0;
152 Int_t * track_fake = new Int_t[ngood];
153 Int_t itrack_fake = 0;
154 Int_t * track_multifound = new Int_t[ngood];
155 Int_t * track_multifound_n = new Int_t[ngood];
156 Int_t itrack_multifound =0;
159 Int_t lab=gt[ngood].lab,tlab=-1;
161 TMath::Sqrt(gt[ngood].px*gt[ngood].px + gt[ngood].py*gt[ngood].py);
163 if (ptg<pmin) continue;
166 AliTPCtrack *track=0;
167 for (i=0; i<nentr; i++) {
168 track=(AliTPCtrack*)tarray.UncheckedAt(i);
169 tlab=track->GetLabel();
170 if (lab==TMath::Abs(tlab)) break;
173 //cerr<<"Track "<<lab<<" was not found !\n";
174 track_notfound[itrack_notfound++]=lab;
178 //MI change - addition
181 AliTPCtrack * mitrack;
182 for (mi=0; mi<nentr; mi++) {
183 mitrack=(AliTPCtrack*)tarray.UncheckedAt(mi);
184 if (lab==TMath::Abs(mitrack->GetLabel())) micount++;
187 //cout<<"Track no. "<<lab<<" found "<<micount<<" times\n";
188 track_multifound[itrack_multifound]=lab;
189 track_multifound_n[itrack_multifound]=micount;
195 Double_t xk=gt[ngood].x;//digp->GetPadRowRadii(0,0);
196 track->PropagateTo(xk);
198 if (lab==tlab) hfound->Fill(ptg);
200 track_fake[itrack_fake++]=lab;
202 //cerr<<lab<<" fake\n";
205 Double_t par[5]; track->GetExternalParameters(xk,par);
206 //cout<<"par = "<<par[0]<<" "<<par[1]<<" "<<par[2]<<" "<<par[3]<<" "<<par[4]
208 Float_t phi=TMath::ASin(par[2]) + track->GetAlpha();
209 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
210 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
211 Float_t lam=TMath::ATan(par[3]);
212 Float_t pt_1=TMath::Abs(par[4]);
214 if (TMath::Abs(gt[ngood].code)==11 && ptg>4.) {
215 hmpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
217 Float_t phig=TMath::ATan2(gt[ngood].py,gt[ngood].px);
218 hp->Fill((phi - phig)*1000.);
220 Float_t lamg=TMath::ATan2(gt[ngood].pz,ptg);
221 hl->Fill((lam - lamg)*1000.);
223 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
226 Float_t mom=1./(pt_1*TMath::Cos(lam));
227 Float_t dedx=track->GetdEdx();
228 hep->Fill(mom,dedx,1.);
229 if (TMath::Abs(gt[ngood].code)==211)
230 if (mom>0.4 && mom<0.5) {
237 Stat_t ng=hgood->GetEntries(); cerr<<"Good tracks "<<ng<<endl;
238 Stat_t nf=hfound->GetEntries();
240 cerr<<"\n\n\nIntegral efficiency is about "<<nf/ng*100.<<" %\n";
242 //MI change - addition
243 cout<<"Total number of found tracks ="<<nentr<<"\n";
244 cout<<"Total number of \"good\" tracks ="<<mingood<<"\n";
247 cout<<"\nList of Not found tracks :\n";
249 for ( i = 0; i< itrack_notfound; i++){
250 cout<<track_notfound[i]<<"\t";
251 if ((i%5)==4) cout<<"\n";
253 cout<<"\nList of fake tracks :\n";
254 for ( i = 0; i< itrack_fake; i++){
255 cout<<track_fake[i]<<"\t";
256 if ((i%5)==4) cout<<"\n";
258 cout<<"\nList of multiple found tracks :\n";
259 for ( i=0; i<itrack_multifound; i++) {
260 cout<<"id. "<<track_multifound[i]<<" found - "<<track_multifound_n[i]<<"times\n";
265 gStyle->SetOptStat(111110);
266 gStyle->SetOptFit(1);
268 TCanvas *c1=new TCanvas("c1","",0,0,700,850);
270 TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
271 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
272 hp->SetFillColor(4); hp->SetXTitle("(mrad)"); hp->Fit("gaus"); c1->cd();
274 TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw();
275 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
276 hl->SetXTitle("(mrad)"); hl->Fit("gaus"); c1->cd();
278 TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
279 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
280 hpt->SetXTitle("(%)"); hpt->Fit("gaus"); c1->cd();
282 TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
283 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
284 hmpt->SetXTitle("(%)"); hmpt->Fit("gaus"); c1->cd();
286 TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd();
287 p5->SetFillColor(41); p5->SetFrameFillColor(10);
288 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
289 hg->Divide(hfound,hgood,1,1.,"b");
290 hf->Divide(hfake,hgood,1,1.,"b");
292 hg->SetYTitle("Tracking efficiency");
293 hg->SetXTitle("Pt (GeV/c)");
296 TLine *line1 = new TLine(0,1.0,7,1.0); line1->SetLineStyle(4);
298 TLine *line2 = new TLine(0,0.9,7,0.9); line2->SetLineStyle(4);
301 TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
303 TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
307 hf->SetFillStyle(3013);
310 hf->Draw("histsame");
311 TText *text = new TText(0.461176,0.248448,"Fake tracks");
312 text->SetTextSize(0.05);
314 text = new TText(0.453919,1.11408,"Good tracks");
315 text->SetTextSize(0.05);
320 TCanvas *c2=new TCanvas("c2","",320,32,530,590);
322 TPad *p6=new TPad("p6","",0.,0.,1.,.5); p6->Draw();
323 p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10);
324 he->SetFillColor(2); he->SetFillStyle(3005);
325 he->SetXTitle("Arbitrary Units");
326 he->Fit("gaus"); c2->cd();
328 TPad *p7=new TPad("p7","",0.,0.5,1.,1.); p7->Draw();
329 p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
330 hep->SetXTitle("p (Gev/c)"); hep->SetYTitle("dE/dX (Arb. Units)");
331 hep->Draw(); c1->cd();
333 gBenchmark->Stop("AliTPCComparison");
334 gBenchmark->Show("AliTPCComparison");
341 Int_t good_tracks(GoodTrack *gt, Int_t max) {
344 //TFile *file=TFile::Open("rfio:galice.root");
345 TFile *file=TFile::Open("galice.root");
346 if (!file->IsOpen()) {cerr<<"Can't open galice.root !\n"; exit(4);}
348 if (!(gAlice=(AliRun*)file->Get("gAlice"))) {
349 cerr<<"gAlice have not been found on galice.root !\n";
353 Int_t np=gAlice->GetEvent(0);
355 AliTPC *TPC=(AliTPC*)gAlice->GetDetector("TPC");
356 Int_t ver = TPC->IsVersion();
357 cerr<<"TPC version "<<ver<<" has been found !\n";
359 AliTPCParam *digp=(AliTPCParam*)file->Get("75x40_100x60");
360 if (!digp) { cerr<<"TPC parameters have not been found !\n"; exit(6); }
363 Int_t nrow_up=digp->GetNRowUp();
364 Int_t nrows=digp->GetNRowLow()+nrow_up;
365 Int_t zero=digp->GetZeroSup();
366 Int_t gap=Int_t(0.125*nrows);
367 Int_t good_number=Int_t(0.4*nrows);
369 Int_t *good=new Int_t[np];
370 for (Int_t ii=0; ii<np; ii++) good[ii]=0;
373 //MI change to be possible compile macro
374 //definition out of the swith statemnet
375 Int_t sectors_by_rows=0;
377 AliSimDigits da, *digits=&da;
382 TFile *cf=TFile::Open("AliTPCclusters.root");
383 if (!cf->IsOpen()){cerr<<"Can't open AliTPCclusters.root !\n";exit(5);}
384 AliTPCClustersArray *ca=new AliTPCClustersArray;
386 ca->SetClusterType("AliTPCcluster");
387 ca->ConnectTree("Segment Tree");
388 Int_t nrows=Int_t(ca->GetTree()->GetEntries());
389 for (Int_t n=0; n<nrows; n++) {
390 AliSegmentID *s=ca->LoadEntry(n);
392 digp->AdjustSectorRow(s->GetID(),sec,row);
393 AliTPCClustersRow &clrow = *ca->GetRow(sec,row);
394 Int_t ncl=clrow.GetArray()->GetEntriesFast();
396 AliTPCcluster *c=(AliTPCcluster*)clrow[ncl];
397 Int_t lab=c->GetLabel(0);
398 if (lab<0) continue; //noise cluster
400 if (sec>=digp->GetNInnerSector())
401 if (row==nrow_up-1 ) good[lab]|=0x1000;
402 if (sec>=digp->GetNInnerSector())
403 if (row==nrow_up-1-gap) good[lab]|=0x800;
406 ca->ClearRow(sec,row);
412 TD=(TTree*)gDirectory->Get("TreeD_75x40_100x60");
413 TD->GetBranch("Segment")->SetAddress(&digits);
414 count = new Int_t[np];
416 for (i=0; i<np; i++) count[i]=0;
417 sectors_by_rows=(Int_t)TD->GetEntries();
418 for (i=0; i<sectors_by_rows; i++) {
419 if (!TD->GetEvent(i)) continue;
421 digp->AdjustSectorRow(digits->GetID(),sec,row);
422 cerr<<sec<<' '<<row<<" \r";
424 // while (digits->Next()) {
425 do { //Many thanks to J.Chudoba who noticed this
426 Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn();
427 Short_t dig = digits->GetDigit(it,ip);
428 Int_t idx0=digits->GetTrackID(it,ip,0);
429 Int_t idx1=digits->GetTrackID(it,ip,1);
430 Int_t idx2=digits->GetTrackID(it,ip,2);
431 if (idx0>=0 && dig>=zero) count[idx0]+=1;
432 if (idx1>=0 && dig>=zero) count[idx1]+=1;
433 if (idx2>=0 && dig>=zero) count[idx2]+=1;
434 } while (digits->Next());
435 for (Int_t j=0; j<np; j++) {
437 if (sec>=digp->GetNInnerSector())
438 if (row==nrow_up-1 ) good[j]|=0x1000;
439 if (sec>=digp->GetNInnerSector())
440 if (row==nrow_up-1-gap) good[j]|=0x800;
449 cerr<<"Invalid TPC version !\n";
454 TTree *TH=gAlice->TreeH();
455 Int_t npart=(Int_t)TH->GetEntries();
462 AliTPChit * hit = (AliTPChit*) TPC->FirstHit(-1);
464 if (hit->fQ==0.) break;
465 hit = (AliTPChit*) TPC->NextHit();
468 hit0 = new AliTPChit(*hit); //Make copy of hit
472 AliTPChit *hit1=(AliTPChit*)TPC->NextHit();
473 if (hit1==0) continue;
474 if (hit1->fQ != 0.) continue;
475 Int_t i=hit->Track();
476 TParticle *p = (TParticle*)gAlice->Particle(i);
478 if (p->GetFirstMother()>=0) continue; //secondary particle
479 if (good[i] < 0x1000+0x800+2+good_number) continue;
480 if (p->Pt()<0.100) continue;
481 if (TMath::Abs(p->Pz()/p->Pt())>0.999) continue;
484 gt[nt].code=p->GetPdgCode();
485 //**** px py pz - in global coordinate system, x y z - in local !
486 gt[nt].px=hit->X(); gt[nt].py=hit->Y(); gt[nt].pz=hit->Z();
487 Float_t cs,sn; digp->AdjustCosSin(hit1->fSector,cs,sn);
488 gt[nt].x = hit1->X()*cs + hit1->Y()*sn;
489 gt[nt].y =-hit1->X()*sn + hit1->Y()*cs;
490 gt[nt].z = hit1->Z();
491 gt[nt].pxg = p->Px();
492 gt[nt].pyg = p->Py();
493 gt[nt].pzg = p->Pz();
494 gt[nt].ptg = p->Pt();
497 if (hit0) delete hit0;
499 if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
503 delete gAlice; gAlice=0;
506 gBenchmark->Stop("AliTPCComparison");
507 gBenchmark->Show("AliTPCComparison");