]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUON.cxx
- Dummy z-arguments in GetPadI, SetHit, FirstPad replaced by real z-coordinate
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
index 23ea3a43851b52f05c51473de3dcaa2dcb8a9606..f51948f7b55eb564b5f29e9cee33a7ef83e1656c 100644 (file)
  **************************************************************************/
 /*
 $Log$
+Revision 1.30  2000/10/02 16:58:29  egangler
+Cleaning of the code :
+-> coding conventions
+-> void Streamers
+-> some useless includes removed or replaced by "class" statement
+
+Revision 1.29  2000/07/28 13:49:38  morsch
+SetAcceptance defines inner and outer chamber radii according to angular acceptance.
+Can be used for simple acceptance studies.
+
+Revision 1.28  2000/07/22 16:43:15  morsch
+Same comment as before, but now done correctly I hope (sorry it's Saturday evening)
+
+Revision 1.27  2000/07/22 16:36:50  morsch
+Change order of indices in creation (new) of xhit and yhit
+
+Revision 1.26  2000/07/03 11:54:57  morsch
+AliMUONSegmentation and AliMUONHitMap have been replaced by AliSegmentation and AliHitMap in STEER
+The methods GetPadIxy and GetPadXxy of AliMUONSegmentation have changed name to GetPadI and GetPadC.
+
+Revision 1.25  2000/06/29 12:34:09  morsch
+AliMUONSegmentation class has been made independent of AliMUONChamber. This makes
+it usable with any other geometry class. The link to the object to which it belongs is
+established via an index. This assumes that there exists a global geometry manager
+from which the pointer to the parent object can be obtained (in our case gAlice).
+
+Revision 1.24  2000/06/28 15:16:35  morsch
+(1) Client code adapted to new method signatures in AliMUONSegmentation (see comments there)
+to allow development of slat-muon chamber simulation and reconstruction code in the MUON
+framework. The changes should have no side effects (mostly dummy arguments).
+(2) Hit disintegration uses 3-dim hit coordinates to allow simulation
+of chambers with overlapping modules (MakePadHits, Disintegration).
+
+Revision 1.23  2000/06/28 12:19:17  morsch
+More consequent seperation of global input data services (AliMUONClusterInput singleton) and the
+cluster and hit reconstruction algorithms in AliMUONClusterFinderVS.
+AliMUONClusterFinderVS becomes the base class for clustering and hit reconstruction.
+It requires two cathode planes. Small modifications in the code will make it usable for
+one cathode plane and, hence, more general (for test beam data).
+AliMUONClusterFinder is now obsolete.
+
+Revision 1.22  2000/06/28 08:06:10  morsch
+Avoid global variables in AliMUONClusterFinderVS by seperating the input data for the fit from the
+algorithmic part of the class. Input data resides inside the AliMUONClusterInput singleton.
+It also naturally takes care of the TMinuit instance.
+
+Revision 1.21  2000/06/27 08:54:41  morsch
+Problems with on constant array sizes (in hitMap, nmuon, xhit, yhit) corrected.
+
+Revision 1.20  2000/06/26 14:02:38  morsch
+Add class AliMUONConstants with MUON specific constants using static memeber data and access methods.
+
+Revision 1.19  2000/06/22 13:40:51  morsch
+scope problem on HP, "i" declared once
+pow changed to TMath::Power (PH, AM)
+
+Revision 1.18  2000/06/15 07:58:48  morsch
+Code from MUON-dev joined
+
 Revision 1.14.4.17  2000/06/14 14:36:46  morsch
 - add TriggerCircuit (PC)
 - add GlobalTrigger and LocalTrigger and specific methods (PC)
@@ -79,6 +138,7 @@ Log message added
 #include <TTUBE.h>
 #include <TBRIK.h>
 #include <TRotMatrix.h>
+#include <TGeometry.h>
 #include <TNode.h> 
 #include <TTree.h> 
 #include <TRandom.h> 
@@ -105,14 +165,16 @@ Log message added
 #include "AliMUONRawCluster.h"
 #include "AliMUONLocalTrigger.h"
 #include "AliMUONGlobalTrigger.h"
-#include "AliMUONHitMap.h"
+#include "AliMUONTriggerCircuit.h"
+#include "AliHitMap.h"
 #include "AliMUONHitMapA1.h"
 #include "AliMUONChamberTrigger.h"
-
-#include "AliMUONClusterFinder.h"
+#include "AliMUONConstants.h"
+#include "AliMUONClusterFinderVS.h"
 #include "AliMUONTriggerDecision.h"
 #include "AliRun.h"
 #include "AliMC.h"
+#include "AliMUONClusterInput.h"
 #include "iostream.h"
 #include "AliCallf77.h" 
 #include "AliConst.h" 
@@ -130,9 +192,6 @@ Log message added
 //     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}; 
 
 ClassImp(AliMUON)
 //___________________________________________
@@ -151,6 +210,9 @@ AliMUON::AliMUON()
    fNLocalTrigger   = 0;
    fLocalTrigger    = 0;
    fNLocalTrigger   = 0;
+   fAccMin          = 0.;
+   fAccMax          = 0.;   
+   fAccCut          = kFALSE;
 }
  
 //___________________________________________
@@ -162,62 +224,50 @@ AliMUON::AliMUON(const char *name, const char *title)
 <img src="gif/alimuon.gif">
 */
 //End_Html
