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