+ Int_t from, to, step;
+ if (xx > t->GetX()) {
+ from=0; to=AliITSgeomTGeo::GetNLayers();
+ step=+1;
+ } else {
+ from=AliITSgeomTGeo::GetNLayers()-1; to=-1;
+ step=-1;
+ }
+
+ for (Int_t i=from; i != to; i += step) {
+ AliITSlayer &layer=fgLayers[i];
+ Double_t r=layer.GetR();
+
+ {
+ Double_t hI=i-0.5*step;
+ if (TMath::Abs(hI-1.5)<0.01 || TMath::Abs(hI-3.5)<0.01) {
+ Double_t rs=0.5*(fgLayers[i-step].GetR() + r);
+ Double_t d=0.0034, x0=38.6;
+ if (TMath::Abs(hI-1.5)<0.01) {rs=9.; d=0.0097; x0=42;}
+ if (!t->PropagateTo(rs,-step*d,x0)) {
+ return kFALSE;
+ }
+ }
+ }
+
+ // remember old position [SR, GSI 18.02.2003]
+ Double_t oldX=0., oldY=0., oldZ=0.;
+ if (t->IsStartedTimeIntegral() && step==1) {
+ t->GetGlobalXYZat(t->GetX(),oldX,oldY,oldZ);
+ }
+ //
+
+ Double_t phi,z;
+ if (!t->GetPhiZat(r,phi,z)) {
+ return kFALSE;
+ }
+
+ Int_t idet=layer.FindDetectorIndex(phi,z);
+ if (idet<0) {
+ return kFALSE;
+ }
+ const AliITSdetector &det=layer.GetDetector(idet);
+ phi=det.GetPhi();
+ if (!t->Propagate(phi,det.GetR())) {
+ return kFALSE;
+ }
+ t->SetDetectorIndex(idet);
+
+ const AliITSRecPoint *cl=0;
+ Double_t maxchi2=AliITSReconstructor::GetRecoParam()->GetMaxChi2();
+
+ Int_t idx=index[i];
+ if (idx>=0) {
+ const AliITSRecPoint *ccc=(AliITSRecPoint *)GetCluster(idx);
+ if (idet != ccc->GetDetectorIndex()) {
+ idet=ccc->GetDetectorIndex();
+ const AliITSdetector &det2=layer.GetDetector(idet);
+ if (!t->Propagate(det2.GetPhi(),det2.GetR())) {
+ return kFALSE;
+ }
+ t->SetDetectorIndex(idet);
+ }
+ Double_t chi2=t->GetPredictedChi2(ccc);
+ if (chi2<maxchi2) {
+ cl=ccc;
+ maxchi2=chi2;
+ } else {
+ return kFALSE;
+ }
+ }
+
+ if (cl) {
+ // Take into account the mis-alignment
+ Double_t x=t->GetX()+cl->GetX();
+ if (!t->PropagateTo(x,0.,0.)) return kFALSE;
+ if (!t->Update(cl,maxchi2,idx)) {
+ return kFALSE;
+ }
+ t->SetSampledEdx(cl->GetQ(),i-2);
+ }
+
+ {
+ Double_t x0;
+ Double_t d=layer.GetThickness(t->GetY(),t->GetZ(),x0);
+ t->CorrectForMaterial(-step*d,x0);
+ }
+
+ if (extra) { //search for extra clusters
+ AliITStrackV2 tmp(*t);
+ Double_t dz=4*TMath::Sqrt(tmp.GetSigmaZ2()+AliITSReconstructor::GetRecoParam()->GetSigmaZ2(i));
+ if (dz < 0.5*TMath::Abs(tmp.GetTgl())) dz=0.5*TMath::Abs(tmp.GetTgl());
+ Double_t dy=4*TMath::Sqrt(t->GetSigmaY2()+AliITSReconstructor::GetRecoParam()->GetSigmaY2(i));
+ if (dy < 0.5*TMath::Abs(tmp.GetSnp())) dy=0.5*TMath::Abs(tmp.GetSnp());
+ Double_t zmin=t->GetZ() - dz;
+ Double_t zmax=t->GetZ() + dz;
+ Double_t ymin=t->GetY() + phi*r - dy;
+ Double_t ymax=t->GetY() + phi*r + dy;
+ layer.SelectClusters(zmin,zmax,ymin,ymax);
+
+ const AliITSRecPoint *cx=0; Int_t ci=-1,cci=-1;
+ maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2();
+ Double_t tolerance=0.1;
+ while ((cx=layer.GetNextCluster(ci))!=0) {
+ if (idet == cx->GetDetectorIndex()) continue;
+
+ const AliITSdetector &detx=layer.GetDetector(cx->GetDetectorIndex());
+
+ if (!tmp.Propagate(detx.GetPhi(),detx.GetR())) continue;
+
+ if (TMath::Abs(tmp.GetZ() - cx->GetZ()) > tolerance) continue;
+ if (TMath::Abs(tmp.GetY() - cx->GetY()) > tolerance) continue;
+
+ Double_t chi2=tmp.GetPredictedChi2(cx);
+ if (chi2<maxchi2) { maxchi2=chi2; cci=ci; }
+ }
+ if (cci>=0) t->SetExtraCluster(i,(i<<28)+cci);
+ }
+
+ // track time update [SR, GSI 17.02.2003]
+ if (t->IsStartedTimeIntegral() && step==1) {
+ Double_t newX, newY, newZ;
+ t->GetGlobalXYZat(t->GetX(),newX,newY,newZ);
+ Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) +
+ (oldZ-newZ)*(oldZ-newZ);
+ t->AddTimeStep(TMath::Sqrt(dL2));
+ }
+ //