]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONClusterFinderVS.cxx
Clean-up of coding rule violations.
[u/mrichter/AliRoot.git] / MUON / AliMUONClusterFinderVS.cxx
index 6f943dd22f3d8c7cfce12ee8a2de9bedc70a01e4..fd8df7c46082003f787d6b4db9b8675e58cb22d7 100644 (file)
  **************************************************************************/
 /*
 $Log$
+Revision 1.14  2000/10/23 16:03:45  morsch
+Correct z-position of all clusters created "on the flight".
+
+Revision 1.13  2000/10/23 13:38:23  morsch
+Set correct z-coordinate when cluster is split.
+
+Revision 1.12  2000/10/18 11:42:06  morsch
+- AliMUONRawCluster contains z-position.
+- Some clean-up of useless print statements during initialisations.
+
+Revision 1.11  2000/10/06 09:04:05  morsch
+- Dummy z-arguments in GetPadI, SetHit, FirstPad replaced by real z-coordinate
+       to make code work with slat chambers (AM)
+- Replace GetPadI calls with unchecked x,y coordinates by pad iterator calls wherever possible.
+
+Revision 1.10  2000/10/03 13:51:57  egangler
+Removal of useless dependencies via forward declarations
+
+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)
@@ -43,9 +95,9 @@ Revised and extended SplitByLocalMaxima method (Isabelle Chevrot):
 #include "AliMUONClusterFinderVS.h"
 #include "AliMUONDigit.h"
 #include "AliMUONRawCluster.h"
-#include "AliMUONSegmentation.h"
+#include "AliSegmentation.h"
 #include "AliMUONResponse.h"
-#include "AliMUONHitMap.h"
+#include "AliMUONClusterInput.h"
 #include "AliMUONHitMapA1.h"
 #include "AliRun.h"
 #include "AliMUON.h"
@@ -57,20 +109,12 @@ Revised and extended SplitByLocalMaxima method (Isabelle Chevrot):
 #include <TGraph.h> 
 #include <TPostScript.h> 
 #include <TMinuit.h> 
+#include <TF1.h>
+
 #include <stdio.h>
 #include <iostream.h>
 
 //_____________________________________________________________________
-static AliMUONSegmentation* fgSegmentation[2];
-static AliMUONResponse*     fgResponse;
-static Int_t                fgix[500][2];
-static Int_t                fgiy[500][2];
-static Float_t              fgCharge[500][2];
-static Int_t                fgNbins[2];
-static Int_t                fgFirst=kTRUE;
-static Int_t                fgChargeTot[2];
-static Float_t              fgQtot[2];
-static TMinuit*             fgMyMinuit ;
 // This function is minimized in the double-Mathieson fit
 void fcnS2(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);
@@ -79,30 +123,12 @@ void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t if
 
 ClassImp(AliMUONClusterFinderVS)
 
-    AliMUONClusterFinderVS::AliMUONClusterFinderVS
-(AliMUONSegmentation *seg1, AliMUONSegmentation *seg2,
- AliMUONResponse *response, 
- TClonesArray *digits1, TClonesArray *digits2, 
- Int_t chamber)   
-    :AliMUONClusterFinder(seg1, response, digits1, chamber)
-{
-// Constructor
-    fSegmentation2=seg2;
-    fDigits2=digits2;
-    fNdigits2 = fDigits2->GetEntriesFast();
-    fHitMap2=0;
-    fTrack[0]=fTrack[1]=-1;
-    
-}
-
     AliMUONClusterFinderVS::AliMUONClusterFinderVS()
-       :AliMUONClusterFinder()
 {
 // Default constructor
-    fSegmentation2=0;
-    fDigits2=0;
-    fNdigits2 = 0;
-    fHitMap2 = 0;
+    fInput=AliMUONClusterInput::Instance();
+    fHitMap[0] = 0;
+    fHitMap[1] = 0;
     fTrack[0]=fTrack[1]=-1;
 }
 
@@ -113,43 +139,6 @@ AliMUONClusterFinderVS::AliMUONClusterFinderVS(
     ;
 }
 
-void AliMUONClusterFinderVS::SetDigits(TClonesArray *MUONdigits1, TClonesArray *MUONdigits2) {
-// Set pointers to digit lists 
-
-    fDigits=MUONdigits1;
-    fNdigits = fDigits->GetEntriesFast();
-    fDigits2=MUONdigits2;
-    fNdigits2 = fDigits2->GetEntriesFast();
-}
-
-// Get Segmentation
-AliMUONSegmentation*  AliMUONClusterFinderVS::Segmentation(Int_t i)
-{
-// Return pointer to segmentation of cathode plane number 1 (i=0) or 2 (i=1)
-    return ((i==0)? fSegmentation : fSegmentation2);
-}
-
-// Get Number of Digits
-Int_t   AliMUONClusterFinderVS::NDigits(Int_t i)
-{
-// Return number of digits for cathode plane i+1
-    return ((i==0)? fNdigits : fNdigits2);
-}
-
-// Get Digits
-TClonesArray*  AliMUONClusterFinderVS::Digits(Int_t i)
-{
-// Return pointer to digits for cathode plane i+1
-    return ((i==0)? fDigits : fDigits2);
-}
-    
-
-AliMUONHitMap*   AliMUONClusterFinderVS::HitMap(Int_t i)
-{
-// Return pointer to  HitMap
-    return ((i==0)? fHitMap : fHitMap2);
-}
-
 void AliMUONClusterFinderVS::Decluster(AliMUONRawCluster *cluster)
 {
 // Decluster by local maxima
@@ -159,20 +148,17 @@ void AliMUONClusterFinderVS::Decluster(AliMUONRawCluster *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];
 
 //
 //  dump digit information into arrays
 //
-    fgSegmentation[0]=Segmentation(0);
-    fgSegmentation[1]=Segmentation(1);
-    fgResponse    =fResponse;
-    fgNbins[0]=fMul[0];
-    fgNbins[1]=fMul[1];
+
     Float_t qtot;
     
     for (cath=0; cath<2; cath++) {
@@ -180,25 +166,16 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
        for (i=0; i<fMul[cath]; i++)
        {
            // pointer to digit
-           fDig[i][cath]=(AliMUONDigit*)
-               (Digits(cath)->UncheckedAt(c->fIndexMap[i][cath]));
+           fDig[i][cath]=fInput->Digit(cath, c->fIndexMap[i][cath]);
            // pad coordinates
            fIx[i][cath]= fDig[i][cath]->fPadX;
            fIy[i][cath]= fDig[i][cath]->fPadY;
            // pad charge
            fQ[i][cath] = fDig[i][cath]->fSignal;
            // pad centre coordinates
-           Segmentation(cath)->
-               GetPadCxy(fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath]);
-            // globals kUsed in fitting functions
-           fgix[i][cath]=fIx[i][cath];
-           fgiy[i][cath]=fIy[i][cath];
-           fgCharge[i][cath]=Float_t(fQ[i][cath]);
-           // total charge per cluster
-           qtot+=fgCharge[i][cath];
+           fSeg[cath]->
+               GetPadC(fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath], fZ[i][cath]);
        } // loop over cluster digits
-       fgQtot[cath]=qtot;
-       fgChargeTot[cath]=Int_t(qtot);  
     }  // loop over cathodes
 
 
@@ -245,8 +222,8 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
        c->fY[1]=fYFit[0];
        c->fChi2[0]=chi2;
        c->fChi2[1]=chi2;
-       c->fX[0]=Segmentation(0)->GetAnod(c->fX[0]);
-       c->fX[1]=Segmentation(1)->GetAnod(c->fX[1]);
+       c->fX[0]=fSeg[0]->GetAnod(c->fX[0]);
+       c->fX[1]=fSeg[1]->GetAnod(c->fX[1]);
        
 // If reasonable chi^2 add result to the list of rawclusters
        //      if (chi2 < 50) {
@@ -338,12 +315,12 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
        for (ico=0; ico<4; ico++) {
            accepted[ico]=kFALSE;
 // cathode one: x-coordinate
-           isec=Segmentation(0)->Sector(ixm[ico][0], iym[ico][0]);
-           dpx=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=Segmentation(1)->Sector(ixm[ico][1], iym[ico][1]);
-           dpy=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)) {
@@ -468,16 +445,18 @@ 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.fX[cath]=Float_t(xm[ico][1]);
+                               cnew.fY[cath]=Float_t(ym[ico][0]);
+                               cnew.fZ[cath]=fZPlane;
+                               
+                               cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
                                for (i=0; i<fMul[cath]; i++) {
-                                 cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
-                                 fgSegmentation[cath]->SetPad(fgix[i][cath], fgiy[i][cath]);
+                                   cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
+                                   fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
                                }
-                             fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
-                             fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
-                             FillCluster(&cnew,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();
                            AddRawCluster(cnew);
@@ -487,90 +466,90 @@ 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 ((accepted[0]&&accepted[1]) || (accepted[2]&&accepted[3])) {
+               fprintf(stderr,"\n Maximum taken twice !!!\n");
 
 // Have a try !! with that 
-                   if (accepted[0]&&accepted[3]) {
-                       fXInit[0]=xm[0][1];
-                       fYInit[0]=ym[0][0];
-                       fXInit[1]=xm[1][1];
-                       fYInit[1]=ym[1][0];
-                   } else {
-                       fXInit[0]=xm[2][1];
-                       fYInit[0]=ym[2][0];
-                       fXInit[1]=xm[3][1];
-                       fYInit[1]=ym[3][0];
-                   }
-                   fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
-                   chi2=CombiDoubleMathiesonFit(c);
+               if (accepted[0]&&accepted[3]) {
+                   fXInit[0]=xm[0][1];
+                   fYInit[0]=ym[0][0];
+                   fXInit[1]=xm[1][1];
+                   fYInit[1]=ym[1][0];
+               } else {
+                   fXInit[0]=xm[2][1];
+                   fYInit[0]=ym[2][0];
+                   fXInit[1]=xm[3][1];
+                   fYInit[1]=ym[3][0];
+               }
+               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);
-                   Split(c);
-
-               } else {
+               Split(c);
+               
+           } else {
 // No ghosts ! No Problems ! -  Perform one fit only !
-                   if (accepted[0]&&accepted[3]) {
-                       fXInit[0]=xm[0][1];
-                       fYInit[0]=ym[0][0];
-                       fXInit[1]=xm[3][1];
-                       fYInit[1]=ym[3][0];
-                   } else {
-                       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");
-                   chi2=CombiDoubleMathiesonFit(c);
+               if (accepted[0]&&accepted[3]) {
+                   fXInit[0]=xm[0][1];
+                   fYInit[0]=ym[0][0];
+                   fXInit[1]=xm[3][1];
+                   fYInit[1]=ym[3][0];
+               } else {
+                   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");
+               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);
-               }
-
+               fprintf(stderr," chi2 %f\n",chi2);
+               Split(c);
+           }
+           
 // ******* iacc = 4 *******
 // Four combinations found between the 2 cathodes
 // Ghost !!
-           } else if (iacc==4) {
+       } else if (iacc==4) {
 // Perform fits for the two possibilities !!   
-               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");
-               chi2=CombiDoubleMathiesonFit(c);
+           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");
+           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);
-               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");
-               chi2=CombiDoubleMathiesonFit(c);
+           fprintf(stderr," chi2 %f\n",chi2);
+           Split(c);
+           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");
+           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);
-           }
+           fprintf(stderr," chi2 %f\n",chi2);
+           Split(c);
+       }
 
-       } else if (fNLocal[0]==2 &&  fNLocal[1]==1) {
+    } else if (fNLocal[0]==2 &&  fNLocal[1]==1) {
 //  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 //  (3) Two local maxima on cathode 1 and one maximum on cathode 2 
 //  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -584,16 +563,16 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //  0-0, 0-1, 1-0, 1-1 
         ico=0;
        for (im1=0; im1<2; im1++) {
-               xm[ico][0]=fX[fIndLocal[im1][0]][0];
-               ym[ico][0]=fY[fIndLocal[im1][0]][0];
-               xm[ico][1]=fX[fIndLocal[0][1]][1];
-               ym[ico][1]=fY[fIndLocal[0][1]][1];
-
-               ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
-               iym[ico][0]=fIy[fIndLocal[im1][0]][0];
-               ixm[ico][1]=fIx[fIndLocal[0][1]][1];
-               iym[ico][1]=fIy[fIndLocal[0][1]][1];
-               ico++;
+           xm[ico][0]=fX[fIndLocal[im1][0]][0];
+           ym[ico][0]=fY[fIndLocal[im1][0]][0];
+           xm[ico][1]=fX[fIndLocal[0][1]][1];
+           ym[ico][1]=fY[fIndLocal[0][1]][1];
+           
+           ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
+           iym[ico][0]=fIy[fIndLocal[im1][0]][0];
+           ixm[ico][1]=fIx[fIndLocal[0][1]][1];
+           iym[ico][1]=fIy[fIndLocal[0][1]][1];
+           ico++;
        }
 // ico = 0 : first local maximum on cathodes 1 and 2
 // ico = 1 : second local maximum on cathode 1 and first on cathode 2
@@ -606,11 +585,11 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
        
        for (ico=0; ico<2; ico++) {
            accepted[ico]=kFALSE;
-           isec=Segmentation(0)->Sector(ixm[ico][0], iym[ico][0]);
-           dpx=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=Segmentation(1)->Sector(ixm[ico][1], iym[ico][1]);
-           dpy=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)) {
@@ -622,10 +601,10 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                accepted[ico]=kFALSE;
            }
        }
-
+       
        Float_t chi21 = 100;
        Float_t chi22 = 100;
-
+       
        if (accepted[0]) {
            fXInit[0]=xm[0][1];
            fYInit[0]=ym[0][0];
@@ -661,10 +640,11 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                    for (cath=0; cath<2; cath++) {
                        cnew.fX[cath]=Float_t(xm[ico][1]);
                        cnew.fY[cath]=Float_t(ym[ico][0]);
+                       cnew.fZ[cath]=fZPlane;
                        cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
                        for (i=0; i<fMul[cath]; i++) {
-                         cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
-                         fgSegmentation[cath]->SetPad(fgix[i][cath], fgiy[i][cath]);
+                           cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
+                           fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
                        }
                        fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
                        fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
@@ -676,12 +656,12 @@ 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];
@@ -691,16 +671,16 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 //  0-0, 0-1, 1-0, 1-1 
         ico=0;
        for (im1=0; im1<2; im1++) {
-               xm[ico][0]=fX[fIndLocal[0][0]][0];
-               ym[ico][0]=fY[fIndLocal[0][0]][0];
-               xm[ico][1]=fX[fIndLocal[im1][1]][1];
-               ym[ico][1]=fY[fIndLocal[im1][1]][1];
-
-               ixm[ico][0]=fIx[fIndLocal[0][0]][0];
-               iym[ico][0]=fIy[fIndLocal[0][0]][0];
-               ixm[ico][1]=fIx[fIndLocal[im1][1]][1];
-               iym[ico][1]=fIy[fIndLocal[im1][1]][1];
-               ico++;
+           xm[ico][0]=fX[fIndLocal[0][0]][0];
+           ym[ico][0]=fY[fIndLocal[0][0]][0];
+           xm[ico][1]=fX[fIndLocal[im1][1]][1];
+           ym[ico][1]=fY[fIndLocal[im1][1]][1];
+           
+           ixm[ico][0]=fIx[fIndLocal[0][0]][0];
+           iym[ico][0]=fIy[fIndLocal[0][0]][0];
+           ixm[ico][1]=fIx[fIndLocal[im1][1]][1];
+           iym[ico][1]=fIy[fIndLocal[im1][1]][1];
+           ico++;
        }
 // ico = 0 : first local maximum on cathodes 1 and 2
 // ico = 1 : first local maximum on cathode 1 and second on cathode 2
@@ -713,11 +693,11 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
        
        for (ico=0; ico<2; ico++) {
            accepted[ico]=kFALSE;
-           isec=Segmentation(0)->Sector(ixm[ico][0], iym[ico][0]);
-           dpx=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=Segmentation(1)->Sector(ixm[ico][1], iym[ico][1]);
-           dpy=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)) {
@@ -769,10 +749,11 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                    for (cath=0; cath<2; cath++) {
                        cnew.fX[cath]=Float_t(xm[ico][1]);
                        cnew.fY[cath]=Float_t(ym[ico][0]);
+                       cnew.fZ[cath]=fZPlane;
                        cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
                        for (i=0; i<fMul[cath]; i++) {
-                         cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
-                         fgSegmentation[cath]->SetPad(fgix[i][cath], fgiy[i][cath]);
+                           cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
+                           fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
                        }
                        fprintf(stderr,"\nRawCluster %d cath %d\n",ico,cath);
                        fprintf(stderr,"mult_av %d\n",c->fMultiplicity[cath]);
@@ -792,7 +773,7 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
        
        Int_t param = fNLocal[0]*fNLocal[1];
        Int_t ii;
-       
+
        Float_t ** xm = new Float_t * [param];
        for (ii=0; ii<param; ii++) xm[ii]=new Float_t [2];
        Float_t ** ym = new Float_t * [param];
@@ -820,17 +801,17 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                ico++;
            }
        }
-
+       
        Int_t nIco = ico;
-
+       
        fprintf(stderr,"nIco %d\n",nIco);
        for (ico=0; ico<nIco; ico++) {
            fprintf(stderr,"ico = %d\n",ico);
-           isec=Segmentation(0)->Sector(ixm[ico][0], iym[ico][0]);
-           dpx=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=Segmentation(1)->Sector(ixm[ico][1], iym[ico][1]);
-           dpy=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);
@@ -842,10 +823,11 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                for (cath=0; cath<2; cath++) {
                    cnew.fX[cath]=Float_t(xm[ico][1]);
                    cnew.fY[cath]=Float_t(ym[ico][0]);
+                   cnew.fZ[cath]=fZPlane;
                    cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
                    for (i=0; i<fMul[cath]; i++) {
-                     cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
-                     fgSegmentation[cath]->SetPad(fgix[i][cath], fgiy[i][cath]);
+                       cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
+                       fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
                    }
                    FillCluster(&cnew,cath);
                } 
@@ -864,7 +846,8 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
 {
 // Find all local maxima of a cluster
-   
+    printf("\n Find Local maxima  !");
+    
     AliMUONDigit* digt;
     
     Int_t cath, cath1; // loops over cathodes
@@ -882,23 +865,23 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
     }
 //  number of next neighbours and arrays to store them 
     Int_t nn;
-    Int_t x[kMaxNeighbours], y[kMaxNeighbours];
+    Int_t x[10], y[10];
 // loop over cathodes
     for (cath=0; cath<2; cath++) {
 // loop over cluster digits
        for (i=0; i<fMul[cath]; i++) {
 // get neighbours for that digit and assume that it is local maximum       
-           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= Segmentation(cath)->Sector(fIx[i][cath], fIy[i][cath]);
-           Float_t a0 = Segmentation(cath)->Dpx(isec)*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 (HitMap(cath)->TestHit(x[j], y[j])==kEmpty) continue;
-               digt=(AliMUONDigit*) HitMap(cath)->GetHit(x[j], y[j]);
-               isec=Segmentation(cath)->Sector(x[j], y[j]);
-               Float_t a1 = Segmentation(cath)->Dpx(isec)*Segmentation(cath)->Dpy(isec);
+               if (fHitMap[cath]->TestHit(x[j], y[j])==kEmpty) continue;
+               digt=(AliMUONDigit*) fHitMap[cath]->GetHit(x[j], y[j]);
+               isec=fSeg[cath]->Sector(x[j], y[j]);
+               Float_t a1 = fSeg[cath]->Dpx(isec)*fSeg[cath]->Dpy(isec);
                if (digt->fSignal/a1 > fQ[i][cath]/a0) {
                    isLocal[i][cath]=kFALSE;
                    break;
@@ -942,9 +925,9 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
        cath1=1;
        
        for (i=0; i<fMul[cath]; i++) {
-           isec=Segmentation(cath)->Sector(fIx[i][cath],fIy[i][cath]);
-           dpy=Segmentation(cath)->Dpy(isec);
-           dpx=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.) && 
@@ -954,20 +937,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
-           Segmentation(cath)->GetPadIxy(fX[i][cath],fY[i][cath]+dpy,ix,iy);
 // iNN counts the number of neighbours with signal, it should be 1 or 2
            Int_t iNN=0;
-           if (HitMap(cath)->TestHit(ix, iy)!=kEmpty) {
-               iNN++;
-               digt=(AliMUONDigit*) HitMap(cath)->GetHit(ix,iy);
-               if (digt->fSignal > fQ[i][cath]) isLocal[i][cath]=kFALSE;
-           }
-           Segmentation(cath)->GetPadIxy(fX[i][cath],fY[i][cath]-dpy,ix,iy);
-           if (HitMap(cath)->TestHit(ix, iy)!=kEmpty) {
-               iNN++;
-               digt=(AliMUONDigit*) HitMap(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->fSignal > 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]++;
@@ -975,8 +965,12 @@ 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]);
+       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;
        }
@@ -990,14 +984,12 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
 //  Look for local maxima considering left and right neighbours on the 2nd cathode only
        cath=1;
        Int_t cath1=0;
-       
-
 //
 //  Loop over cluster digits
        for (i=0; i<fMul[cath]; i++) {
-           isec=Segmentation(cath)->Sector(fIx[i][cath],fIy[i][cath]);
-           dpx=Segmentation(cath)->Dpx(isec);
-           dpy=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.) && 
@@ -1007,20 +999,28 @@ 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
-           Segmentation(cath)->GetPadIxy(fX[i][cath]+dpx,fY[i][cath],ix,iy);
+
 // iNN counts the number of neighbours with signal, it should be 1 or 2
            Int_t iNN=0;
-           if (HitMap(cath)->TestHit(ix, iy)!=kEmpty) {
-               iNN++;
-               digt=(AliMUONDigit*) HitMap(cath)->GetHit(ix,iy);
-               if (digt->fSignal > fQ[i][cath]) isLocal[i][cath]=kFALSE;
-           }
-           Segmentation(cath)->GetPadIxy(fX[i][cath]-dpx,fY[i][cath],ix,iy);
-           if (HitMap(cath)->TestHit(ix, iy)!=kEmpty) {
-               iNN++;
-               digt=(AliMUONDigit*) HitMap(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., dpx);
+                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->fSignal > 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]++;
@@ -1034,9 +1034,6 @@ void AliMUONClusterFinderVS::FindLocalMaxima(AliMUONRawCluster* c)
        if (fNLocal[cath]>2) {
            fNLocal[cath]=iback;
        }
-
-
-
     } // 2,1 local maxima
 }
 
@@ -1047,7 +1044,7 @@ void  AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t flag, Int_
 //  Completes cluster information starting from list of digits
 //
     AliMUONDigit* dig;
-    Float_t x, y;
+    Float_t x, y, z;
     Int_t  ix, iy;
     
     if (cath==1) {
@@ -1066,7 +1063,7 @@ void  AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t flag, Int_
 //    fprintf(stderr,"\n fPeakSignal %d\n",c->fPeakSignal[cath]);
     for (Int_t i=0; i<c->fMultiplicity[cath]; i++)
     {
-       dig= (AliMUONDigit*)Digits(cath)->UncheckedAt(c->fIndexMap[i][cath]);
+       dig= fInput->Digit(cath,c->fIndexMap[i][cath]);
        ix=dig->fPadX+c->fOffsetMap[i][cath];
        iy=dig->fPadY;
        Int_t q=dig->fSignal;
@@ -1090,7 +1087,7 @@ void  AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t flag, Int_
        }
 //
        if (flag) {
-           Segmentation(cath)->GetPadCxy(ix, iy, x, y);
+           fSeg[cath]->GetPadC(ix, iy, x, y, z);
            c->fX[cath] += q*x;
            c->fY[cath] += q*y;
            c->fQ[cath] += q;
@@ -1101,20 +1098,20 @@ void  AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t flag, Int_
 
     if (flag) {
        c->fX[cath]/=c->fQ[cath];
-       c->fX[cath]=Segmentation(cath)->GetAnod(c->fX[cath]);
+       c->fX[cath]=fSeg[cath]->GetAnod(c->fX[cath]);
        c->fY[cath]/=c->fQ[cath]; 
 //
 //  apply correction to the coordinate along the anode wire
 //
        x=c->fX[cath];   
        y=c->fY[cath];
-       Segmentation(cath)->GetPadIxy(x, y, ix, iy);
-       Segmentation(cath)->GetPadCxy(ix, iy, x, y);
-       Int_t isec=Segmentation(cath)->Sector(ix,iy);
-       TF1* cogCorr = Segmentation(cath)->CorrFunc(isec-1);
+       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)/Segmentation(cath)->Dpy(isec);
+           Float_t yOnPad=(c->fY[cath]-y)/fSeg[cath]->Dpy(isec);
            c->fY[cath]=c->fY[cath]-cogCorr->Eval(yOnPad, 0, 0);
        }
     }
@@ -1133,14 +1130,14 @@ void  AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t cath)
        dr0 = 10000;
     }
     
-    Float_t xpad, ypad;
+    Float_t xpad, ypad, zpad;
     Float_t dx, dy, dr;
 
     for (Int_t i=0; i<c->fMultiplicity[cath]; i++)
     {
-      dig= (AliMUONDigit*)Digits(cath)->UncheckedAt(c->fIndexMap[i][cath]);
-      Segmentation(cath)->
-       GetPadCxy(dig->fPadX,dig->fPadY,xpad,ypad);
+       dig = fInput->Digit(cath,c->fIndexMap[i][cath]);
+       fSeg[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];
@@ -1165,22 +1162,25 @@ void  AliMUONClusterFinderVS::FillCluster(AliMUONRawCluster* c, Int_t cath)
     } // loop over digits
 
 //  apply correction to the coordinate along the anode wire
-    c->fX[cath]=Segmentation(cath)->GetAnod(c->fX[cath]);
+    c->fX[cath]=fSeg[cath]->GetAnod(c->fX[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 = HitMap(cath)->GetHitIndex(i,j);
-    AliMUONDigit* dig = (AliMUONDigit*) HitMap(cath)->GetHit(i,j);
+    
+    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;    
+    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;
@@ -1199,25 +1199,25 @@ void  AliMUONClusterFinderVS::FindCluster(Int_t i, Int_t j, Int_t cath, AliMUONR
     } 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--) {
+       for (Int_t ind = mu-1; ind >= 0; ind--) {
            Int_t ist=(c.fIndexMap)[ind][cath];
-           Int_t ql=((AliMUONDigit*)Digits(cath)
-                     ->UncheckedAt(ist))->fSignal;
-           Int_t ix=((AliMUONDigit*)Digits(cath)
-                     ->UncheckedAt(ist))->fPadX;
-           Int_t iy=((AliMUONDigit*)Digits(cath)
-                     ->UncheckedAt(ist))->fPadY;
-
+           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 (q>ql || (q==ql && theX > ix && theY < iy)) {
                c.fIndexMap[ind][cath]=idx;
                c.fIndexMap[ind+1][cath]=ist;
            } else {
+               
                break;
            }
        }
     }
-    
+
     c.fMultiplicity[cath]++;
     if (c.fMultiplicity[cath] >= 50 ) {
        printf("FindCluster - multiplicity >50  %d \n",c.fMultiplicity[0]);
@@ -1225,54 +1225,73 @@ void  AliMUONClusterFinderVS::FindCluster(Int_t i, Int_t j, Int_t cath, AliMUONR
     }
 
 // Prepare center of gravity calculation
-    Float_t x, y;
-    Segmentation(cath)->GetPadCxy(i, j, x, y);
-           
+    Float_t x, y, z;
+    fSeg[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  
-    HitMap(cath)->FlagHit(i,j);
+//
+// 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[kMaxNeighbours], yList[kMaxNeighbours];
-    Segmentation(cath)->Neighbours(i,j,&nn,xList,yList);
+    Int_t xList[10], yList[10];
+    fSeg[cath]->Neighbours(i,j,&nn,xList,yList);
     for (Int_t in=0; in<nn; in++) {
        ix=xList[in];
        iy=yList[in];
-       if (HitMap(cath)->TestHit(ix,iy)==kUnused) FindCluster(ix, iy, cath, c);
-    }
+       
+       if (fHitMap[cath]->TestHit(ix,iy)==kUnused) {
+//         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=Segmentation(cath)->Sector(i,j);    
+    Float_t dx, dy;
+
     if (cath==0) {
-       iop=1;
-       xmin=x-Segmentation(cath)->Dpx(isec);
-       xmax=x+Segmentation(cath)->Dpx(isec);
-       xc=xmin+.001;
-       while (xc < xmax) {
-           xc+=Segmentation(iop)->Dpx(isec);
-           Segmentation(iop)->GetPadIxy(xc,y,ix,iy);
-           if (ix>=(Segmentation(iop)->Npx()) || (iy>=Segmentation(iop)->Npy())) continue;
-           if (HitMap(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-Segmentation(cath)->Dpy(isec);
-       ymax=y+Segmentation(cath)->Dpy(isec);
-       yc=ymin+.001;
-       while (yc < ymax) {
-           yc+=Segmentation(iop)->Dpy(isec);
-           Segmentation(iop)->GetPadIxy(x,yc,ix,iy);
-           if (ix>=(Segmentation(iop)->Npx()) || (iy>=Segmentation(iop)->Npy())) continue;
-           if (HitMap(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();
+//         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;
+//         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);
     }
 }
 
@@ -1285,26 +1304,31 @@ void AliMUONClusterFinderVS::FindRawClusters()
   // fills the tree with raw clusters
   //
 
-    if (!NDigits(0) && !NDigits(1)) return;
+//  Return if no input datad available
+    if (!fInput->NDigits(0) && !fInput->NDigits(1)) return;
 
-    fHitMap  = new AliMUONHitMapA1(fSegmentation , fDigits);
-    fHitMap2 = new AliMUONHitMapA1(fSegmentation2, fDigits2);
+    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;
     Int_t nskip=0;
     Int_t ncls=0;
-    HitMap(0)->FillHits();
-    HitMap(1)->FillHits();
+    fHitMap[0]->FillHits();
+    fHitMap[1]->FillHits();
 //
 //  Outer Loop over Cathodes
     for (cath=0; cath<2; cath++) {
-       for (ndig=0; ndig<NDigits(cath); ndig++) {
-           dig = (AliMUONDigit*)Digits(cath)->UncheckedAt(ndig);
+       for (ndig=0; ndig<fInput->NDigits(cath); ndig++) {
+           dig = fInput->Digit(cath, ndig);
            Int_t i=dig->fPadX;
            Int_t j=dig->fPadY;
-           if (HitMap(cath)->TestHit(i,j)==kUsed ||fHitMap->TestHit(i,j)==kEmpty) {
+           if (fHitMap[cath]->TestHit(i,j)==kUsed ||fHitMap[0]->TestHit(i,j)==kEmpty) {
                nskip++;
                continue;
            }
@@ -1318,28 +1342,28 @@ void AliMUONClusterFinderVS::FindRawClusters()
            c.fTracks[2]=dig->fTracks[1];
            // tag the beginning of cluster list in a raw cluster
            c.fNcluster[0]=-1;
-
+           Float_t xcu, ycu;
+           fSeg[cath]->GetPadC(i,j,xcu, ycu, fZPlane);
+           fSector= fSeg[cath]->Sector(i,j)/100;
+//         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]=Segmentation(0)->GetAnod(c.fX[0]);
+           c.fX[0]=fSeg[0]->GetAnod(c.fX[0]);
            c.fY[0] /= c.fQ[0];
            c.fX[1] /= c.fQ[1];
-           c.fX[1]=Segmentation(0)->GetAnod(c.fX[1]);
+           c.fX[1]=fSeg[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;
            
-           fitted=SingleMathiesonFit(&c, 0);
-           c.fX[0]=Segmentation(0)->GetAnod(c.fX[0]);
-           fitted=SingleMathiesonFit(&c, 1);       
-           c.fX[1]=Segmentation(1)->GetAnod(c.fX[1]);
-*/ 
+           c.fZ[0] = fZPlane;
+           c.fZ[1] = fZPlane;      
+
+           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]);
 //
 //      Analyse cluster and decluster if necessary
 //     
