]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDseedV1.cxx
add jet shape analysis classes
[u/mrichter/AliRoot.git] / TRD / AliTRDseedV1.cxx
index 0925cbf116b6bc39de8007830c26e2e6a86b1846..b718f5e860a5fe5a42b1e42cc2c855fb2912942a 100644 (file)
@@ -13,7 +13,7 @@
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/
 
-/* $Id$ */
+/* $Id: AliTRDseedV1.cxx 60233 2013-01-10 09:04:08Z abercuci $ */
 
 ////////////////////////////////////////////////////////////////////////////
 ////
@@ -36,6 +36,7 @@
 ////////////////////////////////////////////////////////////////////////////
 
 #include "TMath.h"
+#include "TGeoManager.h"
 #include "TTreeStream.h"
 #include "TGraphErrors.h"
 
@@ -538,46 +539,148 @@ Int_t AliTRDseedV1::GetChargeGaps(Float_t sz[kNtb], Float_t pos[kNtb], Int_t isz
 
 
 //____________________________________________________________________
-Bool_t AliTRDseedV1::GetEstimatedCrossPoint(Float_t &x, Float_t &z) const
+Double_t AliTRDseedV1::EstimatedCrossPoint(AliTRDpadPlane *pp)
 {
-// Algorithm to estimate cross point in the x-z plane for pad row cross tracklets.
-// Returns true in case of success.
-  if(!IsRowCross()) return kFALSE;
+// 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 variance of the radial offset from anode wire in case of raw cross or 0 otherwise.
 
-  x=0.; z=0.;
+  Int_t row[] = {-1, -1};
+  Double_t zoff(0.5 * (pp->GetRow0() + pp->GetRowEnd())), sx(0.), mean(0.5*pp->GetNrows()-0.5);
   AliTRDcluster *c(NULL);
-  // Find radial range for first row
-  Float_t x1[] = {0., 1.e3};
-  for(int ic=0; ic<kNtb; ic++){
-    if(!(c=fClusters[ic])) continue;
-    if(!c->IsInChamber()) continue;
-    if(c->GetX() <= x1[1]) x1[1] = c->GetX();
-    if(c->GetX() >= x1[0]) x1[0] = c->GetX();
-    z=c->GetZ();
+  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] = 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
+    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;
+      if(!(c=fClusters[ic]) || !c->IsInChamber()) continue;
+      if(row[0]<0) row[0] = c->GetPadRow();
+      tb[nc[0]++] = ic; tbm[0] += ic;
+    }
+    if(nc[0]>2){
+      tbm[0] /= nc[0];
+      w[0] = kTRUE;
+    }
+    // Find radial range for second row
+    for(int ic(kNtb), jc(0); ic<kNclusters; ic++, jc++){
+      if(!(c=fClusters[ic]) || !c->IsInChamber()) continue;
+      if(row[1]<0) row[1] = c->GetPadRow();
+      tbm[1] += jc; nc[1]++;
+      for(Int_t kc(0); kc<nc[0]; kc++) 
+        if(tb[kc]==jc){
+          tb[kc] += 100; // mark common cluster
+          mc++;
+          break;
+        }
+    }
+    if(nc[1]>2){
+      tbm[1] /= nc[1];
+      w[1] = kTRUE;
+    }
+    //printf("0 : %f[%2d] 1 : %f[%2d] mc[%d]\n", tbm[0], nc[0], tbm[1], nc[1], mc);
+    if(!w[0] && !w[1]){
+      AliError("Too few clusters to estimate tracklet.");
+      return -1;
+    }
+    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]));
+        dtb = Int_t(0.5*TMath::Abs(tbm[0] - tbm[1])); // simple parameterization of the cluster gap
+      } else {
+        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(itbStart<0) itbStart = ltb;
+          itbStop = ltb;
+        } 
+        dtb = itbStop-itbStart+1;
+      }
+      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;
+    }    
   }
-  if((x1[0] - x1[1])<1.e-5) return kFALSE;
 
-  // Find radial range for second row
-  Bool_t kZ(kFALSE);
-  Float_t x2[] = {0., 1.e3};
-  for(int ic=kNtb; ic<kNclusters; ic++){
-    if(!(c=fClusters[ic])) continue;
-    if(!c->IsInChamber()) continue;
-    if(c->GetX() <= x2[1]) x2[1] = c->GetX();
-    if(c->GetX() >= x2[0]) x2[0] = c->GetX();
-    if(!kZ){
-      z+=c->GetZ();
-      z*=0.5;
-      kZ=kTRUE;
+  // estimate dzdx
+  Float_t dx(fX0-fS2Y);
+  fZfit[1] = (fZfit[0]+zoff)/dx; 
+
+  // correct dzdx for the bias
+  UnbiasDZDX(IsRowCross());
+  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]); 
   }
-  if((x2[0] - x2[1])<1.e-5) return kFALSE;
+  return sx;
+}
 
