]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITStrackerMI.cxx
Fixes for Coverity warnings
[u/mrichter/AliRoot.git] / ITS / AliITStrackerMI.cxx
index 47fc3f1b87a444566c7df594f4f2927fd1b45738..b81eccd8a15b2c4a197f271267de51d80fec92ea 100644 (file)
@@ -32,6 +32,7 @@
 #include <TString.h>
 #include <TRandom.h>
 #include <TTreeStream.h>
+#include <TVector3.h>
 
 #include "AliLog.h"
 #include "AliGeomManager.h"
@@ -91,9 +92,16 @@ fPlaneEff(0) {
   //Default constructor
   Int_t i;
   for(i=0;i<4;i++) fSPDdetzcentre[i]=0.;
-  for(i=0;i<2;i++) {fxOverX0Shield[i]=-1.;fxTimesRhoShield[i]=-1.;}
+  for(i=0;i<2;i++) {
+    fxOverX0Shield[i]=-1.;
+    fxTimesRhoShield[i]=-1.;
+    fConstraint[i]=0;
+  }
   for(i=0;i<6;i++) {fxOverX0Layer[i]=-1.;fxTimesRhoLayer[i]=-1.;}
   fOriginal.SetOwner();
+  for(i=0;i<AliITSgeomTGeo::kNLayers;i++)fForceSkippingOfLayer[i]=0;
+  for(i=0;i<100000;i++)fBestTrackIndex[i]=0;
+
 }
 //------------------------------------------------------------------------
 AliITStrackerMI::AliITStrackerMI(const Char_t *geom) : AliTracker(),
@@ -183,7 +191,7 @@ fPlaneEff(0) {
        
       } // end loop on detectors
     } // end loop on ladders
-    fForceSkippingOfLayer[i] = 0;
+    fForceSkippingOfLayer[i-1] = 0;
   } // end loop on layers
 
 
@@ -255,6 +263,7 @@ fPlaneEff(0) {
     if(AliITSReconstructor::GetRecoParam()->GetHistoPlaneEff()) fPlaneEff->SetCreateHistos(kTRUE);
   }
 }
+/*
 //------------------------------------------------------------------------
 AliITStrackerMI::AliITStrackerMI(const AliITStrackerMI &tracker):AliTracker(tracker),
 fI(tracker.fI),
@@ -299,6 +308,7 @@ fPlaneEff(tracker.fPlaneEff) {
     fxTimesRhoShield[i]=tracker.fxTimesRhoShield[i];
   }
 }
+
 //------------------------------------------------------------------------
 AliITStrackerMI & AliITStrackerMI::operator=(const AliITStrackerMI &tracker){
   //Assignment operator
@@ -306,6 +316,7 @@ AliITStrackerMI & AliITStrackerMI::operator=(const AliITStrackerMI &tracker){
   new(this) AliITStrackerMI(tracker);
   return *this;
 }
+*/
 //------------------------------------------------------------------------
 AliITStrackerMI::~AliITStrackerMI()
 {
@@ -350,7 +361,7 @@ void AliITStrackerMI::ReadBadFromDetTypeRec() {
        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)));
+    AliInfo(Form("Layer %d: %d bad out of %d",i-1,nBadDetsPerLayer,ndet*AliITSgeomTGeo::GetNLadders(i)));
   } // end loop on layers
   
   return;
@@ -364,6 +375,8 @@ Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
   TClonesArray *clusters = NULL;
   AliITSRecPointContainer* rpcont=AliITSRecPointContainer::Instance();
   clusters=rpcont->FetchClusters(0,cTree);
