]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/UPGRADE/AliITSUTrackerGlo.cxx
MC labeling added
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUTrackerGlo.cxx
index dfb7b2f0afe4c81757cf6ad19ab5c0ce3ce56eb4..ebd66aa97f89561cbe0f3f5f73d1cc29fe886fb7 100644 (file)
@@ -40,9 +40,14 @@ using namespace AliITSUAux;
 using namespace TMath;
 
 
+
 //----------------- tmp stuff -----------------
 
 ClassImp(AliITSUTrackerGlo)
+
+const Double_t AliITSUTrackerGlo::fgkToler =  1e-6;// tolerance for layer on-surface check
+
+
 //_________________________________________________________________________
 AliITSUTrackerGlo::AliITSUTrackerGlo(AliITSUReconstructor* rec)
 :  fReconstructor(rec)
@@ -52,7 +57,12 @@ AliITSUTrackerGlo::AliITSUTrackerGlo(AliITSUReconstructor* rec)
   ,fHypStore(100)
   ,fCurrHyp(0)
   ,fSeedsPool("AliITSUSeed",0)
+  ,fFreeSeedsID(0)
+  ,fNFreeSeeds(0)
+  ,fLastSeedID(0)
   ,fTrCond()
+  ,fTrackPhase(-1)
+  ,fClInfo(0)
 {
   // Default constructor
   if (rec) Init(rec);
@@ -64,6 +74,7 @@ AliITSUTrackerGlo::~AliITSUTrackerGlo()
  // Default destructor
  //  
   delete fITS;
+  delete[] fClInfo;
   //
 }
 
@@ -73,11 +84,14 @@ void AliITSUTrackerGlo::Init(AliITSUReconstructor* rec)
   // init with external reconstructor
   //
   fITS = new AliITSURecoDet(rec->GetGeom(),"ITSURecoInterface");
