]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONv1.cxx
Minor fixes in the event tag to take into account the new way of storing the trigger...
[u/mrichter/AliRoot.git] / MUON / AliMUONv1.cxx
index 2d87e0ac81faedb6c558db324bdfdce305835e67..1b06b1811b4805c13ca46446f5ed9634ae370f2b 100644 (file)
 
 /* $Id$ */
 
-/////////////////////////////////////////////////////////
-//  Manager and hits classes for set:MUON version 1    //
-/////////////////////////////////////////////////////////
-
-#include <TRandom.h>
-#include <TF1.h>
-#include <TClonesArray.h>
-#include <TRandom.h> 
-#include <TVirtualMC.h>
-#include <TGeoMatrix.h>
+// --------------------
+// Class AliMUONv1
+// --------------------
+// AliDetector class for MUON subsystem which implements
+// functions for simulation 
 
 #include "AliMUONv1.h"
-#include "AliConst.h" 
-#include "AliMUONChamber.h"
 #include "AliMUONConstants.h"
-#include "AliMUONFactoryV2.h"
+#include "AliMUONSegFactory.h"
+#include "AliMUONResponseFactory.h"
+#include "AliMUONSegmentation.h"
 #include "AliMUONHit.h"
 #include "AliMUONTriggerCircuit.h"
 #include "AliMUONGeometryBuilder.h"    
+#include "AliMUONGeometry.h"   
+#include "AliMUONGeometryTransformer.h"        
 #include "AliMUONGeometryModule.h"     
-#include "AliMUONGeometrySVMap.h"      
+#include "AliMUONStringIntMap.h"       
 #include "AliMUONGeometryDetElement.h" 
+
+#include "AliConst.h" 
 #include "AliMagF.h"
 #include "AliRun.h"
 #include "AliMC.h"
 #include "AliLog.h"
 
+#include <TRandom.h>
+#include <TF1.h>
+#include <TClonesArray.h>
+#include <TRandom.h> 
+#include <TVirtualMC.h>
+#include <TGeoMatrix.h>
+
+#include <string>
+
 ClassImp(AliMUONv1)
  
 //___________________________________________
 AliMUONv1::AliMUONv1() 
   : AliMUON(),
-    fStepManagerVersionOld(kFALSE),
-    fStepManagerVersionDE(kFALSE),
+    fStepManagerVersionOld(kTRUE),
+    fStepManagerVersionDE(kTRUE),
     fAngleEffect(kTRUE),
     fStepMaxInActiveGas(0.6),
     fStepSum(0x0),
@@ -59,14 +67,18 @@ AliMUONv1::AliMUONv1()
     fAngleEffect10(0x0),
     fAngleEffectNorma(0x0)
 {
-// Default constructor
+/// Default constructor
+  
+  AliDebug(1,Form("default (empty) ctor this=%p",this));
 } 
 
 //___________________________________________
-AliMUONv1::AliMUONv1(const char *name, const char *title)
-  : AliMUON(name,title), 
-    fStepManagerVersionOld(kFALSE),
-    fStepManagerVersionDE(kFALSE),
+AliMUONv1::AliMUONv1(const char *name, const char *title,
+                     const char* sDigitizerClassName,
+                     const char* digitizerClassName)
+: AliMUON(name,title,sDigitizerClassName,digitizerClassName), 
+    fStepManagerVersionOld(kTRUE),
+    fStepManagerVersionDE(kTRUE),
     fAngleEffect(kTRUE),
     fStepMaxInActiveGas(0.6),
     fStepSum(0x0),
