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