]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
method Order is removed
authorbnandi <bnandi@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 13 Feb 2007 08:20:36 +0000 (08:20 +0000)
committerbnandi <bnandi@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 13 Feb 2007 08:20:36 +0000 (08:20 +0000)
PMD/AliPMDClusteringV1.cxx
PMD/AliPMDClusteringV1.h
PMD/AliPMDClusteringV2.cxx
PMD/AliPMDClusteringV2.h

index c20acd257de1147372b424d115c7bb7a39a3e821..0c75b7c98fa042cb81b33ed9fbb98198d1d9b31a 100644 (file)
    Bhubaneswar 751 005 ( phatak@iopb.res.in ) Given the energy deposited
    ( or ADC value ) in each cell of supermodule ( pmd or cpv ), the code
    builds up superclusters and breaks them into clusters. The input is
-   in array fEdepCell[kNDIMX][kNDIMY] and cluster information is in a
+   in array edepcell[kNMX] and cluster information is in a
    TObjarray. Integer clno gives total number of clusters in the
    supermodule.
 
-   fEdepCell and fClusters are the only global ( public ) variables.
+   fClusters is the only global ( public ) variables.
    Others are local ( private ) to the code.
    At the moment, the data is read for whole detector ( all supermodules
    and pmd as well as cpv. This will have to be modify later )
@@ -45,6 +45,7 @@
 #include <TMath.h>
 #include <TNtuple.h>
 #include <TObjArray.h>
+#include "TRandom.h"
 #include <stdio.h>
 
 #include "AliPMDcludata.h"
 #include "AliPMDClustering.h"
 #include "AliPMDClusteringV1.h"
 #include "AliLog.h"
-#include "TRandom.h"
 
 ClassImp(AliPMDClusteringV1)
 
 const Double_t AliPMDClusteringV1::fgkSqroot3by2=0.8660254;  // sqrt(3.)/2.
 
 AliPMDClusteringV1::AliPMDClusteringV1():
-  pmdclucont(new TObjArray()),
+  fPMDclucont(new TObjArray()),
   fCutoff(0.0)
 {
   for(Int_t i = 0; i < kNDIMX; i++)
@@ -68,14 +68,30 @@ AliPMDClusteringV1::AliPMDClusteringV1():
        {
          fCoord[0][i][j] = i+j/2.;
          fCoord[1][i][j] = fgkSqroot3by2*j;
-         fEdepCell[i][j] = 0;
        }
     }
 }
 // ------------------------------------------------------------------------ //
