]> 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 3487d186fc16321a62f1ab6a5dd44f900deb765e..855c1edb8fc69a5c859c366b8a4dee2ad7fcf991 100644 (file)
@@ -13,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++){
@@ -115,8 +106,8 @@ AliITStrackerSA::AliITStrackerSA(AliITStrackerSA& tracker):AliITStrackerV2(){
   }
   fVertexer = tracker.fVertexer;
   fGeom = tracker.fGeom;
-  fFlagLoad = tracker.fFlagLoad;
   fTable = tracker.fTable;
+  fListOfTracks = tracker.fListOfTracks;
 }
 
 //____________________________________________________________________________
@@ -130,11 +121,11 @@ AliITStrackerSA::~AliITStrackerSA(){
   fVert = 0;
   fVertexer = 0;
   fGeom = 0;
-  fFlagLoad = 0;
   if(fPhiWin)delete []fPhiWin;
   if(fLambdaWin)delete []fLambdaWin;
   fTable =0;
-}
+  fListOfTracks->Delete();
+  }
 
 //____________________________________________________________________________
 void AliITStrackerSA::Init(){
@@ -151,12 +142,12 @@ void AliITStrackerSA::Init(){
     fVert = 0;
     fVertexer = 0;
     fGeom = 0;
-    fFlagLoad = 0;
     SetWindowSizes();
     fTable = 0;
     fITSclusters = 0;
     SetSixPoints();
-}
+    fListOfTracks=new TObjArray(0,0);
+ }
 //_______________________________________________________________________
 void AliITStrackerSA::ResetForFinding(){
   //  Reset data members used in all loops during track finding
@@ -169,6 +160,7 @@ void AliITStrackerSA::ResetForFinding(){
     fCoef3=0;
     fPointc[0]=0;
     fPointc[1]=0;
+    fListOfTracks->Delete();
 }
 //____________________________________________________________________________
 void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
@@ -244,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;
@@ -256,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){
@@ -273,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;
@@ -296,9 +290,11 @@ 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);
           }
-          continue;
+         delete [] nn;
+         delete trs;
+         continue;
         }
         outrack=tr2;  
         out->Fill();
@@ -308,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);
 
         }
       } 
@@ -317,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
@@ -341,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;
@@ -354,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();
@@ -372,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;
@@ -383,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{
@@ -392,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
@@ -402,7 +401,7 @@ void AliITStrackerSA::FindTracks(TTree *out,Int_t evnumber){
   }  // if(!fSixPoints....  
 
   delete [] firstmod;
-  delete fTable;
+  delete fTable; fTable=0;
 }
 
 
@@ -411,6 +410,7 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
 
   // Track finder using the ESD object
 
+
   if(!fITSclusters){
     Fatal("FindTracks","ITS cluster tree is not accessed - Abort!!!\n Please use method SetClusterTree to pass the pointer to the tree\n");
     return -1;
@@ -429,10 +429,11 @@ Int_t AliITStrackerSA::FindTracks(AliESD* event){
   }
 
   //Fill array with cluster indices for each module
-  fTable = new AliITSclusterTable(fGeom,this,primaryVertex);
-  fTable->FillArray(fITSclusters);
-  fTable->FillArrayCoorAngles();
-  
+  if(!fTable){
+    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++){
@@ -441,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];
@@ -463,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){
@@ -480,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;
@@ -503,38 +510,42 @@ 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;
+         continue;
         }
        
        AliESDtrack outtrack;
        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
@@ -543,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;
@@ -562,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();
@@ -576,27 +588,28 @@ 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;
           }
 
          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();
@@ -604,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;
@@ -614,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;
 
 }
@@ -632,8 +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);
   }  
-  TObjArray* listoftracks=new TObjArray(0,0);
-  AliITStrackV2* otrack2;
+
   Int_t nclusters = tr->GetNumberOfClustersSA();
   TObjArray** listlayer = new TObjArray*[fGeom->GetNlayers()];
   for(Int_t i=0;i<fGeom->GetNlayers();i++){
@@ -654,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]++;}
@@ -730,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;
         
@@ -784,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)) listoftracks->AddLast(otrack2);
+                if(RefitAt(3.7,otrack2,ot)) {
+                 fListOfTracks->AddLast(otrack2);
+               } else {
+                 delete otrack2;
+               }
                               
               }       
           
