]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDgeometry.cxx
Splitted calibration object -> PARAMETERS FOR CENTRALITY RECONSTRUCTION
[u/mrichter/AliRoot.git] / TRD / AliTRDgeometry.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  TRD geometry class                                                       //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24
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   // There are three TRD volumes for the supermodules in order to accomodate
574   // the different arrangements in front of PHOS
575   // UTR1: Default supermodule
576   // UTR2: Supermodule in front of PHOS with double carbon cover
577   // UTR3: As UTR2, but w/o middle stack
578
579   // The TRD mother volume for one sector (Air), full length in z-direction
580   // Provides material for side plates of super module
581   parTrd[0] = fgkSwidth1/2.0;
582   parTrd[1] = fgkSwidth2/2.0;
583   parTrd[2] = fgkSlength/2.0;
584   parTrd[3] = fgkSheight/2.0;
585   gMC->Gsvolu("UTR1","TRD1",idtmed[1302-1],parTrd,kNparTrd);
586   gMC->Gsvolu("UTR2","TRD1",idtmed[1302-1],parTrd,kNparTrd);
587   gMC->Gsvolu("UTR3","TRD1",idtmed[1302-1],parTrd,kNparTrd);
588
589   // The outer aluminum plates of the super module (Al)
590   parTrd[0] = fgkSwidth1/2.0;
591   parTrd[1] = fgkSwidth2/2.0;
592   parTrd[2] = fgkSlength/2.0;
593   parTrd[3] = fgkSheight/2.0;
594   gMC->Gsvolu("UTS1","TRD1",idtmed[1301-1],parTrd,kNparTrd);
595   gMC->Gsvolu("UTS2","TRD1",idtmed[1301-1],parTrd,kNparTrd);
596   gMC->Gsvolu("UTS3","TRD1",idtmed[1301-1],parTrd,kNparTrd);
597
598   // The inner part of the TRD mother volume for one sector (Air), 
599   // full length in z-direction
600   parTrd[0] = fgkSwidth1/2.0 - fgkSMpltT;
601   parTrd[1] = fgkSwidth2/2.0 - fgkSMpltT;
602   parTrd[2] = fgkSlength/2.0;
603   parTrd[3] = fgkSheight/2.0 - fgkSMpltT;
604   gMC->Gsvolu("UTI1","TRD1",idtmed[1302-1],parTrd,kNparTrd);
605   gMC->Gsvolu("UTI2","TRD1",idtmed[1302-1],parTrd,kNparTrd);
606   gMC->Gsvolu("UTI3","TRD1",idtmed[1302-1],parTrd,kNparTrd);
607
608   for (Int_t icham = 0; icham < kNcham; icham++) {
609     for (Int_t iplan = 0; iplan < kNplan; iplan++) {  
610
611       Int_t iDet = GetDetectorSec(iplan,icham);
612
613       // The lower part of the readout chambers (drift volume + radiator) 
614       // The aluminum frames 
615       sprintf(cTagV,"UA%02d",iDet);
616       parCha[0] = fCwidth[iplan]/2.0;
617       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
618       parCha[2] = fgkCraH/2.0 + fgkCdrH/2.0;
619       fChamberUAboxd[iDet][0] = parCha[0];
620       fChamberUAboxd[iDet][1] = parCha[1];
621       fChamberUAboxd[iDet][2] = parCha[2];
622       gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
623       // The additional aluminum on the frames
624       // This part has not the correct postion but is just supposed to
625       // represent the missing material. The correct from of the L-shaped
626       // profile would not fit into the alignable volume. 
627       sprintf(cTagV,"UZ%02d",iDet);
628       parCha[0] = fgkCroW/2.0;
629       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
630       parCha[2] = fgkCalW/2.0;
631       fChamberUAboxd[iDet][0] = fChamberUAboxd[iDet][0] + fgkCroW;
632       gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
633       // The Wacosit frames 
634       sprintf(cTagV,"UB%02d",iDet);
635       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT; 
636       parCha[1] = -1.0;
637       parCha[2] = -1.0;
638       gMC->Gsvolu(cTagV,"BOX ",idtmed[1307-1],parCha,kNparCha);
639       // The glue around the radiator
640       sprintf(cTagV,"UX%02d",iDet);
641       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT - fgkCclsT; 
642       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCclfT;
643       parCha[2] = fgkCraH/2.0;
644       gMC->Gsvolu(cTagV,"BOX ",idtmed[1311-1],parCha,kNparCha);
645       // The inner part of radiator (air)
646       sprintf(cTagV,"UC%02d",iDet);
647       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT - fgkCclsT - fgkCglT; 
648       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCclfT - fgkCglT;
649       parCha[2] = -1.0;
650       gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
651
652       // The upper part of the readout chambers (amplification volume)
653       // The Wacosit frames
654       sprintf(cTagV,"UD%02d",iDet);
655       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW;
656       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
657       parCha[2] = fgkCamH/2.0;
658       fChamberUDboxd[iDet][0] = parCha[0];
659       fChamberUDboxd[iDet][1] = parCha[1];
660       fChamberUDboxd[iDet][2] = parCha[2];
661       gMC->Gsvolu(cTagV,"BOX ",idtmed[1307-1],parCha,kNparCha);
662       // The inner part of the Wacosit frame (air)
663       sprintf(cTagV,"UE%02d",iDet);
664       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW - fgkCcuT; 
665       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCcuT;
666       parCha[2] = -1.;
667       gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
668
669       // The support structure (pad plane, back panel, readout boards)
670       // The aluminum frames
671       sprintf(cTagV,"UF%02d",iDet);
672       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW;
673       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
674       parCha[2] = fgkCroH/2.0;
675       fChamberUFboxd[iDet][0] = parCha[0];
676       fChamberUFboxd[iDet][1] = parCha[1];
677       fChamberUFboxd[iDet][2] = parCha[2];
678       gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parCha,kNparCha);
679       // The inner part of the aluminum frames
680       sprintf(cTagV,"UG%02d",iDet);
681       parCha[0] = fCwidth[iplan]/2.0 + fgkCroW - fgkCauT; 
682       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCauT;
683       parCha[2] = -1.0;
684       gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parCha,kNparCha);
685
686       // The material layers inside the chambers
687       // Rohacell layer (radiator)
688       parCha[0] = -1.0;
689       parCha[1] = -1.0;
690       parCha[2] = fgkRaThick/2.0;
691       sprintf(cTagV,"UH%02d",iDet);
692       gMC->Gsvolu(cTagV,"BOX ",idtmed[1315-1],parCha,kNparCha);
693       // Xe/Isobutane layer (drift volume) 
694       parCha[0] = fCwidth[iplan]/2.0 - fgkCalT - fgkCclsT;
695       parCha[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0 - fgkCclfT;
696       parCha[2] = fgkDrThick/2.0;
697       sprintf(cTagV,"UJ%02d",iDet);
698       gMC->Gsvolu(cTagV,"BOX ",idtmed[1309-1],parCha,kNparCha);
699       // Xe/Isobutane layer (amplification volume)
700       parCha[0] = -1.0;
701       parCha[1] = -1.0;
702       parCha[2] = fgkAmThick/2.0;
703       sprintf(cTagV,"UK%02d",iDet);
704       gMC->Gsvolu(cTagV,"BOX ",idtmed[1309-1],parCha,kNparCha);  
705       // Cu layer (wire plane)
706       parCha[0] = -1.0;
707       parCha[1] = -1.0;
708       parCha[2] = fgkWrThick/2.0;
709       sprintf(cTagV,"UW%02d",iDet);
710       gMC->Gsvolu(cTagV,"BOX ",idtmed[1303-1],parCha,kNparCha);
711       // Cu layer (pad plane)
712       parCha[0] = -1.0;
713       parCha[1] = -1.0;
714       parCha[2] = fgkCuThick/2.0;
715       sprintf(cTagV,"UL%02d",iDet);
716       gMC->Gsvolu(cTagV,"BOX ",idtmed[1305-1],parCha,kNparCha);
717       // Epoxy layer (glue)
718       parCha[0] = -1.0;
719       parCha[1] = -1.0;
720       parCha[2] = fgkGlThick/2.0;
721       sprintf(cTagV,"UY%02d",iDet);
722       gMC->Gsvolu(cTagV,"BOX ",idtmed[1311-1],parCha,kNparCha);
723       // G10 layer (support structure / honeycomb)
724       parCha[0] = -1.0;
725       parCha[1] = -1.0;
726       parCha[2] = fgkSuThick/2.0;
727       sprintf(cTagV,"UM%02d",iDet);
728       gMC->Gsvolu(cTagV,"BOX ",idtmed[1310-1],parCha,kNparCha);
729       // G10 layer (PCB readout board)
730       parCha[0] = -1.0;
731       parCha[1] = -1.0;
732       parCha[2] = fgkRpThick/2;
733       sprintf(cTagV,"UN%02d",iDet);
734       gMC->Gsvolu(cTagV,"BOX ",idtmed[1313-1],parCha,kNparCha);
735       // Cu layer (traces in readout board)
736       parCha[0] = -1.0;
737       parCha[1] = -1.0;
738       parCha[2] = fgkRcThick/2.0;
739       sprintf(cTagV,"UO%02d",iDet);
740       gMC->Gsvolu(cTagV,"BOX ",idtmed[1306-1],parCha,kNparCha);
741       // Cu layer (other material on in readout board)
742       parCha[0] = -1.0;
743       parCha[1] = -1.0;
744       parCha[2] = fgkRoThick/2.0;
745       sprintf(cTagV,"UV%02d",iDet);
746       gMC->Gsvolu(cTagV,"BOX ",idtmed[1304-1],parCha,kNparCha);
747
748       // Position the layers in the chambers
749       xpos = 0.0;
750       ypos = 0.0;
751       // Lower part
752       // Rohacell layer (radiator)
753       zpos = fgkRaZpos;
754       sprintf(cTagV,"UH%02d",iDet);
755       sprintf(cTagM,"UC%02d",iDet);
756       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
757       // Xe/Isobutane layer (drift volume) 
758       zpos = fgkDrZpos;
759       sprintf(cTagV,"UJ%02d",iDet);
760       sprintf(cTagM,"UB%02d",iDet);
761       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
762       // Upper part
763       // Xe/Isobutane layer (amplification volume)
764       zpos = fgkAmZpos;
765       sprintf(cTagV,"UK%02d",iDet);
766       sprintf(cTagM,"UE%02d",iDet);
767       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
768       // Cu layer (wire plane inside amplification volume)
769       zpos = fgkWrZpos; 
770       sprintf(cTagV,"UW%02d",iDet);
771       sprintf(cTagM,"UK%02d",iDet);
772       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
773       // Readout part + support plane
774       // Cu layer (pad plane)
775       zpos = fgkCuZpos; 
776       sprintf(cTagV,"UL%02d",iDet);
777       sprintf(cTagM,"UG%02d",iDet);
778       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
779       // Epoxy layer (glue)
780       zpos = fgkGlZpos; 
781       sprintf(cTagV,"UY%02d",iDet);
782       sprintf(cTagM,"UG%02d",iDet);
783       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
784       // G10 layer (support structure)
785       zpos = fgkSuZpos;
786       sprintf(cTagV,"UM%02d",iDet);
787       sprintf(cTagM,"UG%02d",iDet);
788       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
789       // G10 layer (PCB readout board)
790       zpos = fgkRpZpos;
791       sprintf(cTagV,"UN%02d",iDet);
792       sprintf(cTagM,"UG%02d",iDet);
793       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
794       // Cu layer (traces in readout board)
795       zpos = fgkRcZpos;
796       sprintf(cTagV,"UO%02d",iDet);
797       sprintf(cTagM,"UG%02d",iDet);
798       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
799       // Cu layer (other materials on readout board)
800       zpos = fgkRoZpos;
801       sprintf(cTagV,"UV%02d",iDet);
802       sprintf(cTagM,"UG%02d",iDet);
803       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
804
805       // Position the inner volumes of the chambers in the frames
806       xpos = 0.0;
807       ypos = 0.0;
808       // The inner part of the radiator
809       zpos = 0.0;
810       sprintf(cTagV,"UC%02d",iDet);
811       sprintf(cTagM,"UX%02d",iDet);
812       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
813       // The glue around the radiator
814       zpos = fgkCraH/2.0 - fgkCdrH/2.0 - fgkCraH/2.0;
815       sprintf(cTagV,"UX%02d",iDet);
816       sprintf(cTagM,"UB%02d",iDet);
817       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
818       // The lower Wacosit frame inside the aluminum frame
819       zpos = 0.0;
820       sprintf(cTagV,"UB%02d",iDet);
821       sprintf(cTagM,"UA%02d",iDet);
822       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
823       // The inside of the upper Wacosit frame
824       zpos = 0.0;
825       sprintf(cTagV,"UE%02d",iDet);
826       sprintf(cTagM,"UD%02d",iDet);
827       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
828       // The inside of the upper aluminum frame
829       zpos = 0.0;
830       sprintf(cTagV,"UG%02d",iDet);
831       sprintf(cTagM,"UF%02d",iDet);
832       gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");      
833
834       // Position the frames of the chambers in the TRD mother volume
835       xpos  = 0.0;
836       ypos  = fClength[iplan][0] + fClength[iplan][1] + fClength[iplan][2]/2.0;
837       for (Int_t ic = 0; ic < icham; ic++) {
838         ypos -= fClength[iplan][ic];
839       }
840       ypos -= fClength[iplan][icham]/2.0;
841       zpos  = fgkVrocsm + fgkSMpltT + fgkCraH/2.0 + fgkCdrH/2.0 - fgkSheight/2.0
842             + iplan * (fgkCH + fgkVspace);
843       // The lower aluminum frame, radiator + drift region
844       sprintf(cTagV,"UA%02d",iDet);      
845       fChamberUAorig[iDet][0] = xpos;
846       fChamberUAorig[iDet][1] = ypos;
847       fChamberUAorig[iDet][2] = zpos;
848       // The upper G10 frame, amplification region
849       sprintf(cTagV,"UD%02d",iDet);
850       zpos += fgkCamH/2.0 + fgkCraH/2.0 + fgkCdrH/2.0;      
851       fChamberUDorig[iDet][0] = xpos;
852       fChamberUDorig[iDet][1] = ypos;
853       fChamberUDorig[iDet][2] = zpos;
854       // The upper aluminum frame
855       sprintf(cTagV,"UF%02d",iDet);
856       zpos += fgkCroH/2.0 + fgkCamH/2.0;      
857       fChamberUForig[iDet][0] = xpos;
858       fChamberUForig[iDet][1] = ypos;
859       fChamberUForig[iDet][2] = zpos;
860
861     }
862   }
863
864   // Create the volumes of the super module frame
865   CreateFrame(idtmed);
866
867   // Create the volumes of the services
868   CreateServices(idtmed);
869   
870   for (Int_t icham = 0; icham < kNcham; icham++) {
871     for (Int_t iplan = 0; iplan < kNplan; iplan++) {  
872       GroupChamber(iplan,icham,idtmed);
873     }
874   }
875   
876   xpos = 0.0;
877   ypos = 0.0;
878   zpos = 0.0;
879   gMC->Gspos("UTI1",1,"UTS1",xpos,ypos,zpos,0,"ONLY");
880   gMC->Gspos("UTI2",1,"UTS2",xpos,ypos,zpos,0,"ONLY");
881   gMC->Gspos("UTI3",1,"UTS3",xpos,ypos,zpos,0,"ONLY");
882
883   xpos = 0.0;
884   ypos = 0.0;
885   zpos = 0.0;
886   gMC->Gspos("UTS1",1,"UTR1",xpos,ypos,zpos,0,"ONLY");
887   gMC->Gspos("UTS2",1,"UTR2",xpos,ypos,zpos,0,"ONLY");
888   gMC->Gspos("UTS3",1,"UTR3",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       switch (isect) {
899       case 13:
900       case 14:
901       case 15:
902         // Double carbon, w/o middle stack
903         gMC->Gspos("UTR3",1,cTagV,xpos,ypos,zpos,0,"ONLY");
904         break;
905       case 11:
906       case 12:
907         // Double carbon, all stacks
908         gMC->Gspos("UTR2",1,cTagV,xpos,ypos,zpos,0,"ONLY");
909         break;
910       default:
911         // Standard supermodule
912         gMC->Gspos("UTR1",1,cTagV,xpos,ypos,zpos,0,"ONLY");
913       };
914     }
915   }
916
917 }
918
919 //_____________________________________________________________________________
920 void AliTRDgeometry::CreateFrame(Int_t *idtmed)
921 {
922   //
923   // Create the geometry of the frame of the supermodule
924   //
925   // Names of the TRD services volumina
926   //
927   //        USRL    Support rails for the chambers (Al)
928   //        USxx    Support cross bars between the chambers (Al)
929   //        USHx    Horizontal connection between the cross bars (Al)
930   //        USLx    Long corner ledges (Al)
931   //
932
933   Int_t   iplan = 0;
934
935   Float_t xpos  = 0.0;
936   Float_t ypos  = 0.0;
937   Float_t zpos  = 0.0;
938
939   Char_t  cTagV[5];
940   Char_t  cTagM[5];
941
942   // The rotation matrices
943   const Int_t kNmatrix = 4;
944   Int_t   matrix[kNmatrix];
945   gMC->Matrix(matrix[0], 100.0,   0.0,  90.0,  90.0,  10.0,   0.0);
946   gMC->Matrix(matrix[1],  80.0,   0.0,  90.0,  90.0,  10.0, 180.0);
947   gMC->Matrix(matrix[2],  90.0,   0.0,   0.0,   0.0,  90.0,  90.0);
948   gMC->Matrix(matrix[3],  90.0, 180.0,   0.0, 180.0,  90.0,  90.0);
949
950   //
951   // The chamber support rails
952   //
953
954   const Float_t kSRLwid  = 2.00;
955   const Float_t kSRLhgt  = 2.3;
956   const Float_t kSRLdst  = 1.0;
957   const Int_t   kNparSRL = 3;
958   Float_t parSRL[kNparSRL];
959   parSRL[0] = kSRLwid   /2.0;
960   parSRL[1] = fgkSlength/2.0;
961   parSRL[2] = kSRLhgt   /2.0;
962   gMC->Gsvolu("USRL","BOX ",idtmed[1301-1],parSRL,kNparSRL);
963
964   xpos  = 0.0;
965   ypos  = 0.0;
966   zpos  = 0.0;
967   for (iplan = 0; iplan < kNplan; iplan++) {
968     xpos  = fCwidth[iplan]/2.0 + kSRLwid/2.0 + kSRLdst;
969     ypos  = 0.0;
970     zpos  = fgkVrocsm + fgkSMpltT + fgkCraH + fgkCdrH + fgkCamH 
971           - fgkSheight/2.0  
972           + iplan * (fgkCH + fgkVspace);
973     gMC->Gspos("USRL",iplan+1         ,"UTI1", xpos,ypos,zpos,0,"ONLY");
974     gMC->Gspos("USRL",iplan+1+  kNplan,"UTI1",-xpos,ypos,zpos,0,"ONLY");
975   }
976
977   //
978   // The cross bars between the chambers
979   //
980
981   const Float_t kSCBwid  = 1.0;
982   const Float_t kSCBthk  = 2.0;
983   const Float_t kSCHhgt  = 0.3;
984
985   const Int_t   kNparSCB = 3;
986   Float_t parSCB[kNparSCB];
987   parSCB[1] = kSCBwid/2.0;
988   parSCB[2] = fgkCH  /2.0 + fgkVspace/2.0 - kSCHhgt;
989
990   const Int_t   kNparSCI = 3;
991   Float_t parSCI[kNparSCI];
992   parSCI[1] = -1;
993
994   xpos  = 0.0;
995   ypos  = 0.0;
996   zpos  = 0.0;
997   for (iplan = 0; iplan < kNplan; iplan++) {
998
999     // The aluminum of the cross bars
1000     parSCB[0] = fCwidth[iplan]/2.0 + kSRLdst/2.0;
1001     sprintf(cTagV,"USF%01d",iplan);
1002     gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parSCB,kNparSCB);
1003
1004     // The empty regions in the cross bars
1005     Float_t thkSCB = kSCBthk;
1006     if (iplan < 2) {
1007       thkSCB *= 1.5;
1008     }
1009     parSCI[2] = parSCB[2] - thkSCB;
1010     parSCI[0] = parSCB[0]/4.0 - kSCBthk;
1011     sprintf(cTagV,"USI%01d",iplan);
1012     gMC->Gsvolu(cTagV,"BOX ",idtmed[1302-1],parSCI,kNparSCI);
1013
1014     sprintf(cTagV,"USI%01d",iplan);
1015     sprintf(cTagM,"USF%01d",iplan);
1016     ypos  = 0.0;
1017     zpos  = 0.0;
1018     xpos  =   parSCI[0] + thkSCB/2.0;
1019     gMC->Gspos(cTagV,1,cTagM,xpos,ypos,zpos,0,"ONLY");
1020     xpos  = - parSCI[0] - thkSCB/2.0;
1021     gMC->Gspos(cTagV,2,cTagM,xpos,ypos,zpos,0,"ONLY");
1022     xpos  =   3.0 * parSCI[0] + 1.5 * thkSCB;
1023     gMC->Gspos(cTagV,3,cTagM,xpos,ypos,zpos,0,"ONLY");
1024     xpos  = - 3.0 * parSCI[0] - 1.5 * thkSCB;
1025     gMC->Gspos(cTagV,4,cTagM,xpos,ypos,zpos,0,"ONLY");
1026
1027     sprintf(cTagV,"USF%01d",iplan);
1028     xpos  = 0.0;
1029     zpos  = fgkVrocsm + fgkSMpltT + parSCB[2] - fgkSheight/2.0 
1030           + iplan * (fgkCH + fgkVspace);
1031
1032     ypos  =   fgkSlength/2.0 - kSCBwid/2.0;
1033     gMC->Gspos(cTagV,1,"UTI1", xpos,ypos,zpos,0,"ONLY");
1034
1035     ypos  =   fClength[iplan][2]/2.0 + fClength[iplan][1];
1036     gMC->Gspos(cTagV,2,"UTI1", xpos,ypos,zpos,0,"ONLY");
1037
1038     ypos  =   fClength[iplan][2]/2.0;
1039     gMC->Gspos(cTagV,3,"UTI1", xpos,ypos,zpos,0,"ONLY");
1040
1041     ypos  = - fClength[iplan][2]/2.0;
1042     gMC->Gspos(cTagV,4,"UTI1", xpos,ypos,zpos,0,"ONLY");
1043
1044     ypos  = - fClength[iplan][2]/2.0 - fClength[iplan][1];
1045     gMC->Gspos(cTagV,5,"UTI1", xpos,ypos,zpos,0,"ONLY");
1046
1047     ypos  = - fgkSlength/2.0 + kSCBwid/2.0;
1048     gMC->Gspos(cTagV,6,"UTI1", xpos,ypos,zpos,0,"ONLY");
1049
1050   }
1051
1052   //
1053   // The horizontal connections between the cross bars
1054   //
1055
1056   const Int_t   kNparSCH = 3;
1057   Float_t parSCH[kNparSCH];
1058
1059   for (iplan = 1; iplan < kNplan-1; iplan++) {
1060
1061     parSCH[0] = fCwidth[iplan]/2.0;
1062     parSCH[1] = (fClength[iplan+1][2]/2.0 + fClength[iplan+1][1]
1063                - fClength[iplan  ][2]/2.0 - fClength[iplan  ][1])/2.0;
1064     parSCH[2] = kSCHhgt/2.0;
1065
1066     sprintf(cTagV,"USH%01d",iplan);
1067     gMC->Gsvolu(cTagV,"BOX ",idtmed[1301-1],parSCH,kNparSCH);
1068     xpos  = 0.0;
1069     ypos  = fClength[iplan][2]/2.0 + fClength[iplan][1] + parSCH[1];
1070     zpos  = fgkVrocsm + fgkSMpltT - kSCHhgt/2.0 - fgkSheight/2.0 
1071           + (iplan+1) * (fgkCH + fgkVspace);
1072     gMC->Gspos(cTagV,1,"UTI1", xpos,ypos,zpos,0,"ONLY");
1073     ypos  = -ypos;
1074     gMC->Gspos(cTagV,2,"UTI1", xpos,ypos,zpos,0,"ONLY");
1075
1076   }
1077
1078   //
1079   // The long corner ledges
1080   //
1081
1082   const Int_t   kNparSCL  =  3;
1083   Float_t parSCL[kNparSCL];
1084   const Int_t   kNparSCLb = 11;
1085   Float_t parSCLb[kNparSCLb];
1086
1087   // Upper ledges 
1088   // Thickness of the corner ledges
1089   const Float_t kSCLthkUa  =  0.6; 
1090   const Float_t kSCLthkUb  =  0.6; 
1091   // Width of the corner ledges
1092   const Float_t kSCLwidUa  =  3.2;
1093   const Float_t kSCLwidUb  =  4.8;
1094   // Position of the corner ledges
1095   const Float_t kSCLposxUa = 0.7;
1096   const Float_t kSCLposxUb = 3.3;
1097   const Float_t kSCLposzUa = 1.6;
1098   const Float_t kSCLposzUb = 0.3;
1099   // Vertical
1100   parSCL[0]  = kSCLthkUa /2.0;
1101   parSCL[1]  = fgkSlength/2.0;
1102   parSCL[2]  = kSCLwidUa /2.0;
1103   gMC->Gsvolu("USL1","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1104   xpos  =   fgkSwidth2/2.0 - fgkSMpltT - kSCLposxUa;
1105   ypos  =   0.0;
1106   zpos  =   fgkSheight/2.0 - fgkSMpltT - kSCLposzUa;
1107   gMC->Gspos("USL1",1,"UTI1", xpos,ypos,zpos,matrix[0],"ONLY");
1108   xpos  = -xpos;
1109   gMC->Gspos("USL1",2,"UTI1", xpos,ypos,zpos,matrix[1],"ONLY");
1110   // Horizontal
1111   parSCL[0]  = kSCLwidUb /2.0;
1112   parSCL[1]  = fgkSlength/2.0;
1113   parSCL[2]  = kSCLthkUb /2.0;
1114   gMC->Gsvolu("USL2","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1115   xpos  =   fgkSwidth2/2.0 - fgkSMpltT - kSCLposxUb;
1116   ypos  =   0.0;
1117   zpos  =   fgkSheight/2.0 - fgkSMpltT - kSCLposzUb; 
1118   gMC->Gspos("USL2",1,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1119   xpos  = -xpos;
1120   gMC->Gspos("USL2",2,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1121
1122   // Lower ledges 
1123   // Thickness of the corner ledges
1124   const Float_t kSCLthkLa  =  2.464; 
1125   const Float_t kSCLthkLb  =  1.0; 
1126   // Width of the corner ledges
1127   const Float_t kSCLwidLa  =  8.5;
1128   const Float_t kSCLwidLb  =  3.3;
1129   // Position of the corner ledges
1130   const Float_t kSCLposxLa =  0.0;
1131   const Float_t kSCLposxLb =  2.6;
1132   const Float_t kSCLposzLa = -4.25;
1133   const Float_t kSCLposzLb = -0.5;
1134   // Vertical
1135   // Trapezoidal shape
1136   parSCLb[ 0] = fgkSlength/2.0;
1137   parSCLb[ 1] = 0.0;
1138   parSCLb[ 2] = 0.0;
1139   parSCLb[ 3] = kSCLwidLa /2.0;
1140   parSCLb[ 4] = kSCLthkLb /2.0;
1141   parSCLb[ 5] = kSCLthkLa /2.0;
1142   parSCLb[ 6] = 5.0;
1143   parSCLb[ 7] = kSCLwidLa /2.0;
1144   parSCLb[ 8] = kSCLthkLb /2.0;
1145   parSCLb[ 9] = kSCLthkLa /2.0;
1146   parSCLb[10] = 5.0;
1147   gMC->Gsvolu("USL3","TRAP",idtmed[1301-1],parSCLb,kNparSCLb);
1148   xpos  =   fgkSwidth1/2.0 - fgkSMpltT - kSCLposxLa;
1149   ypos  =   0.0;
1150   zpos  = - fgkSheight/2.0 + fgkSMpltT - kSCLposzLa;
1151   gMC->Gspos("USL3",1,"UTI1", xpos,ypos,zpos,matrix[2],"ONLY");
1152   xpos  = -xpos;
1153   gMC->Gspos("USL3",2,"UTI1", xpos,ypos,zpos,matrix[3],"ONLY");
1154   // Horizontal
1155   parSCL[0]  = kSCLwidLb /2.0;
1156   parSCL[1]  = fgkSlength/2.0;
1157   parSCL[2]  = kSCLthkLb /2.0;
1158   gMC->Gsvolu("USL4","BOX ",idtmed[1301-1],parSCL,kNparSCL);
1159   xpos  =   fgkSwidth1/2.0 - fgkSMpltT - kSCLposxLb;
1160   ypos  =   0.0;
1161   zpos  = - fgkSheight/2.0 + fgkSMpltT - kSCLposzLb;
1162   gMC->Gspos("USL4",1,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1163   xpos  = -xpos;
1164   gMC->Gspos("USL4",2,"UTI1", xpos,ypos,zpos,        0,"ONLY");
1165
1166 }
1167
1168 //_____________________________________________________________________________
1169 void AliTRDgeometry::CreateServices(Int_t *idtmed)
1170 {
1171   //
1172   // Create the geometry of the services
1173   //
1174   // Names of the TRD services volumina
1175   //
1176   //        UTCL    Cooling arterias (Al)
1177   //        UTCW    Cooling arterias (Water)
1178   //        UUxx    Volumes for the services at the chambers (Air)
1179   //        UTPW    Power bars       (Cu)
1180   //        UTCP    Cooling pipes    (Fe)
1181   //        UTCH    Cooling pipes    (Water)
1182   //        UTPL    Power lines      (Cu)
1183   //        UMCM    Readout MCMs     (G10/Cu/Si)
1184   //
1185
1186   Int_t   iplan = 0;
1187   Int_t   icham = 0;
1188
1189   Float_t xpos  = 0.0;
1190   Float_t ypos  = 0.0;
1191   Float_t zpos  = 0.0;
1192
1193   Char_t  cTagV[5];
1194
1195   // The rotation matrices
1196   const Int_t kNmatrix = 4;
1197   Int_t   matrix[kNmatrix];
1198   gMC->Matrix(matrix[0], 100.0,   0.0,  90.0,  90.0,  10.0,   0.0);
1199   gMC->Matrix(matrix[1],  80.0,   0.0,  90.0,  90.0,  10.0, 180.0);
1200   gMC->Matrix(matrix[2],   0.0,   0.0,  90.0,  90.0,  90.0,   0.0);
1201   gMC->Matrix(matrix[3], 180.0,   0.0,  90.0,  90.0,  90.0, 180.0);
1202     
1203   //
1204   // The cooling arterias
1205   //
1206
1207   // Width of the cooling arterias
1208   const Float_t kCOLwid  =  0.8; 
1209   // Height of the cooling arterias
1210   const Float_t kCOLhgt  =  6.5;
1211   // Positioning of the cooling 
1212   const Float_t kCOLposx =  1.8;
1213   const Float_t kCOLposz = -0.1;
1214   // Thickness of the walls of the cooling arterias
1215   const Float_t kCOLthk  =  0.1;
1216   const Int_t   kNparCOL =  3;
1217   Float_t parCOL[kNparCOL];
1218   parCOL[0]  = kCOLwid   /2.0;
1219   parCOL[1]  = fgkSlength/2.0;
1220   parCOL[2]  = kCOLhgt   /2.0;
1221   gMC->Gsvolu("UTCL","BOX ",idtmed[1308-1],parCOL,kNparCOL);
1222   parCOL[0] -= kCOLthk;
1223   parCOL[1]  = fgkSlength/2.0;
1224   parCOL[2] -= kCOLthk;
1225   gMC->Gsvolu("UTCW","BOX ",idtmed[1314-1],parCOL,kNparCOL);
1226
1227   xpos  = 0.0;
1228   ypos  = 0.0;
1229   zpos  = 0.0;
1230   gMC->Gspos("UTCW",1,"UTCL", xpos,ypos,zpos,0,"ONLY");
1231
1232   for (iplan = 1; iplan < kNplan; iplan++) { 
1233
1234     xpos  = fCwidth[iplan]/2.0 + kCOLwid/2.0 + kCOLposx;
1235     ypos  = 0.0;
1236     zpos  = fgkVrocsm + fgkSMpltT + kCOLhgt/2.0 - fgkSheight/2.0 + kCOLposz 
1237           + iplan * (fgkCH + fgkVspace);
1238     gMC->Gspos("UTCL",iplan       ,"UTI1", xpos,ypos,zpos,matrix[0],"ONLY");
1239     gMC->Gspos("UTCL",iplan+kNplan,"UTI1",-xpos,ypos,zpos,matrix[1],"ONLY");
1240
1241   }
1242
1243   // The upper most layer (reaching into TOF acceptance)
1244   xpos  = fCwidth[5]/2.0 - kCOLhgt/2.0 - 1.3;
1245   ypos  = 0.0;
1246   zpos  = fgkSheight/2.0 - fgkSMpltT - 0.4 - kCOLwid/2.0; 
1247   gMC->Gspos("UTCL",6       ,"UTI1", xpos,ypos,zpos,matrix[3],"ONLY");
1248   gMC->Gspos("UTCL",6+kNplan,"UTI1",-xpos,ypos,zpos,matrix[3],"ONLY");
1249
1250   //
1251   // The power bars
1252   //
1253
1254   const Float_t kPWRwid  =  0.6;
1255   const Float_t kPWRhgt  =  5.0;
1256   const Float_t kPWRposx =  1.4;
1257   const Float_t kPWRposz =  1.9;
1258   const Int_t   kNparPWR =  3;
1259   Float_t parPWR[kNparPWR];
1260   parPWR[0] = kPWRwid   /2.0;
1261   parPWR[1] = fgkSlength/2.0;
1262   parPWR[2] = kPWRhgt   /2.0;
1263   gMC->Gsvolu("UTPW","BOX ",idtmed[1325-1],parPWR,kNparPWR);
1264   
1265   for (iplan = 1; iplan < kNplan; iplan++) { 
1266     
1267     xpos  = fCwidth[iplan]/2.0 + kPWRwid/2.0 + kPWRposx;
1268     ypos  = 0.0;
1269     zpos  = fgkVrocsm + fgkSMpltT + kPWRhgt/2.0 - fgkSheight/2.0 + kPWRposz 
1270           + iplan * (fgkCH + fgkVspace);
1271     gMC->Gspos("UTPW",iplan       ,"UTI1", xpos,ypos,zpos,matrix[0],"ONLY");
1272     gMC->Gspos("UTPW",iplan+kNplan,"UTI1",-xpos,ypos,zpos,matrix[1],"ONLY");
1273
1274   }
1275
1276   // The upper most layer (reaching into TOF acceptance)
1277   xpos  = fCwidth[5]/2.0 + kPWRhgt/2.0 - 1.3;
1278   ypos  = 0.0;
1279   zpos  = fgkSheight/2.0 - fgkSMpltT - 0.6 - kPWRwid/2.0; 
1280   gMC->Gspos("UTPW",6       ,"UTI1", xpos,ypos,zpos,matrix[3],"ONLY");
1281   gMC->Gspos("UTPW",6+kNplan,"UTI1",-xpos,ypos,zpos,matrix[3],"ONLY");
1282
1283   //
1284   // The volumes for the services at the chambers
1285   //
1286
1287   const Int_t kNparServ = 3;
1288   Float_t parServ[kNparServ];
1289
1290   for (icham = 0; icham < kNcham; icham++) {
1291     for (iplan = 0; iplan < kNplan; iplan++) {
1292
1293       Int_t iDet = GetDetectorSec(iplan,icham);
1294
1295       sprintf(cTagV,"UU%02d",iDet);
1296       parServ[0] = fCwidth[iplan]        /2.0;
1297       parServ[1] = fClength[iplan][icham]/2.0 - fgkHspace/2.0;
1298       parServ[2] = fgkVspace             /2.0 - 0.742/2.0; 
1299       fChamberUUboxd[iDet][0] = parServ[0];
1300       fChamberUUboxd[iDet][1] = parServ[1];
1301       fChamberUUboxd[iDet][2] = parServ[2];
1302       gMC->Gsvolu(cTagV,"BOX",idtmed[1302-1],parServ,kNparServ);
1303
1304       xpos  = 0.0;
1305       ypos  = fClength[iplan][0] + fClength[iplan][1] + fClength[iplan][2]/2.0;
1306       for (Int_t ic = 0; ic < icham; ic++) {
1307         ypos -= fClength[iplan][ic];
1308       }
1309       ypos -= fClength[iplan][icham]/2.0;
1310       zpos  = fgkVrocsm + fgkSMpltT + fgkCH + fgkVspace/2.0 - fgkSheight/2.0
1311             + iplan * (fgkCH + fgkVspace);
1312       zpos -= 0.742/2.0;
1313       fChamberUUorig[iDet][0] = xpos;
1314       fChamberUUorig[iDet][1] = ypos;
1315       fChamberUUorig[iDet][2] = zpos;
1316
1317     }
1318   }
1319
1320   //
1321   // The cooling pipes inside the service volumes
1322   //
1323
1324   const Int_t kNparTube = 3;
1325   Float_t parTube[kNparTube];
1326   // The cooling pipes
1327   parTube[0] =  0.0;
1328   parTube[1] =  0.0;
1329   parTube[2] =  0.0;
1330   gMC->Gsvolu("UTCP","TUBE",idtmed[1324-1],parTube,0);
1331   // The cooling water
1332   parTube[0] =  0.0;
1333   parTube[1] =  0.2/2.0;
1334   parTube[2] = -1.0;
1335   gMC->Gsvolu("UTCH","TUBE",idtmed[1314-1],parTube,kNparTube);
1336   // Water inside the cooling pipe
1337   xpos = 0.0;
1338   ypos = 0.0;
1339   zpos = 0.0;
1340   gMC->Gspos("UTCH",1,"UTCP",xpos,ypos,zpos,0,"ONLY");
1341
1342   // Position the cooling pipes in the mother volume
1343   const Int_t kNpar = 3;
1344   Float_t par[kNpar];
1345   for (icham = 0; icham < kNcham;   icham++) {
1346     for (iplan = 0; iplan < kNplan; iplan++) {
1347       Int_t   iDet    = GetDetectorSec(iplan,icham);
1348       Int_t   iCopy   = GetDetector(iplan,icham,0) * 100;
1349       Int_t   nMCMrow = GetRowMax(iplan,icham,0);
1350       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
1351                       / ((Float_t) nMCMrow);
1352       sprintf(cTagV,"UU%02d",iDet);
1353       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
1354         xpos   = 0.0;
1355         ypos   = (0.5 + iMCMrow) * ySize - 1.9 
1356                - fClength[iplan][icham]/2.0 + fgkHspace/2.0;
1357         zpos   = 0.0 + 0.742/2.0;                 
1358         // The cooling pipes
1359         par[0] = 0.0;
1360         par[1] = 0.3/2.0; // Thickness of the cooling pipes
1361         par[2] = fCwidth[iplan]/2.0;
1362         gMC->Gsposp("UTCP",iCopy+iMCMrow,cTagV,xpos,ypos,zpos
1363                           ,matrix[2],"ONLY",par,kNpar);
1364       }
1365     }
1366   }
1367
1368   //
1369   // The power lines
1370   //
1371
1372   // The copper power lines
1373   parTube[0] = 0.0;
1374   parTube[1] = 0.0;
1375   parTube[2] = 0.0;
1376   gMC->Gsvolu("UTPL","TUBE",idtmed[1305-1],parTube,0);
1377
1378   // Position the power lines in the mother volume
1379   for (icham = 0; icham < kNcham;   icham++) {
1380     for (iplan = 0; iplan < kNplan; iplan++) {
1381       Int_t   iDet    = GetDetectorSec(iplan,icham);
1382       Int_t   iCopy   = GetDetector(iplan,icham,0) * 100;
1383       Int_t   nMCMrow = GetRowMax(iplan,icham,0);
1384       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
1385                       / ((Float_t) nMCMrow);
1386       sprintf(cTagV,"UU%02d",iDet);
1387       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
1388         xpos   = 0.0;
1389         ypos   = (0.5 + iMCMrow) * ySize - 1.0 
1390                - fClength[iplan][icham]/2.0 + fgkHspace/2.0;
1391         zpos   = -0.4 + 0.742/2.0;
1392         par[0] = 0.0;
1393         par[1] = 0.2/2.0; // Thickness of the power lines
1394         par[2] = fCwidth[iplan]/2.0;
1395         gMC->Gsposp("UTPL",iCopy+iMCMrow,cTagV,xpos,ypos,zpos
1396                           ,matrix[2],"ONLY",par,kNpar);
1397       }
1398     }
1399   }
1400
1401   //
1402   // The MCMs
1403   //
1404
1405   const Float_t kMCMx    = 3.0;
1406   const Float_t kMCMy    = 3.0;
1407   const Float_t kMCMz    = 0.3;
1408   
1409   const Float_t kMCMpcTh = 0.1;
1410   const Float_t kMCMcuTh = 0.0025;
1411   const Float_t kMCMsiTh = 0.03;
1412   const Float_t kMCMcoTh = 0.04;
1413
1414   // The mother volume for the MCMs (air)
1415   const Int_t kNparMCM = 3;
1416   Float_t parMCM[kNparMCM];
1417   parMCM[0] = kMCMx   /2.0;
1418   parMCM[1] = kMCMy   /2.0;
1419   parMCM[2] = kMCMz   /2.0;
1420   gMC->Gsvolu("UMCM","BOX",idtmed[1302-1],parMCM,kNparMCM);
1421
1422   // The MCM carrier G10 layer
1423   parMCM[0] = kMCMx   /2.0;
1424   parMCM[1] = kMCMy   /2.0;
1425   parMCM[2] = kMCMpcTh/2.0;
1426   gMC->Gsvolu("UMC1","BOX",idtmed[1319-1],parMCM,kNparMCM);
1427   // The MCM carrier Cu layer
1428   parMCM[0] = kMCMx   /2.0;
1429   parMCM[1] = kMCMy   /2.0;
1430   parMCM[2] = kMCMcuTh/2.0;
1431   gMC->Gsvolu("UMC2","BOX",idtmed[1318-1],parMCM,kNparMCM);
1432   // The silicon of the chips
1433   parMCM[0] = kMCMx   /2.0;
1434   parMCM[1] = kMCMy   /2.0;
1435   parMCM[2] = kMCMsiTh/2.0;
1436   gMC->Gsvolu("UMC3","BOX",idtmed[1320-1],parMCM,kNparMCM);
1437   // The aluminum of the cooling plates
1438   parMCM[0] = kMCMx   /2.0;
1439   parMCM[1] = kMCMy   /2.0;
1440   parMCM[2] = kMCMcoTh/2.0;
1441   gMC->Gsvolu("UMC4","BOX",idtmed[1324-1],parMCM,kNparMCM);
1442
1443   // Put the MCM material inside the MCM mother volume
1444   xpos  =  0.0;
1445   ypos  =  0.0;
1446   zpos  = -kMCMz   /2.0 + kMCMpcTh/2.0;
1447   gMC->Gspos("UMC1",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
1448   zpos +=  kMCMpcTh/2.0 + kMCMcuTh/2.0;
1449   gMC->Gspos("UMC2",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
1450   zpos +=  kMCMcuTh/2.0 + kMCMsiTh/2.0;
1451   gMC->Gspos("UMC3",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
1452   zpos +=  kMCMsiTh/2.0 + kMCMcoTh/2.0;
1453   gMC->Gspos("UMC4",1,"UMCM",xpos,ypos,zpos,0,"ONLY");
1454
1455   // Position the MCMs in the mother volume
1456   for (icham = 0; icham < kNcham;   icham++) {
1457     for (iplan = 0; iplan < kNplan; iplan++) {
1458       Int_t   iDet    = GetDetectorSec(iplan,icham);
1459       Int_t   iCopy   = GetDetector(iplan,icham,0) * 1000;
1460       Int_t   nMCMrow = GetRowMax(iplan,icham,0);
1461       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
1462                       / ((Float_t) nMCMrow);
1463       Int_t   nMCMcol = 8;
1464       Float_t xSize   = (GetChamberWidth(iplan)        - 2.0*fgkCpadW)
1465                       / ((Float_t) nMCMcol);
1466       sprintf(cTagV,"UU%02d",iDet);
1467       for (Int_t iMCMrow = 0; iMCMrow < nMCMrow; iMCMrow++) {
1468         for (Int_t iMCMcol = 0; iMCMcol < nMCMcol; iMCMcol++) {
1469           xpos   = (0.5 + iMCMcol) * xSize + 1.0 
1470                  - fCwidth[iplan]/2.0;
1471           ypos   = (0.5 + iMCMrow) * ySize + 1.0 
1472                  - fClength[iplan][icham]/2.0 + fgkHspace/2.0;
1473           zpos   = -0.4 + 0.742/2.0;
1474           par[0] = 0.0;
1475           par[1] = 0.2/2.0; // Thickness of the power lines
1476           par[2] = fCwidth[iplan]/2.0;
1477           gMC->Gspos("UMCM",iCopy+iMCMrow*10+iMCMcol,cTagV
1478                            ,xpos,ypos,zpos,0,"ONLY");
1479         }
1480       }
1481
1482     }
1483   }
1484
1485 }
1486
1487 //_____________________________________________________________________________
1488 void AliTRDgeometry::GroupChamber(Int_t iplan, Int_t icham, Int_t *idtmed)
1489 {
1490   //
1491   // Group volumes UA, UD, UF, UU in a single chamber (Air)
1492   // UA, UD, UF, UU are boxes
1493   // UT will be a box
1494   //
1495
1496   const Int_t kNparCha = 3;
1497
1498   Int_t iDet = GetDetectorSec(iplan,icham);
1499
1500   Float_t xyzMin[3];
1501   Float_t xyzMax[3];
1502   Float_t xyzOrig[3];
1503   Float_t xyzBoxd[3];
1504
1505   Char_t  cTagV[5];
1506   Char_t  cTagM[5];
1507
1508   for (Int_t i = 0; i < 3; i++) {
1509     xyzMin[i] = +9999.0; 
1510     xyzMax[i] = -9999.0;
1511   }
1512
1513   for (Int_t i = 0; i < 3; i++) {
1514
1515     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUAorig[iDet][i]-fChamberUAboxd[iDet][i]);
1516     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUAorig[iDet][i]+fChamberUAboxd[iDet][i]);
1517
1518     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUDorig[iDet][i]-fChamberUDboxd[iDet][i]);
1519     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUDorig[iDet][i]+fChamberUDboxd[iDet][i]);
1520
1521     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUForig[iDet][i]-fChamberUFboxd[iDet][i]);
1522     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUForig[iDet][i]+fChamberUFboxd[iDet][i]);
1523
1524     xyzMin[i] = TMath::Min(xyzMin[i],fChamberUUorig[iDet][i]-fChamberUUboxd[iDet][i]);
1525     xyzMax[i] = TMath::Max(xyzMax[i],fChamberUUorig[iDet][i]+fChamberUUboxd[iDet][i]);
1526
1527     xyzOrig[i] = 0.5*(xyzMax[i]+xyzMin[i]);
1528     xyzBoxd[i] = 0.5*(xyzMax[i]-xyzMin[i]);
1529
1530   }
1531   
1532   sprintf(cTagM,"UT%02d",iDet);
1533   gMC->Gsvolu(cTagM,"BOX ",idtmed[1302-1],xyzBoxd,kNparCha);
1534
1535   sprintf(cTagV,"UA%02d",iDet);
1536   gMC->Gspos(cTagV,1,cTagM
1537             ,fChamberUAorig[iDet][0]-xyzOrig[0]
1538             ,fChamberUAorig[iDet][1]-xyzOrig[1]
1539             ,fChamberUAorig[iDet][2]-xyzOrig[2]
1540             ,0,"ONLY");
1541
1542   sprintf(cTagV,"UZ%02d",iDet);
1543   gMC->Gspos(cTagV,1,cTagM
1544             ,fChamberUAorig[iDet][0]-xyzOrig[0] + fChamberUAboxd[iDet][0] - fgkCroW/2.0
1545             ,fChamberUAorig[iDet][1]-xyzOrig[1]
1546             ,fChamberUAorig[iDet][2]-xyzOrig[2] + fgkCraH/2.0 + fgkCdrH/2.0 - fgkCalW/2.0
1547             ,0,"ONLY");
1548   gMC->Gspos(cTagV,2,cTagM
1549             ,fChamberUAorig[iDet][0]-xyzOrig[0] - fChamberUAboxd[iDet][0] + fgkCroW/2.0
1550             ,fChamberUAorig[iDet][1]-xyzOrig[1]
1551             ,fChamberUAorig[iDet][2]-xyzOrig[2] + fgkCraH/2.0 + fgkCdrH/2.0 - fgkCalW/2.0
1552             ,0,"ONLY");
1553
1554   sprintf(cTagV,"UD%02d",iDet);
1555   gMC->Gspos(cTagV,1,cTagM
1556             ,fChamberUDorig[iDet][0]-xyzOrig[0]
1557             ,fChamberUDorig[iDet][1]-xyzOrig[1]
1558             ,fChamberUDorig[iDet][2]-xyzOrig[2]
1559             ,0,"ONLY");
1560
1561   sprintf(cTagV,"UF%02d",iDet);
1562   gMC->Gspos(cTagV,1,cTagM
1563             ,fChamberUForig[iDet][0]-xyzOrig[0]
1564             ,fChamberUForig[iDet][1]-xyzOrig[1]
1565             ,fChamberUForig[iDet][2]-xyzOrig[2]
1566             ,0,"ONLY");
1567   
1568   sprintf(cTagV,"UU%02d",iDet);
1569   gMC->Gspos(cTagV,1,cTagM
1570             ,fChamberUUorig[iDet][0]-xyzOrig[0]
1571             ,fChamberUUorig[iDet][1]-xyzOrig[1]
1572             ,fChamberUUorig[iDet][2]-xyzOrig[2]
1573             ,0,"ONLY");
1574
1575   sprintf(cTagV,"UT%02d",iDet);
1576   gMC->Gspos(cTagV,1,"UTI1"
1577             ,xyzOrig[0]
1578             ,xyzOrig[1]
1579             ,xyzOrig[2]
1580             ,0,"ONLY");
1581   gMC->Gspos(cTagV,1,"UTI2"
1582             ,xyzOrig[0]
1583             ,xyzOrig[1]
1584             ,xyzOrig[2]
1585             ,0,"ONLY");
1586   if (icham != 2) {
1587     // W/o middle stack
1588     gMC->Gspos(cTagV,1,"UTI3"
1589               ,xyzOrig[0]
1590               ,xyzOrig[1]
1591               ,xyzOrig[2]
1592               ,0,"ONLY");
1593   }
1594
1595 }
1596
1597 //_____________________________________________________________________________
1598 Bool_t AliTRDgeometry::RotateBack(Int_t det, Double_t *loc, Double_t *glb) const
1599 {
1600   //
1601   // Rotates a chambers to transform the corresponding local frame
1602   // coordinates <loc> into the coordinates of the ALICE restframe <glb>.
1603   //
1604
1605   Int_t sector = GetSector(det);
1606
1607   glb[0] = loc[0] * fRotB11[sector] - loc[1] * fRotB12[sector];
1608   glb[1] = loc[0] * fRotB21[sector] + loc[1] * fRotB22[sector];
1609   glb[2] = loc[2];
1610
1611   return kTRUE;
1612
1613 }
1614
1615 //_____________________________________________________________________________
1616 Int_t AliTRDgeometry::GetDetectorSec(Int_t p, Int_t c)
1617 {
1618   //
1619   // Convert plane / chamber into detector number for one single sector
1620   //
1621
1622   return (p + c * fgkNplan);
1623
1624 }
1625
1626 //_____________________________________________________________________________
1627 Int_t AliTRDgeometry::GetDetector(Int_t p, Int_t c, Int_t s)
1628 {
1629   //
1630   // Convert plane / chamber / sector into detector number
1631   //
1632
1633   return (p + c * fgkNplan + s * fgkNplan * fgkNcham);
1634
1635 }
1636
1637 //_____________________________________________________________________________
1638 Int_t AliTRDgeometry::GetPlane(Int_t d)
1639 {
1640   //
1641   // Reconstruct the plane number from the detector number
1642   //
1643
1644   return ((Int_t) (d % fgkNplan));
1645
1646 }
1647
1648 //_____________________________________________________________________________
1649 Int_t AliTRDgeometry::GetChamber(Int_t d) const
1650 {
1651   //
1652   // Reconstruct the chamber number from the detector number
1653   //
1654
1655   return ((Int_t) (d % (fgkNplan * fgkNcham)) / fgkNplan);
1656
1657 }
1658
1659 //_____________________________________________________________________________
1660 Int_t AliTRDgeometry::GetSector(Int_t d) const
1661 {
1662   //
1663   // Reconstruct the sector number from the detector number
1664   //
1665
1666   return ((Int_t) (d / (fgkNplan * fgkNcham)));
1667
1668 }
1669
1670 //_____________________________________________________________________________
1671 AliTRDpadPlane *AliTRDgeometry::GetPadPlane(Int_t p, Int_t c)
1672 {
1673   //
1674   // Returns the pad plane for a given plane <p> and chamber <c> number
1675   //
1676
1677   if (!fPadPlaneArray) {
1678     CreatePadPlaneArray();
1679   }
1680
1681   Int_t ipp = GetDetectorSec(p,c);
1682   return ((AliTRDpadPlane *) fPadPlaneArray->At(ipp));
1683
1684 }
1685
1686 //_____________________________________________________________________________
1687 Int_t AliTRDgeometry::GetRowMax(Int_t p, Int_t c, Int_t /*s*/)
1688 {
1689   //
1690   // Returns the number of rows on the pad plane
1691   //
1692
1693   return GetPadPlane(p,c)->GetNrows();
1694
1695 }
1696
1697 //_____________________________________________________________________________
1698 Int_t AliTRDgeometry::GetColMax(Int_t p)
1699 {
1700   //
1701   // Returns the number of rows on the pad plane
1702   //
1703
1704   return GetPadPlane(p,0)->GetNcols();
1705
1706 }
1707
1708 //_____________________________________________________________________________
1709 Double_t AliTRDgeometry::GetRow0(Int_t p, Int_t c, Int_t /*s*/)
1710 {
1711   //
1712   // Returns the position of the border of the first pad in a row
1713   //
1714
1715   return GetPadPlane(p,c)->GetRow0();
1716
1717 }
1718
1719 //_____________________________________________________________________________
1720 Double_t AliTRDgeometry::GetCol0(Int_t p)
1721 {
1722   //
1723   // Returns the position of the border of the first pad in a column
1724   //
1725
1726   return GetPadPlane(p,0)->GetCol0();
1727
1728 }
1729
1730 //_____________________________________________________________________________
1731 //Int_t AliTRDgeometry::GetPadRowFromMCM(Int_t irob, Int_t imcm) const
1732 //{
1733   //
1734   // Return on which row this mcm sits 
1735   //
1736 //
1737 //  return fgkMCMrow*(irob/2) + imcm/fgkMCMrow;
1738 //
1739 //}
1740
1741 //_____________________________________________________________________________
1742 //Int_t AliTRDgeometry::GetPadColFromADC(Int_t irob, Int_t imcm, Int_t iadc) const
1743 //{
1744   //
1745   // Return which pad is connected to this adc channel. return -1 if it
1746   // is one of the not directly connected adc channels (0, 1 20)
1747   //
1748 //
1749 //  if (iadc < 2 || iadc > 19 ) return -1;
1750 //
1751 //  return (iadc-2) + (imcm%fgkMCMrow)*fgkPadmax + GetRobSide(irob)*fgkColmax/2;
1752 //
1753 //}
1754
1755 //_____________________________________________________________________________
1756 //Int_t AliTRDgeometry::GetMCMfromPad(Int_t irow, Int_t icol) const
1757 //{
1758   //
1759   // Return on which mcm this pad is
1760   //
1761 //
1762 //  if ( irow < 0 || icol < 0 || irow > fgkRowmaxC1 || icol > fgkColmax ) return -1;
1763 //
1764 //  return (icol%(fgkColmax/2))/fgkPadmax + fgkMCMrow*(irow%fgkMCMrow);
1765 //
1766 //}
1767
1768 //_____________________________________________________________________________
1769 //Int_t AliTRDgeometry::GetROBfromPad(Int_t irow, Int_t icol) const
1770 //{
1771   //
1772   // Return on which rob this pad is
1773   //
1774 //
1775 //  return (irow/fgkMCMrow)*2 + GetColSide(icol);
1776 //
1777 //}
1778
1779 //_____________________________________________________________________________
1780 //Int_t AliTRDgeometry::GetRobSide(Int_t irob) const
1781 //{
1782   //
1783   // Return on which side this rob sits (A side = 0, B side = 1)
1784   //
1785 //
1786 //  if ( irob < 0 || irob >= fgkROBmaxC1 ) return -1;
1787 //
1788 //  return irob%2;
1789 //
1790 //}
1791
1792 //_____________________________________________________________________________
1793 //Int_t AliTRDgeometry::GetColSide(Int_t icol) const
1794 //{
1795   //
1796   // Return on which side this column sits (A side = 0, B side = 1)
1797   //
1798 //
1799 //  if ( icol < 0 || icol >= fgkColmax ) return -1;
1800 //
1801 //  return icol/(fgkColmax/2);
1802 //
1803 //}
1804
1805 //_____________________________________________________________________________
1806 Bool_t AliTRDgeometry::CreateClusterMatrixArray()
1807 {
1808   //
1809   // Create the matrices to transform cluster coordinates from the 
1810   // local chamber system to the tracking coordinate system
1811   //
1812
1813   if (!gGeoManager) {
1814     return kFALSE;
1815   }
1816
1817   fClusterMatrixArray = new TObjArray(kNdet);
1818   AliAlignObjParams o;
1819
1820   for (Int_t iLayer = AliGeomManager::kTRD1; iLayer <= AliGeomManager::kTRD6; iLayer++) {
1821     for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer); iModule++) {
1822
1823       UShort_t     volid   = AliGeomManager::LayerToVolUID(iLayer,iModule);
1824       const char  *symname = AliGeomManager::SymName(volid);
1825       TGeoPNEntry *pne     = gGeoManager->GetAlignableEntry(symname);
1826       const char  *path    = symname;
1827       if (pne) {
1828         path = pne->GetTitle();
1829       }
1830       if (!strstr(path,"ALIC")) {
1831         AliDebug(1,Form("Not a valid path: %s\n",path));
1832         continue;
1833       }
1834       if (!gGeoManager->cd(path)) {
1835         continue;
1836       }
1837       TGeoHMatrix *m         = gGeoManager->GetCurrentMatrix();
1838       Int_t        iLayerTRD = iLayer - AliGeomManager::kTRD1;
1839       Int_t        isector   = iModule/Ncham();
1840       Int_t        ichamber  = iModule%Ncham();
1841       Int_t        lid       = GetDetector(iLayerTRD,ichamber,isector);    
1842       
1843       TGeoRotation mchange; 
1844       mchange.RotateY(90); 
1845       mchange.RotateX(90);
1846
1847       //
1848       // Cluster transformation matrix
1849       //
1850       TGeoHMatrix  rotMatrix(mchange.Inverse());
1851       rotMatrix.MultiplyLeft(m);
1852       Double_t sectorAngle = 20.0 * (isector % 18) + 10.0;
1853       TGeoHMatrix  rotSector;
1854       rotSector.RotateZ(sectorAngle);
1855       rotMatrix.MultiplyLeft(&rotSector.Inverse());
1856
1857       fClusterMatrixArray->AddAt(new TGeoHMatrix(rotMatrix),lid);       
1858
1859     }    
1860   }
1861
1862   return kTRUE;
1863
1864 }
1865