]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONClusterFinderVS.cxx
Reducing the printout
[u/mrichter/AliRoot.git] / MUON / AliMUONClusterFinderVS.cxx
index fcf1af6aa6f7fafb9ca5852f67a836f027182386..f27e356451f77c3d3383cc8595a05b3bb8ddeec2 100644 (file)
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
-/*
-$Log$
-Revision 1.9  2000/10/02 16:58:29  egangler
-Cleaning of the code :
--> coding conventions
--> void Streamers
--> some useless includes removed or replaced by "class" statement
-
-Revision 1.8  2000/07/03 11:54:57  morsch
-AliMUONSegmentation and AliMUONHitMap have been replaced by AliSegmentation and AliHitMap in STEER
-The methods GetPadIxy and GetPadXxy of AliMUONSegmentation have changed name to GetPadI and GetPadC.
-
-Revision 1.7  2000/06/28 15:16:35  morsch
-(1) Client code adapted to new method signatures in AliMUONSegmentation (see comments there)
-to allow development of slat-muon chamber simulation and reconstruction code in the MUON
-framework. The changes should have no side effects (mostly dummy arguments).
-(2) Hit disintegration uses 3-dim hit coordinates to allow simulation
-of chambers with overlapping modules (MakePadHits, Disintegration).
-
-Revision 1.6  2000/06/28 12:19:18  morsch
-More consequent seperation of global input data services (AliMUONClusterInput singleton) and the
-cluster and hit reconstruction algorithms in AliMUONClusterFinderVS.
-AliMUONClusterFinderVS becomes the base class for clustering and hit reconstruction.
-It requires two cathode planes. Small modifications in the code will make it usable for
-one cathode plane and, hence, more general (for test beam data).
-AliMUONClusterFinder is now obsolete.
-
-Revision 1.5  2000/06/28 08:06:10  morsch
-Avoid global variables in AliMUONClusterFinderVS by seperating the input data for the fit from the
-algorithmic part of the class. Input data resides inside the AliMUONClusterInput singleton.
-It also naturally takes care of the TMinuit instance.
-
-Revision 1.4  2000/06/27 16:18:47  gosset
-Finally correct implementation of xm, ym, ixm, iym sizes
-when at least three local maxima on cathode 1 or on cathode 2
-
-Revision 1.3  2000/06/22 14:02:45  morsch
-Parameterised size of xm[], ym[], ixm[], iym[] correctly implemented (PH)
-Some HP scope problems corrected (PH)
-
-Revision 1.2  2000/06/15 07:58:48  morsch
-Code from MUON-dev joined
-
-Revision 1.1.2.3  2000/06/09 21:58:33  morsch
-Most coding rule violations corrected.
-
-Revision 1.1.2.2  2000/02/15 08:33:52  morsch
-Error in calculation of contribution map for double clusters (Split method) corrected   (A.M.)
-Error in determination of track list for double cluster (FillCluster method) corrected  (A.M.)
-Revised and extended SplitByLocalMaxima method (Isabelle Chevrot):
-       - For clusters with more than 2 maxima on one of the cathode planes all valid
-       combinations of maxima on the two cathodes are preserved. The position of the maxima is
-       taken as the hit position.
-       - New FillCluster method with 2 arguments to find tracks associated to the clusters
-       defined above added. (Method destinction by argument list not very elegant in this case,
-       should be revides (A.M.)
-       - Bug in if-statement to handle maximum 1 maximum per plane corrected
-       - Two cluster per cathode but only 1 combination valid is handled.
-       - More rigerous treatment of 1-2 and 2-1 combinations of maxima.
 
-*/
+/* $Id$ */
+
+#include <TMinuit.h> 
+#include <TF1.h>
 
 #include "AliMUONClusterFinderVS.h"
 #include "AliMUONDigit.h"
@@ -81,20 +25,6 @@ Revised and extended SplitByLocalMaxima method (Isabelle Chevrot):
 #include "AliMUONResponse.h"
 #include "AliMUONClusterInput.h"
 #include "AliMUONHitMapA1.h"
-#include "AliRun.h"
-#include "AliMUON.h"
-
-#include <TTree.h>
-#include <TCanvas.h>
-#include <TH1.h>
-#include <TPad.h>
-#include <TGraph.h> 
-#include <TPostScript.h> 
-#include <TMinuit.h> 
-#include <TF1.h>
-
-#include <stdio.h>
-#include <iostream.h>
 
 //_____________________________________________________________________
 // This function is minimized in the double-Mathieson fit
@@ -105,59 +35,87 @@ void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t if
 
 ClassImp(AliMUONClusterFinderVS)
 
-    AliMUONClusterFinderVS::AliMUONClusterFinderVS()
+AliMUONClusterFinderVS::AliMUONClusterFinderVS()
+  : TObject()
 {
 // Default constructor
     fInput=AliMUONClusterInput::Instance();
     fHitMap[0] = 0;
     fHitMap[1] = 0;
     fTrack[0]=fTrack[1]=-1;
+    fDebugLevel = 0; // make silent default
+    fGhostChi2Cut = 1e6; // nothing done by default
+    fSeg[0]    = 0;
+    fSeg[1]    = 0;
+    for(Int_t i=0; i<100; i++) {
+      for (Int_t j=0; j<2; j++) {
+        fDig[i][j] = 0;
+      }
+    } 
+    fRawClusters = new TClonesArray("AliMUONRawCluster",1000);
+    fNRawClusters = 0;
 }
-
-AliMUONClusterFinderVS::AliMUONClusterFinderVS(
-    const AliMUONClusterFinderVS & clusterFinder)
+ //____________________________________________________________________________
+AliMUONClusterFinderVS::~AliMUONClusterFinderVS()
 {
-// Dummy copy Constructor
-    ;
+  // Reset tracks information
+   fNRawClusters = 0;
+   if (fRawClusters) {
+     fRawClusters->Delete();
+     delete fRawClusters;
+   }
 }
 
+AliMUONClusterFinderVS::AliMUONClusterFinderVS(const AliMUONClusterFinderVS & clusterFinder):TObject(clusterFinder)
+{
+// Protected copy constructor
+
+  Fatal("AliMUONClusterFinderAZModule", "Not implemented.");
+}
+//____________________________________________________________________________
+void AliMUONClusterFinderVS::ResetRawClusters()
+{
+  // Reset tracks information
+  fNRawClusters = 0;
+  if (fRawClusters) fRawClusters->Clear();
+}
+//____________________________________________________________________________
 void AliMUONClusterFinderVS::Decluster(AliMUONRawCluster *cluster)
 {
 // Decluster by local maxima
     SplitByLocalMaxima(cluster);
 }
-
+//____________________________________________________________________________
 void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 {
 // Split complex cluster by local maxima 
-
     Int_t cath, i;
 
     fInput->SetCluster(c);
 
-    fMul[0]=c->fMultiplicity[0];
-    fMul[1]=c->fMultiplicity[1];
+    fMul[0]=c->GetMultiplicity(0);
+    fMul[1]=c->GetMultiplicity(1);
 
 //
 //  dump digit information into arrays
 //
 
-    Float_t qtot, zdum;
+    Float_t qtot;
     
     for (cath=0; cath<2; cath++) {
        qtot=0;
        for (i=0; i<fMul[cath]; i++)
        {
            // pointer to digit
-           fDig[i][cath]=fInput->Digit(cath, c->fIndexMap[i][cath]);
+           fDig[i][cath]=fInput->Digit(cath, c->GetIndex(i, cath));
            // pad coordinates
-           fIx[i][cath]= fDig[i][cath]->fPadX;
-           fIy[i][cath]= fDig[i][cath]->fPadY;
+           fIx[i][cath]= fDig[i][cath]->PadX();
+           fIy[i][cath]= fDig[i][cath]->PadY();
            // pad charge
-           fQ[i][cath] = fDig[i][cath]->fSignal;
+           fQ[i][cath] = fDig[i][cath]->Signal();
            // pad centre coordinates
-           fInput->Segmentation(cath)->
-               GetPadC(fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], zdum);
+           fSeg[cath]->
+               GetPadC(fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], fZ[i][cath]);
        } // loop over cluster digits
     }  // loop over cathodes
 