-  // Find intersection of the 2 radial regions
-  x = 0.5*((x1[0]+x1[1] > x2[0]+x2[1]) ? (x1[1]+x2[0]) : (x1[0]+x2[1]));
-  return kTRUE;
+//____________________________________________________________________
+void AliTRDseedV1::UnbiasDZDX(Bool_t rc)
+{
+  // correct dzdx for the bias in z according to MC
+  const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam();
+  if(!recoParam) return;
+  fZfit[1] *= recoParam->GetCorrDZDX(rc);
+  if(rc) fZfit[1] += recoParam->GetCorrDZDXbiasRC(fZfit[1]<0);
 }
 
+//____________________________________________________________________
+Double_t AliTRDseedV1::UnbiasY(Bool_t rc, Bool_t sgn, Int_t chg)
+{
+// 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
+// sgn : TRUE if track has same sign with magnetic field
+// chg : -1 for negative particles, +1 for the rest
+  
+  const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam();
+  if(!recoParam) return 0.;
+  Double_t par[2]={0.};
+  if(rc) recoParam->GetYcorrTailCancel(2, par);
+  else{
+    if(sgn && 1./fPt > 1.5)  recoParam->GetYcorrTailCancel(1, par);
+    else if(!sgn)  recoParam->GetYcorrTailCancel(0, par);
+  }
+  return par[0]+par[1]*chg/fPt;
+}
+
+
 //____________________________________________________________________
 Float_t AliTRDseedV1::GetQperTB(Int_t tb) const
 {
@@ -797,7 +900,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 :
@@ -844,20 +947,19 @@ 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.;
 
   // insert systematic uncertainties
-  /* //RS
   if(fkReconstructor){
     Double_t sys[15]; memset(sys, 0, 15*sizeof(Double_t));
     fkReconstructor->GetRecoParam()->GetSysCovMatrix(sys);
-    sy2 += sys[0];
-    sz2 += sys[1];
+//    sy2 += sys[0];
+//    sz2 += sys[1];
   }
-  */
+
   // rotate covariance matrix if no RC
   if(!IsRowCross()){
     Double_t t2 = GetTilt()*GetTilt();
@@ -865,9 +967,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'));
 }
@@ -1304,7 +1406,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];
@@ -1331,7 +1434,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++){ 
@@ -1433,7 +1536,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;
@@ -1494,7 +1600,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);
@@ -1668,7 +1777,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);
@@ -2049,16 +2161,20 @@ Bool_t AliTRDseedV1::Fit(UChar_t opt)
 
 
 //____________________________________________________________________