@@ -1351,8 +1375,6 @@ void AliMUONClusterFinderVS::FindRawClusters()
 //
 //
        Decluster(&c);
-//     AddRawCluster(c);
-
 //
 //      reset Cluster object
        { // begin local scope
@@ -1368,51 +1390,21 @@ void AliMUONClusterFinderVS::FindRawClusters()
        
        } // end loop ndig
     } // end loop cathodes
-    delete fHitMap;
-    delete fHitMap2;
+    delete fHitMap[0];
+    delete fHitMap[1];
 }
 
 Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t cath)
 {
-//
-//  Initialise global variables for fit
-    Int_t i;
-    fMul[cath]=c->fMultiplicity[cath];
-    fgSegmentation[0]=Segmentation(cath);
-    fgResponse    =fResponse;
-    fgNbins[0]=fMul[cath];
-    Float_t qtot=0;
-//
-//  dump digit information into arrays
-//
-    for (i=0; i<fMul[cath]; i++)
-    {
-       fDig[i][cath]= (AliMUONDigit*)Digits(cath)->UncheckedAt(c->fIndexMap[i][cath]);
-       fIx[i][cath]= fDig[i][cath]->fPadX;
-       fIy[i][cath]= fDig[i][cath]->fPadY;
-       fQ[i][cath] = fDig[i][cath]->fSignal;
-       Segmentation(cath)->GetPadCxy(fIx[i][cath], fIy[i][cath], fX[i][cath], fY[i][cath]);
-       fgix[i][0]=fIx[i][cath];
-       fgiy[i][0]=fIy[i][cath];
-       fgCharge[i][0]=Float_t(fQ[i][cath]);
-       qtot+=fgCharge[i][0];
-    }
-
-    fgQtot[0]=qtot;
-    fgChargeTot[0]=Int_t(qtot);
+// Performs a single Mathieson fit on one cathode
+// 
+    AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
     
-//
-    if (fgFirst) {
-       fgFirst=kFALSE;
-       fgMyMinuit = new TMinuit(5);
-    }
-
-    fgMyMinuit->SetFCN(fcnS1);
-    fgMyMinuit->mninit(2,10,7);
+    clusterInput.Fitter()->SetFCN(fcnS1);
+    clusterInput.Fitter()->mninit(2,10,7);
     Double_t arglist[20];
     Int_t ierflag=0;
     arglist[0]=1;
-//     fgMyMinuit->mnexcm("SET ERR",arglist,1,ierflag);
 // Set starting values 
     static Double_t vstart[2];
     vstart[0]=c->fX[1];
@@ -1422,32 +1414,32 @@ Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t c
 // lower and upper limits
     static Double_t lower[2], upper[2];
     Int_t ix,iy;
-    Segmentation(cath)->GetPadIxy(c->fX[cath], c->fY[cath], ix, iy);
-    Int_t isec=Segmentation(cath)->Sector(ix, iy);
-    lower[0]=vstart[0]-Segmentation(cath)->Dpx(isec)/2;
-    lower[1]=vstart[1]-Segmentation(cath)->Dpy(isec)/2;
+    fSeg[cath]->GetPadI(c->fX[cath], c->fY[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]+Segmentation(cath)->Dpx(isec);
-    upper[1]=lower[1]+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};
     
-    fgMyMinuit->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
-    fgMyMinuit->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
+    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      
-    fgMyMinuit->SetPrintLevel(1);
-    fgMyMinuit->mnexcm("SET OUT", arglist, 0, ierflag);
+    clusterInput.Fitter()->SetPrintLevel(1);
+    clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
     arglist[0]= -1;
     arglist[1]= 0;
     
-    fgMyMinuit->mnexcm("SET NOGR", arglist, 0, ierflag);
-    fgMyMinuit->mnexcm("MIGRAD", arglist, 0, ierflag);
-    fgMyMinuit->mnexcm("EXIT" , arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
     Double_t fmin, fedm, errdef;
     Int_t   npari, nparx, istat;
       
-    fgMyMinuit->mnstat(fmin, fedm, errdef, npari, nparx, istat);  
+    clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);  
     fFitStat=istat;
     
 // Print results
@@ -1456,8 +1448,8 @@ Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t c
     TString chname;
     Double_t epxz, b1, b2;
     Int_t ierflg;
-    fgMyMinuit->mnpout(0, chname, xrec, epxz, b1, b2, ierflg); 
-    fgMyMinuit->mnpout(1, chname, yrec, epxz, b1, b2, ierflg); 
+    clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);      
+    clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);      
     fXFit[cath]=xrec;
     fYFit[cath]=yrec;
     return fmin;
