]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUON.cxx
Update of HP decoders:
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
index 63e9994f370828629f67629169ccf4b09c4e8d80..a6765b48194c4be02f5d4dd1318eb2362a9d2004 100644 (file)
 
 /* $Id$ */
 
-
-///////////////////////////////////////////////
-//  Manager and hits classes for set:MUON     //
-////////////////////////////////////////////////
+//-----------------------------------------------------------------------------
+// Class AliMUON
+// ------------------
+// AliDetector class for MUON subsystem 
+// providing simulation data management 
+//-----------------------------------------------------------------------------
 
 #include "Riostream.h"
 
 #include <TVector.h>
 #include <TVirtualMC.h>
 
-#include "AliConst.h" 
-#include "AliHeader.h"
-#include "AliHitMap.h"
+//#include "AliHeader.h"
 #include "AliLoader.h"
+#include "AliRunDigitizer.h"
+#include "AliMC.h"
+#include "AliRun.h"
+#include "AliRawDataHeaderSim.h"
 #include "AliMUON.h"
 #include "AliMUONChamberTrigger.h"
-#include "AliMUONClusterFinderVS.h"
-#include "AliMUONClusterInput.h"
 #include "AliMUONConstants.h"
-#include "AliMUONDigit.h"
-#include "AliMUONGlobalTrigger.h"
-#include "AliMUONHit.h"
-#include "AliMUONHitMapA1.h"
-#include "AliMUONLocalTrigger.h"
-#include "AliMUONMerger.h"     
-#include "AliMUONPadHit.h"
-#include "AliMUONRawCluster.h"
-#include "AliMUONTransientDigit.h"
-#include "AliMUONTriggerCircuit.h"
-#include "AliMUONTriggerDecision.h"
-#include "AliRun.h"    
-
+#include "AliMUONHit.h"        
+#include "AliMUONGeometry.h"
+#include "AliMUONGeometryTransformer.h"
+#include "AliMUONGeometryBuilder.h"
+#include "AliMUONCommonGeometryBuilder.h"
+#include "AliMUONVGeometryBuilder.h"   
+#include "AliMUONRawWriter.h"
+#include "AliLog.h"
+
+#include "AliMUONSDigitizerV2.h"
+#include "AliMUONDigitizerV3.h"
+#include "AliMUONDigitMaker.h"
+
+#include "AliMUONSt1GeometryBuilderV2.h"
+#include "AliMUONSt2GeometryBuilderV2.h"
+#include "AliMUONSlatGeometryBuilder.h"
+#include "AliMUONTriggerGeometryBuilder.h"
+
+#include "AliMUONDigitStoreV1.h"
+#include "AliMUONVTriggerStore.h"
+#include "AliMUONHitStoreV1.h"
 
 // Defaults parameters for Z positions of chambers
 // taken from values for "stations" in AliMUON::AliMUON
 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
 //          for the first and second chambers in the station, respectively
 
-ClassImp(AliMUON)
-//___________________________________________
+/// \cond CLASSIMP
+ClassImp(AliMUON)  
+/// \endcond
+
+//__________________________________________________________________
 AliMUON::AliMUON()
