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>
40 #include "Riostream.h"
42 #include "AliTPCtrackerMI.h"
43 #include "AliTPCclusterMI.h"
44 #include "AliTPCParam.h"
45 #include "AliTPCClustersRow.h"
46 #include "AliComplexCluster.h"
47 #include "AliTPCpolyTrack.h"
48 #include "TStopwatch.h"
52 ClassImp(AliTPCKalmanSegment)
56 //_____________________________________________________________________________
58 AliTPCKalmanSegment::AliTPCKalmanSegment(){
62 for (Int_t i=0;i<5;i++) fState[i] = 0.;
63 for (Int_t i=0;i<15;i++) fCovariance[i] = 0.;
69 //_____________________________________________________________________________
71 void AliTPCKalmanSegment::Init(AliTPCseed* seed)
74 // initial entrance integral chi2, fNCFoundable and fNC stored
75 fNCFoundable = seed->fNFoundable;
76 fNC = seed->GetNumberOfClusters();
77 fChi2 = seed->GetChi2();
81 void AliTPCKalmanSegment::Finish(AliTPCseed* seed)
84 // in finish state vector stored and chi2 and fNC... calculated
88 seed->GetExternalParameters(x,state);
89 seed->GetExternalCovariance(cov);
90 //float precision for tracklet
91 for (Int_t i=0;i<5;i++) fState[i] = state[i];
92 for (Int_t i=0;i<15;i++) fCovariance[i] = cov[i];
94 // in current seed integral track characteristic
95 // for tracklet differenciation between beginning (Init state) and Finish state
96 fNCFoundable = seed->fNFoundable - fNCFoundable;
97 fNC = seed->GetNumberOfClusters() - fNC;
98 fChi2 = seed->GetChi2()-fChi2;
102 void AliTPCKalmanSegment::GetState(Double_t &x, Double_t & alpha, Double_t state[5])
107 for (Int_t i=0;i<5;i++) state[i] = fState[i];
110 void AliTPCKalmanSegment::GetCovariance(Double_t covariance[15])
113 for (Int_t i=0;i<5;i++) covariance[i] = fCovariance[i];
116 void AliTPCKalmanSegment::GetStatistic(Int_t & nclusters, Int_t & nfoundable, Float_t & chi2)
121 nfoundable = fNCFoundable;
127 AliTPCclusterTracks::AliTPCclusterTracks(){
128 // class for storing overlaping info
145 Int_t AliTPCtrackerMI::UpdateTrack(AliTPCseed * track, AliTPCclusterMI* c, Double_t chi2, UInt_t i){
147 Int_t sec=(i&0xff000000)>>24;
148 Int_t row = (i&0x00ff0000)>>16;
149 track->fRow=(i&0x00ff0000)>>16;
150 track->fSector = sec;
151 // Int_t index = i&0xFFFF;
152 if (sec>=fParam->GetNInnerSector()) track->fRow += fParam->GetNRowLow();
153 track->fClusterIndex[track->fRow] = i;
154 track->fFirstPoint = row;
155 if ( track->fLastPoint<row) track->fLastPoint =row;
158 AliTPCTrackPoint *trpoint =track->GetTrackPoint(track->fRow);
159 Float_t angle2 = track->GetSnp()*track->GetSnp();
160 angle2 = TMath::Sqrt(angle2/(1-angle2));
162 //SET NEW Track Point
165 //if we have a cluster
166 trpoint->GetCPoint().SetY(c->GetY());
167 trpoint->GetCPoint().SetZ(c->GetZ());
169 trpoint->GetCPoint().SetSigmaY(c->GetSigmaY2()/(track->fCurrentSigmaY*track->fCurrentSigmaY));
170 trpoint->GetCPoint().SetSigmaZ(c->GetSigmaZ2()/(track->fCurrentSigmaZ*track->fCurrentSigmaZ));
172 trpoint->GetCPoint().SetType(c->GetType());
173 trpoint->GetCPoint().SetQ(c->GetQ());
174 trpoint->GetCPoint().SetMax(c->GetMax());
176 trpoint->GetCPoint().SetErrY(TMath::Sqrt(track->fErrorY2));
177 trpoint->GetCPoint().SetErrZ(TMath::Sqrt(track->fErrorZ2));
180 trpoint->GetTPoint().SetX(track->GetX());
181 trpoint->GetTPoint().SetY(track->GetY());
182 trpoint->GetTPoint().SetZ(track->GetZ());
184 trpoint->GetTPoint().SetAngleY(angle2);
185 trpoint->GetTPoint().SetAngleZ(track->GetTgl());
190 // printf("suspicious chi2 %f\n",chi2);
192 // if (track->fIsSeeding){
193 track->fErrorY2 *= 1.2;
194 track->fErrorY2 += 0.0064;
195 track->fErrorZ2 *= 1.2;
196 track->fErrorY2 += 0.005;
200 return track->Update(c,chi2,i);
203 //_____________________________________________________________________________
204 AliTPCtrackerMI::AliTPCtrackerMI(const AliTPCParam *par, Int_t eventn):
205 AliTracker(), fkNIS(par->GetNInnerSector()/2), fkNOS(par->GetNOuterSector()/2)
207 //---------------------------------------------------------------------
208 // The main TPC tracker constructor
209 //---------------------------------------------------------------------
210 fInnerSec=new AliTPCSector[fkNIS];
211 fOuterSec=new AliTPCSector[fkNOS];
214 for (i=0; i<fkNIS; i++) fInnerSec[i].Setup(par,0);
215 for (i=0; i<fkNOS; i++) fOuterSec[i].Setup(par,1);
219 fClustersArray.Setup(par);
220 fClustersArray.SetClusterType("AliTPCclusterMI");
224 sprintf(cname,"TreeC_TPC");
227 sprintf(cname,"TreeC_TPC_%d",eventn);
230 fClustersArray.ConnectTree(cname);
238 //_____________________________________________________________________________
239 AliTPCtrackerMI::~AliTPCtrackerMI() {
240 //------------------------------------------------------------------
241 // TPC tracker destructor
242 //------------------------------------------------------------------
252 Double_t AliTPCtrackerMI::ErrY2(AliTPCseed* seed, AliTPCclusterMI * cl){
256 Float_t z = TMath::Abs(fParam->GetZLength()-TMath::Abs(seed->GetZ()));
262 //standard if we don't have cluster - take MIP
263 const Float_t chmip = 50.;
264 Float_t amp = chmip/0.3;
269 rsigmay = cl->GetSigmaY2()/(seed->fCurrentSigmaY*seed->fCurrentSigmaY);
270 ctype = cl->GetType();
274 Float_t landau=2 ; //landau fluctuation part
275 Float_t gg=2; // gg fluctuation part
276 Float_t padlength= fSectors->GetPadPitchLength(seed->GetX());
279 if (fSectors==fInnerSec){
283 gg = (2+0.0002*amp)/nel;
284 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
285 if (landau>1) landau=1;
291 gg = (2+0.0002*amp)/nel;
292 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
293 if (landau>1) landau=1;
297 Float_t sdiff = gg*fParam->GetDiffT()*fParam->GetDiffT()*z;
298 Float_t angle2 = seed->GetSnp()*seed->GetSnp();
299 angle2 = angle2/(1-angle2);
300 Float_t angular = landau*angle2*padlength*padlength/12.;
301 Float_t res = sdiff + angular;
304 if ((ctype==0) && (fSectors ==fOuterSec))
305 res *= 0.78 +TMath::Exp(7.4*(rsigmay-1.2));
307 if ((ctype==0) && (fSectors ==fInnerSec))
308 res *= 0.72 +TMath::Exp(3.36*(rsigmay-1.2));
312 res*= TMath::Power((rsigmay+0.5),1.5)+0.0064;
315 res*=2.4; // overestimate error 2 times
322 seed->SetErrorY2(res);
329 Double_t AliTPCtrackerMI::ErrZ2(AliTPCseed* seed, AliTPCclusterMI * cl){
333 Float_t z = TMath::Abs(fParam->GetZLength()-TMath::Abs(seed->GetZ()));
338 const Float_t chmip = 50.;
339 Float_t amp = chmip/0.3;
344 rsigmaz = cl->GetSigmaZ2()/(seed->fCurrentSigmaZ*seed->fCurrentSigmaZ);
345 ctype = cl->GetType();
349 Float_t landau=2 ; //landau fluctuation part
350 Float_t gg=2; // gg fluctuation part
351 Float_t padlength= fSectors->GetPadPitchLength(seed->GetX());
353 if (fSectors==fInnerSec){
357 gg = (2+0.0002*amp)/nel;
358 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
359 if (landau>1) landau=1;
365 gg = (2+0.0002*amp)/nel;
366 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
367 if (landau>1) landau=1;
369 Float_t sdiff = gg*fParam->GetDiffT()*fParam->GetDiffT()*z;
371 Float_t angle = seed->GetTgl();
372 Float_t angular = landau*angle*angle*padlength*padlength/12.;
373 Float_t res = sdiff + angular;
375 if ((ctype==0) && (fSectors ==fOuterSec))
376 res *= 0.81 +TMath::Exp(6.8*(rsigmaz-1.2));
378 if ((ctype==0) && (fSectors ==fInnerSec))
379 res *= 0.72 +TMath::Exp(2.04*(rsigmaz-1.2));
381 res*= TMath::Power(rsigmaz+0.5,1.5)+0.0064; //0.31+0.147*ctype;
384 if ((ctype<0) &&<70)
391 seed->SetErrorZ2(res);
399 void AliTPCseed::Reset()
406 for (Int_t i=0;i<200;i++) fClusterIndex[i]=-1;
410 Int_t AliTPCseed::GetProlongation(Double_t xk, Double_t &y, Double_t & z) const
412 //-----------------------------------------------------------------
413 // This function find proloncation of a track to a reference plane x=xk.
414 // doesn't change internal state of the track
415 //-----------------------------------------------------------------
417 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1;
418 // Double_t y1=fP0, z1=fP1;
419 Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
420 Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
424 y += dx*(c1+c2)/(r1+r2);
425 z += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
430 //_____________________________________________________________________________
431 Double_t AliTPCseed::GetPredictedChi2(const AliTPCclusterMI *c) const
433 //-----------------------------------------------------------------
434 // This function calculates a predicted chi2 increment.
435 //-----------------------------------------------------------------
436 //Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
437 Double_t r00=fErrorY2, r01=0., r11=fErrorZ2;
438 r00+=fC00; r01+=fC10; r11+=fC11;
440 Double_t det=r00*r11 - r01*r01;
441 if (TMath::Abs(det) < 1.e-10) {
442 Int_t n=GetNumberOfClusters();
443 if (n>4) cerr<<n<<" AliKalmanTrack warning: Singular matrix !\n";
446 Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
448 Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
450 return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
454 //_________________________________________________________________________________________
457 Int_t AliTPCseed::Compare(const TObject *o) const {
458 //-----------------------------------------------------------------
459 // This function compares tracks according to the sector - for given sector according z
460 //-----------------------------------------------------------------
461 AliTPCseed *t=(AliTPCseed*)o;
462 if (t->fRelativeSector>fRelativeSector) return -1;
463 if (t->fRelativeSector<fRelativeSector) return 1;
465 Double_t z2 = t->GetZ();
466 Double_t z1 = GetZ();
468 if (z2<z1) return -1;
472 void AliTPCtrackerMI::RotateToLocal(AliTPCseed *seed)
474 //rotate to track "local coordinata
475 Float_t x = seed->GetX();
476 Float_t y = seed->GetY();
477 Float_t ymax = x*TMath::Tan(0.5*fSectors->GetAlpha());
479 seed->fRelativeSector= (seed->fRelativeSector+1) % fN;
480 if (!seed->Rotate(fSectors->GetAlpha()))
482 } else if (y <-ymax) {
483 seed->fRelativeSector= (seed->fRelativeSector-1+fN) % fN;
484 if (!seed->Rotate(-fSectors->GetAlpha()))
493 //_____________________________________________________________________________
494 Int_t AliTPCseed::Update(const AliTPCclusterMI *c, Double_t chisq, UInt_t index) {
495 //-----------------------------------------------------------------
496 // This function associates a cluster with this track.
497 //-----------------------------------------------------------------
498 // Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
499 //Double_t r00=sigmay2, r01=0., r11=sigmaz2;
500 Double_t r00=fErrorY2, r01=0., r11=fErrorZ2;
502 r00+=fC00; r01+=fC10; r11+=fC11;
503 Double_t det=r00*r11 - r01*r01;
504 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
506 Double_t k00=fC00*r00+fC10*r01, k01=fC00*r01+fC10*r11;
507 Double_t k10=fC10*r00+fC11*r01, k11=fC10*r01+fC11*r11;
508 Double_t k20=fC20*r00+fC21*r01, k21=fC20*r01+fC21*r11;
509 Double_t k30=fC30*r00+fC31*r01, k31=fC30*r01+fC31*r11;
510 Double_t k40=fC40*r00+fC41*r01, k41=fC40*r01+fC41*r11;
512 Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
513 Double_t cur=fP4 + k40*dy + k41*dz, eta=fP2 + k20*dy + k21*dz;
514 if (TMath::Abs(cur*fX-eta) >= 0.9) {
515 // Int_t n=GetNumberOfClusters();
516 //if (n>4) cerr<<n<<" AliTPCtrack warning: Filtering failed !\n";
520 fP0 += k00*dy + k01*dz;
521 fP1 += k10*dy + k11*dz;
523 fP3 += k30*dy + k31*dz;
526 Double_t c01=fC10, c02=fC20, c03=fC30, c04=fC40;
527 Double_t c12=fC21, c13=fC31, c14=fC41;
529 fC00-=k00*fC00+k01*fC10; fC10-=k00*c01+k01*fC11;
530 fC20-=k00*c02+k01*c12; fC30-=k00*c03+k01*c13;
531 fC40-=k00*c04+k01*c14;
533 fC11-=k10*c01+k11*fC11;
534 fC21-=k10*c02+k11*c12; fC31-=k10*c03+k11*c13;
535 fC41-=k10*c04+k11*c14;
537 fC22-=k20*c02+k21*c12; fC32-=k20*c03+k21*c13;
538 fC42-=k20*c04+k21*c14;
540 fC33-=k30*c03+k31*c13;
541 fC43-=k40*c03+k41*c13;
543 fC44-=k40*c04+k41*c14;
545 Int_t n=GetNumberOfClusters();
547 SetNumberOfClusters(n+1);
548 SetChi2(GetChi2()+chisq);
555 //_____________________________________________________________________________
556 Double_t AliTPCtrackerMI::f1(Double_t x1,Double_t y1,
557 Double_t x2,Double_t y2,
558 Double_t x3,Double_t y3)
560 //-----------------------------------------------------------------
561 // Initial approximation of the track curvature
562 //-----------------------------------------------------------------
563 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
564 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
565 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
566 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
567 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
569 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
571 return -xr*yr/sqrt(xr*xr+yr*yr);
575 //_____________________________________________________________________________
576 Double_t AliTPCtrackerMI::f2(Double_t x1,Double_t y1,
577 Double_t x2,Double_t y2,
578 Double_t x3,Double_t y3)
580 //-----------------------------------------------------------------
581 // Initial approximation of the track curvature times center of curvature
582 //-----------------------------------------------------------------
583 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
584 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
585 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
586 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
587 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
589 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
591 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
594 //_____________________________________________________________________________
595 Double_t AliTPCtrackerMI::f3(Double_t x1,Double_t y1,
596 Double_t x2,Double_t y2,
597 Double_t z1,Double_t z2)
599 //-----------------------------------------------------------------
600 // Initial approximation of the tangent of the track dip angle
601 //-----------------------------------------------------------------
602 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
606 void AliTPCtrackerMI::LoadClusters()
609 // load clusters to the memory
610 Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
611 for (Int_t i=0; i<j; i++) {
612 fClustersArray.LoadEntry(i);
616 void AliTPCtrackerMI::UnloadClusters()
619 // load clusters to the memory
620 Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
621 for (Int_t i=0; i<j; i++) {
622 fClustersArray.ClearSegment(i);
628 //_____________________________________________________________________________
629 void AliTPCtrackerMI::LoadOuterSectors() {
630 //-----------------------------------------------------------------
631 // This function fills outer TPC sectors with clusters.
632 //-----------------------------------------------------------------
634 //Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
635 Int_t j = ((AliTPCParam*)fParam)->GetNRowsTotal();
636 for (Int_t i=0; i<j; i++) {
637 // AliSegmentID *s=fClustersArray.LoadEntry(i);
638 AliSegmentID *s= const_cast<AliSegmentID*>(fClustersArray.At(i));
641 AliTPCParam *par=(AliTPCParam*)fClustersArray.GetParam();
642 par->AdjustSectorRow(s->GetID(),sec,row);
643 if (sec<fkNIS*2) continue;
644 AliTPCClustersRow *clrow=fClustersArray.GetRow(sec,row);
645 Int_t ncl=clrow->GetArray()->GetEntriesFast();
647 AliTPCclusterMI *c=(AliTPCclusterMI*)(*clrow)[ncl];
648 index=(((sec<<8)+row)<<16)+ncl;
649 fOuterSec[(sec-fkNIS*2)%fkNOS][row].InsertCluster(c,index);
657 //_____________________________________________________________________________
658 void AliTPCtrackerMI::LoadInnerSectors() {
659 //-----------------------------------------------------------------
660 // This function fills inner TPC sectors with clusters.
661 //-----------------------------------------------------------------
663 //Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
664 Int_t j = ((AliTPCParam*)fParam)->GetNRowsTotal();
665 for (Int_t i=0; i<j; i++) {
666 // AliSegmentID *s=fClustersArray.LoadEntry(i);
667 AliSegmentID *s=const_cast<AliSegmentID*>(fClustersArray.At(i));
670 AliTPCParam *par=(AliTPCParam*)fClustersArray.GetParam();
671 par->AdjustSectorRow(s->GetID(),sec,row);
672 if (sec>=fkNIS*2) continue;
673 AliTPCClustersRow *clrow=fClustersArray.GetRow(sec,row);
674 Int_t ncl=clrow->GetArray()->GetEntriesFast();
676 AliTPCclusterMI *c=(AliTPCclusterMI*)(*clrow)[ncl];
677 index=(((sec<<8)+row)<<16)+ncl;
678 fInnerSec[sec%fkNIS][row].InsertCluster(c,index);
686 Int_t AliTPCtrackerMI::FollowToNext(AliTPCseed& t, Int_t nr) {
687 //-----------------------------------------------------------------
688 // This function tries to find a track prolongation to next pad row
689 //-----------------------------------------------------------------
690 // Double_t xt=t.GetX();
691 // Int_t row = fSectors->GetRowNumber(xt)-1;
692 // if (row < nr) return 1; // don't prolongate if not information until now -
694 Double_t x=fSectors->GetX(nr), ymax=fSectors->GetMaxY(nr);
695 // if (t.GetRadius()>x+10 ) return 0;
697 if (!t.PropagateTo(x)) {
702 t.fCurrentSigmaY = GetSigmaY(&t);
703 t.fCurrentSigmaZ = GetSigmaZ(&t);
705 AliTPCclusterMI *cl=0;
707 const AliTPCRow &krow=fSectors[t.fRelativeSector][nr];
708 Double_t sy2=ErrY2(&t)*2;
709 Double_t sz2=ErrZ2(&t)*2;
712 Double_t roady =3.*sqrt(t.GetSigmaY2() + sy2);
713 Double_t roadz = 3 *sqrt(t.GetSigmaZ2() + sz2);
714 Double_t y=t.GetY(), z=t.GetZ();
716 if (TMath::Abs(TMath::Abs(y)-ymax)<krow.fDeadZone){
719 if (fSectors==fOuterSec) row += fParam->GetNRowLow();
720 t.fClusterIndex[row] = -1;
725 if (TMath::Abs(z)<(1.05*x+10)) t.fNFoundable++;
730 Float_t maxdistance = roady*roady + roadz*roadz;
732 for (Int_t i=krow.Find(z-roadz); i<krow; i++) {
733 AliTPCclusterMI *c=(AliTPCclusterMI*)(krow[i]);
734 if (c->GetZ() > z+roadz) break;
735 if ( (c->GetY()-y) > roady ) continue;
736 Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
737 if (maxdistance>distance) {
738 maxdistance = distance;
740 // index=krow.GetIndex(i);
746 // Double_t sy2= ErrY2(&t,cl);
747 // Double_t sz2= ErrZ2(&t,cl);
748 // Double_t chi2= t.GetPredictedChi2(cl);
749 // UpdateTrack(&t,cl,chi2,index);
751 t.fCurrentCluster = cl;
752 t.fCurrentClusterIndex1 = krow.GetIndex(index);
753 t.fCurrentClusterIndex2 = index;
754 Double_t sy2=ErrY2(&t,t.fCurrentCluster);
755 Double_t sz2=ErrZ2(&t,t.fCurrentCluster);
757 Double_t sdistancey = TMath::Sqrt(sy2+t.GetSigmaY2());
758 Double_t sdistancez = TMath::Sqrt(sz2+t.GetSigmaZ2());
760 Double_t rdistancey = TMath::Abs(t.fCurrentCluster->GetY()-t.GetY());
761 Double_t rdistancez = TMath::Abs(t.fCurrentCluster->GetZ()-t.GetZ());
763 Double_t rdistance = TMath::Sqrt(TMath::Power(rdistancey/sdistancey,2)+TMath::Power(rdistancez/sdistancez,2));
766 // printf("\t%f\t%f\t%f\n",rdistancey/sdistancey,rdistancez/sdistancez,rdistance);
767 if ( (rdistancey>1) || (rdistancez>1)) return 0;
768 if (rdistance>4) return 0;
770 if ((rdistancey/sdistancey>2.5 || rdistancez/sdistancez>2.5) && t.fCurrentCluster->GetType()==0)
771 return 0; //suspisiouce - will be changed
773 if ((rdistancey/sdistancey>2. || rdistancez/sdistancez>2.0) && t.fCurrentCluster->GetType()>0)
774 // strict cut on overlaped cluster
775 return 0; //suspisiouce - will be changed
777 if ( (rdistancey/sdistancey>1. || rdistancez/sdistancez>2.5 ||t.fCurrentCluster->GetQ()<70 )
778 && t.fCurrentCluster->GetType()<0)
781 // t.SetSampledEdx(0.3*t.fCurrentCluster->GetQ()/l,t.GetNumberOfClusters(), GetSigmaY(&t), GetSigmaZ(&t));
782 UpdateTrack(&t,t.fCurrentCluster,t.GetPredictedChi2(t.fCurrentCluster),t.fCurrentClusterIndex1);
786 t.fRelativeSector= (t.fRelativeSector+1) % fN;
787 if (!t.Rotate(fSectors->GetAlpha()))
789 } else if (y <-ymax) {
790 t.fRelativeSector= (t.fRelativeSector-1+fN) % fN;
791 if (!t.Rotate(-fSectors->GetAlpha()))
799 Int_t AliTPCtrackerMI::UpdateClusters(AliTPCseed& t,Int_t trindex, Int_t nr) {
800 //-----------------------------------------------------------------
801 // This function tries to find a track prolongation to next pad row
802 //-----------------------------------------------------------------
803 t.fCurrentCluster = 0;
804 t.fCurrentClusterIndex1 = 0;
805 t.fCurrentClusterIndex2 = 0;
807 Double_t xt=t.GetX();
808 Int_t row = fSectors->GetRowNumber(xt)-1;
809 if (row < nr) return 1; // don't prolongate if not information until now -
810 Double_t x=fSectors->GetX(nr);
811 // if (t.fStopped) return 0;
812 // if (t.GetRadius()>x+10 ) return 0;
813 if (!t.PropagateTo(x)){
818 t.fCurrentSigmaY = GetSigmaY(&t);
819 t.fCurrentSigmaZ = GetSigmaZ(&t);
821 AliTPCclusterMI *cl=0;
823 AliTPCRow &krow=fSectors[t.fRelativeSector][nr];
825 Double_t y=t.GetY(), z=t.GetZ();
826 Double_t roady = 3.* TMath::Sqrt(t.GetSigmaY2() + t.fCurrentSigmaY*t.fCurrentSigmaY);
827 Double_t roadz = 3.* TMath::Sqrt(t.GetSigmaZ2() + t.fCurrentSigmaZ*t.fCurrentSigmaZ);
830 Float_t maxdistance = 1000000;
832 for (Int_t i=krow.Find(z-roadz); i<krow; i++) {
833 AliTPCclusterMI *c=(AliTPCclusterMI*)(krow[i]);
834 if (c->GetZ() > z+roadz) break;
835 if (TMath::Abs(c->GetY()-y)>roady) continue;
837 //krow.UpdateClusterTrack(i,trindex,&t);
839 Float_t dy2 = (c->GetY()- t.GetY());
841 Float_t dz2 = (c->GetZ()- t.GetZ());
844 Float_t distance = dy2+dz2;
846 if (distance > maxdistance) continue;
847 maxdistance = distance;
852 t.fCurrentCluster = cl;
853 t.fCurrentClusterIndex1 = krow.GetIndex(index);
854 t.fCurrentClusterIndex2 = index;
859 Int_t AliTPCtrackerMI::FollowToNextCluster(Int_t trindex, Int_t nr) {
860 //-----------------------------------------------------------------
861 // This function tries to find a track prolongation to next pad row
862 //-----------------------------------------------------------------
863 AliTPCseed & t = *((AliTPCseed*)(fSeeds->At(trindex)));
864 AliTPCRow &krow=fSectors[t.fRelativeSector][nr];
865 // Double_t pt=t.GetConvConst()/(100/0.299792458/0.2)/t.Get1Pt();
867 Double_t ymax=fSectors->GetMaxY(nr);
869 if (TMath::Abs(TMath::Abs(y)-ymax)<krow.fDeadZone){
872 if (fSectors==fOuterSec) row += fParam->GetNRowLow();
873 t.fClusterIndex[row] = -1;
878 if (TMath::Abs(t.GetZ())<(1.05*t.GetX()+10)) t.fNFoundable++;
883 if (t.fCurrentCluster) {
884 // Float_t l=fSectors->GetPadPitchLength();
885 // AliTPCclusterTracks * cltrack = krow.GetClusterTracks(t.fCurrentClusterIndex1);
887 Double_t sy2=ErrY2(&t,t.fCurrentCluster);
888 Double_t sz2=ErrZ2(&t,t.fCurrentCluster);
891 Double_t sdistancey = TMath::Sqrt(sy2+t.GetSigmaY2());
892 Double_t sdistancez = TMath::Sqrt(sz2+t.GetSigmaZ2());
894 Double_t rdistancey = TMath::Abs(t.fCurrentCluster->GetY()-t.GetY());
895 Double_t rdistancez = TMath::Abs(t.fCurrentCluster->GetZ()-t.GetZ());
897 Double_t rdistance = TMath::Sqrt(TMath::Power(rdistancey/sdistancey,2)+TMath::Power(rdistancez/sdistancez,2));
900 // printf("\t%f\t%f\t%f\n",rdistancey/sdistancey,rdistancez/sdistancez,rdistance);
901 if ( (rdistancey>1) || (rdistancez>1)) return 0;
902 if (rdistance>4) return 0;
904 if ((rdistancey/sdistancey>2.5 || rdistancez/sdistancez>2.5) && t.fCurrentCluster->GetType()==0)
905 return 0; //suspisiouce - will be changed
907 if ((rdistancey/sdistancey>2. || rdistancez/sdistancez>2.0) && t.fCurrentCluster->GetType()>0)
908 // strict cut on overlaped cluster
909 return 0; //suspisiouce - will be changed
911 if ( (rdistancey/sdistancey>1. || rdistancez/sdistancez>2.5 ||t.fCurrentCluster->GetQ()<70 )
912 && t.fCurrentCluster->GetType()<0)
915 // t.SetSampledEdx(0.3*t.fCurrentCluster->GetQ()/l,t.GetNumberOfClusters(), GetSigmaY(&t), GetSigmaZ(&t));
916 UpdateTrack(&t,t.fCurrentCluster,t.GetPredictedChi2(t.fCurrentCluster),t.fCurrentClusterIndex1);
920 t.fRelativeSector= (t.fRelativeSector+1) % fN;
921 if (!t.Rotate(fSectors->GetAlpha()))
923 } else if (y <-ymax) {
924 t.fRelativeSector= (t.fRelativeSector-1+fN) % fN;
925 if (!t.Rotate(-fSectors->GetAlpha()))
936 Int_t AliTPCtrackerMI::FollowProlongationFast(AliTPCseed& t, Int_t step)
938 //-----------------------------------------------------------------
939 // fast prolongation mathod -
940 // don't update track only after step clusters
941 //-----------------------------------------------------------------
942 Double_t xt=t.GetX();
944 Double_t alpha=t.GetAlpha();
945 alpha =- fSectors->GetAlphaShift();
946 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
947 if (alpha < 0. ) alpha += 2.*TMath::Pi();
948 t.fRelativeSector = Int_t(alpha/fSectors->GetAlpha())%fN;
949 Int_t row0 = fSectors->GetRowNumber(xt);
950 Double_t x = fSectors->GetX(row0);
951 Double_t ymax = fSectors->GetMaxY(row0);
953 Double_t sy2=ErrY2(&t)*2;
954 Double_t sz2=ErrZ2(&t)*2;
955 Double_t roady =3.*sqrt(t.GetSigmaY2() + sy2);
956 Double_t roadz = 3 *sqrt(t.GetSigmaZ2() + sz2);
957 Float_t maxdistance = roady*roady + roadz*roadz;
958 t.fCurrentSigmaY = GetSigmaY(&t);
959 t.fCurrentSigmaZ = GetSigmaZ(&t);
964 Double_t yy[200]; //track prolongation
966 Double_t cy[200]; // founded cluster position
968 Double_t sy[200]; // founded cluster error
970 Bool_t hitted[200]; // indication of cluster presence
974 for (Int_t drow = step; drow>=0; drow--) {
975 Int_t row = row0-drow;
977 Double_t x = fSectors->GetX(row);
978 Double_t ymax = fSectors->GetMaxY(row);
979 t.GetProlongation(x,y,z);
982 const AliTPCRow &krow=fSectors[t.fRelativeSector][row];
983 if (TMath::Abs(TMath::Abs(y)-ymax)<krow.fDeadZone){
992 //find nearest cluster
993 AliTPCclusterMI *cl= 0;
995 for (Int_t i=krow.Find(z-roadz); i<krow; i++) {
996 AliTPCclusterMI *c=(AliTPCclusterMI*)(krow[i]);
997 if (c->GetZ() > z+roadz) break;
998 if ( (c->GetY()-y) > roady ) continue;
999 Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
1000 if (maxdistance>distance) {
1001 maxdistance = distance;
1003 // index=krow.GetIndex(i);
1007 //update cluster information
1009 cy[drow] = cl->GetY();
1010 cz[drow] = cl->GetZ();
1011 sy[drow] = ErrY2(&t,cl);
1012 sz[drow] = ErrZ2(&t,cl);
1013 hitted[drow] = kTRUE;
1017 hitted[drow] = kFALSE;
1019 //if we have information - update track
1026 for (Int_t i=0;i<step;i++)
1031 sumyw+= (cy[i]-yy[i])/sy[i];
1032 sumzw+= (cz[i]-zz[i])/sz[i];
1035 Float_t dy = sumyw/sumyw0;
1036 Float_t dz = sumzw/sumzw0;
1037 Float_t mrow = sumrow/nclusters+row0;
1038 Float_t x = fSectors->GetX(mrow);
1040 AliTPCclusterMI cvirtual;
1041 cvirtual.SetZ(dz+t.GetZ());
1042 cvirtual.SetY(dy+t.GetY());
1043 t.SetErrorY2(1.2*t.fErrorY2/TMath::Sqrt(Float_t(nclusters)));
1044 t.SetErrorZ2(1.2*t.fErrorZ2/TMath::Sqrt(Float_t(nclusters)));
1045 Float_t chi2 = t.GetPredictedChi2(&cvirtual);
1046 t.Update(&cvirtual,chi2,0);
1047 Int_t ncl = t.GetNumberOfClusters();
1048 ncl = ncl-1+nclusters;
1055 //_____________________________________________________________________________
1056 Int_t AliTPCtrackerMI::FollowProlongation(AliTPCseed& t, Int_t rf) {
1057 //-----------------------------------------------------------------
1058 // This function tries to find a track prolongation.
1059 //-----------------------------------------------------------------
1060 Double_t xt=t.GetX();
1062 Double_t alpha=t.GetAlpha() - fSectors->GetAlphaShift();
1063 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
1064 if (alpha < 0. ) alpha += 2.*TMath::Pi();
1065 t.fRelativeSector = Int_t(alpha/fSectors->GetAlpha())%fN;
1067 for (Int_t nr=fSectors->GetRowNumber(xt)-1; nr>=rf; nr--) {
1069 if (FollowToNext(t,nr)==0) {
1076 //_____________________________________________________________________________
1077 Int_t AliTPCtrackerMI::FollowBackProlongation(AliTPCseed& t, Int_t rf) {
1078 //-----------------------------------------------------------------
1079 // This function tries to find a track prolongation.
1080 //-----------------------------------------------------------------
1081 Double_t xt=t.GetX();
1083 Double_t alpha=t.GetAlpha() - fSectors->GetAlphaShift();
1084 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
1085 if (alpha < 0. ) alpha += 2.*TMath::Pi();
1086 t.fRelativeSector = Int_t(alpha/fSectors->GetAlpha())%fN;
1088 for (Int_t nr=fSectors->GetRowNumber(xt)+1; nr<=rf; nr++) {
1099 Float_t AliTPCtrackerMI::OverlapFactor(AliTPCseed * s1, AliTPCseed * s2, Int_t &sum1, Int_t & sum2)
1107 Float_t dz2 =(s1->GetZ() - s2->GetZ());
1110 Float_t x = s1->GetX();
1111 Float_t x2 = s2->GetX();
1113 Float_t ymax = x*TMath::Tan(0.5*fSectors->GetAlpha());
1115 Float_t dy2 =TMath::Abs((s1->GetY() - s2->GetY()));
1116 //if (TMath::Abs(dy2)>2*ymax-3)
1119 Float_t distance = TMath::Sqrt(dz2+dy2);
1120 if (distance>4.) return 0; // if there are far away - not overlap - to reduce combinatorics
1123 if (fSectors==fOuterSec) offset = fParam->GetNRowLow();
1124 Int_t firstpoint = TMath::Min(s1->fFirstPoint,s2->fFirstPoint);
1125 Int_t lastpoint = TMath::Max(s1->fLastPoint,s2->fLastPoint);
1132 if (firstpoint<lastpoint-15) {
1138 for (Int_t i=firstpoint;i<lastpoint;i++){
1139 if (s1->fClusterIndex[i]>0) sum1++;
1140 if (s2->fClusterIndex[i]>0) sum2++;
1141 if (s1->fClusterIndex[i]==s2->fClusterIndex[i] && s1->fClusterIndex[i]>0) {
1146 Float_t summin = TMath::Min(sum1+1,sum2+1);
1147 Float_t ratio = (sum+1)/Float_t(summin);
1151 void AliTPCtrackerMI::SignShared(AliTPCseed * s1, AliTPCseed * s2)
1155 if (s1->fSector!=s2->fSector) return;
1157 Float_t dz2 =(s1->GetZ() - s2->GetZ());
1159 Float_t dy2 =(s1->GetY() - s2->GetY());
1162 Float_t distance = TMath::Sqrt(dz2+dy2);
1163 if (distance>15.) return ; // if there are far away - not overlap - to reduce combinatorics
1164 //trpoint = new (pointarray[track->fRow]) AliTPCTrackPoint;
1165 // TClonesArray &pointarray1 = *(s1->fPoints);
1166 //TClonesArray &pointarray2 = *(s2->fPoints);
1168 for (Int_t i=0;i<160;i++){
1169 if (s1->fClusterIndex[i]==s2->fClusterIndex[i] && s1->fClusterIndex[i]>0) {
1170 // AliTPCTrackPoint *p1 = (AliTPCTrackPoint *)(pointarray1.UncheckedAt(i));
1171 //AliTPCTrackPoint *p2 = (AliTPCTrackPoint *)(pointarray2.UncheckedAt(i));
1172 AliTPCTrackPoint *p1 = s1->GetTrackPoint(i);
1173 AliTPCTrackPoint *p2 = s2->GetTrackPoint(i);;
1174 p1->fIsShared = kTRUE;
1175 p2->fIsShared = kTRUE;
1183 void AliTPCtrackerMI::RemoveOverlap(TObjArray * arr, Float_t factor, Int_t removalindex , Bool_t shared){
1188 // remove overlap - used removal factor - removal index stored in the track
1189 for (Int_t i=0; i<arr->GetEntriesFast(); i++) {
1190 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1191 if (pt) RotateToLocal(pt);
1193 arr->Sort(); // sorting according z
1194 arr->Expand(arr->GetEntries());
1195 Int_t nseed=arr->GetEntriesFast();
1196 // printf("seeds \t%p \t%d\n",arr, nseed);
1197 // arr->Expand(arr->GetEntries()); //remove 0 pointers
1198 nseed = arr->GetEntriesFast();
1200 for (Int_t i=0; i<nseed; i++) {
1201 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1205 if (!(pt->IsActive())) continue;
1206 for (Int_t j=i+1; j<nseed; j++){
1207 AliTPCseed *pt2=(AliTPCseed*)arr->UncheckedAt(j);
1210 if (!(pt2->IsActive())) continue;
1211 if (TMath::Abs(pt->fRelativeSector-pt2->fRelativeSector)>0) break;
1212 if (TMath::Abs(pt2->GetZ()-pt->GetZ())<4){
1214 Float_t ratio = OverlapFactor(pt,pt2,sum1,sum2);
1216 // pt->Desactivate(removalindex); // arr->RemoveAt(i);
1220 // if (pt->GetChi2()<pt2->GetChi2()) pt2->Desactivate(removalindex); // arr->RemoveAt(j);
1221 Float_t ratio2 = (pt->GetChi2()*sum2)/(pt2->GetChi2()*sum1);
1222 Float_t ratio3 = Float_t(sum1-sum2)/Float_t(sum1+sum2);
1224 if (TMath::Abs(ratio3)>0.025){ // if much more points
1225 if (sum1>sum2) pt2->Desactivate(removalindex);
1227 pt->Desactivate(removalindex); // arr->RemoveAt(i);
1231 else{ //decide on mean chi2
1233 pt2->Desactivate(removalindex);
1235 pt->Desactivate(removalindex); // arr->RemoveAt(i);
1240 } // if suspicious ratio
1246 // printf("removed\t%d\n",removed);
1248 for (Int_t i=0; i<nseed; i++) {
1249 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1251 if (pt->GetNumberOfClusters() < pt->fNFoundable*0.5) {
1252 //desactivate tracks with small number of points
1253 // printf("%d\t%d\t%f\n", pt->GetNumberOfClusters(), pt->fNFoundable,pt->GetNumberOfClusters()/Float_t(pt->fNFoundable));
1254 pt->Desactivate(10); //desactivate - small muber of points
1256 if (!(pt->IsActive())) continue;
1262 for (Int_t i=0; i<nseed; i++) {
1263 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1265 if (!(pt->IsActive())) continue;
1266 for (Int_t j=i+1; j<nseed; j++){
1267 AliTPCseed *pt2=(AliTPCseed*)arr->UncheckedAt(j);
1268 if ((pt2) && pt2->IsActive()) {
1269 if ( TMath::Abs(pt->fSector-pt2->fSector)>1) break;
1275 printf("\n*****\nNumber of good tracks after overlap removal\t%d\n",fNtracks);
1280 void AliTPCtrackerMI::RemoveUsed(TObjArray * arr, Float_t factor, Int_t removalindex)
1283 //Loop over all tracks and remove "overlaps"
1286 Int_t nseed = arr->GetEntriesFast();
1288 for (Int_t i=0; i<nseed; i++) {
1289 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1293 if (!(pt->IsActive())) continue;
1294 Int_t noc=pt->GetNumberOfClusters();
1296 for (Int_t i=0; i<noc; i++) {
1297 Int_t index=pt->GetClusterIndex(i);
1298 AliTPCclusterMI *c=(AliTPCclusterMI*)GetClusterMI(index);
1300 if (c->IsUsed()) shared++;
1302 if ((Float_t(shared)/Float_t(noc))>factor)
1303 pt->Desactivate(removalindex);
1306 for (Int_t i=0; i<noc; i++) {
1307 Int_t index=pt->GetClusterIndex(i);
1308 AliTPCclusterMI *c=(AliTPCclusterMI*)GetClusterMI(index);
1315 printf("\n*****\nNumber of good tracks after shared removal\t%d\n",fNtracks);
1320 void AliTPCtrackerMI::MakeSeedsAll()
1322 if (fSeeds == 0) fSeeds = new TObjArray;
1324 for (Int_t sec=0;sec<fkNOS;sec+=3){
1325 arr = MakeSeedsSectors(sec,sec+3);
1326 Int_t nseed = arr->GetEntriesFast();
1327 for (Int_t i=0;i<nseed;i++)
1328 fSeeds->AddLast(arr->RemoveAt(i));
1330 // fSeeds = MakeSeedsSectors(0,fkNOS);
1333 TObjArray * AliTPCtrackerMI::MakeSeedsSectors(Int_t sec1, Int_t sec2)
1336 // loop over all sectors and make seed
1339 Int_t nup=fOuterSec->GetNRows(), nlow=fInnerSec->GetNRows();
1340 Int_t nrows=nlow+nup;
1341 Int_t gap=Int_t(0.125*nrows), shift=Int_t(0.5*gap);
1342 // if (fSeeds==0) fSeeds = new TObjArray;
1343 TObjArray * arr = new TObjArray;
1345 for (Int_t sec=sec1; sec<sec2;sec++){
1346 MakeSeeds(arr, sec, nup-1, nup-1-gap);
1347 MakeSeeds(arr, sec, nup-2-shift, nup-2-shift-gap);
1349 gap = Int_t(0.2* nrows);
1350 for (Int_t sec=sec1; sec<sec2;sec++){
1352 //MakeSeeds2(arr, sec, nup-1, nup-1-gap);
1353 MakeSeeds2(arr, sec, nup-1-shift, nup-1-shift-gap);
1354 //MakeSeeds2(arr, sec, nup-1-2*shift, nup-1-2*shift-gap);
1355 MakeSeeds2(arr, sec, nup-1-3*shift, nup-1-3*shift-gap);
1356 //MakeSeeds2(arr, sec, nup-1-4*shift, nup-1-4*shift-gap);
1357 MakeSeeds2(arr, sec, nup-1-5*shift, nup-1-5*shift-gap);
1358 MakeSeeds2(arr, sec, gap, 1);
1361 Int_t nseed=arr->GetEntriesFast();
1364 gap=Int_t(0.3*nrows);
1366 for (i=0; i<nseed; i++) {
1367 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i), &t=*pt;
1369 if (FollowProlongation(t,nup-gap)) {
1370 pt->fIsSeeding =kFALSE;
1373 delete arr->RemoveAt(i);
1378 //remove seeds which overlaps
1379 RemoveOverlap(arr,0.4,1);
1380 //delete seeds - which were sign
1381 nseed=arr->GetEntriesFast();
1382 for (i=0; i<nseed; i++) {
1383 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1386 if ((pt->IsActive()) && pt->GetNumberOfClusters() > pt->fNFoundable*0.5 ) {
1388 //FollowBackProlongation(*pt,nup-1);
1389 //if ( pt->GetNumberOfClusters() < pt->fNFoundable*0.5 || pt->GetNumberOfClusters()<10 )
1390 //delete arr->RemoveAt(i);
1395 delete arr->RemoveAt(i);
1397 //RemoveOverlap(arr,0.6,1);
1403 //_____________________________________________________________________________
1404 void AliTPCtrackerMI::MakeSeeds(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2) {
1405 //-----------------------------------------------------------------
1406 // This function creates track seeds.
1407 //-----------------------------------------------------------------
1408 // if (fSeeds==0) fSeeds=new TObjArray(15000);
1410 Double_t x[5], c[15];
1412 Double_t alpha=fOuterSec->GetAlpha(), shift=fOuterSec->GetAlphaShift();
1413 Double_t cs=cos(alpha), sn=sin(alpha);
1415 Double_t x1 =fOuterSec->GetX(i1);
1416 Double_t xx2=fOuterSec->GetX(i2);
1418 // for (Int_t ns=0; ns<fkNOS; ns++)
1421 Int_t nl=fOuterSec[(ns-1+fkNOS)%fkNOS][i2];
1422 Int_t nm=fOuterSec[ns][i2];
1423 Int_t nu=fOuterSec[(ns+1)%fkNOS][i2];
1424 const AliTPCRow& kr1=fOuterSec[ns][i1];
1425 AliTPCRow& kr21 = fOuterSec[(ns-1+fkNOS)%fkNOS][i2];
1426 AliTPCRow& kr22 = fOuterSec[(ns)%fkNOS][i2];
1427 AliTPCRow& kr23 = fOuterSec[(ns+1)%fkNOS][i2];
1429 for (Int_t is=0; is < kr1; is++) {
1430 Double_t y1=kr1[is]->GetY(), z1=kr1[is]->GetZ();
1431 Double_t x3=GetX(), y3=GetY(), z3=GetZ();
1433 Float_t anglez = (z1-z3)/(x1-x3);
1434 Float_t extraz = z1 - anglez*(x1-xx2); // extrapolated z
1436 for (Int_t js=0; js < nl+nm+nu; js++) {
1437 const AliTPCclusterMI *kcl;
1438 Double_t x2, y2, z2;
1441 js = kr21.Find(extraz-15.);
1442 if (js>=nl) continue;
1446 if ((extraz-z2)>10) continue;
1447 if ((extraz-z2)<-10) {
1457 js = nl+kr22.Find(extraz-15.);
1458 if (js>=nl+nm) continue;
1462 if ((extraz-z2)>10) continue;
1463 if ((extraz-z2)<-10) {
1467 x2=xx2; y2=kcl->GetY();
1469 //const AliTPCRow& kr2=fOuterSec[(ns+1)%fkNOS][i2];
1471 js = nl+nm+kr23.Find(extraz-15.);
1472 if (js>=nl+nm+nu) break;
1476 if ((extraz-z2)>10) continue;
1477 if ((extraz-z2)<-10) {
1485 Double_t zz=z1 - anglez*(x1-x2);
1486 if (TMath::Abs(zz-z2)>10.) continue;
1488 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
1489 if (d==0.) {cerr<<"MakeSeeds warning: Straight seed !\n"; continue;}
1493 x[4]=f1(x1,y1,x2,y2,x3,y3);
1494 if (TMath::Abs(x[4]) >= 0.0066) continue;
1495 x[2]=f2(x1,y1,x2,y2,x3,y3);
1496 //if (TMath::Abs(x[4]*x1-x[2]) >= 0.99999) continue;
1497 x[3]=f3(x1,y1,x2,y2,z1,z2);
1498 if (TMath::Abs(x[3]) > 1.2) continue;
1499 Double_t a=asin(x[2]);
1500 Double_t zv=z1 - x[3]/x[4]*(a+asin(x[4]*x1-x[2]));
1501 if (TMath::Abs(zv-z3)>10.) continue;
1503 Double_t sy1=kr1[is]->GetSigmaY2()*2, sz1=kr1[is]->GetSigmaZ2()*4;
1504 Double_t sy2=kcl->GetSigmaY2()*2, sz2=kcl->GetSigmaZ2()*4;
1505 //Double_t sy3=400*3./12., sy=0.1, sz=0.1;
1506 Double_t sy3=25000*x[4]*x[4]+0.1, sy=0.1, sz=0.1;
1507 //Double_t sy3=25000*x[4]*x[4]*60+0.5, sy=0.1, sz=0.1;
1509 Double_t f40=(f1(x1,y1+sy,x2,y2,x3,y3)-x[4])/sy;
1510 Double_t f42=(f1(x1,y1,x2,y2+sy,x3,y3)-x[4])/sy;
1511 Double_t f43=(f1(x1,y1,x2,y2,x3,y3+sy)-x[4])/sy;
1512 Double_t f20=(f2(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
1513 Double_t f22=(f2(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
1514 Double_t f23=(f2(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
1515 Double_t f30=(f3(x1,y1+sy,x2,y2,z1,z2)-x[3])/sy;
1516 Double_t f31=(f3(x1,y1,x2,y2,z1+sz,z2)-x[3])/sz;
1517 Double_t f32=(f3(x1,y1,x2,y2+sy,z1,z2)-x[3])/sy;
1518 Double_t f34=(f3(x1,y1,x2,y2,z1,z2+sz)-x[3])/sz;
1522 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f23*sy3*f23;
1523 c[6]=f30*sy1; c[7]=f31*sz1; c[8]=f30*sy1*f20+f32*sy2*f22;
1524 c[9]=f30*sy1*f30+f31*sz1*f31+f32*sy2*f32+f34*sz2*f34;
1525 c[10]=f40*sy1; c[11]=0.; c[12]=f40*sy1*f20+f42*sy2*f22+f43*sy3*f23;
1526 c[13]=f30*sy1*f40+f32*sy2*f42;
1527 c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
1529 UInt_t index=kr1.GetIndex(is);
1530 AliTPCseed *track=new AliTPCseed(index, x, c, x1, ns*alpha+shift);
1531 track->fIsSeeding = kTRUE;
1532 //Int_t rc=FollowProlongation(*track, i2);
1533 Int_t delta4 = Int_t((i2-i1)/4.);
1535 FollowProlongation(*track, i1-delta4);
1536 if (track->GetNumberOfClusters() < track->fNFoundable/2.) {
1540 FollowProlongation(*track, i1-2*delta4);
1541 if (track->GetNumberOfClusters() < track->fNFoundable/2.) {
1545 FollowProlongation(*track, i1-3*delta4);
1546 if (track->GetNumberOfClusters() < track->fNFoundable/2.) {
1550 FollowProlongation(*track, i2);
1553 track->fLastPoint = i1; // first cluster in track position
1554 if (track->GetNumberOfClusters()<(i1-i2)/4 || track->GetNumberOfClusters() < track->fNFoundable/2. ) delete track;
1555 else arr->AddLast(track);
1562 //_____________________________________________________________________________
1563 void AliTPCtrackerMI::MakeSeeds2(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2) {
1564 //-----------------------------------------------------------------
1565 // This function creates track seeds - without vertex constraint
1566 //-----------------------------------------------------------------
1568 Double_t alpha=fOuterSec->GetAlpha(), shift=fOuterSec->GetAlphaShift();
1569 // Double_t cs=cos(alpha), sn=sin(alpha);
1570 Int_t row0 = (i1+i2)/2;
1571 Int_t drow = (i1-i2)/2;
1572 const AliTPCRow& kr0=fSectors[sec][row0];
1573 const AliTPCRow& krm=fSectors[sec][row0-1];
1574 const AliTPCRow& krp=fSectors[sec][row0+1];
1577 AliTPCpolyTrack polytrack;
1578 Int_t nclusters=fSectors[sec][row0];
1580 for (Int_t is=0; is < nclusters; is++) {
1581 const AliTPCclusterMI * cl= kr0[is];
1582 Double_t x = kr0.GetX();
1584 // Initialization of the polytrack
1587 Double_t y0= cl->GetY();
1588 Double_t z0= cl->GetZ();
1589 polytrack.AddPoint(x,y0,z0);
1590 Float_t roady = 5*TMath::Sqrt(cl->GetSigmaY2()+0.2);
1591 Float_t roadz = 5*TMath::Sqrt(cl->GetSigmaZ2()+0.2);
1594 cl = krm.FindNearest(y0,z0,roady,roadz);
1595 if (cl) polytrack.AddPoint(x,cl->GetY(),cl->GetZ(),roady,roadz);
1598 cl = krp.FindNearest(y0,z0,roady,roadz);
1599 if (cl) polytrack.AddPoint(x,cl->GetY(),cl->GetZ(),cl->GetSigmaY2()+0.05,cl->GetSigmaZ2()+0.05);
1601 polytrack.UpdateParameters();
1607 Int_t nfoundable = polytrack.GetN();
1608 Int_t nfound = nfoundable;
1609 for (Int_t ddrow = 2; ddrow<drow;ddrow++){
1610 for (Int_t delta = -1;delta<=1;delta+=2){
1611 Int_t row = row0+ddrow*delta;
1612 kr = &(fSectors[sec][row]);
1613 Double_t xn = kr->GetX();
1614 Double_t ymax = fSectors->GetMaxY(row)-kr->fDeadZone;
1615 polytrack.GetFitPoint(xn,yn,zn);
1616 if (TMath::Abs(yn)>ymax) continue;
1618 AliTPCclusterMI * cln = kr->FindNearest(yn,zn,roady,roadz);
1620 polytrack.AddPoint(xn,cln->GetY(),cln->GetZ(),cln->GetSigmaY2()+0.05,cln->GetSigmaZ2()+0.05);
1624 polytrack.UpdateParameters();
1625 if (nfound<0.45*nfoundable) break;
1627 if ((nfound>0.5*nfoundable) &&( nfoundable>0.4*(i1-i2))) {
1628 // add polytrack candidate
1629 Double_t x[5], c[15];
1630 Double_t x1,x2,x3,y1,y2,y3,z1,z2,z3;
1631 polytrack.GetBoundaries(x3,x1);
1633 polytrack.GetFitPoint(x1,y1,z1);
1634 polytrack.GetFitPoint(x2,y2,z2);
1635 polytrack.GetFitPoint(x3,y3,z3);
1637 //is track pointing to the vertex ?
1640 polytrack.GetFitPoint(x0,y0,z0);
1641 if ( (TMath::Abs(z0-GetZ())<10) && (TMath::Abs(y0-GetY())<5)){ //if yes apply vertex constraint
1649 x[4]=f1(x1,y1,x2,y2,x3,y3);
1650 if (TMath::Abs(x[4]) >= 0.05) continue; //MI change
1651 x[2]=f2(x1,y1,x2,y2,x3,y3);
1652 //if (TMath::Abs(x[4]*x1-x[2]) >= 0.99999) continue;
1653 x[3]=f3(x1,y1,x2,y2,z1,z2);
1654 if (TMath::Abs(x[3]) > 1.2) continue;
1655 if (TMath::Abs(x[2]) > 0.99) continue;
1656 // Double_t a=asin(x[2]);
1659 Double_t sy=1.5, sz=1.5;
1660 Double_t sy1=1.5, sz1=1.5;
1661 Double_t sy2=1.3, sz2=1.3;
1664 //Double_t sy3=400*3./12., sy=0.1, sz=0.1;
1665 // Double_t sy3=25000*x[4]*x[4]+0.1, sy=0.1, sz=0.1;
1666 //Double_t sy3=25000*x[4]*x[4]*60+0.5, sy=0.1, sz=0.1;
1668 Double_t f40=(f1(x1,y1+sy,x2,y2,x3,y3)-x[4])/sy;
1669 Double_t f42=(f1(x1,y1,x2,y2+sy,x3,y3)-x[4])/sy;
1670 Double_t f43=(f1(x1,y1,x2,y2,x3,y3+sy)-x[4])/sy;
1671 Double_t f20=(f2(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
1672 Double_t f22=(f2(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
1673 Double_t f23=(f2(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
1674 Double_t f30=(f3(x1,y1+sy,x2,y2,z1,z2)-x[3])/sy;
1675 Double_t f31=(f3(x1,y1,x2,y2,z1+sz,z2)-x[3])/sz;
1676 Double_t f32=(f3(x1,y1,x2,y2+sy,z1,z2)-x[3])/sy;
1677 Double_t f34=(f3(x1,y1,x2,y2,z1,z2+sz)-x[3])/sz;
1681 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f23*sy3*f23;
1682 c[6]=f30*sy1; c[7]=f31*sz1; c[8]=f30*sy1*f20+f32*sy2*f22;
1683 c[9]=f30*sy1*f30+f31*sz1*f31+f32*sy2*f32+f34*sz2*f34;
1684 c[10]=f40*sy1; c[11]=0.; c[12]=f40*sy1*f20+f42*sy2*f22+f43*sy3*f23;
1685 c[13]=f30*sy1*f40+f32*sy2*f42;
1686 c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
1690 AliTPCseed *track=new AliTPCseed(index, x, c, x1, sec*alpha+shift);
1691 track->fStopped =kFALSE;
1692 track->fIsSeeding = kTRUE;
1693 Int_t rc=FollowProlongation(*track, i2);
1694 track->fLastPoint = i1; // first cluster in track position
1695 if (rc==0 || track->GetNumberOfClusters()<(i1-i2)/4 || track->GetNumberOfClusters() < track->fNFoundable/2. ) delete track;
1696 else arr->AddLast(track);
1708 //_____________________________________________________________________________
1709 Int_t AliTPCtrackerMI::ReadSeeds(const TFile *inp) {
1710 //-----------------------------------------------------------------
1711 // This function reades track seeds.
1712 //-----------------------------------------------------------------
1713 TDirectory *savedir=gDirectory;
1715 TFile *in=(TFile*)inp;
1716 if (!in->IsOpen()) {
1717 cerr<<"AliTPCtrackerMI::ReadSeeds(): input file is not open !\n";
1722 TTree *seedTree=(TTree*)in->Get("Seeds");
1724 cerr<<"AliTPCtrackerMI::ReadSeeds(): ";
1725 cerr<<"can't get a tree with track seeds !\n";
1728 AliTPCtrack *seed=new AliTPCtrack;
1729 seedTree->SetBranchAddress("tracks",&seed);
1731 if (fSeeds==0) fSeeds=new TObjArray(15000);
1733 Int_t n=(Int_t)seedTree->GetEntries();
1734 for (Int_t i=0; i<n; i++) {
1735 seedTree->GetEvent(i);
1736 fSeeds->AddLast(new AliTPCseed(*seed,seed->GetAlpha()));
1745 //_____________________________________________________________________________
1746 Int_t AliTPCtrackerMI::Clusters2Tracks(const TFile *inp, TFile *out) {
1747 //-----------------------------------------------------------------
1748 // This is a track finder.
1749 //-----------------------------------------------------------------
1750 TDirectory *savedir=gDirectory;
1753 TFile *in=(TFile*)inp;
1754 if (!in->IsOpen()) {
1755 cerr<<"AliTPCtrackerMI::Clusters2Tracks(): input file is not open !\n";
1760 if (!out->IsOpen()) {
1761 cerr<<"AliTPCtrackerMI::Clusters2Tracks(): output file is not open !\n";
1768 sprintf(tname,"TreeT_TPC_%d",fEventN);
1769 TTree tracktree(tname,"Tree with TPC tracks");
1770 TTree seedtree("Seeds","Seeds");
1771 AliTPCtrack *iotrack=0;
1772 AliTPCseed *ioseed=0;
1773 tracktree.Branch("tracks","AliTPCtrack",&iotrack,32000,0);
1776 printf("Loading clusters \n");
1778 printf("Time for loading clusters: \t");timer.Print();timer.Start();
1780 printf("Loading outer sectors\n");
1782 printf("Time for loading outer sectors: \t");timer.Print();timer.Start();
1784 printf("Loading inner sectors\n");
1786 printf("Time for loading inner sectors: \t");timer.Print();timer.Start();
1787 fSectors = fOuterSec;
1793 printf("Time for seeding: \t"); timer.Print();timer.Start();
1794 Int_t nup=fOuterSec->GetNRows(), nlow=fInnerSec->GetNRows();
1795 Int_t nrows=nlow+nup;
1797 Int_t gap=Int_t(0.3*nrows);
1799 //RemoveOverlap(fSeeds,0.6,2);
1800 Int_t nseed=fSeeds->GetEntriesFast();
1801 // outer sectors parallel tracking
1802 ParallelTracking(fSectors->GetNRows()-gap-1,0);
1803 printf("Time for parralel tracking outer sectors: \t"); timer.Print();timer.Start();
1805 RemoveOverlap(fSeeds, 0.4,3);
1806 printf("Time for removal overlap- outer sectors: \t");timer.Print();timer.Start();
1808 fSectors = fInnerSec;
1811 ParallelTracking(fSectors->GetNRows()-1,0);
1813 ParallelTracking(fSectors->GetNRows()-1,2*fSectors->GetNRows()/3);
1814 RemoveOverlap(fSeeds,0.4,5,kTRUE);
1815 ParallelTracking(2*fSectors->GetNRows()/3-1,fSectors->GetNRows()/3);
1816 RemoveOverlap(fSeeds,0.4,5,kTRUE);
1817 ParallelTracking(fSectors->GetNRows()/3-1,0);
1819 printf("Number of tracks after inner tracking %d\n",fNtracks);
1820 printf("Time for parralel tracking inner sectors: \t"); timer.Print();timer.Start();
1822 for (Int_t i=0;i<fSeeds->GetEntriesFast();i++){
1823 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i);
1825 if (!pt->IsActive()) continue;
1826 pt->PropagateTo(90.);
1828 RemoveOverlap(fSeeds,0.4,5,kTRUE); // remove overlap - shared points signed
1829 RemoveUsed(fSeeds,0.4,6);
1830 printf("Time for removal overlap- inner sectors: \t"); timer.Print();timer.Start();
1834 ioseed = (AliTPCseed*)(fSeeds->UncheckedAt(0));
1835 AliTPCseed * vseed = new AliTPCseed;
1836 vseed->fPoints = new TClonesArray("AliTPCTrackPoint",1);
1837 vseed->fEPoints = new TClonesArray("AliTPCExactPoint",1);
1838 vseed->fPoints->ExpandCreateFast(2);
1840 //TBranch * seedbranch =
1841 seedtree.Branch("seeds","AliTPCseed",&vseed,32000,99);
1843 nseed=fSeeds->GetEntriesFast();
1846 for (i=0; i<nseed; i++) {
1847 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
1849 Int_t nc=t.GetNumberOfClusters();
1850 if (nc<20) continue;
1851 t.CookdEdx(0.02,0.6);
1852 CookLabel(pt,0.1); //For comparison only
1853 // if ((pt->IsActive()) && (nc>Int_t(0.4*nrows))){
1854 if ((pt->IsActive()) && (nc>Int_t(0.5*t.fNFoundable) && (t.fNFoundable>Int_t(0.3*nrows)))){
1857 cerr<<found++<<'\r';
1861 seedbranch->SetAddress(&pt);
1864 for (Int_t j=0;j<160;j++){
1865 delete pt->fPoints->RemoveAt(j);
1870 delete fSeeds->RemoveAt(i);
1872 // fNTracks = found;
1873 printf("Time for track writing and dedx cooking: \t"); timer.Print();timer.Start();
1876 printf("Time for unloading cluster: \t"); timer.Print();timer.Start();
1880 cerr<<"Number of found tracks : "<<"\t"<<found<<endl;
1888 void AliTPCtrackerMI::ParallelTracking(Int_t rfirst, Int_t rlast)
1891 // try to track in parralel
1893 Int_t nseed=fSeeds->GetEntriesFast();
1894 //prepare seeds for tracking
1895 for (Int_t i=0; i<nseed; i++) {
1896 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
1898 if (!t.IsActive()) continue;
1899 // follow prolongation to the first layer
1900 if ( (fSectors ==fInnerSec) || (t.fFirstPoint>rfirst+1))
1901 FollowProlongation(t, rfirst+1);
1906 for (Int_t nr=rfirst; nr>=rlast; nr--){
1907 // make indexes with the cluster tracks for given
1908 // for (Int_t i = 0;i<fN;i++)
1909 // fSectors[i][nr].MakeClusterTracks();
1911 // find nearest cluster
1912 for (Int_t i=0; i<nseed; i++) {
1913 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
1915 if (!pt->IsActive()) continue;
1916 if ( (fSectors ==fOuterSec) && pt->fFirstPoint<nr) continue;
1917 if (pt->fRelativeSector>17) {
1920 UpdateClusters(t,i,nr);
1922 // prolonagate to the nearest cluster - if founded
1923 for (Int_t i=0; i<nseed; i++) {
1924 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i);
1926 if (!pt->IsActive()) continue;
1927 if ((fSectors ==fOuterSec) &&pt->fFirstPoint<nr) continue;
1928 if (pt->fRelativeSector>17) {
1931 FollowToNextCluster(i,nr);
1933 // for (Int_t i= 0;i<fN;i++)
1934 // fSectors[i][nr].ClearClusterTracks();
1939 Float_t AliTPCtrackerMI::GetSigmaY(AliTPCseed * seed)
1943 Float_t sd2 = TMath::Abs((fParam->GetZLength()-TMath::Abs(seed->GetZ())))*fParam->GetDiffL()*fParam->GetDiffL();
1944 Float_t padlength = fParam->GetPadPitchLength(seed->fSector);
1945 Float_t sres = (seed->fSector < fParam->GetNSector()/2) ? 0.2 :0.3;
1946 Float_t angular = seed->GetSnp();
1947 angular = angular*angular/(1-angular*angular);
1948 // angular*=angular;
1949 //angular = TMath::Sqrt(angular/(1-angular));
1950 Float_t res = TMath::Sqrt(sd2+padlength*padlength*angular/12.+sres*sres);
1953 Float_t AliTPCtrackerMI::GetSigmaZ(AliTPCseed * seed)
1957 Float_t sd2 = TMath::Abs((fParam->GetZLength()-TMath::Abs(seed->GetZ())))*fParam->GetDiffL()*fParam->GetDiffL();
1958 Float_t padlength = fParam->GetPadPitchLength(seed->fSector);
1959 Float_t sres = fParam->GetZSigma();
1960 Float_t angular = seed->GetTgl();
1961 Float_t res = TMath::Sqrt(sd2+padlength*padlength*angular*angular/12.+sres*sres);
1967 //_________________________________________________________________________
1968 AliTPCclusterMI *AliTPCtrackerMI::GetClusterMI(Int_t index) const {
1969 //--------------------------------------------------------------------
1970 // Return pointer to a given cluster
1971 //--------------------------------------------------------------------
1972 Int_t sec=(index&0xff000000)>>24;
1973 Int_t row=(index&0x00ff0000)>>16;
1974 Int_t ncl=(index&0x0000ffff)>>00;
1976 AliTPCClustersRow *clrow=((AliTPCtrackerMI *) this)->fClustersArray.GetRow(sec,row);
1977 if (!clrow) return 0;
1978 return (AliTPCclusterMI*)(*clrow)[ncl];
1981 //__________________________________________________________________________
1982 void AliTPCtrackerMI::CookLabel(AliKalmanTrack *t, Float_t wrong) const {
1983 //--------------------------------------------------------------------
1984 //This function "cooks" a track label. If label<0, this track is fake.
1985 //--------------------------------------------------------------------
1986 Int_t noc=t->GetNumberOfClusters();
1987 Int_t *lb=new Int_t[noc];
1988 Int_t *mx=new Int_t[noc];
1989 AliTPCclusterMI **clusters=new AliTPCclusterMI*[noc];
1992 for (i=0; i<noc; i++) {
1994 Int_t index=t->GetClusterIndex(i);
1995 clusters[i]=GetClusterMI(index);
1998 Int_t lab=123456789;
1999 for (i=0; i<noc; i++) {
2000 AliTPCclusterMI *c=clusters[i];
2001 if (!clusters[i]) continue;
2002 lab=TMath::Abs(c->GetLabel(0));
2004 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
2010 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
2012 for (i=0; i<noc; i++) {
2013 AliTPCclusterMI *c=clusters[i];
2014 if (!clusters[i]) continue;
2015 if (TMath::Abs(c->GetLabel(1)) == lab ||
2016 TMath::Abs(c->GetLabel(2)) == lab ) max++;
2019 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
2022 Int_t tail=Int_t(0.10*noc);
2024 for (i=1; i<=tail; i++) {
2025 AliTPCclusterMI *c=clusters[noc-i];
2026 if (!clusters[i]) continue;
2027 if (lab == TMath::Abs(c->GetLabel(0)) ||
2028 lab == TMath::Abs(c->GetLabel(1)) ||
2029 lab == TMath::Abs(c->GetLabel(2))) max++;
2031 if (max < Int_t(0.5*tail)) lab=-lab;
2041 //_________________________________________________________________________
2042 void AliTPCtrackerMI::AliTPCSector::Setup(const AliTPCParam *par, Int_t f) {
2043 //-----------------------------------------------------------------------
2044 // Setup inner sector
2045 //-----------------------------------------------------------------------
2047 fAlpha=par->GetInnerAngle();
2048 fAlphaShift=par->GetInnerAngleShift();
2049 fPadPitchWidth=par->GetInnerPadPitchWidth();
2050 fPadPitchLength=par->GetInnerPadPitchLength();
2051 fN=par->GetNRowLow();
2052 fRow=new AliTPCRow[fN];
2053 for (Int_t i=0; i<fN; i++) {
2054 fRow[i].SetX(par->GetPadRowRadiiLow(i));
2055 fRow[i].fDeadZone =1.5; //1.5 cm of dead zone
2058 fAlpha=par->GetOuterAngle();
2059 fAlphaShift=par->GetOuterAngleShift();
2060 fPadPitchWidth = par->GetOuterPadPitchWidth();
2061 fPadPitchLength = par->GetOuter1PadPitchLength();
2062 f1PadPitchLength = par->GetOuter1PadPitchLength();
2063 f2PadPitchLength = par->GetOuter2PadPitchLength();
2065 fN=par->GetNRowUp();
2066 fRow=new AliTPCRow[fN];
2067 for (Int_t i=0; i<fN; i++) {
2068 fRow[i].SetX(par->GetPadRowRadiiUp(i));
2069 fRow[i].fDeadZone =1.5; // 1.5 cm of dead zone
2075 AliTPCtrackerMI::AliTPCRow::~AliTPCRow(){
2077 if (fClusterTracks) delete [] fClusterTracks;
2081 void AliTPCtrackerMI::AliTPCRow::MakeClusterTracks(){
2082 //create cluster tracks
2084 fClusterTracks = new AliTPCclusterTracks[fN];
2087 void AliTPCtrackerMI::AliTPCRow::ClearClusterTracks(){
2088 if (fClusterTracks) delete[] fClusterTracks;
2094 void AliTPCtrackerMI::AliTPCRow::UpdateClusterTrack(Int_t clindex, Int_t trindex, AliTPCseed * seed){
2097 // update information of the cluster tracks - if track is nearer then other tracks to the
2099 const AliTPCclusterMI * cl = (*this)[clindex];
2100 AliTPCclusterTracks * cltracks = GetClusterTracks(clindex);
2101 // find the distance of the cluster to the track
2102 Float_t dy2 = (cl->GetY()- seed->GetY());
2104 Float_t dz2 = (cl->GetZ()- seed->GetZ());
2107 Float_t distance = TMath::Sqrt(dy2+dz2);
2109 return; // MI - to be changed - AliTPCtrackerParam
2111 if ( distance < cltracks->fDistance[0]){
2112 cltracks->fDistance[2] =cltracks->fDistance[1];
2113 cltracks->fDistance[1] =cltracks->fDistance[0];
2114 cltracks->fDistance[0] =distance;
2115 cltracks->fTrackIndex[2] =cltracks->fTrackIndex[1];
2116 cltracks->fTrackIndex[1] =cltracks->fTrackIndex[0];
2117 cltracks->fTrackIndex[0] =trindex;
2120 if ( distance < cltracks->fDistance[1]){
2121 cltracks->fDistance[2] =cltracks->fDistance[1];
2122 cltracks->fDistance[1] =distance;
2123 cltracks->fTrackIndex[2] =cltracks->fTrackIndex[1];
2124 cltracks->fTrackIndex[1] =trindex;
2126 if (distance < cltracks->fDistance[2]){
2127 cltracks->fDistance[2] =distance;
2128 cltracks->fTrackIndex[2] =trindex;
2133 //_________________________________________________________________________
2135 AliTPCtrackerMI::AliTPCRow::InsertCluster(const AliTPCclusterMI* c, UInt_t index) {
2136 //-----------------------------------------------------------------------
2137 // Insert a cluster into this pad row in accordence with its y-coordinate
2138 //-----------------------------------------------------------------------
2139 if (fN==kMaxClusterPerRow) {
2140 cerr<<"AliTPCRow::InsertCluster(): Too many clusters !\n"; return;
2142 if (fN==0) {fIndex[0]=index; fClusters[fN++]=c; return;}
2143 Int_t i=Find(c->GetZ());
2144 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTPCclusterMI*));
2145 memmove(fIndex +i+1 ,fIndex +i,(fN-i)*sizeof(UInt_t));
2146 fIndex[i]=index; fClusters[i]=c; fN++;
2149 //___________________________________________________________________
2150 Int_t AliTPCtrackerMI::AliTPCRow::Find(Double_t z) const {
2151 //-----------------------------------------------------------------------
2152 // Return the index of the nearest cluster
2153 //-----------------------------------------------------------------------
2154 if (fN==0) return 0;
2155 if (z <= fClusters[0]->GetZ()) return 0;
2156 if (z > fClusters[fN-1]->GetZ()) return fN;
2157 Int_t b=0, e=fN-1, m=(b+e)/2;
2158 for (; b<e; m=(b+e)/2) {
2159 if (z > fClusters[m]->GetZ()) b=m+1;
2167 //___________________________________________________________________
2168 AliTPCclusterMI * AliTPCtrackerMI::AliTPCRow::FindNearest(Double_t y, Double_t z, Double_t roady, Double_t roadz) const {
2169 //-----------------------------------------------------------------------
2170 // Return the index of the nearest cluster in z y
2171 //-----------------------------------------------------------------------
2172 Float_t maxdistance = roady*roady + roadz*roadz;
2174 AliTPCclusterMI *cl =0;
2175 for (Int_t i=Find(z-roadz); i<fN; i++) {
2176 AliTPCclusterMI *c=(AliTPCclusterMI*)(fClusters[i]);
2177 if (c->GetZ() > z+roadz) break;
2178 if ( (c->GetY()-y) > roady ) continue;
2179 Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
2180 if (maxdistance>distance) {
2181 maxdistance = distance;
2192 AliTPCseed::AliTPCseed():AliTPCtrack(){
2196 memset(fClusterIndex,0,sizeof(Int_t)*200);
2205 AliTPCseed::AliTPCseed(const AliTPCtrack &t):AliTPCtrack(t){
2213 AliTPCseed::AliTPCseed(const AliKalmanTrack &t, Double_t a):AliTPCtrack(t,a){
2215 memset(fClusterIndex,0,sizeof(Int_t)*200);
2224 AliTPCseed::AliTPCseed(UInt_t index, const Double_t xx[5], const Double_t cc[15],
2225 Double_t xr, Double_t alpha):
2226 AliTPCtrack(index, xx, cc, xr, alpha) {
2230 memset(fClusterIndex,0,sizeof(Int_t)*200);
2239 AliTPCseed::~AliTPCseed(){
2240 if (fPoints) delete fPoints;
2244 for (Int_t i=0;i<8;i++){
2245 delete [] fTrackPoints[i];
2247 delete fTrackPoints;
2253 AliTPCTrackPoint * AliTPCseed::GetTrackPoint(Int_t i)
2257 if (!fTrackPoints) {
2258 fTrackPoints = new AliTPCTrackPoint*[8];
2259 for ( Int_t i=0;i<8;i++)
2262 Int_t index1 = i/20;
2263 if (!fTrackPoints[index1]) fTrackPoints[index1] = new AliTPCTrackPoint[20];
2264 return &(fTrackPoints[index1][i%20]);
2267 void AliTPCseed::RebuildSeed()
2270 // rebuild seed to be ready for storing
2271 fPoints = new TClonesArray("AliTPCTrackPoint",160);
2272 fPoints->ExpandCreateFast(160);
2273 fEPoints = new TClonesArray("AliTPCExactPoint",1);
2274 for (Int_t i=0;i<160;i++){
2275 AliTPCTrackPoint *trpoint = (AliTPCTrackPoint*)fPoints->UncheckedAt(i);
2276 *trpoint = *(GetTrackPoint(i));
2281 //_____________________________________________________________________________
2282 void AliTPCseed::CookdEdx(Double_t low, Double_t up) {
2283 //-----------------------------------------------------------------
2284 // This funtion calculates dE/dX within the "low" and "up" cuts.
2285 //-----------------------------------------------------------------
2288 Float_t angular[200];
2289 Float_t weight[200];
2292 // TClonesArray & arr = *fPoints;
2293 Float_t meanlog = 100.;
2295 Float_t mean[4] = {0,0,0,0};
2296 Float_t sigma[4] = {1000,1000,1000,1000};
2297 Int_t nc[4] = {0,0,0,0};
2298 Float_t norm[4] = {1000,1000,1000,1000};
2303 for (Int_t of =0; of<4; of++){
2304 for (Int_t i=of;i<160;i+=4)
2306 //AliTPCTrackPoint * point = (AliTPCTrackPoint *) arr.At(i);
2307 AliTPCTrackPoint * point = GetTrackPoint(i);
2308 if (point==0) continue;
2309 if (point->fIsShared){
2313 if (point->GetCPoint().GetMax()<5) continue;
2314 Float_t angley = point->GetTPoint().GetAngleY();
2315 Float_t anglez = point->GetTPoint().GetAngleZ();
2316 Int_t type = point->GetCPoint().GetType();
2317 Float_t rsigmay = point->GetCPoint().GetSigmaY();
2318 Float_t rsigmaz = point->GetCPoint().GetSigmaZ();
2319 Float_t rsigma = TMath::Sqrt(rsigmay*rsigmaz);
2321 Float_t ampc = 0; // normalization to the number of electrons
2323 ampc = 1.*point->GetCPoint().GetMax();
2324 //ampc = 1.*point->GetCPoint().GetQ();
2325 // AliTPCClusterPoint & p = point->GetCPoint();
2326 // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.6)) - TMath::Abs(p.GetY()/0.6)+0.5);
2327 // Float_t iz = (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
2329 // TMath::Abs( Int_t(iz) - iz + 0.5);
2330 //ampc *= 1.15*(1-0.3*dy);
2331 //ampc *= 1.15*(1-0.3*dz);
2332 // Float_t zfactor = (1.05-0.0004*TMath::Abs(point->GetCPoint().GetZ()));
2336 ampc = 1.0*point->GetCPoint().GetMax();
2337 //ampc = 1.0*point->GetCPoint().GetQ();
2338 //AliTPCClusterPoint & p = point->GetCPoint();
2339 // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.4)) - TMath::Abs(p.GetY()/0.4)+0.5);
2340 //Float_t iz = (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
2342 // TMath::Abs( Int_t(iz) - iz + 0.5);
2344 //ampc *= 1.15*(1-0.3*dy);
2345 //ampc *= 1.15*(1-0.3*dz);
2346 // Float_t zfactor = (1.02-0.000*TMath::Abs(point->GetCPoint().GetZ()));
2350 ampc *= 2.0; // put mean value to channel 50
2351 //ampc *= 0.58; // put mean value to channel 50
2353 // if (type>0) w = 1./(type/2.-0.5);
2354 // Float_t z = TMath::Abs(point->GetCPoint().GetZ());
2357 //ampc /= (1+0.0008*z);
2361 //ampc /= (1+0.0008*z);
2363 //ampc /= (1+0.0008*z);
2366 if (type<0) { //amp at the border - lower weight
2371 if (rsigma>1.5) ampc/=1.3; // if big backround
2373 angular[nc[of]] = TMath::Sqrt(1.+angley*angley+anglez*anglez);
2378 TMath::Sort(nc[of],amp,index,kFALSE);
2382 //meanlog = amp[index[Int_t(nc[of]*0.33)]];
2384 for (Int_t i=int(nc[of]*low+0.5);i<int(nc[of]*up+0.5);i++){
2385 Float_t ampl = amp[index[i]]/angular[index[i]];
2386 ampl = meanlog*TMath::Log(1.+ampl/meanlog);
2388 sumw += weight[index[i]];
2389 sumamp += weight[index[i]]*ampl;
2390 sumamp2 += weight[index[i]]*ampl*ampl;
2391 norm[of] += angular[index[i]]*weight[index[i]];
2398 mean[of] = sumamp/sumw;
2399 sigma[of] = sumamp2/sumw-mean[of]*mean[of];
2401 sigma[of] = TMath::Sqrt(sigma[of]);
2405 mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
2406 //mean *=(1-0.02*(sigma/(mean*0.17)-1.));
2407 //mean *=(1-0.1*(norm-1.));
2414 // mean[0]*= (1-0.05*(sigma[0]/(0.01+mean[1]*0.18)-1));
2415 // mean[1]*= (1-0.05*(sigma[1]/(0.01+mean[0]*0.18)-1));
2418 // dedx = (mean[0]* TMath::Sqrt((1.+nc[0]))+ mean[1]* TMath::Sqrt((1.+nc[1])) )/
2419 // ( TMath::Sqrt((1.+nc[0]))+TMath::Sqrt((1.+nc[1])));
2423 for (Int_t i =0;i<4;i++){
2424 if (nc[i]>2&&nc[i]<1000){
2425 dedx += mean[i] *nc[i];
2426 fSdEdx += sigma[i]*(nc[i]-2);
2427 fMAngular += norm[i] *nc[i];
2432 fSDEDX[i] = sigma[i];
2445 // Float_t dedx1 =dedx;
2448 for (Int_t i =0;i<4;i++){
2449 if (nc[i]>2&&nc[i]<1000){
2450 mean[i] = mean[i]*(1-0.12*(sigma[i]/(fSdEdx)-1.));
2451 dedx += mean[i] *nc[i];
2466 Double_t p=TMath::Sqrt((1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt()));
2469 if (dedx < 39.+ 12./(p+0.25)/(p+0.25)) { SetMass(0.13957); return;}
2470 if (dedx < 39.+ 12./p/p) { SetMass(0.49368); return;}
2471 SetMass(0.93827); return;
2475 if (dedx < 39.+ 12./(p+0.25)/(p+0.25)) { SetMass(0.13957); return;}
2476 SetMass(0.93827); return;
2479 SetMass(0.13957); return;