]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDgeometry.cxx
AliAlignObjAngles becomes AliAlignObjParams (Raffaele)
[u/mrichter/AliRoot.git] / TRD / AliTRDgeometry.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  TRD geometry class                                                       //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24
25 #include <TGeoManager.h>
26 #include <TGeoPhysicalNode.h>
27 #include <TGeoMatrix.h>
28
29 #include "AliLog.h"
30 #include "AliRunLoader.h"
31 #include "AliAlignObj.h"
32 #include "AliAlignObjParams.h"
33 #include "AliRun.h"
34
35 #include "AliTRD.h"
36 #include "AliTRDcalibDB.h"
37 #include "AliTRDgeometry.h"
38 #include "AliTRDpadPlane.h"
39
40 ClassImp(AliTRDgeometry)
41
42 //_____________________________________________________________________________
43
44   //
45   // The geometry constants
46   //
47   const Int_t    AliTRDgeometry::fgkNsect     = kNsect;
48   const Int_t    AliTRDgeometry::fgkNplan     = kNplan;
49   const Int_t    AliTRDgeometry::fgkNcham     = kNcham;
50   const Int_t    AliTRDgeometry::fgkNdet      = kNdet;
51
52   //
53   // Dimensions of the detector
54   //
55
56   // Parameter of the BTRD mother volumes 
57   const Float_t  AliTRDgeometry::fgkSheight   =  77.9; 
58   const Float_t  AliTRDgeometry::fgkSwidth1   =  94.881; 
59   const Float_t  AliTRDgeometry::fgkSwidth2   = 122.353;
60   const Float_t  AliTRDgeometry::fgkSlength   = 751.0;
61
62   // The super module side plates
63   const Float_t  AliTRDgeometry::fgkSMpltT    =   0.2;
64
65   // Height of different chamber parts
66   // Radiator
67   const Float_t  AliTRDgeometry::fgkCraH      =   4.8; 
68   // Drift region
69   const Float_t  AliTRDgeometry::fgkCdrH      =   3.0;
70   // Amplification region
71   const Float_t  AliTRDgeometry::fgkCamH      =   0.7;
72   // Readout
73   const Float_t  AliTRDgeometry::fgkCroH      =   2.316;
74   // Total height
75   const Float_t  AliTRDgeometry::fgkCH        = AliTRDgeometry::fgkCraH
76                                               + AliTRDgeometry::fgkCdrH
77                                               + AliTRDgeometry::fgkCamH
78                                               + AliTRDgeometry::fgkCroH;  
79
80   // Vertical spacing of the chambers
81   const Float_t  AliTRDgeometry::fgkVspace    =   1.784;
82   // Horizontal spacing of the chambers
83   const Float_t  AliTRDgeometry::fgkHspace    =   2.0;
84   // Radial distance of the first ROC to the outer plates of the SM
85   const Float_t  AliTRDgeometry::fgkVrocsm    =   1.2;
86
87   // Thicknesses of different parts of the chamber frame
88   // Lower aluminum frame
89   const Float_t  AliTRDgeometry::fgkCalT      =   0.4;
90   // Lower Wacosit frame sides
91   const Float_t  AliTRDgeometry::fgkCclsT     =   0.21;
92   // Lower Wacosit frame front
93   const Float_t  AliTRDgeometry::fgkCclfT     =   1.0;
94   // Thickness of glue around radiator
95   const Float_t  AliTRDgeometry::fgkCglT      =   0.25;
96   // Upper Wacosit frame
97   const Float_t  AliTRDgeometry::fgkCcuT      =   0.9;
98   // Al frame of back panel
99   const Float_t  AliTRDgeometry::fgkCauT      =   1.5;
100   // Additional Al of the lower chamber frame
101   const Float_t  AliTRDgeometry::fgkCalW      =   1.11;
102
103   // Additional width of the readout chamber frames
104   const Float_t  AliTRDgeometry::fgkCroW      =   0.9;
105
106   // Difference of outer chamber width and pad plane width
107   const Float_t  AliTRDgeometry::fgkCpadW     =   0.0;
108   const Float_t  AliTRDgeometry::fgkRpadW     =   1.0;
109
110   //
111   // Thickness of the the material layers
112   //
113   const Float_t  AliTRDgeometry::fgkMyThick   = 0.005;
114   const Float_t  AliTRDgeometry::fgkRaThick   = 0.3233;  
115   const Float_t  AliTRDgeometry::fgkDrThick   = AliTRDgeometry::fgkCdrH;    
116   const Float_t  AliTRDgeometry::fgkAmThick   = AliTRDgeometry::fgkCamH;
117   const Float_t  AliTRDgeometry::fgkXeThick   = AliTRDgeometry::fgkDrThick
118                                               + AliTRDgeometry::fgkAmThick;
119   const Float_t  AliTRDgeometry::fgkWrThick   = 0.0002;
120   const Float_t  AliTRDgeometry::fgkCuThick   = 0.0072; 
121   const Float_t  AliTRDgeometry::fgkGlThick   = 0.05;
122   const Float_t  AliTRDgeometry::fgkSuThick   = 0.0919; 
123   const Float_t  AliTRDgeometry::fgkRcThick   = 0.0058;
124   const Float_t  AliTRDgeometry::fgkRpThick   = 0.0632;
125   const Float_t  AliTRDgeometry::fgkRoThick   = 0.0028;
126
127   //
128   // Position of the material layers
129   //
130   const Float_t  AliTRDgeometry::fgkRaZpos    =  0.0;
131   const Float_t  AliTRDgeometry::fgkDrZpos    =  2.4;
132   const Float_t  AliTRDgeometry::fgkAmZpos    =  0.0;
133   const Float_t  AliTRDgeometry::fgkWrZpos    =  0.0;
134   const Float_t  AliTRDgeometry::fgkCuZpos    = -0.9995;
135   const Float_t  AliTRDgeometry::fgkGlZpos    = -0.5; 
136   const Float_t  AliTRDgeometry::fgkSuZpos    =  0.0;
137   const Float_t  AliTRDgeometry::fgkRcZpos    =  1.04;
138   const Float_t  AliTRDgeometry::fgkRpZpos    =  1.0;
139   const Float_t  AliTRDgeometry::fgkRoZpos    =  1.05;
140
141   const Int_t    AliTRDgeometry::fgkMCMmax    = 16;   
142   const Int_t    AliTRDgeometry::fgkMCMrow    = 4;   
143   const Int_t    AliTRDgeometry::fgkROBmaxC0  = 6; 
144   const Int_t    AliTRDgeometry::fgkROBmaxC1  = 8; 
145   const Int_t    AliTRDgeometry::fgkADCmax    = 21;   
146   const Int_t    AliTRDgeometry::fgkTBmax     = 60;   
147   const Int_t    AliTRDgeometry::fgkPadmax    = 18;   
148   const Int_t    AliTRDgeometry::fgkColmax    = 144;
149   const Int_t    AliTRDgeometry::fgkRowmaxC0  = 12;
150   const Int_t    AliTRDgeometry::fgkRowmaxC1  = 16;
151
152   const Double_t AliTRDgeometry::fgkTime0Base = 300.65;
153   const Float_t  AliTRDgeometry::fgkTime0[6]  = { fgkTime0Base + 0 * (Cheight() + Cspace()) 
154                                                 , fgkTime0Base + 1 * (Cheight() + Cspace()) 
155                                                 , fgkTime0Base + 2 * (Cheight() + Cspace()) 
156                                                 , fgkTime0Base + 3 * (Cheight() + Cspace()) 
157                                                 , fgkTime0Base + 4 * (Cheight() + Cspace()) 
158                                                 , fgkTime0Base + 5 * (Cheight() + Cspace())};
159
160 //_____________________________________________________________________________
161 AliTRDgeometry::AliTRDgeometry()
162   :AliGeometry()
163   ,fMatrixArray(0)
164   ,fMatrixCorrectionArray(0)
165   ,fMatrixGeo(0)
166   ,fPadPlaneArray(0)
167 {
168   //
169   // AliTRDgeometry default constructor
170   //
171
172   Init();
173
174 }
175
176 //_____________________________________________________________________________
177 AliTRDgeometry::AliTRDgeometry(const AliTRDgeometry &g)
178   :AliGeometry(g)
179   ,fMatrixArray(0)
180   ,fMatrixCorrectionArray(0)
181   ,fMatrixGeo(0)
182   ,fPadPlaneArray(0)
183 {
184   //
185   // AliTRDgeometry copy constructor
186   //
187
188   Init();
189
190 }
191
192 //_____________________________________________________________________________
193 AliTRDgeometry::~AliTRDgeometry()
194 {
195   //
196   // AliTRDgeometry destructor
197   //
198
199   if (fMatrixArray) {
200     fMatrixArray->Delete();
201     delete fMatrixArray;
202     fMatrixArray = 0;
203   }
204
205   if (fMatrixCorrectionArray) {
206     fMatrixCorrectionArray->Delete();
207     delete fMatrixCorrectionArray;
208     fMatrixCorrectionArray = 0;
209   }
210
211   if (fMatrixGeo) {
212     fMatrixGeo->Delete();
213     delete fMatrixGeo;
214     fMatrixGeo = 0;
215   }
216
217   if (fPadPlaneArray) {
218     fPadPlaneArray->Delete();
219     delete fPadPlaneArray;
220     fPadPlaneArray = 0;
221   }
222
223 }
224
225 //_____________________________________________________________________________
226 AliTRDgeometry &AliTRDgeometry::operator=(const AliTRDgeometry &g)
227 {
228   //
229   // Assignment operator
230   //
231
232   if (this != &g) {
233     Init();
234   }
235
236   return *this;
237
238 }
239
240 //_____________________________________________________________________________
241 void AliTRDgeometry::Init()
242 {
243   //
244   // Initializes the geometry parameter
245   //
246
247   Int_t icham;
248   Int_t iplan;
249   Int_t isect;
250
251   // The outer width of the chambers
252   fCwidth[0] =  90.4;
253   fCwidth[1] =  94.8;
254   fCwidth[2] =  99.3;
255   fCwidth[3] = 103.7;
256   fCwidth[4] = 108.1;
257   fCwidth[5] = 112.6;
258
259   // The outer lengths of the chambers
260   // Includes the spacings between the chambers!
261   Float_t length[kNplan][kNcham]   = { { 124.0, 124.0, 110.0, 124.0, 124.0 }
262                                      , { 124.0, 124.0, 110.0, 124.0, 124.0 }
263                                      , { 131.0, 131.0, 110.0, 131.0, 131.0 }
264                                      , { 138.0, 138.0, 110.0, 138.0, 138.0 }
265                                      , { 145.0, 145.0, 110.0, 145.0, 145.0 }
266                                      , { 147.0, 147.0, 110.0, 147.0, 147.0 } };
267
268   for (icham = 0; icham < kNcham; icham++) {
269     for (iplan = 0; iplan < kNplan; iplan++) {
270       fClength[iplan][icham] = length[iplan][icham];
271     }
272   }
273
274   // The rotation matrix elements
275   Float_t phi = 0.0;
276   for (isect = 0; isect < fgkNsect; isect++) {
277     phi = 2.0 * TMath::Pi() /  (Float_t) fgkNsect * ((Float_t) isect + 0.5);
278     fRotB11[isect] = TMath::Cos(phi);
279     fRotB12[isect] = TMath::Sin(phi);
280     fRotB21[isect] = TMath::Sin(phi);
281     fRotB22[isect] = TMath::Cos(phi);
282   }
283
284   // Initialize the SM status
285   for (isect = 0; isect < fgkNsect; isect++) {
286     SetSMstatus(isect,1);
287   }
288  
289 }
290
291 //_____________________________________________________________________________
292 void AliTRDgeometry::CreatePadPlaneArray()
293 {
294   //
295   // Creates the array of AliTRDpadPlane objects
296   //
297
298   if (fPadPlaneArray) {
299     fPadPlaneArray->Delete();
300     delete fPadPlaneArray;
301   }
302
303   fPadPlaneArray = new TObjArray(fgkNplan * fgkNcham);  
304   for (Int_t iplan = 0; iplan < fgkNplan; iplan++) {
305     for (Int_t icham = 0; icham < fgkNcham; icham++) {
306       Int_t ipp = GetDetectorSec(iplan,icham);
307       fPadPlaneArray->AddAt(CreatePadPlane(iplan,icham),ipp);
308     }
309   }
310
311 }
312
313 //_____________________________________________________________________________
314 AliTRDpadPlane *AliTRDgeometry::CreatePadPlane(Int_t iplan, Int_t icham)
315 {
316   //
317   // Creates an AliTRDpadPlane object
318   //
319
320   AliTRDpadPlane *padPlane = new AliTRDpadPlane();
321
322   padPlane->SetPlane(iplan);
323   padPlane->SetChamber(icham);
324
325   padPlane->SetRowSpacing(0.0);
326   padPlane->SetColSpacing(0.0);
327
328   padPlane->SetLengthRim(1.0);
329   padPlane->SetWidthRim(0.5);
330
331   padPlane->SetNcols(144);
332
333   //
334   // The pad plane parameter
335   //
336   switch (iplan) {
337   case 0:
338     if (icham == 2) {
339       // L0C0 type
340       padPlane->SetNrows(12);
341       padPlane->SetLength(108.0);
342       padPlane->SetWidth(92.2);
343       padPlane->SetLengthOPad(8.0);
344       padPlane->SetWidthOPad(0.515);
345       padPlane->SetLengthIPad(9.0);
346       padPlane->SetWidthIPad(0.635);
347       padPlane->SetTiltingAngle(-2.0);
348     }
349     else {
350       // L0C1 type
351       padPlane->SetNrows(16);
352       padPlane->SetLength(122.0);
353       padPlane->SetWidth(92.2);
354       padPlane->SetLengthOPad(7.5);
355       padPlane->SetWidthOPad(0.515);
356       padPlane->SetLengthIPad(7.5);
357       padPlane->SetWidthIPad(0.635);
358       padPlane->SetTiltingAngle(-2.0);
359     }
360     break;
361   case 1:
362     if (icham == 2) {
363       // L1C0 type
364       padPlane->SetNrows(12);
365       padPlane->SetLength(108.0);
366       padPlane->SetWidth(96.6);
367       padPlane->SetLengthOPad(8.0);
368       padPlane->SetWidthOPad(0.585);
369       padPlane->SetLengthIPad(9.0);
370       padPlane->SetWidthIPad(0.665);
371       padPlane->SetTiltingAngle(2.0);
372     }
373     else {
374       // L1C1 type
375       padPlane->SetNrows(16);
376       padPlane->SetLength(122.0);
377       padPlane->SetWidth(96.6);
378       padPlane->SetLengthOPad(7.5);
379       padPlane->SetWidthOPad(0.585);
380       padPlane->SetLengthIPad(7.5);
381       padPlane->SetWidthIPad(0.665);
382       padPlane->SetTiltingAngle(2.0);
383     }
384     break;
385   case 2:
386     if (icham == 2) {
387       // L2C0 type
388       padPlane->SetNrows(12);
389       padPlane->SetLength(108.0);
390       padPlane->SetWidth(101.1);
391       padPlane->SetLengthOPad(8.0);
392       padPlane->SetWidthOPad(0.705);
393       padPlane->SetLengthIPad(9.0);
394       padPlane->SetWidthIPad(0.695);
395       padPlane->SetTiltingAngle(-2.0);
396     }
397     else {
398       // L2C1 type
399       padPlane->SetNrows(16);
400       padPlane->SetLength(129.0);
401       padPlane->SetWidth(101.1);
402       padPlane->SetLengthOPad(7.5);
403       padPlane->SetWidthOPad(0.705);
404       padPlane->SetLengthIPad(8.0);
405       padPlane->SetWidthIPad(0.695);
406       padPlane->SetTiltingAngle(-2.0);
407     }
408     break;
409   case 3:
410     if (icham == 2) {
411       // L3C0 type
412       padPlane->SetNrows(12);
413       padPlane->SetLength(108.0);
414       padPlane->SetWidth(105.5);
415       padPlane->SetLengthOPad(8.0);
416       padPlane->SetWidthOPad(0.775);
417       padPlane->SetLengthIPad(9.0);
418       padPlane->SetWidthIPad(0.725);
419       padPlane->SetTiltingAngle(2.0);
420     }
421     else {
422       // L3C1 type
423       padPlane->SetNrows(16);
424       padPlane->SetLength(136.0);
425       padPlane->SetWidth(105.5);
426       padPlane->SetLengthOPad(7.5);
427       padPlane->SetWidthOPad(0.775);
428       padPlane->SetLengthIPad(8.5);
429       padPlane->SetWidthIPad(0.725);
430       padPlane->SetTiltingAngle(2.0);
431     }
432     break;
433   case 4:
434     if (icham == 2) {
435       // L4C0 type
436       padPlane->SetNrows(12);
437       padPlane->SetLength(108.0);
438       padPlane->SetWidth(109.9);
439       padPlane->SetLengthOPad(8.0);
440       padPlane->SetWidthOPad(0.845);
441       padPlane->SetLengthIPad(9.0);
442       padPlane->SetWidthIPad(0.755);
443       padPlane->SetTiltingAngle(-2.0);
444     }
445     else {
446       // L4C1 type
447       padPlane->SetNrows(16);
448       padPlane->SetLength(143.0);
449       padPlane->SetWidth(109.9);
450       padPlane->SetLengthOPad(7.5);
451       padPlane->SetWidthOPad(0.845);
452       padPlane->SetLengthIPad(9.0);
453       padPlane->SetWidthIPad(0.755);
454       padPlane->SetTiltingAngle(-2.0);
455     }
456     break;
457   case 5:
458     if (icham == 2) {
459       // L5C0 type
460       padPlane->SetNrows(12);
461       padPlane->SetLength(108.0);
462       padPlane->SetWidth(114.4);
463       padPlane->SetLengthOPad(8.0);
464       padPlane->SetWidthOPad(0.965);
465       padPlane->SetLengthIPad(9.0);
466       padPlane->SetWidthIPad(0.785);
467       padPlane->SetTiltingAngle(2.0);
468     }
469     else {
470       // L5C1 type
471       padPlane->SetNrows(16);
472       padPlane->SetLength(145.0);
473       padPlane->SetWidth(114.4);
474       padPlane->SetLengthOPad(8.5);
475       padPlane->SetWidthOPad(0.965);
476       padPlane->SetLengthIPad(9.0);
477       padPlane->SetWidthIPad(0.785);
478       padPlane->SetTiltingAngle(2.0);
479     }
480     break;
481   };
482
483   //
484   // The positions of the borders of the pads
485   //
486   // Row direction
487   //
488   Double_t row = fClength[iplan][icham] / 2.0
489                - fgkRpadW
490                - padPlane->GetLengthRim();
491   for (Int_t ir = 0; ir < padPlane->GetNrows(); ir++) {
492     padPlane->SetPadRow(ir,row);
493     row -= padPlane->GetRowSpacing();
494     if (ir == 0) {
495       row -= padPlane->GetLengthOPad();
496     }
497     else {
498       row -= padPlane->GetLengthIPad();
499     }
500   }
501   //
502   // Column direction
503   //
504   Double_t col = fCwidth[iplan] / 2.0
505                + fgkCroW
506                - padPlane->GetWidthRim();
507   for (Int_t ic = 0; ic < padPlane->GetNcols(); ic++) {
508     padPlane->SetPadCol(ic,col);
509     col -= padPlane->GetColSpacing();
510     if (ic == 0) {
511       col -= padPlane->GetWidthOPad();
512     }
513     else {
514       col -= padPlane->GetWidthIPad();
515     }
516   }
517   // Calculate the offset to translate from the local ROC system into
518   // the local supermodule system, which is used for clusters
519   Double_t rowTmp = fClength[iplan][0]
520                   + fClength[iplan][1]
521                   + fClength[iplan][2] / 2.0;
522   for (Int_t ic = 0; ic < icham; ic++) {
523     rowTmp -= fClength[iplan][ic];
524   }
525   padPlane->SetPadRowSMOffset(rowTmp - fClength[iplan][icham]/2.0);
526
527   return padPlane;
528
529 }
530
531 //_____________________________________________________________________________
532 void AliTRDgeometry::CreateGeometry(Int_t *idtmed)
533 {
534   //
535   // Create the TRD geometry without hole
536   //
537   //
538   // Names of the TRD volumina (xx = detector number):
539   //
540   //      Volume (Air) wrapping the readout chamber components
541   //        UTxx    includes: UAxx, UDxx, UFxx, UUxx
542   //
543   //      Volume (Air) wrapping the services (fee + cooling)
544   //        UUxx    the services volume has been reduced by 7.42 mm
545   //                in order to allow shifts in radial direction
546   //
547   //      Lower part of the readout chambers (drift volume + radiator)
548   //
549   //        UAxx    Aluminum frames                 (Al)
550   //        UBxx    Wacosit frames                  (C)
551   //        UXxx    Glue around radiator            (Epoxy)
552   //        UCxx    Inner volumes                   (Air)
553   //        UZxx    Additional aluminum ledges      (Al)
554   //
555   //      Upper part of the readout chambers (readout plane + fee)
556   //
557   //        UDxx    Wacosit frames of amp. region   (C)
558   //        UExx    Inner volumes of the frame      (Air)
559   //        UFxx    Aluminum frame of back panel    (Al)
560   //        UGxx    Inner volumes of the back panel (Air)
561   //
562   //      Inner material layers
563   //
564   //        UHxx    Radiator                        (Rohacell)
565   //        UJxx    Drift volume                    (Xe/CO2)
566   //        UKxx    Amplification volume            (Xe/CO2)
567   //        UWxx    Wire plane                      (Cu)
568   //        ULxx    Pad plane                       (Cu)
569   //        UYxx    Glue layer                      (Epoxy)
570   //        UMxx    Support structure               (Rohacell)
571   //        UNxx    ROB base material               (C)
572   //        UOxx    ROB copper                      (Cu)
573   //        UVxx    ROB other materials             (Cu)
574   //
575
576   const Int_t kNparTrd = 4;
577   const Int_t kNparCha = 3;
578
579   Float_t xpos;
580   Float_t ypos;
581   Float_t zpos;
582
583   Float_t parTrd[kNparTrd];
584   Float_t parCha[kNparCha];
585
586   Char_t  cTagV[6];
587   Char_t  cTagM[5];
588
589   // The TRD mother volume for one sector (Air), full length in z-direction
590   // Provides material for side plates of super module
591   parTrd[0] = fgkSwidth1/2.0;
592   parTrd[1] = fgkSwidth2/2.0;
593   parTrd[2] = fgkSlength/2.0;
594   parTrd[3] = fgkSheight/2.0;
595   gMC->Gsvolu("UTR1","TRD1",idtmed[1302-1],parTrd,kNparTrd);
596
597   // The outer aluminum plates of the super module (Al)
598   parTrd[0] = fgkSwidth1/2.0;
599   parTrd[1] = fgkSwidth2/2.0;
600   parTrd[2] = fgkSlength/2.0;
601   parTrd[3] = fgkSheight/2.0;
602   gMC->Gsvolu("UTS1","TRD1",idtmed[1301-1],parTrd,kNparTrd);
603
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
612   for (Int_t icham = 0; icham < kNcham; icham++) {
613     for (Int_t iplan = 0; iplan < kNplan; iplan++) {  
614
615       Int_t iDet = GetDetectorSec(iplan,icham);
616
617       // The lower part of the readout chambers (drift volume + radiator) 
618       // The aluminum frames 
619       sprintf(cTagV,"UA%02d",iDet);
620       parCha[0] = fCwidth[iplan]/2.0;
621       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
622       parCha[2] = fgkCraH/2.0 + fgkCdrH/2.0;
623       fChamberUAboxd[iDet][0] = parCha[0];
624       fChamberUAboxd[iDet][1] = parCha[1];
625       fChamberUAboxd[iDet][2] = parCha[2];
626       gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
627       // The additional aluminum on the frames
628       // This part has not the correct postion but is just supposed to
629       // represent the missing material. The correct from of the L-shaped
630       // profile would not fit into the alignable volume. 
631       sprintf(cTagV,"UZ%02d",iDet);
632       parCha[0] = fgkCroW/2.0;
633       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
634       parCha[2] = fgkCalW/2.0;
635       fChamberUAboxd[iDet][0] = fChamberUAboxd[iDet][0] + fgkCroW;
636       gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
637       // The Wacosit frames 
638       sprintf(cTagV,"UB%02d",iDet);
639       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT; 
640       parCha[1] = -1.0;
641       parCha[2] = -1.0;
642       gMC->Gsvolu(cTagV,"BOX ",idtmed[1307-1],parCha,kNparCha);
643       // The glue around the radiator
644       sprintf(cTagV,"UX%02d",iDet);
645       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT - fgkCclsT; 
646       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCclfT;
647       parCha[2] = fgkCraH/2.0;
648       gMC->Gsvolu(cTagV,"BOX ",idtmed[1311-1],parCha,kNparCha);
649       // The inner part of radiator (air)
650       sprintf(cTagV,"UC%02d",iDet);
651       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT - fgkCclsT - fgkCglT; 
652       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCclfT - fgkCglT;
653       parCha[2] = -1.0;
654       gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
655
656       // The upper part of the readout chambers (amplification volume)
657       // The Wacosit frames
658       sprintf(cTagV,"UD%02d",iDet);
659       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW;
660       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
661       parCha[2] = fgkCamH/2.0;
662       fChamberUDboxd[iDet][0] = parCha[0];
663       fChamberUDboxd[iDet][1] = parCha[1];
664       fChamberUDboxd[iDet][2] = parCha[2];
665       gMC->Gsvolu(cTagV,"BOX ",idtmed[1307-1],parCha,kNparCha);
666       // The inner part of the Wacosit frame (air)
667       sprintf(cTagV,"UE%02d",iDet);
668       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW - fgkCcuT; 
669       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCcuT;
670       parCha[2] = -1.;
671       gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
672
673       // The support structure (pad plane, back panel, readout boards)
674       // The aluminum frames
675       sprintf(cTagV,"UF%02d",iDet);
676       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW;
677       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
678       parCha[2] = fgkCroH/2.0;
679       fChamberUFboxd[iDet][0] = parCha[0];
680       fChamberUFboxd[iDet][1] = parCha[1];
681       fChamberUFboxd[iDet][2] = parCha[2];
682       gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
683       // The inner part of the aluminum frames
684       sprintf(cTagV,"UG%02d",iDet);
685       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW - fgkCauT; 
686       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCauT;
687       parCha[2] = -1.0;
688       gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
689
690       // The material layers inside the chambers
691       // Rohacell layer (radiator)
692       parCha[0] = -1.0;
693       parCha[1] = -1.0;
694       parCha[2] = fgkRaThick/2.0;
695       sprintf(cTagV,"UH%02d",iDet);
696       gMC->Gsvolu(cTagV,"BOX ",idtmed[1315-1],parCha,kNparCha);
697       // Xe/Isobutane layer (drift volume) 
698       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT - fgkCclsT;
699       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCclfT;
700       parCha[2] = fgkDrThick/2.0;
701       sprintf(cTagV,"UJ%02d",iDet);
702       gMC->Gsvolu(cTagV,"BOX ",idtmed[1309-1],parCha,kNparCha);
703       // Xe/Isobutane layer (amplification volume)
704       parCha[0] = -1.0;
705       parCha[1] = -1.0;
706       parCha[2] = fgkAmThick/2.0;
707       sprintf(cTagV,"UK%02d",iDet);
708       gMC->Gsvolu(cTagV,"BOX ",idtmed[1309-1],parCha,kNparCha);  
709       // Cu layer (wire plane)
710       parCha[0] = -1.0;
711       parCha[1] = -1.0;
712       parCha[2] = fgkWrThick/2.0;
713       sprintf(cTagV,"UW%02d",iDet);
714       gMC->Gsvolu(cTagV,"BOX ",idtmed[1303-1],parCha,kNparCha);
715       // Cu layer (pad plane)
716       parCha[0] = -1.0;
717       parCha[1] = -1.0;
718       parCha[2] = fgkCuThick/2.0;
719       sprintf(cTagV,"UL%02d",iDet);
720       gMC->Gsvolu(cTagV,"BOX ",idtmed[1305-1],parCha,kNparCha);
721       // Epoxy layer (glue)
722       parCha[0] = -1.0;
723       parCha[1] = -1.0;
724       parCha[2] = fgkGlThick/2.0;
725       sprintf(cTagV,"UY%02d",iDet);
726       gMC->Gsvolu(cTagV,"BOX ",idtmed[1311-1],parCha,kNparCha);
727       // G10 layer (support structure / honeycomb)
728       parCha[0] = -1.0;
729       parCha[1] = -1.0;
730       parCha[2] = fgkSuThick/2.0;
731       sprintf(cTagV,"UM%02d",iDet);
732       gMC->Gsvolu(cTagV,"BOX ",idtmed[1310-1],parCha,kNparCha);
733       // G10 layer (PCB readout board)
734       parCha[0] = -1.0;
735       parCha[1] = -1.0;
736       parCha[2] = fgkRpThick/2;
737       sprintf(cTagV,"UN%02d",iDet);
738       gMC->Gsvolu(cTagV,"BOX ",idtmed[1313-1],parCha,kNparCha);
739       // Cu layer (traces in readout board)
740       parCha[0] = -1.0;
741       parCha[1] = -1.0;
742       parCha[2] = fgkRcThick/2.0;
743       sprintf(cTagV,"UO%02d",iDet);
744       gMC->Gsvolu(cTagV,"BOX ",idtmed[1306-1],parCha,kNparCha);
745       // Cu layer (other material on in readout board)
746       parCha[0] = -1.0;
747       parCha[1] = -1.0;
748       parCha[2] = fgkRoThick/2.0;
749       sprintf(cTagV,"UV%02d",iDet);
750       gMC->Gsvolu(cTagV,"BOX ",idtmed[1304-1],parCha,kNparCha);
751
752       // Position the layers in the chambers
753       xpos = 0.0;
754       ypos = 0.0;
755       // Lower part
756       // Rohacell layer (radiator)
757       zpos = fgkRaZpos;
758       sprintf(cTagV,"UH%02d",iDet);
759       sprintf(cTagM,"UC%02d",iDet);
760       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
761       // Xe/Isobutane layer (drift volume) 
762       zpos = fgkDrZpos;
763       sprintf(cTagV,"UJ%02d",iDet);
764       sprintf(cTagM,"UB%02d",iDet);
765       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
766       // Upper part
767       // Xe/Isobutane layer (amplification volume)
768       zpos = fgkAmZpos;
769       sprintf(cTagV,"UK%02d",iDet);
770       sprintf(cTagM,"UE%02d",iDet);
771       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
772       // Cu layer (wire plane inside amplification volume)
773       zpos = fgkWrZpos; 
774       sprintf(cTagV,"UW%02d",iDet);
775       sprintf(cTagM,"UK%02d",iDet);
776       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
777       // Readout part + support plane
778       // Cu layer (pad plane)
779       zpos = fgkCuZpos; 
780       sprintf(cTagV,"UL%02d",iDet);
781       sprintf(cTagM,"UG%02d",iDet);
782       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
783       // Epoxy layer (glue)
784       zpos = fgkGlZpos; 
785       sprintf(cTagV,"UY%02d",iDet);
786       sprintf(cTagM,"UG%02d",iDet);
787       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
788       // G10 layer (support structure)
789       zpos = fgkSuZpos;
790       sprintf(cTagV,"UM%02d",iDet);
791       sprintf(cTagM,"UG%02d",iDet);
792       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
793       // G10 layer (PCB readout board)
794       zpos = fgkRpZpos;
795       sprintf(cTagV,"UN%02d",iDet);
796       sprintf(cTagM,"UG%02d",iDet);
797       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
798       // Cu layer (traces in readout board)
799       zpos = fgkRcZpos;
800       sprintf(cTagV,"UO%02d",iDet);
801       sprintf(cTagM,"UG%02d",iDet);
802       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
803       // Cu layer (other materials on readout board)
804       zpos = fgkRoZpos;
805       sprintf(cTagV,"UV%02d",iDet);
806       sprintf(cTagM,"UG%02d",iDet);
807       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
808
809       // Position the inner volumes of the chambers in the frames
810       xpos = 0.0;
811       ypos = 0.0;
812       // The inner part of the radiator
813       zpos = 0.0;
814       sprintf(cTagV,"UC%02d",iDet);
815       sprintf(cTagM,"UX%02d",iDet);
816       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
817       // The glue around the radiator
818       zpos = fgkCraH/2.0 - fgkCdrH/2.0 - fgkCraH/2.0;
819       sprintf(cTagV,"UX%02d",iDet);
820       sprintf(cTagM,"UB%02d",iDet);
821       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
822       // The lower Wacosit frame inside the aluminum frame
823       zpos = 0.0;
824       sprintf(cTagV,"UB%02d",iDet);
825       sprintf(cTagM,"UA%02d",iDet);
826       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
827       // The inside of the upper Wacosit frame
828       zpos = 0.0;
829       sprintf(cTagV,"UE%02d",iDet);
830       sprintf(cTagM,"UD%02d",iDet);
831       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
832       // The inside of the upper aluminum frame
833       zpos = 0.0;
834       sprintf(cTagV,"UG%02d",iDet);
835       sprintf(cTagM,"UF%02d",iDet);
836       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");      
837
838       // Position the frames of the chambers in the TRD mother volume
839       xpos  = 0.0;
840       ypos  = fClength[iplan][0] + fClength[iplan][1] + fClength[iplan][2]/2.0;
841       for (Int_t ic = 0; ic < icham; ic++) {
842         ypos -= fClength[iplan][ic];
843       }
844       ypos -= fClength[iplan][icham]/2.0;
845       zpos  = fgkVrocsm + fgkSMpltT + fgkCraH/2.0 + fgkCdrH/2.0 - fgkSheight/2.0
846             + iplan * (fgkCH + fgkVspace);
847       // The lower aluminum frame, radiator + drift region
848       sprintf(cTagV,"UA%02d",iDet);      
849       fChamberUAorig[iDet][0] = xpos;
850       fChamberUAorig[iDet][1] = ypos;
851       fChamberUAorig[iDet][2] = zpos;
852       // The upper G10 frame, amplification region
853       sprintf(cTagV,"UD%02d",iDet);
854       zpos += fgkCamH/2.0 + fgkCraH/2.0 + fgkCdrH/2.0;      
855       fChamberUDorig[iDet][0] = xpos;
856       fChamberUDorig[iDet][1] = ypos;
857       fChamberUDorig[iDet][2] = zpos;
858       // The upper aluminum frame
859       sprintf(cTagV,"UF%02d",iDet);
860       zpos += fgkCroH/2.0 + fgkCamH/2.0;      
861       fChamberUForig[iDet][0] = xpos;
862       fChamberUForig[iDet][1] = ypos;
863       fChamberUForig[iDet][2] = zpos;
864
865     }
866   }
867
868   // Create the volumes of the super module frame
869   CreateFrame(idtmed);
870
871   // Create the volumes of the services
872   CreateServices(idtmed);
873   
874   for (Int_t icham = 0; icham < kNcham; icham++) {
875     for (Int_t iplan = 0; iplan < kNplan; iplan++) {  
876       GroupChamber(iplan,icham,idtmed);
877     }
878   }
879   
880   xpos = 0.0;
881   ypos = 0.0;
882   zpos = 0.0;
883   gMC->Gspos("UTI1",1,"UTS1",xpos,ypos,zpos,0,"ONLY");
884
885   xpos = 0.0;
886   ypos = 0.0;
887   zpos = 0.0;
888   gMC->Gspos("UTS1",1,"UTR1",xpos,ypos,zpos,0,"ONLY");
889
890   // Put the TRD volumes into the space frame mother volumes
891   // if enabled via status flag
892   xpos = 0.0;
893   ypos = 0.0;
894   zpos = 0.0;
895   for (Int_t isect = 0; isect < kNsect; isect++) {
896     if (fSMstatus[isect]) {
897       sprintf(cTagV,"BTRD%d",isect);
898       gMC->Gspos("UTR1",1,cTagV,xpos,ypos,zpos,0,"ONLY");
899     }
900   }
901
902 }
903
904 //_____________________________________________________________________________
905 void AliTRDgeometry::CreateFrame(Int_t *idtmed)
906 {
907   //
908   // Create the geometry of the frame of the supermodule
909   //
910   // Names of the TRD services volumina
911   //
912   //        USRL    Support rails for the chambers (Al)
913   //        USxx    Support cross bars between the chambers (Al)
914   //        USHx    Horizontal connection between the cross bars (Al)
915   //        USLx    Long corner ledges (Al)
916   //
917
918   Int_t   iplan = 0;
919
920   Float_t xpos  = 0.0;
921   Float_t ypos  = 0.0;
922   Float_t zpos  = 0.0;
923
924   Char_t  cTagV[5];
925   Char_t  cTagM[5];
926
927   // The rotation matrices
928   const Int_t kNmatrix = 4;
929   Int_t   matrix[kNmatrix];
930   gMC->Matrix(matrix[0], 100.0,   0.0,  90.0,  90.0,  10.0,   0.0);
931   gMC->Matrix(matrix[1],  80.0,   0.0,  90.0,  90.0,  10.0, 180.0);
932   gMC->Matrix(matrix[2],  90.0,   0.0,   0.0,   0.0,  90.0,  90.0);
933   gMC->Matrix(matrix[3],  90.0, 180.0,   0.0, 180.0,  90.0,  90.0);
934
935   //
936   // The chamber support rails
937   //
938
939   const Float_t kSRLwid  = 2.00;
940   const Float_t kSRLhgt  = 2.3;
941   const Float_t kSRLdst  = 1.0;
942   const Int_t   kNparSRL = 3;
943   Float_t parSRL[kNparSRL];
944   parSRL[0] = kSRLwid   /2.0;
945   parSRL[1] = fgkSlength/2.0;
946   parSRL[2] = kSRLhgt   /2.0;
947   gMC->Gsvolu("USRL","BOX ",idtmed[1301-1],parSRL,kNparSRL);
948
949   xpos  = 0.0;
950   ypos  = 0.0;
951   zpos  = 0.0;
952   for (iplan = 0; iplan < kNplan; iplan++) {
953     xpos  = fCwidth[iplan]/2.0 + kSRLwid/2.0 + kSRLdst;
954     ypos  = 0.0;
955     zpos  = fgkVrocsm + fgkSMpltT + fgkCraH + fgkCdrH + fgkCamH 
956           - fgkSheight/2.0  
957           + iplan * (fgkCH + fgkVspace);
958     gMC->Gspos("USRL",iplan+1         ,"UTI1", xpos,ypos,zpos,0,"ONLY");
959     gMC->Gspos("USRL",iplan+1+  kNplan,"UTI1",-xpos,ypos,zpos,0,"ONLY");
960   }
961
962   //
963   // The cross bars between the chambers
964   //
965
966   const Float_t kSCBwid  = 1.0;
967   const Float_t kSCBthk  = 2.0;
968   const Float_t kSCHhgt  = 0.3;
969
970   const Int_t   kNparSCB = 3;
971   Float_t parSCB[kNparSCB];
972   parSCB[1] = kSCBwid/2.0;
973   parSCB[2] = fgkCH  /2.0 + fgkVspace/2.0 - kSCHhgt;
974
975   const Int_t   kNparSCI = 3;
976   Float_t parSCI[kNparSCI];
977   parSCI[1] = -1;
978
979   xpos  = 0.0;
980   ypos  = 0.0;
981   zpos  = 0.0;
982   for (iplan = 0; iplan < kNplan; iplan++) {
983
984     // The aluminum of the cross bars
985     parSCB[0] = fCwidth[iplan]/2.0 + kSRLdst/2.0;
986     sprintf(cTagV,"USF%01d",iplan);
987     gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parSCB,kNparSCB);
988
989     // The empty regions in the cross bars
990     Float_t thkSCB = kSCBthk;
991     if (iplan < 2) {
992       thkSCB *= 1.5;
993     }
994     parSCI[2] = parSCB[2] - thkSCB;
995     parSCI[0] = parSCB[0]/4.0 - kSCBthk;
996     sprintf(cTagV,"USI%01d",iplan);
997     gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parSCI,kNparSCI);
998
999     sprintf(cTagV,"USI%01d",iplan);
1000     sprintf(cTagM,"USF%01d",iplan);
1001     ypos  = 0.0;
1002     zpos  = 0.0;
1003     xpos  =   parSCI[0] + thkSCB/2.0;
1004     gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
1005     xpos  = - parSCI[0] - thkSCB/2.0;
1006     gMC->Gspos(cTagV,2,cTagM,xpos,ypos,zpos,0,"ONLY");
1007     xpos  =   3.0 * parSCI[0] + 1.5 * thkSCB;
1008     gMC->Gspos(cTagV,3,cTagM,xpos,ypos,zpos,0,"ONLY");
1009     xpos  = - 3.0 * parSCI[0] - 1.5 * thkSCB;
1010     gMC->Gspos(cTagV,4,cTagM,xpos,ypos,zpos,0,"ONLY");
1011
1012     sprintf(cTagV,"USF%01d",iplan);
1013     xpos  = 0.0;
1014     zpos  = fgkVrocsm + fgkSMpltT + parSCB[2] - fgkSheight/2.0 
1015           + iplan * (fgkCH + fgkVspace);
1016
1017     ypos  =   fgkSlength/2.0 - kSCBwid/2.0;
1018     gMC->Gspos(cTagV,1,"UTI1", xpos,ypos,zpos,0,"ONLY");
1019
1020     ypos  =   fClength[iplan][2]/2.0 + fClength[iplan][1];
1021     gMC->Gspos(cTagV,2,"UTI1", xpos,ypos,zpos,0,"ONLY");
1022
1023     ypos  =   fClength[iplan][2]/2.0;
1024     gMC->Gspos(cTagV,3,"UTI1", xpos,ypos,zpos,0,"ONLY");
1025
1026     ypos  = - fClength[iplan][2]/2.0;
1027     gMC->Gspos(cTagV,4,"UTI1", xpos,ypos,zpos,0,"ONLY");
1028
1029     ypos  = - fClength[iplan][2]/2.0 - fClength[iplan][1];
1030     gMC->Gspos(cTagV,5,"UTI1", xpos,ypos,zpos,0,"ONLY");
1031
1032     ypos  = - fgkSlength/2.0 + kSCBwid/2.0;
1033     gMC->Gspos(cTagV,6,"UTI1", xpos,ypos,zpos,0,"ONLY");
1034
1035   }
1036
1037   //
1038   // The horizontal connections between the cross bars
1039   //
1040
1041   const Int_t   kNparSCH = 3;
1042   Float_t parSCH[kNparSCH];
1043
1044   for (iplan = 1; iplan < kNplan-1; iplan++) {
1045
1046     parSCH[0] = fCwidth[iplan]/2.0;
1047     parSCH[1] = (fClength[iplan+1][2]/2.0 + fClength[iplan+1][1]
1048                - fClength[iplan  ][2]/2.0 - fClength[iplan  ][1])/2.0;
1049     parSCH[2] = kSCHhgt/2.0;
1050
1051     sprintf(cTagV,"USH%01d",iplan);
1052     gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parSCH,kNparSCH);
1053     xpos  = 0.0;
1054     ypos  = fClength[iplan][2]/2.0 + fClength[iplan][1] + parSCH[1];
1055     zpos  = fgkVrocsm + fgkSMpltT - kSCHhgt/2.0 - fgkSheight/2.0 
1056           + (iplan+1) * (fgkCH + fgkVspace);
1057     gMC->Gspos(cTagV,1,"UTI1", xpos,ypos,zpos,0,"ONLY");
1058     ypos  = -ypos;
1059     gMC->Gspos(cTagV,2,"UTI1", xpos,ypos,zpos,0,"ONLY");
1060
1061   }
1062
1063   //
1064   // The long corner ledges
1065   //
1066
1067   const Int_t   kNparSCL  =  3;
1068   Float_t parSCL[kNparSCL];
1069   const Int_t   kNparSCLb = 11;
1070   Float_t parSCLb[kNparSCLb];
1071
1072   // Upper ledges 
1073   // Thickness of the corner ledges
1074   const Float_t kSCLthkUa  =  0.6; 
1075   const Float_t kSCLthkUb  =  0.6; 
1076   // Width of the corner ledges
1077   const Float_t kSCLwidUa  =  3.2;
1078   const Float_t kSCLwidUb  =  4.8;
1079   // Position of the corner ledges
1080   const Float_t kSCLposxUa = 0.7;
1081   const Float_t kSCLposxUb = 3.3;
1082   const Float_t kSCLposzUa = 1.6;
1083   const Float_t kSCLposzUb = 0.3;
1084   // Vertical
1085   parSCL[0]  = kSCLthkUa /2.0;
1086   parSCL[1]  = fgkSlength/2.0;
1087   parSCL[2]  = kSCLwidUa /2.0;
1088   gMC->Gsvolu("USL1","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1089   xpos  =   fgkSwidth2/2.0 - fgkSMpltT - kSCLposxUa;
1090   ypos  =   0.0;
1091   zpos  =   fgkSheight/2.0 - fgkSMpltT - kSCLposzUa;
1092   gMC->Gspos("USL1",1,"UTI1", xpos,ypos,zpos,matrix[0],"ONLY");
1093   xpos  = -xpos;
1094   gMC->Gspos("USL1",2,"UTI1", xpos,ypos,zpos,matrix[1],"ONLY");
1095   // Horizontal
1096   parSCL[0]  = kSCLwidUb /2.0;
1097   parSCL[1]  = fgkSlength/2.0;
1098   parSCL[2]  = kSCLthkUb /2.0;
1099   gMC->Gsvolu("USL2","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1100   xpos  =   fgkSwidth2/2.0 - fgkSMpltT - kSCLposxUb;
1101   ypos  =   0.0;
1102   zpos  =   fgkSheight/2.0 - fgkSMpltT - kSCLposzUb; 
1103   gMC->Gspos("USL2",1,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1104   xpos  = -xpos;
1105   gMC->Gspos("USL2",2,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1106
1107   // Lower ledges 
1108   // Thickness of the corner ledges
1109   const Float_t kSCLthkLa  =  2.464; 
1110   const Float_t kSCLthkLb  =  1.0; 
1111   // Width of the corner ledges
1112   const Float_t kSCLwidLa  =  8.5;
1113   const Float_t kSCLwidLb  =  3.3;
1114   // Position of the corner ledges
1115   const Float_t kSCLposxLa =  0.0;
1116   const Float_t kSCLposxLb =  2.6;
1117   const Float_t kSCLposzLa = -4.25;
1118   const Float_t kSCLposzLb = -0.5;
1119   // Vertical
1120   // Trapezoidal shape
1121   parSCLb[ 0] = fgkSlength/2.0;
1122   parSCLb[ 1] = 0.0;
1123   parSCLb[ 2] = 0.0;
1124   parSCLb[ 3] = kSCLwidLa /2.0;
1125   parSCLb[ 4] = kSCLthkLb /2.0;
1126   parSCLb[ 5] = kSCLthkLa /2.0;
1127   parSCLb[ 6] = 5.0;
1128   parSCLb[ 7] = kSCLwidLa /2.0;
1129   parSCLb[ 8] = kSCLthkLb /2.0;
1130   parSCLb[ 9] = kSCLthkLa /2.0;
1131   parSCLb[10] = 5.0;
1132   gMC->Gsvolu("USL3","TRAP",idtmed[1301-1],parSCLb,kNparSCLb);
1133   xpos  =   fgkSwidth1/2.0 - fgkSMpltT - kSCLposxLa;
1134   ypos  =   0.0;
1135   zpos  = - fgkSheight/2.0 + fgkSMpltT - kSCLposzLa;
1136   gMC->Gspos("USL3",1,"UTI1", xpos,ypos,zpos,matrix[2],"ONLY");
1137   xpos  = -xpos;
1138   gMC->Gspos("USL3",2,"UTI1", xpos,ypos,zpos,matrix[3],"ONLY");
1139   // Horizontal
1140   parSCL[0]  = kSCLwidLb /2.0;
1141   parSCL[1]  = fgkSlength/2.0;
1142   parSCL[2]  = kSCLthkLb /2.0;
1143   gMC->Gsvolu("USL4","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1144   xpos  =   fgkSwidth1/2.0 - fgkSMpltT - kSCLposxLb;
1145   ypos  =   0.0;
1146   zpos  = - fgkSheight/2.0 + fgkSMpltT - kSCLposzLb;
1147   gMC->Gspos("USL4",1,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1148   xpos  = -xpos;
1149   gMC->Gspos("USL4",2,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1150
1151 }
1152
1153 //_____________________________________________________________________________
1154 void AliTRDgeometry::CreateServices(Int_t *idtmed)
1155 {
1156   //
1157   // Create the geometry of the services
1158   //
1159   // Names of the TRD services volumina
1160   //
1161   //        UTCL    Cooling arterias (Al)
1162   //        UTCW    Cooling arterias (Water)
1163   //        UUxx    Volumes for the services at the chambers (Air)
1164   //        UTPW    Power bars       (Cu)
1165   //        UTCP    Cooling pipes    (Fe)
1166   //        UTCH    Cooling pipes    (Water)
1167   //        UTPL    Power lines      (Cu)
1168   //        UMCM    Readout MCMs     (G10/Cu/Si)
1169   //
1170
1171   Int_t   iplan = 0;
1172   Int_t   icham = 0;
1173
1174   Float_t xpos  = 0.0;
1175   Float_t ypos  = 0.0;
1176   Float_t zpos  = 0.0;
1177
1178   Char_t  cTagV[5];
1179
1180   // The rotation matrices
1181   const Int_t kNmatrix = 4;
1182   Int_t   matrix[kNmatrix];
1183   gMC->Matrix(matrix[0], 100.0,   0.0,  90.0,  90.0,  10.0,   0.0);
1184   gMC->Matrix(matrix[1],  80.0,   0.0,  90.0,  90.0,  10.0, 180.0);
1185   gMC->Matrix(matrix[2],   0.0,   0.0,  90.0,  90.0,  90.0,   0.0);
1186   gMC->Matrix(matrix[3], 180.0,   0.0,  90.0,  90.0,  90.0, 180.0);
1187     
1188   //
1189   // The cooling arterias
1190   //
1191
1192   // Width of the cooling arterias
1193   const Float_t kCOLwid  =  0.8; 
1194   // Height of the cooling arterias
1195   const Float_t kCOLhgt  =  6.5;
1196   // Positioning of the cooling 
1197   const Float_t kCOLposx =  1.8;
1198   const Float_t kCOLposz = -0.1;
1199   // Thickness of the walls of the cooling arterias
1200   const Float_t kCOLthk  =  0.1;
1201   const Int_t   kNparCOL =  3;
1202   Float_t parCOL[kNparCOL];
1203   parCOL[0]  = kCOLwid   /2.0;
1204   parCOL[1]  = fgkSlength/2.0;
1205   parCOL[2]  = kCOLhgt   /2.0;
1206   gMC->Gsvolu("UTCL","BOX ",idtmed[1308-1],parCOL,kNparCOL);
1207   parCOL[0] -= kCOLthk;
1208   parCOL[1]  = fgkSlength/2.0;
1209   parCOL[2] -= kCOLthk;
1210   gMC->Gsvolu("UTCW","BOX ",idtmed[1314-1],parCOL,kNparCOL);
1211
1212   xpos  = 0.0;
1213   ypos  = 0.0;
1214   zpos  = 0.0;
1215   gMC->Gspos("UTCW",1,"UTCL", xpos,ypos,zpos,0,"ONLY");
1216
1217   for (iplan = 1; iplan < kNplan; iplan++) { 
1218
1219     xpos  = fCwidth[iplan]/2.0 + kCOLwid/2.0 + kCOLposx;
1220     ypos  = 0.0;
1221     zpos  = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1222           + iplan * (fgkCH + fgkVspace);
1223     gMC->Gspos("UTCL",iplan       ,"UTI1", xpos,ypos,zpos,matrix[0],"ONLY");
1224     gMC->Gspos("UTCL",iplan+kNplan,"UTI1",-xpos,ypos,zpos,matrix[1],"ONLY");
1225
1226   }
1227
1228   // The upper most layer (reaching into TOF acceptance)
1229   xpos  = fCwidth[5]/2.0 - kCOLhgt/2.0 - 1.3;
1230   ypos  = 0.0;
1231   zpos  = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1232   gMC->Gspos("UTCL",6       ,"UTI1", xpos,ypos,zpos,matrix[3],"ONLY");
1233   gMC->Gspos("UTCL",6+kNplan,"UTI1",-xpos,ypos,zpos,matrix[3],"ONLY");
1234
1235   //
1236   // The power bars
1237   //
1238
1239   const Float_t kPWRwid  =  0.6;
1240   const Float_t kPWRhgt  =  5.0;
1241   const Float_t kPWRposx =  1.4;
1242   const Float_t kPWRposz =  1.9;
1243   const Int_t   kNparPWR =  3;
1244   Float_t parPWR[kNparPWR];
1245   parPWR[0] = kPWRwid   /2.0;
1246   parPWR[1] = fgkSlength/2.0;
1247   parPWR[2] = kPWRhgt   /2.0;
1248   gMC->Gsvolu("UTPW","BOX ",idtmed[1325-1],parPWR,kNparPWR);
1249   
1250   for (iplan = 1; iplan < kNplan; iplan++) { 
1251     
1252     xpos  = fCwidth[iplan]/2.0 + kPWRwid/2.0 + kPWRposx;
1253     ypos  = 0.0;
1254     zpos  = fgkVrocsm + fgkSMpltT + kPWRhgt/2.0 - fgkSheight/2.0 + kPWRposz 
1255           + iplan * (fgkCH + fgkVspace);
1256     gMC->Gspos("UTPW",iplan       ,"UTI1", xpos,ypos,zpos,matrix[0],"ONLY");
1257     gMC->Gspos("UTPW",iplan+kNplan,"UTI1",-xpos,ypos,zpos,matrix[1],"ONLY");
1258
1259   }
1260
1261   // The upper most layer (reaching into TOF acceptance)
1262   xpos  = fCwidth[5]/2.0 + kPWRhgt/2.0 - 1.3;
1263   ypos  = 0.0;
1264   zpos  = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
1265   gMC->Gspos("UTPW",6       ,"UTI1", xpos,ypos,zpos,matrix[3],"ONLY");
1266   gMC->Gspos("UTPW",6+kNplan,"UTI1",-xpos,ypos,zpos,matrix[3],"ONLY");
1267
1268   //
1269   // The volumes for the services at the chambers
1270   //
1271
1272   const Int_t kNparServ = 3;
1273   Float_t parServ[kNparServ];
1274
1275   for (icham = 0; icham < kNcham; icham++) {
1276     for (iplan = 0; iplan < kNplan; iplan++) {
1277
1278       Int_t iDet = GetDetectorSec(iplan,icham);
1279
1280       sprintf(cTagV,"UU%02d",iDet);
1281       parServ[0] = fCwidth[iplan]        /2.0;
1282       parServ[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
1283       parServ[2] = fgkVspace             /2.0 - 0.742/2.0; 
1284       fChamberUUboxd[iDet][0] = parServ[0];
1285       fChamberUUboxd[iDet][1] = parServ[1];
1286       fChamberUUboxd[iDet][2] = parServ[2];
1287       gMC->Gsvolu(cTagV,"BOX",idtmed[1302-1],parServ,kNparServ);
1288
1289       xpos  = 0.0;
1290       ypos  = fClength[iplan][0] + fClength[iplan][1] + fClength[iplan][2]/2.0;
1291       for (Int_t ic = 0; ic < icham; ic++) {
1292         ypos -= fClength[iplan][ic];
1293       }
1294       ypos -= fClength[iplan][icham]/2.0;
1295       zpos  = fgkVrocsm + fgkSMpltT + fgkCH + fgkVspace/2.0 - fgkSheight/2.0
1296             + iplan * (fgkCH + fgkVspace);
1297       zpos -= 0.742/2.0;
1298       fChamberUUorig[iDet][0] = xpos;
1299       fChamberUUorig[iDet][1] = ypos;
1300       fChamberUUorig[iDet][2] = zpos;
1301
1302     }
1303   }
1304
1305   //
1306   // The cooling pipes inside the service volumes
1307   //
1308
1309   const Int_t kNparTube = 3;
1310   Float_t parTube[kNparTube];
1311   // The cooling pipes
1312   parTube[0] = 0.0;
1313   parTube[1] = 0.0;
1314   parTube[2] = 0.0;
1315   gMC->Gsvolu("UTCP","TUBE",idtmed[1324-1],parTube,0);
1316   // The cooling water
1317   parTube[0] =  0.0;
1318   parTube[1] =  0.2/2.0;
1319   parTube[2] =  fCwidth[iplan]/2.0;
1320   gMC->Gsvolu("UTCH","TUBE",idtmed[1314-1],parTube,kNparTube);
1321   // Water inside the cooling pipe
1322   xpos = 0.0;
1323   ypos = 0.0;
1324   zpos = 0.0;
1325   gMC->Gspos("UTCH",1,"UTCP",xpos,ypos,zpos,0,"ONLY");
1326
1327   // Position the cooling pipes in the mother volume
1328   const Int_t kNpar = 3;
1329   Float_t par[kNpar];
1330   for (icham = 0; icham < kNcham;   icham++) {
1331     for (iplan = 0; iplan < kNplan; iplan++) {
1332       Int_t   iDet    = GetDetectorSec(iplan,icham);
1333       Int_t   iCopy   = GetDetector(iplan,icham,0) * 100;
1334       Int_t   nMCMrow = GetRowMax(iplan,icham,0);
1335       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
1336                       / ((Float_t) nMCMrow);
1337       sprintf(cTagV,"UU%02d",iDet);
1338       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
1339         xpos   = 0.0;
1340         ypos   = (0.5 + iMCMrow) * ySize - 1.9 
1341                - fClength[iplan][icham]/2.0 + fgkHspace/2.0;
1342         zpos   = 0.0 + 0.742/2.0;                 
1343         par[0] = 0.0;
1344         par[1] = 0.3/2.0; // Thickness of the cooling pipes
1345         par[2] = fCwidth[iplan]/2.0;
1346         gMC->Gsposp("UTCP",iCopy+iMCMrow,cTagV,xpos,ypos,zpos
1347                           ,matrix[2],"ONLY",par,kNpar);
1348       }
1349     }
1350   }
1351
1352   //
1353   // The power lines
1354   //
1355
1356   // The copper power lines
1357   parTube[0] = 0.0;
1358   parTube[1] = 0.0;
1359   parTube[2] = 0.0;
1360   gMC->Gsvolu("UTPL","TUBE",idtmed[1305-1],parTube,0);
1361
1362   // Position the power lines in the mother volume
1363   for (icham = 0; icham < kNcham;   icham++) {
1364     for (iplan = 0; iplan < kNplan; iplan++) {
1365       Int_t   iDet    = GetDetectorSec(iplan,icham);
1366       Int_t   iCopy   = GetDetector(iplan,icham,0) * 100;
1367       Int_t   nMCMrow = GetRowMax(iplan,icham,0);
1368       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
1369                       / ((Float_t) nMCMrow);
1370       sprintf(cTagV,"UU%02d",iDet);
1371       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
1372         xpos   = 0.0;
1373         ypos   = (0.5 + iMCMrow) * ySize - 1.0 
1374                - fClength[iplan][icham]/2.0 + fgkHspace/2.0;
1375         zpos   = -0.4 + 0.742/2.0;
1376         par[0] = 0.0;
1377         par[1] = 0.2/2.0; // Thickness of the power lines
1378         par[2] = fCwidth[iplan]/2.0;
1379         gMC->Gsposp("UTPL",iCopy+iMCMrow,cTagV,xpos,ypos,zpos
1380                           ,matrix[2],"ONLY",par,kNpar);
1381       }
1382     }
1383   }
1384
1385   //
1386   // The MCMs
1387   //
1388
1389   const Float_t kMCMx    = 3.0;
1390   const Float_t kMCMy    = 3.0;
1391   const Float_t kMCMz    = 0.3;
1392   
1393   const Float_t kMCMpcTh = 0.1;
1394   const Float_t kMCMcuTh = 0.0025;
1395   const Float_t kMCMsiTh = 0.03;
1396   const Float_t kMCMcoTh = 0.04;
1397
1398   // The mother volume for the MCMs (air)
1399   const Int_t kNparMCM = 3;
1400   Float_t parMCM[kNparMCM];
1401   parMCM[0] = kMCMx   /2.0;
1402   parMCM[1] = kMCMy   /2.0;
1403   parMCM[2] = kMCMz   /2.0;
1404   gMC->Gsvolu("UMCM","BOX",idtmed[1302-1],parMCM,kNparMCM);
1405
1406   // The MCM carrier G10 layer
1407   parMCM[0] = kMCMx   /2.0;
1408   parMCM[1] = kMCMy   /2.0;
1409   parMCM[2] = kMCMpcTh/2.0;
1410   gMC->Gsvolu("UMC1","BOX",idtmed[1319-1],parMCM,kNparMCM);
1411   // The MCM carrier Cu layer
1412   parMCM[0] = kMCMx   /2.0;
1413   parMCM[1] = kMCMy   /2.0;
1414   parMCM[2] = kMCMcuTh/2.0;
1415   gMC->Gsvolu("UMC2","BOX",idtmed[1318-1],parMCM,kNparMCM);
1416   // The silicon of the chips
1417   parMCM[0] = kMCMx   /2.0;
1418   parMCM[1] = kMCMy   /2.0;
1419   parMCM[2] = kMCMsiTh/2.0;
1420   gMC->Gsvolu("UMC3","BOX",idtmed[1320-1],parMCM,kNparMCM);
1421   // The aluminum of the cooling plates
1422   parMCM[0] = kMCMx   /2.0;
1423   parMCM[1] = kMCMy   /2.0;
1424   parMCM[2] = kMCMcoTh/2.0;
1425   gMC->Gsvolu("UMC4","BOX",idtmed[1324-1],parMCM,kNparMCM);
1426
1427   // Put the MCM material inside the MCM mother volume
1428   xpos  =  0.0;
1429   ypos  =  0.0;
1430   zpos  = -kMCMz   /2.0 + kMCMpcTh/2.0;
1431   gMC->Gspos("UMC1",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
1432   zpos +=  kMCMpcTh/2.0 + kMCMcuTh/2.0;
1433   gMC->Gspos("UMC2",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
1434   zpos +=  kMCMcuTh/2.0 + kMCMsiTh/2.0;
1435   gMC->Gspos("UMC3",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
1436   zpos +=  kMCMsiTh/2.0 + kMCMcoTh/2.0;
1437   gMC->Gspos("UMC4",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
1438
1439   // Position the MCMs in the mother volume
1440   for (icham = 0; icham < kNcham;   icham++) {
1441     for (iplan = 0; iplan < kNplan; iplan++) {
1442       Int_t   iDet    = GetDetectorSec(iplan,icham);
1443       Int_t   iCopy   = GetDetector(iplan,icham,0) * 1000;
1444       Int_t   nMCMrow = GetRowMax(iplan,icham,0);
1445       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
1446                       / ((Float_t) nMCMrow);
1447       Int_t   nMCMcol = 8;
1448       Float_t xSize   = (GetChamberWidth(iplan)        - 2.0*fgkCpadW)
1449                       / ((Float_t) nMCMcol);
1450       sprintf(cTagV,"UU%02d",iDet);
1451       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
1452         for (Int_t iMCMcol = 0; iMCMcol < nMCMcol; iMCMcol++) {
1453           xpos   = (0.5 + iMCMcol) * xSize + 1.0 
1454                  - fCwidth[iplan]/2.0;
1455           ypos   = (0.5 + iMCMrow) * ySize + 1.0 
1456                  - fClength[iplan][icham]/2.0 + fgkHspace/2.0;
1457           zpos   = -0.4 + 0.742/2.0;
1458           par[0] = 0.0;
1459           par[1] = 0.2/2.0; // Thickness of the power lines
1460           par[2] = fCwidth[iplan]/2.0;
1461           gMC->Gspos("UMCM",iCopy+iMCMrow*10+iMCMcol,cTagV
1462                            ,xpos,ypos,zpos,0,"ONLY");
1463         }
1464       }
1465
1466     }
1467   }
1468
1469 }
1470
1471 //_____________________________________________________________________________
1472 void AliTRDgeometry::GroupChamber(Int_t iplan, Int_t icham, Int_t *idtmed)
1473 {
1474   //
1475   // Group volumes UA, UD, UF, UU in a single chamber (Air)
1476   // UA, UD, UF, UU are boxes
1477   // UT will be a box
1478   //
1479
1480   const Int_t kNparCha = 3;
1481
1482   Int_t iDet = GetDetectorSec(iplan,icham);
1483
1484   Float_t xyzMin[3];
1485   Float_t xyzMax[3];
1486   Float_t xyzOrig[3];
1487   Float_t xyzBoxd[3];
1488
1489   Char_t  cTagV[5];
1490   Char_t  cTagM[5];
1491
1492   for (Int_t i = 0; i < 3; i++) {
1493     xyzMin[i] = +9999.0; 
1494     xyzMax[i] = -9999.0;
1495   }
1496
1497   for (Int_t i = 0; i < 3; i++) {
1498
1499     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUAorig[iDet][i]-fChamberUAboxd[iDet][i]);
1500     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUAorig[iDet][i]+fChamberUAboxd[iDet][i]);
1501
1502     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUDorig[iDet][i]-fChamberUDboxd[iDet][i]);
1503     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUDorig[iDet][i]+fChamberUDboxd[iDet][i]);
1504
1505     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUForig[iDet][i]-fChamberUFboxd[iDet][i]);
1506     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUForig[iDet][i]+fChamberUFboxd[iDet][i]);
1507
1508     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUUorig[iDet][i]-fChamberUUboxd[iDet][i]);
1509     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUUorig[iDet][i]+fChamberUUboxd[iDet][i]);
1510
1511     xyzOrig[i] = 0.5*(xyzMax[i]+xyzMin[i]);
1512     xyzBoxd[i] = 0.5*(xyzMax[i]-xyzMin[i]);
1513
1514   }
1515   
1516   sprintf(cTagM,"UT%02d",iDet);
1517   gMC->Gsvolu(cTagM,"BOX ",idtmed[1302-1],xyzBoxd,kNparCha);
1518
1519   sprintf(cTagV,"UA%02d",iDet);
1520   gMC->Gspos(cTagV,1,cTagM
1521             ,fChamberUAorig[iDet][0]-xyzOrig[0]
1522             ,fChamberUAorig[iDet][1]-xyzOrig[1]
1523             ,fChamberUAorig[iDet][2]-xyzOrig[2]
1524             ,0,"ONLY");
1525
1526   sprintf(cTagV,"UZ%02d",iDet);
1527   gMC->Gspos(cTagV,1,cTagM
1528             ,fChamberUAorig[iDet][0]-xyzOrig[0] + fChamberUAboxd[iDet][0] - fgkCroW/2.0
1529             ,fChamberUAorig[iDet][1]-xyzOrig[1]
1530             ,fChamberUAorig[iDet][2]-xyzOrig[2] + fgkCraH/2.0 + fgkCdrH/2.0 - fgkCalW/2.0
1531             ,0,"ONLY");
1532   gMC->Gspos(cTagV,2,cTagM
1533             ,fChamberUAorig[iDet][0]-xyzOrig[0] - fChamberUAboxd[iDet][0] + fgkCroW/2.0
1534             ,fChamberUAorig[iDet][1]-xyzOrig[1]
1535             ,fChamberUAorig[iDet][2]-xyzOrig[2] + fgkCraH/2.0 + fgkCdrH/2.0 - fgkCalW/2.0
1536             ,0,"ONLY");
1537
1538   sprintf(cTagV,"UD%02d",iDet);
1539   gMC->Gspos(cTagV,1,cTagM
1540             ,fChamberUDorig[iDet][0]-xyzOrig[0]
1541             ,fChamberUDorig[iDet][1]-xyzOrig[1]
1542             ,fChamberUDorig[iDet][2]-xyzOrig[2]
1543             ,0,"ONLY");
1544
1545   sprintf(cTagV,"UF%02d",iDet);
1546   gMC->Gspos(cTagV,1,cTagM
1547             ,fChamberUForig[iDet][0]-xyzOrig[0]
1548             ,fChamberUForig[iDet][1]-xyzOrig[1]
1549             ,fChamberUForig[iDet][2]-xyzOrig[2]
1550             ,0,"ONLY");
1551   
1552   sprintf(cTagV,"UU%02d",iDet);
1553   gMC->Gspos(cTagV,1,cTagM
1554             ,fChamberUUorig[iDet][0]-xyzOrig[0]
1555             ,fChamberUUorig[iDet][1]-xyzOrig[1]
1556             ,fChamberUUorig[iDet][2]-xyzOrig[2]
1557             ,0,"ONLY");
1558
1559   sprintf(cTagV,"UT%02d",iDet);
1560   gMC->Gspos(cTagV,1,"UTI1"
1561             ,xyzOrig[0]
1562             ,xyzOrig[1]
1563             ,xyzOrig[2]
1564             ,0,"ONLY");
1565
1566 }
1567
1568 //_____________________________________________________________________________
1569 Bool_t AliTRDgeometry::RotateBack(Int_t det, Double_t *loc, Double_t *glb) const
1570 {
1571   //
1572   // Rotates a chambers to transform the corresponding local frame
1573   // coordinates <loc> into the coordinates of the ALICE restframe <glb>.
1574   //
1575
1576   Int_t sector = GetSector(det);
1577
1578   glb[0] = loc[0] * fRotB11[sector] - loc[1] * fRotB12[sector];
1579   glb[1] = loc[0] * fRotB21[sector] + loc[1] * fRotB22[sector];
1580   glb[2] = loc[2];
1581
1582   return kTRUE;
1583
1584 }
1585
1586 //_____________________________________________________________________________
1587 Int_t AliTRDgeometry::GetDetectorSec(Int_t p, Int_t c)
1588 {
1589   //
1590   // Convert plane / chamber into detector number for one single sector
1591   //
1592
1593   return (p + c * fgkNplan);
1594
1595 }
1596
1597 //_____________________________________________________________________________
1598 Int_t AliTRDgeometry::GetDetector(Int_t p, Int_t c, Int_t s)
1599 {
1600   //
1601   // Convert plane / chamber / sector into detector number
1602   //
1603
1604   return (p + c * fgkNplan + s * fgkNplan * fgkNcham);
1605
1606 }
1607
1608 //_____________________________________________________________________________
1609 Int_t AliTRDgeometry::GetPlane(Int_t d)
1610 {
1611   //
1612   // Reconstruct the plane number from the detector number
1613   //
1614
1615   return ((Int_t) (d % fgkNplan));
1616
1617 }
1618
1619 //_____________________________________________________________________________
1620 Int_t AliTRDgeometry::GetChamber(Int_t d) const
1621 {
1622   //
1623   // Reconstruct the chamber number from the detector number
1624   //
1625
1626   return ((Int_t) (d % (fgkNplan * fgkNcham)) / fgkNplan);
1627
1628 }
1629
1630 //_____________________________________________________________________________
1631 Int_t AliTRDgeometry::GetSector(Int_t d) const
1632 {
1633   //
1634   // Reconstruct the sector number from the detector number
1635   //
1636
1637   return ((Int_t) (d / (fgkNplan * fgkNcham)));
1638
1639 }
1640
1641 //_____________________________________________________________________________
1642 AliTRDpadPlane *AliTRDgeometry::GetPadPlane(Int_t p, Int_t c)
1643 {
1644   //
1645   // Returns the pad plane for a given plane <p> and chamber <c> number
1646   //
1647
1648   if (!fPadPlaneArray) {
1649     CreatePadPlaneArray();
1650   }
1651
1652   Int_t ipp = GetDetectorSec(p,c);
1653   return ((AliTRDpadPlane *) fPadPlaneArray->At(ipp));
1654
1655 }
1656
1657 //_____________________________________________________________________________
1658 Int_t AliTRDgeometry::GetRowMax(Int_t p, Int_t c, Int_t /*s*/)
1659 {
1660   //
1661   // Returns the number of rows on the pad plane
1662   //
1663
1664   return GetPadPlane(p,c)->GetNrows();
1665
1666 }
1667
1668 //_____________________________________________________________________________
1669 Int_t AliTRDgeometry::GetColMax(Int_t p)
1670 {
1671   //
1672   // Returns the number of rows on the pad plane
1673   //
1674
1675   return GetPadPlane(p,0)->GetNcols();
1676
1677 }
1678
1679 //_____________________________________________________________________________
1680 Double_t AliTRDgeometry::GetRow0(Int_t p, Int_t c, Int_t /*s*/)
1681 {
1682   //
1683   // Returns the position of the border of the first pad in a row
1684   //
1685
1686   return GetPadPlane(p,c)->GetRow0();
1687
1688 }
1689
1690 //_____________________________________________________________________________
1691 Double_t AliTRDgeometry::GetCol0(Int_t p)
1692 {
1693   //
1694   // Returns the position of the border of the first pad in a column
1695   //
1696
1697   return GetPadPlane(p,0)->GetCol0();
1698
1699 }
1700
1701 //_____________________________________________________________________________
1702 //Int_t AliTRDgeometry::GetPadRowFromMCM(Int_t irob, Int_t imcm) const
1703 //{
1704   //
1705   // Return on which row this mcm sits 
1706   //
1707 //
1708 //  return fgkMCMrow*(irob/2) + imcm/fgkMCMrow;
1709 //
1710 //}
1711
1712 //_____________________________________________________________________________
1713 //Int_t AliTRDgeometry::GetPadColFromADC(Int_t irob, Int_t imcm, Int_t iadc) const
1714 //{
1715   //
1716   // Return which pad is connected to this adc channel. return -1 if it
1717   // is one of the not directly connected adc channels (0, 1 20)
1718   //
1719 //
1720 //  if (iadc < 2 || iadc > 19 ) return -1;
1721 //
1722 //  return (iadc-2) + (imcm%fgkMCMrow)*fgkPadmax + GetRobSide(irob)*fgkColmax/2;
1723 //
1724 //}
1725
1726 //_____________________________________________________________________________
1727 //Int_t AliTRDgeometry::GetMCMfromPad(Int_t irow, Int_t icol) const
1728 //{
1729   //
1730   // Return on which mcm this pad is
1731   //
1732 //
1733 //  if ( irow < 0 || icol < 0 || irow > fgkRowmaxC1 || icol > fgkColmax ) return -1;
1734 //
1735 //  return (icol%(fgkColmax/2))/fgkPadmax + fgkMCMrow*(irow%fgkMCMrow);
1736 //
1737 //}
1738
1739 //_____________________________________________________________________________
1740 //Int_t AliTRDgeometry::GetROBfromPad(Int_t irow, Int_t icol) const
1741 //{
1742   //
1743   // Return on which rob this pad is
1744   //
1745 //
1746 //  return (irow/fgkMCMrow)*2 + GetColSide(icol);
1747 //
1748 //}
1749
1750 //_____________________________________________________________________________
1751 //Int_t AliTRDgeometry::GetRobSide(Int_t irob) const
1752 //{
1753   //
1754   // Return on which side this rob sits (A side = 0, B side = 1)
1755   //
1756 //
1757 //  if ( irob < 0 || irob >= fgkROBmaxC1 ) return -1;
1758 //
1759 //  return irob%2;
1760 //
1761 //}
1762
1763 //_____________________________________________________________________________
1764 //Int_t AliTRDgeometry::GetColSide(Int_t icol) const
1765 //{
1766   //
1767   // Return on which side this column sits (A side = 0, B side = 1)
1768   //
1769 //
1770 //  if ( icol < 0 || icol >= fgkColmax ) return -1;
1771 //
1772 //  return icol/(fgkColmax/2);
1773 //
1774 //}
1775
1776 //_____________________________________________________________________________
1777 Bool_t AliTRDgeometry::ReadGeoMatrices()
1778 {
1779   //
1780   // Read geo matrices from current gGeoManager for each TRD sector
1781   //
1782
1783   if (!gGeoManager) {
1784     return kFALSE;
1785   }
1786
1787   fMatrixArray           = new TObjArray(kNdet); 
1788   fMatrixCorrectionArray = new TObjArray(kNdet);
1789   fMatrixGeo             = new TObjArray(kNdet);
1790   AliAlignObjParams o;
1791
1792   for (Int_t iLayer = AliGeomManager::kTRD1; iLayer <= AliGeomManager::kTRD6; iLayer++) {
1793     for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer); iModule++) {
1794
1795       UShort_t     volid   = AliGeomManager::LayerToVolUID(iLayer,iModule);
1796       const char  *symname = AliGeomManager::SymName(volid);
1797       TGeoPNEntry *pne     = gGeoManager->GetAlignableEntry(symname);
1798       const char  *path    = symname;
1799       if (pne) {
1800         path = pne->GetTitle();
1801       }
1802       if (!gGeoManager->cd(path)) {
1803         return kFALSE;
1804       }
1805       TGeoHMatrix *m         = gGeoManager->GetCurrentMatrix();
1806       Int_t        iLayerTRD = iLayer - AliGeomManager::kTRD1;
1807       Int_t        isector   = iModule/Ncham();
1808       Int_t        ichamber  = iModule%Ncham();
1809       Int_t        lid       = GetDetector(iLayerTRD,ichamber,isector);    
1810
1811       //
1812       // Local geo system z-x-y  to x-y--z 
1813       //
1814       fMatrixGeo->AddAt(new TGeoHMatrix(*m),lid);
1815       
1816       TGeoRotation mchange; 
1817       mchange.RotateY(90); 
1818       mchange.RotateX(90);
1819
1820       TGeoHMatrix gMatrix(mchange.Inverse());
1821       gMatrix.MultiplyLeft(m);
1822       fMatrixArray->AddAt(new TGeoHMatrix(gMatrix),lid); 
1823
1824       //
1825       // Cluster transformation matrix
1826       //
1827       TGeoHMatrix  rotMatrix(mchange.Inverse());
1828       rotMatrix.MultiplyLeft(m);
1829       Double_t sectorAngle = 20.0 * (isector % 18) + 10.0;
1830       TGeoHMatrix  rotSector;
1831       rotSector.RotateZ(sectorAngle);
1832       rotMatrix.MultiplyLeft(&rotSector.Inverse());
1833
1834       fMatrixCorrectionArray->AddAt(new TGeoHMatrix(rotMatrix),lid);       
1835
1836     }    
1837   }
1838
1839   return kTRUE;
1840
1841 }
1842