track labels added
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITStrackerUpgrade.cxx
index 636057153e4f8532055f21c08a972542dbf0950e..c04ac12728583c0d335c4196349ad79b9097651a 100644 (file)
@@ -71,6 +71,7 @@ ClassImp(AliITStrackerUpgrade)
                                               fMinNPoints(0),
                                               fMinQ(0.),
                                               fLayers(0),
+                                               fSegmentation(0x0),
                                               fCluLayer(0),
                                               fCluCoord(0){
     // Default constructor
@@ -101,6 +102,7 @@ AliITStrackerUpgrade::AliITStrackerUpgrade(const AliITStrackerUpgrade& tracker):
                                                                                fMinNPoints(tracker.fMinNPoints),
                                                                                fMinQ(tracker.fMinQ),
                                                                                fLayers(tracker.fLayers),
+                                                                               fSegmentation(tracker.fSegmentation),
                                                                                fCluLayer(tracker.fCluLayer),
                                                                                fCluCoord(tracker.fCluCoord) {
   // Copy constructor
@@ -166,6 +168,7 @@ AliITStrackerUpgrade::~AliITStrackerUpgrade(){
     delete [] fCluCoord;
   }
   
+ if(fSegmentation) delete fSegmentation;
 }
 
 //____________________________________________________________________________
@@ -224,15 +227,13 @@ void AliITStrackerUpgrade::Init(){
   fCluLayer = 0;
   fCluCoord = 0;
   fMinNPoints = 3;
-  //AliITSsegmentationUpgrade *segmentation2 = 0x0;
-  //if(!segmentation2)
-  //  segmentation2 = new AliITSsegmentationUpgrade();
   for(Int_t layer=0; layer<6; layer++){
     Double_t p=0.;
     Double_t zC= 0.;
     fLayers[layer] = new AliITSlayerUpgrade(p,zC);
   }
 
+  fSegmentation = new AliITSsegmentationUpgrade();
        
 }
 //_______________________________________________________________________
@@ -257,9 +258,6 @@ Int_t AliITStrackerUpgrade::LoadClusters(TTree *clusTree){
       fLayers[recp->GetLayer()]->InsertCluster(new AliITSRecPoint(*recp));
     }//loop clusters
 
-
-
-   
   SetClusterTree(clusTree);
   return 0;
 }
@@ -376,7 +374,7 @@ Int_t AliITStrackerUpgrade::FindTracks(AliESDEvent* event,Bool_t useAllClusters)
         new (clucoo[dmar[ilay]]) AliITSclusterTable(x,y,z,sx,sy,sz,phi,lambda,cli);
         dmar[ilay]++;
       }
-    }
+    } else AliDebug(2,Form("Force skipping layer %i",ilay));
   }
 
 
