]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITStrackerSA.cxx
Corrections for gcc 4.0
[u/mrichter/AliRoot.git] / ITS / AliITStrackerSA.cxx
index 87387fcce5d5de6c74dfc88a4ae9a8348c14fd29..855c1edb8fc69a5c859c366b8a4dee2ad7fcf991 100644 (file)
@@ -1,4 +1,3 @@
-
 /**************************************************************************
  * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
  *                                                                        *
@@ -14,6 +13,8 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+/* $Id$ */
+
 ////////////////////////////////////////////////////
 //  Stand alone tracker class                     //
 //  Origin:  Elisabetta Crescio                   //
 ////////////////////////////////////////////////////
 
 #include <stdlib.h>
-#include "TArrayI.h"
+
+#include <TArrayI.h>
 #include <TBranch.h>
 #include <TMath.h>
 #include <TObjArray.h>
 #include <TTree.h>
-#include "AliRun.h"
+
+#include "AliESD.h"
+#include "AliESDVertex.h"
+#include "AliESDtrack.h"
+#include "AliITSRiemannFit.h"
+#include "AliITSVertexer.h"
 #include "AliITSclusterTable.h"
 #include "AliITSclusterV2.h"
 #include "AliITSgeom.h"
-#include "AliITSRiemannFit.h"
-#include "AliITStrackerSA.h"
 #include "AliITStrackSA.h"
-#include "AliITSVertexer.h"
-#include "AliESDVertex.h"
-#include "AliESD.h"
-#include "AliESDtrack.h"
+#include "AliITStrackerSA.h"
+#include "AliRun.h"
 
 ClassImp(AliITStrackerSA)
 
 //____________________________________________________________________________
