]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSTrackerV1.cxx
Update of slat geometry
[u/mrichter/AliRoot.git] / ITS / AliITSTrackerV1.cxx
index 672ae9e23651ec6ff5450014a9afcc868cf0f0a5..adaea7f61e018d88f60ba4db8bd6c5be6124a99c 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
  
-/*
-$Log$
-Revision 1.12  2001/10/19 21:32:35  nilsen
-Minor changes to remove compliation warning on gcc 2.92.2 compiler, and
-cleanded up a little bit of code.
+/* $Id$ */
 
-*/
-//     The purpose of this class is to permorm the ITS tracking. The 
+// The purpose of this class is to permorm the ITS tracking. The 
 // constructor has the task to inizialize some private members. The method 
 // DoTracking is written to be called by a macro. It gets the event number,
 // the minimum and maximum order number of TPC tracks that are to be tracked
@@ -34,32 +29,31 @@ cleanded up a little bit of code.
 // imposition respectively. The authors thank Mariana Bondila to have help 
 // them to resolve some problems.  July-2000
 
-#include <fstream.h>
+#include <Riostream.h>
+#include <Riostream.h>
 #include <TMath.h>
 #include <TBranch.h>
 #include <TVector.h>
 #include <TFile.h>
 #include <TTree.h>
-#include <TStopwatch.h>
 
 #include "TParticle.h"
 #include "AliRun.h"
 #include "AliITS.h"
-#include "AliITSsegmentationSSD.h"
 #include "AliITSgeomSPD.h"
 #include "AliITSgeomSDD.h"
 #include "AliITSgeomSSD.h"
 #include "AliITSgeom.h"
 #include "AliITSRecPoint.h"
-#include "stdlib.h"
 #include "AliKalmanTrack.h" 
 #include "AliMagF.h"
 #include "AliITSTrackV1.h"
 #include "AliITSIOTrack.h"
 #include "AliITSRad.h"   
-#include "../TPC/AliTPCtracker.h"
+#include "AliTPCtracker.h"
 #include "AliITSTrackerV1.h"
-#include "AliITSVertex.h"
+#include "AliITSPid.h"
+#include "AliMC.h"
 
 ClassImp(AliITSTrackerV1)
  //______________________________________________________________________
@@ -67,44 +61,70 @@ AliITSTrackerV1::AliITSTrackerV1() {
   //Default constructor
   fITS = 0;
   fresult = 0;
+  fPtref=0.;
+  fChi2max=0.;
+  //fepsphi=0.;
+  //fepsz=0.;
   frecPoints = 0;
   fvettid = 0;
+  fflagvert=0;
   frl = 0;
+  Int_t ia;
+  for(ia=0; ia<6; ia++) {
+  fNlad[ia]=0;
+  fNdet[ia]=0;
+  fAvrad[ia]=0.;
+  fDetx[ia]=0.;
+  fDetz[ia]=0.; 
+  } // end for ia  
   fzmin = 0;
   fzmax = 0;
   fphimin = 0;
   fphimax = 0;
   fphidet = 0;
+  fNRecPoints=0;
+  fRecCylR=0;
+  fRecCylPhi=0;
+  fRecCylZ=0;
+  fFieldFactor=0;
 }
 //______________________________________________________________________
