]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCv2.cxx
Several Changes:
[u/mrichter/AliRoot.git] / ZDC / AliZDCv2.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 ///////////////////////////////////////////////////////////////////////
18 //                                                                   //
19 //              AliZDCv2 --- new ZDC geometry                        //
20 //          with the EM ZDC at about 10 m from IP                    //
21 //              Just one set of ZDC is inserted                      //
22 //      (on the same side of the dimuon arm realtive to IP)          //
23 //            Compensator in ZDC geometry (Nov. 2004)                //
24 //                                                                   //  
25 ///////////////////////////////////////////////////////////////////////
26
27 // --- Standard libraries
28 #include "stdio.h"
29
30 // --- ROOT system
31 #include <TMath.h>
32 #include <TRandom.h>
33 #include <TSystem.h>
34 #include <TTree.h>
35 #include <TVirtualMC.h>
36 #include <TGeoManager.h>
37
38 // --- AliRoot classes
39 #include "AliConst.h"
40 #include "AliMagF.h"
41 #include "AliRun.h"
42 #include "AliZDCv2.h"
43 #include "AliMC.h"
44  
45 class  AliZDCHit;
46 class  AliPDG;
47 class  AliDetector;
48  
49 ClassImp(AliZDCv2)
50
51 //_____________________________________________________________________________
52 AliZDCv2::AliZDCv2() :
53   AliZDC(),
54   fMedSensF1(0),
55   fMedSensF2(0),
56   fMedSensZP(0),
57   fMedSensZN(0),
58   fMedSensZEM(0),
59   fMedSensGR(0),
60   fMedSensPI(0),
61   fMedSensTDI(0),
62   fNalfan(0),
63   fNalfap(0),
64   fNben(0),  
65   fNbep(0),
66   fZEMLength(0),
67   fpLostIT(0), 
68   fpLostD1(0), 
69   fpLostTDI(0),
70   fpDetected(0),
71   fnDetected(0)
72 {
73   //
74   // Default constructor for Zero Degree Calorimeter
75   //
76   
77 }
78  
79 //_____________________________________________________________________________
80 AliZDCv2::AliZDCv2(const char *name, const char *title)
81   : AliZDC(name,title),
82   fMedSensF1(0),
83   fMedSensF2(0),
84   fMedSensZP(0),
85   fMedSensZN(0),
86   fMedSensZEM(0),
87   fMedSensGR(0),
88   fMedSensPI(0),
89   fMedSensTDI(0),
90   fNalfan(90),
91   fNalfap(90),
92   fNben(18),  
93   fNbep(28), 
94   fZEMLength(0),
95   fpLostIT(0), 
96   fpLostD1(0), 
97   fpLostTDI(0),
98   fpDetected(0),
99   fnDetected(0)
100
101
102 {
103   //
104   // Standard constructor for Zero Degree Calorimeter 
105   //
106   //
107   // Check that DIPO, ABSO, DIPO and SHIL is there (otherwise tracking is wrong!!!)
108   
109   AliModule* pipe=gAlice->GetModule("PIPE");
110   AliModule* abso=gAlice->GetModule("ABSO");
111   AliModule* dipo=gAlice->GetModule("DIPO");
112   AliModule* shil=gAlice->GetModule("SHIL");
113   if((!pipe) || (!abso) || (!dipo) || (!shil)) {
114     Error("Constructor","ZDC needs PIPE, ABSO, DIPO and SHIL!!!\n");
115     exit(1);
116   } 
117
118   fMedSensF1  = 0;
119   fMedSensF2  = 0;
120   fMedSensZN  = 0;
121   fMedSensZP  = 0;
122   fMedSensZEM = 0;
123   fMedSensGR  = 0;
124   fMedSensPI  = 0;
125   fMedSensTDI = 0;
126
127   
128   // Parameters for light tables
129   fNalfan = 90;       // Number of Alfa (neutrons)
130   fNalfap = 90;       // Number of Alfa (protons)
131   fNben = 18;         // Number of beta (neutrons)
132   fNbep = 28;         // Number of beta (protons)
133   Int_t ip,jp,kp;
134   for(ip=0; ip<4; ip++){
135      for(kp=0; kp<fNalfap; kp++){
136         for(jp=0; jp<fNbep; jp++){
137            fTablep[ip][kp][jp] = 0;
138         } 
139      }
140   }
141   Int_t in,jn,kn;
142   for(in=0; in<4; in++){
143      for(kn=0; kn<fNalfan; kn++){
144         for(jn=0; jn<fNben; jn++){
145            fTablen[in][kn][jn] = 0;
146         } 
147      }
148   }
149
150   // Parameters for hadronic calorimeters geometry
151   fDimZN[0] = 3.52;
152   fDimZN[1] = 3.52;
153   fDimZN[2] = 50.;  
154   fDimZP[0] = 11.2;
155   fDimZP[1] = 6.;
156   fDimZP[2] = 75.;    
157   fPosZN[0] = 0.;
158   fPosZN[1] = 1.2;
159   fPosZN[2] = -11650.; 
160   fPosZP[0] = 23.9;
161   fPosZP[1] = 0.;
162   fPosZP[2] = -11600.; 
163   fFibZN[0] = 0.;
164   fFibZN[1] = 0.01825;
165   fFibZN[2] = 50.;
166   fFibZP[0] = 0.;
167   fFibZP[1] = 0.0275;
168   fFibZP[2] = 75.;
169   
170   // Parameters for EM calorimeter geometry
171   fPosZEM[0] = 8.5;
172   fPosZEM[1] = 0.;
173   fPosZEM[2] = 735.;
174
175   Float_t kDimZEMPb  = 0.15*(TMath::Sqrt(2.));  // z-dimension of the Pb slice
176   Float_t kDimZEMAir = 0.001;                   // scotch
177   Float_t kFibRadZEM = 0.0315;                  // External fiber radius (including cladding)
178   Int_t   kDivZEM[3] = {92, 0, 20};             // Divisions for EM detector
179   Float_t kDimZEM0 = 2*kDivZEM[2]*(kDimZEMPb+kDimZEMAir+kFibRadZEM*(TMath::Sqrt(2.)));
180   fZEMLength = kDimZEM0;
181
182 }
183  
184 //_____________________________________________________________________________
185 void AliZDCv2::CreateGeometry()
186 {
187   //
188   // Create the geometry for the Zero Degree Calorimeter version 2
189   //* Initialize COMMON block ZDC_CGEOM
190   //*
191
192   CreateBeamLine();
193   CreateZDC();
194 }
195   
196 //_____________________________________________________________________________
197 void AliZDCv2::CreateBeamLine()
198 {
199   //
200   // Create the beam line elements
201   //
202   
203   Float_t zc, zq, zd1, zd2;
204   Float_t conpar[9], tubpar[3], tubspar[5], boxpar[3];
205   Int_t im1, im2;
206   
207   Int_t *idtmed = fIdtmed->GetArray();
208   
209   // -- Mother of the ZDCs (Vacuum PCON)
210   // zd1 = 2092.; // (Without compensator in ZDC geometry)
211   zd1 = 1921.6;
212   
213   conpar[0] = 0.;
214   conpar[1] = 360.;
215   conpar[2] = 2.;
216   conpar[3] = -13500.;
217   conpar[4] = 0.;
218   conpar[5] = 55.;
219   conpar[6] = -zd1;
220   conpar[7] = 0.;
221   conpar[8] = 55.;
222   gMC->Gsvolu("ZDC ", "PCON", idtmed[11], conpar, 9);
223   gMC->Gspos("ZDC ", 1, "ALIC", 0., 0., 0., 0, "ONLY");
224
225   // -- FIRST SECTION OF THE BEAM PIPE (from compensator dipole to 
226   //            the beginning of D1) 
227   tubpar[0] = 6.3/2.;
228   tubpar[1] = 6.7/2.;
229   // From beginning of ZDC volumes to beginning of D1
230   tubpar[2] = (5838.3-zd1)/2.;
231   gMC->Gsvolu("QT01", "TUBE", idtmed[7], tubpar, 3);
232   gMC->Gspos("QT01", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
233   // Ch.debug
234   //printf("\n  QT01 TUBE pipe from z = %f to z= %f (D1 beg.)\n",-zd1,-2*tubpar[2]-zd1);
235   
236   //-- SECOND SECTION OF THE BEAM PIPE (from the end of D1 to the
237   //            beginning of D2) 
238   
239   //-- FROM MAGNETIC BEGINNING OF D1 TO MAGNETIC END OF D1 + 13.5 cm
240   //--  Cylindrical pipe (r = 3.47) + conical flare
241   
242   // -> Beginning of D1
243   zd1 += 2.*tubpar[2];
244   
245   tubpar[0] = 3.47;
246   tubpar[1] = 3.47+0.2;
247   tubpar[2] = 958.5/2.;
248   gMC->Gsvolu("QT02", "TUBE", idtmed[7], tubpar, 3);
249   gMC->Gspos("QT02", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
250   // Ch.debug
251   //printf("\n  QT02 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
252
253   zd1 += 2.*tubpar[2];
254   
255   conpar[0] = 25./2.;
256   conpar[1] = 10./2.;
257   conpar[2] = 10.4/2.;
258   conpar[3] = 6.44/2.;
259   conpar[4] = 6.84/2.;
260   gMC->Gsvolu("QC01", "CONE", idtmed[7], conpar, 5);
261   gMC->Gspos("QC01", 1, "ZDC ", 0., 0., -conpar[0]-zd1, 0, "ONLY");
262   // Ch.debug
263   //printf("\n  QC01 CONE pipe from z = %f to z= %f\n",-zd1,-2*conpar[0]-zd1);
264
265   zd1 += 2.*conpar[0];
266   
267   tubpar[0] = 10./2.;
268   tubpar[1] = 10.4/2.;
269   tubpar[2] = 50./2.;
270   gMC->Gsvolu("QT03", "TUBE", idtmed[7], tubpar, 3);
271   gMC->Gspos("QT03", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
272   // Ch.debug
273   //printf("\n  QT03 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
274   
275   zd1 += tubpar[2]*2.;
276   
277   tubpar[0] = 10./2.;
278   tubpar[1] = 10.4/2.;
279   tubpar[2] = 10./2.;
280   gMC->Gsvolu("QT04", "TUBE", idtmed[7], tubpar, 3);
281   gMC->Gspos("QT04", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
282   // Ch.debug
283   //printf("\n  QT04 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
284   
285   zd1 += tubpar[2] * 2.;
286   
287   tubpar[0] = 10./2.;
288   tubpar[1] = 10.4/2.;
289   tubpar[2] = 3.16/2.;
290   gMC->Gsvolu("QT05", "TUBE", idtmed[7], tubpar, 3);
291   gMC->Gspos("QT05", 1, "ZDC ", 0., 0., -tubpar[0]-zd1, 0, "ONLY");
292   // Ch.debug
293   //printf("\n  QT05 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
294   
295   zd1 += tubpar[2] * 2.;
296   
297   tubpar[0] = 10.0/2.;
298   tubpar[1] = 10.4/2;
299   tubpar[2] = 190./2.;
300   gMC->Gsvolu("QT06", "TUBE", idtmed[7], tubpar, 3);
301   gMC->Gspos("QT06", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
302   // Ch.debug
303   //printf("\n  QT06 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
304   
305   zd1 += tubpar[2] * 2.;
306   
307   conpar[0] = 30./2.;
308   conpar[1] = 20.6/2.;
309   conpar[2] = 21./2.;
310   conpar[3] = 10./2.;
311   conpar[4] = 10.4/2.;
312   gMC->Gsvolu("QC02", "CONE", idtmed[7], conpar, 5);
313   gMC->Gspos("QC02", 1, "ZDC ", 0., 0., -conpar[0]-zd1, 0, "ONLY");
314   // Ch.debug
315   //printf("\n  QC02 CONE pipe from z = %f to z= %f\n",-zd1,-2*conpar[0]-zd1);
316   
317   zd1 += conpar[0] * 2.;
318   
319   tubpar[0] = 20.6/2.;
320   tubpar[1] = 21./2.;
321   tubpar[2] = 450./2.;
322   gMC->Gsvolu("QT07", "TUBE", idtmed[7], tubpar, 3);
323   gMC->Gspos("QT07", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
324   // Ch.debug
325   //printf("\n  QT07 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
326   
327   zd1 += tubpar[2] * 2.;
328   
329   conpar[0] = 13.6/2.;
330   conpar[1] = 25.4/2.;
331   conpar[2] = 25.8/2.;
332   conpar[3] = 20.6/2.;
333   conpar[4] = 21./2.;
334   gMC->Gsvolu("QC03", "CONE", idtmed[7], conpar, 5);
335   gMC->Gspos("QC03", 1, "ZDC ", 0., 0., -conpar[0]-zd1, 0, "ONLY");
336   // Ch.debug
337   //printf("\n  QC03 CONE pipe from z = %f to z= %f\n",-zd1,-2*conpar[0]-zd1);
338   
339   zd1 += conpar[0] * 2.;
340   
341   tubpar[0] = 25.4/2.;
342   tubpar[1] = 25.8/2.;
343   tubpar[2] = 205.8/2.;
344   gMC->Gsvolu("QT08", "TUBE", idtmed[7], tubpar, 3);
345   gMC->Gspos("QT08", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
346   // Ch.debug
347   //printf("\n  QT08 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
348   
349   zd1 += tubpar[2] * 2.;
350   
351   tubpar[0] = 50./2.;
352   tubpar[1] = 50.4/2.;
353   // QT09 is 10 cm longer to accomodate TDI
354   tubpar[2] = 515.4/2.;
355   gMC->Gsvolu("QT09", "TUBE", idtmed[7], tubpar, 3);
356   gMC->Gspos("QT09", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
357   // Ch.debug
358   //printf("\n  QT09 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
359   
360   // --- Insert TDI (inside ZDC volume)
361   boxpar[0] = 5.6;
362   boxpar[1] = 5.6;
363   boxpar[2] = 400./2.;
364   gMC->Gsvolu("QTD1", "BOX ", idtmed[7], boxpar, 3);
365   gMC->Gspos("QTD1", 1, "ZDC ", -3., 10.6,  -tubpar[2]-zd1-56.3, 0, "ONLY");
366   gMC->Gspos("QTD1", 2, "ZDC ", -3., -10.6, -tubpar[2]-zd1-56.3, 0, "ONLY");
367   
368   boxpar[0] = 0.2/2.;
369   boxpar[1] = 5.6;
370   boxpar[2] = 400./2.;
371   gMC->Gsvolu("QTD2", "BOX ", idtmed[6], boxpar, 3);
372   gMC->Gspos("QTD2", 1, "ZDC ", -8.6-boxpar[0], 0., -tubpar[2]-zd1-56.3, 0, "ONLY");
373   
374   tubspar[0] = 10.5;    // R = 10.5 cm------------------------------------------
375   tubspar[1] = 10.7;
376   tubspar[2] = 400./2.;
377   tubspar[3] = 360.-75.5;
378   tubspar[4] = 75.5; 
379   gMC->Gsvolu("QTD3", "TUBS", idtmed[6], tubspar, 5);
380   gMC->Gspos("QTD3", 1, "ZDC ", 0., 0., -tubpar[2]-zd1-56.3, 0, "ONLY");
381   // Ch.debug
382   //printf("\n  TDI volume from z = %f to z= %f\n",-tubpar[2]-zd1-56.3,-tubpar[2]-zd1-56.3-400.);
383
384   zd1 += tubpar[2] * 2.;
385   
386   tubpar[0] = 50./2.;
387   tubpar[1] = 50.4/2.;
388   // QT10 is 10 cm shorter
389   tubpar[2] = 690./2.;
390   gMC->Gsvolu("QT10", "TUBE", idtmed[7], tubpar, 3);
391   gMC->Gspos("QT10", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
392   // Ch.debug
393   //printf("\n  QT10 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
394   
395   zd1 += tubpar[2] * 2.;
396   
397   tubpar[0] = 50./2.;
398   tubpar[1] = 50.4/2.;
399   tubpar[2] = 778.5/2.;
400   gMC->Gsvolu("QT11", "TUBE", idtmed[7], tubpar, 3);
401   gMC->Gspos("QT11", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
402   // Ch.debug
403   //printf("\n  QT11 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
404   
405   zd1 += tubpar[2] * 2.;
406   
407   conpar[0] = 14.18/2.;
408   conpar[1] = 55./2.;
409   conpar[2] = 55.4/2.;
410   conpar[3] = 50./2.;
411   conpar[4] = 50.4/2.;
412   gMC->Gsvolu("QC04", "CONE", idtmed[7], conpar, 5);
413   gMC->Gspos("QC04", 1, "ZDC ", 0., 0., -conpar[0]-zd1, 0, "ONLY");
414   // Ch.debug
415   //printf("\n  QC04 CONE pipe from z = %f to z= %f\n",-zd1,-2*conpar[0]-zd1);
416   
417   zd1 += conpar[0] * 2.;
418   
419   tubpar[0] = 55./2.;
420   tubpar[1] = 55.4/2.;
421   tubpar[2] = 730./2.;
422   gMC->Gsvolu("QT12", "TUBE", idtmed[7], tubpar, 3);
423   gMC->Gspos("QT12", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
424   // Ch.debug
425   //printf("\n  QT12 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
426   
427   zd1 += tubpar[2] * 2.;
428   
429   conpar[0] = 36.86/2.;
430   conpar[1] = 68./2.;
431   conpar[2] = 68.4/2.;
432   conpar[3] = 55./2.;
433   conpar[4] = 55.4/2.;
434   gMC->Gsvolu("QC05", "CONE", idtmed[7], conpar, 5);
435   gMC->Gspos("QC05", 1, "ZDC ", 0., 0., -conpar[0]-zd1, 0, "ONLY");
436   // Ch.debug
437   //printf("\n  QC05 CONE pipe from z = %f to z= %f\n",-zd1,-2*conpar[0]-zd1);
438   
439   zd1 += conpar[0] * 2.;
440   
441   tubpar[0] = 68./2.;
442   tubpar[1] = 68.4/2.;
443   tubpar[2] = 927.3/2.;
444   gMC->Gsvolu("QT13", "TUBE", idtmed[7], tubpar, 3);
445   gMC->Gspos("QT13", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
446   // Ch.debug
447   //printf("\n  QT13 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
448   
449   zd1 += tubpar[2] * 2.;
450   
451   tubpar[0] = 0./2.;
452   tubpar[1] = 68.4/2.;
453   tubpar[2] = 0.2/2.;
454   gMC->Gsvolu("QT14", "TUBE", idtmed[8], tubpar, 3);
455   gMC->Gspos("QT14", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
456   // Ch.debug
457   //printf("\n  QT14 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
458   
459   zd1 += tubpar[2] * 2.;
460   
461   tubpar[0] = 0./2.;
462   tubpar[1] = 6.4/2.;
463   tubpar[2] = 0.2/2.;
464   gMC->Gsvolu("QT15", "TUBE", idtmed[11], tubpar, 3);
465   //-- Position QT15 inside QT14
466   gMC->Gspos("QT15", 1, "QT14", -7.7, 0., 0., 0, "ONLY");
467
468   gMC->Gsvolu("QT16", "TUBE", idtmed[11], tubpar, 3);  
469   //-- Position QT16 inside QT14
470   gMC->Gspos("QT16", 1, "QT14", 7.7, 0., 0., 0, "ONLY");
471   
472   
473   //-- BEAM PIPE BETWEEN END OF CONICAL PIPE AND BEGINNING OF D2 
474   
475   tubpar[0] = 6.4/2.;
476   tubpar[1] = 6.8/2.;
477   tubpar[2] = 680.8/2.;
478   gMC->Gsvolu("QT17", "TUBE", idtmed[7], tubpar, 3);
479
480   tubpar[0] = 6.4/2.;
481   tubpar[1] = 6.8/2.;
482   tubpar[2] = 680.8/2.;
483   gMC->Gsvolu("QT18", "TUBE", idtmed[7], tubpar, 3);
484   
485   // -- ROTATE PIPES 
486   Float_t angle = 0.143*kDegrad; // Rotation angle
487   
488   //AliMatrix(im1, 90.+0.143, 0., 90., 90., 0.143, 0.); // x<0
489   gMC->Matrix(im1, 90.+0.143, 0., 90., 90., 0.143, 0.); // x<0
490   gMC->Gspos("QT17", 1, "ZDC ", TMath::Sin(angle) * 680.8/ 2. - 9.4, 
491              0., -tubpar[2]-zd1, im1, "ONLY"); 
492              
493   //AliMatrix(im2, 90.-0.143, 0., 90., 90., 0.143, 180.); // x>0 (ZP)
494   gMC->Matrix(im2, 90.-0.143, 0., 90., 90., 0.143, 180.); // x>0 (ZP)
495   gMC->Gspos("QT18", 1, "ZDC ", 9.7 - TMath::Sin(angle) * 680.8 / 2., 
496              0., -tubpar[2]-zd1, im2, "ONLY"); 
497                  
498   // --  END OF BEAM PIPE VOLUME DEFINITION.  
499   // ----------------------------------------------------------------
500    
501   // ----------------------------------------------------------------
502   // --  MAGNET DEFINITION  -> LHC OPTICS 6.5  
503   // ----------------------------------------------------------------      
504   // --  COMPENSATOR DIPOLE (MBXW)
505   zc = 1921.6;   
506   
507   // --  GAP (VACUUM WITH MAGNETIC FIELD)
508   tubpar[0] = 0.;
509   tubpar[1] = 4.5;
510   tubpar[2] = 170./2.;
511   gMC->Gsvolu("MBXW", "TUBE", idtmed[11], tubpar, 3);
512
513   // --  YOKE 
514   tubpar[0] = 4.5;
515   tubpar[1] = 55.;
516   tubpar[2] = 170./2.;
517   gMC->Gsvolu("YMBX", "TUBE", idtmed[13], tubpar, 3);
518
519   gMC->Gspos("MBXW", 1, "ZDC ", 0., 0., -tubpar[2]-zc, 0, "ONLY");
520   gMC->Gspos("YMBX", 1, "ZDC ", 0., 0., -tubpar[2]-zc, 0, "ONLY");
521   
522   
523   // -- INNER TRIPLET 
524   zq = 2296.5; 
525
526   // -- DEFINE MQXL AND MQX QUADRUPOLE ELEMENT 
527   // --  MQXL 
528   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
529   tubpar[0] = 0.;
530   tubpar[1] = 3.5;
531   tubpar[2] = 637./2.;
532   gMC->Gsvolu("MQXL", "TUBE", idtmed[11], tubpar, 3);
533   
534   
535   // --  YOKE 
536   tubpar[0] = 3.5;
537   tubpar[1] = 22.;
538   tubpar[2] = 637./2.;
539   gMC->Gsvolu("YMQL", "TUBE", idtmed[7], tubpar, 3);
540   
541   gMC->Gspos("MQXL", 1, "ZDC ", 0., 0., -tubpar[2]-zq, 0, "ONLY");
542   gMC->Gspos("YMQL", 1, "ZDC ", 0., 0., -tubpar[2]-zq, 0, "ONLY");
543   
544   gMC->Gspos("MQXL", 2, "ZDC ", 0., 0., -tubpar[2]-zq-2430., 0, "ONLY");
545   gMC->Gspos("YMQL", 2, "ZDC ", 0., 0., -tubpar[2]-zq-2430., 0, "ONLY");
546   
547   // --  MQX 
548   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
549   tubpar[0] = 0.;
550   tubpar[1] = 3.5;
551   tubpar[2] = 550./2.;
552   gMC->Gsvolu("MQX ", "TUBE", idtmed[11], tubpar, 3);
553   
554   // --  YOKE 
555   tubpar[0] = 3.5;
556   tubpar[1] = 22.;
557   tubpar[2] = 550./2.;
558   gMC->Gsvolu("YMQ ", "TUBE", idtmed[7], tubpar, 3);
559   
560   gMC->Gspos("MQX ", 1, "ZDC ", 0., 0., -tubpar[2]-zq-908.5,  0, "ONLY");
561   gMC->Gspos("YMQ ", 1, "ZDC ", 0., 0., -tubpar[2]-zq-908.5,  0, "ONLY");
562   
563   gMC->Gspos("MQX ", 2, "ZDC ", 0., 0., -tubpar[2]-zq-1558.5, 0, "ONLY");
564   gMC->Gspos("YMQ ", 2, "ZDC ", 0., 0., -tubpar[2]-zq-1558.5, 0, "ONLY");
565   
566   // -- SEPARATOR DIPOLE D1 
567   zd1 = 5838.3;
568   
569   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
570   tubpar[0] = 0.;
571   tubpar[1] = 6.94/2.;
572   tubpar[2] = 945./2.;
573   gMC->Gsvolu("MD1 ", "TUBE", idtmed[11], tubpar, 3);
574   
575   // --  Insert horizontal Cu plates inside D1 
576   // --   (to simulate the vacuum chamber)
577   boxpar[0] = TMath::Sqrt(tubpar[1]*tubpar[1]-(2.98+0.2)*(2.98+0.2)) - 0.05;
578   boxpar[1] = 0.2/2.;
579   boxpar[2] =945./2.;
580   gMC->Gsvolu("MD1V", "BOX ", idtmed[6], boxpar, 3);
581   gMC->Gspos("MD1V", 1, "MD1 ", 0., 2.98+boxpar[1], 0., 0, "ONLY");
582   gMC->Gspos("MD1V", 2, "MD1 ", 0., -2.98-boxpar[1], 0., 0, "ONLY");
583     
584   // --  YOKE 
585   tubpar[0] = 0.;
586   tubpar[1] = 110./2;
587   tubpar[2] = 945./2.;
588   gMC->Gsvolu("YD1 ", "TUBE", idtmed[7], tubpar, 3);
589   
590   gMC->Gspos("YD1 ", 1, "ZDC ", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
591   gMC->Gspos("MD1 ", 1, "YD1 ", 0., 0., 0., 0, "ONLY");
592   
593   // -- DIPOLE D2 
594   // --- LHC optics v6.4
595   zd2 = 12147.6;
596   
597   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
598   tubpar[0] = 0.;
599   tubpar[1] = 7.5/2.;
600   tubpar[2] = 945./2.;
601   gMC->Gsvolu("MD2 ", "TUBE", idtmed[11], tubpar, 3);
602   
603   // --  YOKE 
604   tubpar[0] = 0.;
605   tubpar[1] = 55.;
606   tubpar[2] = 945./2.;
607   gMC->Gsvolu("YD2 ", "TUBE", idtmed[7], tubpar, 3);
608   
609   gMC->Gspos("YD2 ", 1, "ZDC ", 0., 0., -tubpar[2]-zd2, 0, "ONLY");
610   
611   gMC->Gspos("MD2 ", 1, "YD2 ", -9.4, 0., 0., 0, "ONLY");
612   gMC->Gspos("MD2 ", 2, "YD2 ",  9.4, 0., 0., 0, "ONLY");
613   
614   // -- END OF MAGNET DEFINITION 
615 }
616   
617 //_____________________________________________________________________________
618 void AliZDCv2::CreateZDC()
619 {
620  //
621  // Create the various ZDCs (ZN + ZP)
622  //
623   
624   Float_t dimPb[6], dimVoid[6];
625   
626   Int_t *idtmed = fIdtmed->GetArray();
627
628   // Parameters for hadronic calorimeters geometry
629   // NB -> parameters used ONLY in CreateZDC()
630   Float_t fGrvZN[3] = {0.03, 0.03, 50.};  // Grooves for neutron detector
631   Float_t fGrvZP[3] = {0.04, 0.04, 75.};  // Grooves for proton detector
632   Int_t   fDivZN[3] = {11, 11, 0};        // Division for neutron detector
633   Int_t   fDivZP[3] = {7, 15, 0};         // Division for proton detector
634   Int_t   fTowZN[2] = {2, 2};             // Tower for neutron detector
635   Int_t   fTowZP[2] = {4, 1};             // Tower for proton detector
636
637   // Parameters for EM calorimeter geometry
638   // NB -> parameters used ONLY in CreateZDC()
639   Float_t kDimZEMPb  = 0.15*(TMath::Sqrt(2.));  // z-dimension of the Pb slice
640   Float_t kFibRadZEM = 0.0315;                  // External fiber radius (including cladding)
641   Int_t   fDivZEM[3] = {92, 0, 20};             // Divisions for EM detector
642   Float_t fDimZEM[6] = {fZEMLength, 3.5, 3.5, 45., 0., 0.}; // Dimensions of EM detector
643   Float_t fFibZEM2 = fDimZEM[2]/TMath::Sin(fDimZEM[3]*kDegrad)-kFibRadZEM;
644   Float_t fFibZEM[3] = {0., 0.0275, fFibZEM2};  // Fibers for EM calorimeter
645
646   
647   //-- Create calorimeters geometry
648   
649   // -------------------------------------------------------------------------------
650   //--> Neutron calorimeter (ZN) 
651   
652   gMC->Gsvolu("ZNEU", "BOX ", idtmed[1], fDimZN, 3); // Passive material  
653   gMC->Gsvolu("ZNF1", "TUBE", idtmed[3], fFibZN, 3); // Active material
654   gMC->Gsvolu("ZNF2", "TUBE", idtmed[4], fFibZN, 3); 
655   gMC->Gsvolu("ZNF3", "TUBE", idtmed[4], fFibZN, 3); 
656   gMC->Gsvolu("ZNF4", "TUBE", idtmed[3], fFibZN, 3); 
657   gMC->Gsvolu("ZNG1", "BOX ", idtmed[12], fGrvZN, 3); // Empty grooves 
658   gMC->Gsvolu("ZNG2", "BOX ", idtmed[12], fGrvZN, 3); 
659   gMC->Gsvolu("ZNG3", "BOX ", idtmed[12], fGrvZN, 3); 
660   gMC->Gsvolu("ZNG4", "BOX ", idtmed[12], fGrvZN, 3); 
661   
662   // Divide ZNEU in towers (for hits purposes) 
663   
664   gMC->Gsdvn("ZNTX", "ZNEU", fTowZN[0], 1); // x-tower 
665   gMC->Gsdvn("ZN1 ", "ZNTX", fTowZN[1], 2); // y-tower
666   
667   //-- Divide ZN1 in minitowers 
668   //  fDivZN[0]= NUMBER OF FIBERS PER TOWER ALONG X-AXIS, 
669   //  fDivZN[1]= NUMBER OF FIBERS PER TOWER ALONG Y-AXIS
670   //  (4 fibres per minitower) 
671   
672   gMC->Gsdvn("ZNSL", "ZN1 ", fDivZN[1], 2); // Slices 
673   gMC->Gsdvn("ZNST", "ZNSL", fDivZN[0], 1); // Sticks
674   
675   // --- Position the empty grooves in the sticks (4 grooves per stick)
676   Float_t dx = fDimZN[0] / fDivZN[0] / 4.;
677   Float_t dy = fDimZN[1] / fDivZN[1] / 4.;
678   
679   gMC->Gspos("ZNG1", 1, "ZNST", 0.-dx, 0.+dy, 0., 0, "ONLY");
680   gMC->Gspos("ZNG2", 1, "ZNST", 0.+dx, 0.+dy, 0., 0, "ONLY");
681   gMC->Gspos("ZNG3", 1, "ZNST", 0.-dx, 0.-dy, 0., 0, "ONLY");
682   gMC->Gspos("ZNG4", 1, "ZNST", 0.+dx, 0.-dy, 0., 0, "ONLY");
683   
684   // --- Position the fibers in the grooves 
685   gMC->Gspos("ZNF1", 1, "ZNG1", 0., 0., 0., 0, "ONLY");
686   gMC->Gspos("ZNF2", 1, "ZNG2", 0., 0., 0., 0, "ONLY");
687   gMC->Gspos("ZNF3", 1, "ZNG3", 0., 0., 0., 0, "ONLY");
688   gMC->Gspos("ZNF4", 1, "ZNG4", 0., 0., 0., 0, "ONLY");
689   
690   // --- Position the neutron calorimeter in ZDC 
691   // -- Rotation of ZDCs
692   Int_t irotzdc;
693   gMC->Matrix(irotzdc, 90., 180., 90., 90., 180., 0.);
694   //
695   gMC->Gspos("ZNEU", 1, "ZDC ", fPosZN[0], fPosZN[1], fPosZN[2]-fDimZN[2], irotzdc, "ONLY");
696   //Ch debug
697   //printf("\n ZN -> %f < z < %f cm\n",fPosZN[2],fPosZN[2]-2*fDimZN[2]);
698
699   // -------------------------------------------------------------------------------
700   //--> Proton calorimeter (ZP)  
701   
702   gMC->Gsvolu("ZPRO", "BOX ", idtmed[2], fDimZP, 3); // Passive material
703   gMC->Gsvolu("ZPF1", "TUBE", idtmed[3], fFibZP, 3); // Active material
704   gMC->Gsvolu("ZPF2", "TUBE", idtmed[4], fFibZP, 3); 
705   gMC->Gsvolu("ZPF3", "TUBE", idtmed[4], fFibZP, 3); 
706   gMC->Gsvolu("ZPF4", "TUBE", idtmed[3], fFibZP, 3); 
707   gMC->Gsvolu("ZPG1", "BOX ", idtmed[12], fGrvZP, 3); // Empty grooves 
708   gMC->Gsvolu("ZPG2", "BOX ", idtmed[12], fGrvZP, 3); 
709   gMC->Gsvolu("ZPG3", "BOX ", idtmed[12], fGrvZP, 3); 
710   gMC->Gsvolu("ZPG4", "BOX ", idtmed[12], fGrvZP, 3); 
711     
712   //-- Divide ZPRO in towers(for hits purposes) 
713   
714   gMC->Gsdvn("ZPTX", "ZPRO", fTowZP[0], 1); // x-tower 
715   gMC->Gsdvn("ZP1 ", "ZPTX", fTowZP[1], 2); // y-tower
716   
717   
718   //-- Divide ZP1 in minitowers 
719   //  fDivZP[0]= NUMBER OF FIBERS ALONG X-AXIS PER MINITOWER, 
720   //  fDivZP[1]= NUMBER OF FIBERS ALONG Y-AXIS PER MINITOWER
721   //  (4 fiber per minitower) 
722   
723   gMC->Gsdvn("ZPSL", "ZP1 ", fDivZP[1], 2); // Slices 
724   gMC->Gsdvn("ZPST", "ZPSL", fDivZP[0], 1); // Sticks
725   
726   // --- Position the empty grooves in the sticks (4 grooves per stick)
727   dx = fDimZP[0] / fTowZP[0] / fDivZP[0] / 2.;
728   dy = fDimZP[1] / fTowZP[1] / fDivZP[1] / 2.;
729   
730   gMC->Gspos("ZPG1", 1, "ZPST", 0.-dx, 0.+dy, 0., 0, "ONLY");
731   gMC->Gspos("ZPG2", 1, "ZPST", 0.+dx, 0.+dy, 0., 0, "ONLY");
732   gMC->Gspos("ZPG3", 1, "ZPST", 0.-dx, 0.-dy, 0., 0, "ONLY");
733   gMC->Gspos("ZPG4", 1, "ZPST", 0.+dx, 0.-dy, 0., 0, "ONLY");
734   
735   // --- Position the fibers in the grooves 
736   gMC->Gspos("ZPF1", 1, "ZPG1", 0., 0., 0., 0, "ONLY");
737   gMC->Gspos("ZPF2", 1, "ZPG2", 0., 0., 0., 0, "ONLY");
738   gMC->Gspos("ZPF3", 1, "ZPG3", 0., 0., 0., 0, "ONLY");
739   gMC->Gspos("ZPF4", 1, "ZPG4", 0., 0., 0., 0, "ONLY");
740   
741
742   // --- Position the proton calorimeter in ZDC 
743   gMC->Gspos("ZPRO", 1, "ZDC ", fPosZP[0], fPosZP[1], fPosZP[2]-fDimZP[2], irotzdc, "ONLY");
744   //Ch debug
745   //printf("\n ZP -> %f < z < %f cm\n",fPosZP[2],fPosZP[2]-2*fDimZP[2]);
746     
747   
748   // -------------------------------------------------------------------------------
749   // -> EM calorimeter (ZEM)  
750   
751   gMC->Gsvolu("ZEM ", "PARA", idtmed[10], fDimZEM, 6);
752
753   Int_t irot1, irot2;
754   gMC->Matrix(irot1,0.,0.,90.,90.,-90.,0.);                    // Rotation matrix 1  
755   gMC->Matrix(irot2,180.,0.,90.,fDimZEM[3]+90.,90.,fDimZEM[3]);// Rotation matrix 2
756   //printf("irot1 = %d, irot2 = %d \n", irot1, irot2);
757   
758   gMC->Gsvolu("ZEMF", "TUBE", idtmed[3], fFibZEM, 3);   // Active material
759
760   gMC->Gsdvn("ZETR", "ZEM ", fDivZEM[2], 1);            // Tranches 
761   
762   dimPb[0] = kDimZEMPb;                                 // Lead slices 
763   dimPb[1] = fDimZEM[2];
764   dimPb[2] = fDimZEM[1];
765   //dimPb[3] = fDimZEM[3]; //controllare
766   dimPb[3] = 90.-fDimZEM[3]; //originale
767   dimPb[4] = 0.;
768   dimPb[5] = 0.;
769   gMC->Gsvolu("ZEL0", "PARA", idtmed[5], dimPb, 6);
770   gMC->Gsvolu("ZEL1", "PARA", idtmed[5], dimPb, 6);
771   gMC->Gsvolu("ZEL2", "PARA", idtmed[5], dimPb, 6);
772   
773   // --- Position the lead slices in the tranche 
774   Float_t zTran = fDimZEM[0]/fDivZEM[2]; 
775   Float_t zTrPb = -zTran+kDimZEMPb;
776   gMC->Gspos("ZEL0", 1, "ZETR", zTrPb, 0., 0., 0, "ONLY");
777   gMC->Gspos("ZEL1", 1, "ZETR", kDimZEMPb, 0., 0., 0, "ONLY");
778   
779   // --- Vacuum zone (to be filled with fibres)
780   dimVoid[0] = (zTran-2*kDimZEMPb)/2.;
781   dimVoid[1] = fDimZEM[2];
782   dimVoid[2] = fDimZEM[1];
783   dimVoid[3] = 90.-fDimZEM[3];
784   dimVoid[4] = 0.;
785   dimVoid[5] = 0.;
786   gMC->Gsvolu("ZEV0", "PARA", idtmed[10], dimVoid,6);
787   gMC->Gsvolu("ZEV1", "PARA", idtmed[10], dimVoid,6);
788   
789   // --- Divide the vacuum slice into sticks along x axis
790   gMC->Gsdvn("ZES0", "ZEV0", fDivZEM[0], 3); 
791   gMC->Gsdvn("ZES1", "ZEV1", fDivZEM[0], 3); 
792   
793   // --- Positioning the fibers into the sticks
794   gMC->Gspos("ZEMF", 1,"ZES0", 0., 0., 0., irot2, "ONLY");
795   gMC->Gspos("ZEMF", 1,"ZES1", 0., 0., 0., irot2, "ONLY");
796   
797   // --- Positioning the vacuum slice into the tranche
798   Float_t displFib = fDimZEM[1]/fDivZEM[0];
799   gMC->Gspos("ZEV0", 1,"ZETR", -dimVoid[0], 0., 0., 0, "ONLY");
800   gMC->Gspos("ZEV1", 1,"ZETR", -dimVoid[0]+zTran, 0., displFib, 0, "ONLY");
801
802   // --- Positioning the ZEM into the ZDC - rotation for 90 degrees  
803   // NB -> In AliZDCv2 ZEM is positioned in ALIC (instead of in ZDC) volume
804   //       beacause it's impossible to make a ZDC pcon volume to contain
805   //       both hadronics and EM calorimeters. 
806   gMC->Gspos("ZEM ", 1,"ALIC", -fPosZEM[0], fPosZEM[1], fPosZEM[2]+fDimZEM[0], irot1, "ONLY");
807   
808   // Second EM ZDC (same side w.r.t. IP, just on the other side w.r.t. beam pipe)
809   gMC->Gspos("ZEM ", 2,"ALIC", fPosZEM[0], fPosZEM[1], fPosZEM[2]+fDimZEM[0], irot1, "ONLY");
810   
811   // --- Adding last slice at the end of the EM calorimeter 
812   Float_t zLastSlice = fPosZEM[2]+kDimZEMPb+2*fDimZEM[0];
813   gMC->Gspos("ZEL2", 1,"ALIC", fPosZEM[0], fPosZEM[1], zLastSlice, irot1, "ONLY");
814   //Ch debug
815   //printf("\n ZEM lenght = %f cm\n",2*fZEMLength);
816   //printf("\n ZEM -> %f < z < %f cm\n",fPosZEM[2],fPosZEM[2]+2*fZEMLength+zLastSlice+kDimZEMPb);
817   
818 }
819  
820 //_____________________________________________________________________________
821 void AliZDCv2::DrawModule() const
822 {
823   //
824   // Draw a shaded view of the Zero Degree Calorimeter version 1
825   //
826
827   // Set everything unseen
828   gMC->Gsatt("*", "seen", -1);
829   // 
830   // Set ALIC mother transparent
831   gMC->Gsatt("ALIC","SEEN",0);
832   //
833   // Set the volumes visible
834   gMC->Gsatt("ZDC ","SEEN",0);
835   gMC->Gsatt("QT01","SEEN",1);
836   gMC->Gsatt("QT02","SEEN",1);
837   gMC->Gsatt("QT03","SEEN",1);
838   gMC->Gsatt("QT04","SEEN",1);
839   gMC->Gsatt("QT05","SEEN",1);
840   gMC->Gsatt("QT06","SEEN",1);
841   gMC->Gsatt("QT07","SEEN",1);
842   gMC->Gsatt("QT08","SEEN",1);
843   gMC->Gsatt("QT09","SEEN",1);
844   gMC->Gsatt("QT10","SEEN",1);
845   gMC->Gsatt("QT11","SEEN",1);
846   gMC->Gsatt("QT12","SEEN",1);
847   gMC->Gsatt("QT13","SEEN",1);
848   gMC->Gsatt("QT14","SEEN",1);
849   gMC->Gsatt("QT15","SEEN",1);
850   gMC->Gsatt("QT16","SEEN",1);
851   gMC->Gsatt("QT17","SEEN",1);
852   gMC->Gsatt("QT18","SEEN",1);
853   gMC->Gsatt("QC01","SEEN",1);
854   gMC->Gsatt("QC02","SEEN",1);
855   gMC->Gsatt("QC03","SEEN",1);
856   gMC->Gsatt("QC04","SEEN",1);
857   gMC->Gsatt("QC05","SEEN",1);
858   gMC->Gsatt("QTD1","SEEN",1);
859   gMC->Gsatt("QTD2","SEEN",1);
860   gMC->Gsatt("QTD3","SEEN",1);
861   gMC->Gsatt("MQXL","SEEN",1);
862   gMC->Gsatt("YMQL","SEEN",1);
863   gMC->Gsatt("MQX ","SEEN",1);
864   gMC->Gsatt("YMQ ","SEEN",1);
865   gMC->Gsatt("ZQYX","SEEN",1);
866   gMC->Gsatt("MD1 ","SEEN",1);
867   gMC->Gsatt("MD1V","SEEN",1);
868   gMC->Gsatt("YD1 ","SEEN",1);
869   gMC->Gsatt("MD2 ","SEEN",1);
870   gMC->Gsatt("YD2 ","SEEN",1);
871   gMC->Gsatt("ZNEU","SEEN",0);
872   gMC->Gsatt("ZNF1","SEEN",0);
873   gMC->Gsatt("ZNF2","SEEN",0);
874   gMC->Gsatt("ZNF3","SEEN",0);
875   gMC->Gsatt("ZNF4","SEEN",0);
876   gMC->Gsatt("ZNG1","SEEN",0);
877   gMC->Gsatt("ZNG2","SEEN",0);
878   gMC->Gsatt("ZNG3","SEEN",0);
879   gMC->Gsatt("ZNG4","SEEN",0);
880   gMC->Gsatt("ZNTX","SEEN",0);
881   gMC->Gsatt("ZN1 ","COLO",4); 
882   gMC->Gsatt("ZN1 ","SEEN",1);
883   gMC->Gsatt("ZNSL","SEEN",0);
884   gMC->Gsatt("ZNST","SEEN",0);
885   gMC->Gsatt("ZPRO","SEEN",0);
886   gMC->Gsatt("ZPF1","SEEN",0);
887   gMC->Gsatt("ZPF2","SEEN",0);
888   gMC->Gsatt("ZPF3","SEEN",0);
889   gMC->Gsatt("ZPF4","SEEN",0);
890   gMC->Gsatt("ZPG1","SEEN",0);
891   gMC->Gsatt("ZPG2","SEEN",0);
892   gMC->Gsatt("ZPG3","SEEN",0);
893   gMC->Gsatt("ZPG4","SEEN",0);
894   gMC->Gsatt("ZPTX","SEEN",0);
895   gMC->Gsatt("ZP1 ","COLO",6); 
896   gMC->Gsatt("ZP1 ","SEEN",1);
897   gMC->Gsatt("ZPSL","SEEN",0);
898   gMC->Gsatt("ZPST","SEEN",0);
899   gMC->Gsatt("ZEM ","COLO",7); 
900   gMC->Gsatt("ZEM ","SEEN",1);
901   gMC->Gsatt("ZEMF","SEEN",0);
902   gMC->Gsatt("ZETR","SEEN",0);
903   gMC->Gsatt("ZEL0","SEEN",0);
904   gMC->Gsatt("ZEL1","SEEN",0);
905   gMC->Gsatt("ZEL2","SEEN",0);
906   gMC->Gsatt("ZEV0","SEEN",0);
907   gMC->Gsatt("ZEV1","SEEN",0);
908   gMC->Gsatt("ZES0","SEEN",0);
909   gMC->Gsatt("ZES1","SEEN",0);
910   
911   //
912   gMC->Gdopt("hide", "on");
913   gMC->Gdopt("shad", "on");
914   gMC->Gsatt("*", "fill", 7);
915   gMC->SetClipBox(".");
916   gMC->SetClipBox("*", 0, 100, -100, 100, 12000, 16000);
917   gMC->DefaultRange();
918   gMC->Gdraw("alic", 40, 30, 0, 488, 220, .07, .07);
919   gMC->Gdhead(1111, "Zero Degree Calorimeter Version 1");
920   gMC->Gdman(18, 4, "MAN");
921 }
922
923 //_____________________________________________________________________________
924 void AliZDCv2::CreateMaterials()
925 {
926   //
927   // Create Materials for the Zero Degree Calorimeter
928   //
929   
930   Float_t dens, ubuf[1], wmat[2], a[2], z[2];
931   
932   // --- Store in UBUF r0 for nuclear radius calculation R=r0*A**1/3 
933
934   // --- Tantalum -> ZN passive material
935   ubuf[0] = 1.1;
936   AliMaterial(1, "TANT", 180.95, 73., 16.65, .4, 11.9, ubuf, 1);
937     
938   // --- Tungsten 
939 //  ubuf[0] = 1.11;
940 //  AliMaterial(1, "TUNG", 183.85, 74., 19.3, .35, 10.3, ubuf, 1);
941   
942   // --- Brass (CuZn)  -> ZP passive material
943   dens = 8.48;
944   a[0] = 63.546;
945   a[1] = 65.39;
946   z[0] = 29.;
947   z[1] = 30.;
948   wmat[0] = .63;
949   wmat[1] = .37;
950   AliMixture(2, "BRASS               ", a, z, dens, 2, wmat);
951   
952   // --- SiO2 
953   dens = 2.64;
954   a[0] = 28.086;
955   a[1] = 15.9994;
956   z[0] = 14.;
957   z[1] = 8.;
958   wmat[0] = 1.;
959   wmat[1] = 2.;
960   AliMixture(3, "SIO2                ", a, z, dens, -2, wmat);  
961   
962   // --- Lead 
963   ubuf[0] = 1.12;
964   AliMaterial(5, "LEAD", 207.19, 82., 11.35, .56, 18.5, ubuf, 1);
965
966   // --- Copper 
967   ubuf[0] = 1.10;
968   AliMaterial(6, "COPP", 63.54, 29., 8.96, 1.4, 0., ubuf, 1);
969   
970   // --- Iron (energy loss taken into account)
971   ubuf[0] = 1.1;
972   AliMaterial(7, "IRON0", 55.85, 26., 7.87, 1.76, 0., ubuf, 1);
973   
974   // --- Iron (no energy loss)
975   ubuf[0] = 1.1;
976   AliMaterial(8, "IRON1", 55.85, 26., 7.87, 1.76, 0., ubuf, 1);
977   AliMaterial(13, "IRON2", 55.85, 26., 7.87, 1.76, 0., ubuf, 1);
978   
979   // ---------------------------------------------------------  
980   Float_t aResGas[3]={1.008,12.0107,15.9994};
981   Float_t zResGas[3]={1.,6.,8.};
982   Float_t wResGas[3]={0.28,0.28,0.44};
983   Float_t dResGas = 3.2E-14;
984
985   // --- Vacuum (no magnetic field) 
986   AliMixture(10, "VOID", aResGas, zResGas, dResGas, 3, wResGas);
987   //AliMaterial(10, "VOID", 1e-16, 1e-16, 1e-16, 1e16, 1e16, ubuf,0);
988   
989   // --- Vacuum (with magnetic field) 
990   AliMixture(11, "VOIM", aResGas, zResGas, dResGas, 3, wResGas);
991   //AliMaterial(11, "VOIM", 1e-16, 1e-16, 1e-16, 1e16, 1e16, ubuf,0);
992   
993   // --- Air (no magnetic field)
994   Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
995   Float_t zAir[4]={6.,7.,8.,18.};
996   Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
997   Float_t dAir = 1.20479E-3;
998   //
999   AliMixture(12, "Air    $", aAir, zAir, dAir, 4, wAir);
1000   //AliMaterial(12, "Air    $", 14.61, 7.3, .001205, 30420., 67500., ubuf, 0);
1001   
1002   // ---  Definition of tracking media: 
1003   
1004   // --- Tantalum = 1 ; 
1005   // --- Brass = 2 ; 
1006   // --- Fibers (SiO2) = 3 ; 
1007   // --- Fibers (SiO2) = 4 ; 
1008   // --- Lead = 5 ; 
1009   // --- Copper = 6 ; 
1010   // --- Iron (with energy loss) = 7 ; 
1011   // --- Iron (without energy loss) = 8 ; 
1012   // --- Vacuum (no field) = 10 
1013   // --- Vacuum (with field) = 11 
1014   // --- Air (no field) = 12 
1015   
1016   // **************************************************** 
1017   //     Tracking media parameters
1018   //
1019   Float_t epsil  = 0.01;   // Tracking precision, 
1020   Float_t stmin  = 0.01;   // Min. value 4 max. step (cm)
1021   Float_t stemax = 1.;     // Max. step permitted (cm) 
1022   Float_t tmaxfd = 0.;     // Maximum angle due to field (degrees) 
1023   Float_t deemax = -1.;    // Maximum fractional energy loss
1024   Float_t nofieldm = 0.;   // Max. field value (no field)
1025   Float_t fieldm = 45.;    // Max. field value (with field)
1026   Int_t isvol = 0;         // ISVOL =0 -> not sensitive volume
1027   Int_t isvolActive = 1;   // ISVOL =1 -> sensitive volume
1028   Int_t inofld = 0;        // IFIELD=0 -> no magnetic field
1029   Int_t ifield =2;         // IFIELD=2 -> magnetic field defined in AliMagFC.h
1030   // *****************************************************
1031   
1032   AliMedium(1, "ZTANT", 1, isvolActive, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1033   AliMedium(2, "ZBRASS",2, isvolActive, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1034   AliMedium(3, "ZSIO2", 3, isvolActive, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1035   AliMedium(4, "ZQUAR", 3, isvolActive, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1036   AliMedium(5, "ZLEAD", 5, isvolActive, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1037   AliMedium(6, "ZCOPP", 6, isvol, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1038   AliMedium(7, "ZIRON", 7, isvol, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1039   AliMedium(8, "ZIRONN",8, isvol, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1040   AliMedium(10,"ZVOID",10, isvol, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1041   AliMedium(12,"ZAIR", 12, isvol, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1042   //
1043   AliMedium(11,"ZVOIM", 11, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
1044   AliMedium(13,"ZIRONE",13, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil, stmin);  
1045
1046
1047 //_____________________________________________________________________________
1048 void AliZDCv2::AddAlignableVolumes() const
1049 {
1050  //
1051  // Create entries for alignable volumes associating the symbolic volume
1052  // name with the corresponding volume path. Needs to be syncronized with
1053  // eventual changes in the geometry.
1054  //
1055  TString volpath1 = "ALIC_1/ZDC_1/ZNEU_1";
1056  TString volpath2 = "ALIC_1/ZDC_1/ZPRO_1";
1057
1058  TString symname1="ZDC/NeutronZDC";
1059  TString symname2="ZDC/ProtonZDC";
1060
1061  if(!gGeoManager->SetAlignableEntry(symname1.Data(),volpath1.Data()))
1062      AliFatal(Form("Alignable entry %s not created. Volume path %s not valid",   symname1.Data(),volpath1.Data()));
1063
1064  if(!gGeoManager->SetAlignableEntry(symname2.Data(),volpath2.Data()))
1065      AliFatal(Form("Alignable entry %s not created. Volume path %s not valid",   symname2.Data(),volpath2.Data()));
1066 }
1067
1068 //_____________________________________________________________________________
1069 void AliZDCv2::Init()
1070 {
1071   InitTables();
1072   Int_t *idtmed = fIdtmed->GetArray();  
1073   Int_t i;
1074   // Thresholds for showering in the ZDCs 
1075   i = 1; //tantalum
1076   gMC->Gstpar(idtmed[i], "CUTGAM", .001);
1077   gMC->Gstpar(idtmed[i], "CUTELE", .001);
1078   gMC->Gstpar(idtmed[i], "CUTNEU", .01);
1079   gMC->Gstpar(idtmed[i], "CUTHAD", .01);
1080   i = 2; //brass
1081   gMC->Gstpar(idtmed[i], "CUTGAM", .001);
1082   gMC->Gstpar(idtmed[i], "CUTELE", .001);
1083   gMC->Gstpar(idtmed[i], "CUTNEU", .01);
1084   gMC->Gstpar(idtmed[i], "CUTHAD", .01);
1085   i = 5; //lead
1086   gMC->Gstpar(idtmed[i], "CUTGAM", .001);
1087   gMC->Gstpar(idtmed[i], "CUTELE", .001);
1088   gMC->Gstpar(idtmed[i], "CUTNEU", .01);
1089   gMC->Gstpar(idtmed[i], "CUTHAD", .01);
1090   
1091   // Avoid too detailed showering in TDI 
1092   i = 6; //copper
1093   gMC->Gstpar(idtmed[i], "CUTGAM", .1);
1094   gMC->Gstpar(idtmed[i], "CUTELE", .1);
1095   gMC->Gstpar(idtmed[i], "CUTNEU", 1.);
1096   gMC->Gstpar(idtmed[i], "CUTHAD", 1.);
1097   
1098   // Avoid too detailed showering along the beam line 
1099   i = 7; //iron with energy loss (ZIRON)
1100   gMC->Gstpar(idtmed[i], "CUTGAM", .1);
1101   gMC->Gstpar(idtmed[i], "CUTELE", .1);
1102   gMC->Gstpar(idtmed[i], "CUTNEU", 1.);
1103   gMC->Gstpar(idtmed[i], "CUTHAD", 1.);
1104   
1105   // Avoid too detailed showering along the beam line 
1106   i = 8; //iron with energy loss (ZIRONN)
1107   gMC->Gstpar(idtmed[i], "CUTGAM", .1);
1108   gMC->Gstpar(idtmed[i], "CUTELE", .1);
1109   gMC->Gstpar(idtmed[i], "CUTNEU", 1.);
1110   gMC->Gstpar(idtmed[i], "CUTHAD", 1.);
1111   // Avoid too detailed showering along the beam line 
1112   i = 13; //iron with energy loss (ZIRONN)
1113   gMC->Gstpar(idtmed[i], "CUTGAM", 1.);
1114   gMC->Gstpar(idtmed[i], "CUTELE", 1.);
1115   gMC->Gstpar(idtmed[i], "CUTNEU", 1.);
1116   gMC->Gstpar(idtmed[i], "CUTHAD", 1.);
1117   
1118   // Avoid interaction in fibers (only energy loss allowed) 
1119   i = 3; //fibers (ZSI02)
1120   gMC->Gstpar(idtmed[i], "DCAY", 0.);
1121   gMC->Gstpar(idtmed[i], "MULS", 0.);
1122   gMC->Gstpar(idtmed[i], "PFIS", 0.);
1123   gMC->Gstpar(idtmed[i], "MUNU", 0.);
1124   gMC->Gstpar(idtmed[i], "LOSS", 1.);
1125   gMC->Gstpar(idtmed[i], "PHOT", 0.);
1126   gMC->Gstpar(idtmed[i], "COMP", 0.);
1127   gMC->Gstpar(idtmed[i], "PAIR", 0.);
1128   gMC->Gstpar(idtmed[i], "BREM", 0.);
1129   gMC->Gstpar(idtmed[i], "DRAY", 0.);
1130   gMC->Gstpar(idtmed[i], "ANNI", 0.);
1131   gMC->Gstpar(idtmed[i], "HADR", 0.);
1132   i = 4; //fibers (ZQUAR)
1133   gMC->Gstpar(idtmed[i], "DCAY", 0.);
1134   gMC->Gstpar(idtmed[i], "MULS", 0.);
1135   gMC->Gstpar(idtmed[i], "PFIS", 0.);
1136   gMC->Gstpar(idtmed[i], "MUNU", 0.);
1137   gMC->Gstpar(idtmed[i], "LOSS", 1.);
1138   gMC->Gstpar(idtmed[i], "PHOT", 0.);
1139   gMC->Gstpar(idtmed[i], "COMP", 0.);
1140   gMC->Gstpar(idtmed[i], "PAIR", 0.);
1141   gMC->Gstpar(idtmed[i], "BREM", 0.);
1142   gMC->Gstpar(idtmed[i], "DRAY", 0.);
1143   gMC->Gstpar(idtmed[i], "ANNI", 0.);
1144   gMC->Gstpar(idtmed[i], "HADR", 0.);
1145   
1146   // Avoid interaction in void 
1147   i = 11; //void with field
1148   gMC->Gstpar(idtmed[i], "DCAY", 0.);
1149   gMC->Gstpar(idtmed[i], "MULS", 0.);
1150   gMC->Gstpar(idtmed[i], "PFIS", 0.);
1151   gMC->Gstpar(idtmed[i], "MUNU", 0.);
1152   gMC->Gstpar(idtmed[i], "LOSS", 0.);
1153   gMC->Gstpar(idtmed[i], "PHOT", 0.);
1154   gMC->Gstpar(idtmed[i], "COMP", 0.);
1155   gMC->Gstpar(idtmed[i], "PAIR", 0.);
1156   gMC->Gstpar(idtmed[i], "BREM", 0.);
1157   gMC->Gstpar(idtmed[i], "DRAY", 0.);
1158   gMC->Gstpar(idtmed[i], "ANNI", 0.);
1159   gMC->Gstpar(idtmed[i], "HADR", 0.);
1160
1161   //
1162   fMedSensZN  = idtmed[1];  // Sensitive volume: ZN passive material
1163   fMedSensZP  = idtmed[2];  // Sensitive volume: ZP passive material
1164   fMedSensF1  = idtmed[3];  // Sensitive volume: fibres type 1
1165   fMedSensF2  = idtmed[4];  // Sensitive volume: fibres type 2
1166   fMedSensZEM = idtmed[5];  // Sensitive volume: ZEM passive material
1167   fMedSensTDI = idtmed[6];  // Sensitive volume: TDI Cu shield
1168   fMedSensPI  = idtmed[7];  // Sensitive volume: beam pipes
1169   fMedSensGR  = idtmed[12]; // Sensitive volume: air into the grooves
1170 }
1171
1172 //_____________________________________________________________________________
1173 void AliZDCv2::InitTables()
1174 {
1175  //
1176  // Read light tables for Cerenkov light production parameterization 
1177  //
1178
1179   Int_t k, j;
1180
1181   char *lightfName1,*lightfName2,*lightfName3,*lightfName4,
1182        *lightfName5,*lightfName6,*lightfName7,*lightfName8;
1183   FILE *fp1, *fp2, *fp3, *fp4, *fp5, *fp6, *fp7, *fp8;
1184
1185   //  --- Reading light tables for ZN 
1186   lightfName1 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620362207s");
1187   if((fp1 = fopen(lightfName1,"r")) == NULL){
1188      printf("Cannot open file fp1 \n");
1189      return;
1190   }
1191   lightfName2 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620362208s");
1192   if((fp2 = fopen(lightfName2,"r")) == NULL){
1193      printf("Cannot open file fp2 \n");
1194      return;
1195   }  
1196   lightfName3 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620362209s");
1197   if((fp3 = fopen(lightfName3,"r")) == NULL){
1198      printf("Cannot open file fp3 \n");
1199      return;
1200   }
1201   lightfName4 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620362210s");
1202   if((fp4 = fopen(lightfName4,"r")) == NULL){
1203      printf("Cannot open file fp4 \n");
1204      return;
1205   }
1206   
1207   for(k=0; k<fNalfan; k++){
1208      for(j=0; j<fNben; j++){
1209        fscanf(fp1,"%f",&fTablen[0][k][j]);
1210        fscanf(fp2,"%f",&fTablen[1][k][j]);
1211        fscanf(fp3,"%f",&fTablen[2][k][j]);
1212        fscanf(fp4,"%f",&fTablen[3][k][j]);
1213      } 
1214   }
1215   fclose(fp1);
1216   fclose(fp2);
1217   fclose(fp3);
1218   fclose(fp4);
1219   
1220   //  --- Reading light tables for ZP and ZEM
1221   lightfName5 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620552207s");
1222   if((fp5 = fopen(lightfName5,"r")) == NULL){
1223      printf("Cannot open file fp5 \n");
1224      return;
1225   }
1226   lightfName6 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620552208s");
1227   if((fp6 = fopen(lightfName6,"r")) == NULL){
1228      printf("Cannot open file fp6 \n");
1229      return;
1230   }
1231   lightfName7 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620552209s");
1232   if((fp7 = fopen(lightfName7,"r")) == NULL){
1233      printf("Cannot open file fp7 \n");
1234      return;
1235   }
1236   lightfName8 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620552210s");
1237   if((fp8 = fopen(lightfName8,"r")) == NULL){
1238      printf("Cannot open file fp8 \n");
1239      return;
1240   }
1241   
1242   for(k=0; k<fNalfap; k++){
1243      for(j=0; j<fNbep; j++){
1244        fscanf(fp5,"%f",&fTablep[0][k][j]);
1245        fscanf(fp6,"%f",&fTablep[1][k][j]);
1246        fscanf(fp7,"%f",&fTablep[2][k][j]);
1247        fscanf(fp8,"%f",&fTablep[3][k][j]);
1248      } 
1249   }
1250   fclose(fp5);
1251   fclose(fp6);
1252   fclose(fp7);
1253   fclose(fp8);
1254 }
1255 //_____________________________________________________________________________
1256 void AliZDCv2::StepManager()
1257 {
1258   //
1259   // Routine called at every step in the Zero Degree Calorimeters
1260   //
1261     
1262   Int_t j, vol[2], ibeta=0, ialfa, ibe, nphe;
1263   Float_t x[3], xdet[3], destep, hits[10], m, ekin, um[3], ud[3], be, out;
1264   //Float_t radius;
1265   Float_t xalic[3], z, guiEff, guiPar[4]={0.31,-0.0004,0.0197,0.7958};
1266   Double_t s[3], p[4];
1267   const char *knamed;
1268
1269   for (j=0;j<10;j++) hits[j]=-999.;
1270   
1271   // --- This part is for no shower developement in beam pipe and TDI
1272   // If particle interacts with beam pipe or TDI -> return
1273   if((gMC->CurrentMedium() == fMedSensPI) || (gMC->CurrentMedium() == fMedSensTDI)){ 
1274   // If option NoShower is set -> StopTrack
1275     if(fNoShower==1) {
1276       if(gMC->CurrentMedium() == fMedSensPI) {
1277         knamed = gMC->CurrentVolName();
1278        if(!strncmp(knamed,"YMQ",3))  fpLostIT += 1;
1279         if(!strncmp(knamed,"YD1",3))   fpLostD1 += 1;
1280       }
1281       else if(gMC->CurrentMedium() == fMedSensTDI){ // NB->Cu = TDI or D1 vacuum chamber
1282         knamed = gMC->CurrentVolName();
1283         if(!strncmp(knamed,"MD1",3)) fpLostD1 += 1;
1284         if(!strncmp(knamed,"QTD",3)) fpLostTDI += 1;
1285       }
1286       printf("\n      # of spectators lost in IT = %d\n",fpLostIT);
1287       printf("\n      # of spectators lost in D1  = %d\n",fpLostD1);
1288       printf("\n      # of spectators lost in TDI = %d\n\n",fpLostTDI);
1289       gMC->StopTrack();
1290     }
1291     return;
1292   }
1293
1294   if((gMC->CurrentMedium() == fMedSensZN) || (gMC->CurrentMedium() == fMedSensZP) ||
1295      (gMC->CurrentMedium() == fMedSensGR) || (gMC->CurrentMedium() == fMedSensF1) ||
1296      (gMC->CurrentMedium() == fMedSensF2) || (gMC->CurrentMedium() == fMedSensZEM)){
1297
1298   
1299   //Particle coordinates 
1300     gMC->TrackPosition(s[0],s[1],s[2]);
1301     for(j=0; j<=2; j++) x[j] = s[j];
1302     hits[0] = x[0];
1303     hits[1] = x[1];
1304     hits[2] = x[2];
1305
1306   // Determine in which ZDC the particle is
1307     knamed = gMC->CurrentVolName();
1308     if(!strncmp(knamed,"ZN",2))      vol[0]=1;
1309     else if(!strncmp(knamed,"ZP",2)) vol[0]=2;
1310     else if(!strncmp(knamed,"ZE",2)) vol[0]=3;
1311   
1312   // Determine in which quadrant the particle is
1313     if(vol[0]==1){      //Quadrant in ZN
1314       // Calculating particle coordinates inside ZN
1315       xdet[0] = x[0]-fPosZN[0];
1316       xdet[1] = x[1]-fPosZN[1];
1317       // Calculating quadrant in ZN
1318       if(xdet[0]<=0.){
1319         if(xdet[1]>=0.)     vol[1]=1;
1320         else if(xdet[1]<0.) vol[1]=3;
1321       }
1322       else if(xdet[0]>0.){
1323         if(xdet[1]>=0.)     vol[1]=2;
1324         else if(xdet[1]<0.) vol[1]=4;
1325       }
1326       if((vol[1]!=1) && (vol[1]!=2) && (vol[1]!=3) && (vol[1]!=4))
1327         printf("\n      ZDC StepManager->ERROR in ZN!!! vol[1] = %d, xdet[0] = %f,"
1328         "xdet[1] = %f\n",vol[1], xdet[0], xdet[1]);
1329     }
1330     
1331     else if(vol[0]==2){ //Quadrant in ZP
1332       // Calculating particle coordinates inside ZP
1333       xdet[0] = x[0]-fPosZP[0];
1334       xdet[1] = x[1]-fPosZP[1];
1335       if(xdet[0]>=fDimZP[0])  xdet[0]=fDimZP[0]-0.01;
1336       if(xdet[0]<=-fDimZP[0]) xdet[0]=-fDimZP[0]+0.01;
1337       // Calculating tower in ZP
1338       Float_t xqZP = xdet[0]/(fDimZP[0]/2.);
1339       for(int i=1; i<=4; i++){
1340          if(xqZP>=(i-3) && xqZP<(i-2)){
1341            vol[1] = i;
1342            break;
1343          }
1344       }
1345       if((vol[1]!=1) && (vol[1]!=2) && (vol[1]!=3) && (vol[1]!=4))
1346         printf("        ZDC StepManager->ERROR in ZP!!! vol[1] = %d, xdet[0] = %f,"
1347         "xdet[1] = %f\n",vol[1], xdet[0], xdet[1]);
1348     }
1349     
1350     // Quadrant in ZEM: vol[1] = 1 -> particle in 1st ZEM (placed at x = 8.5 cm)
1351     //                  vol[1] = 2 -> particle in 2nd ZEM (placed at x = -8.5 cm)
1352     else if(vol[0] == 3){       
1353       if(x[0]>0.){
1354         vol[1] = 1;
1355         // Particle x-coordinate inside ZEM1
1356         xdet[0] = x[0]-fPosZEM[0];
1357       }
1358       else{
1359         vol[1] = 2;
1360         // Particle x-coordinate inside ZEM2
1361         xdet[0] = x[0]+fPosZEM[0];
1362       }
1363       xdet[1] = x[1]-fPosZEM[1];
1364     }
1365
1366   // Store impact point and kinetic energy of the ENTERING particle
1367     
1368       if(gMC->IsTrackEntering()){
1369         //Particle energy
1370         gMC->TrackMomentum(p[0],p[1],p[2],p[3]);
1371         hits[3] = p[3];
1372         // Impact point on ZDC  
1373         hits[4] = xdet[0];
1374         hits[5] = xdet[1];
1375         hits[6] = 0;
1376         hits[7] = 0;
1377         hits[8] = 0;
1378         hits[9] = 0;
1379
1380         AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
1381         
1382         if(fNoShower==1){
1383           if(vol[0]==1) fnDetected += 1;
1384           else if(vol[0]==2) fpDetected += 1;
1385           printf("\n  # of nucleons in ZN = %d",fnDetected);
1386           printf("\n  # of nucleons in ZP = %d\n\n",fpDetected);
1387           gMC->StopTrack();
1388           return;
1389         }
1390       }
1391              
1392       // Charged particles -> Energy loss
1393       if((destep=gMC->Edep())){
1394          if(gMC->IsTrackStop()){
1395            gMC->TrackMomentum(p[0],p[1],p[2],p[3]);
1396            m = gMC->TrackMass();
1397            ekin = p[3]-m;
1398            hits[9] = ekin;
1399            hits[7] = 0.;
1400            hits[8] = 0.;
1401            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
1402            }
1403          else{
1404            hits[9] = destep;
1405            hits[7] = 0.;
1406            hits[8] = 0.;
1407            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
1408            }
1409       }
1410   }
1411
1412
1413   // *** Light production in fibres 
1414   if((gMC->CurrentMedium() == fMedSensF1) || (gMC->CurrentMedium() == fMedSensF2)){
1415
1416      //Select charged particles
1417      if((destep=gMC->Edep())){
1418
1419        // Particle velocity
1420        Float_t beta = 0.;
1421        gMC->TrackMomentum(p[0],p[1],p[2],p[3]);
1422        Float_t ptot=TMath::Sqrt(p[0]*p[0]+p[1]*p[1]+p[2]*p[2]);
1423        if(p[3] > 0.00001) beta =  ptot/p[3];
1424        else return;
1425        if(beta<0.67)return;
1426        else if((beta>=0.67) && (beta<=0.75)) ibeta = 0;
1427        else if((beta>0.75)  && (beta<=0.85)) ibeta = 1;
1428        else if((beta>0.85)  && (beta<=0.95)) ibeta = 2;
1429        else if(beta>0.95) ibeta = 3;
1430  
1431        // Angle between particle trajectory and fibre axis
1432        // 1 -> Momentum directions
1433        um[0] = p[0]/ptot;
1434        um[1] = p[1]/ptot;
1435        um[2] = p[2]/ptot;
1436        gMC->Gmtod(um,ud,2);
1437        // 2 -> Angle < limit angle
1438        Double_t alfar = TMath::ACos(ud[2]);
1439        Double_t alfa = alfar*kRaddeg;
1440        if(alfa>=110.) return;
1441        //
1442        ialfa = Int_t(1.+alfa/2.);
1443  
1444        // Distance between particle trajectory and fibre axis
1445        gMC->TrackPosition(s[0],s[1],s[2]);
1446        for(j=0; j<=2; j++){
1447           x[j] = s[j];
1448        }
1449        gMC->Gmtod(x,xdet,1);
1450        if(TMath::Abs(ud[0])>0.00001){
1451          Float_t dcoeff = ud[1]/ud[0];
1452          be = TMath::Abs((xdet[1]-dcoeff*xdet[0])/TMath::Sqrt(dcoeff*dcoeff+1.));
1453        }
1454        else{
1455          be = TMath::Abs(ud[0]);
1456        }
1457  
1458        ibe = Int_t(be*1000.+1);
1459        //if((vol[0]==1))      radius = fFibZN[1];
1460        //else if((vol[0]==2)) radius = fFibZP[1];
1461  
1462        //Looking into the light tables 
1463        Float_t charge = gMC->TrackCharge();
1464        
1465        if((vol[0]==1)) {        // (1)  ZN fibres
1466          if(ibe>fNben) ibe=fNben;
1467          out =  charge*charge*fTablen[ibeta][ialfa][ibe];
1468          nphe = gRandom->Poisson(out);
1469          // Ch. debug
1470          //if(ibeta==3) printf("\t %f \t %f \t %f\n",alfa, be, out);
1471          //printf("\t ibeta = %d, ialfa = %d, ibe = %d -> nphe = %d\n\n",ibeta,ialfa,ibe,nphe);
1472          if(gMC->CurrentMedium() == fMedSensF1){
1473            hits[7] = nphe;      //fLightPMQ
1474            hits[8] = 0;
1475            hits[9] = 0;
1476            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
1477          }
1478          else{
1479            hits[7] = 0;
1480            hits[8] = nphe;      //fLightPMC
1481            hits[9] = 0;
1482            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
1483          }
1484        } 
1485        else if((vol[0]==2)) {   // (2) ZP fibres
1486          if(ibe>fNbep) ibe=fNbep;
1487          out =  charge*charge*fTablep[ibeta][ialfa][ibe];
1488          nphe = gRandom->Poisson(out);
1489          if(gMC->CurrentMedium() == fMedSensF1){
1490            hits[7] = nphe;      //fLightPMQ
1491            hits[8] = 0;
1492            hits[9] = 0;
1493            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
1494          }
1495          else{
1496            hits[7] = 0;
1497            hits[8] = nphe;      //fLightPMC
1498            hits[9] = 0;
1499            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
1500          }
1501        } 
1502        else if((vol[0]==3)) {   // (3) ZEM fibres
1503          if(ibe>fNbep) ibe=fNbep;
1504          out =  charge*charge*fTablep[ibeta][ialfa][ibe];
1505          gMC->TrackPosition(s[0],s[1],s[2]);
1506          for(j=0; j<=2; j++){
1507             xalic[j] = s[j];
1508          }
1509          // z-coordinate from ZEM front face 
1510          // NB-> fPosZEM[2]+fZEMLength = -1000.+2*10.3 = 979.69 cm
1511          z = -xalic[2]+fPosZEM[2]+2*fZEMLength-xalic[1];
1512 //       z = xalic[2]-fPosZEM[2]-fZEMLength-xalic[1]*(TMath::Tan(45.*kDegrad));
1513 //         printf("\n   fPosZEM[2]+2*fZEMLength = %f", fPosZEM[2]+2*fZEMLength);
1514          guiEff = guiPar[0]*(guiPar[1]*z*z+guiPar[2]*z+guiPar[3]);
1515          out = out*guiEff;
1516          nphe = gRandom->Poisson(out);
1517 //         printf("     out*guiEff = %f nphe = %d", out, nphe);
1518          if(vol[1] == 1){
1519            hits[7] = 0;         
1520            hits[8] = nphe;      //fLightPMC (ZEM1)
1521            hits[9] = 0;
1522            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
1523          }
1524          else{
1525            hits[7] = nphe;      //fLightPMQ (ZEM2)
1526            hits[8] = 0;         
1527            hits[9] = 0;
1528            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
1529          }
1530        }
1531      }
1532    }
1533 }