-AliITStrackerSA::AliITStrackerSA():AliITStrackerV2(){
+AliITStrackerSA::AliITStrackerSA():AliITStrackerMI(){
   // Default constructor
   Init();
 }
 //____________________________________________________________________________
-AliITStrackerSA::AliITStrackerSA(AliITSgeom *geom):AliITStrackerV2(geom) 
+AliITStrackerSA::AliITStrackerSA(AliITSgeom *geom):AliITStrackerMI(geom) 
 {
   // Standard constructor (Vertex is known and passed to this obj.)
   Init();
   fVert = 0;
   fGeom = geom;
 }
 
 //____________________________________________________________________________
-AliITStrackerSA::AliITStrackerSA(AliITSgeom *geom, AliESDVertex *vert):AliITStrackerV2(geom) 
+AliITStrackerSA::AliITStrackerSA(AliITSgeom *geom, AliESDVertex *vert):AliITStrackerMI(geom) 
 {
   // Standard constructor (Vertex is known and passed to this obj.)
   Init();
   fVert = vert;
   fGeom = geom;
-}
-
-//______________________________________________________________________
-AliITStrackerSA::AliITStrackerSA(const AliITStrackerSA &trkr) : 
-                    AliITStrackerV2(trkr) {
-  // Copy constructor
-  // Copies are not allowed. The method is protected to avoid misuse.
-  Error("AliITStrackerSA","Copy constructor not allowed\n");
-}
-
-//______________________________________________________________________
-AliITStrackerSA& AliITStrackerSA::operator=(const 
-                    AliITStrackerSA& /* trkr */){
-  // Assignment operator
-  // Assignment is not allowed. The method is protected to avoid misuse.
-  Error("= operator","Assignment operator not allowed\n");
-  return *this;
 }
 
 //____________________________________________________________________________
-AliITStrackerSA::AliITStrackerSA(AliITSgeom *geom, AliITSVertexer *vertexer):AliITStrackerV2(geom) 
+AliITStrackerSA::AliITStrackerSA(AliITSgeom *geom, AliITSVertexer *vertexer):AliITStrackerMI(geom) 
 {
   // Standard constructor (Vertex is unknown - vertexer is passed to this obj)
   Init();
   fVertexer = vertexer;
   fGeom = geom;
 }
 
 //____________________________________________________________________________
-AliITStrackerSA::AliITStrackerSA(AliITStrackerSA& tracker):AliITStrackerV2(){
+AliITStrackerSA::AliITStrackerSA(AliITStrackerSA& tracker):AliITStrackerMI(){
   // Copy constructor
   fPhiEstimate = tracker.fPhiEstimate;
   for(Int_t i=0;i<2;i++){
@@ -135,7 +125,7 @@ AliITStrackerSA::~AliITStrackerSA(){
   if(fLambdaWin)delete []fLambdaWin;
   fTable =0;
   fListOfTracks->Delete();
- }
 }
 
 //____________________________________________________________________________
 void AliITStrackerSA::Init(){
@@ -157,7 +147,7 @@ void AliITStrackerSA::Init(){
     fITSclusters = 0;
     SetSixPoints();
     fListOfTracks=new TObjArray(0,0);
-}
+ }
 //_______________________________________________________________________
 void AliITStrackerSA::ResetForFinding(){
   //  Reset data members used in all loops during track finding
@@ -246,7 +236,9 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
       ResetForFinding();
       Int_t pflag=0;
       AliITSclusterV2* cl = layer.GetCluster(ncl);
-      if(cl->IsUsed()==1) continue;     
+      if(cl->IsUsed()==1) continue;
+      if(cl->TestBit(kSAflag)==kTRUE) continue;
+      
       fPhic = fTable->GetPhiCluster(0,ncl);
       fLambdac = fTable->GetLambdaCluster(0,ncl);
       fPhiEstimate = fPhic;
@@ -258,15 +250,15 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
       
       Int_t * nn = new Int_t[fGeom->GetNlayers()];//counter for clusters on each layer
       for(Int_t i=0;i<fGeom->GetNlayers();i++){ nn[i]=0;}
-      nn[0] = SearchClusters(0,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable);
-      nn[1] = SearchClusters(1,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable);
+      nn[0] = SearchClusters(0,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
+      nn[1] = SearchClusters(1,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
 
       if(nn[1]>0){
         pflag=1;
         fPoint3[0] = fPointc[0];
         fPoint3[1] = fPointc[1];
       }
-      nn[2] = SearchClusters(2,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable);
+      nn[2] = SearchClusters(2,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
       if(nn[1]==0 && nn[2]==0) pflag=0;
       if(nn[2]!=0 && nn[1]!=0){ pflag=1; UpdatePoints();}
       if(nn[2]!=0 && nn[1]==0){
@@ -275,13 +267,13 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
         fPoint3[1]=fPointc[1];
       }
 
-      nn[3] = SearchClusters(3,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable);
+      nn[3] = SearchClusters(3,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
       pflag=1;
       if(nn[3]!=0) UpdatePoints();
-      nn[4] = SearchClusters(4,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable); 
+      nn[4] = SearchClusters(4,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag); 
       pflag=1;
       if(nn[4]!=0) UpdatePoints();
-      nn[5] = SearchClusters(5,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable); 
+      nn[5] = SearchClusters(5,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag); 
           
 
       Int_t layOK=0;
@@ -298,8 +290,10 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
           while(nct--){
             Int_t index = trs->GetClusterIndexSA(nct);
             AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
-            if(kl->IsUsed()==1) kl->Use();
+           if(kl->TestBit(kSAflag)==kTRUE) kl->ResetBit(kSAflag);
           }
+         delete [] nn;
+         delete trs;
          continue;
         }
         outrack=tr2;  
@@ -310,7 +304,7 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
         while(nct--){
           Int_t index = tr2->GetClusterIndex(nct);     
           AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);      
-          if(kl->IsUsed()==0) kl->Use();
+         kl->SetBit(kSAflag);
 
         }
       } 
@@ -319,9 +313,10 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
         while(nct--){
           Int_t index = trs->GetClusterIndexSA(nct);
           AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
-          if(kl->IsUsed()==1) kl->Use();
+                 if(kl->TestBit(kSAflag)==kTRUE) kl->ResetBit(kSAflag);
         }
       }
+      delete [] nn;
       delete trs;
 
     }//end loop on clusters of layer1
@@ -343,6 +338,7 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
         Int_t pflag=0;
         AliITSclusterV2* cl = layer2.GetCluster(ncl2);
         if(cl->IsUsed()==1) continue;
+       if(cl->TestBit(kSAflag)==kTRUE) continue;
        fPhic = fTable->GetPhiCluster(1,ncl2);
        fLambdac = fTable->GetLambdaCluster(1,ncl2);
         fPhiEstimate = fPhic;
@@ -356,7 +352,7 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
         for(Int_t kk=0;kk<fGeom->GetNlayers()-1;kk++)nn[kk] = 0;
         for(Int_t kk=0;kk<fGeom->GetNlayers()-1;kk++){
           nn[kk] = SearchClusters(kk+1,fPhiWin[nloop],fLambdaWin[nloop],
-                   trs,primaryVertex[2],pflag,fTable);
+                   trs,primaryVertex[2],pflag);
           if(nn[kk]==0)break;
           if(kk>0){
             UpdatePoints();
@@ -374,8 +370,9 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
             while(nct--){
               Int_t index = trs->GetClusterIndexSA(nct);
               AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
-              if(kl->IsUsed()==1) kl->Use();
+             if(kl->TestBit(kSAflag)==kTRUE) kl->ResetBit(kSAflag);
             }
+           delete trs;
             continue;
           }
           outrack=tr2;
@@ -385,7 +382,7 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
             Int_t index = tr2->GetClusterIndex(nct);     
             AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
             if(kl==0) continue;
-            if(kl->IsUsed()==0) kl->Use();
+           kl->SetBit(kSAflag);
           }
         }       
         else{
@@ -394,8 +391,8 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
             Int_t index = trs->GetClusterIndexSA(nct);
             AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
             if(kl==0) continue;
-            if(kl->IsUsed()==1) kl->Use();
-          }
+           if(kl->TestBit(kSAflag)==kTRUE) kl->ResetBit(kSAflag);
+         }
         }
         delete trs;
       }//end loop on clusters of layer2
