]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITStrackerMI.cxx
modifications to satisfy the coding conventions
[u/mrichter/AliRoot.git] / ITS / AliITStrackerMI.cxx
index d64bc598b87ca8729a031891279c828cf62f1b1f..85b1ccdc68cdfce9562a0162675c08c873f2dc0b 100644 (file)
@@ -19,6 +19,8 @@
 //    It reads AliITSRecPoint clusters and creates AliITStrackMI tracks
 //                   and fills with them the ESD
 //          Origin: Marian Ivanov, CERN, Marian.Ivanov@cern.ch 
+//          Current support and development: 
+//                     Andrea Dainese, andrea.dainese@lnl.infn.it
 //     dE/dx analysis by: Boris Batyunya, JINR, Boris.Batiounia@cern.ch
 //     Params moved to AliITSRecoParam by: Andrea Dainese, INFN
 //     Material budget from TGeo by: Ludovic Gaudichet & Andrea Dainese, INFN
 #include "AliTrackPointArray.h"
 #include "AliAlignObj.h"
 #include "AliITSClusterParam.h"
-#include "AliITSPlaneEff.h"
 #include "AliCDBManager.h"
 #include "AliCDBEntry.h"
+#include "AliITSsegmentation.h"
+#include "AliITSCalibration.h"
 #include "AliITSCalibrationSPD.h"
 #include "AliITSCalibrationSDD.h"
 #include "AliITSCalibrationSSD.h"
+#include "AliITSPlaneEff.h"
+#include "AliITSPlaneEffSPD.h"
+#include "AliITSPlaneEffSDD.h"
+#include "AliITSPlaneEffSSD.h"
 #include "AliITStrackerMI.h"
 
 ClassImp(AliITStrackerMI)
@@ -80,6 +87,8 @@ fxTimesRhoShieldTrks(0),
 fxOverX0LayerTrks(0),
 fxTimesRhoLayerTrks(0),
 fDebugStreamer(0),
+fITSChannelStatus(0),
+fDetTypeRec(0),
 fPlaneEff(0) {
   //Default constructor
   Int_t i;
@@ -113,6 +122,8 @@ fxTimesRhoShieldTrks(0),
 fxOverX0LayerTrks(0),
 fxTimesRhoLayerTrks(0),
 fDebugStreamer(0),
+fITSChannelStatus(0),
+fDetTypeRec(0),
 fPlaneEff(0) {
   //--------------------------------------------------------------------
   //This is the AliITStrackerMI constructor
@@ -149,9 +160,10 @@ fPlaneEff(0) {
         TGeoHMatrix m; AliITSgeomTGeo::GetOrigMatrix(i,j,k,m);
         const TGeoHMatrix *tm=AliITSgeomTGeo::GetTracking2LocalMatrix(i,j,k);
         m.Multiply(tm);
-        Double_t txyz[3]={0.}, xyz[3]={0.};
+        Double_t txyz[3]={0.};
+       xyz[0]=0.;xyz[1]=0.;xyz[2]=0.;
         m.LocalToMaster(txyz,xyz);
-        Double_t r=TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
+        r=TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
         Double_t phi=TMath::ATan2(xyz[1],xyz[0]);
 
         if (phi<0) phi+=TMath::TwoPi();
@@ -159,10 +171,18 @@ fPlaneEff(0) {
 
         AliITSdetector &det=fgLayers[i-1].GetDetector((j-1)*ndet + k-1); 
         new(&det) AliITSdetector(r,phi); 
-      } 
-    }  
+       // compute the real radius (with misalignment)
+        TGeoHMatrix mmisal(*(AliITSgeomTGeo::GetMatrix(i,j,k)));
+        mmisal.Multiply(tm);
+       xyz[0]=0.;xyz[1]=0.;xyz[2]=0.;
+        mmisal.LocalToMaster(txyz,xyz);
+        Double_t rmisal=TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
+       det.SetRmisal(rmisal);
+       
+      } // end loop on detectors
+    } // end loop on ladders
+  } // end loop on layers
 
-  }
 
   fI=AliITSgeomTGeo::GetNLayers();
 
@@ -205,6 +225,18 @@ fPlaneEff(0) {
   
   fDebugStreamer = new TTreeSRedirector("ITSdebug.root");
 
+  // only for plane efficiency evaluation
+  if (AliITSReconstructor::GetRecoParam()->GetComputePlaneEff()) {
+    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);
+  }
 }
 //------------------------------------------------------------------------
 AliITStrackerMI::AliITStrackerMI(const AliITStrackerMI &tracker):AliTracker(tracker),
@@ -232,6 +264,8 @@ fxTimesRhoShieldTrks(0),
 fxOverX0LayerTrks(0),
 fxTimesRhoLayerTrks(0),
 fDebugStreamer(tracker.fDebugStreamer),
+fITSChannelStatus(tracker.fITSChannelStatus),
+fDetTypeRec(tracker.fDetTypeRec),
 fPlaneEff(tracker.fPlaneEff) {
   //Copy constructor
   Int_t i;
@@ -266,6 +300,8 @@ AliITStrackerMI::~AliITStrackerMI()
     //fDebugStreamer->Close();
     delete fDebugStreamer;
   }
+  if(fITSChannelStatus) delete fITSChannelStatus;
+  if(fPlaneEff) delete fPlaneEff;
 }
 //------------------------------------------------------------------------
 void AliITStrackerMI::SetLayersNotToSkip(Int_t *l) {
@@ -275,6 +311,37 @@ void AliITStrackerMI::SetLayersNotToSkip(Int_t *l) {
   for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) fLayersNotToSkip[i]=l[i];
 }
 //------------------------------------------------------------------------
+void AliITStrackerMI::ReadBadFromDetTypeRec() {
+  //--------------------------------------------------------------------
+  //This function read ITS bad detectors, chips, channels from AliITSDetTypeRec
+  //i.e. from OCDB
+  //--------------------------------------------------------------------
+
+  if(!AliITSReconstructor::GetRecoParam()->GetUseBadZonesFromOCDB()) return;
+
+  Info("ReadBadFromDetTypeRec","Reading info about bad ITS detectors and channels\n");
+
+  if(!fDetTypeRec) Error("ReadBadFromDetTypeRec","AliITSDetTypeRec nof found!\n");
+
+  // ITS channels map
+  if(fITSChannelStatus) delete fITSChannelStatus;
+  fITSChannelStatus = new AliITSChannelStatus(AliCDBManager::Instance());
+
+  // ITS detectors and chips
+  Int_t i=0,j=0,k=0,ndet=0;
+  for (i=1; i<AliITSgeomTGeo::GetNLayers()+1; i++) {
+    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);
+      } // end loop on detectors
+    } // end loop on ladders
+  } // end loop on layers
+  
+  return;
+}
+//------------------------------------------------------------------------
 Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
   //--------------------------------------------------------------------
   //This function loads ITS clusters
@@ -285,13 +352,13 @@ Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
     return 1;
   }
 
-  TClonesArray dummy("AliITSRecPoint",10000), *clusters=&dummy;
+  static TClonesArray dummy("AliITSRecPoint",10000), *clusters=&dummy;
   branch->SetAddress(&clusters);
 
-  Int_t j=0;
+  Int_t i=0,j=0,ndet=0;
   Int_t detector=0;
-  for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) {
-    Int_t ndet=fgLayers[i].GetNdetectors();
+  for (i=0; i<AliITSgeomTGeo::GetNLayers(); i++) {
+    ndet=fgLayers[i].GetNdetectors();
     Int_t jmax = j + fgLayers[i].GetNladders()*ndet;
     for (; j<jmax; j++) {           
       if (!cTree->GetEvent(j)) continue;
@@ -348,6 +415,8 @@ Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
     fgLayers[i].SortClusters();
   }
 
+  dummy.Clear();
+
   return 0;
 }
 //------------------------------------------------------------------------
@@ -358,6 +427,24 @@ void AliITStrackerMI::UnloadClusters() {
   for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) fgLayers[i].ResetClusters();
 }
 //------------------------------------------------------------------------