+
    fHits     = new TClonesArray("AliMUONHit",1000);
    gAlice->AddHitList(fHits);
    fPadHits = new TClonesArray("AliMUONPadHit",10000);
    fNPadHits  =  0;
    fIshunt     =  0;
 
-   fNdch      = new Int_t[kNCH];
+   fNdch      = new Int_t[AliMUONConstants::NCh()];
 
-   fDchambers = new TObjArray(kNCH);
+   fDchambers = new TObjArray(AliMUONConstants::NCh());
 
    Int_t i;
    
-   for (i=0; i<kNCH ;i++) {
+   for (i=0; i<AliMUONConstants::NCh() ;i++) {
        (*fDchambers)[i] = new TClonesArray("AliMUONDigit",10000); 
        fNdch[i]=0;
    }
 
-   fNrawch      = new Int_t[kNTrackingCh];
+   fNrawch      = new Int_t[AliMUONConstants::NTrackingCh()];
 
-   fRawClusters = new TObjArray(kNTrackingCh);
+   fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
 
-   for (i=0; i<kNTrackingCh;i++) {
+   for (i=0; i<AliMUONConstants::NTrackingCh();i++) {
        (*fRawClusters)[i] = new TClonesArray("AliMUONRawCluster",10000); 
        fNrawch[i]=0;
    }
-   cout << " here " << "\n";
 
    fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
    fNGlobalTrigger = 0;
    fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);    
    fNLocalTrigger = 0;
 
-//   
-// Transport angular cut
-   fAccCut=0;
-   fAccMin=2;
-   fAccMax=9;
-
    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);
+    fChambers = new TObjArray(AliMUONConstants::NCh());
 
     // Loop over stations
