]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONv1.cxx
Merging changes: Trigger, muondata and new step manager
[u/mrichter/AliRoot.git] / MUON / AliMUONv1.cxx
index ada0dd83ebe64bbf259410538a51c7f7d2d31046..68cced8fe2556792c24174274e7a4b37c5a3ee09 100644 (file)
  **************************************************************************/
 
 /* $Id$ */
-/*
-$Log$
-Revision 1.29.4.5  2003/05/14 15:24:30  martinez
-Merging with NewIO: Merging v3 in v1
-
-Revision 1.42  2003/05/13 17:03:54  martinez
-Merging AliMUONv3 in AliMUONv1
-
-Revision 1.41  2003/05/02 15:09:38  hristov
-Code for MUON Station1 (I.Hrivnacova)
-
-Revision 1.40  2003/01/28 13:21:06  morsch
-Improved response simulation for station 1.
-(M. Mac Cormick, I. Hrivnacova, D. Guez)
-
-Revision 1.39  2003/01/14 10:50:19  alibrary
-Cleanup of STEER coding conventions
-
-Revision 1.38  2002/11/21 17:01:56  alibrary
-Removing AliMCProcess and AliMC
-
-Revision 1.37  2002/10/23 07:24:57  alibrary
-Introducing Riostream.h
-
-Revision 1.36  2002/10/14 14:57:29  hristov
-Merging the VirtualMC branch to the main development branch (HEAD)
-
-Revision 1.31.4.3  2002/10/11 06:56:48  hristov
-Updating VirtualMC to v3-09-02
-
-Revision 1.35  2002/09/02 15:51:48  morsch
-Gsbool calls added to resolve MANY. (I. Hrivnacova)
-
-Revision 1.31.4.2  2002/07/24 10:07:21  alibrary
-Updating VirtualMC
-
-Revision 1.33  2002/07/23 10:02:46  morsch
-All volume names start with "S".
-
-Revision 1.32  2002/05/02 12:51:10  morsch
-For G4: gMC->VolId(...) replaced by gAlice->GetModule(...).
-
-Revision 1.31  2002/03/13 07:55:04  jchudoba
-Correction of the errourness last commit.
-
-Revision 1.29  2001/06/21 14:54:37  morsch
-Put volumes of station 3 into DIPO if present. (A. de Falco)
-
-Revision 1.28  2001/05/16 14:57:17  alibrary
-New files for folders and Stack
-
-Revision 1.27  2001/04/06 11:24:43  morsch
-Dependency on implementations of AliSegmentation and AliMUONResponse moved to AliMUONFactory class.
-Static method Build() builds the MUON system out of chambers, segmentation and response.
-
-Revision 1.26  2001/03/17 10:07:20  morsch
-Correct inconsistent variable name / method name / comments.
-
-Revision 1.25  2001/03/16 15:32:06  morsch
-Corrections of overlap with beam shield and dipole (A. de Falco)
-
-Revision 1.24  2001/03/14 17:22:15  pcrochet
-Geometry of the trigger chambers : a vertical gap of has been introduced around x=0 according fig.3.27 of the TDR (P.Dupieux)
-
-Revision 1.23  2001/01/18 15:23:49  egangler
-Bug correction in StepManager :
-Now the systematic offset with angle is cured
-
-Revision 1.22  2001/01/17 21:01:21  hristov
-Unused variable removed
-
-Revision 1.21  2000/12/20 13:00:22  egangler
-
-Added charge correlation between cathods.
-In Config_slat.C, use
- MUON->Chamber(chamber-1).SetChargeCorrel(0.11); to set the RMS of
- q1/q2 to 11 % (number from Alberto)
- This is stored in AliMUONChamber fChargeCorrel member.
- At generation time, when a tracks enters the volume,
- AliMUONv1::StepManager calls
- AliMUONChamber::ChargeCorrelationInit() to set the current value of
- fCurrentCorrel which is then used at Disintegration level to scale
- appropriately the PadHit charges.
-
-Revision 1.20  2000/12/04 17:48:23  gosset
-Modifications for stations 1 et 2 mainly:
-* station 1 with 4 mm gas gap and smaller cathode segmentation...
-* stations 1 and 2 with "grey" frame crosses
-* mean noise at 1.5 ADC channel
-* Ar-CO2 gas (80%+20%)
-
-Revision 1.19  2000/12/02 17:15:46  morsch
-Correction of dead zones in inner regions of stations 3-5
-Correction of length of slats 3 and 9 of station 4.
-
-Revision 1.17  2000/11/24 12:57:10  morsch
-New version of geometry for stations 3-5 "Slats" (A. de Falco)
- - sensitive region at station 3 inner radius
- - improved volume tree structure
-
-Revision 1.16  2000/11/08 13:01:40  morsch
-Chamber half-planes of stations 3-5 at different z-positions.
-
-Revision 1.15  2000/11/06 11:39:02  morsch
-Bug in StepManager() corrected.
-
-Revision 1.14  2000/11/06 09:16:50  morsch
-Avoid overlap of slat volumes.
-
-Revision 1.13  2000/10/26 07:33:44  morsch
-Correct x-position of slats in station 5.
-
-Revision 1.12  2000/10/25 19:55:35  morsch
-Switches for each station individually for debug and lego.
-
-Revision 1.11  2000/10/22 16:44:01  morsch
-Update of slat geometry for stations 3,4,5 (A. deFalco)
-
-Revision 1.10  2000/10/12 16:07:04  gosset
-StepManager:
-* SigGenCond only called for tracking chambers,
-  hence no more division by 0,
-  and may use last ALIROOT/dummies.C with exception handling;
-* "10" replaced by "AliMUONConstants::NTrackingCh()".
-
-Revision 1.9  2000/10/06 15:37:22  morsch
-Problems with variable redefinition in for-loop solved.
-Variable names starting with u-case letters changed to l-case.
-
-Revision 1.8  2000/10/06 09:06:31  morsch
-Include Slat chambers (stations 3-5) into geometry (A. de Falco)
-
-Revision 1.7  2000/10/02 21:28:09  fca
-Removal of useless dependecies via forward declarations
-
-Revision 1.6  2000/10/02 17:20:45  egangler
-Cleaning of the code (continued ) :
--> coding conventions
--> void Streamers
--> some useless includes removed or replaced by "class" statement
-
-Revision 1.5  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.4  2000/06/26 14:02:38  morsch
-Add class AliMUONConstants with MUON specific constants using static memeber data and access methods.
-
-Revision 1.3  2000/06/22 14:10:05  morsch
-HP scope problems corrected (PH)
-
-Revision 1.2  2000/06/15 07:58:49  morsch
-Code from MUON-dev joined
-
-Revision 1.1.2.14  2000/06/14 14:37:25  morsch
-Initialization of TriggerCircuit added (PC)
-
-Revision 1.1.2.13  2000/06/09 21:55:47  morsch
-Most coding rule violations corrected.
-
-Revision 1.1.2.12  2000/05/05 11:34:29  morsch
-Log inside comments.
-
-Revision 1.1.2.11  2000/05/05 10:06:48  morsch
-Coding Rule violations regarding trigger section corrected (CP)
-Log messages included.
-*/
 
 /////////////////////////////////////////////////////////
 //  Manager and hits classes for set:MUON version 0    //
 /////////////////////////////////////////////////////////
