Code from MUON-dev joined
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 15 Jun 2000 07:58:49 +0000 (07:58 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 15 Jun 2000 07:58:49 +0000 (07:58 +0000)
132 files changed:
MUON/AliMUON.cxx
MUON/AliMUON.h
MUON/AliMUONChamber.cxx [new file with mode: 0644]
MUON/AliMUONChamber.h [new file with mode: 0644]
MUON/AliMUONChamberTrigger.cxx [new file with mode: 0644]
MUON/AliMUONChamberTrigger.h [new file with mode: 0644]
MUON/AliMUONClusterFinder.cxx
MUON/AliMUONClusterFinder.h
MUON/AliMUONClusterFinderV0.cxx [new file with mode: 0644]
MUON/AliMUONClusterFinderV0.h [new file with mode: 0644]
MUON/AliMUONClusterFinderVS.cxx [new file with mode: 0644]
MUON/AliMUONClusterFinderVS.h [new file with mode: 0644]
MUON/AliMUONClusterFinderv0.h
MUON/AliMUONConst.h
MUON/AliMUONDigit.cxx [new file with mode: 0644]
MUON/AliMUONDigit.h [new file with mode: 0644]
MUON/AliMUONDisplay.cxx [new file with mode: 0644]
MUON/AliMUONDisplay.h [moved from MUON/AliMUONdisplay.h with 78% similarity]
MUON/AliMUONEventReconstructor.cxx [new file with mode: 0644]
MUON/AliMUONEventReconstructor.h [new file with mode: 0644]
MUON/AliMUONGlobalTrigger.cxx [new file with mode: 0644]
MUON/AliMUONGlobalTrigger.h [new file with mode: 0644]
MUON/AliMUONHit.cxx [new file with mode: 0644]
MUON/AliMUONHit.h [new file with mode: 0644]
MUON/AliMUONHitForRec.cxx [new file with mode: 0644]
MUON/AliMUONHitForRec.h [new file with mode: 0644]
MUON/AliMUONHitMap.cxx
MUON/AliMUONHitMap.h
MUON/AliMUONHitMapA1.cxx [new file with mode: 0644]
MUON/AliMUONHitMapA1.h [new file with mode: 0644]
MUON/AliMUONLocalTrigger.cxx [new file with mode: 0644]
MUON/AliMUONLocalTrigger.h [new file with mode: 0644]
MUON/AliMUONPadHit.cxx [new file with mode: 0644]
MUON/AliMUONPadHit.h [new file with mode: 0644]
MUON/AliMUONPoints.cxx [new file with mode: 0644]
MUON/AliMUONPoints.h [moved from MUON/AliMUONpoints.h with 67% similarity]
MUON/AliMUONRawCluster.cxx [new file with mode: 0644]
MUON/AliMUONRawCluster.h [new file with mode: 0644]
MUON/AliMUONReconstHit.cxx [new file with mode: 0644]
MUON/AliMUONReconstHit.h [new file with mode: 0644]
MUON/AliMUONResponse.cxx [new file with mode: 0644]
MUON/AliMUONResponse.h [new file with mode: 0644]
MUON/AliMUONResponseTrigger.cxx [new file with mode: 0644]
MUON/AliMUONResponseTrigger.h [new file with mode: 0644]
MUON/AliMUONResponseV0.cxx [new file with mode: 0644]
MUON/AliMUONResponseV0.h [new file with mode: 0644]
MUON/AliMUONSegResV01.cxx
MUON/AliMUONSegResV01.h
MUON/AliMUONSegResV04.h [deleted file]
MUON/AliMUONSegResV05.h [deleted file]
MUON/AliMUONSegResV1.cxx [deleted file]
MUON/AliMUONSegment.cxx [new file with mode: 0644]
MUON/AliMUONSegment.h [new file with mode: 0644]
MUON/AliMUONSegmentation.cxx [new file with mode: 0644]
MUON/AliMUONSegmentation.h [moved from MUON/AliMUONSegRes.h with 62% similarity]
MUON/AliMUONSegmentationTrigger.cxx [new file with mode: 0644]
MUON/AliMUONSegmentationTrigger.h [new file with mode: 0644]
MUON/AliMUONSegmentationTriggerX.cxx [new file with mode: 0644]
MUON/AliMUONSegmentationTriggerX.h [new file with mode: 0644]
MUON/AliMUONSegmentationTriggerY.cxx [new file with mode: 0644]
MUON/AliMUONSegmentationTriggerY.h [new file with mode: 0644]
MUON/AliMUONSegmentationV0.cxx [new file with mode: 0644]
MUON/AliMUONSegmentationV0.h [moved from MUON/AliMUONSegResV0.h with 51% similarity]
MUON/AliMUONSegmentationV01.cxx [new file with mode: 0644]
MUON/AliMUONSegmentationV01.h [new file with mode: 0644]
MUON/AliMUONSegmentationV02.cxx [moved from MUON/AliMUONSegResV02.cxx with 60% similarity]
MUON/AliMUONSegmentationV02.h [moved from MUON/AliMUONSegResV02.h with 75% similarity]
MUON/AliMUONSegmentationV04.cxx [moved from MUON/AliMUONSegResV04.cxx with 77% similarity]
MUON/AliMUONSegmentationV04.h [new file with mode: 0644]
MUON/AliMUONSegmentationV05.cxx [moved from MUON/AliMUONSegResV05.cxx with 78% similarity]
MUON/AliMUONSegmentationV05.h [new file with mode: 0644]
MUON/AliMUONSegmentationV1.cxx [new file with mode: 0644]
MUON/AliMUONSegmentationV1.h [new file with mode: 0644]
MUON/AliMUONTUBE.cxx [deleted file]
MUON/AliMUONTUBE.h [deleted file]
MUON/AliMUONTrack.cxx [new file with mode: 0644]
MUON/AliMUONTrack.h [new file with mode: 0644]
MUON/AliMUONTrackHit.cxx [new file with mode: 0644]
MUON/AliMUONTrackHit.h [new file with mode: 0644]
MUON/AliMUONTrackParam.cxx [new file with mode: 0644]
MUON/AliMUONTrackParam.h [new file with mode: 0644]
MUON/AliMUONTrackReconstructor.cxx [new file with mode: 0644]
MUON/AliMUONTrackReconstructor.h [new file with mode: 0644]
MUON/AliMUONTransientDigit.cxx [new file with mode: 0644]
MUON/AliMUONTransientDigit.h [new file with mode: 0644]
MUON/AliMUONTriggerCircuit.cxx [new file with mode: 0644]
MUON/AliMUONTriggerCircuit.h [new file with mode: 0644]
MUON/AliMUONTriggerDecision.cxx [new file with mode: 0644]
MUON/AliMUONTriggerDecision.h [new file with mode: 0644]
MUON/AliMUONTriggerLut.cxx [new file with mode: 0644]
MUON/AliMUONTriggerLut.h [new file with mode: 0644]
MUON/AliMUONchamber.cxx [deleted file]
MUON/AliMUONchamber.h [deleted file]
MUON/AliMUONdisplay.cxx [deleted file]
MUON/AliMUONpoints.cxx [deleted file]
MUON/AliMUONproto.cxx [new file with mode: 0644]
MUON/AliMUONproto.h [new file with mode: 0644]
MUON/AliMUONv0.cxx
MUON/AliMUONv0.h
MUON/AliMUONv1.cxx [new file with mode: 0644]
MUON/AliMUONv1.h [new file with mode: 0644]
MUON/Config.C [new file with mode: 0644]
MUON/MUONConfig.C [new file with mode: 0644]
MUON/MUONLinkDef.h
MUON/MUONRawDigit.C [new file with mode: 0644]
MUON/MUONTestTrigger.C [new file with mode: 0644]
MUON/MUONTriggerLut.C [new file with mode: 0644]
MUON/MUONTriggerLut.root [new file with mode: 0644]
MUON/MUONcombi.C
MUON/MUONdigit.C
MUON/MUONdigits.C [deleted file]
MUON/MUONdisplay.C
MUON/MUONdoubles.C [new file with mode: 0644]
MUON/MUONhitrectest.C [new file with mode: 0644]
MUON/MUONhits.C [new file with mode: 0644]
MUON/MUONlist2digits.C [deleted file]
MUON/MUONmultest.C [new file with mode: 0644]
MUON/MUONocc.C [new file with mode: 0644]
MUON/MUONrawclusters.C
MUON/MUONrechits.C [copied from MUON/MUONcathcorel.C with 93% similarity]
MUON/MUONstraggling.C [new file with mode: 0644]
MUON/MUONtestabso.C
MUON/MUONtestrawclust.C [new file with mode: 0644]
MUON/MUONtestzaza.C [deleted file]
MUON/MUONtracking.C [new file with mode: 0644]
MUON/MUONtrigger.C [moved from MUON/MUONcathcorel.C with 52% similarity]
MUON/Makefile
MUON/abso_dedx.C [new file with mode: 0644]
MUON/algo.F [deleted file]
MUON/dedx.C [new file with mode: 0644]
MUON/masse.C [new file with mode: 0644]
MUON/reco_muon.F

index c8c5119..23ea3a4 100644 (file)
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
-
 /*
 $Log$
-Revision 1.16  2000/04/26 10:17:31  fca
-Changes in Lego for G4 compatibility
+Revision 1.14.4.17  2000/06/14 14:36:46  morsch
+- add TriggerCircuit (PC)
+- add GlobalTrigger and LocalTrigger and specific methods (PC)
+
+Revision 1.14.4.16  2000/06/09 21:20:28  morsch
+Most coding rule violations corrected
+
+Revision 1.14.4.15  2000/05/02 09:54:32  morsch
+RULE RN17 violations corrected
+
+Revision 1.14.4.12  2000/04/26 12:25:02  morsch
+Code revised by P. Crochet:
+- Z position of TriggerChamber changed according to A.Tournaire Priv.Comm.
+- ToF included in the method MakePadHits
+- inner radius of flange between beam shielding and trigger corrected
+- Trigger global volume updated (according to the new geometry)
+
+Revision 1.14.4.11  2000/04/19 19:42:08  morsch
+Some changes of variable names curing viols and methods concerning
+correlated clusters removed.
+
+Revision 1.14.4.10  2000/03/22 16:44:07  gosset
+Memory leak suppressed in function Digitise:
+p_adr->Delete() instead of Clear (I.Chevrot and A.Baldisseri)
+
+Revision 1.14.4.9  2000/03/20 18:15:25  morsch
+Positions of trigger chambers corrected (P.C.)
 
-Revision 1.15  2000/01/19 17:16:56  fca
-Introducing a list of lists of hits -- more hits allowed for detector now
+Revision 1.14.4.8  2000/02/21 15:38:01  morsch
+Call to AddHitList introduced to make this version compatible with head.
 
-Revision 1.14  1999/11/03 13:17:07  fca
-Have ProdProcess return const char*
+Revision 1.14.4.7  2000/02/20 07:45:53  morsch
+Bugs in Trigger part of BuildGeomemetry corrected (P.C)
 
-Revision 1.13  1999/10/26 06:04:48  fca
-Introduce TLorentzVector in AliMC::GetSecondary. Thanks to I.Hrivnacova
+Revision 1.14.4.6  2000/02/17 14:28:54  morsch
+Trigger included into initialization and digitization
 
-Revision 1.12  1999/10/07 21:08:10  fca
-Corrections by G.Chabratova
+Revision 1.14.4.5  2000/02/15 10:02:58  morsch
+Log messages of previous revisions added
 
-Revision 1.11  1999/10/05 17:15:45  fca
-Minor syntax for the Alpha OSF
+Revision 1.14.4.2  2000/02/04 10:57:34  gosset
+Z position of the chambers:
+it was the Z position of the stations;
+it is now really the Z position of the chambers.
+   !!!! WARNING: THE CALLS TO "AliMUONChamber::SetZPOS"
+   !!!!                   AND "AliMUONChamber::ZPosition"
+   !!!! HAVE TO BE CHANGED TO "AliMUONChamber::"SetZ"
+   !!!!                   AND "AliMUONChamber::Z"
 
-Revision 1.10  1999/10/01 09:24:40  fca
-Protect against no current file in FinishEvent
+Revision 1.14.4.3  2000/02/04 16:19:04  gosset
+Correction for mis-spelling of NCH 
 
-Revision 1.9  1999/09/29 09:24:20  fca
-Introduction of the Copyright and cvs Log
+Revision 1.14.4.4  2000/02/15 09:43:38  morsch
+Log message added
 
 */
 
-////////////////////////////////////////////////
+
+///////////////////////////////////////////////
 //  Manager and hits classes for set:MUON     //
 ////////////////////////////////////////////////
 
-#include <TH1.h>
-#include <TH2.h>
 #include <TTUBE.h>
 #include <TBRIK.h>
 #include <TRotMatrix.h>
@@ -66,127 +95,62 @@ Introduction of the Copyright and cvs Log
 #include <TDirectory.h>
 #include <TObjectTable.h>
 #include <AliPDG.h>
+#include <TTUBE.h>
 
 #include "AliMUON.h"
-#include "TTUBE.h"
+#include "AliMUONHit.h"
+#include "AliMUONPadHit.h"
+#include "AliMUONDigit.h"
+#include "AliMUONTransientDigit.h"
+#include "AliMUONRawCluster.h"
+#include "AliMUONLocalTrigger.h"
+#include "AliMUONGlobalTrigger.h"
+#include "AliMUONHitMap.h"
+#include "AliMUONHitMapA1.h"
+#include "AliMUONChamberTrigger.h"
+
 #include "AliMUONClusterFinder.h"
+#include "AliMUONTriggerDecision.h"
 #include "AliRun.h"
 #include "AliMC.h"
 #include "iostream.h"
 #include "AliCallf77.h" 
+#include "AliConst.h" 
+
+// Defaults parameters for Z positions of chambers
+// taken from values for "stations" in AliMUON::AliMUON
+//     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
+// and from array "dstation" in AliMUONv1::CreateGeometry
+//          Float_t dstation[5]={20., 20., 20, 20., 20.};
+//     for tracking chambers,
+//          according to (Z1 = zch - dstation) and  (Z2 = zch + dstation)
+//          for the first and second chambers in the station, respectively,
+// and from "DTPLANES" in AliMUONv1::CreateGeometry
+//           const Float_t DTPLANES = 15.;
+//     for trigger chambers,
+//          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
+//          for the first and second chambers in the station, respectively
+static const Float_t kDefaultChambersZ[kNCH] =
+{518., 538., 680., 700., 965., 985., 1239., 1259., 1439., 1459.,
+ 1603.5, 1618.5, 1703.5, 1718.5}; 
 
-#ifndef WIN32 
-# define reco_init       reco_init_
-# define cutpxz          cutpxz_
-# define sigmacut        sigmacut_
-# define xpreci          xpreci_
-# define ypreci          ypreci_
-# define reconstmuon     reconstmuon_
-# define trackf_read_geant     trackf_read_geant_
-# define trackf_read_spoint     trackf_read_spoint_
-# define chfill          chfill_
-# define chfill2         chfill2_
-# define chf1            chf1_
-# define chfnt           chfnt_
-# define hist_create     hist_create_
-# define hist_closed     hist_closed_
-# define rndm            rndm_
-# define fcn             fcn_
-# define trackf_fit      trackf_fit_
-# define prec_fit        prec_fit_
-# define fcnfit          fcnfit_
-# define reco_term       reco_term_
-#else 
-# define reco_init       RECO_INIT
-# define cutpxz          CUTPXZ
-# define sigmacut        SIGMACUT
-# define xpreci          XPRECI
-# define ypreci          YPRECI
-# define reconstmuon     RECONSTMUON
-# define trackf_read_geant     TRACKF_READ_GEANT
-# define trackf_read_spoint     TRACKF_READ_SPOINT
-# define chfill          CHFILL
-# define chfill2         CHFILL2
-# define chf1            CHF1
-# define chfnt           CHFNT
-# define hist_create     HIST_CREATE
-# define hist_closed     HIST_CLOSED
-# define rndm            RNDM
-# define fcn             FCN
-# define trackf_fit      TRACKF_FIT
-# define prec_fit        PREC_FIT
-# define fcnfit          FCNFIT
-# define reco_term       RECO_TERM
-#endif 
-
-extern "C"
-{
-void type_of_call reco_init(Double_t &, Double_t &, Double_t &);
-void type_of_call reco_term();
-void type_of_call cutpxz(Double_t &);
-void type_of_call sigmacut(Double_t &);
-void type_of_call xpreci(Double_t &);
-void type_of_call ypreci(Double_t &);
-void type_of_call reconstmuon(Int_t &, Int_t &, Int_t &, Int_t &, Int_t &);
-void type_of_call trackf_read_geant(Int_t *, Double_t *, Double_t *, Double_t *, Int_t *, Int_t *, Double_t *, Double_t *, Double_t *, Double_t *,Int_t &, Double_t *, Double_t *, Double_t *, Int_t &, Int_t &, Double_t *, Double_t *, Double_t *, Double_t *); 
-void type_of_call trackf_read_spoint(Int_t *, Double_t *, Double_t *, Double_t *, Int_t *, Int_t *, Double_t *, Double_t *, Double_t *, Double_t *,Int_t &, Double_t *, Double_t *, Double_t *, Int_t &, Int_t &, Double_t *, Double_t *, Double_t *, Double_t *); 
-void type_of_call chfill(Int_t &, Float_t &, Float_t &, Float_t &);
-void type_of_call chfill2(Int_t &, Float_t &, Float_t &, Float_t &);
-void type_of_call chf1(Int_t &, Float_t &, Float_t &);
-void type_of_call chfnt(Int_t &, Int_t &, Int_t *, Int_t *, Float_t *, Float_t *, Float_t *, Float_t *, Float_t *, Float_t *, Float_t *, Float_t *);
-void type_of_call hist_create();
-void type_of_call hist_closed();
-void type_of_call fcnf(Int_t &, Double_t *, Double_t &, Double_t *, Int_t);
-void type_of_call fcn(Int_t &, Double_t *, Double_t &, Double_t *, Int_t &, Int_t &);
-void type_of_call trackf_fit(Int_t &, Double_t *, Double_t *, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &);
-void type_of_call prec_fit(Double_t &, Double_t &, Double_t &, Double_t &, Double_t&, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &);
-void type_of_call fcnfitf(Int_t &, Double_t *, Double_t &, Double_t *, Int_t);
-void type_of_call fcnfit(Int_t &, Double_t *, Double_t &, Double_t *, Int_t &, Int_t &);
-Float_t type_of_call rndm() {return gRandom->Rndm();}
-}
-
-void fcnfwrap(Int_t &i1, Double_t *d1, Double_t &d2,
-       Double_t *d3, Int_t i2)
-{
-   fcnf(i1,d1,d2,d3,i2);
-}
-
-void fcnfitfwrap(Int_t &i1, Double_t *d1, Double_t &d2,
-       Double_t *d3, Int_t i2)
-{
-   fcnfitf(i1,d1,d2,d3,i2);
-}
-
-
-// Static variables for the pad-hit iterator routines
-static Int_t sMaxIterPad=0;
-static Int_t sCurIterPad=0;
-static TTree *TrH1;
-static TTree *TK1;
-static TClonesArray *fHits2;        //Listof hits for one track only
-static TClonesArray *fClusters2;    //List of clusters for one track only
-static TClonesArray *fParticles2;   //List of particles in the Kine tree
 ClassImp(AliMUON)
 //___________________________________________
 AliMUON::AliMUON()
 {
-   fIshunt     = 0;
-   fHits       = 0;
-   fClusters   = 0;
-   fNclusters  = 0;
-   fDchambers  = 0;
-   fNdch       = 0;
-   fRawClusters= 0;
-   fNrawch     = 0;
-   fCathCorrel= 0;
-   fNcorch     = 0;
-   fTreeC = 0;
-
-   // modifs perso
-   fSPxzCut    = 0;
-   fSSigmaCut  = 0;
-   fSXPrec     = 0; 
-   fSYPrec     = 0;
+   fIshunt       = 0;
+   fHits         = 0;
+   fPadHits      = 0;
+   fNPadHits     = 0;
+   fDchambers    = 0;
+   fTriggerCircuits = 0;     // cp new design of AliMUONTriggerDecision
+   fNdch         = 0;
+   fRawClusters  = 0;
+   fNrawch       = 0;
+   fGlobalTrigger   = 0;
+   fNLocalTrigger   = 0;
+   fLocalTrigger    = 0;
+   fNLocalTrigger   = 0;
 }
  
 //___________________________________________
@@ -199,40 +163,37 @@ AliMUON::AliMUON(const char *name, const char *title)
 */
 //End_Html
  
-   fHits     = new TClonesArray("AliMUONhit",1000);
+   fHits     = new TClonesArray("AliMUONHit",1000);
    gAlice->AddHitList(fHits);
-   fClusters = new TClonesArray("AliMUONcluster",10000);
-   fNclusters  =  0;
+   fPadHits = new TClonesArray("AliMUONPadHit",10000);
+   fNPadHits  =  0;
    fIshunt     =  0;
 
-   fNdch      = new Int_t[10];
+   fNdch      = new Int_t[kNCH];
 
-   fDchambers = new TObjArray(10);
+   fDchambers = new TObjArray(kNCH);
 
    Int_t i;
    
-   for (i=0; i<10 ;i++) {
-       (*fDchambers)[i] = new TClonesArray("AliMUONdigit",10000); 
+   for (i=0; i<kNCH ;i++) {
+       (*fDchambers)[i] = new TClonesArray("AliMUONDigit",10000); 
        fNdch[i]=0;
    }
 
-   fNrawch      = new Int_t[10];
+   fNrawch      = new Int_t[kNTrackingCh];
 
-   fRawClusters = new TObjArray(10);
+   fRawClusters = new TObjArray(kNTrackingCh);
 
-   for (i=0; i<10 ;i++) {
+   for (i=0; i<kNTrackingCh;i++) {
        (*fRawClusters)[i] = new TClonesArray("AliMUONRawCluster",10000); 
        fNrawch[i]=0;
    }
+   cout << " here " << "\n";
 
-   fNcorch      = new Int_t[10];
-   fCathCorrel = new TObjArray(10);
-   for (i=0; i<10 ;i++) {
-       (*fCathCorrel)[i] = new TClonesArray("AliMUONcorrelation",1000); 
-       fNcorch[i]=0;
-   }
-
-   fTreeC = 0;
+   fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
+   fNGlobalTrigger = 0;
+   fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);    
+   fNLocalTrigger = 0;
 
 //   
 // Transport angular cut
@@ -240,16 +201,75 @@ AliMUON::AliMUON(const char *name, const char *title)
    fAccMin=2;
    fAccMax=9;
 
-   // modifs perso
-   fSPxzCut   = 3.0;
-   fSSigmaCut = 1.0;
-   fSXPrec    = 0.01; 
-   fSYPrec    = 0.144;
-
    SetMarkerColor(kRed);
+//
+//
+//
+//
+//  inner diameter
+   const Float_t kDmin[7]={ 35.,  47.,  66.,   80.,  80., 100., 100.};
+//
+//  outer diameter
+   const Float_t kDmax[7]={183., 245., 316.6,  520.,  520., 830., 880.};
+//
+    Int_t ch;
+
+    fChambers = new TObjArray(kNCH);
+
+    // Loop over stations
+    for (Int_t st = 0; st < kNCH / 2; st++) {
+      // Loop over 2 chambers in the station
+       for (Int_t stCH = 0; stCH < 2; stCH++) {
+//
+//    
+//    Default Parameters for Muon Tracking Stations
+
+
+           ch = 2 * st + stCH;
+//
+           if (ch < kNTrackingCh) {
+               (*fChambers)[ch] = new AliMUONChamber();
+           } else {
+               (*fChambers)[ch] = new AliMUONChamberTrigger();
+           }
+           
+           AliMUONChamber* chamber = (AliMUONChamber*) (*fChambers)[ch];
+           
+           chamber->SetGid(0);
+           // Default values for Z of chambers
+           chamber->SetZ(kDefaultChambersZ[ch]);
+//
+           chamber->InitGeo(kDefaultChambersZ[ch]);
+           chamber->SetRInner(kDmin[st]/2);
+           chamber->SetROuter(kDmax[st]/2);
+//
+       } // Chamber stCH (0, 1) in 
+    }     // Station st (0...)
+    fMaxStepGas=0.01; 
+    fMaxStepAlu=0.1; 
+    fMaxDestepGas=-1;
+    fMaxDestepAlu=-1;
+//
+   fMaxIterPad   = 0;
+   fCurIterPad   = 0;
+
+   // cp new design of AliMUONTriggerDecision
+   fTriggerCircuits = new TObjArray(kNTriggerCircuit);
+   for (Int_t circ=0; circ<kNTriggerCircuit; circ++) {
+     (*fTriggerCircuits)[circ] = new AliMUONTriggerCircuit();     
+   }
+   // cp new design of AliMUONTriggerDecision
+
 }
  
 //___________________________________________
+AliMUON::AliMUON(const AliMUON& rMUON)
+{
+// Dummy copy constructor
+    ;
+    
+}
+
 AliMUON::~AliMUON()
 {
 
@@ -258,39 +278,43 @@ AliMUON::~AliMUON()
   Int_t i;
   fIshunt  = 0;
   delete fHits;
-  delete fClusters;
-  delete fTreeC;
+  delete fPadHits;
 
-  for (i=0;i<10;i++) {
+  delete fGlobalTrigger;
+  fNGlobalTrigger = 0;
+
+  delete fLocalTrigger;
+  fNLocalTrigger = 0;
+
+  for (i=0;i<kNCH;i++) {
       delete (*fDchambers)[i];
       fNdch[i]=0;
   }
   delete fDchambers;
 
-  for (i=0;i<10;i++) {
+  for (i=0;i<kNTrackingCh;i++) {
       delete (*fRawClusters)[i];
       fNrawch[i]=0;
   }
   delete fRawClusters;
 
-  for (i=0;i<10;i++) {
-      delete (*fCathCorrel)[i];
-      fNcorch[i]=0;
+  for (Int_t circ=0; circ<kNTriggerCircuit; circ++) {
+    delete (*fTriggerCircuits)[circ];
   }
-  delete fCathCorrel;
+  delete fTriggerCircuits;
 }
  
 //___________________________________________
 void AliMUON::AddHit(Int_t track, Int_t *vol, Float_t *hits)
 {
   TClonesArray &lhits = *fHits;
-  new(lhits[fNhits++]) AliMUONhit(fIshunt,track,vol,hits);
+  new(lhits[fNhits++]) AliMUONHit(fIshunt,track,vol,hits);
 }
 //___________________________________________
-void AliMUON::AddCluster(Int_t *clhits)
+void AliMUON::AddPadHit(Int_t *clhits)
 {
-   TClonesArray &lclusters = *fClusters;
-   new(lclusters[fNclusters++]) AliMUONcluster(clhits);
+   TClonesArray &lclusters = *fPadHits;
+   new(lclusters[fNPadHits++]) AliMUONPadHit(clhits);
 }
 //_____________________________________________________________________________
 void AliMUON::AddDigits(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
@@ -300,7 +324,7 @@ void AliMUON::AddDigits(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
     //
 
     TClonesArray &ldigits = *((TClonesArray*)(*fDchambers)[id]);
-    new(ldigits[fNdch[id]++]) AliMUONdigit(tracks,charges,digits);
+    new(ldigits[fNdch[id]++]) AliMUONDigit(tracks,charges,digits);
 }
 
 //_____________________________________________________________________________
@@ -313,98 +337,193 @@ void AliMUON::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
     TClonesArray &lrawcl = *((TClonesArray*)(*fRawClusters)[id]);
     new(lrawcl[fNrawch[id]++]) AliMUONRawCluster(c);
 }
-//_____________________________________________________________________________
-void AliMUON::AddCathCorrel(Int_t id, Int_t *idx, Float_t *x, Float_t *y)
-{
-    //
-    // Add a MUON digit to the list
-    //
 
-    TClonesArray &lcorrel = *((TClonesArray*)(*fCathCorrel)[id]);
-    new(lcorrel[fNcorch[id]++]) AliMUONcorrelation(idx,x,y);
+//___________________________________________
+void AliMUON::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
+                              Int_t *singleUndef,
+                              Int_t *pairUnlike, Int_t *pairLike)
+{
+// add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
+  TClonesArray &globalTrigger = *fGlobalTrigger;
+  new(globalTrigger[fNGlobalTrigger++]) 
+    AliMUONGlobalTrigger(singlePlus, singleMinus,  singleUndef, pairUnlike, 
+                        pairLike);
+}
+//___________________________________________
+void AliMUON::AddLocalTrigger(Int_t *localtr)
+{
+// add a MUON Local Trigger to the list
+  TClonesArray &localTrigger = *fLocalTrigger;
+  new(localTrigger[fNLocalTrigger++]) AliMUONLocalTrigger(localtr);
 }
 
 //___________________________________________
 void AliMUON::BuildGeometry()
 {
-    TNode *Node, *NodeF, *Top;
-    const int kColorMUON = kBlue;
+    TNode *node, *nodeF, *top, *nodeS;
+    const int kColorMUON  = kBlue;
+    const int kColorMUON2 = kGreen; 
     //
-    Top=gAlice->GetGeometry()->GetNode("alice");
+    top=gAlice->GetGeometry()->GetNode("alice");
 // MUON
 //
 //  z-Positions of Chambers
-    const Float_t cz[5]={511., 686., 971., 1245., 1445.};
-//
-//  inner diameter
-    const Float_t dmi[5]={ 35.,  47.,  67.,   86.,  100.};
-//
-//  outer diameter
-    const Float_t dma[5]={183., 245., 346.,  520.,  520.};
+    const Float_t kCz[7]={511., 686., 971., 1245., 1445., 1600, 1700.};
+//  inner diameter (Xlenght for trigger chamber -> active area)
+    const Float_t kDmin[7]={ 35.,  47.,  67.,   86.,  100., 544., 544.};
+//  outer diameter (Ylenght for trigger chamber -> active area)
+    const Float_t kDmax[7]={183., 245., 346.,  520.,  520., 612., 612.};
 
     TRotMatrix* rot000 = new TRotMatrix("Rot000"," ", 90,  0, 90, 90, 0, 0);
     TRotMatrix* rot090 = new TRotMatrix("Rot090"," ", 90, 90, 90,180, 0, 0);
     TRotMatrix* rot180 = new TRotMatrix("Rot180"," ", 90,180, 90,270, 0, 0);
     TRotMatrix* rot270 = new TRotMatrix("Rot270"," ", 90,270, 90,  0, 0, 0);
     
-
-    float rmin, rmax, dx, dy, dz, dr, zpos;
-    float dzc=4.;
-    char NameChamber[9], NameSense[9], NameFrame[9], NameNode[8];
-    for (Int_t i=0; i<5; i++) {
+    Float_t rmin, rmax, dx, dy, dz, dr, xpos, ypos, zpos;
+    Float_t dzc1=4.;           // tracking chambers
+    Float_t dzc2=15.;          // trigger chambers
+    Float_t hole=102.;          // x-y hole around beam pipe for trig. chambers
+    Float_t zscale;            // scaling parameter trigger chambers
+    Float_t halfx, halfy;   
+    char nameChamber[9], nameSense[9], nameFrame[9], nameNode[8];
+    char nameSense1[9], nameSense2[9];    
+    for (Int_t i=0; i<7; i++) {
        for (Int_t j=0; j<2; j++) {
            Int_t id=2*i+j+1;
-           if (j==0) {
-               zpos=cz[i]-dzc;
+           if (i<5) {               // tracking chambers
+               if (j==0) {
+                   zpos=kCz[i]-dzc1;
+               } else {
+                   zpos=kCz[i]+dzc1;
+               }
            } else {
-               zpos=cz[i]+dzc;
+               if (j==0) {
+                   zpos=kCz[i];
+               } else {            
+                   zpos=kCz[i]+dzc2;
+               }
            }
-           
-           
-           sprintf(NameChamber,"C_MUON%d",id);
-           sprintf(NameSense,"S_MUON%d",id);
-           sprintf(NameFrame,"F_MUON%d",id);   
-           rmin = dmi[i]/2.-3;
-           rmax = dma[i]/2.+3;
-           new TTUBE(NameChamber,"Mother","void",rmin,rmax,0.25,1.);
-           rmin = dmi[i]/2.;
-           rmax = dma[i]/2.;
-           new TTUBE(NameSense,"Sens. region","void",rmin,rmax,0.25, 1.);
-           dx=(rmax-rmin)/2;
-           dy=3.;
-           dz=0.25;
-           TBRIK* FMUON = new TBRIK(NameFrame,"Frame","void",dx,dy,dz);
-           Top->cd();
-           sprintf(NameNode,"MUON%d",100+id);
-           Node = new TNode(NameNode,"ChamberNode",NameChamber,0,0,zpos,"");
-           Node->SetLineColor(kColorMUON);
-           fNodes->Add(Node);
-           Node->cd();
-           sprintf(NameNode,"MUON%d",200+id);
-           Node = new TNode(NameNode,"Sens. Region Node",NameSense,0,0,0,"");
-           Node->SetLineColor(kColorMUON);
-           fNodes->Add(Node);
-           Node->cd();
-           dr=dx+rmin;
-           sprintf(NameNode,"MUON%d",300+id);
-           NodeF = new TNode(NameNode,"Frame0",FMUON,dr, 0, 0,rot000,"");
-           NodeF->SetLineColor(kColorMUON);
-           fNodes->Add(NodeF);
-           Node->cd();
-           sprintf(NameNode,"MUON%d",400+id);
-           NodeF = new TNode(NameNode,"Frame1",FMUON,0 ,dr,0,rot090,"");
-           NodeF->SetLineColor(kColorMUON);
-           fNodes->Add(NodeF);
-           Node->cd();
-           sprintf(NameNode,"MUON%d",500+id);
-           NodeF = new TNode(NameNode,"Frame2",FMUON,-dr,0,0,rot180,"");
-           NodeF->SetLineColor(kColorMUON);
-           fNodes->Add(NodeF);
-           Node  ->cd();
-           sprintf(NameNode,"MUON%d",600+id);   
-           NodeF = new TNode(NameNode,"Frame3",FMUON,0,-dr,0,rot270,"");
-           NodeF->SetLineColor(kColorMUON);
-           fNodes->Add(NodeF);
+           sprintf(nameChamber,"C_MUON%d",id);
+           sprintf(nameSense,"S_MUON%d",id);
+           sprintf(nameSense1,"S1_MUON%d",id);
+           sprintf(nameSense2,"S2_MUON%d",id);
+           sprintf(nameFrame,"F_MUON%d",id);   
+           if (i<5) {                        // tracking chambers
+               rmin = kDmin[i]/2.-3;
+               rmax = kDmax[i]/2.+3;
+               new TTUBE(nameChamber,"Mother","void",rmin,rmax,0.25,1.);
+               rmin = kDmin[i]/2.;
+               rmax = kDmax[i]/2.;
+               new TTUBE(nameSense,"Sens. region","void",rmin,rmax,0.25, 1.);
+               dx=(rmax-rmin)/2;
+               dy=3.;
+               dz=0.25;
+               TBRIK* frMUON = new TBRIK(nameFrame,"Frame","void",dx,dy,dz);
+               top->cd();
+               sprintf(nameNode,"MUON%d",100+id);
+               node = new TNode(nameNode,"ChamberNode",nameChamber,0,0,zpos,"");
+               node->SetLineColor(kColorMUON);
+               fNodes->Add(node);
+               node->cd();
+               sprintf(nameNode,"MUON%d",200+id);
+               node = new TNode(nameNode,"Sens. Region Node",nameSense,0,0,0,"");
+               node->SetLineColor(kColorMUON);
+               node->cd();
+               dr=dx+rmin;
+               sprintf(nameNode,"MUON%d",300+id);
+               nodeF = new TNode(nameNode,"Frame0",frMUON,dr, 0, 0,rot000,"");
+               nodeF->SetLineColor(kColorMUON);
+               node->cd();
+               sprintf(nameNode,"MUON%d",400+id);
+               nodeF = new TNode(nameNode,"Frame1",frMUON,0 ,dr,0,rot090,"");
+               nodeF->SetLineColor(kColorMUON);
+               node->cd();
+               sprintf(nameNode,"MUON%d",500+id);
+               nodeF = new TNode(nameNode,"Frame2",frMUON,-dr,0,0,rot180,"");
+               nodeF->SetLineColor(kColorMUON);
+               node  ->cd();
+               sprintf(nameNode,"MUON%d",600+id);   
+               nodeF = new TNode(nameNode,"Frame3",frMUON,0,-dr,0,rot270,"");
+               nodeF->SetLineColor(kColorMUON);
+           } else { 
+               zscale=zpos/kCz[5];
+               Float_t xsize=kDmin[i]*zscale;
+               Float_t ysize=kDmax[i]*zscale;
+               Float_t holeScaled=hole*zscale;
+               
+               halfx=xsize/2.+3.;
+               halfy=ysize/2.+3.;          
+               new TBRIK(nameChamber,"Mother","void",halfx,halfy,0.25);
+               top->cd();
+               sprintf(nameNode,"MUON%d",100+id);
+               node = new TNode(nameNode,"Chambernode",nameChamber,0,0,zpos,"");
+               node->SetLineColor(kColorMUON2);
+               fNodes->Add(node);
+               
+// up/down of beam pipe
+               halfx=xsize/2.;
+               halfy=(ysize/2.-holeScaled/2.)/2.;          
+               new TBRIK(nameSense,"Sens. region","void",halfx,halfy,0.25);
+               
+               node->cd();
+               ypos=holeScaled/2.+((ysize/2.-holeScaled/2.)/2.);
+               sprintf(nameNode,"MUON%d",200+id);
+               nodeS = new TNode(nameNode,"Sens. Region Node",nameSense,0,ypos,0,"");
+               nodeS->SetLineColor(kColorMUON2);
+               
+               node->cd();
+               ypos=-1.*ypos;
+               sprintf(nameNode,"MUON%d",300+id);
+               nodeS = new TNode(nameNode,"Sens. Region Node",nameSense,0,ypos,0,"");
+               nodeS->SetLineColor(kColorMUON2);
+               
+// left/right of beam pipe
+               halfx=(xsize/2.-holeScaled/2.)/2.;
+               halfy=holeScaled/2.;    
+               new TBRIK(nameSense1,"Sens. region","void",halfx,halfy,0.25);
+               
+               node->cd();
+               xpos=holeScaled/2.+((xsize/2.-holeScaled/2.)/2.);           
+               sprintf(nameNode,"MUON%d",400+id);
+               nodeS = new TNode(nameNode,"Sens. Region Node",nameSense1,xpos,0,0,"");
+               nodeS->SetLineColor(kColorMUON2);
+               
+               node->cd();
+               xpos=-1.*xpos;
+               sprintf(nameNode,"MUON%d",500+id);
+               nodeS = new TNode(nameNode,"Sens. Region Node",nameSense1,xpos,0,0,"");
+               nodeS->SetLineColor(kColorMUON2);
+               
+// missing corners
+               halfx=17.*zscale/2.;
+               halfy=halfx;
+               new TBRIK(nameSense2,"Sens. region","void",halfx,halfy,0.25);
+               
+               node->cd();
+               xpos=holeScaled/2.-halfx;
+               ypos=xpos;
+               sprintf(nameNode,"MUON%d",600+id);
+               nodeS = new TNode(nameNode,"Sens. Region Node",nameSense2,xpos,ypos,0,"");
+               nodeS->SetLineColor(kColorMUON2);
+               
+               node->cd();
+               ypos=-1.*xpos;
+               sprintf(nameNode,"MUON%d",700+id);
+               nodeS = new TNode(nameNode,"Sens. Region Node",nameSense2,xpos,ypos,0,"");
+               nodeS->SetLineColor(kColorMUON2);
+               
+               node->cd();
+               xpos=-1.*xpos;
+               sprintf(nameNode,"MUON%d",800+id);
+               nodeS = new TNode(nameNode,"Sens. Region Node",nameSense2,xpos,ypos,0,"");
+               nodeS->SetLineColor(kColorMUON2);
+               
+               node->cd();
+               ypos=-1.*xpos;
+               sprintf(nameNode,"MUON%d",900+id);
+               nodeS = new TNode(nameNode,"Sens. Region Node",nameSense2,xpos,ypos,0,"");
+               nodeS->SetLineColor(kColorMUON2);
+           } 
        }
     }
 }
@@ -421,41 +540,54 @@ void AliMUON::MakeBranch(Option_t* option)
 {
   // Create Tree branches for the MUON.
   
-  const Int_t buffersize = 4000;
+  const Int_t kBufferSize = 4000;
   char branchname[30];
   sprintf(branchname,"%sCluster",GetName());
 
   AliDetector::MakeBranch(option);
 
-  if (fClusters   && gAlice->TreeH()) {
-    gAlice->TreeH()->Branch(branchname,&fClusters, buffersize);
+  if (fPadHits   && gAlice->TreeH()) {
+    gAlice->TreeH()->Branch(branchname,&fPadHits, kBufferSize);
     printf("Making Branch %s for clusters\n",branchname);
   }
 
 // one branch for digits per chamber
   Int_t i;
   
-  for (i=0; i<10 ;i++) {
+  for (i=0; i<kNCH ;i++) {
       sprintf(branchname,"%sDigits%d",GetName(),i+1);
       
       if (fDchambers   && gAlice->TreeD()) {
-         gAlice->TreeD()->Branch(branchname,&((*fDchambers)[i]), buffersize);
+         gAlice->TreeD()->Branch(branchname,&((*fDchambers)[i]), kBufferSize);
          printf("Making Branch %s for digits in chamber %d\n",branchname,i+1);
       }        
   }
 
-  //printf("Make Branch - TreeR address %p\n",gAlice->TreeR());
+  printf("Make Branch - TreeR address %p\n",gAlice->TreeR());
 
 // one branch for raw clusters per chamber
-  for (i=0; i<10 ;i++) {
+  for (i=0; i<kNTrackingCh ;i++) {
       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
       
       if (fRawClusters   && gAlice->TreeR()) {
-        gAlice->TreeR()->Branch(branchname,&((*fRawClusters)[i]), buffersize);
+        gAlice->TreeR()->Branch(branchname,&((*fRawClusters)[i]), kBufferSize);
         printf("Making Branch %s for raw clusters in chamber %d\n",branchname,i+1);
       }        
   }
 
+// one branch for global trigger
+  sprintf(branchname,"%sGlobalTrigger",GetName());
+  if (fGlobalTrigger && gAlice->TreeR()) {  
+    gAlice->TreeR()->Branch(branchname,&fGlobalTrigger,kBufferSize);
+    printf("Making Branch %s for Global Trigger\n",branchname);
+  }
+// one branch for local trigger
+  sprintf(branchname,"%sLocalTrigger",GetName());
+  if (fLocalTrigger && gAlice->TreeR()) {  
+    gAlice->TreeR()->Branch(branchname,&fLocalTrigger,kBufferSize);
+    printf("Making Branch %s for Local Trigger\n",branchname);
+  }
+
 }
 
 //___________________________________________
@@ -471,14 +603,14 @@ void AliMUON::SetTreeAddress()
   TTree *treeR = gAlice->TreeR();
 
   if (treeH) {
-    if (fClusters) {
+    if (fPadHits) {
       branch = treeH->GetBranch("MUONCluster");
-      if (branch) branch->SetAddress(&fClusters);
+      if (branch) branch->SetAddress(&fPadHits);
     }
   }
 
   if (treeD) {
-      for (int i=0; i<10; i++) {
+      for (int i=0; i<kNCH; i++) {
          sprintf(branchname,"%sDigits%d",GetName(),i+1);
          if (fDchambers) {
              branch = treeD->GetBranch(branchname);
@@ -490,23 +622,31 @@ void AliMUON::SetTreeAddress()
   // printf("SetTreeAddress --- treeR address  %p \n",treeR);
 
   if (treeR) {
-      for (int i=0; i<10; i++) {
+      for (int i=0; i<kNTrackingCh; i++) {
          sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
          if (fRawClusters) {
              branch = treeR->GetBranch(branchname);
              if (branch) branch->SetAddress(&((*fRawClusters)[i]));
          }
       }
-  }
 
+      if (fLocalTrigger) {
+       branch = treeR->GetBranch("MUONLocalTrigger");
+       if (branch) branch->SetAddress(&fLocalTrigger);
+      }
+      if (fGlobalTrigger) {
+       branch = treeR->GetBranch("MUONGlobalTrigger");
+       if (branch) branch->SetAddress(&fGlobalTrigger);
+      }
+  }
 }
 //___________________________________________
 void AliMUON::ResetHits()
 {
   // Reset number of clusters and the cluster array for this detector
   AliDetector::ResetHits();
-  fNclusters = 0;
-  if (fClusters) fClusters->Clear();
+  fNPadHits = 0;
+  if (fPadHits) fPadHits->Clear();
 }
 
 //____________________________________________
@@ -515,7 +655,7 @@ void AliMUON::ResetDigits()
     //
     // Reset number of digits and the digits array for this detector
     //
-    for ( int i=0;i<10;i++ ) {
+    for ( int i=0;i<kNCH;i++ ) {
        if ((*fDchambers)[i])    ((TClonesArray*)(*fDchambers)[i])->Clear();
        if (fNdch)  fNdch[i]=0;
     }
@@ -526,63 +666,79 @@ void AliMUON::ResetRawClusters()
     //
     // Reset number of raw clusters and the raw clust array for this detector
     //
-    for ( int i=0;i<10;i++ ) {
+    for ( int i=0;i<kNTrackingCh;i++ ) {
        if ((*fRawClusters)[i])    ((TClonesArray*)(*fRawClusters)[i])->Clear();
        if (fNrawch)  fNrawch[i]=0;
     }
 }
+
 //____________________________________________
-void AliMUON::ResetCorrelation()
+void AliMUON::ResetTrigger()
 {
-    //
-    // Reset number of correl clusters and the correl clust array for 
-    // this detector
-    //
-    for ( int i=0;i<10;i++ ) {
-       if ((*fCathCorrel)[i])   ((TClonesArray*)(*fCathCorrel)[i])->Clear();
-       if (fNcorch)  fNcorch[i]=0;
-    }
+  //  Reset Local and Global Trigger 
+  fNGlobalTrigger = 0;
+  if (fGlobalTrigger) fGlobalTrigger->Clear();
+  fNLocalTrigger = 0;
+  if (fLocalTrigger) fLocalTrigger->Clear();
+}
+
+//____________________________________________
+void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
+{
+    Int_t i=2*(id-1);
+    ((AliMUONChamber*) (*fChambers)[i])  ->SetPadSize(isec,p1,p2);
+    ((AliMUONChamber*) (*fChambers)[i+1])->SetPadSize(isec,p1,p2);
 }
 
 //___________________________________________
+void AliMUON::SetChambersZ(const Float_t *Z)
+{
+  // Set Z values for all chambers (tracking and trigger)
+  // from the array pointed to by "Z"
+  for (Int_t ch = 0; ch < kNCH; ch++)
+    ((AliMUONChamber*) ((*fChambers)[ch]))->SetZ(Z[ch]);
+  return;
+}
 
-void AliMUON::SetPADSIZ(Int_t id, Int_t isec, Float_t p1, Float_t p2)
+//___________________________________________
+void AliMUON::SetChambersZToDefault()
 {
-    Int_t i=2*(id-1);
-    ((AliMUONchamber*) (*fChambers)[i])  ->SetPADSIZ(isec,p1,p2);
-    ((AliMUONchamber*) (*fChambers)[i+1])->SetPADSIZ(isec,p1,p2);
+  // Set Z values for all chambers (tracking and trigger)
+  // to default values
+  SetChambersZ(kDefaultChambersZ);
+  return;
 }
 
 //___________________________________________
 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
 {
     Int_t i=2*(id-1);
-    ((AliMUONchamber*) (*fChambers)[i])->SetChargeSlope(p1);
-    ((AliMUONchamber*) (*fChambers)[i+1])->SetChargeSlope(p1);
+    ((AliMUONChamber*) (*fChambers)[i])->SetChargeSlope(p1);
+    ((AliMUONChamber*) (*fChambers)[i+1])->SetChargeSlope(p1);
 }
 
 //___________________________________________
 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
 {
     Int_t i=2*(id-1);
-    ((AliMUONchamber*) (*fChambers)[i])->SetChargeSpread(p1,p2);
-    ((AliMUONchamber*) (*fChambers)[i+1])->SetChargeSpread(p1,p2);
+    ((AliMUONChamber*) (*fChambers)[i])->SetChargeSpread(p1,p2);
+    ((AliMUONChamber*) (*fChambers)[i+1])->SetChargeSpread(p1,p2);
 }
 
 //___________________________________________
 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
 {
     Int_t i=2*(id-1);
-    ((AliMUONchamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
-    ((AliMUONchamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
+    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
+    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
 }
 
 //___________________________________________
 void AliMUON::SetMaxAdc(Int_t id, Float_t p1)
 {
     Int_t i=2*(id-1);
-    ((AliMUONchamber*) (*fChambers)[i])->SetMaxAdc(p1);
-    ((AliMUONchamber*) (*fChambers)[i+1])->SetMaxAdc(p1);
+    ((AliMUONChamber*) (*fChambers)[i])->SetMaxAdc(p1);
+    ((AliMUONChamber*) (*fChambers)[i+1])->SetMaxAdc(p1);
 }
 
 //___________________________________________
@@ -616,67 +772,34 @@ void AliMUON::SetMuonAcc(Bool_t acc, Float_t angmin, Float_t angmax)
    fAccMax=angmax;
 }
 //___________________________________________
-void   AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliMUONsegmentation *segmentation)
+void   AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliMUONSegmentation *segmentation)
 {
-    ((AliMUONchamber*) (*fChambers)[id])->SegmentationModel(isec, segmentation);
+    ((AliMUONChamber*) (*fChambers)[id])->SetSegmentationModel(isec, segmentation);
 
 }
 //___________________________________________
-void   AliMUON::SetResponseModel(Int_t id, AliMUONresponse *response)
+void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
 {
-    ((AliMUONchamber*) (*fChambers)[id])->ResponseModel(response);
+    ((AliMUONChamber*) (*fChambers)[id])->SetResponseModel(response);
 }
 
 void   AliMUON::SetReconstructionModel(Int_t id, AliMUONClusterFinder *reconst)
 {
-    ((AliMUONchamber*) (*fChambers)[id])->ReconstructionModel(reconst);
+    ((AliMUONChamber*) (*fChambers)[id])->SetReconstructionModel(reconst);
 }
 
 void   AliMUON::SetNsec(Int_t id, Int_t nsec)
 {
-    ((AliMUONchamber*) (*fChambers)[id])->SetNsec(nsec);
+    ((AliMUONChamber*) (*fChambers)[id])->SetNsec(nsec);
 }
 
 
 //___________________________________________
 
-void AliMUON::StepManager()
-{
-    printf("Dummy version of muon step -- it should never happen!!\n");
-    /*
-    const Float_t kRaddeg = 180/TMath::Pi();
-    Int_t nsec, ipart;
-    TLorentzVector x, p;
-    Float_t pt, th0, th2;
-    char *proc;
-    if(fAccCut) {
-       if((nsec=gMC->NSecondaries())>0) {
-           proc=gMC->ProdProcess();
-           if((gMC->TrackPid()==443 || gMC->TrackPid()==553) && !strcmp(proc,"DCAY")) {
-               //
-               // Check angular acceptance
-               // --- and have muons from resonance decays in the wanted window --- 
-               if(nsec != 2) {
-                   printf(" AliMUON::StepManager: Strange resonance Decay into %d particles\n",nsec);
-                   gMC->StopEvent();
-               } else {
-                   gMC->GetSecondary(0,ipart,x,p);
-                   pt  = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
-                   th0 = TMath::ATan2(pt,p[2])*kRaddeg;
-                   gMC->GetSecondary(1,ipart,x,p);
-                   pt  = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
-                   th2 = TMath::ATan2(pt,p[2])*kRaddeg;
-                   if(!(fAccMin < th0 && th0 < fAccMax) ||
-                      !(fAccMin < th2 && th2 < fAccMax)) 
-                       gMC->StopEvent();
-               }
-           }
-       }
-    }
-    */
-}
 
-void AliMUON::MakePadHits(Float_t xhit,Float_t yhit,Float_t eloss, Int_t idvol)
+
+void AliMUON::MakePadHits(Float_t xhit,Float_t yhit,
+                         Float_t eloss, Float_t tof,  Int_t idvol)
 {
 //
 //  Calls the charge disintegration method of the current chamber and adds
@@ -694,8 +817,8 @@ void AliMUON::MakePadHits(Float_t xhit,Float_t yhit,Float_t eloss, Int_t idvol)
     clhits[0]=fNhits+1;
 //
 //
-    ((AliMUONchamber*) (*fChambers)[idvol])->DisIntegration(eloss, xhit, yhit, nnew, newclust);
-//    printf("\n Add new clusters %d %f \n", nnew, eloss*1.e9);
+    ((AliMUONChamber*) (*fChambers)[idvol])
+       ->DisIntegration(eloss, tof, xhit, yhit, nnew, newclust);
     Int_t ic=0;
     
 //
@@ -716,77 +839,76 @@ void AliMUON::MakePadHits(Float_t xhit,Float_t yhit,Float_t eloss, Int_t idvol)
 //  Pad: chamber sector
            clhits[6] = Int_t(newclust[4][i]);
            
-           AddCluster(clhits);
+           AddPadHit(clhits);
        }
     }
-//    printf("\n %d new clusters added", ic);
 }
 
-void AliMUON::Digitise(Int_t nev,Int_t bgr_ev,Option_t *option, Option_t *,Text_t *filename)
+//----------------------------------------------------------------------
+
+void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,Text_t *filename)
 {
     // keep galice.root for signal and name differently the file for 
     // background when add! otherwise the track info for signal will be lost !
   
     static Bool_t first=kTRUE;
-//    static TTree *TrH1;
-    static TFile *File;
-    char *Add = strstr(option,"Add");
-    //char *listoftracks = strstr(opt,"listoftracks");
+    static TFile *file;
+    char *addBackground = strstr(option,"Add");
 
-    AliMUONchamber*  iChamber;
-    AliMUONsegmentation*  segmentation;
+    AliMUONChamber*  iChamber;
+    AliMUONSegmentation*  segmentation;
 
     
     Int_t trk[50];
     Int_t chtrk[50];  
     TObjArray *list=new TObjArray;
-    static TClonesArray *p_adr=0;
-    if(!p_adr) p_adr=new TClonesArray("TVector",1000);
+    static TClonesArray *pAddress=0;
+    if(!pAddress) pAddress=new TClonesArray("TVector",1000);
     Int_t digits[5]; 
 
-    AliMUON *MUON  = (AliMUON *) gAlice->GetModule("MUON");
-    AliMUONHitMap * HitMap[10];
-    for (Int_t i=0; i<10; i++) {HitMap[i]=0;}
-    if (Add ) {
+    AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
+    AliMUONHitMap * hitMap[kNCH];
+    for (Int_t i=0; i<kNCH; i++) {hitMap[i]=0;}
+    if (addBackground ) {
        if(first) {
            fFileName=filename;
            cout<<"filename"<<fFileName<<endl;
-           File=new TFile(fFileName);
+           file=new TFile(fFileName);
            cout<<"I have opened "<<fFileName<<" file "<<endl;
-           fHits2     = new TClonesArray("AliMUONhit",1000  );
-           fClusters2 = new TClonesArray("AliMUONcluster",10000);
+           fHits2     = new TClonesArray("AliMUONHit",1000  );
+           fPadHits2 = new TClonesArray("AliMUONPadHit",10000);
        }           
        first=kFALSE;
-       File->cd();
-       //File->ls();
+       file->cd();
+       //file->ls();
        // Get Hits Tree header from file
        if(fHits2) fHits2->Clear();
-       if(fClusters2) fClusters2->Clear();
-       if(TrH1) delete TrH1;
-       TrH1=0;
+       if(fPadHits2) fPadHits2->Clear();
+       if(fTrH1) delete fTrH1;
+       fTrH1=0;
        
        char treeName[20];
-       sprintf(treeName,"TreeH%d",bgr_ev);
-       TrH1 = (TTree*)gDirectory->Get(treeName);
-        //printf("TrH1 %p of treename %s for event %d \n",TrH1,treeName,bgr_ev);
+       sprintf(treeName,"TreeH%d",bgrEvent);
+       fTrH1 = (TTree*)gDirectory->Get(treeName);
+        //printf("fTrH1 %p of treename %s for event %d \n",fTrH1,treeName,bgrEvent);
        
-       if (!TrH1) {
-           printf("ERROR: cannot find Hits Tree for event:%d\n",bgr_ev);
+       if (!fTrH1) {
+           printf("ERROR: cannot find Hits Tree for event:%d\n",bgrEvent);
        }
        // Set branch addresses
        TBranch *branch;
        char branchname[20];
        sprintf(branchname,"%s",GetName());
-       if (TrH1 && fHits2) {
-           branch = TrH1->GetBranch(branchname);
+       if (fTrH1 && fHits2) {
+           branch = fTrH1->GetBranch(branchname);
            if (branch) branch->SetAddress(&fHits2);
        }
-       if (TrH1 && fClusters2) {
-           branch = TrH1->GetBranch("MUONCluster");
-           if (branch) branch->SetAddress(&fClusters2);
+       if (fTrH1 && fPadHits2) {
+           branch = fTrH1->GetBranch("MUONCluster");
+           if (branch) branch->SetAddress(&fPadHits2);
        }
 // test
-       //Int_t ntracks1 =(Int_t)TrH1->GetEntries();
+       //Int_t ntracks1 =(Int_t)fTrH1->GetEntries();
        //printf("background - ntracks1 - %d\n",ntracks1);
     }
     //
@@ -796,82 +918,78 @@ void AliMUON::Digitise(Int_t nev,Int_t bgr_ev,Option_t *option, Option_t *,Text_
     Int_t countadr=0;
     for (int icat=0; icat<2; icat++) { 
        Int_t counter=0;
-       for (Int_t i =0; i<10; i++) {
-           iChamber=(AliMUONchamber*) (*fChambers)[i];
+       for (Int_t i =0; i<kNCH; i++) {
+           iChamber=(AliMUONChamber*) (*fChambers)[i];
            if (iChamber->Nsec()==1 && icat==1) {
                continue;
            } else {
-               segmentation=iChamber->GetSegmentationModel(icat+1);
+               segmentation=iChamber->SegmentationModel(icat+1);
            }
-           HitMap[i] = new AliMUONHitMapA1(segmentation, list);
+           hitMap[i] = new AliMUONHitMapA1(segmentation, list);
        }
        //printf("Start loop over tracks \n");     
 //
 //   Loop over tracks
 //
 
-       TTree *TH = gAlice->TreeH();
-       Int_t ntracks =(Int_t) TH->GetEntries();
-        //printf("signal - ntracks %d\n",ntracks);
-       Int_t nmuon[10]={0,0,0,0,0,0,0,0,0,0};
-       Float_t xhit[10][2];
-       Float_t yhit[10][2];
+       TTree *treeH = gAlice->TreeH();
+       Int_t ntracks =(Int_t) treeH->GetEntries();
+       Int_t nmuon[kNCH]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+       Float_t xhit[kNCH][2];
+       Float_t yhit[kNCH][2];
        
        for (Int_t track=0; track<ntracks; track++) {
            gAlice->ResetHits();
-           TH->GetEvent(track);
+           treeH->GetEvent(track);
            
 //
 //   Loop over hits
-           for(AliMUONhit* mHit=(AliMUONhit*)MUON->FirstHit(-1); 
+           for(AliMUONHit* mHit=(AliMUONHit*)pMUON->FirstHit(-1); 
                mHit;
-               mHit=(AliMUONhit*)MUON->NextHit()) 
+               mHit=(AliMUONHit*)pMUON->NextHit()) 
            {
                Int_t   nch   = mHit->fChamber-1;  // chamber number
-               if (nch >9) continue;
-               iChamber = &(MUON->Chamber(nch));
-               Int_t rmin = (Int_t)iChamber->RInner();
-               Int_t rmax = (Int_t)iChamber->ROuter();
+               if (nch > kNCH-1) continue;
+               iChamber = &(pMUON->Chamber(nch));
                 // new 17.07.99
-               if (Add) {
-
-                 if (mHit->fParticle == kMuonPlus || mHit->fParticle == kMuonMinus) {
-                   xhit[nch][nmuon[nch]]=mHit->fX;
-                   yhit[nch][nmuon[nch]]=mHit->fY;
-                   nmuon[nch]++;
-                    if (nmuon[nch] >2) printf("nmuon %d\n",nmuon[nch]);
-                   
-                 }
+               if (addBackground) {
+
+                   if (mHit->fParticle == kMuonPlus 
+                       || mHit->fParticle == kMuonMinus) {
+                       xhit[nch][nmuon[nch]]=mHit->fX;
+                       yhit[nch][nmuon[nch]]=mHit->fY;
+                       nmuon[nch]++;
+                       if (nmuon[nch] >2) printf("nmuon %d\n",nmuon[nch]);
+                   }
                }
-
+               
 
 
                
 //
 // Loop over pad hits
-               for (AliMUONcluster* mPad=
-                        (AliMUONcluster*)MUON->FirstPad(mHit,fClusters);
+               for (AliMUONPadHit* mPad=
+                        (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHits);
                     mPad;
-                    mPad=(AliMUONcluster*)MUON->NextPad(fClusters))
+                    mPad=(AliMUONPadHit*)pMUON->NextPad(fPadHits))
                {
                    Int_t cathode  = mPad->fCathode;    // cathode number
                    Int_t ipx      = mPad->fPadX;       // pad number on X
                    Int_t ipy      = mPad->fPadY;       // pad number on Y
-                   Int_t iqpad    = Int_t(mPad->fQpad*kScale);// charge per pad
-//                 Int_t iqpad    = mPad->fQpad;       // charge per pad
+                   Int_t iqpad    = Int_t(mPad->fQpad);// charge per pad
 //
 //
                    
                    if (cathode != (icat+1)) continue;
                    // fill the info array
                    Float_t thex, they;
-                   segmentation=iChamber->GetSegmentationModel(cathode);
+                   segmentation=iChamber->SegmentationModel(cathode);
                    segmentation->GetPadCxy(ipx,ipy,thex,they);
-                   Float_t rpad=TMath::Sqrt(thex*thex+they*they);
-                   if (rpad < rmin || iqpad ==0 || rpad > rmax) continue;
+//                 Float_t rpad=TMath::Sqrt(thex*thex+they*they);
+//                 if (rpad < rmin || iqpad ==0 || rpad > rmax) continue;
 
-                   new((*p_adr)[countadr++]) TVector(2);
-                   TVector &trinfo=*((TVector*) (*p_adr)[countadr-1]);
+                   new((*pAddress)[countadr++]) TVector(2);
+                   TVector &trinfo=*((TVector*) (*pAddress)[countadr-1]);
                    trinfo(0)=(Float_t)track;
                    trinfo(1)=(Float_t)iqpad;
 
@@ -879,41 +997,42 @@ void AliMUON::Digitise(Int_t nev,Int_t bgr_ev,Option_t *option, Option_t *,Text_
                    digits[1]=ipy;
                    digits[2]=iqpad;
                    digits[3]=iqpad;
-                   if (mHit->fParticle == kMuonPlus || mHit->fParticle == kMuonMinus) {
-                   digits[4]=mPad->fHitNumber;
+                   if (mHit->fParticle == kMuonPlus ||
+                       mHit->fParticle == kMuonMinus) {
+                       digits[4]=mPad->fHitNumber;
                    } else digits[4]=-1;
 
-                   AliMUONlist* pdigit;
+                   AliMUONTransientDigit* pdigit;
                    // build the list of fired pads and update the info
-                   if (!HitMap[nch]->TestHit(ipx, ipy)) {
+                   if (!hitMap[nch]->TestHit(ipx, ipy)) {
 
                        list->AddAtAndExpand(
-                           new AliMUONlist(nch,digits),counter);
+                           new AliMUONTransientDigit(nch,digits),counter);
                        
-                       HitMap[nch]->SetHit(ipx, ipy, counter);
+                       hitMap[nch]->SetHit(ipx, ipy, counter);
                        counter++;
-                       pdigit=(AliMUONlist*)list->At(list->GetLast());
+                       pdigit=(AliMUONTransientDigit*)list->At(list->GetLast());
                        // list of tracks
                        TObjArray *trlist=(TObjArray*)pdigit->TrackList();
                        trlist->Add(&trinfo);
                    } else {
-                       pdigit=(AliMUONlist*) HitMap[nch]->GetHit(ipx, ipy);
+                       pdigit=(AliMUONTransientDigit*) hitMap[nch]->GetHit(ipx, ipy);
                        // update charge
                        (*pdigit).fSignal+=iqpad;
                        (*pdigit).fPhysics+=iqpad;                      
                        // update list of tracks
                        TObjArray* trlist=(TObjArray*)pdigit->TrackList();
-                       Int_t last_entry=trlist->GetLast();
-                       TVector *ptrk_p=(TVector*)trlist->At(last_entry);
-                       TVector &ptrk=*ptrk_p;
-                       Int_t last_track=Int_t(ptrk(0));
-                       Int_t last_charge=Int_t(ptrk(1));
-                       if (last_track==track) {
-                           last_charge+=iqpad;
-                           trlist->RemoveAt(last_entry);
-                           trinfo(0)=last_track;
-                           trinfo(1)=last_charge;
-                           trlist->AddAt(&trinfo,last_entry);
+                       Int_t lastEntry=trlist->GetLast();
+                       TVector *pTrack=(TVector*)trlist->At(lastEntry);
+                       TVector &ptrk=*pTrack;
+                       Int_t lastTrack=Int_t(ptrk(0));
+                       Int_t lastCharge=Int_t(ptrk(1));
+                       if (lastTrack==track) {
+                           lastCharge+=iqpad;
+                           trlist->RemoveAt(lastEntry);
+                           trinfo(0)=lastTrack;
+                           trinfo(1)=lastCharge;
+                           trlist->AddAt(&trinfo,lastEntry);
                        } else {
                            trlist->Add(&trinfo);
                        }
@@ -921,8 +1040,8 @@ void AliMUON::Digitise(Int_t nev,Int_t bgr_ev,Option_t *option, Option_t *,Text_
                        Int_t nptracks=trlist->GetEntriesFast();
                        if (nptracks > 2) {
                            for (Int_t tr=0;tr<nptracks;tr++) {
-                               TVector *pptrk_p=(TVector*)trlist->At(tr);
-                               TVector &pptrk=*pptrk_p;
+                               TVector *ppTrack=(TVector*)trlist->At(tr);
+                               TVector &pptrk=*ppTrack;
                                trk[tr]=Int_t(pptrk(0));
                                chtrk[tr]=Int_t(pptrk(1));
                            }
@@ -931,34 +1050,29 @@ void AliMUON::Digitise(Int_t nev,Int_t bgr_ev,Option_t *option, Option_t *,Text_
                } //end loop over clusters
            } // hit loop
        } // track loop
-       
-       //Int_t nentr1=list->GetEntriesFast();
-       //printf(" \n counter, nentr1 %d %d\n",counter,nentr1);
 
        // open the file with background
        
-       if (Add ) {
-           ntracks =(Int_t)TrH1->GetEntries();
-           //printf("background - icat,ntracks1  %d %d\n",icat,ntracks);
-           //printf("background - Start loop over tracks \n");     
+       if (addBackground) {
+           ntracks =(Int_t)fTrH1->GetEntries();
 //
 //   Loop over tracks
 //
            for (Int_t track=0; track<ntracks; track++) {
 
                if (fHits2)       fHits2->Clear();
-               if (fClusters2)   fClusters2->Clear();
+               if (fPadHits2)   fPadHits2->Clear();
 
-               TrH1->GetEvent(track);
+               fTrH1->GetEvent(track);
 //
 //   Loop over hits
-               AliMUONhit* mHit;
+               AliMUONHit* mHit;
                for(int i=0;i<fHits2->GetEntriesFast();++i) 
-       {       
-                   mHit=(AliMUONhit*) (*fHits2)[i];
+               {       
+                   mHit=(AliMUONHit*) (*fHits2)[i];
                    Int_t   nch   = mHit->fChamber-1;  // chamber number
                    if (nch >9) continue;
-                   iChamber = &(MUON->Chamber(nch));
+                   iChamber = &(pMUON->Chamber(nch));
                    Int_t rmin = (Int_t)iChamber->RInner();
                    Int_t rmax = (Int_t)iChamber->ROuter();
                     Float_t xbgr=mHit->fX;
@@ -974,79 +1088,75 @@ void AliMUON::Digitise(Int_t nev,Int_t bgr_ev,Option_t *option, Option_t *,Text_
                    
 //
 // Loop over pad hits
-                   for (AliMUONcluster* mPad=
-                            (AliMUONcluster*)MUON->FirstPad(mHit,fClusters2);
+                   for (AliMUONPadHit* mPad=
+                            (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHits2);
                         mPad;
-                        mPad=(AliMUONcluster*)MUON->NextPad(fClusters2))
+                        mPad=(AliMUONPadHit*)pMUON->NextPad(fPadHits2))
                    {
-
+                       //                  mPad = (AliMUONPadHit*) (*fPadHits2)[j];
                        Int_t cathode  = mPad->fCathode;    // cathode number
                        Int_t ipx      = mPad->fPadX;       // pad number on X
                        Int_t ipy      = mPad->fPadY;       // pad number on Y
-                       Int_t iqpad    = Int_t(mPad->fQpad*kScale);// charge per pad
-//                     Int_t iqpad    = mPad->fQpad;       // charge per pad
+                       Int_t iqpad    = Int_t(mPad->fQpad);// charge per pad
 
                        if (cathode != (icat+1)) continue;
-                       //if (!HitMap[nch]->CheckBoundary()) continue;
-                       // fill the info array
                        Float_t thex, they;
-                       segmentation=iChamber->GetSegmentationModel(cathode);
+                       segmentation=iChamber->SegmentationModel(cathode);
                        segmentation->GetPadCxy(ipx,ipy,thex,they);
                        Float_t rpad=TMath::Sqrt(thex*thex+they*they);
                        if (rpad < rmin || iqpad ==0 || rpad > rmax) continue;
-
-                           new((*p_adr)[countadr++]) TVector(2);
-                           TVector &trinfo=*((TVector*) (*p_adr)[countadr-1]);
-                           trinfo(0)=-1;  // tag background
-                           trinfo(1)=-1;
-
+                       new((*pAddress)[countadr++]) TVector(2);
+                       TVector &trinfo=*((TVector*) (*pAddress)[countadr-1]);
+                       trinfo(0)=-1;  // tag background
+                       trinfo(1)=-1;
+                       
                        digits[0]=ipx;
                        digits[1]=ipy;
                        digits[2]=iqpad;
                        digits[3]=0;
                        digits[4]=-1;
-
-                       AliMUONlist* pdigit;
-                       // build the list of fired pads and update the info
-                       if (!HitMap[nch]->TestHit(ipx, ipy)) {
-                           list->AddAtAndExpand(new AliMUONlist(nch,digits),counter);
                        
-                           HitMap[nch]->SetHit(ipx, ipy, counter);
+                       AliMUONTransientDigit* pdigit;
+                       // build the list of fired pads and update the info
+                       if (!hitMap[nch]->TestHit(ipx, ipy)) {
+                           list->AddAtAndExpand(new AliMUONTransientDigit(nch,digits),counter);
+                           
+                           hitMap[nch]->SetHit(ipx, ipy, counter);
                            counter++;
                            
-                           pdigit=(AliMUONlist*)list->At(list->GetLast());
+                           pdigit=(AliMUONTransientDigit*)list->At(list->GetLast());
                            // list of tracks
-                               TObjArray *trlist=(TObjArray*)pdigit->
-                                                  TrackList();
-                               trlist->Add(&trinfo);
+                           TObjArray *trlist=(TObjArray*)pdigit->
+                               TrackList();
+                           trlist->Add(&trinfo);
                        } else {
-                           pdigit=(AliMUONlist*) HitMap[nch]->GetHit(ipx, ipy);
+                           pdigit=(AliMUONTransientDigit*) hitMap[nch]->GetHit(ipx, ipy);
                            // update charge
                            (*pdigit).fSignal+=iqpad;
-
+                           
                            // update list of tracks
-                               TObjArray* trlist=(TObjArray*)pdigit->
-                                                  TrackList();
-                               Int_t last_entry=trlist->GetLast();
-                               TVector *ptrk_p=(TVector*)trlist->
-                                                At(last_entry);
-                               TVector &ptrk=*ptrk_p;
-                               Int_t last_track=Int_t(ptrk(0));
-                               if (last_track==-1) {
-                                   continue;
-                               } else {
-                                   trlist->Add(&trinfo);
-                               }
+                           TObjArray* trlist=(TObjArray*)pdigit->
+                               TrackList();
+                           Int_t lastEntry=trlist->GetLast();
+                           TVector *pTrack=(TVector*)trlist->
+                               At(lastEntry);
+                           TVector &ptrk=*pTrack;
+                           Int_t lastTrack=Int_t(ptrk(0));
+                           if (lastTrack==-1) {
+                               continue;
+                           } else {
+                               trlist->Add(&trinfo);
+                           }
                                // check the track list
-                               Int_t nptracks=trlist->GetEntriesFast();
-                               if (nptracks > 0) {
-                                   for (Int_t tr=0;tr<nptracks;tr++) {
-                                       TVector *pptrk_p=(TVector*)trlist->At(tr);
-                                       TVector &pptrk=*pptrk_p;
-                                       trk[tr]=Int_t(pptrk(0));
-                                       chtrk[tr]=Int_t(pptrk(1));
-                                   }
-                               } // end if nptracks
+                           Int_t nptracks=trlist->GetEntriesFast();
+                           if (nptracks > 0) {
+                               for (Int_t tr=0;tr<nptracks;tr++) {
+                                   TVector *ppTrack=(TVector*)trlist->At(tr);
+                                   TVector &pptrk=*ppTrack;
+                                   trk[tr]=Int_t(pptrk(0));
+                                   chtrk[tr]=Int_t(pptrk(1));
+                               }
+                           } // end if nptracks
                        } //  end if pdigit
                    } //end loop over clusters
                } // hit loop
@@ -1054,114 +1164,96 @@ void AliMUON::Digitise(Int_t nev,Int_t bgr_ev,Option_t *option, Option_t *,Text_
            //Int_t nentr2=list->GetEntriesFast();
            //printf(" \n counter2, nentr2 %d %d \n",counter,nentr2);
            TTree *fAli=gAlice->TreeK();
-            TFile *file;
+            TFile *file=NULL;
            
            if (fAli) file =fAli->GetCurrentFile();
            file->cd();
-       } // if Add     
-
+       } // if addBackground   
+       
        Int_t tracks[10];
        Int_t charges[10];
-       //cout<<"start filling digits \n "<<endl;
-       //      const Float_t zero_supm =    6.;
        Int_t nentries=list->GetEntriesFast();
-       //printf(" \n \n nentries %d \n",nentries);
-       // start filling the digits
        
        for (Int_t nent=0;nent<nentries;nent++) {
-           AliMUONlist *address=(AliMUONlist*)list->At(nent);
+           AliMUONTransientDigit *address=(AliMUONTransientDigit*)list->At(nent);
            if (address==0) continue; 
            Int_t ich=address->fChamber;
            Int_t q=address->fSignal; 
-           iChamber=(AliMUONchamber*) (*fChambers)[ich];
-           AliMUONresponse * response=iChamber->GetResponseModel();
-           Int_t adcmax= (Int_t) response->MaxAdc();
-           // add white noise and do zero-suppression and signal truncation
-           Float_t MeanNoise = gRandom->Gaus(1, 0.2);
-           Float_t Noise     = gRandom->Gaus(0, MeanNoise);
-           q+=(Int_t)Noise; 
-           if (address->fPhysics !=0 ) address->fPhysics+=(Int_t)Noise; 
-           if ( q <= zero_supm ) continue;
-           if ( q > adcmax)  q=adcmax;
+           iChamber=(AliMUONChamber*) (*fChambers)[ich];
+//
+//  Digit Response (noise, threshold, saturation, ...)
+//             if (address->fPhysics !=0 ) address->fPhysics+=(Int_t)Noise; 
+           AliMUONResponse * response=iChamber->ResponseModel();
+           q=response->DigitResponse(q);
+           
+           if (!q) continue;
+           
            digits[0]=address->fPadX;
            digits[1]=address->fPadY;
            digits[2]=q;
            digits[3]=address->fPhysics;
            digits[4]=address->fHit;
-            //printf("fSignal, fPhysics fTrack %d %d %d \n",digits[2],digits[3],digits[4]);
            
            TObjArray* trlist=(TObjArray*)address->TrackList();
            Int_t nptracks=trlist->GetEntriesFast();
            //printf("nptracks, trlist   %d  %p\n",nptracks,trlist);
 
-               // this was changed to accomodate the real number of tracks
-               if (nptracks > 10) {
-                   cout<<"Attention - nptracks > 10 "<<nptracks<<endl;
-                   nptracks=10;
-               }
-               if (nptracks > 2) {
-                   printf("Attention - nptracks > 2  %d \n",nptracks);
-                   printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,digits[0],digits[1],q);
-               }
-               for (Int_t tr=0;tr<nptracks;tr++) {
-                   TVector *pp_p=(TVector*)trlist->At(tr);
-                   if(!pp_p ) printf("pp_p - %p\n",pp_p);
-                   TVector &pp  =*pp_p;
-                   tracks[tr]=Int_t(pp(0));
-                   charges[tr]=Int_t(pp(1));
+           // this was changed to accomodate the real number of tracks
+           if (nptracks > 10) {
+               cout<<"Attention - nptracks > 10 "<<nptracks<<endl;
+               nptracks=10;
+           }
+           if (nptracks > 2) {
+               printf("Attention - nptracks > 2  %d \n",nptracks);
+               printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,digits[0],digits[1],q);
+           }
+           for (Int_t tr=0;tr<nptracks;tr++) {
+               TVector *ppP=(TVector*)trlist->At(tr);
+               if(!ppP ) printf("ppP - %p\n",ppP);
+               TVector &pp  =*ppP;
+               tracks[tr]=Int_t(pp(0));
+               charges[tr]=Int_t(pp(1));
                 //printf("tracks, charges - %d %d\n",tracks[tr],charges[tr]);
-               }      //end loop over list of tracks for one pad
+           }      //end loop over list of tracks for one pad
             // Sort list of tracks according to charge
-               if (nptracks > 1) {
-                   SortTracks(tracks,charges,nptracks);
-               }
-               if (nptracks < 10 ) {
-                   for (Int_t i=nptracks; i<10; i++) {
-                       tracks[i]=0;
-                       charges[i]=0;
-                   }
+           if (nptracks > 1) {
+               SortTracks(tracks,charges,nptracks);
+           }
+           if (nptracks < 10 ) {
+               for (Int_t i=nptracks; i<10; i++) {
+                   tracks[i]=0;
+                   charges[i]=0;
                }
-
+           }
+           
            // fill digits
-           MUON->AddDigits(ich,tracks,charges,digits);
+           pMUON->AddDigits(ich,tracks,charges,digits);
+           // delete trlist;
        }
        //cout<<"I'm out of the loops for digitisation"<<endl;
+       //      gAlice->GetEvent(nev);
        gAlice->TreeD()->Fill();
-       TTree *TD=gAlice->TreeD();
-
-       Stat_t ndig=TD->GetEntries();
-       cout<<"number of digits  "<<ndig<<endl;
-       TClonesArray *fDch;
-       for (int k=0;k<10;k++) {
-           fDch= MUON->DigitsAddress(k);
-           int ndig=fDch->GetEntriesFast();
-           printf (" i, ndig %d %d \n",k,ndig);
-       }
-
-       MUON->ResetDigits();
+       pMUON->ResetDigits();
        list->Delete();
-       for(Int_t ii=0;ii<10;++ii) {
-           if (HitMap[ii]) {
-               hm=HitMap[ii];
+       
+       for(Int_t ii=0;ii<kNCH;++ii) {
+           if (hitMap[ii]) {
+               hm=hitMap[ii];
                delete hm;
-               HitMap[ii]=0;
+               hitMap[ii]=0;
            }
        }
-       
     } //end loop over cathodes
-
-       char hname[30];
-       sprintf(hname,"TreeD%d",nev);
-       gAlice->TreeD()->Write(hname);
-       // reset tree
-       gAlice->TreeD()->Reset();
-       delete list;
-       //Int_t nadr=p_adr->GetEntriesFast();
-       // printf(" \n \n nadr %d \n",nadr);
-
-       p_adr->Clear();
-       // gObjectTable->Print();
-       
+    
+    char hname[30];
+    sprintf(hname,"TreeD%d",nev);
+    gAlice->TreeD()->Write(hname);
+    // reset tree
+    gAlice->TreeD()->Reset();
+    delete list;
+    
+    pAddress->Delete();
+    // gObjectTable->Print();
 }
 
 void AliMUON::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
@@ -1219,495 +1311,229 @@ void AliMUON::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
 
 }
 
-void AliMUON::FindClusters(Int_t nev,Int_t last_entry)
-{
-
-//
-// Loop on chambers and on cathode planes
-//
-  for (Int_t icat=0;icat<2;icat++) {
-           gAlice->ResetDigits();
-           gAlice->TreeD()->GetEvent(last_entry+icat); // spurious +1 ...
-           if (nev < 10) printf("last_entry , icat - %d %d \n",last_entry,icat);
-           //gAlice->TreeD()->GetEvent(icat+1); // spurious +1 ...
-
-      for (Int_t ich=0;ich<10;ich++) {
-         AliMUONchamber* iChamber=(AliMUONchamber*) (*fChambers)[ich];
-         TClonesArray *MUONdigits  = this->DigitsAddress(ich);
-         if (MUONdigits == 0) continue;
-          //
-         // Get ready the current chamber stuff
-         //
-         AliMUONresponse* response = iChamber->GetResponseModel();
-         AliMUONsegmentation*  seg = iChamber->GetSegmentationModel(icat+1);
-         AliMUONClusterFinder* rec = iChamber->GetReconstructionModel();
-         //printf("icat, ich, seg - %d %d %p\n",icat,ich,seg);
-         if (seg) {      
-             rec->SetSegmentation(seg);
-             rec->SetResponse(response);
-             rec->SetDigits(MUONdigits);
-             rec->SetChamber(ich);
-             if (nev==0) rec->CalibrateCOG(); 
-             rec->FindRawClusters();
-         }  
-          //printf("Finish FindRawClusters for cathode %d in chamber %d\n",icat,ich);
-         
-          TClonesArray *fRch;
-         fRch=RawClustAddress(ich);
-         fRch->Sort();
-          // it seems to work 
-         
-
-      } // for ich
-      // fill the tree
-      TTree *TR=gAlice->TreeR();
-
-      gAlice->TreeR()->Fill();
-
-      Stat_t nent=TR->GetEntries();
-      cout<<"number of entries  "<<nent<<endl;
-      TClonesArray *fRch;
-      for (int i=0;i<10;i++) {
-         fRch=RawClustAddress(i);
-         int nraw=fRch->GetEntriesFast();
-         printf (" i, nraw %d %d \n",i,nraw);
+//___________________________________________
+void AliMUON::Trigger(Int_t nev){
+// call the Trigger Algorithm and fill TreeR
+
+  Int_t singlePlus[3]  = {0,0,0}; 
+  Int_t singleMinus[3] = {0,0,0}; 
+  Int_t singleUndef[3] = {0,0,0};
+  Int_t pairUnlike[3]  = {0,0,0}; 
+  Int_t pairLike[3]    = {0,0,0};
+
+  ResetTrigger();
+
+  AliMUONTriggerDecision* decision= new AliMUONTriggerDecision(1);
+  decision->Trigger();   
+  decision->GetGlobalTrigger(singlePlus, singleMinus, singleUndef,
+                            pairUnlike, pairLike);
+// add a local trigger in the list 
+  AddGlobalTrigger(singlePlus, singleMinus, singleUndef, pairUnlike, pairLike);
+  
+  for (Int_t icirc=0; icirc<kNTriggerCircuit; icirc++) { 
+    if(decision->GetITrigger(icirc)==1) {
+      Int_t localtr[7]={0,0,0,0,0,0,0};      
+      Int_t loLpt[2]={0,0}; Int_t loHpt[2]={0,0}; Int_t loApt[2]={0,0};
+      decision->GetLutOutput(icirc, loLpt, loHpt, loApt);
+      localtr[0] = icirc;
+      localtr[1] = decision->GetStripX11(icirc);
+      localtr[2] = decision->GetDev(icirc);
+      localtr[3] = decision->GetStripY11(icirc);
+      for (Int_t i=0; i<2; i++) {    // convert the Lut output in 1 digit 
+       localtr[4] = localtr[4]+Int_t(loLpt[i]*pow(2,i));
+       localtr[5] = localtr[5]+Int_t(loHpt[i]*pow(2,i));
+       localtr[6] = localtr[6]+Int_t(loApt[i]*pow(2,i));
       }
-      ResetRawClusters();
-
-  } // for icat
+      //      cout << loApt[0] << " , " << loApt[1] << " , " << localtr[6] << "\n";
+      AddLocalTrigger(localtr);  // add a local trigger in the list
+    }
+  }
+  delete decision;
 
+  gAlice->TreeR()->Fill();
+  ResetTrigger();
   char hname[30];
   sprintf(hname,"TreeR%d",nev);
   gAlice->TreeR()->Write(hname);
   gAlice->TreeR()->Reset();
-
-  //gObjectTable->Print();
-
+  printf("\n End of trigger for event %d", nev);
 }
-//______________________________________________________________________________
-//_____________________________________________________________________________ 
-void AliMUON::CathodeCorrelation(Int_t nev)
-{
-
-// Correlates the clusters on the two cathode planes and build a list of
-// other possible combinations (potential ghosts) - for the moment use the
-// criteria of minimum distance between the CoGs of the two correlated
-// clusters
-
-
-//
-// Loop on chambers and on clusters on the cathode plane with the highest
-// number of clusters
-
-    static Bool_t first=kTRUE;
 
-     AliMUONRawCluster  *mRaw1;
-     AliMUONRawCluster  *mRaw2;
-     AliMUONchamber     *iChamber;
-     AliMUONsegmentation *seg;
-     TArrayF x1, y1, x2, y2, q1, q2;
-     x1.Set(5000);
-     x2.Set(5000);     
-     y1.Set(5000);
-     y2.Set(5000);     
-     q1.Set(5000);
-     q2.Set(5000);     
-     
-// Get pointers to Alice detectors and Digits containers
-     TTree *TR = gAlice->TreeR();
-     Int_t nent=(Int_t)TR->GetEntries();
-     if (nev < 10) printf("Found %d entries in the tree (must be one per cathode per event! + 1empty)\n",nent);
-  
 
-     Int_t idx[4]; 
-     Float_t xc2[4],yc2[4];
-     Float_t xrec2, yrec2;
-     Float_t xd0, xdif, ydif;
-     Float_t ysrch,xd,xmax,ymax;
-     Int_t ilow, iup, iraw1, i;
-     //
-     Float_t xarray[50];
-     Float_t xdarray[50];
-     Float_t yarray[50];
-     Float_t qarray[50];
-     Int_t idx2[50];
-
-     // Int_t nraw[2], entry,cathode;
-
-     for (i=0;i<50;i++) {
-         xdarray[i]=1100.;
-         xarray[i]=0.;
-         yarray[i]=0.;
-         qarray[i]=0.;
-         idx2[i]=-1;
-     }
-     for (i=0;i<4;i++) {
-          idx[i]=-1;
-          xc2[i]=0.;
-          yc2[i]=0.;
-     }
-
-     // access to the Raw Clusters tree
-     for (Int_t ich=0;ich<10;ich++) {
-        iChamber = &(Chamber(ich));
-        TClonesArray *MUONrawclust  = RawClustAddress(ich);
-        ResetRawClusters();
-        TR->GetEvent(nent-2);
-        //TR->GetEvent(1);
-        Int_t nrawcl1 = MUONrawclust->GetEntries();
-        // printf("Found %d raw clusters for cathode 1 in chamber %d \n"
-        //      ,nrawcl1,ich+1);
-         if (!nrawcl1) continue;
-
-        seg = iChamber->GetSegmentationModel(1);
-         // loop over raw clusters of first cathode
-        for (iraw1=0; iraw1<nrawcl1; iraw1++) {
-                mRaw1= (AliMUONRawCluster*)MUONrawclust->UncheckedAt(iraw1);
-                x1[iraw1]=mRaw1->fX;
-                y1[iraw1]=mRaw1->fY;
-                q1[iraw1]=(Float_t)mRaw1->fQ; //maybe better fPeakSignal
-        } // rawclusters cathode 1
+//____________________________________________
+void AliMUON::FindClusters(Int_t nev,Int_t lastEntry)
+{
+    TClonesArray *dig1, *dig2;
+    Int_t ndig, k;
+    dig1 = new TClonesArray("AliMUONDigit",1000);
+    dig2 = new TClonesArray("AliMUONDigit",1000);
+    AliMUONDigit *digit;
 //
-         // Get information from 2nd cathode
-        ResetRawClusters();
-        TR->GetEvent(nent-1);
-        //TR->GetEvent(2);
-        Int_t nrawcl2 = MUONrawclust->GetEntries();
-        if (!nrawcl2) {
-            for (iraw1=0; iraw1<nrawcl1; iraw1++) {
-                idx[3]=iraw1;
-                xc2[3]=x1[iraw1];
-                yc2[3]=y1[iraw1];
-                 //printf("nrawcl2 is zero - idx[0] %d\n",idx[0]);
-                
-                AddCathCorrel(ich,idx,xc2,yc2);
-                // reset
-                idx[3]=-1;
-                xc2[3]=0.;
-                yc2[3]=0.;
-                
-            } // store information from cathode 1 only 
-        } else {
-          //  printf("Found %d raw clusters for cathode 2 in chamber %d \n",
-          // nrawcl2, ich+1);
-
-            for (Int_t iraw2=0; iraw2<nrawcl2; iraw2++) {
-                mRaw2= (AliMUONRawCluster*)MUONrawclust->UncheckedAt(iraw2);
-                x2[iraw2]=mRaw2->fX;
-                y2[iraw2]=mRaw2->fY;   
-                q2[iraw2]=(Float_t)mRaw2->fQ;  
-            } // rawclusters cathode 2
+// Loop on chambers and on cathode planes
 //
-// Initalisation finished
-            for (iraw1=0; iraw1<nrawcl1; iraw1++) {
-            // find the sector
-                 Int_t ix,iy;
-                 seg->GetPadIxy(x1[iraw1],y1[iraw1],ix,iy);   
-                 Int_t isec=seg->Sector(ix,iy);
-                // range to look for ghosts ?!
-                 if (ich < 5) {
-                    ymax = seg->Dpy(isec)*7/2;
-                    xmax = seg->Dpx(isec)*7/2;
-                 } else {
-                    ymax = seg->Dpy(isec)*13/2;
-                    xmax = seg->Dpx(isec)*3/2;
-                }
-                ysrch=ymax+y1[iraw1];
-                
-                ilow = AliMUONRawCluster::
-                    BinarySearch(ysrch-2*ymax,y2,0,nrawcl2+1);
-                iup=   AliMUONRawCluster::
-                    BinarySearch(ysrch,y2,ilow,nrawcl2+1);
-                if (ilow<0 || iup <0 || iup>nrawcl2) continue;
-                Int_t counter=0;
-                for (Int_t iraw2=ilow; iraw2<=iup; iraw2++) {
-                    xrec2=x2[iraw2];
-                    yrec2=y2[iraw2];   
-                    xdif=x1[iraw1]-xrec2;
-                    ydif=y1[iraw1]-yrec2;
-                    xd=TMath::Sqrt(xdif*xdif+ydif*ydif);
-                    if (iraw2==ilow) { 
-                        if (ilow==iup) 
-                            xd0=TMath::
-                            Sqrt(2*xmax*2*xmax+2*ymax*2*ymax);
-                        else xd0=101.; 
-                    } 
-                     Float_t qdif=TMath::Abs(q1[iraw1]-q2[iraw2])/q1[iraw1];
-                    
-                    if (x1[iraw1]*xrec2 > 0) {
-                        if (xd <= xd0 )  {
-//                          printf("q1, q2 qdif % f %f %f \n",q1[iraw1],q2[iraw2],qdif);
-//                          printf("x1, x2 y1 y2 % f %f %f %f \n",x1[iraw1],xrec2,y1[iraw1],yrec2);
-                          //if (qdif <0.3) { //check this number
-                                
-                                xd0=xd;
-                                idx2[counter]=iraw2;
-                                xdarray[counter]=xd;
-                                xarray[counter]=xdif;
-                                yarray[counter]=ydif;
-                                qarray[counter]=qdif;
-                                counter++;
-                          // }
-                            
-                        }
-                    } // check for same quadrant
-                 } // loop over 2nd cathode range 
-                
-                
-                 if (counter >=2) {
-                    AliMUONRawCluster::
-                        SortMin(idx2,xdarray,xarray,yarray,qarray,counter);
-                    if (xdarray[0]<seg->Dpx(isec) && xdarray[1]<seg->Dpx(isec)) {
-                        if (qarray[0]>qarray[1]){
-                            Int_t swap=idx2[0];
-                            idx2[0]=idx2[1];
-                            idx2[1]=swap;
-                        }
-                    }
-                }
-                 int imax;
-                 if (counter <3) imax=counter;
-                 else imax=3;
-
-                 for (int i=0;i<imax;i++) {
-                    if (idx2[i] >= 0 && idx2[i] < nrawcl2) {
-                        if (xarray[i] > xmax || yarray[i] > 2*ymax) 
-                            continue;
-                        idx[i]=idx2[i];
-                        xc2[i]=x2[idx2[i]];
-                        yc2[i]=y2[idx2[i]];
-                    }
-                }
-                 // add info about the cluster on the 'starting' cathode
-
-                 idx[3]=iraw1;
-                 xc2[3]=x1[iraw1];
-                 yc2[3]=y1[iraw1];
-                //if (idx[0] <0)  printf("iraw1 imax idx2[0] idx[0] %d %d %d %d\n",iraw1,imax,idx2[0],idx[0]);
-                 AddCathCorrel(ich,idx,xc2,yc2);
-                // reset
-                 for (Int_t ii=0;ii<counter;ii++) {
-                    xdarray[ii]=1100.;
-                    xarray[ii]=0.;
-                    yarray[ii]=0.;
-                    qarray[ii]=0.;
-                    idx2[ii]=-1;
-                }
-                 for (Int_t iii=0;iii<3;iii++) {
-                    idx[iii]=-1;
-                    xc2[iii]=0.;
-                    yc2[iii]=0.;
-                }
-            } // iraw1
-        }
-        x1.Reset();
-        x2.Reset();     
-        y1.Reset();
-        y2.Reset();     
-        q1.Reset();
-        q2.Reset();     
-     } //ich
-// 
-     if (first) {
-         MakeTreeC("C");
-         first=kFALSE;
-     }
-     TTree *TC=TreeC();
-     TC->Fill();
-     //Int_t nentries=(Int_t)TC->GetEntries();
-    //cout<<"number entries in tree of correlated clusters  "<<nentries<<endl;
-     TClonesArray *fCch;
-     static Int_t countev=0;
-     Int_t countch=0;
-
-     for (Int_t ii=0;ii<10;ii++) {
-          fCch= CathCorrelAddress(ii);
-          Int_t ncor=fCch->GetEntriesFast();
-          printf (" ii, ncor %d %d \n",ii,ncor);
-           if (ncor>=2) countch++;
-     }
-
-     // write
-     char hname[30];
-     sprintf(hname,"TreeC%d",nev);
-     TC->Write(hname);
-     // reset tree
-     ResetCorrelation();
-     TC->Reset();
-
-     if (countch==10) countev++;
-     printf("countev - %d\n",countev);
     
-//     gObjectTable->Print();
-     
-     
-}
-
-
-//_____________________________________________________________________________
-
-void AliMUON::MakeTreeC(Option_t *option)
-{
-     char *C = strstr(option,"C");
-     if (C && !fTreeC) fTreeC = new TTree("TC","CathodeCorrelation");
-
-//  Create a branch for correlation 
-
-     const Int_t buffersize = 4000;
-     char branchname[30];
-
-// one branch for correlation per chamber
-     for (int i=0; i<10 ;i++) {
-         sprintf(branchname,"%sCorrelation%d",GetName(),i+1);
-      
-         if (fCathCorrel   && fTreeC) {
-           TreeC()->Branch(branchname,&((*fCathCorrel)[i]), buffersize);
-           printf("Making Branch %s for correlation in chamber %d\n",branchname,i+1);
-         }     
-     }
-}
-
-//_____________________________________________________________________________
-void AliMUON::GetTreeC(Int_t event)
-{
-
-    // set the branch address
-    char treeName[20];
-    char branchname[30];
-
-    ResetCorrelation();
-    if (fTreeC) {
-         delete fTreeC;
-    }
-
-    sprintf(treeName,"TreeC%d",event);
-    fTreeC = (TTree*)gDirectory->Get(treeName);
-
-
-    TBranch *branch;
-    if (fTreeC) {
-       for (int i=0; i<10; i++) {
-           sprintf(branchname,"%sCorrelation%d",GetName(),i+1);
-           if (fCathCorrel) {
-               branch = fTreeC->GetBranch(branchname);
-               if (branch) branch->SetAddress(&((*fCathCorrel)[i]));
-           }
+    for (Int_t ich=0;ich<10;ich++) {
+       AliMUONChamber* iChamber=(AliMUONChamber*) (*fChambers)[ich];
+       AliMUONClusterFinder* rec = iChamber->ReconstructionModel();    
+       gAlice->ResetDigits();
+       gAlice->TreeD()->GetEvent(lastEntry);
+       TClonesArray *muonDigits  = this->DigitsAddress(ich);
+       ndig=muonDigits->GetEntriesFast();
+       printf("\n 1 Found %d digits in %p %d", ndig, muonDigits,ich);
+       TClonesArray &lhits1 = *dig1;
+       Int_t n=0;
+       for (k=0; k<ndig; k++) {
+           digit=(AliMUONDigit*) muonDigits->UncheckedAt(k);
+           if (rec->TestTrack(digit->fTracks[0]))
+               new(lhits1[n++]) AliMUONDigit(*digit);
+       }
+       gAlice->ResetDigits();
+       gAlice->TreeD()->GetEvent(lastEntry+1);
+       muonDigits  = this->DigitsAddress(ich);
+       ndig=muonDigits->GetEntriesFast();
+       printf("\n 2 Found %d digits in %p %d", ndig, muonDigits, ich);
+       TClonesArray &lhits2 = *dig2;
+       n=0;
+       
+       for (k=0; k<ndig; k++) {
+           digit= (AliMUONDigit*) muonDigits->UncheckedAt(k);
+           if (rec->TestTrack(digit->fTracks[0]))
+           new(lhits2[n++]) AliMUONDigit(*digit);
        }
-    } else {
-       printf("ERROR: cannot find CathodeCorrelation Tree for event:%d\n",event);
-    }
-
-    // gObjectTable->Print();
 
+       if (rec) {        
+           rec->SetDigits(dig1, dig2);
+           rec->SetChamber(ich);
+           rec->FindRawClusters();
+       }
+       dig1->Delete();
+       dig2->Delete();
+    } // for ich
+    gAlice->TreeR()->Fill();
+    ResetRawClusters();
+    char hname[30];
+    sprintf(hname,"TreeR%d",nev);
+    gAlice->TreeR()->Write(hname);
+    gAlice->TreeR()->Reset();
+    printf("\n End of cluster finding for event %d", nev);
+    
+    delete dig1;
+    delete dig2;
+    //gObjectTable->Print();
 }
-
 
 void AliMUON::Streamer(TBuffer &R__b)
 {
    // Stream an object of class AliMUON.
-      AliMUONchamber       *iChamber;
-      AliMUONsegmentation  *segmentation;
-      AliMUONresponse      *response;
+      AliMUONChamber       *iChamber;
+      AliMUONTriggerCircuit *iTriggerCircuit;
+      AliMUONSegmentation  *segmentation;
+      AliMUONResponse      *response;
       TClonesArray         *digitsaddress;
       TClonesArray         *rawcladdress;
-      TClonesArray         *corcladdress;
-      //      TObjArray            *clustaddress;
       
    if (R__b.IsReading()) {
       Version_t R__v = R__b.ReadVersion(); if (R__v) { }
       AliDetector::Streamer(R__b);
-      R__b >> fNclusters;
-      R__b >> fClusters; // diff
+      R__b >> fNPadHits;
+      R__b >> fPadHits; // diff
+      R__b >> fNLocalTrigger;       
+      R__b >> fLocalTrigger;       
+      R__b >> fNGlobalTrigger;       
+      R__b >> fGlobalTrigger;   
       R__b >> fDchambers;
       R__b >> fRawClusters;
-      R__b >> fCathCorrel;
       R__b.ReadArray(fNdch);
       R__b.ReadArray(fNrawch);
-      R__b.ReadArray(fNcorch);
-      //
       R__b >> fAccCut;
       R__b >> fAccMin;
       R__b >> fAccMax; 
-      //   
-      // modifs perso  
-      R__b >> fSPxzCut;  
-      R__b >> fSSigmaCut;
-      R__b >> fSXPrec; 
-      R__b >> fSYPrec;
-      //
       R__b >> fChambers;
+      R__b >> fTriggerCircuits;
+      for (Int_t i =0; i<kNTriggerCircuit; i++) {
+       iTriggerCircuit=(AliMUONTriggerCircuit*) (*fTriggerCircuits)[i];
+       iTriggerCircuit->Streamer(R__b);
+      }
 // Stream chamber related information
-      for (Int_t i =0; i<10; i++) {
-         iChamber=(AliMUONchamber*) (*fChambers)[i];
+      for (Int_t i =0; i<kNCH; i++) {
+         iChamber=(AliMUONChamber*) (*fChambers)[i];
          iChamber->Streamer(R__b);
          if (iChamber->Nsec()==1) {
-             segmentation=iChamber->GetSegmentationModel(1);
+             segmentation=iChamber->SegmentationModel(1);
+             if (segmentation)
              segmentation->Streamer(R__b);
          } else {
-             segmentation=iChamber->GetSegmentationModel(1);
+             segmentation=iChamber->SegmentationModel(1);
+             if (segmentation)
              segmentation->Streamer(R__b);
-             segmentation=iChamber->GetSegmentationModel(2);
+             if (segmentation)
+             segmentation=iChamber->SegmentationModel(2);
              segmentation->Streamer(R__b);
          }
-          response=iChamber->GetResponseModel();
+          response=iChamber->ResponseModel();
+         if (response)
          response->Streamer(R__b);       
          digitsaddress=(TClonesArray*) (*fDchambers)[i];
          digitsaddress->Streamer(R__b);
-         rawcladdress=(TClonesArray*) (*fRawClusters)[i];
-         rawcladdress->Streamer(R__b);
-         corcladdress=(TClonesArray*) (*fCathCorrel)[i];
-         corcladdress->Streamer(R__b);
+         if (i < kNTrackingCh) {
+             rawcladdress=(TClonesArray*) (*fRawClusters)[i];
+             rawcladdress->Streamer(R__b);
+         }
       }
       
    } else {
       R__b.WriteVersion(AliMUON::IsA());
       AliDetector::Streamer(R__b);
-      R__b << fNclusters;
-      R__b << fClusters; // diff
+      R__b << fNPadHits;
+      R__b << fPadHits; // diff
+      R__b << fNLocalTrigger;       
+      R__b << fLocalTrigger;       
+      R__b << fNGlobalTrigger;       
+      R__b << fGlobalTrigger; 
       R__b << fDchambers;
       R__b << fRawClusters;
-      R__b << fCathCorrel;
-      R__b.WriteArray(fNdch, 10);
-      R__b.WriteArray(fNrawch, 10);
-      R__b.WriteArray(fNcorch, 10);
-      //
+      R__b.WriteArray(fNdch, kNCH);
+      R__b.WriteArray(fNrawch, kNTrackingCh);
+
       R__b << fAccCut;
       R__b << fAccMin;
       R__b << fAccMax; 
-      //   
-      // modifs perso  
-      R__b << fSPxzCut;  
-      R__b << fSSigmaCut;
-      R__b << fSXPrec; 
-      R__b << fSYPrec;
-      //
+
       R__b << fChambers;
-//  Stream chamber related information
-      for (Int_t i =0; i<10; i++) {
-         iChamber=(AliMUONchamber*) (*fChambers)[i];
+      R__b << fTriggerCircuits;
+      for (Int_t i =0; i<kNTriggerCircuit; i++) {
+       iTriggerCircuit=(AliMUONTriggerCircuit*) (*fTriggerCircuits)[i];
+       iTriggerCircuit->Streamer(R__b);
+      }
+      for (Int_t i =0; i<kNCH; i++) {
+         iChamber=(AliMUONChamber*) (*fChambers)[i];
          iChamber->Streamer(R__b);
          if (iChamber->Nsec()==1) {
-             segmentation=iChamber->GetSegmentationModel(1);
+             segmentation=iChamber->SegmentationModel(1);
+             if (segmentation)
              segmentation->Streamer(R__b);
          } else {
-             segmentation=iChamber->GetSegmentationModel(1);
+             segmentation=iChamber->SegmentationModel(1);
+             if (segmentation)
              segmentation->Streamer(R__b);
-             segmentation=iChamber->GetSegmentationModel(2);
+             segmentation=iChamber->SegmentationModel(2);
+             if (segmentation)
              segmentation->Streamer(R__b);
          }
-          response=iChamber->GetResponseModel();
+          response=iChamber->ResponseModel();
+         if (response)
          response->Streamer(R__b);
          digitsaddress=(TClonesArray*) (*fDchambers)[i];
          digitsaddress->Streamer(R__b);
-         rawcladdress=(TClonesArray*) (*fRawClusters)[i];
-         rawcladdress->Streamer(R__b);
-         corcladdress=(TClonesArray*) (*fCathCorrel)[i];
-         corcladdress->Streamer(R__b);
+         if (i < kNTrackingCh) {
+             rawcladdress=(TClonesArray*) (*fRawClusters)[i];
+             rawcladdress->Streamer(R__b);
+         }
       }
    }
 }
-AliMUONcluster* AliMUON::FirstPad(AliMUONhit*  hit, TClonesArray *clusters) 
+AliMUONPadHit* AliMUON::FirstPad(AliMUONHit*  hit, TClonesArray *clusters) 
 {
 //
     // Initialise the pad iterator
@@ -1715,1496 +1541,50 @@ AliMUONcluster* AliMUON::FirstPad(AliMUONhit*  hit, TClonesArray *clusters)
     TClonesArray *theClusters = clusters;
     Int_t nclust = theClusters->GetEntriesFast();
     if (nclust && hit->fPHlast > 0) {
-       sMaxIterPad=hit->fPHlast;
-       sCurIterPad=hit->fPHfirst;
-       return (AliMUONcluster*) clusters->UncheckedAt(sCurIterPad-1);
+       AliMUON::fMaxIterPad=hit->fPHlast;
+       AliMUON::fCurIterPad=hit->fPHfirst;
+       return (AliMUONPadHit*) clusters->UncheckedAt(AliMUON::fCurIterPad-1);
     } else {
        return 0;
     }
 }
 
-AliMUONcluster* AliMUON::NextPad(TClonesArray *clusters) 
+AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters) 
 {
-    sCurIterPad++;
-    if (sCurIterPad <= sMaxIterPad) {
-       return (AliMUONcluster*) clusters->UncheckedAt(sCurIterPad-1);
+    AliMUON::fCurIterPad++;
+    if (AliMUON::fCurIterPad <= AliMUON::fMaxIterPad) {
+       return (AliMUONPadHit*) clusters->UncheckedAt(AliMUON::fCurIterPad-1);
     } else {
        return 0;
     }
 }
 
-//////////////////////////// modifs perso ///////////////
-
-static TTree *ntuple_global;
-static TFile *hfile_global;
-
-// variables of the tracking ntuple 
-struct { 
-  Int_t ievr;           // number of event 
-  Int_t ntrackr;        // number of tracks per event
-  Int_t istatr[500];    // 1 = good muon, 2 = ghost, 0 = something else
-  Int_t isignr[500];    // sign of the track
-  Float_t pxr[500];     // x momentum of the reconstructed track
-  Float_t pyr[500];     // y momentum of the reconstructed track
-  Float_t pzr[500];     // z momentum of the reconstructed track
-  Float_t zvr[500];     // z vertex 
-  Float_t chi2r[500];   // chi2 of the fit of the track with the field map
-  Float_t pxv[500];     // x momentum at vertex
-  Float_t pyv[500];     // y momentum at vertex
-  Float_t pzv[500];     // z momentum at vertex
-} ntuple_st;
 
 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
 {
-    TClonesArray *MUONrawclust  = RawClustAddress(ichamber);
+    TClonesArray *muonRawCluster  = RawClustAddress(ichamber);
     ResetRawClusters();
-    TTree *TR = gAlice->TreeR();
-    Int_t nent=(Int_t)TR->GetEntries();
-    TR->GetEvent(nent-2+icathod-1);
-    //TR->GetEvent(icathod);
-    //Int_t nrawcl = (Int_t)MUONrawclust->GetEntriesFast();
+    TTree *treeR = gAlice->TreeR();
+    Int_t nent=(Int_t)treeR->GetEntries();
+    treeR->GetEvent(nent-2+icathod-1);
+    //treeR->GetEvent(icathod);
+    //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
 
-    AliMUONRawCluster * mRaw = (AliMUONRawCluster*)MUONrawclust->UncheckedAt(icluster);
+    AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
     //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
     
     return  mRaw;
 }
 
-void AliMUON::Reconst(Int_t &ifit, Int_t &idebug, Int_t bgd_ev, Int_t &nev, Int_t &idres, Int_t &ireadgeant, Option_t *option,Text_t *filename)
-{
-  //
-  // open kine and hits tree of background file for reconstruction of geant hits 
-  // call tracking fortran program
-  static Bool_t first=kTRUE;
-  static TFile *File;
-  char *Add = strstr(option,"Add");
-  
-  if (Add ) { // only in case of background with geant hits 
-    if(first) {
-      fFileName=filename;
-      cout<<"filename  "<<fFileName<<endl;
-      File=new TFile(fFileName);
-      cout<<"I have opened "<<fFileName<<" file "<<endl;
-      fHits2     = new TClonesArray("AliMUONhit",1000  );
-      fParticles2 = new TClonesArray("TParticle",1000);
-      first=kFALSE;
-    }
-    File->cd();
-    if(fHits2) fHits2->Clear();
-    if(fParticles2) fParticles2->Clear();
-    if(TrH1) delete TrH1;
-    TrH1=0;
-    if(TK1) delete TK1;
-    TK1=0;
-    // Get Hits Tree header from file
-    char treeName[20];
-    sprintf(treeName,"TreeH%d",bgd_ev);
-    TrH1 = (TTree*)gDirectory->Get(treeName);
-    if (!TrH1) {
-      printf("ERROR: cannot find Hits Tree for event:%d\n",bgd_ev);
-    }
-    // set branch addresses
-    TBranch *branch;
-    char branchname[30];
-    sprintf(branchname,"%s",GetName());
-    if (TrH1 && fHits2) {
-      branch = TrH1->GetBranch(branchname);
-      if (branch) branch->SetAddress(&fHits2);
-    }
-    TrH1->GetEntries();
-    // get the Kine tree
-    sprintf(treeName,"TreeK%d",bgd_ev);
-    TK1 = (TTree*)gDirectory->Get(treeName);
-    if (!TK1) {
-      printf("ERROR: cannot find Kine Tree for event:%d\n",bgd_ev);
-    }
-    // set branch addresses
-    if (TK1) 
-      TK1->SetBranchAddress("Particles", &fParticles2);
-    TK1->GetEvent(0);
-    
-    // get back to the first file
-    TTree *TK = gAlice->TreeK();
-    TFile *file1 = 0;
-    if (TK) file1 = TK->GetCurrentFile();
-    file1->cd();
-    
-  } // end if Add
-  
-  // call tracking fortran program
-  reconstmuon(ifit,idebug,nev,idres,ireadgeant);
-}
-
-
-void AliMUON::InitTracking(Double_t &seff, Double_t &sb0, Double_t &sbl3)
-{
-  //
-  // introduce in fortran program somme parameters and cuts for tracking 
-  // create output file "reconst.root" (histos + ntuple)
-  cutpxz(fSPxzCut);          // Pxz cut (GeV/c) to begin the track finding
-  sigmacut(fSSigmaCut);      // Number of sigmas delimiting the searching areas
-  xpreci(fSXPrec);           // Chamber precision in X (cm) 
-  ypreci(fSYPrec);           // Chamber precision in Y (cm)
-  reco_init(seff,sb0,sbl3);
-}
-
-void AliMUON::FinishEvent()
-{
-    TTree *TK = gAlice->TreeK();
-    if (TK) {
-      TFile *file1 = TK->GetCurrentFile();
-      if(file1) file1->cd();
-    }
-}
-
-void AliMUON::CloseTracking()
-{
-  //
-  // write histos and ntuple to "reconst.root" file
-    reco_term();
-}
-
-void chfill(Int_t &id, Float_t &x, Float_t &, Float_t &)
-{
-  //
-  // fill histo like hfill in fortran
-    char name[5];
-    sprintf(name,"h%d",id);
-    TH1F *h1 = (TH1F*) gDirectory->Get(name);
-    h1->Fill(x);
-}
-
-void chfill2(Int_t &id, Float_t &x, Float_t &y, Float_t &w)
-{
-  //
-  // fill histo like hfill2 in fortran
-    char name[5];
-    sprintf(name,"h%d",id);
-    TH2F *h2 = (TH2F*) gDirectory->Get(name);
-    h2->Fill(x,y,w);
-}
-
-void chf1(Int_t &id, Float_t &x, Float_t &w)
-{
-  //
-  // fill histo like hf1 in fortran
-    char name[5];
-    sprintf(name,"h%d",id);
-    TH1F *h1 = (TH1F*) gDirectory->Get(name);
-    h1->Fill(x,w);
-}
-
-void hist_create()
-{
-  //
-  // Create an output file ("reconst.root")
-  // Create some histograms and an ntuple
-
-    hfile_global = new TFile("reconst.root","RECREATE","Ntuple - reconstruction");
-
-   ntuple_global = new TTree("ntuple","Reconst ntuple");
-   ntuple_global->Branch("ievr",&ntuple_st.ievr,"ievr/I");
-   ntuple_global->Branch("ntrackr",&ntuple_st.ntrackr,"ntrackr/I");
-   ntuple_global->Branch("istatr",&ntuple_st.istatr[0],"istatr[500]/I");
-   ntuple_global->Branch("isignr",&ntuple_st.isignr[0],"isignr[500]/I");
-   ntuple_global->Branch("pxr",&ntuple_st.pxr[0],"pxr[500]/F");
-   ntuple_global->Branch("pyr",&ntuple_st.pyr[0],"pyr[500]/F");
-   ntuple_global->Branch("pzr",&ntuple_st.pzr[0],"pzr[500]/F");
-   ntuple_global->Branch("zvr",&ntuple_st.zvr[0],"zvr[500]/F");
-   ntuple_global->Branch("chi2r",&ntuple_st.chi2r[0],"chi2r[500]/F");
-   ntuple_global->Branch("pxv",&ntuple_st.pxv[0],"pxv[500]/F");
-   ntuple_global->Branch("pyv",&ntuple_st.pyv[0],"pyv[500]/F");
-   ntuple_global->Branch("pzv",&ntuple_st.pzv[0],"pzv[500]/F");
-
-   // test aliroot
-
-  new TH1F("h100","particule id du hit geant",20,0.,20.);
-  new TH1F("h101","position en x du hit geant",100,-200.,200.);
-  new TH1F("h102","position en y du hit geant",100,-200.,200.);
-  new TH1F("h103","chambre de tracking concernee",15,0.,14.);
-  new TH1F("h104","moment ptot du hit geant",50,0.,100.);
-  new TH1F("h105","px au vertex",50,0.,20.);
-  new TH1F("h106","py au vertex",50,0.,20.);
-  new TH1F("h107","pz au vertex",50,0.,20.);
-  new TH1F("h108","position zv",50,-15.,15.);
-  new TH1F("h109","position en x du hit reconstruit",100,-300.,300.);
-  new TH1F("h110","position en y du hit reconstruit",100,-300.,300.);
-  new TH1F("h111","delta x ",100,-0.4,0.4);
-  new TH1F("h112","delta y ",100,-0.4,0.4);
-
-  char hname[30];
-  char hname1[30];
-  for (int i=0;i<10;i++) {
-    sprintf(hname,"deltax%d",i);
-    sprintf(hname1,"h12%d",i);
-    new TH1F(hname1,hname ,100,-0.4,0.4);
-    sprintf(hname,"deltay%d",i);
-    sprintf(hname1,"h13%d",i);
-    new TH1F(hname1,hname ,100,-0.4,0.4);
-  }
-  new TH2F("h2000","VAR X st. 5",30,3.0,183.0,100,0.,25.);
-  new TH2F("h2001","VAR Y st. 5",30,3.0,183.0,100,0.,25.);
-
-  new TH2F("h2500","P vs X HHIT",30,3.0,183.0,200,0.,200.);
-  new TH2F("h2501","P vs X HHIT**2",30,3.0,183.0,200,0.,5000.);
-  new TH2F("h2502","P vs X EPH2 st. 5",30,3.0,183.0,100,0.,0.000005);
-  new TH2F("h2503","P vs X EAL2 st. 5",30,3.0,183.0,100,0.,0.01);
-  //new TH2F("h2504","P vs X EXM2 st. 5",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2504","P vs X EXM2 st. 5",30,3.0,183.0,100,0.,0.1);
-  new TH2F("h2505","P vs X EYM2 st. 5",30,3.0,183.0,100,0.,30.);
-
-  new TH2F("h2507","P vs X EPH st. 5",30,3.0,183.0,100,0.,0.003);
-  new TH2F("h2508","P vs X EAL st. 5",30,3.0,183.0,100,0.,0.3);
-  //new TH2F("h2509","P vs X EXM st. 5",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2509","P vs X EXM st. 5",30,3.0,183.0,100,0.,0.4);
-  new TH2F("h2510","P vs X EYM st. 5",30,3.0,183.0,100,0.,30.);
-
-  new TH2F("h2511","P vs X EPH cut st. 5",30,3.0,183.0,100,0.,0.01);
-  new TH2F("h2512","P vs X EAL cut st. 5",30,3.0,183.0,100,0.,0.3);
-  //new TH2F("h2513","P vs X EXM cut st. 5",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2513","P vs X EXM cut st. 5",30,3.0,183.0,100,0.,0.4);
-  new TH2F("h2514","P vs X EYM cut st. 5",30,3.0,183.0,100,0.,30.);
-  // 4
-  new TH2F("h2400","P vs X HHIT",30,3.0,183.0,200,0.,200.);
-  new TH2F("h2401","P vs X HHIT**2",30,3.0,183.0,200,0.,5000.);
-  new TH2F("h2402","P vs X EPH2 st. 4",30,3.0,183.0,100,0.,0.000005);
-  new TH2F("h2403","P vs X EAL2 st. 4",30,3.0,183.0,100,0.,0.05);
-  //new TH2F("h2404","P vs X EXM2 st. 4",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2404","P vs X EXM2 st. 4",30,3.0,183.0,100,0.,0.1);
-  new TH2F("h2405","P vs X EYM2 st. 4",30,3.0,183.0,100,0.,30.);
-
-  new TH2F("h2407","P vs X EPH st. 4",30,3.0,183.0,100,0.,0.003);
-  new TH2F("h2408","P vs X EAL st. 4",30,3.0,183.0,100,0.,0.3);
-  //new TH2F("h2409","P vs X EXM st. 4",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2409","P vs X EXM st. 4",30,3.0,183.0,100,0.,0.1);
-  new TH2F("h2410","P vs X EYM st. 4",30,3.0,183.0,100,0.,30.);
-
-  new TH2F("h2411","P vs X EPH cut st. 4",30,3.0,183.0,100,0.,0.01);
-  new TH2F("h2412","P vs X EAL cut st. 4",30,3.0,183.0,100,0.,0.3);
-  //new TH2F("h2413","P vs X EXM cut st. 4",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2413","P vs X EXM cut st. 4",30,3.0,183.0,100,0.,0.1);
-  new TH2F("h2414","P vs X EYM cut st. 4",30,3.0,183.0,100,0.,30.);
-  // 3
-  new TH1F("h2301","P2",30,3.0,183.0);
-  new TH2F("h2302","P2 vs X EPH2 st. 3",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h2303","P2 vs X EAL2 st. 3",30,3.0,183.0,100,0.,0.0005);
-  //new TH2F("h2304","P2 vs X EXM2 st. 3",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2304","P2 vs X EXM2 st. 3",30,3.0,183.0,100,0.,2.);
-  new TH2F("h2305","P2 vs X EYM2 st. 3",30,3.0,183.0,100,0.,3.);
-
-  new TH2F("h2307","P vs X EPH2 st. 3",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h2308","P vs X EAL2 st. 3",30,3.0,183.0,100,0.,0.005);
-  //new TH2F("h2309","P vs X EXM2 st. 3",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2309","P vs X EXM2 st. 3",30,3.0,183.0,100,0.,2.);
-  new TH2F("h2310","P vs X EYM2 st. 3",30,3.0,183.0,100,0.,3.);
-
-  new TH2F("h2311","P vs X EPH cut st. 3",30,3.0,183.0,100,0.,0.06);
-  new TH2F("h2312","P vs X EAL cut st. 3",30,3.0,183.0,100,0.,0.05);
-  //new TH2F("h2313","P vs X EXM cut st. 3",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2313","P vs X EXM cut st. 3",30,3.0,183.0,100,0.,6.);
-  new TH2F("h2314","P vs X EYM cut st. 3",30,3.0,183.0,100,0.,7.);
-
-  new TH2F("h2315","P2 vs X EPH cut st. 3",30,3.0,183.0,100,0.,0.06);
-  new TH2F("h2316","P2 vs X EAL cut st. 3",30,3.0,183.0,100,0.,0.05);
-  //new TH2F("h2317","P2 vs X EXM cut st. 3",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2317","P2 vs X EXM cut st. 3",30,3.0,183.0,100,0.,6.);
-  new TH2F("h2318","P2 vs X EYM cut st. 3",30,3.0,183.0,100,0.,7.);
-  
-  // 2
-  new TH1F("h2201","P2",30,3.0,183.0);
-  new TH2F("h2202","P2 vs X EPH2 st. 2",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h2203","P2 vs X EAL2 st. 2",30,3.0,183.0,100,0.,0.005);
-  //new TH2F("h2204","P2 vs X EXM2 st. 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2204","P2 vs X EXM2 st. 2",30,3.0,183.0,100,0.,7.);
-  new TH2F("h2205","P2 vs X EYM2 st. 2",30,3.0,183.0,100,0.,5.);
-
-  new TH2F("h2207","P vs X EPH2 st. 2",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h2208","P vs X EAL2 st. 2",30,3.0,183.0,100,0.,0.005);
-  //new TH2F("h2209","P vs X EXM2 st. 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2209","P vs X EXM2 st. 2",30,3.0,183.0,100,0.,7.);
-  new TH2F("h2210","P vs X EYM2 st. 2",30,3.0,183.0,100,0.,5.);
-
-  new TH2F("h2211","P vs X EPH cut st. 2",30,3.0,183.0,100,0.,0.05);
-  new TH2F("h2212","P vs X EAL cut st. 2",30,3.0,183.0,100,0.,0.2);
-  //new TH2F("h2213","P vs X EXM cut st. 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2213","P vs X EXM cut st. 2",30,3.0,183.0,100,0.,11.);
-  new TH2F("h2214","P vs X EYM cut st. 2",30,3.0,183.0,100,0.,10.);
-
-  new TH2F("h2215","P2 vs X EPH cut st. 2",30,3.0,183.0,100,0.,0.05);
-  new TH2F("h2216","P2 vs X EAL cut st. 2",30,3.0,183.0,100,0.,0.2);
-  //new TH2F("h2217","P2 vs X EXM cut st. 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2217","P2 vs X EXM cut st. 2",30,3.0,183.0,100,0.,11.);
-  new TH2F("h2218","P2 vs X EYM cut st. 2",30,3.0,183.0,100,0.,10.);
-
-  // 1
-  new TH2F("h2102","P2 vs X EPH2 st. 2",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h2103","P2 vs X EAL2 st. 2",30,3.0,183.0,100,0.,0.005);
-  //new TH2F("h2104","P2 vs X EXM2 st. 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2104","P2 vs X EXM2 st. 2",30,3.0,183.0,100,0.,7.);
-  new TH2F("h2105","P2 vs X EYM2 st. 2",30,3.0,183.0,100,0.,7.);
-
-  new TH2F("h2107","P vs X EPH2 st. 2",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h2108","P vs X EAL2 st. 2",30,3.0,183.0,100,0.,0.005);
-  //new TH2F("h2109","P vs X EXM2 st. 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2109","P vs X EXM2 st. 2",30,3.0,183.0,100,0.,7.);
-  new TH2F("h2110","P vs X EYM2 st. 2",30,3.0,183.0,100,0.,7.);
-
-  new TH2F("h2111","P vs X EPH cut st. 2",30,3.0,183.0,100,0.,0.1);
-  new TH2F("h2112","P vs X EAL cut st. 2",30,3.0,183.0,100,0.,0.2);
-  //new TH2F("h2113","P vs X EXM cut st. 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2113","P vs X EXM cut st. 2",30,3.0,183.0,100,0.,11.);
-  new TH2F("h2114","P vs X EYM cut st. 2",30,3.0,183.0,100,0.,11.);
-
-  new TH2F("h2115","P2 vs X EPH cut st. 2",30,3.0,183.0,100,0.,0.1);
-  new TH2F("h2116","P2 vs X EAL cut st. 2",30,3.0,183.0,100,0.,0.2);
-  //new TH2F("h2117","P2 vs X EXM cut st. 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2117","P2 vs X EXM cut st. 2",30,3.0,183.0,100,0.,11.);
-  new TH2F("h2118","P2 vs X EYM cut st. 2",30,3.0,183.0,100,0.,11.);
-
-  // 2,3,4,5
-  new TH1F("h2701","P2 fit 2",30,3.0,183.0);
-  new TH2F("h2702","P2 vs X EPH2 st. 1 fit 2",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h2703","P2 vs X EAL2 st. 1 fit 2",30,3.0,183.0,100,0.,0.005);
-  // new TH2F("h2704","P2 vs X EXM2 st. 1 fit 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2704","P2 vs X EXM2 st. 1 fit 2",30,3.0,183.0,100,0.,2.);
-  new TH2F("h2705","P2 vs X EYM2 st. 1 fit 2",30,3.0,183.0,100,0.,3.);
-
-  new TH2F("h2707","P vs X EPH2 st. 1 fit 2",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h2708","P vs X EAL2 st. 1 fit 2",30,3.0,183.0,100,0.,0.005);
-  //new TH2F("h2709","P vs X EXM2 st. 1 fit 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2709","P vs X EXM2 st. 1 fit 2",30,3.0,183.0,100,0.,2.);
-  new TH2F("h2710","P vs X EYM2 st. 1 fit 2",30,3.0,183.0,100,0.,3.);
-
-  new TH2F("h2711","P vs X EPH cut st. 1 fit 2",30,3.0,183.0,100,0.,0.07);
-  new TH2F("h2712","P vs X EAL cut st. 1 fit 2",30,3.0,183.0,100,0.,0.2);
-  //new TH2F("h2713","P vs X EXM cut st. 1 fit 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2713","P vs X EXM cut st. 1 fit 2",30,3.0,183.0,100,0.,6.);
-  new TH2F("h2714","P vs X EYM cut st. 1 fit 2",30,3.0,183.0,100,0.,7.);
-
-  new TH2F("h2715","P2 vs X EPH cut st. 1 fit 2",30,3.0,183.0,100,0.,0.07);
-  new TH2F("h2716","P2 vs X EAL cut st. 1 fit 2",30,3.0,183.0,100,0.,0.2);
-  //new TH2F("h2717","P2 vs X EXM cut st. 1 fit 2",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2717","P2 vs X EXM cut st. 1 fit 2",30,3.0,183.0,100,0.,6.);
-  new TH2F("h2718","P2 vs X EYM cut st. 1 fit 2",30,3.0,183.0,100,0.,7.);
-
-  // 1,3,4,5
-  new TH1F("h2801","P2 fit 1",30,3.0,183.0);
-  new TH2F("h2802","P2 vs X EPH2 st. 2 fit 1",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h2803","P2 vs X EAL2 st. 2 fit 1",30,3.0,183.0,100,0.,0.005);
-  //new TH2F("h2804","P2 vs X EXM2 st. 2 fit 1",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2804","P2 vs X EXM2 st. 2 fit 1",30,3.0,183.0,100,0.,2.);
-  new TH2F("h2805","P2 vs X EYM2 st. 2 fit 1",30,3.0,183.0,100,0.,3.);
-
-  new TH2F("h2807","P vs X EPH2 st. 2 fit 1",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h2808","P vs X EAL2 st. 2 fit 1",30,3.0,183.0,100,0.,0.005);
-  //new TH2F("h2809","P vs X EXM2 st. 2 fit 1",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2809","P vs X EXM2 st. 2 fit 1",30,3.0,183.0,100,0.,2.);
-  new TH2F("h2810","P vs X EYM2 st. 2 fit 1",30,3.0,183.0,100,0.,3.);
-
-  new TH2F("h2811","P vs X EPH cut st. 2 fit 1",30,3.0,183.0,100,0.,0.05);
-  new TH2F("h2812","P vs X EAL cut st. 2 fit 1",30,3.0,183.0,100,0.,0.2);
-  //new TH2F("h2813","P vs X EXM cut st. 2 fit 1",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2813","P vs X EXM cut st. 2 fit 1",30,3.0,183.0,100,0.,5.);
-  new TH2F("h2814","P vs X EYM cut st. 2 fit 1",30,3.0,183.0,100,0.,7.);
-
-  new TH2F("h2815","P2 vs X EPH cut st. 2 fit 1",30,3.0,183.0,100,0.,0.05);
-  new TH2F("h2816","P2 vs X EAL cut st. 2 fit 1",30,3.0,183.0,100,0.,0.2);
-  //new TH2F("h2817","P2 vs X EXM cut st. 2 fit 1",30,3.0,183.0,100,0.,1.5);
-  new TH2F("h2817","P2 vs X EXM cut st. 2 fit 1",30,3.0,183.0,100,0.,5.);
-  new TH2F("h2818","P2 vs X EYM cut st. 2 fit 1",30,3.0,183.0,100,0.,7.);
-  // fin de test
-
-  new TH1F("h500","Acceptance en H st. 4",500,0.,500.);
-  new TH1F("h600","Acceptance en H st. 5",500,0.,500.);
-  new TH1F("h700","X vertex track found",200,-10.,10.);
-  new TH1F("h701","Y vertex track found",200,-10.,10.);
-  new TH1F("h800","Rap. muon gen.",100,0.,5.);
-  new TH1F("h801","Rap. muon gen. recons.",100,0.,5.);
-  new TH1F("h802","Rap. muon gen. ghost ",100,0.,5.);
-  new TH1F("h900","Pt muon gen.",100,0.,20.);
-  new TH1F("h901","Pt muon gen. recons.",100,0.,20.);
-  new TH1F("h902","Pt muon gen. ghost",100,0.,20.);
-  new TH1F("h910","phi muon gen.",100,-10.,10.);
-  new TH1F("h911","phi muon gen. recons.",100,-10.,10.);
-  new TH1F("h912","phi muon gen. ghost",100,-10.,10.);
-  new TH2F("h1001","Y VS X hit st. 1",300,-300.,300.,300,-300.,300.);
-  new TH2F("h1002","Y VS X hit st. 2",300,-300.,300.,300,-300.,300.);
-  new TH2F("h1003","Y VS X hit st. 3",300,-300.,300.,300,-300.,300.);
-  new TH2F("h1004","Y VS X hit st. 4",300,-300.,300.,300,-300.,300.);
-  new TH2F("h1005","Y VS X hit st. 5",300,-300.,300.,300,-300.,300.);
-  //  Histos variance dans 4      
-  new TH2F("h11","VAR X st. 4",30,3.0,183.0,100,0.,2.);
-  new TH2F("h12","VAR Y st. 4",30,3.0,183.0,100,0.,600.);
-  new TH2F("h13","VAR PHI st. 4",30,3.0,183.0,100,0.,0.0001);
-  new TH2F("h14","VAR ALM st. 4",30,3.0,183.0,100,0.,0.05);
-  new TH1F("h15","P",30,3.0,183.0);
-  new TH1F("h411","VAR X st. 4",100,-1.42,1.42);
-  new TH1F("h412","VAR Y st. 4",100,-25.,25.);
-  new TH1F("h413","VAR PHI st. 4",100,-0.01,0.01);
-  new TH1F("h414","VAR ALM st. 4",100,-0.23,0.23);
-  // histo2
-  new TH2F("h211","histo2-VAR X st. 4",30,3.0,183.0,100,0.,2.);
-  new TH2F("h212","histo2-VAR Y st. 4",30,3.0,183.0,100,0.,600.);
-  new TH1F("h213","histo2-VAR X st. 4",100,-1.42,1.42);
-  new TH1F("h214","histo2-VAR Y st. 4",100,-25.,25.);
-  new TH1F("h215","histo2-P",30,3.0,183.0);
-
-  //  Histos variance dans 2      
-  new TH2F("h21","VAR X st. 2",30,3.0,183.0,100,0.,3.);
-  new TH2F("h22","VAR Y st. 2",30,3.0,183.0,100,0.,7.);
-  new TH2F("h23","VAR PHI st. 2",30,3.0,183.0,100,0.,0.006);
-  new TH2F("h24","VAR ALM st. 2",30,3.0,183.0,100,0.,0.005);
-  new TH1F("h25","P",30,3.0,183.0);
-  new TH1F("h421","VAR X st. 2",100,-1.72,1.72);
-  new TH1F("h422","VAR Y st. 2",100,-2.7,2.7);
-  new TH1F("h423","VAR PHI st. 2",100,-0.08,0.08);
-  new TH1F("h424","VAR ALM st. 2",100,-0.072,0.072);
-  // histo2
-  new TH2F("h221","histo2-VAR X st. 2",30,3.0,183.0,100,0.,3.);
-  new TH2F("h222","histo2-VAR Y st. 2",30,3.0,183.0,100,0.,7.);
-  new TH1F("h223","histo2-VAR X st. 2",100,-1.72,1.72);
-  new TH1F("h224","histo2-VAR Y st. 2",100,-2.7,2.7);
-  new TH1F("h225","histo2-P",30,3.0,183.0);
-
-  //  Histos variance dans 1      
-  new TH2F("h31","VAR X st. 1",30,3.0,183.0,100,0.,2.);
-  new TH2F("h32","VAR Y st. 1",30,3.0,183.0,100,0.,0.5);
-  new TH2F("h33","VAR PHI st. 1",30,3.0,183.0,100,0.,0.006);
-  new TH2F("h34","VAR ALM st. 1",30,3.0,183.0,100,0.,0.005);
-  new TH1F("h35","P",30,3.0,183.0);
-  new TH1F("h431","VAR X st. 1",100,-1.42,1.42);
-  new TH1F("h432","VAR Y st. 1",100,-0.72,0.72);
-  new TH1F("h433","VAR PHI st. 1",100,-0.08,0.08);
-  new TH1F("h434","VAR ALM st. 1",100,-0.072,0.072);
-  //  Histos variance dans 1      
-  new TH2F("h41","VAR X st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,4.);
-  new TH2F("h42","VAR Y st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,20.);
-  new TH2F("h43","VAR PHI st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,0.005);
-  new TH2F("h44","VAR ALM st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,0.005);
-  new TH1F("h45","P",30,3.0,183.0);
-  new TH1F("h441","VAR X st. 1 fit 5,4,3,2,V",100,-2.,2.);
-  new TH1F("h442","VAR Y st. 1 fit 5,4,3,2,V",100,-4.5,4.5);
-  new TH1F("h443","VAR PHI st. 1 fit 5,4,3,2,V",100,-0.072,0.072);
-  new TH1F("h444","VAR ALM st. 1 fit 5,4,3,2,V",100,-0.072,0.072);
-  // histo2
-  new TH2F("h241","histo2-VAR X st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,4.);
-  new TH2F("h242","histo2-VAR Y st. 1 fit 5,4,3,2,V",30,3.0,183.0,100,0.,20.);
-  new TH1F("h243","histo2-VAR X st. 1 fit 5,4,3,2,V",100,-2.,2.);
-  new TH1F("h244","histo2-VAR Y st. 1 fit 5,4,3,2,V",100,-4.5,4.5);
-  new TH1F("h245","histo2-P",30,3.0,183.0);
-
-  //  Histos variance dans 2      
-  new TH2F("h51","VAR X st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,0.5);
-  new TH2F("h52","VAR Y st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,2.);
-  new TH2F("h53","VAR PHI st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,0.005);
-  new TH2F("h54","VAR ALM st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,0.01);
-  new TH1F("h55","P",30,3.0,183.0);
-  new TH1F("h451","VAR X st. 2 fit 5,4,3,1,V",100,-0.72,0.72);
-  new TH1F("h452","VAR Y st. 2 fit 5,4,3,1,V",100,-1.42,1.42);
-  new TH1F("h453","VAR PHI st. 2 fit 5,4,3,1,V",100,-0.072,0.072);
-  new TH1F("h454","VAR ALM st. 2 fit 5,4,3,1,V",100,-0.1,0.1);
-  new TH1F("h999","PTOT",30,3.0,183.0);
-  // histo2
-  new TH2F("h251","histo2-VAR X st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,0.5);
-  new TH2F("h252","histo2-VAR Y st. 2 fit 5,4,3,1,V",30,3.0,183.0,100,0.,2.);
-  new TH1F("h253","histo2-VAR X st. 2 fit 5,4,3,1,V",100,-0.72,0.72);
-  new TH1F("h254","histo2-VAR Y st. 2 fit 5,4,3,1,V",100,-1.42,1.42);
-  new TH1F("h255","histo2-P",30,3.0,183.0);
-  //  Histos variance dans 3      
-  new TH2F("h61","VAR X st. 3 fit 4,5,V",30,3.0,183.0,100,0.,5.);
-  new TH2F("h62","VAR Y st. 3 fit 4,5,V",30,3.0,183.0,100,0.,2.);
-  new TH2F("h63","VAR PHI st. 3 fit 4,5,V",30,3.0,183.0,100,0.,0.0006);
-  new TH2F("h64","VAR ALM st. 3 fit 4,5,V",30,3.0,183.0,100,0.,0.0006);
-  new TH1F("h65","P",30,3.0,183.0);
-  new TH1F("h461","VAR X st. 3 fit 4,5,V",100,-2.25,2.25);
-  new TH1F("h462","VAR Y st. 3 fit 4,5,V",100,-1.42,1.42);
-  new TH1F("h463","VAR PHI st. 3 fit 4,5,V",100,-0.024,0.024);
-  new TH1F("h464","VAR ALM st. 3 fit 4,5,V",100,-0.024,0.024);
-  // histo2
-  new TH2F("h261","histo2-VAR X st. 3 fit 4,5,V",30,3.0,183.0,100,0.,5.);
-  new TH2F("h262","histo2-VAR Y st. 3 fit 4,5,V",30,3.0,183.0,100,0.,2.);
-  new TH1F("h263","histo2-VAR X st. 3 fit 4,5,V",100,-2.25,2.25);
-  new TH1F("h264","histo2-VAR Y st. 3 fit 4,5,V",100,-1.42,1.42);
-  new TH1F("h265","Phisto2-",30,3.0,183.0);
-  // Histos dx,dy distribution between chambers inside stations
-  new TH1F("h71","DX in st. ID-70",100,-5.,5.);
-  new TH1F("h81","DY in st. ID-80",100,-5.,5.);
-  new TH1F("h72","DX in st. ID-70",100,-5.,5.);
-  new TH1F("h82","DY in st. ID-80",100,-5.,5.);
-  new TH1F("h73","DX in st. ID-70",100,-5.,5.);
-  new TH1F("h83","DY in st. ID-80",100,-5.,5.);
-  new TH1F("h74","DX in st. ID-70",100,-5.,5.);
-  new TH1F("h84","DY in st. ID-80",100,-5.,5.);
-  new TH1F("h75","DX in st. ID-70",100,-5.,5.);
-  new TH1F("h85","DY in st. ID-80",100,-5.,5.);
-}
-
-void chfnt(Int_t &ievr, Int_t &ntrackr, Int_t *istatr, Int_t *isignr, Float_t *pxr, Float_t *pyr, Float_t *pzr, Float_t *zvr, Float_t *chi2r,  Float_t *pxv, Float_t *pyv, Float_t *pzv)
-{
-  //
-  // fill the ntuple 
-    ntuple_st.ievr = ievr;
-    ntuple_st.ntrackr = ntrackr;
-    for (Int_t i=0; i<500; i++) {
-       ntuple_st.istatr[i] = istatr[i];
-       ntuple_st.isignr[i] = isignr[i]; 
-       ntuple_st.pxr[i]    = pxr[i]; 
-       ntuple_st.pyr[i]    = pyr[i];
-       ntuple_st.pzr[i]    = pzr[i];
-       ntuple_st.zvr[i]    = zvr[i];
-       ntuple_st.chi2r[i]  = chi2r[i];
-       ntuple_st.pxv[i]    = pxv[i]; 
-       ntuple_st.pyv[i]    = pyv[i];
-       ntuple_st.pzv[i]    = pzv[i];
-    }
-    ntuple_global->Fill();   
-}
-
-void hist_closed()
-{
-  //
-  // write histos and ntuple to "reconst.root" file
-  hfile_global->Write();
-}
-
-void trackf_read_geant(Int_t *itypg, Double_t *xtrg, Double_t *ytrg, Double_t *ptotg, Int_t *idg, Int_t *izch, Double_t *pvert1g, Double_t *pvert2g, Double_t *pvert3g, Double_t *zvertg, Int_t &nhittot1, Double_t *cx, Double_t *cy, Double_t *cz, Int_t &ievr,Int_t &nev,Double_t *xgeant, Double_t *ygeant,Double_t *clsize1, Double_t *clsize2) 
+AliMUON& AliMUON::operator = (const AliMUON& rhs)
 {
-  //
-  // introduce aliroot variables in fortran common 
-  // tracking study from geant hits 
-  //
-
-  AliMUON *MUON  = (AliMUON*) gAlice->GetModule("MUON");
-  
-  //  TTree *TK = gAlice->TreeK();
-  TTree *TH = gAlice->TreeH();
-  Int_t ntracks = (Int_t)TH->GetEntries();
-  cout<<"ntrack="<<ntracks<<endl;
-
-  Int_t maxidg = 0;
-  Int_t nres=0;
-  
-//
-//  Loop over tracks
-//
-
-  for (Int_t track=0; track<ntracks;track++) {
-      gAlice->ResetHits();
-      TH->GetEvent(track);
-      
-      if (MUON)  {
-//
-//  Loop over hits
-//
-         for(AliMUONhit* mHit=(AliMUONhit*)MUON->FirstHit(-1); 
-             mHit;
-             mHit=(AliMUONhit*)MUON->NextHit()) 
-         {
-             if (maxidg<=20000) {
-               
-               if (mHit->fChamber > 10) continue;
-               TClonesArray *fPartArray = gAlice->Particles();
-               TParticle *Part;
-               Int_t ftrack = mHit->fTrack;
-               Int_t id = ((TParticle*) fPartArray->UncheckedAt(ftrack))->GetPdgCode();
-
-               if (id==kMuonPlus||id==kMuonMinus) {
-                   
-                   // inversion de x et y car le champ est inverse dans le programme tracking
-                   xtrg[maxidg]   = 0;       
-                   ytrg[maxidg]   = 0;       
-                   xgeant[maxidg]   = mHit->fY;             // x-pos of hit
-                   ygeant[maxidg]   = mHit->fX;             // y-pos of hit
-                   clsize1[maxidg]   = 0;     // cluster size on 1-st cathode
-                   clsize2[maxidg]   = 0;     // cluster size on 2-nd cathode
-                   cx[maxidg]     = mHit->fCyHit;            // Px/P of hit
-                   cy[maxidg]     = mHit->fCxHit;            // Py/P of hit
-                   cz[maxidg]     = mHit->fCzHit;            // Pz/P of hit
-                   izch[maxidg]   = mHit->fChamber; 
-                   /*      
-                   Int_t pdgtype  = Int_t(mHit->fParticle); // particle number
-                   itypg[maxidg]  = gMC->IdFromPDG(pdgtype);
-
-                   */
-                    if (id==kMuonPlus) itypg[maxidg]  = 5;
-                   else  itypg[maxidg]  = 6;
-
-                   ptotg[maxidg]  = mHit->fPTot;          // P of hit 
-                   
-                   Part = (TParticle*) fPartArray->UncheckedAt(ftrack);
-                   Float_t thet = Part->Theta();
-                   thet = thet*180./3.1416;
-                   
-                   Int_t iparent = Part->GetFirstMother();
-                   if (iparent >= 0) {
-                       Int_t ip;
-                       while(1) {
-                           ip=((TParticle*) fPartArray->UncheckedAt(iparent))->GetFirstMother();
-                           if (ip < 0) {
-                               break;
-                           } else {
-                               iparent = ip;
-                           }
-                       }
-                   }
-                   //printf("iparent - %d\n",iparent);
-                   Int_t id1  = ftrack; // numero de la particule generee au vertex
-                   Int_t idum = track+1;
-                   Int_t id2 = ((TParticle*) fPartArray->UncheckedAt(iparent))->GetPdgCode();
-
-                   if (id2==443) id2=114;
-                   else id2=116;
-                   
-                    if (id2==116) {
-                     nres++;
-                   }
-                   //printf("id2 %d\n",id2);
-                   idg[maxidg] = 30000*id1+10000*idum+id2;
-                   
-                   pvert1g[maxidg] = Part->Py();      // Px vertex
-                   pvert2g[maxidg] = Part->Px();      // Py vertex  
-                   pvert3g[maxidg] = Part->Pz();      // Pz vertex
-                   zvertg[maxidg]  = Part->Vz();      // z vertex 
-                   maxidg ++;
-
-               }
-             }
-         } // hit loop
-      } // if MUON
-  } // track loop first file
-
-  if (TrH1 && fHits2 ) { // if background file
-    ntracks =(Int_t)TrH1->GetEntries();
-    printf("Trackf_read - 2-nd file - ntracks %d\n",ntracks);
-
-    //  Loop over tracks
-    for (Int_t track=0; track<ntracks; track++) {
-      
-      if (fHits2) fHits2->Clear();
-      TrH1->GetEvent(track);
-
-      //  Loop over hits
-      for (int i=0;i<fHits2->GetEntriesFast();i++) 
-       {
-         AliMUONhit *mHit=(AliMUONhit*) (*fHits2)[i];
-         
-          if (mHit->fChamber > 10) continue;
-
-         if (maxidg<=20000) {
-           
-           // inversion de x et y car le champ est inverse dans le programme tracking !!!!
-           xtrg[maxidg]   = 0;                    // only for reconstructed point
-           ytrg[maxidg]   = 0;                    // only for reconstructed point
-           xgeant[maxidg]   = mHit->fY;           // x-pos of hit
-           ygeant[maxidg]   = mHit->fX;           // y-pos of hit
-           clsize1[maxidg]   = 0;           // cluster size on 1-st cathode
-           clsize2[maxidg]   = 0;           // cluster size on 2-nd cathode
-           cx[maxidg]     = mHit->fCyHit;         // Px/P of hit
-           cy[maxidg]     = mHit->fCxHit;         // Py/P of hit
-           cz[maxidg]     = mHit->fCzHit;         // Pz/P of hit
-           izch[maxidg]   = mHit->fChamber;       // chamber number
-           ptotg[maxidg]  = mHit->fPTot;          // P of hit 
-           
-           Int_t ftrack = mHit->fTrack;
-           Int_t id1  = ftrack;                   // track number 
-           Int_t idum = track+1;
-           
-           TClonesArray *fPartArray = fParticles2;
-           TParticle *Part;
-           Part = (TParticle*) fPartArray->UncheckedAt(ftrack);
-           Int_t id = ((TParticle*) fPartArray->UncheckedAt(ftrack))->GetPdgCode();
-           if (id==kMuonPlus||id==kMuonMinus) {
-               if (id==kMuonPlus) itypg[maxidg]  = 5;
-               else  itypg[maxidg]  = 6;
-           } else itypg[maxidg]=0;
-           
-           Int_t id2=0; // set parent to 0 for background !!
-           idg[maxidg] = 30000*id1+10000*idum+id2;
-           
-           pvert1g[maxidg] = Part->Py();      // Px vertex
-           pvert2g[maxidg] = Part->Px();      // Py vertex  
-           pvert3g[maxidg] = Part->Pz();      // Pz vertex
-           zvertg[maxidg]  = Part->Vz();      // z vertex 
-
-           maxidg ++;
-
-         } // check limits (maxidg)
-       } // hit loop 
-    } // track loop
-  } // if TrH1
-
-  ievr = nev;
-  nhittot1 = maxidg ;
-  cout<<"nhittot1="<<nhittot1<<endl;
-
-  static Int_t nbres=0;
-  if (nres>=19) nbres++;
-  printf("nres, nbres %d %d \n",nres,nbres);
-
-  hfile_global->cd();      
-
+// copy operator
+// dummy version
+    return *this;
 }
 
 
 
-void trackf_read_spoint(Int_t *itypg, Double_t *xtrg, Double_t *ytrg, Double_t *ptotg, Int_t *idg, Int_t *izch, Double_t *pvert1g, Double_t *pvert2g, Double_t *pvert3g, Double_t *zvertg, Int_t &nhittot1, Double_t *cx, Double_t *cy, Double_t *cz, Int_t &ievr,Int_t &nev,Double_t *xgeant, Double_t *ygeant,Double_t *clsize1, Double_t *clsize2) 
-
-{
-  //
-  // introduce aliroot variables in fortran common 
-  // tracking study from reconstructed points 
-  //
-  AliMUON *MUON  = (AliMUON*) gAlice->GetModule("MUON");
-
-  cout<<"numero de l'evenement "<<nev<<endl;
-  
-  MUON->GetTreeC(nev);
-  TTree *TC=MUON->TreeC();
-  TC->GetEntries();
-
-  Int_t maxidg = 0;
-  Int_t nres=0;
-  Int_t nncor=0;
-  static Int_t nuncor=0;
-  static Int_t nbadcor=0;
-  AliMUONRawCluster * mRaw;
-  AliMUONRawCluster * mRaw1;
-  TTree *TH = gAlice->TreeH();
-
-  Int_t ihit;
-  Int_t mult1, mult2;
-  if (MUON) {
-      for (Int_t ich=0;ich<10;ich++) {
-         TClonesArray *MUONcorrel  = MUON->CathCorrelAddress(ich);
-         MUON->ResetCorrelation();
-         TC->GetEvent();
-         Int_t ncor = (Int_t)MUONcorrel->GetEntries();
-         if (ncor>=2) nncor++;
-         if (!ncor) continue;
-
-         //  Loop over correlated clusters
-         for (Int_t icor=0;icor<ncor;icor++) {
-             AliMUONcorrelation * mCor = (AliMUONcorrelation*)MUONcorrel->UncheckedAt(icor);
-
-              Int_t flag=0;   // = 1 if no information in the second cathode
-             Int_t index = mCor->fCorrelIndex[0]; // for the second cathode
-              if (index >= 0) {
-                 Int_t index1 = mCor->fCorrelIndex[3]; // for the 1-st cathode
-                 mRaw1 = MUON->RawCluster(ich,1,index1);
-                  mult1=mRaw1->fMultiplicity;
-                 mRaw = MUON->RawCluster(ich,2,index);
-                 mult2=mRaw->fMultiplicity;
-              } else {
-                 index = mCor->fCorrelIndex[3];
-                 mRaw = MUON->RawCluster(ich,1,index);
-                 mult1=mRaw->fMultiplicity;
-                 mult2=0;
-                  flag=1;
-                 nuncor++;
-             }
-             if (!mRaw) continue;
-
-             Int_t ftrack1 = mRaw->fTracks[1]; // qui doit etre le meme pour 
-                                               // la cathode 1 et 2
-              ihit= mRaw->fTracks[0];
-             //printf("icor, ftrack1 ihit %d %d %d\n",icor,ftrack1,ihit);
-
-              if (mRaw->fClusterType == 0 ) {
-
-                 if (maxidg<=20000) {
-                     if (flag == 0) {
-                         xtrg[maxidg]   = (Double_t) mCor->fY[3];
-                         ytrg[maxidg]   = (Double_t) mCor->fX[0];
-                         Int_t index1 = mCor->fCorrelIndex[3];
-                         mRaw1 = MUON->RawCluster(ich,1,index1);
-                         if (mRaw1->fClusterType==1 || mRaw1->fClusterType==2) {
-                           Float_t xclust=mCor->fX[3];
-                           Float_t yclust=mCor->fY[3];
-                           AliMUONchamber *iChamber=&(MUON->Chamber(ich));
-                           AliMUONsegmentation *seg = iChamber->GetSegmentationModel(1);
-                           Int_t ix,iy;
-                           seg->GetPadIxy(xclust,yclust,ix,iy);   
-                           Int_t isec=seg->Sector(ix,iy);
-                           printf("nev, CORRELATION with pure background in chamber sector %d  %d  %d !!!!!!!!!!!!!!!!!!!!!\n",nev,ich+1,isec);
-                           nbadcor++;
-                           
-                         } // end if cluster type on cathode 1
-                     }else {
-                         xtrg[maxidg]   = (Double_t) mCor->fY[3];
-                         ytrg[maxidg]   = (Double_t) mCor->fX[3];
-                     } // if iflag
-                     izch[maxidg]   = ich+1;
-                     xgeant[maxidg] = 0;
-                     ygeant[maxidg] = 0;
-                     clsize1[maxidg] = mult1;
-                     clsize2[maxidg] = mult2;
-
-                     cx[maxidg]     = 0; // Px/P of hit
-                     cy[maxidg]     = 0; // Py/P of hit
-                     cz[maxidg]     = 0; // Pz/P of hit
-                     itypg[maxidg]  = 0; // particle number
-                     ptotg[maxidg]  = 0; // P of hit
-                     idg[maxidg]    = 0;
-                     pvert1g[maxidg] = 0; // Px vertex
-                     pvert2g[maxidg] = 0; // Py vertex  
-                     pvert3g[maxidg] = 0; // Pz vertex
-                     zvertg[maxidg]  = 0; // z vertex     
-                     maxidg++;
-                     
-                 }// fin maxidg
-                 
-             } else if (mRaw->fClusterType ==1 && ftrack1 < 0) // background + resonance
-               {
-                  nres++;
-                 // get indexmap and loop over digits to find the signal
-                 Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
-                 gAlice->ResetDigits();
-                 if (flag==0) {
-                   //gAlice->TreeD()->GetEvent(2); // cathode 2
-                   gAlice->TreeD()->GetEvent(nent-1); // cathode 2
-                 } else {
-                   //gAlice->TreeD()->GetEvent(1); // cathode 1
-                   gAlice->TreeD()->GetEvent(nent-2); // cathode 1
-                 }
-
-                  TClonesArray *MUONdigits  = MUON->DigitsAddress(ich);
-                   Int_t mul=mRaw->fMultiplicity;
-                   Int_t trsign;
-                   for (int i=0;i<mul;i++) {
-                    Int_t idx=mRaw->fIndexMap[i];
-                     AliMUONdigit *dig= (AliMUONdigit*)MUONdigits->UncheckedAt(idx);
-                    trsign=dig->fTracks[0];
-                     ihit=dig->fHit-1;
-                     if (trsign > 0 && ihit >= 0) break;
-
-                  } // loop over indexmap
-
-                  //printf("trsign, ihit %d %d\n",trsign,ihit);
-                  //printf("signal+background : trsign  %d\n",trsign);
-                  
-                  if (trsign < 0 || ihit < 0) { // no signal muon  was found
-                    
-                    if (maxidg<=20000) {
-                      if (flag == 0) {
-                        xtrg[maxidg]   = (Double_t) mCor->fY[3];
-                        ytrg[maxidg]   = (Double_t) mCor->fX[0];
-                      }else {
-                        xtrg[maxidg]   = (Double_t) mCor->fY[3];
-                        ytrg[maxidg]   = (Double_t) mCor->fX[3];
-                      }
-                      
-                      izch[maxidg]   = ich+1;
-
-                     // initialisation of informations which 
-                     // can't be reached for background
-                      
-                      xgeant[maxidg] = 0; // only for resonances
-                      ygeant[maxidg] = 0; // only for resonances
-                      clsize1[maxidg] = mult1;
-                      clsize2[maxidg] = mult2;
-
-                      cx[maxidg]     = 0; // Px/P of hit
-                      cy[maxidg]     = 0; // Py/P of hit
-                      cz[maxidg]     = 0; // Pz/P of hit
-                      itypg[maxidg]  = 0; // particle number
-                      ptotg[maxidg]  = 0; // P of hit
-                      idg[maxidg]    = 0;
-                      pvert1g[maxidg] = 0; // Px vertex
-                      pvert2g[maxidg] = 0; // Py vertex  
-                      pvert3g[maxidg] = 0; // Pz vertex
-                      zvertg[maxidg]  = 0;                
-                      maxidg++;
-                      
-                    }// fin maxidg
-                  } else { // signal muon - retrieve info
-                    //printf("inside trsign, ihit %d %d\n",trsign,ihit);
-                    if (maxidg<=20000) {
-                      if (flag == 0) {
-                        xtrg[maxidg]   = (Double_t) mCor->fY[3];
-                        ytrg[maxidg]   = (Double_t) mCor->fX[0];
-                      }else {
-                        xtrg[maxidg]   = (Double_t) mCor->fY[3];
-                        ytrg[maxidg]   = (Double_t) mCor->fX[3];
-                      }
-                      izch[maxidg]   = ich+1;
-                      clsize1[maxidg] = mult1;
-                      clsize2[maxidg] = mult2;
-
-                     // initialise and set to the correct values 
-                     // if signal muons 
-                      
-                      xgeant[maxidg] = 0; // only for resonances
-                      ygeant[maxidg] = 0; // only for resonances
-                      
-                      cx[maxidg]     = 0; // Px/P of hit
-                      cy[maxidg]     = 0; // Py/P of hit
-                      cz[maxidg]     = 0; // Pz/P of hit
-                      itypg[maxidg]  = 0; // particle number
-                      ptotg[maxidg]  = 0; // P of hit
-                      idg[maxidg]    = 0;
-                      pvert1g[maxidg] = 0; // Px vertex
-                      pvert2g[maxidg] = 0; // Py vertex  
-                      pvert3g[maxidg] = 0; // Pz vertex
-                      zvertg[maxidg]  = 0;     
-                      // try to retrieve info about signal muons          
-                      gAlice->ResetHits();
-                      TH->GetEvent(trsign);
-
-                      TClonesArray *MUONhits  = MUON->Hits();
-                      AliMUONhit *mHit= (AliMUONhit*)MUONhits->
-                                                        UncheckedAt(ihit);
-                          TClonesArray *fPartArray = gAlice->Particles();
-                          TParticle *Part;
-                          Int_t nch=mHit->fChamber-1;
-                          //printf("sig+bgr ich, nch %d %d \n",ich,nch);
-                          if (nch==ich) {
-                            Int_t ftrack = mHit->fTrack;
-                            Int_t id = ((TParticle*) fPartArray->
-                                        UncheckedAt(ftrack))->GetPdgCode();
-                            if (id==kMuonPlus||id==kMuonMinus) {
-                                xgeant[maxidg] = (Double_t) mHit->fY;
-                                ygeant[maxidg] = (Double_t) mHit->fX;
-                                cx[maxidg]     = (Double_t) mHit->fCyHit; 
-                                cy[maxidg]     = (Double_t) mHit->fCxHit; 
-                                cz[maxidg]     = (Double_t) mHit->fCzHit; 
-
-                                if (id==kMuonPlus) {
-                                  itypg[maxidg]  = 5;
-                                } else if (id==kMuonMinus) {
-                                  itypg[maxidg]  = 6;
-                                } else itypg[maxidg]  = 0;
-                            
-                                ptotg[maxidg]  = (Double_t) mHit->fPTot;  
-                                Part = (TParticle*) fPartArray->
-                                                    UncheckedAt(ftrack);
-                                Int_t iparent = Part->GetFirstMother();
-                                Int_t id2;
-                                id2 = ((TParticle*) fPartArray->
-                                       UncheckedAt(ftrack))->GetPdgCode();
-                            
-                                if (iparent >= 0) {
-                                  Int_t ip;
-                                  while(1) {
-                                    ip=((TParticle*) fPartArray->
-                                      UncheckedAt(iparent))->GetFirstMother();
-                                    if (ip < 0) {
-                                      id2 = ((TParticle*) fPartArray->
-                                          UncheckedAt(iparent))->GetPdgCode();
-                                      break;
-                                    } else {
-                                      iparent = ip;
-                                      id2 = ((TParticle*) fPartArray->
-                                          UncheckedAt(iparent))->GetPdgCode();
-                                    } // ip<0
-                                  } // while
-                                }// iparent
-                                Int_t id1  = ftrack; 
-                                Int_t idum = trsign+1;
-                            
-                                if (id2==443 || id2==553) {
-                                  nres++;
-                                  if (id2==443) id2=114;
-                                  else id2=116;
-                                }
-                            
-                                idg[maxidg] = 30000*id1+10000*idum+id2;
-                                pvert1g[maxidg] = (Double_t) Part->Py(); 
-                                pvert2g[maxidg] = (Double_t) Part->Px();   
-                                pvert3g[maxidg] = (Double_t) Part->Pz(); 
-                                zvertg[maxidg]  = (Double_t) Part->Vz();  
-                            } //if muon                             
-                          } //if nch
-                    maxidg++;
-                    } // check limits
-                  } // sign+bgr, highest bgr
-             } 
-              //pure resonance or mixed cluster with the highest 
-             //contribution coming from resonance
-             if (mRaw->fClusterType >= 1 && ftrack1>=0)  
-               {                             
-                 if (maxidg<=20000) {
-                   if (flag == 0) {
-                     xtrg[maxidg]   = (Double_t) mCor->fY[3];
-                     ytrg[maxidg]   = (Double_t) mCor->fX[0];
-                   }else {
-                     xtrg[maxidg]   = (Double_t) mCor->fY[3];
-                     ytrg[maxidg]   = (Double_t) mCor->fX[3];
-                   }
-                   clsize1[maxidg] = mult1;
-                   clsize2[maxidg] = mult2;
-                   izch[maxidg]   = ich+1;
-
-                   Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
-                   gAlice->ResetDigits();
-                   if (flag==0) {
-                     //gAlice->TreeD()->GetEvent(2); // cathode 2
-                     gAlice->TreeD()->GetEvent(nent-1); // cathode 2
-                   } else {
-                     //gAlice->TreeD()->GetEvent(1);        // cathode 1
-                     gAlice->TreeD()->GetEvent(nent-2); // cathode 1
-                   }
-
-                   TClonesArray *MUONdigits  = MUON->DigitsAddress(ich);
-                   Int_t mul=mRaw->fMultiplicity;
-                   for (int i=0;i<mul;i++) {
-                     Int_t idx=mRaw->fIndexMap[i];
-                     AliMUONdigit *dig= (AliMUONdigit*)MUONdigits->UncheckedAt(idx);
-                     ihit=dig->fHit-1;
-                     if (ihit >= 0) break;
-
-                  } // loop over indexmap
-                   //printf("fClusterType, ihit %d %d \n",mRaw->fClusterType,ihit);
-                   if (ihit < 0) {
-                      xgeant[maxidg] = 0; // only for resonances
-                      ygeant[maxidg] = 0; // only for resonances
-                      
-                      cx[maxidg]     = 0; // Px/P of hit
-                      cy[maxidg]     = 0; // Py/P of hit
-                      cz[maxidg]     = 0; // Pz/P of hit
-                      itypg[maxidg]  = 0; // particle number
-                      ptotg[maxidg]  = 0; // P of hit
-                      idg[maxidg]    = 0;
-                      pvert1g[maxidg] = 0; // Px vertex
-                      pvert2g[maxidg] = 0; // Py vertex  
-                      pvert3g[maxidg] = 0; // Pz vertex
-                      zvertg[maxidg]  = 0;     
-                   } else {
-                   gAlice->ResetHits();
-                   TH->GetEvent(ftrack1);
-                   TClonesArray *MUONhits  = MUON->Hits();
-                   AliMUONhit *mHit= (AliMUONhit*)MUONhits->
-                                                       UncheckedAt(ihit);
-                          TClonesArray *fPartArray = gAlice->Particles();
-                          TParticle *Part;
-                          Int_t nch=mHit->fChamber-1;
-                          //printf("signal ich, nch %d %d \n",ich,nch);
-                          if (nch==ich) {
-                            Int_t ftrack = mHit->fTrack;
-                            Int_t id = ((TParticle*) fPartArray->
-                                        UncheckedAt(ftrack))->GetPdgCode();
-                            //printf("id %d \n",id);
-                            if (id==kMuonPlus||id==kMuonMinus) {
-                                xgeant[maxidg] = (Double_t) mHit->fY;
-                                ygeant[maxidg] = (Double_t) mHit->fX;
-                                cx[maxidg]     = (Double_t) mHit->fCyHit; 
-                                cy[maxidg]     = (Double_t) mHit->fCxHit; 
-                                cz[maxidg]     = (Double_t) mHit->fCzHit; 
-
-                                if (id==kMuonPlus) {
-                                  itypg[maxidg]  = 5;
-                                } else if (id==kMuonMinus) {
-                                  itypg[maxidg]  = 6;
-                                } else itypg[maxidg]  = 0;
-                            
-                                ptotg[maxidg]  = (Double_t) mHit->fPTot;  
-                                Part = (TParticle*) fPartArray->
-                                                    UncheckedAt(ftrack);
-                                Int_t iparent = Part->GetFirstMother();
-                                Int_t id2;
-                                id2 = ((TParticle*) fPartArray->
-                                       UncheckedAt(ftrack))->GetPdgCode();
-                            
-                                if (iparent >= 0) {
-                                  Int_t ip;
-                                  while(1) {
-                                    ip=((TParticle*) fPartArray->
-                                      UncheckedAt(iparent))->GetFirstMother();
-                                    if (ip < 0) {
-                                      id2 = ((TParticle*) fPartArray->
-                                          UncheckedAt(iparent))->GetPdgCode();
-                                      break;
-                                    } else {
-                                      iparent = ip;
-                                      id2 = ((TParticle*) fPartArray->
-                                          UncheckedAt(iparent))->GetPdgCode();
-                                    } // ip<0
-                                  } // while
-                                }// iparent
-                                Int_t id1  = ftrack; 
-                                Int_t idum = ftrack1+1;
-                            
-                                if (id2==443 || id2==553) {
-                                  nres++;
-                                  if (id2==443) id2=114;
-                                  else id2=116;
-                                }
-                                // printf("id2 %d\n",id2);
-                                idg[maxidg] = 30000*id1+10000*idum+id2;
-                                pvert1g[maxidg] = (Double_t) Part->Py(); 
-                                pvert2g[maxidg] = (Double_t) Part->Px();   
-                                pvert3g[maxidg] = (Double_t) Part->Pz(); 
-                                zvertg[maxidg]  = (Double_t) Part->Vz();  
-                            } //if muon                             
-                          } //if nch
-                   } // ihit
-                   maxidg++;
-                 } // check limits
-               } // if cluster type
-         } // icor loop
-      } // ich loop
-  }// if MUON
-
-
-  ievr = nev;
-  cout<<"evenement "<<ievr<<endl;
-  nhittot1 = maxidg ;
-  cout<<"nhittot1="<<nhittot1<<endl;
-
-  static Int_t nbres=0;
-  static Int_t nbcor=0; 
-  if (nres>=19) nbres++;
-  printf("nres ,nncor - %d %d\n",nres,nncor);
-  printf("nbres - %d\n",nbres);
-  if (nncor>=20) nbcor++;
-  printf("nbcor - %d\n",nbcor);
-  printf("nuncor - %d\n",nuncor);
-  printf("nbadcor - %d\n",nbadcor);
-  
-  TC->Reset();
-
-  hfile_global->cd();
-  
-}
-
-void trackf_fit(Int_t &ivertex, Double_t *pest, Double_t *pstep, Double_t &pxzinv, Double_t &tphi, Double_t &talam, Double_t &xvert, Double_t &yvert)
-{
-  //
-  //  Fit a track candidate with the following input parameters: 
-  //  INPUT :  IVERTEX  : vertex flag, if IVERTEX=1 (XVERT,YVERT) are free paramaters
-  //                                   if IVERTEX=1 (XVERT,YVERT)=(0.,0.) 
-  //           PEST(5)  : starting value of parameters (minuit)
-  //           PSTEP(5) : step size for parameters (minuit)
-  //  OUTPUT : PXZINV,TPHI,TALAM,XVERT,YVERT : fitted value of the parameters
-
-  static Double_t arglist[10];
-  static Double_t c[5] = {0.4, 0.45, 0.45, 90., 90.};
-  static Double_t b1, b2, epxz, efi, exs, exvert, eyvert;
-  TString chname;
-  Int_t ierflg = 0;
-  
-  TMinuit *gMinuit = new TMinuit(5);
-  gMinuit->mninit(5,10,7);
-  gMinuit->SetFCN(fcnfwrap);  // constant m.f.
-
-  arglist[0] = -1;
-  
-  gMinuit->mnexcm("SET PRINT", arglist, 1, ierflg);
-  //      gMinuit->mnseti('track fitting');
-  
-  gMinuit->mnparm(0, "invmom",  pest[0], pstep[0], -c[0], c[0], ierflg);
-  gMinuit->mnparm(1, "azimuth", pest[1], pstep[1], -c[1], c[1], ierflg);
-  gMinuit->mnparm(2, "deep",    pest[2], pstep[2], -c[2], c[2], ierflg);
-  if (ivertex==1) {
-    gMinuit->mnparm(3, "x ", pest[3], pstep[3], -c[3], c[3], ierflg);
-    gMinuit->mnparm(4, "y ", pest[4], pstep[4], -c[4], c[4], ierflg);  
-  }   
-  
-  gMinuit->mnexcm("SET NOGR", arglist, 0, ierflg);
-  gMinuit->mnexcm("MINIMIZE", arglist, 0, ierflg);
-  gMinuit->mnexcm("EXIT" , arglist, 0, ierflg);
-  
-  gMinuit->mnpout(0, chname, pxzinv, epxz, b1, b2, ierflg);
-  gMinuit->mnpout(1, chname, tphi, efi, b1, b2, ierflg);
-  gMinuit->mnpout(2, chname, talam, exs, b1, b2, ierflg);
-  if (ivertex==1) {
-    gMinuit->mnpout(3, chname, xvert, exvert, b1, b2, ierflg);
-    gMinuit->mnpout(4, chname, yvert, eyvert, b1, b2, ierflg);
-  }   
-  
-  delete gMinuit;
-
-}
-          
-void fcnf(Int_t &npar, Double_t *grad, Double_t &fval, Double_t *pest, Int_t iflag)
-{
-  //
-  // function called by trackf_fit
-      Int_t futil = 0;
-      fcn(npar,grad,fval,pest,iflag,futil);
-}
-
-void prec_fit(Double_t &pxzinv, Double_t &fis, Double_t &alams, Double_t &xvert, Double_t &yvert, Double_t &pxzinvf, Double_t &fif, Double_t &alf, Double_t &xvertf, Double_t &yvertf, Double_t &epxzinv, Double_t &efi, Double_t &exs, Double_t &exvert, Double_t &eyvert)
-{
-  // 
-  // minuit fits for tracking finding 
-                                                                            
-      static Double_t arglist[10];
-      static Double_t c1[5] = {0.001, 0.001, 0.001, 1., 1.};
-      static Double_t c2[5] = {0.5, 0.5, 0.5, 120., 120.};
-      static Double_t emat[9];
-      static Double_t b1, b2;
-      Double_t fmin, fedm, errdef; 
-      Int_t npari, nparx, istat;
-
-      TString chname;
-      Int_t ierflg = 0;
-      
-      TMinuit *gMinuit = new TMinuit(5);
-      gMinuit->mninit(5,10,7);
-      gMinuit->SetFCN(fcnfitfwrap);
-
-      arglist[0] = -1.;
-      gMinuit->mnexcm("SET PRINT", arglist, 1, ierflg);
-      
-      //      gMinuit->mnseti('track fitting');
-
-      gMinuit->mnparm(0,"invmom",   pxzinv, c1[0], -c2[0], c2[0], ierflg); // 0.003, 0.5
-      gMinuit->mnparm(1,"azimuth ", fis,    c1[1], -c2[1], c2[1], ierflg);
-      gMinuit->mnparm(2,"deep    ", alams,  c1[2], -c2[2], c2[2], ierflg);
-      gMinuit->mnparm(3,"xvert",    xvert,  c1[3], -c2[3], c2[3], ierflg);
-      gMinuit->mnparm(4,"yvert",    yvert,  c1[4], -c2[4], c2[4], ierflg);
-
-      gMinuit->mnexcm("SET NOGR", arglist, 0, ierflg);
-      arglist[0] = 2.;
-      gMinuit->mnexcm("MINIMIZE", arglist, 0, ierflg);
-      gMinuit->mnexcm("EXIT", arglist, 0, ierflg);
-      gMinuit->mnpout(0, chname, pxzinvf, epxzinv, b1, b2, ierflg);
-      gMinuit->mnpout(1, chname, fif, efi, b1, b2, ierflg);
-      gMinuit->mnpout(2, chname, alf, exs, b1, b2, ierflg);
-      gMinuit->mnpout(3, chname, xvertf, exvert, b1, b2, ierflg);
-      gMinuit->mnpout(4, chname, yvertf, eyvert, b1, b2, ierflg);
-  
-      gMinuit->mnemat(emat, 3);
-      gMinuit->mnstat(fmin, fedm, errdef, npari, nparx, istat);
-
-     delete gMinuit;
-}
-
-void fcnfitf(Int_t &npar, Double_t *grad, Double_t &fval, Double_t *xval, Int_t iflag)
-{
-  //
-  // function called by prec_fit 
-      Int_t futil = 0;
-      fcnfit(npar,grad,fval,xval,iflag,futil);
-}
-
-///////////////////// fin modifs perso //////////////////////
-
-ClassImp(AliMUONcluster)
-//___________________________________________
-AliMUONcluster::AliMUONcluster(Int_t *clhits)
-{
-   fHitNumber=clhits[0];
-   fCathode=clhits[1];
-   fQ=clhits[2];
-   fPadX=clhits[3];
-   fPadY=clhits[4];
-   fQpad=clhits[5];
-   fRSec=clhits[6];
-}
-ClassImp(AliMUONdigit)
-//_____________________________________________________________________________
-AliMUONdigit::AliMUONdigit(Int_t *digits)
-{
-  //
-  // Creates a MUON digit object to be updated
-  //
-    fPadX        = digits[0];
-    fPadY        = digits[1];
-    fSignal      = digits[2];
-    fPhysics     = digits[3];
-    fHit       = digits[4];
-
-}
-//_____________________________________________________________________________
-AliMUONdigit::AliMUONdigit(Int_t *tracks, Int_t *charges, Int_t *digits)
-{
-    //
-    // Creates a MUON digit object
-    //
-    fPadX        = digits[0];
-    fPadY        = digits[1];
-    fSignal      = digits[2];
-    fPhysics     = digits[3];
-    fHit       = digits[4];
-    for(Int_t i=0; i<10; i++) {
-       fTcharges[i]  = charges[i];
-       fTracks[i]    = tracks[i];
-    }
-}
-
-AliMUONdigit::~AliMUONdigit()
-{
-    
-}
-
-ClassImp(AliMUONlist)
-//____________________________________________________________________________
-    AliMUONlist::AliMUONlist(Int_t ich, Int_t *digits): 
-       AliMUONdigit(digits)
-{
-    //
-    // Creates a MUON digit list object
-    //
-
-    fChamber     = ich;
-    fTrackList   = new TObjArray;
-}
-
-ClassImp(AliMUONhit)
-//___________________________________________
-    AliMUONhit::AliMUONhit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
-       AliHit(shunt, track)
-{
-    fChamber=vol[0];
-    fParticle=hits[0];
-    fX=hits[1];
-    fY=hits[2];
-    fZ=hits[3];
-    fTheta=hits[4];
-    fPhi=hits[5];
-    fTlength=hits[6];
-    fEloss=hits[7];
-    fPHfirst=(Int_t) hits[8];
-    fPHlast=(Int_t) hits[9];
-
-    // modifs perso
-    fPTot=hits[10];
-    fCxHit=hits[11];
-    fCyHit=hits[12];
-    fCzHit=hits[13];
-}
-ClassImp(AliMUONcorrelation)
-//___________________________________________
-//_____________________________________________________________________________
-AliMUONcorrelation::AliMUONcorrelation(Int_t *idx, Float_t *x, Float_t *y)
-{
-    //
-    // Creates a MUON correlation object
-    //
-    for(Int_t i=0; i<4; i++) {
-       fCorrelIndex[i]  = idx[i];
-       fX[i]    = x[i];
-       fY[i]    = y[i];
-    }
-}
-ClassImp(AliMUONRawCluster)
-Int_t AliMUONRawCluster::Compare(TObject *obj)
-{
-  /*
-         AliMUONRawCluster *raw=(AliMUONRawCluster *)obj;
-        Float_t r=GetRadius();
-         Float_t ro=raw->GetRadius();
-         if (r>ro) return 1;
-         else if (r<ro) return -1;
-         else return 0;
-  */
-         AliMUONRawCluster *raw=(AliMUONRawCluster *)obj;
-        Float_t y=fY;
-         Float_t yo=raw->fY;
-         if (y>yo) return 1;
-         else if (y<yo) return -1;
-         else return 0;
-
-}
-
-Int_t AliMUONRawCluster::
-BinarySearch(Float_t y, TArrayF coord, Int_t from, Int_t upto)
-{
-   // Find object using a binary search. Array must first have been sorted.
-   // Search can be limited by setting upto to desired index.
-
-   Int_t low=from, high=upto-1, half;
-   while(high-low>1) {
-        half=(high+low)/2;
-        if(y>coord[half]) low=half;
-        else high=half;
-   }
-   return low;
-}
-
-void AliMUONRawCluster::SortMin(Int_t *idx,Float_t *xdarray,Float_t *xarray,Float_t *yarray,Float_t *qarray, Int_t ntr)
-{
-  //
-  // Get the 3 closest points(cog) one can find on the second cathode 
-  // starting from a given cog on first cathode
-  //
-  
-  //
-  //  Loop over deltax, only 3 times
-  //
-  
-    Float_t xmin;
-    Int_t jmin;
-    Int_t id[3] = {-2,-2,-2};
-    Float_t jx[3] = {0.,0.,0.};
-    Float_t jy[3] = {0.,0.,0.};
-    Float_t jq[3] = {0.,0.,0.};
-    Int_t jid[3] = {-2,-2,-2};
-    Int_t i,j,imax;
-  
-    if (ntr<3) imax=ntr;
-    else imax=3;
-    for(i=0;i<imax;i++){
-        xmin=1001.;
-        jmin=0;
-    
-        for(j=0;j<ntr;j++){
-            if ((i == 1 && j == id[i-1]) 
-                 ||(i == 2 && (j == id[i-1] || j == id[i-2]))) continue;
-           if (TMath::Abs(xdarray[j]) < xmin) {
-             xmin = TMath::Abs(xdarray[j]);
-             jmin=j;
-           }       
-        } // j
-        if (xmin != 1001.) {    
-           id[i]=jmin;
-           jx[i]=xarray[jmin]; 
-           jy[i]=yarray[jmin]; 
-           jq[i]=qarray[jmin]; 
-           jid[i]=idx[jmin];
-        } 
-    
-    }  // i
-  
-    for (i=0;i<3;i++){
-        if (jid[i] == -2) {
-            xarray[i]=1001.;
-            yarray[i]=1001.;
-            qarray[i]=1001.;
-            idx[i]=-1;
-        } else {
-            xarray[i]=jx[i];
-            yarray[i]=jy[i];
-            qarray[i]=jq[i];
-            idx[i]=jid[i];
-        }
-    }
-
-}
-
-
-Int_t AliMUONRawCluster::PhysicsContribution()
-{
-  Int_t iPhys=0;
-  Int_t iBg=0;
-  Int_t iMixed=0;
-  for (Int_t i=0; i<fMultiplicity; i++) {
-    if (fPhysicsMap[i]==2) iPhys++;
-    if (fPhysicsMap[i]==1) iMixed++;
-    if (fPhysicsMap[i]==0) iBg++;
-  }
-  if (iMixed==0 && iBg==0) {
-    return 2;
-  } else if ((iPhys != 0 && iBg !=0) || iMixed != 0) {
-    return 1;
-  } else {
-    return 0;
-  }
-}
-
-   
-ClassImp(AliMUONreccluster) 
-ClassImp(AliMUONsegmentation)
-ClassImp(AliMUONresponse)      
-
-
-
 
 
 
index fe92afe..e4f8188 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef MUON_H
-#define MUON_H
+#ifndef ALIMUON_H
+#define ALIMUON_H
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
 //  Manager and hits classes for set:MUON     //
 ////////////////////////////////////////////////
 #include "AliDetector.h"
-#include "AliHit.h"
-#include "AliMUONConst.h"
-#include "AliDigit.h"
-#include "AliMUONchamber.h"
-#include "AliMUONSegRes.h"
-#include <TVector.h>
-#include <TObjArray.h>
-#include <TArrayF.h>
-#include <TFile.h>
-#include <TTree.h>
-typedef enum {simple, medium, big} Cluster_t;
-
-static const int NCH=14;
-
-class AliMUONcluster;
+#include "AliMUONTriggerCircuit.h" // cp
+
+static const int kNCH=14;
+static const int kNTrackingCh=10;
+static const int kNTriggerCh=4;
+static const int kNTriggerCircuit=234;   
+
+class AliMUONChamber;
+class AliMUONLocalTrigger;
+class AliMUONGlobalTrigger;
+class AliMUONTriggerCircuit;
+class AliMUONTriggerDecision;
+class AliMUONSegmentation;
+class AliMUONResponse;
+class AliMUONHit;
+class AliMUONPadHit;
 class AliMUONRawCluster;
 class AliMUONClusterFinder;
-class AliMUONcorrelation;
-
-
-//----------------------------------------------
-
-class AliMUONcluster : public TObject {
-public:
-
-   Int_t     fHitNumber;    // Hit number
-   Int_t     fCathode;      // Cathode number
-   Int_t     fQ  ;          // Total charge      
-   Int_t     fPadX  ;       // Pad number along X
-   Int_t     fPadY  ;       // Pad number along Y
-   Int_t     fQpad  ;       // Charge per pad
-   Int_t     fRSec  ;       // R -sector of pad
-public:
-   AliMUONcluster() {
-      fHitNumber=fQ=fPadX=fPadY=fQpad=fRSec=0;   
-}
-   AliMUONcluster(Int_t *clhits);
-   virtual ~AliMUONcluster() {;}
-   ClassDef(AliMUONcluster,1)  //Cluster object for set:MUON
-};
-
-class AliMUONreccluster : public TObject {
-public:
-
-   Int_t     fTracks[3];      //labels of overlapped tracks
-
-   Int_t       fQ  ;          // Q of cluster (in ADC counts)     
-   Float_t     fX  ;          // X of cluster
-   Float_t     fY  ;          // Y of cluster
-
-public:
-   AliMUONreccluster() {
-       fTracks[0]=fTracks[1]=fTracks[2]=-1; 
-       fQ=0; fX=fY=0; 
-   }
-   virtual ~AliMUONreccluster() {;}
-   ClassDef(AliMUONreccluster,1)  //Cluster object for set:MUON
-};
-
-//_____________________________________________________________________________
-
-class AliMUONdigit : public TObject {
- public:
-    Int_t     fPadX;        // Pad number along x
-    Int_t     fPadY ;       // Pad number along y
-    Int_t     fSignal;      // Signal amplitude
-    Int_t     fTcharges[10];   // charge per track making this digit (up to 10)
-    Int_t     fTracks[10];     // primary tracks making this digit (up to 10)
-    Int_t     fPhysics;        // physics contribution to signal 
-    Int_t     fHit;            // hit number - temporary solution
-
-
- public:
-    AliMUONdigit() {}
-    AliMUONdigit(Int_t *digits);
-    AliMUONdigit(Int_t *tracks, Int_t *charges, Int_t *digits);
-    virtual ~AliMUONdigit();
-    
-    ClassDef(AliMUONdigit,1)  //Digits for set:MUON
-};
-//_____________________________________________________________________________
-
-class AliMUONlist : public AliMUONdigit {
- public:
-    Int_t          fChamber;       // chamber number of pad
-    TObjArray     *fTrackList; 
- public:
-    AliMUONlist() {fTrackList=0;}
-    AliMUONlist(Int_t rpad, Int_t *digits);
-    virtual ~AliMUONlist() {delete fTrackList;}
-    TObjArray  *TrackList()   {return fTrackList;}
-    ClassDef(AliMUONlist,1)  //Digits for set:MUON
-};
-//___________________________________________
+class AliMUONReconstHit;
+class TVector;
+class TObjArray;
+class TFile;
+class TTree;
 
 
-//___________________________________________
-class AliMUONhit : public AliHit {
- public:
-    Int_t     fChamber;       // Chamber number
-    Float_t   fParticle;      // Geant3 particle type
-    Float_t   fTheta ;        // Incident theta angle in degrees      
-    Float_t   fPhi   ;        // Incident phi angle in degrees
-    Float_t   fTlength;       // Track length inside the chamber
-    Float_t   fEloss;         // ionisation energy loss in gas   
-    Int_t     fPHfirst;       // first padhit
-    Int_t     fPHlast;        // last padhit
-
-// modifs perso
-    Float_t   fPTot;          // hit momentum P
-    Float_t   fCxHit;            // Px/P
-    Float_t   fCyHit;            // Py/P
-    Float_t   fCzHit;            // Pz/P
-
- public:
-    AliMUONhit() {}
-    AliMUONhit(Int_t fIshunt, Int_t track, Int_t *vol, Float_t *hits);
-    virtual ~AliMUONhit() {}
-    
-    ClassDef(AliMUONhit,1)  //Hits object for set:MUON
-};
-
 class AliMUON : public  AliDetector {
  public:
     AliMUON();
     AliMUON(const char *name, const char *title);
+    AliMUON(const AliMUON& rMUON);
     virtual       ~AliMUON();
-    virtual void   AddHit(Int_t, Int_t*, Float_t*);
-    virtual void   AddCluster(Int_t*);
-    virtual void   AddDigits(Int_t, Int_t*, Int_t*, Int_t*);
-    virtual void   AddRawCluster(Int_t, const AliMUONRawCluster&);
-    virtual void   AddCathCorrel(Int_t, Int_t*, Float_t*, Float_t*);
+    virtual void   AddHit(Int_t track , Int_t *vol, Float_t *hits);
+    virtual void   AddPadHit(Int_t* clhits);
+    virtual void   AddDigits(Int_t id, Int_t* tracks, Int_t* charges,
+                            Int_t* digits);
+    virtual void   AddRawCluster(Int_t id, const AliMUONRawCluster& clust);
     virtual void   BuildGeometry();
-    virtual void   CreateGeometry() {}
-    virtual void   CreateMaterials() {}
-    virtual void   StepManager();
+    void           AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
+                                   Int_t *singleUndef, Int_t *pairUnlike, 
+                                   Int_t *pairLike);
+    void           AddLocalTrigger(Int_t* ltrigger);
     Int_t          DistancetoPrimitive(Int_t px, Int_t py);
-    virtual Int_t  IsVersion() const =0;
-//
-    TClonesArray  *Clusters() {return fClusters;}
-    virtual  void  MakeTreeC(Option_t *option="C");
-    void           GetTreeC(Int_t);
+    virtual Int_t  IsVersion() const {return 0;}
+    TClonesArray  *PadHits() {return fPadHits;}
+    TClonesArray  *LocalTrigger() {return fLocalTrigger;}
+    TClonesArray  *GlobalTrigger() {return fGlobalTrigger;}
     virtual void   MakeBranch(Option_t *opt=" ");
     void           SetTreeAddress();
     virtual void   ResetHits();
     virtual void   ResetDigits();
+    virtual void   ResetTrigger();
     virtual void   ResetRawClusters();
-    virtual void   ResetCorrelation();
-    virtual void   FindClusters(Int_t,Int_t);
-    virtual void   Digitise(Int_t,Int_t,Option_t *opt1=" ",Option_t *opt2=" ",Text_t *name=" ");
-    virtual void   CathodeCorrelation(Int_t);
-    virtual void   SortTracks(Int_t *,Int_t *,Int_t);
-//
-// modifs perso
-
-    void     InitTracking(Double_t &, Double_t &, Double_t &);
-    void     Reconst(Int_t &,Int_t &,Int_t,Int_t &,Int_t&,Int_t&, Option_t *option,Text_t *filename);
-    void     FinishEvent();
-    void     CloseTracking();
-    void     SetCutPxz(Double_t p) {fSPxzCut=p;}
-    void     SetSigmaCut(Double_t p) {fSSigmaCut=p;}
-    void     SetXPrec(Double_t p) {fSXPrec=p;}
-    void     SetYPrec(Double_t p) {fSYPrec=p;}
-    Double_t GetCutPxz() {return fSPxzCut;}
-    Double_t GetSigmaCut() {return fSSigmaCut;}
-    Double_t GetXPrec() {return fSXPrec;}
-    Double_t GetYPrec() {return fSYPrec;}
-// fin modifs perso 
-    
+    // Cluster Finding
+    virtual void   FindClusters(Int_t event ,Int_t lastEntry);
+    // Digitisation 
+    virtual void   Digitise(Int_t nev,Int_t bgrEvent, Option_t *opt1=" ",
+                           Option_t *opt2=" ",Text_t *name=" ");
+    virtual void   SortTracks(Int_t *tracks,Int_t *charges, Int_t ntr);
 // Configuration Methods (per station id)
 //
 // Set Chamber Segmentation Parameters
-// id refers to the station and isec to the cathode plane   
-    virtual void   SetPADSIZ(Int_t id, Int_t isec, Float_t p1, Float_t p2);
-
+// id refers to the station and isec to the cathode plane
+// Set Z values for all chambers
+    virtual void SetChambersZ(const Float_t *Z);
+    virtual void SetChambersZToDefault(void);
+    virtual void SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2);
 // Set Signal Generation Parameters
     virtual void   SetSigmaIntegration(Int_t id, Float_t p1);
     virtual void   SetChargeSlope(Int_t id, Float_t p1);
     virtual void   SetChargeSpread(Int_t id, Float_t p1, Float_t p2);
     virtual void   SetMaxAdc(Int_t id, Float_t p1);
 // Set Segmentation and Response Model
-    virtual void   SetSegmentationModel(Int_t id, Int_t isec, AliMUONsegmentation *segmentation);
-    virtual void   SetResponseModel(Int_t id, AliMUONresponse *response);
+    virtual void   SetSegmentationModel(Int_t id, Int_t isec,
+                                       AliMUONSegmentation *segmentation);
+    virtual void   SetResponseModel(Int_t id, AliMUONResponse *response);
     virtual void   SetNsec(Int_t id, Int_t nsec);
 // Set Reconstruction Model
     virtual void   SetReconstructionModel(Int_t id, AliMUONClusterFinder *reconstruction);
@@ -209,46 +94,49 @@ class AliMUON : public  AliDetector {
     virtual void   SetMaxDestepAlu(Float_t p1);
     virtual void   SetMuonAcc(Bool_t acc=0, Float_t angmin=2, Float_t angmax=9);
 // Response Simulation
-    virtual void   MakePadHits(Float_t xhit,Float_t yhit,Float_t eloss,Int_t id);
+    virtual void   MakePadHits(Float_t xhit,Float_t yhit,
+                              Float_t eloss, Float_t tof, Int_t id);
+// get Trigger answer
+    void   Trigger(Int_t nev);
 // Return reference to Chamber #id
-    virtual AliMUONchamber& Chamber(Int_t id) {return *((AliMUONchamber *) (*fChambers)[id]);}
+    virtual AliMUONChamber& Chamber(Int_t id)
+       {return *((AliMUONChamber *) (*fChambers)[id]);}
+// Return reference to Circuit #id
+    virtual AliMUONTriggerCircuit& TriggerCircuit(Int_t id)
+      {return *((AliMUONTriggerCircuit *) (*fTriggerCircuits)[id]);}
 // Retrieve pad hits for a given Hit
-    virtual AliMUONcluster* FirstPad(AliMUONhit *, TClonesArray *);
-    virtual AliMUONcluster* NextPad(TClonesArray *);
-// Return pointers to digits 
+    virtual AliMUONPadHit* FirstPad(AliMUONHit *hit, TClonesArray *padHits);
+    virtual AliMUONPadHit* NextPad(TClonesArray *padHits);
+// Return pointers to digits
     TObjArray            *Dchambers() {return fDchambers;}
     Int_t                *Ndch() {return fNdch;}
-    virtual TClonesArray *DigitsAddress(Int_t id) {return ((TClonesArray *) (*fDchambers)[id]);}
+    virtual TClonesArray *DigitsAddress(Int_t id)
+       {return ((TClonesArray *) (*fDchambers)[id]);}
 // Return pointers to reconstructed clusters
     TObjArray            *RawClusters() {return fRawClusters;}
-    Int_t                *Nrawch() {return fNrawch;}
-    virtual TClonesArray *RawClustAddress(Int_t id) {return ((TClonesArray *) (*fRawClusters)[id]);}
-
-// modifs perso
-    AliMUONRawCluster *RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster);
+    Int_t                *Nrawch() {return fNrawch;} 
+    virtual TClonesArray *RawClustAddress(Int_t id) 
+       {return ((TClonesArray *) (*fRawClusters)[id]);}
+
+    AliMUONRawCluster    *RawCluster(Int_t ichamber, Int_t icathod,
+                                    Int_t icluster);
+// Copy Operator
+    AliMUON& operator = (const AliMUON& rhs);
     
-    
-    // Return pointers to list of correlated clusters
-    TObjArray            *CathCorrel() {return fCathCorrel;}
-    Int_t                *Ncorch() {return fNcorch;}
-    virtual TClonesArray *CathCorrelAddress(Int_t id)
-       {return ((TClonesArray *) (*fCathCorrel)[id]);}
-
-// Return pointer to TreeC
-    TTree      *TreeC() {return fTreeC;} 
+           
  protected:
     TObjArray            *fChambers;           // List of Tracking Chambers
-    Int_t                fNclusters;           // Number of clusters
-    TClonesArray         *fClusters;           // List of clusters
+    TObjArray            *fTriggerCircuits;   // List of Trigger Circuits
+    Int_t                 fNPadHits;           // Number of pad hits
+    TClonesArray         *fPadHits;            // List of pad hits
     TObjArray            *fDchambers;          // List of digits
     Int_t                *fNdch;               // Number of digits
-
-
-    TObjArray            *fRawClusters;            // List of raw clusters
-    Int_t                *fNrawch;                 // Number of raw clusters
-    TObjArray            *fCathCorrel;             // List of correlated clusters
-    Int_t                *fNcorch;                 // Number of correl clusters
-    TTree                *fTreeC;                  // Cathode correl index tree
+    TObjArray            *fRawClusters;        // List of raw clusters
+    Int_t                *fNrawch;             // Number of raw clusters
+    Int_t                 fNLocalTrigger;      // Number of Local Trigger 
+    TClonesArray         *fLocalTrigger;       // List of Local Trigger      
+    Int_t                 fNGlobalTrigger;     // Number of Global Trigger
+    TClonesArray         *fGlobalTrigger;      // List of Global Trigger  
 
 //
     Bool_t   fAccCut;          //Transport acceptance cut
@@ -261,84 +149,20 @@ class AliMUON : public  AliDetector {
    Float_t fMaxStepAlu;      // Maximum step size inside the chamber aluminum
    Float_t fMaxDestepGas;    // Maximum relative energy loss in gas
    Float_t fMaxDestepAlu;    // Maximum relative energy loss in aluminum
-//
-// modifs perso
-//  Parameters for reconstruction program
-   Double_t fSPxzCut;        // Pxz cut  (GeV/c) to begin the track finding
-   Double_t fSSigmaCut;      // Number of sig. delimiting the searching areas
-   Double_t fSXPrec;         // Chamber precision in X (cm) 
-   Double_t fSYPrec;         // Chamber precision in Y (cm)
 
-   Text_t *fFileName;
-   
- protected:
 
-   ClassDef(AliMUON,1)  //Hits manager for set:MUON
-};
-//___________________________________________
 
-class AliMUONRawCluster : public TObject {
-public:
+// Pad Iterator
+   Int_t fMaxIterPad;        // Maximum pad index
+   Int_t fCurIterPad;        // Current pad index
+// Background eent for event mixing
+   Text_t *fFileName;           // File with background hits
+   TTree *fTrH1;                 // Hits Tree for background event
+   TClonesArray *fHits2;        // List of hits for one track only
+   TClonesArray *fPadHits2;     // List of clusters for one track only
 
-   Int_t     fTracks[3];      //labels of overlapped tracks
-   Int_t       fQ  ;          // Q of cluster (in ADC counts)     
-   Float_t     fX  ;          // X of cluster
-   Float_t     fY  ;          // Y of cluster
-   Int_t       fPeakSignal;
-   Int_t       fIndexMap[50];  //indeces of digits
-   Int_t       fOffsetMap[50]; //Emmanuel special
-   Float_t     fContMap[50];   //Contribution from digit
-   Int_t       fPhysicsMap[50];
-   Int_t       fMultiplicity;  //cluster multiplicity
-   Int_t       fNcluster[2];
-   Int_t       fClusterType;   
- public:
-   AliMUONRawCluster() {
-       fTracks[0]=fTracks[1]=fTracks[2]=-1; 
-       fQ=0; fX=fY=0; fMultiplicity=0;
-       for (int k=0;k<50;k++) {
-           fIndexMap[k]=-1;
-           fOffsetMap[k]=0;
-          fContMap[k]=0;
-          fPhysicsMap[k]=-1;
-       }
-       fNcluster[0]=fNcluster[1]=-1;
-   }
-   virtual ~AliMUONRawCluster() {}
-
-   Float_t GetRadius() {return TMath::Sqrt(fX*fX+fY*fY);}
-
-   Bool_t IsSortable() const {return kTRUE;}
-   Int_t  Compare(TObject *obj);
-   Int_t PhysicsContribution();
-   static Int_t BinarySearch(Float_t r, TArrayF, Int_t from, Int_t upto);
-   static void  SortMin(Int_t *,Float_t *,Float_t *,Float_t *,Float_t *,Int_t);
-   ClassDef(AliMUONRawCluster,1)  //Cluster object for set:MUON
-};
-
-//___________________________________________
-class AliMUONcorrelation : public TObject {
-public:
-
-  // correlation starts from the 1-st cathode  
-  // last number in arrays corresponds to cluster on 1-st cathode
-
-   Int_t       fCorrelIndex[4];  // entry number in TreeR for the associated 
-                                 // cluster candidates on the 2-nd cathode
-   Float_t     fX[4]  ;          // X of clusters on the 2-nd cathode  
-   Float_t     fY[4]  ;          // Y of clusters
-
-public:
-   AliMUONcorrelation() {
-       fCorrelIndex[0]=fCorrelIndex[1]=fCorrelIndex[2]=fCorrelIndex[3]=0;
-       fX[0]=fX[1]=fX[2]=fX[3]=0; fY[0]=fY[1]=fY[2]=fY[3]=0; 
-   }
-   AliMUONcorrelation(Int_t *idx, Float_t *x, Float_t *y);
-   virtual ~AliMUONcorrelation() {}
-   ClassDef(AliMUONcorrelation,1)  //Cathode correlation object for set:MUON
+   ClassDef(AliMUON,1)  //Hits manager for set:MUON
 };
-
 #endif
 
 
diff --git a/MUON/AliMUONChamber.cxx b/MUON/AliMUONChamber.cxx
new file mode 100644 (file)
index 0000000..29b3a47
--- /dev/null
@@ -0,0 +1,163 @@
+/**************************************************************************
+ * 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$
+Revision 1.1.2.5  2000/06/09 21:27:01  morsch
+Most coding rule violations corrected.
+
+Revision 1.1.2.4  2000/05/05 11:34:12  morsch
+Log inside comments.
+
+Revision 1.1.2.3  2000/05/05 10:09:52  morsch
+Log messages included
+*/
+
+#include "AliMUONChamber.h"
+#include "AliMUONSegmentation.h"
+#include "AliMUONResponse.h"
+
+#include "TMath.h"
+ClassImp(AliMUONChamber)       
+
+    AliMUONChamber::AliMUONChamber() 
+{
+    fSegmentation = new TObjArray(2);
+    (*fSegmentation)[0] = 0;
+    (*fSegmentation)[1] = 0;    
+    fResponse=0;
+    fnsec=1;
+    fReconstruction=0;
+}
+
+AliMUONChamber::~AliMUONChamber() 
+{
+    if (fSegmentation) delete fSegmentation;
+}
+
+AliMUONChamber::AliMUONChamber(const AliMUONChamber& rChamber)
+{
+// Dummy copy constructor
+    ;
+}
+
+
+void AliMUONChamber::Init()
+{
+// Initalisation ..
+//
+// ... for chamber segmentation
+    if ((*fSegmentation)[0]) 
+    ((AliMUONSegmentation *) (*fSegmentation)[0])->Init(this);
+
+    if (fnsec==2) {
+       if ((*fSegmentation)[1])
+       ((AliMUONSegmentation *) (*fSegmentation)[1])->Init(this);
+    }
+}
+
+Int_t   AliMUONChamber::SigGenCond(Float_t x, Float_t y, Float_t z)
+{
+// Ask segmentation if signal should be generated 
+    if (fnsec==1) {
+       return ((AliMUONSegmentation*) (*fSegmentation)[0])
+           ->SigGenCond(x, y, z) ;
+    } else {
+       return (((AliMUONSegmentation*) (*fSegmentation)[0])
+               ->SigGenCond(x, y, z)) ||
+           (((AliMUONSegmentation*) (*fSegmentation)[1])
+            ->SigGenCond(x, y, z)) ;
+    }
+}
+
+
+void    AliMUONChamber::SigGenInit(Float_t x, Float_t y, Float_t z)
+{
+//
+// Initialisation of segmentation for hit
+//  
+    if (fnsec==1) {
+       ((AliMUONSegmentation*) (*fSegmentation)[0])->SigGenInit(x, y, z) ;
+    } else {
+       ((AliMUONSegmentation*) (*fSegmentation)[0])->SigGenInit(x, y, z) ;
+       ((AliMUONSegmentation*) (*fSegmentation)[1])->SigGenInit(x, y, z) ;
+    }
+}
+
+void AliMUONChamber::DisIntegration(Float_t eloss, Float_t tof, 
+                                   Float_t xhit, Float_t yhit,
+                                   Int_t& nnew,Float_t newclust[6][500]) 
+{
+//    
+//  Generates pad hits (simulated cluster) 
+//  using the segmentation and the response model 
+    Float_t dx, dy;
+    //
+    // Width of the integration area
+    //
+    dx=fResponse->SigmaIntegration()*fResponse->ChargeSpreadX();
+    dy=fResponse->SigmaIntegration()*fResponse->ChargeSpreadY();
+    //
+    // Get pulse height from energy loss
+    Float_t qtot = fResponse->IntPH(eloss);
+    //
+    // Loop Over Pads
+    
+    Float_t qcheck=0, qp;
+    nnew=0;
+    for (Int_t i=1; i<=fnsec; i++) {
+       qcheck=0;
+       AliMUONSegmentation * segmentation=
+           (AliMUONSegmentation *) (*fSegmentation)[i-1];
+       for (segmentation->FirstPad(xhit, yhit, dx, dy); 
+            segmentation->MorePads(); 
+            segmentation->NextPad()) 
+       {
+           qp=fResponse->IntXY(segmentation);
+           qp=TMath::Abs(qp);
+           
+//
+//
+           if (qp > 1.e-4) {
+               qcheck+=qp;
+           //
+           // --- store signal information
+               newclust[0][nnew]=qtot;                     // total charge
+               newclust[1][nnew]=segmentation->Ix();       // ix-position of pad
+               newclust[2][nnew]=segmentation->Iy();       // iy-position of pad
+               newclust[3][nnew]=qp * qtot;                // charge on pad
+               newclust[4][nnew]=segmentation->ISector();  // sector id
+               newclust[5][nnew]=(Float_t) i;              // counter
+               nnew++;
+           }
+       } // Pad loop
+    } // Cathode plane loop
+}
+
+
+
+void AliMUONChamber::InitGeo(Float_t zpos)
+{
+//    sensitive gas gap
+      fdGas= 0.5;
+//    3% radiation length of aluminum (X0=8.9 cm)      
+      fdAlu= 3.0/100*8.9;
+}
+
+
+AliMUONChamber & AliMUONChamber::operator =(const AliMUONChamber& rhs)
+{
+// Dummy assignment operator
+    return *this;
+}
diff --git a/MUON/AliMUONChamber.h b/MUON/AliMUONChamber.h
new file mode 100644 (file)
index 0000000..001a817
--- /dev/null
@@ -0,0 +1,128 @@
+#ifndef ALIMUONCHAMBER_H
+#define ALIMUONCHAMBER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+#include "TObjArray.h"
+#include "AliMUONSegmentation.h"
+#include "AliMUONResponse.h"
+
+class AliMUONClusterFinder;
+//class AliMUONResponse ;
+//class AliMUONSegmentation ;
+
+class AliMUONChamber:
+public TObject
+{
+ public:
+    AliMUONChamber();
+    AliMUONChamber(const AliMUONChamber & rChamber);
+    virtual ~AliMUONChamber();
+    
+//
+// Get GEANT id of sensitive volume
+  virtual Int_t   GetGid() {return fGid;}
+// Set GEANT id of sensitive volume
+  virtual void    SetGid(Int_t id) {fGid=id;}
+//  
+// Initialisation
+  virtual void    Init();
+// Set z-position of chamber  
+  virtual void    SetZ(Float_t Z) {fZ = Z;}
+// Get z-position of chamber  
+  virtual Float_t Z(){return fZ;}
+// Set inner radius of sensitive volume 
+  virtual void SetRInner(Float_t rmin) {frMin=rmin;}
+// Set outer radius of sensitive volum  
+  virtual void SetROuter(Float_t rmax) {frMax=rmax;}  
+
+// Return inner radius of sensitive volume 
+  virtual  Float_t RInner()            {return frMin;}
+// Return outer radius of sensitive volum  
+  virtual Float_t ROuter()            {return frMax;}  
+//  
+// Set response model
+  virtual void    SetResponseModel(AliMUONResponse* thisResponse) {fResponse=thisResponse;}
+//  
+// Set segmentation model
+  virtual void    SetSegmentationModel(Int_t i, AliMUONSegmentation* thisSegmentation) {
+      (*fSegmentation)[i-1] = thisSegmentation;
+  }
+// Set Cluster reconstruction model  
+  virtual void    SetReconstructionModel(AliMUONClusterFinder *thisReconstruction) {
+      fReconstruction = thisReconstruction;
+  }
+//  
+//  Get pointer to response model
+  virtual AliMUONResponse* &ResponseModel(){return fResponse;}
+//  
+//  Get reference to segmentation model
+  virtual AliMUONSegmentation*  SegmentationModel(Int_t isec) {
+      return (AliMUONSegmentation *) (*fSegmentation)[isec-1];
+  }
+  virtual TObjArray* ChamberSegmentation() {return fSegmentation;}
+//  Get pointer to cluster reconstruction model
+  virtual AliMUONClusterFinder* &ReconstructionModel(){return fReconstruction;}
+// Get number of segmentation sectors  
+  virtual Int_t Nsec()              {return fnsec;}
+// Set number of segmented cathodes (1 or 2)  
+  virtual void  SetNsec(Int_t nsec) {fnsec=nsec;}
+//
+// Member function forwarding to the segmentation and response models
+//
+// Calculate pulse height from energy loss  
+  virtual Float_t IntPH(Float_t eloss) {return fResponse->IntPH(eloss);}
+//  
+// Ask segmentation if signal should be generated  
+  virtual Int_t   SigGenCond(Float_t x, Float_t y, Float_t z);
+//
+// Initialisation of segmentation for hit  
+  virtual void    SigGenInit(Float_t x, Float_t y, Float_t z);
+// Configuration forwarding
+//
+// Define signal distribution region
+// by number of sigmas of the distribution function
+  virtual void   SetSigmaIntegration(Float_t p1)
+      {fResponse->SetSigmaIntegration(p1);}
+// Set the single electron pulse-height (ADCchan/e)  
+  virtual void   SetChargeSlope(Float_t p1)              {fResponse->SetChargeSlope(p1);}
+// Set width of charge distribution function  
+  virtual void   SetChargeSpread(Float_t p1, Float_t p2) {fResponse->SetChargeSpread(p1,p2);}
+// Set maximum ADC count value
+  virtual void   SetMaxAdc(Float_t p1)                   {fResponse->SetMaxAdc(p1);}
+// Set Pad size
+  virtual void   SetPadSize(Int_t isec, Float_t p1, Float_t p2) {
+      ((AliMUONSegmentation*) (*fSegmentation)[isec-1])->SetPadSize(p1,p2);
+  }
+//  
+// Cluster formation method (charge disintegration)
+  virtual void   DisIntegration(Float_t eloss, Float_t tof,
+                               Float_t xhit, Float_t yhit,
+                               Int_t& x, Float_t newclust[6][500]);
+// Initialize geometry related parameters  
+  virtual void    InitGeo(Float_t z);
+//
+  virtual Float_t DGas() {return fdGas;}
+  virtual Float_t DAlu() {return fdAlu;}  
+// assignment operator  
+  virtual AliMUONChamber& operator =(const AliMUONChamber& rhs);
+  
+ protected:
+
+  Float_t fdGas; // half gaz gap
+  Float_t fdAlu; // half Alu width  
+  Int_t   fGid;  // GEANT volume if for sensitive volume of this chamber
+  Float_t fZ;    // Z position (cm)
+  Int_t   fnsec; // number of semented cathode planes
+  Float_t frMin; // innermost sensitive radius
+  Float_t frMax; // outermost sensitive radius
+
+  TObjArray            *fSegmentation;    // pointer to segmentation
+  AliMUONClusterFinder *fReconstruction;  // pointer to reconstruction
+  AliMUONResponse      *fResponse;        // pointer to response
+  ClassDef(AliMUONChamber,1) // Muon tracking and trigger chamber class
+};
+
+#endif
diff --git a/MUON/AliMUONChamberTrigger.cxx b/MUON/AliMUONChamberTrigger.cxx
new file mode 100644 (file)
index 0000000..0ae5613
--- /dev/null
@@ -0,0 +1,126 @@
+/**************************************************************************
+ * 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$
+Revision 1.1.2.3  2000/06/09 21:27:35  morsch
+Most coding rule violations corrected.
+
+Revision 1.1.2.2  2000/04/26 12:28:25  morsch
+- flag pad hits with condition on ToF (CP)
+- Tof included in the method DisIntegration (CP)
+
+Revision 1.1.2.1  2000/02/17 14:30:54  morsch
+Draft version
+
+*/
+
+#include "AliMUONChamberTrigger.h"
+#include "AliMUONSegmentationTrigger.h"
+#include "AliMUONResponseTrigger.h"
+#include <TObjArray.h>
+#include <TMath.h>
+#include <iostream.h>
+
+ClassImp(AliMUONChamberTrigger)
+
+//-------------------------------------------
+AliMUONChamberTrigger::AliMUONChamberTrigger() : AliMUONChamber()
+{
+// Default Constructor
+}
+
+//-------------------------------------------
+void AliMUONChamberTrigger::DisIntegration(Float_t eloss, Float_t tof, 
+                                          Float_t xhit, Float_t yhit, 
+                                          Int_t& nnew,
+                                          Float_t newclust[6][500]) 
+{
+//    
+//  Generates pad hits (simulated cluster) 
+//  using the segmentation and the response model
+
+  Int_t twentyNano;
+  if (tof<75*pow(10,-9)) {
+    twentyNano=1;
+  } else {
+    twentyNano=100;
+  }
+
+  //  cout << " time = " << tof << " , " << twentyNano << "\n";
+
+  Float_t qp;
+  nnew=0;
+  for (Int_t i=1; i<=fnsec; i++) {
+    AliMUONSegmentation * segmentation=
+      (AliMUONSegmentation*) (*fSegmentation)[i-1];
+    
+// Find the module & strip Id. which has fired
+    Int_t ix,iy;
+    
+    segmentation->GetPadIxy(xhit,yhit,ix,iy);
+    segmentation->SetPad(ix,iy);
+
+// treatment of GEANT hits w/o corresponding strip (due to the fact that
+// the 2 geometries are computed in a very slightly different way) 
+    if (ix==0&&iy==0) {
+      cout << " AliMUONChamberTrigger hit w/o strip " << xhit << " , " << yhit << "\n";
+    } else {          
+      // --- store signal information for this strip
+      newclust[0][nnew]=1.;                       // total charge
+      newclust[1][nnew]=ix;                       // ix-position of pad
+      newclust[2][nnew]=iy;                       // iy-position of pad
+      newclust[3][nnew]=twentyNano;               // time of flight
+      newclust[4][nnew]=segmentation->ISector();  // sector id
+      newclust[5][nnew]=(Float_t) i;              // counter
+      nnew++;
+      // set hits
+      segmentation->SetHit(xhit,yhit);
+      // get the list of nearest neighbours
+      Int_t nList, xList[2], yList[2];
+      segmentation->Neighbours(ix,iy,&nList,xList,yList);
+      
+      for (Int_t j=0; j<nList; j++){
+       
+       // neighbour real coordinates (just for checks here)
+       Float_t x,y;
+       segmentation->GetPadCxy(xList[j],yList[j],x,y);
+       // set pad (fx fy & fix fiy are the current pad coord. & Id.)
+       segmentation->SetPad(xList[j],yList[j]);
+       // get the chamber (i.e. current strip) response
+       qp=fResponse->IntXY(segmentation);        
+       
+       if (qp > 0.5) {
+         // --- store signal information for neighbours 
+         newclust[0][nnew]=qp;                       // total charge
+         newclust[1][nnew]=segmentation->Ix();       // ix-position of pad
+         newclust[2][nnew]=segmentation->Iy();       // iy-position of pad
+         newclust[3][nnew]=twentyNano;               // time of flight
+         newclust[4][nnew]=segmentation->ISector();  // sector id
+         newclust[5][nnew]=(Float_t) i;              // counter
+         nnew++;
+       } // qp > 0.5  
+      } // loop on neighbour
+    } // endif hit w/o strip
+  } // loop over planes
+}
+
+
+
+
+
+
+
+
diff --git a/MUON/AliMUONChamberTrigger.h b/MUON/AliMUONChamberTrigger.h
new file mode 100644 (file)
index 0000000..1664ca1
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef ALIMUONCHAMBERTRIGGER_H
+#define ALIMUONCHAMBERTRIGGER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+#include "AliMUONChamber.h"
+
+
+class AliMUONClusterFinder;
+class AliMUONSegmentationTrigger ;
+class AliMUONResponseTrigger ;
+
+class AliMUONChamberTrigger:
+public AliMUONChamber {
+ public:
+    AliMUONChamberTrigger();
+    virtual ~AliMUONChamberTrigger(){}
+// Cluster formation method (charge disintegration)
+
+  virtual void   DisIntegration(Float_t eloss, Float_t tof, Float_t xhit, Float_t yhit,
+                               Int_t& nnew, Float_t newclust[6][500]);
+
+  ClassDef(AliMUONChamberTrigger,1) // Muon trigger chamber class
+      };
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
index 2ba0347..430946b 100644 (file)
 
 /*
 $Log$
+Revision 1.4.4.2  2000/06/09 21:58:15  morsch
+Most coding rule violations corrected.
+
 */
 
 #include "AliMUONClusterFinder.h"
-#include "TTree.h"
+#include "AliMUON.h"
+#include "AliMUONHitMap.h"
+#include "AliMUONHitMapA1.h"
+#include "AliMUONSegmentation.h"
+#include "AliMUONResponse.h"
+#include "AliMUONDigit.h"
+#include "AliMUONRawCluster.h"
 #include "AliRun.h"
+
+
+#include <TTree.h>
 #include <TCanvas.h>
 #include <TH1.h>
+#include <TF1.h>
 #include <TPad.h>
 #include <TGraph.h> 
 #include <TPostScript.h> 
 #include <TMinuit.h> 
+#include <TClonesArray.h> 
+
+//_____________________________________________________________________
+static AliMUONSegmentation* fgSegmentation;
+static AliMUONResponse*     fgResponse;
+static Int_t                fgix[500];
+static Int_t                fgiy[500];
+static Float_t              fgCharge[500];
+static Int_t                fgNbins;
+static Int_t                fgFirst=kTRUE;
+static Int_t                fgChargeTot;
+static Float_t              fgQtot;
+static TMinuit*             fgMyMinuit ;
+// This function is minimized in the double-Mathieson fit
+void fcn2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
+void fcn1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
 
-//----------------------------------------------------------
-static AliMUONsegmentation* gSegmentation;
-static AliMUONresponse*     gResponse;
-static Int_t                gix[500];
-static Int_t                giy[500];
-static Float_t              gCharge[500];
-static Int_t                gNbins;
-static Int_t                gFirst=kTRUE;
-static TMinuit *gMyMinuit ;
-void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
-static Int_t                gChargeTot;
 
-//----------------------------------------------------------
 
 ClassImp(AliMUONClusterFinder)
 
     AliMUONClusterFinder::AliMUONClusterFinder
-(AliMUONsegmentation *segmentation, AliMUONresponse *response, 
- TClonesArray *digits, Int_t chamber)   
+       (AliMUONSegmentation *segmentation, 
+       AliMUONResponse *response, 
+       TClonesArray *digits, Int_t chamber)   
 {
+// Constructor    
     fSegmentation=segmentation;
     fResponse=response;
     
@@ -64,9 +83,9 @@ ClassImp(AliMUONClusterFinder)
 
     AliMUONClusterFinder::AliMUONClusterFinder()
 {
+// Default constructor
     fSegmentation=0;
     fResponse=0;
-    
     fDigits=0;
     fNdigits = 0;
     fChamber=-1;
@@ -80,13 +99,33 @@ ClassImp(AliMUONClusterFinder)
     fNPeaks=-1;
 }
 
+AliMUONClusterFinder::AliMUONClusterFinder(
+    const AliMUONClusterFinder & clusterFinder)
+{
+// Dummy copy Constructor
+    ;
+}
+
+AliMUONClusterFinder::~AliMUONClusterFinder()
+{
+// Destructor
+    delete fRawClusters;
+}
+
+void AliMUONClusterFinder::SetDigits(TClonesArray *MUONdigits) 
+{
+// Set pointer to digits
+    fDigits=MUONdigits;
+    fNdigits = fDigits->GetEntriesFast();
+}
+
 void AliMUONClusterFinder::AddRawCluster(const AliMUONRawCluster c)
 {
   //
   // Add a raw cluster copy to the list
   //
-    AliMUON *MUON=(AliMUON*)gAlice->GetModule("MUON");
-    MUON->AddRawCluster(fChamber,c); 
+    AliMUON *pMUON=(AliMUON*)gAlice->GetModule("MUON");
+    pMUON->AddRawCluster(fChamber,c); 
     fNRawClusters++;
 }
 
@@ -94,15 +133,14 @@ void AliMUONClusterFinder::AddRawCluster(const AliMUONRawCluster c)
 
 void AliMUONClusterFinder::Decluster(AliMUONRawCluster *cluster)
 {
-//    AliMUONdigit *dig;
-//    Int_t q;
-
+// Decluster composite clusters
+    Bool_t fitted;
     
-    Int_t mul = cluster->fMultiplicity;
-//    printf("Decluster - multiplicity   %d \n",mul);
-
+    Int_t mul = cluster->fMultiplicity[0];
     if (mul == 1 || mul ==2) {
-//     printf("\n Nothing special for 1- and 2-clusters \n");
+       if (mul==2) {
+           fitted=SingleMathiesonFit(cluster);
+       }
 //
 // Nothing special for 1- and 2-clusters
        if (fNPeaks != 0) {
@@ -114,15 +152,15 @@ void AliMUONClusterFinder::Decluster(AliMUONRawCluster *cluster)
     } else if (mul ==3) {
 //
 // 3-cluster, check topology
-//     printf("\n 3-cluster, check topology \n");
+// 
+// This part could be activated again in the future
        if (fDeclusterFlag) {
-         if (Centered(cluster)) {
-           // ok, cluster is centered 
-           //      printf("\n ok, cluster is centered \n");
-         } else {
-           // cluster is not centered, split into 2+1
-           //      printf("\n cluster is not centered, split into 2+1 \n");
-         }
+           if (Centered(cluster)) {
+               // ok, cluster is centered
+               fitted = SingleMathiesonFit(cluster);       
+           } else {
+               // cluster is not centered, split into 2+1
+           }
        } else {
          if (fNPeaks != 0) {
             cluster->fNcluster[0]=fNPeaks;
@@ -132,44 +170,42 @@ void AliMUONClusterFinder::Decluster(AliMUONRawCluster *cluster)
          fNPeaks++;
        }           
     } else {
-      //if (mul < 12) {
-         //      printf("Decluster - multiplicity > 45   %d \n",mul);
-         //printf("Decluster - multiplicity < 25   %d \n",mul);
 // 
 // 4-and more-pad clusters
 //
-      if (mul <= fClusterSize) {
-       if (fDeclusterFlag) {
-           SplitByLocalMaxima(cluster);
-       } else {
-           if (fNPeaks != 0) {
-               cluster->fNcluster[0]=fNPeaks;
-               cluster->fNcluster[1]=0;
-            } 
-           AddRawCluster(*cluster);
-           fNPeaks++;
-       }       
-      }
-       //}
+       if (mul <= fClusterSize) {
+           if (fDeclusterFlag) {
+               SplitByLocalMaxima(cluster);
+           } else {
+               if (fNPeaks != 0) {
+                   cluster->fNcluster[0]=fNPeaks;
+                   cluster->fNcluster[1]=0;
+               } 
+               fitted=SingleMathiesonFit(cluster);
+               AddRawCluster(*cluster);
+               fNPeaks++;
+           } // if Declustering selected
+       } // if < maximum clustersize for deconvolution 
     } // multiplicity 
 }
 
 
 Bool_t AliMUONClusterFinder::Centered(AliMUONRawCluster *cluster)
 {
-    AliMUONdigit* dig;
-    dig= (AliMUONdigit*)fDigits->UncheckedAt(cluster->fIndexMap[0]);
+// True if cluster is centered
+    AliMUONDigit* dig;
+    dig= (AliMUONDigit*)fDigits->UncheckedAt(cluster->fIndexMap[0][0]);
     Int_t ix=dig->fPadX;
     Int_t iy=dig->fPadY;
     Int_t nn;
-    Int_t X[kMaxNeighbours], Y[kMaxNeighbours], XN[kMaxNeighbours], YN[kMaxNeighbours];
+    Int_t x[kMaxNeighbours], y[kMaxNeighbours], xN[kMaxNeighbours], yN[kMaxNeighbours];
     
-    fSegmentation->Neighbours(ix,iy,&nn,X,Y);
+    fSegmentation->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]) == used) {
-           XN[nd]=X[i];
-           YN[nd]=Y[i];
+       if (fHitMap->TestHit(x[i],y[i]) == kUsed) {
+           xN[nd]=x[i];
+           yN[nd]=y[i];
            nd++;
        }
     }
@@ -179,41 +215,41 @@ Bool_t AliMUONClusterFinder::Centered(AliMUONRawCluster *cluster)
        if (fNPeaks != 0) {
             cluster->fNcluster[0]=fNPeaks;
             cluster->fNcluster[1]=0;
-        }  
+       }  
        AddRawCluster(*cluster);
        fNPeaks++;
        return kTRUE;
-    } else if (nd ==1) {
+    } else if (nd == 1) {
 //
 // Highest signal on an edge, split cluster into 2+1
 //
 // who is the neighbour ?
-       Int_t nind=fHitMap->GetHitIndex(XN[0], YN[0]);
-       Int_t i1= (nind==cluster->fIndexMap[1]) ? 1:2;
-       Int_t i2= (nind==cluster->fIndexMap[1]) ? 2:1;    
+       Int_t nind=fHitMap->GetHitIndex(xN[0], yN[0]);
+       Int_t i1= (nind==cluster->fIndexMap[1][0]) ? 1:2;
+       Int_t i2= (nind==cluster->fIndexMap[1][0]) ? 2:1;    
 //
 // 2-cluster
        AliMUONRawCluster cnew;
        if (fNPeaks == 0) {
-            cnew.fNcluster[0]=-1;
+           cnew.fNcluster[0]=-1;
             cnew.fNcluster[1]=fNRawClusters;
         } else {
             cnew.fNcluster[0]=fNPeaks;
             cnew.fNcluster[1]=0;
         }
-       cnew.fMultiplicity=2;
-       cnew.fIndexMap[0]=cluster->fIndexMap[0];
-       cnew.fIndexMap[1]=cluster->fIndexMap[i1];
+       cnew.fMultiplicity[0]=2;
+       cnew.fIndexMap[0][0]=cluster->fIndexMap[0][0];
+       cnew.fIndexMap[1][0]=cluster->fIndexMap[i1][0];
        FillCluster(&cnew);
        cnew.fClusterType=cnew.PhysicsContribution();
        AddRawCluster(cnew);
         fNPeaks++;
 //
 // 1-cluster
-       cluster->fMultiplicity=1;
-       cluster->fIndexMap[0]=cluster->fIndexMap[i2];
-       cluster->fIndexMap[1]=0;
-       cluster->fIndexMap[2]=0;        
+       cluster->fMultiplicity[0]=1;
+       cluster->fIndexMap[0][0]=cluster->fIndexMap[i2][0];
+       cluster->fIndexMap[1][0]=0;
+       cluster->fIndexMap[2][0]=0;     
        FillCluster(cluster);
         if (fNPeaks != 0) {
             cluster->fNcluster[0]=fNPeaks;
@@ -225,304 +261,176 @@ Bool_t AliMUONClusterFinder::Centered(AliMUONRawCluster *cluster)
        return kFALSE;
     } else {
        printf("\n Completely screwed up %d !! \n",nd);
-       
     }
     
-       return kFALSE;
+    return kFALSE;
 }
+
 void AliMUONClusterFinder::SplitByLocalMaxima(AliMUONRawCluster *c)
 {
-    AliMUONdigit* dig[100], *digt;
-    Int_t ix[100], iy[100], q[100];
-    Float_t x[100], y[100];
-    Int_t i; // loops over digits
-    Int_t j; // loops over local maxima
-    //    Float_t xPeak[2];
-    //    Float_t yPeak[2];
-    //    Int_t threshold=500;
-    Int_t mul=c->fMultiplicity;
+// Search for local maxima and split cluster accordingly
+    Bool_t fitted;
+    
+    AliMUONDigit* digt;
+     Int_t i; // loops over digits
+     Int_t j; // loops over local maxima
+     fMul=c->fMultiplicity[0];
 //
 //  dump digit information into arrays
 //
-    for (i=0; i<mul; i++)
+    for (i=0; i<fMul; i++)
     {
-       dig[i]= (AliMUONdigit*)fDigits->UncheckedAt(c->fIndexMap[i]);
-       ix[i]= dig[i]->fPadX;
-       iy[i]= dig[i]->fPadY;
-       q[i] = dig[i]->fSignal;
-       fSegmentation->GetPadCxy(ix[i], iy[i], x[i], y[i]);
+       fDig[i]= (AliMUONDigit*)fDigits->UncheckedAt(c->fIndexMap[i][0]);
+       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]);
     }
 //
 //  Find local maxima
 //
-    Bool_t IsLocal[100];
-    Int_t NLocal=0;
-    Int_t AssocPeak[100];
-    Int_t IndLocal[100];
+    fNLocal=0;
+    Bool_t isLocal[100];
+    Int_t assocPeak[100];
     Int_t nn;
-    Int_t X[kMaxNeighbours], Y[kMaxNeighbours];
-    for (i=0; i<mul; i++) {
-       fSegmentation->Neighbours(ix[i], iy[i], &nn, X, Y);
-       IsLocal[i]=kTRUE;
+    Int_t x[kMaxNeighbours], y[kMaxNeighbours];
+    for (i=0; i<fMul; i++) {
+       fSegmentation->Neighbours(fIx[i], fIy[i], &nn, x, y);
+       isLocal[i]=kTRUE;
        for (j=0; j<nn; j++) {
-           if (fHitMap->TestHit(X[j],Y[j])==empty) continue;
-           digt=(AliMUONdigit*) fHitMap->GetHit(X[j], Y[j]);
-           if (digt->fSignal > q[i]) {
-               IsLocal[i]=kFALSE;
+           if (fHitMap->TestHit(x[j], y[j])==kEmpty) continue;
+           digt=(AliMUONDigit*) fHitMap->GetHit(x[j], y[j]);
+           if (digt->fSignal > fQ[i]) {
+               isLocal[i]=kFALSE;
                break;
 //
 // handle special case of neighbouring pads with equal signal
-           } else if (digt->fSignal == q[i]) {
-               if (NLocal >0) {
-                   for (Int_t k=0; k<NLocal; k++) {
-                       if (X[j]==ix[IndLocal[k]] && Y[j]==iy[IndLocal[k]]){
-                           IsLocal[i]=kFALSE;
-                       }
-                   }
-               }
+           } else if (digt->fSignal == fQ[i]) {
+               if (fNLocal >0) {
+                   for (Int_t k=0; k<fNLocal; k++) {
+                       if (x[j]==fIx[fIndLocal[k]] && y[j]==fIy[fIndLocal[k]])
+                       {
+                           isLocal[i]=kFALSE;
+                       } 
+                   } // loop over local maxima
+               } // are there are already local maxima
            } 
        } // loop over next neighbours
        // Maxima should not be on the edge
-       if (IsLocal[i]) {
-           IndLocal[NLocal]=i;
-           NLocal++;
+       if (isLocal[i]) {
+           fIndLocal[fNLocal]=i;
+           fNLocal++;
        } 
     } // loop over all digits
-//    printf("Found %d local Maxima",NLocal);
+//    printf("Found %d local Maxima",fNLocal);
 //
 // If only one local maximum found but multiplicity is high 
 // take global maximum from the list of digits.    
-    if (NLocal==1 && mul>12) {
+// 12 should not be hard wired but a parameter 
+// 
+    if (fNLocal==1 && fMul>=1) {
        Int_t nnew=0;
-       for (i=0; i<mul; i++) {
-           if (!IsLocal[i]) {
-               IndLocal[NLocal]=i;
-               IsLocal[i]=kTRUE;
-               NLocal++;
+       for (i=0; i<fMul; i++) {
+           if (!isLocal[i]) {
+               fIndLocal[fNLocal]=i;
+               isLocal[i]=kTRUE;
+               fNLocal++;
                nnew++;
            }
            if (nnew==1) break;
        }
     }
     
-// If number of local maxima is 2 try to fit a double gaussian
-    if (NLocal==2) {
-//
-//  Initialise global variables for fit
-       gFirst=1;
-       gSegmentation=fSegmentation;
-       gResponse    =fResponse;
-       gNbins=mul;
-       
-       for (i=0; i<mul; i++) {
-           gix[i]=ix[i];
-           giy[i]=iy[i];
-           gCharge[i]=Float_t(q[i]);
-       }
-//
-       if (gFirst) {
-         gFirst=kFALSE;
-         gMyMinuit = new TMinuit(5);
+// If number of local maxima is 2 try to fit a double mathieson
+    if (fNLocal==2) {
+       fitted = DoubleMathiesonFit(c);
+    }
+    
+    if (fNLocal !=2 || !fitted) {
+       // Check if enough local clusters have been found,
+       // if not add global maxima to the list 
+       //
+       Int_t nPerMax;
+       if (fNLocal!=0) {
+           nPerMax=fMul/fNLocal;
+       } else {
+           printf("\n Warning, no local maximum found \n");
+           nPerMax=fNperMax+1;
        }
-       gMyMinuit->SetFCN(fcn);
-       gMyMinuit->mninit(5,10,7);
-       Double_t arglist[20];
-       Int_t ierflag=0;
-       arglist[0]=1;
-//     gMyMinuit->mnexcm("SET ERR",arglist,1,ierflag);
-// Set starting values 
-       static Double_t vstart[5];
-       vstart[0]=x[IndLocal[0]];
-       vstart[1]=y[IndLocal[0]];       
-       vstart[2]=x[IndLocal[1]];
-       vstart[3]=y[IndLocal[1]];       
-       vstart[4]=Float_t(q[IndLocal[0]])/
-           Float_t(q[IndLocal[0]]+q[IndLocal[1]]);
-// lower and upper limits
-       static Double_t lower[5], upper[5];
-       Int_t isec=fSegmentation->Sector(ix[IndLocal[0]], iy[IndLocal[0]]);
-       lower[0]=vstart[0]-fSegmentation->Dpx(isec)/2;
-       lower[1]=vstart[1]-fSegmentation->Dpy(isec)/2;
-//     lower[1]=vstart[1];
-       
-       upper[0]=lower[0]+fSegmentation->Dpx(isec);
-       upper[1]=lower[1]+fSegmentation->Dpy(isec);
-//     upper[1]=vstart[1];
-       
-       isec=fSegmentation->Sector(ix[IndLocal[1]], iy[IndLocal[1]]);
-       lower[2]=vstart[2]-fSegmentation->Dpx(isec)/2;
-       lower[3]=vstart[3]-fSegmentation->Dpy(isec)/2;
-//     lower[3]=vstart[3];
-       
-       upper[2]=lower[2]+fSegmentation->Dpx(isec);
-       upper[3]=lower[3]+fSegmentation->Dpy(isec);
-//     upper[3]=vstart[3];
-       
-       lower[4]=0.;
-       upper[4]=1.;
-// step sizes
-       static Double_t step[5]={0.005, 0.03, 0.005, 0.03, 0.01};
-       
-       gMyMinuit->mnparm(0,"x1",vstart[0],step[0],lower[0],upper[0],ierflag);
-       gMyMinuit->mnparm(1,"y1",vstart[1],step[1],lower[1],upper[1],ierflag);
-       gMyMinuit->mnparm(2,"x2",vstart[2],step[2],lower[2],upper[2],ierflag);
-       gMyMinuit->mnparm(3,"y2",vstart[3],step[3],lower[3],upper[3],ierflag);
-       gMyMinuit->mnparm(4,"a0",vstart[4],step[4],lower[4],upper[4],ierflag);
-// ready for minimisation      
-       gMyMinuit->SetPrintLevel(-1);
-       gMyMinuit->mnexcm("SET OUT", arglist, 0, ierflag);
-       arglist[0]= -1;
-       arglist[1]= 0;
-       
-       gMyMinuit->mnexcm("SET NOGR", arglist, 0, ierflag);
-       gMyMinuit->mnexcm("SCAN", arglist, 0, ierflag);
-       gMyMinuit->mnexcm("EXIT" , arglist, 0, ierflag);
-// Print results
-//     Double_t amin,edm,errdef;
-//     Int_t nvpar,nparx,icstat;
-//     gMyMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat);
-//     gMyMinuit->mnprin(3,amin);
-// Get fitted parameters
 
-       Double_t xrec[2], yrec[2], qfrac;
-       TString chname;
-       Double_t epxz, b1, b2;
-       Int_t ierflg;
-       gMyMinuit->mnpout(0, chname, xrec[0], epxz, b1, b2, ierflg);    
-       gMyMinuit->mnpout(1, chname, yrec[0], epxz, b1, b2, ierflg);    
-       gMyMinuit->mnpout(2, chname, xrec[1], epxz, b1, b2, ierflg);    
-       gMyMinuit->mnpout(3, chname, yrec[1], epxz, b1, b2, ierflg);    
-       gMyMinuit->mnpout(4, chname, qfrac,   epxz, b1, b2, ierflg);    
-       printf("\n %f %f %f %f %f\n", xrec[0], yrec[0], xrec[1], yrec[1],qfrac);
-//     delete gMyMinuit;
-       
-       
- //
- // One cluster for each maximum
- //
-        for (j=0; j<2; j++) {
-            AliMUONRawCluster cnew;
-            if (fNPeaks == 0) {
-                cnew.fNcluster[0]=-1;
-                cnew.fNcluster[1]=fNRawClusters;
-            } else {
-                cnew.fNcluster[0]=fNPeaks;
-                cnew.fNcluster[1]=0;
-            }
-            cnew.fMultiplicity=0;
-            cnew.fX=Float_t(xrec[j]);
-            cnew.fY=Float_t(yrec[j]);
-            if (j==0) {
-                cnew.fQ=Int_t(gChargeTot*qfrac);
-            } else {
-                cnew.fQ=Int_t(gChargeTot*(1-qfrac));
-            }
-            gSegmentation->SetHit(xrec[j],yrec[j]);
-            for (i=0; i<mul; i++) {
-                cnew.fIndexMap[cnew.fMultiplicity]=c->fIndexMap[i];
-                gSegmentation->SetPad(gix[i], giy[i]);
-                Float_t q1=gResponse->IntXY(gSegmentation);
-                cnew.fContMap[cnew.fMultiplicity]=Float_t(q[i])/(q1*cnew.fQ);
-                cnew.fMultiplicity++;
-            }
-            FillCluster(&cnew,0);
-            //printf("\n x,y %f %f ", cnew.fX, cnew.fY);
-            cnew.fClusterType=cnew.PhysicsContribution();
-            AddRawCluster(cnew);
-            fNPeaks++;
-        }
-     }
-
-     Bool_t fitted=kTRUE;
-
-     if (NLocal !=2 || !fitted) {
- // Check if enough local clusters have been found,
- // if not add global maxima to the list 
- //
-        Int_t nPerMax;
-        if (NLocal!=0) {
-            nPerMax=mul/NLocal;
-        } else {
-            printf("\n Warning, no local maximum found \n");
-            nPerMax=fNperMax+1;
-        }
-
-        if (nPerMax > fNperMax) {
-            Int_t nGlob=mul/fNperMax-NLocal+1;
-            if (nGlob > 0) {
-                Int_t nnew=0;
-                for (i=0; i<mul; i++) {
-                    if (!IsLocal[i]) {
-                        IndLocal[NLocal]=i;
-                        IsLocal[i]=kTRUE;
-                        NLocal++;
-                        nnew++;
-                    }
-                    if (nnew==nGlob) break;
-                }
-            }
-        }
- //
- // Associate hits to peaks
- //
-        for (i=0; i<mul; i++) {
-            Float_t dmin=1.E10;
-            Float_t qmax=0;
-            if (IsLocal[i]) continue;
-            for (j=0; j<NLocal; j++) {
-                Int_t il=IndLocal[j];
-                Float_t d=TMath::Sqrt((x[i]-x[il])*(x[i]-x[il])
-                                  +(y[i]-y[il])*(y[i]-y[il]));
-                Float_t ql=q[il];
+       if (nPerMax > fNperMax) {
+           Int_t nGlob=fMul/fNperMax-fNLocal+1;
+           if (nGlob > 0) {
+               Int_t nnew=0;
+               for (i=0; i<fMul; i++) {
+                   if (!isLocal[i]) {
+                       fIndLocal[fNLocal]=i;
+                       isLocal[i]=kTRUE;
+                       fNLocal++;
+                       nnew++;
+                   }
+                   if (nnew==nGlob) break;
+               }
+           }
+       }
+       //
+       // Associate hits to peaks
+       //
+       for (i=0; i<fMul; i++) {
+           Float_t dmin=1.E10;
+           Float_t qmax=0;
+           if (isLocal[i]) continue;
+           for (j=0; j<fNLocal; j++) {
+               Int_t il=fIndLocal[j];
+               Float_t d=TMath::Sqrt((fX[i]-fX[il])*(fX[i]-fX[il])
+                                     +(fY[i]-fY[il])*(fY[i]-fY[il]));
+               Float_t ql=fQ[il];
  //
  // Select nearest peak
  //
-                if (d<dmin) {
-                    dmin=d;
-                    qmax=ql;
-                    AssocPeak[i]=j;
-                } else if (d==dmin) {
+               if (d<dmin) {
+                   dmin=d;
+                   qmax=ql;
+                   assocPeak[i]=j;
+               } else if (d==dmin) {
  //
  // If more than one take highest peak
  //
-                    if (ql>qmax) {
-                        dmin=d;
-                        qmax=ql;
-                        AssocPeak[i]=j;
-                    }
-                }
-            }
-        }
-
-
- //
- // One cluster for each maximum
- //
-        for (j=0; j<NLocal; j++) {
-            AliMUONRawCluster cnew;
-            if (fNPeaks == 0) {
-                cnew.fNcluster[0]=-1;
-                cnew.fNcluster[1]=fNRawClusters;
-            } else {
-                cnew.fNcluster[0]=fNPeaks;
-                cnew.fNcluster[1]=0;
-            }
-            cnew.fIndexMap[0]=c->fIndexMap[IndLocal[j]];
-            cnew.fMultiplicity=1;
-            for (i=0; i<mul; i++) {
-                if (IsLocal[i]) continue;
-                if (AssocPeak[i]==j) {
-                    cnew.fIndexMap[cnew.fMultiplicity]=c->fIndexMap[i];
-                    cnew.fMultiplicity++;
-                }
-            }
-            FillCluster(&cnew);
-            cnew.fClusterType=cnew.PhysicsContribution();
-            AddRawCluster(cnew);
-            fNPeaks++;
-        }
-     }
-     
+                   if (ql>qmax) {
+                       dmin=d;
+                       qmax=ql;
+                       assocPeak[i]=j;
+                   }
+               }
+           }
+       }
+       //
+       // One cluster for each maximum
+       //
+       for (j=0; j<fNLocal; j++) {
+           AliMUONRawCluster cnew;
+           if (fNPeaks == 0) {
+               cnew.fNcluster[0]=-1;
+               cnew.fNcluster[1]=fNRawClusters;
+           } else {
+               cnew.fNcluster[0]=fNPeaks;
+               cnew.fNcluster[1]=0;
+           }
+           cnew.fIndexMap[0][0]=c->fIndexMap[fIndLocal[j]][0];
+           cnew.fMultiplicity[0]=1;
+           for (i=0; i<fMul; i++) {
+               if (isLocal[i]) continue;
+               if (assocPeak[i]==j) {
+                   cnew.fIndexMap[cnew.fMultiplicity[0]][0]=c->fIndexMap[i][0];
+                   cnew.fMultiplicity[0]++;
+               }
+           }
+           FillCluster(&cnew);
+           cnew.fClusterType=cnew.PhysicsContribution();
+           AddRawCluster(cnew);
+           fNPeaks++;
+       }
+    }
 }
 
 
@@ -531,92 +439,77 @@ void  AliMUONClusterFinder::FillCluster(AliMUONRawCluster* c, Int_t flag)
 //
 //  Completes cluster information starting from list of digits
 //
-    AliMUONdigit* dig;
+    AliMUONDigit* dig;
     Float_t x, y;
     Int_t  ix, iy;
     Float_t frac=0;
     
-    c->fPeakSignal=0;
+    c->fPeakSignal[0]=0;
     if (flag) {
-       c->fX=0;
-       c->fY=0;
-       c->fQ=0;
+       c->fX[0]=0;
+       c->fY[0]=0;
+       c->fQ[0]=0;
     }
-    //c->fQ=0;
  
 
-    for (Int_t i=0; i<c->fMultiplicity; i++)
+    for (Int_t i=0; i<c->fMultiplicity[0]; i++)
     {
-       dig= (AliMUONdigit*)fDigits->UncheckedAt(c->fIndexMap[i]);
-       ix=dig->fPadX+c->fOffsetMap[i];
+       dig= (AliMUONDigit*)fDigits->UncheckedAt(c->fIndexMap[i][0]);
+       ix=dig->fPadX+c->fOffsetMap[i][0];
        iy=dig->fPadY;
        Int_t q=dig->fSignal;
        if (dig->fPhysics >= dig->fSignal) {
-         c->fPhysicsMap[i]=2;
+           c->fPhysicsMap[i]=2;
        } else if (dig->fPhysics == 0) {
-         c->fPhysicsMap[i]=0;
+           c->fPhysicsMap[i]=0;
        } else  c->fPhysicsMap[i]=1;
 //
 //
 // peak signal and track list
        if (flag) {
-          if (q>c->fPeakSignal) {
-             c->fPeakSignal=q;
-/*
-           c->fTracks[0]=dig->fTracks[0];
-           c->fTracks[1]=dig->fTracks[1];
-           c->fTracks[2]=dig->fTracks[2];
-*/
-             //c->fTracks[0]=dig->fTrack;
-           c->fTracks[0]=dig->fHit;
-           c->fTracks[1]=dig->fTracks[0];
-           c->fTracks[2]=dig->fTracks[1];
-          }
+           if (q>c->fPeakSignal[0]) {
+               c->fPeakSignal[0]=q;
+               c->fTracks[0]=dig->fHit;
+               c->fTracks[1]=dig->fTracks[0];
+               c->fTracks[2]=dig->fTracks[1];
+           }
        } else {
-          if (c->fContMap[i] > frac) {
-              frac=c->fContMap[i];
-             c->fPeakSignal=q;
-/*
-           c->fTracks[0]=dig->fTracks[0];
-           c->fTracks[1]=dig->fTracks[1];
-           c->fTracks[2]=dig->fTracks[2];
-*/
-             //c->fTracks[0]=dig->fTrack;
-           c->fTracks[0]=dig->fHit;
-           c->fTracks[1]=dig->fTracks[0];
-           c->fTracks[2]=dig->fTracks[1];
-          }
+           if (c->fContMap[i][0] > frac) {
+               frac=c->fContMap[i][0];
+               c->fPeakSignal[0]=q;
+               c->fTracks[0]=dig->fHit;
+               c->fTracks[1]=dig->fTracks[0];
+               c->fTracks[2]=dig->fTracks[1];
+           }
        }
 //
        if (flag) {
            fSegmentation->GetPadCxy(ix, iy, x, y);
-           c->fX += q*x;
-           c->fY += q*y;
-           c->fQ += q;
+           c->fX[0] += q*x;
+           c->fY[0] += q*y;
+           c->fQ[0] += q;
        }
-
     } // loop over digits
-
- if (flag) {
-     
-     c->fX/=c->fQ;
-     c->fX=fSegmentation->GetAnod(c->fX);
-     c->fY/=c->fQ; 
+    
+    if (flag) {
+       c->fX[0]/=c->fQ[0];
+       c->fX[0]=fSegmentation->GetAnod(c->fX[0]);
+       c->fY[0]/=c->fQ[0]; 
 //
 //  apply correction to the coordinate along the anode wire
 //
-     x=c->fX;   
-     y=c->fY;
-     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);
-     
-     if (CogCorr) {
-        Float_t YonPad=(c->fY-y)/fSegmentation->Dpy(isec);
-        c->fY=c->fY-CogCorr->Eval(YonPad, 0, 0);
-     }
- }
+       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);
+       
+       if (cogCorr) {
+           Float_t yOnPad=(c->fY[0]-y)/fSegmentation->Dpy(isec);
+           c->fY[0]=c->fY[0]-cogCorr->Eval(yOnPad, 0, 0);
+       }
+    }
 }
 
 
@@ -627,18 +520,11 @@ void  AliMUONClusterFinder::FindCluster(Int_t i, Int_t j, AliMUONRawCluster &c){
 //
 //  Add i,j as element of the cluster
 //    
-    
     Int_t idx = fHitMap->GetHitIndex(i,j);
-    AliMUONdigit* dig = (AliMUONdigit*) fHitMap->GetHit(i,j);
+    AliMUONDigit* dig = (AliMUONDigit*) fHitMap->GetHit(i,j);
     Int_t q=dig->fSignal;
-    if (q > TMath::Abs(c.fPeakSignal)) {
-       c.fPeakSignal=q;
-/*
-       c.fTracks[0]=dig->fTracks[0];
-       c.fTracks[1]=dig->fTracks[1];
-       c.fTracks[2]=dig->fTracks[2];
-*/
-       //c.fTracks[0]=dig->fTrack;
+    if (q > TMath::Abs(c.fPeakSignal[0])) {
+       c.fPeakSignal[0]=q;
        c.fTracks[0]=dig->fHit;
        c.fTracks[1]=dig->fTracks[0];
        c.fTracks[2]=dig->fTracks[1];
@@ -646,54 +532,54 @@ void  AliMUONClusterFinder::FindCluster(Int_t i, Int_t j, AliMUONRawCluster &c){
 //
 //  Make sure that list of digits is ordered 
 // 
-    Int_t mu=c.fMultiplicity;
-    c.fIndexMap[mu]=idx;
-
+    Int_t mu=c.fMultiplicity[0];
+    c.fIndexMap[mu][0]=idx;
+    
     if (dig->fPhysics >= dig->fSignal) {
         c.fPhysicsMap[mu]=2;
     } else if (dig->fPhysics == 0) {
         c.fPhysicsMap[mu]=0;
     } else  c.fPhysicsMap[mu]=1;
-
+    
     if (mu > 0) {
        for (Int_t ind=mu-1; ind>=0; ind--) {
-           Int_t ist=(c.fIndexMap)[ind];
-           Int_t ql=((AliMUONdigit*)fDigits
+           Int_t ist=(c.fIndexMap)[ind][0];
+           Int_t ql=((AliMUONDigit*)fDigits
                      ->UncheckedAt(ist))->fSignal;
            if (q>ql) {
-               c.fIndexMap[ind]=idx;
-               c.fIndexMap[ind+1]=ist;
+               c.fIndexMap[ind][0]=idx;
+               c.fIndexMap[ind+1][0]=ist;
            } else {
                break;
            }
        }
     }
     
-    c.fMultiplicity++;
+    c.fMultiplicity[0]++;
     
-    if (c.fMultiplicity >= 50 ) {
-       printf("FindCluster - multiplicity >50  %d \n",c.fMultiplicity);
-       c.fMultiplicity=49;
+    if (c.fMultiplicity[0] >= 50 ) {
+       printf("FindCluster - multiplicity >50  %d \n",c.fMultiplicity[0]);
+       c.fMultiplicity[0]=49;
     }
 
 // Prepare center of gravity calculation
     Float_t x, y;
     fSegmentation->GetPadCxy(i, j, x, y);
-    c.fX += q*x;
-    c.fY += q*y;
-    c.fQ += q;
+    c.fX[0] += q*x;
+    c.fY[0] += q*y;
+    c.fQ[0] += q;
 // Flag hit as taken  
     fHitMap->FlagHit(i,j);
 //
 //  Now look recursively for all neighbours
 //  
     Int_t nn;
-    Int_t Xlist[kMaxNeighbours], Ylist[kMaxNeighbours];
-    fSegmentation->Neighbours(i,j,&nn,Xlist,Ylist);
+    Int_t xList[kMaxNeighbours], yList[kMaxNeighbours];
+    fSegmentation->Neighbours(i,j,&nn,xList,yList);
     for (Int_t in=0; in<nn; in++) {
-       Int_t ix=Xlist[in];
-       Int_t iy=Ylist[in];
-       if (fHitMap->TestHit(ix,iy)==unused) FindCluster(ix, iy, c);
+       Int_t ix=xList[in];
+       Int_t iy=yList[in];
+       if (fHitMap->TestHit(ix,iy)==kUnused) FindCluster(ix, iy, c);
     }
 }
 
@@ -705,76 +591,67 @@ void AliMUONClusterFinder::FindRawClusters()
   // simple MUON cluster finder from digits -- finds neighbours and 
   // fill the tree with raw clusters
   //
-
     if (!fNdigits) return;
 
     fHitMap = new AliMUONHitMapA1(fSegmentation, fDigits);
 
-
-    AliMUONdigit *dig;
+    AliMUONDigit *dig;
 
     Int_t ndig;
     Int_t nskip=0;
     Int_t ncls=0;
     fHitMap->FillHits();
     for (ndig=0; ndig<fNdigits; ndig++) {
-       dig = (AliMUONdigit*)fDigits->UncheckedAt(ndig);
+       dig = (AliMUONDigit*)fDigits->UncheckedAt(ndig);
        Int_t i=dig->fPadX;
        Int_t j=dig->fPadY;
-       if (fHitMap->TestHit(i,j)==used ||fHitMap->TestHit(i,j)==empty) {
+       if (fHitMap->TestHit(i,j)==kUsed ||fHitMap->TestHit(i,j)==kEmpty) {
            nskip++;
            continue;
        }
        AliMUONRawCluster c;
-       c.fMultiplicity=0;
-       c.fPeakSignal=dig->fSignal;
-/*
-       c.fTracks[0]=dig->fTracks[0];
-       c.fTracks[1]=dig->fTracks[1];
-       c.fTracks[2]=dig->fTracks[2];
-*/
-       //c.fTracks[0]=dig->fTrack;
+       c.fMultiplicity[0]=0;
+       c.fPeakSignal[0]=dig->fSignal;
        c.fTracks[0]=dig->fHit;
        c.fTracks[1]=dig->fTracks[0];
        c.fTracks[2]=dig->fTracks[1];
-        // tag the beginning of cluster list in a raw cluster
-        c.fNcluster[0]=-1;
+       // tag the beginning of cluster list in a raw cluster
+       c.fNcluster[0]=-1;
        FindCluster(i,j, c);
        // center of gravity
-       c.fX /= c.fQ;
-       c.fX=fSegmentation->GetAnod(c.fX);
-       c.fY /= c.fQ;
+       c.fX[0] /= c.fQ[0];
+       c.fX[0]=fSegmentation->GetAnod(c.fX[0]);
+       c.fY[0] /= c.fQ[0];
 //
 //  apply correction to the coordinate along the anode wire
 //
        Int_t ix,iy;
-       Float_t x=c.fX;   
-       Float_t y=c.fY;
+       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);
-       if (CogCorr) {
-           Float_t YonPad=(c.fY-y)/fSegmentation->Dpy(isec);
-           c.fY=c.fY-CogCorr->Eval(YonPad,0,0);
+       TF1* cogCorr=fSegmentation->CorrFunc(isec-1);
+       if (cogCorr) {
+           Float_t yOnPad=(c.fY[0]-y)/fSegmentation->Dpy(isec);
+           c.fY[0]=c.fY[0]-cogCorr->Eval(yOnPad,0,0);
        }
-
 //
 //      Analyse cluster and decluster if necessary
 //     
-    ncls++;
-    c.fNcluster[1]=fNRawClusters;
-    c.fClusterType=c.PhysicsContribution();
-    Decluster(&c);
-    fNPeaks=0;
+       ncls++;
+       c.fNcluster[1]=fNRawClusters;
+       c.fClusterType=c.PhysicsContribution();
+       Decluster(&c);
+       fNPeaks=0;
 //
 //
 //
 //      reset Cluster object
-       for (int k=0;k<c.fMultiplicity;k++) {
-           c.fIndexMap[k]=0;
+       for (int k=0;k<c.fMultiplicity[0];k++) {
+           c.fIndexMap[k][0]=0;
        }
-       c.fMultiplicity=0;
+       c.fMultiplicity[0]=0;
     } // end loop ndig    
     delete fHitMap;
 }
@@ -782,6 +659,7 @@ void AliMUONClusterFinder::FindRawClusters()
 void AliMUONClusterFinder::
 CalibrateCOG()
 {
+// Calibrate the cog method
     Float_t x[5];
     Float_t y[5];
     Int_t n, i;
@@ -801,18 +679,18 @@ CalibrateCOG()
 void AliMUONClusterFinder::
 SinoidalFit(Float_t x, Float_t y, TF1 &func)
 {
-//
+// Perform a senoidal fit to the residuals of the cog method
     static Int_t count=0;
     char canvasname[3];
     count++;
     sprintf(canvasname,"c%d",count);
-
-    const Int_t ns=101;
-    Float_t xg[ns], yg[ns], xrg[ns], yrg[ns];
-    Float_t xsig[ns], ysig[ns];
-   
-    AliMUONsegmentation *segmentation=fSegmentation;
-
+    
+    const Int_t kns=101;
+    Float_t xg[kns], yg[kns], xrg[kns], yrg[kns];
+    Float_t xsig[kns], ysig[kns];
+    
+    AliMUONSegmentation *segmentation=fSegmentation;
+    
     Int_t ix,iy;
     segmentation->GetPadIxy(x,y,ix,iy);   
     segmentation->GetPadCxy(ix,iy,x,y);   
@@ -824,7 +702,7 @@ SinoidalFit(Float_t x, Float_t y, TF1 &func)
 //      Integration Limits
     Float_t dxI=fResponse->SigmaIntegration()*fResponse->ChargeSpreadX();
     Float_t dyI=fResponse->SigmaIntegration()*fResponse->ChargeSpreadY();
-
+    
 //
 //  Scanning
 //
@@ -833,9 +711,9 @@ SinoidalFit(Float_t x, Float_t y, TF1 &func)
 //
 //  y-position
     Float_t yscan=ymin;
-    Float_t dy=segmentation->Dpy(isec)/(ns-1);
+    Float_t dy=segmentation->Dpy(isec)/(kns-1);
 
-    for (i=0; i<ns; i++) {
+    for (i=0; i<kns; i++) {
 //
 //      Pad Loop
 //      
@@ -869,9 +747,9 @@ SinoidalFit(Float_t x, Float_t y, TF1 &func)
 //
 //  x-position
     Float_t xscan=xmin;
-    Float_t dx=segmentation->Dpx(isec)/(ns-1);
-
-    for (i=0; i<ns; i++) {
+    Float_t dx=segmentation->Dpx(isec)/(kns-1);
+    
+    for (i=0; i<kns; i++) {
 //
 //      Pad Loop
 //      
@@ -908,72 +786,295 @@ SinoidalFit(Float_t x, Float_t y, TF1 &func)
 // Creates a Root function based on function sinoid above
 // and perform the fit
 //
-    //    TGraph *graphx = new TGraph(ns,xg ,xsig);
-    //    TGraph *graphxr= new TGraph(ns,xrg,xsig);   
-    //    TGraph *graphy = new TGraph(ns,yg ,ysig);
-    TGraph *graphyr= new TGraph(ns,yrg,ysig);
+/*
+        TGraph *graphx = new TGraph(kns,xg ,xsig);
+        TGraph *graphxr= new TGraph(kns,xrg,xsig);   
+        TGraph *graphy = new TGraph(kns,yg ,ysig);
+*/
+    TGraph *graphyr= new TGraph(kns,yrg,ysig);
 
     Double_t sinoid(Double_t *x, Double_t *par);
     new TF1("sinoidf",sinoid,0.5,0.5,5);
     graphyr->Fit("sinoidf","Q");
     func = *((TF1*)((graphyr->GetListOfFunctions())->At(0)));
+
 /*
-    
-    TCanvas *c1=new TCanvas(canvasname,canvasname,400,10,600,700);
-    TPad* pad11 = new TPad("pad11"," ",0.01,0.51,0.49,0.99);
-    TPad* pad12 = new TPad("pad12"," ",0.51,0.51,0.99,0.99);
-    TPad* pad13 = new TPad("pad13"," ",0.01,0.01,0.49,0.49);
-    TPad* pad14 = new TPad("pad14"," ",0.51,0.01,0.99,0.49);
-    pad11->SetFillColor(11);
-    pad12->SetFillColor(11);
-    pad13->SetFillColor(11);
-    pad14->SetFillColor(11);
-    pad11->Draw();
-    pad12->Draw();
-    pad13->Draw();
-    pad14->Draw();
+  TCanvas *c1=new TCanvas(canvasname,canvasname,400,10,600,700);
+  TPad* pad11 = new TPad("pad11"," ",0.01,0.51,0.49,0.99);
+  TPad* pad12 = new TPad("pad12"," ",0.51,0.51,0.99,0.99);
+  TPad* pad13 = new TPad("pad13"," ",0.01,0.01,0.49,0.49);
+  TPad* pad14 = new TPad("pad14"," ",0.51,0.01,0.99,0.49);
+  pad11->SetFillColor(11);
+  pad12->SetFillColor(11);
+  pad13->SetFillColor(11);
+  pad14->SetFillColor(11);
+  pad11->Draw();
+  pad12->Draw();
+  pad13->Draw();
+  pad14->Draw();
     
 //
-    pad11->cd();
-    graphx->SetFillColor(42);
-    graphx->SetMarkerColor(4);
-    graphx->SetMarkerStyle(21);
-    graphx->Draw("AC");
-    graphx->GetHistogram()->SetXTitle("x on pad");
-    graphx->GetHistogram()->SetYTitle("xcog-x");   
-
-
-    pad12->cd();
-    graphxr->SetFillColor(42);
-    graphxr->SetMarkerColor(4);
-    graphxr->SetMarkerStyle(21);
-    graphxr->Draw("AP");
-    graphxr->GetHistogram()->SetXTitle("xcog on pad");
-    graphxr->GetHistogram()->SetYTitle("xcog-x");   
+pad11->cd();
+graphx->SetFillColor(42);
+graphx->SetMarkerColor(4);
+graphx->SetMarkerStyle(21);
+graphx->Draw("AC");
+graphx->GetHistogram()->SetXTitle("x on pad");
+graphx->GetHistogram()->SetYTitle("xcog-x");   
+
+
+pad12->cd();
+graphxr->SetFillColor(42);
+graphxr->SetMarkerColor(4);
+graphxr->SetMarkerStyle(21);
+graphxr->Draw("AP");
+graphxr->GetHistogram()->SetXTitle("xcog on pad");
+graphxr->GetHistogram()->SetYTitle("xcog-x");   
     
 
-    pad13->cd();
-    graphy->SetFillColor(42);
-    graphy->SetMarkerColor(4);
-    graphy->SetMarkerStyle(21);
-    graphy->Draw("AF");
-    graphy->GetHistogram()->SetXTitle("y on pad");
-    graphy->GetHistogram()->SetYTitle("ycog-y");   
-    
+pad13->cd();
+graphy->SetFillColor(42);
+graphy->SetMarkerColor(4);
+graphy->SetMarkerStyle(21);
+graphy->Draw("AF");
+graphy->GetHistogram()->SetXTitle("y on pad");
+graphy->GetHistogram()->SetYTitle("ycog-y");   
+
 
 
-    pad14->cd();
-    graphyr->SetFillColor(42);
-    graphyr->SetMarkerColor(4);
-    graphyr->SetMarkerStyle(21);
-    graphyr->Draw("AF");
-    graphyr->GetHistogram()->SetXTitle("ycog on pad");
-    graphyr->GetHistogram()->SetYTitle("ycog-y");   
+pad14->cd();
+graphyr->SetFillColor(42);
+graphyr->SetMarkerColor(4);
+graphyr->SetMarkerStyle(21);
+graphyr->Draw("AF");
+graphyr->GetHistogram()->SetXTitle("ycog on pad");
+graphyr->GetHistogram()->SetYTitle("ycog-y");   
     
     c1->Update();
 */
 }
 
+Bool_t AliMUONClusterFinder::SingleMathiesonFit(AliMUONRawCluster *c)
+{
+//
+//  Initialise global variables for fit
+    Int_t i;
+    fMul=c->fMultiplicity[0];
+    fgSegmentation=fSegmentation;
+    fgResponse    =fResponse;
+    fgNbins=fMul;
+    Float_t qtot=0;
+//
+//  dump digit information into arrays
+//
+    for (i=0; i<fMul; i++)
+    {
+       fDig[i]= (AliMUONDigit*)fDigits->UncheckedAt(c->fIndexMap[i][0]);
+       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]);
+       fgix[i]=fIx[i];
+       fgiy[i]=fIy[i];
+       fgCharge[i]=Float_t(fQ[i]);
+       qtot+=fgCharge[i];
+    }
+
+    fgQtot=qtot;
+    fgChargeTot=Int_t(qtot);
+    
+//
+    if (fgFirst) {
+       fgFirst=kFALSE;
+       fgMyMinuit = new TMinuit(5);
+    }
+
+    fgMyMinuit->SetFCN(fcn1);
+    fgMyMinuit->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[0];
+    vstart[1]=c->fY[0];        
+// 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;
+    
+    upper[0]=lower[0]+fSegmentation->Dpx(isec);
+    upper[1]=lower[1]+fSegmentation->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);
+// ready for minimisation      
+    fgMyMinuit->SetPrintLevel(1);
+    fgMyMinuit->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);
+// Print results
+// Get fitted parameters
+    Double_t xrec, yrec;
+    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); 
+    c->fX[0]=xrec;
+    c->fY[0]=yrec;
+    return kTRUE;
+}
+
+Bool_t AliMUONClusterFinder::DoubleMathiesonFit(AliMUONRawCluster *c)
+{
+//
+//  Initialise global variables for fit
+    Int_t i,j;
+    
+    fgSegmentation=fSegmentation;
+    fgResponse    =fResponse;
+    fgNbins=fMul;
+    Float_t qtot=0;
+       
+    for (i=0; i<fMul; i++) {
+       fgix[i]=fIx[i];
+       fgiy[i]=fIy[i];
+       fgCharge[i]=Float_t(fQ[i]);
+       qtot+=fgCharge[i];
+    }
+    fgQtot=qtot;
+    fgChargeTot=Int_t(qtot);
+    
+//
+    if (fgFirst) {
+       fgFirst=kFALSE;
+       fgMyMinuit = new TMinuit(5);
+    }
+    fgMyMinuit->SetFCN(fcn2);
+    fgMyMinuit->mninit(5,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[5];
+    vstart[0]=fX[fIndLocal[0]];
+    vstart[1]=fY[fIndLocal[0]];        
+    vstart[2]=fX[fIndLocal[1]];
+    vstart[3]=fY[fIndLocal[1]];        
+    vstart[4]=Float_t(fQ[fIndLocal[0]])/
+       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);
+    
+    upper[0]=lower[0]+2.*fSegmentation->Dpx(isec);
+    upper[1]=lower[1]+2.*fSegmentation->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;
+    
+    upper[2]=lower[2]+fSegmentation->Dpx(isec);
+    upper[3]=lower[3]+fSegmentation->Dpy(isec);
+    
+    lower[4]=0.;
+    upper[4]=1.;
+// step sizes
+    static Double_t step[5]={0.0005, 0.0005, 0.0005, 0.0005, 0.01};
+    
+    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);
+// ready for minimisation      
+    fgMyMinuit->SetPrintLevel(-1);
+    fgMyMinuit->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);
+// 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);      
+
+    Double_t fmin, fedm, errdef;
+    Int_t   npari, nparx, istat;
+      
+    fgMyMinuit->mnstat(fmin, fedm, errdef, npari, nparx, istat);  
+    
+    printf("\n fmin %f \n", fmin);
+    
+//
+// 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*qfrac);
+       } else {
+           cnew.fQ[0]=Int_t(fgChargeTot*(1-qfrac));
+       }
+       fgSegmentation->SetHit(xrec[j],yrec[j]);
+       for (i=0; i<fMul; i++) {
+           cnew.fIndexMap[cnew.fMultiplicity[0]][0]=c->fIndexMap[i][0];
+           fgSegmentation->SetPad(fgix[i], fgiy[i]);
+           Float_t q1=fgResponse->IntXY(fgSegmentation);
+           cnew.fContMap[cnew.fMultiplicity[0]][0]=(q1*cnew.fQ[0])/Float_t(fQ[i]);
+           cnew.fMultiplicity[0]++;
+       }
+       FillCluster(&cnew,0);
+       cnew.fClusterType=cnew.PhysicsContribution();
+       AddRawCluster(cnew);
+       fNPeaks++;
+    }
+    return kTRUE;
+}
+
+AliMUONClusterFinder& AliMUONClusterFinder
+::operator = (const AliMUONClusterFinder& rhs)
+{
+// Dummy assignment operator
+    return *this;
+}
+
+
 Double_t sinoid(Double_t *x, Double_t *par)
 {
     Double_t arg = -2*TMath::Pi()*x[0];
@@ -995,7 +1096,22 @@ Double_t DoubleGauss(Double_t *x, Double_t *par)
     return fitval;
  }
 
-Float_t DiscrCharge(Int_t i,Double_t *par) 
+Float_t DiscrCharge1(Int_t i,Double_t *par) 
+{
+// par[0]    x-position of cluster
+// par[1]    y-position of cluster
+
+   fgSegmentation->SetPad(fgix[i], fgiy[i]);
+//  First Cluster
+   fgSegmentation->SetHit(par[0],par[1]);
+   Float_t q1=fgResponse->IntXY(fgSegmentation);
+    
+   Float_t value = fgQtot*q1;
+   return value;
+}
+
+
+Float_t DiscrCharge2(Int_t i,Double_t *par) 
 {
 // par[0]    x-position of first  cluster
 // par[1]    y-position of first  cluster
@@ -1004,33 +1120,23 @@ Float_t DiscrCharge(Int_t i,Double_t *par)
 // par[4]    charge fraction of first  cluster
 // 1-par[4]  charge fraction of second cluster
 
-    static Float_t qtot;
-    if (gFirst) {
-       qtot=0;
-       for (Int_t jbin=0; jbin<gNbins; jbin++) {
-           qtot+=gCharge[jbin];
-       }
-       gFirst=0;
-       //printf("\n sum of charge from DiscrCharge %f\n", qtot);
-       gChargeTot=Int_t(qtot);
-       
-    }
-    gSegmentation->SetPad(gix[i], giy[i]);
+   fgSegmentation->SetPad(fgix[i], fgiy[i]);
 //  First Cluster
-    gSegmentation->SetHit(par[0],par[1]);
-    Float_t q1=gResponse->IntXY(gSegmentation);
+   fgSegmentation->SetHit(par[0],par[1]);
+   Float_t q1=fgResponse->IntXY(fgSegmentation);
     
 //  Second Cluster
-    gSegmentation->SetHit(par[2],par[3]);
-    Float_t q2=gResponse->IntXY(gSegmentation);
+   fgSegmentation->SetHit(par[2],par[3]);
+   Float_t q2=fgResponse->IntXY(fgSegmentation);
     
-    Float_t value = qtot*(par[4]*q1+(1.-par[4])*q2);
-    return value;
+   Float_t value = fgQtot*(par[4]*q1+(1.-par[4])*q2);
+   return value;
 }
 
 //
-// Minimisation function
-void fcn(Int_t &, Double_t *, Double_t &f, Double_t *par, Int_t )
+// Minimisation functions
+// Single Mathieson
+void fcn1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
 {
     Int_t i;
     Float_t delta;
@@ -1038,15 +1144,36 @@ void fcn(Int_t &, Double_t *, Double_t &f, Double_t *par, Int_t )
     Float_t qcont=0;
     Float_t qtot=0;
     
-    for (i=0; i<gNbins; i++) {
-       Float_t q0=gCharge[i];
-       Float_t q1=DiscrCharge(i,par);
+    for (i=0; i<fgNbins; i++) {
+       Float_t q0=fgCharge[i];
+       Float_t q1=DiscrCharge1(i,par);
+       delta=(q0-q1)/TMath::Sqrt(q0);
+       chisq+=delta*delta;
+       qcont+=q1;
+       qtot+=q0;
+    }
+    f=chisq;
+}
+
+// Double Mathieson
+void fcn2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
+{
+    Int_t i;
+    Float_t delta;
+    Float_t chisq=0;
+    Float_t qcont=0;
+    Float_t qtot=0;
+    
+    for (i=0; i<fgNbins; i++) {
+
+       Float_t q0=fgCharge[i];
+       Float_t q1=DiscrCharge2(i,par);
        delta=(q0-q1)/TMath::Sqrt(q0);
        chisq+=delta*delta;
        qcont+=q1;
        qtot+=q0;
     }
-    chisq=chisq+=(qtot-qcont)*(qtot-qcont)*0.5;
+//    chisq=chisq+=(qtot-qcont)*(qtot-qcont)*0.5;
     f=chisq;
 }
 
index b25adb2..bf75805 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef AliMUONClusterFinder_H
-#define AliMUONClusterFinder_H
+#ifndef ALIMUONCLUSTERFINDER_H
+#define ALIMUONCLUSTERFINDER_H
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
 ////////////////////////////////////////////////
 //  MUON Cluster Finder Class                 //
 ////////////////////////////////////////////////
-#include "AliMUONHitMap.h"
-#include "TF1.h"
+#include "TObject.h"
+class AliMUONHitMap;
+class AliMUONHitMapA1;
+class AliMUONDigit;
+class TClonesArray;
+class AliMUONSegmentation;
+class AliMUONResponse;
+class AliMUONRawCluster;
+
+class TF1;
+
+const Int_t kMaxNeighbours = 24; // max number of neighbours
+
 class AliMUONClusterFinder :
  public TObject
 {
-public:
-    TClonesArray*           fDigits;
-    Int_t                   fNdigits;
-protected:
-    AliMUONsegmentation*    fSegmentation;
-    AliMUONresponse*        fResponse;
-    TClonesArray*           fRawClusters;
-    Int_t                   fChamber;
-    Int_t                   fNRawClusters;
-    AliMUONHitMapA1*        fHitMap;
-    TF1*                    fCogCorr;
-    Int_t                   fNperMax;
-    Int_t                   fDeclusterFlag;
-    Int_t                   fClusterSize;
-    Int_t                   fNPeaks; 
  public:
     AliMUONClusterFinder
-       (AliMUONsegmentation *segmentation,
-        AliMUONresponse *response, TClonesArray *digits, Int_t chamber);
+       (AliMUONSegmentation *segmentation,
+        AliMUONResponse *response, TClonesArray *digits, Int_t chamber);
+    AliMUONClusterFinder(const AliMUONClusterFinder& clusterFinder);
     AliMUONClusterFinder();
-    ~AliMUONClusterFinder(){delete fRawClusters;}
+    virtual  ~AliMUONClusterFinder(); 
+// Set segmentation model    
     virtual void SetSegmentation(
-       AliMUONsegmentation *segmentation){
+       AliMUONSegmentation *segmentation){
        fSegmentation=segmentation;
     }
-    virtual void SetResponse(AliMUONresponse *response) {
+// Set response model    
+    virtual void SetResponse(AliMUONResponse *response) {
        fResponse=response;
     }
+// Set pointer to digits
+    virtual void SetDigits(TClonesArray *MUONdigits);
+    virtual void SetDigits(TClonesArray *MUONdigits1,
+                          TClonesArray *MUONdigits2 ) {;}
 
-    virtual void SetDigits(TClonesArray *MUONdigits) {
-       fDigits=MUONdigits;
-       fNdigits = fDigits->GetEntriesFast();
-    }
-    
+// Set current chamber id    
     virtual void SetChamber(Int_t ich){
        fChamber=ich;
     }
-    
-    virtual void AddRawCluster(const AliMUONRawCluster);
-    // Search for raw clusters
+// Add a new raw cluster    
+    virtual void AddRawCluster(const AliMUONRawCluster cluster);
+// Search for raw clusters
     virtual void FindRawClusters();
+// Find cluster    
     virtual void  FindCluster(Int_t i, Int_t j, AliMUONRawCluster &c);
-    // Decluster
+// Decluster
     virtual void Decluster(AliMUONRawCluster *cluster);
-    // Set max. Number of pads per local cluster
+// Set max. number of pads per local cluster
     virtual void SetNperMax(Int_t npermax=5) {fNperMax = npermax;}
-    // Decluster ?
+// Decluster ?
     virtual void SetDeclusterFlag(Int_t flag=1) {fDeclusterFlag =flag;}
-    // Set max. cluster size ; bigger clusters will be rejected
+// Set max. cluster size ; bigger clusters will deconvoluted
     virtual void SetClusterSize(Int_t clsize=5) {fClusterSize = clsize;}
-    // Self Calibration of COG 
+// Self Calibration of COG 
     virtual void CalibrateCOG();
+// Perform fit to sinoidal function    
     virtual void SinoidalFit(Float_t x, Float_t y, TF1 &func);
-    //
+//
     virtual void CorrectCOG(){;}
-    
-    //
+//  True if 3-cluster is centred
     virtual Bool_t Centered(AliMUONRawCluster *cluster);
+//  Perform split by local maxima  
     virtual void   SplitByLocalMaxima(AliMUONRawCluster *cluster);
-    virtual void   FillCluster(AliMUONRawCluster *cluster, Int_t);
+//  Perform Double Mathieson Fit
+    Bool_t  DoubleMathiesonFit(AliMUONRawCluster *c);
+    Bool_t SingleMathiesonFit(AliMUONRawCluster *c);    
+//  Build up full cluster information    
+    virtual void   FillCluster(AliMUONRawCluster *cluster, Int_t n);
     virtual void   FillCluster(AliMUONRawCluster *cluster) {
        FillCluster(cluster,1);}
+    virtual void SetTracks(Int_t, Int_t) {;}
+    virtual Bool_t TestTrack(Int_t) {return kTRUE;}    
+    
+//  Return pointer to raw clusters    
     TClonesArray* RawClusters(){return fRawClusters;}
+//  Assignment operator
+    AliMUONClusterFinder & operator = (const AliMUONClusterFinder& rhs);
+    
+protected:
+    TClonesArray*           fDigits;         // Digits
+    Int_t                   fNdigits;        // Number of Digits
+    AliMUONSegmentation*    fSegmentation;   // Chamber segmentation
+    AliMUONResponse*        fResponse;       // Chamber Response
+    TClonesArray*           fRawClusters;    // Raw Clusters
+    Int_t                   fChamber;        // Chamber Number
+    Int_t                   fNRawClusters;   // Number of Raw Clusters
+    AliMUONHitMapA1*        fHitMap;         // Hit Map
+    TF1*                    fCogCorr;        // Systematic correction function 
+    Int_t                   fNperMax;        // Maximum number of pads per
+                                             // local maximum 
+    Int_t                   fDeclusterFlag;  // flaf for declusterin
+    Int_t                   fClusterSize;    // cluster size 
+    Int_t                   fNPeaks;         // number of local maxima
+//  Current cluster    
+    AliMUONDigit*           fDig[100];        // current list of digits 
+    Int_t                   fIx[100];         // current list of x-pad-coord.
+    Int_t                   fIy[100];         // current list of y-pad-coord.
+    Float_t                 fX[100];          // current list of x-coord.
+    Float_t                 fY[100];          // current list of y-coord.
+    Int_t                   fIndLocal[100];   // indices of local maxima
+    Int_t                   fNLocal;          // Number of local maxima
+    Int_t                   fQ[100];          // current list of charges
+    Int_t                   fMul;             // current multiplicity
     ClassDef(AliMUONClusterFinder,1) //Class for clustering and reconstruction of space points
 };
 #endif
diff --git a/MUON/AliMUONClusterFinderV0.cxx b/MUON/AliMUONClusterFinderV0.cxx
new file mode 100644 (file)
index 0000000..afb38f6
--- /dev/null
@@ -0,0 +1,758 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+#include "AliMUONClusterFinderV0.h"
+#include "AliMUONSegResV1.h"
+//#include "TTree.h"
+//#include "AliRun.h"
+//#include <TCanvas.h>
+//#include <TH1.h>
+//#include <TPad.h>
+//#include <TGraph.h> 
+
+//----------------------------------------------------------
+ClassImp(AliMUONClusterFinderV0)
+
+    AliMUONClusterFinderV0::AliMUONClusterFinderV0
+(AliMUONSegmentation *segmentation, AliMUONResponse *response, 
+ TClonesArray *digits, Int_t chamber) : AliMUONClusterFinder(segmentation,response,digits,chamber)
+{;}
+
+    AliMUONClusterFinderV0::AliMUONClusterFinderV0():AliMUONClusterFinder()
+{;}
+
+/*
+void AliMUONClusterFinder::AddRawCluster(const AliMUONRawCluster c)
+{
+  //
+  // Add a raw cluster copy to the list
+  //
+    AliMUON *MUON=(AliMUON*)gAlice->GetModule("MUON");
+    MUON->AddRawCluster(fChamber,c); 
+    fNRawClusters++;
+}
+*/
+
+
+
+void AliMUONClusterFinderV0::Decluster(AliMUONRawCluster *cluster)
+{
+//    AliMUONDigit *dig;
+//    Int_t q;
+    static int done=0;
+    if (!done) {
+       printf("Calling decluster\n");
+       done=1;
+    }
+    
+
+    
+    Int_t mul = cluster->fMultiplicity;
+//    printf("Decluster - multiplicity   %d \n",mul);
+
+    if (mul == 1) {
+//     printf("\n Nothing special for 1-clusters \n");
+//
+// Nothing special for 1-clusters
+//
+       AddRawCluster(*cluster); 
+    } else if (mul ==2) {
+//
+// 2-cluster, compute offset
+//
+        SetOffset(cluster);
+       FillCluster(cluster);
+        AddRawCluster(*cluster); 
+    } else if (mul ==3) {
+//
+// 3-cluster, check topology
+//     printf("\n 3-cluster, check topology \n");
+//
+       if (Centered(cluster)) {
+//
+// ok, cluster is centered 
+//         printf("\n ok, cluster is centered \n");
+       } else {
+//
+// cluster is not centered, split into 2+1
+//         printf("\n cluster is not centered, split into 2+1 \n");
+       }
+           
+    } else {
+       if (mul >(50-5)) printf("Decluster - multiplicity %d approaching 50\n",mul);
+// 
+// 4-and more-pad clusters
+//
+       SplitByLocalMaxima(cluster);
+    } // multiplicity 
+}
+
+Int_t AliMUONClusterFinderV0::PeakOffsetAndCoordinates(Int_t DigitIndex, Float_t *X, Float_t *Y)
+//
+// Computes for which allowed offsets the digit has the highest neighbouring charge
+// Returns the value of the offset, and sets the pyisical coordinates of that pad
+// Loop on physical neighbours is specific to AliMUONSegmentationV1
+{
+Int_t nPara, offset, returnOffset=0 ;
+AliMUONDigit* dig= (AliMUONDigit*)fDigits->UncheckedAt(DigitIndex);
+AliMUONSegmentationV1* seg = (AliMUONSegmentationV1*) fSegmentation;
+seg->GetNParallelAndOffset(dig->fPadX,dig->fPadY,&nPara,&offset);
+if (nPara>1)
+  {
+  Float_t qMax=0;
+  for (Int_t i=0;i<nPara; i++)
+    {
+    // Compute the charge on the 9 neighbouring pads
+    // We assume that there are no pads connected in parallel in the neighbourhood
+    //
+    Float_t q=0;
+    for (Int_t dx=-1;dx<2;dx++)
+      for (Int_t dy=-1;dy<2;dy++)
+        {
+        if (dx==dy && dy==0)
+          continue; 
+        Int_t padY=dig->fPadY+dy;
+        Int_t padX=seg->Ix((Int_t) (dig->fPadX+dx+i*offset) , padY);
+       if (fHitMap->TestHit(padX, padY)==empty) 
+          continue;
+        AliMUONDigit* digt = (AliMUONDigit*) fHitMap->GetHit(padX,padY);
+        q += digt->fSignal;
+        }
+    if (q>qMax)
+      {
+      returnOffset=i*offset;
+      qMax=q;
+      }
+    }
+  }
+fSegmentation->GetPadCxy(dig->fPadX+returnOffset,dig->fPadY,*X,*Y);
+return returnOffset;
+}
+
+
+void AliMUONClusterFinderV0::SetOffset(AliMUONRawCluster *cluster)
+// compute the offsets assuming that there is only one peak !
+{
+//DumpCluster(cluster);
+Float_t X,Y;
+cluster->fOffsetMap[0]=PeakOffsetAndCoordinates(cluster->fIndexMap[0],&X,&Y);
+for (Int_t i=1;i<cluster->fMultiplicity;i++) {
+  AliMUONDigit* dig= (AliMUONDigit*)fDigits->UncheckedAt(cluster->fIndexMap[i]);
+  fSegmentation->Distance2AndOffset(dig->fPadX,dig->fPadY,X,Y,&(cluster->fOffsetMap[i]));
+  }
+}
+
+void AliMUONClusterFinderV0::DumpCluster(AliMUONRawCluster *cluster)
+{    
+printf ("other cluster\n");
+for (Int_t i=0; i<cluster->fMultiplicity; i++)
+    {
+       AliMUONDigit* dig= (AliMUONDigit*)fDigits->UncheckedAt(cluster->fIndexMap[i]);
+       Int_t nPara, offset;
+       fSegmentation->GetNParallelAndOffset(dig->fPadX,dig->fPadY,&nPara,&offset);
+
+       printf("X %d Y %d Q %d NPara %d \n",dig->fPadX, dig->fPadY,dig->fSignal, nPara);
+    }
+}
+
+Bool_t AliMUONClusterFinderV0::Centered(AliMUONRawCluster *cluster)
+{
+    AliMUONDigit* dig;
+    dig= (AliMUONDigit*)fDigits->UncheckedAt(cluster->fIndexMap[0]);
+    Int_t ix=dig->fPadX;
+    Int_t iy=dig->fPadY;
+    Int_t nn;
+    Int_t X[kMaxNeighbours], Y[kMaxNeighbours], XN[kMaxNeighbours], YN[kMaxNeighbours];
+    fSegmentation->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]) == used) {
+           XN[nd]=X[i];
+           YN[nd]=Y[i];
+           nd++;
+       }
+    }
+    if (nd==2) {
+//
+// cluster is centered !
+       SetOffset(cluster);
+       FillCluster(cluster);
+       AddRawCluster(*cluster);
+       return kTRUE;
+    } else if (nd ==1) {
+//
+// Highest signal on an edge, split cluster into 2+1
+//
+// who is the neighbour ?
+       Int_t nind=fHitMap->GetHitIndex(XN[0], YN[0]);
+       Int_t i1= (nind==cluster->fIndexMap[1]) ? 1:2;
+       Int_t i2= (nind==cluster->fIndexMap[1]) ? 2:1;    
+//
+// 2-cluster
+       AliMUONRawCluster cnew;
+       cnew.fMultiplicity=2;
+       cnew.fIndexMap[0]=cluster->fIndexMap[0];
+       cnew.fIndexMap[1]=cluster->fIndexMap[i1];
+       SetOffset(&cnew);
+       FillCluster(&cnew);
+       AddRawCluster(cnew);
+//
+// 1-cluster
+       cluster->fMultiplicity=1;
+       cluster->fIndexMap[0]=cluster->fIndexMap[i2];
+       cluster->fIndexMap[1]=0;
+       cluster->fIndexMap[2]=0;        
+       FillCluster(cluster);
+       AddRawCluster(*cluster);
+       return kFALSE;
+    } else {
+       printf("\n Completely screwed up %d !! \n",nd);
+       
+    }
+    
+       return kFALSE;
+}
+
+
+void AliMUONClusterFinderV0::SplitByLocalMaxima(AliMUONRawCluster *c)
+{
+    AliMUONDigit* dig[50], *digt;
+    Int_t ix[50], iy[50], q[50];
+    Float_t x[50], y[50];
+    Int_t i; // loops over digits
+    Int_t j; // loops over local maxima
+    
+    Int_t mul=c->fMultiplicity;
+//
+//  dump digit information into arrays
+//
+    for (i=0; i<mul; i++)
+    {
+       dig[i]= (AliMUONDigit*)fDigits->UncheckedAt(c->fIndexMap[i]);
+       ix[i]= dig[i]->fPadX;
+       iy[i]= dig[i]->fPadY;
+       q[i] = dig[i]->fSignal;
+       fSegmentation->GetPadCxy(ix[i], iy[i], x[i], y[i]);
+    }
+//
+//  Find local maxima
+//
+    Bool_t IsLocal[50];
+    Int_t NLocal=0;
+    Int_t AssocPeak[50];
+    Int_t IndLocal[50];
+    Int_t nn;
+    Int_t X[kMaxNeighbours], Y[kMaxNeighbours];
+    for (i=0; i<mul; i++) {
+       fSegmentation->Neighbours(ix[i], iy[i], &nn, X, Y);
+       IsLocal[i]=kTRUE;
+       for (j=0; j<nn; j++) {
+           if (fHitMap->TestHit(X[j], Y[j])==empty) continue;
+           digt=(AliMUONDigit*) fHitMap->GetHit(X[j], Y[j]);
+           if (digt->fSignal > q[i]) {
+                       IsLocal[i]=kFALSE;
+                       break;
+//
+// handle special case of neighbouring pads with equal signal
+           } else if (digt->fSignal == q[i]) {
+                       if (NLocal >0) {
+                       for (Int_t k=0; k<NLocal; k++) {
+                                       if (X[j]==ix[IndLocal[k]] && Y[j]==iy[IndLocal[k]]){
+                                       IsLocal[i]=kFALSE;
+                                       }       
+                               }       
+                       }
+           } 
+       } // loop over next neighbours
+       if (IsLocal[i]) {
+           IndLocal[NLocal]=i;
+            // New for LYON : we guess which is the actual position of the pad hit
+           // But this would run like that for normal chamber !
+            c->fOffsetMap[i]=PeakOffsetAndCoordinates(c->fIndexMap[i], &(x[i]), &(y[i]));
+           NLocal++;
+       } 
+    } // loop over all digits
+//    printf("Found %d local Maxima",NLocal);
+//
+// Associate hits to peaks
+//
+    for (i=0; i<mul; i++) {
+        //
+        // loop on digits
+        //
+       Float_t dmin=1.E10;
+       Float_t qmax=0;
+       Int_t offset;
+       if (IsLocal[i]) continue;
+       for (j=0; j<NLocal; j++) {
+            //
+            // Loop on peaks
+            //
+           Int_t il=IndLocal[j];
+//         Float_t d=TMath::Sqrt((x[i]-x[il])*(x[i]-x[il])
+//                               +(y[i]-y[il])*(y[i]-y[il]));
+            // Can run like that for non-Lyon chambers
+           Float_t d = fSegmentation->Distance2AndOffset(ix[i],iy[i],x[il],y[il], &offset);
+           Float_t ql=q[il];
+//
+// Select nearest peak
+//
+           if (d<dmin) {
+               dmin=d;
+               qmax=ql;
+               AssocPeak[i]=j;
+               c->fOffsetMap[i]=offset;
+           } else if (d==dmin) {
+//
+// If more than one take highest peak
+//
+               if (ql>qmax) {
+                   dmin=d;
+                   qmax=ql;
+                   AssocPeak[i]=j;
+                   c->fOffsetMap[i]=offset;
+               }
+           } // end if
+       } // End loop on peaks
+    } // end loop on digits
+//
+// One cluster for each maximum
+//
+    for (j=0; j<NLocal; j++) {
+       AliMUONRawCluster cnew;
+       cnew.fIndexMap[0]=c->fIndexMap[IndLocal[j]];
+       cnew.fOffsetMap[0]=c->fOffsetMap[IndLocal[j]];
+       cnew.fMultiplicity=1;
+       for (i=0; i<mul; i++) {
+           if (IsLocal[i]) continue;
+           if (AssocPeak[i]==j) {
+               cnew.fIndexMap[cnew.fMultiplicity]=c->fIndexMap[i];
+               cnew.fOffsetMap[cnew.fMultiplicity]=c->fOffsetMap[i];
+               cnew.fMultiplicity++;
+           }
+       }
+       FillCluster(&cnew);
+       AddRawCluster(cnew);
+    }
+}
+
+/*
+void  AliMUONClusterFinderV0::FillCluster(AliMUONRawCluster* c)
+{
+//
+//  Completes cluster information starting from list of digits
+//
+    AliMUONDigit* dig;
+    Float_t x, y;
+    Int_t  ix, iy;
+    
+    c->fPeakSignal=0;
+    c->fX=0;
+    c->fY=0;
+    c->fQ=0;
+    for (Int_t i=0; i<c->fMultiplicity; i++)
+    {
+       dig= (AliMUONDigit*)fDigits->UncheckedAt(c->fIndexMap[i]);
+       ix=dig->fPadX + c.fOffsetMap[i]; // should be 0 for non-LYON
+       iy=dig->fPadY;
+       Int_t q=dig->fSignal;
+//
+//
+// peak signal and track list
+       if (q>c->fPeakSignal) {
+           c->fPeakSignal=0;
+           c->fTracks[0]=dig->fTracks[0];
+           c->fTracks[1]=dig->fTracks[1];
+           c->fTracks[2]=dig->fTracks[2];
+       }
+//
+// centre of gravity
+       fSegmentation->GetPadCxy(ix, iy, x, y);
+       c->fX += q*x;
+       c->fY += q*y;
+       c->fQ += q;
+    }
+    c->fX/=c->fQ;
+// Not valid for inclined tracks in X !!! (Manu)
+//    c->fX=fSegmentation->GetAnod(c->fX);
+    c->fY/=c->fQ; 
+//
+//  apply correction to the coordinate along the anode wire
+//
+    if (fCogCorr) {
+       x=c->fX;   
+       y=c->fY;
+       fSegmentation->GetPadIxy(x, y, ix, iy);
+       fSegmentation->GetPadCxy(ix, iy, x, y);
+       Float_t YonPad=(c->fY-y)/fSegmentation->Dpy();
+       c->fY=y-fCogCorr->Eval(YonPad, 0, 0);
+    }
+
+}
+*/
+/*
+void  AliMUONClusterFinder::FindCluster(Int_t i, Int_t j, AliMUONRawCluster &c){
+//
+//  Find clusters
+//
+//
+//  Add i,j as element of the cluster
+//    
+    
+    Int_t idx = fHitMap->GetHitIndex(i,j);
+    AliMUONDigit* dig = (AliMUONDigit*) fHitMap->GetHit(i,j);
+    Int_t q=dig->fSignal;
+    if (q > TMath::Abs(c.fPeakSignal)) {
+       c.fPeakSignal=q;
+       c.fTracks[0]=dig->fTracks[0];
+       c.fTracks[1]=dig->fTracks[1];
+       c.fTracks[2]=dig->fTracks[2];
+    }
+//
+//  Make sure that list of digits is ordered 
+// 
+    Int_t mu=c.fMultiplicity;
+    c.fIndexMap[mu]=idx;
+
+    if (mu > 0) {
+       for (Int_t ind=mu-1; ind>=0; ind--) {
+           Int_t ist=(c.fIndexMap)[ind];
+           Int_t ql=((AliMUONDigit*)fDigits
+                     ->UncheckedAt(ist))->fSignal;
+           if (q>ql) {
+               c.fIndexMap[ind]=idx;
+               c.fIndexMap[ind+1]=ist;
+           } else {
+               break;
+           }
+       }
+    }
+    
+    c.fMultiplicity++;
+    
+    if (c.fMultiplicity >= 50 ) {
+       printf("FindCluster - multiplicity >50  %d \n",c.fMultiplicity);
+       c.fMultiplicity=50-1;
+    }
+
+// Prepare center of gravity calculation
+    Float_t x, y;
+    fSegmentation->GetPadCxy(i, j, x, y);
+    c.fX += q*x;
+    c.fY += q*y;
+    c.fQ += q;
+// Flag hit as taken  
+    fHitMap->FlagHit(i,j);
+//
+//  Now look recursively for all neighbours
+//  
+    Int_t nn;
+    Int_t Xlist[kMaxNeighbours], Ylist[kMaxNeighbours];
+    fSegmentation->Neighbours(i,j,&nn,Xlist,Ylist);
+    for (Int_t in=0; in<nn; in++) {
+       Int_t ix=Xlist[in];
+       Int_t iy=Ylist[in];
+       if (fHitMap->TestHit(ix,iy)==unused) FindCluster(ix, iy, c);
+    }
+}
+*/
+
+//_____________________________________________________________________________
+
+void AliMUONClusterFinderV0::FindRawClusters()
+{
+  //
+  // simple MUON cluster finder from digits -- finds neighbours and 
+  // fill the tree with raw clusters
+  //
+    if (!fNdigits) return;
+
+    fHitMap = new AliMUONHitMapA1(fSegmentation, fDigits);
+
+    AliMUONDigit *dig;
+
+    int ndig;
+    int nskip=0;
+
+    fHitMap->FillHits();
+    for (ndig=0; ndig<fNdigits; ndig++) {
+       dig = (AliMUONDigit*)fDigits->UncheckedAt(ndig);
+       Int_t i=dig->fPadX;
+       Int_t j=dig->fPadY;
+       if (fHitMap->TestHit(i,j)==used ||fHitMap->TestHit(i,j)==empty) {
+           nskip++;
+           continue;
+       }
+       AliMUONRawCluster c;
+       c.fMultiplicity=0;
+//     c.fPeakSignal=dig->fSignal;
+//     c.fTracks[0]=dig->fTracks[0];
+//     c.fTracks[1]=dig->fTracks[1];
+//     c.fTracks[2]=dig->fTracks[2];
+       c.fPeakSignal=0;
+       FindCluster(i,j, c);
+       // center of gravity
+       c.fX /= c.fQ;
+       c.fX=fSegmentation->GetAnod(c.fX);
+       c.fY /= c.fQ;
+//
+//  apply correction to the coordinate along the anode wire
+//
+
+       
+    if (fCogCorr) {
+       Int_t ix,iy;
+       Float_t x=c.fX;   
+       Float_t y=c.fY;
+       fSegmentation->GetPadIxy(x, y, ix, iy);
+       fSegmentation->GetPadCxy(ix, iy, x, y);
+       Float_t YonPad=(c.fY-y)/fSegmentation->Dpy();
+       c.fY=y-fCogCorr->Eval(YonPad,0,0);
+    }
+//
+//      Analyse cluster and decluster if necessary
+//     
+       Decluster(&c);
+//
+//
+//
+//      reset Cluster object
+       for (int k=0;k<c.fMultiplicity;k++) {
+           c.fIndexMap[k]=0;
+           c.fOffsetMap[k]=0;
+       }
+       c.fMultiplicity=0;
+    } // end loop ndig    
+    delete fHitMap;
+}
+
+/*
+
+void AliMUONClusterFinder::
+CalibrateCOG()
+{
+    Float_t x[5];
+    Float_t y[5];
+    Int_t n, i;
+    TF1 func;
+    
+    if (fSegmentation) {
+       fSegmentation->GiveTestPoints(n, x, y);
+       for (i=0; i<n; i++) {
+           Float_t xtest=x[i];
+           Float_t ytest=y[i];     
+           SinoidalFit(xtest, ytest, func);
+       }
+       fCogCorr = new TF1(func);
+    }
+}
+*/
+/*
+
+void AliMUONClusterFinder::
+SinoidalFit(Float_t x, Float_t y, TF1 &func)
+{
+//
+    static Int_t count=0;
+    char canvasname[3];
+    count++;
+    sprintf(canvasname,"c%d",count);
+
+// MANU : without const, error on HP
+    const Int_t ns=101;
+    Float_t xg[ns], yg[ns], xrg[ns], yrg[ns];
+    Float_t xsig[ns], ysig[ns];
+   
+    AliMUONSegmentation *segmentation=fSegmentation;
+
+    Int_t ix,iy;
+    segmentation->GetPadIxy(x,y,ix,iy);   
+    segmentation->GetPadCxy(ix,iy,x,y);   
+    Int_t isec=segmentation->Sector(ix,iy);
+// Pad Limits    
+    Float_t xmin = x-segmentation->GetRealDpx(isec)/2;
+    Float_t ymin = y-segmentation->Dpy()/2;
+//             
+//      Integration Limits
+    Float_t dxI=fResponse->Nsigma()*fResponse->ChwX();
+    Float_t dyI=fResponse->Nsigma()*fResponse->ChwY();
+
+//
+//  Scanning
+//
+    Int_t i;
+    Float_t qp;
+//
+//  y-position
+    Float_t yscan=ymin;
+    Float_t dy=segmentation->Dpy()/(ns-1);
+
+    for (i=0; i<ns; i++) {
+//
+//      Pad Loop
+//      
+       Float_t sum=0;
+       Float_t qcheck=0;
+       segmentation->SigGenInit(x, yscan, 0);
+       
+       for (segmentation->FirstPad(x, yscan, dxI, dyI); 
+            segmentation->MorePads(); 
+            segmentation->NextPad()) 
+       {
+           qp=fResponse->IntXY(segmentation);
+           qp=TMath::Abs(qp);
+//
+//
+           if (qp > 1.e-4) {
+               qcheck+=qp;
+               Int_t ixs=segmentation->Ix();
+               Int_t iys=segmentation->Iy();
+               Float_t xs,ys;
+               segmentation->GetPadCxy(ixs,iys,xs,ys);
+               sum+=qp*ys;
+           }
+       } // Pad loop
+       Float_t ycog=sum/qcheck;
+       yg[i]=(yscan-y)/segmentation->Dpy();
+       yrg[i]=(ycog-y)/segmentation->Dpy();
+       ysig[i]=ycog-yscan;
+       yscan+=dy;
+    } // scan loop
+//
+//  x-position
+    Float_t xscan=xmin;
+    Float_t dx=segmentation->GetRealDpx(isec)/(ns-1);
+
+    for (i=0; i<ns; i++) {
+//
+//      Pad Loop
+//      
+       Float_t sum=0;
+       Float_t qcheck=0;
+       segmentation->SigGenInit(xscan, y, 0);
+       
+       for (segmentation->FirstPad(xscan, y, dxI, dyI); 
+            segmentation->MorePads(); 
+            segmentation->NextPad()) 
+       {
+           qp=fResponse->IntXY(segmentation);
+           qp=TMath::Abs(qp);
+//
+//
+           if (qp > 1.e-2) {
+               qcheck+=qp;
+               Int_t ixs=segmentation->Ix();
+               Int_t iys=segmentation->Iy();
+               Float_t xs,ys;
+               segmentation->GetPadCxy(ixs,iys,xs,ys);
+               sum+=qp*xs;
+           }
+       } // Pad loop
+       Float_t xcog=sum/qcheck;
+       xcog=segmentation->GetAnod(xcog);
+       
+       xg[i]=(xscan-x)/segmentation->GetRealDpx(isec);
+       xrg[i]=(xcog-x)/segmentation->GetRealDpx(isec);
+       xsig[i]=xcog-xscan;
+       xscan+=dx;
+    }
+
+   TCanvas *c1=new TCanvas(canvasname,canvasname,400,10,600,700);
+   TPad* pad11 = new TPad("pad11"," ",0.01,0.51,0.49,0.99);
+   TPad* pad12 = new TPad("pad12"," ",0.51,0.51,0.99,0.99);
+   TPad* pad13 = new TPad("pad13"," ",0.01,0.01,0.49,0.49);
+   TPad* pad14 = new TPad("pad14"," ",0.51,0.01,0.99,0.49);
+   pad11->SetFillColor(11);
+   pad12->SetFillColor(11);
+   pad13->SetFillColor(11);
+   pad14->SetFillColor(11);
+   pad11->Draw();
+   pad12->Draw();
+   pad13->Draw();
+   pad14->Draw();
+   TGraph *graphx = new TGraph(ns,xg ,xsig);
+   TGraph *graphxr= new TGraph(ns,xrg,xsig);   
+   TGraph *graphy = new TGraph(ns,yg ,ysig);
+   TGraph *graphyr= new TGraph(ns,yrg,ysig);
+//
+// Creates a Root function based on function sinoid above
+// and perform the fit
+//
+   Double_t sinoid(Double_t *x, Double_t *par);
+   TF1 *sinoidf = new TF1("sinoidf",sinoid,0.5,0.5,5);
+   graphyr->Fit("sinoidf","V");
+   sinoidf->Copy(func);
+   func.Eval(0,0,0);
+//
+   pad11->cd();
+   graphx->SetFillColor(42);
+   graphx->SetMarkerColor(4);
+   graphx->SetMarkerStyle(21);
+   graphx->Draw("AC");
+   graphx->GetHistogram()->SetXTitle("x on pad");
+   graphx->GetHistogram()->SetYTitle("xcog-x");   
+
+
+   pad12->cd();
+   graphxr->SetFillColor(42);
+   graphxr->SetMarkerColor(4);
+   graphxr->SetMarkerStyle(21);
+   graphxr->Draw("AP");
+   graphxr->GetHistogram()->SetXTitle("xcog on pad");
+   graphxr->GetHistogram()->SetYTitle("xcog-x");   
+
+
+   pad13->cd();
+   graphy->SetFillColor(42);
+   graphy->SetMarkerColor(4);
+   graphy->SetMarkerStyle(21);
+   graphy->Draw("AF");
+   graphy->GetHistogram()->SetXTitle("y on pad");
+   graphy->GetHistogram()->SetYTitle("ycog-y");   
+
+
+
+   pad14->cd();
+   graphyr->SetFillColor(42);
+   graphyr->SetMarkerColor(4);
+   graphyr->SetMarkerStyle(21);
+   graphyr->Draw("AF");
+   graphyr->GetHistogram()->SetXTitle("ycog on pad");
+   graphyr->GetHistogram()->SetYTitle("ycog-y");   
+
+   c1->Update();
+   
+}
+*/
+/*
+Double_t sinoid(Double_t *x, Double_t *par)
+{
+    Double_t arg = -2*TMath::Pi()*x[0];
+    Double_t fitval= par[0]*TMath::Sin(arg)+
+       par[1]*TMath::Sin(2*arg)+
+       par[2]*TMath::Sin(3*arg)+
+       par[3]*TMath::Sin(4*arg)+
+       par[4]*TMath::Sin(5*arg);
+    return fitval;
+ }
+*/
+
+
+
+
+
+
+
diff --git a/MUON/AliMUONClusterFinderV0.h b/MUON/AliMUONClusterFinderV0.h
new file mode 100644 (file)
index 0000000..0a2c223
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef AliMUONClusterFinderV0_H
+#define AliMUONClusterFinderV0_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+////////////////////////////////////////////////
+//  MUON Cluster Finder Class                 //
+////////////////////////////////////////////////
+#include "AliMUONClusterFinder.h"
+//#include "TF1.h"
+
+class AliMUONClusterFinderV0 :
+public AliMUONClusterFinder {
+ public:
+    AliMUONClusterFinderV0
+       (AliMUONSegmentation *segmentation,
+        AliMUONResponse *response, TClonesArray *digits, Int_t chamber);
+    AliMUONClusterFinderV0();
+    ~AliMUONClusterFinderV0(){delete fRawClusters;}
+    virtual void FindRawClusters();
+    // Specific methods
+    virtual void SetOffset(AliMUONRawCluster *cluster);
+    virtual Int_t PeakOffsetAndCoordinates(Int_t DigitIndex, Float_t *X, Float_t *Y);
+    // Decluster
+    virtual void Decluster(AliMUONRawCluster *cluster);
+    //
+    virtual Bool_t Centered(AliMUONRawCluster *cluster);
+    virtual void   SplitByLocalMaxima(AliMUONRawCluster *cluster);
+    void AliMUONClusterFinderV0::DumpCluster(class AliMUONRawCluster *);
+    
+    
+    TClonesArray* RawClusters(){return fRawClusters;}
+    ClassDef(AliMUONClusterFinderV0,1) //Class for clustering and reconstruction of space points
+};
+#endif
+
+
+
+
+
+
+
diff --git a/MUON/AliMUONClusterFinderVS.cxx b/MUON/AliMUONClusterFinderVS.cxx
new file mode 100644 (file)
index 0000000..349cf7d
--- /dev/null
@@ -0,0 +1,1992 @@
+/**************************************************************************
+ * 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$
+Revision 1.1.2.3  2000/06/09 21:58:33  morsch
+Most coding rule violations corrected.
+
+Revision 1.1.2.2  2000/02/15 08:33:52  morsch
+Error in calculation of contribution map for double clusters (Split method) corrected   (A.M.)
+Error in determination of track list for double cluster (FillCluster method) corrected  (A.M.)
+Revised and extended SplitByLocalMaxima method (Isabelle Chevrot):
+       - For clusters with more than 2 maxima on one of the cathode planes all valid
+       combinations of maxima on the two cathodes are preserved. The position of the maxima is
+       taken as the hit position.
+       - New FillCluster method with 2 arguments to find tracks associated to the clusters
+       defined above added. (Method destinction by argument list not very elegant in this case,
+       should be revides (A.M.)
+       - Bug in if-statement to handle maximum 1 maximum per plane corrected
+       - Two cluster per cathode but only 1 combination valid is handled.
+       - More rigerous treatment of 1-2 and 2-1 combinations of maxima.
+
+*/
+
+#include "AliMUONClusterFinderVS.h"
+#include "AliMUONDigit.h"
+#include "AliMUONRawCluster.h"
+#include "AliMUONSegmentation.h"
+#include "AliMUONResponse.h"
+#include "AliMUONHitMap.h"
+#include "AliMUONHitMapA1.h"
+#include "AliRun.h"
+#include "AliMUON.h"
+
+#include <TTree.h>
+#include <TCanvas.h>
+#include <TH1.h>
+#include <TPad.h>
+#include <TGraph.h> 
+#include <TPostScript.h> 
+#include <TMinuit.h> 
+#include <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);
+void fcnCombiS1(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
+void fcnCombiS2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
+
+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;
+    fTrack[0]=fTrack[1]=-1;
+}
+
+AliMUONClusterFinderVS::AliMUONClusterFinderVS(
+    const AliMUONClusterFinderVS & clusterFinder)
+{
+// Dummy copy Constructor
+    ;
+}
+
+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
+    SplitByLocalMaxima(cluster);
+}
+
+void AliMUONClusterFinderVS::SplitByLocalMaxima(AliMUONRawCluster *c)
+{
+// Split complex cluster by local maxima 
+
+    Int_t cath, i;
+    
+    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++) {
+       qtot=0;
+       for (i=0; i<fMul[cath]; i++)
+       {
+           // pointer to digit
+           fDig[i][cath]=(AliMUONDigit*)
+               (Digits(cath)->UncheckedAt(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];
+       } // loop over cluster digits
+       fgQtot[cath]=qtot;
+       fgChargeTot[cath]=Int_t(qtot);  
+    }  // loop over cathodes
+
+
+    FindLocalMaxima(c);
+
+//
+//  Initialise and perform mathieson fits
+    Float_t chi2, oldchi2;
+//  ++++++++++++++++++*************+++++++++++++++++++++
+//  (1) No more than one local maximum per cathode plane 
+//  +++++++++++++++++++++++++++++++*************++++++++
+    if ((fNLocal[0]==1 && (fNLocal[1]==0 ||  fNLocal[1]==1)) || 
+       (fNLocal[0]==0 && fNLocal[1]==1)) {
+
+// Perform combined single Mathieson fit
+// Initial values for coordinates (x,y) 
+
+       // One local maximum on cathodes 1 and 2 (X->cathode 2, Y->cathode 1)
+       if (fNLocal[0]==1 &&  fNLocal[1]==1) {
+           fXInit[0]=c->fX[1];
+           fYInit[0]=c->fY[0];
+           // One local maximum on cathode 1 (X,Y->cathode 1)
+       } else if (fNLocal[0]==1) {
+           fXInit[0]=c->fX[0];
+           fYInit[0]=c->fY[0];
+           // One local maximum on cathode 2  (X,Y->cathode 2)
+       } else {
+           fXInit[0]=c->fX[1];
+           fYInit[0]=c->fY[1];
+       }
+       fprintf(stderr,"\n cas (1) CombiSingleMathiesonFit(c)\n");
+       chi2=CombiSingleMathiesonFit(c);
+//     Int_t ndf = fgNbins[0]+fgNbins[1]-2;
+//     Float_t prob = TMath::Prob(Double_t(chi2),ndf);
+//     prob1->Fill(prob);
+//     chi2_1->Fill(chi2);
+       oldchi2=chi2;
+       fprintf(stderr," chi2 %f ",chi2);
+
+       c->fX[0]=fXFit[0];
+       c->fY[0]=fYFit[0];
+
+       c->fX[1]=fXFit[0];
+       c->fY[1]=fYFit[0];
+       c->fChi2[0]=chi2;
+       c->fChi2[1]=chi2;
+       c->fX[0]=Segmentation(0)->GetAnod(c->fX[0]);
+       c->fX[1]=Segmentation(1)->GetAnod(c->fX[1]);
+       
+// If reasonable chi^2 add result to the list of rawclusters
+       //      if (chi2 < 50) {
+       if (chi2 < 0.3) {
+           AddRawCluster(*c);
+// If not try combined double Mathieson Fit
+       } else {
+           fprintf(stderr," MAUVAIS CHI2 !!!\n");
+           if (fNLocal[0]==1 &&  fNLocal[1]==1) {
+               fXInit[0]=fX[fIndLocal[0][1]][1];
+               fYInit[0]=fY[fIndLocal[0][0]][0];
+               fXInit[1]=fX[fIndLocal[0][1]][1];
+               fYInit[1]=fY[fIndLocal[0][0]][0];
+           } else if (fNLocal[0]==1) {
+               fXInit[0]=fX[fIndLocal[0][0]][0];
+               fYInit[0]=fY[fIndLocal[0][0]][0];
+               fXInit[1]=fX[fIndLocal[0][0]][0];
+               fYInit[1]=fY[fIndLocal[0][0]][0];
+           } else {
+               fXInit[0]=fX[fIndLocal[0][1]][1];
+               fYInit[0]=fY[fIndLocal[0][1]][1];
+               fXInit[1]=fX[fIndLocal[0][1]][1];
+               fYInit[1]=fY[fIndLocal[0][1]][1];
+           }
+           
+//  Initial value for charge ratios
+           fQrInit[0]=0.5;
+           fQrInit[1]=0.5;
+           fprintf(stderr,"\n cas (1) 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);
+           
+// Was this any better ??
+           fprintf(stderr," Old and new chi2 %f %f ", oldchi2, chi2);
+           if (fFitStat!=0 && chi2>0 && (2.*chi2 < oldchi2)) {
+               fprintf(stderr," Split\n");
+               // Split cluster into two according to fit result
+               Split(c);
+           } else {
+               fprintf(stderr," Don't Split\n");
+               // Don't split
+               AddRawCluster(*c);
+           }
+       }
+
+//  +++++++++++++++++++++++++++++++++++++++
+//  (2) Two local maxima per cathode plane 
+//  +++++++++++++++++++++++++++++++++++++++
+    } else if (fNLocal[0]==2 &&  fNLocal[1]==2) {
+//
+//  Let's look for ghosts first 
+//
+       Float_t xm[4][2], ym[4][2];
+       Float_t dpx, dpy, dx, dy;
+       Int_t ixm[4][2], iym[4][2];
+       Int_t isec, im1, im2, ico;
+//
+//  Form the 2x2 combinations
+//  0-0, 0-1, 1-0, 1-1 
+        ico=0;
+       for (im1=0; im1<2; im1++) {
+           for (im2=0; im2<2; im2++) {     
+               xm[ico][0]=fX[fIndLocal[im1][0]][0];
+               ym[ico][0]=fY[fIndLocal[im1][0]][0];
+               xm[ico][1]=fX[fIndLocal[im2][1]][1];
+               ym[ico][1]=fY[fIndLocal[im2][1]][1];
+
+               ixm[ico][0]=fIx[fIndLocal[im1][0]][0];
+               iym[ico][0]=fIy[fIndLocal[im1][0]][0];
+               ixm[ico][1]=fIx[fIndLocal[im2][1]][1];
+               iym[ico][1]=fIy[fIndLocal[im2][1]][1];
+               ico++;
+           }
+       }
+// ico = 0 : first local maximum on cathodes 1 and 2
+// ico = 1 : fisrt local maximum on cathode 1 and second on cathode 2
+// ico = 2 : second local maximum on cathode 1 and first on cathode 1
+// ico = 3 : second local maximum on cathodes 1 and 2
+
+// Analyse the combinations and keep those that are possible !
+// For each combination check consistency in x and y   
+       Int_t iacc;
+       Bool_t accepted[4];
+       iacc=0;
+       
+       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.;
+           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.;
+           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)) {
+               // consistent
+               accepted[ico]=kTRUE;
+               iacc++;
+           } else {
+               // reject
+               accepted[ico]=kFALSE;
+           }
+       }
+
+       if (iacc==2) {
+           fprintf(stderr,"\n iacc=2: No problem ! \n");
+       } else if (iacc==4) {
+           fprintf(stderr,"\n iacc=4: Ok, but ghost problem !!! \n");
+       } else if (iacc==0) {
+           fprintf(stderr,"\n iacc=0: I don't know what to do with this !!!!!!!!! \n");
+       }
+
+//  Initial value for charge ratios
+       fQrInit[0]=Float_t(fQ[fIndLocal[0][0]][0])/
+           Float_t(fQ[fIndLocal[0][0]][0]+fQ[fIndLocal[1][0]][0]);
+       fQrInit[1]=Float_t(fQ[fIndLocal[0][1]][1])/
+           Float_t(fQ[fIndLocal[0][1]][1]+fQ[fIndLocal[1][1]][1]);
+       
+// ******* iacc = 0 *******
+// No combinations found between the 2 cathodes
+// We keep the center of gravity of the cluster
+       if (iacc==0) {
+           AddRawCluster(*c);
+       }
+
+// ******* iacc = 1 *******
+// Only one combination found between the 2 cathodes
+       if (iacc==1) {
+
+// Initial values for the 2 maxima (x,y)
+
+// 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
+// 1 maximum is initialised with the other maximum of the first cathode  
+           if (accepted[0]){
+               fprintf(stderr,"ico=0\n");
+               fXInit[0]=xm[0][1];
+               fYInit[0]=ym[0][0];
+               fXInit[1]=xm[3][0];
+               fYInit[1]=ym[3][0];
+           } else if (accepted[1]){
+               fprintf(stderr,"ico=1\n");
+               fXInit[0]=xm[1][1];
+               fYInit[0]=ym[1][0];
+               fXInit[1]=xm[2][0];
+               fYInit[1]=ym[2][0];
+           } else if (accepted[2]){
+               fprintf(stderr,"ico=2\n");
+               fXInit[0]=xm[2][1];
+               fYInit[0]=ym[2][0];
+               fXInit[1]=xm[1][0];
+               fYInit[1]=ym[1][0];
+           } else if (accepted[3]){
+               fprintf(stderr,"ico=3\n");
+               fXInit[0]=xm[3][1];
+               fYInit[0]=ym[3][0];
+               fXInit[1]=xm[0][0];
+               fYInit[1]=ym[0][0];
+           }
+           fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
+           chi2=CombiDoubleMathiesonFit(c);
+//         Int_t ndf = fgNbins[0]+fgNbins[1]-6;
+//         Float_t prob = TMath::Prob(chi2,ndf);
+//         prob2->Fill(prob);
+//         chi2_2->Fill(chi2);
+           fprintf(stderr," chi2 %f\n",chi2);
+
+// If reasonable chi^2 add result to the list of rawclusters
+           if (chi2<10) {
+               Split(c);
+
+           } else {
+// 1 maximum is initialised with the maximum of the combination found (X->cathode 2, Y->cathode 1)
+// 1 maximum is initialised with the other maximum of the second cathode  
+               if (accepted[0]){
+                   fprintf(stderr,"ico=0\n");
+                   fXInit[0]=xm[0][1];
+                   fYInit[0]=ym[0][0];
+                   fXInit[1]=xm[3][1];
+                   fYInit[1]=ym[3][1];
+               } else if (accepted[1]){
+                   fprintf(stderr,"ico=1\n");
+                   fXInit[0]=xm[1][1];
+                   fYInit[0]=ym[1][0];
+                   fXInit[1]=xm[2][1];
+                   fYInit[1]=ym[2][1];
+               } else if (accepted[2]){
+                   fprintf(stderr,"ico=2\n");
+                   fXInit[0]=xm[2][1];
+                   fYInit[0]=ym[2][0];
+                   fXInit[1]=xm[1][1];
+                   fYInit[1]=ym[1][1];
+               } else if (accepted[3]){
+                   fprintf(stderr,"ico=3\n");
+                   fXInit[0]=xm[3][1];
+                   fYInit[0]=ym[3][0];
+                   fXInit[1]=xm[0][1];
+                   fYInit[1]=ym[0][1];
+               }
+               fprintf(stderr,"\n cas (2) CombiDoubleMathiesonFit(c)\n");
+               chi2=CombiDoubleMathiesonFit(c);
+//             Int_t ndf = fgNbins[0]+fgNbins[1]-6;
+//             Float_t prob = TMath::Prob(chi2,ndf);
+//             prob2->Fill(prob);
+//             chi2_2->Fill(chi2);
+               fprintf(stderr," chi2 %f\n",chi2);
+
+// If reasonable chi^2 add result to the list of rawclusters
+               if (chi2<10) {
+                   Split(c);
+               } else {
+//We keep only the combination found (X->cathode 2, Y->cathode 1)
+                   for (Int_t ico=0; ico<2; ico++) {
+                       if (accepted[ico]) {
+                           AliMUONRawCluster cnew;
+                           Int_t cath;    
+                           for (cath=0; cath<2; cath++) {
+                             cnew.fX[cath]=Float_t(xm[ico][1]);
+                             cnew.fY[cath]=Float_t(ym[ico][0]);
+                             cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
+                               for (i=0; i<fMul[cath]; i++) {
+                                 cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
+                                 fgSegmentation[cath]->SetPad(fgix[i][cath], fgiy[i][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);
+                           fNPeaks++;
+                       }
+                   }
+               }
+           }
+       }
+
+// ******* 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");
+
+// 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);
+//                 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 {
+// 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);
+//                 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);
+               }
+
+// ******* iacc = 4 *******
+// Four combinations found between the 2 cathodes
+// Ghost !!
+           } 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);
+//             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);
+//             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);
+           }
+
+       } else if (fNLocal[0]==2 &&  fNLocal[1]==1) {
+//  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//  (3) Two local maxima on cathode 1 and one maximum on cathode 2 
+//  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//
+       Float_t xm[4][2], ym[4][2];
+       Float_t dpx, dpy, dx, dy;
+       Int_t ixm[4][2], iym[4][2];
+       Int_t isec, im1, ico;
+//
+//  Form the 2x2 combinations
+//  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++;
+       }
+// ico = 0 : first local maximum on cathodes 1 and 2
+// ico = 1 : second local maximum on cathode 1 and first on cathode 2
+
+// Analyse the combinations and keep those that are possible !
+// For each combination check consistency in x and y   
+       Int_t iacc;
+       Bool_t accepted[4];
+       iacc=0;
+       
+       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.;
+           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.;
+           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)) {
+               // consistent
+               accepted[ico]=kTRUE;
+               iacc++;
+           } else {
+               // reject
+               accepted[ico]=kFALSE;
+           }
+       }
+
+       Float_t chi21 = 100;
+       Float_t chi22 = 100;
+
+       if (accepted[0]) {
+           fXInit[0]=xm[0][1];
+           fYInit[0]=ym[0][0];
+           fXInit[1]=xm[1][0];
+           fYInit[1]=ym[1][0];
+           chi21=CombiDoubleMathiesonFit(c);
+//         Int_t ndf = fgNbins[0]+fgNbins[1]-6;
+//         Float_t prob = TMath::Prob(chi2,ndf);
+//         prob2->Fill(prob);
+//         chi2_2->Fill(chi21);
+           fprintf(stderr," chi2 %f\n",chi21);
+           if (chi21<10) Split(c);
+       } else if (accepted[1]) {
+           fXInit[0]=xm[1][1];
+           fYInit[0]=ym[1][0];
+           fXInit[1]=xm[0][0];
+           fYInit[1]=ym[0][0];
+           chi22=CombiDoubleMathiesonFit(c);
+//         Int_t ndf = fgNbins[0]+fgNbins[1]-6;
+//         Float_t prob = TMath::Prob(chi2,ndf);
+//         prob2->Fill(prob);
+//         chi2_2->Fill(chi22);
+           fprintf(stderr," chi2 %f\n",chi22);
+           if (chi22<10) Split(c);
+       }
+
+       if (chi21 > 10 && chi22 > 10) {
+// We keep only the combination found (X->cathode 2, Y->cathode 1)
+           for (Int_t ico=0; ico<2; ico++) {
+               if (accepted[ico]) {
+                   AliMUONRawCluster cnew;
+                   Int_t cath;    
+                   for (cath=0; cath<2; cath++) {
+                       cnew.fX[cath]=Float_t(xm[ico][1]);
+                       cnew.fY[cath]=Float_t(ym[ico][0]);
+                       cnew.fMultiplicity[cath]=c->fMultiplicity[cath];
+                       for (i=0; i<fMul[cath]; i++) {
+                         cnew.fIndexMap[i][cath]=c->fIndexMap[i][cath];
+                         fgSegmentation[cath]->SetPad(fgix[i][cath], fgiy[i][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);
+                   fNPeaks++;
+               }
+           }
+       }
+          
+//  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//  (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];
+       Int_t isec, im1, ico;
+//
+//  Form the 2x2 combinations
+//  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++;
+       }
+// ico = 0 : first local maximum on cathodes 1 and 2
+// ico = 1 : first local maximum on cathode 1 and second on cathode 2
+
+// Analyse the combinations and keep those that are possible !
+// For each combination check consistency in x and y   
+       Int_t iacc;
+       Bool_t accepted[4];
+       iacc=0;
+       
+       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.;
+           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.;
+           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)) {
+               // consistent
+               accepted[ico]=kTRUE;
+               fprintf(stderr,"ico %d\n",ico);
+               iacc++;
+           } else {
+               // reject
+               accepted[ico]=kFALSE;
+           }
+       }
+
+       Float_t chi21 = 100;
+       Float_t chi22 = 100;
+
+       if (accepted[0]) {
+           fXInit[0]=xm[0][0];
+           fYInit[0]=ym[0][1];
+           fXInit[1]=xm[1][1];
+           fYInit[1]=ym[1][1];
+           chi21=CombiDoubleMathiesonFit(c);
+//         Int_t ndf = fgNbins[0]+fgNbins[1]-6;
+//         Float_t prob = TMath::Prob(chi2,ndf);
+//         prob2->Fill(prob);
+//         chi2_2->Fill(chi21);
+           fprintf(stderr," chi2 %f\n",chi21);
+           if (chi21<10) Split(c);
+       } else if (accepted[1]) {
+           fXInit[0]=xm[1][0];
+           fYInit[0]=ym[1][1];
+           fXInit[1]=xm[0][1];
+           fYInit[1]=ym[0][1];
+           chi22=CombiDoubleMathiesonFit(c);
+//         Int_t ndf = fgNbins[0]+fgNbins[1]-6;
+//         Float_t prob = TMath::Prob(chi2,ndf);
+//    &