+ 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;
+ }