]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDseedV1.cxx
fine tuning of TOF tail (developing task)
[u/mrichter/AliRoot.git] / TRD / AliTRDseedV1.cxx
index 33e02ffa3f6387fcee40824f68b32a58d2ceff9b..9b0e50603b45b92f8a678a605f16cc7d16d901f4 100644 (file)
@@ -539,29 +539,31 @@ Int_t AliTRDseedV1::GetChargeGaps(Float_t sz[kNtb], Float_t pos[kNtb], Int_t isz
 
 
 //____________________________________________________________________
-Double_t AliTRDseedV1::EstimatedCrossPoint(AliTRDpadPlane *pp)
+Double_t AliTRDseedV1::EstimatedCrossPoint(AliTRDpadPlane *pp, Float_t bz)
 {
 // Algorithm to estimate cross point in the x-z plane for pad row cross tracklets or the z coordinate of pad row without pad row cross in the local chamber coordinates.
-// Returns radial offset from anode wire in case of raw cross.
+// Returns variance of the radial offset from anode wire in case of raw cross or 0 otherwise.
 
   Int_t row[] = {-1, -1};
-  Double_t xOff(0.), zOff(0.5 * (pp->GetRow0() + pp->GetRowEnd()));
+  Double_t zoff(0.5 * (pp->GetRow0() + pp->GetRowEnd())), sx(0.), mean(0.5*pp->GetNrows()-0.5);
   AliTRDcluster *c(NULL);
-
+  fS2Y = 0.;
+  
   if(!IsRowCross()){ 
     for(int ic=0; ic<kNtb; ic++){
       if(!(c=fClusters[ic])) continue;
       if(!c->IsInChamber()) continue;
       row[0]   = c->GetPadRow();
-      fZfit[0] = pp->GetRowPos(row[0]) - 0.5*pp->GetRowSize(row[0]);
+      fZfit[0] = Int_t(mean-row[0])*pp->GetLengthIPad() + 
+                 0.5*(mean-row[0]>0.?1.:-1.)*(row[0]>0&&row[0]<pp->GetNrows()-1?pp->GetLengthIPad():pp->GetLengthOPad());      
       break;
     }
   } else {  
-    Float_t tbm[2] = {0.}, // mean value of time bin in rows
-            w[2] = {0.};   // weight of rows
+    Float_t tbm[2] = {0.}; // mean value of time bin in rows
     Int_t tb[kNtb]={0}, //array of time bins from first row
           nc[2] = {0},  // no. of clusters in rows
           mc(0);  // no. of common clusters
+    Bool_t w[2] = {kFALSE, kFALSE};   // acceptance flag for rows
     // Find radial range for first row
     for(int ic(0); ic<kNtb; ic++){
       tb[ic]= -1;
@@ -571,7 +573,7 @@ Double_t AliTRDseedV1::EstimatedCrossPoint(AliTRDpadPlane *pp)
     }
     if(nc[0]>2){
       tbm[0] /= nc[0];
-      w[0] = 1.;
+      w[0] = kTRUE;
     }
     // Find radial range for second row
     for(int ic(kNtb), jc(0); ic<kNclusters; ic++, jc++){
@@ -587,49 +589,94 @@ Double_t AliTRDseedV1::EstimatedCrossPoint(AliTRDpadPlane *pp)
     }
     if(nc[1]>2){
       tbm[1] /= nc[1];
-      w[1] = 1.;
+      w[1] = kTRUE;
     }
     //printf("0 : %f[%2d] 1 : %f[%2d] mc[%d]\n", tbm[0], nc[0], tbm[1], nc[1], mc);
-    Float_t ws = w[0]+w[1]; 
-    if(ws<=0){
+    if(!w[0] && !w[1]){
       AliError("Too few clusters to estimate tracklet.");
       return -1;
     }
-    w[0] /= ws; w[1] /= ws;
-    fZfit[0] = w[0]*(pp->GetRowPos(row[0]) - 0.5*pp->GetRowSize(row[0])) +
-               w[1]*(pp->GetRowPos(row[1]) - 0.5*pp->GetRowSize(row[1])); 
-    if(ws<2.) SetBit(kRowCross, kFALSE); // reset RC bit
-    else{ // find the best matching timebin 
-      Int_t itb(0);
+    if(!w[0] || !w[1]){ 
+      SetBit(kRowCross, kFALSE); // reset RC bit
+      if(w[1]) row[0] = row[1];
+      fZfit[0] = Int_t(mean-row[0])*pp->GetLengthIPad() + 
+                 0.5*(mean-row[0]>0.?1.:-1.)*(row[0]>0&&row[0]<pp->GetNrows()-1?pp->GetLengthIPad():pp->GetLengthOPad());      
+    }else{ // find the best matching timebin 
+      fZfit[0] = Int_t(mean-0.5*(row[0]+row[1]))*pp->GetLengthIPad(); 
+      Int_t itb(0), dtb(0);
       if(!mc) { // no common range
-        itb = Int_t(0.5*(tbm[0] + tbm[1])); 
+        itb = Int_t(0.5*(tbm[0] + tbm[1]));
+        dtb = Int_t(0.5*TMath::Abs(tbm[0] - tbm[1])); // simple parameterization of the cluster gap
       } else {
-        Double_t rmax(100.);
+        Double_t rmax(100.); Int_t itbStart(-1), itbStop(0);
         // compute distance from 
         for(Int_t jc(0); jc<nc[0]; jc++){
           if(tb[jc] < 100) continue;
           Int_t ltb(tb[jc]-100);
           Double_t r = (1. - ltb/tbm[0])*(1. - ltb/tbm[1]);
           //printf("tb[%2d] dr[%f %f %f] rmax[%f]\n", ltb, r, 1. - ltb/tbm[0], 1. - ltb/tbm[1], rmax);
-          if(TMath::Abs(r)<rmax){ rmax = TMath::Abs(r); itb = ltb; } 
+          if(TMath::Abs(r)<rmax){ rmax = TMath::Abs(r); itb = ltb; }
+          if(itbStart<0) itbStart = ltb;
+          itbStop = ltb;
         } 
+        dtb = itbStop-itbStart+1;
       }
-      if(itb>0 && (c = fClusters[itb])) xOff = c->GetXloc(fT0, fVD);  
+      AliTRDCommonParam *cp = AliTRDCommonParam::Instance(); 
+      Double_t freq(cp?cp->GetSamplingFrequency():10.);
+      fS2Y = ((itb-0.5)/freq - fT0 - 0.189)*fVD; // xOff
+      sx   = dtb*0.288675134594812921/freq; sx *= sx; sx += 1.56e-2; sx *= fVD*fVD;
     }    
   }
 
-  fZfit[1] = fZfit[0]/(fX0-xOff);
-  // move to local chamber coordinates
-  fZfit[0]-= zOff;
-  // correct z position for dzdx
-  fZfit[0]+= fZfit[1]*xOff; // in case of RC propate from xoff to anode
-  //else fZfit[0]-= TMath::Tan(-fZfit[1]);     // correct for non-uniformity in dzdx 
-  
-  fS2Z     = 0.05+0.4*TMath::Abs(fZfit[1]); fS2Z *= fS2Z;
+  // estimate dzdx
+  Float_t dx(fX0-fS2Y);
+  fZfit[1] = (fZfit[0]+zoff)/dx; 
 
-  return xOff;
+  // correct dzdx for the bias
+  UnbiasDZDX(IsRowCross(), bz);
+  if(IsRowCross()){
+    // correct x_cross/sigma(x_cross) for the bias in dzdx
+    const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam();
+    if(recoParam){ 
+      fS2Y += recoParam->GetCorrDZDXxcross()*TMath::Abs(fZfit[1]);
+      sx   += recoParam->GetCorrDZDXxcross()*recoParam->GetCorrDZDXxcross()*GetS2DZDX(fZfit[1]);
+    }
+    // correct sigma(x_cross) for the width of the crossing area
+    sx   += GetS2XcrossDZDX(TMath::Abs(fZfit[1]));
+    
+    // estimate z and error @ anode wire
+    fZfit[0] += fZfit[1]*fS2Y;
+    fS2Z  = fZfit[1]*fZfit[1]*sx+fS2Y*fS2Y*GetS2DZDX(fZfit[1]); 
+  }
+  return sx;
 }
 
+//____________________________________________________________________
+void AliTRDseedV1::UnbiasDZDX(Bool_t rc, Float_t bz)
+{
+  // correct dzdx for the bias in z according to MC
+  const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam();
+  if(!recoParam) return;
+  fZfit[1] *= recoParam->GetCorrDZDX(rc)-(bz>0?0.01:0.);
+  if(rc) fZfit[1] += recoParam->GetCorrDZDXbiasRC(fZfit[1]<0);
+}
+
+//____________________________________________________________________
+Double_t AliTRDseedV1::UnbiasY(Bool_t rc, Float_t bz)
+{
+// correct y coordinate for tail cancellation. This should be fixed by considering TC as a function of q/pt. 
+//  rc : TRUE if tracklet crosses rows
+// bz : magnetic field z component
+  
+  const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam();
+  if(!recoParam) return 0.;
+  Double_t par[3]={0.};
+  Int_t idx(2*(rc?1:0)+Int_t(bz>0));
+  recoParam->GetYcorrTailCancel(idx, par);
+  return par[0]*TMath::Sin(par[1]*fYref[1])+par[2];
+}
+
+
 //____________________________________________________________________
 Float_t AliTRDseedV1::GetQperTB(Int_t tb) const
 {
@@ -849,7 +896,7 @@ Float_t AliTRDseedV1::GetQuality(Bool_t kZcorr) const
 }
 
 //____________________________________________________________________
-void AliTRDseedV1::GetCovAt(Double_t x, Double_t *cov) const
+void AliTRDseedV1::GetCovAt(Double_t /*x*/, Double_t *cov) const
 {
 // Computes covariance in the y-z plane at radial point x (in tracking coordinates) 
 // and returns the results in the preallocated array cov[3] as :
@@ -896,8 +943,8 @@ void AliTRDseedV1::GetCovAt(Double_t x, Double_t *cov) const
 //
 
 
-  Double_t xr     = fX0-x; 
-  Double_t sy2    = fCov[0] +2.*xr*fCov[1] + xr*xr*fCov[2];
+  //Double_t xr     = fX0-x; 
+  Double_t sy2    = fCov[0];// +2.*xr*fCov[1] + xr*xr*fCov[2];
   Double_t sz2    = fS2Z;
   //GetPadLength()*GetPadLength()/12.;
 
@@ -916,9 +963,9 @@ void AliTRDseedV1::GetCovAt(Double_t x, Double_t *cov) const
     cov[0] = (sy2+t2*sz2)*correction;
     cov[1] = GetTilt()*(sz2 - sy2)*correction;
     cov[2] = (t2*sy2+sz2)*correction;
-  } else {
-    cov[0] = sy2; cov[1] = 0.; cov[2] = sy2;
-  }
+   } else {
+     cov[0] = sy2; cov[1] = 0.; cov[2] = sz2;
+   }
 
   AliDebug(4, Form("C(%6.1f %+6.3f %6.1f)  RC[%c]", 1.e4*TMath::Sqrt(cov[0]), cov[1], 1.e4*TMath::Sqrt(cov[2]), IsRowCross()?'y':'n'));
 }
@@ -1355,7 +1402,8 @@ Bool_t  AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *const chamber, Bool_
 
   // initialize debug streamer
   TTreeSRedirector *pstreamer(NULL);
-  if(recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 3 && fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
+  if((recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 3 && fkReconstructor->IsDebugStreaming())||
+     AliTRDReconstructor::GetStreamLevel()>30) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
   if(pstreamer){
     // save config. for calibration
     TVectorD vdy[2], vdx[2], vs2[2];
@@ -1382,7 +1430,7 @@ Bool_t  AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *const chamber, Bool_
         << "\n";
     vdx[0].Clear(); vdy[0].Clear(); vs2[0].Clear();
     vdx[1].Clear(); vdy[1].Clear(); vs2[1].Clear();
-    if(recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 4){    
+    if(recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 4 ||AliTRDReconstructor::GetStreamLevel()>4){    
       Int_t idx(idxRow[1]);
       if(idx<0){ 
         for(Int_t ir(0); ir<kNrows; ir++){ 
@@ -1484,7 +1532,10 @@ Bool_t  AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *const chamber, Bool_
       }
     }
   }
-  if(!pstreamer && recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 2 && fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
+  if(!pstreamer && 
+     ( (recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 2 && fkReconstructor->IsDebugStreaming()) ||
+       AliTRDReconstructor::GetStreamLevel()>2 ) 
+     ) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
   if(pstreamer){
     // save config. for calibration
     TVectorD vidx, vn, vx, vy, vr, vs, vsm, vp, vf;
@@ -1545,7 +1596,10 @@ Bool_t  AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *const chamber, Bool_
   if(f[is]<1.e-2){
     AliDebug(1, Form("Seed   seg[%d] row[%2d] n[%2d] f[%f]<0.01.", is, idxRow[0], n[0][is], f[is]));
     SetErrorMsg(kAttachClAttach);
-    if(!pstreamer && recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
+    if(!pstreamer && 
+       ( (recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()) ||
+        AliTRDReconstructor::GetStreamLevel()>1 ) 
+       ) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
     if(pstreamer){
       UChar_t stat(0);
       if(IsKink()) SETBIT(stat, 1);
@@ -1719,7 +1773,10 @@ Bool_t  AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *const chamber, Bool_
   // clear local copy of clusters
   for(Int_t ir(0); ir<kNrows; ir++) clst[ir].Clear();
   
-  if(!pstreamer && recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
+  if(!pstreamer && 
+     ((recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()) ||
+      AliTRDReconstructor::GetStreamLevel()>1 )
+     ) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
   if(pstreamer){
     UChar_t stat(0);
     if(IsKink()) SETBIT(stat, 1);
@@ -2100,7 +2157,7 @@ Bool_t AliTRDseedV1::Fit(UChar_t opt)
 
 
 //____________________________________________________________________
-Bool_t AliTRDseedV1::FitRobust(AliTRDpadPlane *pp, Int_t opt)
+Bool_t AliTRDseedV1::FitRobust(AliTRDpadPlane *pp, TGeoHMatrix *mDet, Float_t bz, Int_t chg, Int_t opt)
 {
 //
 // Linear fit of the clusters attached to the tracklet
@@ -2112,9 +2169,8 @@ Bool_t AliTRDseedV1::FitRobust(AliTRDpadPlane *pp, Int_t opt)
 
   TTreeSRedirector *pstreamer(NULL);
   const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam();   
-  if(recoParam && 
-     recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 3 && 
-     fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
+  if( (recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 3 && fkReconstructor->IsDebugStreaming()) ||
+    AliTRDReconstructor::GetStreamLevel()>3 ) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
 
   // factor to scale y pulls.
   // ideally if error parametrization correct this is 1.
@@ -2135,19 +2191,27 @@ Bool_t AliTRDseedV1::FitRobust(AliTRDpadPlane *pp, Int_t opt)
     SetChmbGood(calibration->IsChamberGood(fDet));
     if(!IsChmbGood()) kScalePulls*=10.;
   }  
-
+  AliTRDCommonParam *cp = AliTRDCommonParam::Instance(); 
+  Double_t freq(cp?cp->GetSamplingFrequency():10.);
+      
   // evaluate locally z and dzdx from TRD only information
-  if(EstimatedCrossPoint(pp)<0.) return kFALSE;
+  if(EstimatedCrossPoint(pp, bz)<0.) return kFALSE;
   
   //printf("D%03d RC[%c] dzdx[%f %f] opt[%d]\n", fDet, IsRowCross()?'y':'n', fZref[1], fZfit[1], opt);
   Double_t //xchmb = 0.5 * AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick(),
            //zchmb = 0.5 * (pp->GetRow0() + pp->GetRowEnd()),
-           z0    = 0.5 * (pp->GetRow0() + pp->GetRowEnd()) + fZfit[0], z;
-  Double_t xc[kNclusters], yc[kNclusters], dz(0.), dzdx(0.), sy[kNclusters],
-           cs(0.);
+           z0(0.5 * (pp->GetRow0() + pp->GetRowEnd()) + fZfit[0]),  
+           DZ(pp->GetRow0() - pp->GetRowEnd() - pp->GetAnodeWireOffset() + fZfit[0]),
+           z, d(-1.);
+  Double_t xc[kNclusters], yc[kNclusters], dz(0.), dzdx(0.), 
+           s2dz(0.), s2dzdx(0.), sy[kNclusters],
+           s2x((8.33e-2/freq/freq+1.56e-2)*fVD*fVD),  // error of 1tb + error of mean time (TRF)
+           t2(fPad[2]*fPad[2]), loc[3]={0.};
   Int_t n(0),          // clusters used in fit 
-        row[]={-1, -1},// pad row spanned by the tracklet
-        col(-1);       // pad column of current cluster
+        row[]={-1, -1};// pad row spanned by the tracklet
+  Double_t ycorr(UnbiasY(IsRowCross(), bz)),
+           kS2Ycorr(recoParam->GetS2Ycorr(IsRowCross(), chg>0));
+        
   AliTRDcluster *c(NULL), **jc = &fClusters[0];
   for(Int_t ic=0; ic<kNtb; ic++, ++jc) {
     if(!(c = (*jc))) continue;
@@ -2157,32 +2221,44 @@ Bool_t AliTRDseedV1::FitRobust(AliTRDpadPlane *pp, Int_t opt)
       z      = pp->GetRowPos(row[0]) - 0.5*pp->GetRowSize(row[0]);
       switch(opt){ 
         case 0: // no dz correction (only for RC tracklet) and dzdx from chamber position assuming primary
-          dzdx = fZfit[1];
-          dz   = IsRowCross()?(z - z0):0.;//5*dzdx*xchmb; 
+          dzdx  = IsRowCross()?fZfit[1]:0.; 
+          s2dzdx= IsRowCross()?GetS2DZDX(dzdx):0.;
+          dz    = IsRowCross()?(z - z0):0.;  
+          s2dz  = IsRowCross()?fS2Z:0.;
           break;
         case 1: // dz correction only for RC tracklet and dzdx from reference
           dzdx = fZref[1];
-          dz   = IsRowCross()?(z - z0):0.;//5*dzdx*xchmb; 
+          dz   = IsRowCross()?(z - z0):0.; 
           break;
         case 2: // full z correction (z0 & dzdx from reference)
-          dz = c->GetZ()-fZref[0]; 
           dzdx = fZref[1];
+          dz   = c->GetZ()-fZref[0]; 
           break;
         default:
           AliError(Form("Wrong option fit %d !", opt));
           break;
       }    
     }
-    if(col != c->GetPadCol()){
-      col = c->GetPadCol();
-      cs  = pp->GetColSize(col);
-    }
-    //Use local cluster coordinates - the code should be identical with AliTRDtransform::Transform() !!!
-    //A.Bercuci 27.11.13
-    xc[n] = c->GetXloc(fT0, fVD); // c->GetX();
-    yc[n] = c->GetYloc(pp->GetColPos(col) + .5*cs, fS2PRF, cs) - xc[n]*fExB; //c->GetY();
+    //Use local cluster coordinates 
+    //A.Bercuci 27.11.13/30.06.14
+    Double_t trk[] = {c->GetX(), c->GetY(), c->GetZ()};
+    mDet->MasterToLocal(trk, loc);
+    xc[n] = AliTRDgeometry::AnodePos()-loc[0]; //c->GetXloc(fT0, fVD); // c->GetX();
+    yc[n] = loc[1]; //c->GetYloc(pp->GetColPos(col) + .5*cs, fS2PRF, cs) - xc[n]*fExB; //c->GetY();
     yc[n]-= fPad[2]*(dz+xc[n]*dzdx);
-    sy[n] = c->GetSigmaY2()>0?(TMath::Min(TMath::Sqrt(c->GetSigmaY2()), 0.08)):0.08;
+    yc[n]-= ycorr;
+    if(IsRowCross()){ // estimate closest distance to anode wire
+      d = DZ-xc[n]*dzdx;
+      d -= ((Int_t)(2 * d)) / 2.0;
+      if (d > 0.25) d  = 0.5 - d;
+    }
+    // recalculate cluster error from knowledge of the track inclination in the bending plane 
+    // and eventually distance to anode wire
+    c->SetSigmaY2(fS2PRF, fDiffT, fExB, xc[n], d, fYref[1]);
+    s2x = c->GetSX(c->GetLocalTimeBin(), d); s2x*=s2x;
+    sy[n] = c->GetSigmaY2()>0?(TMath::Min(Double_t(c->GetSigmaY2()), 6.4e-3)):6.4e-3;
+    sy[n]+= t2*(s2dz+xc[n]*xc[n]*s2dzdx+dzdx*dzdx*s2x);
+    sy[n] = TMath::Sqrt(sy[n]);
     n++;
   }
   for(Int_t ic=kNtb; ic<kNclusters; ic++, ++jc) {
@@ -2193,32 +2269,40 @@ Bool_t AliTRDseedV1::FitRobust(AliTRDpadPlane *pp, Int_t opt)
       z      = pp->GetRowPos(row[1]) - 0.5*pp->GetRowSize(row[1]);
       switch(opt){ 
         case 0: // no dz correction (only for RC tracklet) and dzdx from chamber position assuming primary
-          dzdx = fZfit[1];
+          //dzdx = fZfit[1];
           dz   = z - z0; 
           break;
         case 1: // dz correction only for RC tracklet and dzdx from reference
-          dzdx = fZref[1];
+          //dzdx = fZref[1];
           dz   = z - z0; 
           break;
         case 2: // full z correction (z0 & dzdx from reference)
-          dz = c->GetZ()-fZref[0]; 
-          dzdx = fZref[1];
+          //dzdx = fZref[1];
+          dz   = c->GetZ()-fZref[0]; 
           break;
         default:
           AliError(Form("Wrong option fit %d !", opt));
           break;
       }    
     }  
-    if(col != c->GetPadCol()){
-      col = c->GetPadCol();
-      cs  = pp->GetColSize(col);
-    }
+
     //Use local cluster coordinates - the code should be identical with AliTRDtransform::Transform() !!!
     //A.Bercuci 27.11.13
-    xc[n]  = c->GetXloc(fT0, fVD); // c->GetX();
-    yc[n]  = c->GetYloc(pp->GetColPos(col) + .5*cs, fS2PRF, cs) - xc[n]*fExB ;
-    yc[n] -= fPad[2]*(dz+xc[n]*dzdx);
-    sy[n]  = c->GetSigmaY2()>0?(TMath::Min(TMath::Sqrt(c->GetSigmaY2()), 0.08)):0.08;
+    Double_t trk[] = {c->GetX(), c->GetY(), c->GetZ()};
+    mDet->MasterToLocal(trk, loc);
+    xc[n] = AliTRDgeometry::AnodePos()-loc[0]; //c->GetXloc(fT0, fVD); // c->GetX();
+    yc[n] = loc[1]; //c->GetYloc(pp->GetColPos(col) + .5*cs, fS2PRF, cs) - xc[n]*fExB; //c->GetY();
+    yc[n]-= fPad[2]*(dz+xc[n]*dzdx);
+    yc[n]-= ycorr;
+
+    d = DZ-xc[n]*dzdx;
+    d -= ((Int_t)(2 * d)) / 2.0;
+    if (d > 0.25) d  = 0.5 - d;
+    c->SetSigmaY2(fS2PRF, fDiffT, fExB, xc[n], d, fYref[1]);
+    s2x = c->GetSX(c->GetLocalTimeBin(), d); s2x*=s2x;
+    sy[n] = c->GetSigmaY2()>0?(TMath::Min(Double_t(c->GetSigmaY2()), 6.4e-3)):6.4e-3;
+    sy[n]+= t2*(s2dz+xc[n]*xc[n]*s2dzdx+dzdx*dzdx*s2x);
+    sy[n] = TMath::Sqrt(sy[n]);
     n++;
   }
 
@@ -2236,7 +2320,7 @@ Bool_t AliTRDseedV1::FitRobust(AliTRDpadPlane *pp, Int_t opt)
   fYfit[1] = -par[1];
   //printf(" yfit: %f [%f] x[%e] dydx[%f]\n", fYfit[0], par[0], fX, par[1]);
   // store covariance
-  fCov[0] = kScalePulls*cov[0]; // variance of y0
+  fCov[0] = kS2Ycorr*cov[0]; // variance of y0
   fCov[1] = kScalePulls*cov[2]; // covariance of y0, dydx
   fCov[2] = kScalePulls*cov[1]; // variance of dydx
   // check radial position
@@ -2246,9 +2330,11 @@ Bool_t AliTRDseedV1::FitRobust(AliTRDpadPlane *pp, Int_t opt)
     SetErrorMsg(kFitFailedY);
     return kFALSE;
   }
-  fS2Y = fCov[0] + fX*fCov[1];
-  fS2Z = fPad[0]*fPad[0]/12.;
-  AliDebug(2, Form("[I]  x[cm]=%6.2f y[cm]=%+5.2f z[cm]=%+6.2f dydx[deg]=%+5.2f sy[um]=%6.2f sz[cm]=%6.2f", GetX(), GetY(), GetZ(), TMath::ATan(fYfit[1])*TMath::RadToDeg(), TMath::Sqrt(fS2Y)*1.e4, TMath::Sqrt(fS2Z)));
+  if(!IsRowCross()){ 
+    Double_t padEffLength(fPad[0] - TMath::Abs(dzdx));
+    fS2Z = padEffLength*padEffLength/12.;
+  }
+  AliDebug(2, Form("[I]  x[cm]=%6.2f y[cm]=%+5.2f z[cm]=%+6.2f dydx[deg]=%+5.2f", GetX(), GetY(), GetZ(), TMath::ATan(fYfit[1])*TMath::RadToDeg()));
   
   if(pstreamer){
     Float_t x= fX0 -fX,
@@ -2267,6 +2353,7 @@ Bool_t AliTRDseedV1::FitRobust(AliTRDpadPlane *pp, Int_t opt)
     AliMathBase::EvaluateUni(n, dy, m, s, 0);
     (*pstreamer) << "FitRobust4"
       << "stat=" << status
+      << "opt="  << opt
       << "ncl="  << n
       << "det="  << fDet
       << "x0="   << fX0
@@ -2297,18 +2384,19 @@ void AliTRDseedV1::SetXYZ(TGeoHMatrix *mDet)
   fX0 = trk[0];
   fY  = trk[1];
   fZ  = trk[2];
-//   if(!IsRowCross()) return;
+  return;
+//   if(!IsRowCross()){/*fZfit[1] *= 1.09;*/ return;}
 //   // recalculate local z coordinate assuming primary track for row cross tracklets
-//   Float_t xOff(fZfit[1]);
-//   fZfit[1] = fZ/(fX0-xOff);
-//   //printf("stk[%d] xoff[%f] dzdx[%f]\n", AliTRDgeometry::GetStack(fDet), xOff, fZfit[1]);
-//   fZfit[0]+= xOff*fZfit[1];
+//   Double_t zoff(fZ-fZfit[0]); // no alignment aware !
+//   //printf("SetXYZ : zoff[%f] zpp[%f]\n", zoff, zpp);
+//   fZfit[0] = fX0*fZfit[1] - zoff; 
 //   // recalculate tracking coordinates based on the new z coordinate
-//   loc[2] = GetLocalZ();
+//   loc[2] = fZfit[0];
 //   mDet->LocalToMaster(loc, trk);
 //   fX0 = trk[0];
 //   fY  = trk[1];
-//   fZ  = trk[2];
+//   fZ  = trk[2];//-zcorr[stk];
+  //fZfit[1] = /*(IsRowCross()?1.05:1.09)**/fZ/(fX0-fS2Y);
 }
 
 
@@ -2411,4 +2499,3 @@ Bool_t AliTRDseedV1::IsEqual(const TObject *o) const
   return kTRUE;
 }
 
-