-{
-// Default Constructor
-//
-    fNCh             = 0;
-    fNTrackingCh     = 0;
+  : AliDetector(),
+    fNCh(0),
+    fNTrackingCh(0),
+    fSplitLevel(0),
+    fChambers(0),
+    fGeometryBuilder(0),
+    fAccCut(kFALSE),
+    fAccMin(0.),
+    fAccMax(0.),   
+    fMaxStepGas(0.),
+    fMaxStepAlu(0.),
+    fMaxDestepGas(0.),
+    fMaxDestepAlu(0.),
+    fMaxIterPad(0),
+    fCurIterPad(0),
+    fTriggerScalerEvent(kFALSE),
+    fTriggerResponseV1(kFALSE),
+    fTriggerCoinc44(0),
+    fTriggerEffCells(0),
+    fDigitizerWithNoise(1),
+    fIsTailEffect(kTRUE),
+    fRawWriter(0x0),
+    fDigitMaker(0x0),
+    fHitStore(0x0),
+  fDigitStoreConcreteClassName()
+{
+/// Default Constructor
+    
+    AliDebug(1,Form("default (empty) ctor this=%p",this));
     fIshunt          = 0;
-    fPadHits         = 0;
-    fNPadHits        = 0;
-    fChambers        = 0;
-    fDchambers       = 0;
-    fTriggerCircuits = 0;  
-    fNdch            = 0;
-    fRawClusters     = 0;
-    fNrawch          = 0;
-    fGlobalTrigger   = 0;
-    fNLocalTrigger   = 0;
-    fLocalTrigger    = 0;
-    fNLocalTrigger   = 0;
-    fAccMin          = 0.;
-    fAccMax          = 0.;   
-    fAccCut          = kFALSE;
-    fMerger          = 0;
-    fFileName        = 0;
 }
-//___________________________________________
-AliMUON::AliMUON(const char *name, const char *title)
-       : AliDetector(name,title)
-{
-//Begin_Html
-/*
-<img src="gif/alimuon.gif">
-*/
-//End_Html
-
-   fHits     = new TClonesArray("AliMUONHit",1000);
-   gAlice->AddHitList(fHits);
-   fPadHits = new TClonesArray("AliMUONPadHit",10000);
-   fNPadHits  =  0;
-   fIshunt     =  0;
-
-   fNCh             = AliMUONConstants::NCh(); 
-   fNTrackingCh     = AliMUONConstants::NTrackingCh();
-   fNdch            = new Int_t[fNCh];
-
-   fDchambers = new TObjArray(AliMUONConstants::NCh());
-
-   Int_t i;
-   
-   for (i=0; i<AliMUONConstants::NCh() ;i++) {
-       fDchambers->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
-       fNdch[i]=0;
-   }
-
-   fNrawch      = new Int_t[fNTrackingCh];
-
-   fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
-
-   for (i=0; i<AliMUONConstants::NTrackingCh();i++) {
-       fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
-       fNrawch[i]=0;
-   }
-
-   fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
-   fNGlobalTrigger = 0;
-   fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);    
-   fNLocalTrigger = 0;
-
-   SetMarkerColor(kRed);
-//
-//
-//
-//
 
-    Int_t ch;
+//__________________________________________________________________
+AliMUON::AliMUON(const char *name, const char* title)
+  : AliDetector(name, title),
+    fNCh(AliMUONConstants::NCh()),
+    fNTrackingCh(AliMUONConstants::NTrackingCh()),
+    fSplitLevel(0),
+    fChambers(0),
+    fGeometryBuilder(0),
+    fAccCut(kFALSE),
+    fAccMin(0.),
+    fAccMax(0.),   
+    fMaxStepGas(0.1),
+    fMaxStepAlu(0.1),
+    fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
+    fMaxDestepAlu(-1), // in the calculation of the tracking parameters
+    fMaxIterPad(0),
+    fCurIterPad(0),
+    fTriggerScalerEvent(kFALSE),
+    fTriggerResponseV1(kFALSE),
+    fTriggerCoinc44(0),
+    fTriggerEffCells(0),
+    fDigitizerWithNoise(1),
+    fIsTailEffect(kTRUE),
+    fRawWriter(0x0),
+    fDigitMaker(new AliMUONDigitMaker),
+    fHitStore(0x0),
+  fDigitStoreConcreteClassName("AliMUONDigitStoreV2S")
+{
+/// Standard constructor  
+  
+  AliDebug(1,Form("ctor this=%p",this));
+  fIshunt =  0;
 
+  //PH SetMarkerColor(kRed);//
+    
+  // Geometry builder
+  fGeometryBuilder = new AliMUONGeometryBuilder(this);
+  
+  // Common geometry definitions
+  fGeometryBuilder
+    ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
+
+  // By default, add also all the needed geometry builders.
+  // If you want to change this from outside, please use ResetGeometryBuilder
+  // method, followed by AddGeometryBuilder ones.
+
+  AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
+  AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
+  AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
+  AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
+  
+  //
+  // Creating List of Chambers
+    Int_t ch;
     fChambers = new TObjArray(AliMUONConstants::NCh());
-
+    fChambers->SetOwner(kTRUE);
+    
     // Loop over stations
     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++) {
-//
-//    
-//    Default Parameters for Muon Tracking Stations
-
-
-           ch = 2 * st + stCH;
-//
-           if (ch < AliMUONConstants::NTrackingCh()) {
-             fChambers->AddAt(new AliMUONChamber(ch),ch);
-           } else {
-             fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
-           }
-           
-        //PH       AliMUONChamber* chamber = (AliMUONChamber*) (*fChambers)[ch];
-           AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
-           
-           chamber->SetGid(0);
-           // Default values for Z of chambers
-           chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
-//
-           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 
+      for (Int_t stCH = 0; stCH < 2; stCH++) {
+       //
+       //    
+       //    Default Parameters for Muon Tracking Stations
+       ch = 2 * st + stCH;
+       if (ch < AliMUONConstants::NTrackingCh()) {
+         fChambers->AddAt(new AliMUONChamber(ch),ch);
+       } else {
+         fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
+       }
+      } // Chamber stCH (0, 1) in 
     }     // Station st (0...)
-//    fChambers->SetLast(AliMUONConstants::NCh());
-    fMaxStepGas=0.01; 
-    fMaxStepAlu=0.1; 
-    fMaxDestepGas=-1;
-    fMaxDestepAlu=-1;
-//
-   fMaxIterPad   = 0;
-   fCurIterPad   = 0;
-//
-   fAccMin          = 0.;
-   fAccMax          = 0.;   
-   fAccCut          = kFALSE;
-
-   // cp new design of AliMUONTriggerDecision
-   fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
-   for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
-     fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);     
-
-   }
-     fMerger = 0;
-}
-//___________________________________________
-AliMUON::AliMUON(const AliMUON& rMUON):AliDetector(rMUON)
-{
-// Dummy copy constructor
-    ;
-    
+
 }
 
