]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCv3.cxx
Updated classes
[u/mrichter/AliRoot.git] / ZDC / AliZDCv3.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 //              AliZDCv3 --- new ZDC geometry                        //
20 //          with both ZDC arms geometry implemented                  //
21 //                                                                   //  
22 ///////////////////////////////////////////////////////////////////////
23
24 // --- Standard libraries
25 #include "stdio.h"
26
27 // --- ROOT system
28 #include <TMath.h>
29 #include <TRandom.h>
30 #include <TSystem.h>
31 #include <TTree.h>
32 #include <TVirtualMC.h>
33 #include <TGeoManager.h>
34 #include <TGeoMatrix.h>
35 #include <TGeoCone.h>
36 #include <TGeoShape.h>
37 #include <TGeoCompositeShape.h>
38 #include <TParticle.h>
39
40 // --- AliRoot classes
41 #include "AliConst.h"
42 #include "AliMagF.h"
43 #include "AliRun.h"
44 #include "AliZDCv3.h"
45 #include "AliMC.h"
46  
47 class  AliZDCHit;
48 class  AliPDG;
49 class  AliDetector;
50  
51  
52 ClassImp(AliZDCv3)
53
54 //_____________________________________________________________________________
55 AliZDCv3::AliZDCv3() : 
56   AliZDC(),
57   fMedSensF1(0),
58   fMedSensF2(0),
59   fMedSensZP(0),
60   fMedSensZN(0),
61   fMedSensZEM(0),
62   fMedSensGR(0),
63   fMedSensPI(0),
64   fMedSensTDI(0),
65   fNalfan(0),
66   fNalfap(0),
67   fNben(0),  
68   fNbep(0),
69   fZEMLength(0),
70   fpLostITC(0), 
71   fpLostD1C(0), 
72   fpDetectedC(0),
73   fnDetectedC(0),
74   fnLumiC(0),
75   fpLostITA(0), 
76   fpLostD1A(0), 
77   fpLostTDI(0), 
78   fpDetectedA(0),
79   fnDetectedA(0),
80   fnLumiA(0),
81   fnTrou(0)
82 {
83   //
84   // Default constructor for Zero Degree Calorimeter
85   //
86   
87 }
88  
89 //_____________________________________________________________________________
90 AliZDCv3::AliZDCv3(const char *name, const char *title) : 
91   AliZDC(name,title),
92   fMedSensF1(0),
93   fMedSensF2(0),
94   fMedSensZP(0),
95   fMedSensZN(0),
96   fMedSensZEM(0),
97   fMedSensGR(0),
98   fMedSensPI(0),
99   fMedSensTDI(0),
100   fNalfan(90),
101   fNalfap(90),
102   fNben(18),  
103   fNbep(28), 
104   fZEMLength(0),
105   fpLostITC(0), 
106   fpLostD1C(0), 
107   fpDetectedC(0),
108   fnDetectedC(0),
109   fnLumiC(0),
110   fpLostITA(0), 
111   fpLostD1A(0), 
112   fpLostTDI(0), 
113   fpDetectedA(0),
114   fnDetectedA(0),  
115   fnLumiA(0),
116   fnTrou(0)
117 {
118   //
119   // Standard constructor for Zero Degree Calorimeter 
120   //
121   //
122   // Check that DIPO, ABSO, DIPO and SHIL is there (otherwise tracking is wrong!!!)
123   
124   AliModule* pipe=gAlice->GetModule("PIPE");
125   AliModule* abso=gAlice->GetModule("ABSO");
126   AliModule* dipo=gAlice->GetModule("DIPO");
127   AliModule* shil=gAlice->GetModule("SHIL");
128   if((!pipe) || (!abso) || (!dipo) || (!shil)) {
129     Error("Constructor","ZDC needs PIPE, ABSO, DIPO and SHIL!!!\n");
130     exit(1);
131   } 
132   //
133   Int_t ip,jp,kp;
134   for(ip=0; ip<4; ip++){
135      for(kp=0; kp<fNalfap; kp++){
136         for(jp=0; jp<fNbep; jp++){
137            fTablep[ip][kp][jp] = 0;
138         } 
139      }
140   }
141   Int_t in,jn,kn;
142   for(in=0; in<4; in++){
143      for(kn=0; kn<fNalfan; kn++){
144         for(jn=0; jn<fNben; jn++){
145            fTablen[in][kn][jn] = 0;
146         } 
147      }
148   }
149   //
150   // Parameters for hadronic calorimeters geometry
151   fDimZN[0] = 3.52;
152   fDimZN[1] = 3.52;
153   fDimZN[2] = 50.;  
154   fDimZP[0] = 11.2;
155   fDimZP[1] = 6.;
156   fDimZP[2] = 75.;    
157   fPosZNC[0] = 0.;
158   fPosZNC[1] = 1.2;
159   fPosZNC[2] = -11600.; 
160   fPosZPC[0] = 23.9;
161   fPosZPC[1] = 0.;
162   fPosZPC[2] = -11600.; 
163   fPosZNA[0] = 0.;
164   fPosZNA[1] = 1.2;
165   fPosZNA[2] = 11620.; 
166   fPosZPA[0] = 24.;
167   fPosZPA[1] = 0.;
168   fPosZPA[2] = 11620.; 
169   fFibZN[0] = 0.;
170   fFibZN[1] = 0.01825;
171   fFibZN[2] = 50.;
172   fFibZP[0] = 0.;
173   fFibZP[1] = 0.0275;
174   fFibZP[2] = 75.;
175   // Parameters for EM calorimeter geometry
176   fPosZEM[0] = 8.5;
177   fPosZEM[1] = 0.;
178   fPosZEM[2] = 735.;
179   Float_t kDimZEMPb  = 0.15*(TMath::Sqrt(2.));  // z-dimension of the Pb slice
180   Float_t kDimZEMAir = 0.001;                   // scotch
181   Float_t kFibRadZEM = 0.0315;                  // External fiber radius (including cladding)
182   Int_t   kDivZEM[3] = {92, 0, 20};             // Divisions for EM detector
183   Float_t kDimZEM0 = 2*kDivZEM[2]*(kDimZEMPb+kDimZEMAir+kFibRadZEM*(TMath::Sqrt(2.)));
184   fZEMLength = kDimZEM0;
185   
186 }
187  
188 //_____________________________________________________________________________
189 void AliZDCv3::CreateGeometry()
190 {
191   //
192   // Create the geometry for the Zero Degree Calorimeter version 2
193   //* Initialize COMMON block ZDC_CGEOM
194   //*
195
196   CreateBeamLine();
197   CreateZDC();
198 }
199   
200 //_____________________________________________________________________________
201 void AliZDCv3::CreateBeamLine()
202 {
203   //
204   // Create the beam line elements
205   //
206   
207   Double_t zd1, zd2, zCorrDip, zInnTrip, zD1, zD2;
208   Double_t conpar[9], tubpar[3], tubspar[5], boxpar[3];
209
210   //-- rotation matrices for the legs
211   Int_t irotpipe1, irotpipe2;
212   gMC->Matrix(irotpipe1,90.-1.0027,0.,90.,90.,1.0027,180.);      
213   gMC->Matrix(irotpipe2,90.+1.0027,0.,90.,90.,1.0027,0.);
214
215   //
216   Int_t *idtmed = fIdtmed->GetArray();
217   
218   ////////////////////////////////////////////////////////////////
219   //                                                            //
220   //                SIDE C - RB26 (dimuon side)                 //
221   //                                                            //
222   ///////////////////////////////////////////////////////////////
223   
224   
225   // -- Mother of the ZDCs (Vacuum PCON)
226   zd1 = 1921.6;
227   
228   conpar[0] = 0.;
229   conpar[1] = 360.;
230   conpar[2] = 2.;
231   conpar[3] = -13500.;
232   conpar[4] = 0.;
233   conpar[5] = 55.;
234   conpar[6] = -zd1;
235   conpar[7] = 0.;
236   conpar[8] = 55.;
237   gMC->Gsvolu("ZDCC", "PCON", idtmed[10], conpar, 9);
238   gMC->Gspos("ZDCC", 1, "ALIC", 0., 0., 0., 0, "ONLY");
239   
240
241   // -- FIRST SECTION OF THE BEAM PIPE (from compensator dipole to 
242   //            the beginning of D1) 
243   tubpar[0] = 6.3/2.;
244   tubpar[1] = 6.7/2.;
245   // From beginning of ZDC volumes to beginning of D1
246   tubpar[2] = (5838.3-zd1)/2.;
247   gMC->Gsvolu("QT01", "TUBE", idtmed[7], tubpar, 3);
248   gMC->Gspos("QT01", 1, "ZDCC", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
249   // Ch.debug
250   //printf("    QT01 TUBE pipe from z = %f to z= %f (D1 beg.)\n",-zd1,-2*tubpar[2]-zd1);
251   
252   //-- SECOND SECTION OF THE BEAM PIPE (from the end of D1 to the
253   //            beginning of D2) 
254   
255   //-- FROM MAGNETIC BEGINNING OF D1 TO MAGNETIC END OF D1 + 13.5 cm
256   //--  Cylindrical pipe (r = 3.47) + conical flare
257   
258   // -> Beginning of D1
259   zd1 += 2.*tubpar[2];
260   
261   tubpar[0] = 3.47;
262   tubpar[1] = 3.47+0.2;
263   tubpar[2] = 958.5/2.;
264   gMC->Gsvolu("QT02", "TUBE", idtmed[7], tubpar, 3);
265   gMC->Gspos("QT02", 1, "ZDCC", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
266   // Ch.debug
267   //printf("    QT02 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
268
269   zd1 += 2.*tubpar[2];
270   
271   conpar[0] = 25./2.;
272   conpar[1] = 10./2.;
273   conpar[2] = 10.4/2.;
274   conpar[3] = 6.44/2.;
275   conpar[4] = 6.84/2.;
276   gMC->Gsvolu("QC01", "CONE", idtmed[7], conpar, 5);
277   gMC->Gspos("QC01", 1, "ZDCC", 0., 0., -conpar[0]-zd1, 0, "ONLY");
278   // Ch.debug
279   //printf("    QC01 CONE pipe from z = %f to z= %f\n",-zd1,-2*conpar[0]-zd1);
280
281   zd1 += 2.*conpar[0];
282   
283   tubpar[0] = 10./2.;
284   tubpar[1] = 10.4/2.;
285   tubpar[2] = (50.+10.+3.16+190.)/2.;
286   gMC->Gsvolu("QT03", "TUBE", idtmed[7], tubpar, 3);
287   gMC->Gspos("QT03", 1, "ZDCC", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
288   // Ch.debug
289   //printf("    QT03 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
290   
291   zd1 += tubpar[2]*2.;
292   
293   conpar[0] = 30./2.;
294   conpar[1] = 20.6/2.;
295   conpar[2] = 21./2.;
296   conpar[3] = 10./2.;
297   conpar[4] = 10.4/2.;
298   gMC->Gsvolu("QC02", "CONE", idtmed[7], conpar, 5);
299   gMC->Gspos("QC02", 1, "ZDCC", 0., 0., -conpar[0]-zd1, 0, "ONLY");
300   // Ch.debug
301   //printf("    QC02 CONE pipe from z = %f to z= %f\n",-zd1,-2*conpar[0]-zd1);
302   
303   zd1 += conpar[0] * 2.;
304   
305   tubpar[0] = 20.6/2.;
306   tubpar[1] = 21./2.;
307   tubpar[2] = 450./2.;
308   gMC->Gsvolu("QT04", "TUBE", idtmed[7], tubpar, 3);
309   gMC->Gspos("QT04", 1, "ZDCC", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
310   // Ch.debug
311   //printf("    QT04 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
312   
313   zd1 += tubpar[2] * 2.;
314   
315   conpar[0] = 13.6/2.;
316   conpar[1] = 25.4/2.;
317   conpar[2] = 25.8/2.;
318   conpar[3] = 20.6/2.;
319   conpar[4] = 21./2.;
320   gMC->Gsvolu("QC03", "CONE", idtmed[7], conpar, 5);
321   gMC->Gspos("QC03", 1, "ZDCC", 0., 0., -conpar[0]-zd1, 0, "ONLY");
322   // Ch.debug
323   //printf("    QC03 CONE pipe from z = %f to z= %f\n",-zd1,-2*conpar[0]-zd1);
324   
325   zd1 += conpar[0] * 2.;
326   
327   tubpar[0] = 25.4/2.;
328   tubpar[1] = 25.8/2.;
329   tubpar[2] = 205.8/2.;
330   gMC->Gsvolu("QT05", "TUBE", idtmed[7], tubpar, 3);
331   gMC->Gspos("QT05", 1, "ZDCC", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
332   // Ch.debug
333   //printf("    QT05 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
334   
335   zd1 += tubpar[2] * 2.;
336   
337   tubpar[0] = 50./2.;
338   tubpar[1] = 50.4/2.;
339   tubpar[2] = (515.4+690.+778.5)/2.;
340   gMC->Gsvolu("QT06", "TUBE", idtmed[7], tubpar, 3);
341   gMC->Gspos("QT06", 1, "ZDCC", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
342   // Ch.debug
343   //printf("    QT06 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
344   
345   zd1 += tubpar[2] * 2.;
346   
347   conpar[0] = 14.18/2.;
348   conpar[1] = 55./2.;
349   conpar[2] = 55.4/2.;
350   conpar[3] = 50./2.;
351   conpar[4] = 50.4/2.;
352   gMC->Gsvolu("QC04", "CONE", idtmed[7], conpar, 5);
353   gMC->Gspos("QC04", 1, "ZDCC", 0., 0., -conpar[0]-zd1, 0, "ONLY");
354   // Ch.debug
355   //printf("    QC04 CONE pipe from z = %f to z= %f\n",-zd1,-2*conpar[0]-zd1);
356   
357   zd1 += conpar[0] * 2.;
358   
359   tubpar[0] = 55./2.;
360   tubpar[1] = 55.4/2.;
361   tubpar[2] = 730./2.;
362   gMC->Gsvolu("QT07", "TUBE", idtmed[7], tubpar, 3);
363   gMC->Gspos("QT07", 1, "ZDCC", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
364   // Ch.debug
365   //printf("    QT07 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
366   
367   zd1 += tubpar[2] * 2.;
368   
369   conpar[0] = 36.86/2.;
370   conpar[1] = 68./2.;
371   conpar[2] = 68.4/2.;
372   conpar[3] = 55./2.;
373   conpar[4] = 55.4/2.;
374   gMC->Gsvolu("QC05", "CONE", idtmed[7], conpar, 5);
375   gMC->Gspos("QC05", 1, "ZDCC", 0., 0., -conpar[0]-zd1, 0, "ONLY");
376   // Ch.debug
377   //printf("    QC05 CONE pipe from z = %f to z= %f\n",-zd1,-2*conpar[0]-zd1);
378   
379   zd1 += conpar[0] * 2.;
380   
381   tubpar[0] = 68./2.;
382   tubpar[1] = 68.4/2.;
383   tubpar[2] = 848.6/2.;
384   gMC->Gsvolu("QT08", "TUBE", idtmed[7], tubpar, 3);
385   gMC->Gspos("QT08", 1, "ZDCC", 0., 0., -tubpar[2]-zd1, 0, "ONLY");
386   // Ch.debug
387   //printf("    QT08 TUBE pipe from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
388   
389   zd1 += tubpar[2] * 2.;
390
391   // --------------------------------------------------------
392   // RECOMBINATION CHAMBER IMPLEMENTED USING TGeo CLASSES!!!!
393   // author: Chiara (August 2008)
394   // --------------------------------------------------------
395   // TRANSFORMATION MATRICES
396   // Combi transformation: 
397   Double_t dx = -3.970000;
398   Double_t dy = 0.000000;
399   Double_t dz = 0.0;
400   // Rotation: 
401   Double_t thx = 84.989100;   Double_t phx = 180.000000;
402   Double_t thy = 90.000000;   Double_t phy = 90.000000;
403   Double_t thz = 185.010900;  Double_t phz = 0.000000;
404   TGeoRotation *rotMatrix1c = new TGeoRotation("c",thx,phx,thy,phy,thz,phz);
405   // Combi transformation: 
406   dx = -3.970000;
407   dy = 0.000000;
408   dz = 0.0;
409   TGeoCombiTrans *rotMatrix2c = new TGeoCombiTrans("ZDCC_c1", dx,dy,dz,rotMatrix1c);
410   rotMatrix2c->RegisterYourself();
411   // Combi transformation: 
412   dx = 3.970000;
413   dy = 0.000000;
414   dz = 0.0;
415   // Rotation: 
416   thx = 95.010900;   phx = 180.000000;
417   thy = 90.000000;   phy = 90.000000;
418   thz = 180.-5.010900;    phz = 0.000000;
419   TGeoRotation *rotMatrix3c = new TGeoRotation("",thx,phx,thy,phy,thz,phz);
420   TGeoCombiTrans *rotMatrix4c = new TGeoCombiTrans("ZDCC_c2", dx,dy,dz,rotMatrix3c);
421   rotMatrix4c->RegisterYourself();
422
423   // VOLUMES DEFINITION
424   // Volume: ZDCC
425   TGeoVolume *pZDCC = gGeoManager->GetVolume("ZDCC");
426   
427   conpar[0] = (90.1-0.95-0.26-0.0085)/2.;
428   conpar[1] = 0.0/2.;
429   conpar[2] = 21.6/2.;
430   conpar[3] = 0.0/2.;
431   conpar[4] = 5.8/2.;
432   new TGeoCone("QCLext", conpar[0],conpar[1],conpar[2],conpar[3],conpar[4]);
433   
434   conpar[0] = (90.1-0.95-0.26-0.0085)/2.;
435   conpar[1] = 0.0/2.;
436   conpar[2] = 21.2/2.;
437   conpar[3] = 0.0/2.;
438   conpar[4] = 5.4/2.;
439   new TGeoCone("QCLint", conpar[0],conpar[1],conpar[2],conpar[3],conpar[4]);
440
441   // Outer trousers
442   TGeoCompositeShape *pOutTrousersC = new TGeoCompositeShape("outTrousersC", "QCLext:ZDCC_c1+QCLext:ZDCC_c2");
443   
444   // Volume: QCLext
445   TGeoMedium *medZDCFe = gGeoManager->GetMedium("ZDC_ZIRON");
446   TGeoVolume *pQCLext = new TGeoVolume("QCLext",pOutTrousersC, medZDCFe);
447   pQCLext->SetLineColor(kGreen);
448   pQCLext->SetVisLeaves(kTRUE);
449   //
450   TGeoTranslation *tr1c = new TGeoTranslation(0., 0., (Double_t) -conpar[0]-0.95-zd1);
451   //printf("    Recombination chamber from z = %f to z= %f\n",-zd1,-2*conpar[0]-0.95-zd1);
452   //
453   pZDCC->AddNode(pQCLext, 1, tr1c);
454   // Inner trousers
455   TGeoCompositeShape *pIntTrousersC = new TGeoCompositeShape("intTrousersC", "QCLint:ZDCC_c1+QCLint:ZDCC_c2");
456   // Volume: QCLint
457   TGeoMedium *medZDCvoid = gGeoManager->GetMedium("ZDC_ZVOID");
458   TGeoVolume *pQCLint = new TGeoVolume("QCLint",pIntTrousersC, medZDCvoid);
459   pQCLint->SetLineColor(kTeal);
460   pQCLint->SetVisLeaves(kTRUE);
461   pQCLext->AddNode(pQCLint, 1);
462     
463   zd1 += 90.1;
464   Double_t offset = 0.5;
465   zd1 = zd1+offset;
466   
467   //  second section : 2 tubes (ID = 54. OD = 58.)  
468   tubpar[0] = 5.4/2.;
469   tubpar[1] = 5.8/2.;
470   tubpar[2] = 40.0/2.;
471   gMC->Gsvolu("QC14", "TUBE", idtmed[7], tubpar, 3);
472   gMC->Gspos("QC14", 1, "ZDCC", -15.8/2., 0., -tubpar[2]-zd1, 0, "ONLY");
473   gMC->Gspos("QC14", 2, "ZDCC",  15.8/2., 0., -tubpar[2]-zd1, 0, "ONLY");  
474   // Ch.debug
475   //printf("    QC14 TUBE from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);
476   
477   zd1 += 2.*tubpar[2];
478   
479   // transition x2zdc to recombination chamber : skewed cone  
480   conpar[0] = (10.-0.2-offset)/2.;
481   conpar[1] = 5.4/2.;
482   conpar[2] = 5.8/2.;
483   conpar[3] = 6.3/2.;
484   conpar[4] = 7.0/2.;
485   gMC->Gsvolu("QC15", "CONE", idtmed[7], conpar, 5); 
486   gMC->Gspos("QC15", 1, "ZDCC", -7.9-0.175, 0., -conpar[0]-0.1-zd1, irotpipe1, "ONLY");
487   gMC->Gspos("QC15", 2, "ZDCC", 7.9+0.175, 0., -conpar[0]-0.1-zd1, irotpipe2, "ONLY");
488   //printf("    QC15 CONE from z = %f to z= %f\n",-zd1,-2*conpar[0]-0.2-zd1);
489
490   zd1 += 2.*conpar[0]+0.2;
491   
492   // 2 tubes (ID = 63 mm OD=70 mm)      
493   tubpar[0] = 6.3/2.;
494   tubpar[1] = 7.0/2.;
495   tubpar[2] = 639.8/2.;
496   gMC->Gsvolu("QC16", "TUBE", idtmed[7], tubpar, 3);
497   gMC->Gspos("QC16", 1, "ZDCC", -16.5/2., 0., -tubpar[2]-zd1, 0, "ONLY");
498   gMC->Gspos("QC16", 2, "ZDCC",  16.5/2., 0., -tubpar[2]-zd1, 0, "ONLY");
499   //printf("    QC16 TUBE from z = %f to z= %f\n",-zd1,-2*tubpar[2]-zd1);  
500
501   zd1 += 2.*tubpar[2];
502   //printf("\n  END OF SIDE C BEAM PIPE DEFINITION @ z = %f\n",-zd1);
503
504            
505   // -- Luminometer (Cu box) in front of ZN - side C
506   boxpar[0] = 8.0/2.;
507   boxpar[1] = 8.0/2.;
508   boxpar[2] = 15./2.;
509   gMC->Gsvolu("QLUC", "BOX ", idtmed[6], boxpar, 3);
510   gMC->Gspos("QLUC", 1, "ZDCC", 0., 0.,  fPosZNC[2]+66.+boxpar[2], 0, "ONLY");
511   //printf("    QLUC LUMINOMETER from z = %f to z= %f\n",  fPosZNC[2]+66., fPosZNC[2]+66.+2*boxpar[2]);
512                  
513   // --  END OF BEAM PIPE VOLUME DEFINITION FOR SIDE C (RB26 SIDE) 
514   // ----------------------------------------------------------------
515
516   ////////////////////////////////////////////////////////////////
517   //                                                            //
518   //                SIDE A - RB24                               //
519   //                                                            //
520   ///////////////////////////////////////////////////////////////
521
522   // Rotation Matrices definition
523   Int_t irotpipe3, irotpipe4, irotpipe5;
524   //-- rotation matrices for the tilted cone after the TDI to recenter vacuum chamber      
525   gMC->Matrix(irotpipe3,90.-1.8934,0.,90.,90.,1.8934,180.);    
526   //-- rotation matrices for the tilted tube before and after the TDI 
527   gMC->Matrix(irotpipe4,90.-3.8,0.,90.,90.,3.8,180.);       
528   //-- rotation matrix for the tilted cone after the TDI
529   gMC->Matrix(irotpipe5,90.+9.8,0.,90.,90.,9.8,0.);     
530
531   // -- Mother of the ZDCs (Vacuum PCON)                
532   zd2 = 1910.22;// zd2 initial value
533   
534   conpar[0] = 0.;
535   conpar[1] = 360.;
536   conpar[2] = 2.;
537   conpar[3] = zd2;
538   conpar[4] = 0.;
539   conpar[5] = 55.;
540   conpar[6] = 13500.;
541   conpar[7] = 0.;
542   conpar[8] = 55.;
543   gMC->Gsvolu("ZDCA", "PCON", idtmed[10], conpar, 9);
544   gMC->Gspos("ZDCA", 1, "ALIC", 0., 0., 0., 0, "ONLY");
545   
546   // To avoid overlaps 1 micron are left between certain volumes!
547   Double_t dxNoOverlap = 0.0;
548   //zd2 += dxNoOverlap;  
549   
550   // BEAM PIPE from 19.10 m to inner triplet beginning (22.965 m)  
551   tubpar[0] = 6.0/2.;
552   tubpar[1] = 6.4/2.;
553   tubpar[2] = 386.28/2. - dxNoOverlap; 
554   gMC->Gsvolu("QA01", "TUBE", idtmed[7], tubpar, 3);
555   gMC->Gspos("QA01", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
556   // Ch.debug
557   //printf("\n  QA01 TUBE centred in %f from z = %f to z = %f (IT begin)\n",tubpar[2]+zd2,zd2,2*tubpar[2]+zd2);
558   
559   zd2 += 2.*tubpar[2];  
560
561   // -- FIRST SECTION OF THE BEAM PIPE (from beginning of inner triplet to
562   //    beginning of D1)  
563   tubpar[0] = 6.3/2.;
564   tubpar[1] = 6.7/2.;
565   tubpar[2] = 3541.8/2. - dxNoOverlap;
566   gMC->Gsvolu("QA02", "TUBE", idtmed[7], tubpar, 3);
567   gMC->Gspos("QA02", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
568   // Ch.debug
569   //printf("\n  QA02 TUBE from z = %f to z = %f (D1 begin)\n",zd2,2*tubpar[2]+zd2);
570   
571   zd2 += 2.*tubpar[2]; 
572   
573     
574   // -- SECOND SECTION OF THE BEAM PIPE (from the beginning of D1 to the beginning of D2)
575   //
576   //  FROM (MAGNETIC) BEGINNING OF D1 TO THE (MAGNETIC) END OF D1 + 126.5 cm
577   //  CYLINDRICAL PIPE of diameter increasing from 6.75 cm up to 8.0 cm
578   //  from magnetic end :
579   //  1) 80.1 cm still with ID = 6.75 radial beam screen
580   //  2) 2.5 cm conical section from ID = 6.75 to ID = 8.0 cm
581   //  3) 43.9 cm straight section (tube) with ID = 8.0 cm
582   //
583   //printf("\n  Beginning of D1 at z = %f\n",zd2);
584
585   tubpar[0] = 6.75/2.;
586   tubpar[1] = 7.15/2.;
587   tubpar[2] = (945.0+80.1)/2.;
588   gMC->Gsvolu("QA03", "TUBE", idtmed[7], tubpar, 3);
589   gMC->Gspos("QA03", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
590   // Ch.debug
591   //printf("\n  QA03 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
592   
593   zd2 += 2.*tubpar[2];
594
595   // Transition Cone from ID=67.5 mm  to ID=80 mm
596   conpar[0] = 2.5/2.;
597   conpar[1] = 6.75/2.;
598   conpar[2] = 7.15/2.;
599   conpar[3] = 8.0/2.;
600   conpar[4] = 8.4/2.;
601   gMC->Gsvolu("QA04", "CONE", idtmed[7], conpar, 5);
602   gMC->Gspos("QA04", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
603   //printf("\n  QA04 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
604
605   zd2 += 2.*conpar[0];
606   
607   tubpar[0] = 8.0/2.;
608   tubpar[1] = 8.4/2.;
609   tubpar[2] = (43.9+20.+28.5+28.5)/2.;
610   gMC->Gsvolu("QA05", "TUBE", idtmed[7], tubpar, 3);
611   gMC->Gspos("QA05", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
612   // Ch.debug
613   //printf("\n  QA05 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
614   
615   zd2 += 2.*tubpar[2];
616
617   // Second section of VAEHI (transition cone from ID=80mm to ID=98mm)
618   conpar[0] = 4.0/2.;
619   conpar[1] = 8.0/2.;
620   conpar[2] = 8.4/2.;
621   conpar[3] = 9.8/2.;
622   conpar[4] = 10.2/2.;
623   gMC->Gsvolu("QAV1", "CONE", idtmed[7], conpar, 5);
624   gMC->Gspos("QAV1", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
625   //printf("\n  QAV1 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
626
627   zd2 += 2.*conpar[0];
628   
629   //Third section of VAEHI (transition cone from ID=98mm to ID=90mm)
630   conpar[0] = 1.0/2.;
631   conpar[1] = 9.8/2.;
632   conpar[2] = 10.2/2.;
633   conpar[3] = 9.0/2.;
634   conpar[4] = 9.4/2.;
635   gMC->Gsvolu("QAV2", "CONE", idtmed[7], conpar, 5);
636   gMC->Gspos("QAV2", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
637   //printf("\n  QAV2 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
638
639   zd2 += 2.*conpar[0];
640  
641   // Fourth section of VAEHI (tube ID=90mm)    
642   tubpar[0] = 9.0/2.;
643   tubpar[1] = 9.4/2.;
644   tubpar[2] = 31.0/2.;
645   gMC->Gsvolu("QAV3", "TUBE", idtmed[7], tubpar, 3);
646   gMC->Gspos("QAV3", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
647   // Ch.debug
648   //printf("\n  QAV3 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
649   
650   zd2 += 2.*tubpar[2]; 
651
652   //---------------------------- TCDD beginning ----------------------------------    
653   // space for the insertion of the collimator TCDD (2 m)
654   // TCDD ZONE - 1st volume
655   conpar[0] = 1.3/2.;
656   conpar[1] = 9.0/2.;
657   conpar[2] = 13.0/2.;
658   conpar[3] = 9.6/2.;
659   conpar[4] = 13.0/2.;
660   gMC->Gsvolu("Q01T", "CONE", idtmed[7], conpar, 5);
661   gMC->Gspos("Q01T", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
662   //printf("\n  Q01T CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
663
664   zd2 += 2.*conpar[0];  
665
666   // TCDD ZONE - 2nd volume    
667   tubpar[0] = 9.6/2.;
668   tubpar[1] = 10.0/2.;
669   tubpar[2] = 1.0/2.;
670   gMC->Gsvolu("Q02T", "TUBE", idtmed[7], tubpar, 3);
671   gMC->Gspos("Q02T", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
672   // Ch.debug
673   //printf("\n  Q02T TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
674   
675   zd2 += 2.*tubpar[2]; 
676
677   // TCDD ZONE - third volume
678   conpar[0] = 9.04/2.;
679   conpar[1] = 9.6/2.;
680   conpar[2] = 10.0/2.;
681   conpar[3] = 13.8/2.;
682   conpar[4] = 14.2/2.;
683   gMC->Gsvolu("Q03T", "CONE", idtmed[7], conpar, 5);
684   gMC->Gspos("Q03T", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
685   //printf("\n  Q03T CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
686
687   zd2 += 2.*conpar[0];  
688
689   // TCDD ZONE - 4th volume    
690   tubpar[0] = 13.8/2.;
691   tubpar[1] = 14.2/2.;
692   tubpar[2] = 38.6/2.;
693   gMC->Gsvolu("Q04T", "TUBE", idtmed[7], tubpar, 3);
694   gMC->Gspos("Q04T", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
695   // Ch.debug
696   //printf("\n  Q04T TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
697   
698   zd2 += 2.*tubpar[2]; 
699
700   // TCDD ZONE - 5th volume    
701   tubpar[0] = 21.0/2.;
702   tubpar[1] = 21.4/2.;
703   tubpar[2] = 100.12/2.;
704   gMC->Gsvolu("Q05T", "TUBE", idtmed[7], tubpar, 3);
705   gMC->Gspos("Q05T", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
706   // Ch.debug
707   //printf("\n  Q05T TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
708
709   zd2 += 2.*tubpar[2]; 
710  
711   // TCDD ZONE - 6th volume    
712   tubpar[0] = 13.8/2.;
713   tubpar[1] = 14.2/2.;
714   tubpar[2] = 38.6/2.;
715   gMC->Gsvolu("Q06T", "TUBE", idtmed[7], tubpar, 3);
716   gMC->Gspos("Q06T", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
717   // Ch.debug
718   //printf("\n  Q06T TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
719   
720   zd2 += 2.*tubpar[2];
721
722   // TCDD ZONE - 7th volume
723   conpar[0] = 11.34/2.;
724   conpar[1] = 13.8/2.;
725   conpar[2] = 14.2/2.;
726   conpar[3] = 18.0/2.;
727   conpar[4] = 18.4/2.;
728   gMC->Gsvolu("Q07T", "CONE", idtmed[7], conpar, 5);
729   gMC->Gspos("Q07T", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
730   //printf("\n  Q07T CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
731
732   zd2 += 2.*conpar[0];
733
734   // Upper section : one single phi segment of a tube 
735   //  5 parameters for tubs: inner radius = 0.,
736   //    outer radius = 7. cm, half length = 50 cm
737   //    phi1 = 0., phi2 = 180. 
738   tubspar[0] = 0.0/2.;
739   tubspar[1] = 14.0/2.;
740   tubspar[2] = 100.0/2.;
741   tubspar[3] = 0.;
742   tubspar[4] = 180.;  
743   gMC->Gsvolu("Q08T", "TUBS", idtmed[7], tubspar, 5);
744   // Ch.debug
745   //printf("\n  upper part : one single phi segment of a tube (Q08T)\n");  
746   
747   // rectangular beam pipe inside TCDD upper section (Vacuum)  
748   boxpar[0] = 7.0/2.;
749   boxpar[1] = 2.2/2.;
750   boxpar[2] = 100./2.;
751   gMC->Gsvolu("Q09T", "BOX ", idtmed[10], boxpar, 3);
752   // positioning vacuum box in the upper section of TCDD
753   gMC->Gspos("Q09T", 1, "Q08T", 0., 1.1,  0., 0, "ONLY");
754   
755   // lower section : one single phi segment of a tube       
756   tubspar[0] = 0.0/2.;
757   tubspar[1] = 14.0/2.;
758   tubspar[2] = 100.0/2.;
759   tubspar[3] = 180.;
760   tubspar[4] = 360.;  
761   gMC->Gsvolu("Q10T", "TUBS", idtmed[7], tubspar, 5);
762   // rectangular beam pipe inside TCDD lower section (Vacuum)  
763   boxpar[0] = 7.0/2.;
764   boxpar[1] = 2.2/2.;
765   boxpar[2] = 100./2.;
766   gMC->Gsvolu("Q11T", "BOX ", idtmed[10], boxpar, 3);
767   // positioning vacuum box in the lower section of TCDD
768   gMC->Gspos("Q11T", 1, "Q10T", 0., -1.1,  0., 0, "ONLY");  
769   
770   // positioning  TCDD elements in ZDCA, (inside TCDD volume)
771   gMC->Gspos("Q08T", 1, "ZDCA", 0., 2., -100.+zd2, 0, "ONLY");  
772   gMC->Gspos("Q10T", 1, "ZDCA", 0., -2., -100.+zd2, 0, "ONLY");  
773     
774   // RF screen 
775   boxpar[0] = 0.2/2.;
776   boxpar[1] = 4.0/2.;
777   boxpar[2] = 100./2.;
778   gMC->Gsvolu("Q12T", "BOX ", idtmed[7], boxpar, 3);  
779   // positioning RF screen at both sides of TCDD
780   gMC->Gspos("Q12T", 1, "ZDCA", tubspar[1]+boxpar[0], 0., -100.+zd2, 0, "ONLY");  
781   gMC->Gspos("Q12T", 2, "ZDCA", -tubspar[1]-boxpar[0], 0., -100.+zd2, 0, "ONLY");      
782   //---------------------------- TCDD end ---------------------------------------    
783
784   // The following elliptical tube 180 mm x 70 mm
785   // (obtained positioning the void QA09 in QA08)
786   // represents VMTSA (780 mm) + space reserved to the TCTVB (1480 mm)+ 
787   //            VMTSA (780 mm) + first part of VCTCP (93 mm)
788
789   tubpar[0] = 18.4/2.;
790   tubpar[1] = 7.4/2.;
791   tubpar[2] = 313.3/2.;
792   gMC->Gsvolu("QA06", "ELTU", idtmed[7], tubpar, 3);  
793   //printf("\n  QA06 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
794
795   tubpar[0] = 18.0/2.;
796   tubpar[1] = 7.0/2.;
797   tubpar[2] = 313.3/2.;
798   gMC->Gsvolu("QA07", "ELTU", idtmed[10], tubpar, 3);  
799   //printf("\n  QA07 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
800   gMC->Gspos("QA06", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY"); 
801   gMC->Gspos("QA07", 1, "QA06", 0., 0., 0., 0, "ONLY");  
802
803   zd2 += 2.*tubpar[2];
804       
805   // VCTCP second part: transition cone from ID=180 to ID=212.7 
806   conpar[0] = 31.5/2.;
807   conpar[1] = 18.0/2.;
808   conpar[2] = 18.6/2.;
809   conpar[3] = 21.27/2.;
810   conpar[4] = 21.87/2.;
811   gMC->Gsvolu("QA08", "CONE", idtmed[7], conpar, 5);
812   gMC->Gspos("QA08", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
813   // Ch.debug  
814   //printf("\n  QA08 CONE from z = %Third part of VCTCR: tube (ID=196 mm) f to z = %f\n",zd2,2*conpar[0]+zd2);
815
816   zd2 += 2.*conpar[0];
817   
818   // Tube ID 212.7 mm
819   // Represents VCTCP third part (92 mm) + VCDWB (765 mm) + VMBGA (400 mm) +
820   //            VCDWE (300 mm) + VMBGA (400 mm)
821   tubpar[0] = 21.27/2.;
822   tubpar[1] = 21.87/2.;
823   tubpar[2] = 195.7/2.;
824   gMC->Gsvolu("QA09", "TUBE", idtmed[7], tubpar, 3);
825   gMC->Gspos("QA09", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
826   //printf("\n  QA09 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
827
828   zd2 += 2.*tubpar[2];
829
830   // skewed transition piece (ID=212.7 mm to 332 mm) (before TDI)   
831   conpar[0] = (50.0-0.73-1.13)/2.;
832   conpar[1] = 21.27/2.;
833   conpar[2] = 21.87/2.;
834   conpar[3] = 33.2/2.;
835   conpar[4] = 33.8/2.;
836   gMC->Gsvolu("QA10", "CONE", idtmed[7], conpar, 5);
837   gMC->Gspos("QA10", 1, "ZDCA", -1.66, 0., conpar[0]+0.73+zd2, irotpipe4, "ONLY");
838   // Ch.debug  
839   //printf("\n  QA10 skewed CONE from z = %f to z = %f\n",zd2,2*conpar[0]+0.73+1.13+zd2);
840
841   zd2 += 2.*conpar[0]+0.73+1.13;
842       
843   // Vacuum chamber containing TDI  
844   tubpar[0] = 0.;
845   tubpar[1] = 54.6/2.;
846   tubpar[2] = 540.0/2.;
847   gMC->Gsvolu("Q13TM", "TUBE", idtmed[10], tubpar, 3);
848   gMC->Gspos("Q13TM", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
849   tubpar[0] = 54.0/2.;
850   tubpar[1] = 54.6/2.;
851   tubpar[2] = 540.0/2.;
852   gMC->Gsvolu("Q13T", "TUBE", idtmed[7], tubpar, 3);
853   gMC->Gspos("Q13T", 1, "Q13TM", 0., 0., 0., 0, "ONLY");
854   // Ch.debug
855   //printf("\n  Q13T TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
856
857   zd2 += 2.*tubpar[2];
858   
859   //---------------- INSERT TDI INSIDE Q13T -----------------------------------    
860   boxpar[0] = 11.0/2.;
861   boxpar[1] = 9.0/2.;
862   boxpar[2] = 540.0/2.;
863   gMC->Gsvolu("QTD1", "BOX ", idtmed[7], boxpar, 3);
864   gMC->Gspos("QTD1", 1, "Q13TM", -3.8, 10.5,  0., 0, "ONLY");
865   boxpar[0] = 11.0/2.;
866   boxpar[1] = 9.0/2.;
867   boxpar[2] = 540.0/2.;
868   gMC->Gsvolu("QTD2", "BOX ", idtmed[7], boxpar, 3);
869   gMC->Gspos("QTD2", 1, "Q13TM", -3.8, -10.5,  0., 0, "ONLY");  
870   boxpar[0] = 5.1/2.;
871   boxpar[1] = 0.2/2.;
872   boxpar[2] = 540.0/2.;
873   gMC->Gsvolu("QTD3", "BOX ", idtmed[7], boxpar, 3);
874   gMC->Gspos("QTD3", 1, "Q13TM", -3.8+5.5+boxpar[0], 6.1,  0., 0, "ONLY");  
875   gMC->Gspos("QTD3", 2, "Q13TM", -3.8+5.5+boxpar[0], -6.1,  0., 0, "ONLY"); 
876   gMC->Gspos("QTD3", 3, "Q13TM", -3.8-5.5-boxpar[0], 6.1,  0., 0, "ONLY");  
877   gMC->Gspos("QTD3", 4, "Q13TM", -3.8-5.5-boxpar[0], -6.1,  0., 0, "ONLY");  
878   //
879   tubspar[0] = 12.0/2.;
880   tubspar[1] = 12.4/2.;
881   tubspar[2] = 540.0/2.;
882   tubspar[3] = 90.;
883   tubspar[4] = 270.;  
884   gMC->Gsvolu("QTD4", "TUBS", idtmed[7], tubspar, 5);
885   gMC->Gspos("QTD4", 1, "Q13TM", -3.8-10.6, 0.,  0., 0, "ONLY");
886   tubspar[0] = 12.0/2.;
887   tubspar[1] = 12.4/2.;
888   tubspar[2] = 540.0/2.;
889   tubspar[3] = -90.;
890   tubspar[4] = 90.;  
891   gMC->Gsvolu("QTD5", "TUBS", idtmed[7], tubspar, 5);
892   gMC->Gspos("QTD5", 1, "Q13TM", -3.8+10.6, 0.,  0., 0, "ONLY"); 
893   //---------------- END DEFINING TDI INSIDE Q13T -------------------------------
894   
895   // VCTCG skewed transition piece (ID=332 mm to 212.7 mm) (after TDI)
896   conpar[0] = (50.0-2.92-1.89)/2.;
897   conpar[1] = 33.2/2.;
898   conpar[2] = 33.8/2.;
899   conpar[3] = 21.27/2.;
900   conpar[4] = 21.87/2.;
901   gMC->Gsvolu("QA11", "CONE", idtmed[7], conpar, 5);
902   gMC->Gspos("QA11", 1, "ZDCA", 4.32-3.8, 0., conpar[0]+2.92+zd2, irotpipe5, "ONLY");
903   // Ch.debug  
904   //printf("\n  QA11 skewed CONE from z = %f to z =%f\n",zd2,2*conpar[0]+2.92+1.89+zd2);
905
906   zd2 += 2.*conpar[0]+2.92+1.89;
907   
908   // The following tube ID 212.7 mm  --- (volume QA14)
909   // represents VMBGA (400 mm) + VCDWE (300 mm) + VMBGA (400 mm) +
910   //            BTVTS (600 mm) + VMLGB (400 mm)  
911   tubpar[0] = 21.27/2.;
912   tubpar[1] = 21.87/2.;
913   tubpar[2] = 210.0/2.;
914   gMC->Gsvolu("QA12", "TUBE", idtmed[7], tubpar, 3);
915   gMC->Gspos("QA12", 1, "ZDCA", 4., 0., tubpar[2]+zd2, 0, "ONLY");
916   // Ch.debug
917   //printf("\n  QA12 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
918
919   zd2 += 2.*tubpar[2];  
920   
921   // First part of VCTCC
922   // skewed transition cone from ID=212.7 mm to ID=797 mm
923   conpar[0] = (121.0-0.37-1.35)/2.;
924   conpar[1] = 21.27/2.;
925   conpar[2] = 21.87/2.;
926   conpar[3] = 79.7/2.;
927   conpar[4] = 81.3/2.;
928   gMC->Gsvolu("QA13", "CONE", idtmed[7], conpar, 5);
929   gMC->Gspos("QA13", 1, "ZDCA", 4.-2., 0., conpar[0]+0.37+zd2, irotpipe3, "ONLY");
930   //printf("\n  QA13 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+0.37+1.35+zd2);
931
932   zd2 += 2.*conpar[0]+0.37+1.35;
933   
934   // The following tube ID 797 mm  --- (volume QA16)
935   // represents the second part of VCTCC (4272 mm) + 
936   //            4 x VCDGA (4 x 4272 mm) + 
937   //            the first part of VCTCR (850 mm)
938   tubpar[0] = 79.7/2.;
939   tubpar[1] = 81.3/2.;
940   tubpar[2] = 2221./2.;
941   gMC->Gsvolu("QA14", "TUBE", idtmed[7], tubpar, 3);
942   gMC->Gspos("QA14", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
943   // Ch.debug  
944   //printf("\n  QA14 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
945
946   zd2 += 2.*tubpar[2];
947         
948   // Second part of VCTCR
949   // Transition from ID=797 mm to ID=196 mm:
950   // in order to simulate the thin window opened in the transition cone
951   // we divide the transition cone in three cones:
952   // (1) 8 mm thick (2) 3 mm thick (3) the third 8 mm thick
953   
954   // (1) 8 mm thick
955   conpar[0] = 9.09/2.; // 15 degree
956   conpar[1] = 79.7/2.;
957   conpar[2] = 81.3/2.; // thickness 8 mm  
958   conpar[3] = 74.82868/2.;
959   conpar[4] = 76.42868/2.; // thickness 8 mm 
960   gMC->Gsvolu("QA15", "CONE", idtmed[7], conpar, 5);
961   gMC->Gspos("QA15", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
962   //printf("\n  QA15 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
963
964   zd2 += 2.*conpar[0];  
965
966   // (2) 3 mm thick
967   conpar[0] = 96.2/2.; // 15 degree
968   conpar[1] = 74.82868/2.;
969   conpar[2] = 75.42868/2.; // thickness 3 mm  
970   conpar[3] = 23.19588/2.;
971   conpar[4] = 23.79588/2.; // thickness 3 mm 
972   gMC->Gsvolu("QA16", "CONE", idtmed[7], conpar, 5);
973   gMC->Gspos("QA16", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");  
974   //printf("\n  QA16 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
975
976   zd2 += 2.*conpar[0];
977   
978   // (3) 8 mm thick
979   conpar[0] = 6.71/2.; // 15 degree
980   conpar[1] = 23.19588/2.;
981   conpar[2] = 24.79588/2.;// thickness 8 mm 
982   conpar[3] = 19.6/2.;
983   conpar[4] = 21.2/2.;// thickness 8 mm 
984   gMC->Gsvolu("QA17", "CONE", idtmed[7], conpar, 5);
985   gMC->Gspos("QA17", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
986   //printf("\n  QA19 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
987
988   zd2 += 2.*conpar[0];
989  
990   // Third part of VCTCR: tube (ID=196 mm)  
991   tubpar[0] = 19.6/2.;
992   tubpar[1] = 21.2/2.;
993   tubpar[2] = 9.55/2.;
994   gMC->Gsvolu("QA18", "TUBE", idtmed[7], tubpar, 3);
995   gMC->Gspos("QA18", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
996   // Ch.debug  
997   //printf("\n  QA18 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
998
999   zd2 += 2.*tubpar[2];  
1000   
1001   // Flange (ID=196 mm) (last part of VCTCR and first part of VMZAR)
1002   tubpar[0] = 19.6/2.;
1003   tubpar[1] = 25.3/2.;
1004   tubpar[2] = 4.9/2.;
1005   gMC->Gsvolu("QF01", "TUBE", idtmed[7], tubpar, 3);
1006   gMC->Gspos("QF01", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
1007   // Ch.debug  
1008   //printf("\n  QF01  TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
1009
1010   zd2 += 2.*tubpar[2];
1011   
1012   // VMZAR (5 volumes)  
1013   tubpar[0] = 20.2/2.;
1014   tubpar[1] = 20.6/2.;
1015   tubpar[2] = 2.15/2.;
1016   gMC->Gsvolu("QA19", "TUBE", idtmed[7], tubpar, 3);
1017   gMC->Gspos("QA19", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
1018   // Ch.debug  
1019   //printf("\n  QA19  TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
1020
1021   zd2 += 2.*tubpar[2];
1022   
1023   conpar[0] = 6.9/2.;
1024   conpar[1] = 20.2/2.;
1025   conpar[2] = 20.6/2.;
1026   conpar[3] = 23.9/2.;
1027   conpar[4] = 24.3/2.;
1028   gMC->Gsvolu("QA20", "CONE", idtmed[7], conpar, 5);
1029   gMC->Gspos("QA20", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
1030   // Ch.debug  
1031   //printf("\n  QA20 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
1032
1033   zd2 += 2.*conpar[0];
1034
1035   tubpar[0] = 23.9/2.;
1036   tubpar[1] = 25.5/2.;
1037   tubpar[2] = 17.0/2.;
1038   gMC->Gsvolu("QA21", "TUBE", idtmed[7], tubpar, 3);
1039   gMC->Gspos("QA21", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
1040   // Ch.debug  
1041   //printf("\n  QA21  TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
1042
1043   zd2 += 2.*tubpar[2];
1044   
1045   conpar[0] = 6.9/2.;
1046   conpar[1] = 23.9/2.;
1047   conpar[2] = 24.3/2.;
1048   conpar[3] = 20.2/2.;
1049   conpar[4] = 20.6/2.;
1050   gMC->Gsvolu("QA22", "CONE", idtmed[7], conpar, 5);
1051   gMC->Gspos("QA22", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
1052   // Ch.debug  
1053   //printf("\n  QA22 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
1054
1055   zd2 += 2.*conpar[0];
1056   
1057   tubpar[0] = 20.2/2.;
1058   tubpar[1] = 20.6/2.;
1059   tubpar[2] = 2.15/2.;
1060   gMC->Gsvolu("QA23", "TUBE", idtmed[7], tubpar, 3);
1061   gMC->Gspos("QA23", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
1062   // Ch.debug  
1063   //printf("\n  QA23  TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
1064
1065   zd2 += 2.*tubpar[2];
1066   
1067   // Flange (ID=196 mm)(last part of VMZAR and first part of VCTYD)
1068   tubpar[0] = 19.6/2.;
1069   tubpar[1] = 25.3/2.;
1070   tubpar[2] = 4.9/2.;
1071   gMC->Gsvolu("QF02", "TUBE", idtmed[7], tubpar, 3);
1072   gMC->Gspos("QF02", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
1073   // Ch.debug  
1074   //printf("\n  QF02 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
1075
1076   zd2 += 2.*tubpar[2];
1077   
1078   // simulation of the trousers (VCTYB)     
1079   tubpar[0] = 19.6/2.;
1080   tubpar[1] = 20.0/2.;
1081   tubpar[2] = 3.9/2.;
1082   gMC->Gsvolu("QA24", "TUBE", idtmed[7], tubpar, 3);
1083   gMC->Gspos("QA24", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
1084   // Ch.debug
1085   //printf("\n  QA24  TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
1086
1087   zd2 += 2.*tubpar[2];
1088
1089   // transition cone from ID=196. to ID=216.6
1090   conpar[0] = 32.55/2.;
1091   conpar[1] = 19.6/2.;
1092   conpar[2] = 20.0/2.;
1093   conpar[3] = 21.66/2.;
1094   conpar[4] = 22.06/2.;
1095   gMC->Gsvolu("QA25", "CONE", idtmed[7], conpar, 5);
1096   gMC->Gspos("QA25", 1, "ZDCA", 0., 0., conpar[0]+zd2, 0, "ONLY");
1097   // Ch.debug  
1098   //printf("\n  QA25 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+zd2);
1099
1100   zd2 += 2.*conpar[0]; 
1101   
1102   // tube  
1103   tubpar[0] = 21.66/2.;
1104   tubpar[1] = 22.06/2.;
1105   tubpar[2] = 28.6/2.;
1106   gMC->Gsvolu("QA26", "TUBE", idtmed[7], tubpar, 3);
1107   gMC->Gspos("QA26", 1, "ZDCA", 0., 0., tubpar[2]+zd2, 0, "ONLY");
1108   // Ch.debug 
1109   //printf("\n  QA26  TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
1110
1111   zd2 += 2.*tubpar[2];
1112
1113   // --------------------------------------------------------
1114   // RECOMBINATION CHAMBER IMPLEMENTED USING TGeo CLASSES!!!!
1115   // author: Chiara (June 2008)
1116   // --------------------------------------------------------
1117   // TRANSFORMATION MATRICES
1118   // Combi transformation: 
1119   dx = -3.970000;
1120   dy = 0.000000;
1121   dz = 0.0;
1122   // Rotation: 
1123   thx = 84.989100;   phx = 0.000000;
1124   thy = 90.000000;   phy = 90.000000;
1125   thz = 5.010900;    phz = 180.000000;
1126   TGeoRotation *rotMatrix1 = new TGeoRotation("",thx,phx,thy,phy,thz,phz);
1127   // Combi transformation: 
1128   dx = -3.970000;
1129   dy = 0.000000;
1130   dz = 0.0;
1131   TGeoCombiTrans *rotMatrix2 = new TGeoCombiTrans("ZDC_c1", dx,dy,dz,rotMatrix1);
1132   rotMatrix2->RegisterYourself();
1133   // Combi transformation: 
1134   dx = 3.970000;
1135   dy = 0.000000;
1136   dz = 0.0;
1137   // Rotation: 
1138   thx = 95.010900;   phx = 0.000000;
1139   thy = 90.000000;   phy = 90.000000;
1140   thz = 5.010900;    phz = 0.000000;
1141   TGeoRotation *rotMatrix3 = new TGeoRotation("",thx,phx,thy,phy,thz,phz);
1142   TGeoCombiTrans *rotMatrix4 = new TGeoCombiTrans("ZDC_c2", dx,dy,dz,rotMatrix3);
1143   rotMatrix4->RegisterYourself();
1144   
1145   
1146   // VOLUMES DEFINITION
1147   // Volume: ZDCA
1148   TGeoVolume *pZDCA = gGeoManager->GetVolume("ZDCA");
1149   
1150   conpar[0] = (90.1-0.95-0.26)/2.;
1151   conpar[1] = 0.0/2.;
1152   conpar[2] = 21.6/2.;
1153   conpar[3] = 0.0/2.;
1154   conpar[4] = 5.8/2.;
1155   new TGeoCone("QALext", conpar[0],conpar[1],conpar[2],conpar[3],conpar[4]);
1156   
1157   conpar[0] = (90.1-0.95-0.26)/2.;
1158   conpar[1] = 0.0/2.;
1159   conpar[2] = 21.2/2.;
1160   conpar[3] = 0.0/2.;
1161   conpar[4] = 5.4/2.;
1162   new TGeoCone("QALint", conpar[0],conpar[1],conpar[2],conpar[3],conpar[4]);
1163
1164   // Outer trousers
1165   TGeoCompositeShape *pOutTrousers = new TGeoCompositeShape("outTrousers", "QALext:ZDC_c1+QALext:ZDC_c2");
1166   
1167   // Volume: QALext
1168   //TGeoMedium *medZDCFe = gGeoManager->GetMedium("ZDC_ZIRON");
1169   TGeoVolume *pQALext = new TGeoVolume("QALext",pOutTrousers, medZDCFe);
1170   pQALext->SetLineColor(kBlue);
1171   pQALext->SetVisLeaves(kTRUE);
1172   //
1173   TGeoTranslation *tr1 = new TGeoTranslation(0., 0., (Double_t) conpar[0]+0.95+zd2);
1174   pZDCA->AddNode(pQALext, 1, tr1);
1175   // Inner trousers
1176   TGeoCompositeShape *pIntTrousers = new TGeoCompositeShape("intTrousers", "QALint:ZDC_c1+QALint:ZDC_c2");
1177   // Volume: QALint
1178   //TGeoMedium *medZDCvoid = gGeoManager->GetMedium("ZDC_ZVOID");
1179   TGeoVolume *pQALint = new TGeoVolume("QALint",pIntTrousers, medZDCvoid);
1180   pQALint->SetLineColor(kAzure);
1181   pQALint->SetVisLeaves(kTRUE);
1182   pQALext->AddNode(pQALint, 1);
1183     
1184   zd2 += 90.1;
1185   
1186   //  second section : 2 tubes (ID = 54. OD = 58.)  
1187   tubpar[0] = 5.4/2.;
1188   tubpar[1] = 5.8/2.;
1189   tubpar[2] = 40.0/2.;
1190   gMC->Gsvolu("QA27", "TUBE", idtmed[7], tubpar, 3);
1191   gMC->Gspos("QA27", 1, "ZDCA", -15.8/2., 0., tubpar[2]+zd2, 0, "ONLY");
1192   gMC->Gspos("QA27", 2, "ZDCA",  15.8/2., 0., tubpar[2]+zd2, 0, "ONLY");  
1193   // Ch.debug
1194   //printf("\n  QA27 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);
1195   
1196   zd2 += 2.*tubpar[2];
1197  
1198   // transition x2zdc to recombination chamber : skewed cone  
1199   conpar[0] = (10.-1.)/2.;
1200   conpar[1] = 5.4/2.;
1201   conpar[2] = 5.8/2.;
1202   conpar[3] = 6.3/2.;
1203   conpar[4] = 7.0/2.;
1204   gMC->Gsvolu("QA28", "CONE", idtmed[7], conpar, 5); 
1205   gMC->Gspos("QA28", 1, "ZDCA", -7.9-0.175, 0., conpar[0]+0.5+zd2, irotpipe3, "ONLY");
1206   gMC->Gspos("QA28", 2, "ZDCA", 7.9+0.175, 0., conpar[0]+0.5+zd2, irotpipe4, "ONLY");
1207   //printf("\n  QA28 CONE from z = %f to z = %f\n",zd2,2*conpar[0]+0.2+zd2);
1208
1209   zd2 += 2.*conpar[0]+1.;
1210     
1211   // 2 tubes (ID = 63 mm OD=70 mm)      
1212   tubpar[0] = 6.3/2.;
1213   tubpar[1] = 7.0/2.;
1214   tubpar[2] = (342.5+498.3)/2.;
1215   gMC->Gsvolu("QA29", "TUBE", idtmed[7], tubpar, 3);
1216   gMC->Gspos("QA29", 1, "ZDCA", -16.5/2., 0., tubpar[2]+zd2, 0, "ONLY");
1217   gMC->Gspos("QA29", 2, "ZDCA",  16.5/2., 0., tubpar[2]+zd2, 0, "ONLY");
1218   //printf("\n  QA29 TUBE from z = %f to z = %f\n",zd2,2*tubpar[2]+zd2);  
1219
1220   zd2 += 2.*tubpar[2];
1221            
1222   // -- Luminometer (Cu box) in front of ZN - side A
1223   boxpar[0] = 8.0/2.;
1224   boxpar[1] = 8.0/2.;
1225   boxpar[2] = 15./2.;
1226   gMC->Gsvolu("QLUA", "BOX ", idtmed[6], boxpar, 3);
1227   gMC->Gspos("QLUA", 1, "ZDCA", 0., 0.,  fPosZNA[2]-66.-boxpar[2], 0, "ONLY");
1228   //printf("\n  QLUA LUMINOMETER from z = %f to z = %f\n\n",  fPosZNA[2]-66., fPosZNA[2]-66.-2*boxpar[2]);
1229
1230   //printf("\n  END OF BEAM PIPE VOLUME DEFINITION AT z = %f\n",zd2);
1231   
1232
1233   // ----------------------------------------------------------------
1234   // --  MAGNET DEFINITION  -> LHC OPTICS 6.5  
1235   // ----------------------------------------------------------------      
1236   // ***************************************************************  
1237   //            SIDE C - RB26  (dimuon side) 
1238   // ***************************************************************   
1239   // --  COMPENSATOR DIPOLE (MBXW)
1240   zCorrDip = 1972.5;   
1241   
1242   // --  GAP (VACUUM WITH MAGNETIC FIELD)
1243   tubpar[0] = 0.;
1244   tubpar[1] = 3.14;
1245   tubpar[2] = 153./2.;
1246   gMC->Gsvolu("MBXW", "TUBE", idtmed[11], tubpar, 3);
1247
1248   // --  YOKE 
1249   tubpar[0] = 4.5;
1250   tubpar[1] = 55.;
1251   tubpar[2] = 153./2.;
1252   gMC->Gsvolu("YMBX", "TUBE", idtmed[7], tubpar, 3);
1253
1254   gMC->Gspos("MBXW", 1, "ZDCC", 0., 0., -tubpar[2]-zCorrDip, 0, "ONLY");
1255   gMC->Gspos("YMBX", 1, "ZDCC", 0., 0., -tubpar[2]-zCorrDip, 0, "ONLY");
1256   
1257   
1258   // -- INNER TRIPLET 
1259   zInnTrip = 2296.5; 
1260
1261   // -- DEFINE MQXL AND MQX QUADRUPOLE ELEMENT 
1262   // --  MQXL 
1263   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
1264   tubpar[0] = 0.;
1265   tubpar[1] = 3.14;
1266   tubpar[2] = 637./2.;
1267   gMC->Gsvolu("MQXL", "TUBE", idtmed[11], tubpar, 3);
1268     
1269   // --  YOKE 
1270   tubpar[0] = 3.5;
1271   tubpar[1] = 22.;
1272   tubpar[2] = 637./2.;
1273   gMC->Gsvolu("YMQL", "TUBE", idtmed[7], tubpar, 3);
1274   
1275   gMC->Gspos("MQXL", 1, "ZDCC", 0., 0., -tubpar[2]-zInnTrip, 0, "ONLY");
1276   gMC->Gspos("YMQL", 1, "ZDCC", 0., 0., -tubpar[2]-zInnTrip, 0, "ONLY");
1277   
1278   gMC->Gspos("MQXL", 2, "ZDCC", 0., 0., -tubpar[2]-zInnTrip-2400., 0, "ONLY");
1279   gMC->Gspos("YMQL", 2, "ZDCC", 0., 0., -tubpar[2]-zInnTrip-2400., 0, "ONLY");
1280   
1281   // --  MQX 
1282   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
1283   tubpar[0] = 0.;
1284   tubpar[1] = 3.14;
1285   tubpar[2] = 550./2.;
1286   gMC->Gsvolu("MQX ", "TUBE", idtmed[11], tubpar, 3);
1287   
1288   // --  YOKE 
1289   tubpar[0] = 3.5;
1290   tubpar[1] = 22.;
1291   tubpar[2] = 550./2.;
1292   gMC->Gsvolu("YMQ ", "TUBE", idtmed[7], tubpar, 3);
1293   
1294   gMC->Gspos("MQX ", 1, "ZDCC", 0., 0., -tubpar[2]-zInnTrip-908.5,  0, "ONLY");
1295   gMC->Gspos("YMQ ", 1, "ZDCC", 0., 0., -tubpar[2]-zInnTrip-908.5,  0, "ONLY");
1296   
1297   gMC->Gspos("MQX ", 2, "ZDCC", 0., 0., -tubpar[2]-zInnTrip-1558.5, 0, "ONLY");
1298   gMC->Gspos("YMQ ", 2, "ZDCC", 0., 0., -tubpar[2]-zInnTrip-1558.5, 0, "ONLY");
1299   
1300   // -- SEPARATOR DIPOLE D1 
1301   zD1 = 5838.3001;
1302   
1303   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
1304   tubpar[0] = 0.;
1305   tubpar[1] = 3.46;
1306   tubpar[2] = 945./2.;
1307   gMC->Gsvolu("MD1 ", "TUBE", idtmed[11], tubpar, 3);
1308   
1309   // --  Insert horizontal Cu plates inside D1 
1310   // --   (to simulate the vacuum chamber)
1311   boxpar[0] = TMath::Sqrt(tubpar[1]*tubpar[1]-(2.98+0.2)*(2.98+0.2)) - 0.05;
1312   boxpar[1] = 0.2/2.;
1313   boxpar[2] = 945./2.;
1314   gMC->Gsvolu("MD1V", "BOX ", idtmed[6], boxpar, 3);
1315   gMC->Gspos("MD1V", 1, "MD1 ", 0., 2.98+boxpar[1], 0., 0, "ONLY");
1316   gMC->Gspos("MD1V", 2, "MD1 ", 0., -2.98-boxpar[1], 0., 0, "ONLY");
1317     
1318   // --  YOKE 
1319   tubpar[0] = 3.68;
1320   tubpar[1] = 110./2.;
1321   tubpar[2] = 945./2.;
1322   gMC->Gsvolu("YD1 ", "TUBE", idtmed[7], tubpar, 3);
1323   
1324   gMC->Gspos("YD1 ", 1, "ZDCC", 0., 0., -tubpar[2]-zD1, 0, "ONLY");
1325   gMC->Gspos("MD1 ", 1, "ZDCC", 0., 0., -tubpar[2]-zD1, 0, "ONLY");
1326   // Ch debug
1327   //printf("    MD1 from z = %f to z = %f cm\n",-zD1, -zD1-2*tubpar[2]); 
1328   
1329   // -- DIPOLE D2 
1330   zD2 = 12167.8;
1331   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
1332   tubpar[0] = 0.;
1333   tubpar[1] = 7.5/2.;
1334   tubpar[2] = 945./2.;
1335   gMC->Gsvolu("MD2 ", "TUBE", idtmed[11], tubpar, 3);
1336   
1337   // --  YOKE 
1338   tubpar[0] = 0.;
1339   tubpar[1] = 55.;
1340   tubpar[2] = 945./2.;
1341   gMC->Gsvolu("YD2 ", "TUBE", idtmed[7], tubpar, 3);
1342   
1343   gMC->Gspos("YD2 ", 1, "ZDCC", 0., 0., -tubpar[2]-zD2, 0, "ONLY");
1344   // Ch debug
1345   //printf("    YD2 from z = %f to z = %f cm\n",-zD2, -zD2-2*tubpar[2]); 
1346   
1347   gMC->Gspos("MD2 ", 1, "YD2 ", -9.4, 0., 0., 0, "ONLY");
1348   gMC->Gspos("MD2 ", 2, "YD2 ",  9.4, 0., 0., 0, "ONLY");
1349   
1350   // ***************************************************************  
1351   //            SIDE A - RB24 
1352   // ***************************************************************
1353   
1354   // COMPENSATOR DIPOLE (MCBWA) (2nd compensator)
1355   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
1356   tubpar[0] = 0.;
1357   tubpar[1] = 3.;  
1358   tubpar[2] = 153./2.;
1359   gMC->Gsvolu("MCBW", "TUBE", idtmed[11], tubpar, 3);  
1360   gMC->Gspos("MCBW", 1, "ZDCA", 0., 0., tubpar[2]+zCorrDip, 0, "ONLY");
1361     
1362    // --  YOKE 
1363   tubpar[0] = 4.5;
1364   tubpar[1] = 55.;
1365   tubpar[2] = 153./2.;
1366   gMC->Gsvolu("YMCB", "TUBE", idtmed[7], tubpar, 3);
1367   gMC->Gspos("YMCB", 1, "ZDCA", 0., 0., tubpar[2]+zCorrDip, 0, "ONLY");  
1368   
1369    // -- INNER TRIPLET 
1370   // -- DEFINE MQX1 AND MQX2 QUADRUPOLE ELEMENT 
1371   // --  MQX1 
1372   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
1373   tubpar[0] = 0.;
1374   tubpar[1] = 3.14;
1375   tubpar[2] = 637./2.;
1376   gMC->Gsvolu("MQX1", "TUBE", idtmed[11], tubpar, 3);
1377   gMC->Gsvolu("MQX4", "TUBE", idtmed[11], tubpar, 3);
1378     
1379   // --  YOKE 
1380   tubpar[0] = 3.5;
1381   tubpar[1] = 22.;
1382   tubpar[2] = 637./2.;
1383   gMC->Gsvolu("YMQ1", "TUBE", idtmed[7], tubpar, 3);
1384
1385   // -- Q1
1386   gMC->Gspos("MQX1", 1, "ZDCA", 0., 0., tubpar[2]+zInnTrip, 0, "ONLY");
1387   gMC->Gspos("YMQ1", 1, "ZDCA", 0., 0., tubpar[2]+zInnTrip, 0, "ONLY");
1388
1389    // -- BEAM SCREEN FOR Q1
1390    tubpar[0] = 4.78/2.;
1391    tubpar[1] = 5.18/2.;
1392    tubpar[2] = 637./2.;
1393    gMC->Gsvolu("QBS1", "TUBE", idtmed[6], tubpar, 3);
1394    gMC->Gspos("QBS1", 1, "MQX1", 0., 0., 0., 0, "ONLY");
1395    // INSERT VERTICAL PLATE INSIDE Q1
1396    boxpar[0] = 0.2/2.0;
1397    boxpar[1] = TMath::Sqrt(tubpar[0]*tubpar[0]-(1.9+0.2)*(1.9+0.2));
1398    boxpar[2] =637./2.;
1399    gMC->Gsvolu("QBS2", "BOX ", idtmed[6], boxpar, 3);
1400    gMC->Gspos("QBS2", 1, "MQX1", 1.9+boxpar[0], 0., 0., 0, "ONLY");
1401    gMC->Gspos("QBS2", 2, "MQX1", -1.9-boxpar[0], 0., 0., 0, "ONLY");
1402
1403    // -- Q3   
1404    gMC->Gspos("MQX4", 1, "ZDCA", 0., 0., tubpar[2]+zInnTrip+2400., 0, "ONLY");
1405    gMC->Gspos("YMQ1", 2, "ZDCA", 0., 0., tubpar[2]+zInnTrip+2400., 0, "ONLY");
1406
1407    // -- BEAM SCREEN FOR Q3
1408    tubpar[0] = 5.79/2.;
1409    tubpar[1] = 6.14/2.;
1410    tubpar[2] = 637./2.;
1411    gMC->Gsvolu("QBS3", "TUBE", idtmed[6], tubpar, 3);
1412    gMC->Gspos("QBS3", 1, "MQX4", 0., 0., 0., 0, "ONLY");
1413    // INSERT VERTICAL PLATE INSIDE Q3
1414    boxpar[0] = 0.2/2.0;
1415    boxpar[1] = TMath::Sqrt(tubpar[0]*tubpar[0]-(2.405+0.2)*(2.405+0.2));
1416    boxpar[2] =637./2.;
1417    gMC->Gsvolu("QBS4", "BOX ", idtmed[6], boxpar, 3);
1418    gMC->Gspos("QBS4", 1, "MQX4", 2.405+boxpar[0], 0., 0., 0, "ONLY");
1419    gMC->Gspos("QBS4", 2, "MQX4", -2.405-boxpar[0], 0., 0., 0, "ONLY");
1420     
1421   
1422   
1423   // --  MQX2
1424   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
1425   tubpar[0] = 0.;
1426   tubpar[1] = 3.14;
1427   tubpar[2] = 550./2.;
1428   gMC->Gsvolu("MQX2", "TUBE", idtmed[11], tubpar, 3);
1429   gMC->Gsvolu("MQX3", "TUBE", idtmed[11], tubpar, 3);
1430   
1431   // --  YOKE 
1432   tubpar[0] = 3.5;
1433   tubpar[1] = 22.;
1434   tubpar[2] = 550./2.;
1435   gMC->Gsvolu("YMQ2", "TUBE", idtmed[7], tubpar, 3);
1436
1437    // -- BEAM SCREEN FOR Q2
1438    tubpar[0] = 5.79/2.;
1439    tubpar[1] = 6.14/2.;
1440    tubpar[2] = 550./2.;
1441    gMC->Gsvolu("QBS5", "TUBE", idtmed[6], tubpar, 3);
1442    //    VERTICAL PLATE INSIDE Q2
1443    boxpar[0] = 0.2/2.0;
1444    boxpar[1] = TMath::Sqrt(tubpar[0]*tubpar[0]-(2.405+0.2)*(2.405+0.2));
1445    boxpar[2] =550./2.;
1446    gMC->Gsvolu("QBS6", "BOX ", idtmed[6], boxpar, 3);
1447
1448   // -- Q2A
1449   gMC->Gspos("MQX2", 1, "ZDCA", 0., 0., tubpar[2]+zInnTrip+908.5,  0, "ONLY");
1450   gMC->Gspos("QBS5", 1, "MQX2", 0., 0., 0., 0, "ONLY");  
1451   gMC->Gspos("QBS6", 1, "MQX2", 2.405+boxpar[0], 0., 0., 0, "ONLY");
1452   gMC->Gspos("QBS6", 2, "MQX2", -2.405-boxpar[0], 0., 0., 0, "ONLY");  
1453   gMC->Gspos("YMQ2", 1, "ZDCA", 0., 0., tubpar[2]+zInnTrip+908.5,  0, "ONLY");
1454
1455   
1456   // -- Q2B
1457   gMC->Gspos("MQX3", 1, "ZDCA", 0., 0., tubpar[2]+zInnTrip+1558.5, 0, "ONLY");
1458   gMC->Gspos("QBS5", 2, "MQX3", 0., 0., 0., 0, "ONLY");  
1459   gMC->Gspos("QBS6", 3, "MQX3", 2.405+boxpar[0], 0., 0., 0, "ONLY");
1460   gMC->Gspos("QBS6", 4, "MQX3", -2.405-boxpar[0], 0., 0., 0, "ONLY");
1461   gMC->Gspos("YMQ2", 2, "ZDCA", 0., 0., tubpar[2]+zInnTrip+1558.5, 0, "ONLY");
1462
1463   // -- SEPARATOR DIPOLE D1 
1464   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
1465   tubpar[0] = 0.;
1466   tubpar[1] = 6.75/2.;//3.375
1467   tubpar[2] = 945./2.;
1468   gMC->Gsvolu("MD1L", "TUBE", idtmed[11], tubpar, 3);
1469
1470   // --  The beam screen tube is provided by the beam pipe in D1 (QA03 volume)
1471   // --  Insert the beam screen horizontal Cu plates inside D1  
1472   // --   (to simulate the vacuum chamber)
1473   boxpar[0] = TMath::Sqrt(tubpar[1]*tubpar[1]-(2.885+0.2)*(2.885+0.2));
1474   boxpar[1] = 0.2/2.;
1475   boxpar[2] =945./2.;  
1476   gMC->Gsvolu("QBS7", "BOX ", idtmed[6], boxpar, 3);
1477   gMC->Gspos("QBS7", 1, "MD1L", 0., 2.885+boxpar[1],0., 0, "ONLY");
1478   gMC->Gspos("QBS7", 2, "MD1L", 0., -2.885-boxpar[1],0., 0, "ONLY");  
1479     
1480   // --  YOKE 
1481   tubpar[0] = 3.68;
1482   tubpar[1] = 110./2;
1483   tubpar[2] = 945./2.;
1484   gMC->Gsvolu("YD1L", "TUBE", idtmed[7], tubpar, 3);
1485   
1486   gMC->Gspos("YD1L", 1, "ZDCA", 0., 0., tubpar[2]+zD1, 0, "ONLY");  
1487   gMC->Gspos("MD1L", 1, "ZDCA", 0., 0., tubpar[2]+zD1, 0, "ONLY");  
1488   
1489   // -- DIPOLE D2 
1490   // --  GAP (VACUUM WITH MAGNETIC FIELD) 
1491   tubpar[0] = 0.;
1492   tubpar[1] = 7.5/2.; // this has to be checked
1493   tubpar[2] = 945./2.;
1494   gMC->Gsvolu("MD2L", "TUBE", idtmed[11], tubpar, 3);
1495   
1496   // --  YOKE 
1497   tubpar[0] = 0.;
1498   tubpar[1] = 55.;
1499   tubpar[2] = 945./2.;
1500   gMC->Gsvolu("YD2L", "TUBE", idtmed[7], tubpar, 3);
1501   
1502   gMC->Gspos("YD2L", 1, "ZDCA", 0., 0., tubpar[2]+zD2, 0, "ONLY");
1503   
1504   gMC->Gspos("MD2L", 1, "YD2L", -9.4, 0., 0., 0, "ONLY");
1505   gMC->Gspos("MD2L", 2, "YD2L",  9.4, 0., 0., 0, "ONLY");
1506   
1507   // -- END OF MAGNET DEFINITION     
1508 }
1509   
1510 //_____________________________________________________________________________
1511 void AliZDCv3::CreateZDC()
1512 {
1513  //
1514  // Create the various ZDCs (ZN + ZP)
1515  //
1516   
1517   Float_t dimPb[6], dimVoid[6];
1518   
1519   Int_t *idtmed = fIdtmed->GetArray();
1520
1521   // Parameters for hadronic calorimeters geometry
1522   // NB -> parameters used ONLY in CreateZDC()
1523   Float_t fGrvZN[3] = {0.03, 0.03, 50.};  // Grooves for neutron detector
1524   Float_t fGrvZP[3] = {0.04, 0.04, 75.};  // Grooves for proton detector
1525   Int_t   fDivZN[3] = {11, 11, 0};        // Division for neutron detector
1526   Int_t   fDivZP[3] = {7, 15, 0};         // Division for proton detector
1527   Int_t   fTowZN[2] = {2, 2};             // Tower for neutron detector
1528   Int_t   fTowZP[2] = {4, 1};             // Tower for proton detector
1529
1530   // Parameters for EM calorimeter geometry
1531   // NB -> parameters used ONLY in CreateZDC()
1532   Float_t kDimZEMPb  = 0.15*(TMath::Sqrt(2.));  // z-dimension of the Pb slice
1533   Float_t kFibRadZEM = 0.0315;                  // External fiber radius (including cladding)
1534   Int_t   fDivZEM[3] = {92, 0, 20};             // Divisions for EM detector
1535   Float_t fDimZEM[6] = {fZEMLength, 3.5, 3.5, 45., 0., 0.}; // Dimensions of EM detector
1536   Float_t fFibZEM2 = fDimZEM[2]/TMath::Sin(fDimZEM[3]*kDegrad)-kFibRadZEM;
1537   Float_t fFibZEM[3] = {0., 0.0275, fFibZEM2};  // Fibers for EM calorimeter
1538
1539   
1540   //-- Create calorimeters geometry
1541   
1542   // -------------------------------------------------------------------------------
1543   //--> Neutron calorimeter (ZN) 
1544   
1545   gMC->Gsvolu("ZNEU", "BOX ", idtmed[1], fDimZN, 3); // Passive material  
1546   gMC->Gsvolu("ZNF1", "TUBE", idtmed[3], fFibZN, 3); // Active material
1547   gMC->Gsvolu("ZNF2", "TUBE", idtmed[4], fFibZN, 3); 
1548   gMC->Gsvolu("ZNF3", "TUBE", idtmed[4], fFibZN, 3); 
1549   gMC->Gsvolu("ZNF4", "TUBE", idtmed[3], fFibZN, 3); 
1550   gMC->Gsvolu("ZNG1", "BOX ", idtmed[12], fGrvZN, 3); // Empty grooves 
1551   gMC->Gsvolu("ZNG2", "BOX ", idtmed[12], fGrvZN, 3); 
1552   gMC->Gsvolu("ZNG3", "BOX ", idtmed[12], fGrvZN, 3); 
1553   gMC->Gsvolu("ZNG4", "BOX ", idtmed[12], fGrvZN, 3); 
1554   
1555   // Divide ZNEU in towers (for hits purposes) 
1556   
1557   gMC->Gsdvn("ZNTX", "ZNEU", fTowZN[0], 1); // x-tower 
1558   gMC->Gsdvn("ZN1 ", "ZNTX", fTowZN[1], 2); // y-tower
1559   
1560   //-- Divide ZN1 in minitowers 
1561   //  fDivZN[0]= NUMBER OF FIBERS PER TOWER ALONG X-AXIS, 
1562   //  fDivZN[1]= NUMBER OF FIBERS PER TOWER ALONG Y-AXIS
1563   //  (4 fibres per minitower) 
1564   
1565   gMC->Gsdvn("ZNSL", "ZN1 ", fDivZN[1], 2); // Slices 
1566   gMC->Gsdvn("ZNST", "ZNSL", fDivZN[0], 1); // Sticks
1567   
1568   // --- Position the empty grooves in the sticks (4 grooves per stick)
1569   Float_t dx = fDimZN[0] / fDivZN[0] / 4.;
1570   Float_t dy = fDimZN[1] / fDivZN[1] / 4.;
1571   
1572   gMC->Gspos("ZNG1", 1, "ZNST", 0.-dx, 0.+dy, 0., 0, "ONLY");
1573   gMC->Gspos("ZNG2", 1, "ZNST", 0.+dx, 0.+dy, 0., 0, "ONLY");
1574   gMC->Gspos("ZNG3", 1, "ZNST", 0.-dx, 0.-dy, 0., 0, "ONLY");
1575   gMC->Gspos("ZNG4", 1, "ZNST", 0.+dx, 0.-dy, 0., 0, "ONLY");
1576   
1577   // --- Position the fibers in the grooves 
1578   gMC->Gspos("ZNF1", 1, "ZNG1", 0., 0., 0., 0, "ONLY");
1579   gMC->Gspos("ZNF2", 1, "ZNG2", 0., 0., 0., 0, "ONLY");
1580   gMC->Gspos("ZNF3", 1, "ZNG3", 0., 0., 0., 0, "ONLY");
1581   gMC->Gspos("ZNF4", 1, "ZNG4", 0., 0., 0., 0, "ONLY");
1582   
1583   // --- Position the neutron calorimeter in ZDC 
1584   // -- Rotation of ZDCs
1585   Int_t irotzdc;
1586   gMC->Matrix(irotzdc, 90., 180., 90., 90., 180., 0.);
1587   //
1588   gMC->Gspos("ZNEU", 1, "ZDCC", fPosZNC[0], fPosZNC[1], fPosZNC[2]-fDimZN[2], irotzdc, "ONLY");
1589   //Ch debug
1590   //printf("\n ZN -> %f < z < %f cm\n",fPosZN[2],fPosZN[2]-2*fDimZN[2]);
1591
1592   // --- Position the neutron calorimeter in ZDC2 (left line) 
1593   // -- No Rotation of ZDCs
1594   gMC->Gspos("ZNEU", 2, "ZDCA", fPosZNA[0], fPosZNA[1], fPosZNA[2]+fDimZN[2], 0, "ONLY");
1595   //Ch debug
1596   //printf("\n ZN left -> %f < z < %f cm\n",fPosZNl[2],fPosZNl[2]+2*fDimZN[2]);
1597
1598
1599   // -------------------------------------------------------------------------------
1600   //--> Proton calorimeter (ZP)  
1601   
1602   gMC->Gsvolu("ZPRO", "BOX ", idtmed[2], fDimZP, 3); // Passive material
1603   gMC->Gsvolu("ZPF1", "TUBE", idtmed[3], fFibZP, 3); // Active material
1604   gMC->Gsvolu("ZPF2", "TUBE", idtmed[4], fFibZP, 3); 
1605   gMC->Gsvolu("ZPF3", "TUBE", idtmed[4], fFibZP, 3); 
1606   gMC->Gsvolu("ZPF4", "TUBE", idtmed[3], fFibZP, 3); 
1607   gMC->Gsvolu("ZPG1", "BOX ", idtmed[12], fGrvZP, 3); // Empty grooves 
1608   gMC->Gsvolu("ZPG2", "BOX ", idtmed[12], fGrvZP, 3); 
1609   gMC->Gsvolu("ZPG3", "BOX ", idtmed[12], fGrvZP, 3); 
1610   gMC->Gsvolu("ZPG4", "BOX ", idtmed[12], fGrvZP, 3); 
1611     
1612   //-- Divide ZPRO in towers(for hits purposes) 
1613   
1614   gMC->Gsdvn("ZPTX", "ZPRO", fTowZP[0], 1); // x-tower 
1615   gMC->Gsdvn("ZP1 ", "ZPTX", fTowZP[1], 2); // y-tower
1616   
1617   
1618   //-- Divide ZP1 in minitowers 
1619   //  fDivZP[0]= NUMBER OF FIBERS ALONG X-AXIS PER MINITOWER, 
1620   //  fDivZP[1]= NUMBER OF FIBERS ALONG Y-AXIS PER MINITOWER
1621   //  (4 fiber per minitower) 
1622   
1623   gMC->Gsdvn("ZPSL", "ZP1 ", fDivZP[1], 2); // Slices 
1624   gMC->Gsdvn("ZPST", "ZPSL", fDivZP[0], 1); // Sticks
1625   
1626   // --- Position the empty grooves in the sticks (4 grooves per stick)
1627   dx = fDimZP[0] / fTowZP[0] / fDivZP[0] / 2.;
1628   dy = fDimZP[1] / fTowZP[1] / fDivZP[1] / 2.;
1629   
1630   gMC->Gspos("ZPG1", 1, "ZPST", 0.-dx, 0.+dy, 0., 0, "ONLY");
1631   gMC->Gspos("ZPG2", 1, "ZPST", 0.+dx, 0.+dy, 0., 0, "ONLY");
1632   gMC->Gspos("ZPG3", 1, "ZPST", 0.-dx, 0.-dy, 0., 0, "ONLY");
1633   gMC->Gspos("ZPG4", 1, "ZPST", 0.+dx, 0.-dy, 0., 0, "ONLY");
1634   
1635   // --- Position the fibers in the grooves 
1636   gMC->Gspos("ZPF1", 1, "ZPG1", 0., 0., 0., 0, "ONLY");
1637   gMC->Gspos("ZPF2", 1, "ZPG2", 0., 0., 0., 0, "ONLY");
1638   gMC->Gspos("ZPF3", 1, "ZPG3", 0., 0., 0., 0, "ONLY");
1639   gMC->Gspos("ZPF4", 1, "ZPG4", 0., 0., 0., 0, "ONLY");
1640   
1641
1642   // --- Position the proton calorimeter in ZDCC
1643   gMC->Gspos("ZPRO", 1, "ZDCC", fPosZPC[0], fPosZPC[1], fPosZPC[2]-fDimZP[2], irotzdc, "ONLY");
1644   //Ch debug
1645   //printf("\n ZP -> %f < z < %f cm\n",fPosZP[2],fPosZP[2]-2*fDimZP[2]);
1646   
1647   // --- Position the proton calorimeter in ZDCA
1648   // --- No rotation 
1649   gMC->Gspos("ZPRO", 2, "ZDCA", fPosZPA[0], fPosZPA[1], fPosZPA[2]+fDimZP[2], 0, "ONLY");
1650   //Ch debug
1651   //printf("\n ZP left -> %f < z < %f cm\n",fPosZPl[2],fPosZPl[2]+2*fDimZP[2]);  
1652     
1653   
1654   // -------------------------------------------------------------------------------
1655   // -> EM calorimeter (ZEM)  
1656   
1657   gMC->Gsvolu("ZEM ", "PARA", idtmed[10], fDimZEM, 6);
1658
1659   Int_t irot1, irot2;
1660   gMC->Matrix(irot1,0.,0.,90.,90.,-90.,0.);                    // Rotation matrix 1  
1661   gMC->Matrix(irot2,180.,0.,90.,fDimZEM[3]+90.,90.,fDimZEM[3]);// Rotation matrix 2
1662   //printf("irot1 = %d, irot2 = %d \n", irot1, irot2);
1663   
1664   gMC->Gsvolu("ZEMF", "TUBE", idtmed[3], fFibZEM, 3);   // Active material
1665
1666   gMC->Gsdvn("ZETR", "ZEM ", fDivZEM[2], 1);            // Tranches 
1667   
1668   dimPb[0] = kDimZEMPb;                                 // Lead slices 
1669   dimPb[1] = fDimZEM[2];
1670   dimPb[2] = fDimZEM[1];
1671   //dimPb[3] = fDimZEM[3]; //controllare
1672   dimPb[3] = 90.-fDimZEM[3]; //originale
1673   dimPb[4] = 0.;
1674   dimPb[5] = 0.;
1675   gMC->Gsvolu("ZEL0", "PARA", idtmed[5], dimPb, 6);
1676   gMC->Gsvolu("ZEL1", "PARA", idtmed[5], dimPb, 6);
1677   gMC->Gsvolu("ZEL2", "PARA", idtmed[5], dimPb, 6);
1678   
1679   // --- Position the lead slices in the tranche 
1680   Float_t zTran = fDimZEM[0]/fDivZEM[2]; 
1681   Float_t zTrPb = -zTran+kDimZEMPb;
1682   gMC->Gspos("ZEL0", 1, "ZETR", zTrPb, 0., 0., 0, "ONLY");
1683   gMC->Gspos("ZEL1", 1, "ZETR", kDimZEMPb, 0., 0., 0, "ONLY");
1684   
1685   // --- Vacuum zone (to be filled with fibres)
1686   dimVoid[0] = (zTran-2*kDimZEMPb)/2.;
1687   dimVoid[1] = fDimZEM[2];
1688   dimVoid[2] = fDimZEM[1];
1689   dimVoid[3] = 90.-fDimZEM[3];
1690   dimVoid[4] = 0.;
1691   dimVoid[5] = 0.;
1692   gMC->Gsvolu("ZEV0", "PARA", idtmed[10], dimVoid,6);
1693   gMC->Gsvolu("ZEV1", "PARA", idtmed[10], dimVoid,6);
1694   
1695   // --- Divide the vacuum slice into sticks along x axis
1696   gMC->Gsdvn("ZES0", "ZEV0", fDivZEM[0], 3); 
1697   gMC->Gsdvn("ZES1", "ZEV1", fDivZEM[0], 3); 
1698   
1699   // --- Positioning the fibers into the sticks
1700   gMC->Gspos("ZEMF", 1,"ZES0", 0., 0., 0., irot2, "ONLY");
1701   gMC->Gspos("ZEMF", 1,"ZES1", 0., 0., 0., irot2, "ONLY");
1702   
1703   // --- Positioning the vacuum slice into the tranche
1704   //Float_t displFib = fDimZEM[1]/fDivZEM[0];
1705   gMC->Gspos("ZEV0", 1,"ZETR", -dimVoid[0], 0., 0., 0, "ONLY");
1706   gMC->Gspos("ZEV1", 1,"ZETR", -dimVoid[0]+zTran, 0., 0., 0, "ONLY");
1707
1708   // --- Positioning the ZEM into the ZDC - rotation for 90 degrees  
1709   // NB -> ZEM is positioned in ALIC (instead of in ZDC) volume
1710   gMC->Gspos("ZEM ", 1,"ALIC", -fPosZEM[0], fPosZEM[1], fPosZEM[2]+fDimZEM[0], irot1, "ONLY");
1711   
1712   // Second EM ZDC (same side w.r.t. IP, just on the other side w.r.t. beam pipe)
1713   gMC->Gspos("ZEM ", 2,"ALIC", fPosZEM[0], fPosZEM[1], fPosZEM[2]+fDimZEM[0], irot1, "ONLY");
1714   
1715   // --- Adding last slice at the end of the EM calorimeter 
1716   Float_t zLastSlice = fPosZEM[2]+kDimZEMPb+2*fDimZEM[0];
1717   gMC->Gspos("ZEL2", 1,"ALIC", fPosZEM[0], fPosZEM[1], zLastSlice, irot1, "ONLY");
1718   //Ch debug
1719   //printf("\n ZEM lenght = %f cm\n",2*fZEMLength);
1720   //printf("\n ZEM -> %f < z < %f cm\n",fPosZEM[2],fPosZEM[2]+2*fZEMLength+zLastSlice+kDimZEMPb);
1721   
1722 }
1723  
1724 //_____________________________________________________________________________
1725 void AliZDCv3::DrawModule() const
1726 {
1727   //
1728   // Draw a shaded view of the Zero Degree Calorimeter version 1
1729   //
1730
1731   // Set everything unseen
1732   gMC->Gsatt("*", "seen", -1);
1733   // 
1734   // Set ALIC mother transparent
1735   gMC->Gsatt("ALIC","SEEN",0);
1736   //
1737   // Set the volumes visible
1738   gMC->Gsatt("ZDCC","SEEN",0);
1739   gMC->Gsatt("QT01","SEEN",1);
1740   gMC->Gsatt("QT02","SEEN",1);
1741   gMC->Gsatt("QT03","SEEN",1);
1742   gMC->Gsatt("QT04","SEEN",1);
1743   gMC->Gsatt("QT05","SEEN",1);
1744   gMC->Gsatt("QT06","SEEN",1);
1745   gMC->Gsatt("QT07","SEEN",1);
1746   gMC->Gsatt("QT08","SEEN",1);
1747   gMC->Gsatt("QT09","SEEN",1);
1748   gMC->Gsatt("QT10","SEEN",1);
1749   gMC->Gsatt("QT11","SEEN",1);
1750   gMC->Gsatt("QT12","SEEN",1);
1751   gMC->Gsatt("QT13","SEEN",1);
1752   gMC->Gsatt("QT14","SEEN",1);
1753   gMC->Gsatt("QT15","SEEN",1);
1754   gMC->Gsatt("QT16","SEEN",1);
1755   gMC->Gsatt("QT17","SEEN",1);
1756   gMC->Gsatt("QT18","SEEN",1);
1757   gMC->Gsatt("QC01","SEEN",1);
1758   gMC->Gsatt("QC02","SEEN",1);
1759   gMC->Gsatt("QC03","SEEN",1);
1760   gMC->Gsatt("QC04","SEEN",1);
1761   gMC->Gsatt("QC05","SEEN",1);
1762   gMC->Gsatt("QTD1","SEEN",1);
1763   gMC->Gsatt("QTD2","SEEN",1);
1764   gMC->Gsatt("QTD3","SEEN",1);
1765   gMC->Gsatt("MQXL","SEEN",1);
1766   gMC->Gsatt("YMQL","SEEN",1);
1767   gMC->Gsatt("MQX ","SEEN",1);
1768   gMC->Gsatt("YMQ ","SEEN",1);
1769   gMC->Gsatt("ZQYX","SEEN",1);
1770   gMC->Gsatt("MD1 ","SEEN",1);
1771   gMC->Gsatt("MD1V","SEEN",1);
1772   gMC->Gsatt("YD1 ","SEEN",1);
1773   gMC->Gsatt("MD2 ","SEEN",1);
1774   gMC->Gsatt("YD2 ","SEEN",1);
1775   gMC->Gsatt("ZNEU","SEEN",0);
1776   gMC->Gsatt("ZNF1","SEEN",0);
1777   gMC->Gsatt("ZNF2","SEEN",0);
1778   gMC->Gsatt("ZNF3","SEEN",0);
1779   gMC->Gsatt("ZNF4","SEEN",0);
1780   gMC->Gsatt("ZNG1","SEEN",0);
1781   gMC->Gsatt("ZNG2","SEEN",0);
1782   gMC->Gsatt("ZNG3","SEEN",0);
1783   gMC->Gsatt("ZNG4","SEEN",0);
1784   gMC->Gsatt("ZNTX","SEEN",0);
1785   gMC->Gsatt("ZN1 ","COLO",4); 
1786   gMC->Gsatt("ZN1 ","SEEN",1);
1787   gMC->Gsatt("ZNSL","SEEN",0);
1788   gMC->Gsatt("ZNST","SEEN",0);
1789   gMC->Gsatt("ZPRO","SEEN",0);
1790   gMC->Gsatt("ZPF1","SEEN",0);
1791   gMC->Gsatt("ZPF2","SEEN",0);
1792   gMC->Gsatt("ZPF3","SEEN",0);
1793   gMC->Gsatt("ZPF4","SEEN",0);
1794   gMC->Gsatt("ZPG1","SEEN",0);
1795   gMC->Gsatt("ZPG2","SEEN",0);
1796   gMC->Gsatt("ZPG3","SEEN",0);
1797   gMC->Gsatt("ZPG4","SEEN",0);
1798   gMC->Gsatt("ZPTX","SEEN",0);
1799   gMC->Gsatt("ZP1 ","COLO",6); 
1800   gMC->Gsatt("ZP1 ","SEEN",1);
1801   gMC->Gsatt("ZPSL","SEEN",0);
1802   gMC->Gsatt("ZPST","SEEN",0);
1803   gMC->Gsatt("ZEM ","COLO",7); 
1804   gMC->Gsatt("ZEM ","SEEN",1);
1805   gMC->Gsatt("ZEMF","SEEN",0);
1806   gMC->Gsatt("ZETR","SEEN",0);
1807   gMC->Gsatt("ZEL0","SEEN",0);
1808   gMC->Gsatt("ZEL1","SEEN",0);
1809   gMC->Gsatt("ZEL2","SEEN",0);
1810   gMC->Gsatt("ZEV0","SEEN",0);
1811   gMC->Gsatt("ZEV1","SEEN",0);
1812   gMC->Gsatt("ZES0","SEEN",0);
1813   gMC->Gsatt("ZES1","SEEN",0);
1814   
1815   //
1816   gMC->Gdopt("hide", "on");
1817   gMC->Gdopt("shad", "on");
1818   gMC->Gsatt("*", "fill", 7);
1819   gMC->SetClipBox(".");
1820   gMC->SetClipBox("*", 0, 100, -100, 100, 12000, 16000);
1821   gMC->DefaultRange();
1822   gMC->Gdraw("alic", 40, 30, 0, 488, 220, .07, .07);
1823   gMC->Gdhead(1111, "Zero Degree Calorimeter Version 3");
1824   gMC->Gdman(18, 4, "MAN");
1825 }
1826
1827 //_____________________________________________________________________________
1828 void AliZDCv3::CreateMaterials()
1829 {
1830   //
1831   // Create Materials for the Zero Degree Calorimeter
1832   //
1833   Float_t dens, ubuf[1], wmat[3], a[3], z[3];
1834
1835   // --- W alloy -> ZN passive material
1836   dens = 17.6;
1837   a[0] = 183.85;
1838   a[1] = 55.85;
1839   a[2] = 58.71;
1840   z[0] = 74.;
1841   z[1] = 26.;
1842   z[2] = 28.;
1843   wmat[0] = .93;
1844   wmat[1] = .03;
1845   wmat[2] = .04;
1846   AliMixture(1, "WALL", a, z, dens, 3, wmat);
1847
1848   // --- Brass (CuZn)  -> ZP passive material
1849   dens = 8.48;
1850   a[0] = 63.546;
1851   a[1] = 65.39;
1852   z[0] = 29.;
1853   z[1] = 30.;
1854   wmat[0] = .63;
1855   wmat[1] = .37;
1856   AliMixture(2, "BRASS", a, z, dens, 2, wmat);
1857   
1858   // --- SiO2 
1859   dens = 2.64;
1860   a[0] = 28.086;
1861   a[1] = 15.9994;
1862   z[0] = 14.;
1863   z[1] = 8.;
1864   wmat[0] = 1.;
1865   wmat[1] = 2.;
1866   AliMixture(3, "SIO2", a, z, dens, -2, wmat);  
1867   
1868   // --- Lead 
1869   ubuf[0] = 1.12;
1870   AliMaterial(5, "LEAD", 207.19, 82., 11.35, .56, 18.5, ubuf, 1);
1871
1872   // --- Copper (energy loss taken into account)
1873   ubuf[0] = 1.10;
1874   AliMaterial(6, "COPP0", 63.54, 29., 8.96, 1.4, 0., ubuf, 1);
1875   
1876   // --- Iron (energy loss taken into account)
1877   ubuf[0] = 1.1;
1878   AliMaterial(7, "IRON0", 55.85, 26., 7.87, 1.76, 0., ubuf, 1);
1879   
1880   // --- Iron (no energy loss)
1881   ubuf[0] = 1.1;
1882   AliMaterial(8, "IRON1", 55.85, 26., 7.87, 1.76, 0., ubuf, 1);
1883     
1884   // ---------------------------------------------------------  
1885   Float_t aResGas[3]={1.008,12.0107,15.9994};
1886   Float_t zResGas[3]={1.,6.,8.};
1887   Float_t wResGas[3]={0.28,0.28,0.44};
1888   Float_t dResGas = 3.2E-14;
1889
1890   // --- Vacuum (no magnetic field) 
1891   AliMixture(10, "VOID", aResGas, zResGas, dResGas, 3, wResGas);
1892   
1893   // --- Vacuum (with magnetic field) 
1894   AliMixture(11, "VOIM", aResGas, zResGas, dResGas, 3, wResGas);
1895   
1896   // --- Air (no magnetic field)
1897   Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
1898   Float_t zAir[4]={6.,7.,8.,18.};
1899   Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
1900   Float_t dAir = 1.20479E-3;
1901   //
1902   AliMixture(12, "Air    $", aAir, zAir, dAir, 4, wAir);
1903   
1904   // ---  Definition of tracking media: 
1905   
1906   // --- Tantalum = 1 ; 
1907   // --- Brass = 2 ; 
1908   // --- Fibers (SiO2) = 3 ; 
1909   // --- Fibers (SiO2) = 4 ; 
1910   // --- Lead = 5 ; 
1911   // --- Copper (with energy loss)= 6 ;
1912   // --- Copper (with energy loss)= 13 ; 
1913   // --- Iron (with energy loss) = 7 ; 
1914   // --- Iron (without energy loss) = 8 ; 
1915   // --- Vacuum (no field) = 10 
1916   // --- Vacuum (with field) = 11 
1917   // --- Air (no field) = 12 
1918   
1919   // **************************************************** 
1920   //     Tracking media parameters
1921   //
1922   Float_t epsil  = 0.01;   // Tracking precision, 
1923   Float_t stmin  = 0.01;   // Min. value 4 max. step (cm)
1924   Float_t stemax = 1.;     // Max. step permitted (cm) 
1925   Float_t tmaxfd = 0.;     // Maximum angle due to field (degrees) 
1926   Float_t deemax = -1.;    // Maximum fractional energy loss
1927   Float_t nofieldm = 0.;   // Max. field value (no field)
1928   Float_t fieldm = 45.;    // Max. field value (with field)
1929   Int_t isvol = 0;         // ISVOL =0 -> not sensitive volume
1930   Int_t isvolActive = 1;   // ISVOL =1 -> sensitive volume
1931   Int_t inofld = 0;        // IFIELD=0 -> no magnetic field
1932   Int_t ifield =2;         // IFIELD=2 -> magnetic field defined in AliMagFC.h
1933   // *****************************************************
1934   
1935   AliMedium(1, "ZTANT", 1, isvolActive, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1936   AliMedium(2, "ZBRASS",2, isvolActive, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1937   AliMedium(3, "ZSIO2", 3, isvolActive, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1938   AliMedium(4, "ZQUAR", 3, isvolActive, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1939   AliMedium(5, "ZLEAD", 5, isvolActive, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1940   AliMedium(6, "ZCOPP", 6, isvol, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1941   AliMedium(7, "ZIRON", 7, isvol, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1942   AliMedium(8, "ZIRONN",8, isvol, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1943   AliMedium(10,"ZVOID",10, isvol, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1944   AliMedium(12,"ZAIR", 12, isvol, inofld, nofieldm, tmaxfd, stemax, deemax, epsil, stmin);
1945   //
1946   AliMedium(11,"ZVOIM",11, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil, stmin);
1947
1948
1949
1950
1951 //_____________________________________________________________________________
1952 void AliZDCv3::AddAlignableVolumes() const
1953 {
1954  //
1955  // Create entries for alignable volumes associating the symbolic volume
1956  // name with the corresponding volume path. Needs to be syncronized with
1957  // eventual changes in the geometry.
1958  //
1959  TString volpath1 = "ALIC_1/ZDCC_1/ZNEU_1";
1960  TString volpath2 = "ALIC_1/ZDCC_1/ZPRO_1";
1961  TString volpath3 = "ALIC_1/ZDCA_1/ZNEU_2";
1962  TString volpath4 = "ALIC_1/ZDCA_1/ZPRO_2";
1963
1964  TString symname1="ZDC/NeutronZDC_C";
1965  TString symname2="ZDC/ProtonZDC_C";
1966  TString symname3="ZDC/NeutronZDC_A";
1967  TString symname4="ZDC/ProtonZDC_A";
1968
1969  if(!gGeoManager->SetAlignableEntry(symname1.Data(),volpath1.Data()))
1970      AliFatal(Form("Alignable entry %s not created. Volume path %s not valid",   symname1.Data(),volpath1.Data()));
1971
1972  if(!gGeoManager->SetAlignableEntry(symname2.Data(),volpath2.Data()))
1973      AliFatal(Form("Alignable entry %s not created. Volume path %s not valid",   symname2.Data(),volpath2.Data()));
1974
1975  if(!gGeoManager->SetAlignableEntry(symname3.Data(),volpath3.Data()))
1976      AliFatal(Form("Alignable entry %s not created. Volume path %s not valid",   symname1.Data(),volpath1.Data()));
1977
1978  if(!gGeoManager->SetAlignableEntry(symname4.Data(),volpath4.Data()))
1979      AliFatal(Form("Alignable entry %s not created. Volume path %s not valid",   symname2.Data(),volpath2.Data()));
1980
1981 }
1982
1983
1984 //_____________________________________________________________________________
1985 void AliZDCv3::Init()
1986 {
1987  InitTables();
1988   Int_t *idtmed = fIdtmed->GetArray();  
1989   Int_t i;
1990   // Thresholds for showering in the ZDCs 
1991   i = 1; //tantalum
1992   gMC->Gstpar(idtmed[i], "CUTGAM", .001);
1993   gMC->Gstpar(idtmed[i], "CUTELE", .001);
1994   gMC->Gstpar(idtmed[i], "CUTNEU", .01);
1995   gMC->Gstpar(idtmed[i], "CUTHAD", .01);
1996   i = 2; //brass
1997   gMC->Gstpar(idtmed[i], "CUTGAM", .001);
1998   gMC->Gstpar(idtmed[i], "CUTELE", .001);
1999   gMC->Gstpar(idtmed[i], "CUTNEU", .01);
2000   gMC->Gstpar(idtmed[i], "CUTHAD", .01);
2001   i = 5; //lead
2002   gMC->Gstpar(idtmed[i], "CUTGAM", .001);
2003   gMC->Gstpar(idtmed[i], "CUTELE", .001);
2004   gMC->Gstpar(idtmed[i], "CUTNEU", .01);
2005   gMC->Gstpar(idtmed[i], "CUTHAD", .01);
2006   
2007   // Avoid too detailed showering in TDI 
2008   i = 6; //copper
2009   gMC->Gstpar(idtmed[i], "CUTGAM", .1);
2010   gMC->Gstpar(idtmed[i], "CUTELE", .1);
2011   gMC->Gstpar(idtmed[i], "CUTNEU", 1.);
2012   gMC->Gstpar(idtmed[i], "CUTHAD", 1.);
2013   
2014   // Avoid too detailed showering along the beam line 
2015   i = 7; //iron with energy loss (ZIRON)
2016   gMC->Gstpar(idtmed[i], "CUTGAM", .1);
2017   gMC->Gstpar(idtmed[i], "CUTELE", .1);
2018   gMC->Gstpar(idtmed[i], "CUTNEU", 1.);
2019   gMC->Gstpar(idtmed[i], "CUTHAD", 1.);
2020   
2021   // Avoid too detailed showering along the beam line 
2022   i = 8; //iron with energy loss (ZIRONN)
2023   gMC->Gstpar(idtmed[i], "CUTGAM", .1);
2024   gMC->Gstpar(idtmed[i], "CUTELE", .1);
2025   gMC->Gstpar(idtmed[i], "CUTNEU", 1.);
2026   gMC->Gstpar(idtmed[i], "CUTHAD", 1.);
2027   
2028   // Avoid interaction in fibers (only energy loss allowed) 
2029   i = 3; //fibers (ZSI02)
2030   gMC->Gstpar(idtmed[i], "DCAY", 0.);
2031   gMC->Gstpar(idtmed[i], "MULS", 0.);
2032   gMC->Gstpar(idtmed[i], "PFIS", 0.);
2033   gMC->Gstpar(idtmed[i], "MUNU", 0.);
2034   gMC->Gstpar(idtmed[i], "LOSS", 1.);
2035   gMC->Gstpar(idtmed[i], "PHOT", 0.);
2036   gMC->Gstpar(idtmed[i], "COMP", 0.);
2037   gMC->Gstpar(idtmed[i], "PAIR", 0.);
2038   gMC->Gstpar(idtmed[i], "BREM", 0.);
2039   gMC->Gstpar(idtmed[i], "DRAY", 0.);
2040   gMC->Gstpar(idtmed[i], "ANNI", 0.);
2041   gMC->Gstpar(idtmed[i], "HADR", 0.);
2042   i = 4; //fibers (ZQUAR)
2043   gMC->Gstpar(idtmed[i], "DCAY", 0.);
2044   gMC->Gstpar(idtmed[i], "MULS", 0.);
2045   gMC->Gstpar(idtmed[i], "PFIS", 0.);
2046   gMC->Gstpar(idtmed[i], "MUNU", 0.);
2047   gMC->Gstpar(idtmed[i], "LOSS", 1.);
2048   gMC->Gstpar(idtmed[i], "PHOT", 0.);
2049   gMC->Gstpar(idtmed[i], "COMP", 0.);
2050   gMC->Gstpar(idtmed[i], "PAIR", 0.);
2051   gMC->Gstpar(idtmed[i], "BREM", 0.);
2052   gMC->Gstpar(idtmed[i], "DRAY", 0.);
2053   gMC->Gstpar(idtmed[i], "ANNI", 0.);
2054   gMC->Gstpar(idtmed[i], "HADR", 0.);
2055   
2056   // Avoid interaction in void 
2057   i = 11; //void with field
2058   gMC->Gstpar(idtmed[i], "DCAY", 0.);
2059   gMC->Gstpar(idtmed[i], "MULS", 0.);
2060   gMC->Gstpar(idtmed[i], "PFIS", 0.);
2061   gMC->Gstpar(idtmed[i], "MUNU", 0.);
2062   gMC->Gstpar(idtmed[i], "LOSS", 0.);
2063   gMC->Gstpar(idtmed[i], "PHOT", 0.);
2064   gMC->Gstpar(idtmed[i], "COMP", 0.);
2065   gMC->Gstpar(idtmed[i], "PAIR", 0.);
2066   gMC->Gstpar(idtmed[i], "BREM", 0.);
2067   gMC->Gstpar(idtmed[i], "DRAY", 0.);
2068   gMC->Gstpar(idtmed[i], "ANNI", 0.);
2069   gMC->Gstpar(idtmed[i], "HADR", 0.);
2070
2071   //
2072   fMedSensZN  = idtmed[1];  // Sensitive volume: ZN passive material
2073   fMedSensZP  = idtmed[2];  // Sensitive volume: ZP passive material
2074   fMedSensF1  = idtmed[3];  // Sensitive volume: fibres type 1
2075   fMedSensF2  = idtmed[4];  // Sensitive volume: fibres type 2
2076   fMedSensZEM = idtmed[5];  // Sensitive volume: ZEM passive material
2077   fMedSensTDI = idtmed[6];  // Sensitive volume: TDI Cu shield
2078   fMedSensPI  = idtmed[7];  // Sensitive volume: beam pipes
2079   fMedSensGR  = idtmed[12]; // Sensitive volume: air into the grooves
2080 }
2081
2082 //_____________________________________________________________________________
2083 void AliZDCv3::InitTables()
2084 {
2085  //
2086  // Read light tables for Cerenkov light production parameterization 
2087  //
2088
2089   Int_t k, j;
2090
2091   char *lightfName1,*lightfName2,*lightfName3,*lightfName4,
2092        *lightfName5,*lightfName6,*lightfName7,*lightfName8;
2093   FILE *fp1, *fp2, *fp3, *fp4, *fp5, *fp6, *fp7, *fp8;
2094
2095   //  --- Reading light tables for ZN 
2096   lightfName1 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620362207s");
2097   if((fp1 = fopen(lightfName1,"r")) == NULL){
2098      printf("Cannot open file fp1 \n");
2099      return;
2100   }
2101   lightfName2 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620362208s");
2102   if((fp2 = fopen(lightfName2,"r")) == NULL){
2103      printf("Cannot open file fp2 \n");
2104      return;
2105   }  
2106   lightfName3 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620362209s");
2107   if((fp3 = fopen(lightfName3,"r")) == NULL){
2108      printf("Cannot open file fp3 \n");
2109      return;
2110   }
2111   lightfName4 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620362210s");
2112   if((fp4 = fopen(lightfName4,"r")) == NULL){
2113      printf("Cannot open file fp4 \n");
2114      return;
2115   }
2116   
2117   for(k=0; k<fNalfan; k++){
2118      for(j=0; j<fNben; j++){
2119        fscanf(fp1,"%f",&fTablen[0][k][j]);
2120        fscanf(fp2,"%f",&fTablen[1][k][j]);
2121        fscanf(fp3,"%f",&fTablen[2][k][j]);
2122        fscanf(fp4,"%f",&fTablen[3][k][j]);
2123      } 
2124   }
2125   fclose(fp1);
2126   fclose(fp2);
2127   fclose(fp3);
2128   fclose(fp4);
2129   
2130   //  --- Reading light tables for ZP and ZEM
2131   lightfName5 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620552207s");
2132   if((fp5 = fopen(lightfName5,"r")) == NULL){
2133      printf("Cannot open file fp5 \n");
2134      return;
2135   }
2136   lightfName6 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620552208s");
2137   if((fp6 = fopen(lightfName6,"r")) == NULL){
2138      printf("Cannot open file fp6 \n");
2139      return;
2140   }
2141   lightfName7 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620552209s");
2142   if((fp7 = fopen(lightfName7,"r")) == NULL){
2143      printf("Cannot open file fp7 \n");
2144      return;
2145   }
2146   lightfName8 = gSystem->ExpandPathName("$ALICE_ROOT/ZDC/light22620552210s");
2147   if((fp8 = fopen(lightfName8,"r")) == NULL){
2148      printf("Cannot open file fp8 \n");
2149      return;
2150   }
2151   
2152   for(k=0; k<fNalfap; k++){
2153      for(j=0; j<fNbep; j++){
2154        fscanf(fp5,"%f",&fTablep[0][k][j]);
2155        fscanf(fp6,"%f",&fTablep[1][k][j]);
2156        fscanf(fp7,"%f",&fTablep[2][k][j]);
2157        fscanf(fp8,"%f",&fTablep[3][k][j]);
2158      } 
2159   }
2160   fclose(fp5);
2161   fclose(fp6);
2162   fclose(fp7);
2163   fclose(fp8);
2164 }
2165 //_____________________________________________________________________________
2166 void AliZDCv3::StepManager()
2167 {
2168   //
2169   // Routine called at every step in the Zero Degree Calorimeters
2170   //
2171   Int_t   j, vol[2]={0,0}, ibeta=0, ialfa=0, ibe=0, nphe=0;
2172   Float_t hits[11], x[3], xdet[3], um[3], ud[3];
2173   Float_t m=0., ekin=0., destep=0., be=0., out=0.;
2174   // Parametrization for light guide uniformity
2175   // NEW!!! Light guide tilted @ 51 degrees
2176   Float_t guiPar[4]={0.31,-0.0006305,0.01337,0.8895};
2177   Double_t s[3], p[3];
2178   const char *knamed;
2179   //
2180   for(j=0;j<11;j++) hits[j]=-999.;
2181   //
2182   // --- This part is for no shower developement in beam pipe and TDI
2183   // If particle interacts with beam pipe or TDI -> return
2184   if((gMC->CurrentMedium() == fMedSensPI) || (gMC->CurrentMedium() == fMedSensTDI)){ 
2185     // If option NoShower is set -> StopTrack
2186     Int_t ipr = 0; 
2187     if(fNoShower==1){
2188       gMC->TrackPosition(s[0],s[1],s[2]);
2189       if(gMC->CurrentMedium() == fMedSensPI){
2190         knamed = gMC->CurrentVolName();
2191         if(!strncmp(knamed,"YMQ",3)){
2192           if(s[2]<0) fpLostITC += 1;
2193           else fpLostITA += 1;
2194           ipr=1;
2195         }
2196         else if(!strncmp(knamed,"YD1",3)){
2197           if(s[2]<0) fpLostD1C += 1;
2198           else fpLostD1A += 1;
2199           ipr=1;
2200         }
2201         else if(!strncmp(knamed,"QAL",3)) fnTrou++;
2202       }
2203       else if(gMC->CurrentMedium() == fMedSensTDI){ 
2204         knamed = gMC->CurrentVolName();
2205         if(!strncmp(knamed,"MD1",3)){
2206           if(s[2]<0) fpLostD1C += 1;
2207           else  fpLostD1A += 1;
2208           ipr=1;
2209         }
2210         else if(!strncmp(knamed,"QTD",3)) fpLostTDI += 1;
2211         else if(!strncmp(knamed,"QLU",3)){
2212           if(s[2]<0) fnLumiC ++;
2213           else fnLumiA++;
2214           ipr=1;
2215         }
2216       }
2217       //
2218       //gMC->TrackMomentum(p[0], p[1], p[2], p[3]);
2219       //printf("\t Particle: mass = %1.3f, E = %1.3f GeV, pz = %1.2f GeV -> stopped in volume %s\n", 
2220       //     gMC->TrackMass(), p[3], p[2], gMC->CurrentVolName());
2221       //
2222       if(ipr!=0){
2223         printf("\n\t **********************************\n");
2224         printf("\t ********** Side C **********\n");
2225         printf("\t # of spectators in IT = %d\n",fpLostITC);
2226         printf("\t # of spectators in D1 = %d\n",fpLostD1C);
2227         printf("\t # of spectators in luminometer = %d\n",fnLumiC);
2228         printf("\t ********** Side A **********\n");
2229         printf("\t # of spectators in IT = %d\n",fpLostITA);
2230         printf("\t # of spectators in D1 = %d\n",fpLostD1A);
2231         printf("\t # of spectators in TDI = %d\n",fpLostTDI);
2232         printf("\t # of spectators in luminometer = %d\n",fnLumiA);
2233         printf("\t # of spectators in trousers = %d\n",fnTrou);
2234         printf("\t **********************************\n");
2235       }
2236       gMC->StopTrack();
2237     }
2238     return;
2239   }
2240   
2241
2242   if((gMC->CurrentMedium() == fMedSensZN) || (gMC->CurrentMedium() == fMedSensZP) ||
2243      (gMC->CurrentMedium() == fMedSensGR) || (gMC->CurrentMedium() == fMedSensF1) ||
2244      (gMC->CurrentMedium() == fMedSensF2) || (gMC->CurrentMedium() == fMedSensZEM)){
2245
2246     
2247   //Particle coordinates 
2248     gMC->TrackPosition(s[0],s[1],s[2]);
2249     for(j=0; j<=2; j++) x[j] = s[j];
2250     hits[0] = x[0];
2251     hits[1] = x[1];
2252     hits[2] = x[2];
2253
2254   // Determine in which ZDC the particle is
2255     knamed = gMC->CurrentVolName();
2256     if(!strncmp(knamed,"ZN",2)){
2257           if(x[2]<0.) vol[0]=1; // ZNC (dimuon side)
2258           else if(x[2]>0.) vol[0]=4; //ZNA
2259     }
2260     else if(!strncmp(knamed,"ZP",2)){ 
2261           if(x[2]<0.) vol[0]=2; //ZPC (dimuon side)
2262           else if(x[2]>0.) vol[0]=5; //ZPA  
2263     }
2264     else if(!strncmp(knamed,"ZE",2)) vol[0]=3; //ZEM
2265   
2266   // Determine in which quadrant the particle is
2267     if(vol[0]==1){      //Quadrant in ZNC
2268       // Calculating particle coordinates inside ZNC
2269       xdet[0] = x[0]-fPosZNC[0];
2270       xdet[1] = x[1]-fPosZNC[1];
2271       // Calculating quadrant in ZN
2272       if(xdet[0]<=0.){
2273         if(xdet[1]<=0.) vol[1]=1;
2274         else vol[1]=3;
2275       }
2276       else if(xdet[0]>0.){
2277         if(xdet[1]<=0.) vol[1]=2;
2278         else vol[1]=4;
2279       }
2280       if((vol[1]!=1) && (vol[1]!=2) && (vol[1]!=3) && (vol[1]!=4))
2281         printf("\n      ZDC StepManager->ERROR in ZN!!! vol[1] = %d, xdet[0] = %f,"
2282         "xdet[1] = %f\n",vol[1], xdet[0], xdet[1]);
2283     }
2284     
2285     else if(vol[0]==2){ //Quadrant in ZPC
2286       // Calculating particle coordinates inside ZPC
2287       xdet[0] = x[0]-fPosZPC[0];
2288       xdet[1] = x[1]-fPosZPC[1];
2289       if(xdet[0]>=fDimZP[0])  xdet[0]=fDimZP[0]-0.01;
2290       if(xdet[0]<=-fDimZP[0]) xdet[0]=-fDimZP[0]+0.01;
2291       // Calculating tower in ZP
2292       Float_t xqZP = xdet[0]/(fDimZP[0]/2.);
2293       for(int i=1; i<=4; i++){
2294          if(xqZP>=(i-3) && xqZP<(i-2)){
2295            vol[1] = i;
2296            break;
2297          }
2298       }
2299       if((vol[1]!=1) && (vol[1]!=2) && (vol[1]!=3) && (vol[1]!=4))
2300         printf("        ZDC StepManager->ERROR in ZP!!! vol[1] = %d, xdet[0] = %f,"
2301         "xdet[1] = %f\n",vol[1], xdet[0], xdet[1]);
2302     }
2303     //
2304     // Quadrant in ZEM: vol[1] = 1 -> particle in 1st ZEM (placed at x = 8.5 cm)
2305     //                  vol[1] = 2 -> particle in 2nd ZEM (placed at x = -8.5 cm)
2306     else if(vol[0] == 3){       
2307       if(x[0]>0.){
2308         vol[1] = 1;
2309         // Particle x-coordinate inside ZEM1
2310         xdet[0] = x[0]-fPosZEM[0];
2311       }
2312       else{
2313         vol[1] = 2;
2314         // Particle x-coordinate inside ZEM2
2315         xdet[0] = x[0]+fPosZEM[0];
2316       }
2317       xdet[1] = x[1]-fPosZEM[1];
2318     }
2319     //
2320     else if(vol[0]==4){ //Quadrant in ZNA
2321       // Calculating particle coordinates inside ZNA
2322       xdet[0] = x[0]-fPosZNA[0];
2323       xdet[1] = x[1]-fPosZNA[1];
2324       // Calculating quadrant in ZNA
2325       if(xdet[0]>=0.){
2326         if(xdet[1]<=0.) vol[1]=1;
2327         else vol[1]=3;
2328       }
2329       else if(xdet[0]<0.){
2330         if(xdet[1]<=0.) vol[1]=2;
2331         else vol[1]=4;
2332       }
2333       if((vol[1]!=1) && (vol[1]!=2) && (vol[1]!=3) && (vol[1]!=4))
2334         printf("\n      ZDC StepManager->ERROR in ZNA!!! vol[1] = %d, xdet[0] = %f,"
2335         "xdet[1] = %f\n",vol[1], xdet[0], xdet[1]);
2336     }    
2337     //
2338     else if(vol[0]==5){ //Quadrant in ZPA
2339       // Calculating particle coordinates inside ZPA
2340       xdet[0] = x[0]-fPosZPA[0];
2341       xdet[1] = x[1]-fPosZPA[1];
2342       if(xdet[0]>=fDimZP[0])  xdet[0]=fDimZP[0]-0.01;
2343       if(xdet[0]<=-fDimZP[0]) xdet[0]=-fDimZP[0]+0.01;
2344       // Calculating tower in ZP
2345       Float_t xqZP = -xdet[0]/(fDimZP[0]/2.);
2346       for(int i=1; i<=4; i++){
2347          if(xqZP>=(i-3) && xqZP<(i-2)){
2348            vol[1] = i;
2349            break;
2350          }
2351       }
2352       if((vol[1]!=1) && (vol[1]!=2) && (vol[1]!=3) && (vol[1]!=4))
2353         printf("        ZDC StepManager->ERROR in ZPA!!! vol[1] = %d, xdet[0] = %f,"
2354         "xdet[1] = %f\n",vol[1], xdet[0], xdet[1]);
2355     }    
2356     
2357     
2358   // Store impact point and kinetic energy of the ENTERING particle
2359     
2360       if(gMC->IsTrackEntering()){
2361         //Particle energy
2362         gMC->TrackMomentum(p[0],p[1],p[2],p[3]);
2363         hits[3] = p[3];
2364         // Impact point on ZDC  
2365         hits[4] = xdet[0];
2366         hits[5] = xdet[1];
2367         hits[6] = 0;
2368         hits[7] = 0;
2369         hits[8] = 0;
2370         hits[9] = 0;
2371         //
2372         Int_t curTrackN = gAlice->GetMCApp()->GetCurrentTrackNumber();
2373         TParticle *part = (gAlice->GetMCApp())->Particle(curTrackN);
2374         hits[10] = part->GetPdgCode();
2375         //printf("\t PDGCode = %d\n", part->GetPdgCode());
2376
2377         AddHit(curTrackN, vol, hits);
2378         
2379         if(fNoShower==1){
2380           //printf("\t VolName %s -> det %d quad %d - x = %f, y = %f, z = %f\n", 
2381             //knamed, vol[0], vol[1], x[0], x[1], x[2]);
2382           if(vol[0]==1){
2383             fnDetectedC += 1;
2384             printf("\n    # of particles in ZNC = %d\n\n",fnDetectedC);
2385           }
2386           else if(vol[0]==2){
2387             fpDetectedC += 1;
2388             printf("\n    # of particles in ZPC = %d\n\n",fpDetectedC);
2389           }
2390           else if(vol[0]==4){
2391             fnDetectedA += 1;
2392             printf("\n    # of particles in ZNA = %d\n\n",fnDetectedA);     
2393           }
2394           else if(vol[0]==5){
2395             fpDetectedA += 1;
2396             printf("\n    # of particles in ZPA = %d\n\n",fpDetectedA);      
2397           }
2398           //
2399           //printf("\t Particle: mass = %1.3f, E = %1.3f GeV, pz = %1.2f GeV -> stopped in volume %s\n", 
2400           //   gMC->TrackMass(), p[3], p[2], gMC->CurrentVolName());
2401           //
2402           gMC->StopTrack();
2403           return;
2404         }
2405       }
2406              
2407       // Charged particles -> Energy loss
2408       if((destep=gMC->Edep())){
2409          if(gMC->IsTrackStop()){
2410            gMC->TrackMomentum(p[0],p[1],p[2],p[3]);
2411            m = gMC->TrackMass();
2412            ekin = p[3]-m;
2413            hits[9] = ekin;
2414            hits[7] = 0.;
2415            hits[8] = 0.;
2416            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
2417            }
2418          else{
2419            hits[9] = destep;
2420            hits[7] = 0.;
2421            hits[8] = 0.;
2422            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
2423            }
2424       }
2425   }
2426  
2427
2428   // *** Light production in fibres 
2429   if((gMC->CurrentMedium() == fMedSensF1) || (gMC->CurrentMedium() == fMedSensF2)){
2430
2431      //Select charged particles
2432      if((destep=gMC->Edep())){
2433
2434        // Particle velocity
2435        Float_t beta = 0.;
2436        gMC->TrackMomentum(p[0],p[1],p[2],p[3]);
2437        Float_t ptot=TMath::Sqrt(p[0]*p[0]+p[1]*p[1]+p[2]*p[2]);
2438        if(p[3] > 0.00001) beta =  ptot/p[3];
2439        else return;
2440        if(beta<0.67)return;
2441        else if((beta>=0.67) && (beta<=0.75)) ibeta = 0;
2442        else if((beta>0.75)  && (beta<=0.85)) ibeta = 1;
2443        else if((beta>0.85)  && (beta<=0.95)) ibeta = 2;
2444        else if(beta>0.95) ibeta = 3;
2445  
2446        // Angle between particle trajectory and fibre axis
2447        // 1 -> Momentum directions
2448        um[0] = p[0]/ptot;
2449        um[1] = p[1]/ptot;
2450        um[2] = p[2]/ptot;
2451        gMC->Gmtod(um,ud,2);
2452        // 2 -> Angle < limit angle
2453        Double_t alfar = TMath::ACos(ud[2]);
2454        Double_t alfa = alfar*kRaddeg;
2455        if(alfa>=110.) return;
2456        //
2457        ialfa = Int_t(1.+alfa/2.);
2458  
2459        // Distance between particle trajectory and fibre axis
2460        gMC->TrackPosition(s[0],s[1],s[2]);
2461        for(j=0; j<=2; j++){
2462           x[j] = s[j];
2463        }
2464        gMC->Gmtod(x,xdet,1);
2465        if(TMath::Abs(ud[0])>0.00001){
2466          Float_t dcoeff = ud[1]/ud[0];
2467          be = TMath::Abs((xdet[1]-dcoeff*xdet[0])/TMath::Sqrt(dcoeff*dcoeff+1.));
2468        }
2469        else{
2470          be = TMath::Abs(ud[0]);
2471        }
2472  
2473        ibe = Int_t(be*1000.+1);
2474        //if((vol[0]==1))      radius = fFibZN[1];
2475        //else if((vol[0]==2)) radius = fFibZP[1];
2476  
2477        //Looking into the light tables 
2478        Float_t charge = gMC->TrackCharge();
2479        
2480        if(vol[0]==1 || vol[0]==4) {     // (1)  ZN fibres
2481          if(ibe>fNben) ibe=fNben;
2482          out =  charge*charge*fTablen[ibeta][ialfa][ibe];
2483          nphe = gRandom->Poisson(out);
2484          // Ch. debug
2485          //if(ibeta==3) printf("\t %f \t %f \t %f\n",alfa, be, out);
2486          //printf("\t ibeta = %d, ialfa = %d, ibe = %d -> nphe = %d\n\n",ibeta,ialfa,ibe,nphe);
2487          if(gMC->CurrentMedium() == fMedSensF1){
2488            hits[7] = nphe;      //fLightPMQ
2489            hits[8] = 0;
2490            hits[9] = 0;
2491            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
2492          }
2493          else{
2494            hits[7] = 0;
2495            hits[8] = nphe;      //fLightPMC
2496            hits[9] = 0;
2497            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
2498          }
2499        } 
2500        else if(vol[0]==2 || vol[0]==5) {// (2) ZP fibres
2501          if(ibe>fNbep) ibe=fNbep;
2502          out =  charge*charge*fTablep[ibeta][ialfa][ibe];
2503          nphe = gRandom->Poisson(out);
2504          if(gMC->CurrentMedium() == fMedSensF1){
2505            hits[7] = nphe;      //fLightPMQ
2506            hits[8] = 0;
2507            hits[9] = 0;
2508            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
2509          }
2510          else{
2511            hits[7] = 0;
2512            hits[8] = nphe;      //fLightPMC
2513            hits[9] = 0;
2514            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
2515          }
2516        } 
2517        else if((vol[0]==3)) {   // (3) ZEM fibres
2518          if(ibe>fNbep) ibe=fNbep;
2519          out =  charge*charge*fTablep[ibeta][ialfa][ibe];
2520          gMC->TrackPosition(s[0],s[1],s[2]);
2521          Float_t xalic[3];
2522          for(j=0; j<3; j++){
2523             xalic[j] = s[j];
2524          }
2525          // z-coordinate from ZEM front face 
2526          // NB-> fPosZEM[2]+fZEMLength = -1000.+2*10.3 = 979.69 cm
2527          Float_t z = -xalic[2]+fPosZEM[2]+2*fZEMLength-xalic[1];
2528          //z = xalic[2]-fPosZEM[2]-fZEMLength-xalic[1]*(TMath::Tan(45.*kDegrad));
2529          //printf("\n   fPosZEM[2]+2*fZEMLength = %f", fPosZEM[2]+2*fZEMLength);
2530          Float_t guiEff = guiPar[0]*(guiPar[1]*z*z+guiPar[2]*z+guiPar[3]);
2531          out = out*guiEff;
2532          nphe = gRandom->Poisson(out);
2533          //printf("     out*guiEff = %f nphe = %d", out, nphe);
2534          if(vol[1] == 1){
2535            hits[7] = 0;         
2536            hits[8] = nphe;      //fLightPMC (ZEM1)
2537            hits[9] = 0;
2538            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
2539          }
2540          else{
2541            hits[7] = nphe;      //fLightPMQ (ZEM2)
2542            hits[8] = 0;         
2543            hits[9] = 0;
2544            AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits);
2545          }
2546        }
2547      }
2548    }
2549 }