]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ZDC/AliZDCv1.cxx
Minor change
[u/mrichter/AliRoot.git] / ZDC / AliZDCv1.cxx
index 3f3f4b52fd534270e73bc8bffba7e6309570e0e9..a9ffc429f4481d3e110c7eabf15fb0178941fc90 100644 (file)
 
 /*
 $Log$
+Revision 1.20  2001/05/02 10:33:11  coppedis
+Modify tmaxfd in media definition
+
+Revision 1.19  2001/04/27 08:35:01  coppedis
+Remove some lines for proton acceptance studies
+
+Revision 1.18  2001/04/20 10:08:45  coppedis
+Preliminary version of optics 6.2 - Insertion of TDI
+
+Revision 1.17  2001/03/16 16:18:10  coppedis
+Correction for superposition of ZDC volumes with MUON arm one
+
+Revision 1.16  2001/03/15 16:12:04  coppedis
+Code review
+
+Revision 1.15  2001/03/12 17:47:56  hristov
+Changes needed on Sun with CC 5.0
+
+Revision 1.14  2001/02/23 16:48:28  coppedis
+Correct bug in ZEM hit definition
+
+Revision 1.13  2001/02/07 18:07:41  coppedis
+Modif for splitting
+
+Revision 1.12  2001/01/26 19:56:27  hristov
+Major upgrade of AliRoot code
+
+Revision 1.11  2001/01/16 07:43:33  hristov
+Initialisation of ZDC hits
+
+Revision 1.10  2000/12/14 15:20:02  coppedis
+Hits2Digits method for digitization
+
+Revision 1.9  2000/12/13 10:33:49  coppedis
+Prints only if fDebug==1
+
+Revision 1.8  2000/12/12 14:10:02  coppedis
+Correction suggested by M. Masera
+
+Revision 1.7  2000/11/30 17:23:47  coppedis
+Remove first corrector dipole and introduce digitization
+
+Revision 1.6  2000/11/22 11:33:10  coppedis
+Major code revision
+
+Revision 1.5  2000/10/02 21:28:20  fca
+Removal of useless dependecies via forward declarations
+
+Revision 1.3.2.1  2000/08/24 09:25:47  hristov
+Patch by P.Hristov: Bug in ZDC geometry corrected by E.Scomparin
+
+Revision 1.4  2000/08/24 09:23:59  hristov
+Bug in ZDC geometry corrected by E.Scomparin
+
+Revision 1.3  2000/07/12 06:59:16  fca
+Fixing dimension of hits array
+
+Revision 1.2  2000/07/11 11:12:34  fca
+Some syntax corrections for non standard HP aCC
+
 Revision 1.1  2000/07/10 13:58:01  fca
-New version of ZDC from E.Scomparin & C.Oppedisano
+New version of ZDC from E.Scomparin & C.Oppedisano
 
 Revision 1.7  2000/01/19 17:17:40  fca
 
@@ -28,23 +88,36 @@ Introduction of the Copyright and cvs Log
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
 //  Zero Degree Calorimeter                                                  //
-//  This class contains the basic functions for the Time Of Flight           //
-//  detector. Functions specific to one particular geometry are              //
+//  This class contains the basic functions for the ZDC                      //
+//  Functions specific to one particular geometry are                        //
 //  contained in the derived classes                                         //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+// --- Standard libraries
+#include "stdio.h"
+
+// --- ROOT system
 #include <TBRIK.h>
 #include <TNode.h>
 #include <TMath.h>
+#include <TRandom.h>
+#include <TSystem.h>
+#include <TTree.h>
 
-#include "stdio.h"
+
+// --- AliRoot classes
 #include "AliZDCv1.h"
+#include "AliZDCHit.h"
+#include "AliZDCDigit.h"
 #include "AliRun.h"
+#include "AliDetector.h"
+#include "AliMagF.h"
 #include "AliMC.h"
 #include "AliCallf77.h"
 #include "AliConst.h"
 #include "AliPDG.h"
+#include "TLorentzVector.h"
  
  
 ClassImp(AliZDCv1)
@@ -62,11 +135,15 @@ AliZDCv1::AliZDCv1() : AliZDC()
   //
   // Default constructor for Zero Degree Calorimeter
   //
-  fMedSensF1 = 0;
-  fMedSensF2 = 0;
-  fMedSensZN = 0;
-  fMedSensZP = 0;
-  fMedSensGR = 0;
+  
+  fMedSensF1  = 0;
+  fMedSensF2  = 0;
+  fMedSensZN  = 0;
+  fMedSensZP  = 0;
+  fMedSensZEM = 0;
+  fMedSensGR  = 0;
+  fMedSensPI  = 0;
+  fMedSensTDI = 0;
 }
  
 //_____________________________________________________________________________
@@ -76,11 +153,74 @@ AliZDCv1::AliZDCv1(const char *name, const char *title)
   //
   // Standard constructor for Zero Degree Calorimeter 
   //
-  fMedSensF1 = 0;
-  fMedSensF2 = 0;
-  fMedSensZN = 0;
-  fMedSensZP = 0;
-  fMedSensGR = 0;
+  //
+  // Check that DIPO, ABSO, DIPO and SHIL is there (otherwise tracking is wrong!!!)
+  
+  AliModule* PIPE=gAlice->GetModule("PIPE");
+  AliModule* ABSO=gAlice->GetModule("ABSO");
+  AliModule* DIPO=gAlice->GetModule("DIPO");
+  AliModule* SHIL=gAlice->GetModule("SHIL");
+  if((!PIPE) || (!ABSO) || (!DIPO) || (!SHIL)) {
+    Error("Constructor","ZDC needs PIPE, ABSO, DIPO and SHIL!!!\n");
+    exit(1);
+  } 
+
+  fMedSensF1  = 0;
+  fMedSensF2  = 0;
+  fMedSensZN  = 0;
+  fMedSensZP  = 0;
+  fMedSensZEM = 0;
+  fMedSensGR  = 0;
+  fMedSensPI  = 0;
+  fMedSensTDI = 0;
+
+  
+  // Parameters for light tables
+  fNalfan = 90;       // Number of Alfa (neutrons)
+  fNalfap = 90;       // Number of Alfa (protons)
+  fNben = 18;         // Number of beta (neutrons)
+  fNbep = 28;         // Number of beta (protons)
+  Int_t ip,jp,kp;
+  for(ip=0; ip<4; ip++){
+     for(kp=0; kp<fNalfap; kp++){
+        for(jp=0; jp<fNbep; jp++){
+           fTablep[ip][kp][jp] = 0;
+        } 
+     }
+  }
+  Int_t in,jn,kn;
+  for(in=0; in<4; in++){
+     for(kn=0; kn<fNalfan; kn++){
+        for(jn=0; jn<fNben; jn++){
+           fTablen[in][kn][jn] = 0;
+        } 
+     }
+  }
+
+  // Parameters for hadronic calorimeters geometry
+  fDimZP[0] = 11.2;
+  fDimZP[1] = 6.;
+  fDimZP[2] = 75.;    
+  fPosZN[0] = 0.;
+  fPosZN[1] = -1.2;
+  fPosZN[2] = 11650.;
+  fPosZP[0] = -24.;
+  fPosZP[1] = 0.;
+  fPosZP[2] = 11600.;
+  fFibZN[0] = 0.;
+  fFibZN[1] = 0.01825;
+  fFibZN[2] = 50.;
+  fFibZP[0] = 0.;
+  fFibZP[1] = 0.0275;
+  fFibZP[2] = 75.;
+  
+  // Parameters for EM calorimeter geometry
+  fPosZEM[0] = 0.;
+  fPosZEM[1] = 5.8;
+  fPosZEM[2] = 11600.;
+  
+
+  fDigits = new TClonesArray("AliZDCDigit",1000);
 }
  
 //_____________________________________________________________________________
@@ -99,114 +239,93 @@ void AliZDCv1::CreateGeometry()
 void AliZDCv1::CreateBeamLine()
 {
   
-  Float_t angle;
-  Float_t zq, conpar[9], elpar[3], tubpar[3];
+  Float_t zq, zd1, zd2;
+  Float_t conpar[9], tubpar[3], tubspar[5], boxpar[3];
   Int_t im1, im2;
-  Float_t zd1, zd2;
-  
   
   Int_t *idtmed = fIdtmed->GetArray();
   
-  // -- Mother of the ZDC 
+  // -- Mother of the ZDCs (Vacuum PCON)
   
   conpar[0] = 0.;
   conpar[1] = 360.;
   conpar[2] = 2.;
-  conpar[3] = 1921.6;
+  conpar[3] = 2000.;
   conpar[4] = 0.;
   conpar[5] = 55.;
   conpar[6] = 13060.;
   conpar[7] = 0.;
   conpar[8] = 55.;
-  gMC->Gsvolu("ZDC ", "PCON", idtmed[10], conpar, 9);
+  gMC->Gsvolu("ZDC ", "PCON", idtmed[11], conpar, 9);
   gMC->Gspos("ZDC ", 1, "ALIC", 0., 0., 0., 0, "ONLY");
 
   // -- FIRST SECTION OF THE BEAM PIPE (from compensator dipole to 
-  //    beginning of D1) 
+  //           the beginning of D1) 
   
-  zd1 = 1921.6;
+  zd1 = 2000.;
   
   tubpar[0] = 6.3/2.;
   tubpar[1] = 6.7/2.;
-  tubpar[2] = 3916.7/2.;
-  gMC->Gsvolu("P001", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P001", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
-  
-  //-- SECOND SECTION OF THE BEAM PIPE (FROM THE END OF D1 TO THE BEGINNING OF
-  //    D2) 
-  
-  //-- FROM MAGNETIC BEGINNING OG D1 TO MAGNETIC END OF D1 + 23.5 cm
-  //-- Elliptic pipe
+  tubpar[2] = 3838.3/2.;
+  gMC->Gsvolu("QT01", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT01", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
-  zd1 = 6310.8-472.5;
+  //-- SECOND SECTION OF THE BEAM PIPE (from the end of D1 to the
+  //           beginning of D2) 
   
-  elpar[0] = 6.84/2.;
-  elpar[1] = 5.86/2.;
-  elpar[2] = 945./2.;
-  gMC->Gsvolu("E001", "ELTU", idtmed[5], elpar, 3);
-  gMC->Gspos("E001", 1, "ZDC ", 0., 0., elpar[2] + zd1, 0, "ONLY");
+  //-- FROM MAGNETIC BEGINNING OF D1 TO MAGNETIC END OF D1 + 13.5 cm
+  //--         Cylindrical pipe (r = 3.47) + conical flare
   
-  elpar[0] = 6.44/2.;
-  elpar[1] = 5.46/2.;
-  elpar[2] = 945./2.;
-  gMC->Gsvolu("E002", "ELTU", idtmed[10], elpar, 3);
-  gMC->Gspos("E002", 1, "E001", 0., 0., 0., 0, "ONLY");
-
-  zd1 += 2.*elpar[2];
-  
-  elpar[0] = 6.84/2.;
-  elpar[1] = 5.86/2.;
-  elpar[2] = 13.5/2.;
-  gMC->Gsvolu("E003", "ELTU", idtmed[5], elpar, 3);
-  gMC->Gspos("E002", 1, "ZDC ", 0., 0., elpar[2] + zd1, 0, "ONLY");
+  // -> Beginning of D1
+  zd1 += 2.*tubpar[2];
   
-  elpar[0] = 6.44/2.;
-  elpar[1] = 5.46/2.;
-  elpar[2] = 13.5/2.;
-  gMC->Gsvolu("E004", "ELTU", idtmed[10], elpar, 3);
-  gMC->Gspos("E004", 1, "E003", 0., 0., 0., 0, "ONLY");
+  tubpar[0] = 3.47;
+  tubpar[1] = 3.47+0.2;
+  tubpar[2] = 958.5/2.;
+  gMC->Gsvolu("QT02", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT02", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
 
-  zd1 += 2.*elpar[2];
+  zd1 += 2.*tubpar[2];
   
   conpar[0] = 25./2.;
   conpar[1] = 6.44/2.;
   conpar[2] = 6.84/2.;
   conpar[3] = 10./2.;
   conpar[4] = 10.4/2.;
-  gMC->Gsvolu("C001", "CONE", idtmed[5], conpar, 5);
-  gMC->Gspos("C001", 1, "ZDC ", 0., 0., conpar[0] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QC01", "CONE", idtmed[7], conpar, 5);
+  gMC->Gspos("QC01", 1, "ZDC ", 0., 0., conpar[0] + zd1, 0, "ONLY");
 
   zd1 += 2.*conpar[0];
   
   tubpar[0] = 10./2.;
   tubpar[1] = 10.4/2.;
   tubpar[2] = 50./2.;
-  gMC->Gsvolu("P002", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P002", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QT03", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT03", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
-  zd1 += tubpar[2] * 2.;
+  zd1 += tubpar[2]*2.;
   
   tubpar[0] = 10./2.;
   tubpar[1] = 10.4/2.;
   tubpar[2] = 10./2.;
-  gMC->Gsvolu("P003", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P003", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QT04", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT04", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
   
   tubpar[0] = 10./2.;
   tubpar[1] = 10.4/2.;
   tubpar[2] = 3.16/2.;
-  gMC->Gsvolu("P004", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P004", 1, "ZDC ", 0., 0., tubpar[0] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QT05", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT05", 1, "ZDC ", 0., 0., tubpar[0] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
   
   tubpar[0] = 10.0/2.;
   tubpar[1] = 10.4/2;
   tubpar[2] = 190./2.;
-  gMC->Gsvolu("P005", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P005", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QT06", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT06", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
   
@@ -215,16 +334,16 @@ void AliZDCv1::CreateBeamLine()
   conpar[2] = 10.4/2.;
   conpar[3] = 20.6/2.;
   conpar[4] = 21./2.;
-  gMC->Gsvolu("P006", "CONE", idtmed[5], conpar, 5);
-  gMC->Gspos("P006", 1, "ZDC ", 0., 0., conpar[0] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QC02", "CONE", idtmed[7], conpar, 5);
+  gMC->Gspos("QC02", 1, "ZDC ", 0., 0., conpar[0] + zd1, 0, "ONLY");
   
   zd1 += conpar[0] * 2.;
   
   tubpar[0] = 20.6/2.;
   tubpar[1] = 21./2.;
   tubpar[2] = 450./2.;
-  gMC->Gsvolu("P007", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P007", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QT07", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT07", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
   
@@ -233,40 +352,65 @@ void AliZDCv1::CreateBeamLine()
   conpar[2] = 21./2.;
   conpar[3] = 25.4/2.;
   conpar[4] = 25.8/2.;
-  gMC->Gsvolu("P008", "CONE", idtmed[5], conpar, 5);
-  gMC->Gspos("P008", 1, "ZDC ", 0., 0., conpar[0] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QC03", "CONE", idtmed[7], conpar, 5);
+  gMC->Gspos("QC03", 1, "ZDC ", 0., 0., conpar[0] + zd1, 0, "ONLY");
   
   zd1 += conpar[0] * 2.;
   
   tubpar[0] = 25.4/2.;
   tubpar[1] = 25.8/2.;
   tubpar[2] = 205.8/2.;
-  gMC->Gsvolu("P009", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P009", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QT08", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT08", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
   
   tubpar[0] = 50./2.;
   tubpar[1] = 50.4/2.;
-  tubpar[2] = 505.4/2.;
-  gMC->Gsvolu("P010", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P010", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
-  
+  // QT09 is 10 cm longer to accomodate TDI
+  tubpar[2] = 515.4/2.;
+  gMC->Gsvolu("QT09", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT09", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  
+  // --- Insert TDI (inside ZDC volume)
+  
+  boxpar[0] = 5.6;
+  boxpar[1] = 5.6;
+  boxpar[2] = 400./2.;
+  gMC->Gsvolu("QTD1", "BOX ", idtmed[7], boxpar, 3);
+  gMC->Gspos("QTD1", 1, "ZDC ", 0., 10.6, tubpar[2] + zd1 + 56.3, 0, "ONLY");
+  gMC->Gspos("QTD1", 2, "ZDC ", 0., -10.6, tubpar[2] + zd1 + 56.3, 0, "ONLY");
+  
+  boxpar[0] = 0.2/2.;
+  boxpar[1] = 5.6;
+  boxpar[2] = 400./2.;
+  gMC->Gsvolu("QTD2", "BOX ", idtmed[6], boxpar, 3);
+  gMC->Gspos("QTD2", 1, "ZDC ", 5.6+boxpar[0], 0., tubpar[2] + zd1 + 56.3, 0, "ONLY");
+  
+  tubspar[0] = 6.2;
+  tubspar[1] = 6.4;
+  tubspar[2] = 400./2.;
+  tubspar[3] = 180.-62.5;
+  tubspar[4] = 180.+62.5;
+  gMC->Gsvolu("QTD3", "TUBS", idtmed[6], tubspar, 5);
+  gMC->Gspos("QTD3", 1, "ZDC ", -3., 0., tubpar[2] + zd1 + 56.3, 0, "ONLY");
+
   zd1 += tubpar[2] * 2.;
   
   tubpar[0] = 50./2.;
   tubpar[1] = 50.4/2.;
-  tubpar[2] = 700./2.;
-  gMC->Gsvolu("P011", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P011", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  // QT10 is 10 cm shorter
+  tubpar[2] = 690./2.;
+  gMC->Gsvolu("QT10", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT10", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
   
   tubpar[0] = 50./2.;
   tubpar[1] = 50.4/2.;
   tubpar[2] = 778.5/2.;
-  gMC->Gsvolu("P012", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P012", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QT11", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT11", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
   
@@ -275,16 +419,16 @@ void AliZDCv1::CreateBeamLine()
   conpar[2] = 50.4/2.;
   conpar[3] = 55./2.;
   conpar[4] = 55.4/2.;
-  gMC->Gsvolu("P013", "CONE", idtmed[5], conpar, 5);
-  gMC->Gspos("P013", 1, "ZDC ", 0., 0., conpar[0] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QC04", "CONE", idtmed[7], conpar, 5);
+  gMC->Gspos("QC04", 1, "ZDC ", 0., 0., conpar[0] + zd1, 0, "ONLY");
   
   zd1 += conpar[0] * 2.;
   
   tubpar[0] = 55./2.;
   tubpar[1] = 55.4/2.;
   tubpar[2] = 730./2.;
-  gMC->Gsvolu("P014", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P014", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QT12", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT12", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
   
@@ -293,105 +437,117 @@ void AliZDCv1::CreateBeamLine()
   conpar[2] = 55.4/2.;
   conpar[3] = 68./2.;
   conpar[4] = 68.4/2.;
-  gMC->Gsvolu("P015", "CONE", idtmed[5], conpar, 5);
-  gMC->Gspos("P015", 1, "ZDC ", 0., 0., conpar[0] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QC05", "CONE", idtmed[7], conpar, 5);
+  gMC->Gspos("QC05", 1, "ZDC ", 0., 0., conpar[0] + zd1, 0, "ONLY");
   
   zd1 += conpar[0] * 2.;
   
   tubpar[0] = 68./2.;
   tubpar[1] = 68.4/2.;
   tubpar[2] = 927.3/2.;
-  gMC->Gsvolu("P016", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P016", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QT13", "TUBE", idtmed[7], tubpar, 3);
+  gMC->Gspos("QT13", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
   
   tubpar[0] = 0./2.;
   tubpar[1] = 68.4/2.;
   tubpar[2] = 0.2/2.;
-  gMC->Gsvolu("P017", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("P017", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
+  gMC->Gsvolu("QT14", "TUBE", idtmed[8], tubpar, 3);
+  gMC->Gspos("QT14", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
   
   tubpar[0] = 0./2.;
-  tubpar[1] = 5./2.;
+  tubpar[1] = 6.4/2.;
   tubpar[2] = 0.2/2.;
-  gMC->Gsvolu("Q017", "TUBE", idtmed[10], tubpar, 3);
+  gMC->Gsvolu("QT15", "TUBE", idtmed[11], tubpar, 3);
   
-  //-- Position Q017 inside P017
-  gMC->Gspos("Q017", 1, "P017", -7.7, 0., 0., 0, "ONLY");
+  //-- Position QT15 inside QT14
+  gMC->Gspos("QT15", 1, "QT14", -7.7, 0., 0., 0, "ONLY");
   
   tubpar[0] = 0./2.;
-  tubpar[1] = 7./2.;
+  tubpar[1] = 6.4/2.;
   tubpar[2] = 0.2/2.;
-  gMC->Gsvolu("R017", "TUBE", idtmed[10], tubpar, 3);
+  gMC->Gsvolu("QT16", "TUBE", idtmed[11], tubpar, 3);
+  
+  //-- Position QT16 inside QT14
+  gMC->Gspos("QT16", 1, "QT14", 7.7, 0., 0., 0, "ONLY");
   
-  //-- Position R017 inside P017
-  gMC->Gspos("R017", 1, "P017", 7.7, 0., 0., 0, "ONLY");
   
   //-- BEAM PIPE BETWEEN END OF CONICAL PIPE AND BEGINNING OF D2
   
-  tubpar[0] = 5./2.;
-  tubpar[1] = 5.4/2.;
-  tubpar[2] = 678./2.;
-  gMC->Gsvolu("P018", "TUBE", idtmed[5], tubpar, 3);
+  tubpar[0] = 6.4/2.;
+  tubpar[1] = 6.8/2.;
+  tubpar[2] = 680.8/2.;
+  gMC->Gsvolu("QT17", "TUBE", idtmed[7], tubpar, 3);
 
-  tubpar[0] = 7./2.;
-  tubpar[1] = 7.4/2.;
-  tubpar[2] = 678./2.;
-  gMC->Gsvolu("P019", "TUBE", idtmed[5], tubpar, 3);
+  tubpar[0] = 6.4/2.;
+  tubpar[1] = 6.8/2.;
+  tubpar[2] = 680.8/2.;
+  gMC->Gsvolu("QT18", "TUBE", idtmed[7], tubpar, 3);
   
   // -- ROTATE PIPES 
 
-  AliMatrix(im1, 90.-0.071, 0., 90., 90., .071, 180.);
-  angle = .071*kDegrad;
-  gMC->Gspos("P018", 1, "ZDC ", TMath::Sin(angle) * 645. / 2. - 9.7 + 
-              TMath::Sin(angle) * 945. / 2., 0., tubpar[2] + zd1, im1, "ONLY");
-  AliMatrix(im2, 90.+0.071, 0., 90., 90., .071, 0.);
-  gMC->Gspos("P019", 1, "ZDC ", 9.7 - TMath::Sin(angle) * 645. / 2., 0., 
-              tubpar[2] + zd1, im2, "ONLY");
-  
-  // --  END OF BEAM PIPE VOLUME DEFINITION. MAGNET DEFINITION FOLLOWS 
-  //     (LHC OPTICS 6) 
-  
+  Float_t angle = 0.143*kDegrad;
+  
+  AliMatrix(im1, 90.-0.143, 0., 90., 90., 0.143, 180.);
+  gMC->Gspos("QT17", 1, "ZDC ", TMath::Sin(angle) * 680.8/ 2. - 9.4, 
+             0., tubpar[2] + zd1, im1, "ONLY");
+            
+  AliMatrix(im2, 90.+0.143, 0., 90., 90., 0.143, 0.);
+  gMC->Gspos("QT18", 1, "ZDC ", 9.7 - TMath::Sin(angle) * 680.8 / 2., 
+             0., tubpar[2] + zd1, im2, "ONLY");
+            
+  
+  // --  END OF BEAM PIPE VOLUME DEFINITION.  
+  // ----------------------------------------------------------------
+   
+  // --  MAGNET DEFINITION  -> LHC OPTICS 6.2 (preliminary version) 
+  
+  // ----------------------------------------------------------------
+  //                   Replaced by the muon dipole
+  // ----------------------------------------------------------------
   // -- COMPENSATOR DIPOLE (MBXW) 
   //     GAP (VACUUM WITH MAGNETIC FIELD) 
   
-  tubpar[0] = 0.;
-  tubpar[1] = 4.5;
-  tubpar[2] = 340./2.;
-  gMC->Gsvolu("MBXW", "TUBE", idtmed[11], tubpar, 3);
-  gMC->Gspos("MBXW", 1, "ZDC ", 0., 0., tubpar[2] + 805., 0, "ONLY");
+//  tubpar[0] = 0.;
+//  tubpar[1] = 4.5;
+//  tubpar[2] = 340./2.;
+//  gMC->Gsvolu("MBXW", "TUBE", idtmed[11], tubpar, 3);
+//  gMC->Gspos("MBXW", 1, "ZDC ", 0., 0., tubpar[2] + 805., 0, "ONLY");
   
   // --  YOKE (IRON WITHOUT MAGNETIC FIELD) 
   
-  tubpar[0] = 4.5;
-  tubpar[1] = 55.;
-  tubpar[2] = 340./2.;
-  gMC->Gsvolu("YMBX", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("YMBX", 1, "ZDC ", 0., 0., tubpar[2] + 805., 0, "ONLY");
+//  tubpar[0] = 4.5;
+//  tubpar[1] = 55.;
+//  tubpar[2] = 340./2.;
+//  gMC->Gsvolu("YMBX", "TUBE", idtmed[7], tubpar, 3);
+//  gMC->Gspos("YMBX", 1, "ZDC ", 0., 0., tubpar[2] + 805., 0, "ONLY");
   
+  // ----------------------------------------------------------------
+  //                 Replaced by the second dipole
+  // ----------------------------------------------------------------
   // -- COMPENSATOR DIPOLE (MCBWA) 
   //     GAP (VACUUM WITH MAGNETIC FIELD) 
   
-  tubpar[0] = 0.;
-  tubpar[1] = 4.5;
-  tubpar[2] = 170./2.;
-  gMC->Gsvolu("MCBW", "TUBE", idtmed[11], tubpar, 3);
-  gMC->Gspos("MCBW", 1, "ZDC ", 0., 0., tubpar[2] + 1921.6, 0, "ONLY");
+//  tubpar[0] = 0.;
+//  tubpar[1] = 4.5;
+//  tubpar[2] = 170./2.;
+//  gMC->Gsvolu("MCBW", "TUBE", idtmed[11], tubpar, 3);
+//  gMC->Gspos("MCBW", 1, "ZDC ", 0., 0., tubpar[2] + 1921.6, 0, "ONLY");
   
   // --  YOKE (IRON WITHOUT MAGNETIC FIELD) 
   
-  tubpar[0] = 4.5;
-  tubpar[1] = 55.;
-  tubpar[2] = 170./2.;
-  gMC->Gsvolu("YMCB", "TUBE", idtmed[5], tubpar, 3);
-  gMC->Gspos("YMCB", 1, "ZDC ", 0., 0., tubpar[2] + 1921.6, 0, "ONLY");
+//  tubpar[0] = 4.5;
+//  tubpar[1] = 55.;
+//  tubpar[2] = 170./2.;
+//  gMC->Gsvolu("YMCB", "TUBE", idtmed[7], tubpar, 3);
+//  gMC->Gspos("YMCB", 1, "ZDC ", 0., 0., tubpar[2] + 1921.6, 0, "ONLY");
   
   // -- INNER TRIPLET 
   
-  zq = 2300.;
+  zq = 2296.5;
   
   // -- DEFINE MQXL AND MQX QUADRUPOLE ELEMENT 
   
@@ -400,15 +556,15 @@ void AliZDCv1::CreateBeamLine()
   
   tubpar[0] = 0.;
   tubpar[1] = 3.5;
-  tubpar[2] = 630./2.;
+  tubpar[2] = 637./2.;
   gMC->Gsvolu("MQXL", "TUBE", idtmed[11], tubpar, 3);
   
   // --  YOKE 
   
   tubpar[0] = 3.5;
   tubpar[1] = 22.;
-  tubpar[2] = 630./2.;
-  gMC->Gsvolu("YMQL", "TUBE", idtmed[5], tubpar, 3);
+  tubpar[2] = 637./2.;
+  gMC->Gsvolu("YMQL", "TUBE", idtmed[7], tubpar, 3);
   
   gMC->Gspos("MQXL", 1, "ZDC ", 0., 0., tubpar[2] + zq, 0, "ONLY");
   gMC->Gspos("YMQL", 1, "ZDC ", 0., 0., tubpar[2] + zq, 0, "ONLY");
@@ -429,13 +585,13 @@ void AliZDCv1::CreateBeamLine()
   tubpar[0] = 3.5;
   tubpar[1] = 22.;
   tubpar[2] = 550./2.;
-  gMC->Gsvolu("YMQ ", "TUBE", idtmed[5], tubpar, 3);
+  gMC->Gsvolu("YMQ ", "TUBE", idtmed[7], tubpar, 3);
   
-  gMC->Gspos("MQX ", 1, "ZDC ", 0., 0., tubpar[2] + zq + 880.,  0, "ONLY");
-  gMC->Gspos("YMQ ", 1, "ZDC ", 0., 0., tubpar[2] + zq + 880.,  0, "ONLY");
+  gMC->Gspos("MQX ", 1, "ZDC ", 0., 0., tubpar[2] + zq + 883.5,  0, "ONLY");
+  gMC->Gspos("YMQ ", 1, "ZDC ", 0., 0., tubpar[2] + zq + 883.5,  0, "ONLY");
   
-  gMC->Gspos("MQX ", 2, "ZDC ", 0., 0., tubpar[2] + zq + 1530., 0, "ONLY");
-  gMC->Gspos("YMQ ", 2, "ZDC ", 0., 0., tubpar[2] + zq + 1530., 0, "ONLY");
+  gMC->Gspos("MQX ", 2, "ZDC ", 0., 0., tubpar[2] + zq + 1533.5, 0, "ONLY");
+  gMC->Gspos("YMQ ", 2, "ZDC ", 0., 0., tubpar[2] + zq + 1533.5, 0, "ONLY");
   
   // -- SEPARATOR DIPOLE D1 
   
@@ -444,19 +600,29 @@ void AliZDCv1::CreateBeamLine()
   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
   
   tubpar[0] = 0.;
-  tubpar[1] = 7.5/2.;
+  tubpar[1] = 6.94/2.;
   tubpar[2] = 945./2.;
-  gMC->Gsvolu("D1  ", "TUBE", idtmed[11], tubpar, 3);
+  gMC->Gsvolu("MD1 ", "TUBE", idtmed[11], tubpar, 3);
   
+  // --  Insert horizontal Cu plates inside D1 
+  // --   (to simulate the vacuum chamber)
+  
+  boxpar[0] = TMath::Sqrt(tubpar[1]*tubpar[1]-(2.98+0.2)*(2.98+0.2));
+  boxpar[1] = 0.2/2.;
+  boxpar[2] =945./2.;
+  gMC->Gsvolu("MD1V", "BOX ", idtmed[6], boxpar, 3);
+  gMC->Gspos("MD1V", 1, "MD1 ", 0., 2.98+boxpar[1], 0., 0, "ONLY");
+  gMC->Gspos("MD1V", 2, "MD1 ", 0., -2.98-boxpar[1], 0., 0, "ONLY");
+    
   // --  YOKE 
   
   tubpar[0] = 0.;
   tubpar[1] = 110./2;
   tubpar[2] = 945./2.;
-  gMC->Gsvolu("YD1 ", "TUBE", idtmed[5], tubpar, 3);
+  gMC->Gsvolu("YD1 ", "TUBE", idtmed[7], tubpar, 3);
   
   gMC->Gspos("YD1 ", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
-  gMC->Gspos("D1  ", 1, "YD1 ", 0., 0., 0., 0, "ONLY");
+  gMC->Gspos("MD1 ", 1, "YD1 ", 0., 0., 0., 0, "ONLY");
   
   // -- DIPOLE D2 
   
@@ -467,19 +633,19 @@ void AliZDCv1::CreateBeamLine()
   tubpar[0] = 0.;
   tubpar[1] = 7.5/2.;
   tubpar[2] = 945./2.;
-  gMC->Gsvolu("D2  ", "TUBE", idtmed[11], tubpar, 3);
+  gMC->Gsvolu("MD2 ", "TUBE", idtmed[11], tubpar, 3);
   
   // --  YOKE 
   
   tubpar[0] = 0.;
   tubpar[1] = 55.;
   tubpar[2] = 945./2.;
-  gMC->Gsvolu("YD2 ", "TUBE", idtmed[5], tubpar, 3);
+  gMC->Gsvolu("YD2 ", "TUBE", idtmed[7], tubpar, 3);
   
   gMC->Gspos("YD2 ", 1, "ZDC ", 0., 0., tubpar[2] + zd2, 0, "ONLY");
   
-  gMC->Gspos("D2  ", 1, "YD2 ", -9.7, 0., 0., 0, "ONLY");
-  gMC->Gspos("D2  ", 2, "YD2 ",  9.7, 0., 0., 0, "ONLY");
+  gMC->Gspos("MD2 ", 1, "YD2 ", -9.4, 0., 0., 0, "ONLY");
+  gMC->Gspos("MD2 ", 2, "YD2 ",  9.4, 0., 0., 0, "ONLY");
   
   // -- END OF MAGNET DEFINITION 
 }
@@ -488,10 +654,35 @@ void AliZDCv1::CreateBeamLine()
 void AliZDCv1::CreateZDC()
 {
   
+  Float_t DimPb[6], DimVoid[6];
+  
   Int_t *idtmed = fIdtmed->GetArray();
+
+  // Parameters for hadronic calorimeters geometry
+  // NB -> parameters used ONLY in CreateZDC()
+  Float_t fDimZN[3] = {3.52, 3.52, 50.};  // Dimensions of neutron detector
+  Float_t fGrvZN[3] = {0.03, 0.03, 50.};  // Grooves for neutron detector
+  Float_t fGrvZP[3] = {0.04, 0.04, 75.};  // Grooves for proton detector
+  Int_t   fDivZN[3] = {11, 11, 0};       // Division for neutron detector
+  Int_t   fDivZP[3] = {7, 15, 0};        // Division for proton detector
+  Int_t   fTowZN[2] = {2, 2};                    // Tower for neutron detector
+  Int_t   fTowZP[2] = {4, 1};                    // Tower for proton detector
+
+  // Parameters for EM calorimeter geometry
+  // NB -> parameters used ONLY in CreateZDC()
+  Float_t fDimZEMPb  = 0.15*(TMath::Sqrt(2.));  // z-dimension of the Pb slice
+  Float_t fDimZEMAir = 0.001;                  // scotch
+  Float_t fFibRadZEM = 0.0315;                         // External fiber radius (including cladding)
+  Int_t   fDivZEM[3] = {92, 0, 20};            // Divisions for EM detector
+  Float_t fDimZEM0 = 2*fDivZEM[2]*(fDimZEMPb+fDimZEMAir+fFibRadZEM*(TMath::Sqrt(2.)));
+  Float_t fDimZEM[6] = {fDimZEM0, 3.5, 3.5, 45., 0., 0.}; // Dimensions of EM detector
+  Float_t fFibZEM2 = fDimZEM[2]/TMath::Sin(fDimZEM[3]*kDegrad)-fFibRadZEM;
+  Float_t fFibZEM[3] = {0., 0.0275, fFibZEM2};  // Fibers for EM calorimeter
+
   
   //-- Create calorimeters geometry
   
+  // -------------------------------------------------------------------------------
   //--> Neutron calorimeter (ZN) 
   
   gMC->Gsvolu("ZNEU", "BOX ", idtmed[1], fDimZN, 3); // Passive material  
@@ -535,7 +726,9 @@ void AliZDCv1::CreateZDC()
   // --- Position the neutron calorimeter in ZDC 
   gMC->Gspos("ZNEU", 1, "ZDC ", fPosZN[0], fPosZN[1], fPosZN[2] + fDimZN[2], 0, "ONLY");
   
-  //--> Proton calorimeter 
+
+  // -------------------------------------------------------------------------------
+  //--> Proton calorimeter (ZP)  
   
   gMC->Gsvolu("ZPRO", "BOX ", idtmed[2], fDimZP, 3); // Passive material
   gMC->Gsvolu("ZPF1", "TUBE", idtmed[3], fFibZP, 3); // Active material
@@ -579,6 +772,68 @@ void AliZDCv1::CreateZDC()
 
   // --- Position the proton calorimeter in ZDC 
   gMC->Gspos("ZPRO", 1, "ZDC ", fPosZP[0], fPosZP[1], fPosZP[2] + fDimZP[2], 0, "ONLY");
+    
+  
+  // -------------------------------------------------------------------------------
+  // -> EM calorimeter (ZEM)  
+  
+  gMC->Gsvolu("ZEM ", "PARA", idtmed[10], fDimZEM, 6);
+
+  Int_t irot1, irot2;
+  
+  gMC->Matrix(irot1,0.,0.,90.,90.,90.,180.);                   // Rotation matrix 1  
+  gMC->Matrix(irot2,180.,0.,90.,fDimZEM[3]+90.,90.,fDimZEM[3]); // Rotation matrix 2
+//  printf("irot1 = %d, irot2 = %d \n", irot1, irot2);
+  
+  gMC->Gsvolu("ZEMF", "TUBE", idtmed[3], fFibZEM, 3); // Active material
+
+  gMC->Gsdvn("ZETR", "ZEM ", fDivZEM[2], 1);        // Tranches 
+  
+  DimPb[0] = fDimZEMPb;                        // Lead slices 
+  DimPb[1] = fDimZEM[2];
+  DimPb[2] = fDimZEM[1];
+  DimPb[3] = 90.-fDimZEM[3];
+  DimPb[4] = 0.;
+  DimPb[5] = 0.;
+  gMC->Gsvolu("ZEL0", "PARA", idtmed[5], DimPb, 6);
+  gMC->Gsvolu("ZEL1", "PARA", idtmed[5], DimPb, 6);
+  gMC->Gsvolu("ZEL2", "PARA", idtmed[5], DimPb, 6);
+  
+  // --- Position the lead slices in the tranche 
+  Float_t zTran = fDimZEM[0]/fDivZEM[2]; 
+  Float_t zTrPb = -zTran+fDimZEMPb;
+  gMC->Gspos("ZEL0", 1, "ZETR", zTrPb, 0., 0., 0, "ONLY");
+  gMC->Gspos("ZEL1", 1, "ZETR", fDimZEMPb, 0., 0., 0, "ONLY");
+  
+  // --- Vacuum zone (to be filled with fibres)
+  DimVoid[0] = (zTran-2*fDimZEMPb)/2.;
+  DimVoid[1] = fDimZEM[2];
+  DimVoid[2] = fDimZEM[1];
+  DimVoid[3] = 90.-fDimZEM[3];
+  DimVoid[4] = 0.;
+  DimVoid[5] = 0.;
+  gMC->Gsvolu("ZEV0", "PARA", idtmed[10], DimVoid,6);
+  gMC->Gsvolu("ZEV1", "PARA", idtmed[10], DimVoid,6);
+  
+  // --- Divide the vacuum slice into sticks along x axis
+  gMC->Gsdvn("ZES0", "ZEV0", fDivZEM[0], 3); 
+  gMC->Gsdvn("ZES1", "ZEV1", fDivZEM[0], 3); 
+  
+  // --- Positioning the fibers into the sticks
+  gMC->Gspos("ZEMF", 1,"ZES0", 0., 0., 0., irot2, "ONLY");
+  gMC->Gspos("ZEMF", 1,"ZES1", 0., 0., 0., irot2, "ONLY");
+  
+  // --- Positioning the vacuum slice into the tranche
+  Float_t DisplFib = fDimZEM[1]/fDivZEM[0];
+  gMC->Gspos("ZEV0", 1,"ZETR", -DimVoid[0], 0., 0., 0, "ONLY");
+  gMC->Gspos("ZEV1", 1,"ZETR", -DimVoid[0]+zTran, 0., DisplFib, 0, "ONLY");
+
+  // --- Positioning the ZEM into the ZDC - rotation for 90 degrees  
+  gMC->Gspos("ZEM ", 1,"ZDC ", fPosZEM[0], fPosZEM[1], fPosZEM[2], irot1, "ONLY");
+  
+  // --- Adding last slice at the end of the EM calorimeter 
+  Float_t zLastSlice = fPosZEM[2]+fDimZEMPb+fDimZEM[0];
+  gMC->Gspos("ZEL2", 1,"ZDC ", fPosZEM[0], fPosZEM[1], zLastSlice, irot1, "ONLY");
   
 }
  
@@ -597,43 +852,41 @@ void AliZDCv1::DrawModule()
   //
   // Set the volumes visible
   gMC->Gsatt("ZDC ","SEEN",0);
-  gMC->Gsatt("P001","SEEN",1);
-  gMC->Gsatt("E001","SEEN",1);
-  gMC->Gsatt("E002","SEEN",1);
-  gMC->Gsatt("E003","SEEN",1);
-  gMC->Gsatt("E004","SEEN",1);
-  gMC->Gsatt("C001","SEEN",1);
-  gMC->Gsatt("P002","SEEN",1);
-  gMC->Gsatt("P003","SEEN",1);
-  gMC->Gsatt("P004","SEEN",1);
-  gMC->Gsatt("P005","SEEN",1);
-  gMC->Gsatt("P006","SEEN",1);
-  gMC->Gsatt("P007","SEEN",1);
-  gMC->Gsatt("P008","SEEN",1);
-  gMC->Gsatt("P009","SEEN",1);
-  gMC->Gsatt("P010","SEEN",1);
-  gMC->Gsatt("P011","SEEN",1);
-  gMC->Gsatt("P012","SEEN",1);
-  gMC->Gsatt("P013","SEEN",1);
-  gMC->Gsatt("P014","SEEN",1);
-  gMC->Gsatt("P015","SEEN",1);
-  gMC->Gsatt("P016","SEEN",1);
-  gMC->Gsatt("P017","SEEN",1);
-  gMC->Gsatt("Q017","SEEN",1);
-  gMC->Gsatt("R017","SEEN",1);
-  gMC->Gsatt("P018","SEEN",1);
-  gMC->Gsatt("P019","SEEN",1);
-  gMC->Gsatt("MBXW","SEEN",1);
-  gMC->Gsatt("YMBX","SEEN",1);
-  gMC->Gsatt("MCBW","SEEN",1);
-  gMC->Gsatt("YMCB","SEEN",1);
+  gMC->Gsatt("QT01","SEEN",1);
+  gMC->Gsatt("QT02","SEEN",1);
+  gMC->Gsatt("QT03","SEEN",1);
+  gMC->Gsatt("QT04","SEEN",1);
+  gMC->Gsatt("QT05","SEEN",1);
+  gMC->Gsatt("QT06","SEEN",1);
+  gMC->Gsatt("QT07","SEEN",1);
+  gMC->Gsatt("QT08","SEEN",1);
+  gMC->Gsatt("QT09","SEEN",1);
+  gMC->Gsatt("QT10","SEEN",1);
+  gMC->Gsatt("QT11","SEEN",1);
+  gMC->Gsatt("QT12","SEEN",1);
+  gMC->Gsatt("QT13","SEEN",1);
+  gMC->Gsatt("QT14","SEEN",1);
+  gMC->Gsatt("QT15","SEEN",1);
+  gMC->Gsatt("QT16","SEEN",1);
+  gMC->Gsatt("QT17","SEEN",1);
+  gMC->Gsatt("QT18","SEEN",1);
+  gMC->Gsatt("QC01","SEEN",1);
+  gMC->Gsatt("QC02","SEEN",1);
+  gMC->Gsatt("QC03","SEEN",1);
+  gMC->Gsatt("QC04","SEEN",1);
+  gMC->Gsatt("QC05","SEEN",1);
+  gMC->Gsatt("QTD1","SEEN",1);
+  gMC->Gsatt("QTD2","SEEN",1);
+  gMC->Gsatt("QTD3","SEEN",1);
   gMC->Gsatt("MQXL","SEEN",1);
   gMC->Gsatt("YMQL","SEEN",1);
   gMC->Gsatt("MQX ","SEEN",1);
   gMC->Gsatt("YMQ ","SEEN",1);
-  gMC->Gsatt("D1  ","SEEN",1);
+  gMC->Gsatt("ZQYX","SEEN",1);
+  gMC->Gsatt("MD1 ","SEEN",1);
+  gMC->Gsatt("MD1V","SEEN",1);
   gMC->Gsatt("YD1 ","SEEN",1);
-  gMC->Gsatt("D2  ","SEEN",1);
+  gMC->Gsatt("MD2 ","SEEN",1);
   gMC->Gsatt("YD2 ","SEEN",1);
   gMC->Gsatt("ZNEU","SEEN",0);
   gMC->Gsatt("ZNF1","SEEN",0);
@@ -645,7 +898,7 @@ void AliZDCv1::DrawModule()
   gMC->Gsatt("ZNG3","SEEN",0);
   gMC->Gsatt("ZNG4","SEEN",0);
   gMC->Gsatt("ZNTX","SEEN",0);
-  gMC->Gsatt("ZN1 ","COLO",2); 
+  gMC->Gsatt("ZN1 ","COLO",4); 
   gMC->Gsatt("ZN1 ","SEEN",1);
   gMC->Gsatt("ZNSL","SEEN",0);
   gMC->Gsatt("ZNST","SEEN",0);
@@ -659,10 +912,21 @@ void AliZDCv1::DrawModule()
   gMC->Gsatt("ZPG3","SEEN",0);
   gMC->Gsatt("ZPG4","SEEN",0);
   gMC->Gsatt("ZPTX","SEEN",0);
-  gMC->Gsatt("ZP1 ","COLO",2); 
+  gMC->Gsatt("ZP1 ","COLO",6); 
   gMC->Gsatt("ZP1 ","SEEN",1);
   gMC->Gsatt("ZPSL","SEEN",0);
   gMC->Gsatt("ZPST","SEEN",0);
+  gMC->Gsatt("ZEM ","COLO",7); 
+  gMC->Gsatt("ZEM ","SEEN",1);
+  gMC->Gsatt("ZEMF","SEEN",0);
+  gMC->Gsatt("ZETR","SEEN",0);
+  gMC->Gsatt("ZEL0","SEEN",0);
+  gMC->Gsatt("ZEL1","SEEN",0);
+  gMC->Gsatt("ZEL2","SEEN",0);
+  gMC->Gsatt("ZEV0","SEEN",0);
+  gMC->Gsatt("ZEV1","SEEN",0);
+  gMC->Gsatt("ZES0","SEEN",0);
+  gMC->Gsatt("ZES1","SEEN",0);
   
   //
   gMC->Gdopt("hide", "on");
@@ -682,22 +946,11 @@ void AliZDCv1::CreateMaterials()
   //
   // Create Materials for the Zero Degree Calorimeter
   //
-  // Origin    : E. Scomparin 
   
   Int_t *idtmed = fIdtmed->GetArray();
   
-  Float_t dens, ubuf[1], wmat[2];
-  Int_t isvolActive;
-  Float_t a[2];
+  Float_t dens, ubuf[1], wmat[2], a[2], z[2], deemax = -1;
   Int_t i;
-  Float_t z[2], epsil=0.001, stmin=0.01;
-  Int_t isvol;
-  Float_t fieldm = gAlice->Field()->Max();
-  Int_t inofld;
-  Float_t deemax=-1;
-  Float_t tmaxfd=gAlice->Field()->Max();
-  Int_t isxfld = gAlice->Field()->Integ();
-  Float_t stemax;
   
   // --- Store in UBUF r0 for nuclear radius calculation R=r0*A**1/3 
 
@@ -727,20 +980,23 @@ void AliZDCv1::CreateMaterials()
   z[1] = 8.;
   wmat[0] = 1.;
   wmat[1] = 2.;
-  AliMixture(3, "SIO2                ", a, z, dens, -2, wmat);
+  AliMixture(3, "SIO2                ", a, z, dens, -2, wmat);  
+  
+  // --- Lead 
+  ubuf[0] = 1.12;
+  AliMaterial(5, "LEAD", 207.19, 82., 11.35, .56, 18.5, ubuf, 1);
 
   // --- Copper 
-//  ubuf[0] = 1.1;
-//  AliMaterial(7, "COPP", 63.54, 29., 8.96, 1.4, 0., ubuf, 1);
-  
+  ubuf[0] = 1.10;
+  AliMaterial(6, "COPP", 63.54, 29., 8.96, 1.4, 0., ubuf, 1);
   
-  // --- Lead 
-//  ubuf[0] = 1.12;
-//  AliMaterial(6, "LEAD", 207.19, 82., 11.35, .56, 18.5, ubuf, 1);
+  // --- Iron (energy loss taken into account)
+  ubuf[0] = 1.1;
+  AliMaterial(7, "IRON", 55.85, 26., 7.87, 1.76, 0., ubuf, 1);
   
-  // --- Iron 
+  // --- Iron (no energy loss)
   ubuf[0] = 1.1;
-  AliMaterial(5, "IRON", 55.85, 26., 7.87, 1.76, 0., ubuf, 1);
+  AliMaterial(8, "IRON", 55.85, 26., 7.87, 1.76, 0., ubuf, 1);
   
   // --- Vacuum (no magnetic field) 
   AliMaterial(10, "VOID", 1e-16, 1e-16, 1e-16, 1e16, 1e16, ubuf,0);
@@ -757,58 +1013,65 @@ void AliZDCv1::CreateMaterials()
   // --- Brass = 2 ; 
   // --- Fibers (SiO2) = 3 ; 
   // --- Fibers (SiO2) = 4 ; 
-  // --- Iron = 5 ; 
-  // --- Lead = 6 ; 
+  // --- Lead = 5 ; 
+  // --- Copper = 6 ; 
+  // --- Iron (with energy loss) = 7 ; 
+  // --- Iron (without energy loss) = 8 ; 
   // --- Vacuum (no field) = 10 
   // --- Vacuum (with field) = 11 
   // --- Air (no field) = 12 
   
   
   // --- Tracking media parameters 
-  epsil  = .01;
-  stemax = 1.;
-  isvol  = 0;
-  isvolActive = 1;
-  inofld = 0;
-  fieldm = 0.;
+  Float_t epsil  = .01, stmin=0.01, stemax = 1.;
+  Int_t   isxfld = gAlice->Field()->Integ();
+  Float_t fieldm = gAlice->Field()->Max();
+  Int_t   ifield = 0, isvolActive = 1, isvol = 0, inofld = 0;
   
+  fieldm = 0.;
+  Float_t tmaxfd = 0.;
   AliMedium(1, "ZTANT", 1, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
 //  AliMedium(1, "ZW", 1, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
-  AliMedium(2, "ZBRASS", 2, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
+  AliMedium(2, "ZBRASS",2, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
   AliMedium(3, "ZSIO2", 3, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
   AliMedium(4, "ZQUAR", 3, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
-//  AliMedium(7, "ZCOPP", 7, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
-//  AliMedium(6, "ZLEAD", 6, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
-  AliMedium(5, "ZIRON", 5, isvol, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
-  AliMedium(10, "ZVOID", 10, isvol, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
-  AliMedium(12, "ZAIR", 12, 0, inofld, fieldm, tmaxfd, stemax,deemax, epsil, stmin);
-  
+  AliMedium(5, "ZLEAD", 5, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
+  AliMedium(6, "ZCOPP", 6, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
+  AliMedium(7, "ZIRON", 7, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
+  AliMedium(8, "ZIRONN",8, isvol, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
+  AliMedium(10,"ZVOID",10, isvol, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
+  AliMedium(12,"ZAIR", 12, 0, inofld, fieldm, tmaxfd, stemax,deemax, epsil, stmin);
+  
+  ifield =2;
   fieldm = 45.;
   AliMedium(11, "ZVOIM", 11, isvol, isxfld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
   
   // Thresholds for showering in the ZDCs 
-  
-  i = 1;
+  i = 1; //tantalum
+  gMC->Gstpar(idtmed[i], "CUTGAM", .001);
+  gMC->Gstpar(idtmed[i], "CUTELE", .001);
+  gMC->Gstpar(idtmed[i], "CUTNEU", .01);
+  gMC->Gstpar(idtmed[i], "CUTHAD", .01);
+  i = 2; //brass
   gMC->Gstpar(idtmed[i], "CUTGAM", .001);
   gMC->Gstpar(idtmed[i], "CUTELE", .001);
   gMC->Gstpar(idtmed[i], "CUTNEU", .01);
   gMC->Gstpar(idtmed[i], "CUTHAD", .01);
-  i = 2;
+  i = 5; //lead
   gMC->Gstpar(idtmed[i], "CUTGAM", .001);
   gMC->Gstpar(idtmed[i], "CUTELE", .001);
   gMC->Gstpar(idtmed[i], "CUTNEU", .01);
   gMC->Gstpar(idtmed[i], "CUTHAD", .01);
   
   // Avoid too detailed showering along the beam line 
-  
-  i = 5;
+  i = 7; //iron with energy loss (ZIRON)
   gMC->Gstpar(idtmed[i], "CUTGAM", .1);
   gMC->Gstpar(idtmed[i], "CUTELE", .1);
   gMC->Gstpar(idtmed[i], "CUTNEU", 1.);
   gMC->Gstpar(idtmed[i], "CUTHAD", 1.);
   
   // Avoid interaction in fibers (only energy loss allowed) 
-  i = 3;
+  i = 3; //fibers (ZSI02)
   gMC->Gstpar(idtmed[i], "DCAY", 0.);
   gMC->Gstpar(idtmed[i], "MULS", 0.);
   gMC->Gstpar(idtmed[i], "PFIS", 0.);
@@ -821,7 +1084,7 @@ void AliZDCv1::CreateMaterials()
   gMC->Gstpar(idtmed[i], "DRAY", 0.);
   gMC->Gstpar(idtmed[i], "ANNI", 0.);
   gMC->Gstpar(idtmed[i], "HADR", 0.);
-  i = 4;
+  i = 4; //fibers (ZQUAR)
   gMC->Gstpar(idtmed[i], "DCAY", 0.);
   gMC->Gstpar(idtmed[i], "MULS", 0.);
   gMC->Gstpar(idtmed[i], "PFIS", 0.);
@@ -834,50 +1097,70 @@ void AliZDCv1::CreateMaterials()
   gMC->Gstpar(idtmed[i], "DRAY", 0.);
   gMC->Gstpar(idtmed[i], "ANNI", 0.);
   gMC->Gstpar(idtmed[i], "HADR", 0.);
+  
+  // Avoid interaction in void 
+//  i = 10; //void
+//  gMC->Gstpar(idtmed[i], "DCAY", 0.);
+//  gMC->Gstpar(idtmed[i], "MULS", 0.);
+//  gMC->Gstpar(idtmed[i], "PFIS", 0.);
+//  gMC->Gstpar(idtmed[i], "MUNU", 0.);
+//  gMC->Gstpar(idtmed[i], "LOSS", 0.);
+//  gMC->Gstpar(idtmed[i], "PHOT", 0.);
+//  gMC->Gstpar(idtmed[i], "COMP", 0.);
+//  gMC->Gstpar(idtmed[i], "PAIR", 0.);
+//  gMC->Gstpar(idtmed[i], "BREM", 0.);
+//  gMC->Gstpar(idtmed[i], "DRAY", 0.);
+//  gMC->Gstpar(idtmed[i], "ANNI", 0.);
+//  gMC->Gstpar(idtmed[i], "HADR", 0.);
+
   //
-  fMedSensF1 = idtmed[3];  // Sensitive volume: fibres type 1
-  fMedSensF2 = idtmed[4];  // Sensitive volume: fibres type 2
-  fMedSensZN = idtmed[1];  // Sensitive volume: ZN passive material
-  fMedSensZP = idtmed[2];  // Sensitive volume: ZP passive material
-  fMedSensGR = idtmed[12]; // Sensitive volume: air into the grooves
+  fMedSensZN  = idtmed[1];  // Sensitive volume: ZN passive material
+  fMedSensZP  = idtmed[2];  // Sensitive volume: ZP passive material
+  fMedSensF1  = idtmed[3];  // Sensitive volume: fibres type 1
+  fMedSensF2  = idtmed[4];  // Sensitive volume: fibres type 2
+  fMedSensZEM = idtmed[5];  // Sensitive volume: ZEM passive material
+  fMedSensTDI = idtmed[6];  // Sensitive volume: TDI Cu shield
+  fMedSensPI  = idtmed[7];  // Sensitive volume: beam pipes
+  fMedSensGR  = idtmed[12]; // Sensitive volume: air into the grooves
 } 
 
 //_____________________________________________________________________________
 void AliZDCv1::Init()
 {
  InitTables();
-
 }
 
 //_____________________________________________________________________________
 void AliZDCv1::InitTables()
 {
   Int_t k, j;
-  //Initialize parameters for light tables and read them
-  fNalfan = 90;
-  fNalfap = 90;
-  fNben = 18;
-  fNbep = 28;
-  
+
+  char *lightfName1,*lightfName2,*lightfName3,*lightfName4,
+       *lightfName5,*lightfName6,*lightfName7,*lightfName8;
   FILE *fp1, *fp2, *fp3, *fp4, *fp5, *fp6, *fp7, *fp8;
 
-  if((fp1 = fopen("light22620362207s","r")) == NULL){
+  //  --- Reading light tables for ZN 
+  lightfName1 = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/light22620362207s");
+  if((fp1 = fopen(lightfName1,"r")) == NULL){
      printf("Cannot open file fp1 \n");
      return;
   }
-  if((fp2 = fopen("light22620362208s","r")) == NULL){
+  lightfName2 = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/light22620362208s");
+  if((fp2 = fopen(lightfName2,"r")) == NULL){
      printf("Cannot open file fp2 \n");
      return;
   }  
-  if((fp3 = fopen("light22620362209s","r")) == NULL){
+  lightfName3 = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/light22620362209s");
+  if((fp3 = fopen(lightfName3,"r")) == NULL){
      printf("Cannot open file fp3 \n");
      return;
   }
-  if((fp4 = fopen("light22620362210s","r")) == NULL){
+  lightfName4 = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/light22620362210s");
+  if((fp4 = fopen(lightfName4,"r")) == NULL){
      printf("Cannot open file fp4 \n");
      return;
   }
-//  printf(" --- Reading light tables for ZN \n");
+  
   for(k=0; k<fNalfan; k++){
      for(j=0; j<fNben; j++){
        fscanf(fp1,"%f",&fTablen[0][k][j]);
@@ -891,23 +1174,28 @@ void AliZDCv1::InitTables()
   fclose(fp3);
   fclose(fp4);
   
-  if((fp5 = fopen("light22620552207s","r")) == NULL){
+  //  --- Reading light tables for ZP and ZEM
+  lightfName5 = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/light22620552207s");
+  if((fp5 = fopen(lightfName5,"r")) == NULL){
      printf("Cannot open file fp5 \n");
      return;
   }
-  if((fp6 = fopen("light22620552208s","r")) == NULL){
+  lightfName6 = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/light22620552208s");
+  if((fp6 = fopen(lightfName6,"r")) == NULL){
      printf("Cannot open file fp6 \n");
      return;
   }
-  if((fp7 = fopen("light22620552209s","r")) == NULL){
+  lightfName7 = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/light22620552209s");
+  if((fp7 = fopen(lightfName7,"r")) == NULL){
      printf("Cannot open file fp7 \n");
      return;
   }
-  if((fp8 = fopen("light22620552210s","r")) == NULL){
+  lightfName8 = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/light22620552210s");
+  if((fp8 = fopen(lightfName8,"r")) == NULL){
      printf("Cannot open file fp8 \n");
      return;
   }
-//  printf(" --- Reading light tables for ZP \n");
+  
   for(k=0; k<fNalfap; k++){
      for(j=0; j<fNbep; j++){
        fscanf(fp5,"%f",&fTablep[0][k][j]);
@@ -922,6 +1210,164 @@ void AliZDCv1::InitTables()
   fclose(fp8);
 }
 
+//_____________________________________________________________________________
+Int_t AliZDCv1::Digitize(Int_t Det, Int_t Quad, Int_t Light)
+{
+  // Evaluation of the ADC channel corresponding to the light yield Light
+
+  if(fDebug == 1){
+    printf("\n Digitize -> Det = %d, Quad = %d, Light = %d\n", Det, Quad, Light);
+  }   
+  
+  // Parameters for conversion of light yield in ADC channels
+  Float_t fPMGain[3][5];      // PM gain
+  Float_t fADCRes;            // ADC conversion factor
+  
+  Int_t j,i;
+  for(i=0; i<3; i++){
+     for(j=0; j<5; j++){
+        fPMGain[i][j]   = 100000.;
+     }
+  }
+  fADCRes   = 0.00000064; // ADC Resolution: 250 fC/ADCch
+  
+  Int_t ADCch = Int_t(Light*fPMGain[Det-1][Quad]*fADCRes);
+     
+  return ADCch;
+}
+
+
+//_____________________________________________________________________________
+void AliZDCv1::SDigits2Digits()
+{
+   Hits2Digits(gAlice->GetNtrack());
+}
+
+//_____________________________________________________________________________
+void AliZDCv1::Hits2Digits(Int_t ntracks)
+{
+  AliZDCDigit *newdigit;
+  AliZDCHit   *hit;
+
+  Int_t PMCZN = 0, PMCZP = 0, PMQZN[4], PMQZP[4], PMZEM = 0;
+  
+  Int_t i;
+  for(i=0; i<4; i++){
+     PMQZN[i] =0;
+     PMQZP[i] =0;
+  }
+  
+  Int_t itrack = 0;
+  for(itrack=0; itrack<ntracks; itrack++){
+     gAlice->ResetHits();
+     gAlice->TreeH()->GetEvent(itrack);
+     for(i=0; i<fHits->GetEntries(); i++){
+        hit = (AliZDCHit*)fHits->At(i);
+        Int_t det   = hit->GetVolume(0);
+        Int_t quad  = hit->GetVolume(1);
+        Int_t lightQ = Int_t(hit->GetLightPMQ());
+        Int_t lightC = Int_t(hit->GetLightPMC());
+       if(fDebug == 1)
+          printf("        \n itrack = %d, fNhits = %d, det = %d, quad = %d,"
+         "lightC = %d lightQ = %d\n", itrack, fNhits, det, quad, lightC, lightQ);
+           
+        if(det == 1){   //ZN 
+          PMCZN = PMCZN + lightC;
+          PMQZN[quad-1] = PMQZN[quad-1] + lightQ;
+        }
+
+        if(det == 2){   //ZP 
+          PMCZP = PMCZP + lightC;
+          PMQZP[quad-1] = PMQZP[quad-1] + lightQ;
+        }
+
+        if(det == 3){   //ZEM 
+          PMZEM = PMZEM + lightC;
+        }
+     } // Hits loop
+  
+  } // Tracks loop
+  
+     if(fDebug == 1){
+       printf("\n       PMCZN = %d, PMQZN[0] = %d, PMQZN[1] = %d, PMQZN[2] = %d, PMQZN[3] = %d\n"
+           , PMCZN, PMQZN[0], PMQZN[1], PMQZN[2], PMQZN[3]);
+       printf("\n       PMCZP = %d, PMQZP[0] = %d, PMQZP[1] = %d, PMQZP[2] = %d, PMQZP[3] = %d\n"
+           , PMCZP, PMQZP[0], PMQZP[1], PMQZP[2], PMQZP[3]);
+       printf("\n       PMZEM = %d\n", PMZEM);
+     }
+
+  // ------------------------------------    Hits2Digits
+  // Digits for ZN
+     newdigit = new AliZDCDigit(1, 0, Digitize(1, 0, PMCZN));
+     new((*fDigits)[fNdigits]) AliZDCDigit(*newdigit);
+     fNdigits++;
+     delete newdigit;
+  
+     Int_t j;
+     for(j=0; j<4; j++){
+        newdigit = new AliZDCDigit(1, j+1, Digitize(1, j+1, PMQZN[j]));
+        new((*fDigits)[fNdigits]) AliZDCDigit(*newdigit);
+        fNdigits++;
+        delete newdigit;
+     }
+  
+     // Digits for ZP
+     newdigit = new AliZDCDigit(2, 0, Digitize(2, 0, PMCZP));
+     new((*fDigits)[fNdigits]) AliZDCDigit(*newdigit);
+     fNdigits++;
+     delete newdigit;
+  
+     Int_t k;
+     for(k=0; k<4; k++){
+        newdigit = new AliZDCDigit(2, k+1, Digitize(2, k+1, PMQZP[k]));
+        new((*fDigits)[fNdigits]) AliZDCDigit(*newdigit);
+        fNdigits++;
+        delete newdigit;
+     }
+  
+     // Digits for ZEM
+     newdigit = new AliZDCDigit(3, 0, Digitize(3, 0, PMZEM));
+     new((*fDigits)[fNdigits]) AliZDCDigit(*newdigit);
+     fNdigits++;
+     delete newdigit;
+      
+  
+  gAlice->TreeD()->Fill();
+  gAlice->TreeD()->Write(0,TObject::kOverwrite);
+
+//  if(fDebug == 1){
+//    printf("\n  Event Digits -----------------------------------------------------\n");  
+//    fDigits->Print("");
+//  }
+  
+}
+//_____________________________________________________________________________
+ void AliZDCv1::MakeBranch(Option_t *opt, char *file)
+{
+  //
+  // Create a new branch in the current Root Tree
+  //
+
+  AliDetector::MakeBranch(opt);
+  
+  Char_t branchname[10];
+  sprintf(branchname,"%s",GetName());
+  const char *cD = strstr(opt,"D");
+
+  if (gAlice->TreeD() && cD) {
+
+    // Creation of the digits from hits 
+
+    if(fDigits!=0) fDigits->Clear();
+    else fDigits = new TClonesArray ("AliZDCDigit",1000);
+    char branchname[10];
+    sprintf(branchname,"%s",GetName());
+    gAlice->MakeBranchInTree(gAlice->TreeD(), 
+                             branchname, &fDigits, fBufferSize, file) ;
+    printf("* AliZDCv1::MakeBranch    * Making Branch %s for digits\n\n",branchname);
+  }
+       
+}
 //_____________________________________________________________________________
 void AliZDCv1::StepManager()
 {
@@ -929,17 +1375,36 @@ void AliZDCv1::StepManager()
   // Routine called at every step in the Zero Degree Calorimeters
   //
 
-  Int_t j;
-
-  Int_t vol[2], ibeta, ialfa, ibe;
-  Float_t x[3], xdet[3], destep, hits[9], m, ekin, um[3], ud[3], be, radius, out;
+  Int_t j, vol[2], ibeta=0, ialfa, ibe, nphe;
+  Float_t x[3], xdet[3], destep, hits[10], m, ekin, um[3], ud[3], be, radius, out;
   TLorentzVector s, p;
   const char *knamed;
-  
+
+  for (j=0;j<10;j++) hits[j]=0;
+
   if((gMC->GetMedium() == fMedSensZN) || (gMC->GetMedium() == fMedSensZP) ||
      (gMC->GetMedium() == fMedSensGR) || (gMC->GetMedium() == fMedSensF1) ||
-     (gMC->GetMedium() == fMedSensF2)){
-        
+     (gMC->GetMedium() == fMedSensF2) || (gMC->GetMedium() == fMedSensZEM)||
+     (gMC->GetMedium() == fMedSensPI) || (gMC->GetMedium() == fMedSensTDI)){
+       
+  // If particle interacts with beam pipe -> return
+    if((gMC->GetMedium() == fMedSensPI) || (gMC->GetMedium() == fMedSensTDI)){ 
+      // If option NoShower is set -> StopTrack
+      if(fNoShower==1) {
+//     if(gMC->GetMedium() == fMedSensPI) {
+//          knamed = gMC->CurrentVolName();
+//          if((!strncmp(knamed,"MQ",2)) || (!strncmp(knamed,"YM",2)))  fpLostIT += 1;
+//          if((!strncmp(knamed,"MD1",3))|| (!strncmp(knamed,"YD1",2))) fpLostD1 += 1;
+//     }
+//     if(gMC->GetMedium() == fMedSensTDI) fpLostTDI += 1;
+        gMC->StopTrack();
+//     printf("\n      # of p lost in Inner Triplet = %d\n",fpLostIT);
+//     printf("\n      # of p lost in D1  = %d\n",fpLostD1);
+//     printf("\n      # of p lost in TDI = %d\n",fpLostTDI);
+        return;
+      }
+    }
+  
   //Particle coordinates 
     gMC->TrackPosition(s);
     for(j=0; j<=2; j++){
@@ -953,55 +1418,69 @@ void AliZDCv1::StepManager()
     knamed = gMC->CurrentVolName();
     if(!strncmp(knamed,"ZN",2))vol[0]=1;
     if(!strncmp(knamed,"ZP",2))vol[0]=2;
+    if(!strncmp(knamed,"ZE",2))vol[0]=3;
   
   // Determine in which quadrant the particle is
     
     //Quadrant in ZN
-    gMC->Gmtod(x,xdet,1);
     if(vol[0]==1){
-      if((xdet[0]<0.) && (xdet[1]>0.)) vol[1]=1;
-      if((xdet[0]>0.) && (xdet[1]>0.)) vol[1]=2;
-      if((xdet[0]<0.) && (xdet[1]<0.)) vol[1]=3;
-      if((xdet[0]>0.) && (xdet[1]<0.)) vol[1]=4;
+      xdet[0] = x[0]-fPosZN[0];
+      xdet[1] = x[1]-fPosZN[1];
+      if((xdet[0]<=0.) && (xdet[1]>=0.))  vol[1]=1;
+      if((xdet[0]>0.)  && (xdet[1]>0.))   vol[1]=2;
+      if((xdet[0]<0.)  && (xdet[1]<0.))   vol[1]=3;
+      if((xdet[0]>0.)  && (xdet[1]<0.))   vol[1]=4;
     }
     
     //Quadrant in ZP
     if(vol[0]==2){
+      xdet[0] = x[0]-fPosZP[0];
+      xdet[1] = x[1]-fPosZP[1];
+      if(xdet[0]>fDimZP[0])xdet[0]=fDimZP[0]-0.01;
+      if(xdet[0]<-fDimZP[0])xdet[0]=-fDimZP[0]+0.01;
       Float_t xqZP = xdet[0]/(fDimZP[0]/2);
       for(int i=1; i<=4; i++){
-         if(xqZP>(i-3) && xqZP<(i-2)){
+         if(xqZP>=(i-3) && xqZP<(i-2)){
           vol[1] = i;
           break;
-       }
-     }
+        }
+      }
+    }
+    
+    //ZEM has only 1 quadrant
+    if(vol[0] == 3){
+      vol[1] = 1;
+      xdet[0] = x[0]-fPosZEM[0];
+      xdet[1] = x[1]-fPosZEM[1];
     }
-//    printf(" -> Det. %d Quad. %d \n", vol[0], vol[1]);
 
   // Store impact point and kinetic energy of the ENTERING particle
     
-//    Int_t Curtrack = gAlice->CurrentTrack();
-//    Int_t Prim = gAlice->GetPrimary(Curtrack);
-//    printf ("Primary: %d, Current Track: %d \n", Prim, Curtrack); 
-    
 //    if(Curtrack==Prim){
       if(gMC->IsTrackEntering()){
         //Particle energy
         gMC->TrackMomentum(p);
-//      printf("p[0] = %f, p[1] = %f, p[2] = %f, p[3] = %f \n", 
-//                 p[0], p[1], p[2], p[3]);
         hits[3] = p[3];
-
-        // Impact point on ZN  
+        // Impact point on ZDC  
         hits[4] = xdet[0];
         hits[5] = xdet[1];
+       hits[6] = 0;
         hits[7] = 0;
         hits[8] = 0;
         hits[9] = 0;
 
-//        printf(" hits[2] = %f \n",hits[2]);
-        AddHit(gAlice->CurrentTrack(), vol, hits);
+//       Int_t PcID = gMC->TrackPid();
+//       printf("Pc ID -> %d\n",PcID);
+       AddHit(gAlice->CurrentTrack(), vol, hits);
+       
+       if(fNoShower==1){
+//       fpDetected += 1;
+         gMC->StopTrack();
+//       printf("\n    # of detected p = %d\n",fpDetected);
+         return;
+       }
       }
-//    }
+//    } // Curtrack IF
              
       // Charged particles -> Energy loss
       if((destep=gMC->Edep())){
@@ -1009,7 +1488,6 @@ void AliZDCv1::StepManager()
            gMC->TrackMomentum(p);
           m = gMC->TrackMass();
           ekin = p[3]-m;
-          if(ekin<0.) printf("ATTENTION!!!!!!!!!!!!!!! ->      ekin = %f <0 (?)",ekin);
           hits[9] = ekin;
           hits[7] = 0.;
           hits[8] = 0.;
@@ -1021,33 +1499,26 @@ void AliZDCv1::StepManager()
           hits[8] = 0.;
           AddHit(gAlice->CurrentTrack(), vol, hits);
           }
-//      printf("       -> Charged particle -> Dep. E = %f eV \n",hits[8]);
-        }
-//      printf(" \n");
-  }
+//      printf(" Dep. E = %f \n",hits[9]);
+      }
+  }// NB -> Questa parentesi (chiude il primo IF) io la sposterei al fondo!???
 
 
   // *** Light production in fibres 
   if((gMC->GetMedium() == fMedSensF1) || (gMC->GetMedium() == fMedSensF2)){
-//    printf("%%%%%%%%%%%%%%%% Particle in fibre %%%%%%%%%%%%%%%%\n");
 
      //Select charged particles
      if((destep=gMC->Edep())){
-//       printf("              -> CHARGED particle!!! \n");
 
        // Particle velocity
        gMC->TrackMomentum(p);
        Float_t ptot=TMath::Sqrt(p[0]*p[0]+p[1]*p[1]+p[2]*p[2]);
        Float_t beta =  ptot/p[3];
-//       printf("p[0] = %f, p[1] = %f, p[2] = %f, p[3] = %f, ptot = %f \n",
-//              p[0], p[1], p[2], p[3], ptot);
-//       Int_t pcID = gMC->TrackPid();
-//       printf("      Pc %d in quadrant %d -> beta = %f \n", pcID, vol[1], beta);
        if(beta<0.67) return;
        if((beta>=0.67) && (beta<=0.75)) ibeta = 0;
        if((beta>0.75)  && (beta<=0.85)) ibeta = 1;
        if((beta>0.85)  && (beta<=0.95)) ibeta = 2;
-       if((beta>0.95)  && (beta<=1.00)) ibeta = 3;
+       if(beta>0.95)   ibeta = 3;
  
        // Angle between particle trajectory and fibre axis
        // 1 -> Momentum directions
@@ -1058,7 +1529,7 @@ void AliZDCv1::StepManager()
        // 2 -> Angle < limit angle
        Double_t alfar = TMath::ACos(ud[2]);
        Double_t alfa = alfar*kRaddeg;
-       if(alfa>110.) return;
+       if(alfa>=110.) return;
        ialfa = Int_t(1.+alfa/2.);
  
        // Distance between particle trajectory and fibre axis
@@ -1086,17 +1557,18 @@ void AliZDCv1::StepManager()
        if((vol[0]==1)) {
          if(ibe>fNben) ibe=fNben;
          out =  charge*charge*fTablen[ibeta][ialfa][ibe];
-//      printf("       -> fTablen [%d][%d][%d] = %f \n", 
-//             ibeta, ialfa, ibe, fTablen[ibeta][ialfa][ibe]);
+        nphe = gRandom->Poisson(out);
+//      printf("ZN --- ibeta = %d, ialfa = %d, ibe = %d"
+//             "       -> out = %f, nphe = %d\n", ibeta, ialfa, ibe, out, nphe);
         if(gMC->GetMedium() == fMedSensF1){
-          hits[7] = out;       //fLightPMQ
+          hits[7] = nphe;      //fLightPMQ
           hits[8] = 0;
           hits[9] = 0;
           AddHit(gAlice->CurrentTrack(), vol, hits);
         }
         else{
           hits[7] = 0;
-          hits[8] = out;       //fLightPMC
+          hits[8] = nphe;      //fLightPMC
           hits[9] = 0;
           AddHit(gAlice->CurrentTrack(), vol, hits);
         }
@@ -1106,22 +1578,34 @@ void AliZDCv1::StepManager()
        if((vol[0]==2)) {
          if(ibe>fNbep) ibe=fNbep;
          out =  charge*charge*fTablep[ibeta][ialfa][ibe];
-//      printf("       -> fTablep [%d][%d][%d] = %f\n", 
-//             ibeta, ialfa, ibe, fTablen[ibeta][ialfa][ibe]);
+        nphe = gRandom->Poisson(out);
+//      printf("ZP --- ibeta = %d, ialfa = %d, ibe = %d"
+//             "       -> out = %f, nphe = %d\n", ibeta, ialfa, ibe, out, nphe);
         if(gMC->GetMedium() == fMedSensF1){
-          hits[7] = out;       //fLightPMQ
+          hits[7] = nphe;      //fLightPMQ
           hits[8] = 0;
           hits[9] = 0;
           AddHit(gAlice->CurrentTrack(), vol, hits);
         }
         else{
           hits[7] = 0;
-          hits[8] = out;       //fLightPMC
+          hits[8] = nphe;      //fLightPMC
           hits[9] = 0;
           AddHit(gAlice->CurrentTrack(), vol, hits);
         }
        } 
+       // (3) ZEM
+       if((vol[0]==3)) {
+         if(ibe>fNbep) ibe=fNbep;
+         out =  charge*charge*fTablep[ibeta][ialfa][ibe];
+        nphe = gRandom->Poisson(out);
+//      printf("ZEM --- ibeta = %d, ialfa = %d, ibe = %d"
+//             "       -> out = %f, nphe = %d\n", ibeta, ialfa, ibe, out, nphe);
+        hits[7] = 0;   
+        hits[8] = nphe;        //fLightPMC
+        hits[9] = 0;
+        AddHit(gAlice->CurrentTrack(), vol, hits);
+       }
      }
-//    printf("\n");
    }
 }