Coverity fix
[u/mrichter/AliRoot.git] / TRD / TRDbase / AliTRDgeometry.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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  TRD geometry class                                                       //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TGeoManager.h>
25 #include <TGeoPhysicalNode.h>
26 #include <TVirtualMC.h>
27 #include <TMath.h>
28
29 #include "AliLog.h"
30 #include "AliAlignObjParams.h"
31
32 #include "AliTRDgeometry.h"
33 #include "AliTRDpadPlane.h"
34
35 ClassImp(AliTRDgeometry)
36
37 //_____________________________________________________________________________
38
39   //
40   // The geometry constants
41   //
42   const Int_t    AliTRDgeometry::fgkNsector   = kNsector;
43   const Int_t    AliTRDgeometry::fgkNlayer    = kNlayer;
44   const Int_t    AliTRDgeometry::fgkNstack    = kNstack;
45   const Int_t    AliTRDgeometry::fgkNdet      = kNdet;
46
47   //
48   // Dimensions of the detector
49   //
50
51   // Total length of the TRD mother volume
52   const Float_t  AliTRDgeometry::fgkTlength   = 751.0;
53
54   // Parameter of the super module mother volumes 
55   const Float_t  AliTRDgeometry::fgkSheight   =  77.9; 
56   const Float_t  AliTRDgeometry::fgkSwidth1   =  94.881; 
57   const Float_t  AliTRDgeometry::fgkSwidth2   = 122.353;
58   const Float_t  AliTRDgeometry::fgkSlength   = 702.0;
59
60   // Length of the additional space in front of the supermodule
61   // used for services
62   const Float_t  AliTRDgeometry::fgkFlength   = (AliTRDgeometry::fgkTlength
63                                                - AliTRDgeometry::fgkSlength) / 2.0;
64
65   // The super module side plates
66   const Float_t  AliTRDgeometry::fgkSMpltT    =   0.2;
67
68   // Vertical spacing of the chambers
69   const Float_t  AliTRDgeometry::fgkVspace    =   1.784;
70   // Horizontal spacing of the chambers
71   const Float_t  AliTRDgeometry::fgkHspace    =   2.0;
72   // Radial distance of the first ROC to the outer plates of the SM
73   const Float_t  AliTRDgeometry::fgkVrocsm    =   1.2;
74
75   // Height of different chamber parts
76   // Radiator
77   const Float_t  AliTRDgeometry::fgkCraH      =   4.8; 
78   // Drift region
79   const Float_t  AliTRDgeometry::fgkCdrH      =   3.0;
80   // Amplification region
81   const Float_t  AliTRDgeometry::fgkCamH      =   0.7;
82   // Readout
83   const Float_t  AliTRDgeometry::fgkCroH      =   2.316;
84   // Additional width of the readout chamber frames
85   const Float_t  AliTRDgeometry::fgkCroW      =   0.9;
86   // Services on top of ROC
87   const Float_t  AliTRDgeometry::fgkCsvH      = AliTRDgeometry::fgkVspace 
88                                               -   0.742;
89   // Total height (w/o services)
90   const Float_t  AliTRDgeometry::fgkCH        = AliTRDgeometry::fgkCraH
91                                               + AliTRDgeometry::fgkCdrH
92                                               + AliTRDgeometry::fgkCamH
93                                               + AliTRDgeometry::fgkCroH;  
94   // Total height (with services)
95
96   const Float_t  AliTRDgeometry::fgkCHsv      = AliTRDgeometry::fgkCH 
97                                               + AliTRDgeometry::fgkCsvH;
98
99   // Distance of anode wire plane relative to middle of alignable volume
100   const Float_t  AliTRDgeometry::fgkAnodePos  = AliTRDgeometry::fgkCraH 
101                                               + AliTRDgeometry::fgkCdrH 
102                                               + AliTRDgeometry::fgkCamH/2.0
103                                               - AliTRDgeometry::fgkCHsv/2.0;
104
105   // Thicknesses of different parts of the chamber frame
106   // Lower aluminum frame
107   const Float_t  AliTRDgeometry::fgkCalT      =   0.4;
108   // Lower Wacosit frame sides
109   const Float_t  AliTRDgeometry::fgkCclsT     =   0.21;
110   // Lower Wacosit frame front
111   const Float_t  AliTRDgeometry::fgkCclfT     =   1.0;
112   // Thickness of glue around radiator
113   const Float_t  AliTRDgeometry::fgkCglT      =   0.25;
114   // Upper Wacosit frame around amplification region
115   const Float_t  AliTRDgeometry::fgkCcuTa     =   1.0;
116   const Float_t  AliTRDgeometry::fgkCcuTb     =   0.8;
117   // Al frame of back panel
118   const Float_t  AliTRDgeometry::fgkCauT      =   1.5;
119   // Additional Al ledge at the lower chamber frame
120   // Actually the dimensions are not realistic, but 
121   // modified in order to allow to mis-alignment. 
122   // The amount of material is, however, correct 
123   const Float_t  AliTRDgeometry::fgkCalW      =   2.5;
124   const Float_t  AliTRDgeometry::fgkCalH      =   0.4;
125   const Float_t  AliTRDgeometry::fgkCalWmod   =   0.4;
126   const Float_t  AliTRDgeometry::fgkCalHmod   =   2.5;
127   // Additional Wacosit ledge at the lower chamber frame
128   const Float_t  AliTRDgeometry::fgkCwsW      =   1.2;
129   const Float_t  AliTRDgeometry::fgkCwsH      =   0.3;
130
131   // Difference of outer chamber width and pad plane width
132   const Float_t  AliTRDgeometry::fgkCpadW     =   0.0;
133   const Float_t  AliTRDgeometry::fgkRpadW     =   1.0;
134
135   //
136   // Thickness of the the material layers
137   //
138   const Float_t  AliTRDgeometry::fgkDrThick   = AliTRDgeometry::fgkCdrH;    
139   const Float_t  AliTRDgeometry::fgkAmThick   = AliTRDgeometry::fgkCamH;
140   const Float_t  AliTRDgeometry::fgkXeThick   = AliTRDgeometry::fgkDrThick
141                                               + AliTRDgeometry::fgkAmThick;
142   const Float_t  AliTRDgeometry::fgkWrThick   = 0.00011;
143
144   const Float_t  AliTRDgeometry::fgkRMyThick  = 0.0015;
145   const Float_t  AliTRDgeometry::fgkRCbThick  = 0.0055;
146   const Float_t  AliTRDgeometry::fgkRGlThick  = 0.0065;
147   const Float_t  AliTRDgeometry::fgkRRhThick  = 0.8;
148   const Float_t  AliTRDgeometry::fgkRFbThick  = fgkCraH - 2.0 * (fgkRMyThick 
149                                                                + fgkRCbThick 
150                                                                + fgkRRhThick);
151
152   const Float_t  AliTRDgeometry::fgkPPdThick  = 0.0025; 
153   const Float_t  AliTRDgeometry::fgkPPpThick  = 0.0356; 
154   const Float_t  AliTRDgeometry::fgkPGlThick  = 0.1428;
155   const Float_t  AliTRDgeometry::fgkPCbThick  = 0.019;
156   const Float_t  AliTRDgeometry::fgkPPcThick  = 0.0486;
157   const Float_t  AliTRDgeometry::fgkPRbThick  = 0.0057;
158   const Float_t  AliTRDgeometry::fgkPElThick  = 0.0029;
159   const Float_t  AliTRDgeometry::fgkPHcThick  = fgkCroH - fgkPPdThick 
160                                                         - fgkPPpThick
161                                                         - fgkPGlThick 
162                                                         - fgkPCbThick * 2.0
163                                                         - fgkPPcThick
164                                                         - fgkPRbThick
165                                                         - fgkPElThick;
166
167   //
168   // Position of the material layers
169   //
170   const Float_t  AliTRDgeometry::fgkDrZpos    =  2.4;
171   const Float_t  AliTRDgeometry::fgkAmZpos    =  0.0;
172   const Float_t  AliTRDgeometry::fgkWrZposA   =  0.0;
173   const Float_t  AliTRDgeometry::fgkWrZposB   = -fgkAmThick/2.0 + 0.001;
174   const Float_t  AliTRDgeometry::fgkCalZpos   =  0.3;
175
176   const Int_t    AliTRDgeometry::fgkMCMmax    = 16;   
177   const Int_t    AliTRDgeometry::fgkMCMrow    = 4;   
178   const Int_t    AliTRDgeometry::fgkROBmaxC0  = 6; 
179   const Int_t    AliTRDgeometry::fgkROBmaxC1  = 8; 
180   const Int_t    AliTRDgeometry::fgkADCmax    = 21;   
181   const Int_t    AliTRDgeometry::fgkTBmax     = 60;   
182   const Int_t    AliTRDgeometry::fgkPadmax    = 18;   
183   const Int_t    AliTRDgeometry::fgkColmax    = 144;
184   const Int_t    AliTRDgeometry::fgkRowmaxC0  = 12;
185   const Int_t    AliTRDgeometry::fgkRowmaxC1  = 16;
186
187   const Double_t AliTRDgeometry::fgkTime0Base = 300.65;
188   const Float_t  AliTRDgeometry::fgkTime0[6]  = { static_cast<Float_t>(fgkTime0Base + 0 * (Cheight() + Cspace())) 
189                                                 , static_cast<Float_t>(fgkTime0Base + 1 * (Cheight() + Cspace())) 
190                                                 , static_cast<Float_t>(fgkTime0Base + 2 * (Cheight() + Cspace())) 
191                                                 , static_cast<Float_t>(fgkTime0Base + 3 * (Cheight() + Cspace())) 
192                                                 , static_cast<Float_t>(fgkTime0Base + 4 * (Cheight() + Cspace())) 
193                                                 , static_cast<Float_t>(fgkTime0Base + 5 * (Cheight() + Cspace()))};
194
195   const Double_t AliTRDgeometry::fgkXtrdBeg   = 288.43; // Values depend on position of TRD
196   const Double_t AliTRDgeometry::fgkXtrdEnd   = 366.33; // mother volume inside space frame !!!
197
198   // The outer width of the chambers
199   const Float_t AliTRDgeometry::fgkCwidth[kNlayer] = {  90.4,  94.8,  99.3, 103.7, 108.1, 112.6 };
200   
201   // The outer lengths of the chambers
202   // Includes the spacings between the chambers!
203   const Float_t AliTRDgeometry::fgkClength[kNlayer][kNstack] = { { 124.0, 124.0, 110.0, 124.0, 124.0 }
204                                                                , { 124.0, 124.0, 110.0, 124.0, 124.0 }
205                                                                , { 131.0, 131.0, 110.0, 131.0, 131.0 }
206                                                                , { 138.0, 138.0, 110.0, 138.0, 138.0 }
207                                                                , { 145.0, 145.0, 110.0, 145.0, 145.0 }
208                                                                , { 147.0, 147.0, 110.0, 147.0, 147.0 } };
209
210         Char_t  AliTRDgeometry::fgSMstatus[kNsector]         = { 1, 1, 1, 1, 1, 1, 1, 1, 1
211                                                                , 1, 1, 1, 1, 1, 1, 1, 1, 1 };
212
213   TObjArray* AliTRDgeometry::fgClusterMatrixArray = NULL;
214
215   TObjArray* AliTRDgeometry::fgPadPlaneArray = NULL;
216
217 //_____________________________________________________________________________
218 AliTRDgeometry::AliTRDgeometry()
219 {
220   //
221   // AliTRDgeometry default constructor
222   //
223
224 }
225
226 //_____________________________________________________________________________
227 AliTRDgeometry::~AliTRDgeometry()
228 {
229   //
230   // AliTRDgeometry destructor
231   //
232
233 }
234
235 //_____________________________________________________________________________
236 void AliTRDgeometry::CreatePadPlaneArray()
237 {
238   //
239   // Creates the array of AliTRDpadPlane objects
240   //
241
242   if (fgPadPlaneArray)
243     return;
244
245   static TObjArray padPlaneArray(fgkNlayer * fgkNstack);
246   padPlaneArray.SetOwner(kTRUE);
247
248   fgPadPlaneArray = &padPlaneArray;
249   for (Int_t ilayer = 0; ilayer < fgkNlayer; ilayer++) {
250     for (Int_t istack = 0; istack < fgkNstack; istack++) {
251       Int_t ipp = GetDetectorSec(ilayer,istack);
252       fgPadPlaneArray->AddAt(CreatePadPlane(ilayer,istack),ipp);
253     }
254   }
255
256 }
257
258 //_____________________________________________________________________________
259 AliTRDpadPlane *AliTRDgeometry::CreatePadPlane(Int_t ilayer, Int_t istack)
260 {
261   //
262   // Creates an AliTRDpadPlane object
263   //
264
265   AliTRDpadPlane *padPlane = new AliTRDpadPlane();
266
267   padPlane->SetLayer(ilayer);
268   padPlane->SetStack(istack);
269
270   padPlane->SetRowSpacing(0.0);
271   padPlane->SetColSpacing(0.0);
272
273   padPlane->SetLengthRim(1.0);
274   padPlane->SetWidthRim(0.5);
275
276   padPlane->SetNcols(144);
277
278   padPlane->SetAnodeWireOffset(0.25);
279
280   //
281   // The pad plane parameter
282   //
283   const Float_t kTiltAngle = 2.0;
284   switch (ilayer) {
285   case 0:
286     if (istack == 2) {
287       // L0C0 type
288       padPlane->SetNrows(12);
289       padPlane->SetLength(108.0);
290       padPlane->SetLengthOPad(8.0);
291       padPlane->SetLengthIPad(9.0);
292     }
293     else {
294       // L0C1 type
295       padPlane->SetNrows(16);
296       padPlane->SetLength(122.0);
297       padPlane->SetLengthOPad(7.5);
298       padPlane->SetLengthIPad(7.5);
299     }
300     padPlane->SetWidth(92.2);
301     padPlane->SetWidthOPad(0.515);
302     padPlane->SetWidthIPad(0.635);
303     padPlane->SetTiltingAngle(-kTiltAngle);
304     break;
305   case 1:
306     if (istack == 2) {
307       // L1C0 type
308       padPlane->SetNrows(12);
309       padPlane->SetLength(108.0);
310       padPlane->SetLengthOPad(8.0);
311       padPlane->SetLengthIPad(9.0);
312     }
313     else {
314       // L1C1 type
315       padPlane->SetNrows(16);
316       padPlane->SetLength(122.0);
317       padPlane->SetLengthOPad(7.5);
318       padPlane->SetLengthIPad(7.5);
319     }
320     padPlane->SetWidth(96.6);
321     padPlane->SetWidthOPad(0.585);
322     padPlane->SetWidthIPad(0.665);
323     padPlane->SetTiltingAngle(kTiltAngle);
324     break;
325   case 2:
326     if (istack == 2) {
327       // L2C0 type
328       padPlane->SetNrows(12);
329       padPlane->SetLength(108.0);
330       padPlane->SetLengthOPad(8.0);
331       padPlane->SetLengthIPad(9.0);
332     }
333     else {
334       // L2C1 type
335       padPlane->SetNrows(16);
336       padPlane->SetLength(129.0);
337       padPlane->SetLengthOPad(7.5);
338       padPlane->SetLengthIPad(8.0);
339     }
340     padPlane->SetWidth(101.1);
341     padPlane->SetWidthOPad(0.705);
342     padPlane->SetWidthIPad(0.695);
343     padPlane->SetTiltingAngle(-kTiltAngle);
344     break;
345   case 3:
346     if (istack == 2) {
347       // L3C0 type
348       padPlane->SetNrows(12);
349       padPlane->SetLength(108.0);
350       padPlane->SetLengthOPad(8.0);
351       padPlane->SetLengthIPad(9.0);
352     }
353     else {
354       // L3C1 type
355       padPlane->SetNrows(16);
356       padPlane->SetLength(136.0);
357       padPlane->SetLengthOPad(7.5);
358       padPlane->SetLengthIPad(8.5);
359     }
360     padPlane->SetWidth(105.5);
361     padPlane->SetWidthOPad(0.775);
362     padPlane->SetWidthIPad(0.725);
363     padPlane->SetTiltingAngle(kTiltAngle);
364     break;
365   case 4:
366     if (istack == 2) {
367       // L4C0 type
368       padPlane->SetNrows(12);
369       padPlane->SetLength(108.0);
370       padPlane->SetLengthOPad(8.0);
371     }
372     else {
373       // L4C1 type
374       padPlane->SetNrows(16);
375       padPlane->SetLength(143.0);
376       padPlane->SetLengthOPad(7.5);
377     }
378     padPlane->SetWidth(109.9);
379     padPlane->SetWidthOPad(0.845);
380     padPlane->SetLengthIPad(9.0);
381     padPlane->SetWidthIPad(0.755);
382     padPlane->SetTiltingAngle(-kTiltAngle);
383     break;
384   case 5:
385     if (istack == 2) {
386       // L5C0 type
387       padPlane->SetNrows(12);
388       padPlane->SetLength(108.0);
389       padPlane->SetLengthOPad(8.0);
390     }
391     else {
392       // L5C1 type
393       padPlane->SetNrows(16);
394       padPlane->SetLength(145.0);
395       padPlane->SetLengthOPad(8.5);
396     }
397     padPlane->SetWidth(114.4);
398     padPlane->SetWidthOPad(0.965);
399     padPlane->SetLengthIPad(9.0);
400     padPlane->SetWidthIPad(0.785);
401     padPlane->SetTiltingAngle(kTiltAngle);
402     break;
403   };
404
405   //
406   // The positions of the borders of the pads
407   //
408   // Row direction
409   //
410   Double_t row = fgkClength[ilayer][istack] / 2.0
411                - fgkRpadW
412                - padPlane->GetLengthRim();
413   for (Int_t ir = 0; ir < padPlane->GetNrows(); ir++) {
414     padPlane->SetPadRow(ir,row);
415     row -= padPlane->GetRowSpacing();
416     if (ir == 0) {
417       row -= padPlane->GetLengthOPad();
418     }
419     else {
420       row -= padPlane->GetLengthIPad();
421     }
422   }
423   //
424   // Column direction
425   //
426   Double_t col = - fgkCwidth[ilayer] / 2.0
427                  - fgkCroW
428                  + padPlane->GetWidthRim();
429   for (Int_t ic = 0; ic < padPlane->GetNcols(); ic++) {
430     padPlane->SetPadCol(ic,col);
431     col += padPlane->GetColSpacing();
432     if (ic == 0) {
433       col += padPlane->GetWidthOPad();
434     }
435     else {
436       col += padPlane->GetWidthIPad();
437     }
438   }
439   // Calculate the offset to translate from the local ROC system into
440   // the local supermodule system, which is used for clusters
441   Double_t rowTmp = fgkClength[ilayer][0]
442                   + fgkClength[ilayer][1]
443                   + fgkClength[ilayer][2] / 2.0;
444   for (Int_t jstack = 0; jstack < istack; jstack++) {
445     rowTmp -= fgkClength[ilayer][jstack];
446   }
447   padPlane->SetPadRowSMOffset(rowTmp - fgkClength[ilayer][istack]/2.0);
448
449   return padPlane;
450
451 }
452
453 //_____________________________________________________________________________
454 void AliTRDgeometry::CreateGeometry(Int_t *idtmed)
455 {
456   //
457   // Create the TRD geometry
458   //
459   //
460   // Names of the TRD volumina (xx = detector number):
461   //
462   //   Volume (Air) wrapping the readout chamber components
463   //     UTxx    includes: UAxx, UDxx, UFxx, UUxx
464   //
465   //   Lower part of the readout chambers (drift volume + radiator)
466   //     UAxx    Aluminum frames                (Al)
467   //
468   //   Upper part of the readout chambers (readout plane + fee)
469   //     UDxx    Wacosit frames of amp. region  (Wacosit)
470   //     UFxx    Aluminum frame of back panel   (Al)
471   //
472   //   Services on chambers (cooling, cables, MCMs, DCS boards, ...)
473   //     UUxx    Volume containing the services (Air) 
474   //
475   //   Material layers inside sensitive area:
476   //     Name    Description                     Mat.      Thick.   Dens.    Radl.    X/X_0
477   //                                                        
478   //     URMYxx  Mylar layers (x2)               Mylar     0.0015   1.39     28.5464  0.005%
479   //     URCBxx  Carbon layer (x2)               Carbon    0.0055   1.75     24.2824  0.023%
480   //     URGLxx  Glue on the carbon layers (x2)  Araldite  0.0065   1.12     37.0664  0.018%
481   //     URRHxx  Rohacell layer (x2)             Rohacell  0.8      0.075    536.005  0.149%
482   //     URFBxx  Fiber mat layer                 PP        3.186    0.068    649.727  0.490%
483   //     
484   //     UJxx    Drift region                    Xe/CO2    3.0      0.00495  1792.37  0.167%
485   //     UKxx    Amplification region            Xe/CO2    0.7      0.00495  1792.37  0.039%
486   //     UWxx    Wire planes (x2)                Copper    0.00011  8.96     1.43503  0.008%
487   //
488   //     UPPDxx  Copper of pad plane             Copper    0.0025   8.96     1.43503  0.174%
489   //     UPPPxx  PCB of pad plane                G10       0.0356   2.0      14.9013  0.239%
490   //     UPGLxx  Glue on pad planes              Araldite  0.0923   1.12     37.0664  0.249%
491   //             + add. glue (ca. 600g)          Araldite  0.0505   1.12     37.0663  0.107%
492   //     UPCBxx  Carbon fiber mats (x2)          Carbon    0.019    1.75     24.2824  0.078%
493   //     UPHCxx  Honeycomb structure             Aramide   2.0299   0.032    1198.84  0.169%
494   //     UPPCxx  PCB of readout board            G10       0.0486   2.0      14.9013  0.326%
495   //     UPRDxx  Copper of readout board         Copper    0.0057   8.96     1.43503  0.404%
496   //     UPELxx  Electronics + cables            Copper    0.0029   8.96     1.43503  0.202%
497   //
498
499   const Int_t kNparTrd = 4;
500   const Int_t kNparCha = 3;
501
502   Float_t xpos;
503   Float_t ypos;
504   Float_t zpos;
505
506   Float_t parTrd[kNparTrd];
507   Float_t parCha[kNparCha];
508
509   const Int_t kTag = 100;
510   Char_t  cTagV[kTag];
511   Char_t  cTagM[kTag];
512
513   // There are three TRD volumes for the supermodules in order to accomodate
514   // the different arrangements in front of PHOS
515   // UTR1: Default supermodule
516   // UTR2: Supermodule in front of PHOS with double carbon cover
517   // UTR3: As UTR2, but w/o middle stack
518   // UTR4: Sector 17 with missing chamber L4S4
519   //
520   // The mother volume for one sector (Air), full length in z-direction
521   // Provides material for side plates of super module
522   parTrd[0] = fgkSwidth1/2.0;
523   parTrd[1] = fgkSwidth2/2.0;
524   parTrd[2] = fgkSlength/2.0;
525   parTrd[3] = fgkSheight/2.0;
526   TVirtualMC::GetMC()->Gsvolu("UTR1","TRD1",idtmed[1302-1],parTrd,kNparTrd);
527   TVirtualMC::GetMC()->Gsvolu("UTR2","TRD1",idtmed[1302-1],parTrd,kNparTrd);
528   TVirtualMC::GetMC()->Gsvolu("UTR3","TRD1",idtmed[1302-1],parTrd,kNparTrd);
529   TVirtualMC::GetMC()->Gsvolu("UTR4","TRD1",idtmed[1302-1],parTrd,kNparTrd);
530   // The outer aluminum plates of the super module (Al)
531   parTrd[0] = fgkSwidth1/2.0;
532   parTrd[1] = fgkSwidth2/2.0;
533   parTrd[2] = fgkSlength/2.0;
534   parTrd[3] = fgkSheight/2.0;
535   TVirtualMC::GetMC()->Gsvolu("UTS1","TRD1",idtmed[1301-1],parTrd,kNparTrd);
536   TVirtualMC::GetMC()->Gsvolu("UTS2","TRD1",idtmed[1301-1],parTrd,kNparTrd);
537   TVirtualMC::GetMC()->Gsvolu("UTS3","TRD1",idtmed[1301-1],parTrd,kNparTrd);
538   TVirtualMC::GetMC()->Gsvolu("UTS4","TRD1",idtmed[1301-1],parTrd,kNparTrd);
539   // The inner part of the TRD mother volume for one sector (Air), 
540   // full length in z-direction
541   parTrd[0] = fgkSwidth1/2.0 - fgkSMpltT;
542   parTrd[1] = fgkSwidth2/2.0 - fgkSMpltT;
543   parTrd[2] = fgkSlength/2.0;
544   parTrd[3] = fgkSheight/2.0 - fgkSMpltT;
545   TVirtualMC::GetMC()->Gsvolu("UTI1","TRD1",idtmed[1302-1],parTrd,kNparTrd);
546   TVirtualMC::GetMC()->Gsvolu("UTI2","TRD1",idtmed[1302-1],parTrd,kNparTrd);
547   TVirtualMC::GetMC()->Gsvolu("UTI3","TRD1",idtmed[1302-1],parTrd,kNparTrd);
548   TVirtualMC::GetMC()->Gsvolu("UTI4","TRD1",idtmed[1302-1],parTrd,kNparTrd);
549
550   // The inner part of the TRD mother volume for services in front
551   // of the supermodules  (Air), 
552   parTrd[0] = fgkSwidth1/2.0;
553   parTrd[1] = fgkSwidth2/2.0;
554   parTrd[2] = fgkFlength/2.0;
555   parTrd[3] = fgkSheight/2.0;
556   TVirtualMC::GetMC()->Gsvolu("UTF1","TRD1",idtmed[1302-1],parTrd,kNparTrd);
557   TVirtualMC::GetMC()->Gsvolu("UTF2","TRD1",idtmed[1302-1],parTrd,kNparTrd);
558
559   for (Int_t istack = 0; istack < kNstack; istack++) {
560     for (Int_t ilayer = 0; ilayer < kNlayer; ilayer++) {  
561
562       Int_t iDet = GetDetectorSec(ilayer,istack);
563
564       // The lower part of the readout chambers (drift volume + radiator) 
565       // The aluminum frames 
566       snprintf(cTagV,kTag,"UA%02d",iDet);
567       parCha[0] = fgkCwidth[ilayer]/2.0;
568       parCha[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0;
569       parCha[2] = fgkCraH/2.0 + fgkCdrH/2.0;
570       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
571       // The additional aluminum on the frames
572       // This part has not the correct shape but is just supposed to
573       // represent the missing material. The correct form of the L-shaped
574       // profile would not fit into the alignable volume. 
575       snprintf(cTagV,kTag,"UZ%02d",iDet);
576       parCha[0] = fgkCalWmod/2.0;
577       parCha[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0;
578       parCha[2] = fgkCalHmod/2.0;
579       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
580       // The additional Wacosit on the frames
581       snprintf(cTagV,kTag,"UP%02d",iDet);
582       parCha[0] = fgkCwsW/2.0;
583       parCha[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0;
584       parCha[2] = fgkCwsH/2.0;
585       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1307-1],parCha,kNparCha);
586       // The Wacosit frames 
587       snprintf(cTagV,kTag,"UB%02d",iDet);
588       parCha[0] = fgkCwidth[ilayer]/2.0 - fgkCalT; 
589       parCha[1] = -1.0;
590       parCha[2] = -1.0;
591       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1307-1],parCha,kNparCha);
592       // The glue around the radiator
593       snprintf(cTagV,kTag,"UX%02d",iDet);
594       parCha[0] = fgkCwidth[ilayer]/2.0 - fgkCalT - fgkCclsT; 
595       parCha[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0 - fgkCclfT;
596       parCha[2] = fgkCraH/2.0;
597       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1311-1],parCha,kNparCha);
598       // The inner part of radiator (air)
599       snprintf(cTagV,kTag,"UC%02d",iDet);
600       parCha[0] = fgkCwidth[ilayer]/2.0 - fgkCalT - fgkCclsT - fgkCglT; 
601       parCha[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0 - fgkCclfT - fgkCglT;
602       parCha[2] = -1.0;
603       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
604
605       // The upper part of the readout chambers (amplification volume)
606       // The Wacosit frames
607       snprintf(cTagV,kTag,"UD%02d",iDet);
608       parCha[0] = fgkCwidth[ilayer]/2.0 + fgkCroW;
609       parCha[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0;
610       parCha[2] = fgkCamH/2.0;
611       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1307-1],parCha,kNparCha);
612       // The inner part of the Wacosit frame (air)
613       snprintf(cTagV,kTag,"UE%02d",iDet);
614       parCha[0] = fgkCwidth[ilayer]/2.0 + fgkCroW - fgkCcuTb; 
615       parCha[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0 - fgkCcuTa;
616       parCha[2] = -1.;
617       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
618
619       // The back panel, including pad plane and readout boards
620       // The aluminum frames
621       snprintf(cTagV,kTag,"UF%02d",iDet);
622       parCha[0] = fgkCwidth[ilayer]/2.0 + fgkCroW;
623       parCha[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0;
624       parCha[2] = fgkCroH/2.0;
625       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
626       // The inner part of the aluminum frames
627       snprintf(cTagV,kTag,"UG%02d",iDet);
628       parCha[0] = fgkCwidth[ilayer]/2.0 + fgkCroW - fgkCauT; 
629       parCha[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0 - fgkCauT;
630       parCha[2] = -1.0;
631       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
632
633       //
634       // The material layers inside the chambers
635       //
636
637       // Mylar layer (radiator)
638       parCha[0] = -1.0;
639       parCha[1] = -1.0;
640       parCha[2] = fgkRMyThick/2.0;
641       snprintf(cTagV,kTag,"URMY%02d",iDet);
642       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1327-1],parCha,kNparCha);
643       // Carbon layer (radiator)
644       parCha[0] = -1.0;
645       parCha[1] = -1.0;
646       parCha[2] = fgkRCbThick/2.0;
647       snprintf(cTagV,kTag,"URCB%02d",iDet);
648       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1326-1],parCha,kNparCha);
649       // Araldite layer (radiator)
650       parCha[0] = -1.0;
651       parCha[1] = -1.0;
652       parCha[2] = fgkRGlThick/2.0;
653       snprintf(cTagV,kTag,"URGL%02d",iDet);
654       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1311-1],parCha,kNparCha);
655       // Rohacell layer (radiator)
656       parCha[0] = -1.0;
657       parCha[1] = -1.0;
658       parCha[2] = fgkRRhThick/2.0;
659       snprintf(cTagV,kTag,"URRH%02d",iDet);
660       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1315-1],parCha,kNparCha);
661       // Fiber layer (radiator)
662       parCha[0] = -1.0;
663       parCha[1] = -1.0;
664       parCha[2] = fgkRFbThick/2.0;
665       snprintf(cTagV,kTag,"URFB%02d",iDet);
666       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1328-1],parCha,kNparCha);
667
668       // Xe/Isobutane layer (drift volume) 
669       parCha[0] = fgkCwidth[ilayer]/2.0 - fgkCalT - fgkCclsT;
670       parCha[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0 - fgkCclfT;
671       parCha[2] = fgkDrThick/2.0;
672       snprintf(cTagV,kTag,"UJ%02d",iDet);
673       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1309-1],parCha,kNparCha);
674
675       // Xe/Isobutane layer (amplification volume)
676       parCha[0] = -1.0;
677       parCha[1] = -1.0;
678       parCha[2] = fgkAmThick/2.0;
679       snprintf(cTagV,kTag,"UK%02d",iDet);
680       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1309-1],parCha,kNparCha);  
681       // Cu layer (wire plane)
682       parCha[0] = -1.0;
683       parCha[1] = -1.0;
684       parCha[2] = fgkWrThick/2.0;
685       snprintf(cTagV,kTag,"UW%02d",iDet);
686       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1303-1],parCha,kNparCha);
687
688       // Cu layer (pad plane)
689       parCha[0] = -1.0;
690       parCha[1] = -1.0;
691       parCha[2] = fgkPPdThick/2.0;
692       snprintf(cTagV,kTag,"UPPD%02d",iDet);
693       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1305-1],parCha,kNparCha);
694       // G10 layer (pad plane)
695       parCha[0] = -1.0;
696       parCha[1] = -1.0;
697       parCha[2] = fgkPPpThick/2.0;
698       snprintf(cTagV,kTag,"UPPP%02d",iDet);
699       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1313-1],parCha,kNparCha);
700       // Araldite layer (glue)
701       parCha[0] = -1.0;
702       parCha[1] = -1.0;
703       parCha[2] = fgkPGlThick/2.0;
704       snprintf(cTagV,kTag,"UPGL%02d",iDet);
705       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1311-1],parCha,kNparCha);
706       // Carbon layer (carbon fiber mats)
707       parCha[0] = -1.0;
708       parCha[1] = -1.0;
709       parCha[2] = fgkPCbThick/2.0;
710       snprintf(cTagV,kTag,"UPCB%02d",iDet);
711       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1326-1],parCha,kNparCha);
712       // Aramide layer (honeycomb)
713       parCha[0] = -1.0;
714       parCha[1] = -1.0;
715       parCha[2] = fgkPHcThick/2.0;
716       snprintf(cTagV,kTag,"UPHC%02d",iDet);
717       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1310-1],parCha,kNparCha);
718       // G10 layer (PCB readout board)
719       parCha[0] = -1.0;
720       parCha[1] = -1.0;
721       parCha[2] = fgkPPcThick/2;
722       snprintf(cTagV,kTag,"UPPC%02d",iDet);
723       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1313-1],parCha,kNparCha);
724       // Cu layer (traces in readout board)
725       parCha[0] = -1.0;
726       parCha[1] = -1.0;
727       parCha[2] = fgkPRbThick/2.0;
728       snprintf(cTagV,kTag,"UPRB%02d",iDet);
729       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1306-1],parCha,kNparCha);
730       // Cu layer (other material on in readout board, incl. screws)
731       parCha[0] = -1.0;
732       parCha[1] = -1.0;
733       parCha[2] = fgkPElThick/2.0;
734       snprintf(cTagV,kTag,"UPEL%02d",iDet);
735       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1304-1],parCha,kNparCha);
736
737       //
738       // Position the layers in the chambers
739       //
740       xpos = 0.0;
741       ypos = 0.0;
742
743       // Lower part
744       // Mylar layers (radiator)
745       zpos =  fgkRMyThick/2.0 - fgkCraH/2.0;
746       snprintf(cTagV,kTag,"URMY%02d",iDet);
747       snprintf(cTagM,kTag,"UC%02d",iDet);
748       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
749       zpos = -fgkRMyThick/2.0 + fgkCraH/2.0;
750       snprintf(cTagV,kTag,"URMY%02d",iDet);
751       snprintf(cTagM,kTag,"UC%02d",iDet);
752       TVirtualMC::GetMC()->Gspos(cTagV,2,cTagM,xpos,ypos,zpos,0,"ONLY");
753       // Carbon layers (radiator)
754       zpos =  fgkRCbThick/2.0 + fgkRMyThick - fgkCraH/2.0;
755       snprintf(cTagV,kTag,"URCB%02d",iDet);
756       snprintf(cTagM,kTag,"UC%02d",iDet);
757       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
758       zpos = -fgkRCbThick/2.0 - fgkRMyThick + fgkCraH/2.0;
759       snprintf(cTagV,kTag,"URCB%02d",iDet);
760       snprintf(cTagM,kTag,"UC%02d",iDet);
761       TVirtualMC::GetMC()->Gspos(cTagV,2,cTagM,xpos,ypos,zpos,0,"ONLY");
762       // Carbon layers (radiator)
763       zpos =  fgkRGlThick/2.0 + fgkRCbThick + fgkRMyThick - fgkCraH/2.0;
764       snprintf(cTagV,kTag,"URGL%02d",iDet);
765       snprintf(cTagM,kTag,"UC%02d",iDet);
766       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
767       zpos = -fgkRGlThick/2.0 - fgkRCbThick - fgkRMyThick + fgkCraH/2.0;
768       snprintf(cTagV,kTag,"URGL%02d",iDet);
769       snprintf(cTagM,kTag,"UC%02d",iDet);
770       TVirtualMC::GetMC()->Gspos(cTagV,2,cTagM,xpos,ypos,zpos,0,"ONLY");
771       // Rohacell layers (radiator)
772       zpos =  fgkRRhThick/2.0 + fgkRGlThick + fgkRCbThick + fgkRMyThick - fgkCraH/2.0;
773       snprintf(cTagV,kTag,"URRH%02d",iDet);
774       snprintf(cTagM,kTag,"UC%02d",iDet);
775       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
776       zpos = -fgkRRhThick/2.0 - fgkRGlThick - fgkRCbThick - fgkRMyThick + fgkCraH/2.0;
777       snprintf(cTagV,kTag,"URRH%02d",iDet);
778       snprintf(cTagM,kTag,"UC%02d",iDet);
779       TVirtualMC::GetMC()->Gspos(cTagV,2,cTagM,xpos,ypos,zpos,0,"ONLY");
780       // Fiber layers (radiator)
781       zpos =  0.0;
782       snprintf(cTagV,kTag,"URFB%02d",iDet);
783       snprintf(cTagM,kTag,"UC%02d",iDet);
784       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
785
786       // Xe/Isobutane layer (drift volume) 
787       zpos = fgkDrZpos;
788       snprintf(cTagV,kTag,"UJ%02d",iDet);
789       snprintf(cTagM,kTag,"UB%02d",iDet);
790       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
791
792       // Upper part
793       // Xe/Isobutane layer (amplification volume)
794       zpos = fgkAmZpos;
795       snprintf(cTagV,kTag,"UK%02d",iDet);
796       snprintf(cTagM,kTag,"UE%02d",iDet);
797       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
798       // Cu layer (wire planes inside amplification volume)
799       zpos = fgkWrZposA; 
800       snprintf(cTagV,kTag,"UW%02d",iDet);
801       snprintf(cTagM,kTag,"UK%02d",iDet);
802       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
803       zpos = fgkWrZposB; 
804       snprintf(cTagV,kTag,"UW%02d",iDet);
805       snprintf(cTagM,kTag,"UK%02d",iDet);
806       TVirtualMC::GetMC()->Gspos(cTagV,2,cTagM,xpos,ypos,zpos,0,"ONLY");
807
808       // Back panel + pad plane + readout part
809       // Cu layer (pad plane)
810       zpos =  fgkPPdThick/2.0 - fgkCroH/2.0;
811       snprintf(cTagV,kTag,"UPPD%02d",iDet);
812       snprintf(cTagM,kTag,"UG%02d",iDet);
813       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
814       // G10  layer (pad plane)
815       zpos =  fgkPPpThick/2.0 + fgkPPdThick - fgkCroH/2.0;
816       snprintf(cTagV,kTag,"UPPP%02d",iDet);
817       snprintf(cTagM,kTag,"UG%02d",iDet);
818       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
819       // Araldite layer (glue)
820       zpos =  fgkPGlThick/2.0 + fgkPPpThick + fgkPPdThick - fgkCroH/2.0;
821       snprintf(cTagV,kTag,"UPGL%02d",iDet);
822       snprintf(cTagM,kTag,"UG%02d",iDet);
823       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
824       // Carbon layers (carbon fiber mats)
825       zpos =  fgkPCbThick/2.0 + fgkPGlThick + fgkPPpThick + fgkPPdThick - fgkCroH/2.0;
826       snprintf(cTagV,kTag,"UPCB%02d",iDet);
827       snprintf(cTagM,kTag,"UG%02d",iDet);
828       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
829       zpos = -fgkPCbThick/2.0 - fgkPPcThick - fgkPRbThick - fgkPElThick + fgkCroH/2.0;
830       snprintf(cTagV,kTag,"UPCB%02d",iDet);
831       snprintf(cTagM,kTag,"UG%02d",iDet);
832       TVirtualMC::GetMC()->Gspos(cTagV,2,cTagM,xpos,ypos,zpos,0,"ONLY");
833       // Aramide layer (honeycomb)
834       zpos =  fgkPHcThick/2.0 + fgkPCbThick + fgkPGlThick + fgkPPpThick + fgkPPdThick - fgkCroH/2.0;
835       snprintf(cTagV,kTag,"UPHC%02d",iDet);
836       snprintf(cTagM,kTag,"UG%02d",iDet);
837       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
838       // G10 layer (PCB readout board)
839       zpos = -fgkPPcThick/2.0 - fgkPRbThick - fgkPElThick + fgkCroH/2.0;
840       snprintf(cTagV,kTag,"UPPC%02d",iDet);
841       snprintf(cTagM,kTag,"UG%02d",iDet);
842       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
843       // Cu layer (traces in readout board)
844       zpos = -fgkPRbThick/2.0 - fgkPElThick + fgkCroH/2.0;
845       snprintf(cTagV,kTag,"UPRB%02d",iDet);
846       snprintf(cTagM,kTag,"UG%02d",iDet);
847       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
848       // Cu layer (other materials on readout board, incl. screws)
849       zpos = -fgkPElThick/2.0 + fgkCroH/2.0;
850       snprintf(cTagV,kTag,"UPEL%02d",iDet);
851       snprintf(cTagM,kTag,"UG%02d",iDet);
852       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
853
854       // Position the inner volumes of the chambers in the frames
855       xpos = 0.0;
856       ypos = 0.0;
857
858       // The inner part of the radiator (air)
859       zpos = 0.0;
860       snprintf(cTagV,kTag,"UC%02d",iDet);
861       snprintf(cTagM,kTag,"UX%02d",iDet);
862       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
863       // The glue around the radiator
864       zpos = fgkCraH/2.0 - fgkCdrH/2.0 - fgkCraH/2.0;
865       snprintf(cTagV,kTag,"UX%02d",iDet);
866       snprintf(cTagM,kTag,"UB%02d",iDet);
867       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
868       // The lower Wacosit frame inside the aluminum frame
869       zpos = 0.0;
870       snprintf(cTagV,kTag,"UB%02d",iDet);
871       snprintf(cTagM,kTag,"UA%02d",iDet);
872       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
873
874       // The inside of the upper Wacosit frame
875       zpos = 0.0;
876       snprintf(cTagV,kTag,"UE%02d",iDet);
877       snprintf(cTagM,kTag,"UD%02d",iDet);
878       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
879
880       // The inside of the upper aluminum frame
881       zpos = 0.0;
882       snprintf(cTagV,kTag,"UG%02d",iDet);
883       snprintf(cTagM,kTag,"UF%02d",iDet);
884       TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");      
885
886     }
887   }
888
889   // Create the volumes of the super module frame
890   CreateFrame(idtmed);
891
892   // Create the volumes of the services
893   CreateServices(idtmed);
894   
895   for (Int_t istack = 0; istack < kNstack; istack++) {
896     for (Int_t ilayer = 0; ilayer < kNlayer; ilayer++) {  
897       AssembleChamber(ilayer,istack);
898     }
899   }
900   
901   xpos = 0.0;
902   ypos = 0.0;
903   zpos = 0.0;
904   TVirtualMC::GetMC()->Gspos("UTI1",1,"UTS1",xpos,ypos,zpos,0,"ONLY");
905   TVirtualMC::GetMC()->Gspos("UTI2",1,"UTS2",xpos,ypos,zpos,0,"ONLY");
906   TVirtualMC::GetMC()->Gspos("UTI3",1,"UTS3",xpos,ypos,zpos,0,"ONLY");
907   TVirtualMC::GetMC()->Gspos("UTI4",1,"UTS4",xpos,ypos,zpos,0,"ONLY");
908
909   xpos = 0.0;
910   ypos = 0.0;
911   zpos = 0.0;
912   TVirtualMC::GetMC()->Gspos("UTS1",1,"UTR1",xpos,ypos,zpos,0,"ONLY");
913   TVirtualMC::GetMC()->Gspos("UTS2",1,"UTR2",xpos,ypos,zpos,0,"ONLY");
914   TVirtualMC::GetMC()->Gspos("UTS3",1,"UTR3",xpos,ypos,zpos,0,"ONLY");
915   TVirtualMC::GetMC()->Gspos("UTS4",1,"UTR4",xpos,ypos,zpos,0,"ONLY");
916
917   // Put the TRD volumes into the space frame mother volumes
918   // if enabled via status flag
919   xpos = 0.0;
920   ypos = 0.0;
921   zpos = 0.0;
922   for (Int_t isector = 0; isector < kNsector; isector++) {
923     if (GetSMstatus(isector)) {
924       snprintf(cTagV,kTag,"BTRD%d",isector);
925       switch (isector) {
926       case 17:
927         // Missing L4S4 chamber
928         TVirtualMC::GetMC()->Gspos("UTR4",1,cTagV,xpos,ypos,zpos,0,"ONLY");
929         break;
930       case 13:
931       case 14:
932       case 15:
933         // Double carbon, w/o middle stack
934         TVirtualMC::GetMC()->Gspos("UTR3",1,cTagV,xpos,ypos,zpos,0,"ONLY");
935         break;
936       case 11:
937       case 12:
938         // Double carbon, all stacks
939         TVirtualMC::GetMC()->Gspos("UTR2",1,cTagV,xpos,ypos,zpos,0,"ONLY");
940         break;
941       default:
942         // Standard supermodule
943         TVirtualMC::GetMC()->Gspos("UTR1",1,cTagV,xpos,ypos,zpos,0,"ONLY");
944       };
945     }
946   }
947
948   // Put the TRD volumes into the space frame mother volumes
949   // if enabled via status flag
950   xpos = 0.0;
951   ypos = 0.5*fgkSlength + 0.5*fgkFlength;
952   zpos = 0.0;
953   for (Int_t isector = 0; isector < kNsector; isector++) {
954     if (GetSMstatus(isector)) {
955       snprintf(cTagV,kTag,"BTRD%d",isector);
956       TVirtualMC::GetMC()->Gspos("UTF1",1,cTagV,xpos, ypos,zpos,0,"ONLY");
957       TVirtualMC::GetMC()->Gspos("UTF2",1,cTagV,xpos,-ypos,zpos,0,"ONLY");
958     }
959   }
960
961 }
962
963 //_____________________________________________________________________________
964 void AliTRDgeometry::CreateFrame(Int_t *idtmed)
965 {
966   //
967   // Create the geometry of the frame of the supermodule
968   //
969   // Names of the TRD services volumina
970   //
971   //        USRL    Support rails for the chambers (Al)
972   //        USxx    Support cross bars between the chambers (Al)
973   //        USHx    Horizontal connection between the cross bars (Al)
974   //        USLx    Long corner ledges (Al)
975   //
976
977   Int_t   ilayer = 0;
978
979   Float_t xpos  = 0.0;
980   Float_t ypos  = 0.0;
981   Float_t zpos  = 0.0;
982
983   const Int_t kTag = 100;
984   Char_t  cTagV[kTag];
985   Char_t  cTagM[kTag];
986
987   const Int_t kNparTRD = 4;
988   Float_t parTRD[kNparTRD];
989   const Int_t kNparBOX = 3;
990   Float_t parBOX[kNparBOX];
991   const Int_t kNparTRP = 11;
992   Float_t parTRP[kNparTRP];
993
994   // The rotation matrices
995   const Int_t kNmatrix = 7;
996   Int_t   matrix[kNmatrix];
997   TVirtualMC::GetMC()->Matrix(matrix[0], 100.0,   0.0,  90.0,  90.0,  10.0,   0.0);
998   TVirtualMC::GetMC()->Matrix(matrix[1],  80.0,   0.0,  90.0,  90.0,  10.0, 180.0);
999   TVirtualMC::GetMC()->Matrix(matrix[2],  90.0,   0.0,   0.0,   0.0,  90.0,  90.0);
1000   TVirtualMC::GetMC()->Matrix(matrix[3],  90.0, 180.0,   0.0, 180.0,  90.0,  90.0);
1001   TVirtualMC::GetMC()->Matrix(matrix[4], 170.0,   0.0,  80.0,   0.0,  90.0,  90.0);
1002   TVirtualMC::GetMC()->Matrix(matrix[5], 170.0, 180.0,  80.0, 180.0,  90.0,  90.0);
1003   TVirtualMC::GetMC()->Matrix(matrix[6], 180.0, 180.0,  90.0, 180.0,  90.0,  90.0);
1004
1005   //
1006   // The carbon inserts in the top/bottom aluminum plates
1007   //
1008
1009   const Int_t kNparCrb = 3;
1010   Float_t parCrb[kNparCrb];
1011   parCrb[0] = 0.0;
1012   parCrb[1] = 0.0;
1013   parCrb[2] = 0.0;
1014   TVirtualMC::GetMC()->Gsvolu("USCR","BOX ",idtmed[1326-1],parCrb,0);
1015   // Bottom 1 (all sectors)
1016   parCrb[0] =  77.49/2.0;
1017   parCrb[1] = 104.60/2.0;
1018   parCrb[2] = fgkSMpltT/2.0;
1019   xpos      =   0.0;
1020   ypos      =   0.0;
1021   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1022   TVirtualMC::GetMC()->Gsposp("USCR", 1,"UTS1", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1023   TVirtualMC::GetMC()->Gsposp("USCR", 2,"UTS2", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1024   TVirtualMC::GetMC()->Gsposp("USCR", 3,"UTS3", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1025   TVirtualMC::GetMC()->Gsposp("USCR", 4,"UTS4", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1026   // Bottom 2 (all sectors)
1027   parCrb[0] =  77.49/2.0;
1028   parCrb[1] =  55.80/2.0;
1029   parCrb[2] = fgkSMpltT/2.0;
1030   xpos      =   0.0;
1031   ypos      =  85.6;
1032   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1033   TVirtualMC::GetMC()->Gsposp("USCR", 5,"UTS1", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1034   TVirtualMC::GetMC()->Gsposp("USCR", 6,"UTS2", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1035   TVirtualMC::GetMC()->Gsposp("USCR", 7,"UTS3", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1036   TVirtualMC::GetMC()->Gsposp("USCR", 8,"UTS4", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1037   TVirtualMC::GetMC()->Gsposp("USCR", 9,"UTS1", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1038   TVirtualMC::GetMC()->Gsposp("USCR",10,"UTS2", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1039   TVirtualMC::GetMC()->Gsposp("USCR",11,"UTS3", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1040   TVirtualMC::GetMC()->Gsposp("USCR",12,"UTS4", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1041   // Bottom 3 (all sectors)
1042   parCrb[0] =  77.49/2.0;
1043   parCrb[1] =  56.00/2.0;
1044   parCrb[2] = fgkSMpltT/2.0;
1045   xpos      =   0.0;
1046   ypos      = 148.5;
1047   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1048   TVirtualMC::GetMC()->Gsposp("USCR",13,"UTS1", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1049   TVirtualMC::GetMC()->Gsposp("USCR",14,"UTS2", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1050   TVirtualMC::GetMC()->Gsposp("USCR",15,"UTS3", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1051   TVirtualMC::GetMC()->Gsposp("USCR",16,"UTS4", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1052   TVirtualMC::GetMC()->Gsposp("USCR",17,"UTS1", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1053   TVirtualMC::GetMC()->Gsposp("USCR",18,"UTS2", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1054   TVirtualMC::GetMC()->Gsposp("USCR",19,"UTS3", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1055   TVirtualMC::GetMC()->Gsposp("USCR",20,"UTS4", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1056   // Bottom 4 (all sectors)
1057   parCrb[0] =  77.49/2.0;
1058   parCrb[1] = 118.00/2.0;
1059   parCrb[2] = fgkSMpltT/2.0;
1060   xpos      =   0.0;
1061   ypos      = 240.5;
1062   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1063   TVirtualMC::GetMC()->Gsposp("USCR",21,"UTS1", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1064   TVirtualMC::GetMC()->Gsposp("USCR",22,"UTS2", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1065   TVirtualMC::GetMC()->Gsposp("USCR",23,"UTS3", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1066   TVirtualMC::GetMC()->Gsposp("USCR",24,"UTS4", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1067   TVirtualMC::GetMC()->Gsposp("USCR",25,"UTS1", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1068   TVirtualMC::GetMC()->Gsposp("USCR",26,"UTS2", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1069   TVirtualMC::GetMC()->Gsposp("USCR",27,"UTS3", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1070   TVirtualMC::GetMC()->Gsposp("USCR",28,"UTS4", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1071   // Top 1 (only in front of PHOS)
1072   parCrb[0] = 111.48/2.0;
1073   parCrb[1] = 105.00/2.0;
1074   parCrb[2] = fgkSMpltT/2.0;
1075   xpos      =   0.0;
1076   ypos      =   0.0;
1077   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1078   TVirtualMC::GetMC()->Gsposp("USCR",29,"UTS2", xpos, ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1079   TVirtualMC::GetMC()->Gsposp("USCR",30,"UTS3", xpos, ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1080   // Top 2 (only in front of PHOS)
1081   parCrb[0] = 111.48/2.0;
1082   parCrb[1] =  56.00/2.0;
1083   parCrb[2] = fgkSMpltT/2.0;
1084   xpos      =   0.0;
1085   ypos      =  85.5;
1086   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1087   TVirtualMC::GetMC()->Gsposp("USCR",31,"UTS2", xpos, ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1088   TVirtualMC::GetMC()->Gsposp("USCR",32,"UTS3", xpos, ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1089   TVirtualMC::GetMC()->Gsposp("USCR",33,"UTS2", xpos,-ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1090   TVirtualMC::GetMC()->Gsposp("USCR",34,"UTS3", xpos,-ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1091
1092   //
1093   // The chamber support rails
1094   //
1095
1096   const Float_t kSRLhgt  = 2.00;
1097   const Float_t kSRLwidA = 2.3;
1098   const Float_t kSRLwidB = 1.947;
1099   const Float_t kSRLdst  = 1.135;
1100   const Int_t   kNparSRL = 11;
1101   Float_t parSRL[kNparSRL];
1102   // Trapezoidal shape
1103   parSRL[ 0] = fgkSlength/2.0;
1104   parSRL[ 1] = 0.0;
1105   parSRL[ 2] = 0.0;
1106   parSRL[ 3] = kSRLhgt  /2.0;
1107   parSRL[ 4] = kSRLwidB /2.0;
1108   parSRL[ 5] = kSRLwidA /2.0;
1109   parSRL[ 6] = 5.0;
1110   parSRL[ 7] = kSRLhgt  /2.0;
1111   parSRL[ 8] = kSRLwidB /2.0;
1112   parSRL[ 9] = kSRLwidA /2.0;
1113   parSRL[10] = 5.0;
1114   TVirtualMC::GetMC()->Gsvolu("USRL","TRAP",idtmed[1301-1],parSRL,kNparSRL);
1115
1116   xpos  = 0.0;
1117   ypos  = 0.0;
1118   zpos  = 0.0;
1119   for (ilayer = 1; ilayer < kNlayer; ilayer++) {
1120     xpos  = fgkCwidth[ilayer]/2.0 + kSRLwidA/2.0 + kSRLdst;
1121     ypos  = 0.0;
1122     zpos  = fgkVrocsm + fgkSMpltT - fgkCalZpos - fgkSheight/2.0  
1123           + fgkCraH + fgkCdrH - fgkCalH - kSRLhgt/2.0 
1124           + ilayer * (fgkCH + fgkVspace);
1125     TVirtualMC::GetMC()->Gspos("USRL",ilayer+1          ,"UTI1", xpos,ypos,zpos,matrix[2],"ONLY");
1126     TVirtualMC::GetMC()->Gspos("USRL",ilayer+1+  kNlayer,"UTI1",-xpos,ypos,zpos,matrix[3],"ONLY");
1127     TVirtualMC::GetMC()->Gspos("USRL",ilayer+1+2*kNlayer,"UTI2", xpos,ypos,zpos,matrix[2],"ONLY");
1128     TVirtualMC::GetMC()->Gspos("USRL",ilayer+1+3*kNlayer,"UTI2",-xpos,ypos,zpos,matrix[3],"ONLY");
1129     TVirtualMC::GetMC()->Gspos("USRL",ilayer+1+4*kNlayer,"UTI3", xpos,ypos,zpos,matrix[2],"ONLY");
1130     TVirtualMC::GetMC()->Gspos("USRL",ilayer+1+5*kNlayer,"UTI3",-xpos,ypos,zpos,matrix[3],"ONLY");
1131     TVirtualMC::GetMC()->Gspos("USRL",ilayer+1+6*kNlayer,"UTI4", xpos,ypos,zpos,matrix[2],"ONLY");
1132     TVirtualMC::GetMC()->Gspos("USRL",ilayer+1+7*kNlayer,"UTI4",-xpos,ypos,zpos,matrix[3],"ONLY");
1133   }
1134
1135   //
1136   // The cross bars between the chambers
1137   //
1138
1139   const Float_t kSCBwid  = 1.0;
1140   const Float_t kSCBthk  = 2.0;
1141   const Float_t kSCHhgt  = 0.3;
1142
1143   const Int_t   kNparSCB = 3;
1144   Float_t parSCB[kNparSCB];
1145   parSCB[1] = kSCBwid/2.0;
1146   parSCB[2] = fgkCH  /2.0 + fgkVspace/2.0 - kSCHhgt;
1147
1148   const Int_t   kNparSCI = 3;
1149   Float_t parSCI[kNparSCI];
1150   parSCI[1] = -1;
1151
1152   xpos  = 0.0;
1153   ypos  = 0.0;
1154   zpos  = 0.0;
1155   for (ilayer = 0; ilayer < kNlayer; ilayer++) {
1156
1157     // The aluminum of the cross bars
1158     parSCB[0] = fgkCwidth[ilayer]/2.0 + kSRLdst/2.0;
1159     snprintf(cTagV,kTag,"USF%01d",ilayer);
1160     TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parSCB,kNparSCB);
1161
1162     // The empty regions in the cross bars
1163     Float_t thkSCB = kSCBthk;
1164     if (ilayer < 2) {
1165       thkSCB *= 1.5;
1166     }
1167     parSCI[2] = parSCB[2] - thkSCB;
1168     parSCI[0] = parSCB[0]/4.0 - kSCBthk;
1169     snprintf(cTagV,kTag,"USI%01d",ilayer);
1170     TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parSCI,kNparSCI);
1171
1172     snprintf(cTagV,kTag,"USI%01d",ilayer);
1173     snprintf(cTagM,kTag,"USF%01d",ilayer);
1174     ypos  = 0.0;
1175     zpos  = 0.0;
1176     xpos  =   parSCI[0] + thkSCB/2.0;
1177     TVirtualMC::GetMC()->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
1178     xpos  = - parSCI[0] - thkSCB/2.0;
1179     TVirtualMC::GetMC()->Gspos(cTagV,2,cTagM,xpos,ypos,zpos,0,"ONLY");
1180     xpos  =   3.0 * parSCI[0] + 1.5 * thkSCB;
1181     TVirtualMC::GetMC()->Gspos(cTagV,3,cTagM,xpos,ypos,zpos,0,"ONLY");
1182     xpos  = - 3.0 * parSCI[0] - 1.5 * thkSCB;
1183     TVirtualMC::GetMC()->Gspos(cTagV,4,cTagM,xpos,ypos,zpos,0,"ONLY");
1184
1185     snprintf(cTagV,kTag,"USF%01d",ilayer);
1186     xpos  = 0.0;
1187     zpos  = fgkVrocsm + fgkSMpltT + parSCB[2] - fgkSheight/2.0 
1188           + ilayer * (fgkCH + fgkVspace);
1189
1190     ypos  =   fgkClength[ilayer][2]/2.0 + fgkClength[ilayer][1];
1191     TVirtualMC::GetMC()->Gspos(cTagV, 1,"UTI1", xpos,ypos,zpos,0,"ONLY");
1192     TVirtualMC::GetMC()->Gspos(cTagV, 3,"UTI2", xpos,ypos,zpos,0,"ONLY");
1193     TVirtualMC::GetMC()->Gspos(cTagV, 5,"UTI3", xpos,ypos,zpos,0,"ONLY");
1194     TVirtualMC::GetMC()->Gspos(cTagV, 7,"UTI4", xpos,ypos,zpos,0,"ONLY");
1195
1196     ypos  = - fgkClength[ilayer][2]/2.0 - fgkClength[ilayer][1];
1197     TVirtualMC::GetMC()->Gspos(cTagV, 2,"UTI1", xpos,ypos,zpos,0,"ONLY");
1198     TVirtualMC::GetMC()->Gspos(cTagV, 4,"UTI2", xpos,ypos,zpos,0,"ONLY");
1199     TVirtualMC::GetMC()->Gspos(cTagV, 6,"UTI3", xpos,ypos,zpos,0,"ONLY");
1200     TVirtualMC::GetMC()->Gspos(cTagV, 8,"UTI4", xpos,ypos,zpos,0,"ONLY");
1201
1202   }
1203
1204   //
1205   // The horizontal connections between the cross bars
1206   //
1207
1208   const Int_t   kNparSCH = 3;
1209   Float_t parSCH[kNparSCH];
1210
1211   for (ilayer = 1; ilayer < kNlayer-1; ilayer++) {
1212
1213     parSCH[0] = fgkCwidth[ilayer]/2.0;
1214     parSCH[1] = (fgkClength[ilayer+1][2]/2.0 + fgkClength[ilayer+1][1]
1215                - fgkClength[ilayer  ][2]/2.0 - fgkClength[ilayer  ][1])/2.0;
1216     parSCH[2] = kSCHhgt/2.0;
1217
1218     snprintf(cTagV,kTag,"USH%01d",ilayer);
1219     TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parSCH,kNparSCH);
1220     xpos  = 0.0;
1221     ypos  = fgkClength[ilayer][2]/2.0 + fgkClength[ilayer][1] + parSCH[1];
1222     zpos  = fgkVrocsm + fgkSMpltT - kSCHhgt/2.0 - fgkSheight/2.0 
1223           + (ilayer+1) * (fgkCH + fgkVspace);
1224     TVirtualMC::GetMC()->Gspos(cTagV,1,"UTI1", xpos,ypos,zpos,0,"ONLY");
1225     TVirtualMC::GetMC()->Gspos(cTagV,3,"UTI2", xpos,ypos,zpos,0,"ONLY");
1226     TVirtualMC::GetMC()->Gspos(cTagV,5,"UTI3", xpos,ypos,zpos,0,"ONLY");
1227     TVirtualMC::GetMC()->Gspos(cTagV,7,"UTI4", xpos,ypos,zpos,0,"ONLY");
1228     ypos  = -ypos;
1229     TVirtualMC::GetMC()->Gspos(cTagV,2,"UTI1", xpos,ypos,zpos,0,"ONLY");
1230     TVirtualMC::GetMC()->Gspos(cTagV,4,"UTI2", xpos,ypos,zpos,0,"ONLY");
1231     TVirtualMC::GetMC()->Gspos(cTagV,6,"UTI3", xpos,ypos,zpos,0,"ONLY");
1232     TVirtualMC::GetMC()->Gspos(cTagV,8,"UTI4", xpos,ypos,zpos,0,"ONLY");
1233
1234   }
1235
1236   //
1237   // The aymmetric flat frame in the middle
1238   //
1239
1240   // The envelope volume (aluminum)
1241   parTRD[0]  =  87.60/2.0;
1242   parTRD[1]  = 114.00/2.0;
1243   parTRD[2]  =   1.20/2.0;
1244   parTRD[3]  =  71.30/2.0;
1245   TVirtualMC::GetMC()->Gsvolu("USDB","TRD1",idtmed[1301-1],parTRD,kNparTRD);
1246   // Empty spaces (air)
1247   parTRP[ 0] =   1.20/2.0;
1248   parTRP[ 1] =   0.0;
1249   parTRP[ 2] =   0.0;
1250   parTRP[ 3] =  27.00/2.0;
1251   parTRP[ 4] =  50.60/2.0;
1252   parTRP[ 5] =   5.00/2.0;
1253   parTRP[ 6] =   3.5;
1254   parTRP[ 7] =  27.00/2.0;
1255   parTRP[ 8] =  50.60/2.0;
1256   parTRP[ 9] =   5.00/2.0;
1257   parTRP[10] =   3.5;
1258   TVirtualMC::GetMC()->Gsvolu("USD1","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1259   xpos       =  18.0;
1260   ypos       =   0.0;
1261   zpos       =   27.00/2.0 - 71.3/2.0;
1262   TVirtualMC::GetMC()->Gspos("USD1",1,"USDB", xpos, ypos, zpos,matrix[2],"ONLY");
1263   // Empty spaces (air)
1264   parTRP[ 0] =   1.20/2.0;
1265   parTRP[ 1] =   0.0;
1266   parTRP[ 2] =   0.0;
1267   parTRP[ 3] =  33.00/2.0;
1268   parTRP[ 4] =   5.00/2.0;
1269   parTRP[ 5] =  62.10/2.0;
1270   parTRP[ 6] =   3.5;
1271   parTRP[ 7] =  33.00/2.0;
1272   parTRP[ 8] =   5.00/2.0;
1273   parTRP[ 9] =  62.10/2.0;
1274   parTRP[10] =   3.5;
1275   TVirtualMC::GetMC()->Gsvolu("USD2","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1276   xpos       =  21.0;
1277   ypos       =   0.0;
1278   zpos       =  71.3/2.0 - 33.0/2.0;
1279   TVirtualMC::GetMC()->Gspos("USD2",1,"USDB", xpos, ypos, zpos,matrix[2],"ONLY");
1280   // Empty spaces (air)
1281   parBOX[ 0] =  22.50/2.0;
1282   parBOX[ 1] =   1.20/2.0;
1283   parBOX[ 2] =  70.50/2.0;
1284   TVirtualMC::GetMC()->Gsvolu("USD3","BOX ",idtmed[1302-1],parBOX,kNparBOX);
1285   xpos       = -25.75;
1286   ypos       =   0.0;
1287   zpos       =   0.4;
1288   TVirtualMC::GetMC()->Gspos("USD3",1,"USDB", xpos, ypos, zpos,        0,"ONLY");
1289   // Empty spaces (air)
1290   parTRP[ 0] =   1.20/2.0;
1291   parTRP[ 1] =   0.0;
1292   parTRP[ 2] =   0.0;
1293   parTRP[ 3] =  25.50/2.0;
1294   parTRP[ 4] =   5.00/2.0;
1295   parTRP[ 5] =  65.00/2.0;
1296   parTRP[ 6] =  -1.0;
1297   parTRP[ 7] =  25.50/2.0;
1298   parTRP[ 8] =   5.00/2.0;
1299   parTRP[ 9] =  65.00/2.0;
1300   parTRP[10] =  -1.0;
1301   TVirtualMC::GetMC()->Gsvolu("USD4","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1302   xpos       =   2.0;
1303   ypos       =   0.0;
1304   zpos       =  -1.6;
1305   TVirtualMC::GetMC()->Gspos("USD4",1,"USDB", xpos, ypos, zpos,matrix[6],"ONLY");
1306   // Empty spaces (air)
1307   parTRP[ 0] =   1.20/2.0;
1308   parTRP[ 1] =   0.0;
1309   parTRP[ 2] =   0.0;
1310   parTRP[ 3] =  23.50/2.0;
1311   parTRP[ 4] =  63.50/2.0;
1312   parTRP[ 5] =   5.00/2.0;
1313   parTRP[ 6] =  16.0;
1314   parTRP[ 7] =  23.50/2.0;
1315   parTRP[ 8] =  63.50/2.0;
1316   parTRP[ 9] =   5.00/2.0;
1317   parTRP[10] =  16.0;
1318   TVirtualMC::GetMC()->Gsvolu("USD5","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1319   xpos       =  36.5;
1320   ypos       =   0.0;
1321   zpos       =  -1.5;
1322   TVirtualMC::GetMC()->Gspos("USD5",1,"USDB", xpos, ypos, zpos,matrix[5],"ONLY");
1323   // Empty spaces (air)
1324   parTRP[ 0] =   1.20/2.0;
1325   parTRP[ 1] =   0.0;
1326   parTRP[ 2] =   0.0;
1327   parTRP[ 3] =  70.50/2.0;
1328   parTRP[ 4] =   4.50/2.0;
1329   parTRP[ 5] =  16.50/2.0;
1330   parTRP[ 6] =  -5.0;
1331   parTRP[ 7] =  70.50/2.0;
1332   parTRP[ 8] =   4.50/2.0;
1333   parTRP[ 9] =  16.50/2.0;
1334   parTRP[10] =  -5.0;
1335   TVirtualMC::GetMC()->Gsvolu("USD6","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1336   xpos       = -43.7;
1337   ypos       =   0.0;
1338   zpos       =   0.4;
1339   TVirtualMC::GetMC()->Gspos("USD6",1,"USDB", xpos, ypos, zpos,matrix[2],"ONLY");
1340   xpos       =   0.0;
1341   ypos       =   fgkClength[5][2]/2.0;
1342   zpos       =   0.04;
1343   TVirtualMC::GetMC()->Gspos("USDB",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1344   TVirtualMC::GetMC()->Gspos("USDB",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1345   TVirtualMC::GetMC()->Gspos("USDB",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1346   TVirtualMC::GetMC()->Gspos("USDB",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1347   TVirtualMC::GetMC()->Gspos("USDB",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1348   TVirtualMC::GetMC()->Gspos("USDB",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1349   TVirtualMC::GetMC()->Gspos("USDB",7,"UTI4", xpos, ypos, zpos,        0,"ONLY");
1350   TVirtualMC::GetMC()->Gspos("USDB",8,"UTI4", xpos,-ypos, zpos,        0,"ONLY");
1351   // Upper bar (aluminum)
1352   parBOX[0] = 95.00/2.0;
1353   parBOX[1] =  1.20/2.0;
1354   parBOX[2] =  3.00/2.0;
1355   TVirtualMC::GetMC()->Gsvolu("USD7","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1356   xpos       =   0.0;
1357   ypos       =   fgkClength[5][2]/2.0;
1358   zpos       =   fgkSheight/2.0 - fgkSMpltT  - 3.00/2.0;
1359   TVirtualMC::GetMC()->Gspos("USD7",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1360   TVirtualMC::GetMC()->Gspos("USD7",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1361   TVirtualMC::GetMC()->Gspos("USD7",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1362   TVirtualMC::GetMC()->Gspos("USD7",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1363   TVirtualMC::GetMC()->Gspos("USD7",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1364   TVirtualMC::GetMC()->Gspos("USD7",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1365   TVirtualMC::GetMC()->Gspos("USD7",7,"UTI4", xpos, ypos, zpos,        0,"ONLY");
1366   TVirtualMC::GetMC()->Gspos("USD7",8,"UTI4", xpos,-ypos, zpos,        0,"ONLY");
1367   // Lower bar (aluminum)
1368   parBOX[0] = 90.22/2.0;
1369   parBOX[1] =  1.20/2.0;
1370   parBOX[2] =  1.74/2.0;
1371   TVirtualMC::GetMC()->Gsvolu("USD8","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1372   xpos       =   0.0;
1373   ypos       =   fgkClength[5][2]/2.0 - 0.1;
1374   zpos       =  -fgkSheight/2.0 + fgkSMpltT + 2.27;
1375   TVirtualMC::GetMC()->Gspos("USD8",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1376   TVirtualMC::GetMC()->Gspos("USD8",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1377   TVirtualMC::GetMC()->Gspos("USD8",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1378   TVirtualMC::GetMC()->Gspos("USD8",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1379   TVirtualMC::GetMC()->Gspos("USD8",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1380   TVirtualMC::GetMC()->Gspos("USD8",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1381   TVirtualMC::GetMC()->Gspos("USD8",7,"UTI4", xpos, ypos, zpos,        0,"ONLY");
1382   TVirtualMC::GetMC()->Gspos("USD8",8,"UTI4", xpos,-ypos, zpos,        0,"ONLY");
1383   // Lower bar (aluminum)
1384   parBOX[0] = 82.60/2.0;
1385   parBOX[1] =  1.20/2.0;
1386   parBOX[2] =  1.40/2.0;
1387   TVirtualMC::GetMC()->Gsvolu("USD9","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1388   xpos       =   0.0;
1389   ypos       =   fgkClength[5][2]/2.0;
1390   zpos       =  -fgkSheight/2.0 + fgkSMpltT + 1.40/2.0;
1391   TVirtualMC::GetMC()->Gspos("USD9",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1392   TVirtualMC::GetMC()->Gspos("USD9",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1393   TVirtualMC::GetMC()->Gspos("USD9",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1394   TVirtualMC::GetMC()->Gspos("USD9",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1395   TVirtualMC::GetMC()->Gspos("USD9",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1396   TVirtualMC::GetMC()->Gspos("USD9",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1397   TVirtualMC::GetMC()->Gspos("USD9",7,"UTI4", xpos, ypos, zpos,        0,"ONLY");
1398   TVirtualMC::GetMC()->Gspos("USD9",8,"UTI4", xpos,-ypos, zpos,        0,"ONLY");
1399   // Front sheet (aluminum)
1400   parTRP[ 0] =   0.10/2.0;
1401   parTRP[ 1] =   0.0;
1402   parTRP[ 2] =   0.0;
1403   parTRP[ 3] =  74.50/2.0;
1404   parTRP[ 4] =  31.70/2.0;
1405   parTRP[ 5] =  44.00/2.0;
1406   parTRP[ 6] =  -5.0;
1407   parTRP[ 7] =  74.50/2.0;
1408   parTRP[ 8] =  31.70/2.0;
1409   parTRP[ 9] =  44.00/2.0;
1410   parTRP[10] =  -5.0;
1411   TVirtualMC::GetMC()->Gsvolu("USDF","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1412   xpos       = -32.0;
1413   ypos       =   fgkClength[5][2]/2.0 + 1.20/2.0 + 0.10/2.0;
1414   zpos       =   0.0;
1415   TVirtualMC::GetMC()->Gspos("USDF",1,"UTI1", xpos, ypos, zpos,matrix[2],"ONLY");
1416   TVirtualMC::GetMC()->Gspos("USDF",2,"UTI1", xpos,-ypos, zpos,matrix[2],"ONLY");
1417   TVirtualMC::GetMC()->Gspos("USDF",3,"UTI2", xpos, ypos, zpos,matrix[2],"ONLY");
1418   TVirtualMC::GetMC()->Gspos("USDF",4,"UTI2", xpos,-ypos, zpos,matrix[2],"ONLY");
1419   TVirtualMC::GetMC()->Gspos("USDF",5,"UTI3", xpos, ypos, zpos,matrix[2],"ONLY");
1420   TVirtualMC::GetMC()->Gspos("USDF",6,"UTI3", xpos,-ypos, zpos,matrix[2],"ONLY");
1421   TVirtualMC::GetMC()->Gspos("USDF",7,"UTI4", xpos, ypos, zpos,matrix[2],"ONLY");
1422   TVirtualMC::GetMC()->Gspos("USDF",8,"UTI4", xpos,-ypos, zpos,matrix[2],"ONLY");
1423
1424   //
1425   // The flat frame in front of the chambers
1426   //
1427
1428   // The envelope volume (aluminum)
1429   parTRD[0]  =  90.00/2.0 - 0.1;
1430   parTRD[1]  = 114.00/2.0 - 0.1;
1431   parTRD[2]  =   1.50/2.0;
1432   parTRD[3]  =  70.30/2.0;
1433   TVirtualMC::GetMC()->Gsvolu("USCB","TRD1",idtmed[1301-1],parTRD,kNparTRD);
1434   // Empty spaces (air)
1435   parTRD[0]  =  87.00/2.0;
1436   parTRD[1]  =  10.00/2.0;
1437   parTRD[2]  =   1.50/2.0;
1438   parTRD[3]  =  26.35/2.0;
1439   TVirtualMC::GetMC()->Gsvolu("USC1","TRD1",idtmed[1302-1],parTRD,kNparTRD);
1440   xpos       =  0.0;
1441   ypos       =  0.0;
1442   zpos       = 26.35/2.0 - 70.3/2.0;
1443   TVirtualMC::GetMC()->Gspos("USC1",1,"USCB",xpos,ypos,zpos,0,"ONLY");
1444   // Empty spaces (air)
1445   parTRD[0]  =  10.00/2.0;
1446   parTRD[1]  = 111.00/2.0;
1447   parTRD[2]  =   1.50/2.0;
1448   parTRD[3]  =  35.05/2.0;
1449   TVirtualMC::GetMC()->Gsvolu("USC2","TRD1",idtmed[1302-1],parTRD,kNparTRD);
1450   xpos       =  0.0;
1451   ypos       =  0.0;
1452   zpos       = 70.3/2.0 - 35.05/2.0;
1453   TVirtualMC::GetMC()->Gspos("USC2",1,"USCB",xpos,ypos,zpos,0,"ONLY");
1454   // Empty spaces (air)
1455   parTRP[ 0] =   1.50/2.0;
1456   parTRP[ 1] =   0.0;
1457   parTRP[ 2] =   0.0;
1458   parTRP[ 3] =  37.60/2.0;
1459   parTRP[ 4] =  63.90/2.0;
1460   parTRP[ 5] =   8.86/2.0;
1461   parTRP[ 6] =  16.0;
1462   parTRP[ 7] =  37.60/2.0;
1463   parTRP[ 8] =  63.90/2.0;
1464   parTRP[ 9] =   8.86/2.0;
1465   parTRP[10] =  16.0;
1466   TVirtualMC::GetMC()->Gsvolu("USC3","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1467   xpos       = -30.5;
1468   ypos       =   0.0;
1469   zpos       =  -2.0;
1470   TVirtualMC::GetMC()->Gspos("USC3",1,"USCB", xpos, ypos, zpos,matrix[4],"ONLY");
1471   TVirtualMC::GetMC()->Gspos("USC3",2,"USCB",-xpos, ypos, zpos,matrix[5],"ONLY");
1472   xpos       =   0.0;
1473   ypos       =   fgkClength[5][2]/2.0 + fgkClength[5][1] + fgkClength[5][0];
1474   zpos       =   0.0;
1475   TVirtualMC::GetMC()->Gspos("USCB",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1476   TVirtualMC::GetMC()->Gspos("USCB",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1477   TVirtualMC::GetMC()->Gspos("USCB",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1478   TVirtualMC::GetMC()->Gspos("USCB",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1479   TVirtualMC::GetMC()->Gspos("USCB",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1480   TVirtualMC::GetMC()->Gspos("USCB",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1481   TVirtualMC::GetMC()->Gspos("USCB",7,"UTI4", xpos, ypos, zpos,        0,"ONLY");
1482   TVirtualMC::GetMC()->Gspos("USCB",8,"UTI4", xpos,-ypos, zpos,        0,"ONLY");
1483   // Upper bar (aluminum)
1484   parBOX[0] = 95.00/2.0;
1485   parBOX[1] =  1.50/2.0;
1486   parBOX[2] =  3.00/2.0;
1487   TVirtualMC::GetMC()->Gsvolu("USC4","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1488   xpos       =   0.0;
1489   ypos       =   fgkClength[5][2]/2.0 + fgkClength[5][1] + fgkClength[5][0];
1490   zpos       =   fgkSheight/2.0 - fgkSMpltT - 3.00/2.0;
1491   TVirtualMC::GetMC()->Gspos("USC4",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1492   TVirtualMC::GetMC()->Gspos("USC4",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1493   TVirtualMC::GetMC()->Gspos("USC4",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1494   TVirtualMC::GetMC()->Gspos("USC4",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1495   TVirtualMC::GetMC()->Gspos("USC4",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1496   TVirtualMC::GetMC()->Gspos("USC4",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1497   TVirtualMC::GetMC()->Gspos("USC4",7,"UTI4", xpos, ypos, zpos,        0,"ONLY");
1498   TVirtualMC::GetMC()->Gspos("USC4",8,"UTI4", xpos,-ypos, zpos,        0,"ONLY");
1499   // Lower bar (aluminum)
1500   parBOX[0] = 90.22/2.0;
1501   parBOX[1] =  1.50/2.0;
1502   parBOX[2] =  2.00/2.0;
1503   TVirtualMC::GetMC()->Gsvolu("USC5","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1504   xpos       =   0.0;
1505   ypos       =   fgkClength[5][2]/2.0 + fgkClength[5][1] + fgkClength[5][0];
1506   zpos       =  -fgkSheight/2.0 + fgkSMpltT + 2.60;
1507   TVirtualMC::GetMC()->Gspos("USC5",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1508   TVirtualMC::GetMC()->Gspos("USC5",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1509   TVirtualMC::GetMC()->Gspos("USC5",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1510   TVirtualMC::GetMC()->Gspos("USC5",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1511   TVirtualMC::GetMC()->Gspos("USC5",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1512   TVirtualMC::GetMC()->Gspos("USC5",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1513   TVirtualMC::GetMC()->Gspos("USC5",7,"UTI4", xpos, ypos, zpos,        0,"ONLY");
1514   TVirtualMC::GetMC()->Gspos("USC5",8,"UTI4", xpos,-ypos, zpos,        0,"ONLY");
1515   // Lower bar (aluminum)
1516   parBOX[0] = 82.60/2.0;
1517   parBOX[1] =  1.50/2.0;
1518   parBOX[2] =  1.60/2.0;
1519   TVirtualMC::GetMC()->Gsvolu("USC6","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1520   xpos       =   0.0;
1521   ypos       =   fgkClength[5][2]/2.0 + fgkClength[5][1] + fgkClength[5][0];
1522   zpos       =  -fgkSheight/2.0 + fgkSMpltT + 1.60/2.0;
1523   TVirtualMC::GetMC()->Gspos("USC6",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1524   TVirtualMC::GetMC()->Gspos("USC6",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1525   TVirtualMC::GetMC()->Gspos("USC6",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1526   TVirtualMC::GetMC()->Gspos("USC6",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1527   TVirtualMC::GetMC()->Gspos("USC6",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1528   TVirtualMC::GetMC()->Gspos("USC6",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1529   TVirtualMC::GetMC()->Gspos("USC6",7,"UTI4", xpos, ypos, zpos,        0,"ONLY");
1530   TVirtualMC::GetMC()->Gspos("USC6",8,"UTI4", xpos,-ypos, zpos,        0,"ONLY");
1531
1532   //
1533   // The long corner ledges
1534   //
1535
1536   const Int_t   kNparSCL  =  3;
1537   Float_t parSCL[kNparSCL];
1538   const Int_t   kNparSCLb = 11;
1539   Float_t parSCLb[kNparSCLb];
1540
1541   // Upper ledges 
1542   // Thickness of the corner ledges
1543   const Float_t kSCLthkUa  =  0.6; 
1544   const Float_t kSCLthkUb  =  0.6; 
1545   // Width of the corner ledges
1546   const Float_t kSCLwidUa  =  3.2;
1547   const Float_t kSCLwidUb  =  4.8;
1548   // Position of the corner ledges
1549   const Float_t kSCLposxUa = 0.7;
1550   const Float_t kSCLposxUb = 3.3;
1551   const Float_t kSCLposzUa = 1.65;
1552   const Float_t kSCLposzUb = 0.3;
1553   // Vertical
1554   parSCL[0]  = kSCLthkUa /2.0;
1555   parSCL[1]  = fgkSlength/2.0;
1556   parSCL[2]  = kSCLwidUa /2.0;
1557   TVirtualMC::GetMC()->Gsvolu("USL1","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1558   xpos  =   fgkSwidth2/2.0 - fgkSMpltT - kSCLposxUa;
1559   ypos  =   0.0;
1560   zpos  =   fgkSheight/2.0 - fgkSMpltT - kSCLposzUa;
1561   TVirtualMC::GetMC()->Gspos("USL1",1,"UTI1", xpos,ypos,zpos,matrix[0],"ONLY");
1562   TVirtualMC::GetMC()->Gspos("USL1",3,"UTI4", xpos,ypos,zpos,matrix[0],"ONLY");
1563   xpos  = -xpos;
1564   TVirtualMC::GetMC()->Gspos("USL1",2,"UTI1", xpos,ypos,zpos,matrix[1],"ONLY");
1565   TVirtualMC::GetMC()->Gspos("USL1",4,"UTI4", xpos,ypos,zpos,matrix[1],"ONLY");
1566   // Horizontal
1567   parSCL[0]  = kSCLwidUb /2.0;
1568   parSCL[1]  = fgkSlength/2.0;
1569   parSCL[2]  = kSCLthkUb /2.0;
1570   TVirtualMC::GetMC()->Gsvolu("USL2","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1571   xpos  =   fgkSwidth2/2.0 - fgkSMpltT - kSCLposxUb;
1572   ypos  =   0.0;
1573   zpos  =   fgkSheight/2.0 - fgkSMpltT - kSCLposzUb; 
1574   TVirtualMC::GetMC()->Gspos("USL2",1,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1575   TVirtualMC::GetMC()->Gspos("USL2",3,"UTI2", xpos,ypos,zpos,        0,"ONLY");
1576   TVirtualMC::GetMC()->Gspos("USL2",5,"UTI3", xpos,ypos,zpos,        0,"ONLY");
1577   TVirtualMC::GetMC()->Gspos("USL2",7,"UTI4", xpos,ypos,zpos,        0,"ONLY");
1578   xpos  = -xpos;
1579   TVirtualMC::GetMC()->Gspos("USL2",2,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1580   TVirtualMC::GetMC()->Gspos("USL2",4,"UTI2", xpos,ypos,zpos,        0,"ONLY");
1581   TVirtualMC::GetMC()->Gspos("USL2",6,"UTI3", xpos,ypos,zpos,        0,"ONLY");
1582   TVirtualMC::GetMC()->Gspos("USL2",8,"UTI4", xpos,ypos,zpos,        0,"ONLY");
1583
1584   // Lower ledges 
1585   // Thickness of the corner ledges
1586   const Float_t kSCLthkLa  =  2.464; 
1587   const Float_t kSCLthkLb  =  1.0; 
1588   // Width of the corner ledges
1589   const Float_t kSCLwidLa  =  8.3;
1590   const Float_t kSCLwidLb  =  4.0;
1591   // Position of the corner ledges
1592   const Float_t kSCLposxLa = (3.0 * kSCLthkLb - kSCLthkLa) / 4.0 + 0.05;
1593   const Float_t kSCLposxLb = kSCLthkLb + kSCLwidLb/2.0 + 0.05;
1594   const Float_t kSCLposzLa = kSCLwidLa/2.0;
1595   const Float_t kSCLposzLb = kSCLthkLb/2.0;
1596   // Vertical
1597   // Trapezoidal shape
1598   parSCLb[ 0] = fgkSlength/2.0;
1599   parSCLb[ 1] = 0.0;
1600   parSCLb[ 2] = 0.0;
1601   parSCLb[ 3] = kSCLwidLa /2.0;
1602   parSCLb[ 4] = kSCLthkLb /2.0;
1603   parSCLb[ 5] = kSCLthkLa /2.0;
1604   parSCLb[ 6] = 5.0;
1605   parSCLb[ 7] = kSCLwidLa /2.0;
1606   parSCLb[ 8] = kSCLthkLb /2.0;
1607   parSCLb[ 9] = kSCLthkLa /2.0;
1608   parSCLb[10] = 5.0;
1609   TVirtualMC::GetMC()->Gsvolu("USL3","TRAP",idtmed[1301-1],parSCLb,kNparSCLb);
1610   xpos  =   fgkSwidth1/2.0 - fgkSMpltT - kSCLposxLa;
1611   ypos  =   0.0;
1612   zpos  = - fgkSheight/2.0 + fgkSMpltT + kSCLposzLa;
1613   TVirtualMC::GetMC()->Gspos("USL3",1,"UTI1", xpos,ypos,zpos,matrix[2],"ONLY");
1614   TVirtualMC::GetMC()->Gspos("USL3",3,"UTI2", xpos,ypos,zpos,matrix[2],"ONLY");
1615   TVirtualMC::GetMC()->Gspos("USL3",5,"UTI3", xpos,ypos,zpos,matrix[2],"ONLY");
1616   TVirtualMC::GetMC()->Gspos("USL3",7,"UTI4", xpos,ypos,zpos,matrix[2],"ONLY");
1617   xpos  = -xpos;
1618   TVirtualMC::GetMC()->Gspos("USL3",2,"UTI1", xpos,ypos,zpos,matrix[3],"ONLY");
1619   TVirtualMC::GetMC()->Gspos("USL3",4,"UTI2", xpos,ypos,zpos,matrix[3],"ONLY");
1620   TVirtualMC::GetMC()->Gspos("USL3",6,"UTI3", xpos,ypos,zpos,matrix[3],"ONLY");
1621   TVirtualMC::GetMC()->Gspos("USL3",8,"UTI4", xpos,ypos,zpos,matrix[3],"ONLY");
1622   // Horizontal part
1623   parSCL[0]  = kSCLwidLb /2.0;
1624   parSCL[1]  = fgkSlength/2.0;
1625   parSCL[2]  = kSCLthkLb /2.0;
1626   TVirtualMC::GetMC()->Gsvolu("USL4","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1627   xpos  =   fgkSwidth1/2.0 - fgkSMpltT - kSCLposxLb;
1628   ypos  =   0.0;
1629   zpos  = - fgkSheight/2.0 + fgkSMpltT + kSCLposzLb;
1630   TVirtualMC::GetMC()->Gspos("USL4",1,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1631   TVirtualMC::GetMC()->Gspos("USL4",3,"UTI2", xpos,ypos,zpos,        0,"ONLY");
1632   TVirtualMC::GetMC()->Gspos("USL4",5,"UTI3", xpos,ypos,zpos,        0,"ONLY");
1633   TVirtualMC::GetMC()->Gspos("USL4",7,"UTI4", xpos,ypos,zpos,        0,"ONLY");
1634   xpos  = -xpos;
1635   TVirtualMC::GetMC()->Gspos("USL4",2,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1636   TVirtualMC::GetMC()->Gspos("USL4",4,"UTI2", xpos,ypos,zpos,        0,"ONLY");
1637   TVirtualMC::GetMC()->Gspos("USL4",6,"UTI3", xpos,ypos,zpos,        0,"ONLY");
1638   TVirtualMC::GetMC()->Gspos("USL4",8,"UTI4", xpos,ypos,zpos,        0,"ONLY");
1639
1640   //
1641   // Aluminum plates in the front part of the super modules
1642   //
1643
1644   const Int_t kNparTrd = 4;
1645   Float_t parTrd[kNparTrd];
1646   parTrd[0] = fgkSwidth1/2.0 - 2.5;
1647   parTrd[1] = fgkSwidth2/2.0 - 2.5;
1648   parTrd[2] = fgkSMpltT /2.0;
1649   parTrd[3] = fgkSheight/2.0 - 1.0;
1650   TVirtualMC::GetMC()->Gsvolu("UTA1","TRD1",idtmed[1301-1],parTrd,kNparTrd);
1651   xpos      =  0.0;
1652   ypos      =  fgkSMpltT/2.0 - fgkFlength/2.0;
1653   zpos      = -0.5;
1654   TVirtualMC::GetMC()->Gspos("UTA1",1,"UTF1",xpos, ypos,zpos,        0,"ONLY");
1655   TVirtualMC::GetMC()->Gspos("UTA1",2,"UTF2",xpos,-ypos,zpos,        0,"ONLY");
1656
1657   const Int_t kNparPlt = 3;
1658   Float_t parPlt[kNparPlt];
1659   parPlt[0] =  0.0;
1660   parPlt[1] =  0.0;
1661   parPlt[2] =  0.0;
1662   TVirtualMC::GetMC()->Gsvolu("UTA2","BOX ",idtmed[1301-1],parPlt,0);
1663   xpos      =  0.0;
1664   ypos      =  0.0;
1665   zpos      =  fgkSheight/2.0 - fgkSMpltT/2.0;
1666   parPlt[0] = fgkSwidth2/2.0 - 0.2;
1667   parPlt[1] = fgkFlength/2.0;
1668   parPlt[2] = fgkSMpltT /2.0;
1669   TVirtualMC::GetMC()->Gsposp("UTA2",1,"UTF2",xpos,ypos,zpos
1670                     ,        0,"ONLY",parPlt,kNparPlt);
1671   xpos      = (fgkSwidth1 + fgkSwidth2)/4.0 - fgkSMpltT/2.0 - 0.0016;
1672   ypos      =  0.0;
1673   zpos      =  0.0;
1674   parPlt[0] = fgkSMpltT /2.0;
1675   parPlt[1] = fgkFlength/2.0;
1676   parPlt[2] = fgkSheight/2.0;
1677   TVirtualMC::GetMC()->Gsposp("UTA2",2,"UTF2", xpos,ypos,zpos
1678                     ,matrix[0],"ONLY",parPlt,kNparPlt);
1679   TVirtualMC::GetMC()->Gsposp("UTA2",3,"UTF2",-xpos,ypos,zpos
1680                     ,matrix[1],"ONLY",parPlt,kNparPlt);
1681
1682   // Additional aluminum bar
1683   parBOX[0] = 80.0/2.0;
1684   parBOX[1] =  1.0/2.0;
1685   parBOX[2] = 10.0/2.0;
1686   TVirtualMC::GetMC()->Gsvolu("UTA3","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1687   xpos      =  0.0;
1688   ypos      =  1.0/2.0 + fgkSMpltT - fgkFlength/2.0;
1689   zpos      =  fgkSheight/2.0 - 1.5 - 10.0/2.0;
1690   TVirtualMC::GetMC()->Gspos("UTA3",1,"UTF1", xpos, ypos, zpos,        0,"ONLY");
1691   TVirtualMC::GetMC()->Gspos("UTA3",2,"UTF2", xpos,-ypos, zpos,        0,"ONLY");
1692
1693 }
1694
1695 //_____________________________________________________________________________
1696 void AliTRDgeometry::CreateServices(Int_t *idtmed)
1697 {
1698   //
1699   // Create the geometry of the services
1700   //
1701   // Names of the TRD services volumina
1702   //
1703   //        UTC1    Cooling arterias (Al)
1704   //        UTC2    Cooling arterias (Water)
1705   //        UUxx    Volumes for the services at the chambers (Air)
1706   //        UMCM    Readout MCMs     (G10/Cu/Si)
1707   //        UDCS    DCSs boards      (G10/Cu)
1708   //        UTP1    Power bars       (Cu)
1709   //        UTCP    Cooling pipes    (Fe)
1710   //        UTCH    Cooling pipes    (Water)
1711   //        UTPL    Power lines      (Cu)
1712   //        UTGD    Gas distribution box (V2A)
1713   //
1714
1715   Int_t   ilayer = 0;
1716   Int_t   istack = 0;
1717
1718   Float_t xpos  = 0.0;
1719   Float_t ypos  = 0.0;
1720   Float_t zpos  = 0.0;
1721
1722   const Int_t kTag = 100;
1723   Char_t  cTagV[kTag];
1724
1725   const Int_t kNparBox  = 3;
1726   Float_t parBox[kNparBox];
1727
1728   const Int_t kNparTube = 3;
1729   Float_t parTube[kNparTube];
1730
1731   // Services inside the baby frame
1732   const Float_t kBBMdz = 223.0;
1733   const Float_t kBBSdz =   8.5;
1734
1735   // Services inside the back frame
1736   const Float_t kBFMdz = 118.0;
1737   const Float_t kBFSdz =   8.5;
1738
1739   // The rotation matrices
1740   const Int_t kNmatrix = 10;
1741   Int_t   matrix[kNmatrix];
1742   TVirtualMC::GetMC()->Matrix(matrix[0], 100.0,   0.0,  90.0,  90.0,  10.0,   0.0); // rotation around y-axis
1743   TVirtualMC::GetMC()->Matrix(matrix[1],  80.0,   0.0,  90.0,  90.0,  10.0, 180.0); // rotation around y-axis
1744   TVirtualMC::GetMC()->Matrix(matrix[2],   0.0,   0.0,  90.0,  90.0,  90.0,   0.0);
1745   TVirtualMC::GetMC()->Matrix(matrix[3], 180.0,   0.0,  90.0,  90.0,  90.0, 180.0);
1746   TVirtualMC::GetMC()->Matrix(matrix[4],  90.0,   0.0,   0.0,   0.0,  90.0,  90.0);
1747   TVirtualMC::GetMC()->Matrix(matrix[5], 100.0,   0.0,  90.0, 270.0,  10.0,   0.0);
1748   TVirtualMC::GetMC()->Matrix(matrix[6],  80.0,   0.0,  90.0, 270.0,  10.0, 180.0);
1749   TVirtualMC::GetMC()->Matrix(matrix[7],  90.0,  10.0,  90.0, 100.0,   0.0,   0.0); // rotation around z-axis
1750   TVirtualMC::GetMC()->Matrix(matrix[8],  90.0, 350.0,  90.0,  80.0,   0.0,   0.0); // rotation around z-axis
1751   TVirtualMC::GetMC()->Matrix(matrix[9],  90.0,  90.0,  90.0, 180.0,   0.0,   0.0); // rotation around z-axis
1752     
1753   //
1754   // The cooling arterias
1755   //
1756
1757   // Width of the cooling arterias
1758   const Float_t kCOLwid  =  0.8; 
1759   // Height of the cooling arterias
1760   const Float_t kCOLhgt  =  6.5;
1761   // Positioning of the cooling 
1762   const Float_t kCOLposx =  1.0;
1763   const Float_t kCOLposz = -1.2;
1764   // Thickness of the walls of the cooling arterias
1765   const Float_t kCOLthk  =  0.1;
1766   const Int_t   kNparCOL =  3;
1767   Float_t parCOL[kNparCOL];
1768   parCOL[0] = 0.0;
1769   parCOL[1] = 0.0;
1770   parCOL[2] = 0.0;
1771   TVirtualMC::GetMC()->Gsvolu("UTC1","BOX ",idtmed[1308-1],parCOL,0);
1772   TVirtualMC::GetMC()->Gsvolu("UTC3","BOX ",idtmed[1308-1],parCOL,0);
1773   parCOL[0] =  kCOLwid/2.0 - kCOLthk;
1774   parCOL[1] = -1.0;
1775   parCOL[2] =  kCOLhgt/2.0 - kCOLthk;
1776   TVirtualMC::GetMC()->Gsvolu("UTC2","BOX ",idtmed[1314-1],parCOL,kNparCOL);
1777   TVirtualMC::GetMC()->Gsvolu("UTC4","BOX ",idtmed[1314-1],parCOL,kNparCOL);
1778
1779   xpos  = 0.0;
1780   ypos  = 0.0;
1781   zpos  = 0.0;
1782   TVirtualMC::GetMC()->Gspos("UTC2",1,"UTC1", xpos,ypos,zpos,0,"ONLY");
1783   TVirtualMC::GetMC()->Gspos("UTC4",1,"UTC3", xpos,ypos,zpos,0,"ONLY");
1784
1785   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1786
1787     // Along the chambers
1788     xpos      = fgkCwidth[ilayer]/2.0 + kCOLwid/2.0 + kCOLposx;
1789     ypos      = 0.0;
1790     zpos      = fgkVrocsm + fgkSMpltT - fgkCalZpos 
1791               + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1792               + ilayer * (fgkCH + fgkVspace);
1793     parCOL[0] = kCOLwid   /2.0;
1794     parCOL[1] = fgkSlength/2.0;
1795     parCOL[2] = kCOLhgt   /2.0;
1796     TVirtualMC::GetMC()->Gsposp("UTC1",ilayer           ,"UTI1", xpos,ypos,zpos
1797                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1798     TVirtualMC::GetMC()->Gsposp("UTC1",ilayer+   kNlayer,"UTI1",-xpos,ypos,zpos
1799                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1800     TVirtualMC::GetMC()->Gsposp("UTC1",ilayer+ 6*kNlayer,"UTI2", xpos,ypos,zpos
1801                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1802     TVirtualMC::GetMC()->Gsposp("UTC1",ilayer+ 7*kNlayer,"UTI2",-xpos,ypos,zpos
1803                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1804     TVirtualMC::GetMC()->Gsposp("UTC1",ilayer+ 8*kNlayer,"UTI3", xpos,ypos,zpos
1805                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1806     TVirtualMC::GetMC()->Gsposp("UTC1",ilayer+ 9*kNlayer,"UTI3",-xpos,ypos,zpos
1807                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1808     TVirtualMC::GetMC()->Gsposp("UTC1",ilayer+10*kNlayer,"UTI4", xpos,ypos,zpos
1809                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1810     TVirtualMC::GetMC()->Gsposp("UTC1",ilayer+11*kNlayer,"UTI4",-xpos,ypos,zpos
1811                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1812
1813     // Front of supermodules
1814     xpos      = fgkCwidth[ilayer]/2.0 + kCOLwid/2.0 + kCOLposx;
1815     ypos      = 0.0;
1816     zpos      = fgkVrocsm + fgkSMpltT - fgkCalZpos 
1817               + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1818               + ilayer * (fgkCH + fgkVspace);
1819     parCOL[0] = kCOLwid   /2.0;
1820     parCOL[1] = fgkFlength/2.0;
1821     parCOL[2] = kCOLhgt   /2.0;
1822     TVirtualMC::GetMC()->Gsposp("UTC3",ilayer+2*kNlayer,"UTF1", xpos,ypos,zpos
1823                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1824     TVirtualMC::GetMC()->Gsposp("UTC3",ilayer+3*kNlayer,"UTF1",-xpos,ypos,zpos
1825                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1826     TVirtualMC::GetMC()->Gsposp("UTC3",ilayer+4*kNlayer,"UTF2", xpos,ypos,zpos
1827                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1828     TVirtualMC::GetMC()->Gsposp("UTC3",ilayer+5*kNlayer,"UTF2",-xpos,ypos,zpos
1829                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1830
1831   }
1832
1833   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1834
1835     // In baby frame
1836     xpos      = fgkCwidth[ilayer]/2.0 + kCOLwid/2.0 + kCOLposx - 2.5;
1837     ypos      = kBBSdz/2.0 - kBBMdz/2.0;
1838     zpos      = fgkVrocsm + fgkSMpltT - fgkCalZpos 
1839               + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1840               + ilayer * (fgkCH + fgkVspace);
1841     parCOL[0] = kCOLwid/2.0;
1842     parCOL[1] = kBBSdz /2.0;
1843     parCOL[2] = kCOLhgt/2.0;
1844     TVirtualMC::GetMC()->Gsposp("UTC3",ilayer+6*kNlayer,"BBTRD", xpos, ypos, zpos
1845                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1846     TVirtualMC::GetMC()->Gsposp("UTC3",ilayer+7*kNlayer,"BBTRD",-xpos, ypos, zpos
1847                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1848
1849   }
1850
1851   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1852
1853     // In back frame
1854     xpos      = fgkCwidth[ilayer]/2.0 + kCOLwid/2.0 + kCOLposx - 0.3;
1855     ypos      = -kBFSdz/2.0 + kBFMdz/2.0;
1856     zpos      = fgkVrocsm + fgkSMpltT - fgkCalZpos 
1857               + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1858               + ilayer * (fgkCH + fgkVspace);
1859     parCOL[0] = kCOLwid/2.0;
1860     parCOL[1] = kBFSdz /2.0;
1861     parCOL[2] = kCOLhgt/2.0;
1862     TVirtualMC::GetMC()->Gsposp("UTC3",ilayer+6*kNlayer,"BFTRD", xpos,ypos,zpos
1863                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1864     TVirtualMC::GetMC()->Gsposp("UTC3",ilayer+7*kNlayer,"BFTRD",-xpos,ypos,zpos
1865                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1866
1867   }
1868
1869   // The upper most layer
1870   // Along the chambers
1871   xpos      = fgkCwidth[5]/2.0 - kCOLhgt/2.0 - 1.3;
1872   ypos      = 0.0;
1873   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1874   parCOL[0] = kCOLwid   /2.0;
1875   parCOL[1] = fgkSlength/2.0;
1876   parCOL[2] = kCOLhgt   /2.0;
1877   TVirtualMC::GetMC()->Gsposp("UTC1",6           ,"UTI1", xpos,ypos,zpos
1878                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1879   TVirtualMC::GetMC()->Gsposp("UTC1",6+   kNlayer,"UTI1",-xpos,ypos,zpos
1880                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1881   TVirtualMC::GetMC()->Gsposp("UTC1",6+ 6*kNlayer,"UTI2", xpos,ypos,zpos
1882                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1883   TVirtualMC::GetMC()->Gsposp("UTC1",6+ 7*kNlayer,"UTI2",-xpos,ypos,zpos
1884                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1885   TVirtualMC::GetMC()->Gsposp("UTC1",6+ 8*kNlayer,"UTI3", xpos,ypos,zpos
1886                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1887   TVirtualMC::GetMC()->Gsposp("UTC1",6+ 9*kNlayer,"UTI3",-xpos,ypos,zpos
1888                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1889   TVirtualMC::GetMC()->Gsposp("UTC1",6+10*kNlayer,"UTI4", xpos,ypos,zpos
1890                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1891   TVirtualMC::GetMC()->Gsposp("UTC1",6+11*kNlayer,"UTI4",-xpos,ypos,zpos
1892                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1893   // Front of supermodules
1894   xpos      = fgkCwidth[5]/2.0 - kCOLhgt/2.0 - 1.3;
1895   ypos      = 0.0;
1896   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1897   parCOL[0] = kCOLwid   /2.0;
1898   parCOL[1] = fgkFlength/2.0;
1899   parCOL[2] = kCOLhgt   /2.0;
1900   TVirtualMC::GetMC()->Gsposp("UTC3",6+ 2*kNlayer,"UTF1", xpos,ypos,zpos
1901                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1902   TVirtualMC::GetMC()->Gsposp("UTC3",6+ 3*kNlayer,"UTF1",-xpos,ypos,zpos
1903                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1904   TVirtualMC::GetMC()->Gsposp("UTC3",6+ 4*kNlayer,"UTF2", xpos,ypos,zpos
1905                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1906   TVirtualMC::GetMC()->Gsposp("UTC3",6+ 5*kNlayer,"UTF2",-xpos,ypos,zpos
1907                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1908   // In baby frame
1909   xpos      = fgkCwidth[5]/2.0 - kCOLhgt/2.0 - 3.1;
1910   ypos      = kBBSdz/2.0 - kBBMdz/2.0;
1911   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1912   parCOL[0] = kCOLwid/2.0;
1913   parCOL[1] = kBBSdz /2.0;
1914   parCOL[2] = kCOLhgt/2.0;
1915   TVirtualMC::GetMC()->Gsposp("UTC3",6+6*kNlayer,"BBTRD", xpos, ypos, zpos
1916                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1917   TVirtualMC::GetMC()->Gsposp("UTC3",6+7*kNlayer,"BBTRD",-xpos, ypos, zpos
1918                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1919   // In back frame
1920   xpos      = fgkCwidth[5]/2.0 - kCOLhgt/2.0 - 1.3;
1921   ypos      = -kBFSdz/2.0 + kBFMdz/2.0;
1922   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1923   parCOL[0] = kCOLwid/2.0;
1924   parCOL[1] = kBFSdz /2.0;
1925   parCOL[2] = kCOLhgt/2.0;
1926   TVirtualMC::GetMC()->Gsposp("UTC3",6+6*kNlayer,"BFTRD", xpos,ypos,zpos
1927                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1928   TVirtualMC::GetMC()->Gsposp("UTC3",6+7*kNlayer,"BFTRD",-xpos,ypos,zpos
1929                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1930
1931   //
1932   // The power bus bars
1933   //
1934
1935   const Float_t kPWRwid  =  0.6;
1936   // Increase the height of the power bus bars to take into
1937   // account the material of additional cables, etc.
1938   const Float_t kPWRhgtA =  5.0 + 0.2;
1939   const Float_t kPWRhgtB =  5.0;
1940   const Float_t kPWRposx =  2.0;
1941   const Float_t kPWRposz =  0.1;
1942   const Int_t   kNparPWR =  3;
1943   Float_t parPWR[kNparPWR];
1944   parPWR[0] = 0.0;
1945   parPWR[1] = 0.0;
1946   parPWR[2] = 0.0;
1947   TVirtualMC::GetMC()->Gsvolu("UTP1","BOX ",idtmed[1325-1],parPWR,0);
1948   TVirtualMC::GetMC()->Gsvolu("UTP3","BOX ",idtmed[1325-1],parPWR,0);
1949   
1950   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1951
1952     // Along the chambers
1953     xpos      = fgkCwidth[ilayer]/2.0 + kPWRwid/2.0 + kPWRposx;
1954     ypos      = 0.0;
1955     zpos      = fgkVrocsm + fgkSMpltT - fgkCalZpos 
1956               + kPWRhgtA/2.0 - fgkSheight/2.0 + kPWRposz 
1957               + ilayer * (fgkCH + fgkVspace);
1958     parPWR[0] = kPWRwid   /2.0;
1959     parPWR[1] = fgkSlength/2.0;
1960     parPWR[2] = kPWRhgtA  /2.0;
1961     TVirtualMC::GetMC()->Gsposp("UTP1",ilayer           ,"UTI1", xpos,ypos,zpos
1962                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1963     TVirtualMC::GetMC()->Gsposp("UTP1",ilayer+   kNlayer,"UTI1",-xpos,ypos,zpos
1964                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1965     TVirtualMC::GetMC()->Gsposp("UTP1",ilayer+ 6*kNlayer,"UTI2", xpos,ypos,zpos
1966                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1967     TVirtualMC::GetMC()->Gsposp("UTP1",ilayer+ 7*kNlayer,"UTI2",-xpos,ypos,zpos
1968                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1969     TVirtualMC::GetMC()->Gsposp("UTP1",ilayer+ 8*kNlayer,"UTI3", xpos,ypos,zpos
1970                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1971     TVirtualMC::GetMC()->Gsposp("UTP1",ilayer+ 9*kNlayer,"UTI3",-xpos,ypos,zpos
1972                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1973     TVirtualMC::GetMC()->Gsposp("UTP1",ilayer+10*kNlayer,"UTI4", xpos,ypos,zpos
1974                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1975     TVirtualMC::GetMC()->Gsposp("UTP1",ilayer+11*kNlayer,"UTI4",-xpos,ypos,zpos
1976                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1977
1978     // Front of supermodule
1979     xpos      = fgkCwidth[ilayer]/2.0 + kPWRwid/2.0 + kPWRposx;
1980     ypos      = 0.0;
1981     zpos      = fgkVrocsm + fgkSMpltT - fgkCalZpos 
1982               + kPWRhgtA/2.0 - fgkSheight/2.0 + kPWRposz 
1983               + ilayer * (fgkCH + fgkVspace);
1984     parPWR[0] = kPWRwid   /2.0;
1985     parPWR[1] = fgkFlength/2.0;
1986     parPWR[2] = kPWRhgtA  /2.0;
1987     TVirtualMC::GetMC()->Gsposp("UTP3",ilayer+ 2*kNlayer,"UTF1", xpos,ypos,zpos
1988                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1989     TVirtualMC::GetMC()->Gsposp("UTP3",ilayer+ 3*kNlayer,"UTF1",-xpos,ypos,zpos
1990                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1991     TVirtualMC::GetMC()->Gsposp("UTP3",ilayer+ 4*kNlayer,"UTF2", xpos,ypos,zpos
1992                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1993     TVirtualMC::GetMC()->Gsposp("UTP3",ilayer+ 5*kNlayer,"UTF2",-xpos,ypos,zpos
1994                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1995
1996   }
1997
1998   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1999
2000     // In baby frame
2001     xpos      = fgkCwidth[ilayer]/2.0 + kPWRwid/2.0 + kPWRposx - 2.5;
2002     ypos      = kBBSdz/2.0 - kBBMdz/2.0;
2003     zpos      = fgkVrocsm + fgkSMpltT - fgkCalZpos 
2004               + kPWRhgtB/2.0 - fgkSheight/2.0 + kPWRposz 
2005               + ilayer * (fgkCH + fgkVspace);
2006     parPWR[0] = kPWRwid /2.0;
2007     parPWR[1] = kBBSdz  /2.0;
2008     parPWR[2] = kPWRhgtB/2.0;
2009     TVirtualMC::GetMC()->Gsposp("UTP3",ilayer+6*kNlayer,"BBTRD", xpos, ypos, zpos
2010                       ,matrix[0],"ONLY",parPWR,kNparPWR);
2011     TVirtualMC::GetMC()->Gsposp("UTP3",ilayer+7*kNlayer,"BBTRD",-xpos, ypos, zpos
2012                       ,matrix[1],"ONLY",parPWR,kNparPWR);
2013
2014   }
2015
2016   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
2017
2018     // In back frame
2019     xpos      = fgkCwidth[ilayer]/2.0 + kPWRwid/2.0 + kPWRposx - 0.3;
2020     ypos      = -kBFSdz/2.0 + kBFMdz/2.0;
2021     zpos      = fgkVrocsm + fgkSMpltT - fgkCalZpos 
2022               + kPWRhgtB/2.0 - fgkSheight/2.0 + kPWRposz 
2023               + ilayer * (fgkCH + fgkVspace);
2024     parPWR[0] = kPWRwid /2.0;
2025     parPWR[1] = kBFSdz  /2.0;
2026     parPWR[2] = kPWRhgtB/2.0;
2027     TVirtualMC::GetMC()->Gsposp("UTP3",ilayer+8*kNlayer,"BFTRD", xpos,ypos,zpos
2028                       ,matrix[0],"ONLY",parPWR,kNparPWR);
2029     TVirtualMC::GetMC()->Gsposp("UTP3",ilayer+9*kNlayer,"BFTRD",-xpos,ypos,zpos
2030                       ,matrix[1],"ONLY",parPWR,kNparPWR);
2031
2032   }
2033
2034   // The upper most layer
2035   // Along the chambers
2036   xpos      = fgkCwidth[5]/2.0 + kPWRhgtB/2.0 - 1.3;
2037   ypos      = 0.0;
2038   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
2039   parPWR[0] = kPWRwid   /2.0;
2040   parPWR[1] = fgkSlength/2.0;
2041   parPWR[2] = kPWRhgtB  /2.0 ;
2042   TVirtualMC::GetMC()->Gsposp("UTP1",6           ,"UTI1", xpos,ypos,zpos
2043                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2044   TVirtualMC::GetMC()->Gsposp("UTP1",6+   kNlayer,"UTI1",-xpos,ypos,zpos
2045                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2046   TVirtualMC::GetMC()->Gsposp("UTP1",6+ 6*kNlayer,"UTI2", xpos,ypos,zpos
2047                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2048   TVirtualMC::GetMC()->Gsposp("UTP1",6+ 7*kNlayer,"UTI2",-xpos,ypos,zpos
2049                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2050   TVirtualMC::GetMC()->Gsposp("UTP1",6+ 8*kNlayer,"UTI3", xpos,ypos,zpos
2051                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2052   TVirtualMC::GetMC()->Gsposp("UTP1",6+ 9*kNlayer,"UTI3",-xpos,ypos,zpos
2053                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2054   TVirtualMC::GetMC()->Gsposp("UTP1",6+10*kNlayer,"UTI4", xpos,ypos,zpos
2055                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2056   TVirtualMC::GetMC()->Gsposp("UTP1",6+11*kNlayer,"UTI4",-xpos,ypos,zpos
2057                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2058   // Front of supermodules
2059   xpos      = fgkCwidth[5]/2.0 + kPWRhgtB/2.0 - 1.3;
2060   ypos      = 0.0;
2061   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
2062   parPWR[0] = kPWRwid   /2.0;
2063   parPWR[1] = fgkFlength/2.0;
2064   parPWR[2] = kPWRhgtB  /2.0;
2065   TVirtualMC::GetMC()->Gsposp("UTP3",6+2*kNlayer,"UTF1", xpos,ypos,zpos
2066                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2067   TVirtualMC::GetMC()->Gsposp("UTP3",6+3*kNlayer,"UTF1",-xpos,ypos,zpos
2068                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2069   TVirtualMC::GetMC()->Gsposp("UTP3",6+4*kNlayer,"UTF2", xpos,ypos,zpos
2070                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2071   TVirtualMC::GetMC()->Gsposp("UTP3",6+5*kNlayer,"UTF2",-xpos,ypos,zpos
2072                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2073   // In baby frame
2074   xpos      = fgkCwidth[5]/2.0 + kPWRhgtB/2.0 - 3.0;
2075   ypos      = kBBSdz/2.0 - kBBMdz/2.0;
2076   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
2077   parPWR[0] = kPWRwid /2.0;
2078   parPWR[1] = kBBSdz  /2.0;
2079   parPWR[2] = kPWRhgtB/2.0;
2080   TVirtualMC::GetMC()->Gsposp("UTP3",6+6*kNlayer,"BBTRD", xpos, ypos, zpos
2081                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2082   TVirtualMC::GetMC()->Gsposp("UTP3",6+7*kNlayer,"BBTRD",-xpos, ypos, zpos
2083                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2084   // In back frame
2085   xpos      = fgkCwidth[5]/2.0 + kPWRhgtB/2.0 - 1.3;
2086   ypos      = -kBFSdz/2.0 + kBFMdz/2.0;
2087   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
2088   parPWR[0] = kPWRwid /2.0;
2089   parPWR[1] = kBFSdz  /2.0;
2090   parPWR[2] = kPWRhgtB/2.0;
2091   TVirtualMC::GetMC()->Gsposp("UTP3",6+8*kNlayer,"BFTRD", xpos,ypos,zpos
2092                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2093   TVirtualMC::GetMC()->Gsposp("UTP3",6+9*kNlayer,"BFTRD",-xpos,ypos,zpos
2094                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2095
2096   //
2097   // The gas tubes connecting the chambers in the super modules with holes
2098   // Material: Stainless steel
2099   //
2100
2101   // PHOS holes
2102   parTube[0] = 0.0;
2103   parTube[1] = 2.2/2.0;
2104   parTube[2] = fgkClength[5][2]/2.0 - fgkHspace/2.0;
2105   TVirtualMC::GetMC()->Gsvolu("UTG1","TUBE",idtmed[1308-1],parTube,kNparTube);
2106   parTube[0] = 0.0;
2107   parTube[1] = 2.1/2.0;
2108   parTube[2] = fgkClength[5][2]/2.0 - fgkHspace/2.0;
2109   TVirtualMC::GetMC()->Gsvolu("UTG2","TUBE",idtmed[1309-1],parTube,kNparTube);
2110   xpos  = 0.0;
2111   ypos  = 0.0;
2112   zpos  = 0.0;
2113   TVirtualMC::GetMC()->Gspos("UTG2",1,"UTG1",xpos,ypos,zpos,0,"ONLY");
2114   for (ilayer = 0; ilayer < kNlayer; ilayer++) { 
2115     xpos      = fgkCwidth[ilayer]/2.0 + kCOLwid/2.0 - 1.5;
2116     ypos      = 0.0;
2117     zpos      = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + 5.0 
2118               + ilayer * (fgkCH + fgkVspace);
2119     TVirtualMC::GetMC()->Gspos("UTG1",1+ilayer,"UTI3", xpos, ypos, zpos,matrix[4],"ONLY");
2120     TVirtualMC::GetMC()->Gspos("UTG1",7+ilayer,"UTI3",-xpos, ypos, zpos,matrix[4],"ONLY");
2121   }
2122   // Missing L4S4 chamber in sector 17
2123   parTube[0] = 0.0;
2124   parTube[1] = 2.2/2.0;
2125   parTube[2] = fgkClength[4][4]/2.0 - fgkHspace/2.0;
2126   TVirtualMC::GetMC()->Gsvolu("UTG3","TUBE",idtmed[1308-1],parTube,kNparTube);
2127   parTube[0] = 0.0;
2128   parTube[1] = 2.1/2.0;
2129   parTube[2] = fgkClength[4][4]/2.0 - fgkHspace/2.0;
2130   TVirtualMC::GetMC()->Gsvolu("UTG4","TUBE",idtmed[1309-1],parTube,kNparTube);
2131   xpos  = 0.0;
2132   ypos  = 0.0;
2133   zpos  = 0.0;
2134   TVirtualMC::GetMC()->Gspos("UTG4",1,"UTG3",xpos,ypos,zpos,0,"ONLY");
2135   xpos  = fgkCwidth[4]/2.0 + kCOLwid/2.0 - 1.5;
2136   ypos  = -fgkClength[4][0]/2.0 - fgkClength[4][1] - fgkClength[4][2]/2.0;
2137   zpos  = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + 5.0 + 4 * (fgkCH + fgkVspace);
2138   TVirtualMC::GetMC()->Gspos("UTG3",1,"UTI4", xpos, ypos, zpos,matrix[4],"ONLY");
2139   TVirtualMC::GetMC()->Gspos("UTG4",2,"UTI4",-xpos, ypos, zpos,matrix[4],"ONLY");
2140
2141   //
2142   // The volumes for the services at the chambers
2143   //
2144
2145   const Int_t kNparServ = 3;
2146   Float_t parServ[kNparServ];
2147
2148   for (istack = 0; istack < kNstack; istack++) {
2149     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
2150
2151       Int_t iDet = GetDetectorSec(ilayer,istack);
2152
2153       snprintf(cTagV,kTag,"UU%02d",iDet);
2154       parServ[0] = fgkCwidth[ilayer]         /2.0;
2155       parServ[1] = fgkClength[ilayer][istack]/2.0 - fgkHspace/2.0;
2156       parServ[2] = fgkCsvH                 /2.0;
2157       TVirtualMC::GetMC()->Gsvolu(cTagV,"BOX",idtmed[1302-1],parServ,kNparServ);
2158
2159     }
2160   }
2161
2162   //
2163   // The cooling pipes inside the service volumes
2164   //
2165
2166   // The cooling pipes
2167   parTube[0] =  0.0;
2168   parTube[1] =  0.0;
2169   parTube[2] =  0.0;
2170   TVirtualMC::GetMC()->Gsvolu("UTCP","TUBE",idtmed[1324-1],parTube,0);
2171   // The cooling water
2172   parTube[0] =  0.0;
2173   parTube[1] =  0.2/2.0;
2174   parTube[2] = -1.0;
2175   TVirtualMC::GetMC()->Gsvolu("UTCH","TUBE",idtmed[1314-1],parTube,kNparTube);
2176   // Water inside the cooling pipe
2177   xpos = 0.0;
2178   ypos = 0.0;
2179   zpos = 0.0;
2180   TVirtualMC::GetMC()->Gspos("UTCH",1,"UTCP",xpos,ypos,zpos,0,"ONLY");
2181
2182   // Position the cooling pipes in the mother volume
2183   for (istack = 0; istack < kNstack; istack++) {
2184     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
2185       Int_t   iDet    = GetDetectorSec(ilayer,istack);
2186       Int_t   iCopy   = GetDetector(ilayer,istack,0) * 100;
2187       Int_t   nMCMrow = GetRowMax(ilayer,istack,0);
2188       Float_t ySize   = (GetChamberLength(ilayer,istack) - 2.0*fgkRpadW) 
2189                       / ((Float_t) nMCMrow);
2190       snprintf(cTagV,kTag,"UU%02d",iDet);
2191       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
2192         xpos   = 0.0;
2193         ypos   = (0.5 + iMCMrow) * ySize 
2194                - fgkClength[ilayer][istack]/2.0 + fgkHspace/2.0;
2195         zpos   = 0.0 + 0.742/2.0;                 
2196         // The cooling pipes
2197         parTube[0] = 0.0;
2198         parTube[1] = 0.3/2.0; // Thickness of the cooling pipes
2199         parTube[2] = fgkCwidth[ilayer]/2.0;
2200         TVirtualMC::GetMC()->Gsposp("UTCP",iCopy+iMCMrow,cTagV,xpos,ypos,zpos
2201                           ,matrix[2],"ONLY",parTube,kNparTube);
2202       }
2203     }
2204   }
2205
2206   //
2207   // The power lines
2208   //
2209
2210   // The copper power lines
2211   parTube[0] = 0.0;
2212   parTube[1] = 0.0;
2213   parTube[2] = 0.0;
2214   TVirtualMC::GetMC()->Gsvolu("UTPL","TUBE",idtmed[1305-1],parTube,0);
2215
2216   // Position the power lines in the mother volume
2217   for (istack = 0; istack < kNstack; istack++) {
2218     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
2219       Int_t   iDet    = GetDetectorSec(ilayer,istack);
2220       Int_t   iCopy   = GetDetector(ilayer,istack,0) * 100;
2221       Int_t   nMCMrow = GetRowMax(ilayer,istack,0);
2222       Float_t ySize   = (GetChamberLength(ilayer,istack) - 2.0*fgkRpadW) 
2223                       / ((Float_t) nMCMrow);
2224       snprintf(cTagV,kTag,"UU%02d",iDet);
2225       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
2226         xpos       = 0.0;
2227         ypos       = (0.5 + iMCMrow) * ySize - 1.0 
2228                    - fgkClength[ilayer][istack]/2.0 + fgkHspace/2.0;
2229         zpos       = -0.4 + 0.742/2.0;
2230         parTube[0] = 0.0;
2231         parTube[1] = 0.2/2.0; // Thickness of the power lines
2232         parTube[2] = fgkCwidth[ilayer]/2.0;
2233         TVirtualMC::GetMC()->Gsposp("UTPL",iCopy+iMCMrow,cTagV,xpos,ypos,zpos
2234                           ,matrix[2],"ONLY",parTube,kNparTube);
2235       }
2236     }
2237   }
2238
2239   //
2240   // The MCMs
2241   //
2242
2243   const Float_t kMCMx    = 3.0;
2244   const Float_t kMCMy    = 3.0;
2245   const Float_t kMCMz    = 0.3;
2246   
2247   const Float_t kMCMpcTh = 0.1;
2248   const Float_t kMCMcuTh = 0.0025;
2249   const Float_t kMCMsiTh = 0.03;
2250   const Float_t kMCMcoTh = 0.04;
2251
2252   // The mother volume for the MCMs (air)
2253   const Int_t kNparMCM = 3;
2254   Float_t parMCM[kNparMCM];
2255   parMCM[0] = kMCMx   /2.0;
2256   parMCM[1] = kMCMy   /2.0;
2257   parMCM[2] = kMCMz   /2.0;
2258   TVirtualMC::GetMC()->Gsvolu("UMCM","BOX",idtmed[1302-1],parMCM,kNparMCM);
2259
2260   // The MCM carrier G10 layer
2261   parMCM[0] = kMCMx   /2.0;
2262   parMCM[1] = kMCMy   /2.0;
2263   parMCM[2] = kMCMpcTh/2.0;
2264   TVirtualMC::GetMC()->Gsvolu("UMC1","BOX",idtmed[1319-1],parMCM,kNparMCM);
2265   // The MCM carrier Cu layer
2266   parMCM[0] = kMCMx   /2.0;
2267   parMCM[1] = kMCMy   /2.0;
2268   parMCM[2] = kMCMcuTh/2.0;
2269   TVirtualMC::GetMC()->Gsvolu("UMC2","BOX",idtmed[1318-1],parMCM,kNparMCM);
2270   // The silicon of the chips
2271   parMCM[0] = kMCMx   /2.0;
2272   parMCM[1] = kMCMy   /2.0;
2273   parMCM[2] = kMCMsiTh/2.0;
2274   TVirtualMC::GetMC()->Gsvolu("UMC3","BOX",idtmed[1320-1],parMCM,kNparMCM);
2275   // The aluminum of the cooling plates
2276   parMCM[0] = kMCMx   /2.0;
2277   parMCM[1] = kMCMy   /2.0;
2278   parMCM[2] = kMCMcoTh/2.0;
2279   TVirtualMC::GetMC()->Gsvolu("UMC4","BOX",idtmed[1324-1],parMCM,kNparMCM);
2280
2281   // Put the MCM material inside the MCM mother volume
2282   xpos  =  0.0;
2283   ypos  =  0.0;
2284   zpos  = -kMCMz   /2.0 + kMCMpcTh/2.0;
2285   TVirtualMC::GetMC()->Gspos("UMC1",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2286   zpos +=  kMCMpcTh/2.0 + kMCMcuTh/2.0;
2287   TVirtualMC::GetMC()->Gspos("UMC2",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2288   zpos +=  kMCMcuTh/2.0 + kMCMsiTh/2.0;
2289   TVirtualMC::GetMC()->Gspos("UMC3",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2290   zpos +=  kMCMsiTh/2.0 + kMCMcoTh/2.0;
2291   TVirtualMC::GetMC()->Gspos("UMC4",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2292
2293   // Position the MCMs in the mother volume
2294   for (istack = 0; istack < kNstack; istack++) {
2295     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
2296       Int_t   iDet    = GetDetectorSec(ilayer,istack);
2297       Int_t   iCopy   = GetDetector(ilayer,istack,0) * 1000;
2298       Int_t   nMCMrow = GetRowMax(ilayer,istack,0);
2299       Float_t ySize   = (GetChamberLength(ilayer,istack) - 2.0*fgkRpadW)
2300                       / ((Float_t) nMCMrow);
2301       Int_t   nMCMcol = 8;
2302       Float_t xSize   = (GetChamberWidth(ilayer)         - 2.0*fgkCpadW)
2303                       / ((Float_t) nMCMcol + 6);             // Introduce 6 gaps
2304       Int_t   iMCM[8] = {  1,  2,  3,  5,  8,  9, 10, 12 };  // 0..7 MCM + 6 gap structure
2305       snprintf(cTagV,kTag,"UU%02d",iDet);
2306       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
2307         for (Int_t iMCMcol = 0; iMCMcol < nMCMcol; iMCMcol++) {
2308           xpos      = (0.5 + iMCM[iMCMcol]) * xSize + 1.0
2309                     - fgkCwidth[ilayer]/2.0;
2310           ypos      = (0.5 + iMCMrow) * ySize + 1.0
2311                     - fgkClength[ilayer][istack]/2.0 + fgkHspace/2.0;
2312           zpos      = -0.4 + 0.742/2.0;
2313           TVirtualMC::GetMC()->Gspos("UMCM",iCopy+iMCMrow*10+iMCMcol,cTagV
2314                            ,xpos,ypos,zpos,0,"ONLY");
2315           // Add two additional smaller cooling pipes on top of the MCMs
2316           // to mimic the meandering structure
2317           xpos      = (0.5 + iMCM[iMCMcol]) * xSize + 1.0
2318                     - fgkCwidth[ilayer]/2.0;
2319           ypos      = (0.5 + iMCMrow) * ySize
2320                     - fgkClength[ilayer][istack]/2.0 + fgkHspace/2.0;
2321           zpos      = 0.0 + 0.742/2.0;                 
2322           parTube[0] = 0.0;
2323           parTube[1] = 0.3/2.0; // Thickness of the cooling pipes
2324           parTube[2] = kMCMx/2.0;
2325           TVirtualMC::GetMC()->Gsposp("UTCP",iCopy+iMCMrow*10+iMCMcol+ 50,cTagV
2326                             ,xpos,ypos+1.0,zpos
2327                             ,matrix[2],"ONLY",parTube,kNparTube);
2328           TVirtualMC::GetMC()->Gsposp("UTCP",iCopy+iMCMrow*10+iMCMcol+500,cTagV
2329                             ,xpos,ypos+2.0,zpos
2330                             ,matrix[2],"ONLY",parTube,kNparTube);
2331
2332         }
2333       }
2334
2335     }
2336   }
2337
2338   //
2339   // The DCS boards
2340   //
2341
2342   const Float_t kDCSx    =  9.0;
2343   const Float_t kDCSy    = 14.5;
2344   const Float_t kDCSz    =  0.3;
2345   
2346   const Float_t kDCSpcTh =  0.15;
2347   const Float_t kDCScuTh =  0.01;
2348   const Float_t kDCScoTh =  0.04;
2349
2350   // The mother volume for the DCSs (air)
2351   const Int_t kNparDCS = 3;
2352   Float_t parDCS[kNparDCS];
2353   parDCS[0] = kDCSx   /2.0;
2354   parDCS[1] = kDCSy   /2.0;
2355   parDCS[2] = kDCSz   /2.0;
2356   TVirtualMC::GetMC()->Gsvolu("UDCS","BOX",idtmed[1302-1],parDCS,kNparDCS);
2357
2358   // The DCS carrier G10 layer
2359   parDCS[0] = kDCSx   /2.0;
2360   parDCS[1] = kDCSy   /2.0;
2361   parDCS[2] = kDCSpcTh/2.0;
2362   TVirtualMC::GetMC()->Gsvolu("UDC1","BOX",idtmed[1319-1],parDCS,kNparDCS);
2363   // The DCS carrier Cu layer
2364   parDCS[0] = kDCSx   /2.0;
2365   parDCS[1] = kDCSy   /2.0;
2366   parDCS[2] = kDCScuTh/2.0;
2367   TVirtualMC::GetMC()->Gsvolu("UDC2","BOX",idtmed[1318-1],parDCS,kNparDCS);
2368   // The aluminum of the cooling plates
2369   parDCS[0] = 5.0     /2.0;
2370   parDCS[1] = 5.0     /2.0;
2371   parDCS[2] = kDCScoTh/2.0;
2372   TVirtualMC::GetMC()->Gsvolu("UDC3","BOX",idtmed[1324-1],parDCS,kNparDCS);
2373
2374   // Put the DCS material inside the DCS mother volume
2375   xpos  =  0.0;
2376   ypos  =  0.0;
2377   zpos  = -kDCSz   /2.0 + kDCSpcTh/2.0;
2378   TVirtualMC::GetMC()->Gspos("UDC1",1,"UDCS",xpos,ypos,zpos,0,"ONLY");
2379   zpos +=  kDCSpcTh/2.0 + kDCScuTh/2.0;
2380   TVirtualMC::GetMC()->Gspos("UDC2",1,"UDCS",xpos,ypos,zpos,0,"ONLY");
2381   zpos +=  kDCScuTh/2.0 + kDCScoTh/2.0;
2382   TVirtualMC::GetMC()->Gspos("UDC3",1,"UDCS",xpos,ypos,zpos,0,"ONLY");
2383
2384   // Put the DCS board in the chamber services mother volume
2385   for (istack = 0; istack < kNstack; istack++) {
2386     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
2387       Int_t   iDet    = GetDetectorSec(ilayer,istack);
2388       Int_t   iCopy   = iDet + 1;
2389       xpos =  fgkCwidth[ilayer]/2.0 - 1.9 * (GetChamberLength(ilayer,istack) - 2.0*fgkRpadW) 
2390                                         / ((Float_t) GetRowMax(ilayer,istack,0));
2391       ypos =  0.05 * fgkClength[ilayer][istack];
2392       zpos =  kDCSz/2.0 - fgkCsvH/2.0;
2393       snprintf(cTagV,kTag,"UU%02d",iDet);
2394       TVirtualMC::GetMC()->Gspos("UDCS",iCopy,cTagV,xpos,ypos,zpos,0,"ONLY");
2395     }
2396   }
2397
2398   //
2399   // The ORI boards
2400   //
2401
2402   const Float_t kORIx    =  4.2;
2403   const Float_t kORIy    = 13.5;
2404   const Float_t kORIz    =  0.3;
2405   
2406   const Float_t kORIpcTh =  0.15;
2407   const Float_t kORIcuTh =  0.01;
2408   const Float_t kORIcoTh =  0.04;
2409
2410   // The mother volume for the ORIs (air)
2411   const Int_t kNparORI = 3;
2412   Float_t parORI[kNparORI];
2413   parORI[0] = kORIx   /2.0;
2414   parORI[1] = kORIy   /2.0;
2415   parORI[2] = kORIz   /2.0;
2416   TVirtualMC::GetMC()->Gsvolu("UORI","BOX",idtmed[1302-1],parORI,kNparORI);
2417
2418   // The ORI carrier G10 layer
2419   parORI[0] = kORIx   /2.0;
2420   parORI[1] = kORIy   /2.0;
2421   parORI[2] = kORIpcTh/2.0;
2422   TVirtualMC::GetMC()->Gsvolu("UOR1","BOX",idtmed[1319-1],parORI,kNparORI);
2423   // The ORI carrier Cu layer
2424   parORI[0] = kORIx   /2.0;
2425   parORI[1] = kORIy   /2.0;
2426   parORI[2] = kORIcuTh/2.0;
2427   TVirtualMC::GetMC()->Gsvolu("UOR2","BOX",idtmed[1318-1],parORI,kNparORI);
2428   // The aluminum of the cooling plates
2429   parORI[0] = kORIx   /2.0;
2430   parORI[1] = kORIy   /2.0;
2431   parORI[2] = kORIcoTh/2.0;
2432   TVirtualMC::GetMC()->Gsvolu("UOR3","BOX",idtmed[1324-1],parORI,kNparORI);
2433
2434   // Put the ORI material inside the ORI mother volume
2435   xpos  =  0.0;
2436   ypos  =  0.0;
2437   zpos  = -kORIz   /2.0 + kORIpcTh/2.0;
2438   TVirtualMC::GetMC()->Gspos("UOR1",1,"UORI",xpos,ypos,zpos,0,"ONLY");
2439   zpos +=  kORIpcTh/2.0 + kORIcuTh/2.0;
2440   TVirtualMC::GetMC()->Gspos("UOR2",1,"UORI",xpos,ypos,zpos,0,"ONLY");
2441   zpos +=  kORIcuTh/2.0 + kORIcoTh/2.0;
2442   TVirtualMC::GetMC()->Gspos("UOR3",1,"UORI",xpos,ypos,zpos,0,"ONLY");
2443
2444   // Put the ORI board in the chamber services mother volume
2445   for (istack = 0; istack < kNstack; istack++) {
2446     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
2447       Int_t   iDet    = GetDetectorSec(ilayer,istack);
2448       Int_t   iCopy   = iDet + 1;
2449       xpos =  fgkCwidth[ilayer]/2.0 - 1.92 * (GetChamberLength(ilayer,istack) - 2.0*fgkRpadW) 
2450                                         / ((Float_t) GetRowMax(ilayer,istack,0));
2451       ypos = -16.0;
2452       zpos =  kORIz/2.0 - fgkCsvH/2.0;
2453       snprintf(cTagV,kTag,"UU%02d",iDet);
2454       TVirtualMC::GetMC()->Gspos("UORI",iCopy      ,cTagV,xpos,ypos,zpos,0,"ONLY");
2455       xpos = -fgkCwidth[ilayer]/2.0 + 3.8 * (GetChamberLength(ilayer,istack) - 2.0*fgkRpadW) 
2456                                         / ((Float_t) GetRowMax(ilayer,istack,0));
2457       ypos = -16.0;
2458       zpos =  kORIz/2.0 - fgkCsvH/2.0;
2459       snprintf(cTagV,kTag,"UU%02d",iDet);
2460       TVirtualMC::GetMC()->Gspos("UORI",iCopy+kNdet,cTagV,xpos,ypos,zpos,0,"ONLY");
2461     }
2462   }
2463
2464   //
2465   // Services in front of the super module
2466   //
2467
2468   // Gas in-/outlet pipes (INOX)
2469   parTube[0] = 0.0;
2470   parTube[1] = 0.0;
2471   parTube[2] = 0.0;
2472   TVirtualMC::GetMC()->Gsvolu("UTG3","TUBE",idtmed[1308-1],parTube,0);
2473   // The gas inside the in-/outlet pipes (Xe)
2474   parTube[0] =  0.0;
2475   parTube[1] =  1.2/2.0;
2476   parTube[2] = -1.0;
2477   TVirtualMC::GetMC()->Gsvolu("UTG4","TUBE",idtmed[1309-1],parTube,kNparTube);
2478   xpos = 0.0;
2479   ypos = 0.0;
2480   zpos = 0.0;
2481   TVirtualMC::GetMC()->Gspos("UTG4",1,"UTG3",xpos,ypos,zpos,0,"ONLY");
2482   for (ilayer = 0; ilayer < kNlayer-1; ilayer++) { 
2483     xpos       = 0.0;
2484     ypos       = fgkClength[ilayer][2]/2.0 
2485                + fgkClength[ilayer][1] 
2486                + fgkClength[ilayer][0];
2487     zpos       = 9.0 - fgkSheight/2.0
2488                + ilayer * (fgkCH + fgkVspace);
2489     parTube[0] = 0.0;
2490     parTube[1] = 1.5/2.0;
2491     parTube[2] = fgkCwidth[ilayer]/2.0 - 2.5;
2492     TVirtualMC::GetMC()->Gsposp("UTG3",ilayer+1          ,"UTI1", xpos, ypos, zpos
2493                       ,matrix[2],"ONLY",parTube,kNparTube);
2494     TVirtualMC::GetMC()->Gsposp("UTG3",ilayer+1+1*kNlayer,"UTI1", xpos,-ypos, zpos
2495                       ,matrix[2],"ONLY",parTube,kNparTube);
2496     TVirtualMC::GetMC()->Gsposp("UTG3",ilayer+1+2*kNlayer,"UTI2", xpos, ypos, zpos
2497                       ,matrix[2],"ONLY",parTube,kNparTube);
2498     TVirtualMC::GetMC()->Gsposp("UTG3",ilayer+1+3*kNlayer,"UTI2", xpos,-ypos, zpos
2499                       ,matrix[2],"ONLY",parTube,kNparTube);
2500     TVirtualMC::GetMC()->Gsposp("UTG3",ilayer+1+4*kNlayer,"UTI3", xpos, ypos, zpos
2501                       ,matrix[2],"ONLY",parTube,kNparTube);
2502     TVirtualMC::GetMC()->Gsposp("UTG3",ilayer+1+5*kNlayer,"UTI3", xpos,-ypos, zpos
2503                       ,matrix[2],"ONLY",parTube,kNparTube);
2504     TVirtualMC::GetMC()->Gsposp("UTG3",ilayer+1+6*kNlayer,"UTI4", xpos, ypos, zpos
2505                       ,matrix[2],"ONLY",parTube,kNparTube);
2506     TVirtualMC::GetMC()->Gsposp("UTG3",ilayer+1+7*kNlayer,"UTI4", xpos,-ypos, zpos
2507                       ,matrix[2],"ONLY",parTube,kNparTube);
2508   }
2509
2510   // Gas distribution box
2511   parBox[0] = 14.50/2.0;
2512   parBox[1] =  4.52/2.0;
2513   parBox[2] =  5.00/2.0;
2514   TVirtualMC::GetMC()->Gsvolu("UTGD","BOX ",idtmed[1308-1],parBox,kNparBox);
2515   parBox[0] = 14.50/2.0;
2516   parBox[1] =  4.00/2.0;
2517   parBox[2] =  4.40/2.0;
2518   TVirtualMC::GetMC()->Gsvolu("UTGI","BOX ",idtmed[1309-1],parBox,kNparBox);
2519   parTube[0] = 0.0;
2520   parTube[1] = 4.0/2.0;
2521   parTube[2] = 8.0/2.0;
2522   TVirtualMC::GetMC()->Gsvolu("UTGT","TUBE",idtmed[1308-1],parTube,kNparTube);
2523   parTube[0] = 0.0;
2524   parTube[1] = 3.4/2.0;
2525   parTube[2] = 8.0/2.0;
2526   TVirtualMC::GetMC()->Gsvolu("UTGG","TUBE",idtmed[1309-1],parTube,kNparTube);
2527   xpos = 0.0;
2528   ypos = 0.0;
2529   zpos = 0.0;
2530   TVirtualMC::GetMC()->Gspos("UTGI",1,"UTGD",xpos,ypos,zpos,        0,"ONLY");
2531   TVirtualMC::GetMC()->Gspos("UTGG",1,"UTGT",xpos,ypos,zpos,        0,"ONLY");
2532   xpos = 0.0;
2533   ypos = 0.0;
2534   zpos = 0.0;
2535   TVirtualMC::GetMC()->Gspos("UTGD",1,"UTF1",xpos,ypos,zpos,        0,"ONLY");
2536   xpos =  -3.0;
2537   ypos =   0.0;
2538   zpos =   6.5;
2539   TVirtualMC::GetMC()->Gspos("UTGT",1,"UTF1",xpos,ypos,zpos,        0,"ONLY");
2540   xpos = -11.25;
2541   ypos =   0.0;
2542   zpos =   0.5;
2543   TVirtualMC::GetMC()->Gspos("UTGT",3,"UTF1",xpos,ypos,zpos,matrix[2],"ONLY");
2544   xpos =  11.25;
2545   ypos =   0.0;
2546   zpos =   0.5;
2547   TVirtualMC::GetMC()->Gspos("UTGT",5,"UTF1",xpos,ypos,zpos,matrix[2],"ONLY");
2548
2549   // Cooling manifolds
2550   parBox[0]  =  5.0/2.0;
2551   parBox[1]  = 23.0/2.0;
2552   parBox[2]  = 70.0/2.0;
2553   TVirtualMC::GetMC()->Gsvolu("UTCM","BOX ",idtmed[1302-1],parBox,kNparBox);
2554   parBox[0]  =  5.0/2.0;
2555   parBox[1]  =  5.0/2.0;
2556   parBox[2]  = 70.0/2.0;
2557   TVirtualMC::GetMC()->Gsvolu("UTCA","BOX ",idtmed[1308-1],parBox,kNparBox);
2558   parBox[0]  =  5.0/2.0 - 0.3;
2559   parBox[1]  =  5.0/2.0 - 0.3;
2560   parBox[2]  = 70.0/2.0 - 0.3;
2561   TVirtualMC::GetMC()->Gsvolu("UTCW","BOX ",idtmed[1314-1],parBox,kNparBox);
2562   xpos       =  0.0;
2563   ypos       =  0.0;
2564   zpos       =  0.0;
2565   TVirtualMC::GetMC()->Gspos("UTCW",1,"UTCA", xpos, ypos, zpos,        0,"ONLY");
2566   xpos       =  0.0;
2567   ypos       =  5.0/2.0 - 23.0/2.0;
2568   zpos       =  0.0;
2569   TVirtualMC::GetMC()->Gspos("UTCA",1,"UTCM", xpos, ypos, zpos,        0,"ONLY");
2570   parTube[0] =  0.0;
2571   parTube[1] =  3.0/2.0;
2572   parTube[2] = 18.0/2.0;
2573   TVirtualMC::GetMC()->Gsvolu("UTCO","TUBE",idtmed[1308-1],parTube,kNparTube);
2574   parTube[0] =  0.0;
2575   parTube[1] =  3.0/2.0 - 0.3;
2576   parTube[2] = 18.0/2.0;
2577   TVirtualMC::GetMC()->Gsvolu("UTCL","TUBE",idtmed[1314-1],parTube,kNparTube);
2578   xpos       =  0.0;
2579   ypos       =  0.0;
2580   zpos       =  0.0;
2581   TVirtualMC::GetMC()->Gspos("UTCL",1,"UTCO", xpos, ypos, zpos,        0,"ONLY");
2582   xpos       =  0.0;
2583   ypos       =  2.5;
2584   zpos       = -70.0/2.0 + 7.0;
2585   TVirtualMC::GetMC()->Gspos("UTCO",1,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2586   zpos      +=  7.0;
2587   TVirtualMC::GetMC()->Gspos("UTCO",2,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2588   zpos      +=  7.0;
2589   TVirtualMC::GetMC()->Gspos("UTCO",3,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2590   zpos      +=  7.0;
2591   TVirtualMC::GetMC()->Gspos("UTCO",4,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2592   zpos      +=  7.0;
2593   TVirtualMC::GetMC()->Gspos("UTCO",5,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2594   zpos      +=  7.0;
2595   TVirtualMC::GetMC()->Gspos("UTCO",6,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2596   zpos      +=  7.0;
2597   TVirtualMC::GetMC()->Gspos("UTCO",7,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2598   zpos      +=  7.0;
2599   TVirtualMC::GetMC()->Gspos("UTCO",8,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2600
2601   xpos = 40.0;
2602   ypos =  fgkFlength/2.0 - 23.0/2.0;
2603   zpos =  0.0;
2604   TVirtualMC::GetMC()->Gspos("UTCM",1,"UTF1", xpos, ypos, zpos,matrix[0],"ONLY");
2605   TVirtualMC::GetMC()->Gspos("UTCM",2,"UTF1",-xpos, ypos, zpos,matrix[1],"ONLY");
2606   TVirtualMC::GetMC()->Gspos("UTCM",3,"UTF2", xpos,-ypos, zpos,matrix[5],"ONLY");
2607   TVirtualMC::GetMC()->Gspos("UTCM",4,"UTF2",-xpos,-ypos, zpos,matrix[6],"ONLY");
2608
2609   // Power connection boards (Cu)
2610   parBox[0] =  0.5/2.0;
2611   parBox[1] = 15.0/2.0;
2612   parBox[2] =  7.0/2.0;
2613   TVirtualMC::GetMC()->Gsvolu("UTPC","BOX ",idtmed[1325-1],parBox,kNparBox);
2614   for (ilayer = 0; ilayer < kNlayer-1; ilayer++) { 
2615     xpos      = fgkCwidth[ilayer]/2.0 + kPWRwid/2.0;
2616     ypos      = 0.0;
2617     zpos      = fgkVrocsm + fgkSMpltT + kPWRhgtA/2.0 - fgkSheight/2.0 + kPWRposz 
2618               + (ilayer+1) * (fgkCH + fgkVspace);
2619     TVirtualMC::GetMC()->Gspos("UTPC",ilayer        ,"UTF1", xpos,ypos,zpos,matrix[0],"ONLY");
2620     TVirtualMC::GetMC()->Gspos("UTPC",ilayer+kNlayer,"UTF1",-xpos,ypos,zpos,matrix[1],"ONLY");
2621   }
2622   xpos      = fgkCwidth[5]/2.0 + kPWRhgtA/2.0 - 2.0;
2623   ypos      = 0.0;
2624   zpos      = fgkSheight/2.0 - fgkSMpltT - 2.0; 
2625   TVirtualMC::GetMC()->Gspos("UTPC",5        ,"UTF1", xpos,ypos,zpos,matrix[3],"ONLY");
2626   TVirtualMC::GetMC()->Gspos("UTPC",5+kNlayer,"UTF1",-xpos,ypos,zpos,matrix[3],"ONLY");
2627
2628   // Power connection panel (Al)
2629   parBox[0] = 60.0/2.0;
2630   parBox[1] = 10.0/2.0;
2631   parBox[2] =  3.0/2.0;
2632   TVirtualMC::GetMC()->Gsvolu("UTPP","BOX ",idtmed[1301-1],parBox,kNparBox);
2633   xpos      =  0.0;
2634   ypos      =  0.0;
2635   zpos      = 18.0;
2636   TVirtualMC::GetMC()->Gspos("UTPP",1,"UTF1", xpos,ypos,zpos,0,"ONLY");
2637
2638   //
2639   // Electronics boxes
2640   //
2641
2642   // Casing (INOX)
2643   parBox[0] = 60.0/2.0;
2644   parBox[1] = 10.0/2.0;
2645   parBox[2] =  6.0/2.0;
2646   TVirtualMC::GetMC()->Gsvolu("UTE1","BOX ",idtmed[1308-1],parBox,kNparBox);
2647   // Interior (air)
2648   parBox[0] = parBox[0] - 0.5;
2649   parBox[1] = parBox[1] - 0.5;
2650   parBox[2] = parBox[2] - 0.5;
2651   TVirtualMC::GetMC()->Gsvolu("UTE2","BOX ",idtmed[1302-1],parBox,kNparBox);
2652   xpos      = 0.0;
2653   ypos      = 0.0;
2654   zpos      = 0.0;
2655   TVirtualMC::GetMC()->Gspos("UTE2",1,"UTE1",xpos,ypos,zpos,0,"ONLY");
2656   xpos      = 0.0;
2657   ypos      =  fgkSlength/2.0 - 10.0/2.0 - 3.0;
2658   zpos      = -fgkSheight/2.0 +  6.0/2.0 + 1.0;
2659   TVirtualMC::GetMC()->Gspos("UTE1",1,"UTI1", xpos,ypos,zpos,0,"ONLY");
2660   TVirtualMC::GetMC()->Gspos("UTE1",2,"UTI2", xpos,ypos,zpos,0,"ONLY");
2661   TVirtualMC::GetMC()->Gspos("UTE1",3,"UTI3", xpos,ypos,zpos,0,"ONLY");
2662   TVirtualMC::GetMC()->Gspos("UTE1",4,"UTI4", xpos,ypos,zpos,0,"ONLY");
2663
2664   // Casing (INOX)
2665   parBox[0] = 50.0/2.0;
2666   parBox[1] = 15.0/2.0;
2667   parBox[2] = 20.0/2.0;
2668   TVirtualMC::GetMC()->Gsvolu("UTE3","BOX ",idtmed[1308-1],parBox,kNparBox);
2669   // Interior (air)
2670   parBox[0] = parBox[0] - 0.5;
2671   parBox[1] = parBox[1] - 0.5;
2672   parBox[2] = parBox[2] - 0.5;
2673   TVirtualMC::GetMC()->Gsvolu("UTE4","BOX ",idtmed[1302-1],parBox,kNparBox);
2674   xpos      = 0.0;
2675   ypos      = 0.0;
2676   zpos      = 0.0;
2677   TVirtualMC::GetMC()->Gspos("UTE4",1,"UTE3",xpos,ypos,zpos,0,"ONLY");
2678   xpos      = 0.0;
2679   ypos      = -fgkSlength/2.0 + 15.0/2.0 + 3.0;
2680   zpos      = -fgkSheight/2.0 + 20.0/2.0 + 1.0;
2681   TVirtualMC::GetMC()->Gspos("UTE3",1,"UTI1", xpos,ypos,zpos,0,"ONLY");
2682   TVirtualMC::GetMC()->Gspos("UTE3",2,"UTI2", xpos,ypos,zpos,0,"ONLY");
2683   TVirtualMC::GetMC()->Gspos("UTE3",3,"UTI3", xpos,ypos,zpos,0,"ONLY");
2684   TVirtualMC::GetMC()->Gspos("UTE3",4,"UTI4", xpos,ypos,zpos,0,"ONLY");
2685
2686   // Casing (INOX)
2687   parBox[0] = 20.0/2.0;
2688   parBox[1] =  7.0/2.0;
2689   parBox[2] = 20.0/2.0;
2690   TVirtualMC::GetMC()->Gsvolu("UTE5","BOX ",idtmed[1308-1],parBox,kNparBox);
2691   // Interior (air)
2692   parBox[0] = parBox[0] - 0.5;
2693   parBox[1] = parBox[1] - 0.5;
2694   parBox[2] = parBox[2] - 0.5;
2695   TVirtualMC::GetMC()->Gsvolu("UTE6","BOX ",idtmed[1302-1],parBox,kNparBox);
2696   xpos      = 0.0;
2697   ypos      = 0.0;
2698   zpos      = 0.0;
2699   TVirtualMC::GetMC()->Gspos("UTE6",1,"UTE5",xpos,ypos,zpos,0,"ONLY");
2700   xpos      = 20.0;
2701   ypos      = -fgkSlength/2.0 +  7.0/2.0 + 3.0;
2702   zpos      = 0.0;
2703   TVirtualMC::GetMC()->Gspos("UTE5",1,"UTI1", xpos,ypos,zpos,0,"ONLY");
2704   TVirtualMC::GetMC()->Gspos("UTE5",2,"UTI2", xpos,ypos,zpos,0,"ONLY");
2705   TVirtualMC::GetMC()->Gspos("UTE5",3,"UTI3", xpos,ypos,zpos,0,"ONLY");
2706   TVirtualMC::GetMC()->Gspos("UTE5",4,"UTI4", xpos,ypos,zpos,0,"ONLY");
2707   xpos      = -xpos;
2708   TVirtualMC::GetMC()->Gspos("UTE5",5,"UTI1", xpos,ypos,zpos,0,"ONLY");
2709   TVirtualMC::GetMC()->Gspos("UTE5",6,"UTI2", xpos,ypos,zpos,0,"ONLY");
2710   TVirtualMC::GetMC()->Gspos("UTE5",7,"UTI3", xpos,ypos,zpos,0,"ONLY");
2711   TVirtualMC::GetMC()->Gspos("UTE5",8,"UTI4", xpos,ypos,zpos,0,"ONLY");
2712
2713 }
2714
2715 //_____________________________________________________________________________
2716 void AliTRDgeometry::AssembleChamber(Int_t ilayer, Int_t istack)
2717 {
2718   //
2719   // Group volumes UA, UD, UF, UU into an assembly that defines the
2720   // alignable volume of a single readout chamber
2721   //
2722
2723   const Int_t kTag = 100;
2724   Char_t  cTagV[kTag];
2725   Char_t  cTagM[kTag];
2726
2727   Double_t xpos = 0.0;
2728   Double_t ypos = 0.0;
2729   Double_t zpos = 0.0;
2730
2731   Int_t idet = GetDetectorSec(ilayer,istack);
2732
2733   // Create the assembly for a given ROC
2734   snprintf(cTagM,kTag,"UT%02d",idet);
2735   TGeoVolume *roc = new TGeoVolumeAssembly(cTagM);
2736
2737   // Add the lower part of the chamber (aluminum frame),
2738   // including radiator and drift region
2739   xpos = 0.0;
2740   ypos = 0.0;
2741   zpos = fgkCraH/2.0 + fgkCdrH/2.0 - fgkCHsv/2.0;
2742   snprintf(cTagV,kTag,"UA%02d",idet);
2743   TGeoVolume *rocA = gGeoManager->GetVolume(cTagV);
2744   roc->AddNode(rocA,1,new TGeoTranslation(xpos,ypos,zpos));
2745
2746   // Add the additional aluminum ledges
2747   xpos = fgkCwidth[ilayer]/2.0 + fgkCalWmod/2.0;
2748   ypos = 0.0;
2749   zpos = fgkCraH + fgkCdrH - fgkCalZpos - fgkCalHmod/2.0 - fgkCHsv/2.0;
2750   snprintf(cTagV,kTag,"UZ%02d",idet);
2751   TGeoVolume *rocZ = gGeoManager->GetVolume(cTagV);
2752   roc->AddNode(rocZ,1,new TGeoTranslation( xpos,ypos,zpos));
2753   roc->AddNode(rocZ,2,new TGeoTranslation(-xpos,ypos,zpos));
2754
2755   // Add the additional wacosit ledges
2756   xpos = fgkCwidth[ilayer]/2.0 + fgkCwsW/2.0;
2757   ypos = 0.0;
2758   zpos = fgkCraH + fgkCdrH - fgkCwsH/2.0 - fgkCHsv/2.0;
2759   snprintf(cTagV,kTag,"UP%02d",idet);
2760   TGeoVolume *rocP = gGeoManager->GetVolume(cTagV);
2761   roc->AddNode(rocP,1,new TGeoTranslation( xpos,ypos,zpos));
2762   roc->AddNode(rocP,2,new TGeoTranslation(-xpos,ypos,zpos));
2763
2764   // Add the middle part of the chamber (G10 frame),
2765   // including amplification region
2766   xpos = 0.0;
2767   ypos = 0.0;
2768   zpos = fgkCamH/2.0 + fgkCraH + fgkCdrH - fgkCHsv/2.0;
2769   snprintf(cTagV,kTag,"UD%02d",idet);
2770   TGeoVolume *rocD = gGeoManager->GetVolume(cTagV);
2771   roc->AddNode(rocD,1,new TGeoTranslation(xpos,ypos,zpos));
2772
2773   // Add the upper part of the chamber (aluminum frame),
2774   // including back panel and FEE
2775   xpos = 0.0;
2776   ypos = 0.0;
2777   zpos = fgkCroH/2.0 + fgkCamH + fgkCraH + fgkCdrH - fgkCHsv/2.0;
2778   snprintf(cTagV,kTag,"UF%02d",idet);
2779   TGeoVolume *rocF = gGeoManager->GetVolume(cTagV);
2780   roc->AddNode(rocF,1,new TGeoTranslation(xpos,ypos,zpos));
2781
2782   // Add the volume with services on top of the back panel
2783   xpos = 0.0;
2784   ypos = 0.0;
2785   zpos = fgkCsvH/2.0 + fgkCroH + fgkCamH + fgkCraH + fgkCdrH - fgkCHsv/2.0;
2786   snprintf(cTagV,kTag,"UU%02d",idet);
2787   TGeoVolume *rocU = gGeoManager->GetVolume(cTagV);
2788   roc->AddNode(rocU,1,new TGeoTranslation(xpos,ypos,zpos));
2789
2790   // Place the ROC assembly into the super modules
2791   xpos = 0.0;
2792   ypos = 0.0;
2793   ypos  = fgkClength[ilayer][0] + fgkClength[ilayer][1] + fgkClength[ilayer][2]/2.0;
2794   for (Int_t ic = 0; ic < istack; ic++) {
2795     ypos -= fgkClength[ilayer][ic];
2796   }
2797   ypos -= fgkClength[ilayer][istack]/2.0;
2798   zpos  = fgkVrocsm + fgkSMpltT + fgkCHsv/2.0 - fgkSheight/2.0
2799         + ilayer * (fgkCH + fgkVspace);
2800   TGeoVolume *sm1 = gGeoManager->GetVolume("UTI1");
2801   TGeoVolume *sm2 = gGeoManager->GetVolume("UTI2");
2802   TGeoVolume *sm3 = gGeoManager->GetVolume("UTI3");
2803   TGeoVolume *sm4 = gGeoManager->GetVolume("UTI4");
2804   sm1->AddNode(roc,1,new TGeoTranslation(xpos,ypos,zpos));
2805   sm2->AddNode(roc,1,new TGeoTranslation(xpos,ypos,zpos));
2806   if (istack != 2) {
2807     // w/o middle stack
2808     sm3->AddNode(roc,1,new TGeoTranslation(xpos,ypos,zpos));
2809   }
2810   if (!((ilayer == 4) && (istack == 4))) {
2811     // Sector 17 w/o L4S4 chamber
2812     sm4->AddNode(roc,1,new TGeoTranslation(xpos,ypos,zpos));
2813   }
2814
2815
2816
2817 //_____________________________________________________________________________
2818 Bool_t AliTRDgeometry::RotateBack(Int_t det
2819                                 , const Double_t * const loc
2820                                 , Double_t *glb) const
2821 {
2822   //
2823   // Rotates a chambers to transform the corresponding local frame
2824   // coordinates <loc> into the coordinates of the ALICE restframe <glb>.
2825   //
2826
2827   Int_t   sector = GetSector(det);
2828   Float_t phi = 2.0 * TMath::Pi() /  (Float_t) fgkNsector * ((Float_t) sector + 0.5);
2829
2830   glb[0] = loc[0] * TMath::Cos(phi) - loc[1] * TMath::Sin(phi);
2831   glb[1] = loc[0] * TMath::Sin(phi) + loc[1] * TMath::Cos(phi);
2832   glb[2] = loc[2];
2833
2834   return kTRUE;
2835
2836 }
2837
2838 //_____________________________________________________________________________
2839 Int_t AliTRDgeometry::GetDetectorSec(Int_t layer, Int_t stack)
2840 {
2841   //
2842   // Convert plane / stack into detector number for one single sector
2843   //
2844
2845   return (layer + stack * fgkNlayer);
2846
2847 }
2848
2849 //_____________________________________________________________________________
2850 Int_t AliTRDgeometry::GetDetector(Int_t layer, Int_t stack, Int_t sector)
2851 {
2852   //
2853   // Convert layer / stack / sector into detector number
2854   //
2855
2856   return (layer + stack * fgkNlayer + sector * fgkNlayer * fgkNstack);
2857
2858 }
2859
2860 //_____________________________________________________________________________
2861 Int_t AliTRDgeometry::GetLayer(Int_t det)
2862 {
2863   //
2864   // Reconstruct the layer number from the detector number
2865   //
2866
2867   return ((Int_t) (det % fgkNlayer));
2868
2869 }
2870
2871 //_____________________________________________________________________________
2872 Int_t AliTRDgeometry::GetStack(Int_t det)
2873 {
2874   //
2875   // Reconstruct the stack number from the detector number
2876   //
2877
2878   return ((Int_t) (det % (fgkNlayer * fgkNstack)) / fgkNlayer);
2879
2880 }
2881
2882 //_____________________________________________________________________________
2883 Int_t AliTRDgeometry::GetStack(Double_t z, Int_t layer)
2884 {
2885   //
2886   // Reconstruct the chamber number from the z position and layer number
2887   //
2888   // The return function has to be protected for positiveness !!
2889   //
2890
2891   if ((layer <          0) || 
2892       (layer >= fgkNlayer)) return -1;
2893         
2894   Int_t    istck = fgkNstack;
2895   Double_t zmin  = 0.0;
2896   Double_t zmax  = 0.0;
2897
2898   do {
2899     istck--;
2900     if (istck < 0) break;
2901     AliTRDpadPlane *pp = GetPadPlane(layer,istck);
2902     zmax  = pp->GetRow0();
2903     Int_t nrows = pp->GetNrows();
2904     zmin = zmax -         2 * pp->GetLengthOPad() 
2905                 - (nrows-2) * pp->GetLengthIPad() 
2906                 - (nrows-1) * pp->GetRowSpacing();
2907   } while((z < zmin) || (z > zmax));
2908   
2909   return istck;
2910
2911 }
2912
2913 //_____________________________________________________________________________
2914 Int_t AliTRDgeometry::GetSector(Int_t det)
2915 {
2916   //
2917   // Reconstruct the sector number from the detector number
2918   //
2919
2920   return ((Int_t) (det / (fgkNlayer * fgkNstack)));
2921
2922 }
2923
2924 //_____________________________________________________________________________
2925 AliTRDpadPlane *AliTRDgeometry::GetPadPlane(Int_t layer, Int_t stack)
2926 {
2927   //
2928   // Returns the pad plane for a given plane <pl> and stack <st> number
2929   //
2930
2931   if (!fgPadPlaneArray) {
2932     CreatePadPlaneArray();
2933   }
2934
2935   Int_t ipp = GetDetectorSec(layer,stack);
2936   return ((AliTRDpadPlane *) fgPadPlaneArray->At(ipp));
2937
2938 }
2939
2940 //_____________________________________________________________________________
2941 Int_t AliTRDgeometry::GetRowMax(Int_t layer, Int_t stack, Int_t /*sector*/)
2942 {
2943   //
2944   // Returns the number of rows on the pad plane
2945   //
2946
2947   return GetPadPlane(layer,stack)->GetNrows();
2948
2949 }
2950
2951 //_____________________________________________________________________________
2952 Int_t AliTRDgeometry::GetColMax(Int_t layer)
2953 {
2954   //
2955   // Returns the number of rows on the pad plane
2956   //
2957
2958   return GetPadPlane(layer,0)->GetNcols();
2959
2960 }
2961
2962 //_____________________________________________________________________________
2963 Double_t AliTRDgeometry::GetRow0(Int_t layer, Int_t stack, Int_t /*sector*/)
2964 {
2965   //
2966   // Returns the position of the border of the first pad in a row
2967   //
2968
2969   return GetPadPlane(layer,stack)->GetRow0();
2970
2971 }
2972
2973 //_____________________________________________________________________________
2974 Double_t AliTRDgeometry::GetCol0(Int_t layer)
2975 {
2976   //
2977   // Returns the position of the border of the first pad in a column
2978   //
2979
2980   return GetPadPlane(layer,0)->GetCol0();
2981
2982 }
2983
2984 //_____________________________________________________________________________
2985 Bool_t AliTRDgeometry::CreateClusterMatrixArray()
2986 {
2987   //
2988   // Create the matrices to transform cluster coordinates from the 
2989   // local chamber system to the tracking coordinate system
2990   //
2991
2992   if (!gGeoManager) {
2993     return kFALSE;
2994   }
2995
2996   if(fgClusterMatrixArray)
2997     return kTRUE;
2998
2999   TString volPath;
3000   TString vpStr   = "ALIC_1/B077_1/BSEGMO";
3001   TString vpApp1  = "_1/BTRD";
3002   TString vpApp2  = "_1";
3003   TString vpApp3a = "/UTR1_1/UTS1_1/UTI1_1";
3004   TString vpApp3b = "/UTR2_1/UTS2_1/UTI2_1";
3005   TString vpApp3c = "/UTR3_1/UTS3_1/UTI3_1";
3006   TString vpApp3d = "/UTR4_1/UTS4_1/UTI4_1";
3007
3008   fgClusterMatrixArray = new TObjArray(kNdet);
3009   AliAlignObjParams o;
3010
3011   for (Int_t iLayer = AliGeomManager::kTRD1; iLayer <= AliGeomManager::kTRD6; iLayer++) {
3012     for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer); iModule++) {
3013       
3014       Int_t        isector   = iModule/Nstack();
3015       Int_t        istack    = iModule%Nstack();
3016       Int_t        iLayerTRD = iLayer - AliGeomManager::kTRD1;
3017       Int_t        lid       = GetDetector(iLayerTRD,istack,isector);    
3018
3019       // Check for disabled supermodules
3020       volPath  = vpStr;
3021       volPath += isector;
3022       volPath += vpApp1;
3023       volPath += isector;
3024       volPath += vpApp2;
3025       switch (isector) {
3026       case 17:
3027         if ((istack == 4) && (iLayerTRD == 4)) {
3028           continue;
3029         }
3030         volPath += vpApp3d;
3031         break;
3032       case 13:
3033       case 14:
3034       case 15:
3035         // Check for holes in from of PHOS
3036         if (istack == 2) {
3037           continue;
3038         }
3039         volPath += vpApp3c;
3040         break;
3041       case 11:
3042       case 12:
3043         volPath += vpApp3b;
3044         break;
3045       default:
3046         volPath += vpApp3a;
3047       };
3048       if (!gGeoManager->CheckPath(volPath)) {
3049         continue;
3050       }
3051
3052       UShort_t     volid   = AliGeomManager::LayerToVolUID(iLayer,iModule);
3053       const char  *symname = AliGeomManager::SymName(volid);
3054       TGeoPNEntry *pne     = gGeoManager->GetAlignableEntry(symname);
3055       const char  *path    = symname;
3056       if (pne) {
3057         path = pne->GetTitle();
3058       }
3059       else {
3060         continue;
3061       }
3062       if (!strstr(path,"ALIC")) {
3063         AliDebugClass(1,Form("Not a valid path: %s\n",path));
3064         continue;
3065       }
3066       if (!gGeoManager->cd(path)) {
3067         AliErrorClass(Form("Cannot go to path: %s\n",path));
3068         continue;
3069       }
3070       TGeoHMatrix *m         = gGeoManager->GetCurrentMatrix();
3071       
3072       TGeoRotation mchange; 
3073       mchange.RotateY(90); 
3074       mchange.RotateX(90);
3075
3076       //
3077       // Cluster transformation matrix
3078       //
3079       TGeoHMatrix  rotMatrix(mchange.Inverse());
3080       rotMatrix.MultiplyLeft(m);
3081       Double_t sectorAngle = 20.0 * (isector % 18) + 10.0;
3082       TGeoHMatrix  rotSector;
3083       rotSector.RotateZ(sectorAngle);
3084       rotMatrix.MultiplyLeft(&rotSector.Inverse());
3085
3086       fgClusterMatrixArray->AddAt(new TGeoHMatrix(rotMatrix),lid);       
3087
3088     }    
3089   }
3090
3091   return kTRUE;
3092
3093 }
3094
3095 //_____________________________________________________________________________
3096 TGeoHMatrix *AliTRDgeometry::GetClusterMatrix(Int_t det)
3097 {
3098   //
3099   // Returns the cluster transformation matrix for a given detector
3100   //
3101
3102   if (!fgClusterMatrixArray) {
3103     if (!CreateClusterMatrixArray()) {
3104       return NULL;
3105     }
3106   }  
3107   return (TGeoHMatrix *) fgClusterMatrixArray->At(det);
3108
3109 }
3110
3111 //_____________________________________________________________________________
3112 Bool_t AliTRDgeometry::ChamberInGeometry(Int_t det)
3113 {
3114   //
3115   // Checks whether the given detector is part of the current geometry
3116   //
3117
3118   if (!GetClusterMatrix(det)) {
3119     return kFALSE;
3120   }
3121   else {
3122     return kTRUE;
3123   }
3124
3125 }
3126
3127 //_____________________________________________________________________________
3128 Bool_t AliTRDgeometry::IsHole(Int_t /*la*/, Int_t st, Int_t se) const
3129 {
3130   //
3131   // Checks for holes in front of PHOS
3132   //
3133
3134   if (((se == 13) || (se == 14) || (se == 15)) && 
3135       (st == 2)) {
3136     return kTRUE; 
3137   }
3138
3139   return kFALSE;
3140
3141 }
3142
3143 //_____________________________________________________________________________
3144 Bool_t AliTRDgeometry::IsOnBoundary(Int_t det, Float_t y, Float_t z, Float_t eps) const
3145 {
3146   //
3147   // Checks whether position is at the boundary of the sensitive volume 
3148   //
3149
3150   Int_t ly = GetLayer(det);
3151   if ((ly <          0) || 
3152       (ly >= fgkNlayer)) return kTRUE;
3153         
3154   Int_t stk = GetStack(det);
3155   if ((stk <          0) || 
3156       (stk >= fgkNstack)) return kTRUE;
3157
3158   AliTRDpadPlane *pp = (AliTRDpadPlane*) fgPadPlaneArray->At(GetDetectorSec(ly, stk));
3159   if(!pp) return kTRUE;
3160
3161   Double_t max  = pp->GetRow0();
3162   Int_t n = pp->GetNrows();
3163   Double_t min = max - 2 * pp->GetLengthOPad() 
3164                  - (n-2) * pp->GetLengthIPad() 
3165                  - (n-1) * pp->GetRowSpacing();
3166   if(z < min+eps || z > max-eps){ 
3167     //printf("z : min[%7.2f (%7.2f)] %7.2f max[(%7.2f) %7.2f]\n", min, min+eps, z, max-eps, max);
3168     return kTRUE;
3169   }
3170   min  = pp->GetCol0();
3171   n = pp->GetNcols();
3172   max = min +2 * pp->GetWidthOPad() 
3173        + (n-2) * pp->GetWidthIPad() 
3174        + (n-1) * pp->GetColSpacing();
3175   if(y < min+eps || y > max-eps){ 
3176     //printf("y : min[%7.2f (%7.2f)] %7.2f max[(%7.2f) %7.2f]\n", min, min+eps, y, max-eps, max);
3177     return kTRUE;
3178   }
3179
3180   return kFALSE;
3181
3182 }