]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ZDC/AliZDCv1.cxx
extended check
[u/mrichter/AliRoot.git] / ZDC / AliZDCv1.cxx
index ca0403fbd73282cca777c7381e64896aecf20369..7a17b80f4346c76d9f89545151f0e7a1bb4ae56c 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.22  2001/05/05 13:33:19  coppedis
-Changes in StepManager to speed simulation
-
-Revision 1.21  2001/05/02 11:54:34  enrico
-Minor change
-
-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
-
-Revision 1.7  2000/01/19 17:17:40  fca
-
-Revision 1.6  1999/09/29 09:24:35  fca
-Introduction of the Copyright and cvs Log
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
-//  Zero Degree Calorimeter                                                  //
-//  This class contains the basic functions for the ZDC                      //
-//  Functions specific to one particular geometry are                        //
-//  contained in the derived classes                                         //
+//             AliZDCv1 --- ZDC geometry as designed in TDR (obsolete!)     //
+//                     with the EM ZDC at 116 m from IP                     //
+//  Just one set of ZDC is inserted, on the same side of the dimuon arm      //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -105,36 +28,27 @@ Introduction of the Copyright and cvs Log
 
 // --- ROOT system
 #include <TBRIK.h>
-#include <TNode.h>
+#include <TLorentzVector.h>
 #include <TMath.h>
+#include <TNode.h>
 #include <TRandom.h>
 #include <TSystem.h>
 #include <TTree.h>
-
+#include <TVirtualMC.h>
 
 // --- AliRoot classes
-#include "AliZDCv1.h"
-#include "AliZDCHit.h"
-#include "AliZDCDigit.h"
-#include "AliRun.h"
+#include "AliConst.h"
 #include "AliDetector.h"
 #include "AliMagF.h"
-#include "AliMC.h"
-#include "AliCallf77.h"
-#include "AliConst.h"
 #include "AliPDG.h"
-#include "TLorentzVector.h"
+#include "AliRun.h"
+#include "AliZDCHit.h"
+#include "AliZDCv1.h"
+#include "AliMC.h"
  
  
 ClassImp(AliZDCv1)
  
-
-///////////////////////////////////////////////////////////////////////////////
-//                                                                           //
-//  Zero Degree Calorimeter version 1                                        //
-//                                                                           //
-///////////////////////////////////////////////////////////////////////////////
-
 //_____________________________________________________________________________
 AliZDCv1::AliZDCv1() : AliZDC()
 {
@@ -162,10 +76,10 @@ AliZDCv1::AliZDCv1(const char *name, const char *title)
   //
   // Check that DIPO, ABSO, DIPO and SHIL is there (otherwise tracking is wrong!!!)
   
-  AliModulePIPE=gAlice->GetModule("PIPE");
-  AliModuleABSO=gAlice->GetModule("ABSO");
-  AliModuleDIPO=gAlice->GetModule("DIPO");
-  AliModuleSHIL=gAlice->GetModule("SHIL");
+  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);
@@ -208,7 +122,7 @@ AliZDCv1::AliZDCv1(const char *name, const char *title)
   fDimZP[1] = 6.;
   fDimZP[2] = 75.;    
   fPosZN[0] = 0.;
-  fPosZN[1] = -1.2;
+  fPosZN[1] = 1.2;
   fPosZN[2] = 11650.;
   fPosZP[0] = -24.;
   fPosZP[1] = 0.;
@@ -225,8 +139,6 @@ AliZDCv1::AliZDCv1(const char *name, const char *title)
   fPosZEM[1] = 5.8;
   fPosZEM[2] = 11600.;
   
-
-  fDigits = new TClonesArray("AliZDCDigit",1000);
 }
  
 //_____________________________________________________________________________
@@ -376,7 +288,7 @@ void AliZDCv1::CreateBeamLine()
   // 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");
+  gMC->Gspos("QT09", 1, "ZDC ", 0., 0., tubpar[2] + zd1, 0, "ONLY"); 
   
   // --- Insert TDI (inside ZDC volume)
   
@@ -384,22 +296,27 @@ void AliZDCv1::CreateBeamLine()
   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");