+//____________________________________________________________________
 AliMUON::~AliMUON()
 {
-// Destructor
-    if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
-    
-    fIshunt  = 0;
-    // Delete TObjArrays
-    if (fChambers){
-      fChambers->Delete();
-      delete fChambers;
-    }
-    if (fTriggerCircuits){
-      fTriggerCircuits->Delete();
-      delete fTriggerCircuits;
-    }
-    if (fDchambers){
-      fDchambers->Delete();
-      delete fDchambers;
-    }
-    if (fRawClusters){
-      fRawClusters->Delete();
-      delete fRawClusters;
-    }
+/// Destructor
 
-    if (fNrawch) delete [] fNrawch;
-    // Delete TClonesArrays
-    if (fPadHits){
-      fPadHits->Delete();
-      delete fPadHits;
-    }
-    if (fGlobalTrigger){
-      fGlobalTrigger->Delete();
-      delete fGlobalTrigger;
-    }
-    fNGlobalTrigger = 0;
-    
-    if (fLocalTrigger){
-      fLocalTrigger->Delete();
-      delete fLocalTrigger;
-    }
-    fNLocalTrigger = 0;
-
-    if (fHits) {
-      fHits->Delete();
-      delete fHits;
-    }
-
-    if (fMerger) delete fMerger;
-    if (fNdch) delete [] fNdch;
-
-}
-//___________________________________________
-void AliMUON::AddHit(Int_t track, Int_t *vol, Float_t *hits)
-{
-  TClonesArray &lhits = *fHits;
-  new(lhits[fNhits++]) AliMUONHit(fIshunt,track,vol,hits);
-}
-//___________________________________________
-void AliMUON::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber, 
-             Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
-             Float_t tof, Float_t momentum, Float_t theta, 
-             Float_t phi, Float_t length, Float_t destep)
-{
-  TClonesArray &lhits = *fHits;
-  new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
-              idpart, X, Y, Z, 
-              tof, momentum, theta, 
-              phi, length, destep);
-}
-//___________________________________________
-void AliMUON::AddPadHit(Int_t *clhits)  // To be removed
-{
-   TClonesArray &lclusters = *fPadHits;
-   new(lclusters[fNPadHits++]) AliMUONPadHit(clhits);
+  AliDebug(1,Form("dtor this=%p",this));
+  delete fChambers;
+  delete fGeometryBuilder;
+  delete fRawWriter;
+  delete fDigitMaker;
+  delete fHitStore;
 }
+
 //_____________________________________________________________________________
-void AliMUON::AddDigits(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
+void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
 {
-    //
-    // Add a MUON digit to the list
-    //
+/// Add the geometry builder to the list
 
-  //PH    TClonesArray &ldigits = * ((TClonesArray*)(*fDchambers)[id]);
-    TClonesArray &ldigits = * ( (TClonesArray*) fDchambers->At(id) );
-    new(ldigits[fNdch[id]++]) AliMUONDigit(tracks,charges,digits);
+  fGeometryBuilder->AddBuilder(geomBuilder);
 }
 
-//_____________________________________________________________________________
-void AliMUON::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
+//____________________________________________________________________
+void AliMUON::BuildGeometry()
 {
-    //
-    // Add a MUON digit to the list
-    //
+/// Geometry for event display
 
-  //PH    TClonesArray &lrawcl = *((TClonesArray*)(*fRawClusters)[id]);
-    TClonesArray &lrawcl = *((TClonesArray*)fRawClusters->At(id));
-    new(lrawcl[fNrawch[id]++]) AliMUONRawCluster(c);
-}
 
-//___________________________________________
-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);
+//     for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)     
+//       this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
+     
+  
 }
 
-//___________________________________________
-void AliMUON::BuildGeometry()
+//____________________________________________________________________
+const AliMUONGeometry*  AliMUON::GetGeometry() const
 {
-// Geometry for event display
-  for (Int_t i=0; i<7; i++) {
-    for (Int_t j=0; j<2; j++) {
-      Int_t id=2*i+j+1;
-      this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
-    }
+/// Return geometry parametrisation
+
+  if ( !fGeometryBuilder) {
+    AliWarningStream() << "GeometryBuilder not defined." << std::endl;
+    return 0;
   }
-}
+  
+  return fGeometryBuilder->GetGeometry();
+}   
 
-//___________________________________________
-Int_t AliMUON::DistancetoPrimitive(Int_t , Int_t )
+//____________________________________________________________________
+const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
 {
-   return 9999;
-}
+/// Return geometry parametrisation
 
-//___________________________________________
-void AliMUON::MakeBranch(Option_t* option)
+  const AliMUONGeometry* kGeometry = GetGeometry();
+  
+  if ( !kGeometry) return 0;
+
+  return kGeometry->GetTransformer();
+}   
+
+//__________________________________________________________________
+void 
+AliMUON::MakeBranch(Option_t* opt)
 {
-    //
-    // Create Tree branches for the MUON.
-    //
-    const Int_t kBufferSize = 4000;
-    char branchname[30];
-    sprintf(branchname,"%sCluster",GetName());
-    
-    
-    const char *cD = strstr(option,"D");
-    const char *cR = strstr(option,"R");
-    const char *cH = strstr(option,"H");
-
-    if (TreeH() && cH) 
-     {
-      if (fPadHits == 0x0) fPadHits = new TClonesArray("AliMUONPadHit",10000);
-      MakeBranchInTree(TreeH(), branchname, &fPadHits, kBufferSize, 0);
-      if (fHits == 0x0) fHits     = new TClonesArray("AliMUONHit",1000);
-     }
-    //it must be under fHits creation
-    AliDetector::MakeBranch(option);
-    
-    if (cD  && fLoader->TreeD()) {
-      //
-      // one branch for digits per chamber
-      // 
-      Int_t i;
-      if (fDchambers  == 0x0) 
-        {
-          fDchambers = new TObjArray(AliMUONConstants::NCh());
-          for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
-              fDchambers->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
-          }
-        }
-    
-      for (i=0; i<AliMUONConstants::NCh() ;i++) 
-       {
-        sprintf(branchname,"%sDigits%d",GetName(),i+1);        
-        MakeBranchInTree(fLoader->TreeD(), branchname, &((*fDchambers)[i]), kBufferSize, 0);
-        printf("Making Branch %s for digits in chamber %d\n",branchname,i+1);
-       }
-    }
+  /// Create branche(s) to hold MUON hits
+  AliDebug(1,"");
+  
+  TString sopt(opt);
+  if ( sopt != "H" ) return;
     