@@ -621,8 +619,7 @@ AliITStrackV2* AliITStrackerUpgrade::FitTrack(AliITStrackSA* tr,Double_t *primar
               Double_t yclu1 = p1->GetY();
               Double_t zclu1 = p1->GetZ();
              layer=p1->GetLayer();
-             AliITSsegmentationUpgrade *segmentation = new AliITSsegmentationUpgrade();
-             radius=segmentation->GetRadius(layer);
+             fSegmentation->GetRadius(layer);
              Double_t cv=0.,tgl2=0.,phi2=0.;
              Int_t cln1=mrk1;
              AliITSclusterTable* arr1 = (AliITSclusterTable*)GetClusterCoord(firstLay,cln1);
@@ -651,7 +648,7 @@ AliITStrackV2* AliITStrackerUpgrade::FitTrack(AliITStrackSA* tr,Double_t *primar
              xz[0]= p1->GetDetLocalX(); 
              xz[1]= p1->GetDetLocalZ();   
              Bool_t check2;
-             check2 = segmentation->DetToGlobal(layer,xz[0], xz[1],x,y,z);
+             check2 = fSegmentation->DetToGlobal(layer,xz[0], xz[1],x,y,z);
 
 
               Double_t phiclrad, phicldeg;
@@ -700,14 +697,14 @@ AliITStrackV2* AliITStrackerUpgrade::FitTrack(AliITStrackSA* tr,Double_t *primar
              // Propagate inside the innermost layer with a cluster 
              if(ot.Propagate(ot.GetX()-0.1*ot.GetX())) {
                Double_t rt=0.;
-               rt=segmentation->GetRadius(5);
+               rt=fSegmentation->GetRadius(5);
                if(RefitAtBase(rt,&ot,inx)){ //fit from layer 1 to layer 6
                  AliITStrackMI otrack2(ot);
                  otrack2.ResetCovariance(10.); 
                  otrack2.ResetClusters();
                  
                  //fit from layer 6 to layer 1
-                 if(RefitAtBase(/*AliITSRecoParam::GetrInsideSPD1()*/segmentation->GetRadius(0),&otrack2,inx)) {//check clind
+                 if(RefitAtBase(/*AliITSRecoParam::GetrInsideSPD1()*/fSegmentation->GetRadius(0),&otrack2,inx)) {//check clind
                    new(arrMI[nFoundTracks]) AliITStrackMI(otrack2);
                    new(arrSA[nFoundTracks]) AliITStrackSA(trac);
                    ++nFoundTracks;
@@ -734,6 +731,12 @@ AliITStrackV2* AliITStrackerUpgrade::FitTrack(AliITStrackSA* tr,Double_t *primar
   if(otrack==0) {
     return 0;
   }
+
+  CookLabel(otrack,0.); //MI change - to see fake ratio
+  Int_t label=FindLabel(otrack);
+  otrack->SetLabel(label);
+
+
   Int_t indexc[6];
   for(Int_t i=0;i<6;i++) indexc[i]=0;
   for(Int_t nind=0;nind<otrack->GetNumberOfClusters();nind++){
@@ -776,8 +779,6 @@ void AliITStrackerUpgrade::StoreTrack(AliITStrackV2 *t,AliESDEvent *event, Bool_
 Int_t AliITStrackerUpgrade::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
 
-   AliITSsegmentationUpgrade *segmentation = new AliITSsegmentationUpgrade();
-
   AliDebug(2,"Starting...");
   if(ForceSkippingOfLayer(layer)) {
   AliDebug(2,Form("Forcing skipping of layer %i. Exiting",layer));
@@ -785,7 +786,7 @@ Int_t AliITStrackerUpgrade::SearchClusters(Int_t layer,Double_t phiwindow,Double
   }
 
   Int_t nc=0;
-  Double_t r=segmentation->GetRadius(layer);
+  Double_t r=fSegmentation->GetRadius(layer);
   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);
@@ -833,7 +834,6 @@ Int_t AliITStrackerUpgrade::SearchClusters(Int_t layer,Double_t phiwindow,Double
     fPointc[0]=arr->GetX();
     fPointc[1]=arr->GetY();
   }
-  delete segmentation;
   return nc;
 }
 
@@ -963,49 +963,61 @@ Int_t AliITStrackerUpgrade::FindTrackLowChiSquare() const {
 }
 
 //__________________________________________________________
-/*Int_t AliITStrackerUpgrade::FindLabel(Int_t l0, Int_t l1, Int_t l2, Int_t l3, Int_t l4, Int_t l5){
+Int_t AliITStrackerUpgrade::FindLabel(AliITStrackV2* track) const {
+  //
 
-//function used to determine the track label
-  
-Int_t lb[6] = {l0,l1,l2,l3,l4,l5};
-Int_t aa[6]={1,1,1,1,1,1};
-Int_t ff=0; 
-Int_t ll=0;
-Int_t k=0;Int_t w=0;Int_t num=6;
-for(Int_t i=5;i>=0;i--) if(lb[i]==-1) num=i;
-  
-while(k<num){
-  
-for(Int_t i=k+1;i<num;i++){
-    
-if(lb[k]==lb[i] && aa[k]!=0){
-      
-aa[k]+=1;
-aa[i]=0;
-}
-}
-k++;
-}
+  Int_t labl[AliITSgeomTGeo::kNLayers][3];
+  Int_t cnts[AliITSgeomTGeo::kNLayers][3];
+  for(Int_t j=0;j<AliITSgeomTGeo::GetNLayers();j++){
+    for(Int_t k=0;k<3;k++){
+      labl[j][k]=-2;
+      cnts[j][k]=1;
+    }
+  }
+  Int_t iNotLabel=0;
+  for(Int_t i=0;i<track->GetNumberOfClusters(); i++) {
+    Int_t indexc = track->GetClusterIndex(i);
+    AliITSRecPoint* cl = (AliITSRecPoint*)GetCluster(indexc);
+    AliDebug(2,Form(" cluster index %i  ",indexc));
+    Int_t iLayer=cl->GetLayer();
+    for(Int_t k=0;k<3;k++){
+      labl[iLayer][k]=cl->GetLabel(k);
+      if(labl[iLayer][k]<0) iNotLabel++;
+    }
+  }
+  if(iNotLabel==3*track->GetNumberOfClusters()) return -2;
+
+  for(Int_t j1=0;j1<AliITSgeomTGeo::kNLayers; j1++) {
+    for(Int_t j2=0; j2<j1;  j2++){
+      for(Int_t k1=0; k1<3; k1++){
+        for(Int_t k2=0; k2<3; k2++){
+          if(labl[j1][k1]>=0 && labl[j1][k1]==labl[j2][k2] && cnts[j2][k2]>0){
+            cnts[j2][k2]++;
+            cnts[j1][k1]=0;
+          }
+        }
+      }
+    }
+  }
 
-while(w<num){
-for(Int_t j=0;j<6;j++){
-if(aa[w]<aa[j]){
-ff=aa[w];
-aa[w]=aa[j];
-aa[j]=ff;
-ll=lb[w];
-lb[w]=lb[j];
-lb[j]=ll;
-}
-}
-w++;
-}
-  
-if(num<1) return -1; 
-return lb[num-1];
+
+  Int_t cntMax=0;
+  Int_t label=-1;
+  for(Int_t j=0;j<AliITSgeomTGeo::kNLayers;j++){
+    for(Int_t k=0;k<3;k++){
+      if(cnts[j][k]>cntMax && labl[j][k]>=0){
+        cntMax=cnts[j][k];
+        label=labl[j][k];
+      }
+    }
+  }
+
+  Int_t lflag=0;
+  for(Int_t i=0;i<AliITSgeomTGeo::kNLayers;i++)
+  if(labl[i][0]==label || labl[i][1]==label || labl[i][2]==label) lflag++;
+  if(lflag<track->GetNumberOfClusters()) label = -label;
+  return label;
 }
-*/
 //_____________________________________________________________________________
 /*Int_t AliITStrackerUpgrade::Label(Int_t gl1, Int_t gl2, Int_t gl3, Int_t gl4, Int_t gl5, Int_t gl6,Int_t gl7, Int_t gl8, Int_t gl9, Int_t gl10,Int_t gl11,
   Int_t gl12, Int_t gl13, Int_t gl14,Int_t gl15, Int_t gl16, Int_t gl17, Int_t gl18, Int_t minNPoints){
@@ -1113,16 +1125,14 @@ void AliITStrackerUpgrade::GetCoorAngles(AliITSRecPoint* cl,Double_t &phi,Double
   Double_t xz[2];
   xz[0]= cl->GetDetLocalX(); 
   xz[1]= cl->GetDetLocalZ() ; 
-  AliITSsegmentationUpgrade *segmentation2 = new AliITSsegmentationUpgrade();
   Bool_t check2;
   Int_t ilayer;
   ilayer = cl->GetLayer();
-  check2 = segmentation2->DetToGlobal(ilayer,xz[0], xz[1],x,y,z);
+  check2 = fSegmentation->DetToGlobal(ilayer,xz[0], xz[1],x,y,z);
 
   if(x!=0 && y!=0)  
     phi=TMath::ATan2(y-vertex[1],x-vertex[0]);
   lambda=TMath::ATan2(z-vertex[2],TMath::Sqrt((x-vertex[0])*(x-vertex[0])+(y-vertex[1])*(y-vertex[1])));
-  if(segmentation2) delete segmentation2;
 }
 
 //________________________________________________________________________
@@ -1180,7 +1190,6 @@ Bool_t AliITStrackerUpgrade::RefitAtBase(Double_t xx,AliITStrackMI *track,
   for (k=0; k<AliITSgeomTGeo::GetNLayers(); k++) {
     index[k]=clusters[k];
   }
-  AliITSsegmentationUpgrade *segmentation = new AliITSsegmentationUpgrade();
 
   ULong_t trStatus=0;
   if(track->GetESDtrack()) trStatus=track->GetStatus();
@@ -1189,7 +1198,7 @@ Bool_t AliITStrackerUpgrade::RefitAtBase(Double_t xx,AliITStrackMI *track,
     innermostlayer=5;
     Double_t drphi = TMath::Abs(track->GetD(0.,0.));
     for(innermostlayer=0; innermostlayer<AliITSgeomTGeo::GetNLayers(); innermostlayer++) {
-      if( (drphi < (segmentation->GetRadius(innermostlayer)+1.)) ||
+      if( (drphi < (fSegmentation->GetRadius(innermostlayer)+1.)) ||
           index[innermostlayer] >= 0 ) break;
     }
     AliDebug(2,Form(" drphi  %f  innermost %d",drphi,innermostlayer));
@@ -1207,7 +1216,7 @@ Bool_t AliITStrackerUpgrade::RefitAtBase(Double_t xx,AliITStrackMI *track,
 
   for (Int_t ilayer = from; ilayer != to; ilayer += step) {
     Double_t r=0.;
-    r=segmentation->GetRadius(ilayer);
+    r=fSegmentation->GetRadius(ilayer);
 
     if (step<0 && xx>r){
       break;
@@ -1224,7 +1233,6 @@ Bool_t AliITStrackerUpgrade::RefitAtBase(Double_t xx,AliITStrackMI *track,
     Double_t oldGlobXYZ[3];
 
     if (!track->GetXYZ(oldGlobXYZ)) {
-      if(segmentation) delete segmentation;
       return kFALSE;
     }
     // continue if we are already beyond this layer
@@ -1237,7 +1245,6 @@ Bool_t AliITStrackerUpgrade::RefitAtBase(Double_t xx,AliITStrackMI *track,
     }
     Double_t phi,z;
     if (!track->GetPhiZat(r,phi,z)){
-      if(segmentation) delete segmentation;
       return kFALSE;
     }
     // only for ITS-SA tracks refit
@@ -1251,7 +1258,6 @@ Bool_t AliITStrackerUpgrade::RefitAtBase(Double_t xx,AliITStrackMI *track,
     Double_t alpha= (ladder*18.+9.)*TMath::Pi()/180.;
     
     if (!track->Propagate(alpha,r)) {
-      if(segmentation) delete segmentation;
       return kFALSE;
     }
 
@@ -1270,7 +1276,6 @@ Bool_t AliITStrackerUpgrade::RefitAtBase(Double_t xx,AliITStrackMI *track,
          clAcc=cl;                                                              
          maxchi2=chi2;                                                          
        } else {                                                                 
-           if(segmentation) delete segmentation;
           return kFALSE;                                                         
        }                                                                        
       }                                                                          
@@ -1278,7 +1283,6 @@ Bool_t AliITStrackerUpgrade::RefitAtBase(Double_t xx,AliITStrackMI *track,
 
     if (clAcc) {
       if (!UpdateMI(track,clAcc,maxchi2,idx)){
-        if(segmentation) delete segmentation;
        return kFALSE;
       }
       track->SetSampledEdx(clAcc->GetQ(),ilayer-2);
@@ -1289,17 +1293,14 @@ Bool_t AliITStrackerUpgrade::RefitAtBase(Double_t xx,AliITStrackMI *track,
     // cross material
     // add time if going outward
     if(!CorrectForLayerMaterial(track,ilayer,oldGlobXYZ,dir)){
-      if(segmentation) delete segmentation;
       return kFALSE;
     }
     track->SetCheckInvariant(kFALSE);
   } // end loop on layers
 
   if (!track->PropagateTo(xx,0.,0.)){
-    if(segmentation) delete segmentation;
     return kFALSE;
   } 
-  if(segmentation) delete segmentation;
   return kTRUE;
 }
 
@@ -1383,10 +1384,7 @@ Int_t AliITStrackerUpgrade::CorrectForLayerMaterial(AliITStrackMI *t,
   }
   Float_t  dir = (direction.Contains("inward") ? 1. : -1.);
   Double_t r = 0.;
-  AliITSsegmentationUpgrade *segmentation = 0x0;
-  if(!segmentation)
-    segmentation = new AliITSsegmentationUpgrade();
-  r=segmentation->GetRadius(layerindex);
+  r=fSegmentation->GetRadius(layerindex);
   Double_t deltar=(layerindex<2 ? 0.10*r : 0.05*r);
   Double_t rToGo=TMath::Sqrt(t->GetX()*t->GetX()+t->GetY()*t->GetY())-deltar*dir;
   Double_t xToGo;
@@ -1407,7 +1405,7 @@ Int_t AliITStrackerUpgrade::CorrectForLayerMaterial(AliITStrackMI *t,
   switch(mode) {
   case 1:
     x0=21.82;
-    xOverX0 = segmentation->GetThickness(layerindex)/x0;
+    xOverX0 = fSegmentation->GetThickness(layerindex)/x0;
 
     lengthTimesMeanDensity = xOverX0*x0;
     lengthTimesMeanDensity *= dir;
@@ -1572,6 +1570,7 @@ Int_t AliITStrackerUpgrade::PropagateBack(AliESDEvent *event) {
     if ((esd->GetStatus()&AliESDtrack::kITSin)==0) continue;
     if (esd->GetStatus()&AliESDtrack::kITSout) continue;
 
+/*
     AliITStrackMI *t=0;
     try {
       t=new AliITStrackMI(*esd);
@@ -1580,6 +1579,8 @@ Int_t AliITStrackerUpgrade::PropagateBack(AliESDEvent *event) {
       delete t;
       continue;
     }
+*/
+    AliITStrackMI *t = new AliITStrackMI(*esd);
     t->SetExpQ(TMath::Max(0.8*t->GetESDtrack()->GetTPCsignal(),30.));
 
     ResetTrackToFollow(*t);
@@ -1621,7 +1622,7 @@ Int_t AliITStrackerUpgrade::PropagateBack(AliESDEvent *event) {
       //fTrackToFollow.CookdEdx();
       //CookLabel(&fTrackToFollow,0.); //For comparison only
       fTrackToFollow.UpdateESDtrack(AliESDtrack::kITSout);
-      UseClusters(&fTrackToFollow);
+      //UseClusters(&fTrackToFollow);
       ntrk++;
     }
     delete t;
@@ -1639,8 +1640,9 @@ AliCluster *AliITStrackerUpgrade::GetCluster(Int_t index) const {
   //       Return pointer to a given cluster
   //--------------------------------------------------------------------
   Int_t l=(index & 0xf0000000) >> 28;
+  Int_t c=(index & 0x0fffffff) >> 0;
   AliInfo(Form("index %i  cluster index %i layer %i", index,index & 0x0fffffff,index & 0xf0000000));
-  return fLayers[l]->GetCluster(index);
+  return fLayers[l]->GetCluster(c);
 }
 //______________________________________________________________________________
 Int_t AliITStrackerUpgrade::CorrectForPipeMaterial(AliITStrackMI *t, TString direction) {
@@ -1689,15 +1691,15 @@ if (!t->GetLocalXat(rToGo,xToGo)) return 0;
 Double_t xOverX0,x0,lengthTimesMeanDensity;
 
 switch(mode) {
- case 1:
+ case 0:
    xOverX0 = AliITSRecoParam::GetdPipe();
    x0 = AliITSRecoParam::GetX0Be();
    lengthTimesMeanDensity = xOverX0*x0;
    lengthTimesMeanDensity *= dir;
    if (!t->PropagateTo(xToGo,xOverX0,lengthTimesMeanDensity/xOverX0)) return 0;
    break;
- case 0:
-   if (!t->PropagateToTGeo(xToGo,1)) return 0;
+ case 1:
+   if (!t->PropagateToTGeo(xToGo,20)) return 0; // "20" removes the d0 mean shift of ~20 um -> To be understood.   
    break;
  case 2:
    if(fxOverX0Pipe<0) BuildMaterialLUT("Pipe");