-AliITSTrackerV1::AliITSTrackerV1(AliITS* IITTSS, Bool_t flag) {
+AliITSTrackerV1::AliITSTrackerV1(AliITS* IITTSS, Int_t evnumber, Bool_t flag) {
     //Origin   A. Badala' and G.S. Pappalardo:  
     // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
     // Class constructor. It does some initializations.
 
+  //PH Initialisation taken from the default constructor
     fITS      = IITTSS;
+    fresult = 0;
     fPtref    = 0.;
-    fChi2max  =0.;     
-    fflagvert =flag;
+    fChi2max  =0.; 
+    frecPoints = 0;             
+    fvettid = 0;
+    fflagvert = flag;   
+    frl = 0;
+    fzmin = 0;
+    fzmax = 0;
+    fphimin = 0;
+    fphimax = 0;
+    fphidet = 0;
+  
     Int_t imax = 200,jmax = 450;
     frl       = new AliITSRad(imax,jmax);
 
     //////////  gets information on geometry /////////////////////////////
-    AliITSgeom *g1 = ((AliITS*)gAlice->GetDetector("ITS"))->GetITSgeom();
-    // Why not AliITS *g1 = fITS->GetITSgeom(); // ?? BSN
+        AliITSgeom *g1 = fITS->GetITSgeom();  
     Int_t ll=1, dd=1;
     TVector det(9);
 
-    //cout<<" nlad ed ndet \n";
     Int_t ia;
     for(ia=0; ia<6; ia++) {
        fNlad[ia]=g1->GetNladders(ia+1);
        fNdet[ia]=g1->GetNdetectors(ia+1);
        //cout<<fNlad[i]<<" "<<fNdet[i]<<"\n"; 
     } // end for ia
-    //getchar();
 
-    //cout<<" raggio medio = ";
+    //cout<<" mean radius = ";
     Int_t ib;
     for(ib=0; ib<6; ib++) {  
        g1->GetCenterThetaPhi(ib+1,ll,dd,det);
@@ -137,6 +157,7 @@ AliITSTrackerV1::AliITSTrackerV1(AliITS* IITTSS, Bool_t flag) {
     //for(Int_t la=0; la<6; la++) cout<<"    "<<fDetx[la]<<"     "<<
     //                                 fDetz[la]<<endl;
     //getchar();
+        
     // allocate memory and define matrices fzmin, fzmax, fphimin and fphimax //
     Double_t epsz=1.2;
     Double_t epszdrift=0.05;
@@ -178,7 +199,7 @@ AliITSTrackerV1::AliITSTrackerV1(AliITS* IITTSS, Bool_t flag) {
        fphidet[im1] = new Double_t[im2max];
     } // end for im1
 
-    Float_t global[3],local[3];
+       Double_t global[3],local[3];
     Double_t pigre=TMath::Pi();
     Double_t xmin,ymin,xmax,ymax;
 
@@ -207,20 +228,62 @@ AliITSTrackerV1::AliITSTrackerV1(AliITS* IITTSS, Bool_t flag) {
            if(fphimax[im1][im2]<0.) fphimax[im1][im2]+=2.*pigre;
        } // end for im2
     } // end for im1
+//////////////////////////////////////////////////////////////////////////////////////////////////////////
+/////////////// allocate memory and define vector fNRecPoints and matrices fRecCylR, fRecCylPhi, fRecCylZ /////////////
+       gAlice->GetEvent(evnumber);
+  Int_t numOfModules = g1->GetIndexMax();
+  fRecCylR = new Double_t *[numOfModules];
+  fRecCylPhi = new Double_t *[numOfModules]; 
+  fRecCylZ = new Double_t *[numOfModules];
+  AliITSRecPoint *recp;
+  fNRecPoints = new Int_t[numOfModules];
+   
+                for(Int_t module=0; module<numOfModules; module++) {                           
+                 fITS->ResetRecPoints();                    
+        gAlice->TreeR()->GetEvent(module);               
+                 frecPoints=fITS->RecPoints();
+                 Int_t nRecPoints=fNRecPoints[module]=frecPoints->GetEntries();
+                 fRecCylR[module] = new Double_t[nRecPoints];
+                 fRecCylPhi[module] = new Double_t[nRecPoints];
+                 fRecCylZ[module] = new  Double_t[nRecPoints];           
+                 Int_t ind;
+                 for(ind=0; ind<fNRecPoints[module]; ind++) {    
+                   recp=(AliITSRecPoint*)frecPoints->UncheckedAt(ind);                                          
+                       // Float_t global[3], local[3];
+                        Double_t global[3], local[3];
+              local[0]=recp->GetX();
+              local[1]=0.;
+              local[2]= recp->GetZ();                                  
+                        g1->LtoG(module,local,global);
+                                                                                        
+                        Double_t r = TMath::Sqrt(global[0]*global[0]+global[1]*global[1]);                     // r hit
+                        Double_t phi = TMath::ATan2(global[1],global[0]); if(phi<0.) phi+=2.*TMath::Pi();      // phi hit                      
+                Double_t z = global[2];                                                                // z hit
+                                                                                                                                                                                                                                    
+                        fRecCylR[module][ind]=r;
+                        fRecCylPhi[module][ind]=phi;
+                        fRecCylZ[module][ind]=z;                        
+                 }             
+               }        
+        //}  
+  //}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+        
 
     ////////// gets magnetic field factor //////////////////////////////
 
     AliMagF * fieldPointer = gAlice->Field();
-    fFieldFactor = (Double_t)fieldPointer->Factor();
-    //cout<< " field factor = "<<fFieldFactor<<"\n"; getchar();
+   // fFieldFactor = (Double_t)fieldPointer->Factor();
+    fFieldFactor =(Double_t)fieldPointer-> SolenoidField()/10/.2;
+   // cout<< " field factor = "<<fFieldFactor<<"\n"; getchar();
 }
 //______________________________________________________________________
-AliITSTrackerV1::AliITSTrackerV1(const AliITSTrackerV1 &cobj) {
+AliITSTrackerV1::AliITSTrackerV1(const AliITSTrackerV1 &cobj) : TObject(cobj) {
     // Origin  A. Badala' and G.S. Pappalardo:
     // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
     // copy constructor
-
-    *fITS = *cobj.fITS;
+        
+        *fITS = *cobj.fITS;
     *fresult = *cobj.fresult;
     fPtref = cobj.fPtref;
     fChi2max = cobj.fChi2max;    
@@ -271,23 +334,81 @@ AliITSTrackerV1::AliITSTrackerV1(const AliITSTrackerV1 &cobj) {
            fphidet[im1][im2]=cobj.fphidet[im1][im2];  
        } // end for im2
     } // end for im2
+
+
+       AliITSgeom *g1 = fITS->GetITSgeom();  
+   Int_t numOfModules = g1->GetIndexMax();
+       /*
+  fRecCylR = new Float_t *[numOfModules];
+  fRecCylPhi = new Float_t *[numOfModules]; 
+  fRecCylZ = new Float_t *[numOfModules];
+  */
+  fRecCylR = new Double_t *[numOfModules];
+  fRecCylPhi = new Double_t *[numOfModules]; 
+  fRecCylZ = new Double_t *[numOfModules];  
+  fNRecPoints = new Int_t[numOfModules];       
+               for(Int_t module=0; module<numOfModules; module++) {            
+                 Int_t nRecPoints=fNRecPoints[module]=cobj.fNRecPoints[module];
+                 /*
+                 fRecCylR[module] = new Float_t[nRecPoints];
+                 fRecCylPhi[module] = new Float_t[nRecPoints];
+                 fRecCylZ[module] = new Float_t[nRecPoints];
+                 */
+                 fRecCylR[module] = new Double_t[nRecPoints];
+                 fRecCylPhi[module] = new Double_t[nRecPoints];
+                 fRecCylZ[module] = new Double_t[nRecPoints];            
+                 Int_t ind;    
+                 for(ind=0; ind<nRecPoints; ind++) {       
+                        fRecCylR[module][ind]=cobj.fRecCylR[module][ind];
+                        fRecCylPhi[module][ind]=cobj.fRecCylPhi[module][ind];
+                        fRecCylZ[module][ind]=cobj.fRecCylZ[module][ind];                       
+                 }             
+               }        
+}
+/*
+//______________________________________________________________________
+void AliITSTrackerV1::DelMatrix(Int_t numOfModules) {
+  // cleanup of some data members
+  for(Int_t mod=0; mod<numOfModules; mod++) {
+    delete fRecCylR[mod];
+        delete fRecCylPhi[mod];
+        delete fRecCylZ[mod];
+  }
+    delete fRecCylR;
+        delete fRecCylPhi;
+        delete fRecCylZ;
 }
+*/
 //______________________________________________________________________
 AliITSTrackerV1::~AliITSTrackerV1(){
     // Origin  A. Badala' and G.S. Pappalardo:
     // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it  
-    // class destructor
-
-    //delete fTimerKalman;
-    //delete fTimerIntersection;
+    // class destructor         
+  delete frl;
+  delete fNRecPoints;
+  for(Int_t i=0; i<6; i++) {
+    delete fzmin[i];
+        delete fzmax[i];
+        delete fphimin[i];
+        delete fphimax[i];
+        delete fphidet[i];
+  }
+
+  delete fzmin;
+  delete fzmax;
+  delete fphimin;
+  delete fphimax;
+  delete fphidet;
+        
 }
 //______________________________________________________________________
-AliITSTrackerV1 &AliITSTrackerV1::operator=(AliITSTrackerV1 obj) {
+AliITSTrackerV1 &AliITSTrackerV1::operator=(const AliITSTrackerV1 &obj) {
     // Origin  A. Badala' and G.S. Pappalardo:
     // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it  
     // assignement operator
 
-    *fITS = *obj.fITS;
+        *fITS = *obj.fITS;
     *fresult = *obj.fresult;
     fPtref = obj.fPtref;
     fChi2max = obj.fChi2max;      
@@ -340,11 +461,31 @@ AliITSTrackerV1 &AliITSTrackerV1::operator=(AliITSTrackerV1 obj) {
        } // end for im2
     } // end for im1
 
+       AliITSgeom *g1 = fITS->GetITSgeom();  
+   Int_t numOfModules = g1->GetIndexMax();
+  fRecCylR = new Double_t *[numOfModules];
+  fRecCylPhi = new Double_t *[numOfModules]; 
+  fRecCylZ = new Double_t *[numOfModules];  
+  fNRecPoints = new Int_t[numOfModules];  
+         for(Int_t module=0; module<numOfModules; module++) {            
+                 Int_t nRecPoints=fNRecPoints[module]=obj.fNRecPoints[module];
+                 fRecCylR[module] = new Double_t[nRecPoints];
+                 fRecCylPhi[module] = new Double_t[nRecPoints];
+                 fRecCylZ[module] = new Double_t[nRecPoints];            
+                 Int_t ind;
+                 for(ind=0; ind<nRecPoints; ind++) {     
+                        fRecCylR[module][ind]=obj.fRecCylR[module][ind];
+                        fRecCylPhi[module][ind]=obj.fRecCylPhi[module][ind];
+                        fRecCylZ[module][ind]=obj.fRecCylZ[module][ind];                        
+                 }             
+               }        
+         
+        
     return *this;
 }
 //______________________________________________________________________
 void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
-                                TFile *file) {
+                                TFile *file, Bool_t realmass) {
     // Origin   A. Badala' and G.S. Pappalardo:
     // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
     // The method needs the event number, the minimum and maximum order
@@ -354,26 +495,33 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
     // The method can be called by a macro. It preforms the tracking for
     // all good TPC tracks
 
-    printf("begin DoTracking - file %p\n",file);
+    printf("begin DoTracking - file %p\n",(void*)file);
 
     gAlice->GetEvent(evNumber);  //modificato per gestire hbt
  
-    AliKalmanTrack *kkprov;
-    kkprov->SetConvConst(100/0.299792458/0.2/fFieldFactor);
+    AliKalmanTrack::SetConvConst(1000/0.299792458/gAlice->Field()->SolenoidField());
+   // cout<<" field = "<<gAlice->Field()->SolenoidField()<<endl;
+
 
     TFile *cf=TFile::Open("AliTPCclusters.root");  
-    AliTPCParam *digp= (AliTPCParam*)cf->Get("75x40_100x60");
+    AliTPCParam *digp= (AliTPCParam*)cf->Get("75x40_100x60_150x60");
     if (!digp) { cerr<<"TPC parameters have not been found !\n"; getchar();}
 
     cf->cd();
-    AliTPCtracker *tracker = new AliTPCtracker(digp,evNumber);  
+    TString foldname(fITS->GetLoader()->GetEventFolder()->GetName());
+    
+    printf("This method is not converted to the NewIO !\n");  //I.B.
+    return; //I.B.
+    AliTPCtracker *tracker = new AliTPCtracker(digp);            //I.B.
+    //PH    tracker->SetEventNumber(evNumber);                           //I.B.
 
     // Load clusters
-    tracker->LoadInnerSectors();
-    tracker->LoadOuterSectors();
+    printf("This method is not converted to the NewIO !\n");  //I.B.
+    return; //I.B.
+    tracker->LoadClusters(0);       //I.B.
 
     // Load tracks
-    TFile *tf=TFile::Open("AliTPCtracksSorted.root");  //modificato per hbt
+    TFile *tf=TFile::Open("AliTPCtracksSorted.root");  
     if (!tf->IsOpen()) {
        cerr<<"Can't open AliTPCtracksSorted.root !\n";
        return ;
@@ -388,7 +536,8 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
     Int_t nentr=(Int_t)tracktree->GetEntries();
     Int_t kk;
 
-    AliTPCtrack *ioTrackTPC=0;    
+    AliITSRecPoint *recp;    // oggi
+       AliTPCtrack *ioTrackTPC=0;    
     for (kk=0; kk<nentr; kk++) {
        ioTrackTPC=new AliTPCtrack; 
        tbranch->SetAddress(&ioTrackTPC);
@@ -434,35 +583,71 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
 
     TTree tracktree1("TreeT","Tree with ITS tracks");
     AliITSIOTrack *ioTrack=0;
+       AliITSPid *pid=new AliITSPid(1000);  // oggi
+
     tracktree1.Branch("ITStracks","AliITSIOTrack",&ioTrack,32000,0);
   
+    TDatabasePDG * db = new TDatabasePDG;   
+  
     Int_t j;       
     for (j=minTr; j<=maxTr; j++) {     
        track=(AliTPCtrack*)tracks.UncheckedAt(j);
        if (!track) continue;
-
-       //////   propagation to the end of TPC //////////////
-       Double_t xk=77.415;
-       track->PropagateTo(xk, 28.94, 1.204e-3);         //Ne    
-       xk -=0.01;
-       track->PropagateTo(xk, 44.77, 1.71);     //Tedlar
-       xk -=0.04;
-       track->PropagateTo(xk, 44.86, 1.45);     //kevlar
-       xk -=2.0;
-       track->PropagateTo(xk, 41.28, 0.029);    //Nomex         
-       xk-=16;
-       track->PropagateTo(xk,36.2,1.98e-3); //C02
-       xk -=0.01;
-       track->PropagateTo(xk, 24.01, 2.7);      //Al    
-       xk -=0.01;
-       track->PropagateTo(xk, 44.77, 1.71);     //Tedlar
-       xk -=0.04;
-       track->PropagateTo(xk, 44.86, 1.45);     //kevlar
-       xk -=0.5;
-       track->PropagateTo(xk, 41.28, 0.029);    //Nomex
-    ////////////////////////////////////////////////////////////////////
-
-       AliITSTrackV1 trackITS(*track);
+       
+       ///   mass definition ////////////////////////
+    Double_t mass=0.13956995;
+        Int_t pcode=211;  // a pion by default
+        
+        if(realmass) {
+       if(TMath::Abs(pcode)<20443) mass=db->GetParticle(pcode)->Mass();
+        }
+        else {
+                mass = track->GetMass();
+//              cout << "Mass = " << mass << endl;
+        }
+        
+       
+       
+        //   new propagation to the end of TPC
+    Double_t xk=80.;
+   // track->PropagateTo(xk,0.,0.); //Ne if it's still there   //attenzione funziona solo se modifica in TPC
+       // Double_t xk=77.415;   
+        track->PropagateTo(xk, 28.94, 1.204e-3);
+    xk-=0.005;
+    track->PropagateTo(xk, 44.77,1.71); //Tedlar        
+    xk-=0.02;
+    track->PropagateTo(xk, 44.86, 1.45);   //Kevlar
+    xk-=2.0;
+    track->PropagateTo(xk, 41.28, 0.029);//Nomex
+    xk-=0.02;
+    track->PropagateTo(xk, 44.86, 1.45);   //Kevlar
+    xk-=0.005;
+    track->PropagateTo(xk, 44.77, 1.71); //Tedlar
+
+    xk=61.;
+   // track->PropagateTo(xk,0.,0.); //C02
+        track->PropagateTo(xk,36.2,1.98e-3); //C02        //attenzione funziona solo se modifica in TPC
+
+    xk -=0.005;
+    track->PropagateTo(xk, 24.01, 2.7);    //Al    
+    xk -=0.005;
+    track->PropagateTo(xk, 44.77, 1.71);  //Tedlar
+    xk -=0.02;
+    track->PropagateTo(xk, 44.86, 1.45);    //Kevlar
+    xk -=0.5;
+    track->PropagateTo(xk, 41.28, 0.029);  //Nomex    
+    xk -=0.02;
+    track->PropagateTo(xk, 44.86, 1.45);    //Kevlar
+    xk -=0.005;
+    track->PropagateTo(xk, 44.77, 1.71);  //Tedlar
+    xk -=0.005;
+    track->PropagateTo(xk, 24.01, 2.7);    //Al 
+    
+       ////////////////////////////////////////////////////////////////////////////////////////////////////////        
+       //AliITSTrackV1 trackITS(*track);
+       AliITSTrackV1 trackITS(*track, fFieldFactor);
+       //cout<<" fFieldFactor = "<<fFieldFactor<<"\n";      
+       trackITS.PutMass(mass);   //new to add mass to track
        if(fresult){ delete fresult; fresult=0;}         
        fresult = new AliITSTrackV1(trackITS);   
 
@@ -494,7 +679,7 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
        primaryTrack.SetZv(zv);
        primaryTrack.SetsigmaDv(sigmaDv);
        primaryTrack.SetsigmaZv(sigmaZv);
-       primaryTrack.PrimaryTrack(frl);
+       primaryTrack.PrimaryTrack();
        TVector  d2=primaryTrack.Getd2();
        TVector  tgl2=primaryTrack.Gettgl2();
        TVector  dtgl=primaryTrack.Getdtgl();
@@ -511,6 +696,7 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
        list->AddLast(&trackITS);
   
        fPtref=TMath::Abs( (trackITS).GetPt() );
+       //cout<<" fPtref = " <<fPtref<<"\n";
        if(fPtref>1.0) fChi2max=40.;         
        if(fPtref<=1.0) fChi2max=20.;
        if(fPtref<0.4 ) fChi2max=100.;
@@ -519,7 +705,7 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
        // if(fPtref<0.2 ) fChi2max=20.;
        //if(fPtref<0.2 ) fChi2max=10.;
        //if(fPtref<0.1 ) fChi2max=5.;
-       cout << "\n Pt = " << fPtref <<"\n";  //stampa
+       //cout << "\n Pt = " << fPtref <<"\n";  //stampa
        RecursiveTracking(list);   
        list->Delete();
        delete list;
@@ -534,12 +720,12 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
            for(k=0; k<3; k++){  
                Int_t lpp=(Int_t)vecLabRef(k);
                if(lpp>=0) {
-                   TParticle *p=(TParticle*) gAlice->Particle(lpp);
+                   TParticle *p=(TParticle*) gAlice->GetMCApp()->Particle(lpp);
                    Int_t pcode=p->GetPdgCode();
                    if(pcode==11) vecLabRef(k)=p->GetFirstMother();
                } // end if
                itot++; vecTotLabRef(itot)=vecLabRef(k);
-               if(vecLabRef(k)==0. && clustZ == 0.) vecTotLabRef(itot) =-3.;
+               if(vecLabRef(k)==0. && clustZ == -1.) vecTotLabRef(itot) =-3.;
            } // end for k
        } // end for lay
        Long_t labref;
@@ -553,14 +739,15 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
        // cout<<" progressive track number = "<<j<<"\r";
        // cout<<j<<"\r";
        Int_t numOfCluster=(*fresult).GetNumClust();  
-       cout<<" progressive track number = "<<j<<"\n";    // stampa
+       //cout<<" progressive track number = "<<j<<"\n";    // stampa
        Long_t labITS=(*fresult).GetLabel();
-       cout << " ITS track label = " << labITS << "\n";        // stampa           
+       //cout << " ITS track label = " << labITS << "\n";      // stampa           
        Int_t lab=track->GetLabel();                
-       cout << " TPC track label = " << lab <<"\n";      // stampa
+       //cout << " TPC track label = " << lab <<"\n";      // stampa
        //propagation to vertex
 
        Double_t rbeam=3.;
+       if((*fresult).DoNotCross(rbeam)) continue;  //no intersection with beampipe     
        (*fresult).Propagation(rbeam);
        Double_t c00,c10,c11,c20,c21,c22,c30,c31,c32,c33,c40,c41,c42,c43,c44;
        (*fresult).GetCElements(c00,
@@ -599,6 +786,8 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
            Int_t charge;
            if(c>0.) charge=-1;  else charge=1;
            ioTrack->SetCharge(charge);
+               Double_t trackmass=(*fresult).GetMass();         // oggi
+               ioTrack->SetMass(trackmass);                     // oggi
            ioTrack->SetCovMatrix(c00,
                                  c10,c11,
                                  c20,c21,c22,
@@ -618,24 +807,75 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
            ioTrack->SetZ(ztrack);
            ioTrack->SetLabel(labITS);
            ioTrack->SetTPCLabel(lab);
+                ioTrack->SetDz(dz);
            Int_t il;           
-           for(il=0;il<6; il++){
+           /*
+               for(il=0;il<6; il++){
                ioTrack->SetIdPoint(il,(*fresult).GetIdPoint(il));
                ioTrack->SetIdModule(il,(*fresult).GetIdModule(il));
            } // end for il
-           tracktree1.Fill();
+           */
+           //tracktree1.Fill();
+               Float_t q[4]={-1.,-1.,-1.,-1.};
+           Float_t  globaldedx=0.;        
            for (il=0;il<6;il++) {
                idpoint=(*fresult).GetIdPoint(il);
                idmodule=(*fresult).GetIdModule(il);
-               //*(fvettid[idmodule]+idpoint)=1; 
-               if(idmodule>0.) *(fvettid[idmodule]+idpoint)=1;//modificata
-                                                              // angela
+               if(idmodule>0.) *(fvettid[idmodule]+idpoint)=1;
+                                                              
                ioTrack->SetIdPoint(il,idpoint);
                ioTrack->SetIdModule(il,idmodule);
-           } // end for il         
+               ////  for q definition
+               if(il>1){
+                 if(idmodule>0.){                      
+                   fITS->ResetRecPoints();
+                   gAlice->TreeR()->GetEvent(idmodule);
+                   recp=(AliITSRecPoint*)frecPoints->UncheckedAt(idpoint);
+                   q[il-2]=recp->GetQ()*(*fresult).Getfcor(il-2);
+                 }
+               }                               
+           } // end for il      
+               q[0]/=280.; q[1]/=280.;
+           q[2]/=38.; q[3]/=38.;
+
+ // cout<<" q prima = "<<q[0]<<" "<<q[1]<<" "<<q[2]<<" "<<q[3]<<"\n"; getchar(); 
+     
+     Int_t swap;
+  do{
+    swap=0;   
+    for (il=0; il<3; il++) {
+      if (q[il]<=q[il+1]) continue;
+      Float_t tmp=q[il];
+      q[il]=q[il+1]; q[il+1]=tmp;
+      swap++;
+    }
+  } while(swap); 
+
+  // cout<<" q dopo = "<<q[0]<<" "<<q[1]<<" "<<q[2]<<" "<<q[3]<<"\n"; getchar();
+      
+    if(q[0]<0.) {
+      q[0]=q[1];
+      q[1]=q[2];
+      q[2]=q[3];
+      q[3]=-1.;            
+    } 
+  // cout<<" q  dopo if = "<<q[0]<<" "<<q[1]<<" "<<q[2]<<" "<<q[3]<<"\n"; getchar(); 
+     
+    globaldedx=(q[0]+q[1])/2.;
+    
+   // if(q[3]> 0.) globaldedx=(q[0]+q[1]+q[2]+q[3])/4.;
+   //      else    globaldedx=(q[0]+q[1]+q[2])/3.; 
+   
+    ioTrack->SetdEdx(globaldedx);
+    ioTrack->SetPid(pid->GetPcode(ioTrack));
+           
+           tracktree1.Fill();         
        } // end if on numOfCluster
        //gObjectTable->Print();    // stampa memoria     
     }  //  end for (int j=minTr; j<=maxTr; j++)
+    delete db;          
     static Bool_t first=kTRUE;
     static TFile *tfile;
     if(first) {
@@ -647,6 +887,7 @@ void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
     tfile->ls();
     char hname[30];
     sprintf(hname,"TreeT%d",evNumber);
+       cout << "Number of saved ITS tracks " << tracktree1.GetEntries() << endl;
     tracktree1.Write(hname);
   
     TTree *fAli=gAlice->TreeK();
@@ -727,7 +968,7 @@ void AliITSTrackerV1::RecursiveTracking(TList *trackITSlist) {
 
            if(numClustNow<numClustRef && chi2Now>fresult->GetChi2()) continue;
            //cout<<" chi2Now =  "<<chi2Now<<"\n";   
-           //  commentato il 30-7-2001   
+             
            chi2Now/=numClustNow;
            if(fPtref > 1.0 && chi2Now > 30.) continue; 
            if((fPtref >= 0.6 && fPtref<=1.0) && chi2Now > 40.) continue;
@@ -744,13 +985,7 @@ void AliITSTrackerV1::RecursiveTracking(TList *trackITSlist) {
        Int_t ladp, ladm, detp,detm,ladinters,detinters;        
        Int_t layerfin=layerInit-1;
        // cout<<"Prima di intersection \n";
-       //if(!fTimerIntersection) fTimerIntersection = new TStopwatch();
-       // timer
-       //fTimerIntersection->Continue();
-       // timer 
        Int_t  outinters=Intersection(*trackITS,layerfin,ladinters,detinters);
-       //fTimerIntersection->Stop();
-       // timer
        // cout<<" outinters = "<<outinters<<"\n";
        //  cout<<" Layer ladder detector intersection ="
        //      <<layerfin<<" "<<ladinters<<" "<<detinters<<"\n";
@@ -758,6 +993,8 @@ void AliITSTrackerV1::RecursiveTracking(TList *trackITSlist) {
        //       << " "<<(*trackITS)(1)<<"\n"; getchar();
        if(outinters==-1) continue;
        Int_t flaghit=0;
+       (*trackITS).SetLayer(layerfin);  // oggi
+       (*trackITS).Setfcor();           // oggi
        if(outinters==0){
            TVector toucLad(9), toucDet(9);      
            Int_t lycur=layerfin;
@@ -789,7 +1026,7 @@ void AliITSTrackerV1::RecursiveTracking(TList *trackITSlist) {
            */
            Float_t epsphi=5.0, epsz=5.0;                  
            if(fPtref<0.2) {epsphi=3.; epsz=3.;}     
-           // nuova definizione idetot e toucLad e toucDet to be
+           // new definition of idetot e toucLad e toucDet to be
            // transformed in a method
            // these values could be modified
            Float_t pigre=TMath::Pi();
@@ -822,11 +1059,12 @@ void AliITSTrackerV1::RecursiveTracking(TList *trackITSlist) {
            Float_t distz = 0.0;
            Float_t phicm, phicp, distphim, distphip;
            phicm=phinters;
-           if(phinters>fphimax[layerfin-1][ladm]) phicm=phinters-2*pigre;
-           distphim=TMath::Abs(phicm-fphimax[layerfin-1][ladm]);
+                if(phinters>fphimax[layerfin-1][ladm-1]) phicm=phinters-2*pigre;  //corretto il 20-11-2001
+                distphim=TMath::Abs(phicm-fphimax[layerfin-1][ladm-1]);  //corretto il 20-11-2001
            phicp=phinters;
-           if(phinters>fphimin[layerfin-1][ladp]) phicp=phinters-2.*pigre;
-           distphip=TMath::Abs(phicp-fphimin[layerfin-1][ladp]);
+                //cout<<" fNlad[layerfin-1] e ladp = "<<fNlad[layerfin-1]<<" "<<ladp<<endl;
+                if(phinters>fphimin[layerfin-1][ladp-1]) phicp=phinters-2.*pigre;   //corretto il 20-11-2001
+                distphip=TMath::Abs(phicp-fphimin[layerfin-1][ladp-1]);      //corretto il 20-11-2001
            Int_t flagzmin=0;
            Int_t flagzmax=0;
            idetot=1;
@@ -895,74 +1133,39 @@ void AliITSTrackerV1::RecursiveTracking(TList *trackITSlist) {
                ///////////////////////////////////////////////////////
                /*** Rec points sorted by module *****/
                /**************************************/
-               Int_t indexmod;       //mod ott
-               // AliITSRecPoint *recp;
+               Int_t indexmod;       
                indexmod = g1->GetModuleIndex(lycur,(Int_t)toucLad(iriv),
-                                             (Int_t)toucDet(iriv));
-               //mod ott 
+                                             (Int_t)toucDet(iriv)); 
                fITS->ResetRecPoints();   
                gAlice->TreeR()->GetEvent(indexmod); 
                Int_t npoints=frecPoints->GetEntries();
-               /* mod ott
-                  Int_t *indlist=new Int_t[npoints+1];
-                  Int_t counter=0;
-                  Int_t ind;
-                  for (ind=0; ind<=npoints; ind++) {
-                       indlist[ind]=-1;
-                       if (*(fvettid[index]+ind)==0) {
-                            indlist[counter]=ind;
-                            counter++;
-                       } // end if
-                  } // end for ind
-                  ind=-1;
-                  for(;;) { 
-                        ind++;
-                        if(indlist[ind] < 0) recp=0;
-                        else 
-                             recp = (AliITSRecPoint*)frecPoints->
-                                                    UncheckedAt(indlist[ind]);
-                       if((!recp)  )  break;
-                  } // end for ;;
-               */
-               ///////////////////////// new //////////////////////////       
+       
                Int_t indnew;
                for(indnew=0; indnew<npoints; indnew++){
                    if (*(fvettid[indexmod]+indnew)==0)
                        recp =(AliITSRecPoint*)frecPoints->UncheckedAt(indnew);
                    else
                        continue;
-                   ////////////////////////////////////////////////////
                    TVector cluster(3),vecclust(9);
-                   vecclust(6)=vecclust(7)=vecclust(8)=-1.;
-                   Double_t sigma[2];               
-                   // set veclust in global
-                   Float_t global[3], local[3];
-                   local[0]=recp->GetX();
-                   local[1]=0.;
-                   local[2]= recp->GetZ();
-                   Int_t play = lycur;
-                   Int_t plad = TMath::Nint(toucLad(iriv));   
-                   Int_t pdet = TMath::Nint(toucDet(iriv));            
-                   g1->LtoG(play,plad,pdet,local,global);
-                   vecclust(0)=global[0];
-                   vecclust(1)=global[1];
-                   vecclust(2)=global[2];
-
+                   //vecclust(6)=vecclust(7)=vecclust(8)=-1.;
+                   Double_t sigma[2];
+  // now vecclust is with cylindrical cohordinates
+              vecclust(0)=(Float_t)fRecCylR[indexmod][indnew];     
+              vecclust(1)=(Float_t)fRecCylPhi[indexmod][indnew];
+              vecclust(2)=(Float_t)fRecCylZ[indexmod][indnew];                          
                    vecclust(3) = (Float_t)recp->fTracks[0]; 
-                   //vecclust(4) = (Float_t)indlist[ind];
                    vecclust(4) = (Float_t)indnew;                       
-                   vecclust(5) = (Float_t)indexmod;    //mod ott
+                   vecclust(5) = (Float_t)indexmod;    
                    vecclust(6) = (Float_t)recp->fTracks[0];
                    vecclust(7) = (Float_t)recp->fTracks[1];
                    vecclust(8) = (Float_t)recp->fTracks[2];
                    sigma[0] = (Double_t)  recp->GetSigmaX2();     
                    sigma[1] = (Double_t) recp->GetSigmaZ2();
-                   //now we are in r,phi,z in global
-                   cluster(0) = TMath::Sqrt(vecclust(0)*vecclust(0)+
-                                            vecclust(1)*vecclust(1));//r hit
-                   cluster(1) = TMath::ATan2(vecclust(1),vecclust(0));
-                   if(cluster(1)<0.) cluster(1)+=2.*TMath::Pi();
-                   cluster(2) = vecclust(2);                   // z hit
+                        
+                        cluster(0)=fRecCylR[indexmod][indnew];
+          cluster(1)=fRecCylPhi[indexmod][indnew];
+                        cluster(2)=fRecCylZ[indexmod][indnew];
+                        
                    // cout<<" layer = "<<play<<"\n";
                    // cout<<" cluster prima = "<<vecclust(0)<<" "
                    //     <<vecclust(1)<<" "
@@ -989,7 +1192,7 @@ void AliITSTrackerV1::RecursiveTracking(TList *trackITSlist) {
                        continue;
                    // cout<<" supero sigmaphi \n";      
                    AliITSTrackV1 *newTrack = new AliITSTrackV1((*trackITS));
-                   (*newTrack).SetLayer((*trackITS).GetLayer()-1);
+                   //(*newTrack).SetLayer((*trackITS).GetLayer()-1);
                    if (TMath::Abs(rTrack-cluster(0))/rTrack>1e-6) 
                        (*newTrack).Correct(Double_t(cluster(0)));      
                    //cout<<" cluster(2) e(*newTrack).GetZ()="<<cluster(2)<<" "
@@ -1008,34 +1211,30 @@ void AliITSTrackerV1::RecursiveTracking(TList *trackITSlist) {
                    // cout<<" chi2pred = "<<chi2pred<<"\n";
                    // if(chi2pred>fChi2max) continue; //aggiunto il 30-7-2001
                    if(iriv == 0) flaghit=1;
-                   (*newTrack).AddMS(frl);  // add the multiple scattering 
+                   (*newTrack).AddMS();  // add the multiple scattering 
                                             //matrix to the covariance matrix 
-                   (*newTrack).AddEL(frl,1.,0);
+                   (*newTrack).AddEL(1.,0);
 
-                   //if(!fTimerKalman) fTimerKalman = new TStopwatch();//timer
-                   //fTimerKalman->Continue();                        // timer
                    if(fflagvert){
                        KalmanFilterVert(newTrack,cluster,sigmanew);
                        //KalmanFilterVert(newTrack,cluster,sigmanew,chi2pred);
                    }else{
                        KalmanFilter(newTrack,cluster,sigmanew);
                    } // end if
-                   //fTimerKalman->Stop();                         // timer
                    (*newTrack).PutCluster(layernew, vecclust);
                    newTrack->AddClustInTrack();
                    listoftrack.AddLast(newTrack);
                }   // end for indnew
-               // delete [] indlist;  //mod ott
            }  // end of for on detectors (iriv)
        }//end if(outinters==0)
 
        if(flaghit==0 || outinters==-2) {
            AliITSTrackV1 *newTrack = new AliITSTrackV1(*trackITS);
            (*newTrack).Setfnoclust();           
-           (*newTrack).SetLayer((*trackITS).GetLayer()-1); 
-           (*newTrack).AddMS(frl);  // add the multiple scattering matrix
+           //(*newTrack).SetLayer((*trackITS).GetLayer()-1); 
+           (*newTrack).AddMS();  // add the multiple scattering matrix
                                     // to the covariance matrix  
-           (*newTrack).AddEL(frl,1.,0);
+           (*newTrack).AddEL(1.,0);
            listoftrack.AddLast(newTrack);
        } // end if
 
@@ -1493,3 +1692,4 @@ void AliITSTrackerV1::KalmanFilterVert(AliITSTrackV1 *newTrack,
     newTrack->SetChi2(newTrack->GetChi2()+chi2);   
     //   newTrack->SetChi2(newTrack->GetChi2()+chi2pred);
 }
+