3 #include "AliTPCtracker.h"
7 Int_t fEventN; //event number
13 Int_t good_tracks(GoodTrack *gt, Int_t max, Int_t eventn=1);
15 Int_t AliTPCComparison(Int_t eventn=1) {
16 cerr<<"Doing comparison...\n";
18 gBenchmark->Start("AliTPCComparison");
20 TFile *cf=TFile::Open("AliTPCclusters.root");
21 if (!cf->IsOpen()) {cerr<<"Can't open AliTPCclusters.root !\n"; return 1;}
22 AliTPCParam *digp= (AliTPCParam*)cf->Get("75x40_100x60");
23 if (!digp) { cerr<<"TPC parameters have not been found !\n"; return 2; }
28 AliTPCtracker *tracker =0;
29 TObjArray tarray(2000);
30 AliTPCtrack *iotrack=0;
33 TFile *tf=TFile::Open("AliTPCtracks.root");
38 for (Int_t event=0;event<eventn; event++){
40 tracker = new AliTPCtracker(digp,event);
41 tracker->LoadInnerSectors();
42 tracker->LoadOuterSectors();
45 sprintf(tname,"TreeT_TPC");
48 sprintf(tname,"TreeT_TPC_%d",event);
52 if (!tf->IsOpen()) {cerr<<"Can't open AliTPCtracks.root !\n"; return 3;}
53 tracktree=(TTree*)tf->Get(tname);
54 if (!tracktree) {cerr<<"Can't get a tree with TPC tracks !\n"; return 4;}
55 TBranch *tbranch=tracktree->GetBranch("tracks");
56 Int_t nentr0=(Int_t)tracktree->GetEntries();
58 for (i=0; i<nentr0; i++) {
59 iotrack=new AliTPCtrack;
60 tbranch->SetAddress(&iotrack);
61 tracktree->GetEvent(i);
62 tracker->CookLabel(iotrack,0.1);
63 tarray.AddLast(iotrack);
65 eventptr[event+1] = nentr; //store end of the event
71 //MI change for a moment
74 /////////////////////////////////////////////////////////////////////////
75 // GoodTrack gt[15000];
79 ifstream in("good_tracks_tpc");
81 cerr<<"Reading good tracks...\n";
82 while (in>>gt[ngood].fEventN>>gt[ngood].lab>>gt[ngood].code>>
83 gt[ngood].px>>gt[ngood].py>>gt[ngood].pz>>
84 gt[ngood].x >>gt[ngood].y >>gt[ngood].z) {
88 cerr<<"Too many good tracks !\n";
92 if (!in.eof()) cerr<<"Read error (good_tracks_tpc) !\n";
94 cerr<<"Marking good tracks (this will take a while)...\n";
95 ngood=good_tracks(gt,45000,eventn); //mi change
96 ofstream out("good_tracks_tpc");
98 for (Int_t ngd=0; ngd<ngood; ngd++)
99 out<<gt[ngd].fEventN<<' '<<gt[ngd].lab<<' '<<gt[ngd].code<<' '<<
100 gt[ngd].px<<' '<<gt[ngd].py<<' '<<gt[ngd].pz<<' '<<
101 gt[ngd].x <<' '<<gt[ngd].y <<' '<<gt[ngd].z <<endl;
102 } else cerr<<"Can not open file (good_tracks_tpc) !\n";
106 cerr<<"Preparing tracks for matching with the ITS...\n";
108 tf=TFile::Open("AliTPCtracks.root","recreate");
109 tracktree=new TTree("TPCf","Tree with TPC tracks");
110 tracktree->Branch("tracks","AliTPCtrack",&iotrack,32000,0);
111 for (i=0; i<nentr; i++) {
112 iotrack=(AliTPCtrack*)tarray.UncheckedAt(i);
119 cerr<<"Number of good tracks : "<<ngood<<endl;
121 TH1F *hp=new TH1F("hp","PHI resolution",50,-20.,20.); hp->SetFillColor(4);
122 TH1F *hl=new TH1F("hl","LAMBDA resolution",50,-20,20);hl->SetFillColor(4);
123 TH1F *hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
124 hpt->SetFillColor(2);
125 TH1F *hmpt=new TH1F("hmpt","Relative Pt resolution (pt>4GeV/c)",30,-60,60);
126 hmpt->SetFillColor(6);
128 AliTPCtrack *trk=(AliTPCtrack*)tarray.UncheckedAt(0);
129 Double_t pmin=0.1*(100/0.299792458/0.2/trk->GetConvConst());
130 Double_t pmax=6.0+pmin;
132 TH1F *hgood=new TH1F("hgood","Good tracks",30,pmin,pmax);
133 TH1F *hfound=new TH1F("hfound","Found tracks",30,pmin,pmax);
134 TH1F *hfake=new TH1F("hfake","Fake tracks",30,pmin,pmax);
135 TH1F *hg=new TH1F("hg","",30,pmin,pmax); //efficiency for good tracks
136 hg->SetLineColor(4); hg->SetLineWidth(2);
137 TH1F *hf=new TH1F("hf","Efficiency for fake tracks",30,pmin,pmax);
138 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
140 TH1F *he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,100.);
141 TH2F *hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,250.);
142 hep->SetMarkerStyle(8);
143 hep->SetMarkerSize(0.4);
145 Int_t mingood = ngood; //MI change
146 Int_t * track_notfound = new Int_t[ngood];
147 Int_t itrack_notfound =0;
148 Int_t * track_fake = new Int_t[ngood];
149 Int_t itrack_fake = 0;
150 Int_t * track_multifound = new Int_t[ngood];
151 Int_t * track_multifound_n = new Int_t[ngood];
152 Int_t itrack_multifound =0;
155 Int_t lab=gt[ngood].lab,tlab=-1;
157 TMath::Sqrt(gt[ngood].px*gt[ngood].px + gt[ngood].py*gt[ngood].py);
159 if (ptg<pmin) continue;
162 Int_t ievent = gt[ngood].fEventN;
164 AliTPCtrack *track=0;
165 // for (i=0; i<nentr; i++) {
166 for (i=eventptr[ievent]; i<eventptr[ievent+1]; i++) {
168 track=(AliTPCtrack*)tarray.UncheckedAt(i);
169 tlab=track->GetLabel();
170 if (lab==TMath::Abs(tlab)) break;
173 if (i==eventptr[ievent+1]) {
175 //cerr<<"Track "<<lab<<" was not found !\n";
176 track_notfound[itrack_notfound++]=lab;
180 //MI change - addition
183 AliTPCtrack * mitrack;
184 // for (mi=0; mi<nentr; mi++) {
185 for (mi=eventptr[ievent]; mi<eventptr[ievent+1]; mi++) {
187 mitrack=(AliTPCtrack*)tarray.UncheckedAt(mi);
188 if (lab==TMath::Abs(mitrack->GetLabel())) micount++;
191 //cout<<"Track no. "<<lab<<" found "<<micount<<" times\n";
192 track_multifound[itrack_multifound]=lab;
193 track_multifound_n[itrack_multifound]=micount;
199 Double_t xk=gt[ngood].x;//digp->GetPadRowRadii(0,0);
200 track->PropagateTo(xk);
202 if (lab==tlab) hfound->Fill(ptg);
204 track_fake[itrack_fake++]=lab;
206 //cerr<<lab<<" fake\n";
209 Double_t par[5]; track->GetExternalParameters(xk,par);
210 Float_t phi=TMath::ASin(par[2]) + track->GetAlpha();
211 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
212 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
213 Float_t lam=TMath::ATan(par[3]);
214 Float_t pt_1=TMath::Abs(par[4]);
216 if (TMath::Abs(gt[ngood].code)==11 && ptg>4.) {
217 hmpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
219 Float_t phig=TMath::ATan2(gt[ngood].py,gt[ngood].px);
220 hp->Fill((phi - phig)*1000.);
222 Float_t lamg=TMath::ATan2(gt[ngood].pz,ptg);
223 hl->Fill((lam - lamg)*1000.);
225 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
228 Float_t mom=1./(pt_1*TMath::Cos(lam));
229 Float_t dedx=track->GetdEdx();
230 hep->Fill(mom,dedx,1.);
231 if (TMath::Abs(gt[ngood].code)==211)
232 if (mom>0.4 && mom<0.5) {
239 Stat_t ng=hgood->GetEntries(); cerr<<"Good tracks "<<ng<<endl;
240 Stat_t nf=hfound->GetEntries();
242 cerr<<"\n\n\nIntegral efficiency is about "<<nf/ng*100.<<" %\n";
244 //MI change - addition
245 cout<<"Total number of found tracks ="<<nentr<<"\n";
246 cout<<"Total number of \"good\" tracks ="<<mingood<<"\n";
249 cout<<"\nList of Not found tracks :\n";
251 for ( i = 0; i< itrack_notfound; i++){
252 cout<<track_notfound[i]<<"\t";
253 if ((i%5)==4) cout<<"\n";
255 cout<<"\nList of fake tracks :\n";
256 for ( i = 0; i< itrack_fake; i++){
257 cout<<track_fake[i]<<"\t";
258 if ((i%5)==4) cout<<"\n";
260 cout<<"\nList of multiple found tracks :\n";
261 for ( i=0; i<itrack_multifound; i++) {
262 cout<<"id. "<<track_multifound[i]<<" found - "<<track_multifound_n[i]<<"times\n";
267 gStyle->SetOptStat(111110);
268 gStyle->SetOptFit(1);
270 TCanvas *c1=new TCanvas("c1","",0,0,700,850);
272 TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
273 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
274 hp->SetFillColor(4); hp->SetXTitle("(mrad)"); hp->Fit("gaus"); c1->cd();
276 TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw();
277 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
278 hl->SetXTitle("(mrad)"); hl->Fit("gaus"); c1->cd();
280 TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
281 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
282 hpt->SetXTitle("(%)"); hpt->Fit("gaus"); c1->cd();
284 TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
285 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
286 hmpt->SetXTitle("(%)"); hmpt->Fit("gaus"); c1->cd();
288 TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd();
289 p5->SetFillColor(41); p5->SetFrameFillColor(10);
290 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
291 hg->Divide(hfound,hgood,1,1.,"b");
292 hf->Divide(hfake,hgood,1,1.,"b");
294 hg->SetYTitle("Tracking efficiency");
295 hg->SetXTitle("Pt (GeV/c)");
298 TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
300 TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
304 hf->SetFillStyle(3013);
307 hf->Draw("histsame");
308 TText *text = new TText(0.461176,0.248448,"Fake tracks");
309 text->SetTextSize(0.05);
311 text = new TText(0.453919,1.11408,"Good tracks");
312 text->SetTextSize(0.05);
317 TCanvas *c2=new TCanvas("c2","",320,32,530,590);
319 TPad *p6=new TPad("p6","",0.,0.,1.,.5); p6->Draw();
320 p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10);
321 he->SetFillColor(2); he->SetFillStyle(3005);
322 he->SetXTitle("Arbitrary Units");
323 he->Fit("gaus"); c2->cd();
325 TPad *p7=new TPad("p7","",0.,0.5,1.,1.); p7->Draw();
326 p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
327 hep->SetXTitle("p (Gev/c)"); hep->SetYTitle("dE/dX (Arb. Units)");
328 hep->Draw(); c1->cd();
330 gBenchmark->Stop("AliTPCComparison");
331 gBenchmark->Show("AliTPCComparison");
338 Int_t good_tracks(GoodTrack *gt, Int_t max, Int_t eventn) {
339 //eventn - number of events in file
341 TFile *file=TFile::Open("rfio:galice.root");
342 if (!file->IsOpen()) {cerr<<"Can't open galice.root !\n"; exit(4);}
344 if (!(gAlice=(AliRun*)file->Get("gAlice"))) {
345 cerr<<"gAlice have not been found on galice.root !\n";
349 // Int_t np=gAlice->GetEvent(0); //MI change
351 AliTPC *TPC=(AliTPC*)gAlice->GetDetector("TPC");
352 Int_t ver = TPC->IsVersion();
353 cerr<<"TPC version "<<ver<<" has been found !\n";
355 AliTPCParam *digp=(AliTPCParam*)file->Get("75x40_100x60");
356 if (!digp) { cerr<<"TPC parameters have not been found !\n"; exit(6); }
359 Int_t nrow_up=digp->GetNRowUp();
360 Int_t nrows=digp->GetNRowLow()+nrow_up;
361 Int_t zero=digp->GetZeroSup();
362 Int_t gap=Int_t(0.125*nrows);
363 Int_t good_number=Int_t(0.4*nrows);
367 Int_t nt=0; //reset counter
368 char treeName[100]; //declare event identifier
370 for (Int_t event=0;event<eventn;event++){
372 Int_t np=gAlice->GetEvent(event);
373 Int_t *good=new Int_t[np];
374 for (Int_t ii=0; ii<np; ii++) good[ii]=0;
377 //MI change to be possible compile macro
378 //definition out of the swith statemnet
379 Int_t sectors_by_rows=0;
381 AliSimDigits da, *digits=&da;
386 TFile *cf=TFile::Open("AliTPCclusters.root");
387 if (!cf->IsOpen()){cerr<<"Can't open AliTPCclusters.root !\n";exit(5);}
388 AliTPCClustersArray *ca=new AliTPCClustersArray;
390 ca->SetClusterType("AliTPCcluster");
391 ca->ConnectTree("Segment Tree");
392 Int_t nrows=Int_t(ca->GetTree()->GetEntries());
393 for (Int_t n=0; n<nrows; n++) {
394 AliSegmentID *s=ca->LoadEntry(n);
396 digp->AdjustSectorRow(s->GetID(),sec,row);
397 AliTPCClustersRow &clrow = *ca->GetRow(sec,row);
398 Int_t ncl=clrow.GetArray()->GetEntriesFast();
400 AliTPCcluster *c=(AliTPCcluster*)clrow[ncl];
401 Int_t lab=c->GetLabel(0);
402 if (lab<0) continue; //noise cluster
404 if (sec>=digp->GetNInnerSector())
405 if (row==nrow_up-1 ) good[lab]|=0x1000;
406 if (sec>=digp->GetNInnerSector())
407 if (row==nrow_up-1-gap) good[lab]|=0x800;
410 ca->ClearRow(sec,row);
417 sprintf(treeName,"TreeD_75x40_100x60_%d",event);
418 TD=(TTree*)gDirectory->Get(treeName);
419 TD->GetBranch("Segment")->SetAddress(&digits);
420 count = new Int_t[np];
422 for (i=0; i<np; i++) count[i]=0;
423 sectors_by_rows=(Int_t)TD->GetEntries();
424 for (i=0; i<sectors_by_rows; i++) {
425 if (!TD->GetEvent(i)) continue;
427 digp->AdjustSectorRow(digits->GetID(),sec,row);
428 cerr<<sec<<' '<<row<<" \r";
430 do { //Many thanks to J.Chudoba who noticed this
431 Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn();
432 Short_t dig = digits->GetDigit(it,ip);
433 Int_t idx0=digits->GetTrackID(it,ip,0);
434 Int_t idx1=digits->GetTrackID(it,ip,1);
435 Int_t idx2=digits->GetTrackID(it,ip,2);
436 if (idx0>=0 && dig>=zero) count[idx0]+=1;
437 if (idx1>=0 && dig>=zero) count[idx1]+=1;
438 if (idx2>=0 && dig>=zero) count[idx2]+=1;
439 } while (digits->Next());
440 for (Int_t j=0; j<np; j++) {
442 if (sec>=digp->GetNInnerSector())
443 if (row==nrow_up-1 ) good[j]|=0x1000;
444 if (sec>=digp->GetNInnerSector())
445 if (row==nrow_up-1-gap) good[j]|=0x800;
454 cerr<<"Invalid TPC version !\n";
459 TTree *TH=gAlice->TreeH();
460 Int_t npart=(Int_t)TH->GetEntries();
467 AliTPChit * hit = (AliTPChit*) TPC->FirstHit(-1);
469 if (hit->fQ==0.) break;
470 hit = (AliTPChit*) TPC->NextHit();
473 hit0 = new AliTPChit(*hit); //Make copy of hit
477 AliTPChit *hit1=(AliTPChit*)TPC->NextHit();
478 if (hit1==0) continue;
479 if (hit1->fQ != 0.) continue;
480 Int_t i=hit->Track();
481 TParticle *p = (TParticle*)gAlice->Particle(i);
483 if (p->GetFirstMother()>=0) continue; //secondary particle
484 if (good[i] < 0x1000+0x800+2+good_number) continue;
485 if (p->Pt()<0.100) continue;
486 if (TMath::Abs(p->Pz()/p->Pt())>0.999) continue;
489 gt[nt].code=p->GetPdgCode();
490 //**** px py pz - in global coordinate system, x y z - in local !
491 gt[nt].px=hit->X(); gt[nt].py=hit->Y(); gt[nt].pz=hit->Z();
492 Float_t cs,sn; digp->AdjustCosSin(hit1->fSector,cs,sn);
493 gt[nt].fEventN=event; //MI change
494 gt[nt].x = hit1->X()*cs + hit1->Y()*sn;
495 gt[nt].y =-hit1->X()*sn + hit1->Y()*cs;
496 gt[nt].z = hit1->Z();
498 if (hit0) delete hit0;
500 if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
504 delete gAlice; gAlice=0;
507 gBenchmark->Stop("AliTPCComparison");
508 gBenchmark->Show("AliTPCComparison");