Enalrged size of char arrays
[u/mrichter/AliRoot.git] / TRD / AliTRDgeometry.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  TRD geometry class                                                       //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TGeoManager.h>
25 #include <TGeoPhysicalNode.h>
26 #include <TGeoMatrix.h>
27
28 #include "AliLog.h"
29 #include "AliRunLoader.h"
30 #include "AliAlignObj.h"
31 #include "AliAlignObjParams.h"
32 #include "AliRun.h"
33
34 #include "AliTRD.h"
35 #include "AliTRDcalibDB.h"
36 #include "AliTRDgeometry.h"
37 #include "AliTRDpadPlane.h"
38 #include "AliTRDCommonParam.h"
39
40 ClassImp(AliTRDgeometry)
41
42 //_____________________________________________________________________________
43
44   //
45   // The geometry constants
46   //
47   const Int_t    AliTRDgeometry::fgkNsector   = kNsector;
48   const Int_t    AliTRDgeometry::fgkNlayer    = kNlayer;
49   const Int_t    AliTRDgeometry::fgkNstack    = kNstack;
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 istack;
240   Int_t ilayer;
241   Int_t isector;
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[kNlayer][kNstack]   = { { 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 (istack = 0; istack < kNstack; istack++) {
261     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
262       fClength[ilayer][istack] = length[ilayer][istack];
263     }
264   }
265
266   // The rotation matrix elements
267   Float_t phi = 0.0;
268   for (isector = 0; isector < fgkNsector; isector++) {
269     phi = 2.0 * TMath::Pi() /  (Float_t) fgkNsector * ((Float_t) isector + 0.5);
270     fRotB11[isector] = TMath::Cos(phi);
271     fRotB12[isector] = TMath::Sin(phi);
272     fRotB21[isector] = TMath::Sin(phi);
273     fRotB22[isector] = TMath::Cos(phi);
274   }
275  
276   // SM status
277   for (Int_t i = 0; i < kNsector; i++) {
278     fSMstatus[i] = 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(fgkNlayer * fgkNstack);  
296   for (Int_t ilayer = 0; ilayer < fgkNlayer; ilayer++) {
297     for (Int_t istack = 0; istack < fgkNstack; istack++) {
298       Int_t ipp = GetDetectorSec(ilayer,istack);
299       fPadPlaneArray->AddAt(CreatePadPlane(ilayer,istack),ipp);
300     }
301   }
302
303 }
304
305 //_____________________________________________________________________________
306 AliTRDpadPlane *AliTRDgeometry::CreatePadPlane(Int_t ilayer, Int_t istack)
307 {
308   //
309   // Creates an AliTRDpadPlane object
310   //
311
312   AliTRDpadPlane *padPlane = new AliTRDpadPlane();
313
314   padPlane->SetLayer(ilayer);
315   padPlane->SetStack(istack);
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 (ilayer) {
329   case 0:
330     if (istack == 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 (istack == 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 (istack == 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 (istack == 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 (istack == 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 (istack == 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[ilayer][istack] / 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[ilayer] / 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[ilayer][0]
512                   + fClength[ilayer][1]
513                   + fClength[ilayer][2] / 2.0;
514   for (Int_t jstack = 0; jstack < istack; jstack++) {
515     rowTmp -= fClength[ilayer][jstack];
516   }
517   padPlane->SetPadRowSMOffset(rowTmp - fClength[ilayer][istack]/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[100];
579   Char_t  cTagM[100];
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 istack = 0; istack < kNstack; istack++) {
624     for (Int_t ilayer = 0; ilayer < kNlayer; ilayer++) {  
625
626       Int_t iDet = GetDetectorSec(ilayer,istack);
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[ilayer]/2.0;
632       parCha[1] = fClength[ilayer][istack]/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[ilayer][istack]/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[ilayer]/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[ilayer]/2.0 - fgkCalT - fgkCclsT; 
657       parCha[1] = fClength[ilayer][istack]/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[ilayer]/2.0 - fgkCalT - fgkCclsT - fgkCglT; 
663       parCha[1] = fClength[ilayer][istack]/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[ilayer]/2.0 + fgkCroW;
671       parCha[1] = fClength[ilayer][istack]/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[ilayer]/2.0 + fgkCroW - fgkCcuT; 
680       parCha[1] = fClength[ilayer][istack]/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[ilayer]/2.0 + fgkCroW;
688       parCha[1] = fClength[ilayer][istack]/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[ilayer]/2.0 + fgkCroW - fgkCauT; 
697       parCha[1] = fClength[ilayer][istack]/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[ilayer]/2.0 - fgkCalT - fgkCclsT;
710       parCha[1] = fClength[ilayer][istack]/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[ilayer][0] + fClength[ilayer][1] + fClength[ilayer][2]/2.0;
852       for (Int_t ic = 0; ic < istack; ic++) {
853         ypos -= fClength[ilayer][ic];
854       }
855       ypos -= fClength[ilayer][istack]/2.0;
856       zpos  = fgkVrocsm + fgkSMpltT + fgkCraH/2.0 + fgkCdrH/2.0 - fgkSheight/2.0
857             + ilayer * (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 istack = 0; istack < kNstack; istack++) {
886     for (Int_t ilayer = 0; ilayer < kNlayer; ilayer++) {  
887       GroupChamber(ilayer,istack,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 isector = 0; isector < kNsector; isector++) {
911     if (GetSMstatus(isector)) {
912       sprintf(cTagV,"BTRD%d",isector);
913       switch (isector) {
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 isector = 0; isector < kNsector; isector++) {
938     if (GetSMstatus(isector)) {
939       sprintf(cTagV,"BTRD%d",isector);
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   ilayer = 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[100];
968   Char_t  cTagM[100];
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 (ilayer = 0; ilayer < kNlayer; ilayer++) {
1086     xpos  = fCwidth[ilayer]/2.0 + kSRLwid/2.0 + kSRLdst;
1087     ypos  = 0.0;
1088     zpos  = fgkVrocsm + fgkSMpltT + fgkCraH + fgkCdrH + fgkCamH 
1089           - fgkSheight/2.0  
1090           + ilayer * (fgkCH + fgkVspace);
1091     gMC->Gspos("USRL",ilayer+1          ,"UTI1", xpos,ypos,zpos,0,"ONLY");
1092     gMC->Gspos("USRL",ilayer+1+  kNlayer,"UTI1",-xpos,ypos,zpos,0,"ONLY");
1093     gMC->Gspos("USRL",ilayer+1+2*kNlayer,"UTI2", xpos,ypos,zpos,0,"ONLY");
1094     gMC->Gspos("USRL",ilayer+1+3*kNlayer,"UTI2",-xpos,ypos,zpos,0,"ONLY");
1095     gMC->Gspos("USRL",ilayer+1+4*kNlayer,"UTI3", xpos,ypos,zpos,0,"ONLY");
1096     gMC->Gspos("USRL",ilayer+1+5*kNlayer,"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 (ilayer = 0; ilayer < kNlayer; ilayer++) {
1120
1121     // The aluminum of the cross bars
1122     parSCB[0] = fCwidth[ilayer]/2.0 + kSRLdst/2.0;
1123     sprintf(cTagV,"USF%01d",ilayer);
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 (ilayer < 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",ilayer);
1134     gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parSCI,kNparSCI);
1135
1136     sprintf(cTagV,"USI%01d",ilayer);
1137     sprintf(cTagM,"USF%01d",ilayer);
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",ilayer);
1150     xpos  = 0.0;
1151     zpos  = fgkVrocsm + fgkSMpltT + parSCB[2] - fgkSheight/2.0 
1152           + ilayer * (fgkCH + fgkVspace);
1153
1154     ypos  =   fClength[ilayer][2]/2.0 + fClength[ilayer][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[ilayer][2]/2.0 - fClength[ilayer][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 (ilayer = 1; ilayer < kNlayer-1; ilayer++) {
1174
1175     parSCH[0] = fCwidth[ilayer]/2.0;
1176     parSCH[1] = (fClength[ilayer+1][2]/2.0 + fClength[ilayer+1][1]
1177                - fClength[ilayer  ][2]/2.0 - fClength[ilayer  ][1])/2.0;
1178     parSCH[2] = kSCHhgt/2.0;
1179
1180     sprintf(cTagV,"USH%01d",ilayer);
1181     gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parSCH,kNparSCH);
1182     xpos  = 0.0;
1183     ypos  = fClength[ilayer][2]/2.0 + fClength[ilayer][1] + parSCH[1];
1184     zpos  = fgkVrocsm + fgkSMpltT - kSCHhgt/2.0 - fgkSheight/2.0 
1185           + (ilayer+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.04;
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 - fgkSMpltT  - 3.00/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.74/2.0;
1327   gMC->Gsvolu("USD8","BOX ",idtmed[1301-1],parBOX,kNparBOX);
1328   xpos       =   0.0;
1329   ypos       =   fClength[5][2]/2.0 - 0.1;
1330   zpos       =  -fgkSheight/2.0 + fgkSMpltT + 2.27;
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 + fgkSMpltT + 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 - 0.1;
1380   parTRD[1]  = 114.00/2.0 - 0.1;
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 - fgkSMpltT - 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.00/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 + fgkSMpltT + 2.60;
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 + fgkSMpltT + 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.65;
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.15;
1531   const Float_t kSCLposxLb =  2.7;
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 - 0.2;
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 - fgkSMpltT/2.0 - 0.0016;
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   ilayer = 0;
1649   Int_t   istack = 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[100];
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   // Services inside the baby frame
1664   const Float_t kBBMdz = 223.0;
1665   const Float_t kBBSdz =   8.5;
1666
1667   // Services inside the back frame
1668   const Float_t kBFMdz = 118.0;
1669   const Float_t kBFSdz =   8.5;
1670
1671   // The rotation matrices
1672   const Int_t kNmatrix = 10;
1673   Int_t   matrix[kNmatrix];
1674   gMC->Matrix(matrix[0], 100.0,   0.0,  90.0,  90.0,  10.0,   0.0); // rotation around y-axis
1675   gMC->Matrix(matrix[1],  80.0,   0.0,  90.0,  90.0,  10.0, 180.0); // rotation around y-axis
1676   gMC->Matrix(matrix[2],   0.0,   0.0,  90.0,  90.0,  90.0,   0.0);
1677   gMC->Matrix(matrix[3], 180.0,   0.0,  90.0,  90.0,  90.0, 180.0);
1678   gMC->Matrix(matrix[4],  90.0,   0.0,   0.0,   0.0,  90.0,  90.0);
1679   gMC->Matrix(matrix[5], 100.0,   0.0,  90.0, 270.0,  10.0,   0.0);
1680   gMC->Matrix(matrix[6],  80.0,   0.0,  90.0, 270.0,  10.0, 180.0);
1681   gMC->Matrix(matrix[7],  90.0,  10.0,  90.0, 100.0,   0.0,   0.0); // rotation around z-axis
1682   gMC->Matrix(matrix[8],  90.0, 350.0,  90.0,  80.0,   0.0,   0.0); // rotation around z-axis
1683   gMC->Matrix(matrix[9],  90.0,  90.0,  90.0, 180.0,   0.0,   0.0); // rotation around z-axis
1684     
1685   //
1686   // The cooling arterias
1687   //
1688
1689   // Width of the cooling arterias
1690   const Float_t kCOLwid  =  0.8; 
1691   // Height of the cooling arterias
1692   const Float_t kCOLhgt  =  6.5;
1693   // Positioning of the cooling 
1694   const Float_t kCOLposx =  1.8;
1695   const Float_t kCOLposz = -0.1;
1696   // Thickness of the walls of the cooling arterias
1697   const Float_t kCOLthk  =  0.1;
1698   const Int_t   kNparCOL =  3;
1699   Float_t parCOL[kNparCOL];
1700   parCOL[0] = 0.0;
1701   parCOL[1] = 0.0;
1702   parCOL[2] = 0.0;
1703   gMC->Gsvolu("UTC1","BOX ",idtmed[1308-1],parCOL,0);
1704   gMC->Gsvolu("UTC3","BOX ",idtmed[1308-1],parCOL,0);
1705   parCOL[0] =  kCOLwid/2.0 - kCOLthk;
1706   parCOL[1] = -1.0;
1707   parCOL[2] =  kCOLhgt/2.0 - kCOLthk;
1708   gMC->Gsvolu("UTC2","BOX ",idtmed[1314-1],parCOL,kNparCOL);
1709   gMC->Gsvolu("UTC4","BOX ",idtmed[1314-1],parCOL,kNparCOL);
1710
1711   xpos  = 0.0;
1712   ypos  = 0.0;
1713   zpos  = 0.0;
1714   gMC->Gspos("UTC2",1,"UTC1", xpos,ypos,zpos,0,"ONLY");
1715   gMC->Gspos("UTC4",1,"UTC3", xpos,ypos,zpos,0,"ONLY");
1716
1717   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1718
1719     // Along the chambers
1720     xpos      = fCwidth[ilayer]/2.0 + kCOLwid/2.0 + kCOLposx;
1721     ypos      = 0.0;
1722     zpos      = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1723               + ilayer * (fgkCH + fgkVspace);
1724     parCOL[0] = kCOLwid   /2.0;
1725     parCOL[1] = fgkSlength/2.0;
1726     parCOL[2] = kCOLhgt   /2.0;
1727     gMC->Gsposp("UTC1",ilayer          ,"UTI1", xpos,ypos,zpos
1728                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1729     gMC->Gsposp("UTC1",ilayer+  kNlayer,"UTI1",-xpos,ypos,zpos
1730                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1731     gMC->Gsposp("UTC1",ilayer+6*kNlayer,"UTI2", xpos,ypos,zpos
1732                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1733     gMC->Gsposp("UTC1",ilayer+7*kNlayer,"UTI2",-xpos,ypos,zpos
1734                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1735     gMC->Gsposp("UTC1",ilayer+8*kNlayer ,"UTI3", xpos,ypos,zpos
1736                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1737     gMC->Gsposp("UTC1",ilayer+9*kNlayer,"UTI3",-xpos,ypos,zpos
1738                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1739
1740     // Front of supermodules
1741     xpos      = fCwidth[ilayer]/2.0 + kCOLwid/2.0 + kCOLposx;
1742     ypos      = 0.0;
1743     zpos      = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1744               + ilayer * (fgkCH + fgkVspace);
1745     parCOL[0] = kCOLwid   /2.0;
1746     parCOL[1] = fgkFlength/2.0;
1747     parCOL[2] = kCOLhgt   /2.0;
1748     gMC->Gsposp("UTC3",ilayer+2*kNlayer,"UTF1", xpos,ypos,zpos
1749                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1750     gMC->Gsposp("UTC3",ilayer+3*kNlayer,"UTF1",-xpos,ypos,zpos
1751                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1752     gMC->Gsposp("UTC3",ilayer+4*kNlayer,"UTF2", xpos,ypos,zpos
1753                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1754     gMC->Gsposp("UTC3",ilayer+5*kNlayer,"UTF2",-xpos,ypos,zpos
1755                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1756
1757   }
1758
1759   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1760
1761     // In baby frame
1762     xpos      = fCwidth[ilayer]/2.0 + kCOLwid/2.0 - 1.04;
1763     ypos      = kBBSdz/2.0 - kBBMdz/2.0;
1764     zpos      = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1765               + ilayer * (fgkCH + fgkVspace);
1766     parCOL[0] = kCOLwid/2.0;
1767     parCOL[1] = kBBSdz /2.0;
1768     parCOL[2] = kCOLhgt/2.0;
1769     gMC->Gsposp("UTC3",ilayer+6*kNlayer,"BBTRD", xpos, ypos, zpos
1770                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1771     gMC->Gsposp("UTC3",ilayer+7*kNlayer,"BBTRD",-xpos, ypos, zpos
1772                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1773
1774   }
1775
1776   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1777
1778     // In back frame
1779     xpos      = fCwidth[ilayer]/2.0 + kCOLwid/2.0 + kCOLposx;
1780     ypos      = -kBFSdz/2.0 + kBFMdz/2.0;
1781     zpos      = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1782               + ilayer * (fgkCH + fgkVspace);
1783     parCOL[0] = kCOLwid/2.0;
1784     parCOL[1] = kBFSdz /2.0;
1785     parCOL[2] = kCOLhgt/2.0;
1786     gMC->Gsposp("UTC3",ilayer+6*kNlayer,"BFTRD", xpos,ypos,zpos
1787                       ,matrix[0],"ONLY",parCOL,kNparCOL);
1788     gMC->Gsposp("UTC3",ilayer+7*kNlayer,"BFTRD",-xpos,ypos,zpos
1789                       ,matrix[1],"ONLY",parCOL,kNparCOL);
1790
1791   }
1792
1793   // The upper most layer (reaching into TOF acceptance)
1794   // Along the chambers
1795   xpos      = fCwidth[5]/2.0 - kCOLhgt/2.0 - 1.3;
1796   ypos      = 0.0;
1797   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1798   parCOL[0] = kCOLwid   /2.0;
1799   parCOL[1] = fgkSlength/2.0;
1800   parCOL[2] = kCOLhgt   /2.0;
1801   gMC->Gsposp("UTC1",6          ,"UTI1", xpos,ypos,zpos
1802                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1803   gMC->Gsposp("UTC1",6+  kNlayer,"UTI1",-xpos,ypos,zpos
1804                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1805   gMC->Gsposp("UTC1",6+6*kNlayer,"UTI2", xpos,ypos,zpos
1806                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1807   gMC->Gsposp("UTC1",6+7*kNlayer,"UTI2",-xpos,ypos,zpos
1808                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1809   gMC->Gsposp("UTC1",6+8*kNlayer,"UTI3", xpos,ypos,zpos
1810                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1811   gMC->Gsposp("UTC1",6+9*kNlayer,"UTI3",-xpos,ypos,zpos
1812                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1813   // Front of supermodules
1814   xpos      = fCwidth[5]/2.0 - kCOLhgt/2.0 - 1.3;
1815   ypos      = 0.0;
1816   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1817   parCOL[0] = kCOLwid   /2.0;
1818   parCOL[1] = fgkFlength/2.0;
1819   parCOL[2] = kCOLhgt   /2.0;
1820   gMC->Gsposp("UTC3",6+2*kNlayer,"UTF1", xpos,ypos,zpos
1821                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1822   gMC->Gsposp("UTC3",6+3*kNlayer,"UTF1",-xpos,ypos,zpos
1823                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1824   gMC->Gsposp("UTC3",6+4*kNlayer,"UTF2", xpos,ypos,zpos
1825                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1826   gMC->Gsposp("UTC3",6+5*kNlayer,"UTF2",-xpos,ypos,zpos
1827                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1828   // In baby frame
1829   xpos      = fCwidth[5]/2.0 - kCOLhgt/2.0 - 3.1;
1830   ypos      = kBBSdz/2.0 - kBBMdz/2.0;
1831   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1832   parCOL[0] = kCOLwid/2.0;
1833   parCOL[1] = kBBSdz /2.0;
1834   parCOL[2] = kCOLhgt/2.0;
1835   gMC->Gsposp("UTC3",6+6*kNlayer,"BBTRD", xpos, ypos, zpos
1836                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1837   gMC->Gsposp("UTC3",6+7*kNlayer,"BBTRD",-xpos, ypos, zpos
1838                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1839   // In back frame
1840   xpos      = fCwidth[5]/2.0 - kCOLhgt/2.0 - 1.3;
1841   ypos      = -kBFSdz/2.0 + kBFMdz/2.0;
1842   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1843   parCOL[0] = kCOLwid/2.0;
1844   parCOL[1] = kBFSdz /2.0;
1845   parCOL[2] = kCOLhgt/2.0;
1846   gMC->Gsposp("UTC3",6+6*kNlayer,"BFTRD", xpos,ypos,zpos
1847                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1848   gMC->Gsposp("UTC3",6+7*kNlayer,"BFTRD",-xpos,ypos,zpos
1849                     ,matrix[3],"ONLY",parCOL,kNparCOL);
1850
1851   //
1852   // The power bars
1853   //
1854
1855   const Float_t kPWRwid  =  0.6;
1856   const Float_t kPWRhgt  =  5.0;
1857   const Float_t kPWRposx =  1.4;
1858   const Float_t kPWRposz =  1.9;
1859   const Int_t   kNparPWR =  3;
1860   Float_t parPWR[kNparPWR];
1861   parPWR[0] = 0.0;
1862   parPWR[1] = 0.0;
1863   parPWR[2] = 0.0;
1864   gMC->Gsvolu("UTP1","BOX ",idtmed[1325-1],parPWR,0);
1865   gMC->Gsvolu("UTP3","BOX ",idtmed[1325-1],parPWR,0);
1866   
1867   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1868
1869     // Along the chambers
1870     xpos      = fCwidth[ilayer]/2.0 + kPWRwid/2.0 + kPWRposx;
1871     ypos      = 0.0;
1872     zpos      = fgkVrocsm + fgkSMpltT + kPWRhgt/2.0 - fgkSheight/2.0 + kPWRposz 
1873               + ilayer * (fgkCH + fgkVspace);
1874     parPWR[0] = kPWRwid   /2.0;
1875     parPWR[1] = fgkSlength/2.0;
1876     parPWR[2] = kPWRhgt   /2.0;
1877     gMC->Gsposp("UTP1",ilayer          ,"UTI1", xpos,ypos,zpos
1878                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1879     gMC->Gsposp("UTP1",ilayer+  kNlayer,"UTI1",-xpos,ypos,zpos
1880                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1881     gMC->Gsposp("UTP1",ilayer+6*kNlayer,"UTI2", xpos,ypos,zpos
1882                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1883     gMC->Gsposp("UTP1",ilayer+7*kNlayer,"UTI2",-xpos,ypos,zpos
1884                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1885     gMC->Gsposp("UTP1",ilayer+8*kNlayer,"UTI3", xpos,ypos,zpos
1886                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1887     gMC->Gsposp("UTP1",ilayer+9*kNlayer,"UTI3",-xpos,ypos,zpos
1888                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1889
1890     // Front of supermodule
1891     xpos      = fCwidth[ilayer]/2.0 + kPWRwid/2.0 + kPWRposx;
1892     ypos      = 0.0;
1893     zpos      = fgkVrocsm + fgkSMpltT + kPWRhgt/2.0 - fgkSheight/2.0 + kPWRposz 
1894               + ilayer * (fgkCH + fgkVspace);
1895     parPWR[0] = kPWRwid   /2.0;
1896     parPWR[1] = fgkFlength/2.0;
1897     parPWR[2] = kPWRhgt   /2.0;
1898     gMC->Gsposp("UTP3",ilayer+2*kNlayer,"UTF1", xpos,ypos,zpos
1899                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1900     gMC->Gsposp("UTP3",ilayer+3*kNlayer,"UTF1",-xpos,ypos,zpos
1901                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1902     gMC->Gsposp("UTP3",ilayer+4*kNlayer,"UTF2", xpos,ypos,zpos
1903                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1904     gMC->Gsposp("UTP3",ilayer+5*kNlayer,"UTF2",-xpos,ypos,zpos
1905                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1906
1907   }
1908
1909   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1910
1911     // In baby frame
1912     xpos      = fCwidth[ilayer]/2.0 + kPWRwid/2.0;
1913     ypos      = kBBSdz/2.0 - kBBMdz/2.0;
1914     zpos      = fgkVrocsm + fgkSMpltT + kPWRhgt/2.0 - fgkSheight/2.0 + kPWRposz 
1915               + ilayer * (fgkCH + fgkVspace);
1916     parPWR[0] = kPWRwid/2.0;
1917     parPWR[1] = kBBSdz /2.0;
1918     parPWR[2] = kPWRhgt/2.0;
1919     gMC->Gsposp("UTP3",ilayer+6*kNlayer,"BBTRD", xpos, ypos, zpos
1920                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1921     gMC->Gsposp("UTP3",ilayer+7*kNlayer,"BBTRD",-xpos, ypos, zpos
1922                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1923
1924   }
1925
1926   for (ilayer = 1; ilayer < kNlayer; ilayer++) { 
1927
1928     // In back frame
1929     xpos      = fCwidth[ilayer]/2.0 + kPWRwid/2.0 + kPWRposx;
1930     ypos      = -kBFSdz/2.0 + kBFMdz/2.0;
1931     zpos      = fgkVrocsm + fgkSMpltT + kPWRhgt/2.0 - fgkSheight/2.0 + kPWRposz 
1932               + ilayer * (fgkCH + fgkVspace);
1933     parPWR[0] = kPWRwid/2.0;
1934     parPWR[1] = kBFSdz /2.0;
1935     parPWR[2] = kPWRhgt/2.0;
1936     gMC->Gsposp("UTP3",ilayer+8*kNlayer,"BFTRD", xpos,ypos,zpos
1937                       ,matrix[0],"ONLY",parPWR,kNparPWR);
1938     gMC->Gsposp("UTP3",ilayer+9*kNlayer,"BFTRD",-xpos,ypos,zpos
1939                       ,matrix[1],"ONLY",parPWR,kNparPWR);
1940
1941   }
1942
1943   // The upper most layer
1944   // Along the chambers
1945   xpos      = fCwidth[5]/2.0 + kPWRhgt/2.0 - 1.3;
1946   ypos      = 0.0;
1947   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
1948   parPWR[0] = kPWRwid   /2.0;
1949   parPWR[1] = fgkSlength/2.0;
1950   parPWR[2] = kPWRhgt   /2.0;
1951   gMC->Gsposp("UTP1",6          ,"UTI1", xpos,ypos,zpos
1952                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1953   gMC->Gsposp("UTP1",6+  kNlayer,"UTI1",-xpos,ypos,zpos
1954                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1955   gMC->Gsposp("UTP1",6+6*kNlayer,"UTI2", xpos,ypos,zpos
1956                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1957   gMC->Gsposp("UTP1",6+7*kNlayer,"UTI2",-xpos,ypos,zpos
1958                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1959   gMC->Gsposp("UTP1",6+8*kNlayer,"UTI3", xpos,ypos,zpos
1960                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1961   gMC->Gsposp("UTP1",6+9*kNlayer,"UTI3",-xpos,ypos,zpos
1962                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1963   // Front of supermodules
1964   xpos      = fCwidth[5]/2.0 + kPWRhgt/2.0 - 1.3;
1965   ypos      = 0.0;
1966   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
1967   parPWR[0] = kPWRwid   /2.0;
1968   parPWR[1] = fgkFlength/2.0;
1969   parPWR[2] = kPWRhgt   /2.0;
1970   gMC->Gsposp("UTP3",6+2*kNlayer,"UTF1", xpos,ypos,zpos
1971                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1972   gMC->Gsposp("UTP3",6+3*kNlayer,"UTF1",-xpos,ypos,zpos
1973                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1974   gMC->Gsposp("UTP3",6+4*kNlayer,"UTF2", xpos,ypos,zpos
1975                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1976   gMC->Gsposp("UTP3",6+5*kNlayer,"UTF2",-xpos,ypos,zpos
1977                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1978   // In baby frame
1979   xpos      = fCwidth[5]/2.0 + kPWRhgt/2.0 - 3.0;
1980   ypos      = kBBSdz/2.0 - kBBMdz/2.0;
1981   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
1982   parPWR[0] = kPWRwid/2.0;
1983   parPWR[1] = kBBSdz /2.0;
1984   parPWR[2] = kPWRhgt/2.0;
1985   gMC->Gsposp("UTP3",6+6*kNlayer,"BBTRD", xpos, ypos, zpos
1986                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1987   gMC->Gsposp("UTP3",6+7*kNlayer,"BBTRD",-xpos, ypos, zpos
1988                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1989   // In back frame
1990   xpos      = fCwidth[5]/2.0 + kPWRhgt/2.0 - 1.3;
1991   ypos      = -kBFSdz/2.0 + kBFMdz/2.0;
1992   zpos      = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
1993   parPWR[0] = kPWRwid/2.0;
1994   parPWR[1] = kBFSdz /2.0;
1995   parPWR[2] = kPWRhgt/2.0;
1996   gMC->Gsposp("UTP3",6+8*kNlayer,"BFTRD", xpos,ypos,zpos
1997                     ,matrix[3],"ONLY",parPWR,kNparPWR);
1998   gMC->Gsposp("UTP3",6+9*kNlayer,"BFTRD",-xpos,ypos,zpos
1999                     ,matrix[3],"ONLY",parPWR,kNparPWR);
2000
2001   //
2002   // The gas tubes connecting the chambers in the super modules with holes
2003   // Material: Stainless steel
2004   //
2005
2006   parTube[0] = 0.0;
2007   parTube[1] = 2.2/2.0;
2008   parTube[2] = fClength[5][2]/2.0 - fgkHspace/2.0;
2009   gMC->Gsvolu("UTG1","TUBE",idtmed[1308-1],parTube,kNparTube);
2010   parTube[0] = 0.0;
2011   parTube[1] = 2.1/2.0;
2012   parTube[2] = fClength[5][2]/2.0 - fgkHspace/2.0;
2013   gMC->Gsvolu("UTG2","TUBE",idtmed[1309-1],parTube,kNparTube);
2014   xpos  = 0.0;
2015   ypos  = 0.0;
2016   zpos  = 0.0;
2017   gMC->Gspos("UTG2",1,"UTG1",xpos,ypos,zpos,0,"ONLY");
2018   for (ilayer = 0; ilayer < kNlayer; ilayer++) { 
2019     xpos      = fCwidth[ilayer]/2.0 + kCOLwid/2.0 - 1.5;
2020     ypos      = 0.0;
2021     zpos      = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + 5.0 
2022               + ilayer * (fgkCH + fgkVspace);
2023     gMC->Gspos("UTG1",1+ilayer,"UTI3", xpos, ypos, zpos,matrix[4],"ONLY");
2024     gMC->Gspos("UTG1",7+ilayer,"UTI3",-xpos, ypos, zpos,matrix[4],"ONLY");
2025   }
2026
2027   //
2028   // The volumes for the services at the chambers
2029   //
2030
2031   const Int_t kNparServ = 3;
2032   Float_t parServ[kNparServ];
2033
2034   for (istack = 0; istack < kNstack; istack++) {
2035     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
2036
2037       Int_t iDet = GetDetectorSec(ilayer,istack);
2038
2039       sprintf(cTagV,"UU%02d",iDet);
2040       parServ[0] = fCwidth[ilayer]         /2.0;
2041       parServ[1] = fClength[ilayer][istack]/2.0 - fgkHspace/2.0;
2042       parServ[2] = fgkVspace               /2.0 - 0.742/2.0; 
2043       fChamberUUboxd[iDet][0] = parServ[0];
2044       fChamberUUboxd[iDet][1] = parServ[1];
2045       fChamberUUboxd[iDet][2] = parServ[2];
2046       gMC->Gsvolu(cTagV,"BOX",idtmed[1302-1],parServ,kNparServ);
2047
2048       xpos  = 0.0;
2049       ypos  = fClength[ilayer][0] + fClength[ilayer][1] + fClength[ilayer][2]/2.0;
2050       for (Int_t ic = 0; ic < istack; ic++) {
2051         ypos -= fClength[ilayer][ic];
2052       }
2053       ypos -= fClength[ilayer][istack]/2.0;
2054       zpos  = fgkVrocsm + fgkSMpltT + fgkCH + fgkVspace/2.0 - fgkSheight/2.0
2055             + ilayer * (fgkCH + fgkVspace);
2056       zpos -= 0.742/2.0;
2057       fChamberUUorig[iDet][0] = xpos;
2058       fChamberUUorig[iDet][1] = ypos;
2059       fChamberUUorig[iDet][2] = zpos;
2060
2061     }
2062   }
2063
2064   //
2065   // The cooling pipes inside the service volumes
2066   //
2067
2068   // The cooling pipes
2069   parTube[0] =  0.0;
2070   parTube[1] =  0.0;
2071   parTube[2] =  0.0;
2072   gMC->Gsvolu("UTCP","TUBE",idtmed[1324-1],parTube,0);
2073   // The cooling water
2074   parTube[0] =  0.0;
2075   parTube[1] =  0.2/2.0;
2076   parTube[2] = -1.0;
2077   gMC->Gsvolu("UTCH","TUBE",idtmed[1314-1],parTube,kNparTube);
2078   // Water inside the cooling pipe
2079   xpos = 0.0;
2080   ypos = 0.0;
2081   zpos = 0.0;
2082   gMC->Gspos("UTCH",1,"UTCP",xpos,ypos,zpos,0,"ONLY");
2083
2084   // Position the cooling pipes in the mother volume
2085   for (istack = 0; istack < kNstack; istack++) {
2086     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
2087       Int_t   iDet    = GetDetectorSec(ilayer,istack);
2088       Int_t   iCopy   = GetDetector(ilayer,istack,0) * 100;
2089       Int_t   nMCMrow = GetRowMax(ilayer,istack,0);
2090       Float_t ySize   = (GetChamberLength(ilayer,istack) - 2.0*fgkRpadW) 
2091                       / ((Float_t) nMCMrow);
2092       sprintf(cTagV,"UU%02d",iDet);
2093       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
2094         xpos   = 0.0;
2095         ypos   = (0.5 + iMCMrow) * ySize - 1.9 
2096                - fClength[ilayer][istack]/2.0 + fgkHspace/2.0;
2097         zpos   = 0.0 + 0.742/2.0;                 
2098         // The cooling pipes
2099         parTube[0] = 0.0;
2100         parTube[1] = 0.3/2.0; // Thickness of the cooling pipes
2101         parTube[2] = fCwidth[ilayer]/2.0;
2102         gMC->Gsposp("UTCP",iCopy+iMCMrow,cTagV,xpos,ypos,zpos
2103                           ,matrix[2],"ONLY",parTube,kNparTube);
2104       }
2105     }
2106   }
2107
2108   //
2109   // The power lines
2110   //
2111
2112   // The copper power lines
2113   parTube[0] = 0.0;
2114   parTube[1] = 0.0;
2115   parTube[2] = 0.0;
2116   gMC->Gsvolu("UTPL","TUBE",idtmed[1305-1],parTube,0);
2117
2118   // Position the power lines in the mother volume
2119   for (istack = 0; istack < kNstack; istack++) {
2120     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
2121       Int_t   iDet    = GetDetectorSec(ilayer,istack);
2122       Int_t   iCopy   = GetDetector(ilayer,istack,0) * 100;
2123       Int_t   nMCMrow = GetRowMax(ilayer,istack,0);
2124       Float_t ySize   = (GetChamberLength(ilayer,istack) - 2.0*fgkRpadW) 
2125                       / ((Float_t) nMCMrow);
2126       sprintf(cTagV,"UU%02d",iDet);
2127       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
2128         xpos       = 0.0;
2129         ypos       = (0.5 + iMCMrow) * ySize - 1.0 
2130                    - fClength[ilayer][istack]/2.0 + fgkHspace/2.0;
2131         zpos       = -0.4 + 0.742/2.0;
2132         parTube[0] = 0.0;
2133         parTube[1] = 0.2/2.0; // Thickness of the power lines
2134         parTube[2] = fCwidth[ilayer]/2.0;
2135         gMC->Gsposp("UTPL",iCopy+iMCMrow,cTagV,xpos,ypos,zpos
2136                           ,matrix[2],"ONLY",parTube,kNparTube);
2137       }
2138     }
2139   }
2140
2141   //
2142   // The MCMs
2143   //
2144
2145   const Float_t kMCMx    = 3.0;
2146   const Float_t kMCMy    = 3.0;
2147   const Float_t kMCMz    = 0.3;
2148   
2149   const Float_t kMCMpcTh = 0.1;
2150   const Float_t kMCMcuTh = 0.0025;
2151   const Float_t kMCMsiTh = 0.03;
2152   const Float_t kMCMcoTh = 0.04;
2153
2154   // The mother volume for the MCMs (air)
2155   const Int_t kNparMCM = 3;
2156   Float_t parMCM[kNparMCM];
2157   parMCM[0] = kMCMx   /2.0;
2158   parMCM[1] = kMCMy   /2.0;
2159   parMCM[2] = kMCMz   /2.0;
2160   gMC->Gsvolu("UMCM","BOX",idtmed[1302-1],parMCM,kNparMCM);
2161
2162   // The MCM carrier G10 layer
2163   parMCM[0] = kMCMx   /2.0;
2164   parMCM[1] = kMCMy   /2.0;
2165   parMCM[2] = kMCMpcTh/2.0;
2166   gMC->Gsvolu("UMC1","BOX",idtmed[1319-1],parMCM,kNparMCM);
2167   // The MCM carrier Cu layer
2168   parMCM[0] = kMCMx   /2.0;
2169   parMCM[1] = kMCMy   /2.0;
2170   parMCM[2] = kMCMcuTh/2.0;
2171   gMC->Gsvolu("UMC2","BOX",idtmed[1318-1],parMCM,kNparMCM);
2172   // The silicon of the chips
2173   parMCM[0] = kMCMx   /2.0;
2174   parMCM[1] = kMCMy   /2.0;
2175   parMCM[2] = kMCMsiTh/2.0;
2176   gMC->Gsvolu("UMC3","BOX",idtmed[1320-1],parMCM,kNparMCM);
2177   // The aluminum of the cooling plates
2178   parMCM[0] = kMCMx   /2.0;
2179   parMCM[1] = kMCMy   /2.0;
2180   parMCM[2] = kMCMcoTh/2.0;
2181   gMC->Gsvolu("UMC4","BOX",idtmed[1324-1],parMCM,kNparMCM);
2182
2183   // Put the MCM material inside the MCM mother volume
2184   xpos  =  0.0;
2185   ypos  =  0.0;
2186   zpos  = -kMCMz   /2.0 + kMCMpcTh/2.0;
2187   gMC->Gspos("UMC1",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2188   zpos +=  kMCMpcTh/2.0 + kMCMcuTh/2.0;
2189   gMC->Gspos("UMC2",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2190   zpos +=  kMCMcuTh/2.0 + kMCMsiTh/2.0;
2191   gMC->Gspos("UMC3",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2192   zpos +=  kMCMsiTh/2.0 + kMCMcoTh/2.0;
2193   gMC->Gspos("UMC4",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
2194
2195   // Position the MCMs in the mother volume
2196   for (istack = 0; istack < kNstack; istack++) {
2197     for (ilayer = 0; ilayer < kNlayer; ilayer++) {
2198       Int_t   iDet    = GetDetectorSec(ilayer,istack);
2199       Int_t   iCopy   = GetDetector(ilayer,istack,0) * 1000;
2200       Int_t   nMCMrow = GetRowMax(ilayer,istack,0);
2201       Float_t ySize   = (GetChamberLength(ilayer,istack) - 2.0*fgkRpadW)
2202                       / ((Float_t) nMCMrow);
2203       Int_t   nMCMcol = 8;
2204       Float_t xSize   = (GetChamberWidth(ilayer)         - 2.0*fgkCpadW)
2205                       / ((Float_t) nMCMcol + 6);             // Introduce 6 gaps
2206       Int_t   iMCM[8] = {  1,  2,  3,  5,  8,  9, 10, 12 };  // 0..7 MCM + 6 gap structure
2207       sprintf(cTagV,"UU%02d",iDet);
2208       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
2209         for (Int_t iMCMcol = 0; iMCMcol < nMCMcol; iMCMcol++) {
2210           xpos      = (0.5 + iMCM[iMCMcol]) * xSize + 1.0
2211                     - fCwidth[ilayer]/2.0;
2212           ypos      = (0.5 + iMCMrow) * ySize + 1.0
2213                     - fClength[ilayer][istack]/2.0 + fgkHspace/2.0;
2214           zpos      = -0.4 + 0.742/2.0;
2215           gMC->Gspos("UMCM",iCopy+iMCMrow*10+iMCMcol,cTagV
2216                            ,xpos,ypos,zpos,0,"ONLY");
2217         }
2218       }
2219
2220     }
2221   }
2222
2223   //
2224   // Services in front of the super module
2225   //
2226
2227   // Gas in-/outlet pipes (INOX)
2228   parTube[0] = 0.0;
2229   parTube[1] = 0.0;
2230   parTube[2] = 0.0;
2231   gMC->Gsvolu("UTG3","TUBE",idtmed[1308-1],parTube,0);
2232   // The gas inside the in-/outlet pipes (Xe)
2233   parTube[0] =  0.0;
2234   parTube[1] =  1.2/2.0;
2235   parTube[2] = -1.0;
2236   gMC->Gsvolu("UTG4","TUBE",idtmed[1309-1],parTube,kNparTube);
2237   xpos = 0.0;
2238   ypos = 0.0;
2239   zpos = 0.0;
2240   gMC->Gspos("UTG4",1,"UTG3",xpos,ypos,zpos,0,"ONLY");
2241   for (ilayer = 0; ilayer < kNlayer-1; ilayer++) { 
2242     xpos       = 0.0;
2243     ypos       = fClength[ilayer][2]/2.0 
2244                + fClength[ilayer][1] 
2245                + fClength[ilayer][0];
2246     zpos       = 9.0 - fgkSheight/2.0
2247                + ilayer * (fgkCH + fgkVspace);
2248     parTube[0] = 0.0;
2249     parTube[1] = 1.5/2.0;
2250     parTube[2] = fCwidth[ilayer]/2.0 - 2.5;
2251     gMC->Gsposp("UTG3",ilayer+1          ,"UTI1", xpos, ypos, zpos
2252                       ,matrix[2],"ONLY",parTube,kNparTube);
2253     gMC->Gsposp("UTG3",ilayer+1+1*kNlayer,"UTI1", xpos,-ypos, zpos
2254                       ,matrix[2],"ONLY",parTube,kNparTube);
2255     gMC->Gsposp("UTG3",ilayer+1+2*kNlayer,"UTI2", xpos, ypos, zpos
2256                       ,matrix[2],"ONLY",parTube,kNparTube);
2257     gMC->Gsposp("UTG3",ilayer+1+3*kNlayer,"UTI2", xpos,-ypos, zpos
2258                       ,matrix[2],"ONLY",parTube,kNparTube);
2259     gMC->Gsposp("UTG3",ilayer+1+4*kNlayer,"UTI3", xpos, ypos, zpos
2260                       ,matrix[2],"ONLY",parTube,kNparTube);
2261     gMC->Gsposp("UTG3",ilayer+1+5*kNlayer,"UTI3", xpos,-ypos, zpos
2262                       ,matrix[2],"ONLY",parTube,kNparTube);
2263   }
2264
2265   // Gas distribution box
2266   parBox[0] = 14.50/2.0;
2267   parBox[1] =  4.52/2.0;
2268   parBox[2] =  5.00/2.0;
2269   gMC->Gsvolu("UTGD","BOX ",idtmed[1308-1],parBox,kNparBox);
2270   parBox[0] = 14.50/2.0;
2271   parBox[1] =  4.00/2.0;
2272   parBox[2] =  4.40/2.0;
2273   gMC->Gsvolu("UTGI","BOX ",idtmed[1309-1],parBox,kNparBox);
2274   parTube[0] = 0.0;
2275   parTube[1] = 4.0/2.0;
2276   parTube[2] = 8.0/2.0;
2277   gMC->Gsvolu("UTGT","TUBE",idtmed[1308-1],parTube,kNparTube);
2278   parTube[0] = 0.0;
2279   parTube[1] = 3.4/2.0;
2280   parTube[2] = 8.0/2.0;
2281   gMC->Gsvolu("UTGG","TUBE",idtmed[1309-1],parTube,kNparTube);
2282   xpos = 0.0;
2283   ypos = 0.0;
2284   zpos = 0.0;
2285   gMC->Gspos("UTGI",1,"UTGD",xpos,ypos,zpos,        0,"ONLY");
2286   gMC->Gspos("UTGG",1,"UTGT",xpos,ypos,zpos,        0,"ONLY");
2287   xpos = 0.0;
2288   ypos = 0.0;
2289   zpos = 0.0;
2290   gMC->Gspos("UTGD",1,"UTF1",xpos,ypos,zpos,        0,"ONLY");
2291   xpos =  -3.0;
2292   ypos =   0.0;
2293   zpos =   6.5;
2294   gMC->Gspos("UTGT",1,"UTF1",xpos,ypos,zpos,        0,"ONLY");
2295   xpos = -11.25;
2296   ypos =   0.0;
2297   zpos =   0.5;
2298   gMC->Gspos("UTGT",3,"UTF1",xpos,ypos,zpos,matrix[2],"ONLY");
2299   xpos =  11.25;
2300   ypos =   0.0;
2301   zpos =   0.5;
2302   gMC->Gspos("UTGT",5,"UTF1",xpos,ypos,zpos,matrix[2],"ONLY");
2303
2304   // Cooling manifolds
2305   parBox[0]  =  5.0/2.0;
2306   parBox[1]  = 23.0/2.0;
2307   parBox[2]  = 70.0/2.0;
2308   gMC->Gsvolu("UTCM","BOX ",idtmed[1302-1],parBox,kNparBox);
2309   parBox[0]  =  5.0/2.0;
2310   parBox[1]  =  5.0/2.0;
2311   parBox[2]  = 70.0/2.0;
2312   gMC->Gsvolu("UTCA","BOX ",idtmed[1308-1],parBox,kNparBox);
2313   parBox[0]  =  5.0/2.0 - 0.3;
2314   parBox[1]  =  5.0/2.0 - 0.3;
2315   parBox[2]  = 70.0/2.0 - 0.3;
2316   gMC->Gsvolu("UTCW","BOX ",idtmed[1314-1],parBox,kNparBox);
2317   xpos       =  0.0;
2318   ypos       =  0.0;
2319   zpos       =  0.0;
2320   gMC->Gspos("UTCW",1,"UTCA", xpos, ypos, zpos,        0,"ONLY");
2321   xpos       =  0.0;
2322   ypos       =  5.0/2.0 - 23.0/2.0;
2323   zpos       =  0.0;
2324   gMC->Gspos("UTCA",1,"UTCM", xpos, ypos, zpos,        0,"ONLY");
2325   parTube[0] =  0.0;
2326   parTube[1] =  3.0/2.0;
2327   parTube[2] = 18.0/2.0;
2328   gMC->Gsvolu("UTCO","TUBE",idtmed[1308-1],parTube,kNparTube);
2329   parTube[0] =  0.0;
2330   parTube[1] =  3.0/2.0 - 0.3;
2331   parTube[2] = 18.0/2.0;
2332   gMC->Gsvolu("UTCL","TUBE",idtmed[1314-1],parTube,kNparTube);
2333   xpos       =  0.0;
2334   ypos       =  0.0;
2335   zpos       =  0.0;
2336   gMC->Gspos("UTCL",1,"UTCO", xpos, ypos, zpos,        0,"ONLY");
2337   xpos       =  0.0;
2338   ypos       =  2.5;
2339   zpos       = -70.0/2.0 + 7.0;
2340   gMC->Gspos("UTCO",1,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2341   zpos      +=  7.0;
2342   gMC->Gspos("UTCO",2,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2343   zpos      +=  7.0;
2344   gMC->Gspos("UTCO",3,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2345   zpos      +=  7.0;
2346   gMC->Gspos("UTCO",4,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2347   zpos      +=  7.0;
2348   gMC->Gspos("UTCO",5,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2349   zpos      +=  7.0;
2350   gMC->Gspos("UTCO",6,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2351   zpos      +=  7.0;
2352   gMC->Gspos("UTCO",7,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2353   zpos      +=  7.0;
2354   gMC->Gspos("UTCO",8,"UTCM", xpos, ypos, zpos,matrix[4],"ONLY");
2355
2356   xpos = 40.0;
2357   ypos =  fgkFlength/2.0 - 23.0/2.0;
2358   zpos =  0.0;
2359   gMC->Gspos("UTCM",1,"UTF1", xpos, ypos, zpos,matrix[0],"ONLY");
2360   gMC->Gspos("UTCM",2,"UTF1",-xpos, ypos, zpos,matrix[1],"ONLY");
2361   gMC->Gspos("UTCM",3,"UTF2", xpos,-ypos, zpos,matrix[5],"ONLY");
2362   gMC->Gspos("UTCM",4,"UTF2",-xpos,-ypos, zpos,matrix[6],"ONLY");
2363
2364   // Power connection boards (Cu)
2365   parBox[0] =  0.5/2.0;
2366   parBox[1] = 15.0/2.0;
2367   parBox[2] =  7.0/2.0;
2368   gMC->Gsvolu("UTPC","BOX ",idtmed[1325-1],parBox,kNparBox);
2369   for (ilayer = 0; ilayer < kNlayer-1; ilayer++) { 
2370     xpos      = fCwidth[ilayer]/2.0 + kPWRwid/2.0;
2371     ypos      = 0.0;
2372     zpos      = fgkVrocsm + fgkSMpltT + kPWRhgt/2.0 - fgkSheight/2.0 + kPWRposz 
2373               + (ilayer+1) * (fgkCH + fgkVspace);
2374     gMC->Gspos("UTPC",ilayer        ,"UTF1", xpos,ypos,zpos,matrix[0],"ONLY");
2375     gMC->Gspos("UTPC",ilayer+kNlayer,"UTF1",-xpos,ypos,zpos,matrix[1],"ONLY");
2376   }
2377   xpos      = fCwidth[5]/2.0 + kPWRhgt/2.0 - 2.0;
2378   ypos      = 0.0;
2379   zpos      = fgkSheight/2.0 - fgkSMpltT - 2.0; 
2380   gMC->Gspos("UTPC",5        ,"UTF1", xpos,ypos,zpos,matrix[3],"ONLY");
2381   gMC->Gspos("UTPC",5+kNlayer,"UTF1",-xpos,ypos,zpos,matrix[3],"ONLY");
2382
2383   // Power connection panel (Al)
2384   parBox[0] = 60.0/2.0;
2385   parBox[1] = 10.0/2.0;
2386   parBox[2] =  3.0/2.0;
2387   gMC->Gsvolu("UTPP","BOX ",idtmed[1301-1],parBox,kNparBox);
2388   xpos      =  0.0;
2389   ypos      =  0.0;
2390   zpos      = 18.0;
2391   gMC->Gspos("UTPP",1,"UTF1", xpos,ypos,zpos,0,"ONLY");
2392
2393   //
2394   // Electronics boxes
2395   //
2396
2397   // Casing (INOX)
2398   parBox[0] = 60.0/2.0;
2399   parBox[1] = 10.0/2.0;
2400   parBox[2] =  6.0/2.0;
2401   gMC->Gsvolu("UTE1","BOX ",idtmed[1308-1],parBox,kNparBox);
2402   // Interior (air)
2403   parBox[0] = parBox[0] - 0.5;
2404   parBox[1] = parBox[1] - 0.5;
2405   parBox[2] = parBox[2] - 0.5;
2406   gMC->Gsvolu("UTE2","BOX ",idtmed[1302-1],parBox,kNparBox);
2407   xpos      = 0.0;
2408   ypos      = 0.0;
2409   zpos      = 0.0;
2410   gMC->Gspos("UTE2",1,"UTE1",xpos,ypos,zpos,0,"ONLY");
2411   xpos      = 0.0;
2412   ypos      =  fgkSlength/2.0 - 10.0/2.0 - 3.0;
2413   zpos      = -fgkSheight/2.0 +  6.0/2.0 + 1.0;
2414   gMC->Gspos("UTE1",1,"UTI1", xpos,ypos,zpos,0,"ONLY");
2415   gMC->Gspos("UTE1",2,"UTI2", xpos,ypos,zpos,0,"ONLY");
2416   gMC->Gspos("UTE1",3,"UTI3", xpos,ypos,zpos,0,"ONLY");
2417
2418   // Casing (INOX)
2419   parBox[0] = 50.0/2.0;
2420   parBox[1] = 15.0/2.0;
2421   parBox[2] = 20.0/2.0;
2422   gMC->Gsvolu("UTE3","BOX ",idtmed[1308-1],parBox,kNparBox);
2423   // Interior (air)
2424   parBox[0] = parBox[0] - 0.5;
2425   parBox[1] = parBox[1] - 0.5;
2426   parBox[2] = parBox[2] - 0.5;
2427   gMC->Gsvolu("UTE4","BOX ",idtmed[1302-1],parBox,kNparBox);
2428   xpos      = 0.0;
2429   ypos      = 0.0;
2430   zpos      = 0.0;
2431   gMC->Gspos("UTE4",1,"UTE3",xpos,ypos,zpos,0,"ONLY");
2432   xpos      = 0.0;
2433   ypos      = -fgkSlength/2.0 + 15.0/2.0 + 3.0;
2434   zpos      = -fgkSheight/2.0 + 20.0/2.0 + 1.0;
2435   gMC->Gspos("UTE3",1,"UTI1", xpos,ypos,zpos,0,"ONLY");
2436   gMC->Gspos("UTE3",2,"UTI2", xpos,ypos,zpos,0,"ONLY");
2437   gMC->Gspos("UTE3",3,"UTI3", xpos,ypos,zpos,0,"ONLY");
2438
2439   // Casing (INOX)
2440   parBox[0] = 20.0/2.0;
2441   parBox[1] =  7.0/2.0;
2442   parBox[2] = 20.0/2.0;
2443   gMC->Gsvolu("UTE5","BOX ",idtmed[1308-1],parBox,kNparBox);
2444   // Interior (air)
2445   parBox[0] = parBox[0] - 0.5;
2446   parBox[1] = parBox[1] - 0.5;
2447   parBox[2] = parBox[2] - 0.5;
2448   gMC->Gsvolu("UTE6","BOX ",idtmed[1302-1],parBox,kNparBox);
2449   xpos      = 0.0;
2450   ypos      = 0.0;
2451   zpos      = 0.0;
2452   gMC->Gspos("UTE6",1,"UTE5",xpos,ypos,zpos,0,"ONLY");
2453   xpos      = 20.0;
2454   ypos      = -fgkSlength/2.0 +  7.0/2.0 + 3.0;
2455   zpos      = 0.0;
2456   gMC->Gspos("UTE5",1,"UTI1", xpos,ypos,zpos,0,"ONLY");
2457   gMC->Gspos("UTE5",2,"UTI2", xpos,ypos,zpos,0,"ONLY");
2458   gMC->Gspos("UTE5",3,"UTI3", xpos,ypos,zpos,0,"ONLY");
2459   xpos      = -xpos;
2460   gMC->Gspos("UTE5",4,"UTI1", xpos,ypos,zpos,0,"ONLY");
2461   gMC->Gspos("UTE5",5,"UTI2", xpos,ypos,zpos,0,"ONLY");
2462   gMC->Gspos("UTE5",6,"UTI3", xpos,ypos,zpos,0,"ONLY");
2463
2464 }
2465
2466 //_____________________________________________________________________________
2467 void AliTRDgeometry::GroupChamber(Int_t ilayer, Int_t istack, Int_t *idtmed)
2468 {
2469   //
2470   // Group volumes UA, UD, UF, UU in a single chamber (Air)
2471   // UA, UD, UF, UU are boxes
2472   // UT will be a box
2473   //
2474
2475   const Int_t kNparCha = 3;
2476
2477   Int_t iDet = GetDetectorSec(ilayer,istack);
2478
2479   Float_t xyzMin[3];
2480   Float_t xyzMax[3];
2481   Float_t xyzOrig[3];
2482   Float_t xyzBoxd[3];
2483
2484   Char_t  cTagV[100];
2485   Char_t  cTagM[100];
2486
2487   for (Int_t i = 0; i < 3; i++) {
2488     xyzMin[i] = +9999.0; 
2489     xyzMax[i] = -9999.0;
2490   }
2491
2492   for (Int_t i = 0; i < 3; i++) {
2493
2494     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUAorig[iDet][i]-fChamberUAboxd[iDet][i]);
2495     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUAorig[iDet][i]+fChamberUAboxd[iDet][i]);
2496
2497     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUDorig[iDet][i]-fChamberUDboxd[iDet][i]);
2498     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUDorig[iDet][i]+fChamberUDboxd[iDet][i]);
2499
2500     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUForig[iDet][i]-fChamberUFboxd[iDet][i]);
2501     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUForig[iDet][i]+fChamberUFboxd[iDet][i]);
2502
2503     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUUorig[iDet][i]-fChamberUUboxd[iDet][i]);
2504     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUUorig[iDet][i]+fChamberUUboxd[iDet][i]);
2505
2506     xyzOrig[i] = 0.5*(xyzMax[i]+xyzMin[i]);
2507     xyzBoxd[i] = 0.5*(xyzMax[i]-xyzMin[i]);
2508
2509   }
2510   
2511   sprintf(cTagM,"UT%02d",iDet);
2512   gMC->Gsvolu(cTagM,"BOX ",idtmed[1302-1],xyzBoxd,kNparCha);
2513
2514   sprintf(cTagV,"UA%02d",iDet);
2515   gMC->Gspos(cTagV,1,cTagM
2516             ,fChamberUAorig[iDet][0]-xyzOrig[0]
2517             ,fChamberUAorig[iDet][1]-xyzOrig[1]
2518             ,fChamberUAorig[iDet][2]-xyzOrig[2]
2519             ,0,"ONLY");
2520
2521   sprintf(cTagV,"UZ%02d",iDet);
2522   gMC->Gspos(cTagV,1,cTagM
2523             ,fChamberUAorig[iDet][0]-xyzOrig[0] + fChamberUAboxd[iDet][0] - fgkCroW/2.0
2524             ,fChamberUAorig[iDet][1]-xyzOrig[1]
2525             ,fChamberUAorig[iDet][2]-xyzOrig[2] + fgkCraH/2.0 + fgkCdrH/2.0 - fgkCalW/2.0
2526             ,0,"ONLY");
2527   gMC->Gspos(cTagV,2,cTagM
2528             ,fChamberUAorig[iDet][0]-xyzOrig[0] - fChamberUAboxd[iDet][0] + fgkCroW/2.0
2529             ,fChamberUAorig[iDet][1]-xyzOrig[1]
2530             ,fChamberUAorig[iDet][2]-xyzOrig[2] + fgkCraH/2.0 + fgkCdrH/2.0 - fgkCalW/2.0
2531             ,0,"ONLY");
2532
2533   sprintf(cTagV,"UD%02d",iDet);
2534   gMC->Gspos(cTagV,1,cTagM
2535             ,fChamberUDorig[iDet][0]-xyzOrig[0]
2536             ,fChamberUDorig[iDet][1]-xyzOrig[1]
2537             ,fChamberUDorig[iDet][2]-xyzOrig[2]
2538             ,0,"ONLY");
2539
2540   sprintf(cTagV,"UF%02d",iDet);
2541   gMC->Gspos(cTagV,1,cTagM
2542             ,fChamberUForig[iDet][0]-xyzOrig[0]
2543             ,fChamberUForig[iDet][1]-xyzOrig[1]
2544             ,fChamberUForig[iDet][2]-xyzOrig[2]
2545             ,0,"ONLY");
2546   
2547   sprintf(cTagV,"UU%02d",iDet);
2548   gMC->Gspos(cTagV,1,cTagM
2549             ,fChamberUUorig[iDet][0]-xyzOrig[0]
2550             ,fChamberUUorig[iDet][1]-xyzOrig[1]
2551             ,fChamberUUorig[iDet][2]-xyzOrig[2]
2552             ,0,"ONLY");
2553
2554   sprintf(cTagV,"UT%02d",iDet);
2555   gMC->Gspos(cTagV,1,"UTI1"
2556             ,xyzOrig[0]
2557             ,xyzOrig[1]
2558             ,xyzOrig[2]
2559             ,0,"ONLY");
2560   gMC->Gspos(cTagV,1,"UTI2"
2561             ,xyzOrig[0]
2562             ,xyzOrig[1]
2563             ,xyzOrig[2]
2564             ,0,"ONLY");
2565   if (istack != 2) {
2566     // W/o middle stack
2567     gMC->Gspos(cTagV,1,"UTI3"
2568               ,xyzOrig[0]
2569               ,xyzOrig[1]
2570               ,xyzOrig[2]
2571               ,0,"ONLY");
2572   }
2573
2574 }
2575
2576 //_____________________________________________________________________________
2577 Bool_t AliTRDgeometry::RotateBack(Int_t det, Double_t *loc, Double_t *glb) const
2578 {
2579   //
2580   // Rotates a chambers to transform the corresponding local frame
2581   // coordinates <loc> into the coordinates of the ALICE restframe <glb>.
2582   //
2583
2584   Int_t sector = GetSector(det);
2585
2586   glb[0] = loc[0] * fRotB11[sector] - loc[1] * fRotB12[sector];
2587   glb[1] = loc[0] * fRotB21[sector] + loc[1] * fRotB22[sector];
2588   glb[2] = loc[2];
2589
2590   return kTRUE;
2591
2592 }
2593
2594 //_____________________________________________________________________________
2595 Int_t AliTRDgeometry::GetDetectorSec(Int_t layer, Int_t stack)
2596 {
2597   //
2598   // Convert plane / stack into detector number for one single sector
2599   //
2600
2601   return (layer + stack * fgkNlayer);
2602
2603 }
2604
2605 //_____________________________________________________________________________
2606 Int_t AliTRDgeometry::GetDetector(Int_t layer, Int_t stack, Int_t sector)
2607 {
2608   //
2609   // Convert layer / stack / sector into detector number
2610   //
2611
2612   return (layer + stack * fgkNlayer + sector * fgkNlayer * fgkNstack);
2613
2614 }
2615
2616 //_____________________________________________________________________________
2617 Int_t AliTRDgeometry::GetLayer(Int_t det)
2618 {
2619   //
2620   // Reconstruct the layer number from the detector number
2621   //
2622
2623   return ((Int_t) (det % fgkNlayer));
2624
2625 }
2626
2627 //_____________________________________________________________________________
2628 Int_t AliTRDgeometry::GetStack(Int_t det)
2629 {
2630   //
2631   // Reconstruct the stack number from the detector number
2632   //
2633
2634   return ((Int_t) (det % (fgkNlayer * fgkNstack)) / fgkNlayer);
2635
2636 }
2637
2638 //_____________________________________________________________________________
2639 Int_t AliTRDgeometry::GetStack(Double_t z, Int_t layer)
2640 {
2641   //
2642   // Reconstruct the chamber number from the z position and layer number
2643   //
2644   // The return function has to be protected for positiveness !!
2645   //
2646
2647   if ((layer <          0) || 
2648       (layer >= fgkNlayer)) return -1;
2649         
2650   Int_t    istck = fgkNstack;
2651   Double_t zmin;
2652   Double_t zmax;
2653
2654   do {
2655     istck--;
2656     if (istck < 0) break;
2657     AliTRDpadPlane *pp = GetPadPlane(layer,istck);
2658     zmax  = pp->GetRow0();
2659     Int_t nrows = pp->GetNrows();
2660     zmin = zmax -         2 * pp->GetLengthOPad() 
2661                 - (nrows-2) * pp->GetLengthIPad() 
2662                 - (nrows-1) * pp->GetRowSpacing();
2663   } while((z < zmin) || (z > zmax));
2664   
2665   return istck;
2666
2667 }
2668
2669 //_____________________________________________________________________________
2670 Int_t AliTRDgeometry::GetSector(Int_t det)
2671 {
2672   //
2673   // Reconstruct the sector number from the detector number
2674   //
2675
2676   return ((Int_t) (det / (fgkNlayer * fgkNstack)));
2677
2678 }
2679
2680 //_____________________________________________________________________________
2681 AliTRDpadPlane *AliTRDgeometry::GetPadPlane(Int_t layer, Int_t stack)
2682 {
2683   //
2684   // Returns the pad plane for a given plane <pl> and stack <st> number
2685   //
2686
2687   if (!fPadPlaneArray) {
2688     CreatePadPlaneArray();
2689   }
2690
2691   Int_t ipp = GetDetectorSec(layer,stack);
2692   return ((AliTRDpadPlane *) fPadPlaneArray->At(ipp));
2693
2694 }
2695
2696 //_____________________________________________________________________________
2697 Int_t AliTRDgeometry::GetRowMax(Int_t layer, Int_t stack, Int_t /*sector*/)
2698 {
2699   //
2700   // Returns the number of rows on the pad plane
2701   //
2702
2703   return GetPadPlane(layer,stack)->GetNrows();
2704
2705 }
2706
2707 //_____________________________________________________________________________
2708 Int_t AliTRDgeometry::GetColMax(Int_t layer)
2709 {
2710   //
2711   // Returns the number of rows on the pad plane
2712   //
2713
2714   return GetPadPlane(layer,0)->GetNcols();
2715
2716 }
2717
2718 //_____________________________________________________________________________
2719 Double_t AliTRDgeometry::GetRow0(Int_t layer, Int_t stack, Int_t /*sector*/)
2720 {
2721   //
2722   // Returns the position of the border of the first pad in a row
2723   //
2724
2725   return GetPadPlane(layer,stack)->GetRow0();
2726
2727 }
2728
2729 //_____________________________________________________________________________
2730 Double_t AliTRDgeometry::GetCol0(Int_t layer)
2731 {
2732   //
2733   // Returns the position of the border of the first pad in a column
2734   //
2735
2736   return GetPadPlane(layer,0)->GetCol0();
2737
2738 }
2739
2740 //_____________________________________________________________________________
2741 Bool_t AliTRDgeometry::CreateClusterMatrixArray()
2742 {
2743   //
2744   // Create the matrices to transform cluster coordinates from the 
2745   // local chamber system to the tracking coordinate system
2746   //
2747
2748   if (!gGeoManager) {
2749     return kFALSE;
2750   }
2751
2752   TString volPath;
2753   TString vpStr   = "ALIC_1/B077_1/BSEGMO";
2754   TString vpApp1  = "_1/BTRD";
2755   TString vpApp2  = "_1";
2756   TString vpApp3a = "/UTR1_1/UTS1_1/UTI1_1";
2757   TString vpApp3b = "/UTR2_1/UTS2_1/UTI2_1";
2758   TString vpApp3c = "/UTR3_1/UTS3_1/UTI3_1";
2759
2760   fClusterMatrixArray = new TObjArray(kNdet);
2761   AliAlignObjParams o;
2762
2763   for (Int_t iLayer = AliGeomManager::kTRD1; iLayer <= AliGeomManager::kTRD6; iLayer++) {
2764     for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer); iModule++) {
2765       
2766       Int_t        isector   = iModule/Nstack();
2767       Int_t        istack    = iModule%Nstack();
2768       Int_t        iLayerTRD = iLayer - AliGeomManager::kTRD1;
2769       Int_t        lid       = GetDetector(iLayerTRD,istack,isector);    
2770
2771       // Check for disabled supermodules
2772       volPath  = vpStr;
2773       volPath += isector;
2774       volPath += vpApp1;
2775       volPath += isector;
2776       volPath += vpApp2;
2777       switch (isector) {
2778       case 13:
2779       case 14:
2780       case 15:
2781         if (istack == 2) {
2782           continue;
2783         }
2784         volPath += vpApp3c;
2785         break;
2786       case 11:
2787       case 12:
2788         volPath += vpApp3b;
2789         break;
2790       default:
2791         volPath += vpApp3a;
2792       };
2793       if (!gGeoManager->CheckPath(volPath)) {
2794         continue;
2795       }
2796
2797       // Check for holes in from of PHOS
2798       if (((isector == 13) || (isector == 14) || (isector == 15)) && 
2799           (istack == 2)) {
2800         continue; 
2801       }
2802
2803       UShort_t     volid   = AliGeomManager::LayerToVolUID(iLayer,iModule);
2804       const char  *symname = AliGeomManager::SymName(volid);
2805       TGeoPNEntry *pne     = gGeoManager->GetAlignableEntry(symname);
2806       const char  *path    = symname;
2807       if (pne) {
2808         path = pne->GetTitle();
2809       }
2810       else {
2811         continue;
2812       }
2813       if (!strstr(path,"ALIC")) {
2814         AliDebug(1,Form("Not a valid path: %s\n",path));
2815         continue;
2816       }
2817       if (!gGeoManager->cd(path)) {
2818         AliError(Form("Cannot go to path: %s\n",path));
2819         continue;
2820       }
2821       TGeoHMatrix *m         = gGeoManager->GetCurrentMatrix();
2822       
2823       TGeoRotation mchange; 
2824       mchange.RotateY(90); 
2825       mchange.RotateX(90);
2826
2827       //
2828       // Cluster transformation matrix
2829       //
2830       TGeoHMatrix  rotMatrix(mchange.Inverse());
2831       rotMatrix.MultiplyLeft(m);
2832       Double_t sectorAngle = 20.0 * (isector % 18) + 10.0;
2833       TGeoHMatrix  rotSector;
2834       rotSector.RotateZ(sectorAngle);
2835       rotMatrix.MultiplyLeft(&rotSector.Inverse());
2836
2837       fClusterMatrixArray->AddAt(new TGeoHMatrix(rotMatrix),lid);       
2838
2839     }    
2840   }
2841
2842   return kTRUE;
2843
2844 }
2845
2846 //_____________________________________________________________________________
2847 Bool_t AliTRDgeometry::ChamberInGeometry(Int_t det)
2848 {
2849   //
2850   // Checks whether the given detector is part of the current geometry
2851   //
2852
2853   if (!fClusterMatrixArray) {
2854     CreateClusterMatrixArray();
2855   }  
2856
2857   if (!GetClusterMatrix(det)) {
2858     return kFALSE;
2859   }
2860   else {
2861     return kTRUE;
2862   }
2863
2864 }