+void AliITStrackerMI::FillClusterArray(TObjArray* array) const {
+  //--------------------------------------------------------------------
+  // Publishes all pointers to clusters known to the tracker into the
+  // passed object array.
+  // The ownership is not transfered - the caller is not expected to delete
+  // the clusters.
+  //--------------------------------------------------------------------
+
+  for(Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) {
+    for(Int_t icl=0; icl<fgLayers[i].GetNumberOfClusters(); icl++) {
+      AliCluster *cl = (AliCluster*)fgLayers[i].GetCluster(icl);
+      array->AddLast(cl);
+    }
+  }
+
+  return;
+}
+//------------------------------------------------------------------------
 static Int_t CorrectForTPCtoITSDeadZoneMaterial(AliITStrackMI *t) {
   //--------------------------------------------------------------------
   // Correction for the material between the TPC and the ITS
@@ -383,6 +470,8 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
   // This functions reconstructs ITS tracks
   // The clusters must be already loaded !
   //--------------------------------------------------------------------
+
+
   fTrackingPhase="Clusters2Tracks";
 
   TObjArray itsTracks(15000);
@@ -466,9 +555,9 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
   for (fPass=0; fPass<2; fPass++) {
      Int_t &constraint=fConstraint[fPass]; if (constraint<0) continue;
      for (fCurrentEsdTrack=0; fCurrentEsdTrack<nentr; fCurrentEsdTrack++) {
-       //cerr<<fPass<<"    "<<fCurrentEsdTrack<<'\n';
        AliITStrackMI *t=(AliITStrackMI*)itsTracks.UncheckedAt(fCurrentEsdTrack);
        if (t==0) continue;              //this track has been already tracked
+       //cout<<"========== "<<fPass<<"    "<<fCurrentEsdTrack<<" =========\n";
        if (t->GetReconstructed()&&(t->GetNUsed()<1.5)) continue;  //this track was  already  "succesfully" reconstructed
        Float_t dz[2]; t->GetDZ(GetX(),GetY(),GetZ(),dz);              //I.B.
        if (fConstraint[fPass]) { 
@@ -482,6 +571,7 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
        ResetBestTrack();
 
        FollowProlongationTree(t,fCurrentEsdTrack,fConstraint[fPass]);
 
        SortTrackHypothesys(fCurrentEsdTrack,20,0);  //MI change
        //
@@ -497,16 +587,14 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
        if (fConstraint[fPass]&&(!besttrack->IsGoldPrimary())) continue;  //to be tracked also without vertex constrain 
 
        t->SetReconstructed(kTRUE);
-       ntrk++;                     
+       ntrk++;  
      }
      GetBestHypothesysMIP(itsTracks); 
   } // end loop on the two tracking passes
 
-  //GetBestHypothesysMIP(itsTracks);
   if(event->GetNumberOfV0s()>0) UpdateTPCV0(event);
   if(AliITSReconstructor::GetRecoParam()->GetFindV0s()) FindV02(event);
   fAfterV0 = kTRUE;
-  //GetBestHypothesysMIP(itsTracks);
   //
   itsTracks.Delete();
   //
@@ -632,7 +720,8 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
       fTrackToFollow.ResetCovariance(10.);
 
     //Refitting...
-    if (RefitAt(AliITSRecoParam::GetrInsideSPD1(),&fTrackToFollow,t,kTRUE)) {
+    Bool_t pe=AliITSReconstructor::GetRecoParam()->GetComputePlaneEff();
+    if (RefitAt(AliITSRecoParam::GetrInsideSPD1(),&fTrackToFollow,t,kTRUE,pe)) {
        fTrackToFollow.SetLabel(t->GetLabel());
        //       fTrackToFollow.CookdEdx();
        CookdEdx(&fTrackToFollow);
@@ -685,7 +774,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:
@@ -742,7 +832,8 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
   Float_t expQ = TMath::Max(0.8*t->GetTPCsignal(),30.);
 
   Float_t errlocalx,errlocalz;
-  AliITSClusterParam::GetError(l,cl,tgl,tgphi,expQ,errlocalx,errlocalz);
+  Bool_t addMisalErr=kFALSE;
+  AliITSClusterParam::GetError(l,cl,tgl,tgphi,expQ,errlocalx,errlocalz,addMisalErr);
 
   Float_t xyz[3];
   Float_t cov[6];
@@ -753,6 +844,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) {
@@ -840,6 +933,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);
     fI = ilayer;
     //
     AliITSlayer &layer=fgLayers[ilayer];
@@ -904,45 +998,17 @@ 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;
-      LocalModuleCoord(ilayer,idet,&currenttrack1,xloc,zloc); // local module coords
       currenttrack2.Propagate(det.GetPhi(),det.GetR());
       currenttrack1.SetDetectorIndex(idet);
       currenttrack2.SetDetectorIndex(idet);
+      LocalModuleCoord(ilayer,idet,&currenttrack1,xloc,zloc); // local module coords
 
       //***************
-      // DEFINITION OF SEARCH ROAD FOR CLUSTERS SELECTION
+      // DEFINITION OF SEARCH ROAD AND CLUSTERS SELECTION
       //
-      Double_t dz=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadZ()*
-                    TMath::Sqrt(currenttrack1.GetSigmaZ2() + 
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
-                   AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer));
-      Double_t dy=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadY()*
-                    TMath::Sqrt(currenttrack1.GetSigmaY2() + 
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
-                   AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer));
-      
-      // track at boundary between detectors, enlarge road
-      Double_t boundaryWidth=AliITSRecoParam::GetBoundaryWidth();
-      if ( (currenttrack1.GetY()-dy < det.GetYmin()+boundaryWidth) || 
-          (currenttrack1.GetY()+dy > det.GetYmax()-boundaryWidth) || 
-          (currenttrack1.GetZ()-dz < det.GetZmin()+boundaryWidth) ||
-          (currenttrack1.GetZ()+dz > det.GetZmax()-boundaryWidth) ) {
-       Float_t tgl = TMath::Abs(currenttrack1.GetTgl());
-       if (tgl > 1.) tgl=1.;
-       Double_t deltaXNeighbDets=AliITSRecoParam::GetDeltaXNeighbDets();
-       dz = TMath::Sqrt(dz*dz+deltaXNeighbDets*deltaXNeighbDets*tgl*tgl);
-       Float_t snp = TMath::Abs(currenttrack1.GetSnp());
-       if (snp > AliITSReconstructor::GetRecoParam()->GetMaxSnp()) continue;
-       dy = TMath::Sqrt(dy*dy+deltaXNeighbDets*deltaXNeighbDets*snp*snp);
-      } // boundary
-      
       // road in global (rphi,z) [i.e. in tracking ref. system]
-      Double_t zmin = currenttrack1.GetZ() - dz; 
-      Double_t zmax = currenttrack1.GetZ() + dz;
-      Double_t ymin = currenttrack1.GetY() + r*det.GetPhi() - dy;
-      Double_t ymax = currenttrack1.GetY() + r*det.GetPhi() + dy;
+      Double_t zmin,zmax,ymin,ymax;
+      if (!ComputeRoad(&currenttrack1,ilayer,idet,zmin,zmax,ymin,ymax)) continue;
 
       // select clusters in road
       layer.SelectClusters(zmin,zmax,ymin,ymax); 
@@ -966,6 +1032,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       }
       msz = 1./msz; // 1/RoadZ^2
       msy = 1./msy; // 1/RoadY^2
+
       //
       //
       // LOOP OVER ALL POSSIBLE TRACK PROLONGATIONS ON THIS LAYER
@@ -977,10 +1044,15 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       currenttrack = &currenttrack1;
 
       // check if the road contains a dead zone 