@@ -172,48 +130,50 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //  +++++++++++++++++++++++++++++++*************++++++++
     if ((fNLocal[0]==1 && (fNLocal[1]==0 ||  fNLocal[1]==1)) || 
        (fNLocal[0]==0 && fNLocal[1]==1)) {
-
 // Perform combined single Mathieson fit
 // Initial values for coordinates (x,y) 
 
        // One local maximum on cathodes 1 and 2 (X->cathode 2, Y->cathode 1)
        if (fNLocal[0]==1 &&  fNLocal[1]==1) {
-           fXInit[0]=c->fX[1];
-           fYInit[0]=c->fY[0];
+           fXInit[0]=c->GetX(1);
+           fYInit[0]=c->GetY(0);
            // One local maximum on cathode 1 (X,Y->cathode 1)
        } else if (fNLocal[0]==1) {
-           fXInit[0]=c->fX[0];
-           fYInit[0]=c->fY[0];
+           fXInit[0]=c->GetX(0);
+           fYInit[0]=c->GetY(0);
            // One local maximum on cathode 2  (X,Y->cathode 2)
        } else {
-           fXInit[0]=c->fX[1];
-           fYInit[0]=c->fY[1];
+           fXInit[0]=c->GetX(1);
+           fYInit[0]=c->GetY(1);
        }
-       fprintf(stderr,"\n cas (1) CombiSingleMathiesonFit(c)\n");
+       if (fDebugLevel)
+           fprintf(stderr,"\n cas (1) CombiSingleMathiesonFit(c)\n");
        chi2=CombiSingleMathiesonFit(c);
 //     Int_t ndf = fgNbins[0]+fgNbins[1]-2;
 //     Float_t prob = TMath::Prob(Double_t(chi2),ndf);
 //     prob1->Fill(prob);
 //     chi2_1->Fill(chi2);
        oldchi2=chi2;
-       fprintf(stderr," chi2 %f ",chi2);
-
-       c->fX[0]=fXFit[0];
-       c->fY[0]=fYFit[0];
-
-       c->fX[1]=fXFit[0];
-       c->fY[1]=fYFit[0];
-       c->fChi2[0]=chi2;
-       c->fChi2[1]=chi2;
-       c->fX[0]=fInput->Segmentation(0)->GetAnod(c->fX[0]);
-       c->fX[1]=fInput->Segmentation(1)->GetAnod(c->fX[1]);
+       if (fDebugLevel)
+           fprintf(stderr," chi2 %f ",chi2);
+
+       c->SetX(0, fXFit[0]);
+       c->SetY(0, fYFit[0]);
+
+       c->SetX(1,fXFit[0]);
+       c->SetY(1,fYFit[0]);
+       c->SetChi2(0,chi2);
+       c->SetChi2(1,chi2);
+        // Force on anod
+       c->SetX(0, fSeg[0]->GetAnod(c->GetX(0)));
+       c->SetX(1, fSeg[1]->GetAnod(c->GetX(1)));
        
 // If reasonable chi^2 add result to the list of rawclusters
-       //      if (chi2 < 50) {
        if (chi2 < 0.3) {
            AddRawCluster(*c);
 // If not try combined double Mathieson Fit
        } else {
+         if (fDebugLevel)
            fprintf(stderr," MAUVAIS CHI2 !!!\n");
            if (fNLocal[0]==1 &&  fNLocal[1]==1) {
                fXInit[0]=fX[fIndLocal[0][1]][1];
@@ -235,6 +195,7 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //  Initial value for charge ratios
            fQrInit[0]=0.5;
            fQrInit[1]=0.5;
+           if (fDebugLevel)
            fprintf(stderr,"\n cas (1) CombiDoubleMathiesonFit(c)\n");
            chi2=CombiDoubleMathiesonFit(c);
 //         Int_t ndf = fgNbins[0]+fgNbins[1]-6;
@@ -243,12 +204,15 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //         chi2_2->Fill(chi2);
            
 // Was this any better ??
-           fprintf(stderr," Old and new chi2 %f %f ", oldchi2, chi2);
+           if (fDebugLevel)
+             fprintf(stderr," Old and new chi2 %f %f ", oldchi2, chi2);
            if (fFitStat!=0 && chi2>0 && (2.*chi2 < oldchi2)) {
+             if (fDebugLevel)
                fprintf(stderr," Split\n");
                // Split cluster into two according to fit result
                Split(c);
            } else {
+             if (fDebugLevel)
                fprintf(stderr," Don't Split\n");
                // Don't split
                AddRawCluster(*c);
@@ -261,7 +225,7 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
     } else if (fNLocal[0]==2 &&  fNLocal[1]==2) {
 //
 //  Let's look for ghosts first 
-//
+
        Float_t xm[4][2], ym[4][2];
        Float_t dpx, dpy, dx, dy;
        Int_t ixm[4][2], iym[4][2];
@@ -291,37 +255,82 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 
 // Analyse the combinations and keep those that are possible !
 // For each combination check consistency in x and y   
-       Int_t iacc;
-       Bool_t accepted[4];
+       Int_t   iacc;
+       Bool_t  accepted[4];
+       Float_t dr[4] = {1.e4, 1.e4, 1.e4, 1.e4};
        iacc=0;
-       
+
+// In case of staggering maxima are displaced by exactly half the pad-size in y. 
+// We have to take into account the numerical precision in the consistency check;      
+       Float_t eps = 1.e-5;
+//
        for (ico=0; ico<4; ico++) {
            accepted[ico]=kFALSE;
 // cathode one: x-coordinate
-           isec=fInput->Segmentation(0)->Sector(ixm[ico][0], iym[ico][0]);
-           dpx=fInput->Segmentation(0)->Dpx(isec)/2.;
+           isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
+           dpx=fSeg[0]->Dpx(isec)/2.;
            dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
 // cathode two: y-coordinate
-           isec=fInput->Segmentation(1)->Sector(ixm[ico][1], iym[ico][1]);
-           dpy=fInput->Segmentation(1)->Dpy(isec)/2.;
+           isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
+           dpy=fSeg[1]->Dpy(isec)/2.;
            dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
-//         printf("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy );
-           if ((dx <= dpx) && (dy <= dpy)) {
+           if (fDebugLevel>1) 
+               printf("\n %i %f %f %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy, dx, dpx );
+           if ((dx <= dpx) && (dy <= dpy+eps)) {
                // consistent
                accepted[ico]=kTRUE;
+               dr[ico] = TMath::Sqrt(dx*dx+dy*dy);
                iacc++;
            } else {
                // reject
                accepted[ico]=kFALSE;
            }
        }
+       if (fDebugLevel)
+         printf("\n iacc= %d:\n", iacc);
+       if (iacc == 3) {
+           if (accepted[0] && accepted[1]) {
+               if (dr[0] >= dr[1]) {
+                   accepted[0]=kFALSE;
+               } else {
+                   accepted[1]=kFALSE;
+               }
+           }
 
-       if (iacc==2) {
-           fprintf(stderr,"\n iacc=2: No problem ! \n");
-       } else if (iacc==4) {
-           fprintf(stderr,"\n iacc=4: Ok, but ghost problem !!! \n");
-       } else if (iacc==0) {
-           fprintf(stderr,"\n iacc=0: I don't know what to do with this !!!!!!!!! \n");
+           if (accepted[2] && accepted[3]) {
+               if (dr[2] >= dr[3]) {
+                   accepted[2]=kFALSE;
+               } else {
+                   accepted[3]=kFALSE;
+               }
+           }
+/*         
+// eliminate one candidate
+           Float_t drmax = 0;
+           Int_t icobad = -1;
+
+           for (ico=0; ico<4; ico++) {
+               if (accepted[ico] && dr[ico] > drmax) {
+                   icobad = ico;
+                   drmax  = dr[ico];
+               }
+           }
+           
+           accepted[icobad] = kFALSE;
+*/
+           iacc = 2;
+       }
+       
+       
+       if (fDebugLevel) {
+         printf("\n iacc= %d:\n", iacc);
+           if (iacc==2) {
+               fprintf(stderr,"\n iacc=2: No problem ! \n");
+           } else if (iacc==4) {
+               fprintf(stderr,"\n iacc=4: Ok, but ghost problem !!! \n");
+           } else if (iacc==0) {
+               fprintf(stderr,"\n iacc=0: I don't know what to do with this !!!!!!!!! \n");
+           }
        }
 
 //  Initial value for charge ratios
@@ -340,43 +349,44 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 // ******* iacc = 1 *******
 // Only one combination found between the 2 cathodes
        if (iacc==1) {
-
 // Initial values for the 2 maxima (x,y)
 
 // 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
 // 1 maximum is initialised with the other maximum of the first cathode  
            if (accepted[0]){
-               fprintf(stderr,"ico=0\n");
+               if (fDebugLevel) fprintf(stderr,"ico=0\n");
                fXInit[0]=xm[0][1];
                fYInit[0]=ym[0][0];
                fXInit[1]=xm[3][0];
                fYInit[1]=ym[3][0];
            } else if (accepted[1]){
-               fprintf(stderr,"ico=1\n");
+               if (fDebugLevel) fprintf(stderr,"ico=1\n");
                fXInit[0]=xm[1][1];
                fYInit[0]=ym[1][0];
                fXInit[1]=xm[2][0];
                fYInit[1]=ym[2][0];
            } else if (accepted[2]){
-               fprintf(stderr,"ico=2\n");
+               if (fDebugLevel) fprintf(stderr,"ico=2\n");
                fXInit[0]=xm[2][1];
                fYInit[0]=ym[2][0];
                fXInit[1]=xm[1][0];
                fYInit[1]=ym[1][0];
            } else if (accepted[3]){
-               fprintf(stderr,"ico=3\n");
+               if (fDebugLevel) fprintf(stderr,"ico=3\n");
                fXInit[0]=xm[3][1];
                fYInit[0]=ym[3][0];
                fXInit[1]=xm[0][0];
                fYInit[1]=ym[0][0];
            }
-           fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
+           if (fDebugLevel)
+               fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
            chi2=CombiDoubleMathiesonFit(c);
 //         Int_t ndf = fgNbins[0]+fgNbins[1]-6;
 //         Float_t prob = TMath::Prob(chi2,ndf);
 //         prob2->Fill(prob);
 //         chi2_2->Fill(chi2);
-           fprintf(stderr," chi2 %f\n",chi2);
+           if (fDebugLevel)
+               fprintf(stderr," chi2 %f\n",chi2);
 
 // If reasonable chi^2 add result to the list of rawclusters
            if (chi2<10) {
@@ -386,37 +396,39 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 // 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
 // 1 maximum is initialised with the other maximum of the second cathode  
                if (accepted[0]){
-                   fprintf(stderr,"ico=0\n");
+                   if (fDebugLevel) fprintf(stderr,"ico=0\n");
                    fXInit[0]=xm[0][1];
                    fYInit[0]=ym[0][0];
                    fXInit[1]=xm[3][1];
                    fYInit[1]=ym[3][1];
                } else if (accepted[1]){
-                   fprintf(stderr,"ico=1\n");
+                   if (fDebugLevel) fprintf(stderr,"ico=1\n");
                    fXInit[0]=xm[1][1];
                    fYInit[0]=ym[1][0];
                    fXInit[1]=xm[2][1];
                    fYInit[1]=ym[2][1];
                } else if (accepted[2]){
-                   fprintf(stderr,"ico=2\n");
+                   if (fDebugLevel) fprintf(stderr,"ico=2\n");
                    fXInit[0]=xm[2][1];
                    fYInit[0]=ym[2][0];
                    fXInit[1]=xm[1][1];
                    fYInit[1]=ym[1][1];
                } else if (accepted[3]){
-                   fprintf(stderr,"ico=3\n");
+                   if (fDebugLevel) fprintf(stderr,"ico=3\n");
                    fXInit[0]=xm[3][1];
                    fYInit[0]=ym[3][0];
                    fXInit[1]=xm[0][1];
                    fYInit[1]=ym[0][1];
                }
-               fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
+               if (fDebugLevel)
+                   fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
                chi2=CombiDoubleMathiesonFit(c);
 //             Int_t ndf = fgNbins[0]+fgNbins[1]-6;
 //             Float_t prob = TMath::Prob(chi2,ndf);
 //             prob2->Fill(prob);
 //             chi2_2->Fill(chi2);
-               fprintf(stderr," chi2 %f\n",chi2);
+               if (fDebugLevel)
+                   fprintf(stderr," chi2 %f\n",chi2);
 
 // If reasonable chi^2 add result to the list of rawclusters
                if (chi2<10) {
@@ -428,18 +440,22 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                            AliMUONRawCluster cnew;
                            Int_t cath;    
                            for (cath=0; cath<2; cath++) {
-                               cnew.fX[cath]=Float_t(xm[ico][1]);
-                               cnew.fY[cath]=Float_t(ym[ico][0]);
-                               cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
+                               cnew.SetX(cath, Float_t(xm[ico][1]));
+                               cnew.SetY(cath, Float_t(ym[ico][0]));
+                               cnew.SetZ(cath, fZPlane);
+                               
+                               cnew.SetMultiplicity(cath,c->GetMultiplicity(cath));
                                for (i=0; i<fMul[cath]; i++) {
-                                   cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
-                                   fInput->Segmentation(cath)->SetPad(fIx[i][cath], fIy[i][cath]);
+                                   cnew.SetIndex(i, cath, c->GetIndex(i,cath));
+                                   fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
+                               }
+                               if (fDebugLevel) {
+                                 fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
+                                 fprintf(stderr,"mult_av %d\n",c->GetMultiplicity(cath));
                                }
-                               fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
-                               fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
                                FillCluster(&cnew,cath);
                            } 
-                           cnew.fClusterType=cnew.PhysicsContribution();
+                           cnew.SetClusterType(cnew.PhysicsContribution());
                            AddRawCluster(cnew);
                            fNPeaks++;
                        }
@@ -451,12 +467,11 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 // ******* iacc = 2 *******
 // Two combinations found between the 2 cathodes
        if (iacc==2) {
-
 // Was the same maximum taken twice
            if ((accepted[0]&&accepted[1]) || (accepted[2]&&accepted[3])) {
-               fprintf(stderr,"\n Maximum taken twice !!!\n");
+               if (fDebugLevel) fprintf(stderr,"\n Maximum taken twice !!!\n");
 
-// Have a try !! with that 
+// Have a try !! with that
                if (accepted[0]&&accepted[3]) {
                    fXInit[0]=xm[0][1];
                    fYInit[0]=ym[0][0];
@@ -468,7 +483,8 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                    fXInit[1]=xm[3][1];
                    fYInit[1]=ym[3][0];
                }
-               fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
+               if (fDebugLevel)
+                   fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
                chi2=CombiDoubleMathiesonFit(c);
 //                 Int_t ndf = fgNbins[0]+fgNbins[1]-6;
 //                 Float_t prob = TMath::Prob(chi2,ndf);
@@ -489,13 +505,15 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                    fXInit[1]=xm[2][1];
                    fYInit[1]=ym[2][0];
                }
-               fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
+               if (fDebugLevel)
+                   fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
                chi2=CombiDoubleMathiesonFit(c);
 //                 Int_t ndf = fgNbins[0]+fgNbins[1]-6;
 //                 Float_t prob = TMath::Prob(chi2,ndf);
 //                 prob2->Fill(prob);
 //                 chi2_2->Fill(chi2);
-               fprintf(stderr," chi2 %f\n",chi2);
+               if (fDebugLevel)
+                   fprintf(stderr," chi2 %f\n",chi2);
                Split(c);
            }
            
@@ -504,30 +522,90 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 // Ghost !!
        } else if (iacc==4) {
 // Perform fits for the two possibilities !!   
+// Accept if charges are compatible on both cathodes
+// If none are compatible, keep everything
            fXInit[0]=xm[0][1];
            fYInit[0]=ym[0][0];
            fXInit[1]=xm[3][1];
            fYInit[1]=ym[3][0];
-           fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
+           if (fDebugLevel)
+               fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
            chi2=CombiDoubleMathiesonFit(c);
 //             Int_t ndf = fgNbins[0]+fgNbins[1]-6;
 //             Float_t prob = TMath::Prob(chi2,ndf);
 //             prob2->Fill(prob);
 //             chi2_2->Fill(chi2);
-           fprintf(stderr," chi2 %f\n",chi2);
-           Split(c);
+           if (fDebugLevel)
+               fprintf(stderr," chi2 %f\n",chi2);
+           // store results of fit and postpone decision
+           Double_t sXFit[2],sYFit[2],sQrFit[2];
+           Float_t sChi2[2];
+           for (Int_t i=0;i<2;i++) {
+               sXFit[i]=fXFit[i];
+               sYFit[i]=fYFit[i];
+               sQrFit[i]=fQrFit[i];
+               sChi2[i]=fChi2[i];
+           }
            fXInit[0]=xm[1][1];
            fYInit[0]=ym[1][0];
            fXInit[1]=xm[2][1];
            fYInit[1]=ym[2][0];
-           fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
+           if (fDebugLevel)
+               fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
            chi2=CombiDoubleMathiesonFit(c);
 //             ndf = fgNbins[0]+fgNbins[1]-6;
 //             prob = TMath::Prob(chi2,ndf);
 //             prob2->Fill(prob);
 //             chi2_2->Fill(chi2);
-           fprintf(stderr," chi2 %f\n",chi2);
-           Split(c);
+           if (fDebugLevel)
+               fprintf(stderr," chi2 %f\n",chi2);
+           // We have all informations to perform the decision
+           // Compute the chi2 for the 2 possibilities
+           Float_t chi2fi,chi2si,chi2f,chi2s;
+
+           chi2f = (TMath::Log(fInput->TotalCharge(0)*fQrFit[0]
+                 /  (fInput->TotalCharge(1)*fQrFit[1]) )
+                 / fInput->Response()->ChargeCorrel() );
+           chi2f *=chi2f;
+           chi2fi = (TMath::Log(fInput->TotalCharge(0)*(1-fQrFit[0])
+                 /  (fInput->TotalCharge(1)*(1-fQrFit[1])) )
+                 / fInput->Response()->ChargeCorrel() );
+           chi2f += chi2fi*chi2fi;
+
+           chi2s = (TMath::Log(fInput->TotalCharge(0)*sQrFit[0]
+                 /  (fInput->TotalCharge(1)*sQrFit[1]) )
+                 / fInput->Response()->ChargeCorrel() );
+           chi2s *=chi2s;
+           chi2si = (TMath::Log(fInput->TotalCharge(0)*(1-sQrFit[0])
+                 /  (fInput->TotalCharge(1)*(1-sQrFit[1])) )
+                 / fInput->Response()->ChargeCorrel() );
+           chi2s += chi2si*chi2si;
+
+           // usefull to store the charge matching chi2 in the cluster
+           // fChi2[0]=sChi2[1]=chi2f;
+           // fChi2[1]=sChi2[0]=chi2s;
+
+           if (chi2f<=fGhostChi2Cut && chi2s<=fGhostChi2Cut)
+               c->SetGhost(1);
+           if   (chi2f>fGhostChi2Cut && chi2s>fGhostChi2Cut) {
+               // we keep the ghost
+               c->SetGhost(2);
+               chi2s=-1;
+               chi2f=-1;
+           }
+           if (chi2f<=fGhostChi2Cut)
+               Split(c);
+           if (chi2s<=fGhostChi2Cut) {
+               // retreive saved values
+               for (Int_t i=0;i<2;i++) {
+                   fXFit[i]=sXFit[i];
+                   fYFit[i]=sYFit[i];
+                   fQrFit[i]=sQrFit[i];
+                   fChi2[i]=sChi2[i];
+               }
+               Split(c);
+           }
+           c->SetGhost(0);
        }
 
     } else if (fNLocal[0]==2 &&  fNLocal[1]==1) {
@@ -563,17 +641,22 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
        Int_t iacc;
        Bool_t accepted[4];
        iacc=0;
+       // In case of staggering maxima are displaced by exactly half the pad-size in y. 
+        // We have to take into account the numerical precision in the consistency check;
        
+       Float_t eps = 1.e-5;
+
        for (ico=0; ico<2; ico++) {
            accepted[ico]=kFALSE;
-           isec=fInput->Segmentation(0)->Sector(ixm[ico][0], iym[ico][0]);
-           dpx=fInput->Segmentation(0)->Dpx(isec)/2.;
+           isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
+           dpx=fSeg[0]->Dpx(isec)/2.;
            dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
-           isec=fInput->Segmentation(1)->Sector(ixm[ico][1], iym[ico][1]);
-           dpy=fInput->Segmentation(1)->Dpy(isec)/2.;
+           isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
+           dpy=fSeg[1]->Dpy(isec)/2.;
            dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
-//         printf("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy );
-           if ((dx <= dpx) && (dy <= dpy)) {
+           if (fDebugLevel>1)
+               printf("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy );
+           if ((dx <= dpx) && (dy <= dpy+eps)) {
                // consistent
                accepted[ico]=kTRUE;
                iacc++;
@@ -585,8 +668,31 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
        
        Float_t chi21 = 100;
        Float_t chi22 = 100;
+       Float_t chi23 = 100;
+
+       //  Initial value for charge ratios
+       fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
+           Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
+       fQrInit[1]=fQrInit[0];
        
-       if (accepted[0]) {
+       if (accepted[0] && accepted[1]) {
+           
+           fXInit[0]=0.5*(xm[0][1]+xm[0][0]);
+           fYInit[0]=ym[0][0];
+           fXInit[1]=0.5*(xm[0][1]+xm[1][0]);
+           fYInit[1]=ym[1][0];
+           fQrInit[0]=0.5;
+           fQrInit[1]=0.5;
+           chi23=CombiDoubleMathiesonFit(c);
+           if (chi23<10) {
+               Split(c);
+               Float_t yst;
+               yst = fYFit[0];
+               fYFit[0] = fYFit[1];
+               fYFit[1] = yst;
+               Split(c);
+           }
+       } else if (accepted[0]) {
            fXInit[0]=xm[0][1];
            fYInit[0]=ym[0][0];
            fXInit[1]=xm[1][0];
@@ -596,7 +702,8 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //         Float_t prob = TMath::Prob(chi2,ndf);
 //         prob2->Fill(prob);
 //         chi2_2->Fill(chi21);
-           fprintf(stderr," chi2 %f\n",chi21);
+           if (fDebugLevel)
+               fprintf(stderr," chi2 %f\n",chi21);
            if (chi21<10) Split(c);
        } else if (accepted[1]) {
            fXInit[0]=xm[1][1];
@@ -608,29 +715,33 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //         Float_t prob = TMath::Prob(chi2,ndf);
 //         prob2->Fill(prob);
 //         chi2_2->Fill(chi22);
-           fprintf(stderr," chi2 %f\n",chi22);
+           if (fDebugLevel)
+               fprintf(stderr," chi2 %f\n",chi22);
            if (chi22<10) Split(c);
        }
 
-       if (chi21 > 10 && chi22 > 10) {
+       if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
 // We keep only the combination found (X->cathode 2, Y->cathode 1)
            for (Int_t ico=0; ico<2; ico++) {
                if (accepted[ico]) {
                    AliMUONRawCluster cnew;
                    Int_t cath;    
                    for (cath=0; cath<2; cath++) {
-                       cnew.fX[cath]=Float_t(xm[ico][1]);
-                       cnew.fY[cath]=Float_t(ym[ico][0]);
-                       cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
+                       cnew.SetX(cath, Float_t(xm[ico][1]));
+                       cnew.SetY(cath, Float_t(ym[ico][0]));
+                       cnew.SetZ(cath, fZPlane);
+                       cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
                        for (i=0; i<fMul[cath]; i++) {
-                           cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
-                           fInput->Segmentation(cath)->SetPad(fIx[i][cath], fIy[i][cath]);
+                           cnew.SetIndex(i, cath, c->GetIndex(i, cath));
+                           fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
+                       }
+                       if (fDebugLevel){
+                         fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
+                         fprintf(stderr,"mult_av %d\n",c->GetMultiplicity(cath));
                        }
-                       fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
-                       fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
                        FillCluster(&cnew,cath);
                    } 
-                   cnew.fClusterType=cnew.PhysicsContribution();
+                   cnew.SetClusterType(cnew.PhysicsContribution());
                    AddRawCluster(cnew);
                    fNPeaks++;
                }
@@ -641,7 +752,6 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //  (3') One local maximum on cathode 1 and two maxima on cathode 2 
 //  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     } else if (fNLocal[0]==1 && fNLocal[1]==2) {
-       
        Float_t xm[4][2], ym[4][2];
        Float_t dpx, dpy, dx, dy;
        Int_t ixm[4][2], iym[4][2];
@@ -670,20 +780,25 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
        Int_t iacc;
        Bool_t accepted[4];
        iacc=0;
+        // In case of staggering maxima are displaced by exactly half the pad-size in y. 
+        // We have to take into account the numerical precision in the consistency check;      
+       Float_t eps = 1.e-5;
+
        
        for (ico=0; ico<2; ico++) {
            accepted[ico]=kFALSE;
-           isec=fInput->Segmentation(0)->Sector(ixm[ico][0], iym[ico][0]);
-           dpx=fInput->Segmentation(0)->Dpx(isec)/2.;
+           isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
+           dpx=fSeg[0]->Dpx(isec)/2.;
            dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
-           isec=fInput->Segmentation(1)->Sector(ixm[ico][1], iym[ico][1]);
-           dpy=fInput->Segmentation(1)->Dpy(isec)/2.;
+           isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
+           dpy=fSeg[1]->Dpy(isec)/2.;
            dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
-//         printf("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy );
-           if ((dx <= dpx) && (dy <= dpy)) {
+           if (fDebugLevel>0)
+               printf("\n %i %f %f %f %f \n", ico, ym[ico][0], ym[ico][1], dy, dpy );
+           if ((dx <= dpx) && (dy <= dpy+eps)) {
                // consistent
                accepted[ico]=kTRUE;
-               fprintf(stderr,"ico %d\n",ico);
+               if (fDebugLevel) fprintf(stderr,"ico %d\n",ico);
                iacc++;
            } else {
                // reject
@@ -693,8 +808,31 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 
        Float_t chi21 = 100;
        Float_t chi22 = 100;
+       Float_t chi23 = 100;
+
+       fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
+           Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
+       
+       fQrInit[0]=fQrInit[1];
 
-       if (accepted[0]) {
+       
+       if (accepted[0] && accepted[1]) {
+           fXInit[0]=xm[0][1];
+           fYInit[0]=0.5*(ym[0][0]+ym[0][1]);
+           fXInit[1]=xm[1][1];
+           fYInit[1]=0.5*(ym[0][0]+ym[1][1]);
+           fQrInit[0]=0.5;
+           fQrInit[1]=0.5;
+           chi23=CombiDoubleMathiesonFit(c);
+           if (chi23<10) {
+               Split(c);
+               Float_t yst;
+               yst = fYFit[0];
+               fYFit[0] = fYFit[1];
+               fYFit[1] = yst;
+               Split(c);
+           }
+       } else if (accepted[0]) {
            fXInit[0]=xm[0][0];
            fYInit[0]=ym[0][1];
            fXInit[1]=xm[1][1];
@@ -704,7 +842,8 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //         Float_t prob = TMath::Prob(chi2,ndf);
 //         prob2->Fill(prob);
 //         chi2_2->Fill(chi21);
-           fprintf(stderr," chi2 %f\n",chi21);
+           if (fDebugLevel)
+               fprintf(stderr," chi2 %f\n",chi21);
            if (chi21<10) Split(c);
        } else if (accepted[1]) {
            fXInit[0]=xm[1][0];
@@ -716,29 +855,33 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //         Float_t prob = TMath::Prob(chi2,ndf);
 //         prob2->Fill(prob);
 //         chi2_2->Fill(chi22);
-           fprintf(stderr," chi2 %f\n",chi22);
+           if (fDebugLevel)
+               fprintf(stderr," chi2 %f\n",chi22);
            if (chi22<10) Split(c);
        }
 
-       if (chi21 > 10 && chi22 > 10) {
+       if (chi21 > 10 && chi22 > 10 && chi23 > 10) {
 //We keep only the combination found (X->cathode 2, Y->cathode 1)
            for (Int_t ico=0; ico<2; ico++) {
                if (accepted[ico]) {
                    AliMUONRawCluster cnew;
                    Int_t cath;    
                    for (cath=0; cath<2; cath++) {
-                       cnew.fX[cath]=Float_t(xm[ico][1]);
-                       cnew.fY[cath]=Float_t(ym[ico][0]);
-                       cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
+                       cnew.SetX(cath, Float_t(xm[ico][1]));
+                       cnew.SetY(cath, Float_t(ym[ico][0]));
+                       cnew.SetZ(cath, fZPlane);
+                       cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
                        for (i=0; i<fMul[cath]; i++) {
-                           cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
-                           fInput->Segmentation(cath)->SetPad(fIx[i][cath], fIy[i][cath]);
+                           cnew.SetIndex(i, cath, c->GetIndex(i, cath));
+                           fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
+                       }
+                       if (fDebugLevel) {
+                         fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
+                         fprintf(stderr,"mult_av %d\n",c->GetMultiplicity(cath));
                        }
-                       fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
-                       fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
                        FillCluster(&cnew,cath);
                    } 
-                   cnew.fClusterType=cnew.PhysicsContribution();
+                   cnew.SetClusterType(cnew.PhysicsContribution());
                    AddRawCluster(cnew);
                    fNPeaks++;
                }
@@ -749,7 +892,6 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //  (4) At least three local maxima on cathode 1 or on cathode 2 
 //  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     } else if (fNLocal[0]>2 || fNLocal[1]>2) {
-       
        Int_t param = fNLocal[0]*fNLocal[1];
        Int_t ii;
 
@@ -782,34 +924,38 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
        }
        
        Int_t nIco = ico;
-       
-       fprintf(stderr,"nIco %d\n",nIco);
+       if (fDebugLevel)
+           fprintf(stderr,"nIco %d\n",nIco);
        for (ico=0; ico<nIco; ico++) {
-           fprintf(stderr,"ico = %d\n",ico);
-           isec=fInput->Segmentation(0)->Sector(ixm[ico][0], iym[ico][0]);
-           dpx=fInput->Segmentation(0)->Dpx(isec)/2.;
+           if (fDebugLevel)
+               fprintf(stderr,"ico = %d\n",ico);
+           isec=fSeg[0]->Sector(ixm[ico][0], iym[ico][0]);
+           dpx=fSeg[0]->Dpx(isec)/2.;
            dx=TMath::Abs(xm[ico][0]-xm[ico][1]);
-           isec=fInput->Segmentation(1)->Sector(ixm[ico][1], iym[ico][1]);
-           dpy=fInput->Segmentation(1)->Dpy(isec)/2.;
+           isec=fSeg[1]->Sector(ixm[ico][1], iym[ico][1]);
+           dpy=fSeg[1]->Dpy(isec)/2.;
            dy=TMath::Abs(ym[ico][0]-ym[ico][1]);
-
-           fprintf(stderr,"dx %f dpx %f dy %f dpy %f\n",dx,dpx,dy,dpy);
-           fprintf(stderr,"  X %f Y %f\n",xm[ico][1],ym[ico][0]);
+           if (fDebugLevel) {
+               fprintf(stderr,"dx %f dpx %f dy %f dpy %f\n",dx,dpx,dy,dpy);
+               fprintf(stderr,"  X %f Y %f\n",xm[ico][1],ym[ico][0]);
+           }
            if ((dx <= dpx) && (dy <= dpy)) {
-               fprintf(stderr,"ok\n");
+               if (fDebugLevel)
+                   fprintf(stderr,"ok\n");
                Int_t cath;    
                AliMUONRawCluster cnew;
                for (cath=0; cath<2; cath++) {
-                   cnew.fX[cath]=Float_t(xm[ico][1]);
-                   cnew.fY[cath]=Float_t(ym[ico][0]);
-                   cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
+                   cnew.SetX(cath, Float_t(xm[ico][1]));
+                   cnew.SetY(cath, Float_t(ym[ico][0]));
+                   cnew.SetZ(cath, fZPlane);
+                   cnew.SetMultiplicity(cath, c->GetMultiplicity(cath));
                    for (i=0; i<fMul[cath]; i++) {
-                       cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
-                       fInput->Segmentation(cath)->SetPad(fIx[i][cath], fIy[i][cath]);
+                       cnew.SetIndex(i, cath, c->GetIndex(i, cath));
+                       fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
                    }
                    FillCluster(&cnew,cath);
                } 
-               cnew.fClusterType=cnew.PhysicsContribution();
+               cnew.SetClusterType(cnew.PhysicsContribution());
                AddRawCluster(cnew);
                fNPeaks++;
            }
@@ -821,10 +967,12 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
     }
 }
 
-void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
+void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* /*c*/)
 {
 // Find all local maxima of a cluster
-   
+    if (fDebugLevel)
+       printf("\n Find Local maxima  !");
+    
     AliMUONDigit* digt;
     
     Int_t cath, cath1; // loops over cathodes
@@ -848,23 +996,23 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
 // loop over cluster digits
        for (i=0; i<fMul[cath]; i++) {
 // get neighbours for that digit and assume that it is local maximum       
-           fInput->Segmentation(cath)->Neighbours(fIx[i][cath], fIy[i][cath], &nn, x, y);
+           fSeg[cath]->Neighbours(fIx[i][cath], fIy[i][cath], &nn, x, y);
            isLocal[i][cath]=kTRUE;
-           Int_t isec= fInput->Segmentation(cath)->Sector(fIx[i][cath], fIy[i][cath]);
-           Float_t a0 = fInput->Segmentation(cath)->Dpx(isec)*fInput->Segmentation(cath)->Dpy(isec);
+           Int_t isec= fSeg[cath]->Sector(fIx[i][cath], fIy[i][cath]);
+           Float_t a0 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
 // loop over next neighbours, if at least one neighbour has higher charger assumption
 // digit is not local maximum 
            for (j=0; j<nn; j++) {
                if (fHitMap[cath]->TestHit(x[j], y[j])==kEmpty) continue;
                digt=(AliMUONDigit*) fHitMap[cath]->GetHit(x[j], y[j]);
-               isec=fInput->Segmentation(cath)->Sector(x[j], y[j]);
-               Float_t a1 = fInput->Segmentation(cath)->Dpx(isec)*fInput->Segmentation(cath)->Dpy(isec);
-               if (digt->fSignal/a1 > fQ[i][cath]/a0) {
+               isec=fSeg[cath]->Sector(x[j], y[j]);
+               Float_t a1 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
+               if (digt->Signal()/a1 > fQ[i][cath]/a0) {
                    isLocal[i][cath]=kFALSE;
                    break;
 //
 // handle special case of neighbouring pads with equal signal
-               } else if (digt->fSignal == fQ[i][cath]) {
+               } else if (digt->Signal() == fQ[i][cath]) {
                    if (fNLocal[cath]>0) {
                        for (Int_t k=0; k<fNLocal[cath]; k++) {
                            if (x[j]==fIx[fIndLocal[k][cath]][cath] 
@@ -882,11 +1030,13 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
            } 
        } // loop over all digits
     } // loop over cathodes
-    
-    printf("\n Found %d %d %d %d local Maxima\n",
-          fNLocal[0], fNLocal[1], fMul[0], fMul[1]);
-    fprintf(stderr,"\n Cathode 1 local Maxima %d Multiplicite %d\n",fNLocal[0], fMul[0]);
-    fprintf(stderr," Cathode 2 local Maxima %d Multiplicite %d\n",fNLocal[1], fMul[1]);
+
+    if (fDebugLevel) {
+       printf("\n Found %d %d %d %d local Maxima\n",
+              fNLocal[0], fNLocal[1], fMul[0], fMul[1]);
+       fprintf(stderr,"\n Cathode 1 local Maxima %d Multiplicite %d\n",fNLocal[0], fMul[0]);
+       fprintf(stderr," Cathode 2 local Maxima %d Multiplicite %d\n",fNLocal[1], fMul[1]);
+    }
     Int_t ix, iy, isec;
     Float_t dpx, dpy;
     
@@ -902,9 +1052,9 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
        cath1=1;
        
        for (i=0; i<fMul[cath]; i++) {
-           isec=fInput->Segmentation(cath)->Sector(fIx[i][cath],fIy[i][cath]);
-           dpy=fInput->Segmentation(cath)->Dpy(isec);
-           dpx=fInput->Segmentation(cath)->Dpx(isec);
+           isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
+           dpy=fSeg[cath]->Dpy(isec);
+           dpx=fSeg[cath]->Dpx(isec);
            if (isLocal[i][cath]) continue;
 // Pad position should be consistent with position of local maxima on the opposite cathode
            if ((TMath::Abs(fX[i][cath]-fX[fIndLocal[0][cath1]][cath1]) > dpx/2.) && 
@@ -914,20 +1064,27 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
 // get neighbours for that digit and assume that it is local maximum       
            isLocal[i][cath]=kTRUE;
 // compare signal to that on the two neighbours on the left and on the right
-           fInput->Segmentation(cath)->GetPadI(fX[i][cath],fY[i][cath]+dpy,0,ix,iy);
 // iNN counts the number of neighbours with signal, it should be 1 or 2
            Int_t iNN=0;
-           if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
-               iNN++;
-               digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
-               if (digt->fSignal > fQ[i][cath]) isLocal[i][cath]=kFALSE;
-           }
-           fInput->Segmentation(cath)->GetPadI(fX[i][cath],fY[i][cath]-dpy,0,ix,iy);
-           if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
-               iNN++;
-               digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
-               if (digt->fSignal > fQ[i][cath]) isLocal[i][cath]=kFALSE;
-           }
+
+           for (fSeg[cath]
+                    ->FirstPad(fX[i][cath], fY[i][cath], fZPlane, 0., dpy);
+                fSeg[cath]
+                    ->MorePads();
+                fSeg[cath]
+                    ->NextPad())
+           {
+               ix = fSeg[cath]->Ix();
+               iy = fSeg[cath]->Iy();
+               // skip the current pad
+               if (iy == fIy[i][cath]) continue;
+               
+               if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
+                   iNN++;
+                   digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
+                   if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
+               }
+           } // Loop over pad neighbours in y
            if (isLocal[i][cath] && iNN>0) {
                fIndLocal[fNLocal[cath]][cath]=i;
                fNLocal[cath]++;
@@ -935,8 +1092,14 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
        } // loop over all digits
 // if one additional maximum has been found we are happy 
 // if more maxima have been found restore the previous situation
-       fprintf(stderr,"\n New search gives %d local maxima for cathode 1 \n",fNLocal[0]);
-       fprintf(stderr,"                  %d local maxima for cathode 2 \n",fNLocal[1]);
+       if (fDebugLevel) {
+           fprintf(stderr,
+                   "\n New search gives %d local maxima for cathode 1 \n",
+                   fNLocal[0]);
+           fprintf(stderr,
+                   "                  %d local maxima for cathode 2 \n",
+                   fNLocal[1]);
+       }
        if (fNLocal[cath]>2) {
            fNLocal[cath]=iback;
        }
@@ -949,38 +1112,48 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
 //  Two local maxima on cathode 1 and one maximum on cathode 2 
 //  Look for local maxima considering left and right neighbours on the 2nd cathode only
        cath=1;
-       Int_t cath1=0;
+       Int_t cath1 = 0;
+       Float_t eps = 1.e-5;
        
-
 //
 //  Loop over cluster digits
        for (i=0; i<fMul[cath]; i++) {
-           isec=fInput->Segmentation(cath)->Sector(fIx[i][cath],fIy[i][cath]);
-           dpx=fInput->Segmentation(cath)->Dpx(isec);
-           dpy=fInput->Segmentation(cath)->Dpy(isec);
+           isec=fSeg[cath]->Sector(fIx[i][cath],fIy[i][cath]);
+           dpx=fSeg[cath]->Dpx(isec);
+           dpy=fSeg[cath]->Dpy(isec);
            if (isLocal[i][cath]) continue;
 // Pad position should be consistent with position of local maxima on the opposite cathode
-           if ((TMath::Abs(fY[i][cath]-fY[fIndLocal[0][cath1]][cath1]) > dpy/2.) && 
-               (TMath::Abs(fY[i][cath]-fY[fIndLocal[1][cath1]][cath1]) > dpy/2.))
+           if ((TMath::Abs(fY[i][cath]-fY[fIndLocal[0][cath1]][cath1]) > dpy/2.+eps) && 
+               (TMath::Abs(fY[i][cath]-fY[fIndLocal[1][cath1]][cath1]) > dpy/2.+eps))
                continue;
+           
 //
 // get neighbours for that digit and assume that it is local maximum       
            isLocal[i][cath]=kTRUE;
 // compare signal to that on the two neighbours on the left and on the right
-           fInput->Segmentation(cath)->GetPadI(fX[i][cath]+dpx,fY[i][cath],0,ix,iy);
+
 // iNN counts the number of neighbours with signal, it should be 1 or 2
            Int_t iNN=0;
-           if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
-               iNN++;
-               digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
-               if (digt->fSignal > fQ[i][cath]) isLocal[i][cath]=kFALSE;
-           }
-           fInput->Segmentation(cath)->GetPadI(fX[i][cath]-dpx,fY[i][cath],0,ix,iy);
-           if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
-               iNN++;
-               digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
-               if (digt->fSignal > fQ[i][cath]) isLocal[i][cath]=kFALSE;
-           }
+           for (fSeg[cath]
+                    ->FirstPad(fX[i][cath], fY[i][cath], fZPlane, dpx, 0.);
+                fSeg[cath]
+                    ->MorePads();
+                fSeg[cath]
+                    ->NextPad())
+           {
+
+               ix = fSeg[cath]->Ix();
+               iy = fSeg[cath]->Iy();
+
+               // skip the current pad
+               if (ix == fIx[i][cath]) continue;
+               
+               if (fHitMap[cath]->TestHit(ix, iy)!=kEmpty) {
+                   iNN++;
+                   digt=(AliMUONDigit*) fHitMap[cath]->GetHit(ix,iy);
+                   if (digt->Signal() > fQ[i][cath]) isLocal[i][cath]=kFALSE;
+               }
+           } // Loop over pad neighbours in x
            if (isLocal[i][cath] && iNN>0) {
                fIndLocal[fNLocal[cath]][cath]=i;
                fNLocal[cath]++;
@@ -988,15 +1161,14 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
        } // loop over all digits
 // if one additional maximum has been found we are happy 
 // if more maxima have been found restore the previous situation
-       fprintf(stderr,"\n New search gives %d local maxima for cathode 1 \n",fNLocal[0]);
-       fprintf(stderr,"\n                  %d local maxima for cathode 2 \n",fNLocal[1]);
-//     printf("\n New search gives %d %d \n",fNLocal[0],fNLocal[1]);
+       if (fDebugLevel) {
+           fprintf(stderr,"\n New search gives %d local maxima for cathode 1 \n",fNLocal[0]);
+           fprintf(stderr,"\n                  %d local maxima for cathode 2 \n",fNLocal[1]);
+           printf("\n New search gives %d %d \n",fNLocal[0],fNLocal[1]);
+       }
        if (fNLocal[cath]>2) {
            fNLocal[cath]=iback;
        }
-
-
-
     } // 2,1 local maxima
 }
 
@@ -1011,71 +1183,75 @@ void  AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t flag, Int_
     Int_t  ix, iy;
     
     if (cath==1) {
-       c->fPeakSignal[cath]=c->fPeakSignal[0]; 
+       c->SetPeakSignal(cath,c->GetPeakSignal(0));     
     } else {
-       c->fPeakSignal[cath]=0;
+       c->SetPeakSignal(cath,0);
     }
     
     
     if (flag) {
-       c->fX[cath]=0;
-       c->fY[cath]=0;
-       c->fQ[cath]=0;
+       c->SetX(cath,0.);
+       c->SetY(cath,0.);
+       c->SetCharge(cath,0);
     }
 
-//    fprintf(stderr,"\n fPeakSignal %d\n",c->fPeakSignal[cath]);
-    for (Int_t i=0; i<c->fMultiplicity[cath]; i++)
+    if (fDebugLevel)
+       fprintf(stderr,"\n fPeakSignal %d\n",c->GetPeakSignal(cath));
+    for (Int_t i=0; i<c->GetMultiplicity(cath); i++)
     {
-       dig= fInput->Digit(cath,c->fIndexMap[i][cath]);
-       ix=dig->fPadX+c->fOffsetMap[i][cath];
-       iy=dig->fPadY;
-       Int_t q=dig->fSignal;
-       if (!flag) q=Int_t(q*c->fContMap[i][cath]);
+       dig= fInput->Digit(cath,c->GetIndex(i,cath));
+       ix=dig->PadX()+c->GetOffset(i,cath);
+       iy=dig->PadY();
+       Int_t q=dig->Signal();
+       if (!flag) q=Int_t(q*c->GetContrib(i,cath));
 //     fprintf(stderr,"q %d c->fPeakSignal[ %d ] %d\n",q,cath,c->fPeakSignal[cath]);
-       if (dig->fPhysics >= dig->fSignal) {
-           c->fPhysicsMap[i]=2;
-       } else if (dig->fPhysics == 0) {
-           c->fPhysicsMap[i]=0;
-       } else  c->fPhysicsMap[i]=1;
+       if (dig->Physics() >= dig->Signal()) {
+           c->SetPhysics(i,2);
+       } else if (dig->Physics() == 0) {
+           c->SetPhysics(i,0);
+       } else  c->SetPhysics(i,1);
 //
 // 
-//     fprintf(stderr,"q %d c->fPeakSignal[cath] %d\n",q,c->fPeakSignal[cath]);
+       if (fDebugLevel>1)
+           fprintf(stderr,"q %d c->fPeakSignal[cath] %d\n",q,c->GetPeakSignal(cath));
 // peak signal and track list
-       if (q>c->fPeakSignal[cath]) {
-           c->fPeakSignal[cath]=q;
-           c->fTracks[0]=dig->fHit;
-           c->fTracks[1]=dig->fTracks[0];
-           c->fTracks[2]=dig->fTracks[1];
+       if (q>c->GetPeakSignal(cath)) {
+           c->SetPeakSignal(cath, q);
+           c->SetTrack(0,dig->Hit());
+           c->SetTrack(1,dig->Track(0));
+           c->SetTrack(2,dig->Track(1));
 //         fprintf(stderr," c->fTracks[0] %d c->fTracks[1] %d\n",dig->fHit,dig->fTracks[0]);
        }
 //
        if (flag) {
-           fInput->Segmentation(cath)->GetPadC(ix, iy, x, y, z);
-           c->fX[cath] += q*x;
-           c->fY[cath] += q*y;
-           c->fQ[cath] += q;
+           fSeg[cath]->GetPadC(ix, iy, x, y, z);
+           c->AddX(cath, q*x);
+           c->AddY(cath, q*y);
+           c->AddCharge(cath, q);
        }
     } // loop over digits
-//    fprintf(stderr," fin du cluster c\n");
+    if (fDebugLevel)
+       fprintf(stderr," fin du cluster c\n");
 
 
     if (flag) {
-       c->fX[cath]/=c->fQ[cath];
-       c->fX[cath]=fInput->Segmentation(cath)->GetAnod(c->fX[cath]);
-       c->fY[cath]/=c->fQ[cath]; 
+       c->SetX(cath, c->GetX(cath)/c->GetCharge(cath));
+// Force on anod
+       c->SetX(cath, fSeg[cath]->GetAnod(c->GetX(cath)));
+       c->SetY(cath, c->GetY(cath)/c->GetCharge(cath)); 
 //
 //  apply correction to the coordinate along the anode wire
 //
-       x=c->fX[cath];   
-       y=c->fY[cath];
-       fInput->Segmentation(cath)->GetPadI(x, y, 0, ix, iy);
-       fInput->Segmentation(cath)->GetPadC(ix, iy, x, y, z);
-       Int_t isec=fInput->Segmentation(cath)->Sector(ix,iy);
-       TF1* cogCorr = fInput->Segmentation(cath)->CorrFunc(isec-1);
+       x=c->GetX(cath);   
+       y=c->GetY(cath);
+       fSeg[cath]->GetPadI(x, y, fZPlane, ix, iy);
+       fSeg[cath]->GetPadC(ix, iy, x, y, z);
+       Int_t isec=fSeg[cath]->Sector(ix,iy);
+       TF1* cogCorr = fSeg[cath]->CorrFunc(isec-1);
        
        if (cogCorr) {
-           Float_t yOnPad=(c->fY[cath]-y)/fInput->Segmentation(cath)->Dpy(isec);
-           c->fY[cath]=c->fY[cath]-cogCorr->Eval(yOnPad, 0, 0);
+           Float_t yOnPad=(c->GetY(cath)-y)/fSeg[cath]->Dpy(isec);
+           c->SetY(cath, c->GetY(cath)-cogCorr->Eval(yOnPad, 0, 0));
        }
     }
 }
@@ -1096,140 +1272,174 @@ void  AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t cath)
     Float_t xpad, ypad, zpad;
     Float_t dx, dy, dr;
 
-    for (Int_t i=0; i<c->fMultiplicity[cath]; i++)
+    for (Int_t i=0; i<c->GetMultiplicity(cath); i++)
     {
-       dig = fInput->Digit(cath,c->fIndexMap[i][cath]);
-       fInput->Segmentation(cath)->
-       GetPadC(dig->fPadX,dig->fPadY,xpad,ypad, zpad);
-       fprintf(stderr,"x %f y %f cx %f cy %f\n",xpad,ypad,c->fX[0],c->fY[0]);
-       dx = xpad - c->fX[0];
-       dy = ypad - c->fY[0];
+       dig = fInput->Digit(cath,c->GetIndex(i,cath));
+       fSeg[cath]->
+       GetPadC(dig->PadX(),dig->PadY(),xpad,ypad, zpad);
+       if (fDebugLevel)
+           fprintf(stderr,"x %f y %f cx %f cy %f\n",xpad,ypad,c->GetX(0),c->GetY(0));
+       dx = xpad - c->GetX(0);
+       dy = ypad - c->GetY(0);
        dr = TMath::Sqrt(dx*dx+dy*dy);
 
        if (dr < dr0) {
            dr0 = dr;
-           fprintf(stderr," dr %f\n",dr);
-           Int_t q=dig->fSignal;
-           if (dig->fPhysics >= dig->fSignal) {
-               c->fPhysicsMap[i]=2;
-           } else if (dig->fPhysics == 0) {
-               c->fPhysicsMap[i]=0;
-           } else  c->fPhysicsMap[i]=1;
-           c->fPeakSignal[cath]=q;
-           c->fTracks[0]=dig->fHit;
-           c->fTracks[1]=dig->fTracks[0];
-           c->fTracks[2]=dig->fTracks[1];
-           fprintf(stderr," c->fTracks[0] %d c->fTracks[1] %d\n",dig->fHit,dig->fTracks[0]);
+           if (fDebugLevel)
+               fprintf(stderr," dr %f\n",dr);
+           Int_t q=dig->Signal();
+           if (dig->Physics() >= dig->Signal()) {
+               c->SetPhysics(i,2);
+           } else if (dig->Physics() == 0) {
+               c->SetPhysics(i,0);
+           } else  c->SetPhysics(i,1);
+           c->SetPeakSignal(cath,q);
+           c->SetTrack(0,dig->Hit());
+           c->SetTrack(1,dig->Track(0));
+           c->SetTrack(2,dig->Track(1));
+           if (fDebugLevel)
+               fprintf(stderr," c->fTracks[0] %d c->fTracks[1] %d\n",dig->Hit(),
+                   dig->Track(0));
        }
 //
     } // loop over digits
 
 //  apply correction to the coordinate along the anode wire
-    c->fX[cath]=fInput->Segmentation(cath)->GetAnod(c->fX[cath]);
+// Force on anod
+    c->SetX(cath,fSeg[cath]->GetAnod(c->GetX(cath)));
 }
 
 void  AliMUONClusterFinderVS::FindCluster(Int_t i, Int_t j, Int_t cath, AliMUONRawCluster &c){
+
+
 //
-//  Find clusterset
+//  Find a super cluster on both cathodes
 //
 //
 //  Add i,j as element of the cluster
 //
-
+    
     Int_t idx = fHitMap[cath]->GetHitIndex(i,j);
     AliMUONDigit* dig = (AliMUONDigit*) fHitMap[cath]->GetHit(i,j);
-    Int_t q=dig->fSignal;
-    Int_t theX=dig->fPadX;
-    Int_t theY=dig->fPadY;    
-    if (q > TMath::Abs(c.fPeakSignal[0]) && q > TMath::Abs(c.fPeakSignal[1])) {
-       c.fPeakSignal[cath]=q;
-       c.fTracks[0]=dig->fHit;
-       c.fTracks[1]=dig->fTracks[0];
-       c.fTracks[2]=dig->fTracks[1];
+    Int_t q=dig->Signal();
+    Int_t theX=dig->PadX();
+    Int_t theY=dig->PadY(); 
+   
+    if (q > TMath::Abs(c.GetPeakSignal(0)) && q > TMath::Abs(c.GetPeakSignal(1))) {
+       c.SetPeakSignal(cath,q);
+       c.SetTrack(0,dig->Hit());
+       c.SetTrack(1,dig->Track(0));
+       c.SetTrack(2,dig->Track(1));
     }
 
 //
 //  Make sure that list of digits is ordered 
 // 
-    Int_t mu=c.fMultiplicity[cath];
-    c.fIndexMap[mu][cath]=idx;
+    Int_t mu=c.GetMultiplicity(cath);
+    c.SetIndex(mu, cath, idx);
     
-    if (dig->fPhysics >= dig->fSignal) {
-        c.fPhysicsMap[mu]=2;
-    } else if (dig->fPhysics == 0) {
-        c.fPhysicsMap[mu]=0;
-    } else  c.fPhysicsMap[mu]=1;
-    if (mu > 0) {
-       for (Int_t ind=mu-1; ind>=0; ind--) {
-           Int_t ist=(c.fIndexMap)[ind][cath];
-           Int_t ql=fInput->Digit(cath, ist)->fSignal;
-           Int_t ix=fInput->Digit(cath, ist)->fPadX;
-           Int_t iy=fInput->Digit(cath, ist)->fPadY;
+    if (dig->Physics() >= dig->Signal()) {
+        c.SetPhysics(mu,2);
+    } else if (dig->Physics() == 0) {
+        c.SetPhysics(mu,0);
+    } else  c.SetPhysics(mu,1);
 
+    
+    if (mu > 0) {
+       for (Int_t ind = mu-1; ind >= 0; ind--) {
+           Int_t ist=c.GetIndex(ind,cath);
+           Int_t ql=fInput->Digit(cath, ist)->Signal();
+           Int_t ix=fInput->Digit(cath, ist)->PadX();
+           Int_t iy=fInput->Digit(cath, ist)->PadY();
+           
            if (q>ql || (q==ql && theX > ix && theY < iy)) {
-               c.fIndexMap[ind][cath]=idx;
-               c.fIndexMap[ind+1][cath]=ist;
+               c.SetIndex(ind, cath, idx);
+               c.SetIndex(ind+1, cath, ist);
            } else {
+               
                break;
            }
        }
     }
-    
-    c.fMultiplicity[cath]++;
-    if (c.fMultiplicity[cath] >= 50 ) {
-       printf("FindCluster - multiplicity >50  %d \n",c.fMultiplicity[0]);
-       c.fMultiplicity[cath]=49;
+
+    c.SetMultiplicity(cath, c.GetMultiplicity(cath)+1);
+    if (c.GetMultiplicity(cath) >= 50 ) {
+      if (fDebugLevel)
+       printf("FindCluster - multiplicity >50  %d \n",c.GetMultiplicity(0));
+       c.SetMultiplicity(cath, 49);
     }
 
 // Prepare center of gravity calculation
     Float_t x, y, z;
-    fInput->Segmentation(cath)->GetPadC(i, j, x, y, z);
-           
-    c.fX[cath] += q*x;
-    c.fY[cath] += q*y;
-    c.fQ[cath] += q;
-// Flag hit as taken  
+    fSeg[cath]->GetPadC(i, j, x, y, z);
+    
+    c.AddX(cath,q*x);
+    c.AddY(cath,q*y);
+    c.AddCharge(cath,q);
+//
+// Flag hit as "taken"  
     fHitMap[cath]->FlagHit(i,j);
 //
 //  Now look recursively for all neighbours and pad hit on opposite cathode
 //
 //  Loop over neighbours
     Int_t ix,iy;
+    ix=iy=0;
     Int_t nn;
     Int_t xList[10], yList[10];
-    fInput->Segmentation(cath)->Neighbours(i,j,&nn,xList,yList);
+    fSeg[cath]->Neighbours(i,j,&nn,xList,yList);
     for (Int_t in=0; in<nn; in++) {
        ix=xList[in];
        iy=yList[in];
-       if (fHitMap[cath]->TestHit(ix,iy)==kUnused) FindCluster(ix, iy, cath, c);
-    }
+       
+       if (fHitMap[cath]->TestHit(ix,iy)==kUnused) {
+           if (fDebugLevel>1)
+               printf("\n Neighbours %d %d %d", cath, ix, iy);
+           FindCluster(ix, iy, cath, c);
+       }
+       
+   }
+    Int_t nOpp=0;
+    Int_t iXopp[50], iYopp[50];
+    
 //  Neighbours on opposite cathode 
 //  Take into account that several pads can overlap with the present pad
-    Float_t xmin, xmax, ymin, ymax, xc, yc;
+    Int_t isec=fSeg[cath]->Sector(i,j);    
     Int_t iop;
-    Int_t isec=fInput->Segmentation(cath)->Sector(i,j);    
+    Float_t dx, dy;
+
     if (cath==0) {
-       iop=1;
-       xmin=x-fInput->Segmentation(cath)->Dpx(isec);
-       xmax=x+fInput->Segmentation(cath)->Dpx(isec);
-       xc=xmin+.001;
-       while (xc < xmax) {
-           xc+=fInput->Segmentation(iop)->Dpx(isec);
-           fInput->Segmentation(iop)->GetPadI(xc,y,0,ix,iy);
-           if (ix>=(fInput->Segmentation(iop)->Npx()) || (iy>=fInput->Segmentation(iop)->Npy())) continue;
-           if (fHitMap[iop]->TestHit(ix,iy)==kUnused) FindCluster(ix, iy, iop, c);
-       }
+       iop = 1;
+       dx  = (fSeg[cath]->Dpx(isec))/2.;
+       dy  = 0.;
     } else {
-       iop=0;
-       ymin=y-fInput->Segmentation(cath)->Dpy(isec);
-       ymax=y+fInput->Segmentation(cath)->Dpy(isec);
-       yc=ymin+.001;
-       while (yc < ymax) {
-           yc+=fInput->Segmentation(iop)->Dpy(isec);
-           fInput->Segmentation(iop)->GetPadI(x,yc,0,ix,iy);
-           if (ix>=(fInput->Segmentation(iop)->Npx()) || (iy>=fInput->Segmentation(iop)->Npy())) continue;
-           if (fHitMap[iop]->TestHit(ix,iy)==kUnused) FindCluster(ix, iy, iop, c);
+       iop = 0;
+       dx  = 0.;
+       dy  = (fSeg[cath]->Dpy(isec))/2;
+    }
+// loop over pad neighbours on opposite cathode
+    for (fSeg[iop]->FirstPad(x, y, fZPlane, dx, dy);
+        fSeg[iop]->MorePads();
+        fSeg[iop]->NextPad())
+    {
+       
+       ix = fSeg[iop]->Ix(); iy = fSeg[iop]->Iy();
+       if (fDebugLevel > 1)
+           printf("\n ix, iy: %f %f %f %d %d %d", x,y,z,ix, iy, fSector);
+       if (fHitMap[iop]->TestHit(ix,iy)==kUnused){
+           iXopp[nOpp]=ix;
+           iYopp[nOpp++]=iy;
+           if (fDebugLevel > 1)
+               printf("\n Opposite %d %d %d", iop, ix, iy);
        }
+       
+    } // Loop over pad neighbours
+//  This had to go outside the loop since recursive calls inside the iterator are not possible
+//
+    Int_t jopp;
+    for (jopp=0; jopp<nOpp; jopp++) {
+       if (fHitMap[iop]->TestHit(iXopp[jopp],iYopp[jopp]) == kUnused) 
+           FindCluster(iXopp[jopp], iYopp[jopp], iop, c);
     }
 }
 
@@ -1242,11 +1452,17 @@ void AliMUONClusterFinderVS::FindRawClusters()
   // fills the tree with raw clusters
   //
 
+    ResetRawClusters();
+//  Return if no input datad available
     if (!fInput->NDigits(0) && !fInput->NDigits(1)) return;
 
-    fHitMap[0]  = new AliMUONHitMapA1(fInput->Segmentation(0), fInput->Digits(0));
-    fHitMap[1]  = new AliMUONHitMapA1(fInput->Segmentation(1), fInput->Digits(1));
+    fSeg[0] = fInput->Segmentation(0);
+    fSeg[1] = fInput->Segmentation(1);
+
+    fHitMap[0]  = new AliMUONHitMapA1(fSeg[0], fInput->Digits(0));
+    fHitMap[1]  = new AliMUONHitMapA1(fSeg[1], fInput->Digits(1));
 
     AliMUONDigit *dig;
 
     Int_t ndig, cath;
@@ -1259,68 +1475,75 @@ void AliMUONClusterFinderVS::FindRawClusters()
     for (cath=0; cath<2; cath++) {
        for (ndig=0; ndig<fInput->NDigits(cath); ndig++) {
            dig = fInput->Digit(cath, ndig);
-           Int_t i=dig->fPadX;
-           Int_t j=dig->fPadY;
+           Int_t i=dig->PadX();
+           Int_t j=dig->PadY();
            if (fHitMap[cath]->TestHit(i,j)==kUsed ||fHitMap[0]->TestHit(i,j)==kEmpty) {
                nskip++;
                continue;
            }
-           fprintf(stderr,"\n CATHODE %d CLUSTER %d\n",cath,ncls);
+           if (fDebugLevel)
+               fprintf(stderr,"\n CATHODE %d CLUSTER %d\n",cath,ncls);
            AliMUONRawCluster c;
-           c.fMultiplicity[0]=0;
-           c.fMultiplicity[1]=0;
-           c.fPeakSignal[cath]=dig->fSignal;
-           c.fTracks[0]=dig->fHit;
-           c.fTracks[1]=dig->fTracks[0];
-           c.fTracks[2]=dig->fTracks[1];
+           c.SetMultiplicity(0, 0);
+           c.SetMultiplicity(1, 0);
+           c.SetPeakSignal(cath,dig->Signal());
+           c.SetTrack(0, dig->Hit());
+           c.SetTrack(1, dig->Track(0));
+           c.SetTrack(2, dig->Track(1));
            // tag the beginning of cluster list in a raw cluster
-           c.fNcluster[0]=-1;
-
+           c.SetNcluster(0,-1);
+           Float_t xcu, ycu;
+           fSeg[cath]->GetPadC(i,j,xcu, ycu, fZPlane);
+           fSector= fSeg[cath]->Sector(i,j)/100;
+           if (fDebugLevel)
+               printf("\n New Seed %d %d ", i,j);
+       
+            
            FindCluster(i,j,cath,c);
-
+//          ^^^^^^^^^^^^^^^^^^^^^^^^
            // center of gravity
-           c.fX[0] /= c.fQ[0];
-           c.fX[0]=fInput->Segmentation(0)->GetAnod(c.fX[0]);
-           c.fY[0] /= c.fQ[0];
-           c.fX[1] /= c.fQ[1];
-           c.fX[1]=fInput->Segmentation(0)->GetAnod(c.fX[1]);
-           c.fY[1] /= c.fQ[1];
-           fprintf(stderr,"\n Cathode 1 multiplicite %d X(CG) %f Y(CG) %f\n",c.fMultiplicity[0],c.fX[0],c.fY[0]);
-           fprintf(stderr," Cathode 2 multiplicite %d X(CG) %f Y(CG) %f\n",c.fMultiplicity[1],c.fX[1],c.fY[1]);
-
-//     Mathieson Fit
-/*
-           Bool_t fitted;
+           if (c.GetX(0)!=0.) c.SetX(0, c.GetX(0)/c.GetCharge(0)); // c.fX[0] /= c.fQ[0];
+// Force on anod
+           c.SetX(0,fSeg[0]->GetAnod(c.GetX(0)));
+           if (c.GetY(0)!=0.) c.SetY(0, c.GetY(0)/c.GetCharge(0)); // c.fY[0] /= c.fQ[0];
+           
+           if(c.GetCharge(1)!=0.) c.SetX(1, c.GetX(1)/c.GetCharge(1));  // c.fX[1] /= c.fQ[1];
+                                       
+          // Force on anod
+           c.SetX(1, fSeg[0]->GetAnod(c.GetX(1)));
+           if(c.GetCharge(1)!=0.) c.SetY(1, c.GetY(1)/c.GetCharge(1));// c.fY[1] /= c.fQ[1];
            
-           fitted=SingleMathiesonFit(&c, 0);
-           c.fX[0]=fInput->Segmentation(0)->GetAnod(c.fX[0]);
-           fitted=SingleMathiesonFit(&c, 1);       
-           c.fX[1]=fInput->Segmentation(1)->GetAnod(c.fX[1]);
-*/ 
-//
+           c.SetZ(0, fZPlane);
+           c.SetZ(1, fZPlane);     
+
+           if (fDebugLevel) {
+               fprintf(stderr,"\n Cathode 1 multiplicite %d X(CG) %f Y(CG) %f\n",
+                       c.GetMultiplicity(0),c.GetX(0),c.GetY(0));
+               fprintf(stderr," Cathode 2 multiplicite %d X(CG) %f Y(CG) %f\n",
+                       c.GetMultiplicity(1),c.GetX(1),c.GetY(1));
+           }
 //      Analyse cluster and decluster if necessary
 //     
        ncls++;
-       c.fNcluster[1]=fNRawClusters;
-       c.fClusterType=c.PhysicsContribution();
+       c.SetNcluster(1,fNRawClusters);
+       c.SetClusterType(c.PhysicsContribution());
 
        fNPeaks=0;
 //
 //
        Decluster(&c);
-//     AddRawCluster(c);
-
 //
 //      reset Cluster object
        { // begin local scope
-           for (int k=0;k<c.fMultiplicity[0];k++) c.fIndexMap[k][0]=0;
+           for (int k=0;k<c.GetMultiplicity(0);k++) c.SetIndex(k, 0, 0);
        } // end local scope
 
        { // begin local scope
-           for (int k=0;k<c.fMultiplicity[1];k++) c.fIndexMap[k][1]=0;
+           for (int k=0;k<c.GetMultiplicity(1);k++) c.SetIndex(k, 1, 0);
        } // end local scope
        
-       c.fMultiplicity[0]=c.fMultiplicity[0]=0;
+       c.SetMultiplicity(0,0);
+       c.SetMultiplicity(1,0);
 
        
        } // end loop ndig
@@ -1331,31 +1554,33 @@ void AliMUONClusterFinderVS::FindRawClusters()
 
 Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t cath)
 {
-//
+// Performs a single Mathieson fit on one cathode
+// 
+    Double_t arglist[20];
+    Int_t ierflag=0;
     AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
     
     clusterInput.Fitter()->SetFCN(fcnS1);
     clusterInput.Fitter()->mninit(2,10,7);
-    Double_t arglist[20];
-    Int_t ierflag=0;
-    arglist[0]=1;
-//     clusterInput.Fitter()->mnexcm("SET ERR",arglist,1,ierflag);
+    clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
+    arglist[0]=-1;
+    clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
 // Set starting values 
     static Double_t vstart[2];
-    vstart[0]=c->fX[1];
-    vstart[1]=c->fY[0];
+    vstart[0]=c->GetX(1);
+    vstart[1]=c->GetY(0);
     
     
 // lower and upper limits
     static Double_t lower[2], upper[2];
     Int_t ix,iy;
-    fInput->Segmentation(cath)->GetPadI(c->fX[cath], c->fY[cath], 0, ix, iy);
-    Int_t isec=fInput->Segmentation(cath)->Sector(ix, iy);
-    lower[0]=vstart[0]-fInput->Segmentation(cath)->Dpx(isec)/2;
-    lower[1]=vstart[1]-fInput->Segmentation(cath)->Dpy(isec)/2;
+    fSeg[cath]->GetPadI(c->GetX(cath), c->GetY(cath), fZPlane, ix, iy);
+    Int_t isec=fSeg[cath]->Sector(ix, iy);
+    lower[0]=vstart[0]-fSeg[cath]->Dpx(isec)/2;
+    lower[1]=vstart[1]-fSeg[cath]->Dpy(isec)/2;
     
-    upper[0]=lower[0]+fInput->Segmentation(cath)->Dpx(isec);
-    upper[1]=lower[1]+fInput->Segmentation(cath)->Dpy(isec);
+    upper[0]=lower[0]+fSeg[cath]->Dpx(isec);
+    upper[1]=lower[1]+fSeg[cath]->Dpy(isec);
     
 // step sizes
     static Double_t step[2]={0.0005, 0.0005};
@@ -1363,14 +1588,12 @@ Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t c
     clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
     clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
 // ready for minimisation      
-    clusterInput.Fitter()->SetPrintLevel(1);
-    clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
     arglist[0]= -1;
     arglist[1]= 0;
     
     clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
     clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
-    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
+    //    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
     Double_t fmin, fedm, errdef;
     Int_t   npari, nparx, istat;
       
@@ -1390,52 +1613,80 @@ Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t c
     return fmin;
 }
 
-Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster *c)
+Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster * /*c*/)
 {
 // Perform combined Mathieson fit on both cathode planes
 //
+    Double_t arglist[20];
+    Int_t ierflag=0;
     AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
     clusterInput.Fitter()->SetFCN(fcnCombiS1);
     clusterInput.Fitter()->mninit(2,10,7);
-    Double_t arglist[20];
-    Int_t ierflag=0;
-    arglist[0]=1;
+    clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
+    arglist[0]=-1;
+    clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
     static Double_t vstart[2];
     vstart[0]=fXInit[0];
     vstart[1]=fYInit[0];
     
     
 // lower and upper limits
-    static Double_t lower[2], upper[2];
+    static Float_t lower[2], upper[2];
     Int_t ix,iy,isec;
-    fInput->Segmentation(0)->GetPadI(fXInit[0], fYInit[0], 0, ix, iy);
-    isec=fInput->Segmentation(0)->Sector(ix, iy);
-    Float_t dpy=fInput->Segmentation(0)->Dpy(isec)/2;
-    fInput->Segmentation(1)->GetPadI(fXInit[0], fYInit[0], 0, ix, iy);
-    isec=fInput->Segmentation(1)->Sector(ix, iy);
-    Float_t dpx=fInput->Segmentation(1)->Dpx(isec)/2;
+    fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
+    isec=fSeg[0]->Sector(ix, iy);
+    Float_t dpy=fSeg[0]->Dpy(isec);
+    fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
+    isec=fSeg[1]->Sector(ix, iy);
+    Float_t dpx=fSeg[1]->Dpx(isec);
 
+    Int_t icount;
+    Float_t xdum, ydum, zdum;
 
-    lower[0]=vstart[0]-dpx;
-    lower[1]=vstart[1]-dpy;
+//  Find save upper and lower limits    
     
-    upper[0]=vstart[0]+dpx;
-    upper[1]=vstart[1]+dpy;
+    icount = 0;
     
+    for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.); 
+        fSeg[1]->MorePads(); fSeg[1]->NextPad())
+    {
+       ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
+       fSeg[1]->GetPadC(ix,iy, upper[0], ydum, zdum);  
+       if (icount ==0) lower[0]=upper[0];
+       icount++;
+    }
+
+    if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}
+       
+    icount=0;
+    if (fDebugLevel)
+       printf("\n single y %f %f", fXInit[0], fYInit[0]);
+    
+    for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy); 
+        fSeg[0]->MorePads(); fSeg[0]->NextPad())
+    {
+       ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
+       fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);     
+       if (icount ==0) lower[1]=upper[1];
+       icount++;
+       if (fDebugLevel)
+           printf("\n upper lower %d %f %f", icount, upper[1], lower[1]);
+    }
+    
+    if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}
+
 // step sizes
     static Double_t step[2]={0.00001, 0.0001};
     
     clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
     clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
 // ready for minimisation      
-    clusterInput.Fitter()->SetPrintLevel(1);
-    clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
     arglist[0]= -1;
     arglist[1]= 0;
     
     clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
     clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
-    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
+    //    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
     Double_t fmin, fedm, errdef;
     Int_t   npari, nparx, istat;
       
@@ -1455,16 +1706,21 @@ Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster *c)
     return fmin;
 }
 
-Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster *c, Int_t cath)
+Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster * /*c*/, Int_t cath)
 {
+// Performs a double Mathieson fit on one cathode
+// 
+
 //
 //  Initialise global variables for fit
+    Double_t arglist[20];
+    Int_t ierflag=0;
     AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
     clusterInput.Fitter()->SetFCN(fcnS2);
     clusterInput.Fitter()->mninit(5,10,7);
-    Double_t arglist[20];
-    Int_t ierflag=0;
-    arglist[0]=1;
+    clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
+    arglist[0]=-1;
+    clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
 // Set starting values 
     static Double_t vstart[5];
     vstart[0]=fX[fIndLocal[0][cath]][cath];
@@ -1474,20 +1730,20 @@ Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster *c, Int_t ca
     vstart[4]=Float_t(fQ[fIndLocal[0][cath]][cath])/
        Float_t(fQ[fIndLocal[0][cath]][cath]+fQ[fIndLocal[1][cath]][cath]);
 // lower and upper limits
-    static Double_t lower[5], upper[5];
-    Int_t isec=fInput->Segmentation(cath)->Sector(fIx[fIndLocal[0][cath]][cath], fIy[fIndLocal[0][cath]][cath]);
-    lower[0]=vstart[0]-fInput->Segmentation(cath)->Dpx(isec);
-    lower[1]=vstart[1]-fInput->Segmentation(cath)->Dpy(isec);
+    static Float_t lower[5], upper[5];
+    Int_t isec=fSeg[cath]->Sector(fIx[fIndLocal[0][cath]][cath], fIy[fIndLocal[0][cath]][cath]);
+    lower[0]=vstart[0]-fSeg[cath]->Dpx(isec);
+    lower[1]=vstart[1]-fSeg[cath]->Dpy(isec);
     
-    upper[0]=lower[0]+2.*fInput->Segmentation(cath)->Dpx(isec);
-    upper[1]=lower[1]+2.*fInput->Segmentation(cath)->Dpy(isec);
+    upper[0]=lower[0]+2.*fSeg[cath]->Dpx(isec);
+    upper[1]=lower[1]+2.*fSeg[cath]->Dpy(isec);
     
-    isec=fInput->Segmentation(cath)->Sector(fIx[fIndLocal[1][cath]][cath], fIy[fIndLocal[1][cath]][cath]);
-    lower[2]=vstart[2]-fInput->Segmentation(cath)->Dpx(isec)/2;
-    lower[3]=vstart[3]-fInput->Segmentation(cath)->Dpy(isec)/2;
+    isec=fSeg[cath]->Sector(fIx[fIndLocal[1][cath]][cath], fIy[fIndLocal[1][cath]][cath]);
+    lower[2]=vstart[2]-fSeg[cath]->Dpx(isec)/2;
+    lower[3]=vstart[3]-fSeg[cath]->Dpy(isec)/2;
     
-    upper[2]=lower[2]+fInput->Segmentation(cath)->Dpx(isec);
-    upper[3]=lower[3]+fInput->Segmentation(cath)->Dpy(isec);
+    upper[2]=lower[2]+fSeg[cath]->Dpx(isec);
+    upper[3]=lower[3]+fSeg[cath]->Dpy(isec);
     
     lower[4]=0.;
     upper[4]=1.;
@@ -1500,14 +1756,12 @@ Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster *c, Int_t ca
     clusterInput.Fitter()->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
     clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
 // ready for minimisation      
-    clusterInput.Fitter()->SetPrintLevel(-1);
-    clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
     arglist[0]= -1;
     arglist[1]= 0;
     
     clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
     clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
-    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
+    //    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
 // Get fitted parameters
     Double_t xrec[2], yrec[2], qfrac;
     TString chname;
@@ -1527,17 +1781,19 @@ Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster *c, Int_t ca
     return kTRUE;
 }
 
-Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster *c)
+Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster * /*c*/)
 {
 //
 // Perform combined double Mathieson fit on both cathode planes
 //
+    Double_t arglist[20];
+    Int_t ierflag=0;
     AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
     clusterInput.Fitter()->SetFCN(fcnCombiS2);
     clusterInput.Fitter()->mninit(6,10,7);
-    Double_t arglist[20];
-    Int_t ierflag=0;
-    arglist[0]=1;
+    clusterInput.Fitter()->SetPrintLevel(-1+fDebugLevel);
+    arglist[0]=-1;
+    clusterInput.Fitter()->mnexcm("SET NOW", arglist, 0, ierflag);
 // Set starting values 
     static Double_t vstart[6];
     vstart[0]=fXInit[0];
@@ -1547,37 +1803,97 @@ Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster *c)
     vstart[4]=fQrInit[0];
     vstart[5]=fQrInit[1];
 // lower and upper limits
-    static Double_t lower[6], upper[6];
+    static Float_t lower[6], upper[6];
     Int_t ix,iy,isec;
     Float_t dpx, dpy;
     
-    fInput->Segmentation(1)->GetPadI(fXInit[0], fYInit[0], 0, ix, iy);
-    isec=fInput->Segmentation(1)->Sector(ix, iy);
-    dpx=fInput->Segmentation(1)->Dpx(isec);
+    fSeg[1]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
+    isec=fSeg[1]->Sector(ix, iy);
+    dpx=fSeg[1]->Dpx(isec);
+
+    fSeg[0]->GetPadI(fXInit[0], fYInit[0], fZPlane, ix, iy);
+    isec=fSeg[0]->Sector(ix, iy);
+    dpy=fSeg[0]->Dpy(isec);
+
+
+    Int_t icount;
+    Float_t xdum, ydum, zdum;
+    if (fDebugLevel)
+       printf("\n Cluster Finder: %f %f %f %f  ", fXInit[0], fXInit[1],fYInit[0], fYInit[1] );
+    
+//  Find save upper and lower limits    
+    icount = 0;
+    
+    for (fSeg[1]->FirstPad(fXInit[0], fYInit[0], fZPlane, dpx, 0.); 
+        fSeg[1]->MorePads(); fSeg[1]->NextPad())
+    {
+       ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
+//     if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
+       fSeg[1]->GetPadC(ix,iy,upper[0],ydum,zdum);     
+       if (icount ==0) lower[0]=upper[0];
+       icount++;
+    }
+    if (lower[0]>upper[0]) {xdum=lower[0]; lower[0]=upper[0]; upper[0]=xdum;}    
+//    vstart[0] = 0.5*(lower[0]+upper[0]);
+
+    
+    icount=0;
+    
+    for (fSeg[0]->FirstPad(fXInit[0], fYInit[0], fZPlane, 0., dpy); 
+        fSeg[0]->MorePads(); fSeg[0]->NextPad())
+    {
+       ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
+//     if (fHitMap[0]->TestHit(ix, iy) == kEmpty) continue;
+       fSeg[0]->GetPadC(ix,iy,xdum,upper[1],zdum);     
+       if (icount ==0) lower[1]=upper[1];
+       icount++;
+    }
+    
+    if (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}    
+//     vstart[1] = 0.5*(lower[1]+upper[1]);
 
-    fInput->Segmentation(0)->GetPadI(fXInit[0], fYInit[0], 0, ix, iy);
-    isec=fInput->Segmentation(0)->Sector(ix, iy);
-    dpy=fInput->Segmentation(0)->Dpy(isec);
 
-    lower[0]=vstart[0]-dpx;
-    lower[1]=vstart[1]-dpy;
-    upper[0]=vstart[0]+dpx;
-    upper[1]=vstart[1]+dpy;
+    fSeg[1]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
+    isec=fSeg[1]->Sector(ix, iy);
+    dpx=fSeg[1]->Dpx(isec);
+    fSeg[0]->GetPadI(fXInit[1], fYInit[1], fZPlane, ix, iy);
+    isec=fSeg[0]->Sector(ix, iy);
+    dpy=fSeg[0]->Dpy(isec);
 
 
-    fInput->Segmentation(1)->GetPadI(fXInit[1], fYInit[1], 0, ix, iy);
-    isec=fInput->Segmentation(1)->Sector(ix, iy);
-    dpx=fInput->Segmentation(1)->Dpx(isec);
-    fInput->Segmentation(0)->GetPadI(fXInit[1], fYInit[1], 0, ix, iy);
-    isec=fInput->Segmentation(0)->Sector(ix, iy);
-    dpy=fInput->Segmentation(0)->Dpy(isec);
+//  Find save upper and lower limits    
 
-    lower[2]=vstart[2]-dpx;
-    lower[3]=vstart[3]-dpy;
-    upper[2]=vstart[2]+dpx;
-    upper[3]=vstart[3]+dpy;
+    icount=0;
+    
+    for (fSeg[1]->FirstPad(fXInit[1], fYInit[1], fZPlane, dpx, 0); 
+        fSeg[1]->MorePads(); fSeg[1]->NextPad())
+    {
+       ix=fSeg[1]->Ix(); iy=fSeg[1]->Iy();
+//     if (fHitMap[1]->TestHit(ix, iy) == kEmpty) continue;
+       fSeg[1]->GetPadC(ix,iy,upper[2],ydum,zdum);     
+       if (icount ==0) lower[2]=upper[2];
+       icount++;
+    }
+    if (lower[2]>upper[2]) {xdum=lower[2]; lower[2]=upper[2]; upper[2]=xdum;}    
+    //    vstart[2] = 0.5*(lower[2]+upper[2]);
 
+    icount=0;
+    
+    for (fSeg[0]->FirstPad(fXInit[1], fYInit[1], fZPlane, 0, dpy); 
+        fSeg[0]-> MorePads(); fSeg[0]->NextPad())
+    {
+       ix=fSeg[0]->Ix(); iy=fSeg[0]->Iy();
+//     if (fHitMap[0]->TestHit(ix, iy) != kEmpty) continue;
+       
+       fSeg[0]->GetPadC(ix,iy,xdum,upper[3],zdum);     
+       if (icount ==0) lower[3]=upper[3];
+       icount++;
 
+    }
+    if (lower[3]>upper[3]) {xdum=lower[3]; lower[3]=upper[3]; upper[3]=xdum;}    
+    
+//     vstart[3] = 0.5*(lower[3]+upper[3]);
+    
     lower[4]=0.;
     upper[4]=1.;
     lower[5]=0.;
@@ -1585,7 +1901,6 @@ Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster *c)
 
 // step sizes
     static Double_t step[6]={0.0005, 0.0005, 0.0005, 0.0005, 0.001, 0.001};
-    
     clusterInput.Fitter()->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
     clusterInput.Fitter()->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
     clusterInput.Fitter()->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
@@ -1593,14 +1908,12 @@ Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster *c)
     clusterInput.Fitter()->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
     clusterInput.Fitter()->mnparm(5,"a1",vstart[5],step[5],lower[5],upper[5],ierflag);
 // ready for minimisation      
-    clusterInput.Fitter()->SetPrintLevel(-1);
-    clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
     arglist[0]= -1;
     arglist[1]= 0;
     
     clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
     clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
-    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
+    //    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
 // Get fitted parameters
     TString chname;
     Double_t epxz, b1, b2;
@@ -1632,40 +1945,40 @@ void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
     AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
     for (j=0; j<2; j++) {
        AliMUONRawCluster cnew;
+       cnew.SetGhost(c->GetGhost());
        for (cath=0; cath<2; cath++) {
-           cnew.fChi2[cath]=fChi2[0];
+           cnew.SetChi2(cath,fChi2[0]);
+           // ?? why not cnew.fChi2[cath]=fChi2[cath];
            
            if (fNPeaks == 0) {
-               cnew.fNcluster[0]=-1;
-               cnew.fNcluster[1]=fNRawClusters;
+               cnew.SetNcluster(0,-1);
+               cnew.SetNcluster(1,fNRawClusters);
            } else {
-               cnew.fNcluster[0]=fNPeaks;
-               cnew.fNcluster[1]=0;
+               cnew.SetNcluster(0,fNPeaks);
+               cnew.SetNcluster(1,0);
            }
-           cnew.fMultiplicity[cath]=0;
-           cnew.fX[cath]=Float_t(fXFit[j]);
-           cnew.fY[cath]=Float_t(fYFit[j]);
+           cnew.SetMultiplicity(cath,0);
+           cnew.SetX(cath, Float_t(fXFit[j]));
+           cnew.SetY(cath, Float_t(fYFit[j]));
+           cnew.SetZ(cath, fZPlane);
            if (j==0) {
-               cnew.fQ[cath]=Int_t(clusterInput.TotalCharge(cath)*fQrFit[cath]);
+               cnew.SetCharge(cath, Int_t(clusterInput.TotalCharge(cath)*fQrFit[cath]));
            } else {
-               cnew.fQ[cath]=Int_t(clusterInput.TotalCharge(cath)*(1-fQrFit[cath]));
+               cnew.SetCharge(cath, Int_t(clusterInput.TotalCharge(cath)*(1-fQrFit[cath])));
            }
-           fInput->Segmentation(cath)->SetHit(fXFit[j],fYFit[j],0);
+           fSeg[cath]->SetHit(fXFit[j],fYFit[j],fZPlane);
            for (i=0; i<fMul[cath]; i++) {
-               cnew.fIndexMap[cnew.fMultiplicity[cath]][cath]=
-                   c->fIndexMap[i][cath];
-               fInput->Segmentation(cath)->SetPad(fIx[i][cath], fIy[i][cath]);
-               Float_t q1=fInput->Response()->IntXY(fInput->Segmentation(cath));
-               cnew.fContMap[i][cath]
-                   =(q1*Float_t(cnew.fQ[cath]))/Float_t(fQ[i][cath]);
-               cnew.fMultiplicity[cath]++;
-//             printf(" fXFIT %f fYFIT %f Multiplicite %d\n",cnew.fX[cath],cnew.fY[cath],cnew.fMultiplicity[cath]);
+               cnew.SetIndex(cnew.GetMultiplicity(cath), cath, c->GetIndex(i,cath));
+               fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
+               Float_t q1=fInput->Response()->IntXY(fSeg[cath]);
+               cnew.SetContrib(i, cath, q1*Float_t(cnew.GetCharge(cath))/Float_t(fQ[i][cath]));
+               cnew.SetMultiplicity(cath, cnew.GetMultiplicity(cath)+1 );
            }
            FillCluster(&cnew,0,cath);
        } // cathode loop
        
-       cnew.fClusterType=cnew.PhysicsContribution();
-       if (cnew.fQ[0]>0 && cnew.fQ[1]>0) AddRawCluster(cnew);
+       cnew.SetClusterType(cnew.PhysicsContribution());
+       if (cnew.GetCharge(0)>0 && cnew.GetCharge(1)>0) AddRawCluster(cnew);
        fNPeaks++;
     }
 }
@@ -1674,7 +1987,7 @@ void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
 //
 // Minimisation functions
 // Single Mathieson
-void fcnS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
+void fcnS1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
 {
     AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());    
     Int_t i;
@@ -1694,7 +2007,7 @@ void fcnS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
     f=chisq;
 }
 
-void fcnCombiS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
+void fcnCombiS1(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
 {
     AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());    
     Int_t i, cath;
@@ -1702,27 +2015,22 @@ void fcnCombiS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t if
     Float_t chisq=0;
     Float_t qcont=0;
     Float_t qtot=0;
-    //    Float_t chi2temp=0;
 
     for (cath=0; cath<2; cath++) {
-//     chisq=0;
        for (i=0; i<clusterInput.Nmul(cath); i++) {
            Float_t q0=clusterInput.Charge(i,cath);
            Float_t q1=clusterInput.DiscrChargeCombiS1(i,par,cath);
-           //      delta=(q0-q1);
            delta=(q0-q1)/q0;
            chisq+=delta*delta;
            qcont+=q1;
            qtot+=q0;
        }
-//     if (cath == 0) chi2temp=chisq/clusterInput.Nbins[cath];
     }
-//    chisq = chisq/clusterInput.Nbins[1]+chi2temp; 
     f=chisq;
 }
 
 // Double Mathieson
-void fcnS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
+void fcnS2(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
 {
     AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());    
     Int_t i;
@@ -1740,12 +2048,11 @@ void fcnS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
        qcont+=q1;
        qtot+=q0;
     }
-//    chisq=chisq+=(qtot-qcont)*(qtot-qcont)*0.5;
     f=chisq;
 }
 
 // Double Mathieson
-void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
+void fcnCombiS2(Int_t & /*npar*/, Double_t * /*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
 {
     AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());    
     Int_t i, cath;
@@ -1753,37 +2060,38 @@ void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t if
     Float_t chisq=0;
     Float_t qcont=0;
     Float_t qtot=0;
-    //    Float_t chi2temp=0;
-
     for (cath=0; cath<2; cath++) {
-//     chisq=0;
        for (i=0; i<clusterInput.Nmul(cath); i++) {
            Float_t q0=clusterInput.Charge(i,cath);
            Float_t q1=clusterInput.DiscrChargeCombiS2(i,par,cath);
-           //      delta=(q0-q1);
            delta=(q0-q1)/q0;
            chisq+=delta*delta;
            qcont+=q1;
            qtot+=q0;
        }
-//     if (cath == 0) chi2temp=chisq/clusterInput.Nbins[cath];
     }
-//    chisq = chisq/clusterInput.Nbins[1]+chi2temp;    
     f=chisq;
 }
 
-void AliMUONClusterFinderVS::AddRawCluster(const AliMUONRawCluster c)
+void AliMUONClusterFinderVS::AddRawCluster(const AliMUONRawCluster& c)
 {
   //
   // Add a raw cluster copy to the list
   //
-    AliMUON *pMUON=(AliMUON*)gAlice->GetModule("MUON");
-    pMUON->AddRawCluster(fInput->Chamber(),c); 
-    fNRawClusters++;
-    fprintf(stderr,"\nfNRawClusters %d\n",fNRawClusters);
+
+//     AliMUON *pMUON=(AliMUON*)gAlice->GetModule("MUON");
+//     pMUON->GetMUONData()->AddRawCluster(fInput->Chamber(),c); 
+//     fNRawClusters++;
+
+  
+    TClonesArray &lrawcl = *fRawClusters;
+    new(lrawcl[fNRawClusters++]) AliMUONRawCluster(c);
+    if (fDebugLevel)
+       fprintf(stderr,"\nfNRawClusters %d\n",fNRawClusters);
 }
 
-Bool_t AliMUONClusterFinderVS::TestTrack(Int_t t) {
+Bool_t AliMUONClusterFinderVS::TestTrack(Int_t t) const {
+// Test if track was user selected
     if (fTrack[0]==-1 || fTrack[1]==-1) {
        return kTRUE;
     } else if (t==fTrack[0] || t==fTrack[1]) {
@@ -1796,8 +2104,13 @@ Bool_t AliMUONClusterFinderVS::TestTrack(Int_t t) {
 AliMUONClusterFinderVS& AliMUONClusterFinderVS
 ::operator = (const AliMUONClusterFinderVS& rhs)
 {
-// Dummy assignment operator
-    return *this;
+// Protected assignement operator
+
+  if (this == &rhs) return *this;
+
+  Fatal("operator=", "Not implemented.");
+    
+  return *this;  
 }