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.2 2000/06/30 12:07:50 kowal2
19 Updated from the TPC-PreRelease branch
21 Revision 1.1.2.1 2000/06/25 08:53:55 kowal2
22 Splitted from AliTPCtracking
26 //-------------------------------------------------------
27 // Implementation of the TPC tracker
29 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
30 //-------------------------------------------------------
32 #include <TObjArray.h>
37 #include "AliTPCtracker.h"
38 #include "AliTPCcluster.h"
39 #include "AliTPCClustersArray.h"
40 #include "AliTPCClustersRow.h"
42 const AliTPCParam *AliTPCtracker::AliTPCSector::fgParam;
44 //_____________________________________________________________________________
45 Double_t SigmaY2(Double_t r, Double_t tgl, Double_t pt)
48 // Parametrised error of the cluster reconstruction (pad direction)
51 const Float_t kArphi=0.41818e-2;
52 const Float_t kBrphi=0.17460e-4;
53 const Float_t kCrphi=0.30993e-2;
54 const Float_t kDrphi=0.41061e-3;
56 pt=TMath::Abs(pt)*1000.;
59 Double_t s=kArphi - kBrphi*r*tgl + kCrphi*x*x + kDrphi*x;
60 if (s<0.4e-3) s=0.4e-3;
61 s*=1.3; //Iouri Belikov
66 //_____________________________________________________________________________
67 Double_t SigmaZ2(Double_t r, Double_t tgl)
70 // Parametrised error of the cluster reconstruction (drift direction)
73 const Float_t kAz=0.39614e-2;
74 const Float_t kBz=0.22443e-4;
75 const Float_t kCz=0.51504e-1;
79 Double_t s=kAz - kBz*r*tgl + kCz*tgl*tgl;
80 if (s<0.4e-3) s=0.4e-3;
81 s*=1.3; //Iouri Belikov
86 //_____________________________________________________________________________
87 inline Double_t f1(Double_t x1,Double_t y1,
88 Double_t x2,Double_t y2,
89 Double_t x3,Double_t y3)
91 //-----------------------------------------------------------------
92 // Initial approximation of the track curvature
93 //-----------------------------------------------------------------
94 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
95 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
96 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
97 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
98 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
100 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
102 return -xr*yr/sqrt(xr*xr+yr*yr);
106 //_____________________________________________________________________________
107 inline Double_t f2(Double_t x1,Double_t y1,
108 Double_t x2,Double_t y2,
109 Double_t x3,Double_t y3)
111 //-----------------------------------------------------------------
112 // Initial approximation of the track curvature times center of curvature
113 //-----------------------------------------------------------------
114 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
115 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
116 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
117 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
118 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
120 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
122 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
125 //_____________________________________________________________________________
126 inline Double_t f3(Double_t x1,Double_t y1,
127 Double_t x2,Double_t y2,
128 Double_t z1,Double_t z2)
130 //-----------------------------------------------------------------
131 // Initial approximation of the tangent of the track dip angle
132 //-----------------------------------------------------------------
133 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
136 //_____________________________________________________________________________
137 Int_t AliTPCtracker::FindProlongation(AliTPCseed& t, const AliTPCSector *sec,
140 //-----------------------------------------------------------------
141 // This function tries to find a track prolongation.
142 //-----------------------------------------------------------------
143 const Int_t kSKIP=(t.GetNumberOfClusters()<10) ?
144 10 : Int_t(0.5*sec->GetNRows());
145 Int_t tryAgain=kSKIP;
146 Double_t alpha=sec->GetAlpha();
147 Int_t ns=Int_t(2*TMath::Pi()/alpha+0.5);
149 for (Int_t nr=sec->GetRowNumber(t.GetX())-1; nr>=rf; nr--) {
150 Double_t x=sec->GetX(nr), ymax=sec->GetMaxY(nr);
151 if (!t.PropagateTo(x)) return 0;
155 Double_t maxchi2=12.;
156 const AliTPCRow &krow=sec[s][nr];
157 Double_t sy2=SigmaY2(t.GetX(),t.GetTgl(),t.GetPt());
158 Double_t sz2=SigmaZ2(t.GetX(),t.GetTgl());
159 Double_t road=4.*sqrt(t.GetSigmaY2() + sy2), y=t.GetY(), z=t.GetZ();
162 if (t.GetNumberOfClusters()>4)
163 cerr<<t.GetNumberOfClusters()
164 <<"FindProlongation warning: Too broad road !\n";
169 for (Int_t i=krow.Find(y-road); i<krow; i++) {
170 AliTPCcluster *c=(AliTPCcluster*)(krow[i]);
171 if (c->GetY() > y+road) break;
172 if (c->IsUsed()) continue;
173 if ((c->GetZ()-z)*(c->GetZ()-z) > 16.*(t.GetSigmaZ2()+sz2)) continue;
174 Double_t chi2=t.GetPredictedChi2(c);
175 if (chi2 > maxchi2) continue;
178 index=krow.GetIndex(i);
182 Float_t l=sec->GetPadPitchWidth();
183 t.SetSampledEdx(cl->GetQ()/l,t.GetNumberOfClusters());
184 t.Update(cl,maxchi2,index);
187 if (tryAgain==0) break;
190 if (!t.Rotate(alpha)) return 0;
191 } else if (y <-ymax) {
193 if (!t.Rotate(-alpha)) return 0;
203 //_____________________________________________________________________________
205 AliTPCtracker::MakeSeeds(TObjArray& seeds,const AliTPCSector *sec, Int_t max,
208 //-----------------------------------------------------------------
209 // This function creates track seeds.
210 //-----------------------------------------------------------------
211 Double_t x[5], c[15];
213 Double_t alpha=sec->GetAlpha(), shift=sec->GetAlphaShift();
214 Double_t cs=cos(alpha), sn=sin(alpha);
216 Double_t x1 =sec->GetX(i1);
217 Double_t xx2=sec->GetX(i2);
219 for (Int_t ns=0; ns<max; ns++) {
220 Int_t nl=sec[(ns-1+max)%max][i2];
221 Int_t nm=sec[ns][i2];
222 Int_t nu=sec[(ns+1)%max][i2];
223 const AliTPCRow& kr1=sec[ns][i1];
224 for (Int_t is=0; is < kr1; is++) {
225 Double_t y1=kr1[is]->GetY(), z1=kr1[is]->GetZ();
226 for (Int_t js=0; js < nl+nm+nu; js++) {
227 const AliTPCcluster *kcl;
229 Double_t x3=0.,y3=0.;
232 const AliTPCRow& kr2=sec[(ns-1+max)%max][i2];
234 y2=kcl->GetY(); z2=kcl->GetZ();
239 const AliTPCRow& kr2=sec[ns][i2];
241 x2=xx2; y2=kcl->GetY(); z2=kcl->GetZ();
243 const AliTPCRow& kr2=sec[(ns+1)%max][i2];
245 y2=kcl->GetY(); z2=kcl->GetZ();
250 Double_t zz=z1 - z1/x1*(x1-x2);
251 if (TMath::Abs(zz-z2)>5.) continue;
253 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
254 if (d==0.) {cerr<<"MakeSeeds warning: Straight seed !\n"; continue;}
258 x[3]=f1(x1,y1,x2,y2,x3,y3);
259 if (TMath::Abs(x[3]) >= 0.0066) continue;
260 x[2]=f2(x1,y1,x2,y2,x3,y3);
261 //if (TMath::Abs(x[3]*x1-x[2]) >= 0.99999) continue;
262 x[4]=f3(x1,y1,x2,y2,z1,z2);
263 if (TMath::Abs(x[4]) > 1.2) continue;
264 Double_t a=asin(x[2]);
265 Double_t zv=z1 - x[4]/x[3]*(a+asin(x[3]*x1-x[2]));
266 if (TMath::Abs(zv)>10.) continue;
268 Double_t sy1=kr1[is]->GetSigmaY2(), sz1=kr1[is]->GetSigmaZ2();
269 Double_t sy2=kcl->GetSigmaY2(), sz2=kcl->GetSigmaZ2();
270 Double_t sy3=100*0.025, sy=0.1, sz=0.1;
272 Double_t f30=(f1(x1,y1+sy,x2,y2,x3,y3)-x[3])/sy;
273 Double_t f32=(f1(x1,y1,x2,y2+sy,x3,y3)-x[3])/sy;
274 Double_t f34=(f1(x1,y1,x2,y2,x3,y3+sy)-x[3])/sy;
275 Double_t f20=(f2(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
276 Double_t f22=(f2(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
277 Double_t f24=(f2(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
278 Double_t f40=(f3(x1,y1+sy,x2,y2,z1,z2)-x[4])/sy;
279 Double_t f41=(f3(x1,y1,x2,y2,z1+sz,z2)-x[4])/sz;
280 Double_t f42=(f3(x1,y1,x2,y2+sy,z1,z2)-x[4])/sy;
281 Double_t f43=(f3(x1,y1,x2,y2,z1,z2+sz)-x[4])/sz;
285 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f24*sy3*f24;
286 c[6]=f30*sy1; c[7]=0.; c[8]=f30*sy1*f20+f32*sy2*f22+f34*sy3*f24;
287 c[9]=f30*sy1*f30+f32*sy2*f32+f34*sy3*f34;
288 c[10]=f40*sy1; c[11]=f41*sz1; c[12]=f40*sy1*f20+f42*sy2*f22;
289 c[13]=f40*sy1*f30+f42*sy2*f32;
290 c[14]=f40*sy1*f40+f41*sz1*f41+f42*sy2*f42+f43*sz2*f43;
292 UInt_t index=kr1.GetIndex(is);
293 AliTPCseed *track=new AliTPCseed(index, x, c, x1, ns*alpha+shift);
294 Float_t l=sec->GetPadPitchWidth();
295 track->SetSampledEdx(kr1[is]->GetQ()/l,0);
297 Int_t rc=FindProlongation(*track,sec,ns,i2);
298 if (rc<0 || track->GetNumberOfClusters()<(i1-i2)/2) delete track;
299 else seeds.AddLast(track);
305 //_____________________________________________________________________________
306 Int_t AliTPCtracker::Clusters2Tracks(const AliTPCParam *par, TFile *of) {
307 //-----------------------------------------------------------------
308 // This is a track finder.
309 //-----------------------------------------------------------------
310 TDirectory *savedir=gDirectory;
313 cerr<<"AliTPCtracker::Clusters2Tracks(): output file not open !\n";
317 AliTPCClustersArray carray;
319 carray.SetClusterType("AliTPCcluster");
320 carray.ConnectTree("Segment Tree");
323 TTree tracktree("TreeT","Tree with TPC tracks");
324 AliTPCtrack *iotrack=0;
325 tracktree.Branch("tracks","AliTPCtrack",&iotrack,32000,0);
327 AliTPCSector::SetParam(par);
329 const Int_t kNIS=par->GetNInnerSector()/2;
330 AliTPCSSector *ssec=new AliTPCSSector[kNIS];
331 Int_t nlow=ssec->GetNRows();
333 const Int_t kNOS=par->GetNOuterSector()/2;
334 AliTPCLSector *lsec=new AliTPCLSector[kNOS];
335 Int_t nup=lsec->GetNRows();
341 j=Int_t(carray.GetTree()->GetEntries());
342 for (i=0; i<j; i++) {
343 AliSegmentID *s=carray.LoadEntry(i);
345 par->AdjustSectorRow(s->GetID(),sec,row);
346 if (sec<kNIS*2) continue;
347 AliTPCClustersRow *clrow=carray.GetRow(sec,row);
348 Int_t ncl=clrow->GetArray()->GetEntriesFast();
350 AliTPCcluster *c=(AliTPCcluster*)(*clrow)[ncl];
351 index=(((sec<<8)+row)<<16)+ncl;
352 lsec[(sec-kNIS*2)%kNOS][row].InsertCluster(c,index);
357 TObjArray seeds(20000);
358 Int_t nrows=nlow+nup;
359 Int_t gap=Int_t(0.125*nrows), shift=Int_t(0.5*gap);
360 MakeSeeds(seeds, lsec, kNOS, nup-1, nup-1-gap);
361 MakeSeeds(seeds, lsec, kNOS, nup-1-shift, nup-1-shift-gap);
364 //tracking in outer sectors
365 Int_t nseed=seeds.GetEntriesFast();
366 for (i=0; i<nseed; i++) {
367 AliTPCseed *pt=(AliTPCseed*)seeds.UncheckedAt(i), &t=*pt;
368 Double_t alpha=t.GetAlpha();
369 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
370 if (alpha < 0. ) alpha += 2.*TMath::Pi();
371 Int_t ns=Int_t(alpha/lsec->GetAlpha())%kNOS;
373 if (FindProlongation(t,lsec,ns)) {
374 t.UseClusters(&carray);
377 delete seeds.RemoveAt(i);
380 //unload outer sectors
381 for (i=0; i<kNOS; i++) {
382 for (j=0; j<nup; j++) {
383 if (carray.GetRow(i+kNIS*2,j)) carray.ClearRow(i+kNIS*2,j);
384 if (carray.GetRow(i+kNIS*2+kNOS,j)) carray.ClearRow(i+kNIS*2+kNOS,j);
389 j=Int_t(carray.GetTree()->GetEntries());
390 for (i=0; i<j; i++) {
391 AliSegmentID *s=carray.LoadEntry(i);
393 par->AdjustSectorRow(s->GetID(),sec,row);
394 if (sec>=kNIS*2) continue;
395 AliTPCClustersRow *clrow=carray.GetRow(sec,row);
396 Int_t ncl=clrow->GetArray()->GetEntriesFast();
398 AliTPCcluster *c=(AliTPCcluster*)(*clrow)[ncl];
399 index=(((sec<<8)+row)<<16)+ncl;
400 ssec[sec%kNIS][row].InsertCluster(c,index);
404 //tracking in inner sectors
406 for (i=0; i<nseed; i++) {
407 AliTPCseed *pt=(AliTPCseed*)seeds.UncheckedAt(i), &t=*pt;
409 Int_t nc=t.GetNumberOfClusters();
411 Double_t alpha=t.GetAlpha() - ssec->GetAlphaShift();
412 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
413 if (alpha < 0. ) alpha += 2.*TMath::Pi();
414 Int_t ns=Int_t(alpha/ssec->GetAlpha())%kNIS;
416 alpha=ns*ssec->GetAlpha() + ssec->GetAlphaShift() - t.GetAlpha();
418 if (t.Rotate(alpha)) {
419 if (FindProlongation(t,ssec,ns)) {
420 if (t.GetNumberOfClusters() >= Int_t(0.4*nrows)) {
422 //t.CookLabel(&carray);
425 t.UseClusters(&carray,nc);
430 delete seeds.RemoveAt(i);
434 //unload inner sectors
435 for (i=0; i<kNIS; i++) {
436 for (j=0; j<nlow; j++) {
437 if (carray.GetRow(i,j)) carray.ClearRow(i,j);
438 if (carray.GetRow(i+kNIS,j)) carray.ClearRow(i+kNIS,j);
442 cerr<<"Number of found tracks : "<<found<<endl;
452 //_________________________________________________________________________
454 AliTPCtracker::AliTPCRow::InsertCluster(const AliTPCcluster* c, UInt_t index) {
455 //-----------------------------------------------------------------------
456 // Insert a cluster into this pad row in accordence with its y-coordinate
457 //-----------------------------------------------------------------------
458 if (fN==kMAXCLUSTER) {
459 cerr<<"AliTPCRow::InsertCluster(): Too many clusters !\n"; return;
461 if (fN==0) {fIndex[0]=index; fClusters[fN++]=c; return;}
462 Int_t i=Find(c->GetY());
463 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTPCcluster*));
464 memmove(fIndex +i+1 ,fIndex +i,(fN-i)*sizeof(UInt_t));
465 fIndex[i]=index; fClusters[i]=c; fN++;
468 //___________________________________________________________________
469 Int_t AliTPCtracker::AliTPCRow::Find(Double_t y) const {
470 //-----------------------------------------------------------------------
471 // Return the index of the nearest cluster
472 //-----------------------------------------------------------------------
473 if (y <= fClusters[0]->GetY()) return 0;
474 if (y > fClusters[fN-1]->GetY()) return fN;
475 Int_t b=0, e=fN-1, m=(b+e)/2;
476 for (; b<e; m=(b+e)/2) {
477 if (y > fClusters[m]->GetY()) b=m+1;
483 //_____________________________________________________________________________
484 void AliTPCtracker::AliTPCseed::CookdEdx(Double_t low, Double_t up) {
485 //-----------------------------------------------------------------
486 // This funtion calculates dE/dX within the "low" and "up" cuts.
487 //-----------------------------------------------------------------
490 Int_t swap;//stupid sorting
493 for (i=0; i<fN-1; i++) {
494 if (fdEdx[i]<=fdEdx[i+1]) continue;
495 Float_t tmp=fdEdx[i]; fdEdx[i]=fdEdx[i+1]; fdEdx[i+1]=tmp;
500 Int_t nl=Int_t(low*fN), nu=Int_t(up*fN);
502 for (i=nl; i<=nu; i++) dedx += fdEdx[i];
507 //_____________________________________________________________________________
508 void AliTPCtracker::AliTPCseed::UseClusters(AliTPCClustersArray *ca, Int_t n) {
509 //-----------------------------------------------------------------
510 // This function marks clusters associated with this track.
511 //-----------------------------------------------------------------
513 for (Int_t i=n; i<fN; i++) {
514 GetCluster(i,sec,row,ncl);
515 AliTPCClustersRow *clrow=ca->GetRow(sec,row);
516 AliTPCcluster *c=(AliTPCcluster*)(*clrow)[ncl];