-    if (cR  && fLoader->TreeR()) {
-      //     
-      // one branch for raw clusters per chamber
-      //  
-      printf("Make Branch - TreeR address %p\n",fLoader->TreeR());
-      
-      Int_t i;
-      if (fRawClusters == 0x0)
+  if (!fHitStore)
+  {
+    fHitStore = new AliMUONHitStoreV1;
+    if ( gAlice->GetMCApp() )
+    {
+      if ( gAlice->GetMCApp()->GetHitLists() ) 
       {
-        fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
-        for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
-            fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
-        }
-      }
-
-      for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) 
-       {
-         sprintf(branchname,"%sRawClusters%d",GetName(),i+1);  
-         MakeBranchInTree(fLoader->TreeR(), branchname, &((*fRawClusters)[i]), kBufferSize, 0);
-         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 == 0x0) {
-        fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
-      }
-      MakeBranchInTree(fLoader->TreeR(), branchname, &fGlobalTrigger, kBufferSize, 0);
-      printf("Making Branch %s for Global Trigger\n",branchname);
-      //
-      // one branch for local trigger
-      //  
-      sprintf(branchname,"%sLocalTrigger",GetName());
-      
-      if (fLocalTrigger == 0x0) {
-        fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
-      }
-      
-      MakeBranchInTree(fLoader->TreeR(), branchname, &fLocalTrigger, kBufferSize, 0);
-      printf("Making Branch %s for Local Trigger\n",branchname);
-   }
-}
-
-//___________________________________________
-void AliMUON::SetTreeAddress()
-{
-  // Set branch address for the Hits and Digits Tree.
-  char branchname[30];
-
-  TBranch *branch;
-  TTree *treeH = fLoader->TreeH();
-  TTree *treeD = fLoader->TreeD();
-  TTree *treeR = fLoader->TreeR();
-
-  if (treeH) {
-    if (fPadHits == 0x0) fPadHits = new TClonesArray("AliMUONPadHit",10000);
-    if (fPadHits) {
-      branch = treeH->GetBranch("MUONCluster");
-      if (branch) branch->SetAddress(&fPadHits);
+        // AliStack::PurifyKine needs to be able to loop on our hits
+        // to remap the track numbers.
+        gAlice->GetMCApp()->AddHitList(fHitStore->Collection()); 
+      }  
     }
-    if (fHits == 0x0) fHits     = new TClonesArray("AliMUONHit",1000);
-  }
-  //it must be under fHits creation
-  AliDetector::SetTreeAddress();
-
-  if (treeD) {
-      if (fDchambers == 0x0) 
-        {
-          fDchambers = new TObjArray(AliMUONConstants::NCh());
-          for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
-              fDchambers->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
-          }
-        }
-      for (int i=0; i<AliMUONConstants::NCh(); i++) {
-         sprintf(branchname,"%sDigits%d",GetName(),i+1);
-                        
-                      if (fDchambers) {
-             branch = treeD->GetBranch(branchname);
-             if (branch) branch->SetAddress(&((*fDchambers)[i]));
-         }
-      }
   }
 
-  // printf("SetTreeAddress --- treeR address  %p \n",treeR);
-
-  if (treeR) {
-      if (fRawClusters == 0x0)
-      {
-        fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
-        for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
-            fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
-        }
-      }
-      
-      for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
-         sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
-         if (fRawClusters) {
-             branch = treeR->GetBranch(branchname);
-             if (branch) branch->SetAddress(&((*fRawClusters)[i]));
-         }
-      }
-
-      if (fLocalTrigger == 0x0) {
-        fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
-      }
-
-      if (fLocalTrigger) {
-       branch = treeR->GetBranch("MUONLocalTrigger");
-       if (branch) branch->SetAddress(&fLocalTrigger);
-      }
-      
-      if (fGlobalTrigger == 0x0) {
-        fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
-      }
-      
-      if (fGlobalTrigger) {
-       branch = treeR->GetBranch("MUONGlobalTrigger");
-       if (branch) branch->SetAddress(&fGlobalTrigger);
-      }
+  TTree* treeH = fLoader->TreeH();
+  
+  if (!treeH)
+  {
+    AliFatal("No TreeH");
   }
