+ if (n < kClmin) return kFALSE;
+
+ // fit XY
+ fitterY.Eval();
+ fYfit[0] = fitterY.GetParameter(0);
+ fYfit[1] = -fitterY.GetParameter(1);
+ // store covariance
+ Double_t *p = fitterY.GetCovarianceMatrix();
+ fCov[0] = p[0]; // variance of y0
+ fCov[1] = p[1]; // covariance of y0, dydx
+ fCov[2] = p[3]; // variance of dydx
+ // the ref radial position is set at the minimum of
+ // the y variance of the tracklet
+ fX = -fCov[1]/fCov[2];
+
+ // fit XZ
+ if(IsRowCross()){
+/* // THE LEADING CLUSTER METHOD
+ Float_t xMin = fX0;
+ Int_t ic=n=kNclusters-1; jc = &fClusters[ic];
+ AliTRDcluster *c0 =0x0, **kc = &fClusters[kNtb-1];
+ for(; ic>kNtb; ic--, --jc, --kc){
+ if((c0 = (*kc)) && c0->IsInChamber() && (xMin>c0->GetX())) xMin = c0->GetX();
+ if(!(c = (*jc))) continue;
+ if(!c->IsInChamber()) continue;
+ zc[kNclusters-1] = c->GetZ();
+ fX = fX0 - c->GetX();
+ }
+ fZfit[0] = .5*(zc[0]+zc[kNclusters-1]); fZfit[1] = 0.;
+ // Error parameterization
+ fS2Z = fdX*fZref[1];
+ fS2Z *= fS2Z; fS2Z *= 0.2887; // 1/sqrt(12)*/
+
+ // THE FIT X-Q PLANE METHOD
+ Int_t ic=n=kNclusters-1; jc = &fClusters[ic];
+ for(; ic>kNtb; ic--, --jc){
+ if(!(c = (*jc))) continue;
+ if(!c->IsInChamber()) continue;
+ qc[n] = TMath::Abs(c->GetQ());
+ xc[n] = fX0 - c->GetX();
+ zc[n] = c->GetZ();
+ fitterZ.AddPoint(&xc[n], -qc[n], 1.);
+ n--;
+ }
+ // fit XZ
+ fitterZ.Eval();
+ if(fitterZ.GetParameter(1)!=0.){
+ fX = -fitterZ.GetParameter(0)/fitterZ.GetParameter(1);
+ fX=(fX<0.)?0.:fX;
+ Float_t dl = .5*AliTRDgeometry::CamHght()+AliTRDgeometry::CdrHght();
+ fX=(fX> dl)?dl:fX;
+ fX-=.055; // TODO to be understood
+ }
+
+ fZfit[0] = .5*(zc[0]+zc[kNclusters-1]); fZfit[1] = 0.;
+ // temporary external error parameterization
+ fS2Z = 0.05+0.4*TMath::Abs(fZref[1]); fS2Z *= fS2Z;
+ // TODO correct formula
+ //fS2Z = sigma_x*TMath::Abs(fZref[1]);
+ } else {
+ fZfit[0] = zc[0]; fZfit[1] = 0.;
+ fS2Z = GetPadLength()*GetPadLength()/12.;
+ }
+ fS2Y = fCov[0] +2.*fX*fCov[1] + fX*fX*fCov[2];
+ return kTRUE;
+}
+
+
+/*
+//_____________________________________________________________________________
+void AliTRDseedV1::FitMI()
+{
+//
+// Fit the seed.
+// Marian Ivanov's version
+//
+// linear fit on the y direction with respect to the reference direction.
+// The residuals for each x (x = xc - x0) are deduced from:
+// dy = y - yt (1)
+// the tilting correction is written :
+// y = yc + h*(zc-zt) (2)
+// yt = y0+dy/dx*x (3)
+// zt = z0+dz/dx*x (4)
+// from (1),(2),(3) and (4)
+// dy = yc - y0 - (dy/dx + h*dz/dx)*x + h*(zc-z0)
+// the last term introduces the correction on y direction due to tilting pads. There are 2 ways to account for this:
+// 1. use tilting correction for calculating the y
+// 2. neglect tilting correction here and account for it in the error parametrization of the tracklet.
+ const Float_t kRatio = 0.8;
+ const Int_t kClmin = 5;
+ const Float_t kmaxtan = 2;
+
+ if (TMath::Abs(fYref[1]) > kmaxtan){
+ //printf("Exit: Abs(fYref[1]) = %3.3f, kmaxtan = %3.3f\n", TMath::Abs(fYref[1]), kmaxtan);
+ return; // Track inclined too much
+ }
+
+ Float_t sigmaexp = 0.05 + TMath::Abs(fYref[1] * 0.25); // Expected r.m.s in y direction
+ Float_t ycrosscor = GetPadLength() * GetTilt() * 0.5; // Y correction for crossing
+ Int_t fNChange = 0;
+
+ Double_t sumw;
+ Double_t sumwx;
+ Double_t sumwx2;
+ Double_t sumwy;
+ Double_t sumwxy;
+ Double_t sumwz;
+ Double_t sumwxz;
+
+ // Buffering: Leave it constant fot Performance issues
+ Int_t zints[kNtb]; // Histograming of the z coordinate
+ // Get 1 and second max probable coodinates in z
+ Int_t zouts[2*kNtb];
+ Float_t allowedz[kNtb]; // Allowed z for given time bin
+ Float_t yres[kNtb]; // Residuals from reference
+ //Float_t anglecor = GetTilt() * fZref[1]; // Correction to the angle
+
+ Float_t pos[3*kNtb]; memset(pos, 0, 3*kNtb*sizeof(Float_t));
+ Float_t *fX = &pos[0], *fY = &pos[kNtb], *fZ = &pos[2*kNtb];