@@ -77,8 +89,10 @@ AliMUONv1::AliMUONv1(const char *name, const char *title)
     fAngleEffect10(0x0),
     fAngleEffectNorma(0x0)
 {
-// Standard onstructor
+/// Standard onstructor
 
+    AliDebug(1,Form("ctor this=%p",this));     
+       
     // By default include all stations
 
     fStepSum   = new Float_t [AliMUONConstants::NCh()];
@@ -113,7 +127,7 @@ AliMUONv1::AliMUONv1(const char *name, const char *title)
 AliMUONv1::AliMUONv1(const AliMUONv1& right) 
   : AliMUON(right) 
 {  
-  // copy constructor (not implemented)
+/// Copy constructor (not implemented)
 
   AliFatal("Copy constructor not provided.");
 }
@@ -121,19 +135,20 @@ AliMUONv1::AliMUONv1(const AliMUONv1& right)
 //___________________________________________
 AliMUONv1::~AliMUONv1()
 {
-// Destructor
-
+/// Destructor
+  
+  AliDebug(1,Form("dtor this=%p",this));
   delete [] fStepSum;
   delete [] fDestepSum;
   delete fElossRatio;
   delete fAngleEffect10;
-  delete fAngleEffectNorma;  
+  delete fAngleEffectNorma; 
 }
 
 //_____________________________________________________________________________
 AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
 {
-  // assignement operator (not implemented)
+/// Assignement operator (not implemented)
 
   // check assignement to self
   if (this == &right) return *this;
@@ -146,9 +161,7 @@ AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
 //__________________________________________________
 void AliMUONv1::CreateGeometry()
 {
-//
-// Construct geometry using geometry builder
-//
+/// Construct geometry using geometry builder
 
   fGeometryBuilder->CreateGeometry();
 }
@@ -156,9 +169,7 @@ void AliMUONv1::CreateGeometry()
 //________________________________________________________________
 void AliMUONv1::CreateMaterials()
 {
-//
-// Construct materials using geometry builder
-//
+/// Construct materials using geometry builder
 
   fGeometryBuilder->CreateMaterials();
 }
@@ -166,74 +177,57 @@ void AliMUONv1::CreateMaterials()
 //___________________________________________
 void AliMUONv1::Init()
 { 
-   AliDebug(1,"Start Init for version 1 - CPC chamber type");
-   Int_t i;
+/// Initialize geometry
 
+  AliDebug(1,"Start Init for version 1 - CPC chamber type");
+   
+  fGeometryBuilder->InitGeometry();
+  AliDebug(1,"Finished Init for version 1 - CPC chamber type");   
  
+
+  std::string ftype(GetTitle());
+
+  // Build segmentation
+  // using geometry parametrisation
   //
-   // Initialize geometry
-   //
-   fGeometryBuilder->InitGeometry();
-   AliDebug(1,"Finished Init for version 1 - CPC chamber type");   
-
-   AliMUONFactory* factory = 0x0;
-
-   if (fSegmentationType == 1) {
-     factory = new AliMUONFactory();
-     printf("\n Old Segmentation \n");
-   }
-
-   if (fSegmentationType == 2) {
-     factory = new AliMUONFactoryV2();
-     printf("\n New Segmentation \n");
-   } 
-
-   factory->Build(this, "default");
-
-   //
-   // Initialize segmentation
-   //
-   if (!fSegmentationType) {
-     AliFatal("No Segmentation Type defined.");
-     return;
-   }
-
-   if (fSegmentationType == 1) {
-   for (i=0; i<AliMUONConstants::NCh(); i++) 
-       ( (AliMUONChamber*) (*fChambers)[i])->Init();
-   }
-
-   if (fSegmentationType == 2) {
-     for (i=0; i<AliMUONConstants::NCh(); i++) 
-       ( (AliMUONChamber*) (*fChambers)[i])->Init(fSegmentationType);// new segmentation
-   }
-   if (fSegmentationType == 1) {
-    //cp 
-     AliDebug(1,"Start Init for Trigger Circuits");
-     for (i=0; i<AliMUONConstants::NTriggerCircuit(); i++) 
-       ( (AliMUONTriggerCircuit*) (*fTriggerCircuits)[i])->Init(i);
-     AliDebug(1,"Finished Init for Trigger Circuits");
-   } 
+  AliMUONSegFactory segFactory(GetGeometryTransformer());
+  fSegmentation = segFactory.CreateSegmentation(ftype);
 
+  if (!fSegmentation) {
+    AliFatal(Form("Wrong factory type : %s",ftype.c_str()));
+  }        
 
+  // Build response
+  //
+  AliMUONResponseFactory respFactory("default");
+  respFactory.Build(this);
+  
 
+  // Initialize segmentation
+  //
+  fSegmentation->Init();
+
+  // Initialize trigger circuits
+  //
+  for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++)  {
+    AliMUONTriggerCircuit* c = (AliMUONTriggerCircuit*)(fTriggerCircuits->At(i));
+    c->Init(i);
+//    c->Print();
+  }
+  
 }
 
 //__________________________________________________________________
 Int_t  AliMUONv1::GetChamberId(Int_t volId) const
 {
-// Check if the volume with specified  volId is a sensitive volume (gas) 
-// of some chamber and returns the chamber number;
-// if not sensitive volume - return 0.
-// ---
-
-/*
-  for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
-    if (volId==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()) return i;
-*/
-  for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
-    if ( ((AliMUONChamber*)(*fChambers)[i-1])->IsSensId(volId) ) return i;
+/// Check if the volume with specified  volId is a sensitive volume (gas) 
+/// of some chamber and returns the chamber number;
+/// if not sensitive volume - return 0.
+
+  for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
+    if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
+      return i+1;
+  }    
 
   return 0;
 }
