1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 Revision 1.12 2001/07/20 14:32:44 kowal2
19 Processing of many events possible now
21 Revision 1.11 2001/05/23 08:50:10 hristov
24 Revision 1.10 2001/05/16 14:57:25 alibrary
25 New files for folders and Stack
27 Revision 1.9 2001/05/11 07:16:56 hristov
28 Fix needed on Sun and Alpha
30 Revision 1.8 2001/05/08 15:00:15 hristov
31 Corrections for tracking in arbitrary magnenetic field. Changes towards a concept of global Alice track. Back propagation of reconstructed tracks (Yu.Belikov)
33 Revision 1.5 2000/12/20 07:51:59 kowal2
34 Changes suggested by Alessandra and Paolo to avoid overlapped
35 data fields in encapsulated classes.
37 Revision 1.4 2000/11/02 07:27:16 kowal2
40 Revision 1.2 2000/06/30 12:07:50 kowal2
41 Updated from the TPC-PreRelease branch
43 Revision 1.1.2.1 2000/06/25 08:53:55 kowal2
44 Splitted from AliTPCtracking
48 //-------------------------------------------------------
49 // Implementation of the TPC tracker
51 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
52 //-------------------------------------------------------
54 #include <TObjArray.h>
59 #include "AliTPCtracker.h"
60 #include "AliTPCcluster.h"
61 #include "AliTPCParam.h"
62 #include "AliTPCClustersRow.h"
65 AliTPCtracker::AliTPCtracker(const AliTPCParam *par):
66 fkNIS(par->GetNInnerSector()/2),
67 fkNOS(par->GetNOuterSector()/2)
69 //MI change only provisore - need change in the ITS code which depend on it
73 //_____________________________________________________________________________
74 AliTPCtracker::AliTPCtracker(const AliTPCParam *par, Int_t eventn):
75 fkNIS(par->GetNInnerSector()/2),
76 fkNOS(par->GetNOuterSector()/2)
78 //---------------------------------------------------------------------
79 // The main TPC tracker constructor
80 //---------------------------------------------------------------------
81 fInnerSec=new AliTPCSector[fkNIS];
82 fOuterSec=new AliTPCSector[fkNOS];
85 for (i=0; i<fkNIS; i++) fInnerSec[i].Setup(par,0);
86 for (i=0; i<fkNOS; i++) fOuterSec[i].Setup(par,1);
90 fClustersArray.Setup(par);
91 fClustersArray.SetClusterType("AliTPCcluster");
95 sprintf(cname,"TreeC_TPC");
98 sprintf(cname,"TreeC_TPC_%d",eventn);
101 fClustersArray.ConnectTree(cname);
107 //_____________________________________________________________________________
108 AliTPCtracker::~AliTPCtracker() {
109 //------------------------------------------------------------------
110 // TPC tracker destructor
111 //------------------------------------------------------------------
117 //_____________________________________________________________________________
118 Double_t SigmaY2(Double_t r, Double_t tgl, Double_t pt)
121 // Parametrised error of the cluster reconstruction (pad direction)
124 const Float_t kArphi=0.41818e-2;
125 const Float_t kBrphi=0.17460e-4;
126 const Float_t kCrphi=0.30993e-2;
127 const Float_t kDrphi=0.41061e-3;
129 pt=TMath::Abs(pt)*1000.;
132 Double_t s=kArphi - kBrphi*r*tgl + kCrphi*x*x + kDrphi*x;
133 if (s<0.4e-3) s=0.4e-3;
134 s*=1.3; //Iouri Belikov
139 //_____________________________________________________________________________
140 Double_t SigmaZ2(Double_t r, Double_t tgl)
143 // Parametrised error of the cluster reconstruction (drift direction)
146 const Float_t kAz=0.39614e-2;
147 const Float_t kBz=0.22443e-4;
148 const Float_t kCz=0.51504e-1;
152 Double_t s=kAz - kBz*r*tgl + kCz*tgl*tgl;
153 if (s<0.4e-3) s=0.4e-3;
154 s*=1.3; //Iouri Belikov
159 //_____________________________________________________________________________
160 Double_t f1(Double_t x1,Double_t y1,
161 Double_t x2,Double_t y2,
162 Double_t x3,Double_t y3)
164 //-----------------------------------------------------------------
165 // Initial approximation of the track curvature
166 //-----------------------------------------------------------------
167 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
168 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
169 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
170 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
171 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
173 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
175 return -xr*yr/sqrt(xr*xr+yr*yr);
179 //_____________________________________________________________________________
180 Double_t f2(Double_t x1,Double_t y1,
181 Double_t x2,Double_t y2,
182 Double_t x3,Double_t y3)
184 //-----------------------------------------------------------------
185 // Initial approximation of the track curvature times center of curvature
186 //-----------------------------------------------------------------
187 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
188 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
189 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
190 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
191 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
193 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
195 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
198 //_____________________________________________________________________________
199 Double_t f3(Double_t x1,Double_t y1,
200 Double_t x2,Double_t y2,
201 Double_t z1,Double_t z2)
203 //-----------------------------------------------------------------
204 // Initial approximation of the tangent of the track dip angle
205 //-----------------------------------------------------------------
206 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
209 //_____________________________________________________________________________
210 void AliTPCtracker::LoadOuterSectors() {
211 //-----------------------------------------------------------------
212 // This function fills outer TPC sectors with clusters.
213 //-----------------------------------------------------------------
215 Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
216 for (Int_t i=0; i<j; i++) {
217 AliSegmentID *s=fClustersArray.LoadEntry(i);
219 AliTPCParam *par=(AliTPCParam*)fClustersArray.GetParam();
220 par->AdjustSectorRow(s->GetID(),sec,row);
221 if (sec<fkNIS*2) continue;
222 AliTPCClustersRow *clrow=fClustersArray.GetRow(sec,row);
223 Int_t ncl=clrow->GetArray()->GetEntriesFast();
225 AliTPCcluster *c=(AliTPCcluster*)(*clrow)[ncl];
226 index=(((sec<<8)+row)<<16)+ncl;
227 fOuterSec[(sec-fkNIS*2)%fkNOS][row].InsertCluster(c,index);
235 //_____________________________________________________________________________
236 void AliTPCtracker::UnloadOuterSectors() {
237 //-----------------------------------------------------------------
238 // This function clears outer TPC sectors.
239 //-----------------------------------------------------------------
240 Int_t nup=fOuterSec->GetNRows();
241 for (Int_t i=0; i<fkNOS; i++) {
242 for (Int_t j=0; j<nup; j++) {
243 if (fClustersArray.GetRow(i+fkNIS*2,j))
244 fClustersArray.ClearRow(i+fkNIS*2,j);
245 if (fClustersArray.GetRow(i+fkNIS*2+fkNOS,j))
246 fClustersArray.ClearRow(i+fkNIS*2+fkNOS,j);
254 //_____________________________________________________________________________
255 void AliTPCtracker::LoadInnerSectors() {
256 //-----------------------------------------------------------------
257 // This function fills inner TPC sectors with clusters.
258 //-----------------------------------------------------------------
260 Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
261 for (Int_t i=0; i<j; i++) {
262 AliSegmentID *s=fClustersArray.LoadEntry(i);
264 AliTPCParam *par=(AliTPCParam*)fClustersArray.GetParam();
265 par->AdjustSectorRow(s->GetID(),sec,row);
266 if (sec>=fkNIS*2) continue;
267 AliTPCClustersRow *clrow=fClustersArray.GetRow(sec,row);
268 Int_t ncl=clrow->GetArray()->GetEntriesFast();
270 AliTPCcluster *c=(AliTPCcluster*)(*clrow)[ncl];
271 index=(((sec<<8)+row)<<16)+ncl;
272 fInnerSec[sec%fkNIS][row].InsertCluster(c,index);
280 //_____________________________________________________________________________
281 void AliTPCtracker::UnloadInnerSectors() {
282 //-----------------------------------------------------------------
283 // This function clears inner TPC sectors.
284 //-----------------------------------------------------------------
285 Int_t nlow=fInnerSec->GetNRows();
286 for (Int_t i=0; i<fkNIS; i++) {
287 for (Int_t j=0; j<nlow; j++) {
288 if (fClustersArray.GetRow(i,j)) fClustersArray.ClearRow(i,j);
289 if (fClustersArray.GetRow(i+fkNIS,j)) fClustersArray.ClearRow(i+fkNIS,j);
297 //_____________________________________________________________________________
298 Int_t AliTPCtracker::FollowProlongation(AliTPCseed& t, Int_t rf) {
299 //-----------------------------------------------------------------
300 // This function tries to find a track prolongation.
301 //-----------------------------------------------------------------
302 Double_t xt=t.GetX();
303 const Int_t kSKIP=(t.GetNumberOfClusters()<10) ? kRowsToSkip :
304 Int_t(0.5*fSectors->GetNRows());
305 Int_t tryAgain=kSKIP;
307 Double_t alpha=t.GetAlpha() - fSectors->GetAlphaShift();
308 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
309 if (alpha < 0. ) alpha += 2.*TMath::Pi();
310 Int_t s=Int_t(alpha/fSectors->GetAlpha())%fN;
312 for (Int_t nr=fSectors->GetRowNumber(xt)-1; nr>=rf; nr--) {
313 Double_t x=fSectors->GetX(nr), ymax=fSectors->GetMaxY(nr);
314 if (!t.PropagateTo(x)) return 0;
318 Double_t maxchi2=kMaxCHI2;
319 const AliTPCRow &krow=fSectors[s][nr];
320 Double_t pt=t.GetConvConst()/(100/0.299792458/0.2)/t.Get1Pt();
321 Double_t sy2=SigmaY2(t.GetX(),t.GetTgl(),pt);
322 Double_t sz2=SigmaZ2(t.GetX(),t.GetTgl());
323 Double_t road=4.*sqrt(t.GetSigmaY2() + sy2), y=t.GetY(), z=t.GetZ();
326 if (t.GetNumberOfClusters()>4)
327 cerr<<t.GetNumberOfClusters()
328 <<"FindProlongation warning: Too broad road !\n";
333 for (Int_t i=krow.Find(y-road); i<krow; i++) {
334 AliTPCcluster *c=(AliTPCcluster*)(krow[i]);
335 if (c->GetY() > y+road) break;
336 if (c->IsUsed()) continue;
337 if ((c->GetZ()-z)*(c->GetZ()-z) > 16.*(t.GetSigmaZ2()+sz2)) continue;
338 Double_t chi2=t.GetPredictedChi2(c);
339 if (chi2 > maxchi2) continue;
342 index=krow.GetIndex(i);
346 Float_t l=fSectors->GetPadPitchWidth();
347 t.SetSampledEdx(cl->GetQ()/l,t.GetNumberOfClusters());
348 if (!t.Update(cl,maxchi2,index)) {
349 if (!tryAgain--) return 0;
350 } else tryAgain=kSKIP;
352 if (tryAgain==0) break;
355 if (!t.Rotate(fSectors->GetAlpha())) return 0;
356 } else if (y <-ymax) {
358 if (!t.Rotate(-fSectors->GetAlpha())) return 0;
367 //_____________________________________________________________________________
368 Int_t AliTPCtracker::FollowBackProlongation
369 (AliTPCseed& seed, const AliTPCtrack &track) {
370 //-----------------------------------------------------------------
371 // This function propagates tracks back through the TPC
372 //-----------------------------------------------------------------
373 Double_t alpha=seed.GetAlpha() - fSectors->GetAlphaShift();
374 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
375 if (alpha < 0. ) alpha += 2.*TMath::Pi();
376 Int_t s=Int_t(alpha/fSectors->GetAlpha())%fN;
378 Int_t idx=-1, sec=-1, row=-1;
379 Int_t nc=seed.GetLabel(); //index of the cluster to start with
381 idx=track.GetClusterIndex(nc);
382 sec=(idx&0xff000000)>>24; row=(idx&0x00ff0000)>>16;
384 if (fSectors==fInnerSec) { if (sec >= 2*fkNIS) row=-1; }
385 else { if (sec < 2*fkNIS) row=-1; }
387 Int_t nr=fSectors->GetNRows();
388 for (Int_t i=0; i<nr; i++) {
389 Double_t x=fSectors->GetX(i), ymax=fSectors->GetMaxY(i);
391 if (!seed.PropagateTo(x)) return 0;
393 Double_t y=seed.GetY();
396 if (!seed.Rotate(fSectors->GetAlpha())) return 0;
397 } else if (y <-ymax) {
399 if (!seed.Rotate(-fSectors->GetAlpha())) return 0;
404 Double_t maxchi2=kMaxCHI2;
405 Double_t pt=seed.GetConvConst()/(100/0.299792458/0.2)/seed.Get1Pt();
406 Double_t sy2=SigmaY2(seed.GetX(),seed.GetTgl(),pt);
407 Double_t sz2=SigmaZ2(seed.GetX(),seed.GetTgl());
408 Double_t road=4.*sqrt(seed.GetSigmaY2() + sy2), z=seed.GetZ();
410 cerr<<seed.GetNumberOfClusters()
411 <<"AliTPCtracker::FollowBackProlongation: Too broad road !\n";
416 Int_t accepted=seed.GetNumberOfClusters();
418 //try to accept already found cluster
419 AliTPCcluster *c=(AliTPCcluster*)GetCluster(idx);
421 if ((chi2=seed.GetPredictedChi2(c))<maxchi2 || accepted<27) {
422 index=idx; cl=c; maxchi2=chi2;
423 } //else cerr<<"AliTPCtracker::FollowBackProlongation: oulier !\n";
426 idx=track.GetClusterIndex(nc);
427 sec=(idx&0xff000000)>>24; row=(idx&0x00ff0000)>>16;
429 if (fSectors==fInnerSec) { if (sec >= 2*fkNIS) row=-1; }
430 else { if (sec < 2*fkNIS) row=-1; }
434 //try to fill the gap
435 const AliTPCRow &krow=fSectors[s][i];
438 for (Int_t i=krow.Find(y-road); i<krow; i++) {
439 AliTPCcluster *c=(AliTPCcluster*)(krow[i]);
440 if (c->GetY() > y+road) break;
441 if (c->IsUsed()) continue;
442 if ((c->GetZ()-z)*(c->GetZ()-z)>16.*(seed.GetSigmaZ2()+sz2)) continue;
443 Double_t chi2=seed.GetPredictedChi2(c);
444 if (chi2 > maxchi2) continue;
447 index=krow.GetIndex(i);
453 Float_t l=fSectors->GetPadPitchWidth();
454 seed.SetSampledEdx(cl->GetQ()/l,seed.GetNumberOfClusters());
455 seed.Update(cl,maxchi2,index);
465 //_____________________________________________________________________________
466 void AliTPCtracker::MakeSeeds(Int_t i1, Int_t i2) {
467 //-----------------------------------------------------------------
468 // This function creates track seeds.
469 //-----------------------------------------------------------------
470 if (fSeeds==0) fSeeds=new TObjArray(15000);
472 Double_t x[5], c[15];
474 Double_t alpha=fOuterSec->GetAlpha(), shift=fOuterSec->GetAlphaShift();
475 Double_t cs=cos(alpha), sn=sin(alpha);
477 Double_t x1 =fOuterSec->GetX(i1);
478 Double_t xx2=fOuterSec->GetX(i2);
480 for (Int_t ns=0; ns<fkNOS; ns++) {
481 Int_t nl=fOuterSec[(ns-1+fkNOS)%fkNOS][i2];
482 Int_t nm=fOuterSec[ns][i2];
483 Int_t nu=fOuterSec[(ns+1)%fkNOS][i2];
484 const AliTPCRow& kr1=fOuterSec[ns][i1];
485 for (Int_t is=0; is < kr1; is++) {
486 Double_t y1=kr1[is]->GetY(), z1=kr1[is]->GetZ();
487 for (Int_t js=0; js < nl+nm+nu; js++) {
488 const AliTPCcluster *kcl;
490 Double_t x3=0.,y3=0.;
493 const AliTPCRow& kr2=fOuterSec[(ns-1+fkNOS)%fkNOS][i2];
495 y2=kcl->GetY(); z2=kcl->GetZ();
500 const AliTPCRow& kr2=fOuterSec[ns][i2];
502 x2=xx2; y2=kcl->GetY(); z2=kcl->GetZ();
504 const AliTPCRow& kr2=fOuterSec[(ns+1)%fkNOS][i2];
506 y2=kcl->GetY(); z2=kcl->GetZ();
511 Double_t zz=z1 - z1/x1*(x1-x2);
512 if (TMath::Abs(zz-z2)>5.) continue;
514 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
515 if (d==0.) {cerr<<"MakeSeeds warning: Straight seed !\n"; continue;}
519 x[4]=f1(x1,y1,x2,y2,x3,y3);
520 if (TMath::Abs(x[4]) >= 0.0066) continue;
521 x[2]=f2(x1,y1,x2,y2,x3,y3);
522 //if (TMath::Abs(x[4]*x1-x[2]) >= 0.99999) continue;
523 x[3]=f3(x1,y1,x2,y2,z1,z2);
524 if (TMath::Abs(x[3]) > 1.2) continue;
525 Double_t a=asin(x[2]);
526 Double_t zv=z1 - x[3]/x[4]*(a+asin(x[4]*x1-x[2]));
527 if (TMath::Abs(zv)>10.) continue;
529 Double_t sy1=kr1[is]->GetSigmaY2(), sz1=kr1[is]->GetSigmaZ2();
530 Double_t sy2=kcl->GetSigmaY2(), sz2=kcl->GetSigmaZ2();
531 Double_t sy3=100*0.025, sy=0.1, sz=0.1;
533 Double_t f40=(f1(x1,y1+sy,x2,y2,x3,y3)-x[4])/sy;
534 Double_t f42=(f1(x1,y1,x2,y2+sy,x3,y3)-x[4])/sy;
535 Double_t f43=(f1(x1,y1,x2,y2,x3,y3+sy)-x[4])/sy;
536 Double_t f20=(f2(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
537 Double_t f22=(f2(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
538 Double_t f23=(f2(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
539 Double_t f30=(f3(x1,y1+sy,x2,y2,z1,z2)-x[3])/sy;
540 Double_t f31=(f3(x1,y1,x2,y2,z1+sz,z2)-x[3])/sz;
541 Double_t f32=(f3(x1,y1,x2,y2+sy,z1,z2)-x[3])/sy;
542 Double_t f34=(f3(x1,y1,x2,y2,z1,z2+sz)-x[3])/sz;
546 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f23*sy3*f23;
547 c[6]=f30*sy1; c[7]=f31*sz1; c[8]=f30*sy1*f20+f32*sy2*f22;
548 c[9]=f30*sy1*f30+f31*sz1*f31+f32*sy2*f32+f34*sz2*f34;
549 c[10]=f40*sy1; c[11]=0.; c[12]=f40*sy1*f20+f42*sy2*f22+f43*sy3*f23;
550 c[13]=f30*sy1*f40+f32*sy2*f42;
551 c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
553 UInt_t index=kr1.GetIndex(is);
554 AliTPCseed *track=new AliTPCseed(index, x, c, x1, ns*alpha+shift);
555 Float_t l=fOuterSec->GetPadPitchWidth();
556 track->SetSampledEdx(kr1[is]->GetQ()/l,0);
558 Int_t rc=FollowProlongation(*track, i2);
559 if (rc==0 || track->GetNumberOfClusters()<(i1-i2)/2) delete track;
560 else fSeeds->AddLast(track);
566 //_____________________________________________________________________________
567 Int_t AliTPCtracker::ReadSeeds(const TFile *inp) {
568 //-----------------------------------------------------------------
569 // This function reades track seeds.
570 //-----------------------------------------------------------------
571 TDirectory *savedir=gDirectory;
573 TFile *in=(TFile*)inp;
575 cerr<<"AliTPCtracker::ReadSeeds(): input file is not open !\n";
580 TTree *seedTree=(TTree*)in->Get("Seeds");
582 cerr<<"AliTPCtracker::ReadSeeds(): ";
583 cerr<<"can't get a tree with track seeds !\n";
586 AliTPCtrack *seed=new AliTPCtrack;
587 seedTree->SetBranchAddress("tracks",&seed);
589 if (fSeeds==0) fSeeds=new TObjArray(15000);
591 Int_t n=(Int_t)seedTree->GetEntries();
592 for (Int_t i=0; i<n; i++) {
593 seedTree->GetEvent(i);
594 fSeeds->AddLast(new AliTPCseed(*seed,seed->GetAlpha()));
603 //_____________________________________________________________________________
604 Int_t AliTPCtracker::Clusters2Tracks(const TFile *inp, TFile *out) {
605 //-----------------------------------------------------------------
606 // This is a track finder.
607 //-----------------------------------------------------------------
608 TDirectory *savedir=gDirectory;
611 TFile *in=(TFile*)inp;
613 cerr<<"AliTPCtracker::Clusters2Tracks(): input file is not open !\n";
618 if (!out->IsOpen()) {
619 cerr<<"AliTPCtracker::Clusters2Tracks(): output file is not open !\n";
624 TTree tracktree("TPCf","Tree with TPC tracks");
625 AliTPCtrack *iotrack=0;
626 tracktree.Branch("tracks","AliTPCtrack",&iotrack,32000,0);
631 Int_t nup=fOuterSec->GetNRows(), nlow=fInnerSec->GetNRows();
632 Int_t nrows=nlow+nup;
634 Int_t gap=Int_t(0.125*nrows), shift=Int_t(0.5*gap);
635 MakeSeeds(nup-1, nup-1-gap);
636 MakeSeeds(nup-1-shift, nup-1-shift-gap);
640 //tracking in outer sectors
641 Int_t nseed=fSeeds->GetEntriesFast();
643 for (i=0; i<nseed; i++) {
644 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
645 if (FollowProlongation(t)) {
649 delete fSeeds->RemoveAt(i);
651 UnloadOuterSectors();
653 //tracking in inner sectors
656 for (i=0; i<nseed; i++) {
657 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
659 Int_t nc=t.GetNumberOfClusters();
661 Double_t alpha=t.GetAlpha() - fInnerSec->GetAlphaShift();
662 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
663 if (alpha < 0. ) alpha += 2.*TMath::Pi();
664 Int_t ns=Int_t(alpha/fInnerSec->GetAlpha())%fkNIS;
666 alpha=ns*fInnerSec->GetAlpha() + fInnerSec->GetAlphaShift() - t.GetAlpha();
668 if (t.Rotate(alpha)) {
669 if (FollowProlongation(t)) {
670 if (t.GetNumberOfClusters() >= Int_t(0.4*nrows)) {
679 delete fSeeds->RemoveAt(i);
681 UnloadInnerSectors();
685 sprintf(tname,"TreeT_TPC");
688 sprintf(tname,"TreeT_TPC_%d",fEventN);
692 tracktree.Write(tname);
694 cerr<<"Number of found tracks : "<<found<<endl;
701 //_____________________________________________________________________________
702 Int_t AliTPCtracker::PropagateBack(const TFile *inp, TFile *out) {
703 //-----------------------------------------------------------------
704 // This function propagates tracks back through the TPC.
705 //-----------------------------------------------------------------
706 fSeeds=new TObjArray(15000);
708 TFile *in=(TFile*)inp;
709 TDirectory *savedir=gDirectory;
712 cerr<<"AliTPCtracker::PropagateBack(): ";
713 cerr<<"file with back propagated ITS tracks is not open !\n";
717 if (!out->IsOpen()) {
718 cerr<<"AliTPCtracker::PropagateBack(): ";
719 cerr<<"file for back propagated TPC tracks is not open !\n";
724 TTree *bckTree=(TTree*)in->Get("ITSb");
726 cerr<<"AliTPCtracker::PropagateBack() ";
727 cerr<<"can't get a tree with back propagated ITS tracks !\n";
730 AliTPCtrack *bckTrack=new AliTPCtrack;
731 bckTree->SetBranchAddress("tracks",&bckTrack);
733 TTree *tpcTree=(TTree*)in->Get("TPCf");
735 cerr<<"AliTPCtracker::PropagateBack() ";
736 cerr<<"can't get a tree with TPC tracks !\n";
739 AliTPCtrack *tpcTrack=new AliTPCtrack;
740 tpcTree->SetBranchAddress("tracks",&tpcTrack);
742 //*** Prepare an array of tracks to be back propagated
743 Int_t nup=fOuterSec->GetNRows(), nlow=fInnerSec->GetNRows();
744 Int_t nrows=nlow+nup;
746 TObjArray tracks(15000);
748 Int_t tpcN=(Int_t)tpcTree->GetEntries();
749 Int_t bckN=(Int_t)bckTree->GetEntries();
750 if (j<bckN) bckTree->GetEvent(j++);
751 for (i=0; i<tpcN; i++) {
752 tpcTree->GetEvent(i);
753 Double_t alpha=tpcTrack->GetAlpha();
755 TMath::Abs(tpcTrack->GetLabel())==TMath::Abs(bckTrack->GetLabel())) {
756 if (!bckTrack->Rotate(alpha-bckTrack->GetAlpha())) continue;
757 fSeeds->AddLast(new AliTPCseed(*bckTrack,bckTrack->GetAlpha()));
758 bckTree->GetEvent(j++);
760 tpcTrack->ResetCovariance();
761 fSeeds->AddLast(new AliTPCseed(*tpcTrack,alpha));
763 tracks.AddLast(new AliTPCtrack(*tpcTrack));
767 TTree backTree("TPCb","Tree with back propagated TPC tracks");
768 AliTPCtrack *otrack=0;
769 backTree.Branch("tracks","AliTPCtrack",&otrack,32000,0);
771 //*** Back propagation through inner sectors
773 Int_t nseed=fSeeds->GetEntriesFast();
774 for (i=0; i<nseed; i++) {
775 AliTPCseed *ps=(AliTPCseed*)fSeeds->UncheckedAt(i), &s=*ps;
776 const AliTPCtrack *pt=(AliTPCtrack*)tracks.UncheckedAt(i), &t=*pt;
778 Int_t nc=t.GetNumberOfClusters();
779 s.SetLabel(nc-1); //set number of the cluster to start with
781 if (FollowBackProlongation(s,t)) {
785 delete fSeeds->RemoveAt(i);
787 UnloadInnerSectors();
789 //*** Back propagation through outer sectors
792 for (i=0; i<nseed; i++) {
793 AliTPCseed *ps=(AliTPCseed*)fSeeds->UncheckedAt(i), &s=*ps;
795 Int_t nc=s.GetNumberOfClusters();
796 const AliTPCtrack *pt=(AliTPCtrack*)tracks.UncheckedAt(i), &t=*pt;
798 Double_t alpha=s.GetAlpha() - fSectors->GetAlphaShift();
799 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
800 if (alpha < 0. ) alpha += 2.*TMath::Pi();
801 Int_t ns=Int_t(alpha/fSectors->GetAlpha())%fN;
803 alpha =ns*fSectors->GetAlpha() + fSectors->GetAlphaShift();
806 if (s.Rotate(alpha)) {
807 if (FollowBackProlongation(s,t)) {
808 if (s.GetNumberOfClusters() >= Int_t(0.4*nrows)) {
810 s.SetLabel(t.GetLabel());
819 delete fSeeds->RemoveAt(i);
821 UnloadOuterSectors();
825 cerr<<"Number of seeds: "<<nseed<<endl;
826 cerr<<"Number of back propagated ITS tracks: "<<bckN<<endl;
827 cerr<<"Number of back propagated TPC tracks: "<<found<<endl;
835 //_________________________________________________________________________
836 AliCluster *AliTPCtracker::GetCluster(Int_t index) const {
837 //--------------------------------------------------------------------
838 // Return pointer to a given cluster
839 //--------------------------------------------------------------------
840 Int_t sec=(index&0xff000000)>>24;
841 Int_t row=(index&0x00ff0000)>>16;
842 Int_t ncl=(index&0x0000ffff)>>00;
844 AliTPCClustersRow *clrow=((AliTPCtracker *) this)->fClustersArray.GetRow(sec,row);
845 return (AliCluster*)(*clrow)[ncl];
848 //__________________________________________________________________________
849 void AliTPCtracker::CookLabel(AliKalmanTrack *t, Float_t wrong) const {
850 //--------------------------------------------------------------------
851 //This function "cooks" a track label. If label<0, this track is fake.
852 //--------------------------------------------------------------------
853 Int_t noc=t->GetNumberOfClusters();
854 Int_t *lb=new Int_t[noc];
855 Int_t *mx=new Int_t[noc];
856 AliCluster **clusters=new AliCluster*[noc];
859 for (i=0; i<noc; i++) {
861 Int_t index=t->GetClusterIndex(i);
862 clusters[i]=GetCluster(index);
866 for (i=0; i<noc; i++) {
867 AliCluster *c=clusters[i];
868 lab=TMath::Abs(c->GetLabel(0));
870 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
876 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
878 for (i=0; i<noc; i++) {
879 AliCluster *c=clusters[i];
880 if (TMath::Abs(c->GetLabel(1)) == lab ||
881 TMath::Abs(c->GetLabel(2)) == lab ) max++;
884 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
887 Int_t tail=Int_t(0.10*noc);
889 for (i=1; i<=tail; i++) {
890 AliCluster *c=clusters[noc-i];
891 if (lab == TMath::Abs(c->GetLabel(0)) ||
892 lab == TMath::Abs(c->GetLabel(1)) ||
893 lab == TMath::Abs(c->GetLabel(2))) max++;
895 if (max < Int_t(0.5*tail)) lab=-lab;
905 //_________________________________________________________________________
906 void AliTPCtracker::AliTPCSector::Setup(const AliTPCParam *par, Int_t f) {
907 //-----------------------------------------------------------------------
908 // Setup inner sector
909 //-----------------------------------------------------------------------
911 fAlpha=par->GetInnerAngle();
912 fAlphaShift=par->GetInnerAngleShift();
913 fPadPitchWidth=par->GetInnerPadPitchWidth();
914 fPadPitchLength=par->GetInnerPadPitchLength();
916 fN=par->GetNRowLow();
917 fRow=new AliTPCRow[fN];
918 for (Int_t i=0; i<fN; i++) fRow[i].SetX(par->GetPadRowRadiiLow(i));
920 fAlpha=par->GetOuterAngle();
921 fAlphaShift=par->GetOuterAngleShift();
922 fPadPitchWidth=par->GetOuterPadPitchWidth();
923 fPadPitchLength=par->GetOuterPadPitchLength();
926 fRow=new AliTPCRow[fN];
927 for (Int_t i=0; i<fN; i++) fRow[i].SetX(par->GetPadRowRadiiUp(i));
931 //_________________________________________________________________________
933 AliTPCtracker::AliTPCRow::InsertCluster(const AliTPCcluster* c, UInt_t index) {
934 //-----------------------------------------------------------------------
935 // Insert a cluster into this pad row in accordence with its y-coordinate
936 //-----------------------------------------------------------------------
937 if (fN==kMaxClusterPerRow) {
938 cerr<<"AliTPCRow::InsertCluster(): Too many clusters !\n"; return;
940 if (fN==0) {fIndex[0]=index; fClusters[fN++]=c; return;}
941 Int_t i=Find(c->GetY());
942 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTPCcluster*));
943 memmove(fIndex +i+1 ,fIndex +i,(fN-i)*sizeof(UInt_t));
944 fIndex[i]=index; fClusters[i]=c; fN++;
947 //___________________________________________________________________
948 Int_t AliTPCtracker::AliTPCRow::Find(Double_t y) const {
949 //-----------------------------------------------------------------------
950 // Return the index of the nearest cluster
951 //-----------------------------------------------------------------------
952 if (y <= fClusters[0]->GetY()) return 0;
953 if (y > fClusters[fN-1]->GetY()) return fN;
954 Int_t b=0, e=fN-1, m=(b+e)/2;
955 for (; b<e; m=(b+e)/2) {
956 if (y > fClusters[m]->GetY()) b=m+1;
962 //_____________________________________________________________________________
963 void AliTPCtracker::AliTPCseed::CookdEdx(Double_t low, Double_t up) {
964 //-----------------------------------------------------------------
965 // This funtion calculates dE/dX within the "low" and "up" cuts.
966 //-----------------------------------------------------------------
968 Int_t nc=GetNumberOfClusters();
970 Int_t swap;//stupid sorting
973 for (i=0; i<nc-1; i++) {
974 if (fdEdxSample[i]<=fdEdxSample[i+1]) continue;
975 Float_t tmp=fdEdxSample[i];
976 fdEdxSample[i]=fdEdxSample[i+1]; fdEdxSample[i+1]=tmp;
981 Int_t nl=Int_t(low*nc), nu=Int_t(up*nc);
983 for (i=nl; i<=nu; i++) dedx += fdEdxSample[i];