]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDgeometry.cxx
Updated error definitions.
[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
25 #include <TGeoManager.h>
26 #include <TGeoPhysicalNode.h>
27 #include <TGeoMatrix.h>
28
29 #include "AliLog.h"
30 #include "AliRunLoader.h"
31 #include "AliAlignObj.h"
32 #include "AliAlignObjParams.h"
33 #include "AliRun.h"
34
35 #include "AliTRD.h"
36 #include "AliTRDcalibDB.h"
37 #include "AliTRDgeometry.h"
38 #include "AliTRDpadPlane.h"
39
40 ClassImp(AliTRDgeometry)
41
42 //_____________________________________________________________________________
43
44   //
45   // The geometry constants
46   //
47   const Int_t    AliTRDgeometry::fgkNsect     = kNsect;
48   const Int_t    AliTRDgeometry::fgkNplan     = kNplan;
49   const Int_t    AliTRDgeometry::fgkNcham     = kNcham;
50   const Int_t    AliTRDgeometry::fgkNdet      = kNdet;
51
52   //
53   // Dimensions of the detector
54   //
55
56   // Total length of the TRD mother volume
57   const Float_t  AliTRDgeometry::fgkTlength   = 751.0;
58
59   // Parameter of the super module mother volumes 
60   const Float_t  AliTRDgeometry::fgkSheight   =  77.9; 
61   const Float_t  AliTRDgeometry::fgkSwidth1   =  94.881; 
62   const Float_t  AliTRDgeometry::fgkSwidth2   = 122.353;
63   const Float_t  AliTRDgeometry::fgkSlength   = 702.0;
64
65   // Length of the additional space in front of the supermodule
66   // used for services
67   const Float_t  AliTRDgeometry::fgkFlength   = (AliTRDgeometry::fgkTlength
68                                                - AliTRDgeometry::fgkSlength) / 2.0;
69
70   // The super module side plates
71   const Float_t  AliTRDgeometry::fgkSMpltT    =   0.2;
72
73   // Height of different chamber parts
74   // Radiator
75   const Float_t  AliTRDgeometry::fgkCraH      =   4.8; 
76   // Drift region
77   const Float_t  AliTRDgeometry::fgkCdrH      =   3.0;
78   // Amplification region
79   const Float_t  AliTRDgeometry::fgkCamH      =   0.7;
80   // Readout
81   const Float_t  AliTRDgeometry::fgkCroH      =   2.316;
82   // Total height
83   const Float_t  AliTRDgeometry::fgkCH        = AliTRDgeometry::fgkCraH
84                                               + AliTRDgeometry::fgkCdrH
85                                               + AliTRDgeometry::fgkCamH
86                                               + AliTRDgeometry::fgkCroH;  
87
88   // Vertical spacing of the chambers
89   const Float_t  AliTRDgeometry::fgkVspace    =   1.784;
90   // Horizontal spacing of the chambers
91   const Float_t  AliTRDgeometry::fgkHspace    =   2.0;
92   // Radial distance of the first ROC to the outer plates of the SM
93   const Float_t  AliTRDgeometry::fgkVrocsm    =   1.2;
94
95   // Thicknesses of different parts of the chamber frame
96   // Lower aluminum frame
97   const Float_t  AliTRDgeometry::fgkCalT      =   0.4;
98   // Lower Wacosit frame sides
99   const Float_t  AliTRDgeometry::fgkCclsT     =   0.21;
100   // Lower Wacosit frame front
101   const Float_t  AliTRDgeometry::fgkCclfT     =   1.0;
102   // Thickness of glue around radiator
103   const Float_t  AliTRDgeometry::fgkCglT      =   0.25;
104   // Upper Wacosit frame
105   const Float_t  AliTRDgeometry::fgkCcuT      =   0.9;
106   // Al frame of back panel
107   const Float_t  AliTRDgeometry::fgkCauT      =   1.5;
108   // Additional Al of the lower chamber frame
109   const Float_t  AliTRDgeometry::fgkCalW      =   1.11;
110
111   // Additional width of the readout chamber frames
112   const Float_t  AliTRDgeometry::fgkCroW      =   0.9;
113
114   // Difference of outer chamber width and pad plane width
115   const Float_t  AliTRDgeometry::fgkCpadW     =   0.0;
116   const Float_t  AliTRDgeometry::fgkRpadW     =   1.0;
117
118   //
119   // Thickness of the the material layers
120   //
121   const Float_t  AliTRDgeometry::fgkMyThick   = 0.005;
122   const Float_t  AliTRDgeometry::fgkRaThick   = 0.3233;  
123   const Float_t  AliTRDgeometry::fgkDrThick   = AliTRDgeometry::fgkCdrH;    
124   const Float_t  AliTRDgeometry::fgkAmThick   = AliTRDgeometry::fgkCamH;
125   const Float_t  AliTRDgeometry::fgkXeThick   = AliTRDgeometry::fgkDrThick
126                                               + AliTRDgeometry::fgkAmThick;
127   const Float_t  AliTRDgeometry::fgkWrThick   = 0.0002;
128   const Float_t  AliTRDgeometry::fgkCuThick   = 0.0072; 
129   const Float_t  AliTRDgeometry::fgkGlThick   = 0.05;
130   const Float_t  AliTRDgeometry::fgkSuThick   = 0.0919; 
131   const Float_t  AliTRDgeometry::fgkRcThick   = 0.0058;
132   const Float_t  AliTRDgeometry::fgkRpThick   = 0.0632;
133   const Float_t  AliTRDgeometry::fgkRoThick   = 0.0028;
134
135   //
136   // Position of the material layers
137   //
138   const Float_t  AliTRDgeometry::fgkRaZpos    =  0.0;
139   const Float_t  AliTRDgeometry::fgkDrZpos    =  2.4;
140   const Float_t  AliTRDgeometry::fgkAmZpos    =  0.0;
141   const Float_t  AliTRDgeometry::fgkWrZpos    =  0.0;
142   const Float_t  AliTRDgeometry::fgkCuZpos    = -0.9995;
143   const Float_t  AliTRDgeometry::fgkGlZpos    = -0.5; 
144   const Float_t  AliTRDgeometry::fgkSuZpos    =  0.0;
145   const Float_t  AliTRDgeometry::fgkRcZpos    =  1.04;
146   const Float_t  AliTRDgeometry::fgkRpZpos    =  1.0;
147   const Float_t  AliTRDgeometry::fgkRoZpos    =  1.05;
148
149   const Int_t    AliTRDgeometry::fgkMCMmax    = 16;   
150   const Int_t    AliTRDgeometry::fgkMCMrow    = 4;   
151   const Int_t    AliTRDgeometry::fgkROBmaxC0  = 6; 
152   const Int_t    AliTRDgeometry::fgkROBmaxC1  = 8; 
153   const Int_t    AliTRDgeometry::fgkADCmax    = 21;   
154   const Int_t    AliTRDgeometry::fgkTBmax     = 60;   
155   const Int_t    AliTRDgeometry::fgkPadmax    = 18;   
156   const Int_t    AliTRDgeometry::fgkColmax    = 144;
157   const Int_t    AliTRDgeometry::fgkRowmaxC0  = 12;
158   const Int_t    AliTRDgeometry::fgkRowmaxC1  = 16;
159
160   const Double_t AliTRDgeometry::fgkTime0Base = 300.65;
161   const Float_t  AliTRDgeometry::fgkTime0[6]  = { fgkTime0Base + 0 * (Cheight() + Cspace()) 
162                                                 , fgkTime0Base + 1 * (Cheight() + Cspace()) 
163                                                 , fgkTime0Base + 2 * (Cheight() + Cspace()) 
164                                                 , fgkTime0Base + 3 * (Cheight() + Cspace()) 
165                                                 , fgkTime0Base + 4 * (Cheight() + Cspace()) 
166                                                 , fgkTime0Base + 5 * (Cheight() + Cspace())};
167
168 //_____________________________________________________________________________
169 AliTRDgeometry::AliTRDgeometry()
170   :AliGeometry()
171   ,fClusterMatrixArray(0)
172   ,fPadPlaneArray(0)
173 {
174   //
175   // AliTRDgeometry default constructor
176   //
177
178   Init();
179
180 }
181
182 //_____________________________________________________________________________
183 AliTRDgeometry::AliTRDgeometry(const AliTRDgeometry &g)
184   :AliGeometry(g)
185   ,fClusterMatrixArray(0)
186   ,fPadPlaneArray(0)
187 {
188   //
189   // AliTRDgeometry copy constructor
190   //
191
192   Init();
193
194 }
195
196 //_____________________________________________________________________________
197 AliTRDgeometry::~AliTRDgeometry()
198 {
199   //
200   // AliTRDgeometry destructor
201   //
202
203   if (fClusterMatrixArray) {
204     fClusterMatrixArray->Delete();
205     delete fClusterMatrixArray;
206     fClusterMatrixArray = 0;
207   }
208
209   if (fPadPlaneArray) {
210     fPadPlaneArray->Delete();
211     delete fPadPlaneArray;
212     fPadPlaneArray = 0;
213   }
214
215 }
216
217 //_____________________________________________________________________________
218 AliTRDgeometry &AliTRDgeometry::operator=(const AliTRDgeometry &g)
219 {
220   //
221   // Assignment operator
222   //
223
224   if (this != &g) {
225     Init();
226   }
227
228   return *this;
229
230 }
231
232 //_____________________________________________________________________________
233 void AliTRDgeometry::Init()
234 {
235   //
236   // Initializes the geometry parameter
237   //
238
239   Int_t icham;
240   Int_t iplan;
241   Int_t isect;
242
243   // The outer width of the chambers
244   fCwidth[0] =  90.4;
245   fCwidth[1] =  94.8;
246   fCwidth[2] =  99.3;
247   fCwidth[3] = 103.7;
248   fCwidth[4] = 108.1;
249   fCwidth[5] = 112.6;
250
251   // The outer lengths of the chambers
252   // Includes the spacings between the chambers!
253   Float_t length[kNplan][kNcham]   = { { 124.0, 124.0, 110.0, 124.0, 124.0 }
254                                      , { 124.0, 124.0, 110.0, 124.0, 124.0 }
255                                      , { 131.0, 131.0, 110.0, 131.0, 131.0 }
256                                      , { 138.0, 138.0, 110.0, 138.0, 138.0 }
257                                      , { 145.0, 145.0, 110.0, 145.0, 145.0 }
258                                      , { 147.0, 147.0, 110.0, 147.0, 147.0 } };
259
260   for (icham = 0; icham < kNcham; icham++) {
261     for (iplan = 0; iplan < kNplan; iplan++) {
262       fClength[iplan][icham] = length[iplan][icham];
263     }
264   }
265
266   // The rotation matrix elements
267   Float_t phi = 0.0;
268   for (isect = 0; isect < fgkNsect; isect++) {
269     phi = 2.0 * TMath::Pi() /  (Float_t) fgkNsect * ((Float_t) isect + 0.5);
270     fRotB11[isect] = TMath::Cos(phi);
271     fRotB12[isect] = TMath::Sin(phi);
272     fRotB21[isect] = TMath::Sin(phi);
273     fRotB22[isect] = TMath::Cos(phi);
274   }
275
276   // Initialize the SM status
277   for (isect = 0; isect < fgkNsect; isect++) {
278     SetSMstatus(isect,1);
279   }
280  
281 }
282
283 //_____________________________________________________________________________
284 void AliTRDgeometry::CreatePadPlaneArray()
285 {
286   //
287   // Creates the array of AliTRDpadPlane objects
288   //
289
290   if (fPadPlaneArray) {
291     fPadPlaneArray->Delete();
292     delete fPadPlaneArray;
293   }
294
295   fPadPlaneArray = new TObjArray(fgkNplan * fgkNcham);  
296   for (Int_t iplan = 0; iplan < fgkNplan; iplan++) {
297     for (Int_t icham = 0; icham < fgkNcham; icham++) {
298       Int_t ipp = GetDetectorSec(iplan,icham);
299       fPadPlaneArray->AddAt(CreatePadPlane(iplan,icham),ipp);
300     }
301   }
302
303 }
304
305 //_____________________________________________________________________________
306 AliTRDpadPlane *AliTRDgeometry::CreatePadPlane(Int_t iplan, Int_t icham)
307 {
308   //
309   // Creates an AliTRDpadPlane object
310   //
311
312   AliTRDpadPlane *padPlane = new AliTRDpadPlane();
313
314   padPlane->SetPlane(iplan);
315   padPlane->SetChamber(icham);
316
317   padPlane->SetRowSpacing(0.0);
318   padPlane->SetColSpacing(0.0);
319
320   padPlane->SetLengthRim(1.0);
321   padPlane->SetWidthRim(0.5);
322
323   padPlane->SetNcols(144);
324
325   //
326   // The pad plane parameter
327   //
328   switch (iplan) {
329   case 0:
330     if (icham == 2) {
331       // L0C0 type
332       padPlane->SetNrows(12);
333       padPlane->SetLength(108.0);
334       padPlane->SetWidth(92.2);
335       padPlane->SetLengthOPad(8.0);
336       padPlane->SetWidthOPad(0.515);
337       padPlane->SetLengthIPad(9.0);
338       padPlane->SetWidthIPad(0.635);
339       padPlane->SetTiltingAngle(-2.0);
340     }
341     else {
342       // L0C1 type
343       padPlane->SetNrows(16);
344       padPlane->SetLength(122.0);
345       padPlane->SetWidth(92.2);
346       padPlane->SetLengthOPad(7.5);
347       padPlane->SetWidthOPad(0.515);
348       padPlane->SetLengthIPad(7.5);
349       padPlane->SetWidthIPad(0.635);
350       padPlane->SetTiltingAngle(-2.0);
351     }
352     break;
353   case 1:
354     if (icham == 2) {
355       // L1C0 type
356       padPlane->SetNrows(12);
357       padPlane->SetLength(108.0);
358       padPlane->SetWidth(96.6);
359       padPlane->SetLengthOPad(8.0);
360       padPlane->SetWidthOPad(0.585);
361       padPlane->SetLengthIPad(9.0);
362       padPlane->SetWidthIPad(0.665);
363       padPlane->SetTiltingAngle(2.0);
364     }
365     else {
366       // L1C1 type
367       padPlane->SetNrows(16);
368       padPlane->SetLength(122.0);
369       padPlane->SetWidth(96.6);
370       padPlane->SetLengthOPad(7.5);
371       padPlane->SetWidthOPad(0.585);
372       padPlane->SetLengthIPad(7.5);
373       padPlane->SetWidthIPad(0.665);
374       padPlane->SetTiltingAngle(2.0);
375     }
376     break;
377   case 2:
378     if (icham == 2) {
379       // L2C0 type
380       padPlane->SetNrows(12);
381       padPlane->SetLength(108.0);
382       padPlane->SetWidth(101.1);
383       padPlane->SetLengthOPad(8.0);
384       padPlane->SetWidthOPad(0.705);
385       padPlane->SetLengthIPad(9.0);
386       padPlane->SetWidthIPad(0.695);
387       padPlane->SetTiltingAngle(-2.0);
388     }
389     else {
390       // L2C1 type
391       padPlane->SetNrows(16);
392       padPlane->SetLength(129.0);
393       padPlane->SetWidth(101.1);
394       padPlane->SetLengthOPad(7.5);
395       padPlane->SetWidthOPad(0.705);
396       padPlane->SetLengthIPad(8.0);
397       padPlane->SetWidthIPad(0.695);
398       padPlane->SetTiltingAngle(-2.0);
399     }
400     break;
401   case 3:
402     if (icham == 2) {
403       // L3C0 type
404       padPlane->SetNrows(12);
405       padPlane->SetLength(108.0);
406       padPlane->SetWidth(105.5);
407       padPlane->SetLengthOPad(8.0);
408       padPlane->SetWidthOPad(0.775);
409       padPlane->SetLengthIPad(9.0);
410       padPlane->SetWidthIPad(0.725);
411       padPlane->SetTiltingAngle(2.0);
412     }
413     else {
414       // L3C1 type
415       padPlane->SetNrows(16);
416       padPlane->SetLength(136.0);
417       padPlane->SetWidth(105.5);
418       padPlane->SetLengthOPad(7.5);
419       padPlane->SetWidthOPad(0.775);
420       padPlane->SetLengthIPad(8.5);
421       padPlane->SetWidthIPad(0.725);
422       padPlane->SetTiltingAngle(2.0);
423     }
424     break;
425   case 4:
426     if (icham == 2) {
427       // L4C0 type
428       padPlane->SetNrows(12);
429       padPlane->SetLength(108.0);
430       padPlane->SetWidth(109.9);
431       padPlane->SetLengthOPad(8.0);
432       padPlane->SetWidthOPad(0.845);
433       padPlane->SetLengthIPad(9.0);
434       padPlane->SetWidthIPad(0.755);
435       padPlane->SetTiltingAngle(-2.0);
436     }
437     else {
438       // L4C1 type
439       padPlane->SetNrows(16);
440       padPlane->SetLength(143.0);
441       padPlane->SetWidth(109.9);
442       padPlane->SetLengthOPad(7.5);
443       padPlane->SetWidthOPad(0.845);
444       padPlane->SetLengthIPad(9.0);
445       padPlane->SetWidthIPad(0.755);
446       padPlane->SetTiltingAngle(-2.0);
447     }
448     break;
449   case 5:
450     if (icham == 2) {
451       // L5C0 type
452       padPlane->SetNrows(12);
453       padPlane->SetLength(108.0);
454       padPlane->SetWidth(114.4);
455       padPlane->SetLengthOPad(8.0);
456       padPlane->SetWidthOPad(0.965);
457       padPlane->SetLengthIPad(9.0);
458       padPlane->SetWidthIPad(0.785);
459       padPlane->SetTiltingAngle(2.0);
460     }
461     else {
462       // L5C1 type
463       padPlane->SetNrows(16);
464       padPlane->SetLength(145.0);
465       padPlane->SetWidth(114.4);
466       padPlane->SetLengthOPad(8.5);
467       padPlane->SetWidthOPad(0.965);
468       padPlane->SetLengthIPad(9.0);
469       padPlane->SetWidthIPad(0.785);
470       padPlane->SetTiltingAngle(2.0);
471     }
472     break;
473   };
474
475   //
476   // The positions of the borders of the pads
477   //
478   // Row direction
479   //
480   Double_t row = fClength[iplan][icham] / 2.0
481                - fgkRpadW
482                - padPlane->GetLengthRim();
483   for (Int_t ir = 0; ir < padPlane->GetNrows(); ir++) {
484     padPlane->SetPadRow(ir,row);
485     row -= padPlane->GetRowSpacing();
486     if (ir == 0) {
487       row -= padPlane->GetLengthOPad();
488     }
489     else {
490       row -= padPlane->GetLengthIPad();
491     }
492   }
493   //
494   // Column direction
495   //
496   Double_t col = fCwidth[iplan] / 2.0
497                + fgkCroW
498                - padPlane->GetWidthRim();
499   for (Int_t ic = 0; ic < padPlane->GetNcols(); ic++) {
500     padPlane->SetPadCol(ic,col);
501     col -= padPlane->GetColSpacing();
502     if (ic == 0) {
503       col -= padPlane->GetWidthOPad();
504     }
505     else {
506       col -= padPlane->GetWidthIPad();
507     }
508   }
509   // Calculate the offset to translate from the local ROC system into
510   // the local supermodule system, which is used for clusters
511   Double_t rowTmp = fClength[iplan][0]
512                   + fClength[iplan][1]
513                   + fClength[iplan][2] / 2.0;
514   for (Int_t ic = 0; ic < icham; ic++) {
515     rowTmp -= fClength[iplan][ic];
516   }
517   padPlane->SetPadRowSMOffset(rowTmp - fClength[iplan][icham]/2.0);
518
519   return padPlane;
520
521 }
522
523 //_____________________________________________________________________________
524 void AliTRDgeometry::CreateGeometry(Int_t *idtmed)
525 {
526   //
527   // Create the TRD geometry without hole
528   //
529   //
530   // Names of the TRD volumina (xx = detector number):
531   //
532   //      Volume (Air) wrapping the readout chamber components
533   //        UTxx    includes: UAxx, UDxx, UFxx, UUxx
534   //
535   //      Volume (Air) wrapping the services (fee + cooling)
536   //        UUxx    the services volume has been reduced by 7.42 mm
537   //                in order to allow shifts in radial direction
538   //
539   //      Lower part of the readout chambers (drift volume + radiator)
540   //
541   //        UAxx    Aluminum frames                 (Al)
542   //        UBxx    Wacosit frames                  (C)
543   //        UXxx    Glue around radiator            (Epoxy)
544   //        UCxx    Inner volumes                   (Air)
545   //        UZxx    Additional aluminum ledges      (Al)
546   //
547   //      Upper part of the readout chambers (readout plane + fee)
548   //
549   //        UDxx    Wacosit frames of amp. region   (C)
550   //        UExx    Inner volumes of the frame      (Air)
551   //        UFxx    Aluminum frame of back panel    (Al)
552   //        UGxx    Inner volumes of the back panel (Air)
553   //
554   //      Inner material layers
555   //
556   //        UHxx    Radiator                        (Rohacell)
557   //        UJxx    Drift volume                    (Xe/CO2)
558   //        UKxx    Amplification volume            (Xe/CO2)
559   //        UWxx    Wire plane                      (Cu)
560   //        ULxx    Pad plane                       (Cu)
561   //        UYxx    Glue layer                      (Epoxy)
562   //        UMxx    Support structure               (Rohacell)
563   //        UNxx    ROB base material               (C)
564   //        UOxx    ROB copper                      (Cu)
565   //        UVxx    ROB other materials             (Cu)
566   //
567
568   const Int_t kNparTrd = 4;
569   const Int_t kNparCha = 3;
570
571   Float_t xpos;
572   Float_t ypos;
573   Float_t zpos;
574
575   Float_t parTrd[kNparTrd];
576   Float_t parCha[kNparCha];
577
578   Char_t  cTagV[6];
579   Char_t  cTagM[5];
580
581   // There are three TRD volumes for the supermodules in order to accomodate
582   // the different arrangements in front of PHOS
583   // UTR1: Default supermodule
584   // UTR2: Supermodule in front of PHOS with double carbon cover
585   // UTR3: As UTR2, but w/o middle stack
586   //
587   // The mother volume for one sector (Air), full length in z-direction
588   // Provides material for side plates of super module
589   parTrd[0] = fgkSwidth1/2.0;
590   parTrd[1] = fgkSwidth2/2.0;
591   parTrd[2] = fgkSlength/2.0;
592   parTrd[3] = fgkSheight/2.0;
593   gMC->Gsvolu("UTR1","TRD1",idtmed[1302-1],parTrd,kNparTrd);
594   gMC->Gsvolu("UTR2","TRD1",idtmed[1302-1],parTrd,kNparTrd);
595   gMC->Gsvolu("UTR3","TRD1",idtmed[1302-1],parTrd,kNparTrd);
596   // The outer aluminum plates of the super module (Al)
597   parTrd[0] = fgkSwidth1/2.0;
598   parTrd[1] = fgkSwidth2/2.0;
599   parTrd[2] = fgkSlength/2.0;
600   parTrd[3] = fgkSheight/2.0;
601   gMC->Gsvolu("UTS1","TRD1",idtmed[1301-1],parTrd,kNparTrd);
602   gMC->Gsvolu("UTS2","TRD1",idtmed[1301-1],parTrd,kNparTrd);
603   gMC->Gsvolu("UTS3","TRD1",idtmed[1301-1],parTrd,kNparTrd);
604   // The inner part of the TRD mother volume for one sector (Air), 
605   // full length in z-direction
606   parTrd[0] = fgkSwidth1/2.0 - fgkSMpltT;
607   parTrd[1] = fgkSwidth2/2.0 - fgkSMpltT;
608   parTrd[2] = fgkSlength/2.0;
609   parTrd[3] = fgkSheight/2.0 - fgkSMpltT;
610   gMC->Gsvolu("UTI1","TRD1",idtmed[1302-1],parTrd,kNparTrd);
611   gMC->Gsvolu("UTI2","TRD1",idtmed[1302-1],parTrd,kNparTrd);
612   gMC->Gsvolu("UTI3","TRD1",idtmed[1302-1],parTrd,kNparTrd);
613
614   // The inner part of the TRD mother volume for services in front
615   // of the supermodules  (Air), 
616   parTrd[0] = fgkSwidth1/2.0;
617   parTrd[1] = fgkSwidth2/2.0;
618   parTrd[2] = fgkFlength/2.0;
619   parTrd[3] = fgkSheight/2.0;
620   gMC->Gsvolu("UTF1","TRD1",idtmed[1302-1],parTrd,kNparTrd);
621   gMC->Gsvolu("UTF2","TRD1",idtmed[1302-1],parTrd,kNparTrd);
622
623   for (Int_t icham = 0; icham < kNcham; icham++) {
624     for (Int_t iplan = 0; iplan < kNplan; iplan++) {  
625
626       Int_t iDet = GetDetectorSec(iplan,icham);
627
628       // The lower part of the readout chambers (drift volume + radiator) 
629       // The aluminum frames 
630       sprintf(cTagV,"UA%02d",iDet);
631       parCha[0] = fCwidth[iplan]/2.0;
632       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
633       parCha[2] = fgkCraH/2.0 + fgkCdrH/2.0;
634       fChamberUAboxd[iDet][0] = parCha[0];
635       fChamberUAboxd[iDet][1] = parCha[1];
636       fChamberUAboxd[iDet][2] = parCha[2];
637       gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
638       // The additional aluminum on the frames
639       // This part has not the correct postion but is just supposed to
640       // represent the missing material. The correct form of the L-shaped
641       // profile would not fit into the alignable volume. 
642       sprintf(cTagV,"UZ%02d",iDet);
643       parCha[0] = fgkCroW/2.0;
644       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
645       parCha[2] = fgkCalW/2.0;
646       fChamberUAboxd[iDet][0] = fChamberUAboxd[iDet][0] + fgkCroW;
647       gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
648       // The Wacosit frames 
649       sprintf(cTagV,"UB%02d",iDet);
650       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT; 
651       parCha[1] = -1.0;
652       parCha[2] = -1.0;
653       gMC->Gsvolu(cTagV,"BOX ",idtmed[1307-1],parCha,kNparCha);
654       // The glue around the radiator
655       sprintf(cTagV,"UX%02d",iDet);
656       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT - fgkCclsT; 
657       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCclfT;
658       parCha[2] = fgkCraH/2.0;
659       gMC->Gsvolu(cTagV,"BOX ",idtmed[1311-1],parCha,kNparCha);
660       // The inner part of radiator (air)
661       sprintf(cTagV,"UC%02d",iDet);
662       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT - fgkCclsT - fgkCglT; 
663       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCclfT - fgkCglT;
664       parCha[2] = -1.0;
665       gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
666
667       // The upper part of the readout chambers (amplification volume)
668       // The Wacosit frames
669       sprintf(cTagV,"UD%02d",iDet);
670       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW;
671       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
672       parCha[2] = fgkCamH/2.0;
673       fChamberUDboxd[iDet][0] = parCha[0];
674       fChamberUDboxd[iDet][1] = parCha[1];
675       fChamberUDboxd[iDet][2] = parCha[2];
676       gMC->Gsvolu(cTagV,"BOX ",idtmed[1307-1],parCha,kNparCha);
677       // The inner part of the Wacosit frame (air)
678       sprintf(cTagV,"UE%02d",iDet);
679       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW - fgkCcuT; 
680       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCcuT;
681       parCha[2] = -1.;
682       gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
683
684       // The support structure (pad plane, back panel, readout boards)
685       // The aluminum frames
686       sprintf(cTagV,"UF%02d",iDet);
687       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW;
688       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
689       parCha[2] = fgkCroH/2.0;
690       fChamberUFboxd[iDet][0] = parCha[0];
691       fChamberUFboxd[iDet][1] = parCha[1];
692       fChamberUFboxd[iDet][2] = parCha[2];
693       gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
694       // The inner part of the aluminum frames
695       sprintf(cTagV,"UG%02d",iDet);
696       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW - fgkCauT; 
697       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCauT;
698       parCha[2] = -1.0;
699       gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
700
701       // The material layers inside the chambers
702       // Rohacell layer (radiator)
703       parCha[0] = -1.0;
704       parCha[1] = -1.0;
705       parCha[2] = fgkRaThick/2.0;
706       sprintf(cTagV,"UH%02d",iDet);
707       gMC->Gsvolu(cTagV,"BOX ",idtmed[1315-1],parCha,kNparCha);
708       // Xe/Isobutane layer (drift volume) 
709       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT - fgkCclsT;
710       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCclfT;
711       parCha[2] = fgkDrThick/2.0;
712       sprintf(cTagV,"UJ%02d",iDet);
713       gMC->Gsvolu(cTagV,"BOX ",idtmed[1309-1],parCha,kNparCha);
714       // Xe/Isobutane layer (amplification volume)
715       parCha[0] = -1.0;
716       parCha[1] = -1.0;
717       parCha[2] = fgkAmThick/2.0;
718       sprintf(cTagV,"UK%02d",iDet);
719       gMC->Gsvolu(cTagV,"BOX ",idtmed[1309-1],parCha,kNparCha);  
720       // Cu layer (wire plane)
721       parCha[0] = -1.0;
722       parCha[1] = -1.0;
723       parCha[2] = fgkWrThick/2.0;
724       sprintf(cTagV,"UW%02d",iDet);
725       gMC->Gsvolu(cTagV,"BOX ",idtmed[1303-1],parCha,kNparCha);
726       // Cu layer (pad plane)
727       parCha[0] = -1.0;
728       parCha[1] = -1.0;
729       parCha[2] = fgkCuThick/2.0;
730       sprintf(cTagV,"UL%02d",iDet);
731       gMC->Gsvolu(cTagV,"BOX ",idtmed[1305-1],parCha,kNparCha);
732       // Epoxy layer (glue)
733       parCha[0] = -1.0;
734       parCha[1] = -1.0;
735       parCha[2] = fgkGlThick/2.0;
736       sprintf(cTagV,"UY%02d",iDet);
737       gMC->Gsvolu(cTagV,"BOX ",idtmed[1311-1],parCha,kNparCha);
738       // G10 layer (support structure / honeycomb)
739       parCha[0] = -1.0;
740       parCha[1] = -1.0;
741       parCha[2] = fgkSuThick/2.0;
742       sprintf(cTagV,"UM%02d",iDet);
743       gMC->Gsvolu(cTagV,"BOX ",idtmed[1310-1],parCha,kNparCha);
744       // G10 layer (PCB readout board)
745       parCha[0] = -1.0;
746       parCha[1] = -1.0;
747       parCha[2] = fgkRpThick/2;
748       sprintf(cTagV,"UN%02d",iDet);
749       gMC->Gsvolu(cTagV,"BOX ",idtmed[1313-1],parCha,kNparCha);
750       // Cu layer (traces in readout board)
751       parCha[0] = -1.0;
752       parCha[1] = -1.0;
753       parCha[2] = fgkRcThick/2.0;
754       sprintf(cTagV,"UO%02d",iDet);
755       gMC->Gsvolu(cTagV,"BOX ",idtmed[1306-1],parCha,kNparCha);
756       // Cu layer (other material on in readout board)
757       parCha[0] = -1.0;
758       parCha[1] = -1.0;
759       parCha[2] = fgkRoThick/2.0;
760       sprintf(cTagV,"UV%02d",iDet);
761       gMC->Gsvolu(cTagV,"BOX ",idtmed[1304-1],parCha,kNparCha);
762
763       // Position the layers in the chambers
764       xpos = 0.0;
765       ypos = 0.0;
766       // Lower part
767       // Rohacell layer (radiator)
768       zpos = fgkRaZpos;
769       sprintf(cTagV,"UH%02d",iDet);
770       sprintf(cTagM,"UC%02d",iDet);
771       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
772       // Xe/Isobutane layer (drift volume) 
773       zpos = fgkDrZpos;
774       sprintf(cTagV,"UJ%02d",iDet);
775       sprintf(cTagM,"UB%02d",iDet);
776       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
777       // Upper part
778       // Xe/Isobutane layer (amplification volume)
779       zpos = fgkAmZpos;
780       sprintf(cTagV,"UK%02d",iDet);
781       sprintf(cTagM,"UE%02d",iDet);
782       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
783       // Cu layer (wire plane inside amplification volume)
784       zpos = fgkWrZpos; 
785       sprintf(cTagV,"UW%02d",iDet);
786       sprintf(cTagM,"UK%02d",iDet);
787       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
788       // Readout part + support plane
789       // Cu layer (pad plane)
790       zpos = fgkCuZpos; 
791       sprintf(cTagV,"UL%02d",iDet);
792       sprintf(cTagM,"UG%02d",iDet);
793       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
794       // Epoxy layer (glue)
795       zpos = fgkGlZpos; 
796       sprintf(cTagV,"UY%02d",iDet);
797       sprintf(cTagM,"UG%02d",iDet);
798       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
799       // G10 layer (support structure)
800       zpos = fgkSuZpos;
801       sprintf(cTagV,"UM%02d",iDet);
802       sprintf(cTagM,"UG%02d",iDet);
803       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
804       // G10 layer (PCB readout board)
805       zpos = fgkRpZpos;
806       sprintf(cTagV,"UN%02d",iDet);
807       sprintf(cTagM,"UG%02d",iDet);
808       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
809       // Cu layer (traces in readout board)
810       zpos = fgkRcZpos;
811       sprintf(cTagV,"UO%02d",iDet);
812       sprintf(cTagM,"UG%02d",iDet);
813       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
814       // Cu layer (other materials on readout board)
815       zpos = fgkRoZpos;
816       sprintf(cTagV,"UV%02d",iDet);
817       sprintf(cTagM,"UG%02d",iDet);
818       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
819
820       // Position the inner volumes of the chambers in the frames
821       xpos = 0.0;
822       ypos = 0.0;
823       // The inner part of the radiator
824       zpos = 0.0;
825       sprintf(cTagV,"UC%02d",iDet);
826       sprintf(cTagM,"UX%02d",iDet);
827       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
828       // The glue around the radiator
829       zpos = fgkCraH/2.0 - fgkCdrH/2.0 - fgkCraH/2.0;
830       sprintf(cTagV,"UX%02d",iDet);
831       sprintf(cTagM,"UB%02d",iDet);
832       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
833       // The lower Wacosit frame inside the aluminum frame
834       zpos = 0.0;
835       sprintf(cTagV,"UB%02d",iDet);
836       sprintf(cTagM,"UA%02d",iDet);
837       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
838       // The inside of the upper Wacosit frame
839       zpos = 0.0;
840       sprintf(cTagV,"UE%02d",iDet);
841       sprintf(cTagM,"UD%02d",iDet);
842       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
843       // The inside of the upper aluminum frame
844       zpos = 0.0;
845       sprintf(cTagV,"UG%02d",iDet);
846       sprintf(cTagM,"UF%02d",iDet);
847       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");      
848
849       // Position the frames of the chambers in the TRD mother volume
850       xpos  = 0.0;
851       ypos  = fClength[iplan][0] + fClength[iplan][1] + fClength[iplan][2]/2.0;
852       for (Int_t ic = 0; ic < icham; ic++) {
853         ypos -= fClength[iplan][ic];
854       }
855       ypos -= fClength[iplan][icham]/2.0;
856       zpos  = fgkVrocsm + fgkSMpltT + fgkCraH/2.0 + fgkCdrH/2.0 - fgkSheight/2.0
857             + iplan * (fgkCH + fgkVspace);
858       // The lower aluminum frame, radiator + drift region
859       sprintf(cTagV,"UA%02d",iDet);      
860       fChamberUAorig[iDet][0] = xpos;
861       fChamberUAorig[iDet][1] = ypos;
862       fChamberUAorig[iDet][2] = zpos;
863       // The upper G10 frame, amplification region
864       sprintf(cTagV,"UD%02d",iDet);
865       zpos += fgkCamH/2.0 + fgkCraH/2.0 + fgkCdrH/2.0;      
866       fChamberUDorig[iDet][0] = xpos;
867       fChamberUDorig[iDet][1] = ypos;
868       fChamberUDorig[iDet][2] = zpos;
869       // The upper aluminum frame
870       sprintf(cTagV,"UF%02d",iDet);
871       zpos += fgkCroH/2.0 + fgkCamH/2.0;      
872       fChamberUForig[iDet][0] = xpos;
873       fChamberUForig[iDet][1] = ypos;
874       fChamberUForig[iDet][2] = zpos;
875
876     }
877   }
878
879   // Create the volumes of the super module frame
880   CreateFrame(idtmed);
881
882   // Create the volumes of the services
883   CreateServices(idtmed);
884   
885   for (Int_t icham = 0; icham < kNcham; icham++) {
886     for (Int_t iplan = 0; iplan < kNplan; iplan++) {  
887       GroupChamber(iplan,icham,idtmed);
888     }
889   }
890   
891   xpos = 0.0;
892   ypos = 0.0;
893   zpos = 0.0;
894   gMC->Gspos("UTI1",1,"UTS1",xpos,ypos,zpos,0,"ONLY");
895   gMC->Gspos("UTI2",1,"UTS2",xpos,ypos,zpos,0,"ONLY");
896   gMC->Gspos("UTI3",1,"UTS3",xpos,ypos,zpos,0,"ONLY");
897
898   xpos = 0.0;
899   ypos = 0.0;
900   zpos = 0.0;
901   gMC->Gspos("UTS1",1,"UTR1",xpos,ypos,zpos,0,"ONLY");
902   gMC->Gspos("UTS2",1,"UTR2",xpos,ypos,zpos,0,"ONLY");
903   gMC->Gspos("UTS3",1,"UTR3",xpos,ypos,zpos,0,"ONLY");
904
905   // Put the TRD volumes into the space frame mother volumes
906   // if enabled via status flag
907   xpos = 0.0;
908   ypos = 0.0;
909   zpos = 0.0;
910   for (Int_t isect = 0; isect < kNsect; isect++) {
911     if (fSMstatus[isect]) {
912       sprintf(cTagV,"BTRD%d",isect);
913       switch (isect) {
914       case 13:
915       case 14:
916       case 15:
917         // Double carbon, w/o middle stack
918         gMC->Gspos("UTR3",1,cTagV,xpos,ypos,zpos,0,"ONLY");
919         break;
920       case 11:
921       case 12:
922         // Double carbon, all stacks
923         gMC->Gspos("UTR2",1,cTagV,xpos,ypos,zpos,0,"ONLY");
924         break;
925       default:
926         // Standard supermodule
927         gMC->Gspos("UTR1",1,cTagV,xpos,ypos,zpos,0,"ONLY");
928       };
929     }
930   }
931
932   // Put the TRD volumes into the space frame mother volumes
933   // if enabled via status flag
934   xpos = 0.0;
935   ypos = 0.5*fgkSlength + 0.5*fgkFlength;
936   zpos = 0.0;
937   for (Int_t isect = 0; isect < kNsect; isect++) {
938     if (fSMstatus[isect]) {
939       sprintf(cTagV,"BTRD%d",isect);
940       gMC->Gspos("UTF1",1,cTagV,xpos, ypos,zpos,0,"ONLY");
941       gMC->Gspos("UTF2",1,cTagV,xpos,-ypos,zpos,0,"ONLY");
942     }
943   }
944
945 }
946
947 //_____________________________________________________________________________
948 void AliTRDgeometry::CreateFrame(Int_t *idtmed)
949 {
950   //
951   // Create the geometry of the frame of the supermodule
952   //
953   // Names of the TRD services volumina
954   //
955   //        USRL    Support rails for the chambers (Al)
956   //        USxx    Support cross bars between the chambers (Al)
957   //        USHx    Horizontal connection between the cross bars (Al)
958   //        USLx    Long corner ledges (Al)
959   //
960
961   Int_t   iplan = 0;
962
963   Float_t xpos  = 0.0;
964   Float_t ypos  = 0.0;
965   Float_t zpos  = 0.0;
966
967   Char_t  cTagV[5];
968   Char_t  cTagM[5];
969
970   const Int_t kNparTRD = 4;
971   Float_t parTRD[kNparTRD];
972   const Int_t kNparBOX = 3;
973   Float_t parBOX[kNparBOX];
974   const Int_t kNparTRP = 11;
975   Float_t parTRP[kNparTRP];
976
977   // The rotation matrices
978   const Int_t kNmatrix = 6;
979   Int_t   matrix[kNmatrix];
980   gMC->Matrix(matrix[0], 100.0,   0.0,  90.0,  90.0,  10.0,   0.0);
981   gMC->Matrix(matrix[1],  80.0,   0.0,  90.0,  90.0,  10.0, 180.0);
982   gMC->Matrix(matrix[2],  90.0,   0.0,   0.0,   0.0,  90.0,  90.0);
983   gMC->Matrix(matrix[3],  90.0, 180.0,   0.0, 180.0,  90.0,  90.0);
984   gMC->Matrix(matrix[4], 170.0,   0.0,  80.0,   0.0,  90.0,  90.0);
985   gMC->Matrix(matrix[5], 170.0, 180.0,  80.0, 180.0,  90.0,  90.0);
986   gMC->Matrix(matrix[6], 180.0, 180.0,  90.0, 180.0,  90.0,  90.0);
987
988   //
989   // The carbon inserts in the top/bottom aluminum plates
990   //
991
992   const Int_t kNparCrb = 3;
993   Float_t parCrb[kNparCrb];
994   parCrb[0] = 0.0;
995   parCrb[1] = 0.0;
996   parCrb[2] = 0.0;
997   gMC->Gsvolu("USCR","BOX ",idtmed[1307-1],parCrb,0);
998   // Bottom 1 (all sectors)
999   parCrb[0] =  77.49/2.0;
1000   parCrb[1] = 104.60/2.0;
1001   parCrb[2] = fgkSMpltT/2.0;
1002   xpos      =   0.0;
1003   ypos      =   0.0;
1004   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1005   gMC->Gsposp("USCR", 1,"UTS1", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1006   gMC->Gsposp("USCR", 2,"UTS2", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1007   gMC->Gsposp("USCR", 3,"UTS3", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1008   // Bottom 2 (all sectors)
1009   parCrb[0] =  77.49/2.0;
1010   parCrb[1] =  55.80/2.0;
1011   parCrb[2] = fgkSMpltT/2.0;
1012   xpos      =   0.0;
1013   ypos      =  85.6;
1014   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1015   gMC->Gsposp("USCR", 4,"UTS1", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1016   gMC->Gsposp("USCR", 5,"UTS2", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1017   gMC->Gsposp("USCR", 6,"UTS3", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1018   gMC->Gsposp("USCR", 7,"UTS1", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1019   gMC->Gsposp("USCR", 8,"UTS2", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1020   gMC->Gsposp("USCR", 9,"UTS3", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1021   // Bottom 3 (all sectors)
1022   parCrb[0] =  77.49/2.0;
1023   parCrb[1] =  56.00/2.0;
1024   parCrb[2] = fgkSMpltT/2.0;
1025   xpos      =   0.0;
1026   ypos      = 148.5;
1027   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1028   gMC->Gsposp("USCR",10,"UTS1", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1029   gMC->Gsposp("USCR",11,"UTS2", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1030   gMC->Gsposp("USCR",12,"UTS3", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1031   gMC->Gsposp("USCR",13,"UTS1", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1032   gMC->Gsposp("USCR",14,"UTS2", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1033   gMC->Gsposp("USCR",15,"UTS3", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1034   // Bottom 4 (all sectors)
1035   parCrb[0] =  77.49/2.0;
1036   parCrb[1] = 118.00/2.0;
1037   parCrb[2] = fgkSMpltT/2.0;
1038   xpos      =   0.0;
1039   ypos      = 240.5;
1040   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1041   gMC->Gsposp("USCR",16,"UTS1", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1042   gMC->Gsposp("USCR",17,"UTS2", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1043   gMC->Gsposp("USCR",18,"UTS3", xpos, ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1044   gMC->Gsposp("USCR",19,"UTS1", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1045   gMC->Gsposp("USCR",20,"UTS2", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1046   gMC->Gsposp("USCR",21,"UTS3", xpos,-ypos, zpos,0,"ONLY",parCrb,kNparCrb);
1047   // Top 1 (only in front of PHOS)
1048   parCrb[0] = 111.48/2.0;
1049   parCrb[1] = 105.00/2.0;
1050   parCrb[2] = fgkSMpltT/2.0;
1051   xpos      =   0.0;
1052   ypos      =   0.0;
1053   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1054   gMC->Gsposp("USCR",22,"UTS2", xpos, ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1055   gMC->Gsposp("USCR",23,"UTS3", xpos, ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1056   // Top 2 (only in front of PHOS)
1057   parCrb[0] = 111.48/2.0;
1058   parCrb[1] =  56.00/2.0;
1059   parCrb[2] = fgkSMpltT/2.0;
1060   xpos      =   0.0;
1061   ypos      =  85.5;
1062   zpos      = fgkSMpltT/2.0 - fgkSheight/2.0;
1063   gMC->Gsposp("USCR",24,"UTS2", xpos, ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1064   gMC->Gsposp("USCR",25,"UTS3", xpos, ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1065   gMC->Gsposp("USCR",26,"UTS2", xpos,-ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1066   gMC->Gsposp("USCR",27,"UTS3", xpos,-ypos,-zpos,0,"ONLY",parCrb,kNparCrb);
1067
1068   //
1069   // The chamber support rails
1070   //
1071
1072   const Float_t kSRLwid  = 2.00;
1073   const Float_t kSRLhgt  = 2.3;
1074   const Float_t kSRLdst  = 1.0;
1075   const Int_t   kNparSRL = 3;
1076   Float_t parSRL[kNparSRL];
1077   parSRL[0] = kSRLwid   /2.0;
1078   parSRL[1] = fgkSlength/2.0;
1079   parSRL[2] = kSRLhgt   /2.0;
1080   gMC->Gsvolu("USRL","BOX ",idtmed[1301-1],parSRL,kNparSRL);
1081
1082   xpos  = 0.0;
1083   ypos  = 0.0;
1084   zpos  = 0.0;
1085   for (iplan = 0; iplan < kNplan; iplan++) {
1086     xpos  = fCwidth[iplan]/2.0 + kSRLwid/2.0 + kSRLdst;
1087     ypos  = 0.0;
1088     zpos  = fgkVrocsm + fgkSMpltT + fgkCraH + fgkCdrH + fgkCamH 
1089           - fgkSheight/2.0  
1090           + iplan * (fgkCH + fgkVspace);
1091     gMC->Gspos("USRL",iplan+1         ,"UTI1", xpos,ypos,zpos,0,"ONLY");
1092     gMC->Gspos("USRL",iplan+1+  kNplan,"UTI1",-xpos,ypos,zpos,0,"ONLY");
1093     gMC->Gspos("USRL",iplan+1+2*kNplan,"UTI2", xpos,ypos,zpos,0,"ONLY");
1094     gMC->Gspos("USRL",iplan+1+3*kNplan,"UTI2",-xpos,ypos,zpos,0,"ONLY");
1095     gMC->Gspos("USRL",iplan+1+4*kNplan,"UTI3", xpos,ypos,zpos,0,"ONLY");
1096     gMC->Gspos("USRL",iplan+1+5*kNplan,"UTI3",-xpos,ypos,zpos,0,"ONLY");
1097   }
1098
1099   //
1100   // The cross bars between the chambers
1101   //
1102
1103   const Float_t kSCBwid  = 1.0;
1104   const Float_t kSCBthk  = 2.0;
1105   const Float_t kSCHhgt  = 0.3;
1106
1107   const Int_t   kNparSCB = 3;
1108   Float_t parSCB[kNparSCB];
1109   parSCB[1] = kSCBwid/2.0;
1110   parSCB[2] = fgkCH  /2.0 + fgkVspace/2.0 - kSCHhgt;
1111
1112   const Int_t   kNparSCI = 3;
1113   Float_t parSCI[kNparSCI];
1114   parSCI[1] = -1;
1115
1116   xpos  = 0.0;
1117   ypos  = 0.0;
1118   zpos  = 0.0;
1119   for (iplan = 0; iplan < kNplan; iplan++) {
1120
1121     // The aluminum of the cross bars
1122     parSCB[0] = fCwidth[iplan]/2.0 + kSRLdst/2.0;
1123     sprintf(cTagV,"USF%01d",iplan);
1124     gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parSCB,kNparSCB);
1125
1126     // The empty regions in the cross bars
1127     Float_t thkSCB = kSCBthk;
1128     if (iplan < 2) {
1129       thkSCB *= 1.5;
1130     }
1131     parSCI[2] = parSCB[2] - thkSCB;
1132     parSCI[0] = parSCB[0]/4.0 - kSCBthk;
1133     sprintf(cTagV,"USI%01d",iplan);
1134     gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parSCI,kNparSCI);
1135
1136     sprintf(cTagV,"USI%01d",iplan);
1137     sprintf(cTagM,"USF%01d",iplan);
1138     ypos  = 0.0;
1139     zpos  = 0.0;
1140     xpos  =   parSCI[0] + thkSCB/2.0;
1141     gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
1142     xpos  = - parSCI[0] - thkSCB/2.0;
1143     gMC->Gspos(cTagV,2,cTagM,xpos,ypos,zpos,0,"ONLY");
1144     xpos  =   3.0 * parSCI[0] + 1.5 * thkSCB;
1145     gMC->Gspos(cTagV,3,cTagM,xpos,ypos,zpos,0,"ONLY");
1146     xpos  = - 3.0 * parSCI[0] - 1.5 * thkSCB;
1147     gMC->Gspos(cTagV,4,cTagM,xpos,ypos,zpos,0,"ONLY");
1148
1149     sprintf(cTagV,"USF%01d",iplan);
1150     xpos  = 0.0;
1151     zpos  = fgkVrocsm + fgkSMpltT + parSCB[2] - fgkSheight/2.0 
1152           + iplan * (fgkCH + fgkVspace);
1153
1154     ypos  =   fClength[iplan][2]/2.0 + fClength[iplan][1];
1155     gMC->Gspos(cTagV, 1,"UTI1", xpos,ypos,zpos,0,"ONLY");
1156     gMC->Gspos(cTagV, 3,"UTI2", xpos,ypos,zpos,0,"ONLY");
1157     gMC->Gspos(cTagV, 5,"UTI3", xpos,ypos,zpos,0,"ONLY");
1158
1159     ypos  = - fClength[iplan][2]/2.0 - fClength[iplan][1];
1160     gMC->Gspos(cTagV, 2,"UTI1", xpos,ypos,zpos,0,"ONLY");
1161     gMC->Gspos(cTagV, 4,"UTI2", xpos,ypos,zpos,0,"ONLY");
1162     gMC->Gspos(cTagV, 6,"UTI3", xpos,ypos,zpos,0,"ONLY");
1163
1164   }
1165
1166   //
1167   // The horizontal connections between the cross bars
1168   //
1169
1170   const Int_t   kNparSCH = 3;
1171   Float_t parSCH[kNparSCH];
1172
1173   for (iplan = 1; iplan < kNplan-1; iplan++) {
1174
1175     parSCH[0] = fCwidth[iplan]/2.0;
1176     parSCH[1] = (fClength[iplan+1][2]/2.0 + fClength[iplan+1][1]
1177                - fClength[iplan  ][2]/2.0 - fClength[iplan  ][1])/2.0;
1178     parSCH[2] = kSCHhgt/2.0;
1179
1180     sprintf(cTagV,"USH%01d",iplan);
1181     gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parSCH,kNparSCH);
1182     xpos  = 0.0;
1183     ypos  = fClength[iplan][2]/2.0 + fClength[iplan][1] + parSCH[1];
1184     zpos  = fgkVrocsm + fgkSMpltT - kSCHhgt/2.0 - fgkSheight/2.0 
1185           + (iplan+1) * (fgkCH + fgkVspace);
1186     gMC->Gspos(cTagV,1,"UTI1", xpos,ypos,zpos,0,"ONLY");
1187     gMC->Gspos(cTagV,3,"UTI2", xpos,ypos,zpos,0,"ONLY");
1188     gMC->Gspos(cTagV,5,"UTI3", xpos,ypos,zpos,0,"ONLY");
1189     ypos  = -ypos;
1190     gMC->Gspos(cTagV,2,"UTI1", xpos,ypos,zpos,0,"ONLY");
1191     gMC->Gspos(cTagV,4,"UTI2", xpos,ypos,zpos,0,"ONLY");
1192     gMC->Gspos(cTagV,6,"UTI3", xpos,ypos,zpos,0,"ONLY");
1193
1194   }
1195
1196   //
1197   // The aymmetric flat frame in the middle
1198   //
1199
1200   // The envelope volume (aluminum)
1201   parTRD[0]  =  87.60/2.0;
1202   parTRD[1]  = 114.00/2.0;
1203   parTRD[2]  =   1.20/2.0;
1204   parTRD[3]  =  71.30/2.0;
1205   gMC->Gsvolu("USDB","TRD1",idtmed[1301-1],parTRD,kNparTRD);
1206   // Empty spaces (air)
1207   parTRP[ 0] =   1.20/2.0;
1208   parTRP[ 1] =   0.0;
1209   parTRP[ 2] =   0.0;
1210   parTRP[ 3] =  27.00/2.0;
1211   parTRP[ 4] =  50.60/2.0;
1212   parTRP[ 5] =   5.00/2.0;
1213   parTRP[ 6] =   3.5;
1214   parTRP[ 7] =  27.00/2.0;
1215   parTRP[ 8] =  50.60/2.0;
1216   parTRP[ 9] =   5.00/2.0;
1217   parTRP[10] =   3.5;
1218   gMC->Gsvolu("USD1","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1219   xpos       =  18.0;
1220   ypos       =   0.0;
1221   zpos       =   27.00/2.0 - 71.3/2.0;
1222   gMC->Gspos("USD1",1,"USDB", xpos, ypos, zpos,matrix[2],"ONLY");
1223   // Empty spaces (air)
1224   parTRP[ 0] =   1.20/2.0;
1225   parTRP[ 1] =   0.0;
1226   parTRP[ 2] =   0.0;
1227   parTRP[ 3] =  33.00/2.0;
1228   parTRP[ 4] =   5.00/2.0;
1229   parTRP[ 5] =  62.10/2.0;
1230   parTRP[ 6] =   3.5;
1231   parTRP[ 7] =  33.00/2.0;
1232   parTRP[ 8] =   5.00/2.0;
1233   parTRP[ 9] =  62.10/2.0;
1234   parTRP[10] =   3.5;
1235   gMC->Gsvolu("USD2","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1236   xpos       =  21.0;
1237   ypos       =   0.0;
1238   zpos       =  71.3/2.0 - 33.0/2.0;
1239   gMC->Gspos("USD2",1,"USDB", xpos, ypos, zpos,matrix[2],"ONLY");
1240   // Empty spaces (air)
1241   parBOX[ 0] =  22.50/2.0;
1242   parBOX[ 1] =   1.20/2.0;
1243   parBOX[ 2] =  70.50/2.0;
1244   gMC->Gsvolu("USD3","BOX ",idtmed[1302-1],parBOX,kNparBOX);
1245   xpos       = -25.75;
1246   ypos       =   0.0;
1247   zpos       =   0.4;
1248   gMC->Gspos("USD3",1,"USDB", xpos, ypos, zpos,        0,"ONLY");
1249   // Empty spaces (air)
1250   parTRP[ 0] =   1.20/2.0;
1251   parTRP[ 1] =   0.0;
1252   parTRP[ 2] =   0.0;
1253   parTRP[ 3] =  25.50/2.0;
1254   parTRP[ 4] =   5.00/2.0;
1255   parTRP[ 5] =  65.00/2.0;
1256   parTRP[ 6] =  -1.0;
1257   parTRP[ 7] =  25.50/2.0;
1258   parTRP[ 8] =   5.00/2.0;
1259   parTRP[ 9] =  65.00/2.0;
1260   parTRP[10] =  -1.0;
1261   gMC->Gsvolu("USD4","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1262   xpos       =   2.0;
1263   ypos       =   0.0;
1264   zpos       =  -1.6;
1265   gMC->Gspos("USD4",1,"USDB", xpos, ypos, zpos,matrix[6],"ONLY");
1266   // Empty spaces (air)
1267   parTRP[ 0] =   1.20/2.0;
1268   parTRP[ 1] =   0.0;
1269   parTRP[ 2] =   0.0;
1270   parTRP[ 3] =  23.50/2.0;
1271   parTRP[ 4] =  63.50/2.0;
1272   parTRP[ 5] =   5.00/2.0;
1273   parTRP[ 6] =  16.0;
1274   parTRP[ 7] =  23.50/2.0;
1275   parTRP[ 8] =  63.50/2.0;
1276   parTRP[ 9] =   5.00/2.0;
1277   parTRP[10] =  16.0;
1278   gMC->Gsvolu("USD5","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1279   xpos       =  36.5;
1280   ypos       =   0.0;
1281   zpos       =  -1.5;
1282   gMC->Gspos("USD5",1,"USDB", xpos, ypos, zpos,matrix[5],"ONLY");
1283   // Empty spaces (air)
1284   parTRP[ 0] =   1.20/2.0;
1285   parTRP[ 1] =   0.0;
1286   parTRP[ 2] =   0.0;
1287   parTRP[ 3] =  70.50/2.0;
1288   parTRP[ 4] =   4.50/2.0;
1289   parTRP[ 5] =  16.50/2.0;
1290   parTRP[ 6] =  -5.0;
1291   parTRP[ 7] =  70.50/2.0;
1292   parTRP[ 8] =   4.50/2.0;
1293   parTRP[ 9] =  16.50/2.0;
1294   parTRP[10] =  -5.0;
1295   gMC->Gsvolu("USD6","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1296   xpos       = -43.7;
1297   ypos       =   0.0;
1298   zpos       =   0.4;
1299   gMC->Gspos("USD6",1,"USDB", xpos, ypos, zpos,matrix[2],"ONLY");
1300   xpos       =   0.0;
1301   ypos       =   fClength[5][2]/2.0;
1302   zpos       =   0.0;
1303   gMC->Gspos("USDB",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1304   gMC->Gspos("USDB",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1305   gMC->Gspos("USDB",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1306   gMC->Gspos("USDB",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1307   gMC->Gspos("USDB",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1308   gMC->Gspos("USDB",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1309   // Upper bar (aluminum)
1310   parBOX[0] = 95.00/2.0;
1311   parBOX[1] =  1.20/2.0;
1312   parBOX[2] =  3.00/2.0;
1313   gMC->Gsvolu("USD7","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1314   xpos       =   0.0;
1315   ypos       =   fClength[5][2]/2.0;
1316   zpos       =   fgkSheight/2.0 - 3.20/2.0;
1317   gMC->Gspos("USD7",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1318   gMC->Gspos("USD7",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1319   gMC->Gspos("USD7",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1320   gMC->Gspos("USD7",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1321   gMC->Gspos("USD7",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1322   gMC->Gspos("USD7",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1323   // Lower bar (aluminum)
1324   parBOX[0] = 90.22/2.0;
1325   parBOX[1] =  1.20/2.0;
1326   parBOX[2] =  1.90/2.0;
1327   gMC->Gsvolu("USD8","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1328   xpos       =   0.0;
1329   ypos       =   fClength[5][2]/2.0;
1330   zpos       =  -fgkSheight/2.0 + 2.35;
1331   gMC->Gspos("USD8",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1332   gMC->Gspos("USD8",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1333   gMC->Gspos("USD8",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1334   gMC->Gspos("USD8",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1335   gMC->Gspos("USD8",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1336   gMC->Gspos("USD8",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1337   // Lower bar (aluminum)
1338   parBOX[0] = 82.60/2.0;
1339   parBOX[1] =  1.20/2.0;
1340   parBOX[2] =  1.40/2.0;
1341   gMC->Gsvolu("USD9","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1342   xpos       =   0.0;
1343   ypos       =   fClength[5][2]/2.0;
1344   zpos       =  -fgkSheight/2.0 + 1.40/2.0;
1345   gMC->Gspos("USD9",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1346   gMC->Gspos("USD9",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1347   gMC->Gspos("USD9",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1348   gMC->Gspos("USD9",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1349   gMC->Gspos("USD9",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1350   gMC->Gspos("USD9",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1351   // Front sheet (aluminum)
1352   parTRP[ 0] =   0.10/2.0;
1353   parTRP[ 1] =   0.0;
1354   parTRP[ 2] =   0.0;
1355   parTRP[ 3] =  74.50/2.0;
1356   parTRP[ 4] =  31.70/2.0;
1357   parTRP[ 5] =  44.00/2.0;
1358   parTRP[ 6] =  -5.0;
1359   parTRP[ 7] =  74.50/2.0;
1360   parTRP[ 8] =  31.70/2.0;
1361   parTRP[ 9] =  44.00/2.0;
1362   parTRP[10] =  -5.0;
1363   gMC->Gsvolu("USDF","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1364   xpos       = -32.0;
1365   ypos       =   fClength[5][2]/2.0 + 1.20/2.0 + 0.10/2.0;
1366   zpos       =   0.0;
1367   gMC->Gspos("USDF",1,"UTI1", xpos, ypos, zpos,matrix[2],"ONLY");
1368   gMC->Gspos("USDF",2,"UTI1", xpos,-ypos, zpos,matrix[2],"ONLY");
1369   gMC->Gspos("USDF",3,"UTI2", xpos, ypos, zpos,matrix[2],"ONLY");
1370   gMC->Gspos("USDF",4,"UTI2", xpos,-ypos, zpos,matrix[2],"ONLY");
1371   gMC->Gspos("USDF",5,"UTI3", xpos, ypos, zpos,matrix[2],"ONLY");
1372   gMC->Gspos("USDF",6,"UTI3", xpos,-ypos, zpos,matrix[2],"ONLY");
1373
1374   //
1375   // The flat frame in front of the chambers
1376   //
1377
1378   // The envelope volume (aluminum)
1379   parTRD[0]  =  90.00/2.0;
1380   parTRD[1]  = 114.00/2.0;
1381   parTRD[2]  =   1.50/2.0;
1382   parTRD[3]  =  70.30/2.0;
1383   gMC->Gsvolu("USCB","TRD1",idtmed[1301-1],parTRD,kNparTRD);
1384   // Empty spaces (air)
1385   parTRD[0]  =  87.00/2.0;
1386   parTRD[1]  =  10.00/2.0;
1387   parTRD[2]  =   1.50/2.0;
1388   parTRD[3]  =  26.35/2.0;
1389   gMC->Gsvolu("USC1","TRD1",idtmed[1302-1],parTRD,kNparTRD);
1390   xpos       =  0.0;
1391   ypos       =  0.0;
1392   zpos       = 26.35/2.0 - 70.3/2.0;
1393   gMC->Gspos("USC1",1,"USCB",xpos,ypos,zpos,0,"ONLY");
1394   // Empty spaces (air)
1395   parTRD[0]  =  10.00/2.0;
1396   parTRD[1]  = 111.00/2.0;
1397   parTRD[2]  =   1.50/2.0;
1398   parTRD[3]  =  35.05/2.0;
1399   gMC->Gsvolu("USC2","TRD1",idtmed[1302-1],parTRD,kNparTRD);
1400   xpos       =  0.0;
1401   ypos       =  0.0;
1402   zpos       = 70.3/2.0 - 35.05/2.0;
1403   gMC->Gspos("USC2",1,"USCB",xpos,ypos,zpos,0,"ONLY");
1404   // Empty spaces (air)
1405   parTRP[ 0] =   1.50/2.0;
1406   parTRP[ 1] =   0.0;
1407   parTRP[ 2] =   0.0;
1408   parTRP[ 3] =  37.60/2.0;
1409   parTRP[ 4] =  63.90/2.0;
1410   parTRP[ 5] =   8.86/2.0;
1411   parTRP[ 6] =  16.0;
1412   parTRP[ 7] =  37.60/2.0;
1413   parTRP[ 8] =  63.90/2.0;
1414   parTRP[ 9] =   8.86/2.0;
1415   parTRP[10] =  16.0;
1416   gMC->Gsvolu("USC3","TRAP",idtmed[1302-1],parTRP,kNparTRP);
1417   xpos       = -30.5;
1418   ypos       =   0.0;
1419   zpos       =  -2.0;
1420   gMC->Gspos("USC3",1,"USCB", xpos, ypos, zpos,matrix[4],"ONLY");
1421   gMC->Gspos("USC3",2,"USCB",-xpos, ypos, zpos,matrix[5],"ONLY");
1422   xpos       =   0.0;
1423   ypos       =   fClength[5][2]/2.0 + fClength[5][1] + fClength[5][0];
1424   zpos       =   0.0;
1425   gMC->Gspos("USCB",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1426   gMC->Gspos("USCB",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1427   gMC->Gspos("USCB",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1428   gMC->Gspos("USCB",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1429   gMC->Gspos("USCB",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1430   gMC->Gspos("USCB",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1431   // Upper bar (aluminum)
1432   parBOX[0] = 95.00/2.0;
1433   parBOX[1] =  1.50/2.0;
1434   parBOX[2] =  3.00/2.0;
1435   gMC->Gsvolu("USC4","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1436   xpos       =   0.0;
1437   ypos       =   fClength[5][2]/2.0 + fClength[5][1] + fClength[5][0];
1438   zpos       =   fgkSheight/2.0 - 3.00/2.0;
1439   gMC->Gspos("USC4",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1440   gMC->Gspos("USC4",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1441   gMC->Gspos("USC4",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1442   gMC->Gspos("USC4",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1443   gMC->Gspos("USC4",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1444   gMC->Gspos("USC4",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1445   // Lower bar (aluminum)
1446   parBOX[0] = 90.22/2.0;
1447   parBOX[1] =  1.50/2.0;
1448   parBOX[2] =  2.20/2.0;
1449   gMC->Gsvolu("USC5","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1450   xpos       =   0.0;
1451   ypos       =   fClength[5][2]/2.0 + fClength[5][1] + fClength[5][0];
1452   zpos       =  -fgkSheight/2.0 + 2.70;
1453   gMC->Gspos("USC5",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1454   gMC->Gspos("USC5",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1455   gMC->Gspos("USC5",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1456   gMC->Gspos("USC5",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1457   gMC->Gspos("USC5",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1458   gMC->Gspos("USC5",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1459   // Lower bar (aluminum)
1460   parBOX[0] = 82.60/2.0;
1461   parBOX[1] =  1.50/2.0;
1462   parBOX[2] =  1.60/2.0;
1463   gMC->Gsvolu("USC6","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1464   xpos       =   0.0;
1465   ypos       =   fClength[5][2]/2.0 + fClength[5][1] + fClength[5][0];
1466   zpos       =  -fgkSheight/2.0 + 1.60/2.0;
1467   gMC->Gspos("USC6",1,"UTI1", xpos, ypos, zpos,        0,"ONLY");
1468   gMC->Gspos("USC6",2,"UTI1", xpos,-ypos, zpos,        0,"ONLY");
1469   gMC->Gspos("USC6",3,"UTI2", xpos, ypos, zpos,        0,"ONLY");
1470   gMC->Gspos("USC6",4,"UTI2", xpos,-ypos, zpos,        0,"ONLY");
1471   gMC->Gspos("USC6",5,"UTI3", xpos, ypos, zpos,        0,"ONLY");
1472   gMC->Gspos("USC6",6,"UTI3", xpos,-ypos, zpos,        0,"ONLY");
1473
1474   //
1475   // The long corner ledges
1476   //
1477
1478   const Int_t   kNparSCL  =  3;
1479   Float_t parSCL[kNparSCL];
1480   const Int_t   kNparSCLb = 11;
1481   Float_t parSCLb[kNparSCLb];
1482
1483   // Upper ledges 
1484   // Thickness of the corner ledges
1485   const Float_t kSCLthkUa  =  0.6; 
1486   const Float_t kSCLthkUb  =  0.6; 
1487   // Width of the corner ledges
1488   const Float_t kSCLwidUa  =  3.2;
1489   const Float_t kSCLwidUb  =  4.8;
1490   // Position of the corner ledges
1491   const Float_t kSCLposxUa = 0.7;
1492   const Float_t kSCLposxUb = 3.3;
1493   const Float_t kSCLposzUa = 1.6;
1494   const Float_t kSCLposzUb = 0.3;
1495   // Vertical
1496   parSCL[0]  = kSCLthkUa /2.0;
1497   parSCL[1]  = fgkSlength/2.0;
1498   parSCL[2]  = kSCLwidUa /2.0;
1499   gMC->Gsvolu("USL1","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1500   xpos  =   fgkSwidth2/2.0 - fgkSMpltT - kSCLposxUa;
1501   ypos  =   0.0;
1502   zpos  =   fgkSheight/2.0 - fgkSMpltT - kSCLposzUa;
1503   gMC->Gspos("USL1",1,"UTI1", xpos,ypos,zpos,matrix[0],"ONLY");
1504   xpos  = -xpos;
1505   gMC->Gspos("USL1",2,"UTI1", xpos,ypos,zpos,matrix[1],"ONLY");
1506   // Horizontal
1507   parSCL[0]  = kSCLwidUb /2.0;
1508   parSCL[1]  = fgkSlength/2.0;
1509   parSCL[2]  = kSCLthkUb /2.0;
1510   gMC->Gsvolu("USL2","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1511   xpos  =   fgkSwidth2/2.0 - fgkSMpltT - kSCLposxUb;
1512   ypos  =   0.0;
1513   zpos  =   fgkSheight/2.0 - fgkSMpltT - kSCLposzUb; 
1514   gMC->Gspos("USL2",1,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1515   gMC->Gspos("USL2",3,"UTI2", xpos,ypos,zpos,        0,"ONLY");
1516   gMC->Gspos("USL2",5,"UTI3", xpos,ypos,zpos,        0,"ONLY");
1517   xpos  = -xpos;
1518   gMC->Gspos("USL2",2,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1519   gMC->Gspos("USL2",4,"UTI2", xpos,ypos,zpos,        0,"ONLY");
1520   gMC->Gspos("USL2",6,"UTI3", xpos,ypos,zpos,        0,"ONLY");
1521
1522   // Lower ledges 
1523   // Thickness of the corner ledges
1524   const Float_t kSCLthkLa  =  2.464; 
1525   const Float_t kSCLthkLb  =  1.0; 
1526   // Width of the corner ledges
1527   const Float_t kSCLwidLa  =  8.5;
1528   const Float_t kSCLwidLb  =  3.3;
1529   // Position of the corner ledges
1530   const Float_t kSCLposxLa =  0.0;
1531   const Float_t kSCLposxLb =  2.6;
1532   const Float_t kSCLposzLa = -4.25;
1533   const Float_t kSCLposzLb = -0.5;
1534   // Vertical
1535   // Trapezoidal shape
1536   parSCLb[ 0] = fgkSlength/2.0;
1537   parSCLb[ 1] = 0.0;
1538   parSCLb[ 2] = 0.0;
1539   parSCLb[ 3] = kSCLwidLa /2.0;
1540   parSCLb[ 4] = kSCLthkLb /2.0;
1541   parSCLb[ 5] = kSCLthkLa /2.0;
1542   parSCLb[ 6] = 5.0;
1543   parSCLb[ 7] = kSCLwidLa /2.0;
1544   parSCLb[ 8] = kSCLthkLb /2.0;
1545   parSCLb[ 9] = kSCLthkLa /2.0;
1546   parSCLb[10] = 5.0;
1547   gMC->Gsvolu("USL3","TRAP",idtmed[1301-1],parSCLb,kNparSCLb);
1548   xpos  =   fgkSwidth1/2.0 - fgkSMpltT - kSCLposxLa;
1549   ypos  =   0.0;
1550   zpos  = - fgkSheight/2.0 + fgkSMpltT - kSCLposzLa;
1551   gMC->Gspos("USL3",1,"UTI1", xpos,ypos,zpos,matrix[2],"ONLY");
1552   gMC->Gspos("USL3",3,"UTI2", xpos,ypos,zpos,matrix[2],"ONLY");
1553   gMC->Gspos("USL3",5,"UTI3", xpos,ypos,zpos,matrix[2],"ONLY");
1554   xpos  = -xpos;
1555   gMC->Gspos("USL3",2,"UTI1", xpos,ypos,zpos,matrix[3],"ONLY");
1556   gMC->Gspos("USL3",4,"UTI2", xpos,ypos,zpos,matrix[3],"ONLY");
1557   gMC->Gspos("USL3",6,"UTI3", xpos,ypos,zpos,matrix[3],"ONLY");
1558   // Horizontal
1559   parSCL[0]  = kSCLwidLb /2.0;
1560   parSCL[1]  = fgkSlength/2.0;
1561   parSCL[2]  = kSCLthkLb /2.0;
1562   gMC->Gsvolu("USL4","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1563   xpos  =   fgkSwidth1/2.0 - fgkSMpltT - kSCLposxLb;
1564   ypos  =   0.0;
1565   zpos  = - fgkSheight/2.0 + fgkSMpltT - kSCLposzLb;
1566   gMC->Gspos("USL4",1,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1567   gMC->Gspos("USL4",3,"UTI2", xpos,ypos,zpos,        0,"ONLY");
1568   gMC->Gspos("USL4",5,"UTI3", xpos,ypos,zpos,        0,"ONLY");
1569   xpos  = -xpos;
1570   gMC->Gspos("USL4",2,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1571   gMC->Gspos("USL4",4,"UTI2", xpos,ypos,zpos,        0,"ONLY");
1572   gMC->Gspos("USL4",6,"UTI3", xpos,ypos,zpos,        0,"ONLY");
1573
1574   //
1575   // Aluminum plates in the front part of the super modules
1576   //
1577
1578   const Int_t kNparTrd = 4;
1579   Float_t parTrd[kNparTrd];
1580   parTrd[0] = fgkSwidth1/2.0 - 2.5;
1581   parTrd[1] = fgkSwidth2/2.0 - 2.5;
1582   parTrd[2] = fgkSMpltT /2.0;
1583   parTrd[3] = fgkSheight/2.0 - 1.0;
1584   gMC->Gsvolu("UTA1","TRD1",idtmed[1301-1],parTrd,kNparTrd);
1585   xpos      =  0.0;
1586   ypos      =  fgkSMpltT/2.0 - fgkFlength/2.0;
1587   zpos      = -0.5;
1588   gMC->Gspos("UTA1",1,"UTF1",xpos, ypos,zpos,        0,"ONLY");
1589   gMC->Gspos("UTA1",2,"UTF2",xpos,-ypos,zpos,        0,"ONLY");
1590
1591   const Int_t kNparPlt = 3;
1592   Float_t parPlt[kNparPlt];
1593   parPlt[0] =  0.0;
1594   parPlt[1] =  0.0;
1595   parPlt[2] =  0.0;
1596   gMC->Gsvolu("UTA2","BOX ",idtmed[1301-1],parPlt,0);
1597   xpos      =  0.0;
1598   ypos      =  0.0;
1599   zpos      =  fgkSheight/2.0 - fgkSMpltT/2.0;
1600   parPlt[0] = fgkSwidth2/2.0;
1601   parPlt[1] = fgkFlength/2.0;
1602   parPlt[2] = fgkSMpltT /2.0;
1603   gMC->Gsposp("UTA2",1,"UTF2",xpos,ypos,zpos
1604                     ,        0,"ONLY",parPlt,kNparPlt);
1605   xpos      = (fgkSwidth1 + fgkSwidth2)/4.0;
1606   ypos      =  0.0;
1607   zpos      =  0.0;
1608   parPlt[0] = fgkSMpltT /2.0;
1609   parPlt[1] = fgkFlength/2.0;
1610   parPlt[2] = fgkSheight/2.0;
1611   gMC->Gsposp("UTA2",2,"UTF2", xpos,ypos,zpos
1612                     ,matrix[0],"ONLY",parPlt,kNparPlt);
1613   gMC->Gsposp("UTA2",3,"UTF2",-xpos,ypos,zpos
1614                     ,matrix[1],"ONLY",parPlt,kNparPlt);
1615
1616   // Additional aluminum bar
1617   parBOX[0] = 80.0/2.0;
1618   parBOX[1] =  1.0/2.0;
1619   parBOX[2] = 10.0/2.0;
1620   gMC->Gsvolu("UTA3","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1621   xpos      =  0.0;
1622   ypos      =  1.0/2.0 + fgkSMpltT - fgkFlength/2.0;
1623   zpos      =  fgkSheight/2.0 - 1.5 - 10.0/2.0;
1624   gMC->Gspos("UTA3",1,"UTF1", xpos, ypos, zpos,        0,"ONLY");
1625   gMC->Gspos("UTA3",2,"UTF2", xpos,-ypos, zpos,        0,"ONLY");
1626
1627 }
1628
1629 //_____________________________________________________________________________
1630 void AliTRDgeometry::CreateServices(Int_t *idtmed)
1631 {
1632   //
1633   // Create the geometry of the services
1634   //
1635   // Names of the TRD services volumina
1636   //
1637   //        UTC1    Cooling arterias (Al)
1638   //        UTC2    Cooling arterias (Water)
1639   //        UUxx    Volumes for the services at the chambers (Air)
1640   //        UTP1    Power bars       (Cu)
1641   //        UTCP    Cooling pipes    (Fe)
1642   //        UTCH    Cooling pipes    (Water)
1643   //        UTPL    Power lines      (Cu)
1644   //        UMCM    Readout MCMs     (G10/Cu/Si)
1645   //        UTGD    Gas distribution box (V2A)
1646   //
1647
1648   Int_t   iplan = 0;
1649   Int_t   icham = 0;
1650
1651   Float_t xpos  = 0.0;
1652   Float_t ypos  = 0.0;
1653   Float_t zpos  = 0.0;
1654
1655   Char_t  cTagV[5];
1656
1657   const Int_t kNparBox  = 3;
1658   Float_t parBox[kNparBox];
1659
1660   const Int_t kNparTube = 3;
1661   Float_t parTube[kNparTube];
1662
1663   // The rotation matrices
1664   const Int_t kNmatrix = 7;
1665   Int_t   matrix[kNmatrix];
1666   gMC->Matrix(matrix[0], 100.0,   0.0,  90.0,  90.0,  10.0,   0.0);
1667   gMC->Matrix(matrix[1],  80.0,   0.0,  90.0,  90.0,  10.0, 180.0);
1668   gMC->Matrix(matrix[2],   0.0,   0.0,  90.0,  90.0,  90.0,   0.0);
1669   gMC->Matrix(matrix[3], 180.0,   0.0,  90.0,  90.0,  90.0, 180.0);
1670   gMC->Matrix(matrix[4],  90.0,   0.0,   0.0,   0.0,  90.0,  90.0);
1671   gMC->Matrix(matrix[5], 100.0,   0.0,  90.0, 270.0,  10.0,   0.0);
1672   gMC->Matrix(matrix[6],  80.0,   0.0,  90.0, 270.0,  10.0, 180.0);
1673     
1674   //
1675   // The cooling arterias
1676   //
1677
1678   // Width of the cooling arterias
1679   const Float_t kCOLwid  =  0.8; 
1680   // Height of the cooling arterias
1681   const Float_t kCOLhgt  =  6.5;
1682   // Positioning of the cooling 
1683   const Float_t kCOLposx =  1.8;
1684   const Float_t kCOLposz = -0.1;
1685   // Thickness of the walls of the cooling arterias
1686   const Float_t kCOLthk  =  0.1;
1687   const Int_t   kNparCOL =  3;
1688   Float_t parCOL[kNparCOL];
1689   parCOL[0] = 0.0;
1690   parCOL[1] = 0.0;
1691   parCOL[2] = 0.0;
1692   gMC->Gsvolu("UTC1","BOX ",idtmed[1308-1],parCOL,0);
1693   gMC->Gsvolu("UTC3","BOX ",idtmed[1308-1],parCOL,0);
1694   parCOL[0] =  kCOLwid/2.0 - kCOLthk;
1695   parCOL[1] = -1.0;
1696   parCOL[2] =  kCOLhgt/2.0 - kCOLthk;
1697   gMC->Gsvolu("UTC2","BOX ",idtmed[1314-1],parCOL,kNparCOL);
1698   gMC->Gsvolu("UTC4","BOX ",idtmed[1314-1],parCOL,kNparCOL);
1699
1700   xpos  = 0.0;
1701   ypos  = 0.0;
1702   zpos  = 0.0;
1703   gMC->Gspos("UTC2",1,"UTC1", xpos,ypos,zpos,0,"ONLY");
1704   gMC->Gspos("UTC4",1,"UTC3", xpos,ypos,zpos,0,"ONLY");
1705
1706   for (iplan = 1; iplan < kNplan; iplan++) { 
1707
1708     // Along the chambers
1709     xpos      = fCwidth[iplan]/2.0 + kCOLwid/2.0 + kCOLposx;
1710     ypos      = 0.0;
1711     zpos      = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1712               + iplan * (fgkCH + fgkVspace);
1713     parCOL[0] = kCOLwid   /2.0;
1714     parCOL[1] = fgkSlength/2.0;
1715     parCOL[2] = kCOLhgt   /2.0;
1716     gMC->Gsposp("UTC1",iplan         ,"UTI1", xpos,ypos,zpos
1717                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1718     gMC->Gsposp("UTC1",iplan+  kNplan,"UTI1",-xpos,ypos,zpos
1719                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1720     gMC->Gsposp("UTC1",iplan+6*kNplan,"UTI2", xpos,ypos,zpos
1721                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1722     gMC->Gsposp("UTC1",iplan+7*kNplan,"UTI2",-xpos,ypos,zpos
1723                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1724     gMC->Gsposp("UTC1",iplan+8*kNplan ,"UTI3", xpos,ypos,zpos
1725                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1726     gMC->Gsposp("UTC1",iplan+9*kNplan,"UTI3",-xpos,ypos,zpos
1727                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1728
1729     // Front of supermodules
1730     xpos      = fCwidth[iplan]/2.0 + kCOLwid/2.0 + kCOLposx;
1731     ypos      = 0.0;
1732     zpos      = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1733               + iplan * (fgkCH + fgkVspace);
1734     parCOL[0] = kCOLwid   /2.0;
1735     parCOL[1] = fgkFlength/2.0;
1736     parCOL[2] = kCOLhgt   /2.0;
1737     gMC->Gsposp("UTC3",iplan+2*kNplan,"UTF1", xpos,ypos,zpos
1738                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1739     gMC->Gsposp("UTC3",iplan+3*kNplan,"UTF1",-xpos,ypos,zpos
1740                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1741     gMC->Gsposp("UTC3",iplan+4*kNplan,"UTF2", xpos,ypos,zpos
1742                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1743     gMC->Gsposp("UTC3",iplan+5*kNplan,"UTF2",-xpos,ypos,zpos
1744                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1745
1746   }
1747
1748   // The upper most layer (reaching into TOF acceptance)
1749   // Along the chambers
1750   xpos      = fCwidth[5]/2.0 - kCOLhgt/2.0 - 1.3;
1751   ypos      = 0.0;
1752   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1753   parCOL[0] = kCOLwid   /2.0;
1754   parCOL[1] = fgkSlength/2.0;
1755   parCOL[2] = kCOLhgt   /2.0;
1756   gMC->Gsposp("UTC1",6         ,"UTI1", xpos,ypos,zpos
1757                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1758   gMC->Gsposp("UTC1",6+  kNplan,"UTI1",-xpos,ypos,zpos
1759                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1760   gMC->Gsposp("UTC1",6+6*kNplan,"UTI2", xpos,ypos,zpos
1761                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1762   gMC->Gsposp("UTC1",6+7*kNplan,"UTI2",-xpos,ypos,zpos
1763                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1764   gMC->Gsposp("UTC1",6+8*kNplan,"UTI3", xpos,ypos,zpos
1765                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1766   gMC->Gsposp("UTC1",6+9*kNplan,"UTI3",-xpos,ypos,zpos
1767                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1768   // Front of supermodules
1769   xpos      = fCwidth[5]/2.0 - kCOLhgt/2.0 - 1.3;
1770   ypos      = 0.0;
1771   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1772   parCOL[0] = kCOLwid   /2.0;
1773   parCOL[1] = fgkFlength/2.0;
1774   parCOL[2] = kCOLhgt   /2.0;
1775   gMC->Gsposp("UTC3",6+2*kNplan,"UTF1", xpos,ypos,zpos
1776                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1777   gMC->Gsposp("UTC3",6+3*kNplan,"UTF1",-xpos,ypos,zpos
1778                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1779   gMC->Gsposp("UTC3",6+4*kNplan,"UTF2", xpos,ypos,zpos
1780                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1781   gMC->Gsposp("UTC3",6+5*kNplan,"UTF2",-xpos,ypos,zpos
1782                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1783
1784   //
1785   // The power bars
1786   //
1787
1788   const Float_t kPWRwid  =  0.6;
1789   const Float_t kPWRhgt  =  5.0;
1790   const Float_t kPWRposx =  1.4;
1791   const Float_t kPWRposz =  1.9;
1792   const Int_t   kNparPWR =  3;
1793   Float_t parPWR[kNparPWR];
1794   parPWR[0] = 0.0;
1795   parPWR[1] = 0.0;
1796   parPWR[2] = 0.0;
1797   gMC->Gsvolu("UTP1","BOX ",idtmed[1325-1],parPWR,0);
1798   gMC->Gsvolu("UTP3","BOX ",idtmed[1325-1],parPWR,0);
1799   
1800   for (iplan = 1; iplan < kNplan; iplan++) { 
1801
1802     // Along the chambers
1803     xpos      = fCwidth[iplan]/2.0 + kPWRwid/2.0 + kPWRposx;
1804     ypos      = 0.0;
1805     zpos      = fgkVrocsm + fgkSMpltT + kPWRhgt/2.0 - fgkSheight/2.0 + kPWRposz 
1806               + iplan * (fgkCH + fgkVspace);
1807     parPWR[0] = kPWRwid   /2.0;
1808     parPWR[1] = fgkSlength/2.0;
1809     parPWR[2] = kPWRhgt   /2.0;
1810     gMC->Gsposp("UTP1",iplan         ,"UTI1", xpos,ypos,zpos
1811                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1812     gMC->Gsposp("UTP1",iplan+  kNplan,"UTI1",-xpos,ypos,zpos
1813                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1814     gMC->Gsposp("UTP1",iplan+6*kNplan,"UTI2", xpos,ypos,zpos
1815                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1816     gMC->Gsposp("UTP1",iplan+7*kNplan,"UTI2",-xpos,ypos,zpos
1817                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1818     gMC->Gsposp("UTP1",iplan+8*kNplan,"UTI3", xpos,ypos,zpos
1819                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1820     gMC->Gsposp("UTP1",iplan+9*kNplan,"UTI3",-xpos,ypos,zpos
1821                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1822
1823     // Front of supermodule
1824     xpos      = fCwidth[iplan]/2.0 + kPWRwid/2.0 + kPWRposx;
1825     ypos      = 0.0;
1826     zpos      = fgkVrocsm + fgkSMpltT + kPWRhgt/2.0 - fgkSheight/2.0 + kPWRposz 
1827               + iplan * (fgkCH + fgkVspace);
1828     parPWR[0] = kPWRwid   /2.0;
1829     parPWR[1] = fgkFlength/2.0;
1830     parPWR[2] = kPWRhgt   /2.0;
1831     gMC->Gsposp("UTP3",iplan+2*kNplan,"UTF1", xpos,ypos,zpos
1832                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1833     gMC->Gsposp("UTP3",iplan+3*kNplan,"UTF1",-xpos,ypos,zpos
1834                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1835     gMC->Gsposp("UTP3",iplan+4*kNplan,"UTF2", xpos,ypos,zpos
1836                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1837     gMC->Gsposp("UTP3",iplan+5*kNplan,"UTF2",-xpos,ypos,zpos
1838                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1839
1840   }
1841
1842   // The upper most layer (reaching into TOF acceptance)
1843   // Along the chambers
1844   xpos      = fCwidth[5]/2.0 + kPWRhgt/2.0 - 1.3;
1845   ypos      = 0.0;
1846   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
1847   parPWR[0] = kPWRwid   /2.0;
1848   parPWR[1] = fgkSlength/2.0;
1849   parPWR[2] = kPWRhgt   /2.0;
1850   gMC->Gsposp("UTP1",6         ,"UTI1", xpos,ypos,zpos
1851                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1852   gMC->Gsposp("UTP1",6+  kNplan,"UTI1",-xpos,ypos,zpos
1853                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1854   gMC->Gsposp("UTP1",6+6*kNplan,"UTI2", xpos,ypos,zpos
1855                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1856   gMC->Gsposp("UTP1",6+7*kNplan,"UTI2",-xpos,ypos,zpos
1857                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1858   gMC->Gsposp("UTP1",6+8*kNplan,"UTI3", xpos,ypos,zpos
1859                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1860   gMC->Gsposp("UTP1",6+9*kNplan,"UTI3",-xpos,ypos,zpos
1861                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1862   // Front of supermodules
1863   xpos      = fCwidth[5]/2.0 + kPWRhgt/2.0 - 1.3;
1864   ypos      = 0.0;
1865   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
1866   parPWR[0] = kPWRwid   /2.0;
1867   parPWR[1] = fgkFlength/2.0;
1868   parPWR[2] = kPWRhgt   /2.0;
1869   gMC->Gsposp("UTP3",6+2*kNplan,"UTF1", xpos,ypos,zpos
1870                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1871   gMC->Gsposp("UTP3",6+3*kNplan,"UTF1",-xpos,ypos,zpos
1872                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1873   gMC->Gsposp("UTP3",6+4*kNplan,"UTF2", xpos,ypos,zpos
1874                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1875   gMC->Gsposp("UTP3",6+5*kNplan,"UTF2",-xpos,ypos,zpos
1876                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1877
1878   //
1879   // The gas tubes connecting the chambers in the super modules with holes
1880   //
1881
1882   parTube[0] = 0.0;
1883   parTube[1] = 2.2/2.0;
1884   parTube[2] = fClength[5][2]/2.0 - fgkHspace/2.0;
1885   gMC->Gsvolu("UTG1","TUBE",idtmed[1322-1],parTube,kNparTube);
1886   parTube[0] = 0.0;
1887   parTube[1] = 1.9/2.0;
1888   parTube[2] = fClength[5][2]/2.0 - fgkHspace/2.0;
1889   gMC->Gsvolu("UTG2","TUBE",idtmed[1309-1],parTube,kNparTube);
1890   xpos  = 0.0;
1891   ypos  = 0.0;
1892   zpos  = 0.0;
1893   gMC->Gspos("UTG2",1,"UTG1",xpos,ypos,zpos,0,"ONLY");
1894   for (iplan = 0; iplan < kNplan; iplan++) { 
1895     xpos      = fCwidth[iplan]/2.0 + kCOLwid/2.0 - 1.5;
1896     ypos      = 0.0;
1897     zpos      = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + 5.0 
1898               + iplan * (fgkCH + fgkVspace);
1899     gMC->Gspos("UTG1",1+iplan,"UTI3", xpos, ypos, zpos,matrix[4],"ONLY");
1900     gMC->Gspos("UTG1",7+iplan,"UTI3",-xpos, ypos, zpos,matrix[4],"ONLY");
1901   }
1902
1903   //
1904   // The volumes for the services at the chambers
1905   //
1906
1907   const Int_t kNparServ = 3;
1908   Float_t parServ[kNparServ];
1909
1910   for (icham = 0; icham < kNcham; icham++) {
1911     for (iplan = 0; iplan < kNplan; iplan++) {
1912
1913       Int_t iDet = GetDetectorSec(iplan,icham);
1914
1915       sprintf(cTagV,"UU%02d",iDet);
1916       parServ[0] = fCwidth[iplan]        /2.0;
1917       parServ[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
1918       parServ[2] = fgkVspace             /2.0 - 0.742/2.0; 
1919       fChamberUUboxd[iDet][0] = parServ[0];
1920       fChamberUUboxd[iDet][1] = parServ[1];
1921       fChamberUUboxd[iDet][2] = parServ[2];
1922       gMC->Gsvolu(cTagV,"BOX",idtmed[1302-1],parServ,kNparServ);
1923
1924       xpos  = 0.0;
1925       ypos  = fClength[iplan][0] + fClength[iplan][1] + fClength[iplan][2]/2.0;
1926       for (Int_t ic = 0; ic < icham; ic++) {
1927         ypos -= fClength[iplan][ic];
1928       }
1929       ypos -= fClength[iplan][icham]/2.0;
1930       zpos  = fgkVrocsm + fgkSMpltT + fgkCH + fgkVspace/2.0 - fgkSheight/2.0
1931             + iplan * (fgkCH + fgkVspace);
1932       zpos -= 0.742/2.0;
1933       fChamberUUorig[iDet][0] = xpos;
1934       fChamberUUorig[iDet][1] = ypos;
1935       fChamberUUorig[iDet][2] = zpos;
1936
1937     }
1938   }
1939
1940   //
1941   // The cooling pipes inside the service volumes
1942   //
1943
1944   // The cooling pipes
1945   parTube[0] =  0.0;
1946   parTube[1] =  0.0;
1947   parTube[2] =  0.0;
1948   gMC->Gsvolu("UTCP","TUBE",idtmed[1324-1],parTube,0);
1949   // The cooling water
1950   parTube[0] =  0.0;
1951   parTube[1] =  0.2/2.0;
1952   parTube[2] = -1.0;
1953   gMC->Gsvolu("UTCH","TUBE",idtmed[1314-1],parTube,kNparTube);
1954   // Water inside the cooling pipe
1955   xpos = 0.0;
1956   ypos = 0.0;
1957   zpos = 0.0;
1958   gMC->Gspos("UTCH",1,"UTCP",xpos,ypos,zpos,0,"ONLY");
1959
1960   // Position the cooling pipes in the mother volume
1961   for (icham = 0; icham < kNcham;   icham++) {
1962     for (iplan = 0; iplan < kNplan; iplan++) {
1963       Int_t   iDet    = GetDetectorSec(iplan,icham);
1964       Int_t   iCopy   = GetDetector(iplan,icham,0) * 100;
1965       Int_t   nMCMrow = GetRowMax(iplan,icham,0);
1966       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
1967                       / ((Float_t) nMCMrow);
1968       sprintf(cTagV,"UU%02d",iDet);
1969       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
1970         xpos   = 0.0;
1971         ypos   = (0.5 + iMCMrow) * ySize - 1.9 
1972                - fClength[iplan][icham]/2.0 + fgkHspace/2.0;
1973         zpos   = 0.0 + 0.742/2.0;                 
1974         // The cooling pipes
1975         parTube[0] = 0.0;
1976         parTube[1] = 0.3/2.0; // Thickness of the cooling pipes
1977         parTube[2] = fCwidth[iplan]/2.0;
1978         gMC->Gsposp("UTCP",iCopy+iMCMrow,cTagV,xpos,ypos,zpos
1979                           ,matrix[2],"ONLY",parTube,kNparTube);
1980       }
1981     }
1982   }
1983
1984   //
1985   // The power lines
1986   //
1987
1988   // The copper power lines
1989   parTube[0] = 0.0;
1990   parTube[1] = 0.0;
1991   parTube[2] = 0.0;
1992   gMC->Gsvolu("UTPL","TUBE",idtmed[1305-1],parTube,0);
1993
1994   // Position the power lines in the mother volume
1995   for (icham = 0; icham < kNcham;   icham++) {
1996     for (iplan = 0; iplan < kNplan; iplan++) {
1997       Int_t   iDet    = GetDetectorSec(iplan,icham);
1998       Int_t   iCopy   = GetDetector(iplan,icham,0) * 100;
1999       Int_t   nMCMrow = GetRowMax(iplan,icham,0);
2000       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
2001                       / ((Float_t) nMCMrow);
2002       sprintf(cTagV,"UU%02d",iDet);
2003       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
2004         xpos       = 0.0;
2005         ypos       = (0.5 + iMCMrow) * ySize - 1.0 
2006                    - fClength[iplan][icham]/2.0 + fgkHspace/2.0;
2007         zpos       = -0.4 + 0.742/2.0;
2008         parTube[0] = 0.0;
2009         parTube[1] = 0.2/2.0; // Thickness of the power lines
2010         parTube[2] = fCwidth[iplan]/2.0;
2011         gMC->Gsposp("UTPL",iCopy+iMCMrow,cTagV,xpos,ypos,zpos
2012                           ,matrix[2],"ONLY",parTube,kNparTube);
2013       }
2014     }
2015   }
2016
2017   //
2018   // The MCMs
2019   //
2020
2021   const Float_t kMCMx    = 3.0;
2022   const Float_t kMCMy    = 3.0;
2023   const Float_t kMCMz    = 0.3;
2024   
2025   const Float_t kMCMpcTh = 0.1;
2026   const Float_t kMCMcuTh = 0.0025;
2027   const Float_t kMCMsiTh = 0.03;
2028   const Float_t kMCMcoTh = 0.04;
2029
2030   // The mother volume for the MCMs (air)
2031   const Int_t kNparMCM = 3;
2032   Float_t parMCM[kNparMCM];
2033   parMCM[0] = kMCMx   /2.0;
2034   parMCM[1] = kMCMy   /2.0;
2035   parMCM[2] = kMCMz   /2.0;
2036   gMC->Gsvolu("UMCM","BOX",idtmed[1302-1],parMCM,kNparMCM);
2037
2038   // The MCM carrier G10 layer
2039   parMCM[0] = kMCMx   /2.0;
2040   parMCM[1] = kMCMy   /2.0;
2041   parMCM[2] = kMCMpcTh/2.0;
2042   gMC->Gsvolu("UMC1","BOX",idtmed[1319-1],parMCM,kNparMCM);
2043   // The MCM carrier Cu layer
2044   parMCM[0] = kMCMx   /2.0;
2045   parMCM[1] = kMCMy   /2.0;
2046   parMCM[2] = kMCMcuTh/2.0;
2047   gMC->Gsvolu("UMC2","BOX",idtmed[1318-1],parMCM,kNparMCM);
2048   // The silicon of the chips
2049   parMCM[0] = kMCMx   /2.0;
2050   parMCM[1] = kMCMy   /2.0;
2051   parMCM[2] = kMCMsiTh/2.0;
2052   gMC->Gsvolu("UMC3","BOX",idtmed[1320-1],parMCM,kNparMCM);
2053   // The aluminum of the cooling plates
2054   parMCM[0] = kMCMx   /2.0;
2055   parMCM[1] = kMCMy   /2.0;
2056   parMCM[2] = kMCMcoTh/2.0;
2057   gMC->Gsvolu("UMC4","BOX",idtmed[1324-1],parMCM,kNparMCM);
2058
2059   // Put the MCM material inside the MCM mother volume
2060   xpos  =  0.0;
2061   ypos  =  0.0;
2062   zpos  = -kMCMz   /2.0 + kMCMpcTh/2.0;
2063   gMC->Gspos("UMC1",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2064   zpos +=  kMCMpcTh/2.0 + kMCMcuTh/2.0;
2065   gMC->Gspos("UMC2",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2066   zpos +=  kMCMcuTh/2.0 + kMCMsiTh/2.0;
2067   gMC->Gspos("UMC3",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2068   zpos +=  kMCMsiTh/2.0 + kMCMcoTh/2.0;
2069   gMC->Gspos("UMC4",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2070
2071   // Position the MCMs in the mother volume
2072   for (icham = 0; icham < kNcham;   icham++) {
2073     for (iplan = 0; iplan < kNplan; iplan++) {
2074       Int_t   iDet    = GetDetectorSec(iplan,icham);
2075       Int_t   iCopy   = GetDetector(iplan,icham,0) * 1000;
2076       Int_t   nMCMrow = GetRowMax(iplan,icham,0);
2077       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
2078                       / ((Float_t) nMCMrow);
2079       Int_t   nMCMcol = 8;
2080       Float_t xSize   = (GetChamberWidth(iplan)        - 2.0*fgkCpadW)
2081                       / ((Float_t) nMCMcol);
2082       sprintf(cTagV,"UU%02d",iDet);
2083       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
2084         for (Int_t iMCMcol = 0; iMCMcol < nMCMcol; iMCMcol++) {
2085           xpos      = (0.5 + iMCMcol) * xSize + 1.0 
2086                     - fCwidth[iplan]/2.0;
2087           ypos      = (0.5 + iMCMrow) * ySize + 1.0 
2088                     - fClength[iplan][icham]/2.0 + fgkHspace/2.0;
2089           zpos      = -0.4 + 0.742/2.0;
2090           gMC->Gspos("UMCM",iCopy+iMCMrow*10+iMCMcol,cTagV
2091                            ,xpos,ypos,zpos,0,"ONLY");
2092         }
2093       }
2094
2095     }
2096   }
2097
2098   //
2099   // Services in front of the super module
2100   //
2101
2102   // Gas in-/outlet pipes (INOX)
2103   parTube[0] = 0.0;
2104   parTube[1] = 0.0;
2105   parTube[2] = 0.0;
2106   gMC->Gsvolu("UTG3","TUBE",idtmed[1308-1],parTube,0);
2107   // The gas inside the in-/outlet pipes (Xe)
2108   parTube[0] =  0.0;
2109   parTube[1] =  1.2/2.0;
2110   parTube[2] = -1.0;
2111   gMC->Gsvolu("UTG4","TUBE",idtmed[1309-1],parTube,kNparTube);
2112   xpos = 0.0;
2113   ypos = 0.0;
2114   zpos = 0.0;
2115   gMC->Gspos("UTG4",1,"UTG3",xpos,ypos,zpos,0,"ONLY");
2116   for (iplan = 0; iplan < kNplan-1; iplan++) { 
2117     xpos       = 0.0;
2118     ypos       = fClength[iplan][2]/2.0 
2119                + fClength[iplan][1] 
2120                + fClength[iplan][0];
2121     zpos       = 9.0 - fgkSheight/2.0
2122                + iplan * (fgkCH + fgkVspace);
2123     parTube[0] = 0.0;
2124     parTube[1] = 1.5/2.0;
2125     parTube[2] = fCwidth[iplan]/2.0 - 2.5;
2126     gMC->Gsposp("UTG3",iplan+1         ,"UTI1", xpos, ypos, zpos
2127                       ,matrix[2],"ONLY",parTube,kNparTube);
2128     gMC->Gsposp("UTG3",iplan+1+1*kNplan,"UTI1", xpos,-ypos, zpos
2129                       ,matrix[2],"ONLY",parTube,kNparTube);
2130     gMC->Gsposp("UTG3",iplan+1+2*kNplan,"UTI2", xpos, ypos, zpos
2131                       ,matrix[2],"ONLY",parTube,kNparTube);
2132     gMC->Gsposp("UTG3",iplan+1+3*kNplan,"UTI2", xpos,-ypos, zpos
2133                       ,matrix[2],"ONLY",parTube,kNparTube);
2134     gMC->Gsposp("UTG3",iplan+1+4*kNplan,"UTI3", xpos, ypos, zpos
2135                       ,matrix[2],"ONLY",parTube,kNparTube);
2136     gMC->Gsposp("UTG3",iplan+1+5*kNplan,"UTI3", xpos,-ypos, zpos
2137                       ,matrix[2],"ONLY",parTube,kNparTube);
2138   }
2139
2140   // Gas distribution box
2141   parBox[0] = 14.50/2.0;
2142   parBox[1] =  4.52/2.0;
2143   parBox[2] =  5.00/2.0;
2144   gMC->Gsvolu("UTGD","BOX ",idtmed[1308-1],parBox,kNparBox);
2145   parBox[0] = 14.50/2.0;
2146   parBox[1] =  4.00/2.0;
2147   parBox[2] =  4.40/2.0;
2148   gMC->Gsvolu("UTGI","BOX ",idtmed[1309-1],parBox,kNparBox);
2149   parTube[0] = 0.0;
2150   parTube[1] = 4.0/2.0;
2151   parTube[2] = 8.0/2.0;
2152   gMC->Gsvolu("UTGT","TUBE",idtmed[1308-1],parTube,kNparTube);
2153   parTube[0] = 0.0;
2154   parTube[1] = 3.4/2.0;
2155   parTube[2] = 8.0/2.0;
2156   gMC->Gsvolu("UTGG","TUBE",idtmed[1309-1],parTube,kNparTube);
2157   xpos = 0.0;
2158   ypos = 0.0;
2159   zpos = 0.0;
2160   gMC->Gspos("UTGI",1,"UTGD",xpos,ypos,zpos,        0,"ONLY");
2161   gMC->Gspos("UTGG",1,"UTGT",xpos,ypos,zpos,        0,"ONLY");
2162   xpos = 0.0;
2163   ypos = 0.0;
2164   zpos = 0.0;
2165   gMC->Gspos("UTGD",1,"UTF1",xpos,ypos,zpos,        0,"ONLY");
2166   gMC->Gspos("UTGD",2,"UTF2",xpos,ypos,zpos,        0,"ONLY");
2167   xpos =  -3.0;
2168   ypos =   0.0;
2169   zpos =   6.5;
2170   gMC->Gspos("UTGT",1,"UTF1",xpos,ypos,zpos,        0,"ONLY");
2171   gMC->Gspos("UTGT",2,"UTF2",xpos,ypos,zpos,        0,"ONLY");
2172   xpos = -11.25;
2173   ypos =   0.0;
2174   zpos =   0.5;
2175   gMC->Gspos("UTGT",3,"UTF1",xpos,ypos,zpos,matrix[2],"ONLY");
2176   gMC->Gspos("UTGT",4,"UTF2",xpos,ypos,zpos,matrix[2],"ONLY");
2177   xpos =  11.25;
2178   ypos =   0.0;
2179   zpos =   0.5;
2180   gMC->Gspos("UTGT",5,"UTF1",xpos,ypos,zpos,matrix[2],"ONLY");
2181   gMC->Gspos("UTGT",6,"UTF2",xpos,ypos,zpos,matrix[2],"ONLY");
2182
2183   // Cooling manifolds
2184   parBox[0]  =  5.0/2.0;
2185   parBox[1]  = 23.0/2.0;
2186   parBox[2]  = 70.0/2.0;
2187   gMC->Gsvolu("UTCM","BOX ",idtmed[1302-1],parBox,kNparBox);
2188   parBox[0]  =  5.0/2.0;
2189   parBox[1]  =  5.0/2.0;
2190   parBox[2]  = 70.0/2.0;
2191   gMC->Gsvolu("UTCA","BOX ",idtmed[1308-1],parBox,kNparBox);
2192   parBox[0]  =  5.0/2.0 - 0.3;
2193   parBox[1]  =  5.0/2.0 - 0.3;
2194   parBox[2]  = 70.0/2.0 - 0.3;
2195   gMC->Gsvolu("UTCW","BOX ",idtmed[1314-1],parBox,kNparBox);
2196   xpos       =  0.0;
2197   ypos       =  0.0;
2198   zpos       =  0.0;
2199   gMC->Gspos("UTCW",1,"UTCA", xpos, ypos, zpos,        0,"ONLY");
2200   xpos       =  0.0;
2201   ypos       =  5.0/2.0 - 23.0/2.0;
2202   zpos       =  0.0;
2203   gMC->Gspos("UTCA",1,"UTCM", xpos, ypos, zpos,        0,"ONLY");
2204   parTube[0] =  0.0;
2205   parTube[1] =  3.0/2.0;
2206   parTube[2] = 18.0/2.0;
2207   gMC->Gsvolu("UTCO","TUBE",idtmed[1308-1],parTube,kNparTube);
2208   parTube[0] =  0.0;
2209   parTube[1] =  3.0/2.0 - 0.3;
2210   parTube[2] = 18.0/2.0;
2211   gMC->Gsvolu("UTCL","TUBE",idtmed[1314-1],parTube,kNparTube);
2212   xpos       =  0.0;
2213   ypos       =  0.0;
2214   zpos       =  0.0;
2215   gMC->Gspos("UTCL",1,"UTCO", xpos, ypos, zpos,        0,"ONLY");
2216   xpos       =  0.0;
2217   ypos       =  2.5;
2218   zpos       = -70.0/2.0 + 7.0;
2219   gMC->Gspos("UTCO",1,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2220   zpos      +=  7.0;
2221   gMC->Gspos("UTCO",2,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2222   zpos      +=  7.0;
2223   gMC->Gspos("UTCO",3,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2224   zpos      +=  7.0;
2225   gMC->Gspos("UTCO",4,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2226   zpos      +=  7.0;
2227   gMC->Gspos("UTCO",5,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2228   zpos      +=  7.0;
2229   gMC->Gspos("UTCO",6,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2230   zpos      +=  7.0;
2231   gMC->Gspos("UTCO",7,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2232   zpos      +=  7.0;
2233   gMC->Gspos("UTCO",8,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2234
2235   xpos = 40.0;
2236   ypos =  fgkFlength/2.0 - 23.0/2.0;
2237   zpos =  0.0;
2238   gMC->Gspos("UTCM",1,"UTF1", xpos, ypos, zpos,matrix[0],"ONLY");
2239   gMC->Gspos("UTCM",2,"UTF1",-xpos, ypos, zpos,matrix[1],"ONLY");
2240   gMC->Gspos("UTCM",3,"UTF2", xpos,-ypos, zpos,matrix[5],"ONLY");
2241   gMC->Gspos("UTCM",4,"UTF2",-xpos,-ypos, zpos,matrix[6],"ONLY");
2242
2243 }
2244
2245 //_____________________________________________________________________________
2246 void AliTRDgeometry::GroupChamber(Int_t iplan, Int_t icham, Int_t *idtmed)
2247 {
2248   //
2249   // Group volumes UA, UD, UF, UU in a single chamber (Air)
2250   // UA, UD, UF, UU are boxes
2251   // UT will be a box
2252   //
2253
2254   const Int_t kNparCha = 3;
2255
2256   Int_t iDet = GetDetectorSec(iplan,icham);
2257
2258   Float_t xyzMin[3];
2259   Float_t xyzMax[3];
2260   Float_t xyzOrig[3];
2261   Float_t xyzBoxd[3];
2262
2263   Char_t  cTagV[5];
2264   Char_t  cTagM[5];
2265
2266   for (Int_t i = 0; i < 3; i++) {
2267     xyzMin[i] = +9999.0; 
2268     xyzMax[i] = -9999.0;
2269   }
2270
2271   for (Int_t i = 0; i < 3; i++) {
2272
2273     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUAorig[iDet][i]-fChamberUAboxd[iDet][i]);
2274     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUAorig[iDet][i]+fChamberUAboxd[iDet][i]);
2275
2276     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUDorig[iDet][i]-fChamberUDboxd[iDet][i]);
2277     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUDorig[iDet][i]+fChamberUDboxd[iDet][i]);
2278
2279     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUForig[iDet][i]-fChamberUFboxd[iDet][i]);
2280     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUForig[iDet][i]+fChamberUFboxd[iDet][i]);
2281
2282     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUUorig[iDet][i]-fChamberUUboxd[iDet][i]);
2283     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUUorig[iDet][i]+fChamberUUboxd[iDet][i]);
2284
2285     xyzOrig[i] = 0.5*(xyzMax[i]+xyzMin[i]);
2286     xyzBoxd[i] = 0.5*(xyzMax[i]-xyzMin[i]);
2287
2288   }
2289   
2290   sprintf(cTagM,"UT%02d",iDet);
2291   gMC->Gsvolu(cTagM,"BOX ",idtmed[1302-1],xyzBoxd,kNparCha);
2292
2293   sprintf(cTagV,"UA%02d",iDet);
2294   gMC->Gspos(cTagV,1,cTagM
2295             ,fChamberUAorig[iDet][0]-xyzOrig[0]
2296             ,fChamberUAorig[iDet][1]-xyzOrig[1]
2297             ,fChamberUAorig[iDet][2]-xyzOrig[2]
2298             ,0,"ONLY");
2299
2300   sprintf(cTagV,"UZ%02d",iDet);
2301   gMC->Gspos(cTagV,1,cTagM
2302             ,fChamberUAorig[iDet][0]-xyzOrig[0] + fChamberUAboxd[iDet][0] - fgkCroW/2.0
2303             ,fChamberUAorig[iDet][1]-xyzOrig[1]
2304             ,fChamberUAorig[iDet][2]-xyzOrig[2] + fgkCraH/2.0 + fgkCdrH/2.0 - fgkCalW/2.0
2305             ,0,"ONLY");
2306   gMC->Gspos(cTagV,2,cTagM
2307             ,fChamberUAorig[iDet][0]-xyzOrig[0] - fChamberUAboxd[iDet][0] + fgkCroW/2.0
2308             ,fChamberUAorig[iDet][1]-xyzOrig[1]
2309             ,fChamberUAorig[iDet][2]-xyzOrig[2] + fgkCraH/2.0 + fgkCdrH/2.0 - fgkCalW/2.0
2310             ,0,"ONLY");
2311
2312   sprintf(cTagV,"UD%02d",iDet);
2313   gMC->Gspos(cTagV,1,cTagM
2314             ,fChamberUDorig[iDet][0]-xyzOrig[0]
2315             ,fChamberUDorig[iDet][1]-xyzOrig[1]
2316             ,fChamberUDorig[iDet][2]-xyzOrig[2]
2317             ,0,"ONLY");
2318
2319   sprintf(cTagV,"UF%02d",iDet);
2320   gMC->Gspos(cTagV,1,cTagM
2321             ,fChamberUForig[iDet][0]-xyzOrig[0]
2322             ,fChamberUForig[iDet][1]-xyzOrig[1]
2323             ,fChamberUForig[iDet][2]-xyzOrig[2]
2324             ,0,"ONLY");
2325   
2326   sprintf(cTagV,"UU%02d",iDet);
2327   gMC->Gspos(cTagV,1,cTagM
2328             ,fChamberUUorig[iDet][0]-xyzOrig[0]
2329             ,fChamberUUorig[iDet][1]-xyzOrig[1]
2330             ,fChamberUUorig[iDet][2]-xyzOrig[2]
2331             ,0,"ONLY");
2332
2333   sprintf(cTagV,"UT%02d",iDet);
2334   gMC->Gspos(cTagV,1,"UTI1"
2335             ,xyzOrig[0]
2336             ,xyzOrig[1]
2337             ,xyzOrig[2]
2338             ,0,"ONLY");
2339   gMC->Gspos(cTagV,1,"UTI2"
2340             ,xyzOrig[0]
2341             ,xyzOrig[1]
2342             ,xyzOrig[2]
2343             ,0,"ONLY");
2344   if (icham != 2) {
2345     // W/o middle stack
2346     gMC->Gspos(cTagV,1,"UTI3"
2347               ,xyzOrig[0]
2348               ,xyzOrig[1]
2349               ,xyzOrig[2]
2350               ,0,"ONLY");
2351   }
2352
2353 }
2354
2355 //_____________________________________________________________________________
2356 Bool_t AliTRDgeometry::RotateBack(Int_t det, Double_t *loc, Double_t *glb) const
2357 {
2358   //
2359   // Rotates a chambers to transform the corresponding local frame
2360   // coordinates <loc> into the coordinates of the ALICE restframe <glb>.
2361   //
2362
2363   Int_t sector = GetSector(det);
2364
2365   glb[0] = loc[0] * fRotB11[sector] - loc[1] * fRotB12[sector];
2366   glb[1] = loc[0] * fRotB21[sector] + loc[1] * fRotB22[sector];
2367   glb[2] = loc[2];
2368
2369   return kTRUE;
2370
2371 }
2372
2373 //_____________________________________________________________________________
2374 Int_t AliTRDgeometry::GetDetectorSec(Int_t p, Int_t c)
2375 {
2376   //
2377   // Convert plane / chamber into detector number for one single sector
2378   //
2379
2380   return (p + c * fgkNplan);
2381
2382 }
2383
2384 //_____________________________________________________________________________
2385 Int_t AliTRDgeometry::GetDetector(Int_t p, Int_t c, Int_t s)
2386 {
2387   //
2388   // Convert plane / chamber / sector into detector number
2389   //
2390
2391   return (p + c * fgkNplan + s * fgkNplan * fgkNcham);
2392
2393 }
2394
2395 //_____________________________________________________________________________
2396 Int_t AliTRDgeometry::GetPlane(Int_t d)
2397 {
2398   //
2399   // Reconstruct the plane number from the detector number
2400   //
2401
2402   return ((Int_t) (d % fgkNplan));
2403
2404 }
2405
2406 //_____________________________________________________________________________
2407 Int_t AliTRDgeometry::GetChamber(Int_t d) const
2408 {
2409   //
2410   // Reconstruct the chamber number from the detector number
2411   //
2412
2413   return ((Int_t) (d % (fgkNplan * fgkNcham)) / fgkNplan);
2414
2415 }
2416
2417 //_____________________________________________________________________________
2418 Int_t AliTRDgeometry::GetChamber(Double_t z, Int_t plane)
2419 {
2420   //
2421   // Reconstruct the chamber number from the z position and plane number
2422   //
2423   // The return function has to be protected for pozitiveness !!
2424
2425         if(plane<0 || plane>=fgkNplan) return -1;
2426         
2427         Int_t ichmb = fgkNcham;
2428         Double_t zmin, zmax;
2429   //printf("Looking for z[%7.3f] in plane %d\n", z, plane);
2430   do{
2431         ichmb--;
2432         if(ichmb<0) break;
2433         AliTRDpadPlane *pp = GetPadPlane(plane, ichmb);
2434     zmax  = pp->GetRow0();
2435     // why don't we have the function AliTRDpadPlane::GetLength() ???
2436                 Int_t nrows = pp->GetNrows();
2437                 zmin = zmax - 2*pp->GetLengthOPad() - (nrows-2)*pp->GetLengthIPad() - (nrows-1)*pp->GetRowSpacing(); // pp->GetLength();
2438         //printf("%d %7.3f %7.3f\n", ichmb, zmin, zmax);
2439   } while(z < zmin || z > zmax);
2440   
2441   return ichmb;
2442 }
2443
2444
2445 //_____________________________________________________________________________
2446 Int_t AliTRDgeometry::GetSector(Int_t d) const
2447 {
2448   //
2449   // Reconstruct the sector number from the detector number
2450   //
2451
2452   return ((Int_t) (d / (fgkNplan * fgkNcham)));
2453
2454 }
2455
2456 //_____________________________________________________________________________
2457 AliTRDpadPlane *AliTRDgeometry::GetPadPlane(Int_t p, Int_t c)
2458 {
2459   //
2460   // Returns the pad plane for a given plane <p> and chamber <c> number
2461   //
2462
2463   if (!fPadPlaneArray) {
2464     CreatePadPlaneArray();
2465   }
2466
2467   Int_t ipp = GetDetectorSec(p,c);
2468   return ((AliTRDpadPlane *) fPadPlaneArray->At(ipp));
2469
2470 }
2471
2472 //_____________________________________________________________________________
2473 Int_t AliTRDgeometry::GetRowMax(Int_t p, Int_t c, Int_t /*s*/)
2474 {
2475   //
2476   // Returns the number of rows on the pad plane
2477   //
2478
2479   return GetPadPlane(p,c)->GetNrows();
2480
2481 }
2482
2483 //_____________________________________________________________________________
2484 Int_t AliTRDgeometry::GetColMax(Int_t p)
2485 {
2486   //
2487   // Returns the number of rows on the pad plane
2488   //
2489
2490   return GetPadPlane(p,0)->GetNcols();
2491
2492 }
2493
2494 //_____________________________________________________________________________
2495 Double_t AliTRDgeometry::GetRow0(Int_t p, Int_t c, Int_t /*s*/)
2496 {
2497   //
2498   // Returns the position of the border of the first pad in a row
2499   //
2500
2501   return GetPadPlane(p,c)->GetRow0();
2502
2503 }
2504
2505 //_____________________________________________________________________________
2506 Double_t AliTRDgeometry::GetCol0(Int_t p)
2507 {
2508   //
2509   // Returns the position of the border of the first pad in a column
2510   //
2511
2512   return GetPadPlane(p,0)->GetCol0();
2513
2514 }
2515
2516 //_____________________________________________________________________________
2517 //Int_t AliTRDgeometry::GetPadRowFromMCM(Int_t irob, Int_t imcm) const
2518 //{
2519   //
2520   // Return on which row this mcm sits 
2521   //
2522 //
2523 //  return fgkMCMrow*(irob/2) + imcm/fgkMCMrow;
2524 //
2525 //}
2526
2527 //_____________________________________________________________________________
2528 //Int_t AliTRDgeometry::GetPadColFromADC(Int_t irob, Int_t imcm, Int_t iadc) const
2529 //{
2530   //
2531   // Return which pad is connected to this adc channel. return -1 if it
2532   // is one of the not directly connected adc channels (0, 1 20)
2533   //
2534 //
2535 //  if (iadc < 2 || iadc > 19 ) return -1;
2536 //
2537 //  return (iadc-2) + (imcm%fgkMCMrow)*fgkPadmax + GetRobSide(irob)*fgkColmax/2;
2538 //
2539 //}
2540
2541 //_____________________________________________________________________________
2542 //Int_t AliTRDgeometry::GetMCMfromPad(Int_t irow, Int_t icol) const
2543 //{
2544   //
2545   // Return on which mcm this pad is
2546   //
2547 //
2548 //  if ( irow < 0 || icol < 0 || irow > fgkRowmaxC1 || icol > fgkColmax ) return -1;
2549 //
2550 //  return (icol%(fgkColmax/2))/fgkPadmax + fgkMCMrow*(irow%fgkMCMrow);
2551 //
2552 //}
2553
2554 //_____________________________________________________________________________
2555 //Int_t AliTRDgeometry::GetROBfromPad(Int_t irow, Int_t icol) const
2556 //{
2557   //
2558   // Return on which rob this pad is
2559   //
2560 //
2561 //  return (irow/fgkMCMrow)*2 + GetColSide(icol);
2562 //
2563 //}
2564
2565 //_____________________________________________________________________________
2566 //Int_t AliTRDgeometry::GetRobSide(Int_t irob) const
2567 //{
2568   //
2569   // Return on which side this rob sits (A side = 0, B side = 1)
2570   //
2571 //
2572 //  if ( irob < 0 || irob >= fgkROBmaxC1 ) return -1;
2573 //
2574 //  return irob%2;
2575 //
2576 //}
2577
2578 //_____________________________________________________________________________
2579 //Int_t AliTRDgeometry::GetColSide(Int_t icol) const
2580 //{
2581   //
2582   // Return on which side this column sits (A side = 0, B side = 1)
2583   //
2584 //
2585 //  if ( icol < 0 || icol >= fgkColmax ) return -1;
2586 //
2587 //  return icol/(fgkColmax/2);
2588 //
2589 //}
2590
2591 //_____________________________________________________________________________
2592 Bool_t AliTRDgeometry::CreateClusterMatrixArray()
2593 {
2594   //
2595   // Create the matrices to transform cluster coordinates from the 
2596   // local chamber system to the tracking coordinate system
2597   //
2598
2599   if (!gGeoManager) {
2600     return kFALSE;
2601   }
2602
2603   fClusterMatrixArray = new TObjArray(kNdet);
2604   AliAlignObjParams o;
2605
2606   for (Int_t iLayer = AliGeomManager::kTRD1; iLayer <= AliGeomManager::kTRD6; iLayer++) {
2607     for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer); iModule++) {
2608
2609       UShort_t     volid   = AliGeomManager::LayerToVolUID(iLayer,iModule);
2610       const char  *symname = AliGeomManager::SymName(volid);
2611       TGeoPNEntry *pne     = gGeoManager->GetAlignableEntry(symname);
2612       const char  *path    = symname;
2613       if (pne) {
2614         path = pne->GetTitle();
2615       }
2616       if (!strstr(path,"ALIC")) {
2617         AliDebug(1,Form("Not a valid path: %s\n",path));
2618         continue;
2619       }
2620       if (!gGeoManager->cd(path)) {
2621         AliError(Form("Cannot go to path: %s\n",path));
2622         continue;
2623       }
2624       TGeoHMatrix *m         = gGeoManager->GetCurrentMatrix();
2625       Int_t        iLayerTRD = iLayer - AliGeomManager::kTRD1;
2626       Int_t        isector   = iModule/Ncham();
2627       Int_t        ichamber  = iModule%Ncham();
2628       Int_t        lid       = GetDetector(iLayerTRD,ichamber,isector);    
2629       
2630       TGeoRotation mchange; 
2631       mchange.RotateY(90); 
2632       mchange.RotateX(90);
2633
2634       //
2635       // Cluster transformation matrix
2636       //
2637       TGeoHMatrix  rotMatrix(mchange.Inverse());
2638       rotMatrix.MultiplyLeft(m);
2639       Double_t sectorAngle = 20.0 * (isector % 18) + 10.0;
2640       TGeoHMatrix  rotSector;
2641       rotSector.RotateZ(sectorAngle);
2642       rotMatrix.MultiplyLeft(&rotSector.Inverse());
2643
2644       fClusterMatrixArray->AddAt(new TGeoHMatrix(rotMatrix),lid);       
2645
2646     }    
2647   }
2648
2649   return kTRUE;
2650
2651 }
2652
2653 //_____________________________________________________________________________
2654 Bool_t AliTRDgeometry::ChamberInGeometry(Int_t det)
2655 {
2656   //
2657   // Checks whether the given detector is part of the current geometry
2658   //
2659
2660   if (!fClusterMatrixArray) {
2661     CreateClusterMatrixArray();
2662   }  
2663
2664   if (!GetClusterMatrix(det)) {
2665     return kFALSE;
2666   }
2667   else {
2668     return kTRUE;
2669   }
2670
2671 }