@@ -1467,13 +1459,9 @@ Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster *c)
 {
 // Perform combined Mathieson fit on both cathode planes
 //
-    if (fgFirst) {
-       fgFirst=kFALSE;
-       fgMyMinuit = new TMinuit(5);
-    }
-
-    fgMyMinuit->SetFCN(fcnCombiS1);
-    fgMyMinuit->mninit(2,10,7);
+    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;
@@ -1483,40 +1471,66 @@ Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster *c)
     
     
 // lower and upper limits
-    static Double_t lower[2], upper[2];
+    static Float_t lower[2], upper[2];
     Int_t ix,iy,isec;
-    Segmentation(0)->GetPadIxy(fXInit[0], fYInit[0], ix, iy);
-    isec=Segmentation(0)->Sector(ix, iy);
-    Float_t dpy=Segmentation(0)->Dpy(isec)/2;
-    Segmentation(1)->GetPadIxy(fXInit[0], fYInit[0], ix, iy);
-    isec=Segmentation(1)->Sector(ix, iy);
-    Float_t dpx=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;
+    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++;
+       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};
     
-    fgMyMinuit->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
-    fgMyMinuit->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
+    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      
-    fgMyMinuit->SetPrintLevel(1);
-    fgMyMinuit->mnexcm("SET OUT", arglist, 0, ierflag);
+    clusterInput.Fitter()->SetPrintLevel(1);
+    clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
     arglist[0]= -1;
     arglist[1]= 0;
     
