]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSClusterFinder.cxx
Removed obsolete and no longer maintained cluster finders
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinder.cxx
index 4d5cfb55c3a38ed9bc382dd86d9681753f397547..2b4d7d055251fb5c651a0d11f8502da3d30c515a 100644 (file)
 // AliITSClusterFinderSDD  AliITSClusterFinderV2                          //
 ////////////////////////////////////////////////////////////////////////////
 
+#include "AliRun.h"
 #include "AliITSClusterFinder.h"
 #include "AliITSRecPoint.h"
 #include "AliITSdigit.h"
 #include "AliITSDetTypeRec.h"
-#include "AliITSgeom.h"
 #include "AliITSMap.h"
+#include "AliITSgeomTGeo.h"
+#include <TParticle.h>
+#include "AliMC.h"
 
 ClassImp(AliITSClusterFinder)
 
+extern AliRun *gAlice;
+
 //----------------------------------------------------------------------
 AliITSClusterFinder::AliITSClusterFinder():
 TObject(),
@@ -36,15 +41,16 @@ fDebug(0),
 fModule(0),
 fDigits(0),
 fNdigits(0),
-fResponse(0),
-fSegmentation(0),
+fDetTypeRec(0),
 fClusters(0),
 fNRawClusters(0),
 fMap(0),
 fNperMax(0),
 fDeclusterFlag(0),
 fClusterSize(0),
-fNPeaks(-1){
+fNPeaks(-1),
+fNModules(AliITSgeomTGeo::GetNModules()),
+fEvent(0){
     // default cluster finder
     // Input:
     //   none.
@@ -54,22 +60,23 @@ fNPeaks(-1){
     //   A default constructed AliITSCulsterFinder
 }
 //----------------------------------------------------------------------
-AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg, 
-                                         AliITSresponse *res):
+AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp):
 TObject(),
 fDebug(0),
 fModule(0),
 fDigits(0),
 fNdigits(0),
-fResponse(res),
-fSegmentation(seg),
+fDetTypeRec(dettyp),
 fClusters(0),
 fNRawClusters(0),
 fMap(0),
 fNperMax(0),
 fDeclusterFlag(0),
 fClusterSize(0),
-fNPeaks(-1){
+fNPeaks(-1),
+fNModules(AliITSgeomTGeo::GetNModules()),
+fEvent(0){
+    // default cluster finder
     // Standard constructor for cluster finder
     // Input:
     //   AliITSsegmentation *seg  The segmentation class to be used
@@ -84,23 +91,24 @@ fNPeaks(-1){
     SetDeclusterFlag();
 }
 //----------------------------------------------------------------------
-AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg, 
-                                         AliITSresponse *response, 
-                                         TClonesArray *digits):
+AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp,
+                                        TClonesArray *digits):
 TObject(),
 fDebug(0),
 fModule(0),
 fDigits(digits),
 fNdigits(0),
-fResponse(response),
-fSegmentation(seg),
+fDetTypeRec(dettyp),
 fClusters(0),
 fNRawClusters(0),
 fMap(0),
 fNperMax(0),
 fDeclusterFlag(0),
 fClusterSize(0),