-  for (int ilr=fITS->GetNLayersActive();ilr--;) {
+  int nLr = fITS->GetNLayersActive();
+  fClInfo = new Int_t[nLr<<1];
+  for (int ilr=nLr;ilr--;) {
     fITS->GetLayerActive(ilr)->SetClusters(rec->GetClusters(ilr));
   }
   //
   fSeedsPool.ExpandCreateFast(1000); // RS TOCHECK
+  fFreeSeedsID.Set(1000);
   //
   fTrCond.SetNLayers(fITS->GetNLayersActive());
   fTrCond.AddNewCondition(5);
@@ -104,8 +118,11 @@ Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
 {
   //
   //
-  AliITSUReconstructor::GetRecoParam()->Print();
+  ResetSeedsPool();
+  fTrackPhase = kClus2Tracks;
   int nTrESD = esdEv->GetNumberOfTracks();
+  AliInfo(Form("Will try to find prolongations for %d tracks",nTrESD));
+  AliITSUReconstructor::GetRecoParam()->Print();
   fHypStore.Delete();
   if (fHypStore.GetSize()<nTrESD) fHypStore.Expand(nTrESD+100);
   //
@@ -114,10 +131,11 @@ Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
   for (int itr=0;itr<nTrESD;itr++) {
     AliESDtrack *esdTr = esdEv->GetTrack(itr);
     AliInfo(Form("Processing track %d | MCLabel: %d",itr,esdTr->GetTPCLabel()));
+    if (!NeedToProlong(esdTr)) continue;  // are we interested in this track?
     FindTrack(esdTr, itr);
   }
   //
-  printf("Hypotheses for current event (N seeds in pool: %d, size: %d)\n",fSeedsPool.GetEntriesFast(),fSeedsPool.GetSize());
+  AliInfo(Form("SeedsPool: %d, BookedUpTo: %d, free: %d",fSeedsPool.GetSize(),fSeedsPool.GetEntriesFast(),fNFreeSeeds));
   fHypStore.Print();
   FinalizeHypotheses();
   //
@@ -125,13 +143,69 @@ Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
 }
 
 //_________________________________________________________________________
-Int_t AliITSUTrackerGlo::PropagateBack(AliESDEvent * /*event*/)
+Int_t AliITSUTrackerGlo::PropagateBack(AliESDEvent *esdEv)
 {
   //
-  // To be implemented 
+  // Do outward fits in ITS
+  //
+
+  fTrackPhase = kPropBack;
+  int nTrESD = esdEv->GetNumberOfTracks();
+  AliInfo(Form("Will fit %d tracks",nTrESD));
+  //
+  double bz0 = GetBz();
+  Double_t xyzTrk[3],xyzVtx[3]={GetX(),GetY(),GetZ()};
+  AliITSUTrackHyp dummyTr,*currTr=0;
+  const double kWatchStep=10.; // for larger steps watch arc vs segment difference
+  Double_t times[AliPID::kSPECIES];
+  //
+  //
+  for (int itr=0;itr<nTrESD;itr++) {
+    AliESDtrack *esdTr = esdEv->GetTrack(itr);
+    // Start time integral and add distance from current position to vertex 
+    if (esdTr->IsOn(AliESDtrack::kITSout)) continue; // already done
+    //
+    esdTr->GetXYZ(xyzTrk); 
+    Double_t dst = 0.;     // set initial track lenght, tof
+    {
+      double dxs = xyzTrk[0] - xyzVtx[0];
+      double dys = xyzTrk[1] - xyzVtx[1];
+      double dzs = xyzTrk[2] - xyzVtx[2];
+      // RS: for large segment steps d use approximation of cicrular arc s by
+      // s = 2R*asin(d/2R) = d/p asin(p) \approx d/p (p + 1/6 p^3) = d (1+1/6 p^2)
+      // where R is the track radius, p = d/2R = 2C*d (C is the abs curvature)
+      // Hence s^2/d^2 = (1+1/6 p^2)^2
+      dst = dxs*dxs + dys*dys;
+      if (dst > kWatchStep*kWatchStep) { // correct circular part for arc/segment factor
+       double crv = Abs(esdTr->GetC(bz0));
+       double fcarc = 1.+crv*crv*dst/6.;
+       dst *= fcarc*fcarc;
+      }
+      dst += dzs*dzs;
+      dst = Sqrt(dst); 
+    }
+    //    
+    esdTr->SetStatus(AliESDtrack::kTIME);
+    //
+    if (!esdTr->IsOn(AliESDtrack::kITSin)) { // case of tracks w/o ITS prolongation: just set the time integration
+      dummyTr.AliExternalTrackParam::operator=(*esdTr);
+      dummyTr.StartTimeIntegral();
+      dummyTr.AddTimeStep(dst);
+      dummyTr.GetIntegratedTimes(times); 
+      esdTr->SetIntegratedTimes(times);
+      esdTr->SetIntegratedLength(dummyTr.GetIntegratedLength());
+      continue;
+    }
+    //
+    currTr = GetTrackHyp(itr);
+    currTr->StartTimeIntegral();
+    currTr->AddTimeStep(dst);
+    printf("Before resetCov: "); currTr->AliExternalTrackParam::Print();
+    currTr->ResetCovariance(10000);
+    RefitTrack(currTr,fITS->GetRMax()); // propagate to exit from the ITS/TPC screen
+    //
+  }
   //
-  
- Info("PropagateBack","To be implemented");
   return 0;
 }
 
@@ -205,7 +279,6 @@ void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr, Int_t esdID)
   AliITSUSeed seedUC;  // copy of the seed from the upper layer
   AliITSUSeed seedT;   // transient seed between the seedUC and new prolongation hypothesis
   //
-  if (!NeedToProlong(esdTr)) return;  // are we interested in this track?
   if (!InitHypothesis(esdTr,esdID)) return;  // initialize prolongations hypotheses tree
   //
   AliITSURecoSens *hitSens[AliITSURecoSens::kNNeighbors+1];
@@ -228,7 +301,7 @@ void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr, Int_t esdID)
       else {
        seedU = fCurrHyp->GetSeed(ilaUp,isd);  // seed on prev.active layer to prolong  
        seedUC = *seedU;                       // its copy will be prolonged
-       seedUC.SetParent(seedU);
+       seedUC.SetParent(seedU);        
       }
       seedUC.ResetFMatrix();                    // reset the matrix for propagation to next layer
       // go till next active layer
@@ -237,12 +310,12 @@ void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr, Int_t esdID)
        //
        AliInfo("Transport failed");
        // Check if the seed satisfies to track definition
