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 **************************************************************************/
22 AliTPC parallel tracker -
24 run AliTPCFindClusters.C macro - clusters neccessary for tracker are founded
25 run AliTPCFindTracksMI.C macro - to find tracks
26 tracks are written to AliTPCtracks.root file
27 for comparison also seeds are written to the same file - to special branch
30 //-------------------------------------------------------
31 // Implementation of the TPC tracker
33 // Origin: Marian Ivanov Marian.Ivanov@cern.ch
35 //-------------------------------------------------------
37 #include <TObjArray.h>
42 #include "AliTPCtrackerMI.h"
43 #include "AliTPCclusterMI.h"
44 #include "AliTPCParam.h"
45 #include "AliTPCClustersRow.h"
46 #include "AliComplexCluster.h"
47 #include "TStopwatch.h"
52 AliTPCclusterTracks::AliTPCclusterTracks(){
53 // class for storing overlaping info
66 Int_t AliTPCtrackerMI::UpdateTrack(AliTPCseed * track, AliTPCclusterMI* c, Double_t chi2, UInt_t i){
68 Int_t sec=(i&0xff000000)>>24;
69 Int_t row = (i&0x00ff0000)>>16;
70 track->fRow=(i&0x00ff0000)>>16;
72 // Int_t index = i&0xFFFF;
73 if (sec>=fParam->GetNInnerSector()) track->fRow += fParam->GetNRowLow();
74 track->fClusterIndex[track->fRow] = i;
75 track->fFirstPoint = row;
78 AliTPCTrackPoint *trpoint =track->GetTrackPoint(track->fRow);
79 Float_t angle2 = track->GetSnp()*track->GetSnp();
80 angle2 = TMath::Sqrt(angle2/(1-angle2));
85 //if we have a cluster
86 trpoint->GetCPoint().SetY(c->GetY());
87 trpoint->GetCPoint().SetZ(c->GetZ());
89 trpoint->GetCPoint().SetSigmaY(c->GetSigmaY2()/(track->fCurrentSigmaY*track->fCurrentSigmaY));
90 trpoint->GetCPoint().SetSigmaZ(c->GetSigmaZ2()/(track->fCurrentSigmaZ*track->fCurrentSigmaZ));
92 trpoint->GetCPoint().SetType(c->GetType());
93 trpoint->GetCPoint().SetQ(c->GetQ());
94 trpoint->GetCPoint().SetMax(c->GetMax());
96 trpoint->GetCPoint().SetErrY(TMath::Sqrt(track->fErrorY2));
97 trpoint->GetCPoint().SetErrZ(TMath::Sqrt(track->fErrorZ2));
100 trpoint->GetTPoint().SetX(track->GetX());
101 trpoint->GetTPoint().SetY(track->GetY());
102 trpoint->GetTPoint().SetZ(track->GetZ());
104 trpoint->GetTPoint().SetAngleY(angle2);
105 trpoint->GetTPoint().SetAngleZ(track->GetTgl());
110 // printf("suspicious chi2 %f\n",chi2);
112 // if (track->fIsSeeding){
113 track->fErrorY2 *= 1.2;
114 track->fErrorY2 += 0.0064;
115 track->fErrorZ2 *= 1.2;
116 track->fErrorY2 += 0.005;
120 return track->Update(c,chi2,i);
123 //_____________________________________________________________________________
124 AliTPCtrackerMI::AliTPCtrackerMI(const AliTPCParam *par, Int_t eventn):
125 AliTracker(), fkNIS(par->GetNInnerSector()/2), fkNOS(par->GetNOuterSector()/2)
127 //---------------------------------------------------------------------
128 // The main TPC tracker constructor
129 //---------------------------------------------------------------------
130 fInnerSec=new AliTPCSector[fkNIS];
131 fOuterSec=new AliTPCSector[fkNOS];
134 for (i=0; i<fkNIS; i++) fInnerSec[i].Setup(par,0);
135 for (i=0; i<fkNOS; i++) fOuterSec[i].Setup(par,1);
139 fClustersArray.Setup(par);
140 fClustersArray.SetClusterType("AliTPCclusterMI");
144 sprintf(cname,"TreeC_TPC");
147 sprintf(cname,"TreeC_TPC_%d",eventn);
150 fClustersArray.ConnectTree(cname);
158 //_____________________________________________________________________________
159 AliTPCtrackerMI::~AliTPCtrackerMI() {
160 //------------------------------------------------------------------
161 // TPC tracker destructor
162 //------------------------------------------------------------------
172 Double_t AliTPCtrackerMI::ErrY2(AliTPCseed* seed, AliTPCclusterMI * cl){
176 Float_t z = fParam->GetZLength()-TMath::Abs(seed->GetZ());
182 //standard if we don't have cluster - take MIP
183 const Float_t chmip = 50.;
184 Float_t amp = chmip/0.3;
189 rsigmay = cl->GetSigmaY2()/(seed->fCurrentSigmaY*seed->fCurrentSigmaY);
190 ctype = cl->GetType();
194 Float_t landau=2 ; //landau fluctuation part
195 Float_t gg=2; // gg fluctuation part
196 Float_t padlength= fSectors->GetPadPitchLength(seed->GetX());
199 if (fSectors==fInnerSec){
203 gg = (2+0.0002*amp)/nel;
204 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
205 if (landau>1) landau=1;
211 gg = (2+0.0002*amp)/nel;
212 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
213 if (landau>1) landau=1;
217 Float_t sdiff = gg*fParam->GetDiffT()*fParam->GetDiffT()*z;
218 Float_t angle2 = seed->GetSnp()*seed->GetSnp();
219 angle2 = angle2/(1-angle2);
220 Float_t angular = landau*angle2*padlength*padlength/12.;
221 Float_t res = sdiff + angular;
224 if ((ctype==0) && (fSectors ==fOuterSec))
225 res *= 0.78 +TMath::Exp(7.4*(rsigmay-1.2));
227 if ((ctype==0) && (fSectors ==fInnerSec))
228 res *= 0.72 +TMath::Exp(3.36*(rsigmay-1.2));
232 res*= TMath::Power((rsigmay+0.5),1.5)+0.0064;
235 res*=2.4; // overestimate error 2 times
242 seed->SetErrorY2(res);
249 Double_t AliTPCtrackerMI::ErrZ2(AliTPCseed* seed, AliTPCclusterMI * cl){
253 Float_t z = fParam->GetZLength()-TMath::Abs(seed->GetZ());
258 const Float_t chmip = 50.;
259 Float_t amp = chmip/0.3;
264 rsigmaz = cl->GetSigmaZ2()/(seed->fCurrentSigmaZ*seed->fCurrentSigmaZ);
265 ctype = cl->GetType();
269 Float_t landau=2 ; //landau fluctuation part
270 Float_t gg=2; // gg fluctuation part
271 Float_t padlength= fSectors->GetPadPitchLength(seed->GetX());
273 if (fSectors==fInnerSec){
277 gg = (2+0.0002*amp)/nel;
278 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
279 if (landau>1) landau=1;
285 gg = (2+0.0002*amp)/nel;
286 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
287 if (landau>1) landau=1;
289 Float_t sdiff = gg*fParam->GetDiffT()*fParam->GetDiffT()*z;
291 Float_t angle = seed->GetTgl();
292 Float_t angular = landau*angle*angle*padlength*padlength/12.;
293 Float_t res = sdiff + angular;
295 if ((ctype==0) && (fSectors ==fOuterSec))
296 res *= 0.81 +TMath::Exp(6.8*(rsigmaz-1.2));
298 if ((ctype==0) && (fSectors ==fInnerSec))
299 res *= 0.72 +TMath::Exp(2.04*(rsigmaz-1.2));
301 res*= TMath::Power(rsigmaz+0.5,1.5)+0.0064; //0.31+0.147*ctype;
304 if ((ctype<0) &&<70)
311 seed->SetErrorZ2(res);
317 Int_t AliTPCseed::GetProlongation(Double_t xk, Double_t &y, Double_t & z) const
319 //-----------------------------------------------------------------
320 // This function find proloncation of a track to a reference plane x=xk.
321 // doesn't change internal state of the track
322 //-----------------------------------------------------------------
324 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1;
325 // Double_t y1=fP0, z1=fP1;
326 Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
327 Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
331 y += dx*(c1+c2)/(r1+r2);
332 z += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
337 //_____________________________________________________________________________
338 Double_t AliTPCseed::GetPredictedChi2(const AliTPCclusterMI *c) const
340 //-----------------------------------------------------------------
341 // This function calculates a predicted chi2 increment.
342 //-----------------------------------------------------------------
343 //Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
344 Double_t r00=fErrorY2, r01=0., r11=fErrorZ2;
345 r00+=fC00; r01+=fC10; r11+=fC11;
347 Double_t det=r00*r11 - r01*r01;
348 if (TMath::Abs(det) < 1.e-10) {
349 Int_t n=GetNumberOfClusters();
350 if (n>4) cerr<<n<<" AliKalmanTrack warning: Singular matrix !\n";
353 Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
355 Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
357 return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
361 //_________________________________________________________________________________________
364 Int_t AliTPCseed::Compare(const TObject *o) const {
365 //-----------------------------------------------------------------
366 // This function compares tracks according to the sector - for given sector according z
367 //-----------------------------------------------------------------
368 AliTPCseed *t=(AliTPCseed*)o;
369 if (t->fSector>fSector) return -1;
370 if (t->fSector<fSector) return 1;
372 Double_t z2 = t->GetZ();
373 Double_t z1 = GetZ();
375 if (z2<z1) return -1;
384 //_____________________________________________________________________________
385 Int_t AliTPCseed::Update(const AliTPCclusterMI *c, Double_t chisq, UInt_t index) {
386 //-----------------------------------------------------------------
387 // This function associates a cluster with this track.
388 //-----------------------------------------------------------------
389 // Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
390 //Double_t r00=sigmay2, r01=0., r11=sigmaz2;
391 Double_t r00=fErrorY2, r01=0., r11=fErrorZ2;
393 r00+=fC00; r01+=fC10; r11+=fC11;
394 Double_t det=r00*r11 - r01*r01;
395 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
397 Double_t k00=fC00*r00+fC10*r01, k01=fC00*r01+fC10*r11;
398 Double_t k10=fC10*r00+fC11*r01, k11=fC10*r01+fC11*r11;
399 Double_t k20=fC20*r00+fC21*r01, k21=fC20*r01+fC21*r11;
400 Double_t k30=fC30*r00+fC31*r01, k31=fC30*r01+fC31*r11;
401 Double_t k40=fC40*r00+fC41*r01, k41=fC40*r01+fC41*r11;
403 Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
404 Double_t cur=fP4 + k40*dy + k41*dz, eta=fP2 + k20*dy + k21*dz;
405 if (TMath::Abs(cur*fX-eta) >= 0.99999) {
406 Int_t n=GetNumberOfClusters();
407 if (n>4) cerr<<n<<" AliTPCtrack warning: Filtering failed !\n";
411 fP0 += k00*dy + k01*dz;
412 fP1 += k10*dy + k11*dz;
414 fP3 += k30*dy + k31*dz;
417 Double_t c01=fC10, c02=fC20, c03=fC30, c04=fC40;
418 Double_t c12=fC21, c13=fC31, c14=fC41;
420 fC00-=k00*fC00+k01*fC10; fC10-=k00*c01+k01*fC11;
421 fC20-=k00*c02+k01*c12; fC30-=k00*c03+k01*c13;
422 fC40-=k00*c04+k01*c14;
424 fC11-=k10*c01+k11*fC11;
425 fC21-=k10*c02+k11*c12; fC31-=k10*c03+k11*c13;
426 fC41-=k10*c04+k11*c14;
428 fC22-=k20*c02+k21*c12; fC32-=k20*c03+k21*c13;
429 fC42-=k20*c04+k21*c14;
431 fC33-=k30*c03+k31*c13;
432 fC43-=k40*c03+k41*c13;
434 fC44-=k40*c04+k41*c14;
436 Int_t n=GetNumberOfClusters();
438 SetNumberOfClusters(n+1);
439 SetChi2(GetChi2()+chisq);
446 //_____________________________________________________________________________
447 Double_t AliTPCtrackerMI::f1(Double_t x1,Double_t y1,
448 Double_t x2,Double_t y2,
449 Double_t x3,Double_t y3)
451 //-----------------------------------------------------------------
452 // Initial approximation of the track curvature
453 //-----------------------------------------------------------------
454 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
455 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
456 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
457 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
458 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
460 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
462 return -xr*yr/sqrt(xr*xr+yr*yr);
466 //_____________________________________________________________________________
467 Double_t AliTPCtrackerMI::f2(Double_t x1,Double_t y1,
468 Double_t x2,Double_t y2,
469 Double_t x3,Double_t y3)
471 //-----------------------------------------------------------------
472 // Initial approximation of the track curvature times center of curvature
473 //-----------------------------------------------------------------
474 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
475 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
476 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
477 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
478 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
480 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
482 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
485 //_____________________________________________________________________________
486 Double_t AliTPCtrackerMI::f3(Double_t x1,Double_t y1,
487 Double_t x2,Double_t y2,
488 Double_t z1,Double_t z2)
490 //-----------------------------------------------------------------
491 // Initial approximation of the tangent of the track dip angle
492 //-----------------------------------------------------------------
493 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
497 void AliTPCtrackerMI::LoadClusters()
500 // load clusters to the memory
501 Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
502 for (Int_t i=0; i<j; i++) {
503 fClustersArray.LoadEntry(i);
507 void AliTPCtrackerMI::UnloadClusters()
510 // load clusters to the memory
511 Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
512 for (Int_t i=0; i<j; i++) {
513 fClustersArray.ClearSegment(i);
519 //_____________________________________________________________________________
520 void AliTPCtrackerMI::LoadOuterSectors() {
521 //-----------------------------------------------------------------
522 // This function fills outer TPC sectors with clusters.
523 //-----------------------------------------------------------------
525 Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
526 for (Int_t i=0; i<j; i++) {
527 // AliSegmentID *s=fClustersArray.LoadEntry(i);
528 AliSegmentID *s= fClustersArray.At(i);
530 AliTPCParam *par=(AliTPCParam*)fClustersArray.GetParam();
531 par->AdjustSectorRow(s->GetID(),sec,row);
532 if (sec<fkNIS*2) continue;
533 AliTPCClustersRow *clrow=fClustersArray.GetRow(sec,row);
534 Int_t ncl=clrow->GetArray()->GetEntriesFast();
536 AliTPCclusterMI *c=(AliTPCclusterMI*)(*clrow)[ncl];
537 index=(((sec<<8)+row)<<16)+ncl;
538 fOuterSec[(sec-fkNIS*2)%fkNOS][row].InsertCluster(c,index);
546 //_____________________________________________________________________________
547 void AliTPCtrackerMI::LoadInnerSectors() {
548 //-----------------------------------------------------------------
549 // This function fills inner TPC sectors with clusters.
550 //-----------------------------------------------------------------
552 Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
553 for (Int_t i=0; i<j; i++) {
554 // AliSegmentID *s=fClustersArray.LoadEntry(i);
555 AliSegmentID *s=fClustersArray.At(i);
557 AliTPCParam *par=(AliTPCParam*)fClustersArray.GetParam();
558 par->AdjustSectorRow(s->GetID(),sec,row);
559 if (sec>=fkNIS*2) continue;
560 AliTPCClustersRow *clrow=fClustersArray.GetRow(sec,row);
561 Int_t ncl=clrow->GetArray()->GetEntriesFast();
563 AliTPCclusterMI *c=(AliTPCclusterMI*)(*clrow)[ncl];
564 index=(((sec<<8)+row)<<16)+ncl;
565 fInnerSec[sec%fkNIS][row].InsertCluster(c,index);
573 Int_t AliTPCtrackerMI::FollowToNext(AliTPCseed& t, Int_t nr) {
574 //-----------------------------------------------------------------
575 // This function tries to find a track prolongation to next pad row
576 //-----------------------------------------------------------------
577 // Double_t xt=t.GetX();
578 // Int_t row = fSectors->GetRowNumber(xt)-1;
579 // if (row < nr) return 1; // don't prolongate if not information until now -
581 Double_t x=fSectors->GetX(nr), ymax=fSectors->GetMaxY(nr);
582 if (!t.PropagateTo(x)) return 0;
584 t.fCurrentSigmaY = GetSigmaY(&t);
585 t.fCurrentSigmaZ = GetSigmaZ(&t);
587 AliTPCclusterMI *cl=0;
589 const AliTPCRow &krow=fSectors[t.fRelativeSector][nr];
590 Double_t sy2=ErrY2(&t)*2;
591 Double_t sz2=ErrZ2(&t)*2;
594 Double_t roady =3.*sqrt(t.GetSigmaY2() + sy2);
595 Double_t roadz = 3 *sqrt(t.GetSigmaZ2() + sz2);
596 Double_t y=t.GetY(), z=t.GetZ();
598 if (TMath::Abs(TMath::Abs(y)-ymax)<krow.fDeadZone){
607 Float_t maxdistance = roady*roady + roadz*roadz;
609 for (Int_t i=krow.Find(z-roadz); i<krow; i++) {
610 AliTPCclusterMI *c=(AliTPCclusterMI*)(krow[i]);
611 if (c->GetZ() > z+roadz) break;
612 if ( (c->GetY()-y) > roady ) continue;
613 Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
614 if (maxdistance>distance) {
615 maxdistance = distance;
617 index=krow.GetIndex(i);
626 Double_t chi2= t.GetPredictedChi2(cl);
627 UpdateTrack(&t,cl,chi2,index);
630 t.fRelativeSector= (t.fRelativeSector+1) % fN;
631 if (!t.Rotate(fSectors->GetAlpha()))
633 } else if (y <-ymax) {
634 t.fRelativeSector= (t.fRelativeSector-1+fN) % fN;
635 if (!t.Rotate(-fSectors->GetAlpha()))
643 Int_t AliTPCtrackerMI::UpdateClusters(AliTPCseed& t,Int_t trindex, Int_t nr) {
644 //-----------------------------------------------------------------
645 // This function tries to find a track prolongation to next pad row
646 //-----------------------------------------------------------------
647 t.fCurrentCluster = 0;
648 t.fCurrentClusterIndex1 = 0;
649 t.fCurrentClusterIndex2 = 0;
651 Double_t xt=t.GetX();
652 Int_t row = fSectors->GetRowNumber(xt)-1;
653 if (row < nr) return 1; // don't prolongate if not information until now -
654 Double_t x=fSectors->GetX(nr);
655 if (!t.PropagateTo(x)) return 0;
657 t.fCurrentSigmaY = GetSigmaY(&t);
658 t.fCurrentSigmaZ = GetSigmaZ(&t);
660 AliTPCclusterMI *cl=0;
662 AliTPCRow &krow=fSectors[t.fRelativeSector][nr];
664 Double_t y=t.GetY(), z=t.GetZ();
665 Double_t roady = 3.* TMath::Sqrt(t.GetSigmaY2() + t.fCurrentSigmaY*t.fCurrentSigmaY);
666 Double_t roadz = 3.* TMath::Sqrt(t.GetSigmaZ2() + t.fCurrentSigmaZ*t.fCurrentSigmaZ);
669 Float_t maxdistance = 1000000;
671 for (Int_t i=krow.Find(z-roadz); i<krow; i++) {
672 AliTPCclusterMI *c=(AliTPCclusterMI*)(krow[i]);
673 if (c->GetZ() > z+roadz) break;
674 if (TMath::Abs(c->GetY()-y)>roady) continue;
676 //krow.UpdateClusterTrack(i,trindex,&t);
678 Float_t dy2 = (c->GetY()- t.GetY());
680 Float_t dz2 = (c->GetZ()- t.GetZ());
683 Float_t distance = dy2+dz2;
685 if (distance > maxdistance) continue;
686 maxdistance = distance;
691 t.fCurrentCluster = cl;
692 t.fCurrentClusterIndex1 = krow.GetIndex(index);
693 t.fCurrentClusterIndex2 = index;
698 Int_t AliTPCtrackerMI::FollowToNextCluster(Int_t trindex, Int_t nr) {
699 //-----------------------------------------------------------------
700 // This function tries to find a track prolongation to next pad row
701 //-----------------------------------------------------------------
702 AliTPCseed & t = *((AliTPCseed*)(fSeeds->At(trindex)));
703 AliTPCRow &krow=fSectors[t.fRelativeSector][nr];
704 // Double_t pt=t.GetConvConst()/(100/0.299792458/0.2)/t.Get1Pt();
706 Double_t ymax=fSectors->GetMaxY(nr);
708 if (TMath::Abs(TMath::Abs(y)-ymax)<krow.fDeadZone){
717 if (t.fCurrentCluster) {
718 // Float_t l=fSectors->GetPadPitchLength();
719 // AliTPCclusterTracks * cltrack = krow.GetClusterTracks(t.fCurrentClusterIndex1);
721 Double_t sy2=ErrY2(&t,t.fCurrentCluster);
722 Double_t sz2=ErrZ2(&t,t.fCurrentCluster);
725 Double_t sdistancey = TMath::Sqrt(sy2+t.GetSigmaY2());
726 Double_t sdistancez = TMath::Sqrt(sz2+t.GetSigmaZ2());
728 Double_t rdistancey = TMath::Abs(t.fCurrentCluster->GetY()-t.GetY());
729 Double_t rdistancez = TMath::Abs(t.fCurrentCluster->GetZ()-t.GetZ());
731 Double_t rdistance = TMath::Sqrt(TMath::Power(rdistancey/sdistancey,2)+TMath::Power(rdistancez/sdistancez,2));
734 // printf("\t%f\t%f\t%f\n",rdistancey/sdistancey,rdistancez/sdistancez,rdistance);
735 if (rdistance>4) return 0;
737 if ((rdistancey/sdistancey>2.5 || rdistancez/sdistancez>2.5) && t.fCurrentCluster->GetType()==0)
738 return 0; //suspisiouce - will be changed
740 if ((rdistancey/sdistancey>2. || rdistancez/sdistancez>2.0) && t.fCurrentCluster->GetType()>0)
741 // strict cut on overlaped cluster
742 return 0; //suspisiouce - will be changed
744 if ( (rdistancey/sdistancey>1. || rdistancez/sdistancez>2.5 ||t.fCurrentCluster->GetQ()<70 )
745 && t.fCurrentCluster->GetType()<0)
748 // t.SetSampledEdx(0.3*t.fCurrentCluster->GetQ()/l,t.GetNumberOfClusters(), GetSigmaY(&t), GetSigmaZ(&t));
749 UpdateTrack(&t,t.fCurrentCluster,t.GetPredictedChi2(t.fCurrentCluster),t.fCurrentClusterIndex1);
753 t.fRelativeSector= (t.fRelativeSector+1) % fN;
754 if (!t.Rotate(fSectors->GetAlpha()))
756 } else if (y <-ymax) {
757 t.fRelativeSector= (t.fRelativeSector-1+fN) % fN;
758 if (!t.Rotate(-fSectors->GetAlpha()))
769 Int_t AliTPCtrackerMI::FollowProlongationFast(AliTPCseed& t, Int_t step)
771 //-----------------------------------------------------------------
772 // fast prolongation mathod -
773 // don't update track only after step clusters
774 //-----------------------------------------------------------------
775 Double_t xt=t.GetX();
777 Double_t alpha=t.GetAlpha();
778 alpha =- fSectors->GetAlphaShift();
779 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
780 if (alpha < 0. ) alpha += 2.*TMath::Pi();
781 t.fRelativeSector = Int_t(alpha/fSectors->GetAlpha())%fN;
782 Int_t row0 = fSectors->GetRowNumber(xt);
783 Double_t x = fSectors->GetX(row0);
784 Double_t ymax = fSectors->GetMaxY(row0);
786 Double_t sy2=ErrY2(&t)*2;
787 Double_t sz2=ErrZ2(&t)*2;
788 Double_t roady =3.*sqrt(t.GetSigmaY2() + sy2);
789 Double_t roadz = 3 *sqrt(t.GetSigmaZ2() + sz2);
790 Float_t maxdistance = roady*roady + roadz*roadz;
791 t.fCurrentSigmaY = GetSigmaY(&t);
792 t.fCurrentSigmaZ = GetSigmaZ(&t);
797 Double_t yy[200]; //track prolongation
799 Double_t cy[200]; // founded cluster position
801 Double_t sy[200]; // founded cluster error
803 Bool_t hitted[200]; // indication of cluster presence
807 for (Int_t drow = step; drow>=0; drow--) {
808 Int_t row = row0-drow;
810 Double_t x = fSectors->GetX(row);
811 Double_t ymax = fSectors->GetMaxY(row);
812 t.GetProlongation(x,y,z);
815 const AliTPCRow &krow=fSectors[t.fRelativeSector][row];
816 if (TMath::Abs(TMath::Abs(y)-ymax)<krow.fDeadZone){
825 //find nearest cluster
826 AliTPCclusterMI *cl= 0;
828 for (Int_t i=krow.Find(z-roadz); i<krow; i++) {
829 AliTPCclusterMI *c=(AliTPCclusterMI*)(krow[i]);
830 if (c->GetZ() > z+roadz) break;
831 if ( (c->GetY()-y) > roady ) continue;
832 Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
833 if (maxdistance>distance) {
834 maxdistance = distance;
836 // index=krow.GetIndex(i);
840 //update cluster information
842 cy[drow] = cl->GetY();
843 cz[drow] = cl->GetZ();
844 sy[drow] = ErrY2(&t,cl);
845 sz[drow] = ErrZ2(&t,cl);
846 hitted[drow] = kTRUE;
850 hitted[drow] = kFALSE;
852 //if we have information - update track
859 for (Int_t i=0;i<step;i++)
864 sumyw+= (cy[i]-yy[i])/sy[i];
865 sumzw+= (cz[i]-zz[i])/sz[i];
868 Float_t dy = sumyw/sumyw0;
869 Float_t dz = sumzw/sumzw0;
870 Float_t mrow = sumrow/nclusters+row0;
871 Float_t x = fSectors->GetX(mrow);
873 AliTPCclusterMI cvirtual;
874 cvirtual.SetZ(dz+t.GetZ());
875 cvirtual.SetY(dy+t.GetY());
876 t.SetErrorY2(1.2*t.fErrorY2/TMath::Sqrt(Float_t(nclusters)));
877 t.SetErrorZ2(1.2*t.fErrorZ2/TMath::Sqrt(Float_t(nclusters)));
878 Float_t chi2 = t.GetPredictedChi2(&cvirtual);
879 t.Update(&cvirtual,chi2,0);
880 Int_t ncl = t.GetNumberOfClusters();
881 ncl = ncl-1+nclusters;
888 //_____________________________________________________________________________
889 Int_t AliTPCtrackerMI::FollowProlongation(AliTPCseed& t, Int_t rf) {
890 //-----------------------------------------------------------------
891 // This function tries to find a track prolongation.
892 //-----------------------------------------------------------------
893 Double_t xt=t.GetX();
895 Double_t alpha=t.GetAlpha() - fSectors->GetAlphaShift();
896 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
897 if (alpha < 0. ) alpha += 2.*TMath::Pi();
898 t.fRelativeSector = Int_t(alpha/fSectors->GetAlpha())%fN;
900 for (Int_t nr=fSectors->GetRowNumber(xt)-1; nr>=rf; nr--) {
902 if (FollowToNext(t,nr)==0) {
909 //_____________________________________________________________________________
910 Int_t AliTPCtrackerMI::FollowBackProlongation(AliTPCseed& t, Int_t rf) {
911 //-----------------------------------------------------------------
912 // This function tries to find a track prolongation.
913 //-----------------------------------------------------------------
914 Double_t xt=t.GetX();
916 Double_t alpha=t.GetAlpha() - fSectors->GetAlphaShift();
917 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
918 if (alpha < 0. ) alpha += 2.*TMath::Pi();
919 t.fRelativeSector = Int_t(alpha/fSectors->GetAlpha())%fN;
921 for (Int_t nr=fSectors->GetRowNumber(xt)+1; nr<=rf; nr++) {
932 Float_t AliTPCtrackerMI::OverlapFactor(AliTPCseed * s1, AliTPCseed * s2, Int_t &sum1, Int_t & sum2)
939 if (s1->fSector!=s2->fSector) return 0;
941 Float_t dz2 =(s1->GetZ() - s2->GetZ());
943 Float_t dy2 =(s1->GetY() - s2->GetY());
945 Float_t distance = TMath::Sqrt(dz2+dy2);
946 if (distance>5.) return 0; // if there are far away - not overlap - to reduce combinatorics
948 for (Int_t i=0;i<160;i++){
949 if (s1->fClusterIndex[i]>0) sum1++;
950 if (s2->fClusterIndex[i]>0) sum2++;
951 if (s1->fClusterIndex[i]==s2->fClusterIndex[i] && s1->fClusterIndex[i]>0) {
956 Float_t summin = TMath::Min(sum1,sum2);
957 Float_t ratio = sum/Float_t(summin);
961 void AliTPCtrackerMI::SignShared(AliTPCseed * s1, AliTPCseed * s2)
965 if (s1->fSector!=s2->fSector) return;
967 Float_t dz2 =(s1->GetZ() - s2->GetZ());
969 Float_t dy2 =(s1->GetY() - s2->GetY());
971 Float_t distance = TMath::Sqrt(dz2+dy2);
972 if (distance>15.) return ; // if there are far away - not overlap - to reduce combinatorics
973 //trpoint = new (pointarray[track->fRow]) AliTPCTrackPoint;
974 // TClonesArray &pointarray1 = *(s1->fPoints);
975 //TClonesArray &pointarray2 = *(s2->fPoints);
977 for (Int_t i=0;i<160;i++){
978 if (s1->fClusterIndex[i]==s2->fClusterIndex[i] && s1->fClusterIndex[i]>0) {
979 // AliTPCTrackPoint *p1 = (AliTPCTrackPoint *)(pointarray1.UncheckedAt(i));
980 //AliTPCTrackPoint *p2 = (AliTPCTrackPoint *)(pointarray2.UncheckedAt(i));
981 AliTPCTrackPoint *p1 = s1->GetTrackPoint(i);
982 AliTPCTrackPoint *p2 = s2->GetTrackPoint(i);;
983 p1->fIsShared = kTRUE;
984 p2->fIsShared = kTRUE;
992 void AliTPCtrackerMI::RemoveOverlap(TObjArray * arr, Float_t factor, Int_t removalindex , Bool_t shared=kFALSE){
997 // remove overlap - used removal factor - removal index stored in the track
998 arr->Sort(); // sorting according z
999 arr->Expand(arr->GetEntries());
1000 Int_t nseed=arr->GetEntriesFast();
1001 // printf("seeds \t%p \t%d\n",arr, nseed);
1002 // arr->Expand(arr->GetEntries()); //remove 0 pointers
1003 nseed = arr->GetEntriesFast();
1005 for (Int_t i=0; i<nseed; i++) {
1006 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1010 if (!(pt->IsActive())) continue;
1011 for (Int_t j=i+1; j<nseed; j++){
1012 AliTPCseed *pt2=(AliTPCseed*)arr->UncheckedAt(j);
1013 if ((pt2) && pt2->IsActive())
1014 if (pt->fSector == pt2->fSector)
1015 if (TMath::Abs(pt2->GetZ()-pt->GetZ())<2){
1017 Float_t ratio = OverlapFactor(pt,pt2,sum1,sum2);
1019 // if (pt->GetChi2()<pt2->GetChi2()) pt2->Desactivate(removalindex); // arr->RemoveAt(j);
1020 Float_t ratio2 = (pt->GetChi2()*sum2)/(pt2->GetChi2()*sum1);
1021 Float_t ratio3 = Float_t(sum1-sum2)/Float_t(sum1+sum2);
1023 if (TMath::Abs(ratio3)>0.025){ // if much more points
1024 if (sum1>sum2) pt2->Desactivate(removalindex);
1026 pt->Desactivate(removalindex); // arr->RemoveAt(i);
1030 else{ //decide on mean chi2
1032 pt2->Desactivate(removalindex);
1034 pt->Desactivate(removalindex); // arr->RemoveAt(i);
1039 } // if suspicious ratio
1045 // printf("removed\t%d\n",removed);
1047 for (Int_t i=0; i<nseed; i++) {
1048 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1050 if (pt->GetNumberOfClusters() < pt->fNFoundable*0.5) {
1051 //desactivate tracks with small number of points
1052 // printf("%d\t%d\t%f\n", pt->GetNumberOfClusters(), pt->fNFoundable,pt->GetNumberOfClusters()/Float_t(pt->fNFoundable));
1053 pt->Desactivate(10); //desactivate - small muber of points
1055 if (!(pt->IsActive())) continue;
1061 for (Int_t i=0; i<nseed; i++) {
1062 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1064 if (!(pt->IsActive())) continue;
1065 for (Int_t j=i+1; j<nseed; j++){
1066 AliTPCseed *pt2=(AliTPCseed*)arr->UncheckedAt(j);
1067 if ((pt2) && pt2->IsActive()) {
1068 if ( TMath::Abs(pt->fSector-pt2->fSector)>1) break;
1074 printf("\n*****\nNumber of good tracks after overlap removal\t%d\n",fNtracks);
1078 void AliTPCtrackerMI::MakeSeedsAll()
1080 if (fSeeds == 0) fSeeds = new TObjArray;
1082 for (Int_t sec=0;sec<fkNOS;sec+=3){
1083 arr = MakeSeedsSectors(sec,sec+3);
1084 Int_t nseed = arr->GetEntriesFast();
1085 for (Int_t i=0;i<nseed;i++)
1086 fSeeds->AddLast(arr->RemoveAt(i));
1088 // fSeeds = MakeSeedsSectors(0,fkNOS);
1091 TObjArray * AliTPCtrackerMI::MakeSeedsSectors(Int_t sec1, Int_t sec2)
1094 // loop over all sectors and make seed
1097 Int_t nup=fOuterSec->GetNRows(), nlow=fInnerSec->GetNRows();
1098 Int_t nrows=nlow+nup;
1099 Int_t gap=Int_t(0.125*nrows), shift=Int_t(0.5*gap);
1100 // if (fSeeds==0) fSeeds = new TObjArray;
1101 TObjArray * arr = new TObjArray;
1103 for (Int_t sec=sec1; sec<sec2;sec++){
1104 MakeSeeds(arr, sec, nup-1, nup-1-gap);
1105 MakeSeeds(arr, sec, nup-1-shift, nup-1-shift-gap);
1107 Int_t nseed=arr->GetEntriesFast();
1108 gap=Int_t(0.3*nrows);
1111 for (i=0; i<nseed; i++) {
1112 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i), &t=*pt;
1114 if (FollowProlongation(t,nup-gap)) {
1115 pt->fIsSeeding =kFALSE;
1118 delete arr->RemoveAt(i);
1121 //remove seeds which overlaps
1122 RemoveOverlap(arr,0.6,1);
1123 //delete seeds - which were sign
1124 nseed=arr->GetEntriesFast();
1125 for (i=0; i<nseed; i++) {
1126 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1129 if ((pt->IsActive()) && pt->GetNumberOfClusters() > pt->fNFoundable*0.5 ) {
1130 //FollowBackProlongation(t,nup);
1133 delete arr->RemoveAt(i);
1140 //_____________________________________________________________________________
1141 void AliTPCtrackerMI::MakeSeeds(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2) {
1142 //-----------------------------------------------------------------
1143 // This function creates track seeds.
1144 //-----------------------------------------------------------------
1145 // if (fSeeds==0) fSeeds=new TObjArray(15000);
1147 Double_t x[5], c[15];
1149 Double_t alpha=fOuterSec->GetAlpha(), shift=fOuterSec->GetAlphaShift();
1150 Double_t cs=cos(alpha), sn=sin(alpha);
1152 Double_t x1 =fOuterSec->GetX(i1);
1153 Double_t xx2=fOuterSec->GetX(i2);
1155 // for (Int_t ns=0; ns<fkNOS; ns++)
1158 Int_t nl=fOuterSec[(ns-1+fkNOS)%fkNOS][i2];
1159 Int_t nm=fOuterSec[ns][i2];
1160 Int_t nu=fOuterSec[(ns+1)%fkNOS][i2];
1161 const AliTPCRow& kr1=fOuterSec[ns][i1];
1162 AliTPCRow& kr21 = fOuterSec[(ns-1+fkNOS)%fkNOS][i2];
1163 AliTPCRow& kr22 = fOuterSec[(ns)%fkNOS][i2];
1164 AliTPCRow& kr23 = fOuterSec[(ns+1)%fkNOS][i2];
1166 for (Int_t is=0; is < kr1; is++) {
1167 Double_t y1=kr1[is]->GetY(), z1=kr1[is]->GetZ();
1168 Double_t x3=GetX(), y3=GetY(), z3=GetZ();
1170 Float_t anglez = (z1-z3)/(x1-x3);
1171 Float_t extraz = z1 - anglez*(x1-xx2); // extrapolated z
1173 for (Int_t js=0; js < nl+nm+nu; js++) {
1174 const AliTPCclusterMI *kcl;
1175 Double_t x2, y2, z2;
1178 js = kr21.Find(extraz-15.);
1179 if (js>=nl) continue;
1183 if ((extraz-z2)>10) continue;
1184 if ((extraz-z2)<-10) {
1194 js = nl+kr22.Find(extraz-15.);
1195 if (js>=nl+nm) continue;
1199 if ((extraz-z2)>10) continue;
1200 if ((extraz-z2)<-10) {
1204 x2=xx2; y2=kcl->GetY();
1206 //const AliTPCRow& kr2=fOuterSec[(ns+1)%fkNOS][i2];
1208 js = nl+nm+kr23.Find(extraz-15.);
1209 if (js>=nl+nm+nu) break;
1213 if ((extraz-z2)>10) continue;
1214 if ((extraz-z2)<-10) {
1222 Double_t zz=z1 - anglez*(x1-x2);
1223 if (TMath::Abs(zz-z2)>10.) continue;
1225 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
1226 if (d==0.) {cerr<<"MakeSeeds warning: Straight seed !\n"; continue;}
1230 x[4]=f1(x1,y1,x2,y2,x3,y3);
1231 if (TMath::Abs(x[4]) >= 0.0066) continue;
1232 x[2]=f2(x1,y1,x2,y2,x3,y3);
1233 //if (TMath::Abs(x[4]*x1-x[2]) >= 0.99999) continue;
1234 x[3]=f3(x1,y1,x2,y2,z1,z2);
1235 if (TMath::Abs(x[3]) > 1.2) continue;
1236 Double_t a=asin(x[2]);
1237 Double_t zv=z1 - x[3]/x[4]*(a+asin(x[4]*x1-x[2]));
1238 if (TMath::Abs(zv-z3)>10.) continue;
1240 Double_t sy1=kr1[is]->GetSigmaY2()*2, sz1=kr1[is]->GetSigmaZ2()*4;
1241 Double_t sy2=kcl->GetSigmaY2()*2, sz2=kcl->GetSigmaZ2()*4;
1242 //Double_t sy3=400*3./12., sy=0.1, sz=0.1;
1243 Double_t sy3=25000*x[4]*x[4]+0.1, sy=0.1, sz=0.1;
1244 //Double_t sy3=25000*x[4]*x[4]*60+0.5, sy=0.1, sz=0.1;
1246 Double_t f40=(f1(x1,y1+sy,x2,y2,x3,y3)-x[4])/sy;
1247 Double_t f42=(f1(x1,y1,x2,y2+sy,x3,y3)-x[4])/sy;
1248 Double_t f43=(f1(x1,y1,x2,y2,x3,y3+sy)-x[4])/sy;
1249 Double_t f20=(f2(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
1250 Double_t f22=(f2(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
1251 Double_t f23=(f2(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
1252 Double_t f30=(f3(x1,y1+sy,x2,y2,z1,z2)-x[3])/sy;
1253 Double_t f31=(f3(x1,y1,x2,y2,z1+sz,z2)-x[3])/sz;
1254 Double_t f32=(f3(x1,y1,x2,y2+sy,z1,z2)-x[3])/sy;
1255 Double_t f34=(f3(x1,y1,x2,y2,z1,z2+sz)-x[3])/sz;
1259 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f23*sy3*f23;
1260 c[6]=f30*sy1; c[7]=f31*sz1; c[8]=f30*sy1*f20+f32*sy2*f22;
1261 c[9]=f30*sy1*f30+f31*sz1*f31+f32*sy2*f32+f34*sz2*f34;
1262 c[10]=f40*sy1; c[11]=0.; c[12]=f40*sy1*f20+f42*sy2*f22+f43*sy3*f23;
1263 c[13]=f30*sy1*f40+f32*sy2*f42;
1264 c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
1266 UInt_t index=kr1.GetIndex(is);
1267 AliTPCseed *track=new AliTPCseed(index, x, c, x1, ns*alpha+shift);
1268 track->fIsSeeding = kTRUE;
1269 Int_t rc=FollowProlongation(*track, i2);
1270 //FollowProlongationFast(*track, 5);
1271 //FollowProlongationFast(*track, 5);
1272 //FollowProlongationFast(*track, 5);
1273 //FollowProlongationFast(*track, 5);
1276 track->fLastPoint = i1; // first cluster in track position
1277 if (rc==0 || track->GetNumberOfClusters()<(i1-i2)/4 || track->GetNumberOfClusters() < track->fNFoundable/2. ) delete track;
1278 else arr->AddLast(track);
1284 //_____________________________________________________________________________
1285 Int_t AliTPCtrackerMI::ReadSeeds(const TFile *inp) {
1286 //-----------------------------------------------------------------
1287 // This function reades track seeds.
1288 //-----------------------------------------------------------------
1289 TDirectory *savedir=gDirectory;
1291 TFile *in=(TFile*)inp;
1292 if (!in->IsOpen()) {
1293 cerr<<"AliTPCtrackerMI::ReadSeeds(): input file is not open !\n";
1298 TTree *seedTree=(TTree*)in->Get("Seeds");
1300 cerr<<"AliTPCtrackerMI::ReadSeeds(): ";
1301 cerr<<"can't get a tree with track seeds !\n";
1304 AliTPCtrack *seed=new AliTPCtrack;
1305 seedTree->SetBranchAddress("tracks",&seed);
1307 if (fSeeds==0) fSeeds=new TObjArray(15000);
1309 Int_t n=(Int_t)seedTree->GetEntries();
1310 for (Int_t i=0; i<n; i++) {
1311 seedTree->GetEvent(i);
1312 fSeeds->AddLast(new AliTPCseed(*seed,seed->GetAlpha()));
1321 //_____________________________________________________________________________
1322 Int_t AliTPCtrackerMI::Clusters2Tracks(const TFile *inp, TFile *out) {
1323 //-----------------------------------------------------------------
1324 // This is a track finder.
1325 //-----------------------------------------------------------------
1326 TDirectory *savedir=gDirectory;
1329 TFile *in=(TFile*)inp;
1330 if (!in->IsOpen()) {
1331 cerr<<"AliTPCtrackerMI::Clusters2Tracks(): input file is not open !\n";
1336 if (!out->IsOpen()) {
1337 cerr<<"AliTPCtrackerMI::Clusters2Tracks(): output file is not open !\n";
1344 sprintf(tname,"TreeT_TPC_%d",fEventN);
1345 TTree tracktree(tname,"Tree with TPC tracks");
1346 TTree seedtree("Seeds","Seeds");
1347 AliTPCtrack *iotrack=0;
1348 AliTPCseed *ioseed=0;
1349 tracktree.Branch("tracks","AliTPCtrack",&iotrack,32000,0);
1352 printf("Loading clusters \n");
1354 printf("Time for loading clusters: \t");timer.Print();timer.Start();
1356 printf("Loading outer sectors\n");
1358 printf("Time for loading outer sectors: \t");timer.Print();timer.Start();
1360 printf("Loading inner sectors\n");
1362 printf("Time for loading inner sectors: \t");timer.Print();timer.Start();
1363 fSectors = fOuterSec;
1369 printf("Time for seeding: \t"); timer.Print();timer.Start();
1370 Int_t nup=fOuterSec->GetNRows(), nlow=fInnerSec->GetNRows();
1371 Int_t nrows=nlow+nup;
1373 Int_t gap=Int_t(0.3*nrows);
1375 Int_t nseed=fSeeds->GetEntriesFast();
1376 // outer sectors parallel tracking
1377 ParallelTracking(fSectors->GetNRows()-gap-1,0);
1378 printf("Time for parralel tracking outer sectors: \t"); timer.Print();timer.Start();
1380 RemoveOverlap(fSeeds, 0.6,3);
1381 printf("Time for removal overlap- outer sectors: \t");timer.Print();timer.Start();
1383 fSectors = fInnerSec;
1385 ParallelTracking(fSectors->GetNRows()-1,0);
1386 printf("Number of tracks after inner tracking %d\n",fNtracks);
1387 printf("Time for parralel tracking inner sectors: \t"); timer.Print();timer.Start();
1389 RemoveOverlap(fSeeds,0.6,5,kTRUE); // remove overlap - shared points signed
1390 printf("Time for removal overlap- inner sectors: \t"); timer.Print();timer.Start();
1394 ioseed = (AliTPCseed*)(fSeeds->UncheckedAt(0));
1395 AliTPCseed * vseed = new AliTPCseed;
1396 vseed->fPoints = new TClonesArray("AliTPCTrackPoint",1);
1397 vseed->fEPoints = new TClonesArray("AliTPCExactPoint",1);
1398 vseed->fPoints->ExpandCreateFast(2);
1400 TBranch * seedbranch = seedtree.Branch("seeds","AliTPCseed",&vseed,32000,99);
1402 nseed=fSeeds->GetEntriesFast();
1405 for (i=0; i<nseed; i++) {
1406 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
1408 Int_t nc=t.GetNumberOfClusters();
1409 t.CookdEdx(0.02,0.6);
1410 CookLabel(pt,0.1); //For comparison only
1411 // if ((pt->IsActive()) && (nc>Int_t(0.4*nrows))){
1412 if ((pt->IsActive()) && (nc>Int_t(0.5*t.fNFoundable) && (nc>Int_t(0.3*nrows)))){
1415 cerr<<found++<<'\r';
1418 if ( (pt->IsActive())) fNtracks--;
1420 seedbranch->SetAddress(&pt);
1423 for (Int_t j=0;j<160;j++){
1424 delete pt->fPoints->RemoveAt(j);
1428 delete fSeeds->RemoveAt(i);
1430 printf("Time for track writing and dedx cooking: \t"); timer.Print();timer.Start();
1433 printf("Time for unloading cluster: \t"); timer.Print();timer.Start();
1437 cerr<<"Number of found tracks : "<<fNtracks<<"\t"<<found<<endl;
1445 void AliTPCtrackerMI::ParallelTracking(Int_t rfirst, Int_t rlast)
1448 // try to track in parralel
1450 Int_t nseed=fSeeds->GetEntriesFast();
1451 //prepare seeds for tracking
1452 for (Int_t i=0; i<nseed; i++) {
1453 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
1455 if (!t.IsActive()) continue;
1456 // follow prolongation to the first layer
1457 FollowProlongation(t, rfirst+1);
1462 for (Int_t nr=rfirst; nr>=rlast; nr--){
1463 // make indexes with the cluster tracks for given
1464 // for (Int_t i = 0;i<fN;i++)
1465 // fSectors[i][nr].MakeClusterTracks();
1467 // find nearest cluster
1468 for (Int_t i=0; i<nseed; i++) {
1469 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
1471 if (!pt->IsActive()) continue;
1472 UpdateClusters(t,i,nr);
1474 // prolonagate to the nearest cluster - if founded
1475 for (Int_t i=0; i<nseed; i++) {
1476 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i);
1478 if (!pt->IsActive()) continue;
1479 FollowToNextCluster(i,nr);
1481 // for (Int_t i= 0;i<fN;i++)
1482 // fSectors[i][nr].ClearClusterTracks();
1487 Float_t AliTPCtrackerMI::GetSigmaY(AliTPCseed * seed)
1491 Float_t sd2 = (fParam->GetZLength()-TMath::Abs(seed->GetZ()))*fParam->GetDiffL()*fParam->GetDiffL();
1492 Float_t padlength = fParam->GetPadPitchLength(seed->fSector);
1493 Float_t sres = (seed->fSector < fParam->GetNSector()/2) ? 0.2 :0.3;
1494 Float_t angular = seed->GetSnp();
1495 angular = angular*angular/(1-angular*angular);
1496 // angular*=angular;
1497 //angular = TMath::Sqrt(angular/(1-angular));
1498 Float_t res = TMath::Sqrt(sd2+padlength*padlength*angular/12.+sres*sres);
1501 Float_t AliTPCtrackerMI::GetSigmaZ(AliTPCseed * seed)
1505 Float_t sd2 = (fParam->GetZLength()-TMath::Abs(seed->GetZ()))*fParam->GetDiffL()*fParam->GetDiffL();
1506 Float_t padlength = fParam->GetPadPitchLength(seed->fSector);
1507 Float_t sres = fParam->GetZSigma();
1508 Float_t angular = seed->GetTgl();
1509 Float_t res = TMath::Sqrt(sd2+padlength*padlength*angular*angular/12.+sres*sres);
1515 //_________________________________________________________________________
1516 AliTPCclusterMI *AliTPCtrackerMI::GetClusterMI(Int_t index) const {
1517 //--------------------------------------------------------------------
1518 // Return pointer to a given cluster
1519 //--------------------------------------------------------------------
1520 Int_t sec=(index&0xff000000)>>24;
1521 Int_t row=(index&0x00ff0000)>>16;
1522 Int_t ncl=(index&0x0000ffff)>>00;
1524 AliTPCClustersRow *clrow=((AliTPCtrackerMI *) this)->fClustersArray.GetRow(sec,row);
1525 return (AliTPCclusterMI*)(*clrow)[ncl];
1528 //__________________________________________________________________________
1529 void AliTPCtrackerMI::CookLabel(AliKalmanTrack *t, Float_t wrong) const {
1530 //--------------------------------------------------------------------
1531 //This function "cooks" a track label. If label<0, this track is fake.
1532 //--------------------------------------------------------------------
1533 Int_t noc=t->GetNumberOfClusters();
1534 Int_t *lb=new Int_t[noc];
1535 Int_t *mx=new Int_t[noc];
1536 AliTPCclusterMI **clusters=new AliTPCclusterMI*[noc];
1539 for (i=0; i<noc; i++) {
1541 Int_t index=t->GetClusterIndex(i);
1542 clusters[i]=GetClusterMI(index);
1545 Int_t lab=123456789;
1546 for (i=0; i<noc; i++) {
1547 AliTPCclusterMI *c=clusters[i];
1548 lab=TMath::Abs(c->GetLabel(0));
1550 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
1556 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
1558 for (i=0; i<noc; i++) {
1559 AliTPCclusterMI *c=clusters[i];
1560 if (TMath::Abs(c->GetLabel(1)) == lab ||
1561 TMath::Abs(c->GetLabel(2)) == lab ) max++;
1564 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
1567 Int_t tail=Int_t(0.10*noc);
1569 for (i=1; i<=tail; i++) {
1570 AliTPCclusterMI *c=clusters[noc-i];
1571 if (lab == TMath::Abs(c->GetLabel(0)) ||
1572 lab == TMath::Abs(c->GetLabel(1)) ||
1573 lab == TMath::Abs(c->GetLabel(2))) max++;
1575 if (max < Int_t(0.5*tail)) lab=-lab;
1585 //_________________________________________________________________________
1586 void AliTPCtrackerMI::AliTPCSector::Setup(const AliTPCParam *par, Int_t f) {
1587 //-----------------------------------------------------------------------
1588 // Setup inner sector
1589 //-----------------------------------------------------------------------
1591 fAlpha=par->GetInnerAngle();
1592 fAlphaShift=par->GetInnerAngleShift();
1593 fPadPitchWidth=par->GetInnerPadPitchWidth();
1594 fPadPitchLength=par->GetInnerPadPitchLength();
1595 fN=par->GetNRowLow();
1596 fRow=new AliTPCRow[fN];
1597 for (Int_t i=0; i<fN; i++) {
1598 fRow[i].SetX(par->GetPadRowRadiiLow(i));
1599 fRow[i].fDeadZone =1.5; //1.5 cm of dead zone
1602 fAlpha=par->GetOuterAngle();
1603 fAlphaShift=par->GetOuterAngleShift();
1604 fPadPitchWidth = par->GetOuterPadPitchWidth();
1605 fPadPitchLength = par->GetOuter1PadPitchLength();
1606 f1PadPitchLength = par->GetOuter1PadPitchLength();
1607 f2PadPitchLength = par->GetOuter2PadPitchLength();
1609 fN=par->GetNRowUp();
1610 fRow=new AliTPCRow[fN];
1611 for (Int_t i=0; i<fN; i++) {
1612 fRow[i].SetX(par->GetPadRowRadiiUp(i));
1613 fRow[i].fDeadZone =1.5; // 1.5 cm of dead zone
1619 AliTPCtrackerMI::AliTPCRow::~AliTPCRow(){
1621 if (fClusterTracks) delete [] fClusterTracks;
1625 void AliTPCtrackerMI::AliTPCRow::MakeClusterTracks(){
1626 //create cluster tracks
1628 fClusterTracks = new AliTPCclusterTracks[fN];
1631 void AliTPCtrackerMI::AliTPCRow::ClearClusterTracks(){
1632 if (fClusterTracks) delete[] fClusterTracks;
1638 void AliTPCtrackerMI::AliTPCRow::UpdateClusterTrack(Int_t clindex, Int_t trindex, AliTPCseed * seed){
1641 // update information of the cluster tracks - if track is nearer then other tracks to the
1643 const AliTPCclusterMI * cl = (*this)[clindex];
1644 AliTPCclusterTracks * cltracks = GetClusterTracks(clindex);
1645 // find the distance of the cluster to the track
1646 Float_t dy2 = (cl->GetY()- seed->GetY());
1648 Float_t dz2 = (cl->GetZ()- seed->GetZ());
1651 Float_t distance = TMath::Sqrt(dy2+dz2);
1653 return; // MI - to be changed - AliTPCtrackerParam
1655 if ( distance < cltracks->fDistance[0]){
1656 cltracks->fDistance[2] =cltracks->fDistance[1];
1657 cltracks->fDistance[1] =cltracks->fDistance[0];
1658 cltracks->fDistance[0] =distance;
1659 cltracks->fTrackIndex[2] =cltracks->fTrackIndex[1];
1660 cltracks->fTrackIndex[1] =cltracks->fTrackIndex[0];
1661 cltracks->fTrackIndex[0] =trindex;
1664 if ( distance < cltracks->fDistance[1]){
1665 cltracks->fDistance[2] =cltracks->fDistance[1];
1666 cltracks->fDistance[1] =distance;
1667 cltracks->fTrackIndex[2] =cltracks->fTrackIndex[1];
1668 cltracks->fTrackIndex[1] =trindex;
1670 if (distance < cltracks->fDistance[2]){
1671 cltracks->fDistance[2] =distance;
1672 cltracks->fTrackIndex[2] =trindex;
1677 //_________________________________________________________________________
1679 AliTPCtrackerMI::AliTPCRow::InsertCluster(const AliTPCclusterMI* c, UInt_t index) {
1680 //-----------------------------------------------------------------------
1681 // Insert a cluster into this pad row in accordence with its y-coordinate
1682 //-----------------------------------------------------------------------
1683 if (fN==kMaxClusterPerRow) {
1684 cerr<<"AliTPCRow::InsertCluster(): Too many clusters !\n"; return;
1686 if (fN==0) {fIndex[0]=index; fClusters[fN++]=c; return;}
1687 Int_t i=Find(c->GetZ());
1688 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTPCclusterMI*));
1689 memmove(fIndex +i+1 ,fIndex +i,(fN-i)*sizeof(UInt_t));
1690 fIndex[i]=index; fClusters[i]=c; fN++;
1693 //___________________________________________________________________
1694 Int_t AliTPCtrackerMI::AliTPCRow::Find(Double_t z) const {
1695 //-----------------------------------------------------------------------
1696 // Return the index of the nearest cluster
1697 //-----------------------------------------------------------------------
1698 if (fN==0) return 0;
1699 if (z <= fClusters[0]->GetZ()) return 0;
1700 if (z > fClusters[fN-1]->GetZ()) return fN;
1701 Int_t b=0, e=fN-1, m=(b+e)/2;
1702 for (; b<e; m=(b+e)/2) {
1703 if (z > fClusters[m]->GetZ()) b=m+1;
1711 AliTPCseed::AliTPCseed():AliTPCtrack(){
1715 memset(fClusterIndex,0,sizeof(Int_t)*200);
1724 AliTPCseed::AliTPCseed(const AliTPCtrack &t):AliTPCtrack(t){
1732 AliTPCseed::AliTPCseed(const AliKalmanTrack &t, Double_t a):AliTPCtrack(t,a){
1734 memset(fClusterIndex,0,sizeof(Int_t)*200);
1743 AliTPCseed::AliTPCseed(UInt_t index, const Double_t xx[5], const Double_t cc[15],
1744 Double_t xr, Double_t alpha):
1745 AliTPCtrack(index, xx, cc, xr, alpha) {
1749 memset(fClusterIndex,0,sizeof(Int_t)*200);
1758 AliTPCseed::~AliTPCseed(){
1759 if (fPoints) delete fPoints;
1763 for (Int_t i=0;i<8;i++){
1764 delete [] fTrackPoints[i];
1766 delete fTrackPoints;
1772 AliTPCTrackPoint * AliTPCseed::GetTrackPoint(Int_t i)
1776 if (!fTrackPoints) {
1777 fTrackPoints = new AliTPCTrackPoint*[8];
1778 for ( Int_t i=0;i<8;i++)
1781 Int_t index1 = i/20;
1782 if (!fTrackPoints[index1]) fTrackPoints[index1] = new AliTPCTrackPoint[20];
1783 return &(fTrackPoints[index1][i%20]);
1786 void AliTPCseed::RebuildSeed()
1789 // rebuild seed to be ready for storing
1790 fPoints = new TClonesArray("AliTPCTrackPoint",160);
1791 fPoints->ExpandCreateFast(160);
1792 fEPoints = new TClonesArray("AliTPCExactPoint",1);
1793 for (Int_t i=0;i<160;i++){
1794 AliTPCTrackPoint *trpoint = (AliTPCTrackPoint*)fPoints->UncheckedAt(i);
1795 *trpoint = *(GetTrackPoint(i));
1800 //_____________________________________________________________________________
1801 void AliTPCseed::CookdEdx(Double_t low, Double_t up) {
1802 //-----------------------------------------------------------------
1803 // This funtion calculates dE/dX within the "low" and "up" cuts.
1804 //-----------------------------------------------------------------
1807 Float_t angular[200];
1808 Float_t weight[200];
1811 // TClonesArray & arr = *fPoints;
1812 Float_t meanlog = 100.;
1814 Float_t mean[4] = {0,0,0,0};
1815 Float_t sigma[4] = {1000,1000,1000,1000};
1816 Int_t nc[4] = {0,0,0,0};
1817 Float_t norm[4] = {1000,1000,1000,1000};
1822 for (Int_t of =0; of<4; of++){
1823 for (Int_t i=of;i<160;i+=4)
1825 //AliTPCTrackPoint * point = (AliTPCTrackPoint *) arr.At(i);
1826 AliTPCTrackPoint * point = GetTrackPoint(i);
1827 if (point==0) continue;
1828 if (point->fIsShared){
1832 if (point->GetCPoint().GetMax()<5) continue;
1833 Float_t angley = point->GetTPoint().GetAngleY();
1834 Float_t anglez = point->GetTPoint().GetAngleZ();
1835 Int_t type = point->GetCPoint().GetType();
1836 Float_t rsigmay = point->GetCPoint().GetSigmaY();
1837 Float_t rsigmaz = point->GetCPoint().GetSigmaZ();
1838 Float_t rsigma = TMath::Sqrt(rsigmay*rsigmaz);
1840 Float_t ampc = 0; // normalization to the number of electrons
1842 ampc = 1.*point->GetCPoint().GetMax();
1843 //ampc = 1.*point->GetCPoint().GetQ();
1844 // AliTPCClusterPoint & p = point->GetCPoint();
1845 // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.6)) - TMath::Abs(p.GetY()/0.6)+0.5);
1846 // Float_t iz = (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
1848 // TMath::Abs( Int_t(iz) - iz + 0.5);
1849 //ampc *= 1.15*(1-0.3*dy);
1850 //ampc *= 1.15*(1-0.3*dz);
1854 ampc = 1.0*point->GetCPoint().GetMax();
1855 //ampc = 1.0*point->GetCPoint().GetQ();
1856 //AliTPCClusterPoint & p = point->GetCPoint();
1857 // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.4)) - TMath::Abs(p.GetY()/0.4)+0.5);
1858 //Float_t iz = (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
1860 // TMath::Abs( Int_t(iz) - iz + 0.5);
1862 //ampc *= 1.15*(1-0.3*dy);
1863 //ampc *= 1.15*(1-0.3*dz);
1866 ampc *= 2.0; // put mean value to channel 50
1867 //ampc *= 0.58; // put mean value to channel 50
1869 // if (type>0) w = 1./(type/2.-0.5);
1876 if (type<0) { //amp at the border - lower weight
1880 if (rsigma>1.5) ampc/=1.3; // if big backround
1882 angular[nc[of]] = TMath::Sqrt(1.+angley*angley+anglez*anglez);
1887 TMath::Sort(nc[of],amp,index,kFALSE);
1891 //meanlog = amp[index[Int_t(nc[of]*0.33)]];
1893 for (Int_t i=int(nc[of]*low+0.5);i<int(nc[of]*up+0.5);i++){
1894 Float_t ampl = amp[index[i]]/angular[index[i]];
1895 ampl = meanlog*TMath::Log(1.+ampl/meanlog);
1897 sumw += weight[index[i]];
1898 sumamp += weight[index[i]]*ampl;
1899 sumamp2 += weight[index[i]]*ampl*ampl;
1900 norm[of] += angular[index[i]]*weight[index[i]];
1907 mean[of] = sumamp/sumw;
1908 sigma[of] = sumamp2/sumw-mean[of]*mean[of];
1910 sigma[of] = TMath::Sqrt(sigma[of]);
1914 mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
1915 //mean *=(1-0.02*(sigma/(mean*0.17)-1.));
1916 //mean *=(1-0.1*(norm-1.));
1923 // mean[0]*= (1-0.05*(sigma[0]/(0.01+mean[1]*0.18)-1));
1924 // mean[1]*= (1-0.05*(sigma[1]/(0.01+mean[0]*0.18)-1));
1927 // dedx = (mean[0]* TMath::Sqrt((1.+nc[0]))+ mean[1]* TMath::Sqrt((1.+nc[1])) )/
1928 // ( TMath::Sqrt((1.+nc[0]))+TMath::Sqrt((1.+nc[1])));
1932 for (Int_t i =0;i<4;i++){
1933 if (nc[i]>2&&nc[i]<1000){
1934 dedx += mean[i] *nc[i];
1935 fSdEdx += sigma[i]*(nc[i]-2);
1936 fMAngular += norm[i] *nc[i];
1941 fSDEDX[i] = sigma[i];
1954 // Float_t dedx1 =dedx;
1957 for (Int_t i =0;i<4;i++){
1958 if (nc[i]>2&&nc[i]<1000){
1959 mean[i] = mean[i]*(1-0.12*(sigma[i]/(fSdEdx)-1.));
1960 dedx += mean[i] *nc[i];
1975 Double_t p=TMath::Sqrt((1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt()));
1978 if (dedx < 39.+ 12./(p+0.25)/(p+0.25)) { SetMass(0.13957); return;}
1979 if (dedx < 39.+ 12./p/p) { SetMass(0.49368); return;}
1980 SetMass(0.93827); return;
1984 if (dedx < 39.+ 12./(p+0.25)/(p+0.25)) { SetMass(0.13957); return;}
1985 SetMass(0.93827); return;
1988 SetMass(0.13957); return;