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 **************************************************************************/
19 AliTPC parallel tracker -
21 run AliTPCFindClusters.C macro - clusters neccessary for tracker are founded
22 run AliTPCFindTracksMI.C macro - to find tracks
23 tracks are written to AliTPCtracks.root file
24 for comparison also seeds are written to the same file - to special branch
27 //-------------------------------------------------------
28 // Implementation of the TPC tracker
30 // Origin: Marian Ivanov Marian.Ivanov@cern.ch
32 //-------------------------------------------------------
34 #include <TObjArray.h>
37 #include "Riostream.h"
39 #include "AliTPCtrackerMI.h"
40 #include "AliTPCclusterMI.h"
41 #include "AliTPCParam.h"
42 #include "AliTPCClustersRow.h"
43 #include "AliComplexCluster.h"
44 #include "AliTPCpolyTrack.h"
45 #include "TStopwatch.h"
49 ClassImp(AliTPCKalmanSegment)
53 //_____________________________________________________________________________
55 AliTPCKalmanSegment::AliTPCKalmanSegment(){
59 for (Int_t i=0;i<5;i++) fState[i] = 0.;
60 for (Int_t i=0;i<15;i++) fCovariance[i] = 0.;
66 //_____________________________________________________________________________
68 void AliTPCKalmanSegment::Init(AliTPCseed* seed)
71 // initial entrance integral chi2, fNCFoundable and fNC stored
72 fNCFoundable = seed->fNFoundable;
73 fNC = seed->GetNumberOfClusters();
74 fChi2 = seed->GetChi2();
78 void AliTPCKalmanSegment::Finish(AliTPCseed* seed)
81 // in finish state vector stored and chi2 and fNC... calculated
85 seed->GetExternalParameters(x,state);
86 seed->GetExternalCovariance(cov);
87 //float precision for tracklet
88 for (Int_t i=0;i<5;i++) fState[i] = state[i];
89 for (Int_t i=0;i<15;i++) fCovariance[i] = cov[i];
91 // in current seed integral track characteristic
92 // for tracklet differenciation between beginning (Init state) and Finish state
93 fNCFoundable = seed->fNFoundable - fNCFoundable;
94 fNC = seed->GetNumberOfClusters() - fNC;
95 fChi2 = seed->GetChi2()-fChi2;
99 void AliTPCKalmanSegment::GetState(Double_t &x, Double_t & alpha, Double_t state[5])
104 for (Int_t i=0;i<5;i++) state[i] = fState[i];
107 void AliTPCKalmanSegment::GetCovariance(Double_t covariance[15])
110 for (Int_t i=0;i<5;i++) covariance[i] = fCovariance[i];
113 void AliTPCKalmanSegment::GetStatistic(Int_t & nclusters, Int_t & nfoundable, Float_t & chi2)
118 nfoundable = fNCFoundable;
124 AliTPCclusterTracks::AliTPCclusterTracks(){
125 // class for storing overlaping info
142 Int_t AliTPCtrackerMI::UpdateTrack(AliTPCseed * track, AliTPCclusterMI* c, Double_t chi2, UInt_t i){
144 Int_t sec=(i&0xff000000)>>24;
145 Int_t row = (i&0x00ff0000)>>16;
146 track->fRow=(i&0x00ff0000)>>16;
147 track->fSector = sec;
148 // Int_t index = i&0xFFFF;
149 if (sec>=fParam->GetNInnerSector()) track->fRow += fParam->GetNRowLow();
150 track->fClusterIndex[track->fRow] = i;
151 track->fFirstPoint = row;
152 if ( track->fLastPoint<row) track->fLastPoint =row;
155 AliTPCTrackPoint *trpoint =track->GetTrackPoint(track->fRow);
156 Float_t angle2 = track->GetSnp()*track->GetSnp();
157 angle2 = TMath::Sqrt(angle2/(1-angle2));
159 //SET NEW Track Point
162 //if we have a cluster
163 trpoint->GetCPoint().SetY(c->GetY());
164 trpoint->GetCPoint().SetZ(c->GetZ());
166 trpoint->GetCPoint().SetSigmaY(c->GetSigmaY2()/(track->fCurrentSigmaY*track->fCurrentSigmaY));
167 trpoint->GetCPoint().SetSigmaZ(c->GetSigmaZ2()/(track->fCurrentSigmaZ*track->fCurrentSigmaZ));
169 trpoint->GetCPoint().SetType(c->GetType());
170 trpoint->GetCPoint().SetQ(c->GetQ());
171 trpoint->GetCPoint().SetMax(c->GetMax());
173 trpoint->GetCPoint().SetErrY(TMath::Sqrt(track->fErrorY2));
174 trpoint->GetCPoint().SetErrZ(TMath::Sqrt(track->fErrorZ2));
177 trpoint->GetTPoint().SetX(track->GetX());
178 trpoint->GetTPoint().SetY(track->GetY());
179 trpoint->GetTPoint().SetZ(track->GetZ());
181 trpoint->GetTPoint().SetAngleY(angle2);
182 trpoint->GetTPoint().SetAngleZ(track->GetTgl());
187 // printf("suspicious chi2 %f\n",chi2);
189 // if (track->fIsSeeding){
190 track->fErrorY2 *= 1.2;
191 track->fErrorY2 += 0.0064;
192 track->fErrorZ2 *= 1.2;
193 track->fErrorY2 += 0.005;
197 return track->Update(c,chi2,i);
200 //_____________________________________________________________________________
201 AliTPCtrackerMI::AliTPCtrackerMI(const AliTPCParam *par, Int_t eventn):
202 AliTracker(), fkNIS(par->GetNInnerSector()/2), fkNOS(par->GetNOuterSector()/2)
204 //---------------------------------------------------------------------
205 // The main TPC tracker constructor
206 //---------------------------------------------------------------------
207 fInnerSec=new AliTPCSector[fkNIS];
208 fOuterSec=new AliTPCSector[fkNOS];
211 for (i=0; i<fkNIS; i++) fInnerSec[i].Setup(par,0);
212 for (i=0; i<fkNOS; i++) fOuterSec[i].Setup(par,1);
216 fClustersArray.Setup(par);
217 fClustersArray.SetClusterType("AliTPCclusterMI");
221 sprintf(cname,"TreeC_TPC");
224 sprintf(cname,"TreeC_TPC_%d",eventn);
227 fClustersArray.ConnectTree(cname);
235 //_____________________________________________________________________________
236 AliTPCtrackerMI::~AliTPCtrackerMI() {
237 //------------------------------------------------------------------
238 // TPC tracker destructor
239 //------------------------------------------------------------------
249 Double_t AliTPCtrackerMI::ErrY2(AliTPCseed* seed, AliTPCclusterMI * cl){
253 Float_t z = TMath::Abs(fParam->GetZLength()-TMath::Abs(seed->GetZ()));
259 //standard if we don't have cluster - take MIP
260 const Float_t chmip = 50.;
261 Float_t amp = chmip/0.3;
266 rsigmay = cl->GetSigmaY2()/(seed->fCurrentSigmaY*seed->fCurrentSigmaY);
267 ctype = cl->GetType();
271 Float_t landau=2 ; //landau fluctuation part
272 Float_t gg=2; // gg fluctuation part
273 Float_t padlength= fSectors->GetPadPitchLength(seed->GetX());
276 if (fSectors==fInnerSec){
280 gg = (2+0.0002*amp)/nel;
281 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
282 if (landau>1) landau=1;
288 gg = (2+0.0002*amp)/nel;
289 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
290 if (landau>1) landau=1;
294 Float_t sdiff = gg*fParam->GetDiffT()*fParam->GetDiffT()*z;
295 Float_t angle2 = seed->GetSnp()*seed->GetSnp();
296 angle2 = angle2/(1-angle2);
297 Float_t angular = landau*angle2*padlength*padlength/12.;
298 Float_t res = sdiff + angular;
301 if ((ctype==0) && (fSectors ==fOuterSec))
302 res *= 0.78 +TMath::Exp(7.4*(rsigmay-1.2));
304 if ((ctype==0) && (fSectors ==fInnerSec))
305 res *= 0.72 +TMath::Exp(3.36*(rsigmay-1.2));
309 res*= TMath::Power((rsigmay+0.5),1.5)+0.0064;
312 res*=2.4; // overestimate error 2 times
319 seed->SetErrorY2(res);
326 Double_t AliTPCtrackerMI::ErrZ2(AliTPCseed* seed, AliTPCclusterMI * cl){
330 Float_t z = TMath::Abs(fParam->GetZLength()-TMath::Abs(seed->GetZ()));
335 const Float_t chmip = 50.;
336 Float_t amp = chmip/0.3;
341 rsigmaz = cl->GetSigmaZ2()/(seed->fCurrentSigmaZ*seed->fCurrentSigmaZ);
342 ctype = cl->GetType();
346 Float_t landau=2 ; //landau fluctuation part
347 Float_t gg=2; // gg fluctuation part
348 Float_t padlength= fSectors->GetPadPitchLength(seed->GetX());
350 if (fSectors==fInnerSec){
354 gg = (2+0.0002*amp)/nel;
355 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
356 if (landau>1) landau=1;
362 gg = (2+0.0002*amp)/nel;
363 landau = (2.+0.12*nprim)*0.5*(amp*amp/40000.+2)/nprim;
364 if (landau>1) landau=1;
366 Float_t sdiff = gg*fParam->GetDiffT()*fParam->GetDiffT()*z;
368 Float_t angle = seed->GetTgl();
369 Float_t angular = landau*angle*angle*padlength*padlength/12.;
370 Float_t res = sdiff + angular;
372 if ((ctype==0) && (fSectors ==fOuterSec))
373 res *= 0.81 +TMath::Exp(6.8*(rsigmaz-1.2));
375 if ((ctype==0) && (fSectors ==fInnerSec))
376 res *= 0.72 +TMath::Exp(2.04*(rsigmaz-1.2));
378 res*= TMath::Power(rsigmaz+0.5,1.5)+0.0064; //0.31+0.147*ctype;
381 if ((ctype<0) &&<70)
388 seed->SetErrorZ2(res);
396 void AliTPCseed::Reset()
403 for (Int_t i=0;i<200;i++) fClusterIndex[i]=-1;
407 Int_t AliTPCseed::GetProlongation(Double_t xk, Double_t &y, Double_t & z) const
409 //-----------------------------------------------------------------
410 // This function find proloncation of a track to a reference plane x=xk.
411 // doesn't change internal state of the track
412 //-----------------------------------------------------------------
414 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1;
415 // Double_t y1=fP0, z1=fP1;
416 Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
417 Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
421 y += dx*(c1+c2)/(r1+r2);
422 z += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
427 //_____________________________________________________________________________
428 Double_t AliTPCseed::GetPredictedChi2(const AliTPCclusterMI *c) const
430 //-----------------------------------------------------------------
431 // This function calculates a predicted chi2 increment.
432 //-----------------------------------------------------------------
433 //Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
434 Double_t r00=fErrorY2, r01=0., r11=fErrorZ2;
435 r00+=fC00; r01+=fC10; r11+=fC11;
437 Double_t det=r00*r11 - r01*r01;
438 if (TMath::Abs(det) < 1.e-10) {
439 Int_t n=GetNumberOfClusters();
440 if (n>4) cerr<<n<<" AliKalmanTrack warning: Singular matrix !\n";
443 Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
445 Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
447 return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
451 //_________________________________________________________________________________________
454 Int_t AliTPCseed::Compare(const TObject *o) const {
455 //-----------------------------------------------------------------
456 // This function compares tracks according to the sector - for given sector according z
457 //-----------------------------------------------------------------
458 AliTPCseed *t=(AliTPCseed*)o;
459 if (t->fRelativeSector>fRelativeSector) return -1;
460 if (t->fRelativeSector<fRelativeSector) return 1;
462 Double_t z2 = t->GetZ();
463 Double_t z1 = GetZ();
465 if (z2<z1) return -1;
469 void AliTPCtrackerMI::RotateToLocal(AliTPCseed *seed)
471 //rotate to track "local coordinata
472 Float_t x = seed->GetX();
473 Float_t y = seed->GetY();
474 Float_t ymax = x*TMath::Tan(0.5*fSectors->GetAlpha());
476 seed->fRelativeSector= (seed->fRelativeSector+1) % fN;
477 if (!seed->Rotate(fSectors->GetAlpha()))
479 } else if (y <-ymax) {
480 seed->fRelativeSector= (seed->fRelativeSector-1+fN) % fN;
481 if (!seed->Rotate(-fSectors->GetAlpha()))
490 //_____________________________________________________________________________
491 Int_t AliTPCseed::Update(const AliTPCclusterMI *c, Double_t chisq, UInt_t index) {
492 //-----------------------------------------------------------------
493 // This function associates a cluster with this track.
494 //-----------------------------------------------------------------
495 // Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
496 //Double_t r00=sigmay2, r01=0., r11=sigmaz2;
497 Double_t r00=fErrorY2, r01=0., r11=fErrorZ2;
499 r00+=fC00; r01+=fC10; r11+=fC11;
500 Double_t det=r00*r11 - r01*r01;
501 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
503 Double_t k00=fC00*r00+fC10*r01, k01=fC00*r01+fC10*r11;
504 Double_t k10=fC10*r00+fC11*r01, k11=fC10*r01+fC11*r11;
505 Double_t k20=fC20*r00+fC21*r01, k21=fC20*r01+fC21*r11;
506 Double_t k30=fC30*r00+fC31*r01, k31=fC30*r01+fC31*r11;
507 Double_t k40=fC40*r00+fC41*r01, k41=fC40*r01+fC41*r11;
509 Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
510 Double_t cur=fP4 + k40*dy + k41*dz, eta=fP2 + k20*dy + k21*dz;
511 if (TMath::Abs(cur*fX-eta) >= 0.9) {
512 // Int_t n=GetNumberOfClusters();
513 //if (n>4) cerr<<n<<" AliTPCtrack warning: Filtering failed !\n";
517 fP0 += k00*dy + k01*dz;
518 fP1 += k10*dy + k11*dz;
520 fP3 += k30*dy + k31*dz;
523 Double_t c01=fC10, c02=fC20, c03=fC30, c04=fC40;
524 Double_t c12=fC21, c13=fC31, c14=fC41;
526 fC00-=k00*fC00+k01*fC10; fC10-=k00*c01+k01*fC11;
527 fC20-=k00*c02+k01*c12; fC30-=k00*c03+k01*c13;
528 fC40-=k00*c04+k01*c14;
530 fC11-=k10*c01+k11*fC11;
531 fC21-=k10*c02+k11*c12; fC31-=k10*c03+k11*c13;
532 fC41-=k10*c04+k11*c14;
534 fC22-=k20*c02+k21*c12; fC32-=k20*c03+k21*c13;
535 fC42-=k20*c04+k21*c14;
537 fC33-=k30*c03+k31*c13;
538 fC43-=k40*c03+k41*c13;
540 fC44-=k40*c04+k41*c14;
542 Int_t n=GetNumberOfClusters();
544 SetNumberOfClusters(n+1);
545 SetChi2(GetChi2()+chisq);
552 //_____________________________________________________________________________
553 Double_t AliTPCtrackerMI::f1(Double_t x1,Double_t y1,
554 Double_t x2,Double_t y2,
555 Double_t x3,Double_t y3)
557 //-----------------------------------------------------------------
558 // Initial approximation of the track curvature
559 //-----------------------------------------------------------------
560 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
561 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
562 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
563 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
564 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
566 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
568 return -xr*yr/sqrt(xr*xr+yr*yr);
572 //_____________________________________________________________________________
573 Double_t AliTPCtrackerMI::f2(Double_t x1,Double_t y1,
574 Double_t x2,Double_t y2,
575 Double_t x3,Double_t y3)
577 //-----------------------------------------------------------------
578 // Initial approximation of the track curvature times center of curvature
579 //-----------------------------------------------------------------
580 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
581 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
582 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
583 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
584 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
586 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
588 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
591 //_____________________________________________________________________________
592 Double_t AliTPCtrackerMI::f3(Double_t x1,Double_t y1,
593 Double_t x2,Double_t y2,
594 Double_t z1,Double_t z2)
596 //-----------------------------------------------------------------
597 // Initial approximation of the tangent of the track dip angle
598 //-----------------------------------------------------------------
599 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
603 Int_t AliTPCtrackerMI::LoadClusters()
606 // load clusters to the memory
607 Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
608 for (Int_t i=0; i<j; i++) {
609 fClustersArray.LoadEntry(i);
614 void AliTPCtrackerMI::UnloadClusters()
617 // load clusters to the memory
618 Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
619 for (Int_t i=0; i<j; i++) {
620 fClustersArray.ClearSegment(i);
626 //_____________________________________________________________________________
627 void AliTPCtrackerMI::LoadOuterSectors() {
628 //-----------------------------------------------------------------
629 // This function fills outer TPC sectors with clusters.
630 //-----------------------------------------------------------------
632 //Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
633 Int_t j = ((AliTPCParam*)fParam)->GetNRowsTotal();
634 for (Int_t i=0; i<j; i++) {
635 // AliSegmentID *s=fClustersArray.LoadEntry(i);
636 AliSegmentID *s= const_cast<AliSegmentID*>(fClustersArray.At(i));
639 AliTPCParam *par=(AliTPCParam*)fClustersArray.GetParam();
640 par->AdjustSectorRow(s->GetID(),sec,row);
641 if (sec<fkNIS*2) continue;
642 AliTPCClustersRow *clrow=fClustersArray.GetRow(sec,row);
643 Int_t ncl=clrow->GetArray()->GetEntriesFast();
645 AliTPCclusterMI *c=(AliTPCclusterMI*)(*clrow)[ncl];
646 index=(((sec<<8)+row)<<16)+ncl;
647 fOuterSec[(sec-fkNIS*2)%fkNOS][row].InsertCluster(c,index);
655 //_____________________________________________________________________________
656 void AliTPCtrackerMI::LoadInnerSectors() {
657 //-----------------------------------------------------------------
658 // This function fills inner TPC sectors with clusters.
659 //-----------------------------------------------------------------
661 //Int_t j=Int_t(fClustersArray.GetTree()->GetEntries());
662 Int_t j = ((AliTPCParam*)fParam)->GetNRowsTotal();
663 for (Int_t i=0; i<j; i++) {
664 // AliSegmentID *s=fClustersArray.LoadEntry(i);
665 AliSegmentID *s=const_cast<AliSegmentID*>(fClustersArray.At(i));
668 AliTPCParam *par=(AliTPCParam*)fClustersArray.GetParam();
669 par->AdjustSectorRow(s->GetID(),sec,row);
670 if (sec>=fkNIS*2) continue;
671 AliTPCClustersRow *clrow=fClustersArray.GetRow(sec,row);
672 Int_t ncl=clrow->GetArray()->GetEntriesFast();
674 AliTPCclusterMI *c=(AliTPCclusterMI*)(*clrow)[ncl];
675 index=(((sec<<8)+row)<<16)+ncl;
676 fInnerSec[sec%fkNIS][row].InsertCluster(c,index);
684 Int_t AliTPCtrackerMI::FollowToNext(AliTPCseed& t, Int_t nr) {
685 //-----------------------------------------------------------------
686 // This function tries to find a track prolongation to next pad row
687 //-----------------------------------------------------------------
688 // Double_t xt=t.GetX();
689 // Int_t row = fSectors->GetRowNumber(xt)-1;
690 // if (row < nr) return 1; // don't prolongate if not information until now -
692 Double_t x=fSectors->GetX(nr), ymax=fSectors->GetMaxY(nr);
693 // if (t.GetRadius()>x+10 ) return 0;
695 if (!t.PropagateTo(x)) {
700 t.fCurrentSigmaY = GetSigmaY(&t);
701 t.fCurrentSigmaZ = GetSigmaZ(&t);
703 AliTPCclusterMI *cl=0;
705 const AliTPCRow &krow=fSectors[t.fRelativeSector][nr];
706 Double_t sy2=ErrY2(&t)*2;
707 Double_t sz2=ErrZ2(&t)*2;
710 Double_t roady =3.*sqrt(t.GetSigmaY2() + sy2);
711 Double_t roadz = 3 *sqrt(t.GetSigmaZ2() + sz2);
712 Double_t y=t.GetY(), z=t.GetZ();
714 if (TMath::Abs(TMath::Abs(y)-ymax)<krow.fDeadZone){
717 if (fSectors==fOuterSec) row += fParam->GetNRowLow();
718 t.fClusterIndex[row] = -1;
723 if (TMath::Abs(z)<(1.05*x+10)) t.fNFoundable++;
728 Float_t maxdistance = roady*roady + roadz*roadz;
730 for (Int_t i=krow.Find(z-roadz); i<krow; i++) {
731 AliTPCclusterMI *c=(AliTPCclusterMI*)(krow[i]);
732 if (c->GetZ() > z+roadz) break;
733 if ( (c->GetY()-y) > roady ) continue;
734 Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
735 if (maxdistance>distance) {
736 maxdistance = distance;
738 // index=krow.GetIndex(i);
744 // Double_t sy2= ErrY2(&t,cl);
745 // Double_t sz2= ErrZ2(&t,cl);
746 // Double_t chi2= t.GetPredictedChi2(cl);
747 // UpdateTrack(&t,cl,chi2,index);
749 t.fCurrentCluster = cl;
750 t.fCurrentClusterIndex1 = krow.GetIndex(index);
751 t.fCurrentClusterIndex2 = index;
752 Double_t sy2=ErrY2(&t,t.fCurrentCluster);
753 Double_t sz2=ErrZ2(&t,t.fCurrentCluster);
755 Double_t sdistancey = TMath::Sqrt(sy2+t.GetSigmaY2());
756 Double_t sdistancez = TMath::Sqrt(sz2+t.GetSigmaZ2());
758 Double_t rdistancey = TMath::Abs(t.fCurrentCluster->GetY()-t.GetY());
759 Double_t rdistancez = TMath::Abs(t.fCurrentCluster->GetZ()-t.GetZ());
761 Double_t rdistance = TMath::Sqrt(TMath::Power(rdistancey/sdistancey,2)+TMath::Power(rdistancez/sdistancez,2));
764 // printf("\t%f\t%f\t%f\n",rdistancey/sdistancey,rdistancez/sdistancez,rdistance);
765 if ( (rdistancey>1) || (rdistancez>1)) return 0;
766 if (rdistance>4) return 0;
768 if ((rdistancey/sdistancey>2.5 || rdistancez/sdistancez>2.5) && t.fCurrentCluster->GetType()==0)
769 return 0; //suspisiouce - will be changed
771 if ((rdistancey/sdistancey>2. || rdistancez/sdistancez>2.0) && t.fCurrentCluster->GetType()>0)
772 // strict cut on overlaped cluster
773 return 0; //suspisiouce - will be changed
775 if ( (rdistancey/sdistancey>1. || rdistancez/sdistancez>2.5 ||t.fCurrentCluster->GetQ()<70 )
776 && t.fCurrentCluster->GetType()<0)
779 // t.SetSampledEdx(0.3*t.fCurrentCluster->GetQ()/l,t.GetNumberOfClusters(), GetSigmaY(&t), GetSigmaZ(&t));
780 UpdateTrack(&t,t.fCurrentCluster,t.GetPredictedChi2(t.fCurrentCluster),t.fCurrentClusterIndex1);
784 t.fRelativeSector= (t.fRelativeSector+1) % fN;
785 if (!t.Rotate(fSectors->GetAlpha()))
787 } else if (y <-ymax) {
788 t.fRelativeSector= (t.fRelativeSector-1+fN) % fN;
789 if (!t.Rotate(-fSectors->GetAlpha()))
797 Int_t AliTPCtrackerMI::UpdateClusters(AliTPCseed& t,Int_t trindex, Int_t nr) {
798 //-----------------------------------------------------------------
799 // This function tries to find a track prolongation to next pad row
800 //-----------------------------------------------------------------
801 t.fCurrentCluster = 0;
802 t.fCurrentClusterIndex1 = 0;
803 t.fCurrentClusterIndex2 = 0;
805 Double_t xt=t.GetX();
806 Int_t row = fSectors->GetRowNumber(xt)-1;
807 if (row < nr) return 1; // don't prolongate if not information until now -
808 Double_t x=fSectors->GetX(nr);
809 // if (t.fStopped) return 0;
810 // if (t.GetRadius()>x+10 ) return 0;
811 if (!t.PropagateTo(x)){
816 t.fCurrentSigmaY = GetSigmaY(&t);
817 t.fCurrentSigmaZ = GetSigmaZ(&t);
819 AliTPCclusterMI *cl=0;
821 AliTPCRow &krow=fSectors[t.fRelativeSector][nr];
823 Double_t y=t.GetY(), z=t.GetZ();
824 Double_t roady = 3.* TMath::Sqrt(t.GetSigmaY2() + t.fCurrentSigmaY*t.fCurrentSigmaY);
825 Double_t roadz = 3.* TMath::Sqrt(t.GetSigmaZ2() + t.fCurrentSigmaZ*t.fCurrentSigmaZ);
828 Float_t maxdistance = 1000000;
830 for (Int_t i=krow.Find(z-roadz); i<krow; i++) {
831 AliTPCclusterMI *c=(AliTPCclusterMI*)(krow[i]);
832 if (c->GetZ() > z+roadz) break;
833 if (TMath::Abs(c->GetY()-y)>roady) continue;
835 //krow.UpdateClusterTrack(i,trindex,&t);
837 Float_t dy2 = (c->GetY()- t.GetY());
839 Float_t dz2 = (c->GetZ()- t.GetZ());
842 Float_t distance = dy2+dz2;
844 if (distance > maxdistance) continue;
845 maxdistance = distance;
850 t.fCurrentCluster = cl;
851 t.fCurrentClusterIndex1 = krow.GetIndex(index);
852 t.fCurrentClusterIndex2 = index;
857 Int_t AliTPCtrackerMI::FollowToNextCluster(Int_t trindex, Int_t nr) {
858 //-----------------------------------------------------------------
859 // This function tries to find a track prolongation to next pad row
860 //-----------------------------------------------------------------
861 AliTPCseed & t = *((AliTPCseed*)(fSeeds->At(trindex)));
862 AliTPCRow &krow=fSectors[t.fRelativeSector][nr];
863 // Double_t pt=t.GetConvConst()/(100/0.299792458/0.2)/t.Get1Pt();
865 Double_t ymax=fSectors->GetMaxY(nr);
867 if (TMath::Abs(TMath::Abs(y)-ymax)<krow.fDeadZone){
870 if (fSectors==fOuterSec) row += fParam->GetNRowLow();
871 t.fClusterIndex[row] = -1;
876 if (TMath::Abs(t.GetZ())<(1.05*t.GetX()+10)) t.fNFoundable++;
881 if (t.fCurrentCluster) {
882 // Float_t l=fSectors->GetPadPitchLength();
883 // AliTPCclusterTracks * cltrack = krow.GetClusterTracks(t.fCurrentClusterIndex1);
885 Double_t sy2=ErrY2(&t,t.fCurrentCluster);
886 Double_t sz2=ErrZ2(&t,t.fCurrentCluster);
889 Double_t sdistancey = TMath::Sqrt(sy2+t.GetSigmaY2());
890 Double_t sdistancez = TMath::Sqrt(sz2+t.GetSigmaZ2());
892 Double_t rdistancey = TMath::Abs(t.fCurrentCluster->GetY()-t.GetY());
893 Double_t rdistancez = TMath::Abs(t.fCurrentCluster->GetZ()-t.GetZ());
895 Double_t rdistance = TMath::Sqrt(TMath::Power(rdistancey/sdistancey,2)+TMath::Power(rdistancez/sdistancez,2));
898 // printf("\t%f\t%f\t%f\n",rdistancey/sdistancey,rdistancez/sdistancez,rdistance);
899 if ( (rdistancey>1) || (rdistancez>1)) return 0;
900 if (rdistance>4) return 0;
902 if ((rdistancey/sdistancey>2.5 || rdistancez/sdistancez>2.5) && t.fCurrentCluster->GetType()==0)
903 return 0; //suspisiouce - will be changed
905 if ((rdistancey/sdistancey>2. || rdistancez/sdistancez>2.0) && t.fCurrentCluster->GetType()>0)
906 // strict cut on overlaped cluster
907 return 0; //suspisiouce - will be changed
909 if ( (rdistancey/sdistancey>1. || rdistancez/sdistancez>2.5 ||t.fCurrentCluster->GetQ()<70 )
910 && t.fCurrentCluster->GetType()<0)
913 // t.SetSampledEdx(0.3*t.fCurrentCluster->GetQ()/l,t.GetNumberOfClusters(), GetSigmaY(&t), GetSigmaZ(&t));
914 UpdateTrack(&t,t.fCurrentCluster,t.GetPredictedChi2(t.fCurrentCluster),t.fCurrentClusterIndex1);
918 t.fRelativeSector= (t.fRelativeSector+1) % fN;
919 if (!t.Rotate(fSectors->GetAlpha()))
921 } else if (y <-ymax) {
922 t.fRelativeSector= (t.fRelativeSector-1+fN) % fN;
923 if (!t.Rotate(-fSectors->GetAlpha()))
934 Int_t AliTPCtrackerMI::FollowProlongationFast(AliTPCseed& t, Int_t step)
936 //-----------------------------------------------------------------
937 // fast prolongation mathod -
938 // don't update track only after step clusters
939 //-----------------------------------------------------------------
940 Double_t xt=t.GetX();
942 Double_t alpha=t.GetAlpha();
943 alpha =- fSectors->GetAlphaShift();
944 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
945 if (alpha < 0. ) alpha += 2.*TMath::Pi();
946 t.fRelativeSector = Int_t(alpha/fSectors->GetAlpha())%fN;
947 Int_t row0 = fSectors->GetRowNumber(xt);
948 Double_t x = fSectors->GetX(row0);
949 Double_t ymax = fSectors->GetMaxY(row0);
951 Double_t sy2=ErrY2(&t)*2;
952 Double_t sz2=ErrZ2(&t)*2;
953 Double_t roady =3.*sqrt(t.GetSigmaY2() + sy2);
954 Double_t roadz = 3 *sqrt(t.GetSigmaZ2() + sz2);
955 Float_t maxdistance = roady*roady + roadz*roadz;
956 t.fCurrentSigmaY = GetSigmaY(&t);
957 t.fCurrentSigmaZ = GetSigmaZ(&t);
962 Double_t yy[200]; //track prolongation
964 Double_t cy[200]; // founded cluster position
966 Double_t sy[200]; // founded cluster error
968 Bool_t hitted[200]; // indication of cluster presence
972 for (Int_t drow = step; drow>=0; drow--) {
973 Int_t row = row0-drow;
975 Double_t x = fSectors->GetX(row);
976 Double_t ymax = fSectors->GetMaxY(row);
977 t.GetProlongation(x,y,z);
980 const AliTPCRow &krow=fSectors[t.fRelativeSector][row];
981 if (TMath::Abs(TMath::Abs(y)-ymax)<krow.fDeadZone){
990 //find nearest cluster
991 AliTPCclusterMI *cl= 0;
993 for (Int_t i=krow.Find(z-roadz); i<krow; i++) {
994 AliTPCclusterMI *c=(AliTPCclusterMI*)(krow[i]);
995 if (c->GetZ() > z+roadz) break;
996 if ( (c->GetY()-y) > roady ) continue;
997 Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
998 if (maxdistance>distance) {
999 maxdistance = distance;
1001 // index=krow.GetIndex(i);
1005 //update cluster information
1007 cy[drow] = cl->GetY();
1008 cz[drow] = cl->GetZ();
1009 sy[drow] = ErrY2(&t,cl);
1010 sz[drow] = ErrZ2(&t,cl);
1011 hitted[drow] = kTRUE;
1015 hitted[drow] = kFALSE;
1017 //if we have information - update track
1024 for (Int_t i=0;i<step;i++)
1029 sumyw+= (cy[i]-yy[i])/sy[i];
1030 sumzw+= (cz[i]-zz[i])/sz[i];
1033 Float_t dy = sumyw/sumyw0;
1034 Float_t dz = sumzw/sumzw0;
1035 Float_t mrow = sumrow/nclusters+row0;
1036 Float_t x = fSectors->GetX(mrow);
1038 AliTPCclusterMI cvirtual;
1039 cvirtual.SetZ(dz+t.GetZ());
1040 cvirtual.SetY(dy+t.GetY());
1041 t.SetErrorY2(1.2*t.fErrorY2/TMath::Sqrt(Float_t(nclusters)));
1042 t.SetErrorZ2(1.2*t.fErrorZ2/TMath::Sqrt(Float_t(nclusters)));
1043 Float_t chi2 = t.GetPredictedChi2(&cvirtual);
1044 t.Update(&cvirtual,chi2,0);
1045 Int_t ncl = t.GetNumberOfClusters();
1046 ncl = ncl-1+nclusters;
1053 //_____________________________________________________________________________
1054 Int_t AliTPCtrackerMI::FollowProlongation(AliTPCseed& t, Int_t rf) {
1055 //-----------------------------------------------------------------
1056 // This function tries to find a track prolongation.
1057 //-----------------------------------------------------------------
1058 Double_t xt=t.GetX();
1060 Double_t alpha=t.GetAlpha() - fSectors->GetAlphaShift();
1061 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
1062 if (alpha < 0. ) alpha += 2.*TMath::Pi();
1063 t.fRelativeSector = Int_t(alpha/fSectors->GetAlpha())%fN;
1065 for (Int_t nr=fSectors->GetRowNumber(xt)-1; nr>=rf; nr--) {
1067 if (FollowToNext(t,nr)==0) {
1074 //_____________________________________________________________________________
1075 Int_t AliTPCtrackerMI::FollowBackProlongation(AliTPCseed& t, Int_t rf) {
1076 //-----------------------------------------------------------------
1077 // This function tries to find a track prolongation.
1078 //-----------------------------------------------------------------
1079 Double_t xt=t.GetX();
1081 Double_t alpha=t.GetAlpha() - fSectors->GetAlphaShift();
1082 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
1083 if (alpha < 0. ) alpha += 2.*TMath::Pi();
1084 t.fRelativeSector = Int_t(alpha/fSectors->GetAlpha())%fN;
1086 for (Int_t nr=fSectors->GetRowNumber(xt)+1; nr<=rf; nr++) {
1097 Float_t AliTPCtrackerMI::OverlapFactor(AliTPCseed * s1, AliTPCseed * s2, Int_t &sum1, Int_t & sum2)
1105 Float_t dz2 =(s1->GetZ() - s2->GetZ());
1108 Float_t x = s1->GetX();
1109 Float_t x2 = s2->GetX();
1111 Float_t ymax = x*TMath::Tan(0.5*fSectors->GetAlpha());
1113 Float_t dy2 =TMath::Abs((s1->GetY() - s2->GetY()));
1114 //if (TMath::Abs(dy2)>2*ymax-3)
1117 Float_t distance = TMath::Sqrt(dz2+dy2);
1118 if (distance>4.) return 0; // if there are far away - not overlap - to reduce combinatorics
1121 if (fSectors==fOuterSec) offset = fParam->GetNRowLow();
1122 Int_t firstpoint = TMath::Min(s1->fFirstPoint,s2->fFirstPoint);
1123 Int_t lastpoint = TMath::Max(s1->fLastPoint,s2->fLastPoint);
1130 if (firstpoint<lastpoint-15) {
1136 for (Int_t i=firstpoint;i<lastpoint;i++){
1137 if (s1->fClusterIndex[i]>0) sum1++;
1138 if (s2->fClusterIndex[i]>0) sum2++;
1139 if (s1->fClusterIndex[i]==s2->fClusterIndex[i] && s1->fClusterIndex[i]>0) {
1144 Float_t summin = TMath::Min(sum1+1,sum2+1);
1145 Float_t ratio = (sum+1)/Float_t(summin);
1149 void AliTPCtrackerMI::SignShared(AliTPCseed * s1, AliTPCseed * s2)
1153 if (s1->fSector!=s2->fSector) return;
1155 Float_t dz2 =(s1->GetZ() - s2->GetZ());
1157 Float_t dy2 =(s1->GetY() - s2->GetY());
1160 Float_t distance = TMath::Sqrt(dz2+dy2);
1161 if (distance>15.) return ; // if there are far away - not overlap - to reduce combinatorics
1162 //trpoint = new (pointarray[track->fRow]) AliTPCTrackPoint;
1163 // TClonesArray &pointarray1 = *(s1->fPoints);
1164 //TClonesArray &pointarray2 = *(s2->fPoints);
1166 for (Int_t i=0;i<160;i++){
1167 if (s1->fClusterIndex[i]==s2->fClusterIndex[i] && s1->fClusterIndex[i]>0) {
1168 // AliTPCTrackPoint *p1 = (AliTPCTrackPoint *)(pointarray1.UncheckedAt(i));
1169 //AliTPCTrackPoint *p2 = (AliTPCTrackPoint *)(pointarray2.UncheckedAt(i));
1170 AliTPCTrackPoint *p1 = s1->GetTrackPoint(i);
1171 AliTPCTrackPoint *p2 = s2->GetTrackPoint(i);;
1172 p1->fIsShared = kTRUE;
1173 p2->fIsShared = kTRUE;
1181 void AliTPCtrackerMI::RemoveOverlap(TObjArray * arr, Float_t factor, Int_t removalindex , Bool_t shared){
1186 // remove overlap - used removal factor - removal index stored in the track
1187 for (Int_t i=0; i<arr->GetEntriesFast(); i++) {
1188 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1189 if (pt) RotateToLocal(pt);
1191 arr->Sort(); // sorting according z
1192 arr->Expand(arr->GetEntries());
1193 Int_t nseed=arr->GetEntriesFast();
1194 // printf("seeds \t%p \t%d\n",arr, nseed);
1195 // arr->Expand(arr->GetEntries()); //remove 0 pointers
1196 nseed = arr->GetEntriesFast();
1198 for (Int_t i=0; i<nseed; i++) {
1199 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1203 if (!(pt->IsActive())) continue;
1204 for (Int_t j=i+1; j<nseed; j++){
1205 AliTPCseed *pt2=(AliTPCseed*)arr->UncheckedAt(j);
1208 if (!(pt2->IsActive())) continue;
1209 if (TMath::Abs(pt->fRelativeSector-pt2->fRelativeSector)>0) break;
1210 if (TMath::Abs(pt2->GetZ()-pt->GetZ())<4){
1212 Float_t ratio = OverlapFactor(pt,pt2,sum1,sum2);
1214 // pt->Desactivate(removalindex); // arr->RemoveAt(i);
1218 // if (pt->GetChi2()<pt2->GetChi2()) pt2->Desactivate(removalindex); // arr->RemoveAt(j);
1219 Float_t ratio2 = (pt->GetChi2()*sum2)/(pt2->GetChi2()*sum1);
1220 Float_t ratio3 = Float_t(sum1-sum2)/Float_t(sum1+sum2);
1222 if (TMath::Abs(ratio3)>0.025){ // if much more points
1223 if (sum1>sum2) pt2->Desactivate(removalindex);
1225 pt->Desactivate(removalindex); // arr->RemoveAt(i);
1229 else{ //decide on mean chi2
1231 pt2->Desactivate(removalindex);
1233 pt->Desactivate(removalindex); // arr->RemoveAt(i);
1238 } // if suspicious ratio
1244 // printf("removed\t%d\n",removed);
1246 for (Int_t i=0; i<nseed; i++) {
1247 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1249 if (pt->GetNumberOfClusters() < pt->fNFoundable*0.5) {
1250 //desactivate tracks with small number of points
1251 // printf("%d\t%d\t%f\n", pt->GetNumberOfClusters(), pt->fNFoundable,pt->GetNumberOfClusters()/Float_t(pt->fNFoundable));
1252 pt->Desactivate(10); //desactivate - small muber of points
1254 if (!(pt->IsActive())) continue;
1260 for (Int_t i=0; i<nseed; i++) {
1261 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1263 if (!(pt->IsActive())) continue;
1264 for (Int_t j=i+1; j<nseed; j++){
1265 AliTPCseed *pt2=(AliTPCseed*)arr->UncheckedAt(j);
1266 if ((pt2) && pt2->IsActive()) {
1267 if ( TMath::Abs(pt->fSector-pt2->fSector)>1) break;
1273 printf("\n*****\nNumber of good tracks after overlap removal\t%d\n",fNtracks);
1278 void AliTPCtrackerMI::RemoveUsed(TObjArray * arr, Float_t factor, Int_t removalindex)
1281 //Loop over all tracks and remove "overlaps"
1284 Int_t nseed = arr->GetEntriesFast();
1286 for (Int_t i=0; i<nseed; i++) {
1287 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1291 if (!(pt->IsActive())) continue;
1292 Int_t noc=pt->GetNumberOfClusters();
1294 for (Int_t i=0; i<noc; i++) {
1295 Int_t index=pt->GetClusterIndex(i);
1296 AliTPCclusterMI *c=(AliTPCclusterMI*)GetClusterMI(index);
1298 if (c->IsUsed()) shared++;
1300 if ((Float_t(shared)/Float_t(noc))>factor)
1301 pt->Desactivate(removalindex);
1304 for (Int_t i=0; i<noc; i++) {
1305 Int_t index=pt->GetClusterIndex(i);
1306 AliTPCclusterMI *c=(AliTPCclusterMI*)GetClusterMI(index);
1313 printf("\n*****\nNumber of good tracks after shared removal\t%d\n",fNtracks);
1318 void AliTPCtrackerMI::MakeSeedsAll()
1320 if (fSeeds == 0) fSeeds = new TObjArray;
1322 for (Int_t sec=0;sec<fkNOS;sec+=3){
1323 arr = MakeSeedsSectors(sec,sec+3);
1324 Int_t nseed = arr->GetEntriesFast();
1325 for (Int_t i=0;i<nseed;i++)
1326 fSeeds->AddLast(arr->RemoveAt(i));
1328 // fSeeds = MakeSeedsSectors(0,fkNOS);
1331 TObjArray * AliTPCtrackerMI::MakeSeedsSectors(Int_t sec1, Int_t sec2)
1334 // loop over all sectors and make seed
1337 Int_t nup=fOuterSec->GetNRows(), nlow=fInnerSec->GetNRows();
1338 Int_t nrows=nlow+nup;
1339 Int_t gap=Int_t(0.125*nrows), shift=Int_t(0.5*gap);
1340 // if (fSeeds==0) fSeeds = new TObjArray;
1341 TObjArray * arr = new TObjArray;
1343 for (Int_t sec=sec1; sec<sec2;sec++){
1344 MakeSeeds(arr, sec, nup-1, nup-1-gap);
1345 MakeSeeds(arr, sec, nup-2-shift, nup-2-shift-gap);
1347 gap = Int_t(0.2* nrows);
1348 for (Int_t sec=sec1; sec<sec2;sec++){
1350 //MakeSeeds2(arr, sec, nup-1, nup-1-gap);
1351 MakeSeeds2(arr, sec, nup-1-shift, nup-1-shift-gap);
1352 //MakeSeeds2(arr, sec, nup-1-2*shift, nup-1-2*shift-gap);
1353 MakeSeeds2(arr, sec, nup-1-3*shift, nup-1-3*shift-gap);
1354 //MakeSeeds2(arr, sec, nup-1-4*shift, nup-1-4*shift-gap);
1355 MakeSeeds2(arr, sec, nup-1-5*shift, nup-1-5*shift-gap);
1356 MakeSeeds2(arr, sec, gap, 1);
1359 Int_t nseed=arr->GetEntriesFast();
1362 gap=Int_t(0.3*nrows);
1364 for (i=0; i<nseed; i++) {
1365 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i), &t=*pt;
1367 if (FollowProlongation(t,nup-gap)) {
1368 pt->fIsSeeding =kFALSE;
1371 delete arr->RemoveAt(i);
1376 //remove seeds which overlaps
1377 RemoveOverlap(arr,0.4,1);
1378 //delete seeds - which were sign
1379 nseed=arr->GetEntriesFast();
1380 for (i=0; i<nseed; i++) {
1381 AliTPCseed *pt=(AliTPCseed*)arr->UncheckedAt(i);
1384 if ((pt->IsActive()) && pt->GetNumberOfClusters() > pt->fNFoundable*0.5 ) {
1386 //FollowBackProlongation(*pt,nup-1);
1387 //if ( pt->GetNumberOfClusters() < pt->fNFoundable*0.5 || pt->GetNumberOfClusters()<10 )
1388 //delete arr->RemoveAt(i);
1393 delete arr->RemoveAt(i);
1395 //RemoveOverlap(arr,0.6,1);
1401 //_____________________________________________________________________________
1402 void AliTPCtrackerMI::MakeSeeds(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2) {
1403 //-----------------------------------------------------------------
1404 // This function creates track seeds.
1405 //-----------------------------------------------------------------
1406 // if (fSeeds==0) fSeeds=new TObjArray(15000);
1408 Double_t x[5], c[15];
1410 Double_t alpha=fOuterSec->GetAlpha(), shift=fOuterSec->GetAlphaShift();
1411 Double_t cs=cos(alpha), sn=sin(alpha);
1413 Double_t x1 =fOuterSec->GetX(i1);
1414 Double_t xx2=fOuterSec->GetX(i2);
1416 // for (Int_t ns=0; ns<fkNOS; ns++)
1419 Int_t nl=fOuterSec[(ns-1+fkNOS)%fkNOS][i2];
1420 Int_t nm=fOuterSec[ns][i2];
1421 Int_t nu=fOuterSec[(ns+1)%fkNOS][i2];
1422 const AliTPCRow& kr1=fOuterSec[ns][i1];
1423 AliTPCRow& kr21 = fOuterSec[(ns-1+fkNOS)%fkNOS][i2];
1424 AliTPCRow& kr22 = fOuterSec[(ns)%fkNOS][i2];
1425 AliTPCRow& kr23 = fOuterSec[(ns+1)%fkNOS][i2];
1427 for (Int_t is=0; is < kr1; is++) {
1428 Double_t y1=kr1[is]->GetY(), z1=kr1[is]->GetZ();
1429 Double_t x3=GetX(), y3=GetY(), z3=GetZ();
1431 Float_t anglez = (z1-z3)/(x1-x3);
1432 Float_t extraz = z1 - anglez*(x1-xx2); // extrapolated z
1434 for (Int_t js=0; js < nl+nm+nu; js++) {
1435 const AliTPCclusterMI *kcl;
1436 Double_t x2, y2, z2;
1439 js = kr21.Find(extraz-15.);
1440 if (js>=nl) continue;
1444 if ((extraz-z2)>10) continue;
1445 if ((extraz-z2)<-10) {
1455 js = nl+kr22.Find(extraz-15.);
1456 if (js>=nl+nm) continue;
1460 if ((extraz-z2)>10) continue;
1461 if ((extraz-z2)<-10) {
1465 x2=xx2; y2=kcl->GetY();
1467 //const AliTPCRow& kr2=fOuterSec[(ns+1)%fkNOS][i2];
1469 js = nl+nm+kr23.Find(extraz-15.);
1470 if (js>=nl+nm+nu) break;
1474 if ((extraz-z2)>10) continue;
1475 if ((extraz-z2)<-10) {
1483 Double_t zz=z1 - anglez*(x1-x2);
1484 if (TMath::Abs(zz-z2)>10.) continue;
1486 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
1487 if (d==0.) {cerr<<"MakeSeeds warning: Straight seed !\n"; continue;}
1491 x[4]=f1(x1,y1,x2,y2,x3,y3);
1492 if (TMath::Abs(x[4]) >= 0.0066) continue;
1493 x[2]=f2(x1,y1,x2,y2,x3,y3);
1494 //if (TMath::Abs(x[4]*x1-x[2]) >= 0.99999) continue;
1495 x[3]=f3(x1,y1,x2,y2,z1,z2);
1496 if (TMath::Abs(x[3]) > 1.2) continue;
1497 Double_t a=asin(x[2]);
1498 Double_t zv=z1 - x[3]/x[4]*(a+asin(x[4]*x1-x[2]));
1499 if (TMath::Abs(zv-z3)>10.) continue;
1501 Double_t sy1=kr1[is]->GetSigmaY2()*2, sz1=kr1[is]->GetSigmaZ2()*4;
1502 Double_t sy2=kcl->GetSigmaY2()*2, sz2=kcl->GetSigmaZ2()*4;
1503 //Double_t sy3=400*3./12., sy=0.1, sz=0.1;
1504 Double_t sy3=25000*x[4]*x[4]+0.1, sy=0.1, sz=0.1;
1505 //Double_t sy3=25000*x[4]*x[4]*60+0.5, sy=0.1, sz=0.1;
1507 Double_t f40=(f1(x1,y1+sy,x2,y2,x3,y3)-x[4])/sy;
1508 Double_t f42=(f1(x1,y1,x2,y2+sy,x3,y3)-x[4])/sy;
1509 Double_t f43=(f1(x1,y1,x2,y2,x3,y3+sy)-x[4])/sy;
1510 Double_t f20=(f2(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
1511 Double_t f22=(f2(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
1512 Double_t f23=(f2(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
1513 Double_t f30=(f3(x1,y1+sy,x2,y2,z1,z2)-x[3])/sy;
1514 Double_t f31=(f3(x1,y1,x2,y2,z1+sz,z2)-x[3])/sz;
1515 Double_t f32=(f3(x1,y1,x2,y2+sy,z1,z2)-x[3])/sy;
1516 Double_t f34=(f3(x1,y1,x2,y2,z1,z2+sz)-x[3])/sz;
1520 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f23*sy3*f23;
1521 c[6]=f30*sy1; c[7]=f31*sz1; c[8]=f30*sy1*f20+f32*sy2*f22;
1522 c[9]=f30*sy1*f30+f31*sz1*f31+f32*sy2*f32+f34*sz2*f34;
1523 c[10]=f40*sy1; c[11]=0.; c[12]=f40*sy1*f20+f42*sy2*f22+f43*sy3*f23;
1524 c[13]=f30*sy1*f40+f32*sy2*f42;
1525 c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
1527 UInt_t index=kr1.GetIndex(is);
1528 AliTPCseed *track=new AliTPCseed(index, x, c, x1, ns*alpha+shift);
1529 track->fIsSeeding = kTRUE;
1530 //Int_t rc=FollowProlongation(*track, i2);
1531 Int_t delta4 = Int_t((i2-i1)/4.);
1533 FollowProlongation(*track, i1-delta4);
1534 if (track->GetNumberOfClusters() < track->fNFoundable/2.) {
1538 FollowProlongation(*track, i1-2*delta4);
1539 if (track->GetNumberOfClusters() < track->fNFoundable/2.) {
1543 FollowProlongation(*track, i1-3*delta4);
1544 if (track->GetNumberOfClusters() < track->fNFoundable/2.) {
1548 FollowProlongation(*track, i2);
1551 track->fLastPoint = i1; // first cluster in track position
1552 if (track->GetNumberOfClusters()<(i1-i2)/4 || track->GetNumberOfClusters() < track->fNFoundable/2. ) delete track;
1553 else arr->AddLast(track);
1560 //_____________________________________________________________________________
1561 void AliTPCtrackerMI::MakeSeeds2(TObjArray * arr, Int_t sec, Int_t i1, Int_t i2) {
1562 //-----------------------------------------------------------------
1563 // This function creates track seeds - without vertex constraint
1564 //-----------------------------------------------------------------
1566 Double_t alpha=fOuterSec->GetAlpha(), shift=fOuterSec->GetAlphaShift();
1567 // Double_t cs=cos(alpha), sn=sin(alpha);
1568 Int_t row0 = (i1+i2)/2;
1569 Int_t drow = (i1-i2)/2;
1570 const AliTPCRow& kr0=fSectors[sec][row0];
1571 const AliTPCRow& krm=fSectors[sec][row0-1];
1572 const AliTPCRow& krp=fSectors[sec][row0+1];
1575 AliTPCpolyTrack polytrack;
1576 Int_t nclusters=fSectors[sec][row0];
1578 for (Int_t is=0; is < nclusters; is++) {
1579 const AliTPCclusterMI * cl= kr0[is];
1580 Double_t x = kr0.GetX();
1582 // Initialization of the polytrack
1585 Double_t y0= cl->GetY();
1586 Double_t z0= cl->GetZ();
1587 polytrack.AddPoint(x,y0,z0);
1588 Float_t roady = 5*TMath::Sqrt(cl->GetSigmaY2()+0.2);
1589 Float_t roadz = 5*TMath::Sqrt(cl->GetSigmaZ2()+0.2);
1592 cl = krm.FindNearest(y0,z0,roady,roadz);
1593 if (cl) polytrack.AddPoint(x,cl->GetY(),cl->GetZ(),roady,roadz);
1596 cl = krp.FindNearest(y0,z0,roady,roadz);
1597 if (cl) polytrack.AddPoint(x,cl->GetY(),cl->GetZ(),cl->GetSigmaY2()+0.05,cl->GetSigmaZ2()+0.05);
1599 polytrack.UpdateParameters();
1605 Int_t nfoundable = polytrack.GetN();
1606 Int_t nfound = nfoundable;
1607 for (Int_t ddrow = 2; ddrow<drow;ddrow++){
1608 for (Int_t delta = -1;delta<=1;delta+=2){
1609 Int_t row = row0+ddrow*delta;
1610 kr = &(fSectors[sec][row]);
1611 Double_t xn = kr->GetX();
1612 Double_t ymax = fSectors->GetMaxY(row)-kr->fDeadZone;
1613 polytrack.GetFitPoint(xn,yn,zn);
1614 if (TMath::Abs(yn)>ymax) continue;
1616 AliTPCclusterMI * cln = kr->FindNearest(yn,zn,roady,roadz);
1618 polytrack.AddPoint(xn,cln->GetY(),cln->GetZ(),cln->GetSigmaY2()+0.05,cln->GetSigmaZ2()+0.05);
1622 polytrack.UpdateParameters();
1623 if (nfound<0.45*nfoundable) break;
1625 if ((nfound>0.5*nfoundable) &&( nfoundable>0.4*(i1-i2))) {
1626 // add polytrack candidate
1627 Double_t x[5], c[15];
1628 Double_t x1,x2,x3,y1,y2,y3,z1,z2,z3;
1629 polytrack.GetBoundaries(x3,x1);
1631 polytrack.GetFitPoint(x1,y1,z1);
1632 polytrack.GetFitPoint(x2,y2,z2);
1633 polytrack.GetFitPoint(x3,y3,z3);
1635 //is track pointing to the vertex ?
1638 polytrack.GetFitPoint(x0,y0,z0);
1639 if ( (TMath::Abs(z0-GetZ())<10) && (TMath::Abs(y0-GetY())<5)){ //if yes apply vertex constraint
1647 x[4]=f1(x1,y1,x2,y2,x3,y3);
1648 if (TMath::Abs(x[4]) >= 0.05) continue; //MI change
1649 x[2]=f2(x1,y1,x2,y2,x3,y3);
1650 //if (TMath::Abs(x[4]*x1-x[2]) >= 0.99999) continue;
1651 x[3]=f3(x1,y1,x2,y2,z1,z2);
1652 if (TMath::Abs(x[3]) > 1.2) continue;
1653 if (TMath::Abs(x[2]) > 0.99) continue;
1654 // Double_t a=asin(x[2]);
1657 Double_t sy=1.5, sz=1.5;
1658 Double_t sy1=1.5, sz1=1.5;
1659 Double_t sy2=1.3, sz2=1.3;
1662 //Double_t sy3=400*3./12., sy=0.1, sz=0.1;
1663 // Double_t sy3=25000*x[4]*x[4]+0.1, sy=0.1, sz=0.1;
1664 //Double_t sy3=25000*x[4]*x[4]*60+0.5, sy=0.1, sz=0.1;
1666 Double_t f40=(f1(x1,y1+sy,x2,y2,x3,y3)-x[4])/sy;
1667 Double_t f42=(f1(x1,y1,x2,y2+sy,x3,y3)-x[4])/sy;
1668 Double_t f43=(f1(x1,y1,x2,y2,x3,y3+sy)-x[4])/sy;
1669 Double_t f20=(f2(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
1670 Double_t f22=(f2(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
1671 Double_t f23=(f2(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
1672 Double_t f30=(f3(x1,y1+sy,x2,y2,z1,z2)-x[3])/sy;
1673 Double_t f31=(f3(x1,y1,x2,y2,z1+sz,z2)-x[3])/sz;
1674 Double_t f32=(f3(x1,y1,x2,y2+sy,z1,z2)-x[3])/sy;
1675 Double_t f34=(f3(x1,y1,x2,y2,z1,z2+sz)-x[3])/sz;
1679 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f23*sy3*f23;
1680 c[6]=f30*sy1; c[7]=f31*sz1; c[8]=f30*sy1*f20+f32*sy2*f22;
1681 c[9]=f30*sy1*f30+f31*sz1*f31+f32*sy2*f32+f34*sz2*f34;
1682 c[10]=f40*sy1; c[11]=0.; c[12]=f40*sy1*f20+f42*sy2*f22+f43*sy3*f23;
1683 c[13]=f30*sy1*f40+f32*sy2*f42;
1684 c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
1688 AliTPCseed *track=new AliTPCseed(index, x, c, x1, sec*alpha+shift);
1689 track->fStopped =kFALSE;
1690 track->fIsSeeding = kTRUE;
1691 Int_t rc=FollowProlongation(*track, i2);
1692 track->fLastPoint = i1; // first cluster in track position
1693 if (rc==0 || track->GetNumberOfClusters()<(i1-i2)/4 || track->GetNumberOfClusters() < track->fNFoundable/2. ) delete track;
1694 else arr->AddLast(track);
1706 //_____________________________________________________________________________
1707 Int_t AliTPCtrackerMI::ReadSeeds(const TFile *inp) {
1708 //-----------------------------------------------------------------
1709 // This function reades track seeds.
1710 //-----------------------------------------------------------------
1711 TDirectory *savedir=gDirectory;
1713 TFile *in=(TFile*)inp;
1714 if (!in->IsOpen()) {
1715 cerr<<"AliTPCtrackerMI::ReadSeeds(): input file is not open !\n";
1720 TTree *seedTree=(TTree*)in->Get("Seeds");
1722 cerr<<"AliTPCtrackerMI::ReadSeeds(): ";
1723 cerr<<"can't get a tree with track seeds !\n";
1726 AliTPCtrack *seed=new AliTPCtrack;
1727 seedTree->SetBranchAddress("tracks",&seed);
1729 if (fSeeds==0) fSeeds=new TObjArray(15000);
1731 Int_t n=(Int_t)seedTree->GetEntries();
1732 for (Int_t i=0; i<n; i++) {
1733 seedTree->GetEvent(i);
1734 fSeeds->AddLast(new AliTPCseed(*seed,seed->GetAlpha()));
1743 //_____________________________________________________________________________
1744 Int_t AliTPCtrackerMI::Clusters2Tracks(const TFile *inp, TFile *out) {
1745 //-----------------------------------------------------------------
1746 // This is a track finder.
1747 //-----------------------------------------------------------------
1748 TDirectory *savedir=gDirectory;
1751 TFile *in=(TFile*)inp;
1752 if (!in->IsOpen()) {
1753 cerr<<"AliTPCtrackerMI::Clusters2Tracks(): input file is not open !\n";
1758 if (!out->IsOpen()) {
1759 cerr<<"AliTPCtrackerMI::Clusters2Tracks(): output file is not open !\n";
1766 sprintf(tname,"TreeT_TPC_%d",fEventN);
1767 TTree tracktree(tname,"Tree with TPC tracks");
1768 TTree seedtree("Seeds","Seeds");
1769 AliTPCtrack *iotrack=0;
1770 AliTPCseed *ioseed=0;
1771 tracktree.Branch("tracks","AliTPCtrack",&iotrack,32000,0);
1774 printf("Loading clusters \n");
1776 printf("Time for loading clusters: \t");timer.Print();timer.Start();
1778 printf("Loading outer sectors\n");
1780 printf("Time for loading outer sectors: \t");timer.Print();timer.Start();
1782 printf("Loading inner sectors\n");
1784 printf("Time for loading inner sectors: \t");timer.Print();timer.Start();
1785 fSectors = fOuterSec;
1791 printf("Time for seeding: \t"); timer.Print();timer.Start();
1792 Int_t nup=fOuterSec->GetNRows(), nlow=fInnerSec->GetNRows();
1793 Int_t nrows=nlow+nup;
1795 Int_t gap=Int_t(0.3*nrows);
1797 //RemoveOverlap(fSeeds,0.6,2);
1798 Int_t nseed=fSeeds->GetEntriesFast();
1799 // outer sectors parallel tracking
1800 ParallelTracking(fSectors->GetNRows()-gap-1,0);
1801 printf("Time for parralel tracking outer sectors: \t"); timer.Print();timer.Start();
1803 RemoveOverlap(fSeeds, 0.4,3);
1804 printf("Time for removal overlap- outer sectors: \t");timer.Print();timer.Start();
1806 fSectors = fInnerSec;
1809 ParallelTracking(fSectors->GetNRows()-1,0);
1811 ParallelTracking(fSectors->GetNRows()-1,2*fSectors->GetNRows()/3);
1812 RemoveOverlap(fSeeds,0.4,5,kTRUE);
1813 ParallelTracking(2*fSectors->GetNRows()/3-1,fSectors->GetNRows()/3);
1814 RemoveOverlap(fSeeds,0.4,5,kTRUE);
1815 ParallelTracking(fSectors->GetNRows()/3-1,0);
1817 printf("Number of tracks after inner tracking %d\n",fNtracks);
1818 printf("Time for parralel tracking inner sectors: \t"); timer.Print();timer.Start();
1820 for (Int_t i=0;i<fSeeds->GetEntriesFast();i++){
1821 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i);
1823 if (!pt->IsActive()) continue;
1824 pt->PropagateTo(90.);
1826 RemoveOverlap(fSeeds,0.4,5,kTRUE); // remove overlap - shared points signed
1827 RemoveUsed(fSeeds,0.4,6);
1828 printf("Time for removal overlap- inner sectors: \t"); timer.Print();timer.Start();
1832 ioseed = (AliTPCseed*)(fSeeds->UncheckedAt(0));
1833 AliTPCseed * vseed = new AliTPCseed;
1834 vseed->fPoints = new TClonesArray("AliTPCTrackPoint",1);
1835 vseed->fEPoints = new TClonesArray("AliTPCExactPoint",1);
1836 vseed->fPoints->ExpandCreateFast(2);
1838 //TBranch * seedbranch =
1839 seedtree.Branch("seeds","AliTPCseed",&vseed,32000,99);
1841 nseed=fSeeds->GetEntriesFast();
1844 for (i=0; i<nseed; i++) {
1845 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
1847 Int_t nc=t.GetNumberOfClusters();
1848 if (nc<20) continue;
1849 t.CookdEdx(0.02,0.6);
1850 CookLabel(pt,0.1); //For comparison only
1851 // if ((pt->IsActive()) && (nc>Int_t(0.4*nrows))){
1852 if ((pt->IsActive()) && (nc>Int_t(0.5*t.fNFoundable) && (t.fNFoundable>Int_t(0.3*nrows)))){
1855 // cerr<<found++<<'\r';
1859 seedbranch->SetAddress(&pt);
1862 for (Int_t j=0;j<160;j++){
1863 delete pt->fPoints->RemoveAt(j);
1868 delete fSeeds->RemoveAt(i);
1870 // fNTracks = found;
1871 printf("Time for track writing and dedx cooking: \t"); timer.Print();timer.Start();
1874 printf("Time for unloading cluster: \t"); timer.Print();timer.Start();
1878 cerr<<"Number of found tracks : "<<"\t"<<found<<endl;
1886 void AliTPCtrackerMI::ParallelTracking(Int_t rfirst, Int_t rlast)
1889 // try to track in parralel
1891 Int_t nseed=fSeeds->GetEntriesFast();
1892 //prepare seeds for tracking
1893 for (Int_t i=0; i<nseed; i++) {
1894 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
1896 if (!t.IsActive()) continue;
1897 // follow prolongation to the first layer
1898 if ( (fSectors ==fInnerSec) || (t.fFirstPoint>rfirst+1))
1899 FollowProlongation(t, rfirst+1);
1904 for (Int_t nr=rfirst; nr>=rlast; nr--){
1905 // make indexes with the cluster tracks for given
1906 // for (Int_t i = 0;i<fN;i++)
1907 // fSectors[i][nr].MakeClusterTracks();
1909 // find nearest cluster
1910 for (Int_t i=0; i<nseed; i++) {
1911 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i), &t=*pt;
1913 if (!pt->IsActive()) continue;
1914 if ( (fSectors ==fOuterSec) && pt->fFirstPoint<nr) continue;
1915 if (pt->fRelativeSector>17) {
1918 UpdateClusters(t,i,nr);
1920 // prolonagate to the nearest cluster - if founded
1921 for (Int_t i=0; i<nseed; i++) {
1922 AliTPCseed *pt=(AliTPCseed*)fSeeds->UncheckedAt(i);
1924 if (!pt->IsActive()) continue;
1925 if ((fSectors ==fOuterSec) &&pt->fFirstPoint<nr) continue;
1926 if (pt->fRelativeSector>17) {
1929 FollowToNextCluster(i,nr);
1931 // for (Int_t i= 0;i<fN;i++)
1932 // fSectors[i][nr].ClearClusterTracks();
1937 Float_t AliTPCtrackerMI::GetSigmaY(AliTPCseed * seed)
1941 Float_t sd2 = TMath::Abs((fParam->GetZLength()-TMath::Abs(seed->GetZ())))*fParam->GetDiffL()*fParam->GetDiffL();
1942 Float_t padlength = fParam->GetPadPitchLength(seed->fSector);
1943 Float_t sres = (seed->fSector < fParam->GetNSector()/2) ? 0.2 :0.3;
1944 Float_t angular = seed->GetSnp();
1945 angular = angular*angular/(1-angular*angular);
1946 // angular*=angular;
1947 //angular = TMath::Sqrt(angular/(1-angular));
1948 Float_t res = TMath::Sqrt(sd2+padlength*padlength*angular/12.+sres*sres);
1951 Float_t AliTPCtrackerMI::GetSigmaZ(AliTPCseed * seed)
1955 Float_t sd2 = TMath::Abs((fParam->GetZLength()-TMath::Abs(seed->GetZ())))*fParam->GetDiffL()*fParam->GetDiffL();
1956 Float_t padlength = fParam->GetPadPitchLength(seed->fSector);
1957 Float_t sres = fParam->GetZSigma();
1958 Float_t angular = seed->GetTgl();
1959 Float_t res = TMath::Sqrt(sd2+padlength*padlength*angular*angular/12.+sres*sres);
1965 //_________________________________________________________________________
1966 AliTPCclusterMI *AliTPCtrackerMI::GetClusterMI(Int_t index) const {
1967 //--------------------------------------------------------------------
1968 // Return pointer to a given cluster
1969 //--------------------------------------------------------------------
1970 Int_t sec=(index&0xff000000)>>24;
1971 Int_t row=(index&0x00ff0000)>>16;
1972 Int_t ncl=(index&0x0000ffff)>>00;
1974 AliTPCClustersRow *clrow=((AliTPCtrackerMI *) this)->fClustersArray.GetRow(sec,row);
1975 if (!clrow) return 0;
1976 return (AliTPCclusterMI*)(*clrow)[ncl];
1979 //__________________________________________________________________________
1980 void AliTPCtrackerMI::CookLabel(AliKalmanTrack *t, Float_t wrong) const {
1981 //--------------------------------------------------------------------
1982 //This function "cooks" a track label. If label<0, this track is fake.
1983 //--------------------------------------------------------------------
1984 Int_t noc=t->GetNumberOfClusters();
1985 Int_t *lb=new Int_t[noc];
1986 Int_t *mx=new Int_t[noc];
1987 AliTPCclusterMI **clusters=new AliTPCclusterMI*[noc];
1990 for (i=0; i<noc; i++) {
1992 Int_t index=t->GetClusterIndex(i);
1993 clusters[i]=GetClusterMI(index);
1996 Int_t lab=123456789;
1997 for (i=0; i<noc; i++) {
1998 AliTPCclusterMI *c=clusters[i];
1999 if (!clusters[i]) continue;
2000 lab=TMath::Abs(c->GetLabel(0));
2002 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
2008 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
2010 for (i=0; i<noc; i++) {
2011 AliTPCclusterMI *c=clusters[i];
2012 if (!clusters[i]) continue;
2013 if (TMath::Abs(c->GetLabel(1)) == lab ||
2014 TMath::Abs(c->GetLabel(2)) == lab ) max++;
2017 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
2020 Int_t tail=Int_t(0.10*noc);
2022 for (i=1; i<=tail; i++) {
2023 AliTPCclusterMI *c=clusters[noc-i];
2024 if (!clusters[i]) continue;
2025 if (lab == TMath::Abs(c->GetLabel(0)) ||
2026 lab == TMath::Abs(c->GetLabel(1)) ||
2027 lab == TMath::Abs(c->GetLabel(2))) max++;
2029 if (max < Int_t(0.5*tail)) lab=-lab;
2039 //_________________________________________________________________________
2040 void AliTPCtrackerMI::AliTPCSector::Setup(const AliTPCParam *par, Int_t f) {
2041 //-----------------------------------------------------------------------
2042 // Setup inner sector
2043 //-----------------------------------------------------------------------
2045 fAlpha=par->GetInnerAngle();
2046 fAlphaShift=par->GetInnerAngleShift();
2047 fPadPitchWidth=par->GetInnerPadPitchWidth();
2048 fPadPitchLength=par->GetInnerPadPitchLength();
2049 fN=par->GetNRowLow();
2050 fRow=new AliTPCRow[fN];
2051 for (Int_t i=0; i<fN; i++) {
2052 fRow[i].SetX(par->GetPadRowRadiiLow(i));
2053 fRow[i].fDeadZone =1.5; //1.5 cm of dead zone
2056 fAlpha=par->GetOuterAngle();
2057 fAlphaShift=par->GetOuterAngleShift();
2058 fPadPitchWidth = par->GetOuterPadPitchWidth();
2059 fPadPitchLength = par->GetOuter1PadPitchLength();
2060 f1PadPitchLength = par->GetOuter1PadPitchLength();
2061 f2PadPitchLength = par->GetOuter2PadPitchLength();
2063 fN=par->GetNRowUp();
2064 fRow=new AliTPCRow[fN];
2065 for (Int_t i=0; i<fN; i++) {
2066 fRow[i].SetX(par->GetPadRowRadiiUp(i));
2067 fRow[i].fDeadZone =1.5; // 1.5 cm of dead zone
2073 AliTPCtrackerMI::AliTPCRow::~AliTPCRow(){
2075 if (fClusterTracks) delete [] fClusterTracks;
2079 void AliTPCtrackerMI::AliTPCRow::MakeClusterTracks(){
2080 //create cluster tracks
2082 fClusterTracks = new AliTPCclusterTracks[fN];
2085 void AliTPCtrackerMI::AliTPCRow::ClearClusterTracks(){
2086 if (fClusterTracks) delete[] fClusterTracks;
2092 void AliTPCtrackerMI::AliTPCRow::UpdateClusterTrack(Int_t clindex, Int_t trindex, AliTPCseed * seed){
2095 // update information of the cluster tracks - if track is nearer then other tracks to the
2097 const AliTPCclusterMI * cl = (*this)[clindex];
2098 AliTPCclusterTracks * cltracks = GetClusterTracks(clindex);
2099 // find the distance of the cluster to the track
2100 Float_t dy2 = (cl->GetY()- seed->GetY());
2102 Float_t dz2 = (cl->GetZ()- seed->GetZ());
2105 Float_t distance = TMath::Sqrt(dy2+dz2);
2107 return; // MI - to be changed - AliTPCtrackerParam
2109 if ( distance < cltracks->fDistance[0]){
2110 cltracks->fDistance[2] =cltracks->fDistance[1];
2111 cltracks->fDistance[1] =cltracks->fDistance[0];
2112 cltracks->fDistance[0] =distance;
2113 cltracks->fTrackIndex[2] =cltracks->fTrackIndex[1];
2114 cltracks->fTrackIndex[1] =cltracks->fTrackIndex[0];
2115 cltracks->fTrackIndex[0] =trindex;
2118 if ( distance < cltracks->fDistance[1]){
2119 cltracks->fDistance[2] =cltracks->fDistance[1];
2120 cltracks->fDistance[1] =distance;
2121 cltracks->fTrackIndex[2] =cltracks->fTrackIndex[1];
2122 cltracks->fTrackIndex[1] =trindex;
2124 if (distance < cltracks->fDistance[2]){
2125 cltracks->fDistance[2] =distance;
2126 cltracks->fTrackIndex[2] =trindex;
2131 //_________________________________________________________________________
2133 AliTPCtrackerMI::AliTPCRow::InsertCluster(const AliTPCclusterMI* c, UInt_t index) {
2134 //-----------------------------------------------------------------------
2135 // Insert a cluster into this pad row in accordence with its y-coordinate
2136 //-----------------------------------------------------------------------
2137 if (fN==kMaxClusterPerRow) {
2138 cerr<<"AliTPCRow::InsertCluster(): Too many clusters !\n"; return;
2140 if (fN==0) {fIndex[0]=index; fClusters[fN++]=c; return;}
2141 Int_t i=Find(c->GetZ());
2142 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTPCclusterMI*));
2143 memmove(fIndex +i+1 ,fIndex +i,(fN-i)*sizeof(UInt_t));
2144 fIndex[i]=index; fClusters[i]=c; fN++;
2147 //___________________________________________________________________
2148 Int_t AliTPCtrackerMI::AliTPCRow::Find(Double_t z) const {
2149 //-----------------------------------------------------------------------
2150 // Return the index of the nearest cluster
2151 //-----------------------------------------------------------------------
2152 if (fN==0) return 0;
2153 if (z <= fClusters[0]->GetZ()) return 0;
2154 if (z > fClusters[fN-1]->GetZ()) return fN;
2155 Int_t b=0, e=fN-1, m=(b+e)/2;
2156 for (; b<e; m=(b+e)/2) {
2157 if (z > fClusters[m]->GetZ()) b=m+1;
2165 //___________________________________________________________________
2166 AliTPCclusterMI * AliTPCtrackerMI::AliTPCRow::FindNearest(Double_t y, Double_t z, Double_t roady, Double_t roadz) const {
2167 //-----------------------------------------------------------------------
2168 // Return the index of the nearest cluster in z y
2169 //-----------------------------------------------------------------------
2170 Float_t maxdistance = roady*roady + roadz*roadz;
2172 AliTPCclusterMI *cl =0;
2173 for (Int_t i=Find(z-roadz); i<fN; i++) {
2174 AliTPCclusterMI *c=(AliTPCclusterMI*)(fClusters[i]);
2175 if (c->GetZ() > z+roadz) break;
2176 if ( (c->GetY()-y) > roady ) continue;
2177 Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
2178 if (maxdistance>distance) {
2179 maxdistance = distance;
2190 AliTPCseed::AliTPCseed():AliTPCtrack(){
2194 memset(fClusterIndex,0,sizeof(Int_t)*200);
2203 AliTPCseed::AliTPCseed(const AliTPCtrack &t):AliTPCtrack(t){
2211 AliTPCseed::AliTPCseed(const AliKalmanTrack &t, Double_t a):AliTPCtrack(t,a){
2213 memset(fClusterIndex,0,sizeof(Int_t)*200);
2222 AliTPCseed::AliTPCseed(UInt_t index, const Double_t xx[5], const Double_t cc[15],
2223 Double_t xr, Double_t alpha):
2224 AliTPCtrack(index, xx, cc, xr, alpha) {
2228 memset(fClusterIndex,0,sizeof(Int_t)*200);
2237 AliTPCseed::~AliTPCseed(){
2238 if (fPoints) delete fPoints;
2242 for (Int_t i=0;i<8;i++){
2243 delete [] fTrackPoints[i];
2245 delete fTrackPoints;
2251 AliTPCTrackPoint * AliTPCseed::GetTrackPoint(Int_t i)
2255 if (!fTrackPoints) {
2256 fTrackPoints = new AliTPCTrackPoint*[8];
2257 for ( Int_t i=0;i<8;i++)
2260 Int_t index1 = i/20;
2261 if (!fTrackPoints[index1]) fTrackPoints[index1] = new AliTPCTrackPoint[20];
2262 return &(fTrackPoints[index1][i%20]);
2265 void AliTPCseed::RebuildSeed()
2268 // rebuild seed to be ready for storing
2269 fPoints = new TClonesArray("AliTPCTrackPoint",160);
2270 fPoints->ExpandCreateFast(160);
2271 fEPoints = new TClonesArray("AliTPCExactPoint",1);
2272 for (Int_t i=0;i<160;i++){
2273 AliTPCTrackPoint *trpoint = (AliTPCTrackPoint*)fPoints->UncheckedAt(i);
2274 *trpoint = *(GetTrackPoint(i));
2279 //_____________________________________________________________________________
2280 void AliTPCseed::CookdEdx(Double_t low, Double_t up) {
2281 //-----------------------------------------------------------------
2282 // This funtion calculates dE/dX within the "low" and "up" cuts.
2283 //-----------------------------------------------------------------
2286 Float_t angular[200];
2287 Float_t weight[200];
2290 // TClonesArray & arr = *fPoints;
2291 Float_t meanlog = 100.;
2293 Float_t mean[4] = {0,0,0,0};
2294 Float_t sigma[4] = {1000,1000,1000,1000};
2295 Int_t nc[4] = {0,0,0,0};
2296 Float_t norm[4] = {1000,1000,1000,1000};
2301 for (Int_t of =0; of<4; of++){
2302 for (Int_t i=of;i<160;i+=4)
2304 //AliTPCTrackPoint * point = (AliTPCTrackPoint *) arr.At(i);
2305 AliTPCTrackPoint * point = GetTrackPoint(i);
2306 if (point==0) continue;
2307 if (point->fIsShared){
2311 if (point->GetCPoint().GetMax()<5) continue;
2312 Float_t angley = point->GetTPoint().GetAngleY();
2313 Float_t anglez = point->GetTPoint().GetAngleZ();
2314 Int_t type = point->GetCPoint().GetType();
2315 Float_t rsigmay = point->GetCPoint().GetSigmaY();
2316 Float_t rsigmaz = point->GetCPoint().GetSigmaZ();
2317 Float_t rsigma = TMath::Sqrt(rsigmay*rsigmaz);
2319 Float_t ampc = 0; // normalization to the number of electrons
2321 ampc = 1.*point->GetCPoint().GetMax();
2322 //ampc = 1.*point->GetCPoint().GetQ();
2323 // AliTPCClusterPoint & p = point->GetCPoint();
2324 // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.6)) - TMath::Abs(p.GetY()/0.6)+0.5);
2325 // Float_t iz = (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
2327 // TMath::Abs( Int_t(iz) - iz + 0.5);
2328 //ampc *= 1.15*(1-0.3*dy);
2329 //ampc *= 1.15*(1-0.3*dz);
2330 // Float_t zfactor = (1.05-0.0004*TMath::Abs(point->GetCPoint().GetZ()));
2334 ampc = 1.0*point->GetCPoint().GetMax();
2335 //ampc = 1.0*point->GetCPoint().GetQ();
2336 //AliTPCClusterPoint & p = point->GetCPoint();
2337 // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.4)) - TMath::Abs(p.GetY()/0.4)+0.5);
2338 //Float_t iz = (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
2340 // TMath::Abs( Int_t(iz) - iz + 0.5);
2342 //ampc *= 1.15*(1-0.3*dy);
2343 //ampc *= 1.15*(1-0.3*dz);
2344 // Float_t zfactor = (1.02-0.000*TMath::Abs(point->GetCPoint().GetZ()));
2348 ampc *= 2.0; // put mean value to channel 50
2349 //ampc *= 0.58; // put mean value to channel 50
2351 // if (type>0) w = 1./(type/2.-0.5);
2352 // Float_t z = TMath::Abs(point->GetCPoint().GetZ());
2355 //ampc /= (1+0.0008*z);
2359 //ampc /= (1+0.0008*z);
2361 //ampc /= (1+0.0008*z);
2364 if (type<0) { //amp at the border - lower weight
2369 if (rsigma>1.5) ampc/=1.3; // if big backround
2371 angular[nc[of]] = TMath::Sqrt(1.+angley*angley+anglez*anglez);
2376 TMath::Sort(nc[of],amp,index,kFALSE);
2380 //meanlog = amp[index[Int_t(nc[of]*0.33)]];
2382 for (Int_t i=int(nc[of]*low+0.5);i<int(nc[of]*up+0.5);i++){
2383 Float_t ampl = amp[index[i]]/angular[index[i]];
2384 ampl = meanlog*TMath::Log(1.+ampl/meanlog);
2386 sumw += weight[index[i]];
2387 sumamp += weight[index[i]]*ampl;
2388 sumamp2 += weight[index[i]]*ampl*ampl;
2389 norm[of] += angular[index[i]]*weight[index[i]];
2396 mean[of] = sumamp/sumw;
2397 sigma[of] = sumamp2/sumw-mean[of]*mean[of];
2399 sigma[of] = TMath::Sqrt(sigma[of]);
2403 mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
2404 //mean *=(1-0.02*(sigma/(mean*0.17)-1.));
2405 //mean *=(1-0.1*(norm-1.));
2412 // mean[0]*= (1-0.05*(sigma[0]/(0.01+mean[1]*0.18)-1));
2413 // mean[1]*= (1-0.05*(sigma[1]/(0.01+mean[0]*0.18)-1));
2416 // dedx = (mean[0]* TMath::Sqrt((1.+nc[0]))+ mean[1]* TMath::Sqrt((1.+nc[1])) )/
2417 // ( TMath::Sqrt((1.+nc[0]))+TMath::Sqrt((1.+nc[1])));
2421 for (Int_t i =0;i<4;i++){
2422 if (nc[i]>2&&nc[i]<1000){
2423 dedx += mean[i] *nc[i];
2424 fSdEdx += sigma[i]*(nc[i]-2);
2425 fMAngular += norm[i] *nc[i];
2430 fSDEDX[i] = sigma[i];
2443 // Float_t dedx1 =dedx;
2446 for (Int_t i =0;i<4;i++){
2447 if (nc[i]>2&&nc[i]<1000){
2448 mean[i] = mean[i]*(1-0.12*(sigma[i]/(fSdEdx)-1.));
2449 dedx += mean[i] *nc[i];
2464 Double_t p=TMath::Sqrt((1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt()));
2467 if (dedx < 39.+ 12./(p+0.25)/(p+0.25)) { SetMass(0.13957); return;}
2468 if (dedx < 39.+ 12./p/p) { SetMass(0.49368); return;}
2469 SetMass(0.93827); return;
2473 if (dedx < 39.+ 12./(p+0.25)/(p+0.25)) { SetMass(0.13957); return;}
2474 SetMass(0.93827); return;
2477 SetMass(0.13957); return;