-      Int_t dead = CheckDeadZone(ilayer,idet,zmin,zmax); 
+      Bool_t noClusters = kFALSE;
+      if (!layer.GetNextCluster(clidx,kTRUE)) noClusters=kTRUE;
+      //if (noClusters) printf("no clusters in road\n");
+      Double_t dz=0.5*(zmax-zmin);
+      Double_t dy=0.5*(ymax-ymin);
+      Int_t dead = CheckDeadZone(&currenttrack1,ilayer,idet,dz,dy,noClusters); 
       // create a prolongation without clusters (check also if there are no clusters in the road)
       if (dead || 
-         ((layer.GetNextCluster(clidx,kTRUE))==0 && 
+         (noClusters && 
           AliITSReconstructor::GetRecoParam()->GetAllowProlongationWithEmptyRoad())) {
        AliITStrackMI * updatetrack = new (&tracks[ilayer][ntracks[ilayer]]) AliITStrackMI(*currenttrack);
        updatetrack->SetClIndex(ilayer,0);
@@ -988,7 +1060,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
          modstatus = 5; // no cls in road
        } else if (dead==1) {
          modstatus = 7; // holes in z in SPD
-       } else if (dead==2) {
+       } else if (dead==2 || dead==3) {
          modstatus = 2; // dead from OCDB
        }
        updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
@@ -1022,18 +1094,26 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
        if (ntracks[ilayer]>95) break; //space for skipped clusters  
        Bool_t changedet =kFALSE;  
        if (cl->GetQ()==0 && deadzoneSPD==kTRUE) continue;
-       Int_t idet=cl->GetDetectorIndex();
+       Int_t idetc=cl->GetDetectorIndex();
 
-       if (currenttrack->GetDetectorIndex()==idet) { // track already on the cluster's detector
+       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.);
          // 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. ) 
-           continue; // cluster not associated to track
+           {  // cluster not associated to track
+             //printf("not ass\n");
+             continue;
+           }
+         // bring track back to ideal detector plane
+         currenttrack->PropagateTo(xTrOrig,0.,0.);
        } else {                                      // have to move track to cluster's detector
-         const AliITSdetector &det=layer.GetDetector(idet);
+         const AliITSdetector &detc=layer.GetDetector(idetc);
          // a first cut on track-cluster distance
-         Double_t y,z;
-         if (!currenttrack2.GetProlongationFast(det.GetPhi(),det.GetR(),y,z)) continue;
+         Double_t y;
+         if (!currenttrack2.GetProlongationFast(detc.GetPhi(),detc.GetR()+cl->GetX(),y,z)) continue;
          if ( (z-cl->GetZ())*(z-cl->GetZ())*msz + 
               (y-cl->GetY())*(y-cl->GetY())*msy > 1. ) 
            continue; // cluster not associated to track
@@ -1041,12 +1121,12 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
          new (&backuptrack) AliITStrackMI(currenttrack2);
          changedet = kTRUE;
          currenttrack =&currenttrack2;
-         if (!currenttrack->Propagate(det.GetPhi(),det.GetR())) {
+         if (!currenttrack->Propagate(detc.GetPhi(),detc.GetR())) {
            new (currenttrack) AliITStrackMI(backuptrack);
            changedet = kFALSE;
            continue;
          }
-         currenttrack->SetDetectorIndex(idet);
+         currenttrack->SetDetectorIndex(idetc);
          // Get again the budget to the primary vertex 
          // for the current track being prolonged, if had to change detector 
          //budgetToPrimVertex = GetEffectiveThickness();// not needed at the moment because anyway we take a mean material for this correction
@@ -1055,6 +1135,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));
        if (chi2trkcl < AliITSReconstructor::GetRecoParam()->GetMaxChi2s(ilayer)) {
          if (cl->GetQ()==0) deadzoneSPD=kTRUE; // only 1 prolongation with virtual cluster       
          if (ntracks[ilayer]>=100) continue;
@@ -1063,7 +1144,10 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
          if (changedet) new (&currenttrack2) AliITStrackMI(backuptrack);
 
          if (cl->GetQ()!=0) { // real cluster
-           if (!UpdateMI(updatetrack,cl,chi2trkcl,(ilayer<<28)+clidx)) continue; 
+           if (!UpdateMI(updatetrack,cl,chi2trkcl,(ilayer<<28)+clidx)) {
+             //printf("update failed\n");
+             continue;
+           } 
            updatetrack->SetSampledEdx(cl->GetQ(),updatetrack->GetNumberOfClusters()-1); //b.b.
            modstatus = 1; // found
          } else {             // virtual cluster in dead zone
@@ -1098,6 +1182,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
          } //apply vertex constrain              
          ntracks[ilayer]++;
        }  // create new hypothesis
+       //else printf("chi2 too large\n");
       } // loop over possible prolongations 
      
       // allow one prolongation without clusters
@@ -1385,7 +1470,7 @@ AliITStrackerMI::AliITSlayer::~AliITSlayer() {
   //--------------------------------------------------------------------
   // AliITSlayer destructor
   //--------------------------------------------------------------------
-  delete[] fDetectors;
+  delete [] fDetectors;
   for (Int_t i=0; i<fN; i++) delete fClusters[i];
   for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
     fClusterWeight[i]=0;
@@ -1592,6 +1677,58 @@ Int_t AliITStrackerMI::AliITSlayer::FindClusterIndex(Float_t z) const {
   return m;
 }
 //------------------------------------------------------------------------
+Bool_t AliITStrackerMI::ComputeRoad(AliITStrackMI* track,Int_t ilayer,Int_t idet,Double_t &zmin,Double_t &zmax,Double_t &ymin,Double_t &ymax) const {
+  //--------------------------------------------------------------------
+  // This function computes the rectangular road for this track
+  //--------------------------------------------------------------------
+
+
+  AliITSdetector &det = fgLayers[ilayer].GetDetector(idet);
+  // take into account the misalignment: propagate track to misaligned detector plane
+  if (!track->Propagate(det.GetPhi(),det.GetRmisal())) return kFALSE;
+
+  Double_t dz=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadZ()*
+                    TMath::Sqrt(track->GetSigmaZ2() + 
+                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+                   AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer));
+  Double_t dy=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadY()*
+                    TMath::Sqrt(track->GetSigmaY2() + 
+                   AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+                   AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+                   AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer));
+      
+  // track at boundary between detectors, enlarge road
+  Double_t boundaryWidth=AliITSRecoParam::GetBoundaryWidth();
+  if ( (track->GetY()-dy < det.GetYmin()+boundaryWidth) || 
+       (track->GetY()+dy > det.GetYmax()-boundaryWidth) || 
+       (track->GetZ()-dz < det.GetZmin()+boundaryWidth) ||
+       (track->GetZ()+dz > det.GetZmax()-boundaryWidth) ) {
+    Float_t tgl = TMath::Abs(track->GetTgl());
+    if (tgl > 1.) tgl=1.;
+    Double_t deltaXNeighbDets=AliITSRecoParam::GetDeltaXNeighbDets();
+    dz = TMath::Sqrt(dz*dz+deltaXNeighbDets*deltaXNeighbDets*tgl*tgl);
+    Float_t snp = TMath::Abs(track->GetSnp());
+    if (snp > AliITSReconstructor::GetRecoParam()->GetMaxSnp()) return kFALSE;
+    dy = TMath::Sqrt(dy*dy+deltaXNeighbDets*deltaXNeighbDets*snp*snp);
+  } // boundary
+  
+  // add to the road a term (up to 2-3 mm) to deal with misalignments
+  dy = TMath::Sqrt(dy*dy + AliITSReconstructor::GetRecoParam()->GetRoadMisal()*AliITSReconstructor::GetRecoParam()->GetRoadMisal());
+  dz = TMath::Sqrt(dz*dz + AliITSReconstructor::GetRecoParam()->GetRoadMisal()*AliITSReconstructor::GetRecoParam()->GetRoadMisal());
+
+  Double_t r = fgLayers[ilayer].GetR();
+  zmin = track->GetZ() - dz; 
+  zmax = track->GetZ() + dz;
+  ymin = track->GetY() + r*det.GetPhi() - dy;
+  ymax = track->GetY() + r*det.GetPhi() + dy;
+
+  // bring track back to idead detector plane
+  if (!track->Propagate(det.GetPhi(),det.GetR())) return kFALSE;
+
+  return kTRUE;
+}
+//------------------------------------------------------------------------
 void AliITStrackerMI::AliITSlayer::
 SelectClusters(Double_t zmin,Double_t zmax,Double_t ymin, Double_t ymax) {
   //--------------------------------------------------------------------
@@ -1697,6 +1834,17 @@ FindDetectorIndex(Double_t phi, Double_t z) const {
   if (nz>=fNdetectors) return -1;
   if (nz<0)            return -1;
 
+  // ad hoc correction for 3rd ladder of SDD inner layer,
+  // which is reversed (rotated by pi around local y)
+  // this correction is OK only from AliITSv11Hybrid onwards
+  if (GetR()>12. && GetR()<20.) { // SDD inner
+    if(np==2) { // 3rd ladder
+      nz = (fNdetectors-1) - nz;
+    } 
+  }
+  //printf("ndet %d phi %f z %f  np %d nz %d\n",fNdetectors,phi,z,np,nz);
+
+
   return np*fNdetectors + nz;
 }
 //------------------------------------------------------------------------
@@ -1830,6 +1978,74 @@ const {
   return d;
 }
 //------------------------------------------------------------------------
+AliITStrackerMI::AliITSdetector::AliITSdetector(const AliITSdetector& det):
+fR(det.fR),
+fRmisal(det.fRmisal),
+fPhi(det.fPhi),
+fSinPhi(det.fSinPhi),
+fCosPhi(det.fCosPhi),
+fYmin(det.fYmin),
+fYmax(det.fYmax),
+fZmin(det.fZmin),
+fZmax(det.fZmax),
+fIsBad(det.fIsBad),
+fNChips(det.fNChips),
+fChipIsBad(det.fChipIsBad)
+{
+  //Copy constructor
+}
+//------------------------------------------------------------------------
+void AliITStrackerMI::AliITSdetector::ReadBadDetectorAndChips(Int_t ilayer,Int_t idet,
+                                                AliITSDetTypeRec *detTypeRec)
+{
+  //--------------------------------------------------------------------
+  // Read bad detectors and chips from calibration objects in AliITSDetTypeRec
+  //--------------------------------------------------------------------
+
+  // In AliITSDetTypeRec, detector numbers go from 0 to 2197
+  // while in the tracker they start from 0 for each layer
+  for(Int_t il=0; il<ilayer; il++) 
+    idet += AliITSgeomTGeo::GetNLadders(il+1)*AliITSgeomTGeo::GetNDetectors(il+1);
+
+  Int_t detType;
+  if (ilayer==0 || ilayer==1) {        // ----------  SPD
+    detType = 0;
+  } else if (ilayer==2 || ilayer==3) { // ----------  SDD
+    detType = 1;
+  } else if (ilayer==4 || ilayer==5) { // ----------  SSD
+    detType = 2;
+  } else {
+    printf("AliITStrackerMI::AliITSdetector::InitBadFromOCDB: Wrong layer number %d\n",ilayer);
+    return;
+  }
+
+  // Get calibration from AliITSDetTypeRec
+  AliITSCalibration *calib = (AliITSCalibration*)detTypeRec->GetCalibrationModel(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);
+    }
+
+  // Get segmentation from AliITSDetTypeRec
+  AliITSsegmentation *segm = (AliITSsegmentation*)detTypeRec->GetSegmentationModel(detType);
+
+  // Read info about bad chips
+  fNChips = segm->GetMaximumChipIndex()+1;
+  //printf("ilayer %d  detType %d idet %d fNChips %d %d  GetNumberOfChips %d\n",ilayer,detType,idet,fNChips,segm->GetMaximumChipIndex(),segm->GetNumberOfChips());
+  if(fChipIsBad) { delete [] fChipIsBad; fChipIsBad=NULL; }
+  fChipIsBad = new Bool_t[fNChips];
+  for (Int_t iCh=0;iCh<fNChips;iCh++) {
+    fChipIsBad[iCh] = calib->IsChipBad(iCh);
+    if (detType==0 && calibSPDdead->IsChipBad(iCh)) fChipIsBad[iCh] = kTRUE; // TEMPORARY
+  }
+
+  return;
+}
+//------------------------------------------------------------------------
 Double_t AliITStrackerMI::GetEffectiveThickness()
 {
   //--------------------------------------------------------------------
@@ -1890,13 +2106,15 @@ Int_t AliITStrackerMI::AliITSlayer::InRoad() const {
 }
 //------------------------------------------------------------------------
 Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
-                               const AliITStrackMI *clusters,Bool_t extra) 
+                               const AliITStrackMI *clusters,Bool_t extra, Bool_t planeeff
 {
   //--------------------------------------------------------------------
   // This function refits the track "track" at the position "x" using
   // the clusters from "clusters"
   // If "extra"==kTRUE, 
   //    the clusters from overlapped modules get attached to "track" 
+  // If "planeff"==kTRUE,
+  //    special approach for plane efficiency evaluation is applyed
   //--------------------------------------------------------------------
 
   Int_t index[AliITSgeomTGeo::kNLayers];
@@ -1909,17 +2127,19 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
     index[ilayer]=idx; 
   }
 