-fNPeaks(-1){
+fNPeaks(-1),
+fNModules(AliITSgeomTGeo::GetNModules()),
+fEvent(0){
+    // default cluster finder
     // Standard + cluster finder constructor
     // Input:
     //   AliITSsegmentation *seg  The segmentation class to be used
@@ -116,20 +124,36 @@ fNPeaks(-1){
     SetClusterSize();
     SetDeclusterFlag();
 }
+
 //______________________________________________________________________
-AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) : TObject(source) {
+AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) : TObject(source),
+fDebug(source.fDebug),
+fModule(source.fModule),
+fDigits(),
+fNdigits(source.fNdigits),
+fDetTypeRec(),
+fClusters(),
+fNRawClusters(source.fNRawClusters),
+fMap(),
+fNperMax(source.fNperMax),
+fDeclusterFlag(source.fDeclusterFlag),
+fClusterSize(source.fClusterSize),
+fNPeaks(source.fNPeaks),
+fNModules(source.fNModules),
+fEvent(source.fEvent) {
   // Copy constructor
   // Copies are not allowed. The method is protected to avoid misuse.
-  Fatal("AliITSClusterFinder","Copy constructor not allowed\n");
+  AliError("Copy constructor not allowed\n");
 }
 
+
 //______________________________________________________________________
-AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder& /* source */){
+//AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder& /* source */){
   // Assignment operator
   // Assignment is not allowed. The method is protected to avoid misuse.
-  Fatal("= operator","Assignment operator not allowed\n");
-  return *this;
-}
+//  Fatal("= operator","Assignment operator not allowed\n");
+//  return *this;
+//}
 
 //----------------------------------------------------------------------
 AliITSClusterFinder::~AliITSClusterFinder(){
@@ -143,8 +167,6 @@ AliITSClusterFinder::~AliITSClusterFinder(){
 
     if(fMap) {delete fMap;}
     // Zero local pointers. Other classes own these pointers.
-    fSegmentation = 0;
-    fResponse     = 0;
     fMap          = 0;
     fDigits       = 0;
     fNdigits      = 0;
@@ -153,34 +175,18 @@ AliITSClusterFinder::~AliITSClusterFinder(){
     fDeclusterFlag= 0;
     fClusterSize  = 0;
     fNPeaks       = 0;
-    // fITS          = 0;
     fDetTypeRec   = 0;
-    fITSgeom      = 0;
 
 }
 //__________________________________________________________________________
 void AliITSClusterFinder::InitGeometry(){
-
-
- //Initialisation of ITS geometry
-  if(!fITSgeom) {
-    Error("InitGeometry","ITS geom is null!");
-    return;
-  }
-  Int_t mmax=fITSgeom->GetIndexMax();
-  if (mmax>2200) {
-    Fatal("AliITSClusterFinder","Too many ITS subdetectors !"); 
-  }
-  Int_t m;
-  for (m=0; m<mmax; m++) {
-    Int_t lay,lad,det; fITSgeom->GetModuleId(m,lay,lad,det);
-    Float_t x,y,z;     fITSgeom->GetTrans(lay,lad,det,x,y,z); 
-    Double_t rot[9];   fITSgeom->GetRotMatrix(lay,lad,det,rot);
-    Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
-    Double_t ca=TMath::Cos(alpha), sa=TMath::Sin(alpha);
-    fYshift[m] = x*ca + y*sa;
-    fZshift[m] = (Double_t)z;
-    fNdet[m] = (lad-1)*fITSgeom->GetNdetectors(lay) + (det-1);
+ //
+ // Initialisation of ITS geometry
+ //
+  Int_t mmax=AliITSgeomTGeo::GetNModules();
+  for (Int_t m=0; m<mmax; m++) {
+    Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(m,lay,lad,det);
+    fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
     fNlayer[m] = lay-1;
   }
 }
@@ -418,38 +424,6 @@ void AliITSClusterFinder::Print(ostream *os) const{
     *os << fClusterSize<<",";
     *os << fNPeaks<<endl;
 }
-/*
-//______________________________________________________________________
-void AliITSClusterFinder::RecPoints2Clusters
-(const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
-  //------------------------------------------------------------
-  // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS 
-  // subdetector indexed by idx 
-  //------------------------------------------------------------
-  if(!fITSgeom) {
-    Error("RecPoints2Clusters","ITS geom is null!");
-    return;
-  }
-  Int_t lastSPD1=fITSgeom->GetModuleIndex(2,1,1)-1;
-  TClonesArray &cl=*clusters;
-  Int_t ncl=points->GetEntriesFast();
-  for (Int_t i=0; i<ncl; i++) {
-    AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
-    Float_t lp[5];
-    lp[0]=-(-p->GetX()+fYshift[idx]); if (idx<=lastSPD1) lp[0]*=-1; //SPD1
-    lp[1]=  -p->GetZ()+fZshift[idx];
-    lp[2]=p->GetSigmaX2();
-    lp[3]=p->GetSigmaZ2();
-    lp[4]=p->GetQ()*36./23333.;  //electrons -> ADC
-    Int_t lab[4]; 
-    lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
-    lab[3]=fNdet[idx];
-    CheckLabels(lab);
-    Int_t dummy[3]={0,0,0};
-    new (cl[i]) AliITSclusterV2(lab,lp, dummy);
-  }  
-} 
-*/
 //______________________________________________________________________
 void AliITSClusterFinder::Read(istream *is)  {
     //Standard input for this class
@@ -497,29 +471,201 @@ istream &operator>>(istream &is,AliITSClusterFinder &source){
     source.Read(&is);
     return is;
 }
-/*
-void AliITSClusterFinder::RecPoints2Clusters
-(const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
+//______________________________________________________________________
+void AliITSClusterFinder::CheckLabels2(Int_t lab[10]) {
   //------------------------------------------------------------
-  // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS 
-  // subdetector indexed by idx 
+  // Tries to find mother's labels
   //------------------------------------------------------------
-  TClonesArray &cl=*clusters;
-  Int_t ncl=points->GetEntriesFast();
-  for (Int_t i=0; i<ncl; i++) {
-    AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
-    Float_t lp[5];
-    lp[0]=-(-p->GetX()+fYshift[idx]); if (idx<=fLastSPD1) lp[0]*=-1; //SPD1
-    lp[1]=  -p->GetZ()+fZshift[idx];
-    lp[2]=p->GetSigmaX2();
-    lp[3]=p->GetSigmaZ2();
-    lp[4]=p->GetQ()*36./23333.;  //electrons -> ADC
-    Int_t lab[4]; 
-    lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
-    lab[3]=fNdet[idx];
-    CheckLabels(lab);
-    Int_t dummy[3]={0,0,0};
-    new (cl[i]) AliITSclusterV2(lab,lp, dummy);
-  }  
-} 
-*/
+  AliRunLoader *rl = AliRunLoader::GetRunLoader();
+  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;
+       }
+      }
+    }
+    for (Int_t j=0;j<10;j++) lab[j]=lab2[j];
+  
+  }
+}
+
+//______________________________________________________________________
+void AliITSClusterFinder::AddLabel(Int_t lab[10], Int_t label) {
+  //add label to the cluster
+  AliRunLoader *rl = AliRunLoader::GetRunLoader();
+  TTree *trK=(TTree*)rl->TreeK();
+  if(trK){
+    if(label<0) return; // In case of no label just exit
+
+    Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
+    if (label>ntracks) return;
+    for (Int_t i=0;i<10;i++){
+      //    if (label<0) break;
+      if (lab[i]==label) break;
+      if (lab[i]<0) {
+       lab[i]= label;
+       break;
+      }
+    }
+  }
+}
+
+
+//______________________________________________________________________
+void AliITSClusterFinder:: 
+FindCluster(Int_t k,Int_t maxz,AliBin *bins,Int_t &n,Int_t *idx) {
+  //------------------------------------------------------------
+  // returns an array of indices of digits belonging to the cluster
+  // (needed when the segmentation is not regular) 
+  //------------------------------------------------------------
+  if (n<200) idx[n++]=bins[k].GetIndex();
+  bins[k].Use();
+
+  if (bins[k-maxz].IsNotUsed()) FindCluster(k-maxz,maxz,bins,n,idx);
+  if (bins[k-1   ].IsNotUsed()) FindCluster(k-1   ,maxz,bins,n,idx);
+  if (bins[k+maxz].IsNotUsed()) FindCluster(k+maxz,maxz,bins,n,idx);
+  if (bins[k+1   ].IsNotUsed()) FindCluster(k+1   ,maxz,bins,n,idx);
+  /*
+  if (bins[k-maxz-1].IsNotUsed()) FindCluster(k-maxz-1,maxz,bins,n,idx);
+  if (bins[k-maxz+1].IsNotUsed()) FindCluster(k-maxz+1,maxz,bins,n,idx);
+  if (bins[k+maxz-1].IsNotUsed()) FindCluster(k+maxz-1,maxz,bins,n,idx);
+  if (bins[k+maxz+1].IsNotUsed()) FindCluster(k+maxz+1,maxz,bins,n,idx);
+  */
+}
+
+//______________________________________________________________________
+Bool_t AliITSClusterFinder::IsMaximum(Int_t k,Int_t max,const AliBin *bins) {
+  //------------------------------------------------------------
+  //is this a local maximum ?
+  //------------------------------------------------------------
+  UShort_t q=bins[k].GetQ();
+  if (q==1023) return kFALSE;
+  if (bins[k-max].GetQ() > q) return kFALSE;
+  if (bins[k-1  ].GetQ() > q) return kFALSE; 
+  if (bins[k+max].GetQ() > q) return kFALSE; 
+  if (bins[k+1  ].GetQ() > q) return kFALSE; 
+  if (bins[k-max-1].GetQ() > q) return kFALSE;
+  if (bins[k+max-1].GetQ() > q) return kFALSE; 
+  if (bins[k+max+1].GetQ() > q) return kFALSE; 
+  if (bins[k-max+1].GetQ() > q) return kFALSE;
+  return kTRUE; 
+}
+
+//______________________________________________________________________
+void AliITSClusterFinder::
+FindPeaks(Int_t k,Int_t max,AliBin *b,Int_t *idx,UInt_t *msk,Int_t& n) {
+  //------------------------------------------------------------
+  //find local maxima
+  //------------------------------------------------------------
+  if (n<31)
+  if (IsMaximum(k,max,b)) {
+    idx[n]=k; msk[n]=(2<<n);
+    n++;
+  }
+  b[k].SetMask(0);
+  if (b[k-max].GetMask()&1) FindPeaks(k-max,max,b,idx,msk,n);
+  if (b[k-1  ].GetMask()&1) FindPeaks(k-1  ,max,b,idx,msk,n);
+  if (b[k+max].GetMask()&1) FindPeaks(k+max,max,b,idx,msk,n);
+  if (b[k+1  ].GetMask()&1) FindPeaks(k+1  ,max,b,idx,msk,n);
+}
+
+//______________________________________________________________________
+void AliITSClusterFinder::
+MarkPeak(Int_t k, Int_t max, AliBin *bins, UInt_t m) {
+  //------------------------------------------------------------
+  //mark this peak
+  //------------------------------------------------------------
+  UShort_t q=bins[k].GetQ();
+
+  bins[k].SetMask(bins[k].GetMask()|m); 
+
+  if (bins[k-max].GetQ() <= q)
+     if ((bins[k-max].GetMask()&m) == 0) MarkPeak(k-max,max,bins,m);
+  if (bins[k-1  ].GetQ() <= q)
+     if ((bins[k-1  ].GetMask()&m) == 0) MarkPeak(k-1  ,max,bins,m);
+  if (bins[k+max].GetQ() <= q)
+     if ((bins[k+max].GetMask()&m) == 0) MarkPeak(k+max,max,bins,m);
+  if (bins[k+1  ].GetQ() <= q)
+     if ((bins[k+1  ].GetMask()&m) == 0) MarkPeak(k+1  ,max,bins,m);
+}
+
+//______________________________________________________________________
+void AliITSClusterFinder::
+MakeCluster(Int_t k,Int_t max,AliBin *bins,UInt_t m,AliITSRecPoint &c) {
+  //------------------------------------------------------------
+  //make cluster using digits of this peak
+  //------------------------------------------------------------
+  Float_t q=(Float_t)bins[k].GetQ();
+  Int_t i=k/max, j=k-i*max;
+
+  c.SetQ(c.GetQ()+q);
+  c.SetY(c.GetY()+i*q);
+  c.SetZ(c.GetZ()+j*q);
+  c.SetSigmaY2(c.GetSigmaY2()+i*i*q);
+  c.SetSigmaZ2(c.GetSigmaZ2()+j*j*q);
+
+  bins[k].SetMask(0xFFFFFFFE);
+  
+  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);
+  if (bins[k+1  ].GetMask() == m) MakeCluster(k+1  ,max,bins,m,c);
+}