@@ -241,9 +235,8 @@ Int_t  AliMUONv1::GetChamberId(Int_t volId) const
 //_______________________________________________________________________________
 TString  AliMUONv1::CurrentVolumePath() const
 {
-// Returns current volume path
-// (Could be removed when this function is available via gMC)
-// ---      
+/// Return current volume path
+/// (Could be removed when this function is available via gMC)
 
   TString path = "";
   TString name;
@@ -254,7 +247,7 @@ TString  AliMUONv1::CurrentVolumePath() const
     gMC->CurrentVolOffID(imother++, copyNo);
     TString add = "/";
     add += name;
-    add += ".";
+    add += "_";
     add += copyNo;
     path.Insert(0,add); 
   }
@@ -266,18 +259,14 @@ TString  AliMUONv1::CurrentVolumePath() const
 //_______________________________________________________________________________
 void AliMUONv1::StepManager()
 {
-  // Stepmanager for the chambers
-  // TBR
+/// Step manager for the chambers
+/// TBR
 
  if (fStepManagerVersionDE) {
     StepManager2();
     return;
   }
 
- if (fStepManagerVersionOld) {
-    StepManagerOld();
-    return;
-  }
 
   // Only charged tracks
   if( !(gMC->TrackCharge()) ) return; 
@@ -310,11 +299,10 @@ void AliMUONv1::StepManager()
      if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
   }
 
-//  if (GetDebug()) {
-//     Float_t z = ( (AliMUONChamber*)(*fChambers)[idvol])->Z() ;
-//      Info("StepManager Step","Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber, z);
-//   }  
-  // Particule id and mass, 
+   //  AliDebug(1,
+   //    Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
+   //    ( (AliMUONChamber*)(*fChambers)[idvol])->Z()));
+   // Particule id and mass, 
   Int_t     ipart = gMC->TrackPid();
   Float_t   mass  = gMC->TrackMass();
 
@@ -323,12 +311,19 @@ void AliMUONv1::StepManager()
   if ( fStepSum[idvol]==0.0 )  gMC->TrackMomentum(fTrackMomentum);
   fStepSum[idvol]+=gMC->TrackStep();
   
-//   if (GetDebug()) {
-//     Info("StepManager Step","iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
-//       iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg, mass, fStepSum[idvol], gMC->Edep());//     Info("StepManager Step","Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), fTrackMomentum.Z()) ;
-//     gMC->TrackPosition(fTrackPosition);
-//     Info("StepManager Step","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
-//   }
+  //  if(AliDebugLevel()) {
+  //  AliDebug(1,
+  //        Form("iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
+  //             iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg, 
+  //             mass, fStepSum[idvol], gMC->Edep()));
+  //  AliDebug(1,
+  //        Form("Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), 
+  //             fTrackMomentum.Z()));
+  //  gMC->TrackPosition(fTrackPosition);
+  //  AliDebug(1,
+  //        Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),
+  //     fTrackPosition.Z())) ;
+  //   }
 
   // Track left chamber or StepSum larger than fStepMaxInActiveGas
   if ( gMC->IsTrackExiting() || 
@@ -347,10 +342,10 @@ void AliMUONv1::StepManager()
     TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
                                fStepSum[idvol]/2.*sin(theta)*sin(phi),
                                fStepSum[idvol]/2.*cos(theta),0.0       );
