]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITStrackerMI.cxx
- Introduce fixed step size for material retrieval from TGeo, default is 1mm,
[u/mrichter/AliRoot.git] / ITS / AliITStrackerMI.cxx
index dc2dd66db77ba1a0a317df750863933b1b2fa073..c20b467e339834470f231df76620678bd7ddf1f5 100644 (file)
@@ -34,6 +34,7 @@
 #include <TRandom.h>
 
 
+#include "AliLog.h"
 #include "AliESDEvent.h"
 #include "AliESDtrack.h"
 #include "AliESDVertex.h"
@@ -227,21 +228,15 @@ fPlaneEff(0) {
 
   // only for plane efficiency evaluation
   if (AliITSReconstructor::GetRecoParam()->GetComputePlaneEff()) {
-    for(Int_t ilay=0;ilay<6;ilay++) { 
-      if(AliITSReconstructor::GetRecoParam()->GetLayersToSkip(ilay)) {
-        if (ilay<2) fPlaneEff = new AliITSPlaneEffSPD();
-        else if (ilay<4) fPlaneEff = new AliITSPlaneEffSDD();
-        else fPlaneEff = new AliITSPlaneEffSSD();
-        break; // only one layer type to skip at once
-      }
-    }
+    Int_t iplane=AliITSReconstructor::GetRecoParam()->GetIPlanePlaneEff();
+    if(AliITSReconstructor::GetRecoParam()->GetLayersToSkip(iplane))
+      AliWarning(Form("Evaluation of Plane Eff for layer %d will be attempted without removing it from tracker",iplane));
+    if (iplane<2) fPlaneEff = new AliITSPlaneEffSPD();
+    else if (iplane<4) fPlaneEff = new AliITSPlaneEffSDD();
+    else fPlaneEff = new AliITSPlaneEffSSD();
     if(AliITSReconstructor::GetRecoParam()->GetReadPlaneEffFromOCDB())
-      if(!fPlaneEff->ReadFromCDB()) 
-       {AliWarning("AliITStrackerMI reading of AliITSPlaneEff from OCDB failed") ;}
-    if(AliITSReconstructor::GetRecoParam()->GetHistoPlaneEff()) {
-      fPlaneEff->SetCreateHistos(kTRUE); 
-      //fPlaneEff->ReadHistosFromFile();
-    }
+       if(!fPlaneEff->ReadFromCDB()) {AliWarning("AliITStrackerMI reading of AliITSPlaneEff from OCDB failed") ;}
+    if(AliITSReconstructor::GetRecoParam()->GetHistoPlaneEff()) fPlaneEff->SetCreateHistos(kTRUE);
   }
 }
 //------------------------------------------------------------------------
@@ -325,24 +320,27 @@ void AliITStrackerMI::ReadBadFromDetTypeRec() {
 
   if(!AliITSReconstructor::GetRecoParam()->GetUseBadZonesFromOCDB()) return;
 
-  Info("ReadBadFromDetTypeRec","Reading info about bad ITS detectors and channels\n");
+  Info("ReadBadFromDetTypeRec","Reading info about bad ITS detectors and channels");
 
   if(!fDetTypeRec) Error("ReadBadFromDetTypeRec","AliITSDetTypeRec nof found!\n");
 
   // ITS channels map
   if(fITSChannelStatus) delete fITSChannelStatus;
-  fITSChannelStatus = new AliITSChannelStatus(AliCDBManager::Instance());
+  fITSChannelStatus = new AliITSChannelStatus(fDetTypeRec);
 
   // ITS detectors and chips
   Int_t i=0,j=0,k=0,ndet=0;
   for (i=1; i<AliITSgeomTGeo::GetNLayers()+1; i++) {
+    Int_t nBadDetsPerLayer=0;
     ndet=AliITSgeomTGeo::GetNDetectors(i);    
     for (j=1; j<AliITSgeomTGeo::GetNLadders(i)+1; j++) {
       for (k=1; k<ndet+1; k++) {
         AliITSdetector &det=fgLayers[i-1].GetDetector((j-1)*ndet + k-1);  
        det.ReadBadDetectorAndChips(i-1,(j-1)*ndet + k-1,fDetTypeRec);
+       if(det.IsBad()) {nBadDetsPerLayer++;}
       } // end loop on detectors
     } // end loop on ladders
+    Info("ReadBadFromDetTypeRec",Form("Layer %d: %d bad out of %d",i-1,nBadDetsPerLayer,ndet*AliITSgeomTGeo::GetNLadders(i)));
   } // end loop on layers
   
   return;
@@ -501,6 +499,8 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
     Info("Clusters2Tracks", "Number of ESD tracks: %d\n", nentr);
     while (nentr--) {
       AliESDtrack *esd=event->GetTrack(nentr);
+      //  ---- for debugging:
+      //if(TMath::Abs(esd->GetX()-83.65)<0.1) { FILE *f=fopen("tpc.dat","a"); fprintf(f,"%f %f %f %f %f %f\n",(Float_t)event->GetEventNumberInFile(),(Float_t)TMath::Abs(esd->GetLabel()),(Float_t)esd->GetX(),(Float_t)esd->GetY(),(Float_t)esd->GetZ(),(Float_t)esd->Pt()); fclose(f); }
 
       if ((esd->GetStatus()&AliESDtrack::kTPCin)==0) continue;
       if (esd->GetStatus()&AliESDtrack::kTPCout) continue;
@@ -572,6 +572,7 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
        }
 
        Int_t tpcLabel=t->GetLabel(); //save the TPC track label       
+       AliDebug(2,Form("LABEL %d pass %d",tpcLabel,fPass));
        fI = 6;
        ResetTrackToFollow(*t);
        ResetBestTrack();
@@ -594,6 +595,7 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
 
        t->SetReconstructed(kTRUE);
        ntrk++;  
+       AliDebug(2,Form("TRACK! (label %d) ncls %d",besttrack->GetLabel(),besttrack->GetNumberOfClusters()));
      }
      GetBestHypothesysMIP(itsTracks); 
   } // end loop on the two tracking passes
@@ -727,7 +729,9 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
 
     //Refitting...
     Bool_t pe=AliITSReconstructor::GetRecoParam()->GetComputePlaneEff();