-}
-//___________________________________________
-void AliMUON::ResetHits()
-{
-  // Reset number of clusters and the cluster array for this detector
-  AliDetector::ResetHits();
-  fNPadHits = 0;
-  if (fPadHits) fPadHits->Clear();
-}
-
-//____________________________________________
-void AliMUON::ResetDigits()
-{
-    //
-    // Reset number of digits and the digits array for this detector
-    //
-    if (fDchambers == 0x0) return;
-    for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
-      //PH     if ((*fDchambers)[i])    ((TClonesArray*)(*fDchambers)[i])->Clear();
-       if ((*fDchambers)[i])    ((TClonesArray*)fDchambers->At(i))->Clear();
-       if (fNdch)  fNdch[i]=0;
-    }
-}
-//____________________________________________
-void AliMUON::ResetRawClusters()
-{
-    //
-    // Reset number of raw clusters and the raw clust array for this detector
-    //
-    for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
-      //PH     if ((*fRawClusters)[i])    ((TClonesArray*)(*fRawClusters)[i])->Clear();
-       if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
-       if (fNrawch)  fNrawch[i]=0;
-    }
-}
-
-//____________________________________________
-void AliMUON::ResetTrigger()
-{
-  //  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)
-{
-// Set the pad size for chamber id and cathode isec
-    Int_t i=2*(id-1);
-    //PH    ((AliMUONChamber*) (*fChambers)[i])  ->SetPadSize(isec,p1,p2);
-    //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetPadSize(isec,p1,p2);
-    ((AliMUONChamber*) fChambers->At(i))  ->SetPadSize(isec,p1,p2);
-    ((AliMUONChamber*) fChambers->At(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 < AliMUONConstants::NCh(); ch++)
-      //PH     ((AliMUONChamber*) ((*fChambers)[ch]))->SetZ(Z[ch]);
-       ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
-    return;
+  
+  fHitStore->Connect(*treeH);
 }
 
-//___________________________________________
-void AliMUON::SetChambersZToDefault()
+//__________________________________________________________________
+void  
+AliMUON::SetTreeAddress()
 {
-  // Set Z values for all chambers (tracking and trigger)
-  // to default values
-  SetChambersZ(AliMUONConstants::DefaultChamberZ());
-  return;
+  /// Set Hits tree address  
+//  if ( gAlice->GetMCApp() && fHitStore )
+//  {
+//    TList* l = gAlice->GetMCApp()->GetHitLists();
+//    if ( l )
+//    {
+//      TObject* o = l->First();
+//      if (o!=fHitStore->HitCollection())
+//      {
+//        AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
+//        l->Print();        
+//      }
+//    }  
+//  }  
+}
+
+//_________________________________________________________________
+void
+AliMUON::ResetHits()
+{
+  /// Reset hits
+  
+  AliDebug(1,"");
+  if (fHitStore) fHitStore->Clear();
 }
 
-//___________________________________________
+//_________________________________________________________________
 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
 {
-// Set the inverse charge slope for chamber id
-    Int_t i=2*(id-1);
-    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetChargeSlope(p1);
-    //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetChargeSlope(p1);
+/// Set the inverse charge slope for chamber id
+
+    Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
+    //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
 }
-
-//___________________________________________
+//__________________________________________________________________
 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
 {
-// Set sigma of charge spread for chamber id
+/// Set sigma of charge spread for chamber id
+
     Int_t i=2*(id-1);
-    //PH    ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
-    //PH    ((AliMUONChamber*) fChambers->Ati+1])->SetChargeSpread(p1,p2);
     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
 }
-
-//___________________________________________
+//___________________________________________________________________
 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
 {
-// Set integration limits for charge spread
+/// Set integration limits for charge spread
     Int_t i=2*(id-1);
-    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
-    //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
 }
 
-//___________________________________________
+//__________________________________________________________________
 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
 {
-// Set maximum number for ADCcounts (saturation)
+/// Set maximum number for ADCcounts (saturation)
+
     Int_t i=2*(id-1);
-    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetMaxAdc(p1);
-    //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetMaxAdc(p1);
     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
 }
 
-//___________________________________________
+//__________________________________________________________________
 void AliMUON::SetMaxStepGas(Float_t p1)
 {
-// Set stepsize in gas
-     fMaxStepGas=p1;
-}
+/// Set stepsize in gas
 
-//___________________________________________
+  fMaxStepGas=p1;
+}
+//__________________________________________________________________
 void AliMUON::SetMaxStepAlu(Float_t p1)
 {
-// Set step size in Alu
+/// Set step size in Alu
+
     fMaxStepAlu=p1;
 }
-
-//___________________________________________
+//__________________________________________________________________
 void AliMUON::SetMaxDestepGas(Float_t p1)
 {
-// Set maximum step size in Gas
+/// Set maximum step size in Gas
+
     fMaxDestepGas=p1;
 }
-
-//___________________________________________
+//__________________________________________________________________
 void AliMUON::SetMaxDestepAlu(Float_t p1)
 {
-// Set maximum step size in Alu
-    fMaxDestepAlu=p1;
+/// Set maximum step size in Alu
+
+  fMaxDestepAlu=p1;
 }
-//___________________________________________
-void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
+
+//____________________________________________________________________
+Float_t  AliMUON::GetMaxStepGas() const
+{
+/// Return stepsize in gas
+  
+  return fMaxStepGas;
+}  
+
+//____________________________________________________________________
+Float_t  AliMUON::GetMaxStepAlu() const
 {
-// Set acceptance cuts 
-   fAccCut=acc;
-   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
-   }
+/// Return step size in Alu
+  
+  return fMaxStepAlu;
 }