@@ -821,19 +843,26 @@ AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVert
 
   delete [] end;
 
-  Int_t dim=listoftracks->GetEntries();
+  Int_t dim=fListOfTracks->GetEntries();
   if(dim==0){
-    delete listoftracks;
     for(Int_t i=0;i<fGeom->GetNlayers();i++){
       delete listlayer[i];
     }
-    delete listlayer;
+    delete [] listlayer;
+    delete [] firstmod;
     return 0;
   }
 
-  AliITStrackV2* otrack =(AliITStrackV2*)FindTrackLowChiSquare(listoftracks,dim);
+  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++){
@@ -860,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],
@@ -871,20 +901,20 @@ AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVert
                        cl4->GetLabel(2),labl[2],numberofpoints);
   
   otrack->SetLabel(label);  
-  delete listoftracks;
   for(Int_t i=0;i<fGeom->GetNlayers();i++){
     delete listlayer[i];
   }
-  delete listlayer; 
+  delete [] listlayer; 
   delete [] firstmod;
   return otrack;
 
 }
 
 //_______________________________________________________________________
-void AliITStrackerSA::UseFoundTracksV2(Int_t evnum,TTree* treev2, TTree* clustertree){
+void AliITStrackerSA::UseFoundTracksV2(Int_t evnum,TTree* treev2){
   // Marks as used clusters belonging to tracks found with V2 TPC+ITS tracking
   //(or AliITStrackV2 tracks found with function FindTracks of this class)
+  
 
   //Get primary vertex
   if(fVertexer){
@@ -906,9 +936,6 @@ void AliITStrackerSA::UseFoundTracksV2(Int_t evnum,TTree* treev2, TTree* cluster
     fTable->FillArray(fITSclusters);
     fTable->FillArrayCoorAngles();
   }
-  SetEventNumber(evnum);
-  if(GetFlagLoadedClusters()==0) LoadClusters(clustertree);
-  SetFlagLoadedClusters(1);
 
   TBranch* bra = (TBranch*)treev2->GetBranch("tracks");
   if(!bra) Warning("UseFoundTracksV2","No branch for track tree");
@@ -921,7 +948,8 @@ void AliITStrackerSA::UseFoundTracksV2(Int_t evnum,TTree* treev2, TTree* cluster
     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;
@@ -929,33 +957,20 @@ void AliITStrackerSA::UseFoundTracksV2(Int_t evnum,TTree* treev2, TTree* cluster
 }
 
 //_______________________________________________________________________
-void AliITStrackerSA::UseFoundTracksV2(Int_t evnum,AliESD *event, TTree* 
-clustertree){
+void AliITStrackerSA::UseFoundTracksV2(AliESD *event){
   // Marks as used clusters belonging to tracks found with V2 TPC+ITS tracking
 
   //Get primary vertex
-  if(fVertexer){
-    if(fVert)delete fVert;
-    fVert = fVertexer->FindVertexForCurrentEvent(evnum);
-  }
-  else {
-    gAlice->GetEvent(evnum);
-    if(!fVert){
-      Fatal("FindTracks","Vertex is missing\n");
-      return;
-    }
-  }
+
   Double_t primaryVertex[3];
-  fVert->GetXYZ(primaryVertex);
+  event->GetVertex()->GetXYZ(primaryVertex);
 
   if(!fTable){
     fTable = new AliITSclusterTable(fGeom,this,primaryVertex);
     fTable->FillArray(fITSclusters);
     fTable->FillArrayCoorAngles(); 
   }
-  SetEventNumber(evnum);
-  if(GetFlagLoadedClusters()==0) LoadClusters(clustertree);
-  SetFlagLoadedClusters(1);
+
   Int_t ntracks = event->GetNumberOfTracks();
   while (ntracks--) {
     AliESDtrack *esd=event->GetTrack(ntracks);
@@ -974,8 +989,9 @@ clustertree){
 
 }
 
+/*
 //_______________________________________________________
-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];
@@ -992,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);
@@ -1012,39 +1029,59 @@ Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t la
   Int_t nm[8]={0,0,0,0,0,0,0,0};
   nm[0] = lay.FindDetectorIndex(fi+phiwindow,zed);
   nm[1] = lay.FindDetectorIndex(fi-phiwindow,zed);
-  nm[2]  = lay.FindDetectorIndex(fi,zed1);
-  nm[3]  = lay.FindDetectorIndex(fi,zed2);
-  nm[4]  = lay.FindDetectorIndex(fi+phiwindow,zed1);
-  nm[5]  = lay.FindDetectorIndex(fi-phiwindow,zed1);
-  nm[6]  = lay.FindDetectorIndex(fi+phiwindow,zed2);
-  nm[7]  = lay.FindDetectorIndex(fi-phiwindow,zed2);
+  nm[2] = lay.FindDetectorIndex(fi,zed1);
+  nm[3] = lay.FindDetectorIndex(fi,zed2);
+  nm[4] = lay.FindDetectorIndex(fi+phiwindow,zed1);
+  nm[5] = lay.FindDetectorIndex(fi-phiwindow,zed1);
+  nm[6] = lay.FindDetectorIndex(fi+phiwindow,zed2);
+  nm[7] = lay.FindDetectorIndex(fi-phiwindow,zed2);
+
 
   Int_t nn=0;
-  TArrayI* array =(TArrayI*)table->GetListOfClusters(nmod);
-  TArrayI* list = new TArrayI(array->GetSize());
+  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);
-    list->AddAt(in,nn);
+    listc->AddAt(in,nn);
     nn++;
   }
-  
-//  Info("SearchClusters", "layer %d, module %d", layer, nmod);
+    
+  Int_t k=0;
+  Int_t val;
+  while(k<8){
+    for(Int_t h=k+1;h<8;h++){
+      if(nm[k]>nm[h]){
+       val=nm[k];
+       nm[k]=nm[h];
+       nm[h]=val;
+      }
+     
+   }
+    k++;
+  }
+  Int_t value=-5;
   for(Int_t ii=0;ii<8;ii++){
-    if(nm[ii]!=nmod && nm[ii]>=0){
-      TArrayI* ar =(TArrayI*)table->GetListOfClusters(nm[ii]+firstmod[layer]);
-      list->Set(list->GetSize()+ar->GetSize());
+    if(nm[ii]!=value && nm[ii]!=nmod && nm[ii]>=0){
+      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);
-        list->AddAt(in,nn);
-        nn++;
+       Int_t in=(Int_t)ar->At(j);
+       listc->AddAt(in,nn);
+       nn++;
+       value=nm[ii];
       }
     }
   }
-  for(Int_t i=0;i<list->GetSize();i++){
-    Int_t index = (Int_t)list->At(i);
+  
+  for(Int_t i=0;i<listc->GetSize();i++){
+    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);
  
@@ -1052,33 +1089,83 @@ Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t la
        TMath::Abs(fPhiEstimate-phi)<phiwindow){
       nc+=1;
       fLambdac = lambda;
-      if(trs->GetNumberOfClustersSA()==20){
+      if(trs->GetNumberOfClustersSA()==15){
        delete[] firstmod;
-        delete list;
+        delete listc;
         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);
     }
 
   }
-  delete list;
+  delete listc;
   delete [] firstmod;
   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];
@@ -1087,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){
 
@@ -1109,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;
 
@@ -1280,27 +1366,23 @@ void AliITStrackerSA::SetWindowSizes(Int_t n, Double_t *phi, Double_t *lam){
     }
   }
   else {  // default values
-    
-    Double_t phid[40]   = {0.001,0.0015,0.002,0.0023,0.0025,0.0027,0.003,
-                          0.0033,0.0035,0.0037,0.004,0.0043,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[40] = {0.001,0.0015,0.002,0.0023,0.0025,0.0027,0.003,
-                           0.0033,0.0035,0.0037,0.004,0.0043,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!=40){
-      fNloop = 40;
-      Warning("SetWindowSizes","Number of loop forced to the default value %d",fNloop);
+    if(fNloop!=33){
+      fNloop = 33;
     }
-   
+    
+    
     fPhiWin = new Double_t[fNloop];
     fLambdaWin = new Double_t[fNloop];
    
@@ -1313,4 +1395,3 @@ void AliITStrackerSA::SetWindowSizes(Int_t n, Double_t *phi, Double_t *lam){
 
 }
 
-