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