-//___________________________________________
-void   AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
+  
+//____________________________________________________________________
+Float_t  AliMUON::GetMaxDestepGas() const
 {
-// Set the segmentation for chamber id cathode isec
-  //PH    ((AliMUONChamber*) (*fChambers)[id])->SetSegmentationModel(isec, segmentation);
-    ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
-
+/// Return maximum step size in Gas
+  
+  return fMaxDestepGas;
 }
-//___________________________________________
-void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
+  
+//____________________________________________________________________
+Float_t  AliMUON::GetMaxDestepAlu() const
 {
-// Set the response for chamber id
-  //PH    ((AliMUONChamber*) (*fChambers)[id])->SetResponseModel(response);
-    ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
+/// Return maximum step size in Gas
+  
+  return fMaxDestepAlu;
 }
 
-void   AliMUON::SetReconstructionModel(Int_t id, AliMUONClusterFinderVS *reconst)
+//____________________________________________________________________
+ void  AliMUON::SetAlign(Bool_t align)
+{
+/// Set option for alignement to geometry builder
+   fGeometryBuilder->SetAlign(align);
+}   
+
+//____________________________________________________________________
+ void  AliMUON::SetAlign(const TString& fileName, Bool_t align)
+{
+/// Set option for alignement to geometry builder
+   fGeometryBuilder->SetAlign(fileName, align);
+}   
+
+//____________________________________________________________________
+void   AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
 {
-// Set ClusterFinder for chamber id
-  //PH    ((AliMUONChamber*) (*fChambers)[id])->SetReconstructionModel(reconst);
-    ((AliMUONChamber*) fChambers->At(id))->SetReconstructionModel(reconst);
+/// Set the response for chamber id
+    ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
 }
 
-void   AliMUON::SetNsec(Int_t id, Int_t nsec)
+//____________________________________________________________________
+AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
 {
-// Set number of segmented cathods for chamber id
-  //PH    ((AliMUONChamber*) (*fChambers)[id])->SetNsec(nsec);
-    ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
+/// Return digitizer
+  
+  return new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
 }
 
-//___________________________________________
+//_____________________________________________________________________
 void AliMUON::SDigits2Digits()
 {
+/// Write TreeD here only 
 
-// write TreeD here 
-
-    if (!fMerger) {
-      if (gAlice->GetDebug()>0) {
-       cerr<<"AliMUON::SDigits2Digits: create default AliMUONMerger "<<endl;
-       cerr<<" no merging, just digitization of 1 event will be done"<<endl;
-      }
-      fMerger = new AliMUONMerger();
-    }
-    fMerger->Init();
-    fMerger->Digitise();
     char hname[30];
     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
     fLoader->TreeD()->Reset();
 }
 
-//___________________________________________
-// To be removed
-void AliMUON::MakePadHits(Float_t xhit,Float_t yhit, Float_t zhit,
-                         Float_t eloss, Float_t tof,  Int_t idvol)
+//_____________________________________________________________________
+void AliMUON::Hits2SDigits()
 {
-//
-//  Calls the charge disintegration method of the current chamber and adds
-//  the simulated cluster to the root treee 
-//
-    Int_t clhits[7];
-    Float_t newclust[6][500];
-    Int_t nnew;
-    
-    
-//
-//  Integrated pulse height on chamber
+/// Perform Hits2Digits using SDigitizerV2
+  
+  AliMUONSDigitizerV2 sdigitizer;
+  sdigitizer.ExecuteTask();
+}
 
-    
-    clhits[0]=fNhits+1;
-//
-//
-//    if (idvol == 6) printf("\n ->Disintegration %f %f %f", xhit, yhit, eloss );
-    
+//_____________________________________________________________________
+void AliMUON::Digits2Raw()
+{
+/// Convert digits of the current event to raw data
 
-    //PH    ((AliMUONChamber*) (*fChambers)[idvol])
-    ((AliMUONChamber*) fChambers->At(idvol))
-       ->DisIntegration(eloss, tof, xhit, yhit, zhit, nnew, newclust);
-    Int_t ic=0;
-//    if (idvol == 6) printf("\n nnew  %d \n", nnew);
-//
-//  Add new clusters
-    for (Int_t i=0; i<nnew; i++) {
-       if (Int_t(newclust[3][i]) > 0) {
-           ic++;
-// Cathode plane
-           clhits[1] = Int_t(newclust[5][i]);
-//  Cluster Charge
-           clhits[2] = Int_t(newclust[0][i]);
-//  Pad: ix
-           clhits[3] = Int_t(newclust[1][i]);
-//  Pad: iy 
-           clhits[4] = Int_t(newclust[2][i]);
-//  Pad: charge
-           clhits[5] = Int_t(newclust[3][i]);
-//  Pad: chamber sector
-           clhits[6] = Int_t(newclust[4][i]);
-           
-           AddPadHit(clhits);
-       }
+  AliRawDataHeaderSim header;
+
+  if (!fRawWriter)
+  {
+    fRawWriter = new AliMUONRawWriter;
+    AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
+    if (fTriggerScalerEvent == kTRUE) 
+    {
+      fRawWriter->SetScalersNumbers();
     }
-}
+  }
+  
+  fLoader->LoadDigits("READ");
+  
+  TTree* treeD = fLoader->TreeD();
+  
+  if (!treeD)
+  {
+    AliError("Could not get TreeD");
+    return;
+  }
+  
+  AliMUONVTriggerStore*  triggerStore = AliMUONVTriggerStore::Create(*treeD);
+  AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
 
-//___________________________________________
-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);
-  Int_t i;
+  triggerStore->Connect(*treeD,kFALSE);
+  digitStore->Connect(*treeD,kFALSE);
+  
+  treeD->GetEvent(0);
   