-    for (Int_t st = 0; st < kNCH / 2; st++) {
+    for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
       // Loop over 2 chambers in the station
        for (Int_t stCH = 0; stCH < 2; stCH++) {
 //
@@ -227,21 +277,22 @@ AliMUON::AliMUON(const char *name, const char *title)
 
            ch = 2 * st + stCH;
 //
-           if (ch < kNTrackingCh) {
-               (*fChambers)[ch] = new AliMUONChamber();
+           if (ch < AliMUONConstants::NTrackingCh()) {
+               (*fChambers)[ch] = new AliMUONChamber(ch);
            } else {
-               (*fChambers)[ch] = new AliMUONChamberTrigger();
+               (*fChambers)[ch] = new AliMUONChamberTrigger(ch);
            }
            
            AliMUONChamber* chamber = (AliMUONChamber*) (*fChambers)[ch];
            
            chamber->SetGid(0);
            // Default values for Z of chambers
-           chamber->SetZ(kDefaultChambersZ[ch]);
+           chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
 //
-           chamber->InitGeo(kDefaultChambersZ[ch]);
-           chamber->SetRInner(kDmin[st]/2);
-           chamber->SetROuter(kDmax[st]/2);
+           chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
+//          Set chamber inner and outer radius to default
+           chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
+           chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
 //
        } // Chamber stCH (0, 1) in 
     }     // Station st (0...)
@@ -252,10 +303,14 @@ AliMUON::AliMUON(const char *name, const char *title)
 //
    fMaxIterPad   = 0;
    fCurIterPad   = 0;
+//
+   fAccMin          = 0.;
+   fAccMax          = 0.;   
+   fAccCut          = kFALSE;
 
    // cp new design of AliMUONTriggerDecision
-   fTriggerCircuits = new TObjArray(kNTriggerCircuit);
-   for (Int_t circ=0; circ<kNTriggerCircuit; circ++) {
+   fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
+   for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
      (*fTriggerCircuits)[circ] = new AliMUONTriggerCircuit();     
    }
    // cp new design of AliMUONTriggerDecision
@@ -272,36 +327,35 @@ AliMUON::AliMUON(const AliMUON& rMUON)
 
 AliMUON::~AliMUON()
 {
-
     printf("Calling AliMUON destructor !!!\n");
     
-  Int_t i;
-  fIshunt  = 0;
-  delete fHits;
-  delete fPadHits;
-
-  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<kNTrackingCh;i++) {
-      delete (*fRawClusters)[i];
-      fNrawch[i]=0;
-  }
-  delete fRawClusters;
+    Int_t i;
+    fIshunt  = 0;
+    delete fHits;
+    delete fPadHits;
+    
+    delete fGlobalTrigger;
+    fNGlobalTrigger = 0;
+    
+    delete fLocalTrigger;
+    fNLocalTrigger = 0;
 
-  for (Int_t circ=0; circ<kNTriggerCircuit; circ++) {
-    delete (*fTriggerCircuits)[circ];
-  }
-  delete fTriggerCircuits;
+    for (i=0;i<AliMUONConstants::NCh();i++) {
+       delete (*fDchambers)[i];
+       fNdch[i]=0;
+    }
+    delete fDchambers;
+    
+    for (i=0;i<AliMUONConstants::NTrackingCh();i++) {
+       delete (*fRawClusters)[i];
+       fNrawch[i]=0;
+    }
+    delete fRawClusters;
+    
+    for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
+       delete (*fTriggerCircuits)[circ];
+    }
+    delete fTriggerCircuits;
 }
  
 //___________________________________________
@@ -538,56 +592,55 @@ Int_t AliMUON::DistancetoPrimitive(Int_t , Int_t )
 //___________________________________________
 void AliMUON::MakeBranch(Option_t* option)
 {
-  // Create Tree branches for the MUON.
-  
-  const Int_t kBufferSize = 4000;
-  char branchname[30];
-  sprintf(branchname,"%sCluster",GetName());
-
-  AliDetector::MakeBranch(option);
-
-  if (fPadHits   && gAlice->TreeH()) {
-    gAlice->TreeH()->Branch(branchname,&fPadHits, kBufferSize);
-    printf("Making Branch %s for clusters\n",branchname);
-  }
-
+    // Create Tree branches for the MUON.
+    const Int_t kBufferSize = 4000;
+    char branchname[30];
+    sprintf(branchname,"%sCluster",GetName());
+    
+    AliDetector::MakeBranch(option);
+    
+    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<kNCH ;i++) {
-      sprintf(branchname,"%sDigits%d",GetName(),i+1);
-      
-      if (fDchambers   && gAlice->TreeD()) {
-         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());
-
+    Int_t i;
+    
+    for (i=0; i<AliMUONConstants::NCh() ;i++) {
+       sprintf(branchname,"%sDigits%d",GetName(),i+1);
+       
+       if (fDchambers   && gAlice->TreeD()) {
+           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());
+    
 // one branch for raw clusters per chamber
-  for (i=0; i<kNTrackingCh ;i++) {
-      sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
-      
-      if (fRawClusters   && gAlice->TreeR()) {
-        gAlice->TreeR()->Branch(branchname,&((*fRawClusters)[i]), kBufferSize);
-        printf("Making Branch %s for raw clusters in chamber %d\n",branchname,i+1);
-      }        
-  }
-
+    for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
+       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
+       
+       if (fRawClusters   && gAlice->TreeR()) {
+           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);
-  }
+    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);
-  }
-
+    sprintf(branchname,"%sLocalTrigger",GetName());
+    if (fLocalTrigger && gAlice->TreeR()) {  
+       gAlice->TreeR()->Branch(branchname,&fLocalTrigger,kBufferSize);
+       printf("Making Branch %s for Local Trigger\n",branchname);
+    }
+    
 }
 
 //___________________________________________