-Bool_t AliTRDseedV1::FitRobust(Bool_t chg)
+Bool_t AliTRDseedV1::FitRobust(AliTRDpadPlane *pp, Bool_t sgn, Int_t chg, Int_t opt)
 {
 //
 // Linear fit of the clusters attached to the tracklet
+//   The fit is performed in local chamber coordinates (27.11.2013) to take into account correctly the misalignment
+//   Also the pad row cross is checked here and some background is removed
 //
 // Author 
 // A.Bercuci <A.Bercuci@gsi.de>
 
   TTreeSRedirector *pstreamer(NULL);
-  const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam();   if(recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 3 && fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
+  const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam();   
+  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.
@@ -2073,56 +2189,149 @@ Bool_t AliTRDseedV1::FitRobust(Bool_t chg)
     if(!attach){ 
       AliWarning("No usable AttachClusters calib object.");
     } else { 
-      // kScalePulls = attach->GetScaleCov();//*lyScaler;
+      //kScalePulls = attach->GetScaleCov();//*lyScaler;
     }
     // Retrieve chamber status
     SetChmbGood(calibration->IsChamberGood(fDet));
     if(!IsChmbGood()) kScalePulls*=10.;
   }  
-  Double_t xc[kNclusters], yc[kNclusters], sy[kNclusters];
-  Int_t n(0),           // clusters used in fit 
-        row[]={-1, 0}; // pad row spanned by the tracklet
+  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;
+  
+  //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]),  
+           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]),
+           cs(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
+  Double_t ycorr(UnbiasY(IsRowCross(), sgn, chg)),
+           kS2Ycorr(recoParam->GetS2Ycorr(sgn));
+        
   AliTRDcluster *c(NULL), **jc = &fClusters[0];
   for(Int_t ic=0; ic<kNtb; ic++, ++jc) {
     if(!(c = (*jc))) continue;
     if(!c->IsInChamber()) continue;
     if(row[0]<0){ 
-      fZfit[0] = c->GetZ();
-      fZfit[1] = 0.;
       row[0] = c->GetPadRow();
+      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  = 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.; 
+          break;
+        case 2: // full z correction (z0 & dzdx from reference)
+          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();
+    yc[n]-= fPad[2]*(dz+xc[n]*dzdx);
+    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;
     }
-    xc[n]  = c->GetX();
-    yc[n]  = c->GetY();
-    sy[n]  = c->GetSigmaY2()>0?(TMath::Min(TMath::Sqrt(c->GetSigmaY2()), 0.08)):0.08;
+    // 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++;
   }
-  Double_t corr = fPad[2]*fPad[0];
-
   for(Int_t ic=kNtb; ic<kNclusters; ic++, ++jc) {
     if(!(c = (*jc))) continue;
     if(!c->IsInChamber()) continue;
-    if(row[1]==0) row[1] = c->GetPadRow() - row[0];
-    xc[n]  = c->GetX();
-    yc[n]  = c->GetY() + corr*row[1];
-    sy[n]  = c->GetSigmaY2()>0?(TMath::Min(TMath::Sqrt(c->GetSigmaY2()), 0.08)):0.08;
+    if(row[1]<0){ 
+      row[1] = c->GetPadRow();
+      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];
+          dz   = z - z0; 
+          break;
+        case 1: // dz correction only for RC tracklet and dzdx from reference
+          //dzdx = fZref[1];
+          dz   = z - z0; 
+          break;
+        case 2: // full z correction (z0 & dzdx from reference)
+          //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);
+    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++;
   }
+
   UChar_t status(0);
-  Double_t par[3] = {0.,0.,fX0}, cov[3];
+  // the ref radial position is set close to the minimum of 
+  // the y variance of the tracklet
+  fX   = 0.;//set reference to anode wire
+  Double_t par[3] = {0.,0.,fX}, cov[3];
   if(!AliTRDtrackletOflHelper::Fit(n, xc, yc, sy, par, 1.5, cov)){ 
     AliDebug(1, Form("Tracklet fit failed D[%03d].", fDet));
     SetErrorMsg(kFitCl);
     return kFALSE; 
   }
-  fYfit[0] = par[0];
-  fYfit[1] = par[1];
+  fYfit[0] = par[0] - fX * par[1];
+  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
-  // the ref radial position is set at the minimum of 
-  // the y variance of the tracklet
-  fX   = 0.;//-fCov[1]/fCov[2];
   // check radial position
   Float_t xs=fX+.5*AliTRDgeometry::CamHght();
   if(xs < 0. || xs > AliTRDgeometry::CamHght()+AliTRDgeometry::CdrHght()){
@@ -2130,24 +2339,11 @@ Bool_t AliTRDseedV1::FitRobust(Bool_t chg)
     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()){
-    Float_t x,z;
-    if(!GetEstimatedCrossPoint(x,z)){
-      AliDebug(2, Form("Failed(I) getting crossing point D[%03d].", fDet));
-      SetErrorMsg(kFitFailedY);
-      return kTRUE;
-    }
-    //if(IsPrimary()){ 
-      fZfit[0] = fX0*z/x;
-      fZfit[1] = z/x;
-      fS2Z     = 0.05+0.4*TMath::Abs(fZfit[1]); fS2Z *= fS2Z;
-    //}
-    AliDebug(2, Form("s2y[%f] s2z[%f]", fS2Y, fS2Z));
-    AliDebug(2, Form("[II] x[cm]=%6.2f y[cm]=%+5.2f z[cm]=%+6.2f dydx[deg]=%+5.2f sy[um]=%6.2f sz[um]=%6.2f dzdx[deg]=%+5.2f", GetX(), GetY(), GetZ(), TMath::ATan(fYfit[1])*TMath::RadToDeg(), TMath::Sqrt(fS2Y)*1.e4, TMath::Sqrt(fS2Z)*1.e4, TMath::ATan(fZfit[1])*TMath::RadToDeg()));
+  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,
@@ -2166,7 +2362,7 @@ Bool_t AliTRDseedV1::FitRobust(Bool_t chg)
     AliMathBase::EvaluateUni(n, dy, m, s, 0);
     (*pstreamer) << "FitRobust4"
       << "stat=" << status
-      << "chg="  << chg
+      << "opt="  << opt
       << "ncl="  << n
       << "det="  << fDet
       << "x0="   << fX0
@@ -2186,6 +2382,33 @@ Bool_t AliTRDseedV1::FitRobust(Bool_t chg)
   return kTRUE;
 }
 
+//___________________________________________________________________
+void AliTRDseedV1::SetXYZ(TGeoHMatrix *mDet)
+{
+// Apply alignment to the local position of tracklet
+// A.Bercuci @ 27.11.2013
+
+  Double_t loc[] = {AliTRDgeometry::AnodePos(), GetLocalY(), fZfit[0]}, trk[3]={0.};
+  mDet->LocalToMaster(loc, trk);
+  fX0 = trk[0];
+  fY  = trk[1];
+  fZ  = trk[2];
+  return;
+//   if(!IsRowCross()){/*fZfit[1] *= 1.09;*/ return;}
+//   // recalculate local z coordinate assuming primary track for row cross tracklets
+//   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] = fZfit[0];
+//   mDet->LocalToMaster(loc, trk);
+//   fX0 = trk[0];
+//   fY  = trk[1];
+//   fZ  = trk[2];//-zcorr[stk];
+  //fZfit[1] = /*(IsRowCross()?1.05:1.09)**/fZ/(fX0-fS2Y);
+}
+
+
 //___________________________________________________________________
 void AliTRDseedV1::Print(Option_t *o) const
 {