-  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
-      }
+  fRawWriter->SetHeader(header);
+  if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
+  {
+    AliError("pb writting raw data");
   }
+  
+  delete triggerStore;
+  delete digitStore;
+  
+  fLoader->UnloadDigits();
+}
 
-  delete decision;
+//_____________________________________________________________________
+Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
+{
+/// Convert  raw data to SDigit
+/// Only for tracking for the moment (ChF) 
+
+  fLoader->LoadDigits("READ");
+  if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
 
-  fLoader->TreeR()->Fill();
-//  char hname[30];
-//  sprintf(hname,"TreeR%d",nev);
-//  fLoader->TreeR()->Write(hname,TObject::kOverwrite);
-//  fLoader->TreeR()->Reset();
-  fLoader->WriteRecPoints("OVERWRITE");
-  ResetTrigger();
+  TTree* treeS = fLoader->TreeS();
   
-  printf("\n End of trigger for event %d", nev);
-}
+  AliMUONVDigitStore* sDigitStore = new AliMUONDigitStoreV1;
+  sDigitStore->Connect(*treeS);
+  
+  fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
 
+  fLoader->WriteSDigits("OVERWRITE");
 
-//____________________________________________
-void AliMUON::Digits2Reco()
-{
-  FindClusters();
-  Int_t nev = gAlice->GetHeader()->GetEvent();
-  fLoader->TreeR()->Fill();
-  // char hname[30];
-  // sprintf(hname,"TreeR%d", nev);
-  //fLoader->TreeR()->Write(hname);
-  //fLoader->TreeR()->Reset();
-  fLoader->WriteRecPoints("OVERWRITE");
-  ResetRawClusters();        
-  printf("\n End of cluster finding for event %d", nev);
+  fLoader->UnloadSDigits();
+
+  delete sDigitStore;
+  
+  return kTRUE;
 }
 
-void AliMUON::FindClusters()
-{
-//
-//  Perform cluster finding
-//
-    TClonesArray *dig1, *dig2;
-    Int_t ndig, k;
-    dig1 = new TClonesArray("AliMUONDigit",1000);
-    dig2 = new TClonesArray("AliMUONDigit",1000);
-    AliMUONDigit *digit;
-// Loop on chambers and on cathode planes
-//
-    ResetRawClusters();        
-    TClonesArray * muonDigits;
-
-    for (Int_t ich = 0; ich < 10; ich++) {
-      //PH     AliMUONChamber* iChamber = (AliMUONChamber*) (*fChambers)[ich];
-       AliMUONChamber* iChamber = (AliMUONChamber*) fChambers->At(ich);
-       AliMUONClusterFinderVS* rec = iChamber->ReconstructionModel();
-    
-       ResetDigits();
-       fLoader->TreeD()->GetEvent(0);
-       //TClonesArray *
-       muonDigits = (TClonesArray *) Dchambers()->At(ich);
-       ndig=muonDigits->GetEntriesFast();
-       printf("\n 1 Found %d digits in %p chamber %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->Track(0)))
-               new(lhits1[n++]) AliMUONDigit(*digit);
-       }
-       ResetDigits();
-       fLoader->TreeD()->GetEvent(1);
-       //muonDigits  = this->DigitsAddress(ich);
-       muonDigits = (TClonesArray *) Dchambers()->At(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->Track(0)))
-           new(lhits2[n++]) AliMUONDigit(*digit);
-       }
+//_______________________________________________________________________
+AliLoader* AliMUON::MakeLoader(const char* topfoldername)
+{ 
+/// Build standard getter (AliLoader type);
+/// if detector wants to use castomized getter, it must overload this method
+ AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
+         GetName(),topfoldername));
+ fLoader   = new AliLoader(GetName(),topfoldername);
 
-       if (rec) {       
-           AliMUONClusterInput::Instance()->SetDigits(ich, dig1, dig2);
-           rec->FindRawClusters();
-       }
-       dig1->Delete();
-       dig2->Delete();
-    } // for ich
-    delete dig1;
-    delete dig2;
+ return fLoader;
 }
-#ifdef never
-void AliMUON::Streamer(TBuffer &R__b)
+
+//________________________________________________________________________
+void
+AliMUON::ResetGeometryBuilder()
 {
-   // Stream an object of class AliMUON.
-      AliMUONChamber        *iChamber;
-      AliMUONTriggerCircuit *iTriggerCircuit;
-      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);
-         }
-// 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, 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);
-         }
-         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);
-             }
-         }
-      }
+/// Only to be used by "experts" wanting to change the geometry builders
+/// to be used. 
+/// As the ctor of AliMUON now defines a default geometrybuilder, this
+/// ResetGeometryBuilder() must be called prior to call the 
+/// AddGeometryBuilder()
+
+  delete fGeometryBuilder;
+  fGeometryBuilder = new AliMUONGeometryBuilder(this);
+  fGeometryBuilder
+    ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
 }