@@ -610,7 +663,7 @@ void AliMUON::SetTreeAddress()
   }
 
   if (treeD) {
-      for (int i=0; i<kNCH; i++) {
+      for (int i=0; i<AliMUONConstants::NCh(); i++) {
          sprintf(branchname,"%sDigits%d",GetName(),i+1);
          if (fDchambers) {
              branch = treeD->GetBranch(branchname);
@@ -622,7 +675,7 @@ void AliMUON::SetTreeAddress()
   // printf("SetTreeAddress --- treeR address  %p \n",treeR);
 
   if (treeR) {
-      for (int i=0; i<kNTrackingCh; i++) {
+      for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
          sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
          if (fRawClusters) {
              branch = treeR->GetBranch(branchname);
@@ -655,7 +708,7 @@ void AliMUON::ResetDigits()
     //
     // Reset number of digits and the digits array for this detector
     //
-    for ( int i=0;i<kNCH;i++ ) {
+    for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
        if ((*fDchambers)[i])    ((TClonesArray*)(*fDchambers)[i])->Clear();
        if (fNdch)  fNdch[i]=0;
     }
@@ -666,7 +719,7 @@ void AliMUON::ResetRawClusters()
     //
     // Reset number of raw clusters and the raw clust array for this detector
     //
-    for ( int i=0;i<kNTrackingCh;i++ ) {
+    for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
        if ((*fRawClusters)[i])    ((TClonesArray*)(*fRawClusters)[i])->Clear();
        if (fNrawch)  fNrawch[i]=0;
     }
@@ -695,9 +748,9 @@ 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;
+    for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
+       ((AliMUONChamber*) ((*fChambers)[ch]))->SetZ(Z[ch]);
+    return;
 }
 
 //___________________________________________
@@ -705,7 +758,7 @@ void AliMUON::SetChambersZToDefault()
 {
   // Set Z values for all chambers (tracking and trigger)
   // to default values
-  SetChambersZ(kDefaultChambersZ);
+  SetChambersZ(AliMUONConstants::DefaultChamberZ());
   return;
 }
 
@@ -734,7 +787,7 @@ void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
 }
 
 //___________________________________________
-void AliMUON::SetMaxAdc(Int_t id, Float_t p1)
+void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
 {
     Int_t i=2*(id-1);
     ((AliMUONChamber*) (*fChambers)[i])->SetMaxAdc(p1);
@@ -765,14 +818,26 @@ void AliMUON::SetMaxDestepAlu(Float_t p1)
     fMaxDestepAlu=p1;
 }
 //___________________________________________
-void AliMUON::SetMuonAcc(Bool_t acc, Float_t angmin, Float_t angmax)
+void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
 {
    fAccCut=acc;
-   fAccMin=angmin;
-   fAccMax=angmax;
+   fAccMin=angmin*TMath::Pi()/180;
+   fAccMax=angmax*TMath::Pi()/180;
+   Int_t ch;
+   if (acc) {
+       for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
+          // Loop over 2 chambers in the station
+          for (Int_t stCH = 0; stCH < 2; stCH++) {
+              ch = 2 * st + stCH;
+//         Set chamber inner and outer radius according to acceptance cuts
+              Chamber(ch).SetRInner(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin));
+              Chamber(ch).SetROuter(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax));
+          } // chamber loop
+       } // station loop
+   }
 }
 //___________________________________________
-void   AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliMUONSegmentation *segmentation)
+void   AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
 {
     ((AliMUONChamber*) (*fChambers)[id])->SetSegmentationModel(isec, segmentation);
 
@@ -783,7 +848,7 @@ void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
     ((AliMUONChamber*) (*fChambers)[id])->SetResponseModel(response);
 }
 
-void   AliMUON::SetReconstructionModel(Int_t id, AliMUONClusterFinder *reconst)
+void   AliMUON::SetReconstructionModel(Int_t id, AliMUONClusterFinderVS *reconst)
 {
     ((AliMUONChamber*) (*fChambers)[id])->SetReconstructionModel(reconst);
 }
@@ -798,7 +863,7 @@ void   AliMUON::SetNsec(Int_t id, Int_t nsec)
 
 
 
-void AliMUON::MakePadHits(Float_t xhit,Float_t yhit,
+void AliMUON::MakePadHits(Float_t xhit,Float_t yhit, Float_t zhit,
                          Float_t eloss, Float_t tof,  Int_t idvol)
 {
 //
@@ -818,7 +883,7 @@ void AliMUON::MakePadHits(Float_t xhit,Float_t yhit,
 //
 //
     ((AliMUONChamber*) (*fChambers)[idvol])
-       ->DisIntegration(eloss, tof, xhit, yhit, nnew, newclust);
+       ->DisIntegration(eloss, tof, xhit, yhit, zhit, nnew, newclust);
     Int_t ic=0;
     
 //
@@ -855,8 +920,9 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
     static TFile *file;
     char *addBackground = strstr(option,"Add");
 
-    AliMUONChamber*  iChamber;
-    AliMUONSegmentation*  segmentation;
+
+    AliMUONChamber*   iChamber;
+    AliSegmentation*  segmentation;
 
     
     Int_t trk[50];
@@ -867,8 +933,8 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
     Int_t digits[5]; 
 
     AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
-    AliMUONHitMap * hitMap[kNCH];
-    for (Int_t i=0; i<kNCH; i++) {hitMap[i]=0;}
+    AliHitMap** hitMap= new AliHitMap* [AliMUONConstants::NCh()];
+    for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {hitMap[i]=0;}
     if (addBackground ) {
        if(first) {
            fFileName=filename;
@@ -914,11 +980,12 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
     //
     // loop over cathodes
     //
-    AliMUONHitMap* hm;
+    AliHitMap* hm;
     Int_t countadr=0;
     for (int icat=0; icat<2; icat++) { 
        Int_t counter=0;
-       for (Int_t i =0; i<kNCH; i++) {
+       Int_t * nmuon = new Int_t [AliMUONConstants::NCh()];
+       for (Int_t i =0; i<AliMUONConstants::NCh(); i++) {
            iChamber=(AliMUONChamber*) (*fChambers)[i];
            if (iChamber->Nsec()==1 && icat==1) {
                continue;
@@ -926,6 +993,7 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
                segmentation=iChamber->SegmentationModel(icat+1);
            }
            hitMap[i] = new AliMUONHitMapA1(segmentation, list);
+           nmuon[i]=0;
        }
        //printf("Start loop over tracks \n");     
 //
@@ -934,14 +1002,16 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
 
        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];
-       
+       Int_t jj;
+
+       Float_t ** xhit = new Float_t * [AliMUONConstants::NCh()];
+       for (jj=0; jj<AliMUONConstants::NCh(); jj++) xhit[jj] = new Float_t[2];
+       Float_t ** yhit = new Float_t * [AliMUONConstants::NCh()];
+       for (jj=0; jj<AliMUONConstants::NCh(); jj++) yhit[jj] = new Float_t[2];
+
        for (Int_t track=0; track<ntracks; track++) {
            gAlice->ResetHits();
            treeH->GetEvent(track);
-           
 //
 //   Loop over hits
            for(AliMUONHit* mHit=(AliMUONHit*)pMUON->FirstHit(-1); 
@@ -949,15 +1019,15 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
                mHit=(AliMUONHit*)pMUON->NextHit()) 
            {
                Int_t   nch   = mHit->fChamber-1;  // chamber number
-               if (nch > kNCH-1) continue;
+               if (nch > AliMUONConstants::NCh()-1) continue;
                iChamber = &(pMUON->Chamber(nch));
                 // new 17.07.99
                if (addBackground) {
 
                    if (mHit->fParticle == kMuonPlus 
                        || mHit->fParticle == kMuonMinus) {
-                       xhit[nch][nmuon[nch]]=mHit->fX;
-                       yhit[nch][nmuon[nch]]=mHit->fY;
+                       xhit[nch][nmuon[nch]]=mHit->X();
+                       yhit[nch][nmuon[nch]]=mHit->Y();
                        nmuon[nch]++;
                        if (nmuon[nch] >2) printf("nmuon %d\n",nmuon[nch]);
                    }
@@ -982,9 +1052,9 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
                    
                    if (cathode != (icat+1)) continue;
                    // fill the info array
-                   Float_t thex, they;
+                   Float_t thex, they, thez;
                    segmentation=iChamber->SegmentationModel(cathode);
-                   segmentation->GetPadCxy(ipx,ipy,thex,they);
+                   segmentation->GetPadC(ipx,ipy,thex,they,thez);
 //                 Float_t rpad=TMath::Sqrt(thex*thex+they*they);
 //                 if (rpad < rmin || iqpad ==0 || rpad > rmax) continue;
 
@@ -1075,8 +1145,8 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
                    iChamber = &(pMUON->Chamber(nch));
                    Int_t rmin = (Int_t)iChamber->RInner();
                    Int_t rmax = (Int_t)iChamber->ROuter();
-                    Float_t xbgr=mHit->fX;
-                   Float_t ybgr=mHit->fY;
+                    Float_t xbgr=mHit->X();
+                   Float_t ybgr=mHit->Y();
                    Bool_t cond=kFALSE;
                    
                    for (Int_t imuon =0; imuon < nmuon[nch]; imuon++) {
@@ -1100,9 +1170,9 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
                        Int_t iqpad    = Int_t(mPad->fQpad);// charge per pad
 
                        if (cathode != (icat+1)) continue;
-                       Float_t thex, they;
+                       Float_t thex, they, thez;
                        segmentation=iChamber->SegmentationModel(cathode);
-                       segmentation->GetPadCxy(ipx,ipy,thex,they);
+                       segmentation->GetPadC(ipx,ipy,thex,they,thez);
                        Float_t rpad=TMath::Sqrt(thex*thex+they*they);
                        if (rpad < rmin || iqpad ==0 || rpad > rmax) continue;
                        new((*pAddress)[countadr++]) TVector(2);
@@ -1168,8 +1238,10 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
            
            if (fAli) file =fAli->GetCurrentFile();
            file->cd();
-       } // if addBackground   
-       
+       } // if addBackground
+       delete [] xhit;
+       delete [] yhit;
+
        Int_t tracks[10];
        Int_t charges[10];
        Int_t nentries=list->GetEntriesFast();
@@ -1235,16 +1307,18 @@ void AliMUON::Digitise(Int_t nev,Int_t bgrEvent,Option_t *option,Option_t *opt,T
        gAlice->TreeD()->Fill();
        pMUON->ResetDigits();
        list->Delete();
+
        
-       for(Int_t ii=0;ii<kNCH;++ii) {
+       for(Int_t ii=0;ii<AliMUONConstants::NCh();++ii) {
            if (hitMap[ii]) {
                hm=hitMap[ii];
                delete hm;
                hitMap[ii]=0;
            }
        }
+       delete [] nmuon;    
     } //end loop over cathodes
-    
+    delete [] hitMap;
     char hname[30];
     sprintf(hname,"TreeD%d",nev);
     gAlice->TreeD()->Write(hname);
@@ -1322,31 +1396,30 @@ void AliMUON::Trigger(Int_t nev){
   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);
+  Int_t i;
   
-  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));
+  for (Int_t icirc=0; icirc<AliMUONConstants::NTriggerCircuit(); 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 (i=0; i<2; i++) {    // convert the Lut output in 1 digit 
+             localtr[4] = localtr[4]+Int_t(loLpt[i]*TMath::Power(2,i));
+             localtr[5] = localtr[5]+Int_t(loHpt[i]*TMath::Power(2,i));
+             localtr[6] = localtr[6]+Int_t(loApt[i]*TMath::Power(2,i));
+         }
+         AddLocalTrigger(localtr);  // add a local trigger in the list
       }
-      //      cout << loApt[0] << " , " << loApt[1] << " , " << localtr[6] << "\n";
-      AddLocalTrigger(localtr);  // add a local trigger in the list
-    }
   }
   delete decision;
 
@@ -1374,7 +1447,7 @@ void AliMUON::FindClusters(Int_t nev,Int_t lastEntry)
     
     for (Int_t ich=0;ich<10;ich++) {
        AliMUONChamber* iChamber=(AliMUONChamber*) (*fChambers)[ich];
-       AliMUONClusterFinder* rec = iChamber->ReconstructionModel();    
+       AliMUONClusterFinderVS* rec = iChamber->ReconstructionModel();    
        gAlice->ResetDigits();
        gAlice->TreeD()->GetEvent(lastEntry);
        TClonesArray *muonDigits  = this->DigitsAddress(ich);
@@ -1401,9 +1474,8 @@ void AliMUON::FindClusters(Int_t nev,Int_t lastEntry)
            new(lhits2[n++]) AliMUONDigit(*digit);
        }
 
-       if (rec) {        
-           rec->SetDigits(dig1, dig2);
-           rec->SetChamber(ich);
+       if (rec) {       
+           AliMUONClusterInput::Instance()->SetDigits(ich, dig1, dig2);
            rec->FindRawClusters();
        }
        dig1->Delete();
@@ -1426,112 +1498,112 @@ void AliMUON::FindClusters(Int_t nev,Int_t lastEntry)
 void AliMUON::Streamer(TBuffer &R__b)
 {
    // Stream an object of class AliMUON.
-      AliMUONChamber       *iChamber;
+      AliMUONChamber        *iChamber;
       AliMUONTriggerCircuit *iTriggerCircuit;
-      AliMUONSegmentation  *segmentation;
-      AliMUONResponse      *response;
-      TClonesArray         *digitsaddress;
-      TClonesArray         *rawcladdress;
-      
-   if (R__b.IsReading()) {
-      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
-      AliDetector::Streamer(R__b);
-      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.ReadArray(fNdch);
-      R__b.ReadArray(fNrawch);
-      R__b >> fAccCut;
-      R__b >> fAccMin;
-      R__b >> fAccMax; 
-      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<kNCH; i++) {
-         iChamber=(AliMUONChamber*) (*fChambers)[i];
-         iChamber->Streamer(R__b);
-         if (iChamber->Nsec()==1) {
-             segmentation=iChamber->SegmentationModel(1);
-             if (segmentation)
-             segmentation->Streamer(R__b);
-         } else {
-             segmentation=iChamber->SegmentationModel(1);
-             if (segmentation)
-             segmentation->Streamer(R__b);
-             if (segmentation)
-             segmentation=iChamber->SegmentationModel(2);
-             segmentation->Streamer(R__b);
+      AliSegmentation       *segmentation;
+      AliMUONResponse       *response;
+      TClonesArray          *digitsaddress;
+      TClonesArray          *rawcladdress;
+      Int_t i;
+      if (R__b.IsReading()) {
+         Version_t R__v = R__b.ReadVersion(); if (R__v) { }
+         AliDetector::Streamer(R__b);
+         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.ReadArray(fNdch);
+         R__b.ReadArray(fNrawch);
+         R__b >> fAccCut;
+         R__b >> fAccMin;
+         R__b >> fAccMax; 
+         R__b >> fChambers;
+         R__b >> fTriggerCircuits;
+         for (i =0; i<AliMUONConstants::NTriggerCircuit(); i++) {
+             iTriggerCircuit=(AliMUONTriggerCircuit*) (*fTriggerCircuits)[i];
+             iTriggerCircuit->Streamer(R__b);
          }
-          response=iChamber->ResponseModel();
-         if (response)
-         response->Streamer(R__b);       
-         digitsaddress=(TClonesArray*) (*fDchambers)[i];
-         digitsaddress->Streamer(R__b);
-         if (i < kNTrackingCh) {
-             rawcladdress=(TClonesArray*) (*fRawClusters)[i];
-             rawcladdress->Streamer(R__b);
+// Stream chamber related information
+         for (i =0; i<AliMUONConstants::NCh(); i++) {
+             iChamber=(AliMUONChamber*) (*fChambers)[i];
+             iChamber->Streamer(R__b);
+             if (iChamber->Nsec()==1) {
+                 segmentation=iChamber->SegmentationModel(1);
+                 if (segmentation)
+                     segmentation->Streamer(R__b);
+             } else {
+                 segmentation=iChamber->SegmentationModel(1);
+                 if (segmentation)
+                     segmentation->Streamer(R__b);
+                 if (segmentation)
+                     segmentation=iChamber->SegmentationModel(2);
+                 segmentation->Streamer(R__b);
+             }
+             response=iChamber->ResponseModel();
+             if (response)
+                 response->Streamer(R__b);       
+             digitsaddress=(TClonesArray*) (*fDchambers)[i];
+             digitsaddress->Streamer(R__b);
+             if (i < AliMUONConstants::NTrackingCh()) {
+                 rawcladdress=(TClonesArray*) (*fRawClusters)[i];
+                 rawcladdress->Streamer(R__b);
+             }
          }
-      }
-      
-   } else {
-      R__b.WriteVersion(AliMUON::IsA());
-      AliDetector::Streamer(R__b);
-      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.WriteArray(fNdch, kNCH);
-      R__b.WriteArray(fNrawch, kNTrackingCh);
-
-      R__b << fAccCut;
-      R__b << fAccMin;
-      R__b << fAccMax; 
-
-      R__b << fChambers;
-      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->SegmentationModel(1);
-             if (segmentation)
-             segmentation->Streamer(R__b);
-         } else {
-             segmentation=iChamber->SegmentationModel(1);
-             if (segmentation)
-             segmentation->Streamer(R__b);
-             segmentation=iChamber->SegmentationModel(2);
-             if (segmentation)
-             segmentation->Streamer(R__b);
+         
+      } else {
+         R__b.WriteVersion(AliMUON::IsA());
+         AliDetector::Streamer(R__b);
+         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.WriteArray(fNdch, AliMUONConstants::NCh());
+         R__b.WriteArray(fNrawch, AliMUONConstants::NTrackingCh());
+         
+         R__b << fAccCut;
+         R__b << fAccMin;
+         R__b << fAccMax; 
+         
+         R__b << fChambers;
+         R__b << fTriggerCircuits;
+         for (i =0; i<AliMUONConstants::NTriggerCircuit(); i++) {
+             iTriggerCircuit=(AliMUONTriggerCircuit*) (*fTriggerCircuits)[i];
+             iTriggerCircuit->Streamer(R__b);
          }
-          response=iChamber->ResponseModel();
-         if (response)
-         response->Streamer(R__b);
-         digitsaddress=(TClonesArray*) (*fDchambers)[i];
-         digitsaddress->Streamer(R__b);
-         if (i < kNTrackingCh) {
-             rawcladdress=(TClonesArray*) (*fRawClusters)[i];
-             rawcladdress->Streamer(R__b);
+         for (i =0; i<AliMUONConstants::NCh(); i++) {
+             iChamber=(AliMUONChamber*) (*fChambers)[i];
+             iChamber->Streamer(R__b);
+             if (iChamber->Nsec()==1) {
+                 segmentation=iChamber->SegmentationModel(1);
+                 if (segmentation)
+                     segmentation->Streamer(R__b);
+             } else {
+                 segmentation=iChamber->SegmentationModel(1);
+                 if (segmentation)
+                     segmentation->Streamer(R__b);
+                 segmentation=iChamber->SegmentationModel(2);
+                 if (segmentation)
+                     segmentation->Streamer(R__b);
+             }
+             response=iChamber->ResponseModel();
+             if (response)
+                 response->Streamer(R__b);
+             digitsaddress=(TClonesArray*) (*fDchambers)[i];
+             digitsaddress->Streamer(R__b);
+             if (i < AliMUONConstants::NTrackingCh()) {
+                 rawcladdress=(TClonesArray*) (*fRawClusters)[i];
+                 rawcladdress->Streamer(R__b);
+             }
          }
       }
-   }
 }
 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit*  hit, TClonesArray *clusters) 
 {