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