]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ZDC/AliZDCv1.cxx
Correction for superposition of ZDC volumes with MUON arm one
[u/mrichter/AliRoot.git] / ZDC / AliZDCv1.cxx
index 3f3f4b52fd534270e73bc8bffba7e6309570e0e9..b1c3ea6debe1a530ac6141be7edb0b9cda9b9c44 100644 (file)
 
 /*
 $Log$
+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 +76,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 +123,14 @@ 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;
 }
  
 //_____________________________________________________________________________
@@ -76,11 +140,62 @@ AliZDCv1::AliZDCv1(const char *name, const char *title)
   //
   // Standard 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;
+
+  
+  // 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] = 0.;
+  fPosZN[2] = 11650.;
+  fPosZP[0] = -23.;
+  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,20 +214,17 @@ void AliZDCv1::CreateGeometry()
 void AliZDCv1::CreateBeamLine()
 {
   
-  Float_t angle;
-  Float_t zq, conpar[9], elpar[3], tubpar[3];
+  Float_t angle, zq, conpar[9], elpar[3], tubpar[3], zd1, zd2;
   Int_t im1, im2;
-  Float_t zd1, zd2;
-  
   
   Int_t *idtmed = fIdtmed->GetArray();
   
-  // -- Mother of the ZDC 
+  // -- Mother of the ZDCs 
   
   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.;
@@ -124,47 +236,48 @@ void AliZDCv1::CreateBeamLine()
   // -- FIRST SECTION OF THE BEAM PIPE (from compensator dipole to 
   //    beginning of D1) 
   
-  zd1 = 1921.6;
+  zd1 = 2000.;
   
   tubpar[0] = 6.3/2.;
   tubpar[1] = 6.7/2.;
-  tubpar[2] = 3916.7/2.;
+  tubpar[2] = 3838.3/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
+  //-- FROM MAGNETIC BEGINNING OF D1 TO MAGNETIC END OF D1 + 23.5 cm
+  //-- Elliptic pipe -> ELLIPTIC PIPE NOT INSERTED FOR THE MOMENT!
   
+  //-> D1 begins at (6310.8-472.5)
   zd1 = 6310.8-472.5;
   
   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");
-  
+//  gMC->Gsvolu("E001", "ELTU", idtmed[5], elpar, 3);
+//  gMC->Gspos("E001", 1, "ZDC ", 0., 0., elpar[2] + zd1, 0, "ONLY");
+//  
   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");
+//  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");
+//  gMC->Gsvolu("E003", "ELTU", idtmed[5], elpar, 3);
+//  gMC->Gspos("E002", 1, "ZDC ", 0., 0., elpar[2] + zd1, 0, "ONLY");
   
   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");
+//  gMC->Gsvolu("E004", "ELTU", idtmed[10], elpar, 3);
+//  gMC->Gspos("E004", 1, "E003", 0., 0., 0., 0, "ONLY");
 
   zd1 += 2.*elpar[2];
   
@@ -184,7 +297,7 @@ void AliZDCv1::CreateBeamLine()
   gMC->Gsvolu("P002", "TUBE", idtmed[5], tubpar, 3);
   gMC->Gspos("P002", 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.;
@@ -309,7 +422,7 @@ void AliZDCv1::CreateBeamLine()
   tubpar[0] = 0./2.;
   tubpar[1] = 68.4/2.;
   tubpar[2] = 0.2/2.;
-  gMC->Gsvolu("P017", "TUBE", idtmed[5], tubpar, 3);
+  gMC->Gsvolu("P017", "TUBE", idtmed[8], tubpar, 3);
   gMC->Gspos("P017", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY");
   
   zd1 += tubpar[2] * 2.;
@@ -355,39 +468,45 @@ void AliZDCv1::CreateBeamLine()
   // --  END OF BEAM PIPE VOLUME DEFINITION. MAGNET DEFINITION FOLLOWS 
   //     (LHC OPTICS 6) 
   
+  // ----------------------------------------------------------------
+  //                   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[5], tubpar, 3);
+//  gMC->Gspos("YMBX", 1, "ZDC ", 0., 0., tubpar[2] + 805., 0, "ONLY");
   
+  // ----------------------------------------------------------------
+  //                 Replaced by the muon compesator
+  // ----------------------------------------------------------------
   // -- 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[5], tubpar, 3);
+//  gMC->Gspos("YMCB", 1, "ZDC ", 0., 0., tubpar[2] + 1921.6, 0, "ONLY");
   
   // -- INNER TRIPLET 
   
@@ -488,7 +607,32 @@ void AliZDCv1::CreateBeamLine()
 void AliZDCv1::CreateZDC()
 {
   
+  Int_t irot1, irot2;
+  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
   
@@ -535,7 +679,8 @@ 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 +724,66 @@ 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);
+  
+  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[6], DimPb, 6);
+  gMC->Gsvolu("ZEL1", "PARA", idtmed[6], DimPb, 6);
+  gMC->Gsvolu("ZEL2", "PARA", idtmed[6], 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");
   
 }
  
@@ -623,8 +828,8 @@ void AliZDCv1::DrawModule()
   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("MBXW","SEEN",1);
+//  gMC->Gsatt("YMBX","SEEN",1);
   gMC->Gsatt("MCBW","SEEN",1);
   gMC->Gsatt("YMCB","SEEN",1);
   gMC->Gsatt("MQXL","SEEN",1);
@@ -663,6 +868,17 @@ void AliZDCv1::DrawModule()
   gMC->Gsatt("ZP1 ","SEEN",1);
   gMC->Gsatt("ZPSL","SEEN",0);
   gMC->Gsatt("ZPST","SEEN",0);
+  gMC->Gsatt("ZEM ","COLO",2); 
+  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");
@@ -686,18 +902,12 @@ void AliZDCv1::CreateMaterials()
   
   Int_t *idtmed = fIdtmed->GetArray();
   
-  Float_t dens, ubuf[1], wmat[2];
-  Int_t isvolActive;
-  Float_t a[2];
-  Int_t i;
-  Float_t z[2], epsil=0.001, stmin=0.01;
-  Int_t isvol;
+  Float_t dens, ubuf[1], wmat[2], a[2], z[2], epsil=0.001, stmin=0.01;
+  Float_t deemax = -1, stemax;
   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;
+  Int_t   i, isvolActive, isvol, inofld;
+  Int_t   isxfld = gAlice->Field()->Integ();
   
   // --- Store in UBUF r0 for nuclear radius calculation R=r0*A**1/3 
 
@@ -728,19 +938,23 @@ void AliZDCv1::CreateMaterials()
   wmat[0] = 1.;
   wmat[1] = 2.;
   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);
   
+  // --- Iron (energy loss taken into account)
+  ubuf[0] = 1.1;
+  AliMaterial(6, "IRON", 55.85, 26., 7.87, 1.76, 0., ubuf, 1);
   
-  // --- Lead 
-//  ubuf[0] = 1.12;
-//  AliMaterial(6, "LEAD", 207.19, 82., 11.35, .56, 18.5, 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(7, "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,8 +971,9 @@ void AliZDCv1::CreateMaterials()
   // --- Brass = 2 ; 
   // --- Fibers (SiO2) = 3 ; 
   // --- Fibers (SiO2) = 4 ; 
-  // --- Iron = 5 ; 
-  // --- Lead = 6 ; 
+  // --- Lead = 5 ; 
+  // --- Iron (with energy loss) = 6 ; 
+  // --- Iron (without energy loss) = 7 ; 
   // --- Vacuum (no field) = 10 
   // --- Vacuum (with field) = 11 
   // --- Air (no field) = 12 
@@ -777,9 +992,10 @@ void AliZDCv1::CreateMaterials()
   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(6, "ZLEAD", 5, 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(5, "ZIRON", 6, isvolActive, inofld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
+  AliMedium(8, "ZIRONN", 7, 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);
   
@@ -798,6 +1014,11 @@ void AliZDCv1::CreateMaterials()
   gMC->Gstpar(idtmed[i], "CUTELE", .001);
   gMC->Gstpar(idtmed[i], "CUTNEU", .01);
   gMC->Gstpar(idtmed[i], "CUTHAD", .01);
+  i = 6;
+  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 
   
@@ -834,46 +1055,64 @@ 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;
+  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
+  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
+  fMedSensZEM = idtmed[6];  // Sensitive volume: ZEM passive material
+  fMedSensGR  = idtmed[12]; // Sensitive volume: air into the grooves
+  fMedSensPI  = idtmed[5];  // Sensitive volume: beam pipes
 } 
 
 //_____________________________________________________________________________
 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){
+  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;
   }
@@ -891,23 +1130,27 @@ void AliZDCv1::InitTables()
   fclose(fp3);
   fclose(fp4);
   
-  if((fp5 = fopen("light22620552207s","r")) == NULL){
+  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");
+//  printf(" --- Reading light tables for ZP and ZEM \n");
   for(k=0; k<fNalfap; k++){
      for(j=0; j<fNbep; j++){
        fscanf(fp5,"%f",&fTablep[0][k][j]);
@@ -922,6 +1165,163 @@ 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()
 {
@@ -930,16 +1330,26 @@ void AliZDCv1::StepManager()
   //
 
   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 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)){
+       
+  // If particle interacts with beam pipe -> return
+    if(gMC->GetMedium() == fMedSensPI){ 
+  
+  // If option NoShower is set -> StopTrack
+      if(fNoShower==1) gMC->StopTrack();
+      return;
+    }
+  
   //Particle coordinates 
     gMC->TrackPosition(s);
     for(j=0; j<=2; j++){
@@ -953,53 +1363,67 @@ 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){
+       gMC->StopTrack();
+       return;
+       }
       }
 //    }
              
@@ -1029,7 +1453,6 @@ void AliZDCv1::StepManager()
 
   // *** Light production in fibres 
   if((gMC->GetMedium() == fMedSensF1) || (gMC->GetMedium() == fMedSensF2)){
-//    printf("%%%%%%%%%%%%%%%% Particle in fibre %%%%%%%%%%%%%%%%\n");
 
      //Select charged particles
      if((destep=gMC->Edep())){
@@ -1039,15 +1462,12 @@ void AliZDCv1::StepManager()
        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)  && (beta<=1.00)) ibeta = 3;
+       if(beta>0.95) ibeta = 3;
  
        // Angle between particle trajectory and fibre axis
        // 1 -> Momentum directions
@@ -1058,7 +1478,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 +1506,16 @@ 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);
         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 +1525,31 @@ 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);
         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);
+        hits[7] = 0;   
+        hits[8] = nphe;        //fLightPMC
+        hits[9] = 0;
+        AddHit(gAlice->CurrentTrack(), vol, hits);
+       } 
      }
-//    printf("\n");
+       
    }
 }