-
+#include <TRandom.h>
+#include <TF1.h>
 #include <Riostream.h>
 #include <TClonesArray.h>
 #include <TLorentzVector.h> 
@@ -218,7 +49,10 @@ AliMUONv1::AliMUONv1() : AliMUON()
     fChambers = 0;
     fStations = 0;
     fStepManagerVersionOld = kFALSE;
-    fStepMaxInActiveGas = 0.6;
+    fStepManagerVersionNew = kFALSE;
+    fStepManagerVersionTest = kFALSE;
+
+    fStepMaxInActiveGas = 2.0;
 }
 
  
@@ -235,7 +69,10 @@ AliMUONv1::AliMUONv1(const char *name, const char *title)
     factory.Build(this, title);
 
     fStepManagerVersionOld = kFALSE;
-    fStepMaxInActiveGas = 0.6;
+    fStepManagerVersionNew = kFALSE;
+    fStepManagerVersionTest = kFALSE;
+
+    fStepMaxInActiveGas = 2.0;
 }
 
 //___________________________________________
@@ -1403,540 +1240,196 @@ void AliMUONv1::CreateGeometry()
  }
  
 
-///////////////////////////////////////
-// GEOMETRY FOR THE TRIGGER CHAMBERS //
-///////////////////////////////////////
-
-// 03/00 P. Dupieux : introduce a slighly more realistic  
-//                    geom. of the trigger readout planes with
-//                    2 Zpos per trigger plane (alternate
-//                    between left and right of the trigger)  
-
-//  Parameters of the Trigger Chambers
-
-// DP03-01 introduce dead zone of +/- 2 cm arround x=0 (as in TDR, fig3.27)                    
-     const Float_t kDXZERO=2.; 
-     const Float_t kXMC1MIN=34.;       
-     const Float_t kXMC1MED=51.;                                
-     const Float_t kXMC1MAX=272.;                               
-     const Float_t kYMC1MIN=34.;                              
-     const Float_t kYMC1MAX=51.;                              
-     const Float_t kRMIN1=50.;
-// DP03-01     const Float_t kRMAX1=62.;
-     const Float_t kRMAX1=64.;
-     const Float_t kRMIN2=50.;
-// DP03-01      const Float_t kRMAX2=66.;
-     const Float_t kRMAX2=68.;
-
-//   zposition of the middle of the gas gap in mother vol 
-     const Float_t kZMCm=-3.6;
-     const Float_t kZMCp=+3.6;
-
-
-// TRIGGER STATION 1 - TRIGGER STATION 1 - TRIGGER STATION 1
-
-     // iChamber 1 and 2 for first and second chambers in the station
-     // iChamber (first chamber) kept for other quanties than Z,
-     // assumed to be the same in both chambers
-     iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[10];
-     iChamber2 =(AliMUONChamber*) (*fChambers)[11]; 
-
-     // 03/00 
-     // zpos1 and zpos2 are now the middle of the first and second
-     // plane of station 1 : 
-     // zpos1=(16075+15995)/2=16035 mm, thick/2=40 mm
-     // zpos2=(16225+16145)/2=16185 mm, thick/2=40 mm
-     //
-     // zpos1m=15999 mm , zpos1p=16071 mm (middles of gas gaps)
-     // zpos2m=16149 mm , zpos2p=16221 mm (middles of gas gaps)
-     // rem : the total thickness accounts for 1 mm of al on both 
-     // side of the RPCs (see zpos1 and zpos2), as previously
-
-     zpos1=iChamber1->Z();
-     zpos2=iChamber2->Z();
-
-
-// Mother volume definition     
-     tpar[0] = iChamber->RInner(); 
-     tpar[1] = iChamber->ROuter();
-     tpar[2] = 4.0;    
-     gMC->Gsvolu("SM11", "TUBE", idAir, tpar, 3);
-     gMC->Gsvolu("SM12", "TUBE", idAir, tpar, 3);
-     
-// Definition of the flange between the beam shielding and the RPC 
-     tpar[0]= kRMIN1;
-     tpar[1]= kRMAX1;
-     tpar[2]= 4.0;
-   
-     gMC->Gsvolu("SF1A", "TUBE", idAlu1, tpar, 3);     //Al
-     gMC->Gspos("SF1A", 1, "SM11", 0., 0., 0., 0, "MANY");
-      
-     gMC->Gsvolu("SF3A", "TUBE", idAlu1, tpar, 3);     //Al
-     gMC->Gspos("SF3A", 1, "SM12", 0., 0., 0., 0, "MANY");
-
-
-// FIRST PLANE OF STATION 1
-
-//   ratios of zpos1m/zpos1p and inverse for first plane
-     Float_t zmp=(zpos1-3.6)/(zpos1+3.6);
-     Float_t zpm=1./zmp;
-   
-
-// Definition of prototype for chambers in the first plane     
-          
-     tpar[0]= 0.;
-     tpar[1]= 0.;
-     tpar[2]= 0.;
-          
-     gMC->Gsvolu("SC1A", "BOX ", idAlu1, tpar, 0);           //Al    
-     gMC->Gsvolu("SB1A", "BOX ", idtmed[1107], tpar, 0);     //Bakelite 
-     gMC->Gsvolu("SG1A", "BOX ", idtmed[1106], tpar, 0);     //Gas streamer
-
-// chamber type A
-     tpar[0] = -1.;
-     tpar[1] = -1.;
-     
-// DP03-01     const Float_t kXMC1A=kXMC1MED+(kXMC1MAX-kXMC1MED)/2.;
-     const Float_t kXMC1A=kDXZERO+kXMC1MED+(kXMC1MAX-kXMC1MED)/2.;
-     const Float_t kYMC1Am=0.;
-     const Float_t kYMC1Ap=0.;
-          
-     tpar[2] = 0.1;    
-     gMC->Gsposp("SG1A", 1, "SB1A", 0., 0., 0., 0, "ONLY",tpar,3);
-     tpar[2] = 0.3;
-     gMC->Gsposp("SB1A", 1, "SC1A", 0., 0., 0., 0, "ONLY",tpar,3);
-
-     tpar[2] = 0.4;
-     tpar[0] = (kXMC1MAX-kXMC1MED)/2.;
-     tpar[1] = kYMC1MIN;
-
-     gMC->Gsposp("SC1A", 1, "SM11",kXMC1A,kYMC1Am,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 2, "SM11",-kXMC1A,kYMC1Ap,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsbool("SC1A", "SF1A");
-     
-//  chamber type B    
-     Float_t tpar1save=tpar[1];
-     Float_t y1msave=kYMC1Am;
-     Float_t y1psave=kYMC1Ap;
+//********************************************************************
+//                            Trigger                               **
+//******************************************************************** 
+ /* 
+    zpos1 and zpos2 are the middle of the first and second
+    planes of station 1 (+1m for second station):
+    zpos1=(zpos1m+zpos1p)/2=(15999+16071)/2=16035 mm, thick/2=40 mm
+    zpos2=(zpos2m+zpos2p)/2=(16169+16241)/2=16205 mm, thick/2=40 mm
+    zposxm and zposxp= middles of gaz gaps within a detection plane
+    rem: the total thickness accounts for 1 mm of al on both
+    side of the RPCs (see zpos1 and zpos2)
+ */
+
+// vertical gap between right and left chambers (kDXZERO*2=4cm)
+ const Float_t kDXZERO=2.; 
+// main distances for chamber definition in first plane/first station
+ const Float_t kXMIN=34.;       
+ const Float_t kXMED=51.;                                
+ const Float_t kXMAX=272.; 
+// kXMAX will become 255. in real life. segmentation to be updated accordingly
+// (see fig.2-4 & 2-5 of Local Trigger Board PRR)
+ const Float_t kYMIN=34.;                              
+ const Float_t kYMAX=51.;                              
+// inner/outer radius of flange between beam shield. and chambers (1/station)
+ const Float_t kRMIN[2]={50.,50.};
+ const Float_t kRMAX[2]={64.,68.};
+// z position of the middle of the gas gap in mother vol 
+ const Float_t kZm=-3.6;
+ const Float_t kZp=+3.6;     
  
-     tpar[0] = (kXMC1MAX-kXMC1MIN)/2.;
-     tpar[1] = (kYMC1MAX-kYMC1MIN)/2.;
-     
-// DP03-01     const Float_t kXMC1B=kXMC1MIN+tpar[0];
-     const Float_t kXMC1B=kDXZERO+kXMC1MIN+tpar[0];
-     const Float_t kYMC1Bp=(y1msave+tpar1save)*zpm+tpar[1];
-     const Float_t kYMC1Bm=(y1psave+tpar1save)*zmp+tpar[1];
-
-     gMC->Gsposp("SC1A", 3, "SM11",kXMC1B,kYMC1Bp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 4, "SM11",-kXMC1B,kYMC1Bm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 5, "SM11",kXMC1B,-kYMC1Bp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 6, "SM11",-kXMC1B,-kYMC1Bm,kZMCm, 0, "ONLY", tpar, 3);
-     
-//  chamber type C  (end of type B !!)      
-     tpar1save=tpar[1];
-     y1msave=kYMC1Bm;
-     y1psave=kYMC1Bp;
-
-     tpar[0] = kXMC1MAX/2;
-     tpar[1] = kYMC1MAX/2;
-     
-
-// DP03-01     const Float_t kXMC1C=tpar[0];
-     const Float_t kXMC1C=kDXZERO+tpar[0];
-// warning : same Z than type B
-     const Float_t kYMC1Cp=(y1psave+tpar1save)*1.+tpar[1];
-     const Float_t kYMC1Cm=(y1msave+tpar1save)*1.+tpar[1];
-     
-     gMC->Gsposp("SC1A", 7, "SM11",kXMC1C,kYMC1Cp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 8, "SM11",-kXMC1C,kYMC1Cm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 9, "SM11",kXMC1C,-kYMC1Cp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 10, "SM11",-kXMC1C,-kYMC1Cm,kZMCm, 0, "ONLY", tpar, 3);
-     
-//  chamber type D, E and F (same size)        
-     tpar1save=tpar[1];
-     y1msave=kYMC1Cm;
-     y1psave=kYMC1Cp;
-
-     tpar[0] = kXMC1MAX/2.;
-     tpar[1] = kYMC1MIN;
-     
-// DP03-01     const Float_t kXMC1D=tpar[0];
-     const Float_t kXMC1D=kDXZERO+tpar[0];
-     const Float_t kYMC1Dp=(y1msave+tpar1save)*zpm+tpar[1];
-     const Float_t kYMC1Dm=(y1psave+tpar1save)*zmp+tpar[1];
-     
-     gMC->Gsposp("SC1A", 11, "SM11",kXMC1D,kYMC1Dm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 12, "SM11",-kXMC1D,kYMC1Dp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 13, "SM11",kXMC1D,-kYMC1Dm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 14, "SM11",-kXMC1D,-kYMC1Dp,kZMCp, 0, "ONLY", tpar, 3);
-
-
-     tpar1save=tpar[1];
-     y1msave=kYMC1Dm;
-     y1psave=kYMC1Dp;
-     const Float_t kYMC1Ep=(y1msave+tpar1save)*zpm+tpar[1];
-     const Float_t kYMC1Em=(y1psave+tpar1save)*zmp+tpar[1];
-     
-     gMC->Gsposp("SC1A", 15, "SM11",kXMC1D,kYMC1Ep,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 16, "SM11",-kXMC1D,kYMC1Em,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 17, "SM11",kXMC1D,-kYMC1Ep,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 18, "SM11",-kXMC1D,-kYMC1Em,kZMCm, 0, "ONLY", tpar, 3);
-
-     tpar1save=tpar[1];
-     y1msave=kYMC1Em;
-     y1psave=kYMC1Ep;
-     const Float_t kYMC1Fp=(y1msave+tpar1save)*zpm+tpar[1];
-     const Float_t kYMC1Fm=(y1psave+tpar1save)*zmp+tpar[1];
-    
-     gMC->Gsposp("SC1A", 19, "SM11",kXMC1D,kYMC1Fm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 20, "SM11",-kXMC1D,kYMC1Fp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 21, "SM11",kXMC1D,-kYMC1Fm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC1A", 22, "SM11",-kXMC1D,-kYMC1Fp,kZMCp, 0, "ONLY", tpar, 3);
-
-// Positioning first plane in ALICE     
-     gMC->Gspos("SM11", 1, "ALIC", 0., 0., zpos1, 0, "ONLY");
-
-// End of geometry definition for the first plane of station 1
-
-
-
-// SECOND PLANE OF STATION 1 : proj ratio = zpos2/zpos1
-
-     const Float_t kZ12=zpos2/zpos1;
-      
-// Definition of prototype for chambers in the second plane of station 1    
-          
-     tpar[0]= 0.;
-     tpar[1]= 0.;
-     tpar[2]= 0.;
-          
-     gMC->Gsvolu("SC2A", "BOX ", idAlu1, tpar, 0);           //Al    
-     gMC->Gsvolu("SB2A", "BOX ", idtmed[1107], tpar, 0);     //Bakelite 
-     gMC->Gsvolu("SG2A", "BOX ", idtmed[1106], tpar, 0);     //Gas streamer
-
-// chamber type A
-     tpar[0] = -1.;
-     tpar[1] = -1.;
-     
-     const Float_t kXMC2A=kXMC1A*kZ12;
-     const Float_t kYMC2Am=0.;
-     const Float_t kYMC2Ap=0.;
-          
-     tpar[2] = 0.1;    
-     gMC->Gsposp("SG2A", 1, "SB2A", 0., 0., 0., 0, "ONLY",tpar,3);
-     tpar[2] = 0.3;
-     gMC->Gsposp("SB2A", 1, "SC2A", 0., 0., 0., 0, "ONLY",tpar,3);
-
-     tpar[2] = 0.4;
-     tpar[0] = ((kXMC1MAX-kXMC1MED)/2.)*kZ12;
-     tpar[1] = kYMC1MIN*kZ12;
-
-     gMC->Gsposp("SC2A", 1, "SM12",kXMC2A,kYMC2Am,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 2, "SM12",-kXMC2A,kYMC2Ap,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsbool("SC2A", "SF3A");
-     
-
-//  chamber type B    
-
-     tpar[0] = ((kXMC1MAX-kXMC1MIN)/2.)*kZ12;
-     tpar[1] = ((kYMC1MAX-kYMC1MIN)/2.)*kZ12;
-     
-     const Float_t kXMC2B=kXMC1B*kZ12;
-     const Float_t kYMC2Bp=kYMC1Bp*kZ12;
-     const Float_t kYMC2Bm=kYMC1Bm*kZ12;
-     gMC->Gsposp("SC2A", 3, "SM12",kXMC2B,kYMC2Bp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 4, "SM12",-kXMC2B,kYMC2Bm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 5, "SM12",kXMC2B,-kYMC2Bp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 6, "SM12",-kXMC2B,-kYMC2Bm,kZMCm, 0, "ONLY", tpar, 3);
-
-     
-//  chamber type C   (end of type B !!)     
-
-     tpar[0] = (kXMC1MAX/2)*kZ12;
-     tpar[1] = (kYMC1MAX/2)*kZ12;
-     
-     const Float_t kXMC2C=kXMC1C*kZ12;
-     const Float_t kYMC2Cp=kYMC1Cp*kZ12;
-     const Float_t kYMC2Cm=kYMC1Cm*kZ12;     
-     gMC->Gsposp("SC2A", 7, "SM12",kXMC2C,kYMC2Cp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 8, "SM12",-kXMC2C,kYMC2Cm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 9, "SM12",kXMC2C,-kYMC2Cp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 10, "SM12",-kXMC2C,-kYMC2Cm,kZMCm, 0, "ONLY", tpar, 3);
-     
-//  chamber type D, E and F (same size)        
-
-     tpar[0] = (kXMC1MAX/2.)*kZ12;
-     tpar[1] = kYMC1MIN*kZ12;
-     
-     const Float_t kXMC2D=kXMC1D*kZ12;
-     const Float_t kYMC2Dp=kYMC1Dp*kZ12;
-     const Float_t kYMC2Dm=kYMC1Dm*kZ12;     
-     gMC->Gsposp("SC2A", 11, "SM12",kXMC2D,kYMC2Dm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 12, "SM12",-kXMC2D,kYMC2Dp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 13, "SM12",kXMC2D,-kYMC2Dm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 14, "SM12",-kXMC2D,-kYMC2Dp,kZMCp, 0, "ONLY", tpar, 3);
-
-     const Float_t kYMC2Ep=kYMC1Ep*kZ12;
-     const Float_t kYMC2Em=kYMC1Em*kZ12;
-     gMC->Gsposp("SC2A", 15, "SM12",kXMC2D,kYMC2Ep,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 16, "SM12",-kXMC2D,kYMC2Em,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 17, "SM12",kXMC2D,-kYMC2Ep,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 18, "SM12",-kXMC2D,-kYMC2Em,kZMCm, 0, "ONLY", tpar, 3);
-
-
-     const Float_t kYMC2Fp=kYMC1Fp*kZ12;
-     const Float_t kYMC2Fm=kYMC1Fm*kZ12;
-     gMC->Gsposp("SC2A", 19, "SM12",kXMC2D,kYMC2Fm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 20, "SM12",-kXMC2D,kYMC2Fp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 21, "SM12",kXMC2D,-kYMC2Fm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC2A", 22, "SM12",-kXMC2D,-kYMC2Fp,kZMCp, 0, "ONLY", tpar, 3);
-
-// Positioning second plane of station 1 in ALICE     
-     
-     gMC->Gspos("SM12", 1, "ALIC", 0., 0., zpos2, 0, "ONLY");
+ iChamber1 = (AliMUONChamber*) (*fChambers)[10];     
+ zpos1 = iChamber1->Z();
 
-// End of geometry definition for the second plane of station 1
-
-
-
-// TRIGGER STATION 2 - TRIGGER STATION 2 - TRIGGER STATION 2    
-
-     // 03/00 
-     // zpos3 and zpos4 are now the middle of the first and second
-     // plane of station 2 : 
-     // zpos3=(17075+16995)/2=17035 mm, thick/2=40 mm
-     // zpos4=(17225+17145)/2=17185 mm, thick/2=40 mm
-     //
-     // zpos3m=16999 mm , zpos3p=17071 mm (middles of gas gaps)
-     // zpos4m=17149 mm , zpos4p=17221 mm (middles of gas gaps)
-     // rem : the total thickness accounts for 1 mm of al on both 
-     // side of the RPCs (see zpos3 and zpos4), as previously
-     iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[12];
-     iChamber2 =(AliMUONChamber*) (*fChambers)[13];
-     Float_t zpos3=iChamber1->Z();
-     Float_t zpos4=iChamber2->Z();
-
-
-// Mother volume definition     
-     tpar[0] = iChamber->RInner(); 
-     tpar[1] = iChamber->ROuter();
-     tpar[2] = 4.0;    
+// ratio of zpos1m/zpos1p and inverse for first plane
+ Float_t zmp=(zpos1-3.6)/(zpos1+3.6);
+ Float_t zpm=1./zmp;
  
-     gMC->Gsvolu("SM21", "TUBE", idAir, tpar, 3);
-     gMC->Gsvolu("SM22", "TUBE", idAir, tpar, 3);
-     
-// Definition of the flange between the beam shielding and the RPC 
-//  ???? interface shielding
-
-     tpar[0]= kRMIN2;
-     tpar[1]= kRMAX2;
-     tpar[2]= 4.0;
-   
-     gMC->Gsvolu("SF2A", "TUBE", idAlu1, tpar, 3);            //Al
-     gMC->Gspos("SF2A", 1, "SM21", 0., 0., 0., 0, "MANY");
-
-     gMC->Gsvolu("SF4A", "TUBE", idAlu1, tpar, 3);            //Al
-     gMC->Gspos("SF4A", 1, "SM22", 0., 0., 0., 0, "MANY");
-    
-
-
-// FIRST PLANE OF STATION 2 : proj ratio = zpos3/zpos1
-
-     const Float_t kZ13=zpos3/zpos1; 
-
-// Definition of prototype for chambers in the first plane of station 2       
-     tpar[0]= 0.;
-     tpar[1]= 0.;
-     tpar[2]= 0.;
-          
-     gMC->Gsvolu("SC3A", "BOX ", idAlu1, tpar, 0);           //Al  
-     gMC->Gsvolu("SB3A", "BOX ", idtmed[1107], tpar, 0);     //Bakelite 
-     gMC->Gsvolu("SG3A", "BOX ", idtmed[1106], tpar, 0);     //Gas streamer
-
-
-// chamber type A
-     tpar[0] = -1.;
-     tpar[1] = -1.;
-     
-     const Float_t kXMC3A=kXMC1A*kZ13;
-     const Float_t kYMC3Am=0.;
-     const Float_t kYMC3Ap=0.;
-          
-     tpar[2] = 0.1;    
-     gMC->Gsposp("SG3A", 1, "SB3A", 0., 0., 0., 0, "ONLY",tpar,3);
-     tpar[2] = 0.3;
-     gMC->Gsposp("SB3A", 1, "SC3A", 0., 0., 0., 0, "ONLY",tpar,3);
-
-     tpar[2] = 0.4;
-     tpar[0] = ((kXMC1MAX-kXMC1MED)/2.)*kZ13;
-     tpar[1] = kYMC1MIN*kZ13;
-     gMC->Gsposp("SC3A", 1, "SM21",kXMC3A,kYMC3Am,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 2, "SM21",-kXMC3A,kYMC3Ap,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsbool("SC3A", "SF2A");
-
-     
-//  chamber type B    
-     tpar[0] = ((kXMC1MAX-kXMC1MIN)/2.)*kZ13;
-     tpar[1] = ((kYMC1MAX-kYMC1MIN)/2.)*kZ13;
-     
-     const Float_t kXMC3B=kXMC1B*kZ13;
-     const Float_t kYMC3Bp=kYMC1Bp*kZ13;
-     const Float_t kYMC3Bm=kYMC1Bm*kZ13;
-     gMC->Gsposp("SC3A", 3, "SM21",kXMC3B,kYMC3Bp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 4, "SM21",-kXMC3B,kYMC3Bm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 5, "SM21",kXMC3B,-kYMC3Bp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 6, "SM21",-kXMC3B,-kYMC3Bm,kZMCm, 0, "ONLY", tpar, 3);
-
-     
-//  chamber type C  (end of type B !!)      
-     tpar[0] = (kXMC1MAX/2)*kZ13;
-     tpar[1] = (kYMC1MAX/2)*kZ13;
-     
-     const Float_t kXMC3C=kXMC1C*kZ13;
-     const Float_t kYMC3Cp=kYMC1Cp*kZ13;
-     const Float_t kYMC3Cm=kYMC1Cm*kZ13;     
-     gMC->Gsposp("SC3A", 7, "SM21",kXMC3C,kYMC3Cp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 8, "SM21",-kXMC3C,kYMC3Cm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 9, "SM21",kXMC3C,-kYMC3Cp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 10, "SM21",-kXMC3C,-kYMC3Cm,kZMCm, 0, "ONLY", tpar, 3);
-     
-
-//  chamber type D, E and F (same size)         
-
-     tpar[0] = (kXMC1MAX/2.)*kZ13;
-     tpar[1] = kYMC1MIN*kZ13;
-     
-     const Float_t kXMC3D=kXMC1D*kZ13;
-     const Float_t kYMC3Dp=kYMC1Dp*kZ13;
-     const Float_t kYMC3Dm=kYMC1Dm*kZ13;          
-     gMC->Gsposp("SC3A", 11, "SM21",kXMC3D,kYMC3Dm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 12, "SM21",-kXMC3D,kYMC3Dp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 13, "SM21",kXMC3D,-kYMC3Dm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 14, "SM21",-kXMC3D,-kYMC3Dp,kZMCp, 0, "ONLY", tpar, 3);
-
-     const Float_t kYMC3Ep=kYMC1Ep*kZ13;
-     const Float_t kYMC3Em=kYMC1Em*kZ13;
-     gMC->Gsposp("SC3A", 15, "SM21",kXMC3D,kYMC3Ep,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 16, "SM21",-kXMC3D,kYMC3Em,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 17, "SM21",kXMC3D,-kYMC3Ep,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 18, "SM21",-kXMC3D,-kYMC3Em,kZMCm, 0, "ONLY", tpar, 3);
-
-     const Float_t kYMC3Fp=kYMC1Fp*kZ13;
-     const Float_t kYMC3Fm=kYMC1Fm*kZ13;
-     gMC->Gsposp("SC3A", 19, "SM21",kXMC3D,kYMC3Fm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 20, "SM21",-kXMC3D,kYMC3Fp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 21, "SM21",kXMC3D,-kYMC3Fm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC3A", 22, "SM21",-kXMC3D,-kYMC3Fp,kZMCp, 0, "ONLY", tpar, 3);
-       
-
-// Positioning first plane of station 2 in ALICE
-     
-     gMC->Gspos("SM21", 1, "ALIC", 0., 0., zpos3, 0, "ONLY");
-
-// End of geometry definition for the first plane of station 2
-
-
-
-
-// SECOND PLANE OF STATION 2 : proj ratio = zpos4/zpos1
-
-     const Float_t kZ14=zpos4/zpos1;
-     
-// Definition of prototype for chambers in the second plane of station 2    
-          
-     tpar[0]= 0.;
-     tpar[1]= 0.;
-     tpar[2]= 0.;
-          
-     gMC->Gsvolu("SC4A", "BOX ", idAlu1, tpar, 0);           //Al      
-     gMC->Gsvolu("SB4A", "BOX ", idtmed[1107], tpar, 0);     //Bakelite 
-     gMC->Gsvolu("SG4A", "BOX ", idtmed[1106], tpar, 0);     //Gas streamer
-
+ Int_t icount=0; // chamber counter (0 1 2 3)
+ for (Int_t istation=0; istation<2; istation++) { // loop on stations   
+     for (Int_t iplane=0; iplane<2; iplane++) {          // loop on detection planes
+        
+        Int_t iVolNum=1; // counter Volume Number
+        icount = Int_t(iplane*TMath::Power(2,0))+
+            Int_t(istation*TMath::Power(2,1));
+        
+        char volPlane[5]; 
+        sprintf(volPlane,"SM%d%d",istation+1,iplane+1);
+        
+        iChamber = (AliMUONChamber*) (*fChambers)[10+icount];
+        Float_t zpos = iChamber->Z();       
+        
+// mother volume 
+        tpar[0] = iChamber->RInner(); 
+        tpar[1] = iChamber->ROuter(); 
+        tpar[2] = 4.0;    
+        gMC->Gsvolu(volPlane,"TUBE",idAir,tpar,3);
+        
+// Flange between beam shielding and RPC 
+        tpar[0]= kRMIN[istation];
+        tpar[1]= kRMAX[istation];
+        tpar[2]= 4.0;
+        
+        char volFlange[5];
+        sprintf(volFlange,"SF%dA",icount+1);    
+        gMC->Gsvolu(volFlange,"TUBE",idAlu1,tpar,3);     //Al
+        gMC->Gspos(volFlange,1,volPlane,0.,0.,0.,0,"MANY");
+        
+// scaling factor
+        Float_t zRatio = zpos / zpos1;
+        
+// chamber prototype
+        tpar[0]= 0.;
+        tpar[1]= 0.;
+        tpar[2]= 0.;
+        
+        char volAlu[5]; // Alu
+        char volBak[5]; // Bakelite
+        char volGaz[5]; // Gas streamer
+        
+        sprintf(volAlu,"SC%dA",icount+1);
+        sprintf(volBak,"SB%dA",icount+1);
+        sprintf(volGaz,"SG%dA",icount+1);
+        
+        gMC->Gsvolu(volAlu,"BOX",idAlu1,tpar,0);           // Al
+        gMC->Gsvolu(volBak,"BOX",idtmed[1107],tpar,0);     // Bakelite
+        gMC->Gsvolu(volGaz,"BOX",idtmed[1106],tpar,0);     // Gas streamer
+        
 // chamber type A
-     tpar[0] = -1.;
-     tpar[1] = -1.;
-     
-     const Float_t kXMC4A=kXMC1A*kZ14;
-     const Float_t kYMC4Am=0.;
-     const Float_t kYMC4Ap=0.;
-          
-     tpar[2] = 0.1;    
-     gMC->Gsposp("SG4A", 1, "SB4A", 0., 0., 0., 0, "ONLY",tpar,3);
-     tpar[2] = 0.3;
-     gMC->Gsposp("SB4A", 1, "SC4A", 0., 0., 0., 0, "ONLY",tpar,3);
-
-     tpar[2] = 0.4;
-     tpar[0] = ((kXMC1MAX-kXMC1MED)/2.)*kZ14;
-     tpar[1] = kYMC1MIN*kZ14;
-     gMC->Gsposp("SC4A", 1, "SM22",kXMC4A,kYMC4Am,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 2, "SM22",-kXMC4A,kYMC4Ap,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsbool("SC4A", "SF4A");
-     
-
-//  chamber type B    
-     tpar[0] = ((kXMC1MAX-kXMC1MIN)/2.)*kZ14;
-     tpar[1] = ((kYMC1MAX-kYMC1MIN)/2.)*kZ14;
-     
-     const Float_t kXMC4B=kXMC1B*kZ14;
-     const Float_t kYMC4Bp=kYMC1Bp*kZ14;
-     const Float_t kYMC4Bm=kYMC1Bm*kZ14;
-     gMC->Gsposp("SC4A", 3, "SM22",kXMC4B,kYMC4Bp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 4, "SM22",-kXMC4B,kYMC4Bm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 5, "SM22",kXMC4B,-kYMC4Bp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 6, "SM22",-kXMC4B,-kYMC4Bm,kZMCm, 0, "ONLY", tpar, 3);
-
-     
-//  chamber type C   (end of type B !!)      
-     tpar[0] =(kXMC1MAX/2)*kZ14;
-     tpar[1] =  (kYMC1MAX/2)*kZ14;
-     
-     const Float_t kXMC4C=kXMC1C*kZ14;
-     const Float_t kYMC4Cp=kYMC1Cp*kZ14;
-     const Float_t kYMC4Cm=kYMC1Cm*kZ14;     
-     gMC->Gsposp("SC4A", 7, "SM22",kXMC4C,kYMC4Cp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 8, "SM22",-kXMC4C,kYMC4Cm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 9, "SM22",kXMC4C,-kYMC4Cp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 10, "SM22",-kXMC4C,-kYMC4Cm,kZMCm, 0, "ONLY", tpar, 3);
-
-     
-//  chamber type D, E and F (same size)      
-     tpar[0] = (kXMC1MAX/2.)*kZ14;
-     tpar[1] =  kYMC1MIN*kZ14;
-     
-     const Float_t kXMC4D=kXMC1D*kZ14;
-     const Float_t kYMC4Dp=kYMC1Dp*kZ14;
-     const Float_t kYMC4Dm=kYMC1Dm*kZ14;          
-     gMC->Gsposp("SC4A", 11, "SM22",kXMC4D,kYMC4Dm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 12, "SM22",-kXMC4D,kYMC4Dp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 13, "SM22",kXMC4D,-kYMC4Dm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 14, "SM22",-kXMC4D,-kYMC4Dp,kZMCp, 0, "ONLY", tpar, 3);
-
-     const Float_t kYMC4Ep=kYMC1Ep*kZ14;
-     const Float_t kYMC4Em=kYMC1Em*kZ14;          
-     gMC->Gsposp("SC4A", 15, "SM22",kXMC4D,kYMC4Ep,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 16, "SM22",-kXMC4D,kYMC4Em,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 17, "SM22",kXMC4D,-kYMC4Ep,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 18, "SM22",-kXMC4D,-kYMC4Em,kZMCm, 0, "ONLY", tpar, 3);
-
-     const Float_t kYMC4Fp=kYMC1Fp*kZ14;
-     const Float_t kYMC4Fm=kYMC1Fm*kZ14;          
-     gMC->Gsposp("SC4A", 19, "SM22",kXMC4D,kYMC4Fm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 20, "SM22",-kXMC4D,kYMC4Fp,kZMCp, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 21, "SM22",kXMC4D,-kYMC4Fm,kZMCm, 0, "ONLY", tpar, 3);
-     gMC->Gsposp("SC4A", 22, "SM22",-kXMC4D,-kYMC4Fp,kZMCp, 0, "ONLY", tpar, 3);
-     
-
-// Positioning second plane of station 2 in ALICE
-     
-     gMC->Gspos("SM22", 1, "ALIC", 0., 0., zpos4, 0, "ONLY");
-
-// End of geometry definition for the second plane of station 2
+        tpar[0] = -1.;
+        tpar[1] = -1.;
+        
+        Float_t xA=(kDXZERO+kXMED+(kXMAX-kXMED)/2.)*zRatio;
+        Float_t yAm=0.;
+        Float_t yAp=0.;
+        
+        tpar[2] = 0.1;    
+        gMC->Gsposp(volGaz,1,volBak,0.,0.,0.,0,"ONLY",tpar,3);
+        tpar[2] = 0.3;
+        gMC->Gsposp(volBak,1,volAlu,0.,0.,0.,0,"ONLY",tpar,3);
+        
+        tpar[2] = 0.4;
+        tpar[0] = ((kXMAX-kXMED)/2.)*zRatio;
+        tpar[1] = kYMIN*zRatio;
+        
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xA,yAm,kZm,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xA,yAp,kZp,0,"ONLY",tpar,3);
+        gMC->Gsbool(volAlu,volFlange);
+        
+// chamber type B    
+        Float_t tpar1save=tpar[1];
+        Float_t y1msave=yAm;
+        Float_t y1psave=yAp;
+        
+        tpar[0] = ((kXMAX-kXMIN)/2.) * zRatio;
+        tpar[1] = ((kYMAX-kYMIN)/2.) * zRatio;
+        
+        Float_t xB=(kDXZERO+kXMIN)*zRatio+tpar[0];
+        Float_t yBp=(y1msave+tpar1save)*zpm+tpar[1];
+        Float_t yBm=(y1psave+tpar1save)*zmp+tpar[1];    
+
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xB, yBp,kZp,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xB, yBm,kZm,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xB,-yBp,kZp,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xB,-yBm,kZm,0,"ONLY",tpar,3);
+        
+// chamber type C (note : same Z than type B)
+        tpar1save=tpar[1];
+        y1msave=yBm;
+        y1psave=yBp;
+        
+        tpar[0] = (kXMAX/2)*zRatio;
+        tpar[1] = (kYMAX/2)*zRatio;
+        
+        Float_t xC=kDXZERO*zRatio+tpar[0];
+        Float_t yCp=(y1psave+tpar1save)*1.+tpar[1];
+        Float_t yCm=(y1msave+tpar1save)*1.+tpar[1];
+        
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xC, yCp,kZp,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xC, yCm,kZm,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xC,-yCp,kZp,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xC,-yCm,kZm,0,"ONLY",tpar,3);
+                
+// chamber type D, E and F (same size)        
+        tpar1save=tpar[1];
+        y1msave=yCm;
+        y1psave=yCp;
+        
+        tpar[0] = (kXMAX/2.)*zRatio;
+        tpar[1] =  kYMIN*zRatio;
+        
+        Float_t xD=kDXZERO*zRatio+tpar[0];
+        Float_t yDp=(y1msave+tpar1save)*zpm+tpar[1];
+        Float_t yDm=(y1psave+tpar1save)*zmp+tpar[1];
+        
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xD, yDm,kZm,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD, yDp,kZp,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xD,-yDm,kZm,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD,-yDp,kZp,0,"ONLY",tpar,3);
+        
+        tpar1save=tpar[1];
+        y1msave=yDm;
+        y1psave=yDp;
+        Float_t yEp=(y1msave+tpar1save)*zpm+tpar[1];
+        Float_t yEm=(y1psave+tpar1save)*zmp+tpar[1];
+        
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xD, yEp,kZp,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD, yEm,kZm,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xD,-yEp,kZp,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD,-yEm,kZm,0,"ONLY",tpar,3);
+        
+        tpar1save=tpar[1];
+        y1msave=yEm;
+        y1psave=yEp;
+        Float_t yFp=(y1msave+tpar1save)*zpm+tpar[1];
+        Float_t yFm=(y1psave+tpar1save)*zmp+tpar[1];
+        
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xD, yFm,kZm,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD, yFp,kZp,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane, xD,-yFm,kZm,0,"ONLY",tpar,3);
+        gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD,-yFp,kZp,0,"ONLY",tpar,3);
 
-// End of trigger geometry definition
+// Positioning plane in ALICE     
+        gMC->Gspos(volPlane,1,"ALIC",0.,0.,zpos,0,"ONLY");
+        
+     } // end loop on detection planes
+ } // end loop on stations
 
 }
 
