1 /****************************************************************************
2 * Very important, delicate and rather obscure macro. *
4 * Creates list of "trackable" tracks, *
5 * sorts tracks for matching with the ITS, *
6 * calculates efficiency, resolutions etc. *
8 * Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch *
9 * with several nice improvements by: M.Ivanov, GSI, m.ivanov@gsi.de *
10 ****************************************************************************/
12 #if !defined(__CINT__) || defined(__MAKECINT__)
16 #include<TClassTable.h>
17 #include<TClonesArray.h>
27 #include <AliTPCtracker.h>
32 multievent comparison of reconstructed tracks with "exact tracks"
39 Int_t fEventN; //event number
46 enum tagprimary {kPrimaryCharged = 0x4000};
48 Int_t good_tracks(GoodTrackTPC *gt, Int_t max, Int_t firstev, Int_t eventn);
50 Int_t FindPrimaries(Int_t nparticles);
52 Int_t AliTPCComparison2(Int_t firstev=0, Int_t eventn=1) {
54 const Int_t MAX = 20000;
55 const Bool_t kOLD = kFALSE; // if tracking was done with a previous version
56 /***********************************************************************/
58 TFile *inkin = TFile::Open("rfio:galice.root");
59 // if(gAlice)delete gAlice; COMMENTED BECAUSE OF A BUG (IN COMPILED MODE)
60 gAlice = (AliRun*)inkin->Get("gAlice");
61 cout<<"AliRun object found on file "<<gAlice<<endl;
62 AliKalmanTrack::SetFieldMap(gAlice->Field());
65 delete gAlice; COMMENTED BECAUSE OF A BUG IN COMPILED MODE
68 /***********************************************************************/
69 cerr<<"Doing comparison...\n";
71 gBenchmark->Start("AliTPCComparison2");
76 cf=TFile::Open("AliTPCclusters.root");
77 if (!cf->IsOpen()) {cerr<<"Can't open AliTPCclusters.root !\n"; return 1;}
78 digp= (AliTPCParam*)cf->Get("75x40_100x60_150x60");
79 if (!digp) { cerr<<"TPC parameters have not been found !\n"; return 2; }
82 AliTPCtracker *tracker =0;
83 TObjArray tarray(MAX);
84 AliTPCtrack *iotrack=0;
87 TFile *tf=TFile::Open("AliTPCtracks.root");
91 eventptr[firstev+1]=0;
92 for (Int_t event=firstev;event<eventn; event++){
93 cout<<"================================================"<<endl;
94 cout<<"Processing event "<<event<<endl;
95 cout<<"================================================"<<endl;
99 sprintf(tname,"TreeT_TPC");
102 sprintf(tname,"TreeT_TPC_%d",event);
106 if (!tf->IsOpen()) {cerr<<"Can't open AliTPCtracks.root !\n"; return 3;}
108 tracktree=(TTree*)tf->Get(tname);
109 if (!tracktree) {cerr<<"Can't get a tree with TPC tracks !\n"; return 4;}
110 TBranch *tbranch=tracktree->GetBranch("tracks");
111 Int_t nentr0=(Int_t)tracktree->GetEntries();
113 for (i=0; i<nentr0; i++) {
114 iotrack=new AliTPCtrack;
115 tbranch->SetAddress(&iotrack);
116 tracktree->GetEvent(i);
117 // if(kOLD)tracker->CookLabel(iotrack,0.1);
118 tarray.AddLast(iotrack);
120 eventptr[event+1] = nentr; //store end of the event
127 GoodTrackTPC gt[MAX];
130 ifstream in("good_tracks_tpc");
132 cerr<<"Reading good tracks...\n";
133 while (in>>gt[ngood].fEventN>>gt[ngood].lab>>gt[ngood].code>>
134 gt[ngood].px>>gt[ngood].py>>gt[ngood].pz>>
135 gt[ngood].x >>gt[ngood].y >>gt[ngood].z) {
140 cerr<<"Too many good tracks !\n";
145 if (!in.eof()) cerr<<"Read error (good_tracks_tpc) !\n";
147 cerr<<"Marking good tracks (this will take a while)...\n";
148 ngood=good_tracks(gt,45000,firstev,eventn);
149 printf("Goood %d\n", ngood);
150 ofstream out("good_tracks_tpc");
152 cout<<"File good_tracks_tpc opened\n";
153 for (Int_t ngd=0; ngd<ngood; ngd++) {
154 out<<gt[ngd].fEventN<<' '<<gt[ngd].lab<<' '<<gt[ngd].code<<' '<<
155 gt[ngd].px<<' '<<gt[ngd].py<<' '<<gt[ngd].pz<<' '<<
156 gt[ngd].x <<' '<<gt[ngd].y <<' '<<gt[ngd].z <<endl;
158 } else cerr<<"Can not open file (good_tracks_tpc) !\n";
162 ofstream out2("good_tracks_tpc_par");
165 //cout<<"File good_tracks_tpc opened\n";
166 for (Int_t ngd=0; ngd<ngood; ngd++) {
167 Float_t pt = TMath::Sqrt(gt[ngd].px*gt[ngd].px+gt[ngd].py*gt[ngd].py);
169 if (TMath::Abs(pt)>0.01) angle = gt[ngd].pz/pt;
170 out2<<gt[ngd].fEventN<<"\t"<<gt[ngd].lab<<"\t"<<gt[ngd].code<<"\t"<<
171 pt<<"\t"<<angle<<"\t"<<endl;
173 } else cerr<<"Can not open file (good_tracks_tpc) !\n";
178 cerr<<"Number of good tracks : "<<ngood<<endl;
179 cout<<"Number of good tracks : "<<ngood<<endl;
180 if(ngood==0)return 5;
181 TH1F *hp=new TH1F("hp","PHI resolution",50,-20.,20.); hp->SetFillColor(4);
182 TH1F *hl=new TH1F("hl","LAMBDA resolution",50,-20,20);hl->SetFillColor(4);
183 TH1F *hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
184 hpt->SetFillColor(2);
185 TH1F *hmpt=new TH1F("hmpt","Relative Pt resolution (pt>4GeV/c)",30,-60,60);
186 hmpt->SetFillColor(6);
188 AliTPCtrack *trk=(AliTPCtrack*)tarray.UncheckedAt(0);
190 Double_t pmin=0.1*(100/0.299792458/0.2/trk->GetConvConst());
191 Double_t pmax=6.0+pmin;
193 TH1F *hgood=new TH1F("hgood","Good tracks",30,pmin,pmax);
194 TH1F *hfound=new TH1F("hfound","Found tracks",30,pmin,pmax);
195 TH1F *hfake=new TH1F("hfake","Fake tracks",30,pmin,pmax);
196 TH1F *hg=new TH1F("hg","",30,pmin,pmax); //efficiency for good tracks
197 hg->SetLineColor(4); hg->SetLineWidth(2);
198 TH1F *hf=new TH1F("hf","Efficiency for fake tracks",30,pmin,pmax);
199 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
201 TH1F *he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,100.);
202 TH2F *hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,250.);
203 hep->SetMarkerStyle(8);
204 hep->SetMarkerSize(0.4);
207 Int_t track_notfound[MAX], itrack_notfound=0;
208 Int_t track_fake[MAX], itrack_fake=0;
209 Int_t track_multifound[MAX], track_multifound_n[MAX], itrack_multifound=0;
211 Int_t lab=gt[ngood].lab,tlab=-1;
213 TMath::Sqrt(gt[ngood].px*gt[ngood].px + gt[ngood].py*gt[ngood].py);
215 if (ptg<pmin) continue; // Should be 1e-33 instead pmin?
218 Int_t ievent = gt[ngood].fEventN;
220 AliTPCtrack *track=0;
221 for (i=eventptr[ievent]; i<eventptr[ievent+1]; i++) {
223 track=(AliTPCtrack*)tarray.UncheckedAt(i);
224 tlab=track->GetLabel();
225 if (lab==TMath::Abs(tlab)) break;
227 if (i==eventptr[ievent+1]) {
228 track_notfound[itrack_notfound++]=lab;
234 AliTPCtrack * mitrack;
235 for (mi=eventptr[ievent]; mi<eventptr[ievent+1]; mi++) {
237 mitrack=(AliTPCtrack*)tarray.UncheckedAt(mi);
238 if (lab==TMath::Abs(mitrack->GetLabel())) micount++;
241 track_multifound[itrack_multifound]=lab;
242 track_multifound_n[itrack_multifound]=micount;
247 Double_t xk=gt[ngood].x;
248 if (!track) continue;
249 // printf("Track =%p\n",track);
250 track->PropagateTo(xk);
252 if (lab==tlab) hfound->Fill(ptg);
254 track_fake[itrack_fake++]=lab;
257 Double_t par[5]; track->GetExternalParameters(xk,par);
258 Float_t phi=TMath::ASin(par[2]) + track->GetAlpha();
259 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
260 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
261 Float_t lam=TMath::ATan(par[3]);
262 Float_t pt_1=TMath::Abs(par[4]);
264 if (TMath::Abs(gt[ngood].code)==11 && ptg>4.) {
265 hmpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
269 Float_t phig=TMath::ATan2(gt[ngood].py,gt[ngood].px);
270 hp->Fill((phi - phig)*1000.);
272 Float_t lamg=TMath::ATan2(gt[ngood].pz,ptg);
273 hl->Fill((lam - lamg)*1000.);
275 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
278 Float_t mom=1./(pt_1*TMath::Cos(lam));
279 Float_t dedx=track->GetdEdx();
280 hep->Fill(mom,dedx,1.);
281 if (TMath::Abs(gt[ngood].code)==211)
282 if (mom>0.4 && mom<0.5) {
288 cout<<"\nList of Not found tracks :\n";
289 for ( i = 0; i< itrack_notfound; i++){
290 cout<<track_notfound[i]<<"\t";
291 if ((i%5)==4) cout<<"\n";
293 cout<<"\nList of fake tracks :\n";
294 for ( i = 0; i< itrack_fake; i++){
295 cout<<track_fake[i]<<"\t";
296 if ((i%5)==4) cout<<"\n";
298 cout<<"\nList of multiple found tracks :\n";
299 for ( i=0; i<itrack_multifound; i++) {
300 cout<<"id. "<<track_multifound[i]
301 <<" found - "<<track_multifound_n[i]<<"times\n";
304 Stat_t ng=hgood->GetEntries(), nf=hfound->GetEntries();
305 if (ng!=0) cerr<<"\n\nIntegral efficiency is about "<<nf/ng*100.<<" %\n";
306 if (ng!=0) cout<<"\n\nIntegral efficiency is about "<<nf/ng*100.<<" %\n";
307 cout<<"Total number of found tracks ="<<nentr<<endl;
308 cout<<"Total number of \"good\" tracks ="
309 <<mingood<<" (selected for comparison: "<<ng<<')'<<endl<<endl;
312 gStyle->SetOptStat(111110);
313 gStyle->SetOptFit(1);
315 TCanvas *c1=new TCanvas("c1","",0,0,700,850);
317 TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
318 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
319 hp->SetFillColor(4); hp->SetXTitle("(mrad)"); hp->Fit("gaus"); c1->cd();
321 TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw();
322 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
323 hl->SetXTitle("(mrad)"); hl->Fit("gaus"); c1->cd();
325 TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
326 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
327 hpt->SetXTitle("(%)"); hpt->Fit("gaus"); c1->cd();
329 TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
330 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
331 hmpt->SetXTitle("(%)"); hmpt->Fit("gaus"); c1->cd();
333 TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd();
334 p5->SetFillColor(41); p5->SetFrameFillColor(10);
335 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
336 hg->Divide(hfound,hgood,1,1.,"b");
337 hf->Divide(hfake,hgood,1,1.,"b");
339 hg->SetYTitle("Tracking efficiency");
340 hg->SetXTitle("Pt (GeV/c)");
343 TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
345 TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
349 hf->SetFillStyle(3013);
352 hf->Draw("histsame");
353 TText *text = new TText(0.461176,0.248448,"Fake tracks");
354 text->SetTextSize(0.05);
356 text = new TText(0.453919,1.11408,"Good tracks");
357 text->SetTextSize(0.05);
362 TCanvas *c2=new TCanvas("c2","",320,32,530,590);
364 TPad *p6=new TPad("p6","",0.,0.,1.,.5); p6->Draw();
365 p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10);
366 he->SetFillColor(2); he->SetFillStyle(3005);
367 he->SetXTitle("Arbitrary Units");
368 he->Fit("gaus"); c2->cd();
370 TPad *p7=new TPad("p7","",0.,0.5,1.,1.); p7->Draw();
371 p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
372 hep->SetXTitle("p (Gev/c)"); hep->SetYTitle("dE/dX (Arb. Units)");
373 hep->Draw(); c1->cd();
375 gBenchmark->Stop("AliTPCComparison2");
376 gBenchmark->Show("AliTPCComparison2");
383 Int_t good_tracks(GoodTrackTPC *gt, Int_t max, Int_t firstev, Int_t eventn) {
384 //eventn - number of events in file
386 TFile *file=TFile::Open("galice.root");
387 if (!file->IsOpen()) {cerr<<"Can't open galice.root !\n"; exit(4);}
388 // delete gAlice; gAlice = 0;
389 if (!(gAlice=(AliRun*)file->Get("gAlice"))) {
390 cerr<<"gAlice have not been found on galice.root !\n";
394 TFile *fdigit = TFile::Open("digits.root");
397 AliTPC *TPC=(AliTPC*)gAlice->GetDetector("TPC");
398 Int_t ver = TPC->IsVersion();
399 cerr<<"TPC version "<<ver<<" has been found !\n";
401 AliTPCParam *digp=(AliTPCParam*)file->Get("75x40_100x60");
403 cerr<<"2 pad-lenght geom hits with 3 pad-length geom digits...\n";
405 digp = new AliTPCParamSR();
409 digp =(AliTPCParam*)gDirectory->Get("75x40_100x60_150x60");
412 if (!digp) { cerr<<"TPC parameters have not been found !\n"; exit(6); }
415 Int_t nrow_up=digp->GetNRowUp();
416 Int_t nrows=digp->GetNRowLow()+nrow_up;
417 Int_t zero=digp->GetZeroSup();
418 Int_t gap=Int_t(0.125*nrows), shift=Int_t(0.5*gap);
419 Int_t good_number=Int_t(0.4*nrows);
421 Int_t nt=0; //reset counter
422 char treeName[100]; //declare event identifier
424 for (Int_t event=firstev;event<eventn;event++){
425 Int_t np=gAlice->GetEvent(event);
426 Int_t nopr = FindPrimaries(np);
427 cout<<"function good_tracks -- event "<<event<<", Charged primaries:"<<nopr<<"\n";
429 Int_t *good=new Int_t[np];
430 for (Int_t ii=0; ii<np; ii++) good[ii]=0;
433 Int_t sectors_by_rows=0;
435 AliSimDigits da, *digits=&da;
440 TFile *cf=TFile::Open("AliTPCclusters.root");
441 if (!cf->IsOpen()){cerr<<"Can't open AliTPCclusters.root !\n";exit(5);}
442 AliTPCClustersArray *ca=new AliTPCClustersArray;
444 ca->SetClusterType("AliTPCcluster");
445 ca->ConnectTree("TreeC_TPC_0");
446 Int_t nrows=Int_t(ca->GetTree()->GetEntries());
447 for (Int_t n=0; n<nrows; n++) {
448 AliSegmentID *s=ca->LoadEntry(n);
450 digp->AdjustSectorRow(s->GetID(),sec,row);
451 AliTPCClustersRow &clrow = *ca->GetRow(sec,row);
452 Int_t ncl=clrow.GetArray()->GetEntriesFast();
454 AliTPCcluster *c=(AliTPCcluster*)clrow[ncl];
455 Int_t lab=c->GetLabel(0);
456 if (lab<0) continue; //noise cluster
458 if (sec>=digp->GetNInnerSector())
459 if (row==nrow_up-1 ) good[lab]|=0x1000;
460 if (sec>=digp->GetNInnerSector())
461 if (row==nrow_up-1-gap) good[lab]|=0x800;
464 ca->ClearRow(sec,row);
472 sprintf(treeName,"TreeD_75x40_100x60_150x60_%d",event);
473 TD=(TTree*)fdigit->Get(treeName); // To be revised according to
474 // NewIO schema M.Kowalski
475 TD->GetBranch("Segment")->SetAddress(&digits);
476 count = new Int_t[np];
478 for (i=0; i<np; i++) count[i]=0;
479 sectors_by_rows=(Int_t)TD->GetEntries();
480 for (i=0; i<sectors_by_rows; i++) {
481 if (!TD->GetEvent(i)) continue;
483 digp->AdjustSectorRow(digits->GetID(),sec,row);
485 digits->ExpandTrackBuffer();
486 do { //Many thanks to J.Chudoba who noticed this
487 Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn();
488 // Short_t dig = digits->GetDigit(it,ip);
489 Short_t dig = digits->CurrentDigit();
491 Int_t idx0=digits->GetTrackIDFast(it,ip,0)-2;
492 Int_t idx1=digits->GetTrackIDFast(it,ip,1)-2;
493 Int_t idx2=digits->GetTrackIDFast(it,ip,2)-2;
494 if (idx0>=0 && dig>=zero && idx0<np ) count[idx0]+=1; //background events - higher track ID's
495 if (idx1>=0 && dig>=zero && idx1<np ) count[idx1]+=1;
496 if (idx2>=0 && dig>=zero && idx2<np ) count[idx2]+=1;
497 } while (digits->Next());
498 for (Int_t j=0; j<np; j++) {
500 if (sec>=digp->GetNInnerSector())
501 if (row==nrow_up-1 ) good[j]|=0x4000;
502 if (sec>=digp->GetNInnerSector())
503 if (row==nrow_up-1-gap) good[j]|=0x1000;
505 if (sec>=digp->GetNInnerSector())
506 if (row==nrow_up-1-shift) good[j]|=0x2000;
507 if (sec>=digp->GetNInnerSector())
508 if (row==nrow_up-1-gap-shift) good[j]|=0x800;
516 delete TD; //Thanks to Mariana Bondila
520 cerr<<"Invalid TPC version !\n";
525 /** select tracks which are "good" enough **/
526 //printf("\t %d \n",np);
527 for (Int_t i=0; i<np; i++) {
528 if ((good[i]&0x5000) != 0x5000)
529 if ((good[i]&0x2800) != 0x2800) continue;
530 if ((good[i]&0x7FF ) < good_number) continue;
532 TParticle *p = (TParticle*)gAlice->Particle(i);
534 if (p->Pt()<0.100) continue;
535 if (TMath::Abs(p->Pz()/p->Pt())>0.999) continue;
536 // THIS IS GOOD IF YOU WANT SECONDARIES
537 Int_t j=p->GetFirstMother();
539 TParticle *pp = (TParticle*)gAlice->Particle(j);
540 //if (!(pp->TestBit(kPrimaryCharged))) continue; //only one decay is allowed
543 if(!(p->TestBit(kPrimaryCharged)))continue; // only primaries
546 gt[nt].fEventN=event;
548 gt[nt].code=p->GetPdgCode();
549 gt[nt].px=0.; gt[nt].py=0.; gt[nt].pz=0.;
550 gt[nt].x=0.; gt[nt].y=0.; gt[nt].z=0.;
552 if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
556 /** check if there is also information at the entrance of the TPC **/
557 TTree *TH=gAlice->TreeH(); np=(Int_t)TH->GetEntries();
559 for (Int_t i=0; i<np; i++) {
562 AliTPChit *phit = (AliTPChit*)TPC->FirstHit(-1);
563 for ( ; phit; phit=(AliTPChit*)TPC->NextHit() ) {
564 if (phit->fQ !=0. ) continue;
566 Double_t px=phit->X(), py=phit->Y(), pz=phit->Z();
568 if ((phit=(AliTPChit*)TPC->NextHit())==0) break;
569 if (phit->fQ != 0.) continue;
571 Double_t x=phit->X(), y=phit->Y(), z=phit->Z();
572 if (TMath::Sqrt(x*x+y*y)>90.) continue;
574 Int_t j, lab=phit->Track();
575 for (j=0; j<nt; j++) {if (gt[j].fEventN==event && gt[j].lab==lab) break;}
578 // (px,py,pz) - in global coordinate system, (x,y,z) - in local !
579 gt[j].px=px; gt[j].py=py; gt[j].pz=pz;
580 Float_t cs,sn; digp->AdjustCosSin(phit->fSector,cs,sn);
581 gt[j].x = x*cs + y*sn;
582 gt[j].y =-x*sn + y*cs;
587 //printf("\n%d\n",nt);
590 } // /// loop on events
591 delete gAlice; gAlice=0;
594 gBenchmark->Stop("AliTPCComparison2");
595 gBenchmark->Show("AliTPCComparison2");
600 Int_t FindPrimaries(Int_t nparticles){
603 Double_t vertcut = 0.001;
604 Double_t decacut = 3.;
605 Double_t timecut = 0.;
607 TParticle * part = gAlice->Particle(0);
608 Double_t xori = part->Vx();
609 Double_t yori = part->Vy();
610 Double_t zori = part->Vz();
611 for(Int_t iprim = 0; iprim<nparticles; iprim++){ //loop on tracks
613 part = gAlice->Particle(iprim);
614 Double_t ptot=TMath::Sqrt(part->Px()*part->Px()+part->Py()*part->Py()+part->Pz()*part->Pz());
615 if (ptot<0.01) continue;
616 char *xxx=strstr(part->GetName(),"XXX");
619 TParticlePDG *ppdg = part->GetPDG();
620 if(TMath::Abs(ppdg->Charge())!=3)continue; // only charged (no quarks)
622 Double_t dist=TMath::Sqrt((part->Vx()-xori)*(part->Vx()-xori)+(part->Vy()-yori)*(part->Vy()-yori)+(part->Vz()-zori)*(part->Vz()-zori));
623 if(dist>vertcut)continue; // cut on the vertex
625 if(part->T()>timecut)continue;
627 //Double_t ptot=TMath::Sqrt(part->Px()*part->Px()+part->Py()*part->Py()+part->Pz()*part->Pz());
628 if(ptot==(TMath::Abs(part->Pz())))continue; // no beam particles
630 Bool_t prmch = kTRUE; // candidate primary track
631 Int_t fidau=part->GetFirstDaughter(); // cut on daughters
635 lasdau=part->GetLastDaughter();
639 for(Int_t j=fidau;j<=lasdau;j++){
640 TParticle *dau=gAlice->Particle(j);
641 Double_t distd=TMath::Sqrt((dau->Vx()-xori)*(dau->Vx()-xori)+(dau->Vy()-yori)*(dau->Vy()-yori)+(dau->Vz()-zori)*(dau->Vz()-zori));
642 if(distd<decacut)prmch=kFALSE; // eliminate if the decay is near the vertex
648 part->SetBit(kPrimaryCharged);