+AliPMDClusteringV1::AliPMDClusteringV1(const AliPMDClusteringV1& pmdclv1):
+  AliPMDClustering(pmdclv1),
+  fPMDclucont(0),
+  fCutoff(0)
+{
+  // copy constructor
+  AliError("Copy constructor not allowed ");
+  
+}
+// ------------------------------------------------------------------------ //
+AliPMDClusteringV1 &AliPMDClusteringV1::operator=(const AliPMDClusteringV1& /*pmdclv1*/)
+{
+  // copy constructor
+  AliError("Assignment operator not allowed ");
+  return *this;
+}
+// ------------------------------------------------------------------------ //
 AliPMDClusteringV1::~AliPMDClusteringV1()
 {
-  delete pmdclucont;
+  delete fPMDclucont;
 }
 // ------------------------------------------------------------------------ //
 void AliPMDClusteringV1::DoClust(Int_t idet, Int_t ismn, 
@@ -83,18 +99,14 @@ void AliPMDClusteringV1::DoClust(Int_t idet, Int_t ismn,
 {
   // main function to call other necessary functions to do clustering
   //
-  AliPMDcluster *pmdcl = 0;
-  /*
-    int id and jd defined to read the input data.
-    It is assumed that for data we have 0 <= id <= 48
-    and 0 <= jd <=96
-  */
 
-  Int_t i, i1, i2, j, nmx1, incr, id, jd;
-  Int_t   celldataX[15], celldataY[15];
-  Float_t clusdata[6];
+  AliPMDcluster *pmdcl = 0;
 
-  Double_t  cutoff, ave;
+  Int_t    i,  j, nmx1, incr, id, jd;
+  Int_t    celldataX[15], celldataY[15];
+  Float_t  clusdata[6];
+  Double_t cutoff, ave;
+  Double_t edepcell[kNMX];
 
   const float ktwobysqrt3 = 1.1547; // 2./sqrt(3.)
 
@@ -114,12 +126,14 @@ void AliPMDClusteringV1::DoClust(Int_t idet, Int_t ismn,
       ndimYr = 96;
     }
 
+  Int_t kk = 0;
   for (Int_t i = 0; i < kNDIMX; i++)
     {
       for (Int_t j = 0; j < kNDIMY; j++)
        {
-         fEdepCell[i][j] = 0;
          fCellTrNo[i][j] = -1;
+         edepcell[kk] = 0.;
+         kk++;
        }
     }
 
@@ -130,33 +144,34 @@ void AliPMDClusteringV1::DoClust(Int_t idet, Int_t ismn,
          j = jd;
          i = id+(ndimYr/2-1)-(jd/2);
 
+         Int_t ij = i + j*kNDIMX;
+
          if (ismn < 12)
            {
-             fEdepCell[i][j] = celladc[jd][id];
-             fCellTrNo[i][j] = jd*10000+id; /* for association */
+             edepcell[ij]    = celladc[jd][id];
+             fCellTrNo[i][j] = jd*10000+id;  // for association 
            }
          else if (ismn >= 12 && ismn <= 23)
            {
-             fEdepCell[i][j] = celladc[id][jd];
-             fCellTrNo[i][j] = id*10000+jd; /* for association */
+             edepcell[ij]    = celladc[id][jd];
+             fCellTrNo[i][j] = id*10000+jd;  // for association 
            }
 
        }
     }
-  Order();          // order the data
-  cutoff = fCutoff; // cutoff used to discard cells having ener. dep.
-  ave = 0.;
+  
+  Int_t iord1[kNMX];
+  TMath::Sort(kNMX,edepcell,iord1);// order the data
+  cutoff = fCutoff;                // cutoff to discard cells
+  ave  = 0.;
   nmx1 = -1;
-
-  for(j = 0;j < kNMX; j++)
+  for(i = 0;i < kNMX; i++)
     {
-      i1 = fIord[0][j];
-      i2 = fIord[1][j];
-      if(fEdepCell[i1][i2] > 0.) 
+      if(edepcell[i] > 0.) 
        {
-         ave += fEdepCell[i1][i2];
+         ave += edepcell[i];
        }
-      if(fEdepCell[i1][i2] > cutoff )
+      if(edepcell[i] > cutoff )
        {
          nmx1++;
        }
@@ -169,16 +184,18 @@ void AliPMDClusteringV1::DoClust(Int_t idet, Int_t ismn,
 
   AliDebug(1,Form("Number of cells in a SuperM = %d and Average = %f",
                  kNMX,ave));
-          
-  incr = CrClust(ave, cutoff, nmx1);
-  RefClust(incr);
-  Int_t nentries1 = pmdclucont->GetEntries();
+  
+  incr = CrClust(ave, cutoff, nmx1,iord1, edepcell );
+  
+  RefClust(incr,edepcell);
+  Int_t nentries1 = fPMDclucont->GetEntries();
   AliDebug(1,Form("Detector Plane = %d  Serial Module No = %d Number of clusters = %d",idet, ismn, nentries1));
   AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
+  
   for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
     {
       AliPMDcludata *pmdcludata = 
-       (AliPMDcludata*)pmdclucont->UncheckedAt(ient1);
+       (AliPMDcludata*)fPMDclucont->UncheckedAt(ient1);
       Float_t cluXC    = pmdcludata->GetClusX();
       Float_t cluYC    = pmdcludata->GetClusY();
       Float_t cluADC   = pmdcludata->GetClusADC();
@@ -210,59 +227,30 @@ void AliPMDClusteringV1::DoClust(Int_t idet, Int_t ismn,
       //
       // Cells associated with a cluster
       //
+
       for (Int_t ihit = 0; ihit < 15; ihit++)
        {
-         
          if (ismn < 12)
            {
-             celldataX[ihit] = fClTr[ihit][i1]%10000;
-             celldataY[ihit] = fClTr[ihit][i1]/10000;
+             celldataX[ihit] = pmdcludata->GetCellXY(ihit)%10000;
+             celldataY[ihit] = pmdcludata->GetCellXY(ihit)/10000;
            }
          else if (ismn >= 12 && ismn <= 23)
            {
-             celldataX[ihit] = fClTr[ihit][i1]/10000;
-             celldataY[ihit] = fClTr[ihit][i1]%10000;
+             celldataX[ihit] = pmdcludata->GetCellXY(ihit)/10000;
+             celldataY[ihit] = pmdcludata->GetCellXY(ihit)%10000;
            }
        }
       pmdcl = new AliPMDcluster(idet, ismn, clusdata, celldataX, celldataY);
       pmdcont->Add(pmdcl);
     }
   
-  pmdclucont->Clear();
-  
-}
-// ------------------------------------------------------------------------ //
-void AliPMDClusteringV1::Order()
-{
-  // Sorting algorithm
-  // sorts the ADC values from higher to lower
-  //
-  Int_t i, j, i1, i2;
-  Int_t iord1[kNMX];
-  Double_t dd[kNMX];
-  
-  for(i1=0; i1 < kNDIMX; i1++)
-    {
-      for(i2=0; i2 < kNDIMY; i2++)
-       {
-         i        = i1 + i2*kNDIMX;
-         iord1[i] = i;
-         dd[i]    = fEdepCell[i1][i2];
-       }
-    }
+  fPMDclucont->Clear();
   
-  TMath::Sort(kNMX,dd,iord1); //PH Using much better algorithm...
-  for(i=0; i<kNMX; i++)
-    {
-      j  = iord1[i];
-      i2 = j/kNDIMX;
-      i1 = j-i2*kNDIMX;
-      fIord[0][i]=i1;
-      fIord[1][i]=i2;
-    }
 }
 // ------------------------------------------------------------------------ //
-Int_t AliPMDClusteringV1::CrClust(Double_t ave, Double_t cutoff, Int_t nmx1)
+Int_t AliPMDClusteringV1::CrClust(Double_t ave, Double_t cutoff, Int_t nmx1,
+                                 Int_t iord1[], Double_t edepcell[])
 {
   // Does crude clustering 
   // Finds out only the big patch by just searching the
@@ -272,11 +260,6 @@ Int_t AliPMDClusteringV1::CrClust(Double_t ave, Double_t cutoff, Int_t nmx1)
   Int_t jd1,jd2, icell, cellcount;
   static Int_t neibx[6]={1,0,-1,-1,0,1}, neiby[6]={0,1,1,0,-1,-1};
 
-  // neibx and neiby define ( incremental ) (i,j) for the neighbours of a
-  // cell. There are six neighbours.
-  // cellcount --- total number of cells having nonzero ener dep
-  // numcell --- number of cells in a given supercluster
-  
   AliDebug(1,Form("kNMX = %d nmx1 = %d kNDIMX = %d kNDIMY = %d ave = %f cutoff = %f",kNMX,nmx1,kNDIMX,kNDIMY,ave,cutoff));
   
   for (j = 0; j < kNDIMX; j++)
@@ -290,24 +273,31 @@ Int_t AliPMDClusteringV1::CrClust(Double_t ave, Double_t cutoff, Int_t nmx1)
   for(i=0; i < kNMX; i++)
     {
       fInfcl[0][i] = -1;
-      id1 = fIord[0][i];
-      id2 = fIord[1][i];
-      if(fEdepCell[id1][id2] <= cutoff)
+      
+      j  = iord1[i];
+      id2 = j/kNDIMX;
+      id1 = j-id2*kNDIMX;
+
+      if(edepcell[j] <= cutoff)
        {
          fInfocl[0][id1][id2] = -1;
        }
     }
+
   // ---------------------------------------------------------------
   // crude clustering begins. Start with cell having largest adc
   // count and loop over the cells in descending order of adc count
   // ---------------------------------------------------------------
+
   icl       = -1;
   cellcount = -1;
 
   for(icell = 0; icell <= nmx1; icell++)
     {
-      id1 = fIord[0][icell];
-      id2 = fIord[1][icell];
+      j  = iord1[icell];
+      id2 = j/kNDIMX;
+      id1 = j-id2*kNDIMX;
+
       if(fInfocl[0][id1][id2] == 0 )
        {
          icl++;
@@ -383,34 +373,40 @@ Int_t AliPMDClusteringV1::CrClust(Double_t ave, Double_t cutoff, Int_t nmx1)
   return cellcount;
 }
 // ------------------------------------------------------------------------ //
-void AliPMDClusteringV1::RefClust(Int_t incr)
+void AliPMDClusteringV1::RefClust(Int_t incr, Double_t edepcell[])
 {
   // Does the refining of clusters
   // Takes the big patch and does gaussian fitting and
   // finds out the more refined clusters
   //
-  
+
+  AliPMDcludata *pmdcludata = 0;
+
   const Int_t kdim = 4500;
-  Int_t     i, j, k, i1, i2, id, icl,  itest,ihld, ig, nsupcl,clno;
-  Double_t  x1, y1, z1, x2, y2, z2, dist,rr,sum;
-  
-  Int_t t[kdim],cellCount[kdim];
-  Int_t    ncl[kdim], iord[kdim], lev1[20], lev2[20];
+
+  Int_t i, j, k, i1, i2, id, icl,  itest,ihld, ig, nsupcl,clno;
+  Int_t lev1[20], lev2[20];
+  Int_t ncl[kdim], iord[kdim], t[kdim];
+  Int_t clxy[15];
+
+  Int_t *cellCount;
+  Int_t **cellXY;
+
+  Float_t  clusdata[6];
+  Double_t x1, y1, z1, x2, y2, z2, dist,rr,sum;
   Double_t x[kdim], y[kdim], z[kdim];
   Double_t xc[kdim], yc[kdim], zc[kdim], cells[kdim], rc[kdim];
   
-  Float_t  clusdata[6];
-  for(Int_t kk = 0; kk < 6; kk++)
-    {
-      clusdata[kk] = 0.;
-    }
-  
-  //asso
+
+  // Initialisation  
   for(i = 0; i<kdim; i++)
     { 
       t[i]         = -1;
-      cellCount[i] = 0;
+      ncl[i]       = -1;
+      if (i < 6) clusdata[i] = 0.;
+      if (i < 15) clxy[i] = 0;
     }
+
   // clno counts the final clusters
   // nsupcl =  # of superclusters; ncl[i]= # of cells in supercluster i
   // x, y and z store (x,y) coordinates of and energy deposited in a cell
@@ -420,10 +416,7 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
   
   clno  = -1;
   nsupcl = -1;
-  for(i = 0; i < kdim; i++)
-    {
-      ncl[i] = -1;
-    }
+
   for(i = 0; i <= incr; i++)
     {
       if(fInfcl[0][i] != nsupcl)
@@ -443,6 +436,7 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
                  incr+1,nsupcl+1));
   id  = -1;
   icl = -1;
+  
   for(i = 0; i <= nsupcl; i++) 
     {
       if(ncl[i] == 0)
@@ -458,22 +452,22 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
          i1 = fInfcl[1][id];
          i2 = fInfcl[2][id];
          
+         Int_t i12 = i1 + i2*kNDIMX;
+         
          clusdata[0] = fCoord[0][i1][i2];
          clusdata[1] = fCoord[1][i1][i2];
-         clusdata[2] = fEdepCell[i1][i2];
+         clusdata[2] = edepcell[i12];
          clusdata[3] = 1.;
          clusdata[4] = 0.5;
          clusdata[5] = 0.0;
-         pmdcludata  = new AliPMDcludata(clusdata);
-         pmdclucont->Add(pmdcludata);
-         
-         //association
-         
-         fClTr[0][clno] = fCellTrNo[i1][i2];
-         for(Int_t icltr = 1; icltr < 14; icltr++)
+
+         clxy[0] = fCellTrNo[i1][i2];            //association
+         for(Int_t icltr = 1; icltr < 15; icltr++)
            {
-             fClTr[icltr][clno] = -1;
+             clxy[icltr] = -1;
            }
+         pmdcludata  = new AliPMDcludata(clusdata,clxy);
+         fPMDclucont->Add(pmdcludata);
        }
       else if(ncl[i] == 1) 
        {
@@ -487,29 +481,25 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
          clno++;
          i1   = fInfcl[1][id];
          i2   = fInfcl[2][id];
+         Int_t i12 = i1 + i2*kNDIMX;
+
          x1   = fCoord[0][i1][i2];
          y1   = fCoord[1][i1][i2];
-         z1   = fEdepCell[i1][i2];
-         
-         //asso
-         fClTr[0][clno] = fCellTrNo[i1][i2];
-         //
-         
-         id   = id+1;
+         z1   = edepcell[i12];
+         clxy[0] = fCellTrNo[i1][i2];    //asso
+         id++;
          i1   = fInfcl[1][id];
          i2   = fInfcl[2][id];
+
+         Int_t i22 = i1 + i2*kNDIMX;
          x2   = fCoord[0][i1][i2];
          y2   = fCoord[1][i1][i2];
-         z2   = fEdepCell[i1][i2];
-         
-         //asso
-         
-         fClTr[1][clno] = fCellTrNo[i1][i2];
-         for(Int_t icltr = 2; icltr < 14; icltr++)
+         z2   = edepcell[i22];
+         clxy[1] = fCellTrNo[i1][i2];            //asso
+         for(Int_t icltr = 2; icltr < 15; icltr++)
            {
-             fClTr[icltr][clno] = -1;
+             clxy[icltr] = -1;
            }
-         //
          
          clusdata[0] = (x1*z1+x2*z2)/(z1+z2);
          clusdata[1] = (y1*z1+y2*z2)/(z1+z2);
@@ -517,18 +507,11 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
          clusdata[3] = 2.;
          clusdata[4] = 0.5;
          clusdata[5] = 0.0;
-         pmdcludata  = new AliPMDcludata(clusdata);
-         pmdclucont->Add(pmdcludata);
+         pmdcludata  = new AliPMDcludata(clusdata,clxy);
+         fPMDclucont->Add(pmdcludata);
        }
       else
        {
-         //asso
-         for(Int_t icg = 0; icg < kdim; icg++)
-           {
-             cellCount[icg]=0;
-           }
-         //
-         
          id++;
          iord[0] = 0;
          // super-cluster of more than two cells - broken up into smaller
@@ -537,13 +520,13 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
          // cluster center
          i1      = fInfcl[1][id];
          i2      = fInfcl[2][id];
+         Int_t i12 = i1 + i2*kNDIMX;
+         
          x[0]    = fCoord[0][i1][i2];
          y[0]    = fCoord[1][i1][i2];
-         z[0]    = fEdepCell[i1][i2];
-         
-         //asso
-         t[0] = fCellTrNo[i1][i2];
-         //
+         z[0]    = edepcell[i12];
+
+         t[0] = fCellTrNo[i1][i2];       //asso
          
          iord[0] = 0;
          for(j = 1; j <= ncl[i]; j++)
@@ -551,16 +534,16 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
              id++;
              i1      = fInfcl[1][id];
              i2      = fInfcl[2][id];
+             Int_t i12 = i1 + i2*kNDIMX;
+
              iord[j] = j;
              x[j]    = fCoord[0][i1][i2];
              y[j]    = fCoord[1][i1][i2];
-             z[j]    = fEdepCell[i1][i2];
-             //asso
-             t[j]    = fCellTrNo[i1][i2];
-             //
+             z[j]    = edepcell[i12];
+
+             t[j]    = fCellTrNo[i1][i2];            //asso
            }
          
-         
          // arranging cells within supercluster in decreasing order
          
          for(j = 1;j <= ncl[i]; j++)
@@ -584,7 +567,7 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
          // guess )
          // centers must be separated by cells having smaller ener. dep.
          // neighbouring centers should be either strong or well-separated
-         ig=0;
+         ig = 0;
          xc[ig] = x[iord[0]];
          yc[ig] = y[iord[0]];
          zc[ig] = z[iord[0]];
@@ -598,18 +581,9 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
                  x2 = xc[k]; 
                  y2 = yc[k];
                  rr = Distance(x1,y1,x2,y2);
-                 if( rr >= 1.1 && rr < 1.8 && z[iord[j]] > zc[k]/4.)
-                   {
-                     itest++;
-                   }
-                 if( rr >= 1.8 && rr < 2.1 && z[iord[j]] > zc[k]/10.)
-                   {
-                     itest++;
-                   }
-                 if( rr >= 2.1)
-                   {
-                     itest++;
-                   }
+                 if(rr >= 1.1 && rr < 1.8 && z[iord[j]] > zc[k]/4.)itest++;
+                 if(rr >= 1.8 && rr < 2.1 && z[iord[j]] > zc[k]/10.)itest++;
+                 if( rr >= 2.1)itest++;
                }
              if(itest == ig)
                {
@@ -619,16 +593,23 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
                  zc[ig] = z[iord[j]];
                }
            }
-         
          GaussFit(ncl[i], ig, x[0], y[0] ,z[0], xc[0], yc[0], zc[0], rc[0]);
          icl += ig+1;
          // compute the number of cells belonging to each cluster.
          // cell is shared between several clusters ( if they are equidistant
          // from it ) in the ratio of cluster energy deposition
+
+         Int_t jj = 15;
+         cellCount = new Int_t [ig+1];
+         cellXY = new Int_t *[jj];
+         for(Int_t ij = 0; ij < 15; ij++) cellXY[ij] = new Int_t [ig+1];
+
          for(j = 0; j <= ig; j++)
            {
-             cells[j]=0.;
+             cellCount[j] = 0;
+             cells[j]     = 0.;
            }
+         
          if(ig > 0)
            {
              for(j = 0; j <= ncl[i]; j++)
@@ -641,7 +622,10 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
                      if(dist < TMath::Sqrt(3.) )
                        {
                          //asso
-                         fClTr[cellCount[k]][clno+k+1] = t[j];
+                         if (cellCount[k] < 15)
+                           {
+                             cellXY[cellCount[k]][k] = t[j];
+                           }
                          cellCount[k]++;
                          //
                          lev1[0]++;
@@ -703,9 +687,9 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
          //asso
          for( k = 0; k <= ig; k++)
            {
-             for(Int_t icltr = cellCount[k]; icltr < 14; icltr++)
+             for(Int_t icltr = cellCount[k]; icltr < 15; icltr++)
                {
-                 fClTr[icltr][clno] = -1;
+                 cellXY[icltr][k] = -1;
                }
            }
          //
@@ -731,9 +715,18 @@ void AliPMDClusteringV1::RefClust(Int_t incr)
                {
                  clusdata[3] = cells[j];
                }
-             pmdcludata = new AliPMDcludata(clusdata);
-             pmdclucont->Add(pmdcludata);
+
+
+             for (Int_t ii=0; ii < 15; ii++)
+               {
+                 clxy[ii] = cellXY[ii][j];
+               }  
+             pmdcludata = new AliPMDcludata(clusdata,clxy);
+             fPMDclucont->Add(pmdcludata);
            }
+         delete [] cellCount;
+         for(Int_t jj = 0; jj < 15; jj++)delete [] cellXY[jj];
+         delete [] cellXY;
        }
     }
 }
@@ -744,14 +737,16 @@ void AliPMDClusteringV1::GaussFit(Int_t ncell, Int_t nclust, Double_t &x,
 {
   // Does gaussian fitting
   //
+
   const Int_t kdim = 4500;
   Int_t i, j, i1, i2, novar, idd, jj;
+  Int_t neib[kdim][50];
+
   Double_t sum, dx, dy, str, str1, aint, sum1, rr, dum;
   Double_t x1, x2, y1, y2;
   Double_t xx[kdim], yy[kdim], zz[kdim], xxc[kdim], yyc[kdim];
   Double_t a[kdim], b[kdim], c[kdim], d[kdim], ha[kdim], hb[kdim];
   Double_t hc[kdim], hd[kdim], zzc[kdim], rrc[kdim];
-  Int_t neib[kdim][50];
   
   TRandom rnd;
   
@@ -759,7 +754,7 @@ void AliPMDClusteringV1::GaussFit(Int_t ncell, Int_t nclust, Double_t &x,
   str1  = 0.;
   rr    = 0.3;
   novar = 0;
-  j = 0;  
+  j     = 0;  
 
   for(i = 0; i <= ncell; i++)
     {
@@ -786,6 +781,7 @@ void AliPMDClusteringV1::GaussFit(Int_t ncell, Int_t nclust, Double_t &x,
       x1     = xxc[i];
       y1     = yyc[i];
     }
   for(i = 0; i <= ncell; i++)
     {
       idd = 0;
@@ -819,6 +815,7 @@ void AliPMDClusteringV1::GaussFit(Int_t ncell, Int_t nclust, Double_t &x,
       sum += (aint - zz[i1])*(aint - zz[i1])/str;
     } 
   str1 = 0.;
   for(i = 0; i <= nclust; i++)
     {
       a[i]  = xxc[i] + 0.6*(rnd.Uniform() - 0.5);
@@ -837,6 +834,7 @@ void AliPMDClusteringV1::GaussFit(Int_t ncell, Int_t nclust, Double_t &x,
       c[i] = c[i]*str/str1; 
     }
   sum1=0.;
+  
   for(i1 = 0; i1 <= ncell; i1++)
     {
       aint = 0.;
index d48ec65f578a3e0ed6cf3f6b29e536eecd2a40cf..ed667384ef9c1a407549facbaa64bcfff4f5893c 100644 (file)
 //  clustering code for alice pmd                      //
 //                                                     //
 //-----------------------------------------------------//
-/* --------------------------------------------------------------------
-   Code developed by S. C. Phatak, Institute of Physics,
-   Bhubaneswar 751 005 ( phatak@iopb.res.in ) Given the energy deposited
-   ( or ADC value ) in each cell of supermodule ( pmd or cpv ), the code
-   builds up superclusters and breaks them into clusters. The input is 
-   in array d[ndimx][ndimy] and cluster information is in array
-   clusters[5][5000]. integer clno gives total number of clusters in the
-   supermodule.
-   d, clno  and clusters are the only global ( public ) variables. Others
-   are local ( private ) to the code.
-   At the moment, the data is read for whole detector ( all supermodules
-   and pmd as well as cpv. This will have to be modify later )
-   LAST UPDATE  :  October 23, 2002
------------------------------------------------------------------------*/
+// -- Author   : S.C. Phatak
+// -- Modified : B.K. Nandi, Ajay Dash
+//               S. Chattopadhyay
+//
 #include "Rtypes.h"
 #include "AliPMDClustering.h"
 
@@ -36,14 +26,15 @@ class AliPMDClusteringV1: public AliPMDClustering
 {
  public:
   AliPMDClusteringV1();
+  AliPMDClusteringV1(const AliPMDClusteringV1 &pmdclv1);
+  AliPMDClusteringV1 &operator=(const AliPMDClusteringV1 &pmdclv1);
   virtual ~AliPMDClusteringV1();
 
   void     DoClust(Int_t idet, Int_t ismn, Double_t celladc[][96],
                   TObjArray *pmdcont);
-  void     Order();
-  
-  Int_t    CrClust(Double_t ave, Double_t cutoff, Int_t nmx1);
-  void     RefClust(Int_t incr);
+  Int_t    CrClust(Double_t ave, Double_t cutoff, Int_t nmx1,
+                  Int_t iord1[], Double_t edepcell[]);
+  void     RefClust(Int_t incr, Double_t edepcell[]);
   void     GaussFit(Int_t ncell, Int_t nclust, Double_t &x,
                    Double_t &y, Double_t &z, Double_t &xc,
                    Double_t &yc, Double_t &zc, Double_t &rc);
@@ -53,8 +44,7 @@ class AliPMDClusteringV1: public AliPMDClustering
   
  protected:
   
-  TObjArray *pmdclucont;
-  AliPMDcludata *pmdcludata;
+  TObjArray *fPMDclucont;    // carry cluster informations
   
   static const Double_t fgkSqroot3by2;  // fgkSqroot3by2 = sqrt(3.)/2.
   
@@ -64,33 +54,16 @@ class AliPMDClusteringV1: public AliPMDClustering
     kNDIMY  = 96         // max no. of cells along axis at 60 deg with x axis
   };
 
-  Double_t fEdepCell[kNDIMX][kNDIMY]; //energy(ADC) in each cell
   //Variables for association
-  Int_t fCellTrNo[kNDIMX][kNDIMY];     // id x-y value of cells
-  Int_t fClTr[15][5000];               // 1d x-y cell info of attached cells
-
-  Int_t    fIord[2][kNMX];             // ordered list of i and j according
-                                       // to decreasing energy dep.
+  Int_t    fCellTrNo[kNDIMX][kNDIMY];  // id x-y value of cells
   Int_t    fInfocl[2][kNDIMX][kNDIMY]; // cellwise information on the 
                                        // cluster to which the cell
   Int_t    fInfcl[3][kNMX];            // cluster information [0][i]
                                        // -- cluster number
   Double_t fCoord[2][kNDIMX][kNDIMY];
 
-  /*
-    fIord --- ordered list of i and j according to decreasing energy dep.
-    fInfocl --- cellwise information on the cluster to which the cell
-    belongs and whether it has largest energy dep. or not
-    ( now redundant - probably )
-    fInfcl ---  cluster information [0][i] -- cluster number
-    [1][i] -- i of the cell
-    [2][i] -- j of the cell
-    coord --- x and y coordinates of center of each cell
-  */
-
   Float_t fCutoff; // Energy(ADC) cutoff per cell before clustering
 
-  ClassDef(AliPMDClusteringV1,3) // Does clustering for PMD
+  ClassDef(AliPMDClusteringV1,4) // Does clustering for PMD
 };
 #endif
index c8ee50efb973a17f40b8b907171cf4f0ea05748c..18909d37d6046ffe2d6aa3163299e84f3e23ad34 100644 (file)
    Bhubaneswar 751 005 ( phatak@iopb.res.in ) Given the energy deposited
    ( or ADC value ) in each cell of supermodule ( pmd or cpv ), the code
    builds up superclusters and breaks them into clusters. The input is
-   in array fEdepCell[kNDIMX][kNDIMY] and cluster information is in array
-   fClusters[5][5000]. integer fClno gives total number of clusters in the
-   supermodule.
-
-   fEdepCell, fClno  and fClusters are the only global ( public ) variables.
+   in TObjarray  and cluster information is in TObjArray.
+   integer clno gives total number of clusters in the  supermodule.
+   fClusters is the  global ( public ) variables.
    Others are local ( private ) to the code.
    At the moment, the data is read for whole detector ( all supermodules
    and pmd as well as cpv. This will have to be modify later )
@@ -42,8 +40,9 @@
 #include <Riostream.h>
 #include <TMath.h>
 #include <TObjArray.h>
-#include <stdio.h>
+#include <TArrayI.h>
 
+#include "AliPMDcludata.h"
 #include "AliPMDcluster.h"
 #include "AliPMDClustering.h"
 #include "AliPMDClusteringV2.h"
@@ -54,7 +53,7 @@ ClassImp(AliPMDClusteringV2)
 const Double_t AliPMDClusteringV2::fgkSqroot3by2=0.8660254;  // sqrt(3.)/2.
 
 AliPMDClusteringV2::AliPMDClusteringV2():
-  fClno(0),
+  fPMDclucont(new TObjArray()),
   fCutoff(0.0)
 {
   for(int i = 0; i < kNDIMX; i++)
@@ -63,31 +62,52 @@ AliPMDClusteringV2::AliPMDClusteringV2():
        {
          fCoord[0][i][j] = i+j/2.;
          fCoord[1][i][j] = fgkSqroot3by2*j;
-         fEdepCell[i][j] = 0;
        }
     }
 }
 // ------------------------------------------------------------------------ //
+
+
+AliPMDClusteringV2::AliPMDClusteringV2(const AliPMDClusteringV2& pmdclv2):
+  AliPMDClustering(pmdclv2),
+  fPMDclucont(0),
+  fCutoff(0)
+{
+  // copy constructor
+  AliError("Copy constructor not allowed ");
+  
+}
+// ------------------------------------------------------------------------ //
+AliPMDClusteringV2 &AliPMDClusteringV2::operator=(const AliPMDClusteringV2& /*pmdclv2*/)
+{
+  // copy constructor
+  AliError("Assignment operator not allowed ");
+  return *this;
+}
+// ------------------------------------------------------------------------ //
 AliPMDClusteringV2::~AliPMDClusteringV2()
 {
-
+  delete fPMDclucont;
 }
 // ------------------------------------------------------------------------ //
-void AliPMDClusteringV2::DoClust(Int_t idet, Int_t ismn, Double_t celladc[48][96], TObjArray *pmdcont)
+
+void AliPMDClusteringV2::DoClust(Int_t idet, Int_t ismn, 
+                                Double_t celladc[48][96], TObjArray *pmdcont)
 {
   // main function to call other necessary functions to do clustering
   //
   AliPMDcluster *pmdcl = 0;
 
-  Int_t    i, i1, i2, j, nmx1, incr, id, jd;
+  const float ktwobysqrt3 = 1.1547; // 2./sqrt(3.)
+
+  Int_t    i, j, nmx1, incr, id, jd;
+  Int_t    ndimXr = 0;
+  Int_t    ndimYr = 0;
   Int_t    celldataX[15], celldataY[15];
-  Float_t  clusdata[6];
+  Float_t  clusdata[6];  
   Double_t cutoff, ave;
+  Double_t edepcell[kNMX];
 
-  const float ktwobysqrt3 = 1.1547; // 2./sqrt(3.)
-
-  Int_t ndimXr =0;
-  Int_t ndimYr =0;
 
   if (ismn < 12)
     {
@@ -99,72 +119,80 @@ void AliPMDClusteringV2::DoClust(Int_t idet, Int_t ismn, Double_t celladc[48][96
       ndimXr = 48;
       ndimYr = 96;
     }
-
-  for (Int_t i =0; i < kNDIMX; i++)
+  
+  for (Int_t i =0; i < kNMX; i++)
     {
-      for (Int_t j =0; j < kNDIMY; j++)
-       {
-         fEdepCell[i][j] = 0;
-       }
+     edepcell[i] = 0.;
     }
-
-
+    
   for (id = 0; id < ndimXr; id++)
     {
       for (jd = 0; jd < ndimYr; jd++)
        {
-         j=jd;
-         i=id+(ndimYr/2-1)-(jd/2);
-         
+         j = jd;
+         i = id + (ndimYr/2-1) - (jd/2);
+         Int_t ij = i + j*kNDIMX;
          if (ismn < 12)
            {
-             fEdepCell[i][j] = celladc[jd][id];
+             edepcell[ij]    = celladc[jd][id];
            }
          else if (ismn >= 12 && ismn <= 23)
            {
-             fEdepCell[i][j] = celladc[id][jd];
+            edepcell[ij]    = celladc[id][jd];
            }
 
        }
     }
 
-  Order();          // order the data
+  Int_t iord1[kNMX];
+  TMath::Sort(kNMX,edepcell,iord1);// order the data
   cutoff = fCutoff; // cutoff used to discard cells having ener. dep.
-  ave=0.;
-  nmx1=-1;
+  ave  = 0.;
+  nmx1 = -1;
 
-  for(j=0;j<kNMX; j++)
+  for(i = 0;i < kNMX; i++)
     {
-      i1 = fIord[0][j];
-      i2 = fIord[1][j];
-      if (fEdepCell[i1][i2] > 0.) {ave = ave + fEdepCell[i1][i2];}
-      if (fEdepCell[i1][i2] > cutoff ) nmx1 = nmx1 + 1;
+      if(edepcell[i] > 0.) 
+       {
+         ave += edepcell[i];
+       }
+      if(edepcell[i] > cutoff )
+       {
+         nmx1++;
+       }
     }
-  // nmx1 --- number of cells having ener dep >= cutoff
-
+  
   AliDebug(1,Form("Number of cells having energy >= %f are %d",cutoff,nmx1));
-
-  if (nmx1 == 0) nmx1 = 1;
-  ave=ave/nmx1;
-
+  
+  if (nmx1 == 0) 
+    {
+      nmx1 = 1;
+    }
+  ave = ave/nmx1;
+  
   AliDebug(1,Form("Number of cells in a SuperM = %d and Average = %f",
                  kNMX,ave));
-          
-  incr = CrClust(ave, cutoff, nmx1);
-  RefClust(incr);
-
-  AliDebug(1,Form("Detector Plane = %d  Serial Module No = %d Number of clusters = %d",idet, ismn, fClno));
   
-  for(i1=0; i1<=fClno; i1++)
+  incr = CrClust(ave, cutoff, nmx1,iord1, edepcell);
+  RefClust(incr,edepcell );
+  
+  Int_t nentries1 = fPMDclucont->GetEntries();
+  AliDebug(1,Form("Detector Plane = %d  Serial Module No = %d Number of clusters = %d",idet, ismn, nentries1));
+  AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
+  for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
     {
-      Float_t cluXC    = (Float_t) fClusters[0][i1];
-      Float_t cluYC    = (Float_t) fClusters[1][i1];
-      Float_t cluADC   = (Float_t) fClusters[2][i1];
-      Float_t cluCELLS = (Float_t) fClusters[3][i1];
-      Float_t sigmaX   = (Float_t) fClusters[4][i1];
-      Float_t sigmaY   = (Float_t) fClusters[5][i1];
+      AliPMDcludata *pmdcludata = 
+       (AliPMDcludata*)fPMDclucont->UncheckedAt(ient1);
+      Float_t cluXC    = pmdcludata->GetClusX();
+      Float_t cluYC    = pmdcludata->GetClusY();
+      Float_t cluADC   = pmdcludata->GetClusADC();
+      Float_t cluCELLS = pmdcludata->GetClusCells();
+      Float_t cluSIGX  = pmdcludata->GetClusSigmaX();
+      Float_t cluSIGY  = pmdcludata->GetClusSigmaY();
+      
       Float_t cluY0    = ktwobysqrt3*cluYC;
       Float_t cluX0    = cluXC - cluY0/2.;
+      
       // 
       // Cluster X centroid is back transformed
       //
@@ -172,664 +200,786 @@ void AliPMDClusteringV2::DoClust(Int_t idet, Int_t ismn, Double_t celladc[48][96
        {
          clusdata[0] = cluX0 - (24-1) + cluY0/2.;
        }
-      else if (ismn >= 12 && ismn <= 23)
+      else if (ismn  >= 12 && ismn <= 23)
        {
          clusdata[0] = cluX0 - (48-1) + cluY0/2.;
        }         
 
-      clusdata[1]      = cluY0;
-      clusdata[2]      = cluADC;
-      clusdata[3]      = cluCELLS;
-      clusdata[4]      = sigmaX;
-      clusdata[5]      = sigmaY;
-
+      clusdata[1]     = cluY0;
+      clusdata[2]     = cluADC;
+      clusdata[3]     = cluCELLS;
+      clusdata[4]     = cluSIGX;
+      clusdata[5]     = cluSIGY;
       //
       // Cells associated with a cluster
       //
       for (Int_t ihit = 0; ihit < 15; ihit++)
        {
-         celldataX[ihit] = 1;  // dummy nos. -- will be changed
-         celldataY[ihit] = 1;  // dummy nos. -- will be changed
+         Int_t dummyXY = pmdcludata->GetCellXY(ihit);
+        
+         Int_t celldumY   = dummyXY%10000;
+         Int_t celldumX   = dummyXY/10000;
+         Float_t cellY    = (Float_t) (ktwobysqrt3*celldumY/10);
+         Float_t cellX    = (Float_t) (celldumX/10 - (celldumY/2.)/10);
+         
+         // 
+         // Cell X centroid is back transformed
+         //
+         if (ismn < 12)
+           {
+             celldataX[ihit] = (Int_t) (cellX - (24-1) + cellY/2.);
+           }
+         else if (ismn  >= 12 && ismn <= 23)
+           {
+             celldataX[ihit] = (Int_t) (cellX - (48-1) + cellY/2.);
+           }     
+         celldataY[ihit] = (Int_t) cellY;
        }
 
       pmdcl = new AliPMDcluster(idet, ismn, clusdata, celldataX, celldataY);
       pmdcont->Add(pmdcl);
     }
+  fPMDclucont->Clear();
 }
 // ------------------------------------------------------------------------ //
-void AliPMDClusteringV2::Order()
-{
-  // Sorting algorithm
-  // sorts the ADC values from higher to lower
-  //
-  double dd[kNMX];
-  // matrix fEdepCell converted into
-  // one dimensional array dd. adum a place holder for double
-  int i, j, i1, i2, iord1[kNMX];
-  // information of
-  // ordering is stored in iord1, original array not ordered
-  //
-  // define arrays dd and iord1
-  for(i1=0; i1 < kNDIMX; i1++)
-    {
-      for(i2=0; i2 < kNDIMY; i2++)
-       {
-         i        = i1 + i2*kNDIMX;
-         iord1[i] = i;
-         dd[i]    = fEdepCell[i1][i2];
-       }
-    }
-  // sort and store sorting information in iord1
-
-  TMath::Sort(kNMX,dd,iord1);
-
-  // store the sorted information in fIord for later use
-  for(i=0; i<kNMX; i++)
-    {
-      j  = iord1[i];
-      i2 = j/kNDIMX;
-      i1 = j-i2*kNDIMX;
-      fIord[0][i]=i1;
-      fIord[1][i]=i2;
-    }
-}
-// ------------------------------------------------------------------------ //
-Int_t AliPMDClusteringV2::CrClust(Double_t ave, Double_t cutoff, Int_t nmx1)
+Int_t AliPMDClusteringV2::CrClust(Double_t ave, Double_t cutoff, Int_t nmx1,
+                                 Int_t iord1[], Double_t edepcell[])
 {
   // Does crude clustering
   // Finds out only the big patch by just searching the
   // connected cells
   //
 
-  int i,j,k,id1,id2,icl, numcell;
-  int jd1,jd2, icell, cellcount;
-  int clust[2][5000];
-  static int neibx[6]={1,0,-1,-1,0,1}, neiby[6]={0,1,1,0,-1,-1};
+  Int_t i,j,k,id1,id2,icl, numcell;
+  Int_t jd1,jd2, icell, cellcount;
+  Int_t clust[2][5000];
+  static Int_t neibx[6] = {1,0,-1,-1,0,1}, neiby[6] = {0,1,1,0,-1,-1};
 
   // neibx and neiby define ( incremental ) (i,j) for the neighbours of a
   // cell. There are six neighbours.
   // cellcount --- total number of cells having nonzero ener dep
   // numcell --- number of cells in a given supercluster
-  // ofstream ofl0("cells_loc",ios::out);
-  // initialize fInfocl[2][kNDIMX][kNDIMY]
-
+  
   AliDebug(1,Form("kNMX = %d nmx1 = %d kNDIMX = %d kNDIMY = %d ave = %f cutoff = %f",kNMX,nmx1,kNDIMX,kNDIMY,ave,cutoff));
   
-  for (j=0; j < kNDIMX; j++){
-    for(k=0; k < kNDIMY; k++){
-      fInfocl[0][j][k] = 0;
-      fInfocl[1][j][k] = 0;
+  for (j=0; j < kNDIMX; j++)
+    {
+      for(k=0; k < kNDIMY; k++)
+       {
+         fInfocl[0][j][k] = 0;
+         fInfocl[1][j][k] = 0;
+       }
+    }
+  for(i=0; i < kNMX; i++)
+    {
+      fInfcl[0][i] = -1;
+      
+      j  = iord1[i];
+      id2 = j/kNDIMX;
+      id1 = j-id2*kNDIMX;
+      
+      if(edepcell[j] <= cutoff)
+       {
+         fInfocl[0][id1][id2] = -1;
+       }
     }
-  }
-  for(i=0; i < kNMX; i++){
-    fInfcl[0][i] = -1;
-    id1=fIord[0][i];
-    id2=fIord[1][i];
-    if(fEdepCell[id1][id2] <= cutoff){fInfocl[0][id1][id2]=-1;}
-  }
   // ---------------------------------------------------------------
   // crude clustering begins. Start with cell having largest adc
   // count and loop over the cells in descending order of adc count
   // ---------------------------------------------------------------
-  icl=-1;
-  cellcount=-1;
-  for(icell=0; icell <= nmx1; icell++){
-    id1=fIord[0][icell];
-    id2=fIord[1][icell];
-    if(fInfocl[0][id1][id2] == 0 ){
-      // ---------------------------------------------------------------
-      // icl -- cluster #, numcell -- # of cells in it, clust -- stores
-      // coordinates of the cells in a cluster, fInfocl[0][i1][i2] is 1 for
-      // primary and 2 for secondary cells,
-      // fInfocl[1][i1][i2] stores cluster #
-      // ---------------------------------------------------------------
-      icl=icl+1;
-      numcell=0;
-      cellcount = cellcount + 1;
-      fInfocl[0][id1][id2]=1;
-      fInfocl[1][id1][id2]=icl;
-      fInfcl[0][cellcount]=icl;
-      fInfcl[1][cellcount]=id1;
-      fInfcl[2][cellcount]=id2;
-
-      clust[0][numcell]=id1;
-      clust[1][numcell]=id2;
-      for(i=1; i<5000; i++)clust[0][i] = -1;
-      // ---------------------------------------------------------------
-      // check for adc count in neib. cells. If ne 0 put it in this clust
-      // ---------------------------------------------------------------
-      for(i=0; i<6; i++){
-       jd1=id1+neibx[i];
-       jd2=id2+neiby[i];
-       if( (jd1 >= 0 && jd1 < kNDIMX) && (jd2 >= 0 && jd2 < kNDIMY) &&
-           fInfocl[0][jd1][jd2] == 0){
-         numcell=numcell+1;
-         fInfocl[0][jd1][jd2]=2;
-         fInfocl[1][jd1][jd2]=icl;
-         clust[0][numcell]=jd1;
-         clust[1][numcell]=jd2;
-         cellcount=cellcount+1;
-         fInfcl[0][cellcount]=icl;
-         fInfcl[1][cellcount]=jd1;
-         fInfcl[2][cellcount]=jd2;
-       }
-      }
-      // ---------------------------------------------------------------
-      // check adc count for neighbour's neighbours recursively and
-      // if nonzero, add these to the cluster.
-      // ---------------------------------------------------------------
-      for(i=1;i < 5000;i++){
-       if(clust[0][i] != -1){
-         id1=clust[0][i];
-         id2=clust[1][i];
-         for(j=0; j<6 ; j++){
-           jd1=id1+neibx[j];
-           jd2=id2+neiby[j];
+  icl       = -1;
+  cellcount = -1;
+  for(icell=0; icell <= nmx1; icell++)
+    {
+      j  = iord1[icell];
+      id2 = j/kNDIMX;
+      id1 = j-id2*kNDIMX;
+      if(fInfocl[0][id1][id2] == 0 )
+       {
+         // ---------------------------------------------------------------
+         // icl -- cluster #, numcell -- # of cells in it, clust -- stores
+         // coordinates of the cells in a cluster, fInfocl[0][i1][i2] is 1 for
+         // primary and 2 for secondary cells,
+         // fInfocl[1][i1][i2] stores cluster #
+         // ---------------------------------------------------------------
+         icl++;
+         numcell = 0;
+         cellcount++;
+         fInfocl[0][id1][id2]  = 1;
+         fInfocl[1][id1][id2]  = icl;
+         fInfcl[0][cellcount]  = icl;
+         fInfcl[1][cellcount]  = id1;
+         fInfcl[2][cellcount]  = id2;
+
+         clust[0][numcell]     = id1;
+         clust[1][numcell]     = id2;
+         for(i = 1; i < 5000; i++)
+           {
+             clust[0][i] = -1;
+           }
+         // ---------------------------------------------------------------
+         // check for adc count in neib. cells. If ne 0 put it in this clust
+         // ---------------------------------------------------------------
+         for(i = 0; i < 6; i++)
+           {
+           jd1 = id1 + neibx[i];
+           jd2 = id2 + neiby[i];
            if( (jd1 >= 0 && jd1 < kNDIMX) && (jd2 >= 0 && jd2 < kNDIMY) &&
-               fInfocl[0][jd1][jd2] == 0 ){
-             fInfocl[0][jd1][jd2] = 2;
-             fInfocl[1][jd1][jd2] = icl;
-             numcell              = numcell + 1;
-             clust[0][numcell]    = jd1;
-             clust[1][numcell]    = jd2;
-             cellcount            = cellcount+1;
-             fInfcl[0][cellcount] = icl;
-             fInfcl[1][cellcount] = jd1;
-             fInfcl[2][cellcount] = jd2;
+               fInfocl[0][jd1][jd2] == 0)
+             {
+               numcell++;
+               fInfocl[0][jd1][jd2] = 2;
+               fInfocl[1][jd1][jd2] = icl;
+               clust[0][numcell]    = jd1;
+               clust[1][numcell]    = jd2;
+               cellcount++;
+               fInfcl[0][cellcount] = icl;
+               fInfcl[1][cellcount] = jd1;
+               fInfcl[2][cellcount] = jd2;
+             }
+           }
+         // ---------------------------------------------------------------
+         // check adc count for neighbour's neighbours recursively and
+         // if nonzero, add these to the cluster.
+         // ---------------------------------------------------------------
+         for(i = 1;i < 5000; i++)
+           { 
+             if(clust[0][i] != -1)
+               {
+                 id1 = clust[0][i];
+                 id2 = clust[1][i];
+                 for(j = 0; j < 6 ; j++)
+                   {
+                     jd1 = id1 + neibx[j];
+                     jd2 = id2 + neiby[j];
+                     if( (jd1 >= 0 && jd1 < kNDIMX) && 
+                         (jd2 >= 0 && jd2 < kNDIMY) 
+                         && fInfocl[0][jd1][jd2] == 0 )
+                       {
+                         fInfocl[0][jd1][jd2] = 2;
+                         fInfocl[1][jd1][jd2] = icl;
+                         numcell++;
+                         clust[0][numcell]    = jd1;
+                         clust[1][numcell]    = jd2;
+                         cellcount++;
+                         fInfcl[0][cellcount] = icl;
+                         fInfcl[1][cellcount] = jd1;
+                         fInfcl[2][cellcount] = jd2;
+                       }
+                   }
+               }
            }
-         }
        }
-      }
     }
-  }
-  //  for(icell=0; icell<=cellcount; icell++){
-  //    ofl0 << fInfcl[0][icell] << " " << fInfcl[1][icell] << " " <<
-  //      fInfcl[2][icell] << endl;
-  //  }
   return cellcount;
 }
 // ------------------------------------------------------------------------ //
-void AliPMDClusteringV2::RefClust(Int_t incr)
+  void AliPMDClusteringV2::RefClust(Int_t incr, Double_t edepcell[])
 {
   // Does the refining of clusters
   // Takes the big patch and does gaussian fitting and
   // finds out the more refined clusters
-  //
 
+  AliPMDcludata *pmdcludata = 0;
+  TArrayI testncl;
+  TArrayI testindex;
   const Int_t kndim = 4500;
-
-  int i, j, k, i1, i2, id, icl, itest;
-  int ihld;
-  int ig, nsupcl;
-  int ncl[kndim], iord[kndim];
-
-  double x1, y1, z1, x2, y2, z2;
-  double rr;
-
-  double x[kndim], y[kndim], z[kndim];
-  double xc[kndim], yc[kndim], zc[kndim], cells[kndim];
-  double rcl[kndim], rcs[kndim];
-
-  // fClno counts the final clusters
+  Int_t    i, j, k, i1, i2, id, icl, itest, ihld;
+  Int_t    ig, nsupcl, clno, clX,clY;
+  Int_t    clxy[15];
+  Int_t    ncl[kndim], iord[kndim];
+  Float_t  clusdata[6];
+  Double_t x1, y1, z1, x2, y2, z2, rr;
+  Double_t x[kndim], y[kndim], z[kndim];
+  Double_t xc[kndim], yc[kndim], zc[kndim], cells[kndim];
+  Double_t rcl[kndim], rcs[kndim];
+  
+  for(Int_t kk = 0; kk < 15; kk++)
+    {
+      if( kk < 6 )clusdata[kk] = 0.;
+    }
+   
   // nsupcl =  # of superclusters; ncl[i]= # of cells in supercluster i
   // x, y and z store (x,y) coordinates of and energy deposited in a cell
   // xc, yc store (x,y) coordinates of the cluster center
-  // zc stores the energy deposited in a cluster
-  // rc is cluster radius
-  // finally the cluster information is put in 2-dimensional array clusters
-  // ofstream ofl1("checking.5",ios::app);
+  // zc stores the energy deposited in a cluster, rc is cluster radius
 
-  fClno  = -1;
+  clno   = -1;
   nsupcl = -1;
-  for(i=0; i<4500; i++){ncl[i]=-1;}
-  for(i=0; i<incr; i++){
-    if(fInfcl[0][i] != nsupcl){ nsupcl=nsupcl+1; }
-    if (nsupcl > 4500) {
-      AliWarning("RefClust: Too many superclusters!");
-      nsupcl = 4500;
-      break;
+  for(i = 0; i < 4500; i++)
+    {
+      ncl[i] = -1;
     }
-    ncl[nsupcl]=ncl[nsupcl]+1;
-  }
-
+  for(i = 0; i < incr; i++)
+    {
+      if(fInfcl[0][i] != nsupcl)
+       {
+         nsupcl++;
+       }
+      if (nsupcl > 4500) 
+       {
+         AliWarning("RefClust: Too many superclusters!");
+         nsupcl = 4500;
+         break;
+       }
+      ncl[nsupcl]++;
+    }
+  
   AliDebug(1,Form("Number of cells = %d Number of Superclusters = %d",
                  incr+1,nsupcl+1));
-
-  id=-1;
-  icl=-1;
-  for(i=0; i<nsupcl; i++){
-    if(ncl[i] == 0){
-      id++;
-      icl++;
-      // one  cell super-clusters --> single cluster
-      // cluster center at the centyer of the cell
-      // cluster radius = half cell dimension
-      if (fClno >= 5000) {
-       AliWarning("RefClust: Too many clusters! more than 5000");
-       return;
-      }
-      fClno++;
-      i1 = fInfcl[1][id];
-      i2 = fInfcl[2][id];
-      fClusters[0][fClno] = fCoord[0][i1][i2];
-      fClusters[1][fClno] = fCoord[1][i1][i2];
-      fClusters[2][fClno] = fEdepCell[i1][i2];
-      fClusters[3][fClno] = 1.;
-      fClusters[4][fClno] = 0.0;
-      fClusters[5][fClno] = 0.0;
-      //ofl1 << icl << " " << fCoord[0][i1][i2] << " " << fCoord[1][i1][i2] <<
-      //" " << fEdepCell[i1][i2] << " " << fClusters[3][fClno] <<endl;
-    }else if(ncl[i] == 1){
-      // two cell super-cluster --> single cluster
-      // cluster center is at ener. dep.-weighted mean of two cells
-      // cluster radius == half cell dimension
-      id++;
-      icl++;
-      if (fClno >= 5000) {
-       AliWarning("RefClust: Too many clusters! more than 5000");
-       return;
-      }
-      fClno++;
-      i1   = fInfcl[1][id];
-      i2   = fInfcl[2][id];
-      x1   = fCoord[0][i1][i2];
-      y1   = fCoord[1][i1][i2];
-      z1   = fEdepCell[i1][i2];
-
-      id++;
-      i1   = fInfcl[1][id];
-      i2   = fInfcl[2][id];
-      x2   = fCoord[0][i1][i2];
-      y2   = fCoord[1][i1][i2];
-      z2   = fEdepCell[i1][i2];
-
-      fClusters[0][fClno] = (x1*z1+x2*z2)/(z1+z2);
-      fClusters[1][fClno] = (y1*z1+y2*z2)/(z1+z2);
-      fClusters[2][fClno] = z1+z2;
-      fClusters[3][fClno] = 2.;
-      fClusters[4][fClno] = sqrt(z1*z2)/(z1+z2);
-      fClusters[5][fClno] = 0;  // sigma large nonzero, sigma small zero
-
-      //ofl1 << icl << " " << fClusters[0][fClno] << " " << fClusters[1][fClno]
-      //   << " " << fClusters[2][fClno] << " " <<fClusters[3][fClno] <<endl;
-    }
-    else{
-      id      = id + 1;
-      iord[0] = 0;
-      // super-cluster of more than two cells - broken up into smaller
-      // clusters gaussian centers computed. (peaks separated by > 1 cell)
-      // Begin from cell having largest energy deposited This is first
-      // cluster center
-      // *****************************************************************
-      // NOTE --- POSSIBLE MODIFICATION: ONE MAY NOT BREAKING SUPERCLUSTERS
-      // IF NO. OF CELLS IS NOT TOO LARGE ( SAY 5 OR 6 )
-      // SINCE WE EXPECT THE SUPERCLUSTER 
-      // TO BE A SINGLE CLUSTER
-      //*******************************************************************
-
-      i1      = fInfcl[1][id];
-      i2      = fInfcl[2][id];
-      x[0]    = fCoord[0][i1][i2];
-      y[0]    = fCoord[1][i1][i2];
-      z[0]    = fEdepCell[i1][i2];
-      iord[0] = 0;
-      for(j=1;j<=ncl[i];j++){
-
-       id      = id + 1;
-       i1      = fInfcl[1][id];
-       i2      = fInfcl[2][id];
-       iord[j] = j;
-       x[j]    = fCoord[0][i1][i2];
-       y[j]    = fCoord[1][i1][i2];
-       z[j]    = fEdepCell[i1][i2];
-      }
-      // arranging cells within supercluster in decreasing order
-      for(j=1;j<=ncl[i];j++)
+  
+  id  = -1;
+  icl = -1;
+  for(i = 0; i < nsupcl; i++)
+    {
+      if(ncl[i] == 0)
        {
-         itest = 0;
-         ihld  = iord[j];
-         for(i1=0; i1<j; i1++)
+         id++;
+         icl++;
+         // one  cell super-clusters --> single cluster
+         // cluster center at the centyer of the cell
+         // cluster radius = half cell dimension
+         if (clno >= 5000) 
            {
-             if(itest == 0 && z[iord[i1]] < z[ihld])
-               {
-                 itest = 1;
-                 for(i2=j-1;i2>=i1;i2--)
-                   {
-                     iord[i2+1] = iord[i2];
-                   }
-                 iord[i1] = ihld;
-               }
+             AliWarning("RefClust: Too many clusters! more than 5000");
+             return;
            }
+         clno++;
+         i1          = fInfcl[1][id];
+         i2          = fInfcl[2][id];
+         Int_t i12 = i1 + i2*kNDIMX;
+         clusdata[0] = fCoord[0][i1][i2];
+         clusdata[1] = fCoord[1][i1][i2];
+         clusdata[2] = edepcell[i12];
+         clusdata[3] = 1.;
+         clusdata[4] = 0.0;
+         clusdata[5] = 0.0;
+         
+         //cell information
+         clX = (Int_t) fCoord[0][i1][i2]*10;
+         clY = (Int_t) fCoord[1][i1][i2]*10;
+         clxy[0] = clX*10000 + clY;
+         for(Int_t icltr = 1; icltr < 15; icltr++)
+           {
+             clxy[icltr] = -1;
+           }
+         pmdcludata  = new AliPMDcludata(clusdata,clxy);
+         fPMDclucont->Add(pmdcludata);
+         
+         
        }
-
-      // compute the number of clusters and their centers ( first
-      // guess )
-      // centers must be separated by cells having smaller ener. dep.
-      // neighbouring centers should be either strong or well-separated
-      ig     = 0;
-      xc[ig] = x[iord[0]];
-      yc[ig] = y[iord[0]];
-      zc[ig] = z[iord[0]];
-      for(j=1;j<=ncl[i];j++){
-       itest = -1;
-       x1    = x[iord[j]];
-       y1    = y[iord[j]];
-       for(k=0;k<=ig;k++){
-         x2 = xc[k];
-         y2 = yc[k];
-         rr = Distance(x1,y1,x2,y2);
-         //***************************************************************
-         // finetuning cluster splitting
-         // the numbers zc/4 and zc/10 may need to be changed. 
-         // Also one may need to add one more layer because our 
-         // cells are smaller in absolute scale
-         //****************************************************************
-
-
-         if( rr >= 1.1 && rr < 1.8 && z[iord[j]] > zc[k]/4.)
-           itest++;
-         if( rr >= 1.8 && rr < 2.1 && z[iord[j]] > zc[k]/10.)
-           itest++;
-         if( rr >= 2.1)itest++;
-       }
-       if(itest == ig){
-         ig++;
-         xc[ig] = x1;
-         yc[ig] = y1;
-         zc[ig] = z[iord[j]];
-       }
-      }
-
-      ClustDetails(ncl[i], ig, x[0], y[0] ,z[0], xc[0], yc[0], zc[0],
-                  rcl[0], rcs[0], cells[0]);
-
-      icl = icl + ig + 1;
-
-      for(j=0; j<=ig; j++)
+      else if(ncl[i] == 1)
        {
-         if (fClno >= 5000)
+         // two cell super-cluster --> single cluster
+         // cluster center is at ener. dep.-weighted mean of two cells
+         // cluster radius == half cell dimension
+         id++;
+         icl++;
+         if (clno >= 5000) 
            {
              AliWarning("RefClust: Too many clusters! more than 5000");
              return;
            }
-         fClno++;
-         fClusters[0][fClno] = xc[j];
-         fClusters[1][fClno] = yc[j];
-         fClusters[2][fClno] = zc[j];
-         fClusters[4][fClno] = rcl[j];
-         fClusters[5][fClno] = rcs[j];
-         if(ig == 0)
-           {
-             fClusters[3][fClno] = ncl[i];
-           }
-         else
+         clno++;
+         i1   = fInfcl[1][id];
+         i2   = fInfcl[2][id];
+         Int_t i12 = i1 + i2*kNDIMX;
+         
+         x1   = fCoord[0][i1][i2];
+         y1   = fCoord[1][i1][i2];
+         z1   = edepcell[i12];
+         
+         id++;
+         i1   = fInfcl[1][id];
+         i2   = fInfcl[2][id];
+         i12  = i1 + i2*kNDIMX;
+         
+         x2   = fCoord[0][i1][i2];
+         y2   = fCoord[1][i1][i2];
+         z2   = edepcell[i12];
+         
+         clusdata[0] = (x1*z1+x2*z2)/(z1+z2);
+         clusdata[1] = (y1*z1+y2*z2)/(z1+z2);
+         clusdata[2] = z1+z2;
+         clusdata[3] = 2.;
+         clusdata[4] = (TMath::Sqrt(z1*z2))/(z1+z2);
+         clusdata[5] = 0.0;
+
+         clX = (Int_t) x1*10;
+         clY = (Int_t) y1*10;
+         clxy[0] = clX*10000 + clY;
+         
+         clX = (Int_t) x2*10;
+         clY = (Int_t) y2*10;
+         clxy[1] = clX*10000 + clY;
+         
+         for(Int_t icltr = 2; icltr < 15; icltr++)
            {
-             fClusters[3][fClno] = cells[j];
+             clxy[icltr] = -1;
            }
+         pmdcludata  = new AliPMDcludata(clusdata, clxy);
+         fPMDclucont->Add(pmdcludata);
        }
-
-
+      else{
+       id++;
+       iord[0] = 0;
+       // super-cluster of more than two cells - broken up into smaller
+       // clusters gaussian centers computed. (peaks separated by > 1 cell)
+       // Begin from cell having largest energy deposited This is first
+       // cluster center
+       // *****************************************************************
+       // NOTE --- POSSIBLE MODIFICATION: ONE MAY NOT BREAKING SUPERCLUSTERS
+       // IF NO. OF CELLS IS NOT TOO LARGE ( SAY 5 OR 6 )
+       // SINCE WE EXPECT THE SUPERCLUSTER 
+       // TO BE A SINGLE CLUSTER
+       //*******************************************************************
+       
+       i1      = fInfcl[1][id];
+       i2      = fInfcl[2][id];
+       Int_t i12 = i1 + i2*kNDIMX;
+       
+       x[0]    = fCoord[0][i1][i2];
+       y[0]    = fCoord[1][i1][i2];
+       z[0]    = edepcell[i12];
+       
+       iord[0] = 0;
+       for(j = 1; j <= ncl[i]; j++)
+         {
+           
+           id++;
+           i1      = fInfcl[1][id];
+           i2      = fInfcl[2][id];
+           Int_t i12 = i1 + i2*kNDIMX;
+           iord[j] = j;
+           x[j]    = fCoord[0][i1][i2];
+           y[j]    = fCoord[1][i1][i2];
+           z[j]    = edepcell[i12];
+         }
+       
+       // arranging cells within supercluster in decreasing order
+       for(j = 1; j <= ncl[i];j++)
+         {
+           itest = 0;
+           ihld  = iord[j];
+           for(i1 = 0; i1 < j; i1++)
+             {
+               if(itest == 0 && z[iord[i1]] < z[ihld])
+                 {
+                   itest = 1;
+                   for(i2 = j-1;i2 >= i1;i2--)
+                     {
+                       iord[i2+1] = iord[i2];
+                     }
+                   iord[i1] = ihld;
+                 }
+             }
+         }
+       
+       
+       // compute the number of clusters and their centers ( first
+       // guess )
+       // centers must be separated by cells having smaller ener. dep.
+       // neighbouring centers should be either strong or well-separated
+       ig     = 0;
+       xc[ig] = x[iord[0]];
+       yc[ig] = y[iord[0]];
+       zc[ig] = z[iord[0]];
+       for(j = 1; j <= ncl[i]; j++)
+         {
+           itest = -1;
+           x1    = x[iord[j]];
+           y1    = y[iord[j]];
+           for(k = 0; k <= ig; k++)
+             {
+               x2 = xc[k];
+               y2 = yc[k];
+               rr = Distance(x1,y1,x2,y2);
+               //************************************************************
+               // finetuning cluster splitting
+               // the numbers zc/4 and zc/10 may need to be changed. 
+               // Also one may need to add one more layer because our 
+               // cells are smaller in absolute scale
+               //************************************************************
+               
+               
+               if( rr >= 1.1 && rr < 1.8 && z[iord[j]] > zc[k]/4.) itest++;
+               if( rr >= 1.8 && rr < 2.1 && z[iord[j]] > zc[k]/10.) itest++;
+               if( rr >= 2.1)itest++;
+             }
+           
+           if(itest == ig)
+             {
+               ig++;
+               xc[ig] = x1;
+               yc[ig] = y1;
+               zc[ig] = z[iord[j]];
+             }
+         }
+       ClustDetails(ncl[i], ig, x[0], y[0] ,z[0], xc[0], yc[0], zc[0],
+                    rcl[0], rcs[0], cells[0], testncl, testindex);
+       
+       Int_t pp = 0;
+       for(j = 0; j <= ig; j++)
+         { 
+           clno++;
+           if (clno >= 5000)
+             {
+               AliWarning("RefClust: Too many clusters! more than 5000");
+               return;
+             }
+           clusdata[0] = xc[j];
+           clusdata[1] = yc[j];
+           clusdata[2] = zc[j];
+           clusdata[4] = rcl[j];
+           clusdata[5] = rcs[j];
+           if(ig == 0)
+             {
+               clusdata[3] = ncl[i];
+             }
+           else
+             {
+               clusdata[3] = cells[j];
+             }
+           // cell information
+           Int_t ncellcls =  testncl[j];
+           if( ncellcls < 15 )
+             {
+               for(Int_t kk = 1; kk <= ncellcls; kk++)
+                 {
+                   Int_t ll =  testindex[pp];
+                   clX = (Int_t) x[ll]*10;
+                   clY = (Int_t) y[ll]*10;
+                   clxy[kk-1] = (Int_t) clX*10000 + clY ;
+                   pp++;
+                 }
+               for(Int_t icltr = ncellcls ; icltr < 15; icltr++)
+                 {
+                   clxy[icltr] = -1;
+                 }
+             }
+           pmdcludata = new AliPMDcludata(clusdata, clxy);
+           fPMDclucont->Add(pmdcludata);
+         }
+       testncl.Set(0);
+       testindex.Set(0);
+      }
     }
-  }
 }
-
-
 // ------------------------------------------------------------------------ //
-
-void AliPMDClusteringV2::ClustDetails(Int_t ncell, Int_t nclust,
-                                     Double_t &x, Double_t &y, Double_t &z,
-                                     Double_t &xc, Double_t &yc, Double_t &zc,
-                                     Double_t &rcl, Double_t &rcs,
-                                     Double_t &cells)
+void AliPMDClusteringV2::ClustDetails(Int_t ncell, Int_t nclust, Double_t &x, 
+                                     Double_t &y, Double_t &z, Double_t &xc,
+                                     Double_t &yc, Double_t &zc,
+                                     Double_t &rcl, Double_t &rcs, 
+                                     Double_t &cells, TArrayI &testncl,
+                                     TArrayI &testindex)
 {
   // function begins
   //
-  
-  const Int_t kndim1 = 4500;
-  const Int_t kndim2 = 10;
-  const Int_t kndim3 = 100;
 
-  int i, j, k, i1, i2;
-  int cluster[kndim1][kndim2];
+  const Int_t kndim1 = 2000;
+  const Int_t kndim2 = 10;
+  const Int_t kndim3 = 400;
   
-  double x1, y1, x2, y2, rr;
-  double sumx, sumy, sumxy, sumxx;
-  double sum, sum1, sumyy;
-  double b, c, r1, r2;
-
-  double xx[kndim1], yy[kndim1], zz[kndim1];
-  double xxc[kndim1], yyc[kndim1];
-
-  double str[kndim1];
-
-  double str1[kndim1];
-  double xcl[kndim1], ycl[kndim1], cln[kndim1];
-  double clustcell[kndim1][kndim3];
-
-  for(i=0; i<=nclust; i++){
-   xxc[i]=*(&xc+i); 
-   yyc[i]=*(&yc+i); 
-   str[i]=0.; 
-   str1[i]=0.;
-  }
-  for(i=0; i<=ncell; i++){
-    xx[i]=*(&x+i); 
-    yy[i]=*(&y+i); 
-    zz[i]=*(&z+i);
-  }
-  // INITIALIZE 
-  for(i=0; i<4500; i++){
-    for(j=0; j<100; j++){
-      clustcell[i][j]=0.;
-    }
-  }
+  Int_t    i, j, k, i1, i2;
+  Int_t    cluster[kndim1][kndim2], cell[kndim1][kndim3];
+  
+  Double_t x1, y1, x2, y2, rr, b, c, r1, r2;
+  Double_t sumx, sumy, sumxy, sumxx, sum, sum1, sumyy;
+  Double_t xx[kndim1], yy[kndim1], zz[kndim1];
+  Double_t xxc[kndim1], yyc[kndim1],clustcell[kndim3][kndim1];
+  Double_t str[kndim1], str1[kndim1],xcl[kndim1], ycl[kndim1], cln[kndim1];
 
-  // INITIALIZE
-  for(i=0;i<4500;i++){
-    for(j=0;j<10;j++){
-      cluster[i][j]=0;
+  for(i = 0; i <= nclust; i++)
+    {
+      xxc[i]  = *(&xc+i); 
+      yyc[i]  = *(&yc+i); 
+      str[i]  = 0.; 
+      str1[i] = 0.;
     }
-  }
-
-
-  if(nclust > 0){
-    // more than one cluster
-    // checking cells shared between several  clusters.
-    // First check if the cell is within
-    // one cell unit ( nearest neighbour). Else, 
-    // if it is within 1.74 cell units ( next nearest )
-    // Else if it is upto 2 cell units etc.
-
-    for (i=0; i<=ncell; i++){
-      x1            = xx[i];
-      y1            = yy[i];
-      cluster[i][0] = 0;
-      // distance <= 1 cell unit
-      for(j=0; j<=nclust; j++)
+  for(i = 0; i <= ncell; i++)
+    {
+      xx[i] = *(&x+i); 
+      yy[i] = *(&y+i); 
+      zz[i] = *(&z+i);
+    }
+
+  // INITIALIZE 
+
+  for(i = 0; i < kndim1; i++)
+    {
+      for(j = 0; j < kndim2; j++)
        {
-         x2 = xxc[j];
-         y2 = yyc[j];
-         rr = Distance(x1, y1, x2, y2);
-         if(rr <= 1.)
-           {
-             cluster[i][0]++;
-             i1             = cluster[i][0];
-             cluster[i][i1] = j;
-           }
+         cluster[i][j] = 0;
+         
+       }
+      for(j = 0; j < kndim3; j++)
+       {
+         cell[i][j]      = 0;
+         clustcell[j][i] = 0.;
        }
-      // next nearest neighbour
-      if(cluster[i][0] == 0)
+    }
+
+
+  if(nclust > 0)
+    {
+      // more than one cluster
+      // checking cells shared between several  clusters.
+      // First check if the cell is within
+      // one cell unit ( nearest neighbour). Else, 
+      // if it is within 1.74 cell units ( next nearest )
+      // Else if it is upto 2 cell units etc.
+      
+      for (i = 0; i <= ncell; i++)
        {
-         for(j=0; j<=nclust; j++)
+         x1            = xx[i];
+         y1            = yy[i];
+         cluster[i][0] = 0;
+         // distance <= 1 cell unit
+         for(j = 0; j <= nclust; j++)
            {
              x2 = xxc[j];
              y2 = yyc[j];
              rr = Distance(x1, y1, x2, y2);
-             if(rr <= sqrt(3.))
+             if(rr <= 1.)
                {
                  cluster[i][0]++;
                  i1             = cluster[i][0];
                  cluster[i][i1] = j;
                }
            }
+         // next nearest neighbour
+         if(cluster[i][0] == 0)
+           {
+             for(j=0; j<=nclust; j++)
+               {
+                 x2 = xxc[j];
+                 y2 = yyc[j];
+                 rr = Distance(x1, y1, x2, y2);
+                 if(rr <= TMath::Sqrt(3.))
+                   {
+                     cluster[i][0]++;
+                     i1             = cluster[i][0];
+                     cluster[i][i1] = j;
+                   }
+               }
+           }
+         // next-to-next nearest neighbour
+         if(cluster[i][0] == 0)
+           {
+             for(j=0; j<=nclust; j++)
+               {
+                 x2 = xxc[j];
+                 y2 = yyc[j];
+                 rr = Distance(x1, y1, x2, y2);
+                 if(rr <= 2.)
+                   {
+                     cluster[i][0]++;
+                     i1             = cluster[i][0];
+                     cluster[i][i1] = j;
+                   }
+               }
+           }
+         // one more
+         if(cluster[i][0] == 0)
+           {
+             for(j = 0; j <= nclust; j++)
+               {
+                 x2 = xxc[j];
+                 y2 = yyc[j];
+                 rr = Distance(x1, y1, x2, y2);
+                 if(rr <= 2.7)
+                   {
+                     cluster[i][0]++;
+                     i1             = cluster[i][0];
+                     cluster[i][i1] = j;
+                   }
+               }
+           }
        }
-      // next-to-next nearest neighbour
-      if(cluster[i][0] == 0)
+      
+      // computing cluster strength. Some cells are shared.
+      for(i = 0; i <= ncell; i++)
        {
-         for(j=0; j<=nclust; j++)
+         if(cluster[i][0] != 0)
            {
-             x2 = xxc[j];
-             y2 = yyc[j];
-             rr = Distance(x1, y1, x2, y2);
-             if(rr <= 2.)
+             i1 = cluster[i][0];
+             for(j = 1; j <= i1; j++)
                {
-                 cluster[i][0]++;
-                 i1 = cluster[i][0];
-                 cluster[i][i1] = j;
+                 i2       = cluster[i][j];
+                 str[i2] += zz[i]/i1;
                }
            }
        }
-      // one more
-      if(cluster[i][0] == 0)
+      
+      for(k = 0; k < 5; k++)
        {
-         for(j=0; j<=nclust; j++)
+         for(i = 0; i <= ncell; i++)
            {
-             x2 = xxc[j];
-             y2 = yyc[j];
-             rr = Distance(x1, y1, x2, y2);
-             if(rr <= 2.7)
+             if(cluster[i][0] != 0)
                {
-                 cluster[i][0]++;
-                 i1 = cluster[i][0];
-                 cluster[i][i1] = j;
+                 i1=cluster[i][0];
+                 sum=0.;
+                 for(j = 1; j <= i1; j++)
+                   {
+                     sum += str[cluster[i][j]];
+                   }
+                 
+                 for(j = 1; j <= i1; j++)
+                   {
+                     i2               = cluster[i][j]; 
+                     str1[i2]        +=  zz[i]*str[i2]/sum;
+                     clustcell[i2][i] = zz[i]*str[i2]/sum;
+                   }
                }
            }
+         
+         
+         for(j = 0; j <= nclust; j++)
+           {
+             str[j]  = str1[j];
+             str1[j] = 0.;
+           }
        }
-    }
-
-
-    // computing cluster strength. Some cells are shared.
-    for(i=0; i<=ncell; i++){
-      if(cluster[i][0] != 0){
-       i1 = cluster[i][0];
-       for(j=1; j<=i1; j++){
-         i2      = cluster[i][j];
-         str[i2] = str[i2]+zz[i]/i1;
+      
+      for(i = 0; i <= nclust; i++)
+       {
+         sumx = 0.;
+         sumy = 0.;
+         sum  = 0.;
+         sum1 = 0.;
+         for(j = 0; j <= ncell; j++)
+           {
+             if(clustcell[i][j] != 0)
+               {
+                 sumx  +=  clustcell[i][j]*xx[j];
+                 sumy  +=  clustcell[i][j]*yy[j];
+                 sum   +=  clustcell[i][j];
+                 sum1  +=  clustcell[i][j]/zz[j];
+               }
+           }
+         //** xcl and ycl are cluster centroid positions ( center of gravity )
+         
+         xcl[i] = sumx/sum;
+         ycl[i] = sumy/sum;
+         cln[i] = sum1;
+         sumxx = 0.;
+         sumyy = 0.;
+         sumxy = 0.;
+         for(j = 0; j <= ncell; j++)
+           {
+             sumxx += clustcell[i][j]*(xx[j]-xcl[i])*(xx[j]-xcl[i])/sum;
+             sumyy += clustcell[i][j]*(yy[j]-ycl[i])*(yy[j]-ycl[i])/sum;
+             sumxy += clustcell[i][j]*(xx[j]-xcl[i])*(yy[j]-ycl[i])/sum;
+           }
+         b = sumxx+sumyy;
+         c = sumxx*sumyy-sumxy*sumxy;
+         // ******************r1 and r2 are major and minor axes ( r1 > r2 ). 
+         r1 = b/2.+TMath::Sqrt(b*b/4.-c);
+         r2 = b/2.-TMath::Sqrt(b*b/4.-c);
+         // final assignments to proper external variables
+         *(&xc + i) = xcl[i];
+         *(&yc + i) = ycl[i];
+         *(&zc + i) = str[i];
+         *(&cells + i) = cln[i];
+         *(&rcl+i) = r1;
+         *(&rcs+i) = r2;
        }
-      }
-    }
-
-    for(k=0; k<5; k++)
-      {
-       for(i=0; i<=ncell; i++)
-         {
-           if(cluster[i][0] != 0)
-             {
-               i1=cluster[i][0];
-               sum=0.;
-               for(j=1; j<=i1; j++)
-                 {
-                   sum=sum+str[cluster[i][j]];
-                 }
-
-               for(j=1; j<=i1; j++)
-                 {
-                   i2 = cluster[i][j]; 
-                   str1[i2]         = str1[i2] + zz[i]*str[i2]/sum;
-                   clustcell[i2][i] = zz[i]*str[i2]/sum;
-                 }
-             }
-         }
-
-
-         for(j=0; j<=nclust; j++)
+      
+      //To get the cell position in a cluster
+      
+      for(Int_t ii=0; ii<= ncell; ii++)
+       {
+         Int_t jj = cluster[ii][0]; 
+         for(Int_t kk=1; kk<= jj; kk++)
            {
-             str[j]=str1[j];
-             str1[j]=0.;
+             Int_t ll = cluster[ii][kk];
+             cell[ll][0]++;
+             cell[ll][cell[ll][0]] = ii;
            }
-      }
-
-    for(i=0; i<=nclust; i++){
+       }
+      
+      testncl.Set(nclust+1);
+      Int_t counter = 0;
+      
+      for(Int_t ii=0; ii <= nclust; ii++)
+       {
+         testncl[ii] =  cell[ii][0];
+         counter += testncl[ii];
+       }
+      testindex.Set(counter);
+      Int_t ll = 0;
+      for(Int_t ii=0; ii<= nclust; ii++)
+       {
+         for(Int_t jj = 1; jj<= testncl[ii]; jj++)
+           {
+             Int_t kk = cell[ii][jj];
+             testindex[ll] = kk;
+             ll++;
+           }
+       }
+      
+    }
+  else
+    {
       sumx = 0.;
       sumy = 0.;
       sum  = 0.;
       sum1 = 0.;
-      for(j=0; j<=ncell; j++){
-       if(clustcell[i][j] != 0){
-         sumx = sumx+clustcell[i][j]*xx[j];
-         sumy = sumy+clustcell[i][j]*yy[j];
-         sum  = sum+clustcell[i][j];
-         sum1 = sum1+clustcell[i][j]/zz[j];
+      i    = 0;
+      for(j = 0; j <= ncell; j++)
+       {
+         sumx += zz[j]*xx[j];
+         sumy += zz[j]*yy[j];
+         sum  += zz[j];
+         sum1++;
        }
-      }
-      //***** xcl and ycl are cluster centroid positions ( center of gravity )
-
       xcl[i] = sumx/sum;
       ycl[i] = sumy/sum;
       cln[i] = sum1;
-      sumxx = 0.;
-      sumyy = 0.;
-      sumxy = 0.;
-      for(j=0; j<=ncell; j++){
-       sumxx = sumxx+clustcell[i][j]*(xx[j]-xcl[i])*(xx[j]-xcl[i])/sum;
-       sumyy = sumyy+clustcell[i][j]*(yy[j]-ycl[i])*(yy[j]-ycl[i])/sum;
-       sumxy = sumxy+clustcell[i][j]*(xx[j]-xcl[i])*(yy[j]-ycl[i])/sum;
-      }
-      b = sumxx+sumyy;
-      c = sumxx*sumyy-sumxy*sumxy;
-      // ******************r1 and r2 are major and minor axes ( r1 > r2 ). 
-      r1 = b/2.+sqrt(b*b/4.-c);
-      r2 = b/2.-sqrt(b*b/4.-c);
-      // final assignments to proper external variables
-      *(&xc + i) = xcl[i];
-      *(&yc + i) = ycl[i];
-      *(&zc + i) = str[i];
+      sumxx  = 0.;
+      sumyy  = 0.;
+      sumxy  = 0.;
+      for(j = 0; j <= ncell; j++)
+       {
+         sumxx += clustcell[i][j]*(xx[j]-xcl[i])*(xx[j]-xcl[i])/sum;
+         sumyy += clustcell[i][j]*(yy[j]-ycl[i])*(yy[j]-ycl[i])/sum;
+         sumxy += clustcell[i][j]*(xx[j]-xcl[i])*(yy[j]-ycl[i])/sum;
+       }
+      b  = sumxx+sumyy;
+      c  = sumxx*sumyy-sumxy*sumxy;
+      r1 = b/2.+ TMath::Sqrt(b*b/4.-c);
+      r2 = b/2.- TMath::Sqrt(b*b/4.-c);
+      
+      // To get the cell position in a cluster
+      testncl.Set(nclust+1);
+      testindex.Set(ncell);
+      cell[0][0] = ncell;
+      testncl[0] = cell[0][0];
+      Int_t ll   = 0;
+      for(Int_t ii=1; ii<=ncell; ii++)
+       {
+         cell[0][ii]=ii;
+         //clustcell[0][ii]=1.;
+         Int_t kk = cell[0][ii];
+         testindex[ll] = kk;
+         ll++;
+       }
+      // final assignments
+      *(&xc + i)    = xcl[i];
+      *(&yc + i)    = ycl[i];
+      *(&zc + i)    = str[i];
       *(&cells + i) = cln[i];
-      *(&rcl+i) = r1;
-      *(&rcs+i) = r2;
-    }
-  }else{
-    sumx = 0.;
-    sumy = 0.;
-    sum  = 0.;
-    sum1 = 0.;
-    i    = 0;
-    for(j=0; j<=ncell; j++){
-      sumx = sumx+zz[j]*xx[j];
-      sumy = sumy+zz[j]*yy[j];
-      sum  = sum+zz[j];
-      sum1 = sum1+1.;
-    }
-    xcl[i] = sumx/sum;
-    ycl[i] = sumy/sum;
-    cln[i] = sum1;
-    sumxx  = 0.;
-    sumyy  = 0.;
-    sumxy  = 0.;
-    for(j=0; j<=ncell; j++){
-      sumxx = sumxx+clustcell[i][j]*(xx[j]-xcl[i])*(xx[j]-xcl[i])/sum;
-      sumyy = sumyy+clustcell[i][j]*(yy[j]-ycl[i])*(yy[j]-ycl[i])/sum;
-      sumxy = sumxy+clustcell[i][j]*(xx[j]-xcl[i])*(yy[j]-ycl[i])/sum;
+      *(&rcl+i)     = r1;
+      *(&rcs+i)     = r2;
     }
-    b  = sumxx+sumyy;
-    c  = sumxx*sumyy-sumxy*sumxy;
-    r1 = b/2.+sqrt(b*b/4.-c);
-    r2 = b/2.-sqrt(b*b/4.-c);
-    // final assignments
-    *(&xc + i)    = xcl[i];
-    *(&yc + i)    = ycl[i];
-    *(&zc + i)    = str[i];
-    *(&cells + i) = cln[i];
-    *(&rcl+i)     = r1;
-    *(&rcs+i)     = r2;
-  }
 }
 
 // ------------------------------------------------------------------------ //
 Double_t AliPMDClusteringV2::Distance(Double_t x1, Double_t y1,
                                      Double_t x2, Double_t y2)
 {
-  return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
+  return TMath::Sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
 }
 // ------------------------------------------------------------------------ //
 void AliPMDClusteringV2::SetEdepCut(Float_t decut)
index 9b7bf9e9115036cadff30cfb6ff9a511ef51f467..c74cb68f82d0eaa2596d43c96a69dc61eea49e2c 100644 (file)
@@ -9,97 +9,58 @@
 //  clustering code for alice pmd                      //
 //                                                     //
 //-----------------------------------------------------//
-/* --------------------------------------------------------------------
-   Code developed by S. C. Phatak, Institute of Physics,
-   Bhubaneswar 751 005 ( phatak@iopb.res.in ) Given the energy deposited
-   ( or ADC value ) in each cell of supermodule ( pmd or cpv ), the code
-   builds up superclusters and breaks them into clusters. The input is 
-   in array d[ndimx][ndimy] and cluster information is in array
-   clusters[5][5000]. integer clno gives total number of clusters in the
-   supermodule.
-   d, clno  and clusters are the only global ( public ) variables. Others
-   are local ( private ) to the code.
-   At the moment, the data is read for whole detector ( all supermodules
-   and pmd as well as cpv. This will have to be modify later )
-   LAST UPDATE  :  October 23, 2002
------------------------------------------------------------------------*/
+// Author      : S.C. Phatak
+// Modified by : B.K. Nandi, Ajay Dash
+//
 #include "Rtypes.h"
+#include "AliPMDClustering.h"
 
 class TObjArray;
+class TArrayI;
 class AliPMDcluster;
+class AliPMDcludata;
 class AliPMDClusteringV2 : public AliPMDClustering
 {
-
+  
  public:
   AliPMDClusteringV2();
+  AliPMDClusteringV2(const AliPMDClusteringV2 &pmdclv2);
+  AliPMDClusteringV2 &operator=(const AliPMDClusteringV2 &pmdclv2);
   virtual ~AliPMDClusteringV2();
-
+  
   void     DoClust(Int_t idet, Int_t ismn, Double_t celladc[][96],
                   TObjArray *pmdcont);
-  void     Order();
-  
-  Int_t    CrClust(Double_t ave, Double_t cutoff, Int_t nmx1);
-  void     RefClust(Int_t incr);
-
+  Int_t    CrClust(Double_t ave, Double_t cutoff, Int_t nmx1,
+                  Int_t iord1[], Double_t edepcell[]);
+  void     RefClust(Int_t incr, Double_t edepcell[]);
+       
   void     ClustDetails(Int_t ncell, Int_t nclust, Double_t &x,
-                      Double_t &y, Double_t &z, Double_t &xc,
-                      Double_t &yc, Double_t &zc,
-                      Double_t &rcl, Double_t &rcs, Double_t &cells);
-  Double_t Distance(Double_t x1, Double_t y1,
-                   Double_t x2, Double_t y2);
+                       Double_t &y, Double_t &z, Double_t &xc,
+                       Double_t &yc, Double_t &zc,
+                       Double_t &rcl, Double_t &rcs, Double_t &cells,
+                       TArrayI &testncl, TArrayI &testindex);
+  Double_t Distance(Double_t x1, Double_t y1, Double_t x2, Double_t y2);
   void     SetEdepCut(Float_t decut);
   
  protected:
-
+  
+  TObjArray *fPMDclucont;
+  
   static const Double_t fgkSqroot3by2;  // fgkSqroot3by2 = sqrt(3.)/2.
-
-
   enum {
-    kNMX    = 11424,
-    kNDIMX  = 119,
-    kNDIMY  = 96
+    kNMX    = 11424, // no. of cells in a module
+    kNDIMX  = 119,   // max no. of cells along x direction
+    kNDIMY  = 96     // max no. of cells along axis at 60 deg with x axis
   };
-  /*
-    kNMX   : # of cells in a supermodule
-    kNDIMX : maximum number of cells along x direction (origin at one corner)
-    kNDIMY : maximum number of cells along axis at 60 degrees with x axis
-  */
-
-  Double_t fEdepCell[kNDIMX][kNDIMY]; //energy(ADC) in each cell of the supermodule
-  Double_t fClusters[6][5000]; // Cluster informations
-  Int_t    fClno;   // number of clusters in a supermodule
-
-  /*
-    clusters[0][i] --- x position of the cluster center
-    clusters[1][i] --- y position of the cluster center
-    clusters[2][i] --- total energy in the cluster
-    clusters[3][i] --- number of cells forming the cluster
-                       ( possibly fractional )
-    clusters[4][i] --- cluster sigma x
-    clusters[5][i] --- cluster sigma y
-  */
-
-  Int_t    fIord[2][kNMX];             // ordered list of i and j according to
-                                       // decreasing energy dep.
   Int_t    fInfocl[2][kNDIMX][kNDIMY]; // cellwise information on the 
                                        // cluster to which the cell
   Int_t    fInfcl[3][kNMX];            // cluster information [0][i]
                                        // -- cluster number
   Double_t fCoord[2][kNDIMX][kNDIMY];
 
-  /*
-    fIord --- ordered list of i and j according to decreasing energy dep.
-    fInfocl --- cellwise information on the cluster to which the cell
-    belongs and whether it has largest energy dep. or not
-    ( now redundant - probably )
-    fInfcl ---  cluster information [0][i] -- cluster number
-    [1][i] -- i of the cell
-    [2][i] -- j of the cell
-    coord --- x and y coordinates of center of each cell
-  */
-
   Float_t fCutoff; // Energy(ADC) cutoff per cell before clustering
-
-  ClassDef(AliPMDClusteringV2,0) // Does clustering for PMD
+  
+  ClassDef(AliPMDClusteringV2,2) // Does clustering for PMD
 };
 #endif
+