-
  
 //___________________________________________
 void AliMUONv1::CreateMaterials()
@@ -2112,6 +1605,17 @@ void AliMUONv1::StepManager()
     StepManagerOld();
     return;
   }
+ if (fStepManagerVersionNew) {
+    StepManagerNew();
+    return;
+  }
+ if (fStepManagerVersionTest) {
+    StepManagerTest();
+    return;
+  }
+
+
   // Volume id
   Int_t   copy, id;
   Int_t   idvol;
@@ -2140,6 +1644,7 @@ void AliMUONv1::StepManager()
   }
   if (idvol == -1) return;
 
+   printf(">>>> This Chamber %d\n",iChamber);
 
   // record hits when track enters ...
   if( gMC->IsTrackEntering()) gMC->SetMaxStep(fStepMaxInActiveGas);  
@@ -2156,18 +1661,19 @@ void AliMUONv1::StepManager()
     // momentum loss and steplength in last step
     destep = gMC->Edep();
     step   = gMC->TrackStep();
+
     //new hit
-    AddHit(fIshunt, gAlice->CurrentTrack(), iChamber, ipart, 
-          pos.X(), pos.Y(), pos.Z(), tof, mom.P(), 
-          theta, phi, step, destep);
+    GetMUONData()->AddHit(fIshunt, gAlice->GetCurrentTrackNumber(), iChamber, ipart, 
+                         pos.X(), pos.Y(), pos.Z(), tof, mom.P(), 
+                         theta, phi, step, destep);
   }
   // Track left chamber ...
   if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
     gMC->SetMaxStep(kBig);
   }
