90783f75b9da727a1378b4cb28517a9ee6092c10
[u/mrichter/AliRoot.git] / MUON / AliMUONSlatGeometryBuilder.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 /// \class AliMUONSlatGeometryBuilder
21 /// This Builder is designed according to the enveloppe methode. The basic idea is to be able to allow moves 
22 /// of the slats on the support panels. 
23 /// Those moves can be described with a simple set of parameters. The next step should be now to describe all 
24 /// the slats and their places by a unique 
25 /// class, which would make the SlatBuilder far more compact since now only three parameters can define a slat 
26 /// and its position, like:
27 ///   - Bool_t rounded_shape_slat
28 ///   - Float_t slat_length
29 ///   - Float_t slat_number or Float_t slat_position
30 /// Reference system is the one described in the note ALICE-INT-2003-038  v.2  EDMS Id 406391 
31 ///
32 /// \author Eric Dumonteil (dumontei@cea.fr)
33 //-----------------------------------------------------------------------------
34
35 #include "AliMUONSlatGeometryBuilder.h"
36 #include "AliMUON.h"
37 #include "AliMUONConstants.h"
38 #include "AliMUONGeometryModule.h"
39 #include "AliMUONGeometryEnvelopeStore.h"
40 #include "AliMUONConstants.h"
41
42 #include "AliMpDEManager.h"
43
44 #include "AliRun.h"
45 #include "AliLog.h"
46
47 #include <TVirtualMC.h>
48 #include <TGeoBBox.h>
49 #include <TGeoVolume.h>
50 #include <TGeoManager.h>
51 #include <TGeoMatrix.h>
52 #include <TGeoCompositeShape.h>
53 #include <TGeoTube.h>
54 #include <Riostream.h>
55
56 /// \cond CLASSIMP
57 ClassImp(AliMUONSlatGeometryBuilder)
58 /// \endcond
59
60 //______________________________________________________________________________
61 AliMUONSlatGeometryBuilder::AliMUONSlatGeometryBuilder(AliMUON* muon)
62  : AliMUONVGeometryBuilder(4, 12),
63    fMUON(muon)
64 {
65 /// Standard constructor
66
67 }
68
69 //______________________________________________________________________________
70 AliMUONSlatGeometryBuilder::AliMUONSlatGeometryBuilder() 
71  : AliMUONVGeometryBuilder(),
72    fMUON(0)
73 {
74 /// Default constructor
75 }
76
77 //______________________________________________________________________________
78 AliMUONSlatGeometryBuilder::~AliMUONSlatGeometryBuilder() 
79 {
80 /// Destructor
81 }
82
83 //
84 // public methods
85 //
86
87 //______________________________________________________________________________
88 void AliMUONSlatGeometryBuilder::CreateGeometry()
89 {
90   /// CreateGeometry is the method containing all the informations concerning Stations 345 geometry.
91   /// It includes description and placements of support panels and slats.
92   /// The code comes directly from what was written in AliMUONv1.cxx before, with modifications concerning 
93   /// the use of Enveloppe method to place the Geant volumes.
94   /// Now, few changes would allow the creation of a Slat methode where slat could be described by few parameters, 
95   /// and this builder would then be dedicated only to the
96   /// placements of the slats. Those modifications could shorten the Station 345 geometry by a non-negligeable factor...
97  
98   Int_t *idtmed = fMUON->GetIdtmed()->GetArray()-1099;
99
100   Float_t angle;
101   Float_t *dum=0;
102
103   // define the id of tracking media:
104   //  Int_t idAir    = idtmed[1100]; // medium 1
105   Int_t idGas    = idtmed[1108]; // medium 9 = Ar-CO2 gas (80%+20%)
106   Int_t idCopper = idtmed[1110];
107   Int_t idG10    = idtmed[1111];
108   Int_t idCarbon = idtmed[1112];
109   Int_t idRoha   = idtmed[1113];
110   Int_t idNomex  = idtmed[1114]; // honey comb
111   Int_t idNoryl  = idtmed[1115]; 
112   Int_t idNomexB = idtmed[1116]; // bulk material 
113   
114   // Getting mediums for pannel support geometry
115   TGeoMedium* kMedNomex     = gGeoManager->GetMedium("MUON_Nomex");
116   TGeoMedium* kMedCarbon    = gGeoManager->GetMedium("MUON_CARBON");
117
118   // sensitive area: 40*40 cm**2
119   const Float_t kSensLength = 40.; 
120   const Float_t kSensHeight = 40.; 
121   const Float_t kSensWidth  = AliMUONConstants::Pitch()*2;// 0.5 cm, according to TDR fig 2.120 
122   const Int_t kSensMaterial = idGas;
123   //     const Float_t kYoverlap   = 1.5; 
124
125   // PCB dimensions in cm; width: 30 mum copper   
126   const Float_t kPcbLength  = kSensLength; 
127   const Float_t kPcbHeight  = 58.; // updated Ch. Finck 
128   const Float_t kPcbWidth   = 0.003; 
129   const Int_t kPcbMaterial  = idCopper;
130
131   // Insulating material: 220 mum G10 fiber  glued to pcb  
132   const Float_t kInsuLength = kPcbLength; 
133   const Float_t kInsuHeight = kPcbHeight; 
134   const Float_t kInsuWidth  = 0.022;  // updated Ch. Finck 
135   const Int_t kInsuMaterial = idG10;
136
137   // Carbon fiber panels: 200mum carbon/epoxy skin   
138   const Float_t kCarbonWidth  = 0.020;      
139   const Int_t kCarbonMaterial = idCarbon;
140
141   // Nomex (honey comb) between the two panel carbon skins    
142   const Float_t kNomexLength = kSensLength; 
143   const Float_t kNomexHeight = kSensHeight; 
144   const Float_t kNomexWidth  = 0.8; // updated Ch. Finck 
145   const Int_t kNomexMaterial = idNomex;
146  
147   // Bulk Nomex under panel sandwich Ch. Finck    
148   const Float_t kNomexBWidth  = 0.025; 
149   const Int_t kNomexBMaterial = idNomexB;
150
151   // Panel sandwich 0.02 carbon*2 + 0.8 nomex     
152   const Float_t kPanelLength = kSensLength; 
153   const Float_t kPanelHeight = kSensHeight; 
154   const Float_t kPanelWidth  = 2 * kCarbonWidth + kNomexWidth;
155
156   // Frame along the rounded (spacers) slats 
157   const Float_t kRframeHeight = 2.00; 
158
159   // spacer around the slat: 2 sticks along length,2 along height  
160   // H: the horizontal ones 
161   const Float_t kHframeLength = kPcbLength; 
162   const Float_t kHframeHeight = 1.95; // updated Ch. Finck 
163   const Float_t kHframeWidth  = kSensWidth; 
164   const Int_t kHframeMaterial = idNoryl;
165
166   // V: the vertical ones; vertical spacers 
167   const Float_t kVframeLength = 2.5; 
168   const Float_t kVframeHeight = kSensHeight + kHframeHeight; 
169   const Float_t kVframeWidth  = kSensWidth;
170   const Int_t kVframeMaterial = idNoryl;
171
172   // R: rounded part of vertical spacers 
173   const Float_t kRframeLength = 2.0; 
174   const Float_t kRframeWidth  = kSensWidth;
175   const Int_t kRframeMaterial = idNoryl;
176
177   // B: the horizontal border filled with rohacell: ok Ch. Finck
178   const Float_t kBframeLength = kHframeLength; 
179   const Float_t kBframeHeight = (kPcbHeight - kSensHeight)/2. - kHframeHeight; 
180   const Float_t kBframeWidth  = kHframeWidth;
181   const Int_t kBframeMaterial = idRoha;
182
183   // NULOC: 30 mum copper + 200 mum vetronite (same radiation length as 14mum copper) for electronics
184   const Float_t kNulocLength   = 2.5; 
185   const Float_t kNulocHeight   = kBframeHeight;
186   const Float_t kNulocWidth    = 0.0030 + 0.0014; // equivalent copper width of vetronite; 
187   const Int_t   kNulocMaterial = idCopper;
188
189   // Readout cables: Equivalent to 260 mum copper   
190   const Float_t kCableHeight = 2.6; 
191   const Float_t kCableWidth  = 0.026;  
192   const Int_t kCableMaterial = idCopper;
193
194   // Slat parameters
195   const Float_t kSlatHeight = kPcbHeight; 
196   const Float_t kSlatWidth  = kSensWidth + 2.*(kPcbWidth + kInsuWidth + kPanelWidth 
197                                                + kNomexBWidth); //replaced rohacell with Nomex Ch. Finck 
198   // const Int_t   kSlatMaterial = idAir;
199   const Float_t kDslatLength  = -1.25; // position of the slat respect to the beam plane (half vertical spacer) Ch. Finck
200   Float_t zSlat               = AliMUONConstants::DzSlat();// implemented Ch. Finck
201   Float_t dzCh                = AliMUONConstants::DzCh();
202
203   Float_t spar[3];  
204   Int_t i, j;
205   Int_t detElemId;
206   Int_t moduleId;
207
208   // the panel volume contains the nomex
209   Float_t panelpar[3] = { kPanelLength/2., kPanelHeight/2., kPanelWidth/2. }; 
210   Float_t nomexpar[3] = { kNomexLength/2., kNomexHeight/2., kNomexWidth/2. }; 
211   Float_t twidth =  kPanelWidth +  kNomexBWidth; 
212   Float_t nomexbpar[3] = {kNomexLength/2., kNomexHeight/2.,twidth/2. };// bulk nomex 
213
214   // insulating material contains PCB-> gas   
215   twidth = 2*(kInsuWidth + kPcbWidth) + kSensWidth ; 
216   Float_t insupar[3] = {kInsuLength/2., kInsuHeight/2., twidth/2. }; 
217   twidth -= 2 * kInsuWidth; 
218   Float_t pcbpar[3]  = {kPcbLength/2., kPcbHeight/2., twidth/2. }; 
219   Float_t senspar[3] = {kSensLength/2., kSensHeight/2., kSensWidth/2. }; 
220   Float_t theight    = 2 * kHframeHeight + kSensHeight;
221   Float_t hFramepar[3] = {kHframeLength/2., theight/2., kHframeWidth/2.}; 
222   Float_t bFramepar[3] = {kBframeLength/2., kBframeHeight/2., kBframeWidth/2.}; 
223   Float_t vFramepar[3] = {kVframeLength/2., kVframeHeight/2., kVframeWidth/2.};
224   Float_t nulocpar[3]  = {kNulocLength/2.,  kNulocHeight/2.,  kNulocWidth/2.}; 
225
226   Float_t xx;
227   Float_t xxmax = (kBframeLength - kNulocLength)/2.; 
228   Int_t index=0;
229   Int_t* fStations = new Int_t[5];
230   for (Int_t i=0; i<5; i++) fStations[i] = 1;
231   fStations[2] = 1;
232      
233   if (fStations[2])
234     {
235       //********************************************************************
236       //                            Station 3                             **
237       //********************************************************************
238       // Mother volume for each chamber in St3 is an envelop (or assembly)
239       // There is one assembly mother per half a chamber
240       // Mother volume for each chamber in St3 is an envelop (or assembly)
241       // There is one assembly mother per half a chamber  called SC05I, SC05O, SC06I and SC06O
242       // volumes for slat geometry (xx=5,..,10 chamber id): 
243       // Sxx0 Sxx1 Sxx2 Sxx3  -->   Slat Mother volumes 
244       // SxxG                          -->   Sensitive volume (gas)
245       // SxxP                          -->   PCB (copper) 
246       // SxxI                          -->   Insulator (G10) 
247       // SxxC                          -->   Carbon panel 
248       // SxxN                          -->   Nomex comb
249       // SxxX                          -->   Nomex bulk
250       // SxxH, SxxV                    -->   Horizontal and Vertical frames (Noryl)
251       // SB5x                          -->   Volumes for the 35 cm long PCB
252       // slat dimensions: slat is a MOTHER volume!!! made of air
253       // Only for chamber 5: slat 1 has a PCB shorter by 5cm!
254
255       Float_t tlength = 35.;
256       Float_t panelpar2[3]  = { tlength/2., panelpar[1],  panelpar[2]}; 
257       Float_t nomexpar2[3]  = { tlength/2., nomexpar[1],  nomexpar[2]}; 
258       Float_t nomexbpar2[3] = { tlength/2., nomexbpar[1],  nomexbpar[2]}; 
259       Float_t insupar2[3]   = { tlength/2., insupar[1],   insupar[2]}; 
260       Float_t pcbpar2[3]    = { tlength/2., pcbpar[1],    pcbpar[2]}; 
261       Float_t senspar2[3]   = { tlength/2., senspar[1],   senspar[2]}; 
262       Float_t hFramepar2[3] = { tlength/2., hFramepar[1], hFramepar[2]}; 
263       Float_t bFramepar2[3] = { tlength/2., bFramepar[1], bFramepar[2]}; 
264       Float_t *dum=0;
265       Float_t pcbDLength3   = (kPcbLength - tlength);
266       
267       // For rounded pcb of central slat
268       Float_t csvPcbLength = 59.25-40.; // PQ-LAT-SR1
269       Float_t panelpar3[3]  = { csvPcbLength/2., panelpar[1],  panelpar[2]}; 
270       Float_t nomexpar3[3]  = { csvPcbLength/2., nomexpar[1],  nomexpar[2]}; 
271       Float_t nomexbpar3[3] = { csvPcbLength/2., nomexbpar[1],  nomexbpar[2]}; 
272       Float_t insupar3[3]   = { csvPcbLength/2., insupar[1],   insupar[2]}; 
273       Float_t pcbpar3[3]    = { csvPcbLength/2., pcbpar[1],    pcbpar[2]}; 
274       Float_t senspar3[3]   = { csvPcbLength/2., senspar[1],   senspar[2]}; 
275       Float_t hFramepar3[3] = { csvPcbLength/2., hFramepar[1], hFramepar[2]}; 
276       Float_t bFramepar3[3] = { csvPcbLength/2., bFramepar[1], bFramepar[2]}; 
277       Float_t cPhi = TMath::RadToDeg()*(TMath::Pi()/2.-TMath::ACos(hFramepar3[1]/(AliMUONConstants::Rmin(2)-kRframeLength)));
278       Float_t cFramepar3[5] = { AliMUONConstants::Rmin(2)-kRframeLength, AliMUONConstants::Rmin(2), kRframeWidth, -cPhi, cPhi}; 
279
280       const Int_t   kNslats3         = 5;  // number of slats per quadrant
281       const Int_t   kNPCB3[kNslats3] = {4, 4, 4, 3, 2}; // n PCB per slat
282       const Float_t kXpos3[kNslats3] = {0., 0., 0., 0., 0.};//{31., 0., 0., 0., 0.};
283       const Float_t kYpos3[kNslats3] = {0, 37.8, 37.7, 37.3, 33.7};
284       Float_t slatLength3[kNslats3]; 
285
286       Float_t rPhi1 = TMath::RadToDeg()*(TMath::ASin((kYpos3[1]-hFramepar3[1])/(AliMUONConstants::Rmin(2))));
287       Float_t rPhi2 = TMath::RadToDeg()*(TMath::ACos(-vFramepar[0]/(AliMUONConstants::Rmin(2)-kRframeLength)));
288       Float_t rFramepar3[5] = { AliMUONConstants::Rmin(2)-kRframeLength, AliMUONConstants::Rmin(2), kRframeWidth, rPhi1, rPhi2}; 
289       Float_t vrFrameHeight = hFramepar3[1]+kYpos3[1]-AliMUONConstants::Rmin(2)+kRframeLength;
290
291       // create and position the slat (mother) volumes 
292
293       char idSlatCh5[5];
294       char idSlatCh6[5];
295       Float_t xSlat3;
296       Float_t ySlat3 = 0;
297       Float_t angle = 0.;
298       Float_t spar2[3];
299       for (i = 0; i < kNslats3; i++){
300
301         slatLength3[i] = kPcbLength * kNPCB3[i] + 2.* kVframeLength; 
302         xSlat3 = slatLength3[i]/2. +  kDslatLength + kXpos3[i]; 
303         ySlat3 += kYpos3[i];
304
305         spar[0] = slatLength3[i]/2.; 
306         spar[1] = kSlatHeight/2.;
307         spar[2] = kSlatWidth/2.; 
308         // take away 5 cm from the first slat in chamber 5
309         if (i == 0 || i == 1 || i == 2) { // 1 pcb is shortened by 5cm
310           spar2[0] = spar[0] - pcbDLength3/2.;
311         } else {
312           spar2[0] = spar[0];
313         }
314         spar2[1] = spar[1];
315         spar2[2] = spar[2]; 
316         Float_t dzCh3 = dzCh; 
317         Float_t zSlat3 = (i%2 ==0)? -zSlat : zSlat; // seems not that zSlat3 = zSlat4 & 5 refering to plan PQ7EN345-6 ?
318
319         sprintf(idSlatCh5,"LA%d",i+kNslats3-1);
320         detElemId = 509 - (i + kNslats3-1-4);
321         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
322         if (detElemId % 2 == 0)
323             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
324                                                 TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
325         else
326             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
327                                                 TGeoRotation("rot1",90,angle,90,270+angle,180,0) ); 
328
329         sprintf(idSlatCh5,"LA%d",3*kNslats3-2+i);
330         detElemId = 500 + (i + kNslats3-1-4);
331         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
332         if (detElemId % 2 == 0)
333             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
334                                                 TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );
335         else
336             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
337                                                 TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
338
339         if (i > 0) { 
340           sprintf(idSlatCh5,"LA%d",kNslats3-1-i);
341           detElemId = 509 + (i + kNslats3-1-4);
342           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
343           if (detElemId % 2 == 0 && detElemId != 510)
344               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3), 
345                                                   TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
346           else
347               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3), 
348                                                   TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
349
350           sprintf(idSlatCh5,"LA%d",3*kNslats3-2-i);
351           detElemId = 518 - (i + kNslats3-1-4);
352           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
353           if (detElemId % 2 == 1 && detElemId != 517)
354               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
355                                                   TGeoRotation("rot4",90,180+angle,90,90+angle,180,0) );
356           else
357               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
358                                                   TGeoRotation("rot4",90,180+angle,90,270+angle,0,0) );   
359         }
360
361         sprintf(idSlatCh6,"LB%d",kNslats3-1+i);  
362         detElemId = 609 - (i  + kNslats3-1-4);
363         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
364         if (detElemId % 2 == 0)
365             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
366                                      TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
367         else
368             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
369                                      TGeoRotation("rot5",90,angle,90,270+angle,180,0) );
370
371         sprintf(idSlatCh6,"LB%d",3*kNslats3-2+i);
372         detElemId = 600 + (i + kNslats3-1-4);
373         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
374         if (detElemId % 2 == 0)
375             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
376                                                 TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
377         else
378             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
379                                                 TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) ); 
380
381         if (i > 0) { 
382           sprintf(idSlatCh6,"LB%d",kNslats3-1-i);
383           detElemId = 609 + (i + kNslats3-1-4);
384           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
385           if (detElemId % 2 == 0 && detElemId != 610)
386               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3),
387                                                   TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
388           else
389               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3),
390                                                   TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
391           sprintf(idSlatCh6,"LB%d",3*kNslats3-2-i);
392           detElemId = 618 - (i + kNslats3-1-4);
393           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
394           if (detElemId % 2 == 1 && detElemId != 617)
395               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
396                                                   TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) );
397           else
398               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
399                                                   TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) );   
400         }
401       }
402      
403       // create the panel volume 
404  
405       gMC->Gsvolu("S05C","BOX",kCarbonMaterial,panelpar,3);
406       gMC->Gsvolu("SB5C","BOX",kCarbonMaterial,panelpar2,3);
407       gMC->Gsvolu("SC5C","BOX",kCarbonMaterial,panelpar3,3);
408       gMC->Gsvolu("SD5C","BOX",kCarbonMaterial,panelpar,3);
409       gMC->Gsvolu("S06C","BOX",kCarbonMaterial,panelpar,3);
410       gMC->Gsvolu("SC6C","BOX",kCarbonMaterial,panelpar3,3);
411       gMC->Gsvolu("SD6C","BOX",kCarbonMaterial,panelpar,3);
412  
413       // create the nomex volume (honey comb)
414
415       gMC->Gsvolu("S05N","BOX",kNomexMaterial,nomexpar,3);
416       gMC->Gsvolu("SB5N","BOX",kNomexMaterial,nomexpar2,3);
417       gMC->Gsvolu("SC5N","BOX",kNomexMaterial,nomexpar3,3);
418       gMC->Gsvolu("SD5N","BOX",kNomexMaterial,nomexpar,3);
419       gMC->Gsvolu("S06N","BOX",kNomexMaterial,nomexpar,3);
420       gMC->Gsvolu("SC6N","BOX",kNomexMaterial,nomexpar3,3);
421       gMC->Gsvolu("SD6N","BOX",kNomexMaterial,nomexpar,3);
422  
423       // create the nomex volume (bulk)
424
425       gMC->Gsvolu("S05X","BOX",kNomexBMaterial,nomexbpar,3);
426       gMC->Gsvolu("SB5X","BOX",kNomexBMaterial,nomexbpar2,3);
427       gMC->Gsvolu("SC5X","BOX",kNomexBMaterial,nomexbpar3,3);
428       gMC->Gsvolu("SD5X","BOX",kNomexBMaterial,nomexbpar,3);
429       gMC->Gsvolu("S06X","BOX",kNomexBMaterial,nomexbpar,3);
430       gMC->Gsvolu("SC6X","BOX",kNomexBMaterial,nomexbpar3,3);
431       gMC->Gsvolu("SD6X","BOX",kNomexBMaterial,nomexbpar,3);
432
433       // create the insulating material volume 
434
435       gMC->Gsvolu("S05I","BOX",kInsuMaterial,insupar,3);
436       gMC->Gsvolu("SB5I","BOX",kInsuMaterial,insupar2,3);
437       gMC->Gsvolu("SC5I","BOX",kInsuMaterial,insupar3,3);
438       gMC->Gsvolu("SD5I","BOX",kInsuMaterial,insupar,3);
439       gMC->Gsvolu("S06I","BOX",kInsuMaterial,insupar,3);
440       gMC->Gsvolu("SC6I","BOX",kInsuMaterial,insupar3,3);
441       gMC->Gsvolu("SD6I","BOX",kInsuMaterial,insupar,3);
442  
443       // create the PCB volume 
444
445       gMC->Gsvolu("S05P","BOX",kPcbMaterial,pcbpar,3);
446       gMC->Gsvolu("SB5P","BOX",kPcbMaterial,pcbpar2,3);
447       gMC->Gsvolu("SC5P","BOX",kPcbMaterial,pcbpar3,3);
448       gMC->Gsvolu("SD5P","BOX",kPcbMaterial,pcbpar,3);
449       gMC->Gsvolu("S06P","BOX",kPcbMaterial,pcbpar,3);
450       gMC->Gsvolu("SC6P","BOX",kPcbMaterial,pcbpar3,3);
451       gMC->Gsvolu("SD6P","BOX",kPcbMaterial,pcbpar,3);
452  
453       // create the sensitive volumes,
454
455       gMC->Gsvolu("S05G","BOX",kSensMaterial,dum,0);
456       gMC->Gsvolu("SC5G","BOX",kSensMaterial,senspar3,3);
457       gMC->Gsvolu("SD5G","BOX",kSensMaterial,senspar,3);
458       gMC->Gsvolu("S06G","BOX",kSensMaterial,dum,0);
459       gMC->Gsvolu("SC6G","BOX",kSensMaterial,senspar3,3);
460       gMC->Gsvolu("SD6G","BOX",kSensMaterial,senspar,3);
461
462       // create the vertical frame volume 
463
464       gMC->Gsvolu("S05V","BOX",kVframeMaterial,vFramepar,3);
465       gMC->Gsvolu("S06V","BOX",kVframeMaterial,vFramepar,3);
466
467       // create the rounded vertical frame volume 
468
469       gMC->Gsvolu("SC5D","TUBS",kRframeMaterial,cFramepar3,5);
470       gMC->Gsvolu("SD5D","TUBS",kRframeMaterial,rFramepar3,5);
471       gMC->Gsvolu("SC6D","TUBS",kRframeMaterial,cFramepar3,5);
472       gMC->Gsvolu("SD6D","TUBS",kRframeMaterial,rFramepar3,5);
473
474       // create the horizontal frame volume 
475
476       gMC->Gsvolu("S05H","BOX",kHframeMaterial,hFramepar,3);
477       gMC->Gsvolu("SB5H","BOX",kHframeMaterial,hFramepar2,3);
478       gMC->Gsvolu("SC5H","BOX",kHframeMaterial,hFramepar3,3);
479       gMC->Gsvolu("SD5H","BOX",kHframeMaterial,hFramepar,3);
480       gMC->Gsvolu("S06H","BOX",kHframeMaterial,hFramepar,3);
481       gMC->Gsvolu("SC6H","BOX",kHframeMaterial,hFramepar3,3);
482       gMC->Gsvolu("SD6H","BOX",kHframeMaterial,hFramepar,3);
483  
484       // create the horizontal border volume 
485
486       gMC->Gsvolu("S05B","BOX",kBframeMaterial,bFramepar,3);
487       gMC->Gsvolu("SB5B","BOX",kBframeMaterial,bFramepar2,3);
488       gMC->Gsvolu("SC5B","BOX",kBframeMaterial,bFramepar3,3);
489       gMC->Gsvolu("SD5B","BOX",kBframeMaterial,bFramepar,3);
490       gMC->Gsvolu("S06B","BOX",kBframeMaterial,bFramepar,3);
491       gMC->Gsvolu("SC6B","BOX",kBframeMaterial,bFramepar3,3);
492       gMC->Gsvolu("SD6B","BOX",kBframeMaterial,bFramepar,3);
493
494       // Replace the volume shape with a composite shape
495       // with substracted overlap with beam shield     
496       if ( gMC->IsRootGeometrySupported() ) { 
497         
498         // Get shape
499         Int_t nSlatType = 2;
500         Int_t nVol = 8;
501         char slatType[3] = "CD"; // C: central slat; D: rounded slat
502         char volLetter[9] = "CNXIPHBG";
503         char volName[5] = "SC5C";
504         char compName[11] = "SC5C";
505         char csName[14] = "centerSlatC5C";
506         TGeoVolume *mVol = 0x0;
507         TGeoShape *centerSlat[nSlatType*((nVol+1)*2)];  
508         TGeoShape *composite[nSlatType*((nVol+1)*2)];
509
510         // Beam shield recess
511         //      TGeoTube *tubeCut = new TGeoTube("tubeCut", 0., AliMUONConstants::Rmin(2), kSlatWidth/2.+0.001);
512         new TGeoTube("tubeCut", 0., AliMUONConstants::Rmin(2), kSlatWidth/2.+0.001);
513         // Displacement
514         TGeoTranslation* trCTube = new TGeoTranslation("trCTube", -(kPcbLength-csvPcbLength/2.+kVframeLength/2.), 0., 0.);
515         trCTube->RegisterYourself();
516         TGeoTranslation* trDTube = new TGeoTranslation("trDTube", -(kPcbLength+kVframeLength)/2., -kYpos3[1], 0.);
517         trDTube->RegisterYourself();
518
519         Float_t cPhi2 = (TMath::Pi()/2.-TMath::ACos((kSensHeight/2.)/(AliMUONConstants::Rmin(2)-kRframeLength)));
520         TGeoBBox *boxCCut = new TGeoBBox("boxCCut",(cFramepar3[1]-cFramepar3[0]*TMath::Cos(cPhi2))/2., hFramepar3[1], cFramepar3[2]+0.001);
521         // Displacement
522         TGeoTranslation* trCBox = new TGeoTranslation("trCBox",cFramepar3[0]*TMath::Cos(cPhi2)+boxCCut->GetDX(), 0., 0.);
523         trCBox->RegisterYourself();
524         //      TGeoBBox *boxDCut = new TGeoBBox("boxDCut",(kPcbLength+kVframeLength)/2., hFramepar3[1], vFramepar[2]+0.001);
525         new TGeoBBox("boxDCut",(kPcbLength+kVframeLength)/2., hFramepar3[1], vFramepar[2]+0.001);
526         // Displacement
527         TGeoTranslation* trDBox = new TGeoTranslation("trDBox",kPcbLength/2., kYpos3[1], 0.);
528         trDBox->RegisterYourself();
529
530         TGeoBBox *boxVframe = new TGeoBBox("boxVframe",vFramepar[0],vrFrameHeight/2., vFramepar[2]);
531         TGeoTranslation* trVBox = new TGeoTranslation("trVBox", 0., AliMUONConstants::Rmin(2)-kRframeLength + boxVframe->GetDY(), 0.);
532         trVBox->RegisterYourself();
533
534         for(int iCh=5; iCh<=6; iCh++){
535           for (int iSlatType = 0; iSlatType<nSlatType; iSlatType++) {
536             for (int iVol = 0; iVol<nVol; iVol++){
537               Int_t lIndex = (iCh-5)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+iVol;
538               sprintf(volName,"S%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
539               mVol = gGeoManager->FindVolumeFast(volName);
540               if ( !mVol ) {
541                 AliErrorStream() 
542                   << "Slat volume " << volName << " not found" << endl;  
543               }
544               else {
545                 centerSlat[lIndex] = mVol->GetShape();
546                 sprintf(csName,"centerSlat%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
547                 centerSlat[lIndex]->SetName(csName);              
548                 
549                 // Composite shape
550                 TString compOperation(csName);
551                 compOperation+="-tubeCut:tr";
552                 compOperation+=slatType[iSlatType];
553                 compOperation+="Tube";
554                 if (strstr(volName,"B")){
555                   // Displacement
556                   TGeoTranslation* trB = new TGeoTranslation("trB", 0., -( kPcbHeight - kBframeHeight ) / 2., 0.);
557                   trB->RegisterYourself();
558                   compOperation.ReplaceAll("-tubeCut",":trB-tubeCut");
559                 }
560                 sprintf(compName,"composite%d%c",iCh,volLetter[iVol]);
561                 composite[lIndex] = new TGeoCompositeShape(compName, compOperation.Data()); 
562                 
563                 // Reset shape to volume      
564                 mVol->SetShape(composite[lIndex]);
565               }
566             }
567
568             // For rounded spacer
569             Int_t lIndex = (iCh-5)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+nVol;
570             sprintf(volName,"S%c%dD",slatType[iSlatType],iCh);
571             mVol = gGeoManager->FindVolumeFast(volName);
572             if ( !mVol ) {
573               AliErrorStream() 
574                 << "Slat volume " << volName << " not found" << endl;    
575             }
576             else {
577               centerSlat[lIndex] = mVol->GetShape();
578               sprintf(csName,"centerSlat%c%dD",slatType[iSlatType],iCh);
579               centerSlat[lIndex]->SetName(csName);                
580               
581               // Composite shape
582               TString compOperation(csName);
583               if (strstr(volName,"SC")){
584                 compOperation+="*boxCCut:trCBox";
585               }
586               if (strstr(volName,"SD")){
587                 compOperation.Prepend("(");
588                 compOperation+="+boxVframe:trVBox)*boxDCut:trDBox";
589               }
590               sprintf(compName,"composite%c%dD",slatType[iSlatType],iCh);
591               composite[lIndex] = new TGeoCompositeShape(compName, compOperation.Data());             
592               // Reset shape to volume      
593               mVol->SetShape(composite[lIndex]);
594             }
595           }
596         }
597       }
598         
599       index = 0; 
600       for (i = 0; i<kNslats3; i++){
601         for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
602
603           if (i == 0 && quadrant == 2) continue;
604           if (i == 0 && quadrant == 4) continue;
605
606           sprintf(idSlatCh5,"LA%d",ConvertSlatNum(i,quadrant,kNslats3-1));
607           sprintf(idSlatCh6,"LB%d",ConvertSlatNum(i,quadrant,kNslats3-1));
608           Int_t moduleSlatCh5 = GetModuleId(idSlatCh5);
609           Int_t moduleSlatCh6 = GetModuleId(idSlatCh6);
610           Float_t xvFrame  = (slatLength3[i] - kVframeLength)/2.;
611           Float_t xvFrame2  = xvFrame;    
612
613           if (i == 0 || i == 1 || i == 2) xvFrame2 -= pcbDLength3; // Correct position (J.C.)
614
615           // position the vertical frames 
616           if ( i > 2) { 
617             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
618                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
619             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
620                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
621             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
622                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
623             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
624                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));   
625           } 
626
627           if (i == 2) {
628             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
629                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame2,0.,0.)); 
630             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
631                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
632             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
633                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
634             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
635                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
636           }
637
638           if (i == 0 || i == 1) { // first vertical spacers
639             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
640                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame2,0.,0.)); 
641             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
642                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));          
643             if (i == 0) { // rounded spacer for central slat (J.C.)
644               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5D", idSlatCh5, 
645                                                                   (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
646               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6D", idSlatCh6, 
647                                                                   (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
648
649             }
650             if (i == 1) { // rounded + vertical spacer for rounded slat (J.C.)
651               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5D", idSlatCh5, 
652                                                                   (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos3[1],0.));
653               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6D", idSlatCh6, 
654                                                                   (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos3[1],0.));
655             }
656           }
657
658           // position the panels and the insulating material 
659           for (j = 0; j < kNPCB3[i]; j++){
660             index++;
661             Float_t xx = kSensLength * (-kNPCB3[i]/2. + j + 0.5); 
662             Float_t xx2 = xx - pcbDLength3/2.; 
663             Float_t xx3 = xx + (kSensLength-csvPcbLength)/2.;
664
665             Float_t zPanel = spar[2] - nomexbpar[2]; 
666
667             if (i==0 && j==0){ // Rounded pcb of central slat (SR1, NR1)
668               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5X", idSlatCh5, 2*index-1,TGeoTranslation(xx3,0.,zPanel));
669               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5X", idSlatCh5, 2*index,TGeoTranslation(xx3,0.,-zPanel));
670               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5I", idSlatCh5, index,TGeoTranslation(xx3,0.,0.));
671               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6X", idSlatCh6, 2*index-1,TGeoTranslation(xx3,0.,zPanel));
672               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6X", idSlatCh6, 2*index,TGeoTranslation(xx3,0.,-zPanel));
673               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6I", idSlatCh6, index,TGeoTranslation(xx3,0.,0.));
674             } else {          
675               if (i==1 && j==0){ // Rounded pcb of rounded slats (SR2. NR2)
676                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5X", idSlatCh5, 2*index-1,TGeoTranslation(xx,0.,zPanel));
677                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5X", idSlatCh5, 2*index,TGeoTranslation(xx,0.,-zPanel));
678                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5I", idSlatCh5, index,TGeoTranslation(xx,0.,0.));
679                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6X", idSlatCh6, 2*index-1,TGeoTranslation(xx,0.,zPanel));
680                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6X", idSlatCh6, 2*index,TGeoTranslation(xx,0.,-zPanel));
681                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6I", idSlatCh6, index,TGeoTranslation(xx,0.,0.));
682               } else {        
683                 if ( (i == 0 || i == 1 || i == 2) && j == kNPCB3[i]-1) { // 1 pcb is shortened by 5cm 
684                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5X", idSlatCh5, 2*index-1,TGeoTranslation(xx2,0.,zPanel));
685                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5X", idSlatCh5, 2*index,TGeoTranslation(xx2,0.,-zPanel));
686                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5I", idSlatCh5, index,TGeoTranslation(xx2,0.,0.));
687                 } else {                
688                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05X", idSlatCh5, 2*index-1,TGeoTranslation(xx,0.,zPanel));
689                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05X", idSlatCh5, 2*index,TGeoTranslation(xx,0.,-zPanel));
690                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05I", idSlatCh5, index,TGeoTranslation(xx,0.,0.));
691                 }          
692                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06X", idSlatCh6, 2*index-1,TGeoTranslation(xx,0.,zPanel));
693                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06X", idSlatCh6, 2*index,TGeoTranslation(xx,0.,-zPanel));
694                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06I", idSlatCh6, index,TGeoTranslation(xx,0.,0.));                        
695               }
696             }
697           }
698         }
699       }
700       
701       // position the nomex volume inside the panel volume
702       gMC->Gspos("S05N",1,"S05C",0.,0.,0.,0,"ONLY"); 
703       gMC->Gspos("SB5N",1,"SB5C",0.,0.,0.,0,"ONLY"); 
704       gMC->Gspos("SC5N",1,"SC5C",0.,0.,0.,0,"ONLY"); 
705       gMC->Gspos("SD5N",1,"SD5C",0.,0.,0.,0,"ONLY"); 
706       gMC->Gspos("S06N",1,"S06C",0.,0.,0.,0,"ONLY"); 
707       gMC->Gspos("SC6N",1,"SC6C",0.,0.,0.,0,"ONLY"); 
708       gMC->Gspos("SD6N",1,"SD6C",0.,0.,0.,0,"ONLY"); 
709   
710       // position panel volume inside the bulk nomex material volume
711       gMC->Gspos("S05C",1,"S05X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
712       gMC->Gspos("SB5C",1,"SB5X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
713       gMC->Gspos("SC5C",1,"SC5X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
714       gMC->Gspos("SD5C",1,"SD5X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
715       gMC->Gspos("S06C",1,"S06X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
716       gMC->Gspos("SC6C",1,"SC6X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
717       gMC->Gspos("SD6C",1,"SD6X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
718
719       // position the PCB volume inside the insulating material volume
720       gMC->Gspos("S05P",1,"S05I",0.,0.,0.,0,"ONLY"); 
721       gMC->Gspos("SB5P",1,"SB5I",0.,0.,0.,0,"ONLY"); 
722       gMC->Gspos("SC5P",1,"SC5I",0.,0.,0.,0,"ONLY"); 
723       gMC->Gspos("SD5P",1,"SD5I",0.,0.,0.,0,"ONLY"); 
724       gMC->Gspos("S06P",1,"S06I",0.,0.,0.,0,"ONLY"); 
725       gMC->Gspos("SC6P",1,"SC6I",0.,0.,0.,0,"ONLY"); 
726       gMC->Gspos("SD6P",1,"SD6I",0.,0.,0.,0,"ONLY"); 
727   
728       // position the horizontal frame volume inside the PCB volume
729       gMC->Gspos("S05H",1,"S05P",0.,0.,0.,0,"ONLY"); 
730       gMC->Gspos("SB5H",1,"SB5P",0.,0.,0.,0,"ONLY"); 
731       gMC->Gspos("SC5H",1,"SC5P",0.,0.,0.,0,"ONLY"); 
732       gMC->Gspos("SD5H",1,"SD5P",0.,0.,0.,0,"ONLY"); 
733       gMC->Gspos("S06H",1,"S06P",0.,0.,0.,0,"ONLY"); 
734       gMC->Gspos("SC6H",1,"SC6P",0.,0.,0.,0,"ONLY"); 
735       gMC->Gspos("SD6H",1,"SD6P",0.,0.,0.,0,"ONLY"); 
736   
737       // position the sensitive volume inside the horizontal frame volume
738       gMC->Gsposp("S05G",1,"S05H",0.,0.,0.,0,"ONLY",senspar,3); 
739       gMC->Gsposp("S05G",1,"SB5H",0.,0.,0.,0,"ONLY",senspar2,3); 
740       gMC->Gspos("SC5G",1,"SC5H",0.,0.,0.,0,"ONLY"); 
741       gMC->Gspos("SD5G",1,"SD5H",0.,0.,0.,0,"ONLY"); 
742       gMC->Gsposp("S06G",1,"S06H",0.,0.,0.,0,"ONLY",senspar,3); 
743       gMC->Gspos("SC6G",1,"SC6H",0.,0.,0.,0,"ONLY"); 
744       gMC->Gspos("SD6G",1,"SD6H",0.,0.,0.,0,"ONLY"); 
745   
746  
747       // position the border volumes inside the PCB volume
748       Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
749       Int_t rotB = 0;
750       gMC->Matrix(rotB,90,0,90,270,180,0); // rotation around x for second border
751
752       gMC->Gspos("S05B",1,"S05P",0., yborder,0.,0,"ONLY"); 
753       gMC->Gspos("S05B",2,"S05P",0.,-yborder,0.,0,"ONLY"); 
754       gMC->Gspos("SB5B",1,"SB5P",0., yborder,0.,0,"ONLY"); 
755       gMC->Gspos("SB5B",2,"SB5P",0.,-yborder,0.,0,"ONLY"); 
756       gMC->Gspos("SC5B",1,"SC5P",0., 0.,0.,0,"ONLY"); 
757       gMC->Gspos("SC5B",2,"SC5P",0., 0.,0.,rotB,"ONLY"); 
758       gMC->Gspos("SD5B",1,"SD5P",0., 0.,0.,0,"ONLY"); 
759       gMC->Gspos("S05B",1,"SD5P",0., yborder,0.,0,"ONLY"); 
760
761       gMC->Gspos("S06B",1,"S06P",0., yborder,0.,0,"ONLY"); 
762       gMC->Gspos("S06B",2,"S06P",0.,-yborder,0.,0,"ONLY"); 
763       gMC->Gspos("SC6B",1,"SC6P",0., 0.,0.,0,"ONLY"); 
764       gMC->Gspos("SC6B",2,"SC6P",0., 0.,0.,rotB,"ONLY"); 
765       gMC->Gspos("SD6B",1,"SD6P",0., 0.,0.,0,"ONLY"); 
766       gMC->Gspos("S06B",1,"SD6P",0., yborder,0.,0,"ONLY"); 
767   
768       // create the NULOC volume and position it in the horizontal frame
769       gMC->Gsvolu("S05E","BOX",kNulocMaterial,nulocpar,3);
770       gMC->Gsvolu("S06E","BOX",kNulocMaterial,nulocpar,3);
771       index = 0;
772       Float_t xxmax2 = xxmax - pcbDLength3/2.;
773       Float_t xxmax3 = xxmax - (kPcbLength-csvPcbLength)/2.;
774       Float_t rPhi3 = TMath::ASin((kYpos3[1]-kPcbHeight/2.)/AliMUONConstants::Rmin(2));
775       Float_t xxmax4 = (AliMUONConstants::Rmin(2)*TMath::Cos(rPhi3)-kVframeLength/2.) - (kBframeLength - kNulocLength)/2.;
776       for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
777         index++; 
778         gMC->Gspos("S05E",2*index-1,"S05B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
779         gMC->Gspos("S05E",2*index  ,"S05B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
780         gMC->Gspos("S06E",2*index-1,"S06B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
781         gMC->Gspos("S06E",2*index  ,"S06B", xx, 0., kBframeWidth/2.-  kNulocWidth/2, 0, "ONLY");
782         if (xx > -xxmax2 && xx< xxmax2) {
783           gMC->Gspos("S05E",2*index-1,"SB5B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
784           gMC->Gspos("S05E",2*index  ,"SB5B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
785         }
786         if (xx > -xxmax3 && xx< xxmax3) {
787           gMC->Gspos("S05E",2*index-1,"SC5B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2., 0, "ONLY");
788           gMC->Gspos("S05E",2*index  ,"SC5B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2., 0, "ONLY");
789           gMC->Gspos("S06E",2*index-1,"SC6B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
790           gMC->Gspos("S06E",2*index  ,"SC6B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
791         }
792         if (xx > xxmax4 && xx< xxmax) {
793           gMC->Gspos("S05E",2*index-1,"SD5B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
794           gMC->Gspos("S05E",2*index  ,"SD5B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
795           gMC->Gspos("S06E",2*index-1,"SD6B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
796           gMC->Gspos("S06E",2*index  ,"SD6B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
797         }
798       }
799       
800       //
801       //Geometry of the support pannel Verticla length 3.62m, horizontal length 1.62m, internal radius  dMotherInner of SC05 and SC06  (F. Orsini, Saclay)
802       //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
803       // Outer excess and inner recess for mother volume radius
804       // with respect to ROuter and RInner
805       Float_t dMotherInner = AliMUONConstants::Rmin(2)-kRframeHeight; 
806       Float_t nomexthickness = 1.5;
807       Float_t carbonthickness = 0.03;
808       Float_t supporthlength =  162.;  //    chamber 5 
809       Float_t supporthlengthCh6 =  167.;  // chamber 6 
810       Float_t supportvlength =  362.; 
811
812       // Generating the composite shape of the carbon and nomex pannels
813       new TGeoBBox("shNomexBoxSt3",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
814       new TGeoBBox("shCarbonBoxSt3",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
815       new TGeoBBox("shNomexBoxSt3Ch6",(supporthlengthCh6)/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
816       new TGeoBBox("shCarbonBoxSt3Ch6",(supporthlengthCh6)/2., supportvlength/2. ,carbonthickness/2.); 
817       new TGeoTubeSeg("shNomexHoleSt3",0., dMotherInner, nomexthickness/2.+carbonthickness+3*kCableWidth+0.001, -90. ,90.);
818       new TGeoTubeSeg("shCarbonHoleSt3",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
819       TGeoTranslation* trHoleSt3 = new TGeoTranslation("trHoleSt3",-supporthlength/2.,0.,0.); 
820       trHoleSt3->RegisterYourself();
821       TGeoTranslation* trHoleSt3Ch6 = new TGeoTranslation("trHoleSt3Ch6",-(supporthlengthCh6)/2.,0.,0.); 
822       trHoleSt3Ch6->RegisterYourself();
823       TGeoCompositeShape* shNomexSupportSt3  = new TGeoCompositeShape("shNomexSupportSt3","shNomexBoxSt3-shNomexHoleSt3:trHoleSt3");
824       TGeoCompositeShape* shCarbonSupportSt3 = new TGeoCompositeShape("shCarbonSupportSt3","shCarbonBoxSt3-shCarbonHoleSt3:trHoleSt3");
825       TGeoCompositeShape* shNomexSupportSt3Ch6  = new TGeoCompositeShape("shNomexSupportSt3Ch6","shNomexBoxSt3Ch6-shNomexHoleSt3:trHoleSt3Ch6");
826       TGeoCompositeShape* shCarbonSupportSt3Ch6 = new TGeoCompositeShape("shCarbonSupportSt3Ch6","shCarbonBoxSt3Ch6-shCarbonHoleSt3:trHoleSt3Ch6");
827
828       // Generating Nomex and Carbon pannel volumes
829       TGeoVolume * voNomexSupportSt3  = new TGeoVolume("S05S", shNomexSupportSt3, kMedNomex);
830       TGeoVolume * voCarbonSupportSt3 = new TGeoVolume("S05K", shCarbonSupportSt3, kMedCarbon);
831       TGeoVolume * voNomexSupportSt3Ch6  = new TGeoVolume("S06S", shNomexSupportSt3Ch6, kMedNomex);
832       TGeoVolume * voCarbonSupportSt3Ch6 = new TGeoVolume("S06K", shCarbonSupportSt3Ch6, kMedCarbon);
833
834       TGeoTranslation *trCarbon1St3   = new TGeoTranslation("trCarbon1St3",0.,0., -(nomexthickness+carbonthickness)/2.);
835       TGeoTranslation *trCarbon2St3   = new TGeoTranslation("trCarbon2St3",0.,0.,  (nomexthickness+carbonthickness)/2.);
836       voNomexSupportSt3->AddNode(voCarbonSupportSt3,1,trCarbon1St3);
837       voNomexSupportSt3->AddNode(voCarbonSupportSt3,2,trCarbon2St3);
838       voNomexSupportSt3Ch6->AddNode(voCarbonSupportSt3Ch6,1,trCarbon1St3);
839       voNomexSupportSt3Ch6->AddNode(voCarbonSupportSt3Ch6,2,trCarbon2St3);
840
841
842       // Add readout cables
843       gMC->Gsvolu("S05L","BOX",kCableMaterial,dum,0);
844       gMC->Gsvolu("S06L","BOX",kCableMaterial,dum,0);
845
846       ySlat3 = 0.;
847       Float_t lCableX = 0.;
848       Float_t lCableX6 = 0.;
849       Float_t lCableY = 0.;
850       Float_t lCableZ = 0.;
851       Float_t cablepar[3] = {supporthlength/2., kCableHeight/2., kCableWidth/2.};
852       Float_t cablepar6[3] = {supporthlengthCh6/2., kCableHeight/2., kCableWidth/2.};
853       Float_t lCableDY = 0.;
854       Int_t cIndex = 0;
855       Int_t cIndex6 = 0;
856       for (i = 0; i<kNslats3; i++){
857         Int_t iCable = 1;
858         cIndex = 0;
859         cIndex6 = 0;
860         ySlat3 += kYpos3[i];
861         lCableY = ySlat3;
862
863         // Cables going out from the start of slat
864         if(kNPCB3[i]>=4){ // Only if 4 or more pcb
865           // First top cables
866           cablepar[0] = supporthlength/2.;
867           lCableX = 0.;
868           cablepar6[0] = supporthlengthCh6/2.;
869           lCableX6 = 0.;
870           lCableDY = (kYpos3[i+1]+kYpos3[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
871           lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
872           if(i==0){ // central slat is shorter (rounded)
873             cablepar[0] -= (kPcbLength-csvPcbLength)/2.;
874             lCableX = (kPcbLength-csvPcbLength)/2.;
875             cablepar6[0] -= (kPcbLength-csvPcbLength)/2.;
876             lCableX6 = (kPcbLength-csvPcbLength)/2.;
877           }
878           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);       
879           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
880           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar6,3);    
881           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar6,3);
882
883           // Then bottom cables
884           if(i>0){
885             if(i==1){ // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
886               cablepar[0] -= dMotherInner/2.;
887               lCableX += dMotherInner/2.;
888               cablepar6[0] -= dMotherInner/2.;
889               lCableX6 += dMotherInner/2.;
890               lCableDY = (kYpos3[i]+kYpos3[i])/2.-cablepar[1];
891             }
892             if(i>=2){ 
893               lCableDY = (kYpos3[i]+kYpos3[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
894               if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
895                 lCableDY = lCableY - dMotherInner - cablepar[1];
896               }
897             }
898             gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
899             gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
900             gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
901             gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
902           }
903         }
904         
905         // Rounded slats have an extra cable starting at second pcb
906         if(i==1){ 
907           // First top cables
908           cablepar[0] = (supporthlength-kPcbLength-kVframeLength)/2.;
909           lCableX = (kPcbLength+kVframeLength)/2.;
910           cablepar6[0] = (supporthlengthCh6-kPcbLength-kVframeLength)/2.;
911           lCableX6 = (kPcbLength+kVframeLength)/2.;
912           lCableDY = (kYpos3[i+1]+kYpos3[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
913           lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
914           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);       
915           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
916           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar6,3);    
917           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar6,3);
918           // Then bottom cables
919           lCableDY = (kYpos3[i]+kYpos3[i])/2.-cablepar[1];
920           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
921           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
922           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
923           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
924         }
925         
926         // Cables going out from the end of the slats
927         // First top cables
928         cablepar[0] = (supporthlength-(slatLength3[i]+kDslatLength)+kVframeLength)/2.;
929         lCableX = slatLength3[i]-kVframeLength+kDslatLength+cablepar[0]-supporthlength/2.;
930         cablepar6[0] = (supporthlengthCh6-(slatLength3[i]+kDslatLength)+kVframeLength)/2.;
931         lCableX6 = slatLength3[i]-kVframeLength+kDslatLength+cablepar6[0]-supporthlengthCh6/2.;
932         if(i+1>=kNslats3 || i+2>=kNslats3){ // If no more higher slats, then use distance to lower slat
933           lCableDY = kPcbHeight/2.+cablepar[1];
934         }
935         else {
936           lCableDY = (kYpos3[i+1]+kYpos3[i+2])/2.-cablepar[1];
937         }
938         lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
939         if (i<=2){ // shortened pcb
940           cablepar[0] += pcbDLength3/2.;
941           lCableX -=  pcbDLength3/2.;
942         } 
943         gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
944         gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
945         gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
946         gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
947         // Then bottom cables
948         if(i>0){ // Loop is over top half of slats, lower half are symmetric 
949           if (i==1) {
950             lCableDY = (kYpos3[i]+kYpos3[i])/2.-cablepar[1];
951           }
952           else{
953             lCableDY = (kYpos3[i]+kYpos3[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
954           }
955           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
956           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
957           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
958           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
959         }
960       }
961
962       Float_t dzCh5  = dzCh;
963       TGeoTranslation* trSupport1St3   = new TGeoTranslation("trSupport1St3", supporthlength/2., 0. , dzCh5);
964       TGeoRotation*    roSupportSt3    = new TGeoRotation("roSupportSt3",90.,180.,-90.);
965       TGeoCombiTrans*  coSupport2St3   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh5, roSupportSt3);       
966       TGeoTranslation* trSupport1St3Ch6   = new TGeoTranslation("trSupport1St3Ch6", supporthlengthCh6/2., 0. , dzCh5);
967       TGeoCombiTrans*  coSupport2St3Ch6   = new TGeoCombiTrans(-supporthlengthCh6/2., 0., -dzCh5, roSupportSt3);       
968       GetEnvelopes(5)->AddEnvelope("S05S", 0, 1, *trSupport1St3);  
969       GetEnvelopes(4)->AddEnvelope("S05S", 0, 2, *coSupport2St3);  
970       GetEnvelopes(7)->AddEnvelope("S06S", 0, 1, *trSupport1St3Ch6);   
971       GetEnvelopes(6)->AddEnvelope("S06S", 0, 2, *coSupport2St3Ch6);  
972       // End of pannel support geometry          
973
974       // cout << "Geometry for Station 3...... done" << endl;   
975     }
976   if (fStations[3]) {
977
978
979     // //********************************************************************
980     // //                            Station 4                             **
981     // //********************************************************************
982     // Mother volume for each chamber in St4 is an envelop (or assembly)
983     // There is one assembly mother per half a chamber  called SC07I, SC07O, SC08I and SC08O
984     // Same volume name definitions as in St3
985     const Int_t   kNslats4          = 7;  // number of slats per quadrant
986     const Int_t   kNPCB4[kNslats4]  = {5, 6, 5, 5, 4, 3, 2}; // n PCB per slat
987     const Float_t kXpos4[kNslats4]  = {38.75, 0., 0., 0., 0., 0., 0.}; // J.C. Correct value
988     const Float_t kYpos41[kNslats4] = {0., 38.2, 34.40, 36.60, 29.3, 37.0, 28.6};
989     const Float_t kYpos42[kNslats4] = {0., 38.2, 37.85, 37.55, 29.4, 37.0, 28.6};
990     Float_t slatLength4[kNslats4];     
991
992     Float_t rPhi1 = TMath::RadToDeg()*(TMath::ASin((kYpos41[1]-hFramepar[1])/(AliMUONConstants::Rmin(3))));
993     Float_t rPhi2 = TMath::RadToDeg()*(TMath::ACos(-vFramepar[0]/(AliMUONConstants::Rmin(3)-kRframeLength)));
994     Float_t rFramepar4[5] = { AliMUONConstants::Rmin(3)-kRframeLength, AliMUONConstants::Rmin(3), kRframeWidth, rPhi1, rPhi2}; 
995     Float_t vrFrameHeight = hFramepar[1]+kYpos41[1]-AliMUONConstants::Rmin(3)+kRframeLength;
996     
997     char idSlatCh7[5];
998     char idSlatCh8[5];
999     Float_t xSlat4;
1000     Float_t ySlat41 = 0;
1001     Float_t ySlat42 = 0;
1002     angle = 0.;
1003
1004     for (i = 0; i<kNslats4; i++){
1005       slatLength4[i] = kPcbLength * kNPCB4[i] + 2. * kVframeLength; 
1006       xSlat4 = slatLength4[i]/2. + kDslatLength + kXpos4[i]; 
1007       ySlat41 += kYpos41[i];
1008       ySlat42 += kYpos42[i];
1009
1010       spar[0] = slatLength4[i]/2.; 
1011       spar[1] = kSlatHeight/2.;
1012       spar[2] = kSlatWidth/2.; 
1013       Float_t dzCh4 = dzCh;
1014       Float_t zSlat4 = (i%2 ==0)? -zSlat : zSlat; 
1015
1016       sprintf(idSlatCh7,"LC%d",kNslats4-1+i);
1017       detElemId = 713 - (i + kNslats4-1-6);
1018       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1019       if (detElemId % 2 == 0)
1020           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, ySlat41, -zSlat4 + dzCh4),
1021                                    TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
1022       else
1023           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, ySlat41, -zSlat4 + dzCh4),
1024                                    TGeoRotation("rot1",90,angle,90,270+angle,180,0) );
1025
1026       sprintf(idSlatCh7,"LC%d",3*kNslats4-2+i);
1027       detElemId = 700 + (i + kNslats4-1-6);
1028       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1029       if (detElemId % 2 == 0)
1030           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, ySlat41, zSlat4 - dzCh4),
1031                                    TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );
1032       else
1033           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, ySlat41, zSlat4 - dzCh4),
1034                                    TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
1035       if (i > 0) { 
1036         sprintf(idSlatCh7,"LC%d",kNslats4-1-i);
1037         detElemId = 713 + (i + kNslats4-1-6);
1038         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1039         if (detElemId % 2 == 0 && detElemId != 714)
1040             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, -ySlat41, -zSlat4 + dzCh4),
1041                                                 TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
1042         else
1043             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, -ySlat41, -zSlat4 + dzCh4),
1044                                                 TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
1045         sprintf(idSlatCh7,"LC%d",3*kNslats4-2-i);
1046         detElemId = 726 - (i + kNslats4-1-6);
1047         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1048         if (detElemId % 2 == 1 && detElemId != 725 )
1049             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, -ySlat41, zSlat4 - dzCh4),
1050                                      TGeoRotation("rot4",90,180+angle,90,90+angle,180,0) );
1051         else
1052              GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, -ySlat41, zSlat4 - dzCh4),
1053                                      TGeoRotation("rot4",90,180+angle,90,270+angle,0,0) ); 
1054       }
1055
1056       sprintf(idSlatCh8,"LD%d",kNslats4-1+i);
1057       detElemId = 813 - (i + kNslats4-1-6);
1058       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1059       if (detElemId % 2 == 0)
1060           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, ySlat42, -zSlat4 + dzCh4),
1061                                    TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
1062       else
1063           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, ySlat42, -zSlat4 + dzCh4),
1064                                    TGeoRotation("rot5",90,angle,90,270+angle,180,0) ); 
1065
1066       sprintf(idSlatCh8,"LD%d",3*kNslats4-2+i);
1067       detElemId = 800 + (i + kNslats4-1-6);
1068       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1069       if (detElemId % 2 == 0)
1070           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, ySlat42, zSlat4 - dzCh4),
1071                                    TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
1072       else
1073           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, ySlat42, zSlat4 - dzCh4),
1074                                    TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) );
1075       if (i > 0) { 
1076         sprintf(idSlatCh8,"LD%d",kNslats4-1-i);
1077         detElemId = 813 + (i + kNslats4-1-6);
1078         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1079         if (detElemId % 2 == 0 && detElemId != 814)
1080             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, -ySlat42, -zSlat4 + dzCh4),
1081                                                 TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
1082         else
1083             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, -ySlat42, -zSlat4 + dzCh4),
1084                                                 TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
1085         sprintf(idSlatCh8,"LD%d",3*kNslats4-2-i);
1086         detElemId = 826 - (i + kNslats4-1-6);
1087         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1088         if (detElemId % 2 == 1 && detElemId != 825 )
1089             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, -ySlat42, zSlat4 - dzCh4),
1090                                      TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) ); 
1091         else
1092             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, -ySlat42, zSlat4 - dzCh4),
1093                                      TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) );
1094           
1095       }
1096     }
1097      
1098     // create the panel volume 
1099  
1100     gMC->Gsvolu("S07C","BOX",kCarbonMaterial,panelpar,3);
1101     gMC->Gsvolu("SD7C","BOX",kCarbonMaterial,panelpar,3);
1102     gMC->Gsvolu("S08C","BOX",kCarbonMaterial,panelpar,3);
1103     gMC->Gsvolu("SD8C","BOX",kCarbonMaterial,panelpar,3);
1104
1105     // create the nomex volume 
1106
1107     gMC->Gsvolu("S07N","BOX",kNomexMaterial,nomexpar,3);
1108     gMC->Gsvolu("SD7N","BOX",kNomexMaterial,nomexpar,3);
1109     gMC->Gsvolu("S08N","BOX",kNomexMaterial,nomexpar,3);
1110     gMC->Gsvolu("SD8N","BOX",kNomexMaterial,nomexpar,3);
1111
1112
1113     // create the nomex volume (bulk)
1114
1115     gMC->Gsvolu("S07X","BOX",kNomexBMaterial,nomexbpar,3);
1116     gMC->Gsvolu("SD7X","BOX",kNomexBMaterial,nomexbpar,3);
1117     gMC->Gsvolu("S08X","BOX",kNomexBMaterial,nomexbpar,3);
1118     gMC->Gsvolu("SD8X","BOX",kNomexBMaterial,nomexbpar,3);
1119
1120     // create the insulating material volume 
1121
1122     gMC->Gsvolu("S07I","BOX",kInsuMaterial,insupar,3);
1123     gMC->Gsvolu("SD7I","BOX",kInsuMaterial,insupar,3);
1124     gMC->Gsvolu("S08I","BOX",kInsuMaterial,insupar,3);
1125     gMC->Gsvolu("SD8I","BOX",kInsuMaterial,insupar,3);
1126
1127     // create the PCB volume 
1128
1129     gMC->Gsvolu("S07P","BOX",kPcbMaterial,pcbpar,3);
1130     gMC->Gsvolu("SD7P","BOX",kPcbMaterial,pcbpar,3);
1131     gMC->Gsvolu("S08P","BOX",kPcbMaterial,pcbpar,3);
1132     gMC->Gsvolu("SD8P","BOX",kPcbMaterial,pcbpar,3);
1133  
1134     // create the sensitive volumes,
1135
1136     gMC->Gsvolu("S07G","BOX",kSensMaterial,dum,0);
1137     gMC->Gsvolu("SD7G","BOX",kSensMaterial,senspar,3);
1138     gMC->Gsvolu("S08G","BOX",kSensMaterial,dum,0);
1139     gMC->Gsvolu("SD8G","BOX",kSensMaterial,senspar,3);
1140
1141     // create the vertical frame volume 
1142
1143     gMC->Gsvolu("S07V","BOX",kVframeMaterial,vFramepar,3);
1144     gMC->Gsvolu("S08V","BOX",kVframeMaterial,vFramepar,3);
1145
1146     // create the rounded vertical frame volume 
1147
1148     gMC->Gsvolu("SD7D","TUBS",kRframeMaterial,rFramepar4,5);
1149     gMC->Gsvolu("SD8D","TUBS",kRframeMaterial,rFramepar4,5);
1150     
1151     // create the horizontal frame volume 
1152
1153     gMC->Gsvolu("S07H","BOX",kHframeMaterial,hFramepar,3);
1154     gMC->Gsvolu("SD7H","BOX",kHframeMaterial,hFramepar,3);
1155     gMC->Gsvolu("S08H","BOX",kHframeMaterial,hFramepar,3);
1156     gMC->Gsvolu("SD8H","BOX",kHframeMaterial,hFramepar,3);
1157
1158     // create the horizontal border volume 
1159
1160     gMC->Gsvolu("S07B","BOX",kBframeMaterial,bFramepar,3);
1161     gMC->Gsvolu("SD7B","BOX",kBframeMaterial,bFramepar,3);
1162     gMC->Gsvolu("S08B","BOX",kBframeMaterial,bFramepar,3);
1163     gMC->Gsvolu("SD8B","BOX",kBframeMaterial,bFramepar,3);
1164
1165     // Replace the volume shape with a composite shape
1166     // with substracted overlap with beam shield     
1167     if ( gMC->IsRootGeometrySupported() ) { 
1168         
1169       // Get shape
1170       Int_t nSlatType = 1;
1171       Int_t nVol = 8;
1172       char slatType[2] = "D"; // D: Rounded slat
1173       char volLetter[9] = "CNXIPHBG";
1174       char volName[5] = "SD7C";
1175       char compName[14] = "SD7C";
1176       char csName[16] = "rounded4SlatD7C";
1177       TGeoVolume *mVol = 0x0;
1178       // Beam shield recess
1179       //      TGeoTube *tube4Cut = new TGeoTube("tube4Cut", 0., AliMUONConstants::Rmin(3), kSlatWidth/2.+0.001);
1180       new TGeoTube("tube4Cut", 0., AliMUONConstants::Rmin(3), kSlatWidth/2.+0.001);
1181       TGeoShape *rounded4Slat[nSlatType*((nVol+1)*2)];  
1182       // Displacement
1183       TGeoTranslation* trDTube4 = new TGeoTranslation("trDTube4", -(kPcbLength+kVframeLength)/2., -kYpos41[1], 0.);
1184       trDTube4->RegisterYourself();
1185       TGeoShape *composite4[nSlatType*((nVol+1)*2)];
1186       //      TGeoBBox *box4DCut = new TGeoBBox("box4DCut",(kPcbLength+kVframeLength)/2., hFramepar[1], vFramepar[2]+0.001);
1187       new TGeoBBox("box4DCut",(kPcbLength+kVframeLength)/2., hFramepar[1], vFramepar[2]+0.001);
1188       // Displacement
1189       TGeoTranslation* trDBox4 = new TGeoTranslation("trDBox4",kPcbLength/2., kYpos41[1], 0.);
1190       trDBox4->RegisterYourself();      
1191
1192       TGeoBBox *box4Vframe = new TGeoBBox("box4Vframe",vFramepar[0],vrFrameHeight/2., vFramepar[2]);
1193       TGeoTranslation* trVBox4 = new TGeoTranslation("trVBox4", 0., AliMUONConstants::Rmin(3)-kRframeLength + box4Vframe->GetDY(), 0.);
1194       trVBox4->RegisterYourself();
1195       
1196       for(int iCh=7; iCh<=8; iCh++){
1197         for (int iSlatType = 0; iSlatType<nSlatType; iSlatType++) {
1198           for (int iVol = 0; iVol<nVol; iVol++){
1199             Int_t lIndex = (iCh-7)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+iVol;
1200             sprintf(volName,"S%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
1201             mVol = gGeoManager->FindVolumeFast(volName);
1202             if ( !mVol ) {
1203               AliErrorStream() 
1204                 << "Slat volume " << volName << " not found" << endl;    
1205             }
1206             else {
1207               rounded4Slat[lIndex] = mVol->GetShape();
1208               sprintf(csName,"rounded4Slat%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
1209               rounded4Slat[lIndex]->SetName(csName);              
1210               
1211               // Composite shape
1212               TString compOperation(csName);
1213               compOperation+="-tube4Cut:tr";
1214               compOperation+=slatType[iSlatType];
1215               compOperation+="Tube4";
1216               if (strstr(volName,"B")){
1217                 // Displacement
1218                 Float_t posXb = 0.;
1219                 Float_t posYb = -( kPcbHeight - kBframeHeight ) / 2.;
1220                 Float_t posZb = 0.;
1221                 TGeoTranslation* trB = new TGeoTranslation("trB", posXb, posYb, posZb);
1222                 trB->RegisterYourself();
1223                 compOperation.ReplaceAll("-tube4Cut",":trB-tube4Cut");
1224               }
1225               sprintf(compName,"composite4%d%c",iCh,volLetter[iVol]);
1226               composite4[lIndex] = new TGeoCompositeShape(compName, compOperation.Data()); 
1227               
1228               // Reset shape to volume      
1229               mVol->SetShape(composite4[lIndex]);
1230             }
1231           }
1232
1233           // For rounded spacer
1234           Int_t lIndex = (iCh-7)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+nVol;
1235           sprintf(volName,"S%c%dD",slatType[iSlatType],iCh);
1236           mVol = gGeoManager->FindVolumeFast(volName);
1237           if ( !mVol ) {
1238             AliErrorStream() 
1239               << "Slat volume " << volName << " not found" << endl;      
1240           }
1241           else {
1242             rounded4Slat[lIndex] = mVol->GetShape();
1243             sprintf(csName,"rounded4Slat%c%dD",slatType[iSlatType],iCh);
1244             rounded4Slat[lIndex]->SetName(csName);                
1245             
1246             // Composite shape
1247             TString compOperation(csName);
1248             if (strstr(volName,"SD")){
1249               compOperation.Prepend("(");
1250               compOperation+="+box4Vframe:trVBox4)*box4DCut:trDBox4";
1251             }
1252             sprintf(compName,"composite4%c%dD",slatType[iSlatType],iCh);
1253             composite4[lIndex] = new TGeoCompositeShape(compName, compOperation.Data());              
1254             // Reset shape to volume      
1255             mVol->SetShape(composite4[lIndex]);
1256           }
1257         }
1258       }
1259     }
1260
1261
1262     index = 0; 
1263     for (i = 0; i < kNslats4; i++){
1264       for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
1265
1266         if (i == 0 && quadrant == 2) continue;
1267         if (i == 0 && quadrant == 4) continue;
1268
1269         sprintf(idSlatCh7,"LC%d",ConvertSlatNum(i,quadrant,kNslats4-1));
1270         sprintf(idSlatCh8,"LD%d",ConvertSlatNum(i,quadrant,kNslats4-1));
1271         Int_t moduleSlatCh7 = GetModuleId(idSlatCh7);
1272         Int_t moduleSlatCh8 = GetModuleId(idSlatCh8);
1273
1274         Float_t xvFrame  = (slatLength4[i] - kVframeLength)/2.;
1275
1276         // position the vertical frames 
1277         if (i != 1) { 
1278           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1279           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1280           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1281           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1282         } else { // Vertical and Rounded+Vertical spacer 
1283           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1284           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7D", idSlatCh7, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos41[1],0.));
1285           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1286           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8D", idSlatCh8, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos42[1],0.));
1287         }
1288         // position the panels and the insulating material 
1289         for (j = 0; j < kNPCB4[i]; j++){
1290           index++;
1291           Float_t xx = kSensLength * (-kNPCB4[i]/2.+j+.5); 
1292           Float_t zPanel = spar[2] - nomexbpar[2]; 
1293           if (i==1 && j==0){ // Rounded pcb of rounded slat
1294             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7X", idSlatCh7, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1295             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7X", idSlatCh7, 2*index,TGeoTranslation(xx,0.,-zPanel));
1296             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7I", idSlatCh7, index,TGeoTranslation(xx,0.,0.));
1297             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8X", idSlatCh8, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1298             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8X", idSlatCh8, 2*index,TGeoTranslation(xx,0.,-zPanel));
1299             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8I", idSlatCh8, index,TGeoTranslation(xx,0.,0.));
1300           } else {            
1301             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07X", idSlatCh7, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1302             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07X", idSlatCh7, 2*index,TGeoTranslation(xx,0.,-zPanel));
1303             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07I", idSlatCh7, index,TGeoTranslation(xx,0.,0.));
1304             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08X", idSlatCh8, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1305             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08X", idSlatCh8, 2*index,TGeoTranslation(xx,0.,-zPanel));
1306             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08I", idSlatCh8, index,TGeoTranslation(xx,0.,0.));
1307           }
1308         }
1309       } 
1310     }
1311
1312     // position the nomex volume inside the panel volume
1313     gMC->Gspos("S07N",1,"S07C",0.,0.,0.,0,"ONLY"); 
1314     gMC->Gspos("SD7N",1,"SD7C",0.,0.,0.,0,"ONLY"); 
1315     gMC->Gspos("S08N",1,"S08C",0.,0.,0.,0,"ONLY"); 
1316     gMC->Gspos("SD8N",1,"SD8C",0.,0.,0.,0,"ONLY"); 
1317
1318     // position panel volume inside the bulk nomex material volume
1319     gMC->Gspos("S07C",1,"S07X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1320     gMC->Gspos("SD7C",1,"SD7X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1321     gMC->Gspos("S08C",1,"S08X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1322     gMC->Gspos("SD8C",1,"SD8X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1323
1324     // position the PCB volume inside the insulating material volume
1325     gMC->Gspos("S07P",1,"S07I",0.,0.,0.,0,"ONLY"); 
1326     gMC->Gspos("SD7P",1,"SD7I",0.,0.,0.,0,"ONLY"); 
1327     gMC->Gspos("S08P",1,"S08I",0.,0.,0.,0,"ONLY"); 
1328     gMC->Gspos("SD8P",1,"SD8I",0.,0.,0.,0,"ONLY"); 
1329
1330     // position the horizontal frame volume inside the PCB volume
1331     gMC->Gspos("S07H",1,"S07P",0.,0.,0.,0,"ONLY"); 
1332     gMC->Gspos("SD7H",1,"SD7P",0.,0.,0.,0,"ONLY"); 
1333     gMC->Gspos("S08H",1,"S08P",0.,0.,0.,0,"ONLY"); 
1334     gMC->Gspos("SD8H",1,"SD8P",0.,0.,0.,0,"ONLY"); 
1335
1336     // position the sensitive volume inside the horizontal frame volume
1337     gMC->Gsposp("S07G",1,"S07H",0.,0.,0.,0,"ONLY",senspar,3); 
1338     gMC->Gspos("SD7G",1,"SD7H",0.,0.,0.,0,"ONLY"); 
1339     gMC->Gsposp("S08G",1,"S08H",0.,0.,0.,0,"ONLY",senspar,3); 
1340     gMC->Gspos("SD8G",1,"SD8H",0.,0.,0.,0,"ONLY"); 
1341
1342     // position the border volumes inside the PCB volume
1343     Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
1344     gMC->Gspos("S07B",1,"S07P",0., yborder,0.,0,"ONLY"); 
1345     gMC->Gspos("S07B",2,"S07P",0.,-yborder,0.,0,"ONLY");
1346     gMC->Gspos("SD7B",1,"SD7P",0., 0.,0.,0,"ONLY"); 
1347     gMC->Gspos("S07B",1,"SD7P",0., yborder,0.,0,"ONLY"); 
1348     gMC->Gspos("S08B",1,"S08P",0., yborder,0.,0,"ONLY"); 
1349     gMC->Gspos("S08B",2,"S08P",0.,-yborder,0.,0,"ONLY"); 
1350     gMC->Gspos("SD8B",1,"SD8P",0., 0.,0.,0,"ONLY"); 
1351     gMC->Gspos("S08B",1,"SD8P",0., yborder,0.,0,"ONLY"); 
1352
1353     // create the NULOC volume and position it in the horizontal frame
1354
1355     gMC->Gsvolu("S07E","BOX",kNulocMaterial,nulocpar,3);
1356     gMC->Gsvolu("S08E","BOX",kNulocMaterial,nulocpar,3);
1357     index = 0;
1358     Float_t rPhi3 = TMath::ASin((kYpos41[1]-kPcbHeight/2.)/AliMUONConstants::Rmin(3));
1359     Float_t xxmax4 = (AliMUONConstants::Rmin(3)*TMath::Cos(rPhi3)-kVframeLength/2.) - (kBframeLength - kNulocLength)/2.;
1360     for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
1361       index++; 
1362       gMC->Gspos("S07E",2*index-1,"S07B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
1363       gMC->Gspos("S07E",2*index  ,"S07B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
1364       gMC->Gspos("S08E",2*index-1,"S08B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
1365       gMC->Gspos("S08E",2*index  ,"S08B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
1366     }
1367     if (xx > xxmax4 && xx< xxmax) {
1368       gMC->Gspos("S07E",2*index-1,"SD7B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
1369       gMC->Gspos("S07E",2*index  ,"SD7B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
1370       gMC->Gspos("S08E",2*index-1,"SD8B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
1371       gMC->Gspos("S08E",2*index  ,"SD8B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
1372     }
1373
1374     //
1375     //Geometry of the support pannel Verticla length 5.3m, horizontal length 2.6m, internal radius  dMotherInner o SC07 and SC08  (F. Orsini, Saclay)
1376     //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
1377     Float_t dMotherInner =  AliMUONConstants::Rmin(3)-kRframeHeight; 
1378     Float_t nomexthickness = 1.5;
1379     Float_t carbonthickness = 0.03;
1380     Float_t supporthlength =  260.;  
1381     Float_t supportvlength =  530.;  
1382     // Generating the composite shape of the carbon and nomex pannels
1383     new TGeoBBox("shNomexBoxSt4",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
1384     new TGeoBBox("shCarbonBoxSt4",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
1385     new TGeoTubeSeg("shNomexHoleSt4",0., dMotherInner, nomexthickness/2.+carbonthickness+3*kCableWidth+0.001, -90. ,90.);
1386     new TGeoTubeSeg("shCarbonHoleSt4",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
1387     TGeoTranslation* trHoleSt4 = new TGeoTranslation("trHoleSt4",-supporthlength/2.,0.,0.); 
1388     trHoleSt4->RegisterYourself();
1389     TGeoCompositeShape* shNomexSupportSt4  = new TGeoCompositeShape("shNomexSupportSt4","shNomexBoxSt4-shNomexHoleSt4:trHoleSt4");
1390     TGeoCompositeShape* shCarbonSupportSt4 = new TGeoCompositeShape("shCarbonSupportSt4","shCarbonBoxSt4-shCarbonHoleSt4:trHoleSt4");
1391  
1392    // Generating Nomex and Carbon pannel volumes
1393     TGeoVolume* voNomexSupportSt4   = new TGeoVolume("S07S", shNomexSupportSt4, kMedNomex);
1394     TGeoVolume* voCarbonSupportSt4  = new TGeoVolume("S07K", shCarbonSupportSt4, kMedCarbon);
1395     TGeoVolume* voNomexSupportSt4Ch8   = new TGeoVolume("S08S", shNomexSupportSt4, kMedNomex);
1396     TGeoVolume* voCarbonSupportSt4Ch8  = new TGeoVolume("S08K", shCarbonSupportSt4, kMedCarbon);
1397     TGeoTranslation* trCarbon1St4   = new TGeoTranslation("trCarbon1St4",0.,0., -(nomexthickness+carbonthickness)/2.);
1398     TGeoTranslation* trCarbon2St4   = new TGeoTranslation("trCarbon2St4",0.,0.,  (nomexthickness+carbonthickness)/2.);
1399     voNomexSupportSt4->AddNode(voCarbonSupportSt4,1,trCarbon1St4);
1400     voNomexSupportSt4->AddNode(voCarbonSupportSt4,2,trCarbon2St4);
1401     voNomexSupportSt4Ch8->AddNode(voCarbonSupportSt4Ch8,1,trCarbon1St4);
1402     voNomexSupportSt4Ch8->AddNode(voCarbonSupportSt4Ch8,2,trCarbon2St4);
1403  
1404     // Add readout cables
1405     gMC->Gsvolu("S07L","BOX",kCableMaterial,dum,0);
1406     gMC->Gsvolu("S08L","BOX",kCableMaterial,dum,0);
1407
1408     ySlat41 = 0.;
1409     ySlat42 = 0.;
1410     Float_t lCableX = 0.;
1411     Float_t lCableY = 0.;
1412     Float_t lCableY8 = 0.;
1413     Float_t lCableZ = 0.;
1414     Float_t cablepar[3] = {supporthlength/2., kCableHeight/2., kCableWidth/2.};
1415     Float_t lCableDY = 0.;
1416     Float_t lCableDY8 = 0.;
1417     for (i = 0; i<kNslats4; i++){
1418       Int_t iCable = 1;
1419       Int_t cIndex = 0;
1420       Int_t cIndex8 = 0;
1421       ySlat41 += kYpos41[i];
1422       ySlat42 += kYpos42[i];
1423
1424       lCableY = ySlat41;
1425       lCableY8 = ySlat42;
1426
1427       // Cables going out from the start of slat
1428       if(kNPCB4[i]>=4){ // Only if 4 or more pcb
1429         // First top cables
1430         cablepar[0] = (supporthlength-kXpos4[i])/2.;
1431         lCableX = kXpos4[i]/2.;
1432         lCableDY = (kYpos41[i+1]+kYpos41[i+2])/2.-cablepar[1];
1433         lCableDY8 = (kYpos42[i+1]+kYpos42[i+2])/2.-cablepar[1];
1434         lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
1435         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);  
1436         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
1437         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8+lCableDY8,lCableZ,0,"ONLY",cablepar,3);       
1438         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8+lCableDY8),lCableZ,0,"ONLY",cablepar,3);
1439         // Then bottom cables
1440         if (i>0){
1441           if (i==1) { // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
1442             cablepar[0] = (supporthlength-kXpos4[i]-dMotherInner)/2.;
1443             lCableX = (kXpos4[i]+dMotherInner)/2.;
1444             lCableDY = (kYpos41[i]+kYpos41[i])/2.-cablepar[1];
1445             lCableDY8 = (kYpos42[i]+kYpos42[i])/2.-cablepar[1];
1446           }
1447           if (i>=2) {
1448             lCableDY = (kYpos41[i]+kYpos41[i-1])/2.-cablepar[1];
1449             if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
1450               lCableDY = lCableY - dMotherInner - cablepar[1];
1451             }
1452             lCableDY8 = (kYpos42[i]+kYpos42[i-1])/2.-cablepar[1];
1453             if ((lCableY8-lCableDY8)<(dMotherInner+cablepar[1])){
1454               lCableDY8 = lCableY8 - dMotherInner - cablepar[1];
1455             }
1456           }
1457           gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
1458           gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
1459           gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8-lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
1460           gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8-lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
1461         }
1462       }
1463
1464       // Rounded slats have an extra cable starting at second pcb
1465       if(i==1){ 
1466         // Only on top
1467         cablepar[0] = (supporthlength-kPcbLength-kVframeLength)/2.;
1468         lCableX = (kPcbLength+kVframeLength)/2.;
1469         lCableDY = (kYpos41[i+1]+kYpos41[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
1470         lCableDY8 = (kYpos42[i+1]+kYpos42[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
1471         lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
1472         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
1473         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
1474         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8+lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
1475         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8+lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
1476       } 
1477
1478       // Cables going out from the end of the slats
1479       cablepar[0] = (supporthlength-(slatLength4[i]+kXpos4[i]+kDslatLength)+kVframeLength)/2.;
1480       lCableX = slatLength4[i]+kXpos4[i]-kVframeLength+kDslatLength+cablepar[0]-supporthlength/2.;
1481       if(i+1>=kNslats4 || i+2>=kNslats4){ // If no more higher slats, then use distance to lower slat
1482         lCableDY = kPcbHeight/2.+cablepar[1];
1483         lCableDY8 = lCableDY;
1484       }
1485       else {
1486         lCableDY = (kYpos41[i+1]+kYpos41[i+2])/2.-cablepar[1];
1487         lCableDY8 = (kYpos42[i+1]+kYpos42[i+2])/2.-cablepar[1];
1488       }
1489       lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
1490       gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
1491       gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
1492       gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8+lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
1493       gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8+lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
1494       // Then bottom cables
1495       if(i>0){
1496         if (i==1) {
1497           lCableDY = (kYpos41[i]+kYpos41[i])/2.-cablepar[1];
1498           lCableDY8 = (kYpos42[i]+kYpos42[i])/2.-cablepar[1];
1499         }
1500         else{
1501           lCableDY = (kYpos41[i]+kYpos41[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
1502           if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
1503             lCableDY = lCableY - dMotherInner - cablepar[1];
1504           }
1505           lCableDY8 = (kYpos42[i]+kYpos42[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
1506           if ((lCableY8-lCableDY8)<(dMotherInner+cablepar[1])){
1507             lCableDY8 = lCableY8 - dMotherInner - cablepar[1];
1508           }
1509         }
1510         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
1511         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
1512         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8-lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
1513         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8-lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
1514       } 
1515     }
1516     
1517     Float_t dzCh7  = dzCh;
1518     TGeoTranslation* trSupport1St4   = new TGeoTranslation("trSupport1St4", supporthlength/2., 0. , dzCh7);
1519     TGeoRotation*    roSupportSt4    = new TGeoRotation("roSupportSt4",90.,180.,-90.);
1520     TGeoCombiTrans*  coSupport2St4   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh7, roSupportSt4); 
1521     GetEnvelopes(9)->AddEnvelope("S07S", 0, 1, *trSupport1St4);  
1522     GetEnvelopes(8)->AddEnvelope("S07S", 0, 2, *coSupport2St4);  
1523     GetEnvelopes(11)->AddEnvelope("S08S", 0, 1, *trSupport1St4);   
1524     GetEnvelopes(10)->AddEnvelope("S08S", 0, 2, *coSupport2St4);
1525
1526     // End of pannel support geometry    
1527
1528     // cout << "Geometry for Station 4...... done" << endl;
1529
1530   }
1531     
1532   if (fStations[4]) {
1533       
1534
1535     // //********************************************************************
1536     // //                            Station 5                             **
1537     // //********************************************************************
1538     // Mother volume for each chamber in St4 is an envelop (or assembly)
1539     // There is one assembly mother per half a chamber  called SC09I, SC09O, SC10I and SC10O 
1540     // Same volume name definitions as in St3
1541     
1542     const Int_t   kNslats5         = 7;  // number of slats per quadrant
1543     const Int_t   kNPCB5[kNslats5] = {5, 6, 6, 6, 5, 4, 3}; // n PCB per slat
1544     const Float_t kXpos5[kNslats5] = {38.75, 0., 0., 0., 0., 0., 0.}; // J.C. Correct value  
1545     const Float_t kYpos5[kNslats5] = {0., 38.2, 37.9, 37.6, 37.3, 37.05, 36.75};
1546     Float_t slatLength5[kNslats5]; 
1547
1548     Float_t rPhi1 = TMath::RadToDeg()*(TMath::ASin((kYpos5[1]-hFramepar[1])/(AliMUONConstants::Rmin(4))));
1549     Float_t rPhi2 = TMath::RadToDeg()*(TMath::ACos(-vFramepar[0]/(AliMUONConstants::Rmin(4)-kRframeLength)));
1550     Float_t rFramepar5[5] = { AliMUONConstants::Rmin(4)-kRframeLength, AliMUONConstants::Rmin(4), kRframeWidth, rPhi1, rPhi2}; 
1551     Float_t vrFrameHeight = hFramepar[1]+kYpos5[1]-AliMUONConstants::Rmin(4)+kRframeLength;
1552
1553     char idSlatCh9[5];
1554     char idSlatCh10[5];
1555     Float_t xSlat5;
1556     Float_t ySlat5 = 0;
1557     angle = 0.;
1558
1559     for (i = 0; i < kNslats5; i++){
1560
1561       slatLength5[i] = kPcbLength * kNPCB5[i] + 2.* kVframeLength; 
1562       xSlat5 = slatLength5[i]/2. + kDslatLength + kXpos5[i]; 
1563       ySlat5 += kYpos5[i];
1564
1565       spar[0] = slatLength5[i]/2.; 
1566       spar[1] = kSlatHeight/2.;
1567       spar[2] = kSlatWidth/2.; 
1568
1569       Float_t dzCh5  = dzCh;
1570       Float_t zSlat5 = (i%2 ==0)? -zSlat : zSlat; 
1571
1572       sprintf(idSlatCh9,"LE%d",kNslats5-1+i);
1573       detElemId = 913 - (i + kNslats5-1-6);
1574       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1575       if (detElemId % 2 == 0)
1576           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1577                                               TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
1578       else
1579           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1580                                               TGeoRotation("rot1",90,angle,90,270+angle,180,0) );
1581       sprintf(idSlatCh9,"LE%d",3*kNslats5-2+i);
1582       detElemId = 900 + (i + kNslats5-1-6);
1583       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1584       if (detElemId % 2 == 0)
1585           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1586                                               TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );
1587       else
1588           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1589                                               TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
1590       if (i > 0) { 
1591         sprintf(idSlatCh9,"LE%d",kNslats5-1-i);
1592         detElemId = 913 + (i + kNslats5-1-6);
1593         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1594       if (detElemId % 2 == 0  && detElemId != 914)
1595           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1596                                      TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
1597       else
1598           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1599                                      TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
1600         sprintf(idSlatCh9,"LE%d",3*kNslats5-2-i);
1601         detElemId = 926 - (i + kNslats5-1-6);
1602         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1603         if (detElemId % 2 == 1 && detElemId != 925 )
1604             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1605                                                 TGeoRotation("rot4",90,180+angle,90,90+angle,180,0)  );
1606         else
1607             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1608                                                 TGeoRotation("rot4",90,180+angle,90,270+angle,0,0)  );   
1609       }
1610
1611       sprintf(idSlatCh10,"LF%d",kNslats5-1+i);
1612       detElemId = 1013 - (i + kNslats5-1-6);
1613       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1614       if (detElemId % 2 == 0)
1615           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1616                                               TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
1617       else
1618           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1619                                               TGeoRotation("rot5",90,angle,90,270+angle,180,0) );
1620
1621       sprintf(idSlatCh10,"LF%d",3*kNslats5-2+i);
1622       detElemId = 1000 + (i + kNslats5-1-6);
1623       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1624       if (detElemId % 2 == 0)
1625           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1626                                               TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
1627       else
1628           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1629                                               TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) ); 
1630       if (i > 0) { 
1631         sprintf(idSlatCh10,"LF%d",kNslats5-1-i);
1632         detElemId = 1013 + (i + kNslats5-1-6);
1633         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1634       if (detElemId % 2 == 0  && detElemId != 1014)
1635           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1636                                      TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
1637       else
1638           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1639                                      TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
1640         sprintf(idSlatCh10,"LF%d",3*kNslats5-2-i);
1641         detElemId = 1026 - (i + kNslats5-1-6);
1642         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1643         if (detElemId % 2 == 1 && detElemId != 1025 )
1644             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1645                                               TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) );
1646         else
1647             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1648                                               TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) ); 
1649       }
1650     }
1651
1652     // create the panel volume 
1653  
1654     gMC->Gsvolu("S09C","BOX",kCarbonMaterial,panelpar,3);
1655     gMC->Gsvolu("SD9C","BOX",kCarbonMaterial,panelpar,3);
1656     gMC->Gsvolu("S10C","BOX",kCarbonMaterial,panelpar,3);
1657     gMC->Gsvolu("SD0C","BOX",kCarbonMaterial,panelpar,3);
1658
1659     // create the nomex volume 
1660
1661     gMC->Gsvolu("S09N","BOX",kNomexMaterial,nomexpar,3);
1662     gMC->Gsvolu("SD9N","BOX",kNomexMaterial,nomexpar,3);
1663     gMC->Gsvolu("S10N","BOX",kNomexMaterial,nomexpar,3);
1664     gMC->Gsvolu("SD0N","BOX",kNomexMaterial,nomexpar,3);
1665
1666
1667     // create the nomex volume (bulk)
1668
1669     gMC->Gsvolu("S09X","BOX",kNomexBMaterial,nomexbpar,3);
1670     gMC->Gsvolu("SD9X","BOX",kNomexBMaterial,nomexbpar,3);
1671     gMC->Gsvolu("S10X","BOX",kNomexBMaterial,nomexbpar,3);
1672     gMC->Gsvolu("SD0X","BOX",kNomexBMaterial,nomexbpar,3);
1673
1674     // create the insulating material volume 
1675
1676     gMC->Gsvolu("S09I","BOX",kInsuMaterial,insupar,3);
1677     gMC->Gsvolu("SD9I","BOX",kInsuMaterial,insupar,3);
1678     gMC->Gsvolu("S10I","BOX",kInsuMaterial,insupar,3);
1679     gMC->Gsvolu("SD0I","BOX",kInsuMaterial,insupar,3);
1680
1681     // create the PCB volume 
1682
1683     gMC->Gsvolu("S09P","BOX",kPcbMaterial,pcbpar,3);
1684     gMC->Gsvolu("SD9P","BOX",kPcbMaterial,pcbpar,3);
1685     gMC->Gsvolu("S10P","BOX",kPcbMaterial,pcbpar,3);
1686     gMC->Gsvolu("SD0P","BOX",kPcbMaterial,pcbpar,3);
1687  
1688     // create the sensitive volumes,
1689
1690     gMC->Gsvolu("S09G","BOX",kSensMaterial,dum,0);
1691     gMC->Gsvolu("SD9G","BOX",kSensMaterial,senspar,3);
1692     gMC->Gsvolu("S10G","BOX",kSensMaterial,dum,0);
1693     gMC->Gsvolu("SD0G","BOX",kSensMaterial,senspar,3);
1694
1695     // create the vertical frame volume 
1696
1697     gMC->Gsvolu("S09V","BOX",kVframeMaterial,vFramepar,3);
1698     gMC->Gsvolu("S10V","BOX",kVframeMaterial,vFramepar,3);
1699
1700     // create the rounded vertical frame volume 
1701
1702     gMC->Gsvolu("SD9D","TUBS",kRframeMaterial,rFramepar5,5);
1703     gMC->Gsvolu("SD0D","TUBS",kRframeMaterial,rFramepar5,5);
1704
1705     // create the horizontal frame volume 
1706
1707     gMC->Gsvolu("S09H","BOX",kHframeMaterial,hFramepar,3);
1708     gMC->Gsvolu("SD9H","BOX",kHframeMaterial,hFramepar,3);
1709     gMC->Gsvolu("S10H","BOX",kHframeMaterial,hFramepar,3);
1710     gMC->Gsvolu("SD0H","BOX",kHframeMaterial,hFramepar,3);
1711
1712     // create the horizontal border volume 
1713
1714     gMC->Gsvolu("S09B","BOX",kBframeMaterial,bFramepar,3);
1715     gMC->Gsvolu("SD9B","BOX",kBframeMaterial,bFramepar,3);
1716     gMC->Gsvolu("S10B","BOX",kBframeMaterial,bFramepar,3);
1717     gMC->Gsvolu("SD0B","BOX",kBframeMaterial,bFramepar,3);
1718
1719     // Replace the volume shape with a composite shape
1720     // with substracted overlap with beam shield     
1721     if ( gMC->IsRootGeometrySupported() ) { 
1722         
1723       // Get shape
1724       Int_t nSlatType = 1;
1725       Int_t nVol = 8;
1726       char slatType[2] = "D"; // D: Rounde slat
1727       char volLetter[9] = "CNXIPHBG";
1728       char volName[5] = "SD9D";
1729       char compName[14] = "SD9D";
1730       char csName[16] = "rounded5SlatD9D";
1731       TGeoVolume *mVol = 0x0;
1732       // Beam shield recess
1733       //      TGeoTube *tube5Cut = new TGeoTube("tube5Cut", 0., AliMUONConstants::Rmin(4), kSlatWidth/2.+0.001);
1734       new TGeoTube("tube5Cut", 0., AliMUONConstants::Rmin(4), kSlatWidth/2.+0.001);
1735       TGeoShape *rounded5Slat[nSlatType*((nVol+1)*2)];  
1736       // Displacement
1737       TGeoTranslation* trDTube5 = new TGeoTranslation("trDTube5", -(kPcbLength+kVframeLength)/2., -kYpos5[1], 0.);
1738       trDTube5->RegisterYourself();
1739       TGeoShape *composite5[nSlatType*((nVol+1)*2)];
1740       //      TGeoBBox *box5DCut = new TGeoBBox("box5DCut",(kPcbLength+kVframeLength)/2., hFramepar[1], vFramepar[2]+0.001);
1741       new TGeoBBox("box5DCut",(kPcbLength+kVframeLength)/2., hFramepar[1], vFramepar[2]+0.001);
1742       // Displacement
1743       TGeoTranslation* trDBox5 = new TGeoTranslation("trDBox5",kPcbLength/2., kYpos5[1], 0.);
1744       trDBox5->RegisterYourself();
1745       
1746       TGeoBBox *box5Vframe = new TGeoBBox("box5Vframe",vFramepar[0],vrFrameHeight/2., vFramepar[2]);
1747       TGeoTranslation* trVBox5 = new TGeoTranslation("trVBox5", 0., AliMUONConstants::Rmin(4)-kRframeLength + box5Vframe->GetDY(), 0.);
1748       trVBox5->RegisterYourself();
1749       
1750       for(int iCh=9; iCh<=10; iCh++){
1751         for (int iSlatType = 0; iSlatType<nSlatType; iSlatType++) {
1752           for (int iVol = 0; iVol<nVol; iVol++){
1753             Int_t lIndex = (iCh-9)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+iVol;
1754             sprintf(volName,"S%c%d%c",slatType[iSlatType],iCh%10,volLetter[iVol]);
1755             mVol = gGeoManager->FindVolumeFast(volName);
1756             if ( !mVol ) {
1757               AliErrorStream() 
1758                 << "Slat volume " << volName << " not found" << endl;    
1759             }
1760             else {
1761               rounded5Slat[lIndex] = mVol->GetShape();
1762               sprintf(csName,"rounded5Slat%c%d%c",slatType[iSlatType],iCh%10,volLetter[iVol]);
1763               rounded5Slat[lIndex]->SetName(csName);              
1764               
1765               // Composite shape
1766               TString compOperation(csName);
1767               compOperation+="-tube5Cut:tr";
1768               compOperation+=slatType[iSlatType];
1769               compOperation+="Tube5";
1770               if (strstr(volName,"B")){
1771                 // Displacement
1772                 TGeoTranslation* trB = new TGeoTranslation("trB", 0., -(kPcbHeight - kBframeHeight)/2., 0.);
1773                 trB->RegisterYourself();
1774                 compOperation.ReplaceAll("-tube5Cut",":trB-tube5Cut");
1775               }
1776               sprintf(compName,"composite5%d%c",iCh,volLetter[iVol]);
1777               composite5[lIndex] = new TGeoCompositeShape(compName, compOperation.Data()); 
1778               
1779               // Reset shape to volume      
1780               mVol->SetShape(composite5[lIndex]);
1781             }
1782           }
1783
1784           // For rounded spacer
1785           Int_t lIndex = (iCh-9)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+nVol;
1786           sprintf(volName,"S%c%dD",slatType[iSlatType],iCh%10);
1787           mVol = gGeoManager->FindVolumeFast(volName);
1788           if ( !mVol ) {
1789             AliErrorStream() 
1790               << "Slat volume " << volName << " not found" << endl;      
1791           }
1792           else {
1793             rounded5Slat[lIndex] = mVol->GetShape();
1794             sprintf(csName,"rounded5Slat%c%dD",slatType[iSlatType],iCh%10);
1795             rounded5Slat[lIndex]->SetName(csName);                
1796             
1797             // Composite shape
1798             TString compOperation(csName);
1799             if (strstr(volName,"SD")){
1800               compOperation.Prepend("(");
1801               compOperation+="+box5Vframe:trVBox5)*box5DCut:trDBox5";
1802             }
1803             sprintf(compName,"composite5%c%dD",slatType[iSlatType],iCh%10);
1804             composite5[lIndex] = new TGeoCompositeShape(compName, compOperation.Data());              
1805             // Reset shape to volume      
1806             mVol->SetShape(composite5[lIndex]);
1807           }
1808         }
1809       }
1810     }
1811     
1812     index = 0; 
1813     for (i = 0; i < kNslats5; i++){
1814       for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
1815
1816         if (i == 0 && quadrant == 2) continue;
1817         if (i == 0 && quadrant == 4) continue;
1818
1819         sprintf(idSlatCh9,"LE%d",ConvertSlatNum(i,quadrant,kNslats5-1));
1820         sprintf(idSlatCh10,"LF%d",ConvertSlatNum(i,quadrant,kNslats5-1));
1821         Int_t moduleSlatCh9 = GetModuleId(idSlatCh9);
1822         Int_t moduleSlatCh10 = GetModuleId(idSlatCh10);
1823         Float_t xvFrame  = (slatLength5[i] - kVframeLength)/2.; // ok
1824
1825         // position the vertical frames (spacers)
1826         if (i != 1) { 
1827           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1828           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1829           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1830           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1831         } else {  // Vertical and Rounded+Vertical spacer
1832           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1833           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9D", idSlatCh9, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos5[1],0.));
1834           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1835           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0D", idSlatCh10, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos5[1],0.));
1836         }
1837
1838         // position the panels and the insulating material 
1839         for (j = 0; j < kNPCB5[i]; j++){
1840           index++;
1841           Float_t xx = kSensLength * (-kNPCB5[i]/2.+j+.5); 
1842
1843           Float_t zPanel = spar[2] - nomexbpar[2]; 
1844           if (i==1 && j==0){ // Rounded pcb of rounded slat 
1845             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9X", idSlatCh9, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1846             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9X", idSlatCh9, 2*index,TGeoTranslation(xx,0.,-zPanel));
1847             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9I", idSlatCh9, index,TGeoTranslation(xx,0.,0.));
1848             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0X", idSlatCh10, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1849             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0X", idSlatCh10, 2*index,TGeoTranslation(xx,0.,-zPanel));
1850             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0I", idSlatCh10, index,TGeoTranslation(xx,0.,0.));
1851           } else { 
1852             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09X", idSlatCh9, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1853             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09X", idSlatCh9, 2*index,TGeoTranslation(xx,0.,-zPanel));
1854             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09I", idSlatCh9, index,TGeoTranslation(xx,0.,0.));
1855             
1856             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10X", idSlatCh10, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1857             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10X", idSlatCh10, 2*index,TGeoTranslation(xx,0.,-zPanel));
1858             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10I", idSlatCh10, index,TGeoTranslation(xx,0.,0.));
1859           }
1860         } 
1861       }
1862     }
1863
1864     // position the nomex volume inside the panel volume
1865     gMC->Gspos("S09N",1,"S09C",0.,0.,0.,0,"ONLY"); 
1866     gMC->Gspos("SD9N",1,"SD9C",0.,0.,0.,0,"ONLY"); 
1867     gMC->Gspos("S10N",1,"S10C",0.,0.,0.,0,"ONLY"); 
1868     gMC->Gspos("SD0N",1,"SD0C",0.,0.,0.,0,"ONLY"); 
1869
1870     // position panel  volume inside the bulk nomex material volume
1871     gMC->Gspos("S09C",1,"S09X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1872     gMC->Gspos("SD9C",1,"SD9X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1873     gMC->Gspos("S10C",1,"S10X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1874     gMC->Gspos("SD0C",1,"SD0X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1875
1876     // position the PCB volume inside the insulating material volume
1877     gMC->Gspos("S09P",1,"S09I",0.,0.,0.,0,"ONLY"); 
1878     gMC->Gspos("SD9P",1,"SD9I",0.,0.,0.,0,"ONLY"); 
1879     gMC->Gspos("S10P",1,"S10I",0.,0.,0.,0,"ONLY"); 
1880     gMC->Gspos("SD0P",1,"SD0I",0.,0.,0.,0,"ONLY"); 
1881
1882     // position the horizontal frame volume inside the PCB volume
1883     gMC->Gspos("S09H",1,"S09P",0.,0.,0.,0,"ONLY"); 
1884     gMC->Gspos("SD9H",1,"SD9P",0.,0.,0.,0,"ONLY"); 
1885     gMC->Gspos("S10H",1,"S10P",0.,0.,0.,0,"ONLY"); 
1886     gMC->Gspos("SD0H",1,"SD0P",0.,0.,0.,0,"ONLY"); 
1887
1888     // position the sensitive volume inside the horizontal frame volume
1889     gMC->Gsposp("S09G",1,"S09H",0.,0.,0.,0,"ONLY",senspar,3); 
1890     gMC->Gspos("SD9G",1,"SD9H",0.,0.,0.,0,"ONLY"); 
1891     gMC->Gsposp("S10G",1,"S10H",0.,0.,0.,0,"ONLY",senspar,3); 
1892     gMC->Gspos("SD0G",1,"SD0H",0.,0.,0.,0,"ONLY"); 
1893
1894     // position the border volumes inside the PCB volume
1895     Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
1896     gMC->Gspos("S09B",1,"S09P",0., yborder,0.,0,"ONLY"); 
1897     gMC->Gspos("S09B",2,"S09P",0.,-yborder,0.,0,"ONLY"); 
1898     gMC->Gspos("SD9B",1,"SD9P",0., 0.,0.,0,"ONLY"); 
1899     gMC->Gspos("S09B",1,"SD9P",0., yborder,0.,0,"ONLY"); 
1900     gMC->Gspos("S10B",1,"S10P",0., yborder,0.,0,"ONLY"); 
1901     gMC->Gspos("S10B",2,"S10P",0.,-yborder,0.,0,"ONLY"); 
1902     gMC->Gspos("SD0B",1,"SD0P",0., 0.,0.,0,"ONLY"); 
1903     gMC->Gspos("S10B",1,"SD0P",0., yborder,0.,0,"ONLY"); 
1904
1905     //      // create the NULOC volume and position it in the horizontal frame
1906
1907     gMC->Gsvolu("S09E","BOX",kNulocMaterial,nulocpar,3);
1908     gMC->Gsvolu("S10E","BOX",kNulocMaterial,nulocpar,3);
1909     index = 0;
1910     Float_t rPhi3 = TMath::ASin((kYpos5[1]-kPcbHeight/2.)/AliMUONConstants::Rmin(4));
1911     Float_t xxmax4 = (AliMUONConstants::Rmin(4)*TMath::Cos(rPhi3)-kVframeLength/2.) - (kBframeLength - kNulocLength)/2.;
1912     for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
1913       index++; 
1914       gMC->Gspos("S09E",2*index-1,"S09B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
1915       gMC->Gspos("S09E",2*index  ,"S09B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
1916       gMC->Gspos("S10E",2*index-1,"S10B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
1917       gMC->Gspos("S10E",2*index  ,"S10B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
1918     }
1919     if (xx > xxmax4 && xx< xxmax) {
1920       gMC->Gspos("S09E",2*index-1,"SD9B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
1921       gMC->Gspos("S09E",2*index  ,"SD9B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
1922       gMC->Gspos("S10E",2*index-1,"SD0B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
1923       gMC->Gspos("S10E",2*index  ,"SD0B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
1924     }
1925
1926     //    
1927     //Geometry of the support pannel Verticla length 5.7m, horizontal length 2.6m, internal radius  dMotherInner o SC09 and SC10  (F. Orsini, Saclay)
1928     //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
1929     Float_t dMotherInner =  AliMUONConstants::Rmin(4)-kRframeHeight; 
1930     Float_t nomexthickness = 1.5;
1931     Float_t carbonthickness = 0.03;
1932     Float_t supporthlength =  260.;  
1933     Float_t supportvlength =  570.;  
1934     // Generating the composite shape of the carbon and nomex pannels
1935     new TGeoBBox("shNomexBoxSt5",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
1936     new TGeoBBox("shCarbonBoxSt5",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
1937     new TGeoTubeSeg("shNomexHoleSt5",0., dMotherInner, nomexthickness/2.+carbonthickness+3*kCableWidth+0.001, -90. ,90.);
1938     new TGeoTubeSeg("shCarbonHoleSt5",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
1939     TGeoTranslation* trHoleSt5 = new TGeoTranslation("trHoleSt5",-supporthlength/2.,0.,0.); 
1940     trHoleSt5->RegisterYourself();
1941     TGeoCompositeShape* shNomexSupportSt5  = new TGeoCompositeShape("shNomexSupportSt5","shNomexBoxSt5-shNomexHoleSt5:trHoleSt5");
1942     TGeoCompositeShape* shCarbonSupportSt5 = new TGeoCompositeShape("shCarbonSupportSt5","shCarbonBoxSt5-shCarbonHoleSt5:trHoleSt5");
1943
1944    // Generating Nomex and Carbon pannel volumes
1945     TGeoVolume* voNomexSupportSt5  = new TGeoVolume("S09S", shNomexSupportSt5, kMedNomex);
1946     TGeoVolume* voCarbonSupportSt5 = new TGeoVolume("S09K", shCarbonSupportSt5, kMedCarbon);
1947     TGeoTranslation* trCarbon1St5   = new TGeoTranslation("trCarbon1St5",0.,0., -(nomexthickness+carbonthickness)/2.);
1948     TGeoTranslation* trCarbon2St5   = new TGeoTranslation("trCarbon2St5",0.,0.,  (nomexthickness+carbonthickness)/2.);
1949     voNomexSupportSt5->AddNode(voCarbonSupportSt5,1,trCarbon1St5);
1950     voNomexSupportSt5->AddNode(voCarbonSupportSt5,2,trCarbon2St5);
1951
1952     // Add readout cables
1953     gMC->Gsvolu("S09L","BOX",kCableMaterial,dum,0);
1954
1955     ySlat5 = 0.;
1956     Float_t lCableX = 0.;
1957     Float_t lCableY = 0.;
1958     Float_t lCableZ = 0.;
1959     Float_t cablepar[3] = {supporthlength/2., kCableHeight/2., kCableWidth/2.};
1960     Float_t lCableDY = 0.;
1961     for (i = 0; i<kNslats5; i++){
1962       Int_t iCable = 1;
1963       Int_t cIndex = 0;
1964       ySlat5 += kYpos5[i];
1965
1966       lCableY = ySlat5;
1967
1968       // Cables going out from the start of slat
1969       if(kNPCB5[i]>=4){ // Only if 4 or more pcb
1970         // First top cables
1971         cablepar[0] = (supporthlength-kXpos5[i])/2.;
1972         lCableX = kXpos5[i]/2.;
1973         if(i+1>=kNslats5 || i+2>=kNslats5){ // If no more higher slats, then use distance to lower slat
1974           lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
1975         }
1976         else {
1977           lCableDY = (kYpos5[i+1]+kYpos5[i+2])/2.-cablepar[1];
1978         }
1979         lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
1980         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);  
1981         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
1982         // Then bottom cables
1983         if (i>0) {
1984           if (i==1) { // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
1985             cablepar[0] = (supporthlength-kXpos5[i]-dMotherInner)/2.;
1986             lCableX = (kXpos5[i]+dMotherInner)/2.;
1987             lCableDY = (kYpos5[i]+kYpos5[i])/2.-cablepar[1];
1988           }
1989           else {
1990             lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
1991             if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
1992               lCableDY = lCableY - dMotherInner - cablepar[1];
1993             }
1994           }
1995           gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
1996           gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
1997         }
1998       }
1999       
2000       // Rounded slats have an extra cable starting at second pcb
2001       if(i==1){ 
2002         // Only on top
2003         cablepar[0] = (supporthlength-kPcbLength-kVframeLength)/2.;
2004         lCableX = (kPcbLength+kVframeLength)/2.;
2005         lCableDY = (kYpos5[i+1]+kYpos5[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
2006         lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
2007         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
2008         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
2009       } 
2010
2011       // Cables going out from the end of the slats
2012       // First top cables
2013       cablepar[0] = (supporthlength-(slatLength5[i]+kXpos5[i]+kDslatLength)+kVframeLength)/2.;
2014       lCableX = slatLength5[i]+kXpos5[i]-kVframeLength+kDslatLength+cablepar[0]-supporthlength/2.;
2015       if(i+1>=kNslats5 || i+2>=kNslats5){ // If no more higher slats, then use distance to lower slat
2016         lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
2017       }
2018       else {
2019         lCableDY = (kYpos5[i+1]+kYpos5[i+2])/2.-cablepar[1];
2020       }
2021       lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
2022       gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
2023       gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
2024       if(i>0){
2025         if (i==1) { // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
2026           lCableDY = (kYpos5[i]+kYpos5[i])/2.-cablepar[1];
2027         }
2028         else {
2029           lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
2030           if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
2031               lCableDY = lCableY - dMotherInner - cablepar[1];
2032           }
2033         }
2034         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
2035         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
2036       }
2037     }
2038
2039     Float_t dzCh9  = dzCh;
2040     TGeoTranslation* trSupport1St5   = new TGeoTranslation("trSupport1St5", supporthlength/2., 0. , dzCh9);
2041     TGeoRotation*    roSupportSt5    = new TGeoRotation("roSupportSt5",90.,180.,-90.);
2042     TGeoCombiTrans*  coSupport2St5   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh9, roSupportSt5);
2043     GetEnvelopes(13)->AddEnvelope("S09S", 0, 1, *trSupport1St5);  
2044     GetEnvelopes(12)->AddEnvelope("S09S", 0, 2, *coSupport2St5);  
2045     GetEnvelopes(15)->AddEnvelope("S09S", 0, 3, *trSupport1St5);   
2046     GetEnvelopes(14)->AddEnvelope("S09S", 0, 4, *coSupport2St5);
2047
2048
2049     // End of pannel support geometry    
2050
2051     // cout << "Geometry for Station 5...... done" << endl;
2052
2053   }
2054
2055   delete [] fStations;
2056
2057 }
2058
2059
2060 //______________________________________________________________________________
2061 void AliMUONSlatGeometryBuilder::SetTransformations()
2062 {
2063 /// Defines the transformations for the station345 chambers.
2064
2065   if (gAlice->GetModule("DIPO")) {
2066     // if DIPO is preset, the whole station will be placed in DDIP volume
2067     SetMotherVolume(4, "DDIP");
2068     SetMotherVolume(5, "DDIP");
2069     SetMotherVolume(6, "DDIP");
2070     SetMotherVolume(7, "DDIP");
2071   }     
2072   SetVolume(4, "SC05I", true);
2073   SetVolume(5, "SC05O", true);
2074   SetVolume(6, "SC06I", true);
2075   SetVolume(7, "SC06O", true);
2076      
2077   if (gAlice->GetModule("SHIL")) {
2078     SetMotherVolume(8, "YOUT2");
2079     SetMotherVolume(9, "YOUT2");
2080     SetMotherVolume(10, "YOUT2");
2081     SetMotherVolume(11, "YOUT2");
2082     SetMotherVolume(12, "YOUT2");
2083     SetMotherVolume(13, "YOUT2");
2084     SetMotherVolume(14, "YOUT2");
2085     SetMotherVolume(15, "YOUT2");
2086   }  
2087
2088   SetVolume( 8, "SC07I", true);
2089   SetVolume( 9, "SC07O", true);
2090   SetVolume(10, "SC08I", true);
2091   SetVolume(11, "SC08O", true);
2092   SetVolume(12, "SC09I", true);
2093   SetVolume(13, "SC09O", true);
2094   SetVolume(14, "SC10I", true);
2095   SetVolume(15, "SC10O", true);
2096
2097 // Stations 345 are not perpendicular to the beam axis
2098 // See AliMUONConstants class
2099   TGeoRotation st345inclination("rot99");
2100   st345inclination.RotateX(AliMUONConstants::St345Inclination());
2101   
2102 // The rotation of the half-chamber is done with respect the center of the chamber.
2103 // the distance beween the roation axis and the chamber position is 
2104 // AliMUONConstants::DzCh()+AliMUONConstants::DzSlat()
2105 // Therefore the position of the half-chamber has to be corrected by a traslation in Z and Y axis
2106   Double_t deltaY = (AliMUONConstants::DzCh()+AliMUONConstants::DzSlat())*
2107     TMath::Sin(AliMUONConstants::St345Inclination() * TMath::Pi()/180.);
2108   Double_t deltaZ = (AliMUONConstants::DzCh()+AliMUONConstants::DzSlat())*
2109     (1.-TMath::Cos(AliMUONConstants::St345Inclination() * TMath::Pi()/180.));
2110
2111
2112   Double_t zpos1= - AliMUONConstants::DefaultChamberZ(4); 
2113   SetTransformation(4, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
2114   SetTransformation(5, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
2115
2116   zpos1= - AliMUONConstants::DefaultChamberZ(5); 
2117   SetTransformation(6, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
2118   SetTransformation(7, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
2119
2120   zpos1 = - AliMUONConstants::DefaultChamberZ(6); 
2121   SetTransformation(8, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
2122   SetTransformation(9, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
2123
2124   zpos1 = - AliMUONConstants::DefaultChamberZ(7); 
2125   SetTransformation(10, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination );
2126   SetTransformation(11, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination );
2127
2128   zpos1 = - AliMUONConstants::DefaultChamberZ(8); 
2129   SetTransformation(12, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
2130   SetTransformation(13, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
2131
2132   zpos1 = - AliMUONConstants::DefaultChamberZ(9); 
2133   SetTransformation(14, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
2134   SetTransformation(15, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
2135
2136 }
2137
2138 //______________________________________________________________________________
2139 void AliMUONSlatGeometryBuilder::SetSensitiveVolumes()
2140 {
2141 /// Defines the sensitive volumes for slat stations chambers.
2142
2143   GetGeometry( 4)->SetSensitiveVolume("S05G");
2144   GetGeometry( 4)->SetSensitiveVolume("SC5G");
2145   GetGeometry( 4)->SetSensitiveVolume("SD5G");
2146   GetGeometry( 5)->SetSensitiveVolume("S05G");
2147   GetGeometry( 5)->SetSensitiveVolume("SC5G");
2148   GetGeometry( 5)->SetSensitiveVolume("SD5G");
2149   GetGeometry( 6)->SetSensitiveVolume("S06G");
2150   GetGeometry( 6)->SetSensitiveVolume("SC6G");
2151   GetGeometry( 6)->SetSensitiveVolume("SD6G");
2152   GetGeometry( 7)->SetSensitiveVolume("S06G");
2153   GetGeometry( 7)->SetSensitiveVolume("SC6G");
2154   GetGeometry( 7)->SetSensitiveVolume("SD6G");
2155   GetGeometry( 8)->SetSensitiveVolume("S07G");
2156   GetGeometry( 8)->SetSensitiveVolume("SD7G");
2157   GetGeometry( 9)->SetSensitiveVolume("S07G");
2158   GetGeometry( 9)->SetSensitiveVolume("SD7G");
2159   GetGeometry(10)->SetSensitiveVolume("S08G");
2160   GetGeometry(10)->SetSensitiveVolume("SD8G");
2161   GetGeometry(11)->SetSensitiveVolume("S08G");
2162   GetGeometry(11)->SetSensitiveVolume("SD8G");
2163   GetGeometry(12)->SetSensitiveVolume("S09G");
2164   GetGeometry(12)->SetSensitiveVolume("SD9G");
2165   GetGeometry(13)->SetSensitiveVolume("S09G");
2166   GetGeometry(13)->SetSensitiveVolume("SD9G");
2167   GetGeometry(14)->SetSensitiveVolume("S10G");
2168   GetGeometry(14)->SetSensitiveVolume("SD0G");
2169   GetGeometry(15)->SetSensitiveVolume("S10G");
2170   GetGeometry(15)->SetSensitiveVolume("SD0G");
2171 }
2172
2173 //______________________________________________________________________________
2174 Int_t  AliMUONSlatGeometryBuilder::ConvertSlatNum(Int_t numslat, Int_t quadnum, Int_t fspq) const
2175 {
2176 /// On-line function establishing the correspondance between numslat (the slat number on a particular quadrant (numslat->0....4 for St3))
2177 /// and slatnum (the slat number on the whole panel (slatnum->1...18 for St3)
2178   numslat += 1;
2179   if (quadnum==2 || quadnum==3) 
2180     numslat += fspq;
2181   else
2182     numslat = fspq + 2-numslat;
2183   numslat -= 1;
2184               
2185   if (quadnum==3 || quadnum==4) numslat += 2*fspq+1;
2186
2187   return numslat;
2188 }