-    fgMyMinuit->mnexcm("SET NOGR", arglist, 0, ierflag);
-    fgMyMinuit->mnexcm("MIGRAD", arglist, 0, ierflag);
-    fgMyMinuit->mnexcm("EXIT" , arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
     Double_t fmin, fedm, errdef;
     Int_t   npari, nparx, istat;
       
-    fgMyMinuit->mnstat(fmin, fedm, errdef, npari, nparx, istat);  
+    clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);  
     fFitStat=istat;
     
 // Print results
@@ -1525,8 +1539,8 @@ Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster *c)
     TString chname;
     Double_t epxz, b1, b2;
     Int_t ierflg;
-    fgMyMinuit->mnpout(0, chname, xrec, epxz, b1, b2, ierflg); 
-    fgMyMinuit->mnpout(1, chname, yrec, epxz, b1, b2, ierflg); 
+    clusterInput.Fitter()->mnpout(0, chname, xrec, epxz, b1, b2, ierflg);      
+    clusterInput.Fitter()->mnpout(1, chname, yrec, epxz, b1, b2, ierflg);      
     fXFit[0]=xrec;
     fYFit[0]=yrec;
     return fmin;
@@ -1534,31 +1548,14 @@ Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster *c)
 
 Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster *c, Int_t cath)
 {
+// Performs a double Mathieson fit on one cathode
+// 
+
 //
 //  Initialise global variables for fit
-    Int_t i,j;
-    
-    fgSegmentation[0]=Segmentation(cath);
-    fgResponse    =fResponse;
-    fgNbins[0]=fMul[cath];
-    Float_t qtot=0;
-       
-    for (i=0; i<fMul[cath]; i++) {
-       fgix[i][0]=fIx[i][cath];
-       fgiy[i][0]=fIy[i][cath];
-       fgCharge[i][0]=Float_t(fQ[i][cath]);
-       qtot+=fgCharge[i][0];
-    }
-    fgQtot[0]=qtot;
-    fgChargeTot[0]=Int_t(qtot);
-    
-//
-    if (fgFirst) {
-       fgFirst=kFALSE;
-       fgMyMinuit = new TMinuit(5);
-    }
-    fgMyMinuit->SetFCN(fcnS2);
-    fgMyMinuit->mninit(5,10,7);
+    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;
@@ -1571,93 +1568,56 @@ 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=Segmentation(cath)->Sector(fIx[fIndLocal[0][cath]][cath], fIy[fIndLocal[0][cath]][cath]);
-    lower[0]=vstart[0]-Segmentation(cath)->Dpx(isec);
-    lower[1]=vstart[1]-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.*Segmentation(cath)->Dpx(isec);
-    upper[1]=lower[1]+2.*Segmentation(cath)->Dpy(isec);
+    upper[0]=lower[0]+2.*fSeg[cath]->Dpx(isec);
+    upper[1]=lower[1]+2.*fSeg[cath]->Dpy(isec);
     
-    isec=Segmentation(cath)->Sector(fIx[fIndLocal[1][cath]][cath], fIy[fIndLocal[1][cath]][cath]);
-    lower[2]=vstart[2]-Segmentation(cath)->Dpx(isec)/2;
-    lower[3]=vstart[3]-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]+Segmentation(cath)->Dpx(isec);
-    upper[3]=lower[3]+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.;
 // step sizes
     static Double_t step[5]={0.0005, 0.0005, 0.0005, 0.0005, 0.0001};
     