+  gMC->Gspos("QTD1", 1, "ZDC ", 3., 10.6, tubpar[2] + zd1 + 56.3, 0, "ONLY");
+  gMC->Gspos("QTD1", 2, "ZDC ", 3., -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;
+  gMC->Gspos("QTD2", 1, "ZDC ", 8.6+boxpar[0], 0., tubpar[2] + zd1 + 56.3, 0, "ONLY");
+  
+//  tubspar[0] = 6.2;  // R = 6.2 cm----------------------------------------
+//  tubspar[1] = 6.4;
+//  tubspar[2] = 400./2.;
+//  tubspar[3] = 180.-62.5;
+//  tubspar[4] = 180.+62.5;
+  tubspar[0] = 10.5;   // R = 10.5 cm------------------------------------------
+  tubspar[1] = 10.7;
   tubspar[2] = 400./2.;
-  tubspar[3] = 180.-62.5;
-  tubspar[4] = 180.+62.5;
+  tubspar[3] = 180.-75.5;
+  tubspar[4] = 180.+75.5;
   gMC->Gsvolu("QTD3", "TUBS", idtmed[6], tubspar, 5);
-  gMC->Gspos("QTD3", 1, "ZDC ", -3., 0., tubpar[2] + zd1 + 56.3, 0, "ONLY");
+  gMC->Gspos("QTD3", 1, "ZDC ", 0., 0., tubpar[2] + zd1 + 56.3, 0, "ONLY");
 
   zd1 += tubpar[2] * 2.;
   
@@ -1030,7 +947,7 @@ void AliZDCv1::CreateMaterials()
   
   // --- Tracking media parameters 
   Float_t epsil  = .01, stmin=0.01, stemax = 1.;
-  Int_t   isxfld = gAlice->Field()->Integ();
+//  Int_t   isxfld = gAlice->Field()->Integ();
 //  Float_t fieldm = gAlice->Field()->Max();
   Float_t fieldm = 0., tmaxfd = 0.;
   Int_t   ifield = 0, isvolActive = 1, isvol = 0, inofld = 0;
@@ -1051,7 +968,7 @@ void AliZDCv1::CreateMaterials()
   
   ifield =2;
   fieldm = 45.;
-  AliMedium(11, "ZVOIM", 11, isvol, isxfld, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
+  AliMedium(11, "ZVOIM", 11, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
   
   // Thresholds for showering in the ZDCs 
   i = 1; //tantalum
@@ -1230,165 +1147,6 @@ void AliZDCv1::InitTables()
   fclose(fp7);
   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()
 {
@@ -1398,6 +1156,7 @@ void AliZDCv1::StepManager()
 
   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;
+  Float_t xalic[3], z, GuiEff, GuiPar[4]={0.31,-0.0004,0.0197,0.7958};
   TLorentzVector s, p;
   const char *knamed;
 
@@ -1406,6 +1165,8 @@ void AliZDCv1::StepManager()
   if((gMC->GetMedium() == fMedSensZN) || (gMC->GetMedium() == fMedSensZP) ||
      (gMC->GetMedium() == fMedSensGR) || (gMC->GetMedium() == fMedSensF1) ||
      (gMC->GetMedium() == fMedSensF2) || (gMC->GetMedium() == fMedSensZEM)){
+
+//   --- This part is for no shower developement in beam pipe and TDI
 //     (gMC->GetMedium() == fMedSensPI) || (gMC->GetMedium() == fMedSensTDI)){
        
   // If particle interacts with beam pipe -> return
@@ -1422,8 +1183,8 @@ void AliZDCv1::StepManager()
 //     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;
 //      }
+//      return;
 //    }
   
   //Particle coordinates 
@@ -1437,14 +1198,19 @@ void AliZDCv1::StepManager()
 
   // Determine in which ZDC the particle is
     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;
+    if(!strncmp(knamed,"ZN",2)){
+      vol[0]=1;
+    }
+    else if(!strncmp(knamed,"ZP",2)){
+      vol[0]=2;
+    }
+    else if(!strncmp(knamed,"ZE",2)){
+      vol[0]=3;
+    }
   
   // Determine in which quadrant the particle is
-    
-    //Quadrant in ZN
-    if(vol[0]==1){
+       
+    if(vol[0]==1){     //Quadrant in ZN
       xdet[0] = x[0]-fPosZN[0];
       xdet[1] = x[1]-fPosZN[1];
       if((xdet[0]<=0.) && (xdet[1]>=0.))  vol[1]=1;
@@ -1452,9 +1218,7 @@ void AliZDCv1::StepManager()
       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){
+    else if(vol[0]==2){        //Quadrant in ZP
       xdet[0] = x[0]-fPosZP[0];
       xdet[1] = x[1]-fPosZP[1];
       if(xdet[0]>fDimZP[0])xdet[0]=fDimZP[0]-0.01;
@@ -1463,14 +1227,11 @@ void AliZDCv1::StepManager()
       for(int i=1; i<=4; i++){
          if(xqZP>=(i-3) && xqZP<(i-2)){
           vol[1] = i;
-          if(i==0) printf("\n!!! vol[1] = 0 -> xqZP = %f\n", xqZP);
           break;
         }
       }
     }
-    
-    //ZEM has only 1 quadrant
-    if(vol[0] == 3){
+    else if(vol[0] == 3){      //ZEM has only 1 quadrant
       vol[1] = 1;
       xdet[0] = x[0]-fPosZEM[0];
       xdet[1] = x[1]-fPosZEM[1];
@@ -1493,7 +1254,7 @@ void AliZDCv1::StepManager()
 
 //       Int_t PcID = gMC->TrackPid();
 //       printf("Pc ID -> %d\n",PcID);
-       AddHit(gAlice->CurrentTrack(), vol, hits);
+       AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
        
        if(fNoShower==1){
 //       fpDetected += 1;
@@ -1513,13 +1274,13 @@ void AliZDCv1::StepManager()
           hits[9] = ekin;
           hits[7] = 0.;
           hits[8] = 0.;
-          AddHit(gAlice->CurrentTrack(), vol, hits);
+          AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
           }
         else{
           hits[9] = destep;
           hits[7] = 0.;
           hits[8] = 0.;
-          AddHit(gAlice->CurrentTrack(), vol, hits);
+          AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
           }
 //      printf(" Dep. E = %f \n",hits[9]);
       }
@@ -1536,11 +1297,21 @@ 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];
-       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)   ibeta = 3;
+       if(beta<0.67){
+         return;
+       }
+       else 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){
+         ibeta = 3;
+       }
  
        // Angle between particle trajectory and fibre axis
        // 1 -> Momentum directions
@@ -1568,15 +1339,18 @@ void AliZDCv1::StepManager()
          be = TMath::Abs(ud[0]);
        }
  
-       if((vol[0]==1)) radius = fFibZN[1];
-       if((vol[0]==2)) radius = fFibZP[1];
+       if((vol[0]==1)){
+         radius = fFibZN[1];
+       }
+       else if((vol[0]==2)){
+         radius = fFibZP[1];
+       }
        ibe = Int_t(be*1000.+1);
  
        //Looking into the light tables 
        Float_t charge = gMC->TrackCharge();
        
-       // (1)  ZN
-       if((vol[0]==1)) {
+       if((vol[0]==1)) {       // (1)  ZN fibres
          if(ibe>fNben) ibe=fNben;
          out =  charge*charge*fTablen[ibeta][ialfa][ibe];
         nphe = gRandom->Poisson(out);
@@ -1586,18 +1360,16 @@ void AliZDCv1::StepManager()
           hits[7] = nphe;      //fLightPMQ
           hits[8] = 0;
           hits[9] = 0;
-          AddHit(gAlice->CurrentTrack(), vol, hits);
+          AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
         }
         else{
           hits[7] = 0;
           hits[8] = nphe;      //fLightPMC
           hits[9] = 0;
-          AddHit(gAlice->CurrentTrack(), vol, hits);
+          AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
         }
        } 
-       
-       // (2) ZP
-       if((vol[0]==2)) {
+       else if((vol[0]==2)) {  // (2) ZP fibres
          if(ibe>fNbep) ibe=fNbep;
          out =  charge*charge*fTablep[ibeta][ialfa][ibe];
         nphe = gRandom->Poisson(out);
@@ -1607,26 +1379,39 @@ void AliZDCv1::StepManager()
           hits[7] = nphe;      //fLightPMQ
           hits[8] = 0;
           hits[9] = 0;
-          AddHit(gAlice->CurrentTrack(), vol, hits);
+          AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
         }
         else{
           hits[7] = 0;
           hits[8] = nphe;      //fLightPMC
           hits[9] = 0;
-          AddHit(gAlice->CurrentTrack(), vol, hits);
+          AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
         }
        } 
-       // (3) ZEM
-       if((vol[0]==3)) {
+       else if((vol[0]==3)) {  // (3) ZEM fibres
          if(ibe>fNbep) ibe=fNbep;
          out =  charge*charge*fTablep[ibeta][ialfa][ibe];
+        gMC->TrackPosition(s);
+         for(j=0; j<=2; j++){
+            xalic[j] = s[j];
+         }
+        // z-coordinate from ZEM front face 
+        // NB-> fPosZEM[2]+fZEMLength = -1000.+2*10.3 = 979.69 cm
+        z = -xalic[2]+fPosZEM[2]+2*fZEMLength-xalic[1];
+//      z = xalic[2]-fPosZEM[2]-fZEMLength-xalic[1]*(TMath::Tan(45.*kDegrad));
+//         printf("\n  fPosZEM[2]+2*fZEMLength = %f", fPosZEM[2]+2*fZEMLength);
+        GuiEff = GuiPar[0]*(GuiPar[1]*z*z+GuiPar[2]*z+GuiPar[3]);
+//         printf("\n  xalic[0] = %f   xalic[1] = %f   xalic[2] = %f   z = %f  \n",
+//             xalic[0],xalic[1],xalic[2],z);
+        out = out*GuiEff;
         nphe = gRandom->Poisson(out);
+//         printf("    out*GuiEff = %f nphe = %d", out, nphe);
 //      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);
+        AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
        }
      }
    }