+  if(!clusters) return 1;
+
   if(!(rpcont->IsSPDActive() || rpcont->IsSDDActive() || rpcont->IsSSDActive())){
       AliError("ITS is not in a known running configuration: SPD, SDD and SSD are not active");
       return 1;
@@ -401,11 +414,12 @@ Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
          Int_t lab[4]   = {0,0,0,detector};
          Int_t info[3]  = {0,0,i};
          Float_t q      = 0.; // this identifies virtual clusters
-         Float_t hit[5] = {xdead,
+         Float_t hit[6] = {xdead,
                            0.,
                            AliITSReconstructor::GetRecoParam()->GetSigmaXDeadZoneHit2(),
                            AliITSReconstructor::GetRecoParam()->GetSigmaZDeadZoneHit2(),
-                           q};
+                           q,
+                           0.};
          Bool_t local   = kTRUE;
          Double_t zwindow = AliITSReconstructor::GetRecoParam()->GetZWindowDeadZone();
          hit[1] = fSPDdetzcentre[0]+0.5*AliITSRecoParam::GetSPDdetzlength();
@@ -525,14 +539,7 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
       if (esd->GetStatus()&AliESDtrack::kTPCout) continue;
       if (esd->GetStatus()&AliESDtrack::kITSin) continue;
       if (esd->GetKinkIndex(0)>0) continue;   //kink daughter
-      AliITStrackMI *t=0;
-      try {
-        t=new AliITStrackMI(*esd);
-      } catch (const Char_t *msg) {
-        //Warning("Clusters2Tracks",msg);
-        delete t;
-        continue;
-      }
+      AliITStrackMI *t = new AliITStrackMI(*esd);
       t->GetDZ(GetX(),GetY(),GetZ(),t->GetDP());              //I.B.
       Double_t vdist = TMath::Sqrt(t->GetD(0)*t->GetD(0)+t->GetD(1)*t->GetD(1));
 
@@ -668,14 +675,8 @@ Int_t AliITStrackerMI::PropagateBack(AliESDEvent *event) {
      if ((esd->GetStatus()&AliESDtrack::kITSin)==0) continue;
      if (esd->GetStatus()&AliESDtrack::kITSout) continue;
 
-     AliITStrackMI *t=0;
-     try {
-        t=new AliITStrackMI(*esd);
-     } catch (const Char_t *msg) {
-       //Warning("PropagateBack",msg);
-        delete t;
-        continue;
-     }
+     AliITStrackMI *t = new AliITStrackMI(*esd);
+
      t->SetExpQ(TMath::Max(0.8*t->GetESDtrack()->GetTPCsignal(),30.));
 
      ResetTrackToFollow(*t);
@@ -733,6 +734,9 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
 
   if(AliITSReconstructor::GetRecoParam()->GetFindV0s()) AliITSV0Finder::RefitV02(event,this);
 
+  Bool_t doExtra=AliITSReconstructor::GetRecoParam()->GetSearchForExtraClusters();
+  if(!doExtra) AliDebug(2,"Do not search for extra clusters");
+
   Int_t nentr=event->GetNumberOfTracks();
   //  Info("RefitInward", "Number of ESD tracks: %d\n", nentr);
 
@@ -745,14 +749,8 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
     if (esd->GetStatus()&AliESDtrack::kTPCout)
       if ((esd->GetStatus()&AliESDtrack::kTPCrefit)==0) continue;
 
-    AliITStrackMI *t=0;
-    try {
-        t=new AliITStrackMI(*esd);
-    } catch (const Char_t *msg) {
-      //Warning("RefitInward",msg);
-        delete t;
-        continue;
-    }
+    AliITStrackMI *t = new AliITStrackMI(*esd);
+
     t->SetExpQ(TMath::Max(0.8*t->GetESDtrack()->GetTPCsignal(),30.));
     if (!CorrectForTPCtoITSDeadZoneMaterial(t)) {
        delete t;
@@ -762,15 +760,23 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
     ResetTrackToFollow(*t);
     fTrackToFollow.ResetClusters();
 
-    if ((esd->GetStatus()&AliESDtrack::kTPCin)==0)
+    // ITS standalone tracks
+    if ((esd->GetStatus()&AliESDtrack::kTPCin)==0) {
       fTrackToFollow.ResetCovariance(10.);
+      // protection for loopers that can have parameters screwed up
+      if(TMath::Abs(fTrackToFollow.GetY())>1000. ||
+        TMath::Abs(fTrackToFollow.GetZ())>1000.) {
+       delete t;
+       continue;
+      }
+    }
 
     //Refitting...
     Bool_t pe=(AliITSReconstructor::GetRecoParam()->GetComputePlaneEff() &&
                AliITSReconstructor::GetRecoParam()->GetIPlanePlaneEff()>=0);
 
     AliDebug(2,Form("Refit LABEL %d  %d",t->GetLabel(),t->GetNumberOfClusters()));
-    if (RefitAt(AliITSRecoParam::GetrInsideSPD1(),&fTrackToFollow,t,kTRUE,pe)) {
+    if (RefitAt(AliITSRecoParam::GetrInsideSPD1(),&fTrackToFollow,t,doExtra,pe)) {
        AliDebug(2,"  refit OK");
        fTrackToFollow.SetLabel(t->GetLabel());
        //       fTrackToFollow.CookdEdx();
@@ -877,7 +883,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,GetBz()));
+  Float_t phi = TMath::ASin(t->GetSnpAt(xdetintrackframe+cl->GetX(),GetBz()));
   phi += alpha-det.GetPhi();
   Float_t tgphi = TMath::Tan(phi);
 
@@ -1340,15 +1346,12 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
     for (Int_t i=0;i<TMath::Min(2,ntracks[2]);i++) {
       AliITStrackMI & track= tracks[2][nindexes[2][i]];
       if (track.GetNumberOfClusters()<3) continue;
-      if (!constrain && track.GetNormChi2(2) >
+      if (track.GetNormChi2(2) >
          AliITSReconstructor::GetRecoParam()->GetMaxNormChi2NonCForHypothesis()) continue;
-      if (constrain) track.SetNSkipped(track.GetNSkipped()+2);      
-      if (!constrain){
-       track.SetD(0,track.GetD(GetX(),GetY()));
-       track.SetNSkipped(track.GetNSkipped()+7./(7.+8.*TMath::Abs(track.GetD(0))));
-       if (track.GetNumberOfClusters()+track.GetNDeadZone()+track.GetNSkipped()>6) {
-         track.SetNSkipped(6-track.GetNumberOfClusters()+track.GetNDeadZone());
-       }
+      track.SetD(0,track.GetD(GetX(),GetY()));
+      track.SetNSkipped(track.GetNSkipped()+7./(7.+8.*TMath::Abs(track.GetD(0))));
+      if (track.GetNumberOfClusters()+track.GetNDeadZone()+track.GetNSkipped()>6) {
+       track.SetNSkipped(6-track.GetNumberOfClusters()+track.GetNDeadZone());
       }
       AddTrackHypothesys(new AliITStrackMI(track), esdindex);
     }
@@ -1387,7 +1390,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       Double_t xrp[3]; vertex->GetXYZ(xrp[0],xrp[1],xrp[2]);  //I.B.
       Int_t nearestold  = GetNearestLayer(xrp);               //I.B.
       Int_t nearest     = nearestold; 
-      for (Int_t ilayer =nearest;ilayer<8;ilayer++){
+      for (Int_t ilayer =nearest;ilayer<7;ilayer++){
        if (ntracks[nearest]==0){
          nearest = ilayer;
        }
@@ -1464,7 +1467,51 @@ fNMaxSigmaCl(3)
     fClusterTracks[0][i]=-1;
     fClusterTracks[1][i]=-1;
     fClusterTracks[2][i]=-1;    
-    fClusterTracks[3][i]=-1;    
+    fClusterTracks[3][i]=-1;
+    fY[i]=0;    
+    fZ[i]=0;    
+  }
+  fYB[0]=0;
+  fYB[1]=0;
+
+  for (Int_t j=0; j<AliITSRecoParam::fgkMaxClusterPerLayer5; j++) {
+    for (Int_t j1=0; j1<6; j1++) {
+      fClusters5[j1][j]=0;
+      fClusterIndex5[j1][j]=-1;
+      fY5[j1][j]=0;
+      fZ5[j1][j]=0;
+      fN5[j1]=0;
+      fBy5[j1][0]=0;
+      fBy5[j1][1]=0;
+    }
+  }
+
+  for (Int_t j=0; j<AliITSRecoParam::fgkMaxClusterPerLayer10; j++) {
+    for (Int_t j1=0; j1<11; j1++) {
+      fClusters10[j1][j]=0;
+      fClusterIndex10[j1][j]=-1;
+      fY10[j1][j]=0;
+      fZ10[j1][j]=0;
+      fN10[j1]=0;
+      fBy10[j1][0]=0;
+      fBy10[j1][1]=0;
+    }
+  }
+
+  for (Int_t j=0; j<AliITSRecoParam::fgkMaxClusterPerLayer20; j++) {
+    for (Int_t j1=0; j1<21; j1++) {
+      fClusters20[j1][j]=0;
+      fClusterIndex20[j1][j]=-1;
+      fY20[j1][j]=0;
+      fZ20[j1][j]=0;
+      fN20[j1]=0;
+      fBy20[j1][0]=0;
+      fBy20[j1][1]=0;
+    }
+  }
+  for(Int_t i=0;i<AliITSRecoParam::fgkMaxClusterPerLayer;i++){
+    fClusters[i]=NULL;
+    fClusterIndex[i]=0;
   }
 }
 //------------------------------------------------------------------------
@@ -1503,7 +1550,61 @@ fNMaxSigmaCl(3) {
   //--------------------------------------------------------------------
   fDetectors=new AliITSdetector[fNladders*fNdetectors];
   fRoad=2*fR*TMath::Sqrt(TMath::Pi()/1.);//assuming that there's only one cluster
+
+  for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
+    fClusterWeight[i]=0;
+    fClusterTracks[0][i]=-1;
+    fClusterTracks[1][i]=-1;
+    fClusterTracks[2][i]=-1;    
+    fClusterTracks[3][i]=-1;    
+    fY[i]=0;    
+    fZ[i]=0;    
+  }
+
+  fYB[0]=0;
+  fYB[1]=0;
+
+  for (Int_t j=0; j<AliITSRecoParam::fgkMaxClusterPerLayer5; j++) {
+    for (Int_t j1=0; j1<6; j1++) {
+      fClusters5[j1][j]=0;
+      fClusterIndex5[j1][j]=-1;
+      fY5[j1][j]=0;
+      fZ5[j1][j]=0;
+      fN5[j1]=0;
+      fBy5[j1][0]=0;
+      fBy5[j1][1]=0;
+    }
+  }
+
+  for (Int_t j=0; j<AliITSRecoParam::fgkMaxClusterPerLayer10; j++) {
+    for (Int_t j1=0; j1<11; j1++) {
+      fClusters10[j1][j]=0;
+      fClusterIndex10[j1][j]=-1;
+      fY10[j1][j]=0;
+      fZ10[j1][j]=0;
+      fN10[j1]=0;
+      fBy10[j1][0]=0;
+      fBy10[j1][1]=0;
+    }
+  }
+
+  for (Int_t j=0; j<AliITSRecoParam::fgkMaxClusterPerLayer20; j++) {
+    for (Int_t j1=0; j1<21; j1++) {
+      fClusters20[j1][j]=0;
+      fClusterIndex20[j1][j]=-1;
+      fY20[j1][j]=0;
+      fZ20[j1][j]=0;
+      fN20[j1]=0;
+      fBy20[j1][0]=0;
+      fBy20[j1][1]=0;
+    }
+  }
+  for(Int_t i=0;i<AliITSRecoParam::fgkMaxClusterPerLayer;i++){
+    fClusters[i]=NULL;
+    fClusterIndex[i]=0;
+  }
 }
+/*
 //------------------------------------------------------------------------
 AliITStrackerMI::AliITSlayer::AliITSlayer(const AliITSlayer& layer):
 fR(layer.fR),
@@ -1537,6 +1638,7 @@ fNMaxSigmaCl(layer.fNMaxSigmaCl)
 {
   //Copy constructor
 }
+*/
 //------------------------------------------------------------------------
 AliITStrackerMI::AliITSlayer::~AliITSlayer() {
   //--------------------------------------------------------------------
@@ -2409,7 +2511,7 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      track->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
 
 
-     if (extra) { // search for extra clusters in overlapped modules
+     if (extra && clAcc) { // search for extra clusters in overlapped modules
        AliITStrackV2 tmp(*track);
        if (!ComputeRoad(track,ilayer,idet,zmin,zmax,ymin,ymax)) return kFALSE;
        layer.SelectClusters(zmin,zmax,ymin,ymax);
@@ -2811,6 +2913,7 @@ Float_t AliITStrackerMI::GetNumberOfSharedClusters(AliITStrackMI* track,Int_t id
       if (fgLayers[l].GetClusterTracks(itrack,c)>=0 && fgLayers[l].GetClusterTracks(itrack,c)!=id){
        list[l]=index;
        clist[l] = (AliITSRecPoint*)GetCluster(index);
+       track->SetSharedWeight(l,weight);
        shared+=weight; 
        break;
       }
@@ -3483,6 +3586,9 @@ AliITStrackMI * AliITStrackerMI::GetBestHypothesys(Int_t esdindex, AliITStrackMI
   }
   delete backtrack;
   delete forwardtrack;
+
+  if (!besttrack)  return 0;
+
   Int_t accepted=0;
   for (Int_t i=0;i<entries;i++){    
     AliITStrackMI * track = (AliITStrackMI*)array->At(i);
@@ -3661,13 +3767,13 @@ void  AliITStrackerMI::GetBestHypothesysMIP(TObjArray &itsTracks)
       if (besttrack&&fAfterV0) {
        UpdateESDtrack(besttrack,AliESDtrack::kITSin);
       }
-      if (besttrack&&fConstraint[fPass]) 
-       UpdateESDtrack(besttrack,AliESDtrack::kITSin);
-      if (besttrack->GetChi2MIP(0)+besttrack->GetNUsed()>1.5 && fConstraint[fPass]) {
-       if ( TMath::Abs(besttrack->GetD(0))>0.1 || 
-            TMath::Abs(besttrack->GetD(1))>0.1 ) track->SetReconstructed(kFALSE);      
-      }       
-
+      if (besttrack) {
+       if (fConstraint[fPass]) UpdateESDtrack(besttrack,AliESDtrack::kITSin);
+       if (besttrack->GetChi2MIP(0)+besttrack->GetNUsed()>1.5 && fConstraint[fPass]) {
+         if ( TMath::Abs(besttrack->GetD(0))>0.1 || 
+              TMath::Abs(besttrack->GetD(1))>0.1 ) track->SetReconstructed(kFALSE);    
+       }       
+      }
     }    
   }
 } 
@@ -3744,15 +3850,15 @@ Double_t AliITStrackerMI::GetPredictedChi2MI(AliITStrackMI* track, const AliITSR
   //
   // Compute predicted chi2
   //
+  // Take into account the mis-alignment (bring track to cluster plane)
+  Double_t xTrOrig=track->GetX();
+  if (!track->Propagate(xTrOrig+cluster->GetX())) return 1000.;
   Float_t erry,errz,covyz;
   Float_t theta = track->GetTgl();
   Float_t phi   = track->GetSnp();
-  phi = TMath::Abs(phi)*TMath::Sqrt(1./((1.-phi)*(1.+phi)));
+  phi *= TMath::Sqrt(1./((1.-phi)*(1.+phi)));
   AliITSClusterParam::GetError(layer,cluster,theta,phi,track->GetExpQ(),erry,errz,covyz);
   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->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,covyz);
   // Bring the track back to detector plane in ideal geometry
@@ -3825,8 +3931,9 @@ void AliITStrackerMI::GetDCASigma(const AliITStrackMI* track, Float_t & sigmarfi
   //to be paramterized using external parameters in future 
   //
   // 
-  sigmarfi = 0.0040+1.4 *TMath::Abs(track->GetC())+332.*track->GetC()*track->GetC();
-  sigmaz   = 0.0110+4.37*TMath::Abs(track->GetC());
+  Double_t curv=track->GetC();
+  sigmarfi = 0.0040+1.4 *TMath::Abs(curv)+332.*curv*curv;
+  sigmaz   = 0.0110+4.37*TMath::Abs(curv);
 }
 //------------------------------------------------------------------------
 void AliITStrackerMI::SignDeltas(const TObjArray *clusterArray, Float_t vz)
@@ -4462,7 +4569,7 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
 
   // check if the road overlaps with bad chips
   Float_t xloc,zloc;
-  LocalModuleCoord(ilayer,idet,track,xloc,zloc);
+  if(!(LocalModuleCoord(ilayer,idet,track,xloc,zloc)))return 0;
   Float_t zlocmin = zloc-dz;
   Float_t zlocmax = zloc+dz;
   Float_t xlocmin = xloc-dy;
@@ -4567,6 +4674,7 @@ Bool_t AliITStrackerMI::LocalModuleCoord(Int_t ilayer,Int_t idet,
   return kTRUE;
 }
 //------------------------------------------------------------------------
+//------------------------------------------------------------------------
 Bool_t AliITStrackerMI::IsOKForPlaneEff(const AliITStrackMI* track, const Int_t *clusters, Int_t ilayer) const {
 //
 // Method to be optimized further: 
@@ -4605,16 +4713,17 @@ Bool_t AliITStrackerMI::IsOKForPlaneEff(const AliITStrackMI* track, const Int_t
 // require a minimal number of cluster in other layers and eventually clusters in closest layers 
   Int_t ncl_out=0; Int_t ncl_in=0;
   for(Int_t lay=AliITSgeomTGeo::kNLayers-1;lay>ilayer;lay--) { // count n. of cluster in outermost layers
   AliDebug(2,Form("trak=%d  lay=%d  ; index=%d ESD label= %d",tmp.GetLabel(),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_out++;
+   // if (tmp.GetClIndex(lay)>=0) ncl_out++;
+if(index[lay]>=0)ncl_out++;
   }
   for(Int_t lay=ilayer-1; lay>=0;lay--) { // count n. of cluster in innermost layers
     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_in++;
+   if (index[lay]>=0) ncl_in++; 
   }
-  Int_t ncl=ncl_out+ncl_out;
+  Int_t ncl=ncl_out+ncl_in;
   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 );
@@ -4655,14 +4764,11 @@ Bool_t AliITStrackerMI::IsOKForPlaneEff(const AliITStrackMI* track, const Int_t
   //***************
   // DEFINITION OF SEARCH ROAD FOR accepting a track
   //
-  //For the time being they are hard-wired, later on from AliITSRecoParam
   Double_t nsigx=AliITSReconstructor::GetRecoParam()->GetNSigXFromBoundaryPlaneEff();
   Double_t nsigz=AliITSReconstructor::GetRecoParam()->GetNSigZFromBoundaryPlaneEff();
-  // 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
+                                                    // done for RecPoints
 
   // exclude tracks at boundary between detectors
   //Double_t boundaryWidth=AliITSRecoParam::GetBoundaryWidthPlaneEff();
@@ -4670,7 +4776,6 @@ Bool_t AliITStrackerMI::IsOKForPlaneEff(const AliITStrackMI* track, const Int_t
   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) ||
@@ -4806,6 +4911,9 @@ void AliITStrackerMI::UseTrackForPlaneEff(const AliITStrackMI* track, Int_t ilay
     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};
+                                                          // and the module
+
+Float_t AngleModTrack[3]={99999.,99999.,99999.}; // angles (phi, z and "absolute angle") between the track and the mormal to the module (see below)
 
     tr[0]=locx;
     tr[1]=locz;
@@ -4835,8 +4943,54 @@ void AliITStrackerMI::UseTrackForPlaneEff(const AliITStrackMI* track, Int_t ilay
         clu[3]=TMath::Sqrt(c.GetSigmaZ2());
       //}
     }
-    fPlaneEff->FillHistos(key,found,tr,clu,cltype);
+  // Compute the angles between the track and the module
+      // compute the angle "in phi direction", i.e. the angle in the transverse plane 
+      // between the normal to the module and the projection (in the transverse plane) of the 
+      // track trajectory
+    // tgphi and tglambda of the track in tracking frame with alpha=det.GetPhi
+    Float_t tgl = tmp.GetTgl();
+    Float_t phitr   = tmp.GetSnp();
+    phitr = TMath::ASin(phitr);
+    Int_t volId = AliGeomManager::LayerToVolUIDSafe(ilayer+1 ,idet );
+
+    Double_t tra[3]; AliGeomManager::GetOrigTranslation(volId,tra);
+    Double_t rot[9]; AliGeomManager::GetOrigRotation(volId,rot);
+   Double_t alpha =0.;
+    alpha = tmp.GetAlpha();
+    Double_t phiglob = alpha+phitr;
+    Double_t p[3];
+    p[0] = TMath::Cos(phiglob);
+    p[1] = TMath::Sin(phiglob);
+    p[2] = tgl;
+    TVector3 pvec(p[0],p[1],p[2]);
+    TVector3 normvec(rot[1],rot[4],rot[7]);
+    Double_t angle = pvec.Angle(normvec);
+
+    if(angle>0.5*TMath::Pi()) angle = (TMath::Pi()-angle);
+    angle *= 180./TMath::Pi();
+
+    //Trasverse Plane
+    TVector3 pt(p[0],p[1],0);
+    TVector3 normt(rot[1],rot[4],0);
+    Double_t anglet = pt.Angle(normt);
+
+    Double_t phiPt = TMath::ATan2(p[1],p[0]);
+    if(phiPt<0)phiPt+=2.*TMath::Pi();
+    Double_t phiNorm = TMath::ATan2(rot[4],rot[1]);
+    if(phiNorm<0) phiNorm+=2.*TMath::Pi();
+    if(anglet>0.5*TMath::Pi()) anglet = (TMath::Pi()-anglet);
+    if(phiNorm>phiPt) anglet*=-1.;// pt-->normt  clockwise: anglet>0
+    if((phiNorm-phiPt)>TMath::Pi()) anglet*=-1.;
+    anglet *= 180./TMath::Pi();
+
+     AngleModTrack[2]=(Float_t) angle;
+     AngleModTrack[0]=(Float_t) anglet;
+     // now the "angle in z" (much easier, i.e. the angle between the z axis and the track momentum + 90)
+    AngleModTrack[1]=TMath::ACos(tgl/TMath::Sqrt(tgl*tgl+1.));
+    AngleModTrack[1]-=TMath::Pi()/2.; // range of angle is -pi/2 , pi/2
+    AngleModTrack[1]*=180./TMath::Pi(); // in degree
+
+      fPlaneEff->FillHistos(key,found,tr,clu,cltype,AngleModTrack);
   }
 return;
 }
-