-    fgMyMinuit->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
-    fgMyMinuit->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
-    fgMyMinuit->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
-    fgMyMinuit->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
-    fgMyMinuit->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
+    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);
+    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      
-    fgMyMinuit->SetPrintLevel(-1);
-    fgMyMinuit->mnexcm("SET OUT", arglist, 0, ierflag);
+    clusterInput.Fitter()->SetPrintLevel(-1);
+    clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
     arglist[0]= -1;
     arglist[1]= 0;
     
-    fgMyMinuit->mnexcm("SET NOGR", arglist, 0, ierflag);
-    fgMyMinuit->mnexcm("MIGRAD", arglist, 0, ierflag);
-    fgMyMinuit->mnexcm("EXIT" , arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
 // Get fitted parameters
     Double_t xrec[2], yrec[2], qfrac;
     TString chname;
     Double_t epxz, b1, b2;
     Int_t ierflg;
-    fgMyMinuit->mnpout(0, chname, xrec[0], epxz, b1, b2, ierflg);      
-    fgMyMinuit->mnpout(1, chname, yrec[0], epxz, b1, b2, ierflg);      
-    fgMyMinuit->mnpout(2, chname, xrec[1], epxz, b1, b2, ierflg);      
-    fgMyMinuit->mnpout(3, chname, yrec[1], epxz, b1, b2, ierflg);      
-    fgMyMinuit->mnpout(4, chname, qfrac,   epxz, b1, b2, ierflg);      
+    clusterInput.Fitter()->mnpout(0, chname, xrec[0], epxz, b1, b2, ierflg);   
+    clusterInput.Fitter()->mnpout(1, chname, yrec[0], epxz, b1, b2, ierflg);   
+    clusterInput.Fitter()->mnpout(2, chname, xrec[1], epxz, b1, b2, ierflg);   
+    clusterInput.Fitter()->mnpout(3, chname, yrec[1], epxz, b1, b2, ierflg);   
+    clusterInput.Fitter()->mnpout(4, chname, qfrac,   epxz, b1, b2, ierflg);   
 
     Double_t fmin, fedm, errdef;
     Int_t   npari, nparx, istat;
       
-    fgMyMinuit->mnstat(fmin, fedm, errdef, npari, nparx, istat);  
+    clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);  
     fFitStat=istat;
