Avoid global variables in AliMUONClusterFinderVS by seperating the input data for...
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 28 Jun 2000 08:06:10 +0000 (08:06 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 28 Jun 2000 08:06:10 +0000 (08:06 +0000)
algorithmic part of the class. Input data resides inside the AliMUONClusterInput singleton.
It also naturally takes care of the TMinuit instance.

MUON/AliMUON.cxx
MUON/AliMUONClusterFinder.cxx
MUON/AliMUONClusterFinder.h
MUON/AliMUONClusterFinderVS.cxx
MUON/AliMUONClusterFinderVS.h
MUON/AliMUONClusterInput.cxx [new file with mode: 0644]
MUON/AliMUONClusterInput.h [new file with mode: 0644]

index 15214da61ed58f5a905333126976118f1ed6165e..6c4772b823c8715b480506e21715e097b6657749 100644 (file)
@@ -14,6 +14,9 @@
  **************************************************************************/
 /*
 $Log$
+Revision 1.21  2000/06/27 08:54:41  morsch
+Problems with on constant array sizes (in hitMap, nmuon, xhit, yhit) corrected.
+
 Revision 1.20  2000/06/26 14:02:38  morsch
 Add class AliMUONConstants with MUON specific constants using static memeber data and access methods.
 
@@ -123,6 +126,7 @@ Log message added
 #include "AliMUONTriggerDecision.h"
 #include "AliRun.h"
 #include "AliMC.h"
+#include "AliMUONClusterInput.h"
 #include "iostream.h"
 #include "AliCallf77.h" 
 #include "AliConst.h" 
@@ -1409,7 +1413,9 @@ void AliMUON::FindClusters(Int_t nev,Int_t lastEntry)
            new(lhits2[n++]) AliMUONDigit(*digit);
        }
 
-       if (rec) {        
+       if (rec) {       
+           AliMUONClusterInput::Instance()->SetDigits(ich, dig1, dig2);
+           
            rec->SetDigits(dig1, dig2);
            rec->SetChamber(ich);
            rec->FindRawClusters();
index 430946beaac8f65d7dc5f97aab965855ee1ae889..d8738c76def7409be4ca3f6f2375eb636efd7fc7 100644 (file)
@@ -15,6 +15,9 @@
 
 /*
 $Log$
+Revision 1.5  2000/06/15 07:58:48  morsch
+Code from MUON-dev joined
+
 Revision 1.4.4.2  2000/06/09 21:58:15  morsch
 Most coding rule violations corrected.
 
@@ -66,7 +69,7 @@ ClassImp(AliMUONClusterFinder)
        TClonesArray *digits, Int_t chamber)   
 {
 // Constructor    
-    fSegmentation=segmentation;
+    fSegmentation[0]=segmentation;
     fResponse=response;
     
     fDigits=digits;
@@ -84,7 +87,7 @@ ClassImp(AliMUONClusterFinder)
     AliMUONClusterFinder::AliMUONClusterFinder()
 {
 // Default constructor
-    fSegmentation=0;
+    fSegmentation[0]=0;
     fResponse=0;
     fDigits=0;
     fNdigits = 0;
@@ -200,7 +203,7 @@ Bool_t AliMUONClusterFinder::Centered(AliMUONRawCluster *cluster)
     Int_t nn;
     Int_t x[kMaxNeighbours], y[kMaxNeighbours], xN[kMaxNeighbours], yN[kMaxNeighbours];
     
-    fSegmentation->Neighbours(ix,iy,&nn,x,y);
+    fSegmentation[0]->Neighbours(ix,iy,&nn,x,y);
     Int_t nd=0;
     for (Int_t i=0; i<nn; i++) {
        if (fHitMap->TestHit(x[i],y[i]) == kUsed) {
@@ -284,7 +287,7 @@ void AliMUONClusterFinder::SplitByLocalMaxima(AliMUONRawCluster *c)
        fIx[i]= fDig[i]->fPadX;
        fIy[i]= fDig[i]->fPadY;
        fQ[i] = fDig[i]->fSignal;
-       fSegmentation->GetPadCxy(fIx[i], fIy[i], fX[i], fY[i]);
+       fSegmentation[0]->GetPadCxy(fIx[i], fIy[i], fX[i], fY[i]);
     }
 //
 //  Find local maxima
@@ -295,7 +298,7 @@ void AliMUONClusterFinder::SplitByLocalMaxima(AliMUONRawCluster *c)
     Int_t nn;
     Int_t x[kMaxNeighbours], y[kMaxNeighbours];
     for (i=0; i<fMul; i++) {
-       fSegmentation->Neighbours(fIx[i], fIy[i], &nn, x, y);
+       fSegmentation[0]->Neighbours(fIx[i], fIy[i], &nn, x, y);
        isLocal[i]=kTRUE;
        for (j=0; j<nn; j++) {
            if (fHitMap->TestHit(x[j], y[j])==kEmpty) continue;
@@ -484,7 +487,7 @@ void  AliMUONClusterFinder::FillCluster(AliMUONRawCluster* c, Int_t flag)
        }
 //
        if (flag) {
-           fSegmentation->GetPadCxy(ix, iy, x, y);
+           fSegmentation[0]->GetPadCxy(ix, iy, x, y);
            c->fX[0] += q*x;
            c->fY[0] += q*y;
            c->fQ[0] += q;
@@ -493,20 +496,20 @@ void  AliMUONClusterFinder::FillCluster(AliMUONRawCluster* c, Int_t flag)
     
     if (flag) {
        c->fX[0]/=c->fQ[0];
-       c->fX[0]=fSegmentation->GetAnod(c->fX[0]);
+       c->fX[0]=fSegmentation[0]->GetAnod(c->fX[0]);
        c->fY[0]/=c->fQ[0]; 
 //
 //  apply correction to the coordinate along the anode wire
 //
        x=c->fX[0];   
        y=c->fY[0];
-       fSegmentation->GetPadIxy(x, y, ix, iy);
-       fSegmentation->GetPadCxy(ix, iy, x, y);
-       Int_t isec=fSegmentation->Sector(ix,iy);
-       TF1* cogCorr = fSegmentation->CorrFunc(isec-1);
+       fSegmentation[0]->GetPadIxy(x, y, ix, iy);
+       fSegmentation[0]->GetPadCxy(ix, iy, x, y);
+       Int_t isec=fSegmentation[0]->Sector(ix,iy);
+       TF1* cogCorr = fSegmentation[0]->CorrFunc(isec-1);
        
        if (cogCorr) {
-           Float_t yOnPad=(c->fY[0]-y)/fSegmentation->Dpy(isec);
+           Float_t yOnPad=(c->fY[0]-y)/fSegmentation[0]->Dpy(isec);
            c->fY[0]=c->fY[0]-cogCorr->Eval(yOnPad, 0, 0);
        }
     }
@@ -564,7 +567,7 @@ void  AliMUONClusterFinder::FindCluster(Int_t i, Int_t j, AliMUONRawCluster &c){
 
 // Prepare center of gravity calculation
     Float_t x, y;
-    fSegmentation->GetPadCxy(i, j, x, y);
+    fSegmentation[0]->GetPadCxy(i, j, x, y);
     c.fX[0] += q*x;
     c.fY[0] += q*y;
     c.fQ[0] += q;
@@ -575,7 +578,7 @@ void  AliMUONClusterFinder::FindCluster(Int_t i, Int_t j, AliMUONRawCluster &c){
 //  
     Int_t nn;
     Int_t xList[kMaxNeighbours], yList[kMaxNeighbours];
-    fSegmentation->Neighbours(i,j,&nn,xList,yList);
+    fSegmentation[0]->Neighbours(i,j,&nn,xList,yList);
     for (Int_t in=0; in<nn; in++) {
        Int_t ix=xList[in];
        Int_t iy=yList[in];
@@ -593,7 +596,7 @@ void AliMUONClusterFinder::FindRawClusters()
   //
     if (!fNdigits) return;
 
-    fHitMap = new AliMUONHitMapA1(fSegmentation, fDigits);
+    fHitMap = new AliMUONHitMapA1(fSegmentation[0], fDigits);
 
     AliMUONDigit *dig;
 
@@ -620,7 +623,7 @@ void AliMUONClusterFinder::FindRawClusters()
        FindCluster(i,j, c);
        // center of gravity
        c.fX[0] /= c.fQ[0];
-       c.fX[0]=fSegmentation->GetAnod(c.fX[0]);
+       c.fX[0]=fSegmentation[0]->GetAnod(c.fX[0]);
        c.fY[0] /= c.fQ[0];
 //
 //  apply correction to the coordinate along the anode wire
@@ -628,12 +631,12 @@ void AliMUONClusterFinder::FindRawClusters()
        Int_t ix,iy;
        Float_t x=c.fX[0];   
        Float_t y=c.fY[0];
-       fSegmentation->GetPadIxy(x, y, ix, iy);
-       fSegmentation->GetPadCxy(ix, iy, x, y);
-       Int_t isec=fSegmentation->Sector(ix,iy);
-       TF1* cogCorr=fSegmentation->CorrFunc(isec-1);
+       fSegmentation[0]->GetPadIxy(x, y, ix, iy);
+       fSegmentation[0]->GetPadCxy(ix, iy, x, y);
+       Int_t isec=fSegmentation[0]->Sector(ix,iy);
+       TF1* cogCorr=fSegmentation[0]->CorrFunc(isec-1);
        if (cogCorr) {
-           Float_t yOnPad=(c.fY[0]-y)/fSegmentation->Dpy(isec);
+           Float_t yOnPad=(c.fY[0]-y)/fSegmentation[0]->Dpy(isec);
            c.fY[0]=c.fY[0]-cogCorr->Eval(yOnPad,0,0);
        }
 //
@@ -664,13 +667,13 @@ CalibrateCOG()
     Float_t y[5];
     Int_t n, i;
     TF1 func;
-    if (fSegmentation) {
-       fSegmentation->GiveTestPoints(n, x, y);
+    if (fSegmentation[0]) {
+       fSegmentation[0]->GiveTestPoints(n, x, y);
        for (i=0; i<n; i++) {
            Float_t xtest=x[i];
            Float_t ytest=y[i];     
            SinoidalFit(xtest, ytest, func);
-           fSegmentation->SetCorrFunc(i, new TF1(func));
+           fSegmentation[0]->SetCorrFunc(i, new TF1(func));
        }
     }
 }
@@ -689,7 +692,7 @@ SinoidalFit(Float_t x, Float_t y, TF1 &func)
     Float_t xg[kns], yg[kns], xrg[kns], yrg[kns];
     Float_t xsig[kns], ysig[kns];
     
-    AliMUONSegmentation *segmentation=fSegmentation;
+    AliMUONSegmentation *segmentation=fSegmentation[0];
     
     Int_t ix,iy;
     segmentation->GetPadIxy(x,y,ix,iy);   
@@ -860,7 +863,7 @@ Bool_t AliMUONClusterFinder::SingleMathiesonFit(AliMUONRawCluster *c)
 //  Initialise global variables for fit
     Int_t i;
     fMul=c->fMultiplicity[0];
-    fgSegmentation=fSegmentation;
+    fgSegmentation=fSegmentation[0];
     fgResponse    =fResponse;
     fgNbins=fMul;
     Float_t qtot=0;
@@ -873,7 +876,7 @@ Bool_t AliMUONClusterFinder::SingleMathiesonFit(AliMUONRawCluster *c)
        fIx[i]= fDig[i]->fPadX;
        fIy[i]= fDig[i]->fPadY;
        fQ[i] = fDig[i]->fSignal;
-       fSegmentation->GetPadCxy(fIx[i], fIy[i], fX[i], fY[i]);
+       fSegmentation[0]->GetPadCxy(fIx[i], fIy[i], fX[i], fY[i]);
        fgix[i]=fIx[i];
        fgiy[i]=fIy[i];
        fgCharge[i]=Float_t(fQ[i]);
@@ -902,13 +905,13 @@ Bool_t AliMUONClusterFinder::SingleMathiesonFit(AliMUONRawCluster *c)
 // lower and upper limits
     static Double_t lower[2], upper[2];
     Int_t ix,iy;
-    fSegmentation->GetPadIxy(c->fX[0], c->fY[0], ix, iy);
-    Int_t isec=fSegmentation->Sector(ix, iy);
-    lower[0]=vstart[0]-fSegmentation->Dpx(isec)/2;
-    lower[1]=vstart[1]-fSegmentation->Dpy(isec)/2;
+    fSegmentation[0]->GetPadIxy(c->fX[0], c->fY[0], ix, iy);
+    Int_t isec=fSegmentation[0]->Sector(ix, iy);
+    lower[0]=vstart[0]-fSegmentation[0]->Dpx(isec)/2;
+    lower[1]=vstart[1]-fSegmentation[0]->Dpy(isec)/2;
     
-    upper[0]=lower[0]+fSegmentation->Dpx(isec);
-    upper[1]=lower[1]+fSegmentation->Dpy(isec);
+    upper[0]=lower[0]+fSegmentation[0]->Dpx(isec);
+    upper[1]=lower[1]+fSegmentation[0]->Dpy(isec);
     
 // step sizes
     static Double_t step[2]={0.0005, 0.0005};
@@ -943,7 +946,7 @@ Bool_t AliMUONClusterFinder::DoubleMathiesonFit(AliMUONRawCluster *c)
 //  Initialise global variables for fit
     Int_t i,j;
     
-    fgSegmentation=fSegmentation;
+    fgSegmentation=fSegmentation[0];
     fgResponse    =fResponse;
     fgNbins=fMul;
     Float_t qtot=0;
@@ -978,19 +981,19 @@ Bool_t AliMUONClusterFinder::DoubleMathiesonFit(AliMUONRawCluster *c)
        Float_t(fQ[fIndLocal[0]]+fQ[fIndLocal[1]]);
 // lower and upper limits
     static Double_t lower[5], upper[5];
-    Int_t isec=fSegmentation->Sector(fIx[fIndLocal[0]], fIy[fIndLocal[0]]);
-    lower[0]=vstart[0]-fSegmentation->Dpx(isec);
-    lower[1]=vstart[1]-fSegmentation->Dpy(isec);
+    Int_t isec=fSegmentation[0]->Sector(fIx[fIndLocal[0]], fIy[fIndLocal[0]]);
+    lower[0]=vstart[0]-fSegmentation[0]->Dpx(isec);
+    lower[1]=vstart[1]-fSegmentation[0]->Dpy(isec);
     
-    upper[0]=lower[0]+2.*fSegmentation->Dpx(isec);
-    upper[1]=lower[1]+2.*fSegmentation->Dpy(isec);
+    upper[0]=lower[0]+2.*fSegmentation[0]->Dpx(isec);
+    upper[1]=lower[1]+2.*fSegmentation[0]->Dpy(isec);
     
-    isec=fSegmentation->Sector(fIx[fIndLocal[1]], fIy[fIndLocal[1]]);
-    lower[2]=vstart[2]-fSegmentation->Dpx(isec)/2;
-    lower[3]=vstart[3]-fSegmentation->Dpy(isec)/2;
+    isec=fSegmentation[0]->Sector(fIx[fIndLocal[1]], fIy[fIndLocal[1]]);
+    lower[2]=vstart[2]-fSegmentation[0]->Dpx(isec)/2;
+    lower[3]=vstart[3]-fSegmentation[0]->Dpy(isec)/2;
     
-    upper[2]=lower[2]+fSegmentation->Dpx(isec);
-    upper[3]=lower[3]+fSegmentation->Dpy(isec);
+    upper[2]=lower[2]+fSegmentation[0]->Dpx(isec);
+    upper[3]=lower[3]+fSegmentation[0]->Dpy(isec);
     
     lower[4]=0.;
     upper[4]=1.;
index bf75805c6879e4c405e23a617744db5df81016a1..04bc63d831287d636281f18cb467713f2a0f18a7 100644 (file)
@@ -34,7 +34,7 @@ class AliMUONClusterFinder :
 // Set segmentation model    
     virtual void SetSegmentation(
        AliMUONSegmentation *segmentation){
-       fSegmentation=segmentation;
+       fSegmentation[0]=segmentation;
     }
 // Set response model    
     virtual void SetResponse(AliMUONResponse *response) {
@@ -91,7 +91,7 @@ class AliMUONClusterFinder :
 protected:
     TClonesArray*           fDigits;         // Digits
     Int_t                   fNdigits;        // Number of Digits
-    AliMUONSegmentation*    fSegmentation;   // Chamber segmentation
+    AliMUONSegmentation*    fSegmentation[2];   // Chamber segmentation
     AliMUONResponse*        fResponse;       // Chamber Response
     TClonesArray*           fRawClusters;    // Raw Clusters
     Int_t                   fChamber;        // Chamber Number
index 6f943dd22f3d8c7cfce12ee8a2de9bedc70a01e4..986a4b5396f739884192207d2d0c6b214831787e 100644 (file)
  **************************************************************************/
 /*
 $Log$
+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)
@@ -49,6 +53,7 @@ Revised and extended SplitByLocalMaxima method (Isabelle Chevrot):
 #include "AliMUONHitMapA1.h"
 #include "AliRun.h"
 #include "AliMUON.h"
+#include "AliMUONClusterInput.h"
 
 #include <TTree.h>
 #include <TCanvas.h>
@@ -61,6 +66,7 @@ Revised and extended SplitByLocalMaxima method (Isabelle Chevrot):
 #include <iostream.h>
 
 //_____________________________________________________________________
+/*
 static AliMUONSegmentation* fgSegmentation[2];
 static AliMUONResponse*     fgResponse;
 static Int_t                fgix[500][2];
@@ -71,6 +77,7 @@ 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);
@@ -87,7 +94,7 @@ ClassImp(AliMUONClusterFinderVS)
     :AliMUONClusterFinder(seg1, response, digits1, chamber)
 {
 // Constructor
-    fSegmentation2=seg2;
+    fSegmentation[1]=seg2;
     fDigits2=digits2;
     fNdigits2 = fDigits2->GetEntriesFast();
     fHitMap2=0;
@@ -99,7 +106,7 @@ ClassImp(AliMUONClusterFinderVS)
        :AliMUONClusterFinder()
 {
 // Default constructor
-    fSegmentation2=0;
+    fSegmentation[1]=0;
     fDigits2=0;
     fNdigits2 = 0;
     fHitMap2 = 0;
@@ -115,7 +122,6 @@ AliMUONClusterFinderVS::AliMUONClusterFinderVS(
 
 void AliMUONClusterFinderVS::SetDigits(TClonesArray *MUONdigits1, TClonesArray *MUONdigits2) {
 // Set pointers to digit lists 
-
     fDigits=MUONdigits1;
     fNdigits = fDigits->GetEntriesFast();
     fDigits2=MUONdigits2;
@@ -126,7 +132,7 @@ void AliMUONClusterFinderVS::SetDigits(TClonesArray *MUONdigits1, TClonesArray *
 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);
+    return ((i==0)? fSegmentation[0] : fSegmentation[1]);
 }
 
 // Get Number of Digits
@@ -161,18 +167,16 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
 // Split complex cluster by local maxima 
 
     Int_t cath, i;
-    
+
+    AliMUONClusterInput::Instance()->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++) {
@@ -190,15 +194,7 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
            // 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];
        } // loop over cluster digits
-       fgQtot[cath]=qtot;
-       fgChargeTot[cath]=Int_t(qtot);  
     }  // loop over cathodes
 
 
@@ -468,16 +464,16 @@ 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.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];
+                                   fSegmentation[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 +483,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 +580,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
@@ -622,10 +618,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];
@@ -663,8 +659,8 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                        cnew.fY[cath]=Float_t(ym[ico][0]);
                        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];
+                           fSegmentation[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 +672,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 +687,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
@@ -771,8 +767,8 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                        cnew.fY[cath]=Float_t(ym[ico][0]);
                        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];
+                           fSegmentation[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 +788,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,9 +816,9 @@ 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);
@@ -844,8 +840,8 @@ void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
                    cnew.fY[cath]=Float_t(ym[ico][0]);
                    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];
+                       fSegmentation[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
                    }
                    FillCluster(&cnew,cath);
                } 
@@ -1287,8 +1283,8 @@ void AliMUONClusterFinderVS::FindRawClusters()
 
     if (!NDigits(0) && !NDigits(1)) return;
 
-    fHitMap  = new AliMUONHitMapA1(fSegmentation , fDigits);
-    fHitMap2 = new AliMUONHitMapA1(fSegmentation2, fDigits2);
+    fHitMap  = new AliMUONHitMapA1(fSegmentation[0] , fDigits);
+    fHitMap2 = new AliMUONHitMapA1(fSegmentation[1], fDigits2);
 
     AliMUONDigit *dig;
 
@@ -1375,44 +1371,14 @@ void AliMUONClusterFinderVS::FindRawClusters()
 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);
+    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);
+//     clusterInput.Fitter()->mnexcm("SET ERR",arglist,1,ierflag);
 // Set starting values 
     static Double_t vstart[2];
     vstart[0]=c->fX[1];
@@ -1433,21 +1399,21 @@ Float_t AliMUONClusterFinderVS::SingleMathiesonFit(AliMUONRawCluster *c, Int_t c
 // 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 +1422,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 +1433,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;
@@ -1502,21 +1464,21 @@ Float_t AliMUONClusterFinderVS::CombiSingleMathiesonFit(AliMUONRawCluster *c)
 // 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 +1487,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;
@@ -1536,29 +1498,9 @@ Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster *c, Int_t ca
 {
 //
 //  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;
@@ -1591,73 +1533,36 @@ Bool_t AliMUONClusterFinderVS::DoubleMathiesonFit(AliMUONRawCluster *c, Int_t ca
 // 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 +1571,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;
@@ -1723,36 +1625,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 +1668,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++) {
@@ -1783,16 +1685,16 @@ void AliMUONClusterFinderVS::Split(AliMUONRawCluster* c)
            cnew.fX[cath]=Float_t(fXFit[j]);
            cnew.fY[cath]=Float_t(fYFit[j]);
            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]);
+           fSegmentation[cath]->SetHit(fXFit[j],fYFit[j]);
            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]);
+               fSegmentation[cath]->SetPad(fIx[i][cath], fIy[i][cath]);
+               Float_t q1=fResponse->IntXY(fSegmentation[cath]);
                cnew.fContMap[i][cath]
                    =(q1*Float_t(cnew.fQ[cath]))/Float_t(fQ[i][cath]);
                cnew.fMultiplicity[cath]++;
@@ -1808,97 +1710,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,6 +1735,7 @@ 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;
@@ -1918,35 +1745,35 @@ void fcnCombiS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t if
 
     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);
+       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/fgNbins[cath];
+//     if (cath == 0) chi2temp=chisq/clusterInput.Nbins[cath];
     }
-//    chisq = chisq/fgNbins[1]+chi2temp; 
-    
+//    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)
 {
+    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;
@@ -1959,6 +1786,7 @@ void fcnS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
 // 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;
@@ -1968,18 +1796,18 @@ void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t if
 
     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);
+       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/fgNbins[cath];
+//     if (cath == 0) chi2temp=chisq/clusterInput.Nbins[cath];
     }
-//    chisq = chisq/fgNbins[1]+chi2temp;       
+//    chisq = chisq/clusterInput.Nbins[1]+chi2temp;    
     f=chisq;
 }
 
index 2728ab7a0908f0b10de7a0f46c63cb1f9dafbbce..f5182950e4ee901f3b6b01051713e8603ee1a891 100644 (file)
@@ -11,6 +11,8 @@
 #include "AliMUONHitMap.h"
 #include "TF1.h"
 #include "AliMUONClusterFinder.h"
+#include "AliMUONSegmentation.h"
+
 class AliMUONClusterFinderVS : 
  public AliMUONClusterFinder
 {
@@ -26,8 +28,8 @@ class AliMUONClusterFinderVS :
 // Set segmentation model    
     virtual void SetSegmentation(AliMUONSegmentation *seg1, AliMUONSegmentation *seg2)
        {
-       fSegmentation=seg1;
-       fSegmentation2=seg2;
+       fSegmentation[0]=seg1;
+       fSegmentation[1]=seg2;
        }
 // Set pointer to digits
     virtual void SetDigits(TClonesArray *MUONdigits1, TClonesArray *MUONdigits2);
@@ -85,7 +87,6 @@ class AliMUONClusterFinderVS :
 protected:
     TClonesArray*           fDigits2;            // Digits
     Int_t                   fNdigits2;           // Number of Digits    
-    AliMUONSegmentation*    fSegmentation2;      // Chamber segmentation
     AliMUONHitMapA1*        fHitMap2;            // Hit Map
     AliMUONDigit*           fDig[100][2];        // current list of digits 
     Int_t                   fIx[100][2];         // current list of x-pad-coord.
diff --git a/MUON/AliMUONClusterInput.cxx b/MUON/AliMUONClusterInput.cxx
new file mode 100644 (file)
index 0000000..3e786cf
--- /dev/null
@@ -0,0 +1,195 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/*
+$Log$
+*/
+#include "AliRun.h"
+#include "AliMUON.h"
+#include "AliMUONChamber.h"
+#include "AliMUONClusterInput.h"
+#include "AliMUONSegmentation.h"
+#include "AliMUONResponse.h"
+#include "AliMUONRawCluster.h"
+#include "AliMUONDigit.h"
+
+#include <TClonesArray.h>
+#include <TMinuit.h>
+
+ClassImp(AliMUONClusterInput)
+
+AliMUONClusterInput* AliMUONClusterInput::fgClusterInput = 0; 
+TMinuit* AliMUONClusterInput::fgMinuit = 0; 
+
+AliMUONClusterInput* AliMUONClusterInput::Instance()
+{
+// return pointer to the singleton instance
+    if (fgClusterInput == 0) {
+       fgClusterInput = new AliMUONClusterInput();
+       fgMinuit = new TMinuit(5);
+    }
+    
+    return fgClusterInput;
+}
+
+void AliMUONClusterInput::SetDigits(Int_t chamber, TClonesArray* dig1, TClonesArray* dig2)
+{
+// Set pointer to digits with corresponding segmentations and responses (two cathode planes)
+    fDigits[0]=dig1;
+    fDigits[1]=dig2; 
+    AliMUON *pMUON;
+    AliMUONChamber* iChamber;
+
+    pMUON = (AliMUON*) gAlice->GetModule("MUON");
+    iChamber =  &(pMUON->Chamber(chamber));
+
+    fSegmentation[0]=iChamber->SegmentationModel(1);
+    fSegmentation[1]=iChamber->SegmentationModel(2);
+    fResponse=iChamber->ResponseModel();
+    fNseg = 2;
+}
+
+void AliMUONClusterInput::SetDigits(Int_t chamber, TClonesArray* dig)
+{
+// Set pointer to digits with corresponding segmentations and responses (one cathode plane)
+    fDigits[0]=dig;
+    AliMUON *pMUON;
+    AliMUONChamber* iChamber;
+
+    pMUON = (AliMUON*) gAlice->GetModule("MUON");
+    iChamber =  &(pMUON->Chamber(chamber));
+
+    fSegmentation[0]=iChamber->SegmentationModel(1);
+    fResponse=iChamber->ResponseModel();
+    fNseg=1;
+}
+
+void  AliMUONClusterInput::SetCluster(AliMUONRawCluster* cluster)
+{
+// Set the current cluster
+    fCluster=cluster;
+    Float_t qtot;
+    Int_t   i, cath, ix, iy;
+    AliMUONDigit* digit;
+    fNmul[0]=cluster->fMultiplicity[0];
+    fNmul[1]=cluster->fMultiplicity[1];
+    printf("\n %p %p ", fDigits[0], fDigits[1]);
+    
+    for (cath=0; cath<2; cath++) {
+       qtot=0;
+       for (i=0; i<fNmul[cath]; i++) {
+           // pointer to digit
+           digit =(AliMUONDigit*)
+               (fDigits[cath]->UncheckedAt(cluster->fIndexMap[i][cath]));
+           // pad coordinates
+           ix = digit->fPadX;
+           iy = digit->fPadY;
+           // pad charge
+           fCharge[i][cath] = digit->fSignal;
+           // pad centre coordinates
+//         fSegmentation[cath]->GetPadCxy(ix, iy, x, y);
+            // globals kUsed in fitting functions
+           fix[i][cath]=ix;
+           fiy[i][cath]=iy;
+           // total charge per cluster
+           qtot+=fCharge[i][cath];
+       } // loop over cluster digits
+       fQtot[cath]=qtot;
+       fChargeTot[cath]=Int_t(qtot);  
+    }  // loop over cathodes
+}
+
+
+
+Float_t AliMUONClusterInput::DiscrChargeS1(Int_t i,Double_t *par) 
+{
+// par[0]    x-position of cluster
+// par[1]    y-position of cluster
+
+   fSegmentation[0]->SetPad(fix[i][0], fiy[i][0]);
+//  First Cluster
+   fSegmentation[0]->SetHit(par[0],par[1]);
+   Float_t q1=fResponse->IntXY(fSegmentation[0]);
+    
+   Float_t value = fQtot[0]*q1;
+   return value;
+}
+
+Float_t AliMUONClusterInput::DiscrChargeCombiS1(Int_t i,Double_t *par, Int_t cath) 
+{
+// par[0]    x-position of cluster
+// par[1]    y-position of cluster
+
+   fSegmentation[cath]->SetPad(fix[i][cath], fiy[i][cath]);
+//  First Cluster
+   fSegmentation[cath]->SetHit(par[0],par[1]);
+   Float_t q1=fResponse->IntXY(fSegmentation[cath]);
+    
+   Float_t value = fQtot[cath]*q1;
+   return value;
+}
+
+
+Float_t AliMUONClusterInput::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
+
+   fSegmentation[0]->SetPad(fix[i][0], fiy[i][0]);
+//  First Cluster
+   fSegmentation[0]->SetHit(par[0],par[1]);
+   Float_t q1=fResponse->IntXY(fSegmentation[0]);
+    
+//  Second Cluster
+   fSegmentation[0]->SetHit(par[2],par[3]);
+   Float_t q2=fResponse->IntXY(fSegmentation[0]);
+    
+   Float_t value = fQtot[0]*(par[4]*q1+(1.-par[4])*q2);
+   return value;
+}
+
+Float_t AliMUONClusterInput::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
+
+   fSegmentation[cath]->SetPad(fix[i][cath], fiy[i][cath]);
+//  First Cluster
+   fSegmentation[cath]->SetHit(par[0],par[1]);
+   Float_t q1=fResponse->IntXY(fSegmentation[cath]);
+    
+//  Second Cluster
+   fSegmentation[cath]->SetHit(par[2],par[3]);
+   Float_t q2=fResponse->IntXY(fSegmentation[cath]);
+   Float_t value;
+   if (cath==0) {
+       value = fQtot[0]*(par[4]*q1+(1.-par[4])*q2);
+   } else {
+       value = fQtot[1]*(par[5]*q1+(1.-par[5])*q2);
+   }
+   return value;
+}
+
+
+
+
diff --git a/MUON/AliMUONClusterInput.h b/MUON/AliMUONClusterInput.h
new file mode 100644 (file)
index 0000000..09cbc1f
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef ALIMUONCLUSTERINPUT_H
+#define ALIMUONCLUSTERINPUT_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/*$Id $*/
+
+#include <TObject.h>
+#include <TClonesArray.h>
+
+class TMinuit;
+class AliMUONDigit;
+class AliMUONRawCluster;
+class AliMUONSegmentation;
+class AliMUONResponse;
+
+
+
+class AliMUONClusterInput : public TObject {
+ public:
+    static AliMUONClusterInput* Instance();
+//  Setters
+    void SetDigits(Int_t chamber, TClonesArray* dig1, TClonesArray* dig2);
+    void SetDigits(Int_t chamber, TClonesArray* dig);
+    void SetCluster(AliMUONRawCluster* cluster);
+// Access functions
+    AliMUONDigit* Digit(Int_t cath, Int_t i) {return (AliMUONDigit*) (fDigits[cath]->UncheckedAt(i));}
+    TMinuit*      Fitter() {return fgMinuit;}
+    Float_t       TotalCharge(Int_t cath) {return fChargeTot[cath];}
+    Float_t       Charge(Int_t dig, Int_t cath) {return fCharge[dig][cath];}
+    Int_t         Ix(Int_t dig, Int_t cath) {return fix[dig][cath];}
+    Int_t         Iy(Int_t dig, Int_t cath) {return fiy[dig][cath];}
+    Int_t         Nmul(Int_t cath)  {return fNmul[cath];}
+//  Helpers for Fit     
+    Float_t DiscrChargeS1(Int_t i,Double_t *par);
+    Float_t DiscrChargeCombiS1(Int_t i,Double_t *par, Int_t cath);
+    Float_t DiscrChargeS2(Int_t i,Double_t *par);
+    Float_t DiscrChargeCombiS2(Int_t i,Double_t *par, Int_t cath);
+// 
+ protected:
+    AliMUONClusterInput(){;}
+ private:
+    static AliMUONClusterInput* fgClusterInput;
+    // Digits
+    TClonesArray*        fDigits[2];       // ! Array of pointers to digits
+    AliMUONSegmentation* fSegmentation[2]; // ! Segmentation per cathode
+    AliMUONResponse*     fResponse;        // ! Response
+    Int_t                fNseg;            // ! number of cathode planes
+    // Current cluster
+    AliMUONRawCluster*   fCluster;         // ! current cluster
+    Int_t                fNmul[2];         // ! current cluster multiplicity
+    // Digits contribuing to current cluster
+    Int_t                fix[500][2];      // ! List of x-positions for current cluster
+    Int_t                fiy[500][2];      // ! List of y-positions for current cluster
+    Float_t              fCharge[500][2];  // ! List of charges for current cluster
+    Int_t                fChargeTot[2];    // ! Total charge
+    Float_t              fQtot[2];         // ! Total charge
+    // Fitter
+    static TMinuit*      fgMinuit;          // ! Fitter
+    ClassDef(AliMUONClusterInput, 1) // Class definition in ROOT context
+};
+#endif
+