+    AliDebug(2,Form("Refit LABEL %d  %d",t->GetLabel(),t->GetNumberOfClusters()));
     if (RefitAt(AliITSRecoParam::GetrInsideSPD1(),&fTrackToFollow,t,kTRUE,pe)) {
+       AliDebug(2,"  refit OK");
        fTrackToFollow.SetLabel(t->GetLabel());
        //       fTrackToFollow.CookdEdx();
        CookdEdx(&fTrackToFollow);
@@ -780,7 +784,8 @@ Bool_t AliITStrackerMI::GetTrackPoint(Int_t index, AliTrackPoint& p) const {
   cl->GetGlobalXYZ(xyz);
   cl->GetGlobalCov(cov);
   p.SetXYZ(xyz, cov);
-
+  p.SetCharge(cl->GetQ());
+  p.SetDriftTime(cl->GetDriftTime());
   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer; 
   switch (l) {
   case 0:
@@ -821,6 +826,7 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
   Int_t c=(index & 0x0fffffff) >> 00;
   const AliITSRecPoint *cl = fgLayers[l].GetCluster(c);
   Int_t idet = cl->GetDetectorIndex();
+
   const AliITSdetector &det=fgLayers[l].GetDetector(idet);
 
   // tgphi and tglambda of the track in tracking frame with alpha=det.GetPhi
@@ -829,7 +835,7 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
   detxy[1] = det.GetR()*TMath::Sin(det.GetPhi());
   Double_t alpha = t->GetAlpha();
   Double_t xdetintrackframe = detxy[0]*TMath::Cos(alpha)+detxy[1]*TMath::Sin(alpha);
-  Float_t phi = TMath::ASin(t->GetSnpAt(xdetintrackframe,AliTracker::GetBz()));
+  Float_t phi = TMath::ASin(t->GetSnpAt(xdetintrackframe,GetBz()));
   phi += alpha-det.GetPhi();
   Float_t tgphi = TMath::Tan(phi);
 
@@ -849,6 +855,8 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
   tmpcl.GetGlobalCov(cov);
 
   p.SetXYZ(xyz, cov);
+  p.SetCharge(cl->GetQ());
+  p.SetDriftTime(cl->GetDriftTime());
 
   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer; 
   switch (l) {
@@ -875,6 +883,7 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
     break;
   };
   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,idet);
+
   p.SetVolumeID((UShort_t)volid);
   return kTRUE;
 }
@@ -936,7 +945,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
   //
   // follow prolongations
   for (Int_t ilayer=5; ilayer>=0; ilayer--) {
-    //printf("FollowProlongationTree: layer %d\n",ilayer);
+    AliDebug(2,Form("FollowProlongationTree: layer %d",ilayer));
     fI = ilayer;
     //
     AliITSlayer &layer=fgLayers[ilayer];
@@ -970,7 +979,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       Int_t idet=layer.FindDetectorIndex(phi,z);
 
       Double_t trackGlobXYZ1[3];
-      currenttrack1.GetXYZ(trackGlobXYZ1);
+      if (!currenttrack1.GetXYZ(trackGlobXYZ1)) continue;
 
       // Get the budget to the primary vertex for the current track being prolonged
       Double_t budgetToPrimVertex = GetEffectiveThickness();
@@ -980,15 +989,16 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       if (skip) {
        AliITStrackMI* vtrack = new (&tracks[ilayer][ntracks[ilayer]]) AliITStrackMI(currenttrack1);
        // propagate to the layer radius
-       Double_t xToGo; vtrack->GetLocalXat(r,xToGo);
-       vtrack->AliExternalTrackParam::PropagateTo(xToGo,GetBz());
+       Double_t xToGo; if (!vtrack->GetLocalXat(r,xToGo)) continue;
+       if(!vtrack->Propagate(xToGo)) continue;
        // apply correction for material of the current layer
        CorrectForLayerMaterial(vtrack,ilayer,trackGlobXYZ1,"inward");
        vtrack->SetNDeadZone(vtrack->GetNDeadZone()+1);
        vtrack->SetClIndex(ilayer,0);
        modstatus = (skip==1 ? 3 : 4); // skipped : out in z
-       LocalModuleCoord(ilayer,idet,vtrack,xloc,zloc); // local module coords
-       vtrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
+       if(LocalModuleCoord(ilayer,idet,vtrack,xloc,zloc)) { // local module coords
+         vtrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
+       }
        if(constrain) vtrack->Improve(budgetToPrimVertex,xyzVtx,ersVtx);
        ntracks[ilayer]++;
        continue;
@@ -1001,10 +1011,10 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       const AliITSdetector &det=layer.GetDetector(idet);
       new(&currenttrack2)  AliITStrackMI(currenttrack1);
       if (!currenttrack1.Propagate(det.GetPhi(),det.GetR())) continue;
-      currenttrack2.Propagate(det.GetPhi(),det.GetR());
+      if (!currenttrack2.Propagate(det.GetPhi(),det.GetR())) continue;
       currenttrack1.SetDetectorIndex(idet);
       currenttrack2.SetDetectorIndex(idet);
-      LocalModuleCoord(ilayer,idet,&currenttrack1,xloc,zloc); // local module coords
+      if(!LocalModuleCoord(ilayer,idet,&currenttrack1,xloc,zloc)) continue; // local module coords
 
       //***************
       // DEFINITION OF SEARCH ROAD AND CLUSTERS SELECTION
@@ -1049,10 +1059,11 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       // check if the road contains a dead zone 
       Bool_t noClusters = kFALSE;
       if (!layer.GetNextCluster(clidx,kTRUE)) noClusters=kTRUE;
-      //if (noClusters) printf("no clusters in road\n");
+      if (noClusters) AliDebug(2,"no clusters in road");
       Double_t dz=0.5*(zmax-zmin);
       Double_t dy=0.5*(ymax-ymin);
       Int_t dead = CheckDeadZone(&currenttrack1,ilayer,idet,dz,dy,noClusters); 
+      if(dead) AliDebug(2,Form("DEAD (%d)\n",dead));
       // create a prolongation without clusters (check also if there are no clusters in the road)
       if (dead || 
          (noClusters && 
@@ -1102,16 +1113,16 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
        if (currenttrack->GetDetectorIndex()==idetc) { // track already on the cluster's detector
          // take into account misalignment (bring track to real detector plane)
          Double_t xTrOrig = currenttrack->GetX();
-         currenttrack->PropagateTo(xTrOrig+cl->GetX(),0.,0.);
+         if (!currenttrack->Propagate(xTrOrig+cl->GetX())) continue;
          // a first cut on track-cluster distance
          if ( (currenttrack->GetZ()-cl->GetZ())*(currenttrack->GetZ()-cl->GetZ())*msz + 
               (currenttrack->GetY()-cl->GetY())*(currenttrack->GetY()-cl->GetY())*msy > 1. ) 
            {  // cluster not associated to track
-             //printf("not ass\n");
+             AliDebug(2,"not associated");
              continue;
            }
          // bring track back to ideal detector plane
-         currenttrack->PropagateTo(xTrOrig,0.,0.);
+         if (!currenttrack->Propagate(xTrOrig)) continue;
        } else {                                      // have to move track to cluster's detector
          const AliITSdetector &detc=layer.GetDetector(idetc);
          // a first cut on track-cluster distance
@@ -1138,7 +1149,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
        // calculate track-clusters chi2
        chi2trkcl = GetPredictedChi2MI(currenttrack,cl,ilayer); 
        // chi2 cut
-       //printf("chi2 %f max %f\n",chi2trkcl,AliITSReconstructor::GetRecoParam()->GetMaxChi2s(ilayer));
+       AliDebug(2,Form("chi2 %f max %f",chi2trkcl,AliITSReconstructor::GetRecoParam()->GetMaxChi2s(ilayer)));
        if (chi2trkcl < AliITSReconstructor::GetRecoParam()->GetMaxChi2s(ilayer)) {
          if (cl->GetQ()==0) deadzoneSPD=kTRUE; // only 1 prolongation with virtual cluster       
          if (ntracks[ilayer]>=100) continue;
@@ -1148,7 +1159,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
 
          if (cl->GetQ()!=0) { // real cluster
            if (!UpdateMI(updatetrack,cl,chi2trkcl,(ilayer<<28)+clidx)) {
-             //printf("update failed\n");
+             AliDebug(2,"update failed");
              continue;
            } 
            updatetrack->SetSampledEdx(cl->GetQ(),updatetrack->GetNumberOfClusters()-1); //b.b.
@@ -1161,8 +1172,9 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
 
          if (changedet) {
            Float_t xlocnewdet,zlocnewdet;
-           LocalModuleCoord(ilayer,idet,updatetrack,xlocnewdet,zlocnewdet); // local module coords
-           updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xlocnewdet,zlocnewdet);
+           if(LocalModuleCoord(ilayer,idet,updatetrack,xlocnewdet,zlocnewdet)) { // local module coords
+             updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xlocnewdet,zlocnewdet);
+           }
          } else {
            updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
          }
@@ -1185,7 +1197,10 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
          } //apply vertex constrain              
          ntracks[ilayer]++;
        }  // create new hypothesis
-       //else printf("chi2 too large\n");
+       else {
+         AliDebug(2,"chi2 too large");
+       }
+
       } // loop over possible prolongations 
      
       // allow one prolongation without clusters
@@ -2024,13 +2039,14 @@ void AliITStrackerMI::AliITSdetector::ReadBadDetectorAndChips(Int_t ilayer,Int_t
 
   // Get calibration from AliITSDetTypeRec
   AliITSCalibration *calib = (AliITSCalibration*)detTypeRec->GetCalibrationModel(idet);
+  calib->SetModuleIndex(idet);
   AliITSCalibration *calibSPDdead = 0;
   if(detType==0) calibSPDdead = (AliITSCalibration*)detTypeRec->GetSPDDeadModel(idet); // TEMPORARY
   if (calib->IsBad() ||
       (detType==0 && calibSPDdead->IsBad())) // TEMPORARY
     {
       SetBad();
-      printf("lay %d bad %d\n",ilayer,idet);
+      //      printf("lay %d bad %d\n",ilayer,idet);
     }
 
   // Get segmentation from AliITSDetTypeRec
@@ -2044,6 +2060,7 @@ void AliITStrackerMI::AliITSdetector::ReadBadDetectorAndChips(Int_t ilayer,Int_t
   for (Int_t iCh=0;iCh<fNChips;iCh++) {
     fChipIsBad[iCh] = calib->IsChipBad(iCh);
     if (detType==0 && calibSPDdead->IsChipBad(iCh)) fChipIsBad[iCh] = kTRUE; // TEMPORARY
+    //if(fChipIsBad[iCh]) {printf("lay %d det %d bad chip %d\n",ilayer,idet,iCh);}
   }
 
   return;
@@ -2188,12 +2205,13 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      // remember old position [SR, GSI 18.02.2003]
      Double_t oldX=0., oldY=0., oldZ=0.;
      if (track->IsStartedTimeIntegral() && step==1) {
-        track->GetGlobalXYZat(track->GetX(),oldX,oldY,oldZ);
+        if (!track->GetGlobalXYZat(track->GetX(),oldX,oldY,oldZ)) return kFALSE;
      }
      //
 
      Double_t oldGlobXYZ[3];
-     track->GetXYZ(oldGlobXYZ);
+     if (!track->GetXYZ(oldGlobXYZ)) return kFALSE;
+     //TMath::Sqrt(track->GetSigmaY2());
 
      Double_t phi,z;
      if (!track->GetPhiZat(r,phi,z)) return kFALSE;
@@ -2204,17 +2222,18 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      Int_t skip = CheckSkipLayer(track,ilayer,idet);
      if (skip==2) {
        // propagate to the layer radius
-       Double_t xToGo; track->GetLocalXat(r,xToGo);
-       track->AliExternalTrackParam::PropagateTo(xToGo,GetBz());
+       Double_t xToGo; if (!track->GetLocalXat(r,xToGo)) return kFALSE;
+       if (!track->Propagate(xToGo)) return kFALSE;
        // apply correction for material of the current layer
        CorrectForLayerMaterial(track,ilayer,oldGlobXYZ,dir);
        modstatus = 4; // out in z
-       LocalModuleCoord(ilayer,idet,track,xloc,zloc); // local module coords
-       track->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
+       if(LocalModuleCoord(ilayer,idet,track,xloc,zloc)) { // local module coords
+        track->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
+       }
        // track time update [SR, GSI 17.02.2003]
        if (track->IsStartedTimeIntegral() && step==1) {
         Double_t newX, newY, newZ;
-        track->GetGlobalXYZat(track->GetX(),newX,newY,newZ);
+        if (!track->GetGlobalXYZat(track->GetX(),newX,newY,newZ)) return kFALSE;
         Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) + 
                        (oldZ-newZ)*(oldZ-newZ);
         track->AddTimeStep(TMath::Sqrt(dL2));
@@ -2228,7 +2247,7 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      if (!track->Propagate(det.GetPhi(),det.GetR())) return kFALSE;
 
      track->SetDetectorIndex(idet);
-     LocalModuleCoord(ilayer,idet,track,xloc,zloc); // local module coords
+     if(!LocalModuleCoord(ilayer,idet,track,xloc,zloc)) return kFALSE; // local module coords
 
      Double_t dz,zmin,zmax,dy,ymin,ymax;
 
@@ -2245,7 +2264,7 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
           const AliITSdetector &detc=layer.GetDetector(idet);
           if (!track->Propagate(detc.GetPhi(),detc.GetR())) return kFALSE;
           track->SetDetectorIndex(idet);
-          LocalModuleCoord(ilayer,idet,track,xloc,zloc); // local module coords
+          if(!LocalModuleCoord(ilayer,idet,track,xloc,zloc)) return kFALSE; // local module coords
         }
         Int_t cllayer = (idx & 0xf0000000) >> 28;;
         Double_t chi2=GetPredictedChi2MI(track,cl,cllayer);
@@ -2260,10 +2279,10 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      } else { // no cluster in this layer
        if (skip==1) {
         modstatus = 3; // skipped
-         // Plane Eff determination: 
-         if (planeeff && AliITSReconstructor::GetRecoParam()->GetLayersToSkip(ilayer)) { 
-           if (IsOKForPlaneEff(track,ilayer))  // only adequate track for plane eff. evaluation
-              UseTrackForPlaneEff(track,ilayer); 
+         // Plane Eff determination:
+         if (planeeff && ilayer==AliITSReconstructor::GetRecoParam()->GetIPlanePlaneEff()) {
+           if (IsOKForPlaneEff(track,clusters,ilayer))  // only adequate track for plane eff. evaluation
+              UseTrackForPlaneEff(track,ilayer);
          }
        } else {
         modstatus = 5; // no cls in road
@@ -2320,7 +2339,7 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      // track time update [SR, GSI 17.02.2003]
      if (track->IsStartedTimeIntegral() && step==1) {
         Double_t newX, newY, newZ;
-        track->GetGlobalXYZat(track->GetX(),newX,newY,newZ);
+        if (!track->GetGlobalXYZat(track->GetX(),newX,newY,newZ)) return kFALSE;
         Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) + 
                        (oldZ-newZ)*(oldZ-newZ);
         track->AddTimeStep(TMath::Sqrt(dL2));
@@ -2329,7 +2348,7 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
 
   } // end loop on layers
 
-  if (!track->PropagateTo(xx,0.,0.)) return kFALSE;
+  if (!track->Propagate(xx)) return kFALSE;
 
   return kTRUE;
 }
@@ -2440,8 +2459,10 @@ Double_t AliITStrackerMI::GetMatchingChi2(AliITStrackMI * track1, AliITStrackMI
 {
   //
   // return matching chi2 between two tracks
+  Double_t largeChi2=1000.;
+
   AliITStrackMI track3(*track2);
-  track3.Propagate(track1->GetAlpha(),track1->GetX());
+  if (!track3.Propagate(track1->GetAlpha(),track1->GetX())) return largeChi2;
   TMatrixD vec(5,1);
   vec(0,0)=track1->GetY()   - track3.GetY();
   vec(1,0)=track1->GetZ()   - track3.GetZ();
@@ -3528,6 +3549,7 @@ void AliITStrackerMI::CookLabel(AliITStrackMI *track,Float_t wrong) const {
      for (Int_t ind=0;ind<3;ind++){
        if (tpcLabel>0)
         if (cl->GetLabel(ind)==tpcLabel) isWrong=0;
+       AliDebug(2,Form("icl %d  ilab %d lab %d",i,ind,cl->GetLabel(ind)));
      }
      track->SetChi2MIP(9,track->GetChi2MIP(9)+isWrong*(2<<l));
      nwrong+=isWrong;
@@ -3540,6 +3562,7 @@ void AliITStrackerMI::CookLabel(AliITStrackMI *track,Float_t wrong) const {
      else
        track->SetLabel(tpcLabel);
    }
+   AliDebug(2,Form(" nls %d wrong %d  label %d  tpcLabel %d\n",nclusters,nwrong,track->GetLabel(),tpcLabel));
    
 }
 //------------------------------------------------------------------------
@@ -3610,16 +3633,15 @@ Double_t AliITStrackerMI::GetPredictedChi2MI(AliITStrackMI* track, const AliITSR
   Float_t phi   = track->GetSnp();
   phi = TMath::Sqrt(phi*phi/(1.-phi*phi));
   AliITSClusterParam::GetError(layer,cluster,theta,phi,track->GetExpQ(),erry,errz);
-  //printf(" chi2: tr-cl   %f  %f   tr X %f cl X %f\n",track->GetY()-cluster->GetY(),track->GetZ()-cluster->GetZ(),track->GetX(),cluster->GetX());
+  AliDebug(2,Form(" chi2: tr-cl   %f  %f   tr X %f cl X %f",track->GetY()-cluster->GetY(),track->GetZ()-cluster->GetZ(),track->GetX(),cluster->GetX()));
   // Take into account the mis-alignment (bring track to cluster plane)
   Double_t xTrOrig=track->GetX();
-  if (!track->PropagateTo(xTrOrig+cluster->GetX(),0.,0.)) return 1000.;
-  //printf(" chi2: tr-cl   %f  %f   tr X %f cl X %f\n",track->GetY()-cluster->GetY(),track->GetZ()-cluster->GetZ(),track->GetX(),cluster->GetX());
+  if (!track->Propagate(xTrOrig+cluster->GetX())) return 1000.;
+  AliDebug(2,Form(" chi2: tr-cl   %f  %f   tr X %f cl X %f",track->GetY()-cluster->GetY(),track->GetZ()-cluster->GetZ(),track->GetX(),cluster->GetX()));
   Double_t chi2 = track->GetPredictedChi2MI(cluster->GetY(),cluster->GetZ(),erry,errz);
   // Bring the track back to detector plane in ideal geometry
   // [mis-alignment will be accounted for in UpdateMI()]
-  if (!track->PropagateTo(xTrOrig,0.,0.)) return 1000.;
+  if (!track->Propagate(xTrOrig)) return 1000.;
   Float_t ny,nz;
   AliITSClusterParam::GetNTeor(layer,cluster,theta,phi,ny,nz);  
   Double_t delta = cluster->GetNy()+cluster->GetNz()-nz-ny;
@@ -3657,10 +3679,12 @@ Int_t AliITStrackerMI::UpdateMI(AliITStrackMI* track, const AliITSRecPoint* cl,D
 
   // Take into account the mis-alignment (bring track to cluster plane)
   Double_t xTrOrig=track->GetX();
-  //Float_t clxyz[3]; cl->GetGlobalXYZ(clxyz);Double_t trxyz[3]; track->GetXYZ(trxyz);printf("gtr %f %f %f\n",trxyz[0],trxyz[1],trxyz[2]);printf("gcl %f %f %f\n",clxyz[0],clxyz[1],clxyz[2]);
-  //printf(" xtr %f  xcl %f\n",track->GetX(),cl->GetX());
+  Float_t clxyz[3]; cl->GetGlobalXYZ(clxyz);Double_t trxyz[3]; track->GetXYZ(trxyz);
+  AliDebug(2,Form("gtr %f %f %f",trxyz[0],trxyz[1],trxyz[2]));
+  AliDebug(2,Form("gcl %f %f %f",clxyz[0],clxyz[1],clxyz[2]));
+  AliDebug(2,Form(" xtr %f  xcl %f",track->GetX(),cl->GetX()));
 
-  if (!track->PropagateTo(xTrOrig+cl->GetX(),0.,0.)) return 0;
+  if (!track->Propagate(xTrOrig+cl->GetX())) return 0;
 
   
   AliCluster c(*cl);
@@ -3671,9 +3695,9 @@ Int_t AliITStrackerMI::UpdateMI(AliITStrackMI* track, const AliITSRecPoint* cl,D
   Int_t updated = track->UpdateMI(&c,chi2,index);
 
   // Bring the track back to detector plane in ideal geometry
-  if (!track->PropagateTo(xTrOrig,0.,0.)) return 0;
+  if (!track->Propagate(xTrOrig)) return 0;
 
-  //if(!updated) printf("update failed\n");
+  if(!updated) AliDebug(2,"update failed");
   return updated;
 }
 
@@ -4034,9 +4058,9 @@ void AliITStrackerMI::FindV02(AliESDEvent *event)
     //I.B. trackat0 = *bestLong;
     new (&trackat0) AliITStrackMI(*bestLong);
     Double_t xx,yy,zz,alpha; 
-    bestLong->GetGlobalXYZat(bestLong->GetX(),xx,yy,zz);
+    if (!bestLong->GetGlobalXYZat(bestLong->GetX(),xx,yy,zz)) continue;
     alpha = TMath::ATan2(yy,xx);    
-    trackat0.Propagate(alpha,0);      
+    if (!trackat0.Propagate(alpha,0)) continue;      
     // calculate normalized distances to the vertex 
     //
     Float_t ptfac  = (1.+100.*TMath::Abs(trackat0.GetC()));
@@ -4402,7 +4426,7 @@ void AliITStrackerMI::FindV02(AliESDEvent *event)
        if (fnorm0<0) fnorm0*=-3;
        Float_t fnorm1 = normdist[itrack1];
        if (fnorm1<0) fnorm1*=-3;
-       if (pvertex->GetAnglep()[2]>0.1 ||  (pvertex->GetRr()<10.5)&& pvertex->GetAnglep()[2]>0.05 || pvertex->GetRr()<3){
+       if ((pvertex->GetAnglep()[2]>0.1) || ( (pvertex->GetRr()<10.5)&& pvertex->GetAnglep()[2]>0.05 ) || (pvertex->GetRr()<3)){
          pb0    =  TMath::Exp(-TMath::Min(fnorm0,Float_t(16.))/12.);
          pb1    =  TMath::Exp(-TMath::Min(fnorm1,Float_t(16.))/12.);
        }
@@ -4689,9 +4713,9 @@ Int_t AliITStrackerMI::CorrectForPipeMaterial(AliITStrackMI *t,
 
   // Define budget mode:
   // 0: material from AliITSRecoParam (hard coded)
-  // 1: material from TGeo (on the fly)
+  // 1: material from TGeo in one step (on the fly)
   // 2: material from lut
-  // 3: material from TGeo (same for all hypotheses)
+  // 3: material from TGeo in one step (same for all hypotheses)
   Int_t mode;
   switch(fUseTGeo) {
   case 0:
@@ -4721,7 +4745,8 @@ Int_t AliITStrackerMI::CorrectForPipeMaterial(AliITStrackMI *t,
 
   Float_t  dir = (direction.Contains("inward") ? 1. : -1.);
   Double_t rToGo=(dir>0 ? AliITSRecoParam::GetrInsidePipe() : AliITSRecoParam::GetrOutsidePipe());
-  Double_t xToGo; t->GetLocalXat(rToGo,xToGo);
+  Double_t xToGo;
+  if (!t->GetLocalXat(rToGo,xToGo)) return 0;
 
   Double_t xOverX0,x0,lengthTimesMeanDensity;
   Bool_t anglecorr=kTRUE;
@@ -4731,15 +4756,20 @@ Int_t AliITStrackerMI::CorrectForPipeMaterial(AliITStrackMI *t,
     xOverX0 = AliITSRecoParam::GetdPipe();
     x0 = AliITSRecoParam::GetX0Be();
     lengthTimesMeanDensity = xOverX0*x0;
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   case 1:
     if (!t->PropagateToTGeo(xToGo,1)) return 0;
-    return 1;
     break;
   case 2:
     if(fxOverX0Pipe<0) BuildMaterialLUT("Pipe");  
     xOverX0 = fxOverX0Pipe;
     lengthTimesMeanDensity = fxTimesRhoPipe;
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   case 3:
     if(!fxOverX0PipeTrks || index<0 || index>=fNtracks) Error("CorrectForPipeMaterial","Incorrect usage of UseTGeo option!\n");
@@ -4753,14 +4783,12 @@ Int_t AliITStrackerMI::CorrectForPipeMaterial(AliITStrackMI *t,
     }
     xOverX0 = fxOverX0PipeTrks[index];
     lengthTimesMeanDensity = fxTimesRhoPipeTrks[index];
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   }
 
-  lengthTimesMeanDensity *= dir;
-
-  if (!t->AliExternalTrackParam::PropagateTo(xToGo,GetBz())) return 0;
-  if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
-
   return 1;
 }
 //------------------------------------------------------------------------
@@ -4774,9 +4802,10 @@ Int_t AliITStrackerMI::CorrectForShieldMaterial(AliITStrackMI *t,
 
   // Define budget mode:
   // 0: material from AliITSRecoParam (hard coded)
-  // 1: material from TGeo (on the fly)
+  // 1: material from TGeo in steps of X cm (on the fly)
+  //    X = AliITSRecoParam::GetStepSizeTGeo()
   // 2: material from lut
-  // 3: material from TGeo (same for all hypotheses)
+  // 3: material from TGeo in one step (same for all hypotheses)
   Int_t mode;
   switch(fUseTGeo) {
   case 0:
@@ -4815,27 +4844,35 @@ Int_t AliITStrackerMI::CorrectForShieldMaterial(AliITStrackMI *t,
     Error("CorrectForShieldMaterial"," Wrong shield name\n");
     return 0;
   }
-  Double_t xToGo; t->GetLocalXat(rToGo,xToGo);
+  Double_t xToGo;
+  if (!t->GetLocalXat(rToGo,xToGo)) return 0;
 
   Int_t index=2*fCurrentEsdTrack+shieldindex;
 
   Double_t xOverX0,x0,lengthTimesMeanDensity;
   Bool_t anglecorr=kTRUE;
+  Int_t nsteps=1;
 
   switch(mode) {
   case 0:
     xOverX0 = AliITSRecoParam::Getdshield(shieldindex);
     x0 = AliITSRecoParam::GetX0shield(shieldindex);
     lengthTimesMeanDensity = xOverX0*x0;
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   case 1:
-    if (!t->PropagateToTGeo(xToGo,1)) return 0;
-    return 1;
+    nsteps= (Int_t)(TMath::Abs(t->GetX()-xToGo)/AliITSReconstructor::GetRecoParam()->GetStepSizeTGeo())+1;
+    if (!t->PropagateToTGeo(xToGo,nsteps)) return 0; // cross the material and apply correction
     break;
   case 2:
     if(fxOverX0Shield[shieldindex]<0) BuildMaterialLUT("Shields");  
     xOverX0 = fxOverX0Shield[shieldindex];
     lengthTimesMeanDensity = fxTimesRhoShield[shieldindex];
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   case 3:
     if(!fxOverX0ShieldTrks || index<0 || index>=2*fNtracks) Error("CorrectForShieldMaterial","Incorrect usage of UseTGeo option!\n");
@@ -4849,14 +4886,12 @@ Int_t AliITStrackerMI::CorrectForShieldMaterial(AliITStrackMI *t,
     }
     xOverX0 = fxOverX0ShieldTrks[index];
     lengthTimesMeanDensity = fxTimesRhoShieldTrks[index];
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   }
 
-  lengthTimesMeanDensity *= dir;
-
-  if (!t->AliExternalTrackParam::PropagateTo(xToGo,GetBz())) return 0;
-  if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
-
   return 1;
 }
 //------------------------------------------------------------------------
@@ -4871,9 +4906,10 @@ Int_t AliITStrackerMI::CorrectForLayerMaterial(AliITStrackMI *t,
 
   // Define budget mode:
   // 0: material from AliITSRecoParam (hard coded)
-  // 1: material from TGeo (on the fly)
+  // 1: material from TGeo in stepsof X cm (on the fly)
+  //    X = AliITSRecoParam::GetStepSizeTGeo()
   // 2: material from lut
-  // 3: material from TGeo (same for all hypotheses)
+  // 3: material from TGeo in one step (same for all hypotheses)
   Int_t mode;
   switch(fUseTGeo) {
   case 0:
@@ -4905,39 +4941,50 @@ Int_t AliITStrackerMI::CorrectForLayerMaterial(AliITStrackMI *t,
   Double_t deltar=(layerindex<2 ? 0.10*r : 0.05*r);
 
   Double_t rToGo=TMath::Sqrt(t->GetX()*t->GetX()+t->GetY()*t->GetY())-deltar*dir;
-  Double_t xToGo; t->GetLocalXat(rToGo,xToGo);
+  Double_t xToGo;
+  if (!t->GetLocalXat(rToGo,xToGo)) return 0;
 
   Int_t index=6*fCurrentEsdTrack+layerindex;
 
-  // Bring the track beyond the material
-  if (!t->AliExternalTrackParam::PropagateTo(xToGo,GetBz())) return 0;
-  Double_t globXYZ[3];
-  t->GetXYZ(globXYZ);
 
   Double_t xOverX0=0.0,x0=0.0,lengthTimesMeanDensity=0.0;
   Double_t mparam[7];
   Bool_t anglecorr=kTRUE;
+  Int_t nsteps=1;
 
   switch(mode) {
   case 0:
     xOverX0 = fgLayers[layerindex].GetThickness(t->GetY(),t->GetZ(),x0);
     lengthTimesMeanDensity = xOverX0*x0;
+    // Bring the track beyond the material
+    if (!t->Propagate(xToGo)) return 0;
+    lengthTimesMeanDensity *= dir;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   case 1:
-    AliTracker::MeanMaterialBudget(oldGlobXYZ,globXYZ,mparam);
-    if(mparam[1]>900000) return 0;
-    xOverX0=mparam[1];
-    lengthTimesMeanDensity=mparam[0]*mparam[4];
-    anglecorr=kFALSE;
+    Double_t rOld=TMath::Sqrt(oldGlobXYZ[0]*oldGlobXYZ[0]+oldGlobXYZ[1]*oldGlobXYZ[1]);
+    Double_t xOld;
+    if (!t->GetLocalXat(rOld,xOld)) return 0;
+    if (!t->Propagate(xOld)) return 0; // back before material (no correction)
+    nsteps = (Int_t)(TMath::Abs(xOld-xToGo)/AliITSReconstructor::GetRecoParam()->GetStepSizeTGeo())+1;
+    if (!t->PropagateToTGeo(xToGo,nsteps)) return 0; // cross the material and apply correction
     break;
   case 2:
     if(fxOverX0Layer[layerindex]<0) BuildMaterialLUT("Layers");  
     xOverX0 = fxOverX0Layer[layerindex];
     lengthTimesMeanDensity = fxTimesRhoLayer[layerindex];
+    // Bring the track beyond the material
+    if (!t->Propagate(xToGo)) return 0;
+    lengthTimesMeanDensity *= dir;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   case 3:
     if(!fxOverX0LayerTrks || index<0 || index>=6*fNtracks) Error("CorrectForLayerMaterial","Incorrect usage of UseTGeo option!\n");
-    if(fxOverX0LayerTrks[index]<0) {
+    // Bring the track beyond the material
+    if (!t->Propagate(xToGo)) return 0;
+    Double_t globXYZ[3];
+    if (!t->GetXYZ(globXYZ)) return 0;
+    if (fxOverX0LayerTrks[index]<0) {
       AliTracker::MeanMaterialBudget(oldGlobXYZ,globXYZ,mparam);
       if(mparam[1]>900000) return 0;
       Double_t angle=TMath::Sqrt((1.+t->GetTgl()*t->GetTgl())/
@@ -4949,13 +4996,11 @@ Int_t AliITStrackerMI::CorrectForLayerMaterial(AliITStrackMI *t,
     }
     xOverX0 = fxOverX0LayerTrks[index];
     lengthTimesMeanDensity = fxTimesRhoLayerTrks[index];
+    lengthTimesMeanDensity *= dir;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   }
 
-  lengthTimesMeanDensity *= dir;
-
-  if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
-
   return 1;
 }
 //------------------------------------------------------------------------
@@ -5059,7 +5104,10 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
                          fSPDdetzcentre[2] - 0.5*AliITSRecoParam::GetSPDdetzlength(),
                          fSPDdetzcentre[3] - 0.5*AliITSRecoParam::GetSPDdetzlength()};
     for (Int_t i=0; i<3; i++)
-      if (track->GetZ()-dz<zmaxdead[i] && track->GetZ()+dz>zmindead[i]) return 1;  
+      if (track->GetZ()-dz<zmaxdead[i] && track->GetZ()+dz>zmindead[i]) {
+       AliDebug(2,Form("crack SPD %d",ilayer));
+       return 1; 
+      } 
   }
 
   // check bad zones from OCDB
@@ -5069,12 +5117,6 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
 
   AliITSdetector &det=fgLayers[ilayer].GetDetector(idet);  
 
-  // check if this detector is bad
-  if (det.IsBad()) {
-    //printf("lay %d  bad detector %d\n",ilayer,idet);
-    return 2;
-  }
-
   Int_t detType=-1;
   Float_t detSizeFactorX=0.0001,detSizeFactorZ=0.0001;
   if (ilayer==0 || ilayer==1) {        // ----------  SPD
@@ -5099,17 +5141,32 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
   Float_t xlocmax = xloc+dy;
   Int_t chipsInRoad[100];
 
-  if (TMath::Max(TMath::Abs(xlocmin),TMath::Abs(xlocmax))>0.5*detSizeX ||
-      TMath::Max(TMath::Abs(zlocmin),TMath::Abs(zlocmax))>0.5*detSizeZ) return 0;
-  //printf("lay %d det %d zmim zmax %f %f xmin xmax %f %f   %f %f\n",ilayer,idet,zlocmin,zlocmax,xlocmin,xlocmax,segm->Dx(),segm->Dz());
+  // check if road goes out of detector
+  Bool_t touchNeighbourDet=kFALSE; 
+  if (TMath::Abs(xlocmin)>0.5*detSizeX) {xlocmin=-0.5*detSizeX; touchNeighbourDet=kTRUE;} 
+  if (TMath::Abs(xlocmax)>0.5*detSizeX) {xlocmax=+0.5*detSizeX; touchNeighbourDet=kTRUE;} 
+  if (TMath::Abs(zlocmin)>0.5*detSizeZ) {zlocmin=-0.5*detSizeZ; touchNeighbourDet=kTRUE;} 
+  if (TMath::Abs(zlocmax)>0.5*detSizeZ) {zlocmax=+0.5*detSizeZ; touchNeighbourDet=kTRUE;} 
+  AliDebug(2,Form("layer %d det %d zmim zmax %f %f xmin xmax %f %f   %f %f",ilayer,idet,zlocmin,zlocmax,xlocmin,xlocmax,detSizeZ,detSizeX));
+
+  // check if this detector is bad
+  if (det.IsBad()) {
+    AliDebug(2,Form("lay %d  bad detector %d",ilayer,idet));
+    if(!touchNeighbourDet) {
+      return 2; // all detectors in road are bad
+    } else { 
+      return 3; // at least one is bad
+    }
+  }
+
   Int_t nChipsInRoad = segm->GetChipsInLocalWindow(chipsInRoad,zlocmin,zlocmax,xlocmin,xlocmax);
-  //printf("lay %d nChipsInRoad %d\n",ilayer,nChipsInRoad);
+  AliDebug(2,Form("lay %d nChipsInRoad %d",ilayer,nChipsInRoad));
   if (!nChipsInRoad) return 0;
 
   Bool_t anyBad=kFALSE,anyGood=kFALSE;
   for (Int_t iCh=0; iCh<nChipsInRoad; iCh++) {
     if (chipsInRoad[iCh]<0 || chipsInRoad[iCh]>det.GetNChips()-1) continue;
-    //printf("  chip %d bad %d\n",chipsInRoad[iCh],(Int_t)det.IsChipBad(chipsInRoad[iCh]));
+    AliDebug(2,Form("  chip %d bad %d",chipsInRoad[iCh],(Int_t)det.IsChipBad(chipsInRoad[iCh])));
     if (det.IsChipBad(chipsInRoad[iCh])) {
       anyBad=kTRUE;
     } else {
@@ -5117,9 +5174,19 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
     } 
   }
 
-  if (!anyGood) return 2; // all chips in road are bad
+  if (!anyGood) {
+    if(!touchNeighbourDet) {
+      AliDebug(2,"all bad in road");
+      return 2;  // all chips in road are bad
+    } else {
+      return 3; // at least a bad chip in road
+    }
+  }
 
-  if (anyBad) return 3; // at least a bad chip in road
+  if (anyBad) {
+    AliDebug(2,"at least a bad in road");
+    return 3; // at least a bad chip in road
+  } 
 
 
   if (!AliITSReconstructor::GetRecoParam()->GetUseSingleBadChannelsFromOCDB()
@@ -5129,12 +5196,14 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
   // There are no clusters in road: check if there is at least 
   // a bad SPD pixel or SDD anode 
 
-  if(ilayer==1 || ilayer==3 || ilayer==5) 
-    idet += AliITSgeomTGeo::GetNLadders(ilayer)*AliITSgeomTGeo::GetNDetectors(ilayer);
-
-  //if (fITSChannelStatus->AnyBadInRoad(idet,zlocmin,zlocmax,xlocmin,xlocmax)) return 3;
+  Int_t idetInITS=idet;
+  for(Int_t l=0;l<ilayer;l++) idetInITS+=AliITSgeomTGeo::GetNLadders(l+1)*AliITSgeomTGeo::GetNDetectors(l+1);
 
-  if (fITSChannelStatus->FractionOfBadInRoad(idet,zlocmin,zlocmax,xlocmin,xlocmax) > AliITSReconstructor::GetRecoParam()->GetMinFractionOfBadInRoad()) return 3;
+  if (fITSChannelStatus->AnyBadInRoad(idetInITS,zlocmin,zlocmax,xlocmin,xlocmax)) {
+    AliDebug(2,Form("Bad channel in det %d of layer %d\n",idet,ilayer));
+    return 3;
+  }
+  //if (fITSChannelStatus->FractionOfBadInRoad(idet,zlocmin,zlocmax,xlocmin,xlocmax) > AliITSReconstructor::GetRecoParam()->GetMinFractionOfBadInRoad()) return 3;
 
   return 0;
 }
@@ -5161,9 +5230,9 @@ Bool_t AliITStrackerMI::LocalModuleCoord(Int_t ilayer,Int_t idet,
 
   AliITSdetector &detector = fgLayers[ilayer].GetDetector(idet);
   // take into account the misalignment: xyz at real detector plane
-  track->GetXYZAt(detector.GetRmisal(),GetBz(),xyzGlob);
+  if(!track->GetXYZAt(detector.GetRmisal(),GetBz(),xyzGlob)) return kFALSE;
 
-  AliITSgeomTGeo::GlobalToLocal(ilayer+1,lad,det,xyzGlob,xyzLoc);
+  if(!AliITSgeomTGeo::GlobalToLocal(ilayer+1,lad,det,xyzGlob,xyzLoc)) return kFALSE;
 
   xloc = (Float_t)xyzLoc[0];
   zloc = (Float_t)xyzLoc[2];
@@ -5171,7 +5240,7 @@ Bool_t AliITStrackerMI::LocalModuleCoord(Int_t ilayer,Int_t idet,
   return kTRUE;
 }
 //------------------------------------------------------------------------
-Bool_t AliITStrackerMI::IsOKForPlaneEff(AliITStrackMI* track, Int_t ilayer) const {
+Bool_t AliITStrackerMI::IsOKForPlaneEff(AliITStrackMI* track, const Int_t *clusters, Int_t ilayer) const {
 //
 // Method to be optimized further: 
 // Aim: decide whether a track can be used for PlaneEff evaluation
@@ -5191,12 +5260,41 @@ Bool_t AliITStrackerMI::IsOKForPlaneEff(AliITStrackMI* track, Int_t ilayer) cons
 //
 // input: AliITStrackMI* track, ilayer= layer number [0,5]
 // return: Bool_t   -> kTRUE if usable track, kFALSE if not usable. 
+//
+  Int_t index[AliITSgeomTGeo::kNLayers];
+  Int_t k;
+  for (k=0; k<AliITSgeomTGeo::GetNLayers(); k++) index[k]=-1;
+  //
+  for (k=0; k<AliITSgeomTGeo::GetNLayers(); k++) {
+    index[k]=clusters[k];
+  }
+
   if(!fPlaneEff)
     {AliWarning("IsOKForPlaneEff: null pointer to AliITSPlaneEff"); return kFALSE;}
   AliITSlayer &layer=fgLayers[ilayer];
   Double_t r=layer.GetR();
   AliITStrackMI tmp(*track);
 
+// require a minimal number of cluster in other layers and eventually clusters in closest layers 
+  Int_t ncl=0; 
+  for(Int_t lay=AliITSgeomTGeo::kNLayers-1;lay>ilayer;lay--) {
+    AliDebug(2,Form("trak=%d  lay=%d  ; index=%d ESD label= %d",tmp.GetLabel(),lay,
+                    tmp.GetClIndex(lay),((AliESDtrack*)tmp.GetESDtrack())->GetLabel())) ;
+    if (tmp.GetClIndex(lay)>0) ncl++;
+  }
+  Bool_t nextout = kFALSE;
+  if(ilayer==AliITSgeomTGeo::kNLayers-1) nextout=kTRUE; // you are already on the outermost layer
+  else nextout = ((tmp.GetClIndex(ilayer+1)>0)? kTRUE : kFALSE );
+  Bool_t nextin = kFALSE;
+  if(ilayer==0) nextin=kTRUE; // you are already on the innermost layer
+  else nextin = ((index[ilayer-1]>=0)? kTRUE : kFALSE );
+  if(ncl<AliITSgeomTGeo::kNLayers-(ilayer+1)-AliITSReconstructor::GetRecoParam()->GetMaxMissingClustersPlaneEff()) 
+     return kFALSE; 
+  if(AliITSReconstructor::GetRecoParam()->GetRequireClusterInOuterLayerPlaneEff() && !nextout)  return kFALSE;
+  if(AliITSReconstructor::GetRecoParam()->GetRequireClusterInInnerLayerPlaneEff() && !nextin)   return kFALSE;
+  if(tmp.Pt() < AliITSReconstructor::GetRecoParam()->GetMinPtPlaneEff()) return kFALSE;
+ //  if(AliITSReconstructor::GetRecoParam()->GetOnlyConstraintPlaneEff()  && !tmp.GetConstrain()) return kFALSE;
+
 // detector number
   Double_t phi,z;
   if (!tmp.GetPhiZat(r,phi,z)) return kFALSE;