]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSClusterFinder.cxx
Fixed https://savannah.cern.ch/bugs/?88157
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinder.cxx
index de400891a834622a5e8d7c903ed076883c34d19a..52bc25b816d8afdb0c3735ae5005b9199449bd2c 100644 (file)
@@ -28,7 +28,9 @@
 #include "AliITSMap.h"
 #include "AliITSgeomTGeo.h"
 #include <TParticle.h>
+#include <TArrayI.h>
 #include "AliMC.h"
+#include "AliLog.h"
 
 ClassImp(AliITSClusterFinder)
 
@@ -49,7 +51,10 @@ fEvent(0),
 fZmin(0),
 fZmax(0),
 fXmin(0),
-fXmax(0){
+fXmax(0),
+fNClusters(0),
+fRawID2ClusID(0)
+{
     // default cluster finder
     // Input:
     //   none.
@@ -57,6 +62,10 @@ fXmax(0){
     //   none.
     // Return:
     //   A default constructed AliITSCulsterFinder
+  for(Int_t i=0; i<2200; i++){
+    fNdet[i]=0;
+    fNlayer[i]=0;
+  }
 }
 //----------------------------------------------------------------------
 AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp):
@@ -73,7 +82,10 @@ fEvent(0),
 fZmin(0),
 fZmax(0),
 fXmin(0),
-fXmax(0){
+fXmax(0),
+fNClusters(0),
+fRawID2ClusID(0)
+{
     // default cluster finder
     // Standard constructor for cluster finder
     // Input:
@@ -83,7 +95,10 @@ fXmax(0){
     //   none.
     // Return:
     //   A Standard constructed AliITSCulsterFinder
-
+  for(Int_t i=0; i<2200; i++){
+    fNdet[i]=0;
+    fNlayer[i]=0;
+  }
 }
 //----------------------------------------------------------------------
 AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp,
@@ -101,7 +116,10 @@ fEvent(0),
 fZmin(0),
 fZmax(0),
 fXmin(0),
-fXmax(0){
+fXmax(0),
+fNClusters(0),
+fRawID2ClusID(0)
+{
     // default cluster finder
     // Standard + cluster finder constructor
     // Input:
@@ -113,7 +131,11 @@ fXmax(0){
     // Return:
     //   A Standard constructed AliITSCulsterFinder
 
-    fNdigits = fDigits->GetEntriesFast();
+  fNdigits = fDigits->GetEntriesFast();
+  for(Int_t i=0; i<2200; i++){
+    fNdet[i]=0;
+    fNlayer[i]=0;
+  }
 }
 
 //______________________________________________________________________
@@ -131,7 +153,9 @@ AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) :
   fZmin(source.fZmin),
   fZmax(source.fZmax),
   fXmin(source.fXmin),
-  fXmax(source.fXmax) 
+  fXmax(source.fXmax),
+  fNClusters(source.fNClusters),
+  fRawID2ClusID(source.fRawID2ClusID) 
 {
   // Copy constructor
   // Copies are not allowed. The method is protected to avoid misuse.
@@ -282,81 +306,57 @@ istream &operator>>(istream &is,AliITSClusterFinder &source){
     source.Read(&is);
     return is;
 }
+
 //______________________________________________________________________
-void AliITSClusterFinder::CheckLabels2(Int_t lab[10]) {
+void AliITSClusterFinder::CheckLabels2(Int_t lab[10]) 
+{
   //------------------------------------------------------------
   // Tries to find mother's labels
   //------------------------------------------------------------
   AliRunLoader *rl = AliRunLoader::Instance();
   if(!rl) return;
   TTree *trK=(TTree*)rl->TreeK();
-
-  if(trK){
-    Int_t nlabels =0; 
-    for (Int_t i=0;i<10;i++) if (lab[i]>=0) nlabels++;
-    if(nlabels == 0) return; // In case of no labels just exit
-
-
-    Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
-
-    for (Int_t i=0;i<10;i++){
-      Int_t label = lab[i];
-      if (label>=0 && label<ntracks) {
-       TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
-
-       if (part->P() < 0.02) {
-         Int_t m=part->GetFirstMother();
-         if (m<0) {    
-           continue;
-         }
-         if (part->GetStatusCode()>0) {
-           continue;
-         }
-         lab[i]=m;       
-       }
-       else
-         if (part->P() < 0.12 && nlabels>3) {
-           lab[i]=-2;
-           nlabels--;
-         } 
-      }
-      else{
-       if ( (label>ntracks||label <0) && nlabels>3) {
-         lab[i]=-2;
-         nlabels--;
-       } 
-      }
-    }  
-    if (nlabels>3){
-      for (Int_t i=0;i<10;i++){
-       if (nlabels>3){
-         Int_t label = lab[i];
-         if (label>=0 && label<ntracks) {
-           TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
-           if (part->P() < 0.1) {
-             lab[i]=-2;
-             nlabels--;
-           }
-         }
-       }
-      }
-    }
-
-    //compress labels -- if multi-times the same
-    Int_t lab2[10];
-    for (Int_t i=0;i<10;i++) lab2[i]=-2;
-    for (Int_t i=0;i<10  ;i++){
-      if (lab[i]<0) continue;
-      for (Int_t j=0;j<10 &&lab2[j]!=lab[i];j++){
-       if (lab2[j]<0) {
-         lab2[j]= lab[i];
-         break;
-       }
-      }
+  if (!trK) return;
+  //
+  int labS[10];
+  Int_t nlabels = 0; 
+  Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
+  for (Int_t i=0;i<10;i++) if (lab[i]>=0) labS[nlabels++] = lab[i];
+  if (nlabels==0) return;
+  //
+  float mom[10];
+  for (Int_t i=0;i<nlabels;i++) {
+    Int_t label = labS[i];
+    mom[i] = 0;
+    if (label>=ntracks) continue;
+    TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
+    mom[i] = part->P();
+    if (part->P() < 0.02) {    // reduce soft particles from the same cluster
+      Int_t m=part->GetFirstMother();
+      if (m<0) continue; // primary
+      //
+      if (part->GetStatusCode()>0) continue;
+      //
+      // if the parent is within the same cluster, reassign the label to it
+      for (int j=0;j<nlabels;j++) if (labS[j]==m) { labS[i] = m; break;        }
     }
-    for (Int_t j=0;j<10;j++) lab[j]=lab2[j];
-  
+  } 
+  //
+  if (nlabels>3) { // only 3 labels are stored in cluster, sort in decreasing momentum
+    int ind[10],labSS[10];
+    TMath::Sort(nlabels,mom,ind);
+    for (int i=nlabels;i--;) labSS[i] = labS[i];
+    for (int i=0;i<nlabels;i++) labS[i] = labSS[ind[i]]; 
+  }
+  //
+  //compress labels -- if multi-times the same
+  for (Int_t i=0;i<10;i++) lab[i]=-2;
+  int nlabFin=0,j=0;
+  for (int i=0;i<nlabels;i++) {
+    for (j=0;j<nlabFin;j++) if (labS[i]==lab[j]) break; // the label already there
+    if (j==nlabFin) lab[nlabFin++] = labS[i];
   }
+  //
 }
 
 //______________________________________________________________________
@@ -485,7 +485,11 @@ MakeCluster(Int_t k,Int_t max,AliBin *bins,UInt_t m,AliITSRecPoint &c) {
   c.SetSigmaZ2(c.GetSigmaZ2()+j*j*q);
 
   bins[k].SetMask(0xFFFFFFFE);
-  
+  if (fRawID2ClusID) { // RS: Register cluster id in raw words list
+    int rwid = bins[k].GetRawID();
+    if (fRawID2ClusID->GetSize()<=rwid) fRawID2ClusID->Set( (rwid+10)<<1 );
+    (*fRawID2ClusID)[rwid] = fNClusters+1; // RS: store clID+1 as a reference to the cluster
+  }
   if (bins[k-max].GetMask() == m) MakeCluster(k-max,max,bins,m,c);
   if (bins[k-1  ].GetMask() == m) MakeCluster(k-1  ,max,bins,m,c);
   if (bins[k+max].GetMask() == m) MakeCluster(k+max,max,bins,m,c);