-    
 }
 
+
 Int_t  AliMUONv1::GetChamberId(Int_t volId) const
 {
 // Check if the volume with specified  volId is a sensitive volume (gas) 
@@ -2180,6 +1686,107 @@ Int_t  AliMUONv1::GetChamberId(Int_t volId) const
 
   return 0;
 }
+//__
+
+
+
+void AliMUONv1::StepManagerTest()
+{
+  return;
+}
+//________________________________________
+void AliMUONv1::StepManagerNew()
+{
+
+
+
+
+
+  // Volume id
+  Int_t   copy, id;
+  Int_t   idvol;
+  Int_t   iChamber=0;
+  // Particule id, pos and mom vectors, 
+  // theta, phi angles with respect the normal of the chamber, 
+  // spatial step, delta_energy and time of flight
+  Int_t          ipart;
+  TLorentzVector pos, mom;
+  Float_t        theta, phi, tof;
+  Float_t        destep, step;
+  const  Float_t kBig = 1.e10;
+
+  // Only charged tracks
+  if( !(gMC->TrackCharge()) ) return; 
+
+  // Only gas gap inside chamber
+  // Tag chambers and record hits when track enters 
+  idvol=-1;
+  id=gMC->CurrentVolID(copy);
+  for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++) {
+    if(id==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()) {
+      iChamber = i;
+      idvol  = i-1;
+    }
+  }
+  static Float_t Sstep[20]; // Sum of steps per chamber
+  // static Float_t Sdestep[20]; // Sum of eloss per chamber
+  Float_t GAP;
+  Float_t TEST; 
+
+  if (idvol == -1) return;
+
+  //  printf(">>>> This Chamber %d\n",iChamber);
+
+  // record hits when track enters ...
+  //if( gMC->IsTrackEntering()) gMC->SetMaxStep(fStepMaxInActiveGas);  
+
+  if (gMC->TrackStep() > 0.) {
+    // Get current particle id (ipart), track position (pos)  and momentum (mom)
+    gMC->TrackPosition(pos);
+    gMC->TrackMomentum(mom);
+    ipart    = gMC->TrackPid();         // Particle
+    theta    = mom.Theta()*kRaddeg;     // theta of track
+    phi      = mom.Phi()  *kRaddeg;     // phi of the track
+    tof      = gMC->TrackTime();        // Time of flight
+    //
+    // momentum loss and steplength in last step
+    destep = gMC->Edep();
+    step   = gMC->TrackStep();
+
+    Sstep[iChamber]+=step;
+    // Sdestep[iChamber]+=destep;
+
+  }
+  
+  step   =  Sstep[iChamber]; // Total step >= gap
+  //  destep   =  Sdestep[iChamber]; // Total eloss
+
+
+  // Track left chamber ...
+  if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
+    gMC->SetMaxStep(kBig);
+
+    Sstep[iChamber]=0; // Reset for the next event
+    //Sdestep[iChamber]=0; // Reset for the next event
+
+    if (iChamber>=1 && iChamber<=2) GAP=0.4;
+    if (iChamber>=11 && iChamber<=14) GAP=0.2;
+    if (iChamber>=3 && iChamber<=10) GAP=0.5;
+   
+    TF1 *ELOSS1 = new TF1("Gauss1","exp(-((x-4.13727e+01)**2)/(2*1.42223e+01**2))",0,75);
+    TF1 *ELOSS2 = new TF1("Gauss2","exp(-((x+6.83795e+02)**2)/(2*4.48415e+02**2))",75,350);
+    TEST=gRandom->Rndm();
+    if (TEST <=0.89) destep=ELOSS1->GetRandom();
+    else destep=ELOSS2->GetRandom();
+    destep*=pow(10,-6)*0.0274;
+    destep*=GAP/0.5;
+
+    // One hit per chamber
+    GetMUONData()->AddHit(fIshunt, gAlice->GetCurrentTrackNumber(), iChamber, ipart, 
+          pos.X()-(step/2*sin(theta*kDegrad)*cos(phi*kDegrad)), pos.Y()-(step/2*sin(theta*kDegrad)*sin(phi*kDegrad)), pos.Z()-GAP/2, tof, mom.P(),theta, phi, step, destep);
+
+  }
+}
 
 //___________________________________________
 void AliMUONv1::StepManagerOld()
@@ -2192,7 +1799,8 @@ void AliMUONv1::StepManagerOld()
   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];
@@ -2223,10 +1831,11 @@ void AliMUONv1::StepManagerOld()
   // 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);
@@ -2245,7 +1854,7 @@ void AliMUONv1::StepManagerOld()
       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] = (Float_t) fNPadHits;    // first padhit
+      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
@@ -2256,27 +1865,34 @@ void AliMUONv1::StepManagerOld()
       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);
-      }
+     //  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 
   //
@@ -2304,21 +1920,22 @@ void AliMUONv1::StepManagerOld()
       }
       
 
-      if (eloss >0)  MakePadHits(x0,y0,z0,eloss,tof,idvol);
+      //      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] = (Float_t) fNPadHits;
-      }
+
+      //      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->CurrentTrack(), vol,hits);
+         AliMUONHit(fIshunt, gAlice->GetCurrentTrackNumber(), vol,hits);
       eloss = 0; 
       //
       // Check additional signal generation conditions 
@@ -2338,8 +1955,8 @@ void AliMUONv1::StepManagerOld()
 
       eloss    += destep;
 
-      if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
-       MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
+      // 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];