-  return RefitAt(xx,track,index,extra); // call the method below
+  return RefitAt(xx,track,index,extra,planeeff); // call the method below
 }
 //------------------------------------------------------------------------
 Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
-                               const Int_t *clusters,Bool_t extra) 
+                               const Int_t *clusters,Bool_t extra, Bool_t planeeff
 {
   //--------------------------------------------------------------------
   // This function refits the track "track" at the position "x" using
   // the clusters from array
   // If "extra"==kTRUE, 
   //    the clusters from overlapped modules get attached to "track" 
+  // If "planeff"==kTRUE,
+  //    special approach for plane efficiency evaluation is applyed
   //--------------------------------------------------------------------
   Int_t index[AliITSgeomTGeo::kNLayers];
   Int_t k;
@@ -2002,12 +2222,12 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      if (idet<0) return kFALSE;
 
      const AliITSdetector &det=layer.GetDetector(idet);
-     phi=det.GetPhi();
-     if (!track->Propagate(phi,det.GetR())) return kFALSE;
+     if (!track->Propagate(det.GetPhi(),det.GetR())) return kFALSE;
+
      track->SetDetectorIndex(idet);
      LocalModuleCoord(ilayer,idet,track,xloc,zloc); // local module coords
 
-     Double_t dz,zmin,zmax;
+     Double_t dz,zmin,zmax,dy,ymin,ymax;
 
      const AliITSRecPoint *clAcc=0;
      Double_t maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2();
@@ -2019,12 +2239,11 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
        if (cl) {
         if (idet != cl->GetDetectorIndex()) {
           idet=cl->GetDetectorIndex();
-          const AliITSdetector &det=layer.GetDetector(idet);
-          if (!track->Propagate(det.GetPhi(),det.GetR())) return kFALSE;
+          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
         }
-        //Double_t chi2=track->GetPredictedChi2(cl);
         Int_t cllayer = (idx & 0xf0000000) >> 28;;
         Double_t chi2=GetPredictedChi2MI(track,cl,cllayer);
         if (chi2<maxchi2) { 
@@ -2032,25 +2251,26 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
           maxchi2=chi2; 
           modstatus = 1; // found
         } else {
-          return kFALSE;
+           return kFALSE; //
         }
        }
      } else { // no cluster in this layer
        if (skip==1) {
         modstatus = 3; // skipped
+         // 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
         // check dead
-        dz=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadZ()*
-                    TMath::Sqrt(track->GetSigmaZ2() + 
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
-                   AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer));
-        zmin=track->GetZ() - dz;
-        zmax=track->GetZ() + dz;
-        Int_t dead = CheckDeadZone(ilayer,idet,zmin,zmax);
+        if (!ComputeRoad(track,ilayer,idet,zmin,zmax,ymin,ymax)) return kFALSE;
+        dz = 0.5*(zmax-zmin);
+        dy = 0.5*(ymax-ymin);
+        Int_t dead = CheckDeadZone(track,ilayer,idet,dz,dy,kTRUE);
         if (dead==1) modstatus = 7; // holes in z in SPD
-        if (dead==2) modstatus = 2; // dead from OCDB
+        if (dead==2 || dead==3) modstatus = 2; // dead from OCDB
        }
      }
      
@@ -2063,31 +2283,24 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
 
      if (extra) { // search for extra clusters in overlapped modules
        AliITStrackV2 tmp(*track);
-       Double_t dy,ymin,ymax;
-       dz=4*TMath::Sqrt(tmp.GetSigmaZ2()+AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer));
-       if (dz < 0.5*TMath::Abs(tmp.GetTgl())) dz=0.5*TMath::Abs(tmp.GetTgl());
-       dy=4*TMath::Sqrt(track->GetSigmaY2()+AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer));
-       if (dy < 0.5*TMath::Abs(tmp.GetSnp())) dy=0.5*TMath::Abs(tmp.GetSnp());
-       zmin=track->GetZ() - dz;
-       zmax=track->GetZ() + dz;
-       ymin=track->GetY() + phi*r - dy;
-       ymax=track->GetY() + phi*r + dy;
+       if (!ComputeRoad(track,ilayer,idet,zmin,zmax,ymin,ymax)) return kFALSE;
        layer.SelectClusters(zmin,zmax,ymin,ymax);
        
        const AliITSRecPoint *clExtra=0; Int_t ci=-1,cci=-1;
        Int_t idetExtra=-1;  