-       if (NeedToKill(&seedUC,kTransportFailed) && seedU) seedU->Kill(); 
+       if (NeedToKill(&seedUC,kTransportFailed) && seedU) KillSeed(seedU,kTRUE);
        continue; // RS TODO: decide what to do with tracks stopped on higher layers w/o killing
       }
       AliITSURecoLayer* lrA = fITS->GetLayerActive(ila);
       if (!GetRoadWidth(&seedUC, ila)) { // failed to find road width on the layer
-       if (NeedToKill(&seedUC,kRWCheckFailed) && seedU) seedU->Kill(); 
+       if (NeedToKill(&seedUC,kRWCheckFailed) && seedU) KillSeed(seedU,kTRUE);
        continue;
       }
       int nsens = lrA->FindSensors(&fTrImpData[kTrPhi0], hitSens);  // find detectors which may be hit by the track
@@ -257,7 +330,8 @@ void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr, Int_t esdID)
        // since the transport matrix should be defined in this frame.
        double xs; // X in the TF of current seed, corresponding to intersection with sensor plane
        if (!seedT.GetTrackingXAtXAlpha(sens->GetXTF(),sens->GetPhiTF(),bz, xs)) continue;
-       if (!seedT.PropagateToX(xs,bz)) continue;
+       if (!PropagateSeed(&seedT,xs,fCurrMass)) continue;
+       //      if (!seedT.PropagateToX(xs,bz)) continue;
        //      if (!seedT.Rotate(sens->GetPhiTF())) continue;
        if (!seedT.RotateToAlpha(sens->GetPhiTF())) continue;
        //
@@ -317,6 +391,7 @@ Bool_t AliITSUTrackerGlo::InitHypothesis(AliESDtrack *esdTr, Int_t esdID)
   fCurrHyp = new AliITSUTrackHyp(fITS->GetNLayersActive());
   fCurrHyp->SetESDTrack(esdTr);
   fCurrHyp->SetUniqueID(esdID);
+  fCurrHyp->SetMass(fCurrMass);
   SetTrackHyp(fCurrHyp,esdID);
   //
   return kTRUE;