-    
-    
-//
-// One cluster for each maximum
-//
-    for (j=0; j<2; j++) {
-       AliMUONRawCluster cnew;
-       cnew.fChi2[0]=Float_t(fmin);
-       
-       if (fNPeaks == 0) {
-           cnew.fNcluster[0]=-1;
-           cnew.fNcluster[1]=fNRawClusters;
-       } else {
-           cnew.fNcluster[0]=fNPeaks;
-           cnew.fNcluster[1]=0;
-       }
-       cnew.fMultiplicity[0]=0;
-       cnew.fX[0]=Float_t(xrec[j]);
-       cnew.fY[0]=Float_t(yrec[j]);
-       if (j==0) {
-           cnew.fQ[0]=Int_t(fgChargeTot[0]*qfrac);
-       } else {
-           cnew.fQ[0]=Int_t(fgChargeTot[0]*(1-qfrac));
-       }
-       fgSegmentation[0]->SetHit(xrec[j],yrec[j]);
-       for (i=0; i<fMul[cath]; i++) {
-           cnew.fIndexMap[cnew.fMultiplicity[0]][cath]=c->fIndexMap[i][cath];
-           fgSegmentation[0]->SetPad(fgix[i][0], fgiy[i][0]);
-           Float_t q1=fgResponse->IntXY(fgSegmentation[0]);
-           cnew.fContMap[cnew.fMultiplicity[0]][0]=(q1*cnew.fQ[0])/Float_t(fQ[i][cath]);
-           cnew.fMultiplicity[0]++;
-       }
-       FillCluster(&cnew,0,0);
-       cnew.fClusterType=cnew.PhysicsContribution();
-       AddRawCluster(cnew);
-       fNPeaks++;
-    }
     return kTRUE;
 }
 