-       Double_t maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2(), tolerance=0.1;
+       maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2();
+       Double_t tolerance=0.1;
        while ((clExtra=layer.GetNextCluster(ci))!=0) {
         // only clusters in another module! (overlaps)
         idetExtra = clExtra->GetDetectorIndex();
         if (idet == idetExtra) continue;
         
-        const AliITSdetector &det=layer.GetDetector(idetExtra);
-        
-        if (!tmp.Propagate(det.GetPhi(),det.GetR())) continue;
+        const AliITSdetector &detx=layer.GetDetector(idetExtra);
         
+        if (!tmp.Propagate(detx.GetPhi(),detx.GetR()+clExtra->GetX())) continue;
         if (TMath::Abs(tmp.GetZ() - clExtra->GetZ()) > tolerance) continue;
         if (TMath::Abs(tmp.GetY() - clExtra->GetY()) > tolerance) continue;
+        if (!tmp.Propagate(detx.GetPhi(),detx.GetR())) continue;
         
         Double_t chi2=tmp.GetPredictedChi2(clExtra);
         if (chi2<maxchi2) { maxchi2=chi2; cci=ci; }
@@ -2500,13 +2713,13 @@ Int_t AliITStrackerMI::GetOverlapTrack(AliITStrackMI *track, Int_t trackID, Int_
     if (trackindex==2) sharedtrack =TMath::Min(tracks[0],tracks[1]);
     else{
       //
-      Int_t track[24], cluster[24];
-      for (Int_t i=0;i<trackindex;i++){ track[i]=-1; cluster[i]=0;}
+      Int_t tracks2[24], cluster[24];
+      for (Int_t i=0;i<trackindex;i++){ tracks2[i]=-1; cluster[i]=0;}
       Int_t index =0;
       //
       for (Int_t i=0;i<trackindex;i++){
        if (tracks[i]<0) continue;
-       track[index] = tracks[i];
+       tracks2[index] = tracks[i];
        cluster[index]++;       
        for (Int_t j=i+1;j<trackindex;j++){
          if (tracks[j]<0) continue;
@@ -2520,7 +2733,7 @@ Int_t AliITStrackerMI::GetOverlapTrack(AliITStrackMI *track, Int_t trackID, Int_
       Int_t max=0;
       for (Int_t i=0;i<index;i++){
        if (cluster[index]>max) {
-         sharedtrack=track[index];
+         sharedtrack=tracks2[index];
          max=cluster[index];
        }
       }
@@ -2667,8 +2880,6 @@ AliITStrackMI *  AliITStrackerMI::GetBest2Tracks(Int_t trackID1, Int_t trackID2,
       //if (track2->fFakeRatio>0) continue;
       Float_t nskipped=0;            
       RegisterClusterTracks(track2,trackID2);
-      Int_t list1[6],list2[6];
-      AliITSRecPoint *clist1[6], *clist2[6] ;
       Float_t cconflict1 = GetNumberOfSharedClusters(track1,trackID1,list1,clist1);
       Float_t cconflict2 = GetNumberOfSharedClusters(track2,trackID2,list2,clist2);
       UnRegisterClusterTracks(track2,trackID2);
@@ -2724,7 +2935,7 @@ AliITStrackMI *  AliITStrackerMI::GetBest2Tracks(Int_t trackID1, Int_t trackID2,
          }       
        }
        //
-       Double_t chi21=0,chi22=0;
+       chi21=0;chi22=0;
        if (TMath::Abs(track1->GetDy(i))>0.) {
          chi21 = (track1->GetDy(i)/track1->GetSigmaY(i))*(track1->GetDy(i)/track1->GetSigmaY(i))+
            (track1->GetDz(i)/track1->GetSigmaZ(i))*(track1->GetDz(i)/track1->GetSigmaZ(i));
@@ -2827,7 +3038,8 @@ void AliITStrackerMI::AddTrackHypothesys(AliITStrackMI * track, Int_t esdindex)
   // add track to the list of hypothesys
   //------------------------------------------------------------------
 
-  if (esdindex>=fTrackHypothesys.GetEntriesFast()) fTrackHypothesys.Expand(esdindex*2+10);
+  if (esdindex>=fTrackHypothesys.GetEntriesFast()) 
+    fTrackHypothesys.Expand(TMath::Max(fTrackHypothesys.GetSize(),esdindex*2+10));
   //
   TObjArray * array = (TObjArray*) fTrackHypothesys.At(esdindex);
   if (!array) {
@@ -2884,12 +3096,12 @@ void AliITStrackerMI::SortTrackHypothesys(Int_t esdindex, Int_t maxcut, Int_t mo
   //take errors of best track as a reference
   Float_t *erry = GetErrY(esdindex), *errz = GetErrZ(esdindex);
   Float_t *ny = GetNy(esdindex), *nz = GetNz(esdindex);
-  for (Int_t i=0;i<6;i++) {
-    if (besttrack->GetClIndex(i)>0){
-      erry[i] = besttrack->GetSigmaY(i); erry[i+6] = besttrack->GetSigmaY(i+6);
-      errz[i] = besttrack->GetSigmaZ(i); errz[i+6] = besttrack->GetSigmaZ(i+6);
-      ny[i]   = besttrack->GetNy(i);
-      nz[i]   = besttrack->GetNz(i);
+  for (Int_t j=0;j<6;j++) {
+    if (besttrack->GetClIndex(j)>0){
+      erry[j] = besttrack->GetSigmaY(j); erry[j+6] = besttrack->GetSigmaY(j+6);
+      errz[j] = besttrack->GetSigmaZ(j); errz[j+6] = besttrack->GetSigmaZ(j+6);
+      ny[j]   = besttrack->GetNy(j);
+      nz[j]   = besttrack->GetNz(j);
     }
   }
   //
@@ -2915,12 +3127,12 @@ void AliITStrackerMI::SortTrackHypothesys(Int_t esdindex, Int_t maxcut, Int_t mo
   TMath::Sort(entries,chi2,index,kFALSE);
   besttrack = (AliITStrackMI*)array->At(index[0]);
   if (besttrack&&besttrack->GetChi2MIP(0)<AliITSReconstructor::GetRecoParam()->GetMaxChi2PerCluster(0)){
-    for (Int_t i=0;i<6;i++){
-      if (besttrack->GetClIndex(i)>0){
-       erry[i] = besttrack->GetSigmaY(i); erry[i+6] = besttrack->GetSigmaY(i+6);
-       errz[i] = besttrack->GetSigmaZ(i); erry[i+6] = besttrack->GetSigmaY(i+6);
-       ny[i]   = besttrack->GetNy(i);
-       nz[i]   = besttrack->GetNz(i);
+    for (Int_t j=0;j<6;j++){
+      if (besttrack->GetClIndex(j)>0){
+       erry[j] = besttrack->GetSigmaY(j); erry[j+6] = besttrack->GetSigmaY(j+6);
+       errz[j] = besttrack->GetSigmaZ(j); erry[j+6] = besttrack->GetSigmaY(j+6);
+       ny[j]   = besttrack->GetNy(j);
+       nz[j]   = besttrack->GetNz(j);
       }
     }
   }
@@ -2950,16 +3162,16 @@ void AliITStrackerMI::SortTrackHypothesys(Int_t esdindex, Int_t maxcut, Int_t mo
     besttrack = (AliITStrackMI*)array->At(index[0]);
     if (besttrack){
       //
-      for (Int_t i=0;i<6;i++){
-       if (besttrack->GetNz(i)>0&&besttrack->GetNy(i)>0){
-         erry[i] = besttrack->GetSigmaY(i); erry[i+6] = besttrack->GetSigmaY(i+6);
-         errz[i] = besttrack->GetSigmaZ(i); errz[i+6] = besttrack->GetSigmaZ(i+6);
-         ny[i]   = besttrack->GetNy(i);
-         nz[i]   = besttrack->GetNz(i);
+      for (Int_t j=0;j<6;j++){
+       if (besttrack->GetNz(j)>0&&besttrack->GetNy(j)>0){
+         erry[j] = besttrack->GetSigmaY(j); erry[j+6] = besttrack->GetSigmaY(j+6);
+         errz[j] = besttrack->GetSigmaZ(j); errz[j+6] = besttrack->GetSigmaZ(j+6);
+         ny[j]   = besttrack->GetNy(j);
+         nz[j]   = besttrack->GetNz(j);
        }
       }
       besttrack->SetChi2MIP(0,GetNormalizedChi2(besttrack,mode));
-      Float_t minchi2 = TMath::Min(besttrack->GetChi2MIP(0)+5.+besttrack->GetNUsed(), double(AliITSReconstructor::GetRecoParam()->GetMaxChi2PerCluster(0)));
+      minchi2 = TMath::Min(besttrack->GetChi2MIP(0)+5.+besttrack->GetNUsed(), double(AliITSReconstructor::GetRecoParam()->GetMaxChi2PerCluster(0)));
       Float_t minn = besttrack->GetNumberOfClusters()-3;
       Int_t accepted=0;
       for (Int_t i=0;i<entries;i++){
@@ -2978,12 +3190,12 @@ void AliITStrackerMI::SortTrackHypothesys(Int_t esdindex, Int_t maxcut, Int_t mo
          if (!shortbest) accepted++;
          //
          newarray->AddLast(array->RemoveAt(index[i]));      
-         for (Int_t i=0;i<6;i++){
-           if (nz[i]==0){
-             erry[i] = track->GetSigmaY(i); erry[i+6] = track->GetSigmaY(i+6);
-             errz[i] = track->GetSigmaZ(i); errz[i]   = track->GetSigmaZ(i+6);
-             ny[i]   = track->GetNy(i);
-             nz[i]   = track->GetNz(i);
+         for (Int_t j=0;j<6;j++){
+           if (nz[j]==0){
+             erry[j] = track->GetSigmaY(j); erry[j+6] = track->GetSigmaY(j+6);
+             errz[j] = track->GetSigmaZ(j); errz[j]   = track->GetSigmaZ(j+6);
+             ny[j]   = track->GetNy(j);
+             nz[j]   = track->GetNz(j);
            }
          }
        }
@@ -3108,7 +3320,8 @@ AliITStrackMI * AliITStrackerMI::GetBestHypothesys(Int_t esdindex, AliITStrackMI
   delete forwardtrack;
   Int_t accepted=0;
   for (Int_t i=0;i<entries;i++){    
-    AliITStrackMI * track = (AliITStrackMI*)array->At(i);   
+    AliITStrackMI * track = (AliITStrackMI*)array->At(i);
+   
     if (!track) continue;
     
     if (accepted>checkmax || track->GetChi2MIP(3)>AliITSReconstructor::GetRecoParam()->GetMaxChi2PerCluster(3)*6. || 
@@ -3126,6 +3339,7 @@ AliITStrackMI * AliITStrackerMI::GetBestHypothesys(Int_t esdindex, AliITStrackMI
   //
   array->Compress();
   SortTrackHypothesys(esdindex,checkmax,1);
+
   array = (TObjArray*) fTrackHypothesys.At(esdindex);
   if (!array) return 0; // PH What can be the reason? Check SortTrackHypothesys
   besttrack = (AliITStrackMI*)array->At(0);  
@@ -3235,23 +3449,23 @@ void  AliITStrackerMI::GetBestHypothesysMIP(TObjArray &itsTracks)
     Float_t minn=0;
     Float_t maxchi2=1000;
     for (Int_t j=0;j<array->GetEntriesFast();j++){
-      AliITStrackMI* track = (AliITStrackMI*)array->At(j);
-      if (!track) continue;
-      if (track->GetGoldV0()) {
-       longtrack = track;   //gold V0 track taken
+      AliITStrackMI* trackHyp = (AliITStrackMI*)array->At(j);
+      if (!trackHyp) continue;
+      if (trackHyp->GetGoldV0()) {
+       longtrack = trackHyp;   //gold V0 track taken
        break;
       }
-      if (track->GetNumberOfClusters()+track->GetNDeadZone()<minn) continue;
-      Float_t chi2 = track->GetChi2MIP(0);
+      if (trackHyp->GetNumberOfClusters()+trackHyp->GetNDeadZone()<minn) continue;
+      Float_t chi2 = trackHyp->GetChi2MIP(0);
       if (fAfterV0){
-       if (!track->GetGoldV0()&&track->GetConstrain()==kFALSE) chi2+=5;
+       if (!trackHyp->GetGoldV0()&&trackHyp->GetConstrain()==kFALSE) chi2+=5;
       }
-      if (track->GetNumberOfClusters()+track->GetNDeadZone()>minn) maxchi2 = track->GetChi2MIP(0);       
+      if (trackHyp->GetNumberOfClusters()+trackHyp->GetNDeadZone()>minn) maxchi2 = trackHyp->GetChi2MIP(0);       
       //
       if (chi2 > maxchi2) continue;
-      minn= track->GetNumberOfClusters()+track->GetNDeadZone();
+      minn= trackHyp->GetNumberOfClusters()+trackHyp->GetNDeadZone();
       maxchi2 = chi2;
-      longtrack=track;
+      longtrack=trackHyp;
     }    
     //
     //
@@ -3393,7 +3607,16 @@ 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());
+  // 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());
   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.;
   Float_t ny,nz;
   AliITSClusterParam::GetNTeor(layer,cluster,theta,phi,ny,nz);  
   Double_t delta = cluster->GetNy()+cluster->GetNz()-nz-ny;
@@ -3428,15 +3651,29 @@ Int_t AliITStrackerMI::UpdateMI(AliITStrackMI* track, const AliITSRecPoint* cl,D
 
   if (cl->GetQ()<=0) return 0;  // ingore the "virtual" clusters
 
+
+  // 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());
 
+  if (!track->PropagateTo(xTrOrig+cl->GetX(),0.,0.)) return 0;
 
-  // Take into account the mis-alignment
-  Double_t x=track->GetX()+cl->GetX();
-  if (!track->PropagateTo(x,0.,0.)) return 0;
   
-  return track->UpdateMI(cl->GetY(),cl->GetZ(),track->GetSigmaY(layer),track->GetSigmaZ(layer),chi2,index);
+  AliCluster c(*cl);
+  c.SetSigmaY2(track->GetSigmaY(layer)*track->GetSigmaY(layer));
+  c.SetSigmaZ2(track->GetSigmaZ(layer)*track->GetSigmaZ(layer));
+
+
+  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(!updated) printf("update failed\n");
+  return updated;
 }
+
 //------------------------------------------------------------------------
 void AliITStrackerMI::GetDCASigma(AliITStrackMI* track, Float_t & sigmarfi, Float_t &sigmaz)
 {
@@ -4162,7 +4399,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.);
        }
@@ -4381,8 +4618,8 @@ void AliITStrackerMI::BuildMaterialLUT(TString material) {
   Double_t point1[3],point2[3];
   Double_t phi,cosphi,sinphi,z;
   // 0-5 layers, 6 pipe, 7-8 shields 
-  Double_t rmin[9]={ 3.5, 5.5,13.0,22.0,35.0,41.0, 2.0, 7.5,25.0};
-  Double_t rmax[9]={ 5.5, 7.3,17.0,26.0,41.0,47.0, 3.0,10.5,30.0};
+  Double_t rmin[9]={ 3.5, 5.5,13.0,22.0,35.0,41.0, 2.0, 8.0,25.0};
+  Double_t rmax[9]={ 5.5, 8.0,17.0,26.0,41.0,47.0, 3.0,10.5,30.0};
 
   Int_t ifirst=0,ilast=0;  
   if(material.Contains("Pipe")) {
@@ -4481,7 +4718,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;
@@ -4575,7 +4813,8 @@ 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;
 
@@ -4665,7 +4904,8 @@ 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;
 
@@ -4797,15 +5037,17 @@ Int_t AliITStrackerMI::CheckSkipLayer(AliITStrackMI *track,
   return 0;
 }
 //------------------------------------------------------------------------
-Int_t AliITStrackerMI::CheckDeadZone(/*AliITStrackMI *track,*/
+Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
                                     Int_t ilayer,Int_t idet,
-                                    Double_t zmin,Double_t zmax/*,Double_t ymin,Double_t ymax*/) const {
+                                    Double_t dz,Double_t dy,
+                                    Bool_t noClusters) const {
   //-----------------------------------------------------------------
   // This method is used to decide whether to allow a prolongation 
   // without clusters, because there is a dead zone in the road.
   // In this case the return value is > 0:
   // return 1: dead zone at z=0,+-7cm in SPD
-  // return 2: dead area from the OCDB // NOT YET IMPLEMENTED
+  // return 2: all road is "bad" (dead or noisy) from the OCDB
+  // return 3: something "bad" (dead or noisy) from the OCDB
   //-----------------------------------------------------------------
 
   // check dead zones at z=0,+-7cm in the SPD
@@ -4817,52 +5059,83 @@ 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 (zmin<zmaxdead[i] && zmax>zmindead[i]) return 1;  
+      if (track->GetZ()-dz<zmaxdead[i] && track->GetZ()+dz>zmindead[i]) return 1;  
   }
 
-  // check dead zones from OCDB
-  if (!AliITSReconstructor::GetRecoParam()->GetUseDeadZonesFromOCDB()) return 0;
+  // check bad zones from OCDB
+  if (!AliITSReconstructor::GetRecoParam()->GetUseBadZonesFromOCDB()) return 0;
 
-  if(idet<0) return 0;
+  if (idet<0) return 0;
 
-  // look in OCDB (only entire dead modules for the moment)
-  if (ilayer==0 || ilayer==1) { // SPD
-    AliCDBEntry* cdbEntry = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead");
-    if (!cdbEntry) {
-      Error("CheckDeadZone","Cannot get CDB entry for SPD\n");
-      return 0;
-    }
-    TObjArray* spdEntry = (TObjArray*)cdbEntry->GetObject();
-    if (!spdEntry) {
-      Error("CheckDeadZone","Cannot get CDB entry for SPD\n");
-      return 0;
-    }
-    if(ilayer==1) idet += AliITSgeomTGeo::GetNLadders(1)*AliITSgeomTGeo::GetNDetectors(1);
-    //printf("SPD det: %d\n",idet);
-    AliITSCalibrationSPD *calibSPD = (AliITSCalibrationSPD*)spdEntry->At(idet);
-    if (calibSPD->IsBad()) return 2;
-  } else if (ilayer==2 || ilayer==3) { // SDD
-    AliCDBEntry* cdbEntry = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD");
-    if (!cdbEntry) {
-      Error("CheckDeadZone","Cannot get CDB entry for SDD\n");
-      return 0;
-    }
-    TObjArray* sddEntry = (TObjArray*)cdbEntry->GetObject();
-    if (!sddEntry) {
-      Error("CheckDeadZone","Cannot get CDB entry for SDD\n");
-      return 0;
-    }
-    if(ilayer==3) idet += AliITSgeomTGeo::GetNLadders(3)*AliITSgeomTGeo::GetNDetectors(3);
-    //printf("SDD det: %d\n",idet);
-    AliITSCalibrationSDD *calibSDD = (AliITSCalibrationSDD*)sddEntry->At(idet);
-    if (calibSDD->IsDead()) return 2;
-  } else if (ilayer==4 || ilayer==5) { // SSD
-  } else {
-    Error("CheckDeadZone","Wrong layer number\n");
-    if(ilayer==5) idet += AliITSgeomTGeo::GetNLadders(5)*AliITSgeomTGeo::GetNDetectors(5);
-    return 0;
+  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
+    detType = 0;
+  } else if (ilayer==2 || ilayer==3) { // ----------  SDD
+    detType = 1;
+    detSizeFactorX *= 2.;
+  } else if (ilayer==4 || ilayer==5) { // ----------  SSD
+    detType = 2;
+  }
+  AliITSsegmentation *segm = (AliITSsegmentation*)fDetTypeRec->GetSegmentationModel(detType);
+  if (detType==2) segm->SetLayer(ilayer+1);
+  Float_t detSizeX = detSizeFactorX*segm->Dx(); 
+  Float_t detSizeZ = detSizeFactorZ*segm->Dz(); 
+
+  // check if the road overlaps with bad chips
+  Float_t xloc,zloc;
+  LocalModuleCoord(ilayer,idet,track,xloc,zloc);
+  Float_t zlocmin = zloc-dz;
+  Float_t zlocmax = zloc+dz;
+  Float_t xlocmin = xloc-dy;
+  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());
+  Int_t nChipsInRoad = segm->GetChipsInLocalWindow(chipsInRoad,zlocmin,zlocmax,xlocmin,xlocmax);
+  //printf("lay %d nChipsInRoad %d\n",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]));
+    if (det.IsChipBad(chipsInRoad[iCh])) {
+      anyBad=kTRUE;
+    } else {
+      anyGood=kTRUE;
+    } 
   }
 
+  if (!anyGood) return 2; // all chips in road are bad
+
+  if (anyBad) return 3; // at least a bad chip in road
+
+
+  if (!AliITSReconstructor::GetRecoParam()->GetUseSingleBadChannelsFromOCDB()
+      || ilayer==4 || ilayer==5     // SSD
+      || !noClusters) return 0;
+
+  // 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;
+
+  if (fITSChannelStatus->FractionOfBadInRoad(idet,zlocmin,zlocmax,xlocmin,xlocmax) > AliITSReconstructor::GetRecoParam()->GetMinFractionOfBadInRoad()) return 3;
+
   return 0;
 }
 //------------------------------------------------------------------------
@@ -4886,7 +5159,9 @@ Bool_t AliITStrackerMI::LocalModuleCoord(Int_t ilayer,Int_t idet,
 
   Double_t xyzGlob[3],xyzLoc[3];
 
-  track->GetXYZ(xyzGlob);
+  AliITSdetector &detector = fgLayers[ilayer].GetDetector(idet);
+  // take into account the misalignment: xyz at real detector plane
+  track->GetXYZAt(detector.GetRmisal(),GetBz(),xyzGlob);
 
   AliITSgeomTGeo::GlobalToLocal(ilayer+1,lad,det,xyzGlob,xyzLoc);
 
@@ -4896,3 +5171,265 @@ Bool_t AliITStrackerMI::LocalModuleCoord(Int_t ilayer,Int_t idet,
   return kTRUE;
 }
 //------------------------------------------------------------------------
+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
+//      the decision is taken based on the track quality at the layer under study
+//      no information on the clusters on this layer has to be used
+//      The criterium is to reject tracks at boundaries between basic block (e.g. SPD chip)
+//      the cut is done on number of sigmas from the boundaries
+//
+//  Input: Actual track, layer [0,5] under study
+//  Output: none
+//  Return: kTRUE if this is a good track
+//
+// it will apply a pre-selection to obtain good quality tracks.  
+// Here also  you will have the possibility to put a control on the 
+// impact point of the track on the basic block, in order to exclude border regions 
+// this will be done by calling a proper method of the AliITSPlaneEff class.  
+//
+// 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;
+  Int_t idet=layer.FindDetectorIndex(phi,z);
+  if(idet<0) { AliInfo(Form("cannot find detector"));
+    return kFALSE;}
+
+  // here check if it has good Chi Square.
+
+  //propagate to the intersection with the detector plane
+  const AliITSdetector &det=layer.GetDetector(idet);
+  if (!tmp.Propagate(det.GetPhi(),det.GetR())) return kFALSE;
+
+  Float_t locx; //
+  Float_t locz; //
+  if(!LocalModuleCoord(ilayer,idet,&tmp,locx,locz)) return kFALSE;
+  UInt_t key=fPlaneEff->GetKeyFromDetLocCoord(ilayer,idet,locx,locz);
+  if(key>fPlaneEff->Nblock()) return kFALSE;
+  Float_t blockXmn,blockXmx,blockZmn,blockZmx;
+  if (!fPlaneEff->GetBlockBoundaries(key,blockXmn,blockXmx,blockZmn,blockZmx)) return kFALSE;
+  //***************
+  // DEFINITION OF SEARCH ROAD FOR accepting a track
+  //
+  //For the time being they are hard-wired, later on from AliITSRecoParam
+  // Double_t nsigx=AliITSRecoParam::GetNSigXFarFromBoundary();
+  // Double_t nsigz=AliITSRecoParam::GetNSigZFarFromBoundary();
+  Double_t nsigz=4; 
+  Double_t nsigx=4; 
+  Double_t dx=nsigx*TMath::Sqrt(tmp.GetSigmaY2());  // those are precisions in the tracking reference system
+  Double_t dz=nsigz*TMath::Sqrt(tmp.GetSigmaZ2());  // Use it also for the module reference system, as it is
+                                                // done for RecPoints
+
+  // exclude tracks at boundary between detectors
+  //Double_t boundaryWidth=AliITSRecoParam::GetBoundaryWidthPlaneEff();
+  Double_t boundaryWidth=0; // for the time being hard-wired, later on from AliITSRecoParam
+  AliDebug(2,Form("Tracking: track impact x=%f, y=%f, z=%f",tmp.GetX(), tmp.GetY(), tmp.GetZ()));
+  AliDebug(2,Form("Local:    track impact x=%f, z=%f",locx,locz));
+  AliDebug(2,Form("Search Road. Tracking: dy=%f , dz=%f",dx,dz));
+
+  if ( (locx-dx < blockXmn+boundaryWidth) ||
+       (locx+dx > blockXmx-boundaryWidth) ||
+       (locz-dz < blockZmn+boundaryWidth) ||
+       (locz+dz > blockZmx-boundaryWidth) ) return kFALSE;
+  return kTRUE;
+}
+//------------------------------------------------------------------------
+void AliITStrackerMI::UseTrackForPlaneEff(AliITStrackMI* track, Int_t ilayer) {
+//
+// This Method has to be optimized! For the time-being it uses the same criteria
+// as those used in the search of extra clusters for overlapping modules.
+//
+// Method Purpose: estabilish whether a track has produced a recpoint or not
+//                 in the layer under study (For Plane efficiency)
+//
+// inputs: AliITStrackMI* track  (pointer to a usable track)
+// outputs: none
+// side effects: update (by 1 count) the Plane Efficiency statistics of the basic block
+//               traversed by this very track. In details:
+//               - if a cluster can be associated to the track then call
+//                  AliITSPlaneEff::UpDatePlaneEff(key,kTRUE);
+//               - if not, the AliITSPlaneEff::UpDatePlaneEff(key,kFALSE) is called
+//
+  if(!fPlaneEff)
+    {AliWarning("UseTrackForPlaneEff: null pointer to AliITSPlaneEff"); return;}
+  AliITSlayer &layer=fgLayers[ilayer];
+  Double_t r=layer.GetR();
+  AliITStrackMI tmp(*track);
+
+// detector number
+  Double_t phi,z;
+  if (!tmp.GetPhiZat(r,phi,z)) return;
+  Int_t idet=layer.FindDetectorIndex(phi,z);
+
+  if(idet<0) { AliInfo(Form("cannot find detector"));
+    return;}
+
+
+//propagate to the intersection with the detector plane
+  const AliITSdetector &det=layer.GetDetector(idet);
+  if (!tmp.Propagate(det.GetPhi(),det.GetR())) return;
+
+
+//***************
+// DEFINITION OF SEARCH ROAD FOR CLUSTERS SELECTION
+//
+  Double_t dz=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadZ()*
+                    TMath::Sqrt(tmp.GetSigmaZ2() +
+                    AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+                    AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+                    AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer));
+  Double_t dy=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadY()*
+                    TMath::Sqrt(tmp.GetSigmaY2() +
+                    AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+                    AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+                    AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer));
+
+// road in global (rphi,z) [i.e. in tracking ref. system]
+  Double_t zmin = tmp.GetZ() - dz;
+  Double_t zmax = tmp.GetZ() + dz;
+  Double_t ymin = tmp.GetY() + r*det.GetPhi() - dy;
+  Double_t ymax = tmp.GetY() + r*det.GetPhi() + dy;
+
+// select clusters in road
+  layer.SelectClusters(zmin,zmax,ymin,ymax);
+
+// Define criteria for track-cluster association
+  Double_t msz = tmp.GetSigmaZ2() +
+  AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+  AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+  AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer);
+  Double_t msy = tmp.GetSigmaY2() +
+  AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+  AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+  AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer);
+  if (tmp.GetConstrain()) {
+    msz *= AliITSReconstructor::GetRecoParam()->GetNSigma2RoadZC();
+    msy *= AliITSReconstructor::GetRecoParam()->GetNSigma2RoadYC();
+  }  else {
+    msz *= AliITSReconstructor::GetRecoParam()->GetNSigma2RoadZNonC();
+    msy *= AliITSReconstructor::GetRecoParam()->GetNSigma2RoadYNonC();
+  }
+  msz = 1./msz; // 1/RoadZ^2
+  msy = 1./msy; // 1/RoadY^2
+//
+
+  const AliITSRecPoint *cl=0; Int_t clidx=-1, ci=-1;
+  Int_t idetc=-1;
+  Double_t chi2trkcl=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2();
+  //Double_t  tolerance=0.2;
+  /*while ((cl=layer.GetNextCluster(clidx))!=0) {
+    idetc = cl->GetDetectorIndex();
+    if(idet!=idetc) continue;
+    //Int_t ilay = cl->GetLayer();
+
+    if (TMath::Abs(tmp.GetZ() - cl->GetZ()) > tolerance) continue;
+    if (TMath::Abs(tmp.GetY() - cl->GetY()) > tolerance) continue;
+
+    Double_t chi2=tmp.GetPredictedChi2(cl);
+    if (chi2<chi2trkcl) { chi2trkcl=chi2; ci=clidx; }
+  }*/
+  Float_t locx; //
+  Float_t locz; //
+  if(!LocalModuleCoord(ilayer,idet,&tmp,locx,locz)) return;
+//
+  AliDebug(2,Form("ilayer= %d, idet=%d, x= %f, z=%f",ilayer,idet,locx,locz));
+  UInt_t key=fPlaneEff->GetKeyFromDetLocCoord(ilayer,idet,locx,locz);
+  if(key>fPlaneEff->Nblock()) return;
+  Bool_t found=kFALSE;
+  //if (ci>=0) {
+  Double_t chi2;
+  while ((cl=layer.GetNextCluster(clidx))!=0) {
+    idetc = cl->GetDetectorIndex();
+    if(idet!=idetc) continue;
+    // here real control to see whether the cluster can be associated to the track.
+    // cluster not associated to track
+    if ( (tmp.GetZ()-cl->GetZ())*(tmp.GetZ()-cl->GetZ())*msz +
+         (tmp.GetY()-cl->GetY())*(tmp.GetY()-cl->GetY())*msy   > 1. ) continue;
+    // calculate track-clusters chi2
+    chi2 = GetPredictedChi2MI(&tmp,cl,ilayer); // note that this method change track tmp
+                                               // in particular, the error associated to the cluster 
+    //Double_t chi2 = tmp.GetPredictedChi(cl); // this method does not change track tmp
+    // chi2 cut
+    if (chi2 > AliITSReconstructor::GetRecoParam()->GetMaxChi2s(ilayer)) continue;
+    found=kTRUE;
+    if (chi2<chi2trkcl) { chi2trkcl=chi2; ci=clidx; } // this just to trace which cluster is selected
+   // track->SetExtraCluster(ilayer,(ilayer<<28)+ci);
+   // track->SetExtraModule(ilayer,idetExtra);
+  }
+  if(!fPlaneEff->UpDatePlaneEff(found,key))
+       AliWarning(Form("UseTrackForPlaneEff: cannot UpDate PlaneEff for key=%d",key));
+  if(fPlaneEff->GetCreateHistos()&&  AliITSReconstructor::GetRecoParam()->GetHistoPlaneEff()) {
+    Float_t tr[4]={99999.,99999.,9999.,9999.};    // initialize to high values 
+    Float_t clu[4]={-99999.,-99999.,9999.,9999.}; // (in some cases GetCov fails) 
+    Int_t cltype[2]={-999,-999};
+
+    tr[0]=locx;
+    tr[1]=locz;
+    tr[2]=TMath::Sqrt(tmp.GetSigmaY2());  // those are precisions in the tracking reference system
+    tr[3]=TMath::Sqrt(tmp.GetSigmaZ2());  // Use it also for the module reference system, as it is
+
+    if (found){
+      clu[0]=layer.GetCluster(ci)->GetDetLocalX();
+      clu[1]=layer.GetCluster(ci)->GetDetLocalZ();
+      cltype[0]=layer.GetCluster(ci)->GetNy();
+      cltype[1]=layer.GetCluster(ci)->GetNz();
+     
+     // Without the following 6 lines you would retrieve the nominal error of a cluster (e.g. for the SPD:
+     //  X->50/sqrt(12)=14 micron   Z->450/sqrt(12)= 120 micron) 
+     // Within AliTrackerMI/AliTrackMI the error on the cluster is associated to the AliITStrackMI (fSigmaY,Z)
+     // It is computed properly by calling the method 
+     // AliITStrackerMI::GetPredictedChi2MI(AliITStrackMI* track, const AliITSRecPoint *cluster,Int_t layer)
+     // T
+     //Double_t x=0.5*(tmp.GetX()+layer.GetCluster(ci)->GetX()); // Take into account the mis-alignment
+      //if (tmp.PropagateTo(x,0.,0.)) {
+        chi2=GetPredictedChi2MI(&tmp,layer.GetCluster(ci),ilayer);
+        AliCluster c(*layer.GetCluster(ci));
+        c.SetSigmaY2(tmp.GetSigmaY(ilayer)*tmp.GetSigmaY(ilayer));
+        c.SetSigmaZ2(tmp.GetSigmaZ(ilayer)*tmp.GetSigmaZ(ilayer));
+        //if (layer.GetCluster(ci)->GetGlobalCov(cov))  // by using this, instead, you got nominal cluster errors
+        clu[2]=TMath::Sqrt(c.GetSigmaY2());
+        clu[3]=TMath::Sqrt(c.GetSigmaZ2());
+      //}
+    }
+    fPlaneEff->FillHistos(key,found,tr,clu,cltype);
+  }
+return;
+}