@@ -328,32 +403,22 @@ Bool_t AliITSUTrackerGlo::TransportToLayer(AliITSUSeed* seed, Int_t lFrom, Int_t
 {
   // transport seed from layerFrom to the entrance of layerTo
   //  
-  const double kToler = 1e-6; // tolerance for layer on-surface check
+  //
+  if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
   //
   int dir = lTo > lFrom ? 1:-1;
   AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
   Bool_t checkFirst = kTRUE;
   while(lFrom!=lTo) {
-    double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
     if (lrFr) {
-      Bool_t doLayer = kTRUE;
-      double xToGo = dir>0 ? lrFr->GetRMax() : lrFr->GetRMin();
-      if (checkFirst) { // do we need to track till the surface of the current layer ?
-       checkFirst = kFALSE;
-       if      (dir>0) { if (curR2-xToGo*xToGo>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
-       else if (dir<0) { if (xToGo*xToGo-curR2>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
-      }
-      if (doLayer) {
-       if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
-       // go via layer to its boundary, applying material correction.
-       if (!PropagateSeed(seed,xToGo,fCurrMass, lrFr->GetMaxStep())) return kFALSE;
-      }
+      if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
+      checkFirst = kFALSE;
     }
     AliITSURecoLayer* lrTo =  fITS->GetLayer( (lFrom+=dir) );
     if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
     //
     // go the entrance of the layer, assuming no materials in between
-    double xToGo = dir>0 ? lrTo->GetRMin() : lrTo->GetRMax();
+    double xToGo = lrTo->GetR(-dir);
     if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
     if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) return kFALSE;
     lrFr = lrTo;
@@ -367,40 +432,99 @@ Bool_t AliITSUTrackerGlo::TransportToLayer(AliExternalTrackParam* seed, Int_t lF
 {
   // transport track from layerFrom to the entrance of layerTo
   //  
-  const double kToler = 1e-6; // tolerance for layer on-surface check
+  if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
   //
   int dir = lTo > lFrom ? 1:-1;
   AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
   Bool_t checkFirst = kTRUE;
   while(lFrom!=lTo) {
-    double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
     if (lrFr) {
-      Bool_t doLayer = kTRUE;
-      double xToGo = dir>0 ? lrFr->GetRMax() : lrFr->GetRMin();
-      if (checkFirst) { // do we need to track till the surface of the current layer ?
-       checkFirst = kFALSE;
-       if      (dir>0) { if (curR2-xToGo*xToGo>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
-       else if (dir<0) { if (xToGo*xToGo-curR2>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
-      }
-      if (doLayer) {
-       if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
-       // go via layer to its boundary, applying material correction.
-       if (!PropagateSeed(seed,xToGo,fCurrMass, lrFr->GetMaxStep())) return kFALSE;
-      }
+      if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
+      checkFirst = kFALSE;
     }
     AliITSURecoLayer* lrTo =  fITS->GetLayer( (lFrom+=dir) );
     if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
     //
-    // go the entrance of the layer, assuming no materials in between
-    double xToGo = dir>0 ? lrTo->GetRMin() : lrTo->GetRMax();
-    if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
-    if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) return kFALSE;
+    if (!GoToExitFromLayer(seed,lrTo,dir)) return kFALSE; // go the entrance of the layer, assuming no materials in between
     lrFr = lrTo;
   }
   return kTRUE;
   //
 }
 
+//_________________________________________________________________________
+Bool_t AliITSUTrackerGlo::GoToExitFromLayer(AliITSUSeed* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
+{
+  // go to the exit from lr in direction dir, applying material corrections in steps specific for this layer
+  // If check is requested, do this only provided the track has not exited the layer already
+  double xToGo = lr->GetR(dir);
+  if (check) { // do we need to track till the surface of the current layer ?
+    double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
+    if      (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // on the surface or outside of the layer
+    else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // on the surface or outside of the layer
+  }
+  if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
+  // go via layer to its boundary, applying material correction.
+  if (!PropagateSeed(seed,xToGo,fCurrMass, lr->GetMaxStep())) return kFALSE;
+  return kTRUE;
+  //
+}
+
+//_________________________________________________________________________
+Bool_t AliITSUTrackerGlo::GoToExitFromLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
+{
+  // go to the exit from lr in direction dir, applying material corrections in steps specific for this layer
+  // If check is requested, do this only provided the track has not exited the layer already
+  double xToGo = lr->GetR(dir);
+  if (check) { // do we need to track till the surface of the current layer ?
+    double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
+    if      (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // on the surface or outside of the layer
+    else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // on the surface or outside of the layer
+  }
+  if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
+  // go via layer to its boundary, applying material correction.
+  if (!PropagateSeed(seed,xToGo,fCurrMass, lr->GetMaxStep())) return kFALSE;
+  return kTRUE;
+  //
+}
+
+
+//_________________________________________________________________________
+Bool_t AliITSUTrackerGlo::GoToEntranceToLayer(AliITSUSeed* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
+{
+  // go to the entrance of lr in direction dir, w/o applying material corrections.
+  // If check is requested, do this only provided the track did not reach the layer already
+  double xToGo = lr->GetR(-dir);
+  if (check) { // do we need to track till the surface of the current layer ?
+    double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
+    if      (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // already passed
+    else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // already passed
+  }
+  if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
+  // go via layer to its boundary, applying material correction.
+  if (!PropagateSeed(seed,xToGo,fCurrMass, 100, kFALSE)) return kFALSE;
+  return kTRUE;
+  //
+}
+
+//_________________________________________________________________________
+Bool_t AliITSUTrackerGlo::GoToEntranceToLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
+{
+  // go to the entrance of lr in direction dir, w/o applying material corrections.
+  // If check is requested, do this only provided the track did not reach the layer already
+  double xToGo = lr->GetR(-dir);
+  if (check) { // do we need to track till the surface of the current layer ?
+    double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
+    if      (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // already passed
+    else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // already passed
+  }
+  if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
+  // go via layer to its boundary, applying material correction.
+  if (!PropagateSeed(seed,xToGo,fCurrMass, 100, kFALSE)) return kFALSE;
+  return kTRUE;
+  //
+}
+
 //_________________________________________________________________________
 Bool_t AliITSUTrackerGlo::GetRoadWidth(AliITSUSeed* seed, int ilrA)
 {
@@ -443,13 +567,29 @@ Bool_t AliITSUTrackerGlo::GetRoadWidth(AliITSUSeed* seed, int ilrA)
   return kTRUE;
 }
 
-//_________________________________________________________________________
-AliITSUSeed* AliITSUTrackerGlo::NewSeedFromPool(const AliITSUSeed* src)
+//________________________________________
+void AliITSUTrackerGlo::ResetSeedsPool()
 {
-  // create new seed, optionally copying from the source
-  return src ? 
-    new(fSeedsPool[fSeedsPool.GetEntriesFast()]) AliITSUSeed(*src) :
-    new(fSeedsPool[fSeedsPool.GetEntriesFast()]) AliITSUSeed();
+  // mark all seeds in the pool as unused
+  AliInfo(Form("CurrentSize: %d, BookedUpTo: %d, free: %d",fSeedsPool.GetSize(),fSeedsPool.GetEntriesFast(),fNFreeSeeds));
+  fNFreeSeeds = 0;
+  fSeedsPool.Clear(); // seeds don't allocate memory
+}
+
+
+//________________________________________
+void AliITSUTrackerGlo::MarkSeedFree(AliITSUSeed *sd) 
+{
+  // account that this seed is "deleted" 
+  int id = sd->GetPoolID();
+  if (id<0) {
+    AliError(Form("Freeing of seed %p NOT from the pool is requested",sd)); 
+    return;
+  }
+  //  AliInfo(Form("%d %p",id, seed));
+  fSeedsPool.RemoveAt(id);
+  if (fFreeSeedsID.GetSize()<=fNFreeSeeds) fFreeSeedsID.Set( 2*fNFreeSeeds + 100 );
+  fFreeSeedsID.GetArray()[fNFreeSeeds++] = id;
 }
 
 //_________________________________________________________________________
@@ -467,7 +607,9 @@ Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
   Bool_t goodCl = kFALSE;
   int currLabel = Abs(fCurrESDtrack->GetTPCLabel());
   //
-  if (cl->GetLabel(0)>=0) {for (int i=0;i<3;i++) if (cl->GetLabel(i)>=0 && cl->GetLabel(i)==currLabel) {goodCl = kTRUE; break;}}
+  if (cl->GetLabel(0)>=0) {
+    for (int i=0;i<3;i++) if (cl->GetLabel(i)>=0 && cl->GetLabel(i)==currLabel) {goodCl = kTRUE; break;}
+  }
   else goodCl = kTRUE;
   //
   if (TMath::Abs(cl->GetX())>kTolerX) { // if due to the misalingment X is large, propagate track only
@@ -512,6 +654,7 @@ Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
   track = NewSeedFromPool(track);  // input track will be reused, use its clone for updates
   if (!track->Update()) {
     if (goodCl) {printf("Loose good cl: Failed update |"); cl->Print();}
+    MarkSeedFree(track);
     return kClusterNotMatching;
   }
   track->SetChi2Cl(chi2);
@@ -552,22 +695,34 @@ Bool_t AliITSUTrackerGlo::PropagateSeed(AliITSUSeed *seed, Double_t xToGo, Doubl
   Int_t dir         = (xpos<xToGo) ? 1:-1;
   Double_t xyz0[3],xyz1[3],param[7];
   //
-  if (matCorr) seed->GetXYZ(xyz1);   //starting global position
+  Bool_t updTime = dir>0 && seed->IsStartedTimeIntegral();
+  if (matCorr || updTime) seed->GetXYZ(xyz1);   //starting global position
   while ( (xToGo-xpos)*dir > kEpsilon){
     Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
     Double_t x    = xpos+step;
     Double_t bz=GetBz();   // getting the local Bz
     if (!seed->PropagateToX(x,bz))  return kFALSE;
-    if (matCorr) {
+    double ds = 0;
+    if (matCorr || updTime) {
       xyz0[0]=xyz1[0]; // global pos at the beginning of step
       xyz0[1]=xyz1[1];
       xyz0[2]=xyz1[2];
       seed->GetXYZ(xyz1);    //  // global pos at the end of step
-      MeanMaterialBudget(xyz0,xyz1,param);     
-      Double_t xrho=param[0]*param[4], xx0=param[1];
-      if (dir>0) xrho = -xrho; // outward should be negative
-      if (!seed->ApplyMaterialCorrection(xx0,xrho,mass,kFALSE)) return kFALSE;
+      if (matCorr) {
+       MeanMaterialBudget(xyz0,xyz1,param);    
+       Double_t xrho=param[0]*param[4], xx0=param[1];
+       if (dir>0) xrho = -xrho; // outward should be negative
+       if (!seed->ApplyMaterialCorrection(xx0,xrho,mass,kFALSE)) return kFALSE;
+       ds = param[4];
+      }
+       else { // matCorr is not requested but time integral is
+       double d0 = xyz1[0]-xyz0[0];
+       double d1 = xyz1[1]-xyz0[1];
+       double d2 = xyz1[2]-xyz0[2];    
+       ds = TMath::Sqrt(d0*d0+d1*d1+d2*d2);
+      }     
     }
+    if (updTime) seed->AddTimeStep(ds);
     xpos = seed->GetX();
   }
   return kTRUE;
@@ -636,7 +791,148 @@ void AliITSUTrackerGlo::FinalizeHypotheses()
   for (int ih=0;ih<nh;ih++) {
     AliITSUTrackHyp* hyp = (AliITSUTrackHyp*) fHypStore.UncheckedAt(ih); 
     if (!hyp) continue;
-    hyp->UpdateESD();
+    hyp->DefineWinner();  // TODO
+    UpdateESDTrack(hyp);
   }
 
 }
+
+//______________________________________________________________________________
+void AliITSUTrackerGlo::UpdateESDTrack(AliITSUTrackHyp* hyp)
+{
+  // update ESD track with current best hypothesis
+  AliESDtrack* esdTr = hyp->GetESDTrack();
+  if (!esdTr) return;
+  AliITSUSeed* win = hyp->GetWinner();
+  if (!win) return;
+  esdTr->UpdateTrackParams(hyp,AliESDtrack::kITSin);
+  //
+  // transfer module indices
+  // TODO
+}
+
+//______________________________________________________________________________
+Bool_t AliITSUTrackerGlo::RefitTrack(AliITSUTrackHyp* trc, Double_t rDest)
+{
+  // refit track till radius rDest
+  AliITSUTrackHyp tmpTr;
+  //
+  double rCurr = Sqrt(trc->GetX()*trc->GetX() + trc->GetY()*trc->GetY());
+  int dir,lrStart,lrStop;
+  //
+  dir = rCurr<rDest ? 1 : -1;
+  lrStart = fITS->FindFirstLayerID(rCurr,dir);
+  lrStop  = fITS->FindLastLayerID(rDest,dir);
+  printf("Refit %d: Lr:%d (%f) -> Lr:%d (%f)\n",dir,lrStart,rCurr, lrStop,rDest);
+  printf("Before refit: "); trc->AliExternalTrackParam::Print();
+  if (lrStop<0 || lrStart<0) AliFatal(Form("Failed to find start(%d) or last(%d) layers. Track from %.3f to %.3f",lrStart,lrStop,rCurr,rDest));
+  //
+  trc->FetchClusterInfo(fClInfo);
+  fCurrMass = trc->GetMass();
+  tmpTr.AliKalmanTrack::operator=(*trc);
+  tmpTr.SetChi2(0);
+  int iclLr[2],nclLr;
+  //
+  for (int ilr=lrStart;ilr!=lrStop;ilr+=dir) {
+    AliITSURecoLayer* lr = fITS->GetLayer(ilr);
+    if ( dir*(rCurr-lr->GetR(dir))>0) continue; // this layer is already passed
+    int ilrA2,ilrA = lr->GetActiveID();
+    // passive layer or active w/o hits will be traversed on the way to next cluster
+    if (!lr->IsActive() || fClInfo[ilrA2=(ilrA<<1)]<0) continue; 
+    //
+    if (ilr!=lrStart && !TransportToLayer(&tmpTr,lrStart,ilr)) {
+      printf("Failed to transport %d -> %d\n",lrStart,ilr);
+      return kFALSE; // go to the entrance to the layer
+    }
+    lrStart = ilr;
+    //
+    // select the order in which possible 2 clusters (in case of the overlap) will be traversed and fitted
+    nclLr=0;
+    if (dir>0) { // clusters are stored in increasing radius order
+      iclLr[nclLr++]=fClInfo[ilrA2++];
+      if (fClInfo[ilrA2]>=0) iclLr[nclLr++]=fClInfo[ilrA2];
+    }
+    else {
+      if ( fClInfo[ilrA2+1]>=0 ) iclLr[nclLr++]=fClInfo[ilrA2+1];
+      iclLr[nclLr++]=fClInfo[ilrA2];
+    }
+    //
+    for (int icl=0;icl<nclLr;icl++) {
+      AliITSUClusterPix* clus =  (AliITSUClusterPix*)lr->GetCluster(iclLr[icl]);
+      AliITSURecoSens* sens = lr->GetSensorFromID(clus->GetVolumeId());
+      if (!tmpTr.Rotate(sens->GetPhiTF())) return kFALSE;
+      printf("Refit cl:%d on lr %d Need to go %.4f -> %.4f\n",icl,ilrA,tmpTr.GetX(),sens->GetXTF()+clus->GetX());
+      if (!PropagateSeed(&tmpTr,sens->GetXTF()+clus->GetX(),fCurrMass)) return kFALSE;
+      if (!tmpTr.Update(clus)) return kFALSE;
+      printf("AfterRefit: "); tmpTr.AliExternalTrackParam::Print();
+    }
+    //
+  }
+  // All clusters were succesfully fitted. Even if the track does not reach rDest, this is enough to validate it.
+  // Still, try to go as close as possible to rDest.
+  //
+  if (lrStart!=lrStop) {
+    printf("Going to last layer %d -> %d\n",lrStart,lrStop);
+    if (!TransportToLayer(&tmpTr,lrStart,lrStop)) return kTRUE;    
+    if (!GoToExitFromLayer(&tmpTr,fITS->GetLayer(lrStop),dir)) return kFALSE; // go till the exit from layer
+    //
+    printf("On exit from last layer\n");
+    tmpTr.AliExternalTrackParam::Print();
+    // go to the destination radius
+    if (!tmpTr.GetXatLabR(rDest,rDest,GetBz(),dir)) return kTRUE;
+    if (!PropagateSeed(&tmpTr,rDest,fCurrMass, 100, kFALSE)) return kTRUE;
+  }
+  trc->AliKalmanTrack::operator=(tmpTr);
+  printf("After refit (now at lr %d): ",lrStart); trc->AliExternalTrackParam::Print();
+  return kTRUE;
+}
+
+//__________________________________________________________________
+void AliITSUTrackerGlo::CookMCLabel(AliITSUTrackHyp* hyp) 
+{
+  // build MC label
+  //
+  const int kMaxLbPerCl = 3;
+  int lbID[kMaxLayers*6],lbStat[kMaxLayers*6];
+  Int_t lr,nLab=0,nCl=0;
+  AliITSUSeed *seed = hyp->GetWinner();
+  while(seed) {
+    int clID = seed->GetLrCluster(lr);
+    if (clID>=0) {
+      AliCluster *cl = fITS->GetLayerActive(lr)->GetCluster(clID);
+      nCl++;
+      for (int imc=0;imc<kMaxLbPerCl;imc++) { // labels within single cluster
+       int trLb = cl->GetLabel(imc);
+       if (imc<0) break;
+       // search this mc track in already accounted ones
+       int iLab;
+       for (iLab=0;iLab<nLab;iLab++) if (lbID[iLab]==trLb) break;
+       if (iLab<nLab) lbStat[iLab]++;
+       else {
+         lbID[nLab] = trLb;
+         lbStat[nLab++] = 1;
+       }
+      } // loop over given cluster's labels
+    }
+    seed = (AliITSUSeed*)seed->GetParent();
+  } // loop over clusters
+  // 
+  if (nCl) {
+    int maxLab=0,nTPCok=0;
+    AliESDtrack* esdTr = hyp->GetESDTrack();
+    int tpcLab = esdTr ? Abs(esdTr->GetTPCLabel()) : -kDummyLabel;
+    for (int ilb=nLab;ilb--;) {
+      int st = lbStat[ilb];
+      if (lbStat[maxLab]<st) maxLab=ilb;
+      if (tpcLab==lbID[ilb]) nTPCok += st;
+    }
+    hyp->SetFakeRatio(1.-float(nTPCok)/nCl);
+    hyp->SetLabel( nTPCok==nCl ? tpcLab : -tpcLab);
+    hyp->SetITSLabel( lbStat[maxLab]==nCl ? lbStat[maxLab] : -lbStat[maxLab]); // winner label
+    return;
+  }
+  //
+  hyp->SetFakeRatio(-1.);
+  hyp->SetLabel( kDummyLabel );
+  hyp->SetITSLabel( kDummyLabel );
+}