@@ -1666,12 +1626,9 @@ Float_t AliMUONClusterFinderVS::CombiDoubleMathiesonFit(AliMUONRawCluster *c)
 //
 // Perform combined double Mathieson fit on both cathode planes
 //
-    if (fgFirst) {
-       fgFirst=kFALSE;
-       fgMyMinuit = new TMinuit(5);
-    }
-    fgMyMinuit->SetFCN(fcnCombiS2);
-    fgMyMinuit->mninit(6,10,7);
+    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;
@@ -1684,36 +1641,80 @@ 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;
     
-    Segmentation(1)->GetPadIxy(fXInit[0], fYInit[0], ix, iy);
-    isec=Segmentation(1)->Sector(ix, iy);
-    dpx=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);
 
-    Segmentation(0)->GetPadIxy(fXInit[0], fYInit[0], ix, iy);
-    isec=Segmentation(0)->Sector(ix, iy);
-    dpy=Segmentation(0)->Dpy(isec);
 
-    lower[0]=vstart[0]-dpx;
-    lower[1]=vstart[1]-dpy;
-    upper[0]=vstart[0]+dpx;
-    upper[1]=vstart[1]+dpy;
+    Int_t icount;
+    Float_t xdum, ydum, zdum;
+//    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();
+       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;
+    
+    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 (lower[1]>upper[1]) {xdum=lower[1]; lower[1]=upper[1]; upper[1]=xdum;}    
 
+    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);
 
-    Segmentation(1)->GetPadIxy(fXInit[1], fYInit[1], ix, iy);
-    isec=Segmentation(1)->Sector(ix, iy);
-    dpx=Segmentation(1)->Dpx(isec);
-    Segmentation(0)->GetPadIxy(fXInit[1], fYInit[1], ix, iy);
-    isec=Segmentation(0)->Sector(ix, iy);
-    dpy=Segmentation(0)->Dpy(isec);
 
-    lower[2]=vstart[2]-dpx;
-    lower[3]=vstart[3]-dpy;
-    upper[2]=vstart[2]+dpx;
-    upper[3]=vstart[3]+dpy;
+//  Find save upper and lower limits    
 
+    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();
+       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;}    
+
+    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();
+       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;}    
 
     lower[4]=0.;
     upper[4]=1.;
@@ -1722,37 +1723,36 @@ 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};
-    
-    fgMyMinuit->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
-    fgMyMinuit->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
-    fgMyMinuit->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
-    fgMyMinuit->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
-    fgMyMinuit->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
-    fgMyMinuit->mnparm(5,"a1",vstart[5],step[5],lower[5],upper[5],ierflag);
+    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);
+    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);
+    clusterInput.Fitter()->mnparm(5,"a1",vstart[5],step[5],lower[5],upper[5],ierflag);
 // ready for minimisation      
-    fgMyMinuit->SetPrintLevel(-1);
-    fgMyMinuit->mnexcm("SET OUT", arglist, 0, ierflag);
+    clusterInput.Fitter()->SetPrintLevel(-1);
+    clusterInput.Fitter()->mnexcm("SET OUT", arglist, 0, ierflag);
     arglist[0]= -1;
     arglist[1]= 0;
     
-    fgMyMinuit->mnexcm("SET NOGR", arglist, 0, ierflag);
-    fgMyMinuit->mnexcm("MIGRAD", arglist, 0, ierflag);
-    fgMyMinuit->mnexcm("EXIT" , arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("SET NOGR", arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("MIGRAD", arglist, 0, ierflag);
+    clusterInput.Fitter()->mnexcm("EXIT" , arglist, 0, ierflag);
 // Get fitted parameters
     TString chname;
     Double_t epxz, b1, b2;
     Int_t ierflg;
-    fgMyMinuit->mnpout(0, chname, fXFit[0],  epxz, b1, b2, ierflg);    
-    fgMyMinuit->mnpout(1, chname, fYFit[0],  epxz, b1, b2, ierflg);    
-    fgMyMinuit->mnpout(2, chname, fXFit[1],  epxz, b1, b2, ierflg);    
-    fgMyMinuit->mnpout(3, chname, fYFit[1],  epxz, b1, b2, ierflg);    
-    fgMyMinuit->mnpout(4, chname, fQrFit[0], epxz, b1, b2, ierflg);    
-    fgMyMinuit->mnpout(5, chname, fQrFit[1], epxz, b1, b2, ierflg);    
+    clusterInput.Fitter()->mnpout(0, chname, fXFit[0],  epxz, b1, b2, ierflg); 
+    clusterInput.Fitter()->mnpout(1, chname, fYFit[0],  epxz, b1, b2, ierflg); 
+    clusterInput.Fitter()->mnpout(2, chname, fXFit[1],  epxz, b1, b2, ierflg); 
+    clusterInput.Fitter()->mnpout(3, chname, fYFit[1],  epxz, b1, b2, ierflg); 
+    clusterInput.Fitter()->mnpout(4, chname, fQrFit[0], epxz, b1, b2, ierflg); 
+    clusterInput.Fitter()->mnpout(5, chname, fQrFit[1], epxz, b1, b2, ierflg); 
 
     Double_t fmin, fedm, errdef;
     Int_t   npari, nparx, istat;
       
-    fgMyMinuit->mnstat(fmin, fedm, errdef, npari, nparx, istat);  
+    clusterInput.Fitter()->mnstat(fmin, fedm, errdef, npari, nparx, istat);  
     fFitStat=istat;
     
     fChi2[0]=fmin;
@@ -1766,7 +1766,7 @@ void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
 // One cluster for each maximum
 //
     Int_t i, j, cath;
-    
+    AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());
     for (j=0; j<2; j++) {
        AliMUONRawCluster cnew;
        for (cath=0; cath<2; cath++) {
@@ -1782,21 +1782,21 @@ void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
            cnew.fMultiplicity[cath]=0;
            cnew.fX[cath]=Float_t(fXFit[j]);
            cnew.fY[cath]=Float_t(fYFit[j]);
+           cnew.fZ[cath]=fZPlane;
            if (j==0) {
-               cnew.fQ[cath]=Int_t(fgChargeTot[cath]*fQrFit[cath]);
+               cnew.fQ[cath]=Int_t(clusterInput.TotalCharge(cath)*fQrFit[cath]);
            } else {
-               cnew.fQ[cath]=Int_t(fgChargeTot[cath]*(1-fQrFit[cath]));
+               cnew.fQ[cath]=Int_t(clusterInput.TotalCharge(cath)*(1-fQrFit[cath]));
            }
-           fgSegmentation[cath]->SetHit(fXFit[j],fYFit[j]);
+           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];
-               fgSegmentation[cath]->SetPad(fgix[i][cath], fgiy[i][cath]);
-               Float_t q1=fgResponse->IntXY(fgSegmentation[cath]);
+               fSeg[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
+               Float_t q1=fInput->Response()->IntXY(fSeg[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]);
            }
            FillCluster(&cnew,0,cath);
        } // cathode loop
@@ -1808,97 +1808,21 @@ void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
 }
 
 