@@ -404,7 +401,7 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
   }  // if(!fSixPoints....  
 
   delete [] firstmod;
-  delete fTable;
+  delete fTable; fTable=0;
 }
 
 
@@ -436,7 +433,7 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
     fTable = new AliITSclusterTable(fGeom,this,primaryVertex);
     fTable->FillArray(fITSclusters);
     fTable->FillArrayCoorAngles();
-   }
+  }
 
   Int_t * firstmod = new Int_t[fGeom->GetNlayers()];
   for(Int_t i=0;i<fGeom->GetNlayers();i++){
@@ -445,20 +442,26 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
   // firstmod [i] number of the first module in the ITS layer i.
   
     
-  AliITSlayer &layer=fgLayers[0];   // first layer
+  AliITSlayer &layer=fgLayers[0];   
   Int_t ntrack=0;
-
-  Int_t dim=layer.GetNumberOfClusters();
+   Int_t dim=layer.GetNumberOfClusters();
   //loop on the different windows
   for(Int_t nloop=0;nloop<fNloop;nloop++){
     for(Int_t ncl=0;ncl<dim;ncl++){ //loop starting from layer 0
+
       ResetForFinding();
       Int_t pflag=0;
       AliITSclusterV2* cl = (AliITSclusterV2*)layer.GetCluster(ncl);
       if(cl==0) continue;
       if(cl->IsUsed()==1) continue;
+      if(cl->TestBit(kSAflag)==kTRUE) continue;
+      if (cl->GetQ()<=0) continue;
+      
       fPhic = fTable->GetPhiCluster(0,ncl);
       fLambdac = fTable->GetLambdaCluster(0,ncl);
+
+      if (TMath::Abs(fLambdac)>0.26*TMath::Pi()) continue;
+
       fPhiEstimate = fPhic;
       AliITStrackSA* trs = new AliITStrackSA();      
       fPoint1[0]=primaryVertex[0];
@@ -467,15 +470,15 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
       fPoint2[1]=fTable->GetYCluster(0,ncl);
       Int_t * nn = new Int_t[fGeom->GetNlayers()];//counter for clusters on each layer
       for(Int_t i=0;i<fGeom->GetNlayers();i++){ nn[i]=0;}
-      nn[0] = SearchClusters(0,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable);
+      nn[0] = SearchClusters(0,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
           
-      nn[1] = SearchClusters(1,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable);
+      nn[1] = SearchClusters(1,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
       if(nn[1]>0){
         pflag=1;
         fPoint3[0] = fPointc[0];
         fPoint3[1] = fPointc[1];
       }
-      nn[2] = SearchClusters(2,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable);
+      nn[2] = SearchClusters(2,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
       if(nn[1]==0 && nn[2]==0) pflag=0;
       if(nn[2]!=0 && nn[1]!=0){ pflag=1; UpdatePoints();}
       if(nn[2]!=0 && nn[1]==0){
@@ -484,13 +487,13 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
         fPoint3[1]=fPointc[1];
       }
 
-      nn[3] = SearchClusters(3,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable);
+      nn[3] = SearchClusters(3,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
       pflag=1;
       if(nn[3]!=0) UpdatePoints();
-      nn[4] = SearchClusters(4,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable); 
+      nn[4] = SearchClusters(4,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag); 
       pflag=1;
       if(nn[4]!=0) UpdatePoints();
-      nn[5] = SearchClusters(5,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag,fTable); 
+      nn[5] = SearchClusters(5,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag); 
           
 
       Int_t layOK=0;
@@ -507,7 +510,8 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
           while(nct--){
             Int_t index = trs->GetClusterIndexSA(nct);
             AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
-            if(kl->IsUsed()==1) kl->Use();
+           if(kl->TestBit(kSAflag)==kTRUE) kl->ResetBit(kSAflag);
+           
           }
          continue;
         }
@@ -516,29 +520,32 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
        outtrack.UpdateTrackParams(tr2,AliESDtrack::kITSin);
        event->AddTrack(&outtrack);
        ntrack++;
-        Int_t nct = tr2->GetNumberOfClusters();
+       Int_t nct = tr2->GetNumberOfClusters();
        while(nct--){
           Int_t index = tr2->GetClusterIndex(nct);     
           AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);      
-          if(kl->IsUsed()==0) kl->Use();
-         
-        }
-      } 
+         kl->SetBit(kSAflag);
+          
+       } 
+      }
       else{
-        Int_t nct = trs->GetNumberOfClustersSA();
-        while(nct--){
-          Int_t index = trs->GetClusterIndexSA(nct);
-          AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
-          if(kl->IsUsed()==1) kl->Use();
+       Int_t nct = trs->GetNumberOfClustersSA();
+       while(nct--){
+         Int_t index = trs->GetClusterIndexSA(nct);
+         AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
+         if(kl->TestBit(kSAflag)==kTRUE) kl->ResetBit(kSAflag);
+         
        }
       }
       delete trs;
       delete[] nn;
-
+      
     }//end loop on clusters of layer1
-
+    
   }//end loop2
 
+
+
   //if 5/6 points are required, second loop starting 
   //from second layer, to find tracks with point of 
   //layer 1 missing
@@ -547,13 +554,14 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
     //   counter for clusters on each layer  
     Int_t * nn = new Int_t[fGeom->GetNlayers()-1];      
     for(Int_t nloop=0;nloop<fNloop;nloop++){
-      AliITSlayer &layer2=fgLayers[1]; //loop on layer 2
+      AliITSlayer &layer2=fgLayers[1]; 
       Int_t ncl2=layer2.GetNumberOfClusters();
       while(ncl2--){ //loop starting from layer 2
         ResetForFinding();
         Int_t pflag=0;
         AliITSclusterV2* cl = layer2.GetCluster(ncl2);
         if(cl->IsUsed()==1) continue;
+       if(cl->TestBit(kSAflag)==kTRUE) continue;
        fPhic = fTable->GetPhiCluster(1,ncl2);
        fLambdac = fTable->GetLambdaCluster(1,ncl2);
        fPhiEstimate = fPhic;
@@ -566,7 +574,7 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
         for(Int_t kk=0;kk<fGeom->GetNlayers()-1;kk++)nn[kk] = 0;
         for(Int_t kk=0;kk<fGeom->GetNlayers()-1;kk++){
           nn[kk] = SearchClusters(kk+1,fPhiWin[nloop],fLambdaWin[nloop],
-                   trs,primaryVertex[2],pflag,fTable);
+                   trs,primaryVertex[2],pflag);
           if(nn[kk]==0)break;
           if(kk>0){
             UpdatePoints();
@@ -580,12 +588,12 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
         if(fl>=5){  // 5/6       
           AliITStrackV2* tr2 = FitTrack(trs,primaryVertex,errorsprimvert);
           if(tr2==0){
-           ntrack++;
-            Int_t nct = trs->GetNumberOfClustersSA();
+           Int_t nct = trs->GetNumberOfClustersSA();
             while(nct--){
               Int_t index = trs->GetClusterIndexSA(nct);
               AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
-              if(kl->IsUsed()==1) kl->Use();
+             if(kl->TestBit(kSAflag)==kTRUE) kl->ResetBit(kSAflag);
+             
             }
 
             continue;
@@ -594,13 +602,14 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
          AliESDtrack outtrack;
          outtrack.UpdateTrackParams(tr2,AliESDtrack::kITSin);
          event->AddTrack(&outtrack);
+         ntrack++;
           Int_t nct = tr2->GetNumberOfClusters();
           while(nct--){
             Int_t index = tr2->GetClusterIndex(nct);     
             AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
             if(kl==0) continue;
-            if(kl->IsUsed()==0) kl->Use();
-          }
+           kl->SetBit(kSAflag);
+         }
         }       
         else{
           Int_t nct = trs->GetNumberOfClustersSA();
@@ -608,7 +617,8 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
             Int_t index = trs->GetClusterIndexSA(nct);
             AliITSclusterV2* kl = (AliITSclusterV2*)GetCluster(index);
             if(kl==0) continue;
-            if(kl->IsUsed()==1) kl->Use();
+           if(kl->TestBit(kSAflag)==kTRUE) kl->ResetBit(kSAflag);
+           
           }
         }
         delete trs;
@@ -618,9 +628,8 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
   }  //end opt="5/6"  
 
   delete [] firstmod;
-  delete fTable;   
+  delete fTable;fTable=0;   
   Info("FindTracks","Number of found tracks: %d",event->GetNumberOfTracks());
-
   return 0;
 
 }
@@ -636,7 +645,7 @@ AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVert
   for(Int_t i=0;i<fGeom->GetNlayers();i++){
     firstmod[i]=fGeom->GetModuleIndex(i+1,1,1);
   }  
-  AliITStrackV2* otrack2;
+
   Int_t nclusters = tr->GetNumberOfClustersSA();
   TObjArray** listlayer = new TObjArray*[fGeom->GetNlayers()];
   for(Int_t i=0;i<fGeom->GetNlayers();i++){
@@ -657,7 +666,7 @@ AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVert
     Int_t index = tr->GetClusterIndexSA(ncl);   
     AliITSclusterV2* cl = (AliITSclusterV2*)GetCluster(index);
 
-    if(cl->IsUsed()==1) cl->Use();
+    if(cl->TestBit(kSAflag)==kTRUE) cl->ResetBit(kSAflag);
     Int_t lay = (index & 0xf0000000) >> 28;
     if(lay==0) { listlayer[0]->AddLast(cl); clind0[nnn[0]]=index;nnn[0]++;}
     if(lay==1) { listlayer[1]->AddLast(cl); clind1[nnn[1]]=index;nnn[1]++;}
@@ -733,7 +742,13 @@ AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVert
         Float_t seed1,seed2,seed3;
         AliITSRiemannFit fit;
         Int_t rf = fit.FitHelix(3,recp,errs,seed1,seed2,seed3); //this gives phi,tgl,curvature to start Kalman Filter
-        if(rf==0) continue;  
+        if(rf==0) {
+         for(Int_t i=1;i<3;i++){
+           delete recp[i];
+           delete errs[i];
+         }     
+         continue;
+       }  
         Double_t phi=seed1;
         Double_t tgl=seed2;
         
@@ -787,20 +802,24 @@ AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVert
               if(cl1!=0) trac->AddClusterV2(1,(clind1[l2] & 0x0fffffff)>>0);
               if(cl0!=0) trac->AddClusterV2(0,(clind0[l1] & 0x0fffffff)>>0);
             
-              //fit with Kalman filter using AliITStrackerV2::RefitAt()
+              //fit with Kalman filter using AliITStrackerMI::RefitAt()
           
-              AliITStrackV2* ot = new AliITStrackV2(*trac);
+              AliITStrackMI* ot = new AliITStrackSA(*trac);
               
               ot->ResetCovariance();
               ot->ResetClusters();
               
               if(RefitAt(49.,ot,trac)){ //fit from layer 1 to layer 6
 
-                otrack2 = new AliITStrackV2(*ot);
+                AliITStrackMI *otrack2 = new AliITStrackMI(*ot);
                 otrack2->ResetCovariance(); 
                 otrack2->ResetClusters();
                 //fit from layer 6 to layer 1
-                if(RefitAt(3.7,otrack2,ot)) fListOfTracks->AddLast(otrack2);
+                if(RefitAt(3.7,otrack2,ot)) {
+                 fListOfTracks->AddLast(otrack2);
+               } else {
+                 delete otrack2;
+               }
                               
               }       
           
@@ -829,13 +848,21 @@ AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVert
     for(Int_t i=0;i<fGeom->GetNlayers();i++){
       delete listlayer[i];
     }
-    delete listlayer;
+    delete [] listlayer;
+    delete [] firstmod;
     return 0;
   }
 
   AliITStrackV2* otrack =(AliITStrackV2*)FindTrackLowChiSquare(fListOfTracks,dim);
 
-  if(otrack==0) return 0;
+  if(otrack==0) {
+    for(Int_t i=0;i<fGeom->GetNlayers();i++){
+      delete listlayer[i];
+    }
+    delete [] listlayer; 
+    delete [] firstmod;
+    return 0;
+  }
   Int_t * indexc = new Int_t[fGeom->GetNlayers()];
   for(Int_t i=0;i<fGeom->GetNlayers();i++) indexc[i]=0;
   for(Int_t nind=0;nind<otrack->GetNumberOfClusters();nind++){
@@ -862,6 +889,7 @@ AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVert
   Int_t numberofpoints;
   if(fSixPoints) numberofpoints=6;
   else numberofpoints=5;
+  CookLabel(otrack,0.); //MI change - to see fake ratio
   Int_t label =  Label(cl0->GetLabel(0),cl1->GetLabel(0), 
                        cl2->GetLabel(0),cl3->GetLabel(0),
                        cl4->GetLabel(0),labl[0],
@@ -876,7 +904,7 @@ AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVert
   for(Int_t i=0;i<fGeom->GetNlayers();i++){
     delete listlayer[i];
   }
-  delete listlayer; 
+  delete [] listlayer; 
   delete [] firstmod;
   return otrack;
 
@@ -920,7 +948,8 @@ void AliITStrackerSA::UseFoundTracksV2(Int_t evnum,TTree* treev2){
     for(Int_t k=0;k<ncl;k++){
       Int_t index = ttrrt->GetClusterIndex(k);
       AliITSclusterV2* clui = (AliITSclusterV2*)GetCluster(index);
-      if(clui->IsUsed()==0) clui->Use();  
+      if(clui->IsUsed()==0) clui->Use();
+      
     }
   }
   delete ttrrt;
@@ -960,8 +989,9 @@ void AliITStrackerSA::UseFoundTracksV2(AliESD *event){
 
 }
 
+/*
 //_______________________________________________________
-Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t lambdawindow, AliITStrackSA* trs,Double_t zvertex,Int_t pflag,AliITSclusterTable* table){
+Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t lambdawindow, AliITStrackSA* trs,Double_t zvertex,Int_t pflag){
   //function used to to find the clusters associated to the track
   Int_t nc=0;
   AliITSlayer &lay = fgLayers[layer];
@@ -978,6 +1008,7 @@ Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t la
       delete[] firstmod;
       return 0;
     }
+
     Double_t fi1 =TMath::ATan2(cy1,cx1);
     Double_t fi2 =TMath::ATan2(cy2,cx2);
     fPhiEstimate = ChoosePoint(fi1,fi2,fPhic);
@@ -1007,14 +1038,14 @@ Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t la
 
 
   Int_t nn=0;
-  TArrayI* array =(TArrayI*)table->GetListOfClusters(nmod);
+  TArrayI* array =(TArrayI*)fTable->GetListOfClusters(nmod);
   TArrayI* listc = new TArrayI(array->GetSize());
   for(Int_t i=0;i<array->GetSize();i++){
     Int_t in=(Int_t)array->At(i);
     listc->AddAt(in,nn);
     nn++;
   }
-  
+    
   Int_t k=0;
   Int_t val;
   while(k<8){
@@ -1033,7 +1064,7 @@ Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t la
  
   for(Int_t ii=0;ii<8;ii++){
     if(nm[ii]!=value && nm[ii]!=nmod && nm[ii]>=0){
-      TArrayI* ar =(TArrayI*)table->GetListOfClusters(nm[ii]+firstmod[layer]);
+      TArrayI* ar =(TArrayI*)fTable->GetListOfClusters(nm[ii]+firstmod[layer]);
       listc->Set(listc->GetSize()+ar->GetSize());
       for(Int_t j=0;j<ar->GetSize();j++){
        Int_t in=(Int_t)ar->At(j);
@@ -1049,7 +1080,8 @@ Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t la
     Int_t index = (Int_t)listc->At(i);
     AliITSclusterV2* cllay = lay.GetCluster(index);
     if(cllay==0) continue;
-    if(cllay->IsUsed()==1) continue;  
+    if(cllay->IsUsed()==1) continue;
+    if(cllay->TestBit(kSAflag)==kTRUE) continue;
     Double_t phi   = fTable->GetPhiCluster(layer,index);
     Double_t lambda= fTable->GetLambdaCluster(layer,index);
  
@@ -1063,7 +1095,7 @@ Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t la
         return 0;
       }
       trs->AddClusterSA(layer,index);
-      cllay->Use();
+      cllay->SetBit(kSAflag);
       fPhiEstimate=phi;
       fPointc[0]=fTable->GetXCluster(layer,index);
       fPointc[1]=fTable->GetYCluster(layer,index);
@@ -1075,15 +1107,65 @@ Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t la
   return nc;
 
 }
+*/
+
 
+//_______________________________________________________
+Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t lambdawindow, AliITStrackSA* trs,Double_t zvertex,Int_t pflag){
+  //function used to to find the clusters associated to the track
+  Int_t nc=0;
+  AliITSlayer &lay = fgLayers[layer];
+  Double_t r=lay.GetR(),tgl=TMath::Tan(fLambdac);
+
+  if(pflag==1){      
+    Float_t cx1,cx2,cy1,cy2;
+    FindEquation(fPoint1[0],fPoint1[1],fPoint2[0],fPoint2[1],fPoint3[0],fPoint3[1],fCoef1,fCoef2,fCoef3);
+    if (FindIntersection(fCoef1,fCoef2,fCoef3,-r*r,cx1,cy1,cx2,cy2)==0)
+       return 0;
+    Double_t fi1=TMath::ATan2(cy1,cx1);
+    Double_t fi2=TMath::ATan2(cy2,cx2);
+    fPhiEstimate=ChoosePoint(fi1,fi2,fPhic);
+  }
+
+  Double_t dz=r*lambdawindow*TMath::Sqrt(1+tgl*tgl) + 0.3*TMath::Abs(tgl);
+  Double_t zmax=r*tgl + zvertex + dz;
+  Double_t zmin=r*tgl + zvertex - dz;
+
+  Int_t indmin = lay.FindClusterIndex(zmin);
+  Int_t indmax = lay.FindClusterIndex(zmax);
+  for (Int_t index=indmin; index<indmax; index++) {
+     AliITSclusterV2 *c=lay.GetCluster(index);
+     if (c->IsUsed()) continue;
+     if (c->GetQ()<=0) continue;
+     if (c->TestBit(kSAflag)==kTRUE) continue;
+
+     Double_t phi   =fTable->GetPhiCluster(layer,index);
+     if (TMath::Abs(phi-fPhiEstimate)>phiwindow) continue;
+
+     Double_t lambda=fTable->GetLambdaCluster(layer,index);
+     if (TMath::Abs(lambda-fLambdac)>lambdawindow) continue;
+
+     if(trs->GetNumberOfClustersSA()==15) return 0;
+
+     trs->AddClusterSA(layer,index);
+     nc++;
+     fLambdac=lambda;
+     fPhiEstimate=phi;
+     fPointc[0]=fTable->GetXCluster(layer,index);
+     fPointc[1]=fTable->GetYCluster(layer,index);
+
+     c->SetBit(kSAflag);
+  }
+  return nc;
+}
 
 
 //________________________________________________________________
 void AliITStrackerSA::UpdatePoints(){
   //update of points for the estimation of the curvature  
 
-  fPoint1[0]=fPoint2[0]; 
-  fPoint1[1]=fPoint2[1];
+  //fPoint1[0]=fPoint2[0]; 
+  //fPoint1[1]=fPoint2[1];
   fPoint2[0]=fPoint3[0];
   fPoint2[1]=fPoint3[1];
   fPoint3[0]=fPointc[0];
@@ -1092,8 +1174,6 @@ void AliITStrackerSA::UpdatePoints(){
   
 }
 
-
-
 //___________________________________________________________________
 Int_t AliITStrackerSA::FindEquation(Float_t x1, Float_t y1, Float_t x2, Float_t y2, Float_t x3, Float_t y3,Float_t& a, Float_t& b, Float_t& c){
 
@@ -1114,14 +1194,15 @@ Int_t AliITStrackerSA::FindEquation(Float_t x1, Float_t y1, Float_t x2, Float_t
  //c2 is -rlayer*rlayer
 
   if(a1==0) return 0;
- Float_t m = c2-c1; 
- Float_t aA = (b1*b1)/(a1*a1)+1;
- Float_t bB = (-2*m*b1/(a1*a1));
- Float_t cC = c2+(m*m)/(a1*a1);
- if((bB*bB-4*aA*cC)<0) return 0;
+ Double_t m = c2-c1; 
+ Double_t aA = (b1*b1)/(a1*a1)+1;
+ Double_t bB = (-2*m*b1/(a1*a1));
+ Double_t cC = c2+(m*m)/(a1*a1);
+ Double_t dD = bB*bB-4*aA*cC;
+ if(dD<0) return 0;
  
- y1 = (-bB+TMath::Sqrt(bB*bB-4*aA*cC))/(2*aA); 
- y2 = (-bB-TMath::Sqrt(bB*bB-4*aA*cC))/(2*aA); 
+ y1 = (-bB+TMath::Sqrt(dD))/(2*aA); 
+ y2 = (-bB-TMath::Sqrt(dD))/(2*aA); 
  x1 = (c2-c1-b1*y1)/a1;
  x2 = (c2-c1-b1*y2)/a1;
 
@@ -1285,24 +1366,23 @@ void AliITStrackerSA::SetWindowSizes(Int_t n, Double_t *phi, Double_t *lam){
     }
   }
   else {  // default values
-    
-    Double_t phid[32]   = {0.002,0.003,0.004,0.0045,0.0047,
+            
+    Double_t phid[33]   = {0.002,0.003,0.004,0.0045,0.0047,
                           0.005,0.0053,0.0055,
                           0.006,0.0063,0.0065,0.007,0.0073,0.0075,0.0077,
                           0.008,0.0083,0.0085,0.0087,0.009,0.0095,0.0097,
-                          0.01,0.0105,0.011,0.0115,0.012,0.0125,0.013,0.0135,
-                          0.014};
-    Double_t lambdad[32] = {0.002,0.003,0.004,0.0045,0.0047,
-                           0.005,0.0053,0.0055,
-                           0.006,0.0063,0.0065,0.007,0.0073,0.0075,0.0077,
-                           0.008,0.0083,0.0085,0.0087,0.009,0.0095,0.0097,
-                           0.01,0.015,0.011,0.0115,0.012,0.0125,0.013,0.0135,
-                           0.014};
+                          0.01,0.0105,0.011,0.0115,0.012,0.0125,0.013,0.0135,0.0140,0.0145};
+    Double_t lambdad[33] = {0.003,0.004,0.005,0.005,0.005,
+                           0.005,0.005,0.006,
+                           0.006,0.006,0.006,0.007,0.007,0.007,0.007,
+                           0.007,0.007,0.007,0.007,0.007,0.007,0.007,
+                           0.008,0.008,0.008,0.008,0.008,0.008,0.008,0.008,0.008,0.008};
     
-    if(fNloop!=32){
-      fNloop = 32;
+    if(fNloop!=33){
+      fNloop = 33;
     }
-   
+    
+    
     fPhiWin = new Double_t[fNloop];
     fLambdaWin = new Double_t[fNloop];
    
@@ -1315,4 +1395,3 @@ void AliITStrackerSA::SetWindowSizes(Int_t n, Double_t *phi, Double_t *lam){
 
 }
 
-