-#endif
 
-AliMUONPadHit* AliMUON::FirstPad(AliMUONHit*  hit, TClonesArray *clusters) 
+//____________________________________________________________________
+Bool_t  AliMUON::GetTriggerResponseV1() const
 {
-// to be removed
-    // Initialise the pad iterator
-    // Return the address of the first padhit for hit
-    TClonesArray *theClusters = clusters;
-    Int_t nclust = theClusters->GetEntriesFast();
-    if (nclust && hit->PHlast() > 0) {
-       AliMUON::fMaxIterPad=hit->PHlast();
-       AliMUON::fCurIterPad=hit->PHfirst();
-       return (AliMUONPadHit*) clusters->UncheckedAt(AliMUON::fCurIterPad-1);
-    } else {
-       return 0;
-    }
-}
+///
+/// Returns fTriggerResponseV1
+///  
+    return fTriggerResponseV1;
+    
+}  
 
-AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters) 
+//____________________________________________________________________
+Int_t  AliMUON::GetTriggerCoinc44() const
 {
-  // To be removed
-// Get next pad (in iterator) 
-//
-    AliMUON::fCurIterPad++;
-    if (AliMUON::fCurIterPad <= AliMUON::fMaxIterPad) {
-       return (AliMUONPadHit*) clusters->UncheckedAt(AliMUON::fCurIterPad-1);
-    } else {
-       return 0;
-    }
+///
+/// Returns fTriggerCoinc44
+///  
+    return fTriggerCoinc44;
+    
 }
 
+//____________________________________________________________________
+Bool_t  AliMUON::GetTriggerEffCells() const
+{
+///
+/// Returns fTriggerEffCells
+///  
+    return fTriggerEffCells;
+    
+}  
 
-AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
+//____________________________________________________________________
+Int_t  AliMUON::GetDigitizerWithNoise() const
 {
-//
-//  Return rawcluster (icluster) for chamber ichamber and cathode icathod
-//  Obsolete ??
-    TClonesArray *muonRawCluster  = RawClustAddress(ichamber);
-    ResetRawClusters();
-    TTree *treeR = fLoader->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*)muonRawCluster->UncheckedAt(icluster);
-    //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
+///
+/// Returns fDigitizerWithNoise
+///  
+    return fDigitizerWithNoise;
     
-    return  mRaw;
-}
-void   AliMUON::SetMerger(AliMUONMerger* merger)
+}  
+
+//____________________________________________________________________
+Bool_t AliMUON::UsingFastTrackerDecoder() const
 {
-// Set pointer to merger 
-    fMerger = merger;
+/// Checks to see if we are using the fast decoder for tracker DDL streams.
+
+  if ( ! fDigitMaker ) {
+    AliError("Digit maker is not instantiated.");
+    return kFALSE;
+  }
+  
+  return fDigitMaker->UsingFastTrackerDecoder();
 }
 
-AliMUONMerger*  AliMUON::Merger()
+//____________________________________________________________________
+Bool_t AliMUON::UsingFastTriggerDecoder() const
 {
-// Return pointer to merger
-    return fMerger;
+/// Checks to see if we are using the fast decoder for trigger DDL streams.
+
+  if ( ! fDigitMaker ) {
+    AliError("Digit maker is not instantiated.");
+    return kFALSE;
+  }
+  
+  return fDigitMaker->UsingFastTriggerDecoder();
 }
 
+//____________________________________________________________________
+void AliMUON::SetFastTrackerDecoder(Bool_t useFastDecoder)
+{
+/// Set fast raw data decoder 
 
+  if ( ! fDigitMaker ) {
+    AliError("Digit maker is not instantiated.");
+    return;
+  }
 
-AliMUON& AliMUON::operator = (const AliMUON& /*rhs*/)
-{
-// copy operator
-// dummy version
-    return *this;
+  fDigitMaker->SetFastTrackerDecoder(useFastDecoder);
 }
 
-////////////////////////////////////////////////////////////////////////
-void AliMUON::MakeBranchInTreeD(TTree *treeD, const char *file)
+//____________________________________________________________________
+void AliMUON::SetFastTriggerDecoder(Bool_t useFastDecoder)
 {
-    //
-    // Create TreeD branches for the MUON.
-    //
+/// Set fast raw data decoder 
 
-  const Int_t kBufferSize = 4000;
-  char branchname[30];
-    
-  if (fDchambers  == 0x0)   {
-    fDchambers = new TObjArray(AliMUONConstants::NCh());
-    for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
-      fDchambers->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
-    }
-  }
-  //
-  // one branch for digits per chamber
-  // 
-  for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
-    sprintf(branchname,"%sDigits%d",GetName(),i+1);    
-    if (fDchambers && treeD) {
-      MakeBranchInTree(treeD, 
-                      branchname, &((*fDchambers)[i]), kBufferSize, file);
-//      printf("Making Branch %s for digits in chamber %d\n",branchname,i+1);
-    }
+  if ( ! fDigitMaker ) {
+    AliError("Digit maker is not instantiated.");
+    return;
   }
-}
 
-//___________________________________________
+  fDigitMaker->SetFastTriggerDecoder(useFastDecoder);
+}