-Float_t DiscrChargeS1(Int_t i,Double_t *par) 
-{
-// par[0]    x-position of cluster
-// par[1]    y-position of cluster
-
-   fgSegmentation[0]->SetPad(fgix[i][0], fgiy[i][0]);
-//  First Cluster
-   fgSegmentation[0]->SetHit(par[0],par[1]);
-   Float_t q1=fgResponse->IntXY(fgSegmentation[0]);
-    
-   Float_t value = fgQtot[0]*q1;
-   return value;
-}
-
-Float_t DiscrChargeCombiS1(Int_t i,Double_t *par, Int_t cath) 
-{
-// par[0]    x-position of cluster
-// par[1]    y-position of cluster
-
-   fgSegmentation[cath]->SetPad(fgix[i][cath], fgiy[i][cath]);
-//  First Cluster
-   fgSegmentation[cath]->SetHit(par[0],par[1]);
-   Float_t q1=fgResponse->IntXY(fgSegmentation[cath]);
-    
-   Float_t value = fgQtot[cath]*q1;
-   return value;
-}
-
-
-Float_t DiscrChargeS2(Int_t i,Double_t *par) 
-{
-// par[0]    x-position of first  cluster
-// par[1]    y-position of first  cluster
-// par[2]    x-position of second cluster
-// par[3]    y-position of second cluster
-// par[4]    charge fraction of first  cluster
-// 1-par[4]  charge fraction of second cluster
-
-   fgSegmentation[0]->SetPad(fgix[i][0], fgiy[i][0]);
-//  First Cluster
-   fgSegmentation[0]->SetHit(par[0],par[1]);
-   Float_t q1=fgResponse->IntXY(fgSegmentation[0]);
-    
-//  Second Cluster
-   fgSegmentation[0]->SetHit(par[2],par[3]);
-   Float_t q2=fgResponse->IntXY(fgSegmentation[0]);
-    
-   Float_t value = fgQtot[0]*(par[4]*q1+(1.-par[4])*q2);
-   return value;
-}
-
-Float_t DiscrChargeCombiS2(Int_t i,Double_t *par, Int_t cath) 
-{
-// par[0]    x-position of first  cluster
-// par[1]    y-position of first  cluster
-// par[2]    x-position of second cluster
-// par[3]    y-position of second cluster
-// par[4]    charge fraction of first  cluster
-// 1-par[4]  charge fraction of second cluster
-
-   fgSegmentation[cath]->SetPad(fgix[i][cath], fgiy[i][cath]);
-//  First Cluster
-   fgSegmentation[cath]->SetHit(par[0],par[1]);
-   Float_t q1=fgResponse->IntXY(fgSegmentation[cath]);
-    
-//  Second Cluster
-   fgSegmentation[cath]->SetHit(par[2],par[3]);
-   Float_t q2=fgResponse->IntXY(fgSegmentation[cath]);
-   Float_t value;
-   if (cath==0) {
-       value = fgQtot[0]*(par[4]*q1+(1.-par[4])*q2);
-   } else {
-       value = fgQtot[1]*(par[5]*q1+(1.-par[5])*q2);
-   }
-   return value;
-}
-
 //
 // Minimisation functions
 // Single Mathieson
 void fcnS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
 {
+    AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());    
     Int_t i;
     Float_t delta;
     Float_t chisq=0;
     Float_t qcont=0;
     Float_t qtot=0;
-    
-    for (i=0; i<fgNbins[0]; i++) {
-       Float_t q0=fgCharge[i][0];
-       Float_t q1=DiscrChargeS1(i,par);
+
+    for (i=0; i<clusterInput.Nmul(0); i++) {
+       Float_t q0=clusterInput.Charge(i,0);
+       Float_t q1=clusterInput.DiscrChargeS1(i,par);
        delta=(q0-q1)/q0;
        chisq+=delta*delta;
        qcont+=q1;
@@ -1909,91 +1833,91 @@ void fcnS1(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;
     Float_t delta;
     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<fgNbins[cath]; i++) {
-           Float_t q0=fgCharge[i][cath];
-           Float_t q1=DiscrChargeCombiS1(i,par,cath);
-           //      delta=(q0-q1);
+       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)/q0;
            chisq+=delta*delta;
            qcont+=q1;
            qtot+=q0;
        }
-//     if (cath == 0) chi2temp=chisq/fgNbins[cath];
     }
-//    chisq = chisq/fgNbins[1]+chi2temp; 
-    
     f=chisq;
 }
 
 // Double Mathieson
 void fcnS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
 {
+    AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());    
     Int_t i;
     Float_t delta;
     Float_t chisq=0;
     Float_t qcont=0;
     Float_t qtot=0;
     
-    for (i=0; i<fgNbins[0]; i++) {
+    for (i=0; i<clusterInput.Nmul(0); i++) {
 
-       Float_t q0=fgCharge[i][0];
-       Float_t q1=DiscrChargeS2(i,par);
+       Float_t q0=clusterInput.Charge(i,0);
+       Float_t q1=clusterInput.DiscrChargeS2(i,par);
        delta=(q0-q1)/q0;
        chisq+=delta*delta;
        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)
 {
+    AliMUONClusterInput& clusterInput = *(AliMUONClusterInput::Instance());    
     Int_t i, cath;
     Float_t delta;
     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<fgNbins[cath]; i++) {
-           Float_t q0=fgCharge[i][cath];
-           Float_t q1=DiscrChargeCombiS2(i,par,cath);
-           //      delta=(q0-q1);
+       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)/q0;
            chisq+=delta*delta;
            qcont+=q1;
            qtot+=q0;
        }
-//     if (cath == 0) chi2temp=chisq/fgNbins[cath];
     }
-//    chisq = chisq/fgNbins[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(fChamber,c); 
+    pMUON->AddRawCluster(fInput->Chamber(),c); 
     fNRawClusters++;
     fprintf(stderr,"\nfNRawClusters %d\n",fNRawClusters);
 }
 
+Bool_t AliMUONClusterFinderVS::TestTrack(Int_t t) {
+// Test if track was user selected
+    if (fTrack[0]==-1 || fTrack[1]==-1) {
+       return kTRUE;
+    } else if (t==fTrack[0] || t==fTrack[1]) {
+       return kTRUE;
+    } else {
+       return kFALSE;
+    }
+}
 
 AliMUONClusterFinderVS& AliMUONClusterFinderVS
 ::operator = (const AliMUONClusterFinderVS& rhs)