-    //     if (GetDebug()) 
-    //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
-    //     if (GetDebug()) 
-    //        Info("StepManager Exit ","Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z()) ;
+    //     AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),
+    //                     fTrackPosition.Y(),fTrackPosition.Z())) ;
+    //     AliDebug(1,Form("Exit: Track backToWire %f %f %f",backToWire.X(),
+    //                     backToWire.Y(),backToWire.Z()) ;
     fTrackPosition-=backToWire;
     
     //-------------- Angle effect 
@@ -379,11 +374,11 @@ void AliMUONv1::StepManager()
     }
     
     // Detection elements ids
-    AliMUONGeometryModule* geometry
-      = Chamber(iChamber-1).GetGeometry();
+    const AliMUONGeometryModule* kGeometryModule
+      = GetGeometry()->GetModule(iChamber-1);
 
     AliMUONGeometryDetElement* detElement
-      = geometry->FindBySensitiveVolume(CurrentVolumePath());
+      = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
 
     Int_t detElemId = 0;
     if (detElement) detElemId = detElement->GetUniqueID(); 
@@ -421,10 +416,10 @@ void AliMUONv1::StepManager()
                          fTrackPosition.Y(),
                          fTrackPosition.Z());
 
-//     if (GetDebug()){
-//       Info("StepManager Exit","Particle exiting from chamber %d",iChamber);
-//       Info("StepManager Exit","StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]);
-//       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
+//     if (AliDebugLevel()){
+//       AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
+//       AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
+//       AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z())) ;
 //     }
     fStepSum[idvol]  =0; // Reset for the next event
     fDestepSum[idvol]=0; // Reset for the next event
@@ -434,12 +429,7 @@ void AliMUONv1::StepManager()
 //_______________________________________________________________________________
 void AliMUONv1::StepManager2()
 {
-  // Stepmanager for the chambers
-
- if (fStepManagerVersionOld) {
-    StepManagerOld2();
-    return;
-  }
+/// Step manager for the chambers
 
   // Only charged tracks
   if( !(gMC->TrackCharge()) ) return; 
@@ -447,12 +437,12 @@ void AliMUONv1::StepManager2()
   
   // Only gas gap inside chamber
   // Tag chambers and record hits when track enters 
-  static Int_t   idvol=-1;
+  static Int_t   idvol=-1, iEnter = 0;
   Int_t   iChamber=0;
   Int_t   id=0;
   Int_t   copy;
   const  Float_t kBig = 1.e10;
-
+  static Double_t xyzEnter[3];
 
   //
   // Only gas gap inside chamber
@@ -470,12 +460,13 @@ void AliMUONv1::StepManager2()
    if( gMC->IsTrackEntering() ) {
      Float_t theta = fTrackMomentum.Theta();
      if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
+     iEnter = 1;
+     gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
   }
 
-//  if (GetDebug()) {
-//     Float_t z = ( (AliMUONChamber*)(*fChambers)[idvol])->Z() ;
-//      Info("StepManager Step","Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber, z);
-//   }  
+   //   AliDebug(1,
+   //      Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
+   //           ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
   // Particule id and mass, 
   Int_t     ipart = gMC->TrackPid();
   Float_t   mass  = gMC->TrackMass();
@@ -485,12 +476,16 @@ void AliMUONv1::StepManager2()
   if ( fStepSum[idvol]==0.0 )  gMC->TrackMomentum(fTrackMomentum);
   fStepSum[idvol]+=gMC->TrackStep();
   
-//   if (GetDebug()) {
-//     Info("StepManager Step","iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
-//       iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg, mass, fStepSum[idvol], gMC->Edep());//     Info("StepManager Step","Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), fTrackMomentum.Z()) ;
-//     gMC->TrackPosition(fTrackPosition);
-//     Info("StepManager Step","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
-//   }
+  //  if (AliDebugLevel()) {
+  //   AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
+  //                iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
+  //        mass, fStepSum[idvol], gMC->Edep()));
+  // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), 
+  //        fTrackMomentum.Z()));
+  // gMC->TrackPosition(fTrackPosition);
+  // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
+  //        fTrackPosition.Y(),fTrackPosition.Z())) ;
+  //}
 
   // Track left chamber or StepSum larger than fStepMaxInActiveGas
   if ( gMC->IsTrackExiting() || 
@@ -501,19 +496,56 @@ void AliMUONv1::StepManager2()
     if   ( gMC->IsTrackExiting() || 
            gMC->IsTrackStop() || 
            gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
+    if (fDestepSum[idvol] == 0) {
+      // AZ - no energy release
+      fStepSum[idvol] = 0; // Reset for the next event
+      iEnter = 0;
+      return; 
+    }
 
     gMC->TrackPosition(fTrackPosition);
     Float_t theta = fTrackMomentum.Theta();
     Float_t phi   = fTrackMomentum.Phi();
     
-    TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
-                               fStepSum[idvol]/2.*sin(theta)*sin(phi),
-                               fStepSum[idvol]/2.*cos(theta),0.0       );
-    //     if (GetDebug()) 
-    //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
-    //     if (GetDebug()) 
-    //        Info("StepManager Exit ","Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z()) ;
-    fTrackPosition-=backToWire;
+    Int_t merge = 0;
+    Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
+    if (gMC->IsTrackExiting() && iEnter != 0) {
+      // AZ - this code is to avoid artificial hit splitting at the
+      // "fake" boundary inside the same chamber. It will still produce 
+      // 2 hits but with the same coordinates (at the wire) to allow 
+      // their merging at the digitization level.
+
+      // Only for a track going from the entrance to the exit from the volume
+      // Get local coordinates
+      gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
+
+      fTrackPosition.Vect().GetXYZ(tmp);
+      gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
+      Float_t dx = xyz0[0] - xyz1[0];
+      Float_t dy = xyz0[1] - xyz1[1];
+      Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
+      if (thLoc * TMath::RadToDeg() < 15) merge = 1; 
+    }
+
+    if (merge) {
+      Double_t dz = -0.5;
+      if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
+      tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
+      tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
+      tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
+      gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
+      fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
+    } else {
+      TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
+                                fStepSum[idvol]/2.*sin(theta)*sin(phi),
+                                fStepSum[idvol]/2.*cos(theta),0.0       );
+      fTrackPosition-=backToWire;
+      //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
+      //    AliDebug(1,
+      //     Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
+      // AliDebug(1,
+      //     Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
+    }
     
     //-------------- Angle effect 
     // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
@@ -541,11 +573,11 @@ void AliMUONv1::StepManager2()
     }
     
     // Detection elements ids
