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.5 2000/12/20 07:51:59 kowal2
19 Changes suggested by Alessandra and Paolo to avoid overlapped
20 data fields in encapsulated classes.
22 Revision 1.4 2000/11/02 07:27:16 kowal2
25 Revision 1.2 2000/06/30 12:07:50 kowal2
26 Updated from the TPC-PreRelease branch
28 Revision 1.1.2.1 2000/06/25 08:53:55 kowal2
29 Splitted from AliTPCtracking
33 //-------------------------------------------------------
34 // Implementation of the TPC tracker
36 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
37 //-------------------------------------------------------
39 #include <TObjArray.h>
44 #include "AliTPCtracker.h"
45 #include "AliTPCcluster.h"
46 #include "AliTPCClustersArray.h"
47 #include "AliTPCClustersRow.h"
49 const AliTPCParam *AliTPCtracker::AliTPCSector::fgParam;
51 //_____________________________________________________________________________
52 Double_t SigmaY2(Double_t r, Double_t tgl, Double_t pt)
55 // Parametrised error of the cluster reconstruction (pad direction)
58 const Float_t kArphi=0.41818e-2;
59 const Float_t kBrphi=0.17460e-4;
60 const Float_t kCrphi=0.30993e-2;
61 const Float_t kDrphi=0.41061e-3;
63 pt=TMath::Abs(pt)*1000.;
66 Double_t s=kArphi - kBrphi*r*tgl + kCrphi*x*x + kDrphi*x;
67 if (s<0.4e-3) s=0.4e-3;
68 s*=1.3; //Iouri Belikov
73 //_____________________________________________________________________________
74 Double_t SigmaZ2(Double_t r, Double_t tgl)
77 // Parametrised error of the cluster reconstruction (drift direction)
80 const Float_t kAz=0.39614e-2;
81 const Float_t kBz=0.22443e-4;
82 const Float_t kCz=0.51504e-1;
86 Double_t s=kAz - kBz*r*tgl + kCz*tgl*tgl;
87 if (s<0.4e-3) s=0.4e-3;
88 s*=1.3; //Iouri Belikov
93 //_____________________________________________________________________________
94 inline Double_t f1(Double_t x1,Double_t y1,
95 Double_t x2,Double_t y2,
96 Double_t x3,Double_t y3)
98 //-----------------------------------------------------------------
99 // Initial approximation of the track curvature
100 //-----------------------------------------------------------------
101 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
102 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
103 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
104 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
105 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
107 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
109 return -xr*yr/sqrt(xr*xr+yr*yr);
113 //_____________________________________________________________________________
114 inline Double_t f2(Double_t x1,Double_t y1,
115 Double_t x2,Double_t y2,
116 Double_t x3,Double_t y3)
118 //-----------------------------------------------------------------
119 // Initial approximation of the track curvature times center of curvature
120 //-----------------------------------------------------------------
121 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
122 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
123 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
124 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
125 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
127 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
129 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
132 //_____________________________________________________________________________
133 inline Double_t f3(Double_t x1,Double_t y1,
134 Double_t x2,Double_t y2,
135 Double_t z1,Double_t z2)
137 //-----------------------------------------------------------------
138 // Initial approximation of the tangent of the track dip angle
139 //-----------------------------------------------------------------
140 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
143 //_____________________________________________________________________________
144 Int_t AliTPCtracker::FindProlongation(AliTPCseed& t, const AliTPCSector *sec,
147 //-----------------------------------------------------------------
148 // This function tries to find a track prolongation.
149 //-----------------------------------------------------------------
150 const Int_t kSKIP=(t.GetNumberOfClusters()<10) ? 10 :
151 Int_t(0.5*sec->GetNRows());
152 Int_t tryAgain=kSKIP;
153 Double_t alpha=sec->GetAlpha();
154 Int_t ns=Int_t(2*TMath::Pi()/alpha+0.5);
156 for (Int_t nr=sec->GetRowNumber(t.GetX())-1; nr>=rf; nr--) {
157 Double_t x=sec->GetX(nr), ymax=sec->GetMaxY(nr);
158 if (!t.PropagateTo(x)) return 0;
162 Double_t maxchi2=12.;
163 const AliTPCRow &krow=sec[s][nr];
164 Double_t sy2=SigmaY2(t.GetX(),t.GetTgl(),1./t.Get1Pt());
165 Double_t sz2=SigmaZ2(t.GetX(),t.GetTgl());
166 Double_t road=4.*sqrt(t.GetSigmaY2() + sy2), y=t.GetY(), z=t.GetZ();
169 if (t.GetNumberOfClusters()>4)
170 cerr<<t.GetNumberOfClusters()
171 <<"FindProlongation warning: Too broad road !\n";
176 for (Int_t i=krow.Find(y-road); i<krow; i++) {
177 AliTPCcluster *c=(AliTPCcluster*)(krow[i]);
178 if (c->GetY() > y+road) break;
179 if (c->IsUsed()) continue;
180 if ((c->GetZ()-z)*(c->GetZ()-z) > 16.*(t.GetSigmaZ2()+sz2)) continue;
181 Double_t chi2=t.GetPredictedChi2(c);
182 if (chi2 > maxchi2) continue;
185 index=krow.GetIndex(i);
189 Float_t l=sec->GetPadPitchWidth();
190 t.SetSampledEdx(cl->GetQ()/l,t.GetNumberOfClusters());
191 if (!t.Update(cl,maxchi2,index)) {
192 if (!tryAgain--) return 0;
193 } else tryAgain=kSKIP;
195 if (tryAgain==0) break;
198 if (!t.Rotate(alpha)) return 0;
199 } else if (y <-ymax) {
201 if (!t.Rotate(-alpha)) return 0;
211 //_____________________________________________________________________________
213 AliTPCtracker::MakeSeeds(TObjArray& seeds,const AliTPCSector *sec, Int_t max,
216 //-----------------------------------------------------------------
217 // This function creates track seeds.
218 //-----------------------------------------------------------------
219 Double_t x[5], c[15];
221 Double_t alpha=sec->GetAlpha(), shift=sec->GetAlphaShift();
222 Double_t cs=cos(alpha), sn=sin(alpha);
224 Double_t x1 =sec->GetX(i1);
225 Double_t xx2=sec->GetX(i2);
227 for (Int_t ns=0; ns<max; ns++) {
228 Int_t nl=sec[(ns-1+max)%max][i2];
229 Int_t nm=sec[ns][i2];
230 Int_t nu=sec[(ns+1)%max][i2];
231 const AliTPCRow& kr1=sec[ns][i1];
232 for (Int_t is=0; is < kr1; is++) {
233 Double_t y1=kr1[is]->GetY(), z1=kr1[is]->GetZ();
234 for (Int_t js=0; js < nl+nm+nu; js++) {
235 const AliTPCcluster *kcl;
237 Double_t x3=0.,y3=0.;
240 const AliTPCRow& kr2=sec[(ns-1+max)%max][i2];
242 y2=kcl->GetY(); z2=kcl->GetZ();
247 const AliTPCRow& kr2=sec[ns][i2];
249 x2=xx2; y2=kcl->GetY(); z2=kcl->GetZ();
251 const AliTPCRow& kr2=sec[(ns+1)%max][i2];
253 y2=kcl->GetY(); z2=kcl->GetZ();
258 Double_t zz=z1 - z1/x1*(x1-x2);
259 if (TMath::Abs(zz-z2)>5.) continue;
261 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
262 if (d==0.) {cerr<<"MakeSeeds warning: Straight seed !\n"; continue;}
266 x[3]=f1(x1,y1,x2,y2,x3,y3);
267 if (TMath::Abs(x[3]) >= 0.0066) continue;
268 x[2]=f2(x1,y1,x2,y2,x3,y3);
269 //if (TMath::Abs(x[3]*x1-x[2]) >= 0.99999) continue;
270 x[4]=f3(x1,y1,x2,y2,z1,z2);
271 if (TMath::Abs(x[4]) > 1.2) continue;
272 Double_t a=asin(x[2]);
273 Double_t zv=z1 - x[4]/x[3]*(a+asin(x[3]*x1-x[2]));
274 if (TMath::Abs(zv)>10.) continue;
276 Double_t sy1=kr1[is]->GetSigmaY2(), sz1=kr1[is]->GetSigmaZ2();
277 Double_t sy2=kcl->GetSigmaY2(), sz2=kcl->GetSigmaZ2();
278 Double_t sy3=100*0.025, sy=0.1, sz=0.1;
280 Double_t f30=(f1(x1,y1+sy,x2,y2,x3,y3)-x[3])/sy;
281 Double_t f32=(f1(x1,y1,x2,y2+sy,x3,y3)-x[3])/sy;
282 Double_t f34=(f1(x1,y1,x2,y2,x3,y3+sy)-x[3])/sy;
283 Double_t f20=(f2(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
284 Double_t f22=(f2(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
285 Double_t f24=(f2(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
286 Double_t f40=(f3(x1,y1+sy,x2,y2,z1,z2)-x[4])/sy;
287 Double_t f41=(f3(x1,y1,x2,y2,z1+sz,z2)-x[4])/sz;
288 Double_t f42=(f3(x1,y1,x2,y2+sy,z1,z2)-x[4])/sy;
289 Double_t f43=(f3(x1,y1,x2,y2,z1,z2+sz)-x[4])/sz;
293 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f24*sy3*f24;
294 c[6]=f30*sy1; c[7]=0.; c[8]=f30*sy1*f20+f32*sy2*f22+f34*sy3*f24;
295 c[9]=f30*sy1*f30+f32*sy2*f32+f34*sy3*f34;
296 c[10]=f40*sy1; c[11]=f41*sz1; c[12]=f40*sy1*f20+f42*sy2*f22;
297 c[13]=f40*sy1*f30+f42*sy2*f32;
298 c[14]=f40*sy1*f40+f41*sz1*f41+f42*sy2*f42+f43*sz2*f43;
300 UInt_t index=kr1.GetIndex(is);
301 AliTPCseed *track=new AliTPCseed(index, x, c, x1, ns*alpha+shift);
302 Float_t l=sec->GetPadPitchWidth();
303 track->SetSampledEdx(kr1[is]->GetQ()/l,0);
305 Int_t rc=FindProlongation(*track,sec,ns,i2);
306 if (rc==0 || track->GetNumberOfClusters()<(i1-i2)/2) delete track;
307 else seeds.AddLast(track);
313 //_____________________________________________________________________________
314 Int_t AliTPCtracker::Clusters2Tracks(const AliTPCParam *par, TFile *of) {
315 //-----------------------------------------------------------------
316 // This is a track finder.
317 //-----------------------------------------------------------------
318 TDirectory *savedir=gDirectory;
321 cerr<<"AliTPCtracker::Clusters2Tracks(): output file not open !\n";
325 AliTPCClustersArray carray;
327 carray.SetClusterType("AliTPCcluster");
328 carray.ConnectTree("Segment Tree");
331 TTree tracktree("TreeT","Tree with TPC tracks");
332 AliTPCtrack *iotrack=0;
333 tracktree.Branch("tracks","AliTPCtrack",&iotrack,32000,0);
335 AliTPCSector::SetParam(par);
337 const Int_t kNIS=par->GetNInnerSector()/2;
338 AliTPCSSector *ssec=new AliTPCSSector[kNIS];
339 Int_t nlow=ssec->GetNRows();
341 const Int_t kNOS=par->GetNOuterSector()/2;
342 AliTPCLSector *lsec=new AliTPCLSector[kNOS];
343 Int_t nup=lsec->GetNRows();
349 j=Int_t(carray.GetTree()->GetEntries());
350 for (i=0; i<j; i++) {
351 AliSegmentID *s=carray.LoadEntry(i);
353 par->AdjustSectorRow(s->GetID(),sec,row);
354 if (sec<kNIS*2) continue;
355 AliTPCClustersRow *clrow=carray.GetRow(sec,row);
356 Int_t ncl=clrow->GetArray()->GetEntriesFast();
358 AliTPCcluster *c=(AliTPCcluster*)(*clrow)[ncl];
359 index=(((sec<<8)+row)<<16)+ncl;
360 lsec[(sec-kNIS*2)%kNOS][row].InsertCluster(c,index);
365 TObjArray seeds(20000);
366 Int_t nrows=nlow+nup;
367 Int_t gap=Int_t(0.125*nrows), shift=Int_t(0.5*gap);
368 MakeSeeds(seeds, lsec, kNOS, nup-1, nup-1-gap);
369 MakeSeeds(seeds, lsec, kNOS, nup-1-shift, nup-1-shift-gap);
372 //tracking in outer sectors
373 Int_t nseed=seeds.GetEntriesFast();
374 for (i=0; i<nseed; i++) {
375 AliTPCseed *pt=(AliTPCseed*)seeds.UncheckedAt(i), &t=*pt;
376 Double_t alpha=t.GetAlpha();
377 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
378 if (alpha < 0. ) alpha += 2.*TMath::Pi();
379 Int_t ns=Int_t(alpha/lsec->GetAlpha())%kNOS;
381 if (FindProlongation(t,lsec,ns)) {
382 t.UseClusters(&carray);
385 delete seeds.RemoveAt(i);
388 //unload outer sectors
389 for (i=0; i<kNOS; i++) {
390 for (j=0; j<nup; j++) {
391 if (carray.GetRow(i+kNIS*2,j)) carray.ClearRow(i+kNIS*2,j);
392 if (carray.GetRow(i+kNIS*2+kNOS,j)) carray.ClearRow(i+kNIS*2+kNOS,j);
397 j=Int_t(carray.GetTree()->GetEntries());
398 for (i=0; i<j; i++) {
399 AliSegmentID *s=carray.LoadEntry(i);
401 par->AdjustSectorRow(s->GetID(),sec,row);
402 if (sec>=kNIS*2) continue;
403 AliTPCClustersRow *clrow=carray.GetRow(sec,row);
404 Int_t ncl=clrow->GetArray()->GetEntriesFast();
406 AliTPCcluster *c=(AliTPCcluster*)(*clrow)[ncl];
407 index=(((sec<<8)+row)<<16)+ncl;
408 ssec[sec%kNIS][row].InsertCluster(c,index);
412 //tracking in inner sectors
414 for (i=0; i<nseed; i++) {
415 AliTPCseed *pt=(AliTPCseed*)seeds.UncheckedAt(i), &t=*pt;
417 Int_t nc=t.GetNumberOfClusters();
419 Double_t alpha=t.GetAlpha() - ssec->GetAlphaShift();
420 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
421 if (alpha < 0. ) alpha += 2.*TMath::Pi();
422 Int_t ns=Int_t(alpha/ssec->GetAlpha())%kNIS;
424 alpha=ns*ssec->GetAlpha() + ssec->GetAlphaShift() - t.GetAlpha();
426 if (t.Rotate(alpha)) {
427 if (FindProlongation(t,ssec,ns)) {
428 if (t.GetNumberOfClusters() >= Int_t(0.4*nrows)) {
430 //t.CookLabel(&carray);
433 t.UseClusters(&carray,nc);
438 delete seeds.RemoveAt(i);
442 //unload inner sectors
443 for (i=0; i<kNIS; i++) {
444 for (j=0; j<nlow; j++) {
445 if (carray.GetRow(i,j)) carray.ClearRow(i,j);
446 if (carray.GetRow(i+kNIS,j)) carray.ClearRow(i+kNIS,j);
450 cerr<<"Number of found tracks : "<<found<<endl;
460 //_________________________________________________________________________
462 AliTPCtracker::AliTPCRow::InsertCluster(const AliTPCcluster* c, UInt_t index) {
463 //-----------------------------------------------------------------------
464 // Insert a cluster into this pad row in accordence with its y-coordinate
465 //-----------------------------------------------------------------------
466 if (fN==kMAXCLUSTER) {
467 cerr<<"AliTPCRow::InsertCluster(): Too many clusters !\n"; return;
469 if (fN==0) {fIndex[0]=index; fClusters[fN++]=c; return;}
470 Int_t i=Find(c->GetY());
471 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTPCcluster*));
472 memmove(fIndex +i+1 ,fIndex +i,(fN-i)*sizeof(UInt_t));
473 fIndex[i]=index; fClusters[i]=c; fN++;
476 //___________________________________________________________________
477 Int_t AliTPCtracker::AliTPCRow::Find(Double_t y) const {
478 //-----------------------------------------------------------------------
479 // Return the index of the nearest cluster
480 //-----------------------------------------------------------------------
481 if (y <= fClusters[0]->GetY()) return 0;
482 if (y > fClusters[fN-1]->GetY()) return fN;
483 Int_t b=0, e=fN-1, m=(b+e)/2;
484 for (; b<e; m=(b+e)/2) {
485 if (y > fClusters[m]->GetY()) b=m+1;
491 //_____________________________________________________________________________
492 void AliTPCtracker::AliTPCseed::CookdEdx(Double_t low, Double_t up) {
493 //-----------------------------------------------------------------
494 // This funtion calculates dE/dX within the "low" and "up" cuts.
495 //-----------------------------------------------------------------
497 Int_t nc=GetNumberOfClusters();
499 Int_t swap;//stupid sorting
502 for (i=0; i<nc-1; i++) {
503 if (fdEdxSample[i]<=fdEdxSample[i+1]) continue;
504 Float_t tmp=fdEdxSample[i];
505 fdEdxSample[i]=fdEdxSample[i+1]; fdEdxSample[i+1]=tmp;
510 Int_t nl=Int_t(low*nc), nu=Int_t(up*nc);
512 for (i=nl; i<=nu; i++) dedx += fdEdxSample[i];
517 //_____________________________________________________________________________
518 void AliTPCtracker::AliTPCseed::UseClusters(AliTPCClustersArray *ca, Int_t n) {
519 //-----------------------------------------------------------------
520 // This function marks clusters associated with this track.
521 //-----------------------------------------------------------------
522 Int_t nc=GetNumberOfClusters();
525 for (Int_t i=n; i<nc; i++) {
526 GetCluster(i,sec,row,ncl);
527 AliTPCClustersRow *clrow=ca->GetRow(sec,row);
528 AliTPCcluster *c=(AliTPCcluster*)(*clrow)[ncl];