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