-    AliMUONGeometryModule* geometry
-      = Chamber(iChamber-1).GetGeometry();
+    const AliMUONGeometryModule* kGeometryModule
+      = GetGeometry()->GetModule(iChamber-1);
 
     AliMUONGeometryDetElement* detElement
-      = geometry->FindBySensitiveVolume(CurrentVolumePath());
+      = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
 
     Int_t detElemId = 0;
     if (detElement) detElemId = detElement->GetUniqueID(); 
@@ -583,408 +615,12 @@ void AliMUONv1::StepManager2()
                          fTrackPosition.Y(),
                          fTrackPosition.Z());
 
-//     if (GetDebug()){
-//       Info("StepManager Exit","Particle exiting from chamber %d",iChamber);
-//       Info("StepManager Exit","StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]);
-//       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
-//     }
+    //       AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
+    //       AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
+    //       AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
+
     fStepSum[idvol]  =0; // Reset for the next event
     fDestepSum[idvol]=0; // Reset for the next event
-  }
-}
-
-//__________________________________________
-void AliMUONv1::StepManagerOld()
-{
-  // Old Stepmanager for the chambers
-  // TBR
-  
-  Int_t          copy, id;
-  static Int_t   idvol =-1;
-  static Int_t   vol[2];
-  Int_t          ipart;
-  TLorentzVector pos;
-  TLorentzVector mom;
-  Float_t        theta,phi;
-  Float_t        destep, step;
-  
-  static Float_t sstep;
-  static Float_t eloss, eloss2, xhit, yhit, zhit, tof, tlength;
-  const  Float_t kBig = 1.e10;
-  static Float_t hits[15];
-
-  TClonesArray &lhits = *fHits;
-
-  //
-  //
-  // Only charged tracks
-  if( !(gMC->TrackCharge()) ) return; 
-  //
-  // Only gas gap inside chamber
-  // Tag chambers and record hits when track enters 
-  id=gMC->CurrentVolID(copy);
-  vol[0] = GetChamberId(id);
-  idvol = vol[0] -1;
-
-  if (idvol == -1) return;
-
-  //
-  // Get current particle id (ipart), track position (pos)  and momentum (mom) 
-  gMC->TrackPosition(pos);
-  gMC->TrackMomentum(mom);
-
-  ipart  = gMC->TrackPid();
-
-  //
-  // momentum loss and steplength in last step
-  destep = gMC->Edep();
-  step   = gMC->TrackStep();
-  // cout<<"------------"<<step<<endl;
-  //
-  // record hits when track enters ...
-  if( gMC->IsTrackEntering()) {
-
-      gMC->SetMaxStep(fMaxStepGas);
-      Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
-      Double_t rt = TMath::Sqrt(tc);
-      Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
-      Double_t tx = mom[0]/pmom;
-      Double_t ty = mom[1]/pmom;
-      Double_t tz = mom[2]/pmom;
-      Double_t s  = ((AliMUONChamber*)(*fChambers)[idvol])
-          ->ResponseModel()
-          ->Pitch()/tz;
-      theta   = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
-      phi     = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
-      hits[0] = Float_t(ipart);         // Geant3 particle type
-      hits[1] = pos[0]+s*tx;            // X-position for hit
-      hits[2] = pos[1]+s*ty;            // Y-position for hit
-      hits[3] = pos[2]+s*tz;            // Z-position for hit
-      hits[4] = theta;                  // theta angle of incidence
-      hits[5] = phi;                    // phi angle of incidence 
-      hits[8] = 0;//PadHits does not exist anymore  (Float_t) fNPadHits;    // first padhit
-      hits[9] = -1;                     // last pad hit
-      hits[10] = mom[3];                // hit momentum P
-      hits[11] = mom[0];                // Px
-      hits[12] = mom[1];                // Py
-      hits[13] = mom[2];                // Pz
-      tof=gMC->TrackTime();
-      hits[14] = tof;                   // Time of flight
-      tlength  = 0;
-      eloss    = 0;
-      eloss2   = 0;
-      sstep=0;
-      xhit     = pos[0];
-      yhit     = pos[1];      
-      zhit     = pos[2];      
-      Chamber(idvol).ChargeCorrelationInit();
-      // Only if not trigger chamber
-
-//       printf("---------------------------\n");
-//       printf(">>>> Y =  %f \n",hits[2]);
-//       printf("---------------------------\n");
-    
-      
-
-     //  if(idvol < AliMUONConstants::NTrackingCh()) {
-//        //
-//        //  Initialize hit position (cursor) in the segmentation model 
-//        ((AliMUONChamber*) (*fChambers)[idvol])
-//            ->SigGenInit(pos[0], pos[1], pos[2]);
-//       } else {
-//        //geant3->Gpcxyz();
-//        //printf("In the Trigger Chamber #%d\n",idvol-9);
-//       }
-  }
-  eloss2+=destep;
-  sstep+=step;
-
-  // cout<<sstep<<endl;
-
-  // 
-  // Calculate the charge induced on a pad (disintegration) in case 
-  //
-  // Mip left chamber ...
-  if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
-      gMC->SetMaxStep(kBig);
-      eloss   += destep;
-      tlength += step;
-      
-      Float_t x0,y0,z0;
-      Float_t localPos[3];
-      Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
-      gMC->Gmtod(globalPos,localPos,1); 
-
-      if(idvol < AliMUONConstants::NTrackingCh()) {
-// tracking chambers
-          x0 = 0.5*(xhit+pos[0]);
-          y0 = 0.5*(yhit+pos[1]);
-          z0 = 0.5*(zhit+pos[2]);
-      } else {
-// trigger chambers
-          x0 = xhit;
-          y0 = yhit;
-          z0 = 0.;
-      }
-      
-
-      //      if (eloss >0)  MakePadHits(x0,y0,z0,eloss,tof,idvol);
-      
-          
-      hits[6] = tlength;   // track length
-      hits[7] = eloss2;    // de/dx energy loss
-
-
-      //      if (fNPadHits > (Int_t)hits[8]) {
-      //          hits[8] = hits[8]+1;
-      //          hits[9] = 0: // PadHits does not exist anymore (Float_t) fNPadHits;
-      //}
-//
-//    new hit 
-      
-      new(lhits[fNhits++]) 
-       AliMUONHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits, kTRUE);
-      eloss = 0; 
-      //
-      // Check additional signal generation conditions 
-      // defined by the segmentation
-      // model (boundary crossing conditions)
-      // only for tracking chambers
-  } else if 
-      ((idvol < AliMUONConstants::NTrackingCh()) &&
-       ((AliMUONChamber*) (*fChambers)[idvol])->SigGenCond(pos[0], pos[1], pos[2]))
-  {
-      ((AliMUONChamber*) (*fChambers)[idvol])
-          ->SigGenInit(pos[0], pos[1], pos[2]);
-      
-      Float_t localPos[3];
-      Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
-      gMC->Gmtod(globalPos,localPos,1); 
-
-      eloss    += destep;
-
-      // if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
-      //        MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
-      xhit     = pos[0];
-      yhit     = pos[1]; 
-      zhit     = pos[2];
-      eloss = 0;
-      tlength += step ;
-      //
-      // nothing special  happened, add up energy loss
-  } else {        
-      eloss   += destep;
-      tlength += step ;
-  }
-}
-
-//__________________________________________
-void AliMUONv1::StepManagerOld2()
-{
-  // Old Stepmanager for the chambers
-  Int_t          copy, id;
-  static Int_t   idvol =-1;
-  static Int_t   vol[2];
-  Int_t          ipart;
-  TLorentzVector pos;
-  TLorentzVector mom;
-  Float_t        theta,phi;
-  Float_t        destep, step;
-  
-  static Float_t sstep;
-  static Float_t eloss, eloss2, xhit, yhit, zhit, tof, tlength;
-  const  Float_t kBig = 1.e10;
-  static Float_t hits[15];
-
-  TClonesArray &lhits = *fHits;
-
-  //
-  //
-  // Only charged tracks
-  if( !(gMC->TrackCharge()) ) return; 
-  //
-  // Only gas gap inside chamber
-  // Tag chambers and record hits when track enters 
-  id=gMC->CurrentVolID(copy);
-
-  Int_t iChamber = GetChamberId(id);
-  idvol =  iChamber-1;
-
-  if (idvol == -1) return;
-
-  // Detection elements id
-  AliMUONGeometryModule* geometry
-    = Chamber(iChamber-1).GetGeometry();
-
-  AliMUONGeometryDetElement* detElement
-    = geometry->FindBySensitiveVolume(CurrentVolumePath());
-
-  Int_t detElemId = 0;
-  if (detElement) detElemId = detElement->GetUniqueID(); 
-  if (!detElemId) {
-    cerr << "Chamber id: "
-         << setw(3) << iChamber << "  "
-         << "Current SV: " 
-         <<  CurrentVolumePath() 
-        << "  detElemId: "
-         << setw(5) << detElemId 
-        << endl;
-    Double_t x, y, z;
-    gMC->TrackPosition(x, y, z);          
-    cerr << "   global position: "
-         << x << ", " << y << ", " << z
-         << endl;
-    AliError("DetElemId not identified.");
-  }  
-  vol[0] = detElemId;
-    
-  //
-  // Get current particle id (ipart), track position (pos)  and momentum (mom) 
-  gMC->TrackPosition(pos);
-  gMC->TrackMomentum(mom);
-
-  ipart  = gMC->TrackPid();
-
-  //
-  // momentum loss and steplength in last step
-  destep = gMC->Edep();
-  step   = gMC->TrackStep();
-  // cout<<"------------"<<step<<endl;
-  //
-  // record hits when track enters ...
-  if( gMC->IsTrackEntering()) {
-
-      gMC->SetMaxStep(fMaxStepGas);
-      Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
-      Double_t rt = TMath::Sqrt(tc);
-      Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
-      Double_t tx = mom[0]/pmom;
-      Double_t ty = mom[1]/pmom;
-      Double_t tz = mom[2]/pmom;
-      Double_t s  = ((AliMUONChamber*)(*fChambers)[idvol])
-          ->ResponseModel()
-          ->Pitch()/tz;
-      theta   = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
-      phi     = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
-      hits[0] = Float_t(ipart);         // Geant3 particle type
-      hits[1] = pos[0]+s*tx;            // X-position for hit
-      hits[2] = pos[1]+s*ty;            // Y-position for hit
-      hits[3] = pos[2]+s*tz;            // Z-position for hit
-      hits[4] = theta;                  // theta angle of incidence
-      hits[5] = phi;                    // phi angle of incidence 
-      hits[8] = 0;//PadHits does not exist anymore  (Float_t) fNPadHits;    // first padhit
-      hits[9] = -1;                     // last pad hit
-      hits[10] = mom[3];                // hit momentum P
-      hits[11] = mom[0];                // Px
-      hits[12] = mom[1];                // Py
-      hits[13] = mom[2];                // Pz
-      tof=gMC->TrackTime();
-      hits[14] = tof;                   // Time of flight
-      tlength  = 0;
-      eloss    = 0;
-      eloss2   = 0;
-      sstep=0;
-      xhit     = pos[0];
-      yhit     = pos[1];      
-      zhit     = pos[2];      
-      Chamber(idvol).ChargeCorrelationInit();
-      // Only if not trigger chamber
-
-//       printf("---------------------------\n");
-//       printf(">>>> Y =  %f \n",hits[2]);
-//       printf("---------------------------\n");
-    
-      
-
-     //  if(idvol < AliMUONConstants::NTrackingCh()) {
-//        //
-//        //  Initialize hit position (cursor) in the segmentation model 
-//        ((AliMUONChamber*) (*fChambers)[idvol])
-//            ->SigGenInit(pos[0], pos[1], pos[2]);
-//       } else {
-//        //geant3->Gpcxyz();
-//        //printf("In the Trigger Chamber #%d\n",idvol-9);
-//       }
-  }
-  eloss2+=destep;
-  sstep+=step;
-
-  // cout<<sstep<<endl;
-
-  // 
-  // Calculate the charge induced on a pad (disintegration) in case 
-  //
-  // Mip left chamber ...
-  if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
-      gMC->SetMaxStep(kBig);
-      eloss   += destep;
-      tlength += step;
-      
-      Float_t x0,y0,z0;
-      Float_t localPos[3];
-      Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
-      gMC->Gmtod(globalPos,localPos,1); 
-
-      if(idvol < AliMUONConstants::NTrackingCh()) {
-// tracking chambers
-          x0 = 0.5*(xhit+pos[0]);
-          y0 = 0.5*(yhit+pos[1]);
-          z0 = 0.5*(zhit+pos[2]);
-      } else {
-// trigger chambers
-          x0 = xhit;
-          y0 = yhit;
-          z0 = 0.;
-      }
-      
-
-      //      if (eloss >0)  MakePadHits(x0,y0,z0,eloss,tof,idvol);
-      
-          
-      hits[6] = tlength;   // track length
-      hits[7] = eloss2;    // de/dx energy loss
-
-
-      //      if (fNPadHits > (Int_t)hits[8]) {
-      //          hits[8] = hits[8]+1;
-      //          hits[9] = 0: // PadHits does not exist anymore (Float_t) fNPadHits;
-      //}
-//
-//    new hit 
-      
-      new(lhits[fNhits++]) 
-          AliMUONHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);
-      eloss = 0; 
-      //
-      // Check additional signal generation conditions 
-      // defined by the segmentation
-      // model (boundary crossing conditions)
-      // only for tracking chambers
-  } else if 
-      ((idvol < AliMUONConstants::NTrackingCh()) &&
-       ((AliMUONChamber*) (*fChambers)[idvol])->SigGenCond(pos[0], pos[1], pos[2]))
-  {
-      ((AliMUONChamber*) (*fChambers)[idvol])
-          ->SigGenInit(pos[0], pos[1], pos[2]);
-      
-      Float_t localPos[3];
-      Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
-      gMC->Gmtod(globalPos,localPos,1); 
-
-      eloss    += destep;
-
-      // if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
-      //        MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
-      xhit     = pos[0];
-      yhit     = pos[1]; 
-      zhit     = pos[2];
-      eloss = 0;
-      tlength += step ;
-      //
-      // nothing special  happened, add up energy loss
-  } else {        
-      eloss   += destep;
-      tlength += step ;
+    iEnter = 0;
   }
 }