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