10965f1f84d8331cbe3be78cd05fb6519f026a29
[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         const char* slatType = "CD"; // C: central slat; D: rounded slat
502         const char* volLetter = "CNXIPHBG";
503         TString volName;
504         TString compName;
505         TString csName;
506         TGeoVolume *mVol = 0x0;
507         TObjArray centerSlat(nSlatType*((nVol+1)*2));   
508         TObjArray composite(nSlatType*((nVol+1)*2));
509
510         // Beam shield recess
511         new TGeoTube("tubeCut", 0., AliMUONConstants::Rmin(2), kSlatWidth/2.+0.001);
512         // Displacement
513         TGeoTranslation* trCTube = new TGeoTranslation("trCTube", -(kPcbLength-csvPcbLength/2.+kVframeLength/2.), 0., 0.);
514         trCTube->RegisterYourself();
515         TGeoTranslation* trDTube = new TGeoTranslation("trDTube", -(kPcbLength+kVframeLength)/2., -kYpos3[1], 0.);
516         trDTube->RegisterYourself();
517
518         Float_t cPhi2 = (TMath::Pi()/2.-TMath::ACos((kSensHeight/2.)/(AliMUONConstants::Rmin(2)-kRframeLength)));
519         TGeoBBox *boxCCut = new TGeoBBox("boxCCut",(cFramepar3[1]-cFramepar3[0]*TMath::Cos(cPhi2))/2., hFramepar3[1], cFramepar3[2]+0.001);
520         // Displacement
521         TGeoTranslation* trCBox = new TGeoTranslation("trCBox",cFramepar3[0]*TMath::Cos(cPhi2)+boxCCut->GetDX(), 0., 0.);
522         trCBox->RegisterYourself();
523         new TGeoBBox("boxDCut",(kPcbLength+kVframeLength)/2., hFramepar3[1], vFramepar[2]+0.001);
524         // Displacement
525         TGeoTranslation* trDBox = new TGeoTranslation("trDBox",kPcbLength/2., kYpos3[1], 0.);
526         trDBox->RegisterYourself();
527
528         TGeoBBox *boxVframe = new TGeoBBox("boxVframe",vFramepar[0],vrFrameHeight/2., vFramepar[2]);
529         TGeoTranslation* trVBox = new TGeoTranslation("trVBox", 0., AliMUONConstants::Rmin(2)-kRframeLength + boxVframe->GetDY(), 0.);
530         trVBox->RegisterYourself();
531
532         for(int iCh=5; iCh<=6; iCh++){
533           for (int iSlatType = 0; iSlatType<nSlatType; iSlatType++) {
534             for (int iVol = 0; iVol<nVol; iVol++){
535               Int_t lIndex = (iCh-5)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+iVol;
536               volName=Form("S%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
537               mVol = gGeoManager->FindVolumeFast(volName);
538               if ( !mVol ) {
539                 AliErrorStream() 
540                   << "Slat volume " << volName << " not found" << endl;  
541               }
542               else {
543                 centerSlat[lIndex] = mVol->GetShape();
544                 csName=Form("centerSlat%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
545                 ((TGeoShape*)centerSlat[lIndex])->SetName(csName); 
546
547                 // Composite shape
548                 TString compOperation(csName);
549                 compOperation+="-tubeCut:tr";
550                 compOperation+=slatType[iSlatType];
551                 compOperation+="Tube";
552                 if (strstr(volName,"B")){
553                   // Displacement
554                   TGeoTranslation* trB = new TGeoTranslation("trB", 0., -( kPcbHeight - kBframeHeight ) / 2., 0.);
555                   trB->RegisterYourself();
556                   compOperation.ReplaceAll("-tubeCut",":trB-tubeCut");
557                 }
558                 compName=Form("composite%d%c",iCh,volLetter[iVol]);
559                 composite[lIndex] = new TGeoCompositeShape(compName, compOperation.Data()); 
560                 
561                 // Reset shape to volume      
562                 mVol->SetShape((TGeoShape*)composite[lIndex]);
563               }
564             }
565
566             // For rounded spacer
567             Int_t lIndex = (iCh-5)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+nVol;
568             volName=Form("S%c%dD",slatType[iSlatType],iCh);
569             mVol = gGeoManager->FindVolumeFast(volName);
570             if ( !mVol ) {
571               AliErrorStream() 
572                 << "Slat volume " << volName << " not found" << endl;    
573             }
574             else {
575               centerSlat[lIndex] = mVol->GetShape();
576               csName=Form("centerSlat%c%dD",slatType[iSlatType],iCh);
577               ((TGeoShape*)centerSlat[lIndex])->SetName(csName);                  
578               
579               // Composite shape
580               TString compOperation(csName);
581               if (strstr(volName,"SC")){
582                 compOperation+="*boxCCut:trCBox";
583               }
584               if (strstr(volName,"SD")){
585                 compOperation.Prepend("(");
586                 compOperation+="+boxVframe:trVBox)*boxDCut:trDBox";
587               }
588               compName=Form("composite%c%dD",slatType[iSlatType],iCh);
589               composite[lIndex] = new TGeoCompositeShape(compName, compOperation.Data());             
590               // Reset shape to volume      
591               mVol->SetShape((TGeoShape*)composite[lIndex]);
592             }
593           }
594         }
595       }
596         
597       index = 0; 
598       for (i = 0; i<kNslats3; i++){
599         for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
600
601           if (i == 0 && quadrant == 2) continue;
602           if (i == 0 && quadrant == 4) continue;
603
604           sprintf(idSlatCh5,"LA%d",ConvertSlatNum(i,quadrant,kNslats3-1));
605           sprintf(idSlatCh6,"LB%d",ConvertSlatNum(i,quadrant,kNslats3-1));
606           Int_t moduleSlatCh5 = GetModuleId(idSlatCh5);
607           Int_t moduleSlatCh6 = GetModuleId(idSlatCh6);
608           Float_t xvFrame  = (slatLength3[i] - kVframeLength)/2.;
609           Float_t xvFrame2  = xvFrame;    
610
611           if (i == 0 || i == 1 || i == 2) xvFrame2 -= pcbDLength3; // Correct position (J.C.)
612
613           // position the vertical frames 
614           if ( i > 2) { 
615             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
616                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
617             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
618                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
619             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
620                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
621             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
622                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));   
623           } 
624
625           if (i == 2) {
626             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
627                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame2,0.,0.)); 
628             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
629                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
630             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
631                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
632             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
633                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
634           }
635
636           if (i == 0 || i == 1) { // first vertical spacers
637             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
638                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame2,0.,0.)); 
639             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
640                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));          
641             if (i == 0) { // rounded spacer for central slat (J.C.)
642               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5D", idSlatCh5, 
643                                                                   (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
644               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6D", idSlatCh6, 
645                                                                   (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
646
647             }
648             if (i == 1) { // rounded + vertical spacer for rounded slat (J.C.)
649               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5D", idSlatCh5, 
650                                                                   (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos3[1],0.));
651               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6D", idSlatCh6, 
652                                                                   (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos3[1],0.));
653             }
654           }
655
656           // position the panels and the insulating material 
657           for (j = 0; j < kNPCB3[i]; j++){
658             index++;
659             Float_t xx = kSensLength * (-kNPCB3[i]/2. + j + 0.5); 
660             Float_t xx2 = xx - pcbDLength3/2.; 
661             Float_t xx3 = xx + (kSensLength-csvPcbLength)/2.;
662
663             Float_t zPanel = spar[2] - nomexbpar[2]; 
664
665             if (i==0 && j==0){ // Rounded pcb of central slat (SR1, NR1)
666               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5X", idSlatCh5, 2*index-1,TGeoTranslation(xx3,0.,zPanel));
667               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5X", idSlatCh5, 2*index,TGeoTranslation(xx3,0.,-zPanel));
668               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SC5I", idSlatCh5, index,TGeoTranslation(xx3,0.,0.));
669               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6X", idSlatCh6, 2*index-1,TGeoTranslation(xx3,0.,zPanel));
670               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6X", idSlatCh6, 2*index,TGeoTranslation(xx3,0.,-zPanel));
671               GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SC6I", idSlatCh6, index,TGeoTranslation(xx3,0.,0.));
672             } else {          
673               if (i==1 && j==0){ // Rounded pcb of rounded slats (SR2. NR2)
674                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5X", idSlatCh5, 2*index-1,TGeoTranslation(xx,0.,zPanel));
675                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5X", idSlatCh5, 2*index,TGeoTranslation(xx,0.,-zPanel));
676                 GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SD5I", idSlatCh5, index,TGeoTranslation(xx,0.,0.));
677                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6X", idSlatCh6, 2*index-1,TGeoTranslation(xx,0.,zPanel));
678                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6X", idSlatCh6, 2*index,TGeoTranslation(xx,0.,-zPanel));
679                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("SD6I", idSlatCh6, index,TGeoTranslation(xx,0.,0.));
680               } else {        
681                 if ( (i == 0 || i == 1 || i == 2) && j == kNPCB3[i]-1) { // 1 pcb is shortened by 5cm 
682                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5X", idSlatCh5, 2*index-1,TGeoTranslation(xx2,0.,zPanel));
683                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5X", idSlatCh5, 2*index,TGeoTranslation(xx2,0.,-zPanel));
684                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5I", idSlatCh5, index,TGeoTranslation(xx2,0.,0.));
685                 } else {                
686                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05X", idSlatCh5, 2*index-1,TGeoTranslation(xx,0.,zPanel));
687                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05X", idSlatCh5, 2*index,TGeoTranslation(xx,0.,-zPanel));
688                   GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05I", idSlatCh5, index,TGeoTranslation(xx,0.,0.));
689                 }          
690                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06X", idSlatCh6, 2*index-1,TGeoTranslation(xx,0.,zPanel));
691                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06X", idSlatCh6, 2*index,TGeoTranslation(xx,0.,-zPanel));
692                 GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06I", idSlatCh6, index,TGeoTranslation(xx,0.,0.));                        
693               }
694             }
695           }
696         }
697       }
698       
699       // position the nomex volume inside the panel volume
700       gMC->Gspos("S05N",1,"S05C",0.,0.,0.,0,"ONLY"); 
701       gMC->Gspos("SB5N",1,"SB5C",0.,0.,0.,0,"ONLY"); 
702       gMC->Gspos("SC5N",1,"SC5C",0.,0.,0.,0,"ONLY"); 
703       gMC->Gspos("SD5N",1,"SD5C",0.,0.,0.,0,"ONLY"); 
704       gMC->Gspos("S06N",1,"S06C",0.,0.,0.,0,"ONLY"); 
705       gMC->Gspos("SC6N",1,"SC6C",0.,0.,0.,0,"ONLY"); 
706       gMC->Gspos("SD6N",1,"SD6C",0.,0.,0.,0,"ONLY"); 
707   
708       // position panel volume inside the bulk nomex material volume
709       gMC->Gspos("S05C",1,"S05X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
710       gMC->Gspos("SB5C",1,"SB5X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
711       gMC->Gspos("SC5C",1,"SC5X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
712       gMC->Gspos("SD5C",1,"SD5X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
713       gMC->Gspos("S06C",1,"S06X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
714       gMC->Gspos("SC6C",1,"SC6X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
715       gMC->Gspos("SD6C",1,"SD6X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
716
717       // position the PCB volume inside the insulating material volume
718       gMC->Gspos("S05P",1,"S05I",0.,0.,0.,0,"ONLY"); 
719       gMC->Gspos("SB5P",1,"SB5I",0.,0.,0.,0,"ONLY"); 
720       gMC->Gspos("SC5P",1,"SC5I",0.,0.,0.,0,"ONLY"); 
721       gMC->Gspos("SD5P",1,"SD5I",0.,0.,0.,0,"ONLY"); 
722       gMC->Gspos("S06P",1,"S06I",0.,0.,0.,0,"ONLY"); 
723       gMC->Gspos("SC6P",1,"SC6I",0.,0.,0.,0,"ONLY"); 
724       gMC->Gspos("SD6P",1,"SD6I",0.,0.,0.,0,"ONLY"); 
725   
726       // position the horizontal frame volume inside the PCB volume
727       gMC->Gspos("S05H",1,"S05P",0.,0.,0.,0,"ONLY"); 
728       gMC->Gspos("SB5H",1,"SB5P",0.,0.,0.,0,"ONLY"); 
729       gMC->Gspos("SC5H",1,"SC5P",0.,0.,0.,0,"ONLY"); 
730       gMC->Gspos("SD5H",1,"SD5P",0.,0.,0.,0,"ONLY"); 
731       gMC->Gspos("S06H",1,"S06P",0.,0.,0.,0,"ONLY"); 
732       gMC->Gspos("SC6H",1,"SC6P",0.,0.,0.,0,"ONLY"); 
733       gMC->Gspos("SD6H",1,"SD6P",0.,0.,0.,0,"ONLY"); 
734   
735       // position the sensitive volume inside the horizontal frame volume
736       gMC->Gsposp("S05G",1,"S05H",0.,0.,0.,0,"ONLY",senspar,3); 
737       gMC->Gsposp("S05G",1,"SB5H",0.,0.,0.,0,"ONLY",senspar2,3); 
738       gMC->Gspos("SC5G",1,"SC5H",0.,0.,0.,0,"ONLY"); 
739       gMC->Gspos("SD5G",1,"SD5H",0.,0.,0.,0,"ONLY"); 
740       gMC->Gsposp("S06G",1,"S06H",0.,0.,0.,0,"ONLY",senspar,3); 
741       gMC->Gspos("SC6G",1,"SC6H",0.,0.,0.,0,"ONLY"); 
742       gMC->Gspos("SD6G",1,"SD6H",0.,0.,0.,0,"ONLY"); 
743   
744  
745       // position the border volumes inside the PCB volume
746       Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
747       Int_t rotB = 0;
748       gMC->Matrix(rotB,90,0,90,270,180,0); // rotation around x for second border
749
750       gMC->Gspos("S05B",1,"S05P",0., yborder,0.,0,"ONLY"); 
751       gMC->Gspos("S05B",2,"S05P",0.,-yborder,0.,0,"ONLY"); 
752       gMC->Gspos("SB5B",1,"SB5P",0., yborder,0.,0,"ONLY"); 
753       gMC->Gspos("SB5B",2,"SB5P",0.,-yborder,0.,0,"ONLY"); 
754       gMC->Gspos("SC5B",1,"SC5P",0., 0.,0.,0,"ONLY"); 
755       gMC->Gspos("SC5B",2,"SC5P",0., 0.,0.,rotB,"ONLY"); 
756       gMC->Gspos("SD5B",1,"SD5P",0., 0.,0.,0,"ONLY"); 
757       gMC->Gspos("S05B",1,"SD5P",0., yborder,0.,0,"ONLY"); 
758
759       gMC->Gspos("S06B",1,"S06P",0., yborder,0.,0,"ONLY"); 
760       gMC->Gspos("S06B",2,"S06P",0.,-yborder,0.,0,"ONLY"); 
761       gMC->Gspos("SC6B",1,"SC6P",0., 0.,0.,0,"ONLY"); 
762       gMC->Gspos("SC6B",2,"SC6P",0., 0.,0.,rotB,"ONLY"); 
763       gMC->Gspos("SD6B",1,"SD6P",0., 0.,0.,0,"ONLY"); 
764       gMC->Gspos("S06B",1,"SD6P",0., yborder,0.,0,"ONLY"); 
765   
766       // create the NULOC volume and position it in the horizontal frame
767       gMC->Gsvolu("S05E","BOX",kNulocMaterial,nulocpar,3);
768       gMC->Gsvolu("S06E","BOX",kNulocMaterial,nulocpar,3);
769       index = 0;
770       Float_t xxmax2 = xxmax - pcbDLength3/2.;
771       Float_t xxmax3 = xxmax - (kPcbLength-csvPcbLength)/2.;
772       Float_t rPhi3 = TMath::ASin((kYpos3[1]-kPcbHeight/2.)/AliMUONConstants::Rmin(2));
773       Float_t xxmax4 = (AliMUONConstants::Rmin(2)*TMath::Cos(rPhi3)-kVframeLength/2.) - (kBframeLength - kNulocLength)/2.;
774       for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
775         index++; 
776         gMC->Gspos("S05E",2*index-1,"S05B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
777         gMC->Gspos("S05E",2*index  ,"S05B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
778         gMC->Gspos("S06E",2*index-1,"S06B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
779         gMC->Gspos("S06E",2*index  ,"S06B", xx, 0., kBframeWidth/2.-  kNulocWidth/2, 0, "ONLY");
780         if (xx > -xxmax2 && xx< xxmax2) {
781           gMC->Gspos("S05E",2*index-1,"SB5B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
782           gMC->Gspos("S05E",2*index  ,"SB5B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
783         }
784         if (xx > -xxmax3 && xx< xxmax3) {
785           gMC->Gspos("S05E",2*index-1,"SC5B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2., 0, "ONLY");
786           gMC->Gspos("S05E",2*index  ,"SC5B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2., 0, "ONLY");
787           gMC->Gspos("S06E",2*index-1,"SC6B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
788           gMC->Gspos("S06E",2*index  ,"SC6B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
789         }
790         if (xx > xxmax4 && xx< xxmax) {
791           gMC->Gspos("S05E",2*index-1,"SD5B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
792           gMC->Gspos("S05E",2*index  ,"SD5B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
793           gMC->Gspos("S06E",2*index-1,"SD6B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
794           gMC->Gspos("S06E",2*index  ,"SD6B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
795         }
796       }
797       
798       //
799       //Geometry of the support pannel Verticla length 3.62m, horizontal length 1.62m, internal radius  dMotherInner of SC05 and SC06  (F. Orsini, Saclay)
800       //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
801       // Outer excess and inner recess for mother volume radius
802       // with respect to ROuter and RInner
803       Float_t dMotherInner = AliMUONConstants::Rmin(2)-kRframeHeight; 
804       Float_t nomexthickness = 1.5;
805       Float_t carbonthickness = 0.03;
806       Float_t supporthlength =  162.;  //    chamber 5 
807       Float_t supporthlengthCh6 =  167.;  // chamber 6 
808       Float_t supportvlength =  362.; 
809
810       // Generating the composite shape of the carbon and nomex pannels
811       new TGeoBBox("shNomexBoxSt3",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
812       new TGeoBBox("shCarbonBoxSt3",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
813       new TGeoBBox("shNomexBoxSt3Ch6",(supporthlengthCh6)/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
814       new TGeoBBox("shCarbonBoxSt3Ch6",(supporthlengthCh6)/2., supportvlength/2. ,carbonthickness/2.); 
815       new TGeoTubeSeg("shNomexHoleSt3",0., dMotherInner, nomexthickness/2.+carbonthickness+3*kCableWidth+0.001, -90. ,90.);
816       new TGeoTubeSeg("shCarbonHoleSt3",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
817       TGeoTranslation* trHoleSt3 = new TGeoTranslation("trHoleSt3",-supporthlength/2.,0.,0.); 
818       trHoleSt3->RegisterYourself();
819       TGeoTranslation* trHoleSt3Ch6 = new TGeoTranslation("trHoleSt3Ch6",-(supporthlengthCh6)/2.,0.,0.); 
820       trHoleSt3Ch6->RegisterYourself();
821       TGeoCompositeShape* shNomexSupportSt3  = new TGeoCompositeShape("shNomexSupportSt3","shNomexBoxSt3-shNomexHoleSt3:trHoleSt3");
822       TGeoCompositeShape* shCarbonSupportSt3 = new TGeoCompositeShape("shCarbonSupportSt3","shCarbonBoxSt3-shCarbonHoleSt3:trHoleSt3");
823       TGeoCompositeShape* shNomexSupportSt3Ch6  = new TGeoCompositeShape("shNomexSupportSt3Ch6","shNomexBoxSt3Ch6-shNomexHoleSt3:trHoleSt3Ch6");
824       TGeoCompositeShape* shCarbonSupportSt3Ch6 = new TGeoCompositeShape("shCarbonSupportSt3Ch6","shCarbonBoxSt3Ch6-shCarbonHoleSt3:trHoleSt3Ch6");
825
826       // Generating Nomex and Carbon pannel volumes
827       TGeoVolume * voNomexSupportSt3  = new TGeoVolume("S05S", shNomexSupportSt3, kMedNomex);
828       TGeoVolume * voCarbonSupportSt3 = new TGeoVolume("S05K", shCarbonSupportSt3, kMedCarbon);
829       TGeoVolume * voNomexSupportSt3Ch6  = new TGeoVolume("S06S", shNomexSupportSt3Ch6, kMedNomex);
830       TGeoVolume * voCarbonSupportSt3Ch6 = new TGeoVolume("S06K", shCarbonSupportSt3Ch6, kMedCarbon);
831
832       TGeoTranslation *trCarbon1St3   = new TGeoTranslation("trCarbon1St3",0.,0., -(nomexthickness+carbonthickness)/2.);
833       TGeoTranslation *trCarbon2St3   = new TGeoTranslation("trCarbon2St3",0.,0.,  (nomexthickness+carbonthickness)/2.);
834       voNomexSupportSt3->AddNode(voCarbonSupportSt3,1,trCarbon1St3);
835       voNomexSupportSt3->AddNode(voCarbonSupportSt3,2,trCarbon2St3);
836       voNomexSupportSt3Ch6->AddNode(voCarbonSupportSt3Ch6,1,trCarbon1St3);
837       voNomexSupportSt3Ch6->AddNode(voCarbonSupportSt3Ch6,2,trCarbon2St3);
838
839
840       // Add readout cables
841       gMC->Gsvolu("S05L","BOX",kCableMaterial,dum,0);
842       gMC->Gsvolu("S06L","BOX",kCableMaterial,dum,0);
843
844       ySlat3 = 0.;
845       Float_t lCableX = 0.;
846       Float_t lCableX6 = 0.;
847       Float_t lCableY = 0.;
848       Float_t lCableZ = 0.;
849       Float_t cablepar[3] = {supporthlength/2., kCableHeight/2., kCableWidth/2.};
850       Float_t cablepar6[3] = {supporthlengthCh6/2., kCableHeight/2., kCableWidth/2.};
851       Float_t lCableDY = 0.;
852       Int_t cIndex = 0;
853       Int_t cIndex6 = 0;
854       for (i = 0; i<kNslats3; i++){
855         Int_t iCable = 1;
856         cIndex = 0;
857         cIndex6 = 0;
858         ySlat3 += kYpos3[i];
859         lCableY = ySlat3;
860
861         // Cables going out from the start of slat
862         if(kNPCB3[i]>=4){ // Only if 4 or more pcb
863           // First top cables
864           cablepar[0] = supporthlength/2.;
865           lCableX = 0.;
866           cablepar6[0] = supporthlengthCh6/2.;
867           lCableX6 = 0.;
868           lCableDY = (kYpos3[i+1]+kYpos3[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
869           lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
870           if(i==0){ // central slat is shorter (rounded)
871             cablepar[0] -= (kPcbLength-csvPcbLength)/2.;
872             lCableX = (kPcbLength-csvPcbLength)/2.;
873             cablepar6[0] -= (kPcbLength-csvPcbLength)/2.;
874             lCableX6 = (kPcbLength-csvPcbLength)/2.;
875           }
876           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);       
877           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
878           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar6,3);    
879           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar6,3);
880
881           // Then bottom cables
882           if(i>0){
883             if(i==1){ // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
884               cablepar[0] -= dMotherInner/2.;
885               lCableX += dMotherInner/2.;
886               cablepar6[0] -= dMotherInner/2.;
887               lCableX6 += dMotherInner/2.;
888               lCableDY = (kYpos3[i]+kYpos3[i])/2.-cablepar[1];
889             }
890             if(i>=2){ 
891               lCableDY = (kYpos3[i]+kYpos3[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
892               if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
893                 lCableDY = lCableY - dMotherInner - cablepar[1];
894               }
895             }
896             gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
897             gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
898             gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
899             gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
900           }
901         }
902         
903         // Rounded slats have an extra cable starting at second pcb
904         if(i==1){ 
905           // First top cables
906           cablepar[0] = (supporthlength-kPcbLength-kVframeLength)/2.;
907           lCableX = (kPcbLength+kVframeLength)/2.;
908           cablepar6[0] = (supporthlengthCh6-kPcbLength-kVframeLength)/2.;
909           lCableX6 = (kPcbLength+kVframeLength)/2.;
910           lCableDY = (kYpos3[i+1]+kYpos3[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
911           lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
912           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);       
913           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
914           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar6,3);    
915           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar6,3);
916           // Then bottom cables
917           lCableDY = (kYpos3[i]+kYpos3[i])/2.-cablepar[1];
918           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
919           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
920           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
921           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
922         }
923         
924         // Cables going out from the end of the slats
925         // First top cables
926         cablepar[0] = (supporthlength-(slatLength3[i]+kDslatLength)+kVframeLength)/2.;
927         lCableX = slatLength3[i]-kVframeLength+kDslatLength+cablepar[0]-supporthlength/2.;
928         cablepar6[0] = (supporthlengthCh6-(slatLength3[i]+kDslatLength)+kVframeLength)/2.;
929         lCableX6 = slatLength3[i]-kVframeLength+kDslatLength+cablepar6[0]-supporthlengthCh6/2.;
930         if(i+1>=kNslats3 || i+2>=kNslats3){ // If no more higher slats, then use distance to lower slat
931           lCableDY = kPcbHeight/2.+cablepar[1];
932         }
933         else {
934           lCableDY = (kYpos3[i+1]+kYpos3[i+2])/2.-cablepar[1];
935         }
936         lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
937         if (i<=2){ // shortened pcb
938           cablepar[0] += pcbDLength3/2.;
939           lCableX -=  pcbDLength3/2.;
940         } 
941         gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
942         gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
943         gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
944         gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
945         // Then bottom cables
946         if(i>0){ // Loop is over top half of slats, lower half are symmetric 
947           if (i==1) {
948             lCableDY = (kYpos3[i]+kYpos3[i])/2.-cablepar[1];
949           }
950           else{
951             lCableDY = (kYpos3[i]+kYpos3[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
952           }
953           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
954           gMC->Gsposp("S05L",100*i+cIndex++,"S05S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
955           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar6,3); 
956           gMC->Gsposp("S06L",100*i+cIndex6++,"S06S",lCableX6,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar6,3); 
957         }
958       }
959
960       Float_t dzCh5  = dzCh;
961       TGeoTranslation* trSupport1St3   = new TGeoTranslation("trSupport1St3", supporthlength/2., 0. , dzCh5);
962       TGeoRotation*    roSupportSt3    = new TGeoRotation("roSupportSt3",90.,180.,-90.);
963       TGeoCombiTrans*  coSupport2St3   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh5, roSupportSt3);       
964       TGeoTranslation* trSupport1St3Ch6   = new TGeoTranslation("trSupport1St3Ch6", supporthlengthCh6/2., 0. , dzCh5);
965       TGeoCombiTrans*  coSupport2St3Ch6   = new TGeoCombiTrans(-supporthlengthCh6/2., 0., -dzCh5, roSupportSt3);       
966       GetEnvelopes(5)->AddEnvelope("S05S", 0, 1, *trSupport1St3);  
967       GetEnvelopes(4)->AddEnvelope("S05S", 0, 2, *coSupport2St3);  
968       GetEnvelopes(7)->AddEnvelope("S06S", 0, 1, *trSupport1St3Ch6);   
969       GetEnvelopes(6)->AddEnvelope("S06S", 0, 2, *coSupport2St3Ch6);  
970       // End of pannel support geometry          
971
972       // cout << "Geometry for Station 3...... done" << endl;   
973     }
974   if (fStations[3]) {
975
976
977     // //********************************************************************
978     // //                            Station 4                             **
979     // //********************************************************************
980     // Mother volume for each chamber in St4 is an envelop (or assembly)
981     // There is one assembly mother per half a chamber  called SC07I, SC07O, SC08I and SC08O
982     // Same volume name definitions as in St3
983     const Int_t   kNslats4          = 7;  // number of slats per quadrant
984     const Int_t   kNPCB4[kNslats4]  = {5, 6, 5, 5, 4, 3, 2}; // n PCB per slat
985     const Float_t kXpos4[kNslats4]  = {38.75, 0., 0., 0., 0., 0., 0.}; // J.C. Correct value
986     const Float_t kYpos41[kNslats4] = {0., 38.2, 34.40, 36.60, 29.3, 37.0, 28.6};
987     const Float_t kYpos42[kNslats4] = {0., 38.2, 37.85, 37.55, 29.4, 37.0, 28.6};
988     Float_t slatLength4[kNslats4];     
989
990     Float_t rPhi1 = TMath::RadToDeg()*(TMath::ASin((kYpos41[1]-hFramepar[1])/(AliMUONConstants::Rmin(3))));
991     Float_t rPhi2 = TMath::RadToDeg()*(TMath::ACos(-vFramepar[0]/(AliMUONConstants::Rmin(3)-kRframeLength)));
992     Float_t rFramepar4[5] = { AliMUONConstants::Rmin(3)-kRframeLength, AliMUONConstants::Rmin(3), kRframeWidth, rPhi1, rPhi2}; 
993     Float_t vrFrameHeight = hFramepar[1]+kYpos41[1]-AliMUONConstants::Rmin(3)+kRframeLength;
994     
995     char idSlatCh7[5];
996     char idSlatCh8[5];
997     Float_t xSlat4;
998     Float_t ySlat41 = 0;
999     Float_t ySlat42 = 0;
1000     angle = 0.;
1001
1002     for (i = 0; i<kNslats4; i++){
1003       slatLength4[i] = kPcbLength * kNPCB4[i] + 2. * kVframeLength; 
1004       xSlat4 = slatLength4[i]/2. + kDslatLength + kXpos4[i]; 
1005       ySlat41 += kYpos41[i];
1006       ySlat42 += kYpos42[i];
1007
1008       spar[0] = slatLength4[i]/2.; 
1009       spar[1] = kSlatHeight/2.;
1010       spar[2] = kSlatWidth/2.; 
1011       Float_t dzCh4 = dzCh;
1012       Float_t zSlat4 = (i%2 ==0)? -zSlat : zSlat; 
1013
1014       sprintf(idSlatCh7,"LC%d",kNslats4-1+i);
1015       detElemId = 713 - (i + kNslats4-1-6);
1016       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1017       if (detElemId % 2 == 0)
1018           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, ySlat41, -zSlat4 + dzCh4),
1019                                    TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
1020       else
1021           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, ySlat41, -zSlat4 + dzCh4),
1022                                    TGeoRotation("rot1",90,angle,90,270+angle,180,0) );
1023
1024       sprintf(idSlatCh7,"LC%d",3*kNslats4-2+i);
1025       detElemId = 700 + (i + kNslats4-1-6);
1026       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1027       if (detElemId % 2 == 0)
1028           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, ySlat41, zSlat4 - dzCh4),
1029                                    TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );
1030       else
1031           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, ySlat41, zSlat4 - dzCh4),
1032                                    TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
1033       if (i > 0) { 
1034         sprintf(idSlatCh7,"LC%d",kNslats4-1-i);
1035         detElemId = 713 + (i + kNslats4-1-6);
1036         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1037         if (detElemId % 2 == 0 && detElemId != 714)
1038             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, -ySlat41, -zSlat4 + dzCh4),
1039                                                 TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
1040         else
1041             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, -ySlat41, -zSlat4 + dzCh4),
1042                                                 TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
1043         sprintf(idSlatCh7,"LC%d",3*kNslats4-2-i);
1044         detElemId = 726 - (i + kNslats4-1-6);
1045         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1046         if (detElemId % 2 == 1 && detElemId != 725 )
1047             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, -ySlat41, zSlat4 - dzCh4),
1048                                      TGeoRotation("rot4",90,180+angle,90,90+angle,180,0) );
1049         else
1050              GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, -ySlat41, zSlat4 - dzCh4),
1051                                      TGeoRotation("rot4",90,180+angle,90,270+angle,0,0) ); 
1052       }
1053
1054       sprintf(idSlatCh8,"LD%d",kNslats4-1+i);
1055       detElemId = 813 - (i + kNslats4-1-6);
1056       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1057       if (detElemId % 2 == 0)
1058           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, ySlat42, -zSlat4 + dzCh4),
1059                                    TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
1060       else
1061           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, ySlat42, -zSlat4 + dzCh4),
1062                                    TGeoRotation("rot5",90,angle,90,270+angle,180,0) ); 
1063
1064       sprintf(idSlatCh8,"LD%d",3*kNslats4-2+i);
1065       detElemId = 800 + (i + kNslats4-1-6);
1066       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1067       if (detElemId % 2 == 0)
1068           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, ySlat42, zSlat4 - dzCh4),
1069                                    TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
1070       else
1071           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, ySlat42, zSlat4 - dzCh4),
1072                                    TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) );
1073       if (i > 0) { 
1074         sprintf(idSlatCh8,"LD%d",kNslats4-1-i);
1075         detElemId = 813 + (i + kNslats4-1-6);
1076         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1077         if (detElemId % 2 == 0 && detElemId != 814)
1078             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, -ySlat42, -zSlat4 + dzCh4),
1079                                                 TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
1080         else
1081             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, -ySlat42, -zSlat4 + dzCh4),
1082                                                 TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
1083         sprintf(idSlatCh8,"LD%d",3*kNslats4-2-i);
1084         detElemId = 826 - (i + kNslats4-1-6);
1085         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1086         if (detElemId % 2 == 1 && detElemId != 825 )
1087             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, -ySlat42, zSlat4 - dzCh4),
1088                                      TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) ); 
1089         else
1090             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, -ySlat42, zSlat4 - dzCh4),
1091                                      TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) );
1092           
1093       }
1094     }
1095      
1096     // create the panel volume 
1097  
1098     gMC->Gsvolu("S07C","BOX",kCarbonMaterial,panelpar,3);
1099     gMC->Gsvolu("SD7C","BOX",kCarbonMaterial,panelpar,3);
1100     gMC->Gsvolu("S08C","BOX",kCarbonMaterial,panelpar,3);
1101     gMC->Gsvolu("SD8C","BOX",kCarbonMaterial,panelpar,3);
1102
1103     // create the nomex volume 
1104
1105     gMC->Gsvolu("S07N","BOX",kNomexMaterial,nomexpar,3);
1106     gMC->Gsvolu("SD7N","BOX",kNomexMaterial,nomexpar,3);
1107     gMC->Gsvolu("S08N","BOX",kNomexMaterial,nomexpar,3);
1108     gMC->Gsvolu("SD8N","BOX",kNomexMaterial,nomexpar,3);
1109
1110
1111     // create the nomex volume (bulk)
1112
1113     gMC->Gsvolu("S07X","BOX",kNomexBMaterial,nomexbpar,3);
1114     gMC->Gsvolu("SD7X","BOX",kNomexBMaterial,nomexbpar,3);
1115     gMC->Gsvolu("S08X","BOX",kNomexBMaterial,nomexbpar,3);
1116     gMC->Gsvolu("SD8X","BOX",kNomexBMaterial,nomexbpar,3);
1117
1118     // create the insulating material volume 
1119
1120     gMC->Gsvolu("S07I","BOX",kInsuMaterial,insupar,3);
1121     gMC->Gsvolu("SD7I","BOX",kInsuMaterial,insupar,3);
1122     gMC->Gsvolu("S08I","BOX",kInsuMaterial,insupar,3);
1123     gMC->Gsvolu("SD8I","BOX",kInsuMaterial,insupar,3);
1124
1125     // create the PCB volume 
1126
1127     gMC->Gsvolu("S07P","BOX",kPcbMaterial,pcbpar,3);
1128     gMC->Gsvolu("SD7P","BOX",kPcbMaterial,pcbpar,3);
1129     gMC->Gsvolu("S08P","BOX",kPcbMaterial,pcbpar,3);
1130     gMC->Gsvolu("SD8P","BOX",kPcbMaterial,pcbpar,3);
1131  
1132     // create the sensitive volumes,
1133
1134     gMC->Gsvolu("S07G","BOX",kSensMaterial,dum,0);
1135     gMC->Gsvolu("SD7G","BOX",kSensMaterial,senspar,3);
1136     gMC->Gsvolu("S08G","BOX",kSensMaterial,dum,0);
1137     gMC->Gsvolu("SD8G","BOX",kSensMaterial,senspar,3);
1138
1139     // create the vertical frame volume 
1140
1141     gMC->Gsvolu("S07V","BOX",kVframeMaterial,vFramepar,3);
1142     gMC->Gsvolu("S08V","BOX",kVframeMaterial,vFramepar,3);
1143
1144     // create the rounded vertical frame volume 
1145
1146     gMC->Gsvolu("SD7D","TUBS",kRframeMaterial,rFramepar4,5);
1147     gMC->Gsvolu("SD8D","TUBS",kRframeMaterial,rFramepar4,5);
1148     
1149     // create the horizontal frame volume 
1150
1151     gMC->Gsvolu("S07H","BOX",kHframeMaterial,hFramepar,3);
1152     gMC->Gsvolu("SD7H","BOX",kHframeMaterial,hFramepar,3);
1153     gMC->Gsvolu("S08H","BOX",kHframeMaterial,hFramepar,3);
1154     gMC->Gsvolu("SD8H","BOX",kHframeMaterial,hFramepar,3);
1155
1156     // create the horizontal border volume 
1157
1158     gMC->Gsvolu("S07B","BOX",kBframeMaterial,bFramepar,3);
1159     gMC->Gsvolu("SD7B","BOX",kBframeMaterial,bFramepar,3);
1160     gMC->Gsvolu("S08B","BOX",kBframeMaterial,bFramepar,3);
1161     gMC->Gsvolu("SD8B","BOX",kBframeMaterial,bFramepar,3);
1162
1163     // Replace the volume shape with a composite shape
1164     // with substracted overlap with beam shield     
1165     if ( gMC->IsRootGeometrySupported() ) { 
1166         
1167       // Get shape
1168       Int_t nSlatType = 1;
1169       Int_t nVol = 8;
1170       const char* slatType = "D"; // D: Rounded slat
1171       const char* volLetter = "CNXIPHBG";
1172       TString volName;
1173       TString compName;
1174       TString csName;
1175       TGeoVolume *mVol = 0x0;
1176       // Beam shield recess
1177       new TGeoTube("tube4Cut", 0., AliMUONConstants::Rmin(3), kSlatWidth/2.+0.001);
1178       TObjArray rounded4Slat(nSlatType*((nVol+1)*2));   
1179       // Displacement
1180       TGeoTranslation* trDTube4 = new TGeoTranslation("trDTube4", -(kPcbLength+kVframeLength)/2., -kYpos41[1], 0.);
1181       trDTube4->RegisterYourself();
1182       TObjArray composite4(nSlatType*((nVol+1)*2));
1183       new TGeoBBox("box4DCut",(kPcbLength+kVframeLength)/2., hFramepar[1], vFramepar[2]+0.001);
1184       // Displacement
1185       TGeoTranslation* trDBox4 = new TGeoTranslation("trDBox4",kPcbLength/2., kYpos41[1], 0.);
1186       trDBox4->RegisterYourself();      
1187
1188       TGeoBBox *box4Vframe = new TGeoBBox("box4Vframe",vFramepar[0],vrFrameHeight/2., vFramepar[2]);
1189       TGeoTranslation* trVBox4 = new TGeoTranslation("trVBox4", 0., AliMUONConstants::Rmin(3)-kRframeLength + box4Vframe->GetDY(), 0.);
1190       trVBox4->RegisterYourself();
1191       
1192       for(int iCh=7; iCh<=8; iCh++){
1193         for (int iSlatType = 0; iSlatType<nSlatType; iSlatType++) {
1194           for (int iVol = 0; iVol<nVol; iVol++){
1195             Int_t lIndex = (iCh-7)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+iVol;
1196             volName=Form("S%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
1197             mVol = gGeoManager->FindVolumeFast(volName);
1198             if ( !mVol ) {
1199               AliErrorStream() 
1200                 << "Slat volume " << volName << " not found" << endl;    
1201             }
1202             else {
1203               rounded4Slat[lIndex] = mVol->GetShape();
1204               csName=Form("rounded4Slat%c%d%c",slatType[iSlatType],iCh,volLetter[iVol]);
1205               ((TGeoShape*)rounded4Slat[lIndex])->SetName(csName);
1206               
1207               // Composite shape
1208               TString compOperation(csName);
1209               compOperation+="-tube4Cut:tr";
1210               compOperation+=slatType[iSlatType];
1211               compOperation+="Tube4";
1212               if (strstr(volName,"B")){
1213                 // Displacement
1214                 Float_t posXb = 0.;
1215                 Float_t posYb = -( kPcbHeight - kBframeHeight ) / 2.;
1216                 Float_t posZb = 0.;
1217                 TGeoTranslation* trB = new TGeoTranslation("trB", posXb, posYb, posZb);
1218                 trB->RegisterYourself();
1219                 compOperation.ReplaceAll("-tube4Cut",":trB-tube4Cut");
1220               }
1221               compName=Form("composite4%d%c",iCh,volLetter[iVol]);
1222               composite4[lIndex] = new TGeoCompositeShape(compName, compOperation.Data()); 
1223               
1224               // Reset shape to volume      
1225               mVol->SetShape((TGeoShape*)composite4[lIndex]);
1226             }
1227           }
1228
1229           // For rounded spacer
1230           Int_t lIndex = (iCh-7)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+nVol;
1231           volName=Form("S%c%dD",slatType[iSlatType],iCh);
1232           mVol = gGeoManager->FindVolumeFast(volName);
1233           if ( !mVol ) {
1234             AliErrorStream() 
1235               << "Slat volume " << volName << " not found" << endl;      
1236           }
1237           else {
1238             rounded4Slat[lIndex] = mVol->GetShape();
1239             csName=Form("rounded4Slat%c%dD",slatType[iSlatType],iCh);
1240             ((TGeoShape*)rounded4Slat[lIndex])->SetName(csName);
1241             
1242             // Composite shape
1243             TString compOperation(csName);
1244             if (strstr(volName,"SD")){
1245               compOperation.Prepend("(");
1246               compOperation+="+box4Vframe:trVBox4)*box4DCut:trDBox4";
1247             }
1248             compName=Form("composite4%c%dD",slatType[iSlatType],iCh);
1249             composite4[lIndex] = new TGeoCompositeShape(compName, compOperation.Data());              
1250             // Reset shape to volume      
1251             mVol->SetShape((TGeoShape*)composite4[lIndex]);
1252           }
1253         }
1254       }
1255     }
1256
1257
1258     index = 0; 
1259     for (i = 0; i < kNslats4; i++){
1260       for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
1261
1262         if (i == 0 && quadrant == 2) continue;
1263         if (i == 0 && quadrant == 4) continue;
1264
1265         sprintf(idSlatCh7,"LC%d",ConvertSlatNum(i,quadrant,kNslats4-1));
1266         sprintf(idSlatCh8,"LD%d",ConvertSlatNum(i,quadrant,kNslats4-1));
1267         Int_t moduleSlatCh7 = GetModuleId(idSlatCh7);
1268         Int_t moduleSlatCh8 = GetModuleId(idSlatCh8);
1269
1270         Float_t xvFrame  = (slatLength4[i] - kVframeLength)/2.;
1271
1272         // position the vertical frames 
1273         if (i != 1) { 
1274           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1275           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1276           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1277           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1278         } else { // Vertical and Rounded+Vertical spacer 
1279           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1280           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7D", idSlatCh7, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos41[1],0.));
1281           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1282           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8D", idSlatCh8, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos42[1],0.));
1283         }
1284         // position the panels and the insulating material 
1285         for (j = 0; j < kNPCB4[i]; j++){
1286           index++;
1287           Float_t xx = kSensLength * (-kNPCB4[i]/2.+j+.5); 
1288           Float_t zPanel = spar[2] - nomexbpar[2]; 
1289           if (i==1 && j==0){ // Rounded pcb of rounded slat
1290             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7X", idSlatCh7, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1291             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7X", idSlatCh7, 2*index,TGeoTranslation(xx,0.,-zPanel));
1292             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("SD7I", idSlatCh7, index,TGeoTranslation(xx,0.,0.));
1293             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8X", idSlatCh8, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1294             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8X", idSlatCh8, 2*index,TGeoTranslation(xx,0.,-zPanel));
1295             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("SD8I", idSlatCh8, index,TGeoTranslation(xx,0.,0.));
1296           } else {            
1297             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07X", idSlatCh7, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1298             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07X", idSlatCh7, 2*index,TGeoTranslation(xx,0.,-zPanel));
1299             GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07I", idSlatCh7, index,TGeoTranslation(xx,0.,0.));
1300             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08X", idSlatCh8, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1301             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08X", idSlatCh8, 2*index,TGeoTranslation(xx,0.,-zPanel));
1302             GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08I", idSlatCh8, index,TGeoTranslation(xx,0.,0.));
1303           }
1304         }
1305       } 
1306     }
1307
1308     // position the nomex volume inside the panel volume
1309     gMC->Gspos("S07N",1,"S07C",0.,0.,0.,0,"ONLY"); 
1310     gMC->Gspos("SD7N",1,"SD7C",0.,0.,0.,0,"ONLY"); 
1311     gMC->Gspos("S08N",1,"S08C",0.,0.,0.,0,"ONLY"); 
1312     gMC->Gspos("SD8N",1,"SD8C",0.,0.,0.,0,"ONLY"); 
1313
1314     // position panel volume inside the bulk nomex material volume
1315     gMC->Gspos("S07C",1,"S07X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1316     gMC->Gspos("SD7C",1,"SD7X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1317     gMC->Gspos("S08C",1,"S08X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1318     gMC->Gspos("SD8C",1,"SD8X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1319
1320     // position the PCB volume inside the insulating material volume
1321     gMC->Gspos("S07P",1,"S07I",0.,0.,0.,0,"ONLY"); 
1322     gMC->Gspos("SD7P",1,"SD7I",0.,0.,0.,0,"ONLY"); 
1323     gMC->Gspos("S08P",1,"S08I",0.,0.,0.,0,"ONLY"); 
1324     gMC->Gspos("SD8P",1,"SD8I",0.,0.,0.,0,"ONLY"); 
1325
1326     // position the horizontal frame volume inside the PCB volume
1327     gMC->Gspos("S07H",1,"S07P",0.,0.,0.,0,"ONLY"); 
1328     gMC->Gspos("SD7H",1,"SD7P",0.,0.,0.,0,"ONLY"); 
1329     gMC->Gspos("S08H",1,"S08P",0.,0.,0.,0,"ONLY"); 
1330     gMC->Gspos("SD8H",1,"SD8P",0.,0.,0.,0,"ONLY"); 
1331
1332     // position the sensitive volume inside the horizontal frame volume
1333     gMC->Gsposp("S07G",1,"S07H",0.,0.,0.,0,"ONLY",senspar,3); 
1334     gMC->Gspos("SD7G",1,"SD7H",0.,0.,0.,0,"ONLY"); 
1335     gMC->Gsposp("S08G",1,"S08H",0.,0.,0.,0,"ONLY",senspar,3); 
1336     gMC->Gspos("SD8G",1,"SD8H",0.,0.,0.,0,"ONLY"); 
1337
1338     // position the border volumes inside the PCB volume
1339     Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
1340     gMC->Gspos("S07B",1,"S07P",0., yborder,0.,0,"ONLY"); 
1341     gMC->Gspos("S07B",2,"S07P",0.,-yborder,0.,0,"ONLY");
1342     gMC->Gspos("SD7B",1,"SD7P",0., 0.,0.,0,"ONLY"); 
1343     gMC->Gspos("S07B",1,"SD7P",0., yborder,0.,0,"ONLY"); 
1344     gMC->Gspos("S08B",1,"S08P",0., yborder,0.,0,"ONLY"); 
1345     gMC->Gspos("S08B",2,"S08P",0.,-yborder,0.,0,"ONLY"); 
1346     gMC->Gspos("SD8B",1,"SD8P",0., 0.,0.,0,"ONLY"); 
1347     gMC->Gspos("S08B",1,"SD8P",0., yborder,0.,0,"ONLY"); 
1348
1349     // create the NULOC volume and position it in the horizontal frame
1350
1351     gMC->Gsvolu("S07E","BOX",kNulocMaterial,nulocpar,3);
1352     gMC->Gsvolu("S08E","BOX",kNulocMaterial,nulocpar,3);
1353     index = 0;
1354     Float_t rPhi3 = TMath::ASin((kYpos41[1]-kPcbHeight/2.)/AliMUONConstants::Rmin(3));
1355     Float_t xxmax4 = (AliMUONConstants::Rmin(3)*TMath::Cos(rPhi3)-kVframeLength/2.) - (kBframeLength - kNulocLength)/2.;
1356     for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
1357       index++; 
1358       gMC->Gspos("S07E",2*index-1,"S07B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
1359       gMC->Gspos("S07E",2*index  ,"S07B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
1360       gMC->Gspos("S08E",2*index-1,"S08B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
1361       gMC->Gspos("S08E",2*index  ,"S08B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
1362     }
1363     if (xx > xxmax4 && xx< xxmax) {
1364       gMC->Gspos("S07E",2*index-1,"SD7B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
1365       gMC->Gspos("S07E",2*index  ,"SD7B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
1366       gMC->Gspos("S08E",2*index-1,"SD8B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
1367       gMC->Gspos("S08E",2*index  ,"SD8B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
1368     }
1369
1370     //
1371     //Geometry of the support pannel Verticla length 5.3m, horizontal length 2.6m, internal radius  dMotherInner o SC07 and SC08  (F. Orsini, Saclay)
1372     //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
1373     Float_t dMotherInner =  AliMUONConstants::Rmin(3)-kRframeHeight; 
1374     Float_t nomexthickness = 1.5;
1375     Float_t carbonthickness = 0.03;
1376     Float_t supporthlength =  260.;  
1377     Float_t supportvlength =  530.;  
1378     // Generating the composite shape of the carbon and nomex pannels
1379     new TGeoBBox("shNomexBoxSt4",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
1380     new TGeoBBox("shCarbonBoxSt4",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
1381     new TGeoTubeSeg("shNomexHoleSt4",0., dMotherInner, nomexthickness/2.+carbonthickness+3*kCableWidth+0.001, -90. ,90.);
1382     new TGeoTubeSeg("shCarbonHoleSt4",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
1383     TGeoTranslation* trHoleSt4 = new TGeoTranslation("trHoleSt4",-supporthlength/2.,0.,0.); 
1384     trHoleSt4->RegisterYourself();
1385     TGeoCompositeShape* shNomexSupportSt4  = new TGeoCompositeShape("shNomexSupportSt4","shNomexBoxSt4-shNomexHoleSt4:trHoleSt4");
1386     TGeoCompositeShape* shCarbonSupportSt4 = new TGeoCompositeShape("shCarbonSupportSt4","shCarbonBoxSt4-shCarbonHoleSt4:trHoleSt4");
1387  
1388    // Generating Nomex and Carbon pannel volumes
1389     TGeoVolume* voNomexSupportSt4   = new TGeoVolume("S07S", shNomexSupportSt4, kMedNomex);
1390     TGeoVolume* voCarbonSupportSt4  = new TGeoVolume("S07K", shCarbonSupportSt4, kMedCarbon);
1391     TGeoVolume* voNomexSupportSt4Ch8   = new TGeoVolume("S08S", shNomexSupportSt4, kMedNomex);
1392     TGeoVolume* voCarbonSupportSt4Ch8  = new TGeoVolume("S08K", shCarbonSupportSt4, kMedCarbon);
1393     TGeoTranslation* trCarbon1St4   = new TGeoTranslation("trCarbon1St4",0.,0., -(nomexthickness+carbonthickness)/2.);
1394     TGeoTranslation* trCarbon2St4   = new TGeoTranslation("trCarbon2St4",0.,0.,  (nomexthickness+carbonthickness)/2.);
1395     voNomexSupportSt4->AddNode(voCarbonSupportSt4,1,trCarbon1St4);
1396     voNomexSupportSt4->AddNode(voCarbonSupportSt4,2,trCarbon2St4);
1397     voNomexSupportSt4Ch8->AddNode(voCarbonSupportSt4Ch8,1,trCarbon1St4);
1398     voNomexSupportSt4Ch8->AddNode(voCarbonSupportSt4Ch8,2,trCarbon2St4);
1399  
1400     // Add readout cables
1401     gMC->Gsvolu("S07L","BOX",kCableMaterial,dum,0);
1402     gMC->Gsvolu("S08L","BOX",kCableMaterial,dum,0);
1403
1404     ySlat41 = 0.;
1405     ySlat42 = 0.;
1406     Float_t lCableX = 0.;
1407     Float_t lCableY = 0.;
1408     Float_t lCableY8 = 0.;
1409     Float_t lCableZ = 0.;
1410     Float_t cablepar[3] = {supporthlength/2., kCableHeight/2., kCableWidth/2.};
1411     Float_t lCableDY = 0.;
1412     Float_t lCableDY8 = 0.;
1413     for (i = 0; i<kNslats4; i++){
1414       Int_t iCable = 1;
1415       Int_t cIndex = 0;
1416       Int_t cIndex8 = 0;
1417       ySlat41 += kYpos41[i];
1418       ySlat42 += kYpos42[i];
1419
1420       lCableY = ySlat41;
1421       lCableY8 = ySlat42;
1422
1423       // Cables going out from the start of slat
1424       if(kNPCB4[i]>=4){ // Only if 4 or more pcb
1425         // First top cables
1426         cablepar[0] = (supporthlength-kXpos4[i])/2.;
1427         lCableX = kXpos4[i]/2.;
1428         lCableDY = (kYpos41[i+1]+kYpos41[i+2])/2.-cablepar[1];
1429         lCableDY8 = (kYpos42[i+1]+kYpos42[i+2])/2.-cablepar[1];
1430         lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
1431         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);  
1432         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
1433         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8+lCableDY8,lCableZ,0,"ONLY",cablepar,3);       
1434         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8+lCableDY8),lCableZ,0,"ONLY",cablepar,3);
1435         // Then bottom cables
1436         if (i>0){
1437           if (i==1) { // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
1438             cablepar[0] = (supporthlength-kXpos4[i]-dMotherInner)/2.;
1439             lCableX = (kXpos4[i]+dMotherInner)/2.;
1440             lCableDY = (kYpos41[i]+kYpos41[i])/2.-cablepar[1];
1441             lCableDY8 = (kYpos42[i]+kYpos42[i])/2.-cablepar[1];
1442           }
1443           if (i>=2) {
1444             lCableDY = (kYpos41[i]+kYpos41[i-1])/2.-cablepar[1];
1445             if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
1446               lCableDY = lCableY - dMotherInner - cablepar[1];
1447             }
1448             lCableDY8 = (kYpos42[i]+kYpos42[i-1])/2.-cablepar[1];
1449             if ((lCableY8-lCableDY8)<(dMotherInner+cablepar[1])){
1450               lCableDY8 = lCableY8 - dMotherInner - cablepar[1];
1451             }
1452           }
1453           gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
1454           gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
1455           gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8-lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
1456           gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8-lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
1457         }
1458       }
1459
1460       // Rounded slats have an extra cable starting at second pcb
1461       if(i==1){ 
1462         // Only on top
1463         cablepar[0] = (supporthlength-kPcbLength-kVframeLength)/2.;
1464         lCableX = (kPcbLength+kVframeLength)/2.;
1465         lCableDY = (kYpos41[i+1]+kYpos41[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
1466         lCableDY8 = (kYpos42[i+1]+kYpos42[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
1467         lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
1468         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
1469         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
1470         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8+lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
1471         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8+lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
1472       } 
1473
1474       // Cables going out from the end of the slats
1475       cablepar[0] = (supporthlength-(slatLength4[i]+kXpos4[i]+kDslatLength)+kVframeLength)/2.;
1476       lCableX = slatLength4[i]+kXpos4[i]-kVframeLength+kDslatLength+cablepar[0]-supporthlength/2.;
1477       if(i+1>=kNslats4 || i+2>=kNslats4){ // If no more higher slats, then use distance to lower slat
1478         lCableDY = kPcbHeight/2.+cablepar[1];
1479         lCableDY8 = lCableDY;
1480       }
1481       else {
1482         lCableDY = (kYpos41[i+1]+kYpos41[i+2])/2.-cablepar[1];
1483         lCableDY8 = (kYpos42[i+1]+kYpos42[i+2])/2.-cablepar[1];
1484       }
1485       lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
1486       gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
1487       gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
1488       gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8+lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
1489       gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8+lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
1490       // Then bottom cables
1491       if(i>0){
1492         if (i==1) {
1493           lCableDY = (kYpos41[i]+kYpos41[i])/2.-cablepar[1];
1494           lCableDY8 = (kYpos42[i]+kYpos42[i])/2.-cablepar[1];
1495         }
1496         else{
1497           lCableDY = (kYpos41[i]+kYpos41[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
1498           if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
1499             lCableDY = lCableY - dMotherInner - cablepar[1];
1500           }
1501           lCableDY8 = (kYpos42[i]+kYpos42[i-1])/2.-cablepar[1]; // half way between 2 slats on same side
1502           if ((lCableY8-lCableDY8)<(dMotherInner+cablepar[1])){
1503             lCableDY8 = lCableY8 - dMotherInner - cablepar[1];
1504           }
1505         }
1506         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
1507         gMC->Gsposp("S07L",10*i+cIndex++,"S07S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
1508         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,lCableY8-lCableDY8,lCableZ,0,"ONLY",cablepar,3); 
1509         gMC->Gsposp("S08L",10*i+cIndex8++,"S08S",lCableX,-(lCableY8-lCableDY8),lCableZ,0,"ONLY",cablepar,3); 
1510       } 
1511     }
1512     
1513     Float_t dzCh7  = dzCh;
1514     TGeoTranslation* trSupport1St4   = new TGeoTranslation("trSupport1St4", supporthlength/2., 0. , dzCh7);
1515     TGeoRotation*    roSupportSt4    = new TGeoRotation("roSupportSt4",90.,180.,-90.);
1516     TGeoCombiTrans*  coSupport2St4   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh7, roSupportSt4); 
1517     GetEnvelopes(9)->AddEnvelope("S07S", 0, 1, *trSupport1St4);  
1518     GetEnvelopes(8)->AddEnvelope("S07S", 0, 2, *coSupport2St4);  
1519     GetEnvelopes(11)->AddEnvelope("S08S", 0, 1, *trSupport1St4);   
1520     GetEnvelopes(10)->AddEnvelope("S08S", 0, 2, *coSupport2St4);
1521
1522     // End of pannel support geometry    
1523
1524     // cout << "Geometry for Station 4...... done" << endl;
1525
1526   }
1527     
1528   if (fStations[4]) {
1529       
1530
1531     // //********************************************************************
1532     // //                            Station 5                             **
1533     // //********************************************************************
1534     // Mother volume for each chamber in St4 is an envelop (or assembly)
1535     // There is one assembly mother per half a chamber  called SC09I, SC09O, SC10I and SC10O 
1536     // Same volume name definitions as in St3
1537     
1538     const Int_t   kNslats5         = 7;  // number of slats per quadrant
1539     const Int_t   kNPCB5[kNslats5] = {5, 6, 6, 6, 5, 4, 3}; // n PCB per slat
1540     const Float_t kXpos5[kNslats5] = {38.75, 0., 0., 0., 0., 0., 0.}; // J.C. Correct value  
1541     const Float_t kYpos5[kNslats5] = {0., 38.2, 37.9, 37.6, 37.3, 37.05, 36.75};
1542     Float_t slatLength5[kNslats5]; 
1543
1544     Float_t rPhi1 = TMath::RadToDeg()*(TMath::ASin((kYpos5[1]-hFramepar[1])/(AliMUONConstants::Rmin(4))));
1545     Float_t rPhi2 = TMath::RadToDeg()*(TMath::ACos(-vFramepar[0]/(AliMUONConstants::Rmin(4)-kRframeLength)));
1546     Float_t rFramepar5[5] = { AliMUONConstants::Rmin(4)-kRframeLength, AliMUONConstants::Rmin(4), kRframeWidth, rPhi1, rPhi2}; 
1547     Float_t vrFrameHeight = hFramepar[1]+kYpos5[1]-AliMUONConstants::Rmin(4)+kRframeLength;
1548
1549     char idSlatCh9[5];
1550     char idSlatCh10[5];
1551     Float_t xSlat5;
1552     Float_t ySlat5 = 0;
1553     angle = 0.;
1554
1555     for (i = 0; i < kNslats5; i++){
1556
1557       slatLength5[i] = kPcbLength * kNPCB5[i] + 2.* kVframeLength; 
1558       xSlat5 = slatLength5[i]/2. + kDslatLength + kXpos5[i]; 
1559       ySlat5 += kYpos5[i];
1560
1561       spar[0] = slatLength5[i]/2.; 
1562       spar[1] = kSlatHeight/2.;
1563       spar[2] = kSlatWidth/2.; 
1564
1565       Float_t dzCh5  = dzCh;
1566       Float_t zSlat5 = (i%2 ==0)? -zSlat : zSlat; 
1567
1568       sprintf(idSlatCh9,"LE%d",kNslats5-1+i);
1569       detElemId = 913 - (i + kNslats5-1-6);
1570       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1571       if (detElemId % 2 == 0)
1572           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1573                                               TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
1574       else
1575           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1576                                               TGeoRotation("rot1",90,angle,90,270+angle,180,0) );
1577       sprintf(idSlatCh9,"LE%d",3*kNslats5-2+i);
1578       detElemId = 900 + (i + kNslats5-1-6);
1579       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1580       if (detElemId % 2 == 0)
1581           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1582                                               TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );
1583       else
1584           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1585                                               TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
1586       if (i > 0) { 
1587         sprintf(idSlatCh9,"LE%d",kNslats5-1-i);
1588         detElemId = 913 + (i + kNslats5-1-6);
1589         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1590       if (detElemId % 2 == 0  && detElemId != 914)
1591           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1592                                      TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
1593       else
1594           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1595                                      TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
1596         sprintf(idSlatCh9,"LE%d",3*kNslats5-2-i);
1597         detElemId = 926 - (i + kNslats5-1-6);
1598         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1599         if (detElemId % 2 == 1 && detElemId != 925 )
1600             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1601                                                 TGeoRotation("rot4",90,180+angle,90,90+angle,180,0)  );
1602         else
1603             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1604                                                 TGeoRotation("rot4",90,180+angle,90,270+angle,0,0)  );   
1605       }
1606
1607       sprintf(idSlatCh10,"LF%d",kNslats5-1+i);
1608       detElemId = 1013 - (i + kNslats5-1-6);
1609       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1610       if (detElemId % 2 == 0)
1611           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1612                                               TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
1613       else
1614           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1615                                               TGeoRotation("rot5",90,angle,90,270+angle,180,0) );
1616
1617       sprintf(idSlatCh10,"LF%d",3*kNslats5-2+i);
1618       detElemId = 1000 + (i + kNslats5-1-6);
1619       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1620       if (detElemId % 2 == 0)
1621           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1622                                               TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
1623       else
1624           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1625                                               TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) ); 
1626       if (i > 0) { 
1627         sprintf(idSlatCh10,"LF%d",kNslats5-1-i);
1628         detElemId = 1013 + (i + kNslats5-1-6);
1629         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1630       if (detElemId % 2 == 0  && detElemId != 1014)
1631           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1632                                      TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
1633       else
1634           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1635                                      TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
1636         sprintf(idSlatCh10,"LF%d",3*kNslats5-2-i);
1637         detElemId = 1026 - (i + kNslats5-1-6);
1638         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1639         if (detElemId % 2 == 1 && detElemId != 1025 )
1640             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1641                                               TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) );
1642         else
1643             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1644                                               TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) ); 
1645       }
1646     }
1647
1648     // create the panel volume 
1649  
1650     gMC->Gsvolu("S09C","BOX",kCarbonMaterial,panelpar,3);
1651     gMC->Gsvolu("SD9C","BOX",kCarbonMaterial,panelpar,3);
1652     gMC->Gsvolu("S10C","BOX",kCarbonMaterial,panelpar,3);
1653     gMC->Gsvolu("SD0C","BOX",kCarbonMaterial,panelpar,3);
1654
1655     // create the nomex volume 
1656
1657     gMC->Gsvolu("S09N","BOX",kNomexMaterial,nomexpar,3);
1658     gMC->Gsvolu("SD9N","BOX",kNomexMaterial,nomexpar,3);
1659     gMC->Gsvolu("S10N","BOX",kNomexMaterial,nomexpar,3);
1660     gMC->Gsvolu("SD0N","BOX",kNomexMaterial,nomexpar,3);
1661
1662
1663     // create the nomex volume (bulk)
1664
1665     gMC->Gsvolu("S09X","BOX",kNomexBMaterial,nomexbpar,3);
1666     gMC->Gsvolu("SD9X","BOX",kNomexBMaterial,nomexbpar,3);
1667     gMC->Gsvolu("S10X","BOX",kNomexBMaterial,nomexbpar,3);
1668     gMC->Gsvolu("SD0X","BOX",kNomexBMaterial,nomexbpar,3);
1669
1670     // create the insulating material volume 
1671
1672     gMC->Gsvolu("S09I","BOX",kInsuMaterial,insupar,3);
1673     gMC->Gsvolu("SD9I","BOX",kInsuMaterial,insupar,3);
1674     gMC->Gsvolu("S10I","BOX",kInsuMaterial,insupar,3);
1675     gMC->Gsvolu("SD0I","BOX",kInsuMaterial,insupar,3);
1676
1677     // create the PCB volume 
1678
1679     gMC->Gsvolu("S09P","BOX",kPcbMaterial,pcbpar,3);
1680     gMC->Gsvolu("SD9P","BOX",kPcbMaterial,pcbpar,3);
1681     gMC->Gsvolu("S10P","BOX",kPcbMaterial,pcbpar,3);
1682     gMC->Gsvolu("SD0P","BOX",kPcbMaterial,pcbpar,3);
1683  
1684     // create the sensitive volumes,
1685
1686     gMC->Gsvolu("S09G","BOX",kSensMaterial,dum,0);
1687     gMC->Gsvolu("SD9G","BOX",kSensMaterial,senspar,3);
1688     gMC->Gsvolu("S10G","BOX",kSensMaterial,dum,0);
1689     gMC->Gsvolu("SD0G","BOX",kSensMaterial,senspar,3);
1690
1691     // create the vertical frame volume 
1692
1693     gMC->Gsvolu("S09V","BOX",kVframeMaterial,vFramepar,3);
1694     gMC->Gsvolu("S10V","BOX",kVframeMaterial,vFramepar,3);
1695
1696     // create the rounded vertical frame volume 
1697
1698     gMC->Gsvolu("SD9D","TUBS",kRframeMaterial,rFramepar5,5);
1699     gMC->Gsvolu("SD0D","TUBS",kRframeMaterial,rFramepar5,5);
1700
1701     // create the horizontal frame volume 
1702
1703     gMC->Gsvolu("S09H","BOX",kHframeMaterial,hFramepar,3);
1704     gMC->Gsvolu("SD9H","BOX",kHframeMaterial,hFramepar,3);
1705     gMC->Gsvolu("S10H","BOX",kHframeMaterial,hFramepar,3);
1706     gMC->Gsvolu("SD0H","BOX",kHframeMaterial,hFramepar,3);
1707
1708     // create the horizontal border volume 
1709
1710     gMC->Gsvolu("S09B","BOX",kBframeMaterial,bFramepar,3);
1711     gMC->Gsvolu("SD9B","BOX",kBframeMaterial,bFramepar,3);
1712     gMC->Gsvolu("S10B","BOX",kBframeMaterial,bFramepar,3);
1713     gMC->Gsvolu("SD0B","BOX",kBframeMaterial,bFramepar,3);
1714
1715     // Replace the volume shape with a composite shape
1716     // with substracted overlap with beam shield     
1717     if ( gMC->IsRootGeometrySupported() ) { 
1718         
1719       // Get shape
1720       Int_t nSlatType = 1;
1721       Int_t nVol = 8;
1722       const char* slatType = "D"; // D: Rounde slat
1723       const char* volLetter = "CNXIPHBG";
1724       TString volName;
1725       TString compName;
1726       TString csName;
1727       TGeoVolume *mVol = 0x0;
1728       // Beam shield recess
1729       new TGeoTube("tube5Cut", 0., AliMUONConstants::Rmin(4), kSlatWidth/2.+0.001);
1730       TObjArray rounded5Slat(nSlatType*((nVol+1)*2));   
1731       // Displacement
1732       TGeoTranslation* trDTube5 = new TGeoTranslation("trDTube5", -(kPcbLength+kVframeLength)/2., -kYpos5[1], 0.);
1733       trDTube5->RegisterYourself();
1734       TObjArray composite5(nSlatType*((nVol+1)*2));
1735       new TGeoBBox("box5DCut",(kPcbLength+kVframeLength)/2., hFramepar[1], vFramepar[2]+0.001);
1736       // Displacement
1737       TGeoTranslation* trDBox5 = new TGeoTranslation("trDBox5",kPcbLength/2., kYpos5[1], 0.);
1738       trDBox5->RegisterYourself();
1739       
1740       TGeoBBox *box5Vframe = new TGeoBBox("box5Vframe",vFramepar[0],vrFrameHeight/2., vFramepar[2]);
1741       TGeoTranslation* trVBox5 = new TGeoTranslation("trVBox5", 0., AliMUONConstants::Rmin(4)-kRframeLength + box5Vframe->GetDY(), 0.);
1742       trVBox5->RegisterYourself();
1743       
1744       for(int iCh=9; iCh<=10; iCh++){
1745         for (int iSlatType = 0; iSlatType<nSlatType; iSlatType++) {
1746           for (int iVol = 0; iVol<nVol; iVol++){
1747             Int_t lIndex = (iCh-9)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+iVol;
1748             volName=Form("S%c%d%c",slatType[iSlatType],iCh%10,volLetter[iVol]);
1749             mVol = gGeoManager->FindVolumeFast(volName);
1750             if ( !mVol ) {
1751               AliErrorStream() 
1752                 << "Slat volume " << volName << " not found" << endl;    
1753             }
1754             else {
1755               rounded5Slat[lIndex] = mVol->GetShape();
1756               csName=Form("rounded5Slat%c%d%c",slatType[iSlatType],iCh%10,volLetter[iVol]);
1757               ((TGeoShape*)rounded5Slat[lIndex])->SetName(csName);  
1758               
1759               // Composite shape
1760               TString compOperation(csName);
1761               compOperation+="-tube5Cut:tr";
1762               compOperation+=slatType[iSlatType];
1763               compOperation+="Tube5";
1764               if (strstr(volName,"B")){
1765                 // Displacement
1766                 TGeoTranslation* trB = new TGeoTranslation("trB", 0., -(kPcbHeight - kBframeHeight)/2., 0.);
1767                 trB->RegisterYourself();
1768                 compOperation.ReplaceAll("-tube5Cut",":trB-tube5Cut");
1769               }
1770               compName=Form("composite5%d%c",iCh,volLetter[iVol]);
1771               composite5[lIndex] = new TGeoCompositeShape(compName, compOperation.Data()); 
1772               
1773               // Reset shape to volume      
1774               mVol->SetShape((TGeoShape*)composite5[lIndex]);
1775             }
1776           }
1777
1778           // For rounded spacer
1779           Int_t lIndex = (iCh-9)*(nSlatType*(nVol+1))+iSlatType*(nVol+1)+nVol;
1780           volName=Form("S%c%dD",slatType[iSlatType],iCh%10);
1781           mVol = gGeoManager->FindVolumeFast(volName);
1782           if ( !mVol ) {
1783             AliErrorStream() 
1784               << "Slat volume " << volName << " not found" << endl;      
1785           }
1786           else {
1787             rounded5Slat[lIndex] = mVol->GetShape();
1788             csName=Form("rounded5Slat%c%dD",slatType[iSlatType],iCh%10);
1789             ((TGeoShape*)rounded5Slat[lIndex])->SetName(csName);                  
1790             
1791             // Composite shape
1792             TString compOperation(csName);
1793             if (strstr(volName,"SD")){
1794               compOperation.Prepend("(");
1795               compOperation+="+box5Vframe:trVBox5)*box5DCut:trDBox5";
1796             }
1797             compName=Form("composite5%c%dD",slatType[iSlatType],iCh%10);
1798             composite5[lIndex] = new TGeoCompositeShape(compName, compOperation.Data());              
1799             // Reset shape to volume      
1800             mVol->SetShape((TGeoShape*)composite5[lIndex]);
1801           }
1802         }
1803       }
1804     }
1805     
1806     index = 0; 
1807     for (i = 0; i < kNslats5; i++){
1808       for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
1809
1810         if (i == 0 && quadrant == 2) continue;
1811         if (i == 0 && quadrant == 4) continue;
1812
1813         sprintf(idSlatCh9,"LE%d",ConvertSlatNum(i,quadrant,kNslats5-1));
1814         sprintf(idSlatCh10,"LF%d",ConvertSlatNum(i,quadrant,kNslats5-1));
1815         Int_t moduleSlatCh9 = GetModuleId(idSlatCh9);
1816         Int_t moduleSlatCh10 = GetModuleId(idSlatCh10);
1817         Float_t xvFrame  = (slatLength5[i] - kVframeLength)/2.; // ok
1818
1819         // position the vertical frames (spacers)
1820         if (i != 1) { 
1821           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1822           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1823           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1824           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1825         } else {  // Vertical and Rounded+Vertical spacer
1826           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1827           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9D", idSlatCh9, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos5[1],0.));
1828           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1829           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0D", idSlatCh10, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,-kYpos5[1],0.));
1830         }
1831
1832         // position the panels and the insulating material 
1833         for (j = 0; j < kNPCB5[i]; j++){
1834           index++;
1835           Float_t xx = kSensLength * (-kNPCB5[i]/2.+j+.5); 
1836
1837           Float_t zPanel = spar[2] - nomexbpar[2]; 
1838           if (i==1 && j==0){ // Rounded pcb of rounded slat 
1839             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9X", idSlatCh9, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1840             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9X", idSlatCh9, 2*index,TGeoTranslation(xx,0.,-zPanel));
1841             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("SD9I", idSlatCh9, index,TGeoTranslation(xx,0.,0.));
1842             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0X", idSlatCh10, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1843             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0X", idSlatCh10, 2*index,TGeoTranslation(xx,0.,-zPanel));
1844             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("SD0I", idSlatCh10, index,TGeoTranslation(xx,0.,0.));
1845           } else { 
1846             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09X", idSlatCh9, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1847             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09X", idSlatCh9, 2*index,TGeoTranslation(xx,0.,-zPanel));
1848             GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09I", idSlatCh9, index,TGeoTranslation(xx,0.,0.));
1849             
1850             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10X", idSlatCh10, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1851             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10X", idSlatCh10, 2*index,TGeoTranslation(xx,0.,-zPanel));
1852             GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10I", idSlatCh10, index,TGeoTranslation(xx,0.,0.));
1853           }
1854         } 
1855       }
1856     }
1857
1858     // position the nomex volume inside the panel volume
1859     gMC->Gspos("S09N",1,"S09C",0.,0.,0.,0,"ONLY"); 
1860     gMC->Gspos("SD9N",1,"SD9C",0.,0.,0.,0,"ONLY"); 
1861     gMC->Gspos("S10N",1,"S10C",0.,0.,0.,0,"ONLY"); 
1862     gMC->Gspos("SD0N",1,"SD0C",0.,0.,0.,0,"ONLY"); 
1863
1864     // position panel  volume inside the bulk nomex material volume
1865     gMC->Gspos("S09C",1,"S09X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1866     gMC->Gspos("SD9C",1,"SD9X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1867     gMC->Gspos("S10C",1,"S10X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1868     gMC->Gspos("SD0C",1,"SD0X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1869
1870     // position the PCB volume inside the insulating material volume
1871     gMC->Gspos("S09P",1,"S09I",0.,0.,0.,0,"ONLY"); 
1872     gMC->Gspos("SD9P",1,"SD9I",0.,0.,0.,0,"ONLY"); 
1873     gMC->Gspos("S10P",1,"S10I",0.,0.,0.,0,"ONLY"); 
1874     gMC->Gspos("SD0P",1,"SD0I",0.,0.,0.,0,"ONLY"); 
1875
1876     // position the horizontal frame volume inside the PCB volume
1877     gMC->Gspos("S09H",1,"S09P",0.,0.,0.,0,"ONLY"); 
1878     gMC->Gspos("SD9H",1,"SD9P",0.,0.,0.,0,"ONLY"); 
1879     gMC->Gspos("S10H",1,"S10P",0.,0.,0.,0,"ONLY"); 
1880     gMC->Gspos("SD0H",1,"SD0P",0.,0.,0.,0,"ONLY"); 
1881
1882     // position the sensitive volume inside the horizontal frame volume
1883     gMC->Gsposp("S09G",1,"S09H",0.,0.,0.,0,"ONLY",senspar,3); 
1884     gMC->Gspos("SD9G",1,"SD9H",0.,0.,0.,0,"ONLY"); 
1885     gMC->Gsposp("S10G",1,"S10H",0.,0.,0.,0,"ONLY",senspar,3); 
1886     gMC->Gspos("SD0G",1,"SD0H",0.,0.,0.,0,"ONLY"); 
1887
1888     // position the border volumes inside the PCB volume
1889     Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
1890     gMC->Gspos("S09B",1,"S09P",0., yborder,0.,0,"ONLY"); 
1891     gMC->Gspos("S09B",2,"S09P",0.,-yborder,0.,0,"ONLY"); 
1892     gMC->Gspos("SD9B",1,"SD9P",0., 0.,0.,0,"ONLY"); 
1893     gMC->Gspos("S09B",1,"SD9P",0., yborder,0.,0,"ONLY"); 
1894     gMC->Gspos("S10B",1,"S10P",0., yborder,0.,0,"ONLY"); 
1895     gMC->Gspos("S10B",2,"S10P",0.,-yborder,0.,0,"ONLY"); 
1896     gMC->Gspos("SD0B",1,"SD0P",0., 0.,0.,0,"ONLY"); 
1897     gMC->Gspos("S10B",1,"SD0P",0., yborder,0.,0,"ONLY"); 
1898
1899     //      // create the NULOC volume and position it in the horizontal frame
1900
1901     gMC->Gsvolu("S09E","BOX",kNulocMaterial,nulocpar,3);
1902     gMC->Gsvolu("S10E","BOX",kNulocMaterial,nulocpar,3);
1903     index = 0;
1904     Float_t rPhi3 = TMath::ASin((kYpos5[1]-kPcbHeight/2.)/AliMUONConstants::Rmin(4));
1905     Float_t xxmax4 = (AliMUONConstants::Rmin(4)*TMath::Cos(rPhi3)-kVframeLength/2.) - (kBframeLength - kNulocLength)/2.;
1906     for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
1907       index++; 
1908       gMC->Gspos("S09E",2*index-1,"S09B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
1909       gMC->Gspos("S09E",2*index  ,"S09B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
1910       gMC->Gspos("S10E",2*index-1,"S10B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
1911       gMC->Gspos("S10E",2*index  ,"S10B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
1912     }
1913     if (xx > xxmax4 && xx< xxmax) {
1914       gMC->Gspos("S09E",2*index-1,"SD9B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
1915       gMC->Gspos("S09E",2*index  ,"SD9B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
1916       gMC->Gspos("S10E",2*index-1,"SD0B", xx, -yborder,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
1917       gMC->Gspos("S10E",2*index  ,"SD0B", xx, -yborder, kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
1918     }
1919
1920     //    
1921     //Geometry of the support pannel Verticla length 5.7m, horizontal length 2.6m, internal radius  dMotherInner o SC09 and SC10  (F. Orsini, Saclay)
1922     //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
1923     Float_t dMotherInner =  AliMUONConstants::Rmin(4)-kRframeHeight; 
1924     Float_t nomexthickness = 1.5;
1925     Float_t carbonthickness = 0.03;
1926     Float_t supporthlength =  260.;  
1927     Float_t supportvlength =  570.;  
1928     // Generating the composite shape of the carbon and nomex pannels
1929     new TGeoBBox("shNomexBoxSt5",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness+3*kCableWidth);
1930     new TGeoBBox("shCarbonBoxSt5",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
1931     new TGeoTubeSeg("shNomexHoleSt5",0., dMotherInner, nomexthickness/2.+carbonthickness+3*kCableWidth+0.001, -90. ,90.);
1932     new TGeoTubeSeg("shCarbonHoleSt5",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
1933     TGeoTranslation* trHoleSt5 = new TGeoTranslation("trHoleSt5",-supporthlength/2.,0.,0.); 
1934     trHoleSt5->RegisterYourself();
1935     TGeoCompositeShape* shNomexSupportSt5  = new TGeoCompositeShape("shNomexSupportSt5","shNomexBoxSt5-shNomexHoleSt5:trHoleSt5");
1936     TGeoCompositeShape* shCarbonSupportSt5 = new TGeoCompositeShape("shCarbonSupportSt5","shCarbonBoxSt5-shCarbonHoleSt5:trHoleSt5");
1937
1938    // Generating Nomex and Carbon pannel volumes
1939     TGeoVolume* voNomexSupportSt5  = new TGeoVolume("S09S", shNomexSupportSt5, kMedNomex);
1940     TGeoVolume* voCarbonSupportSt5 = new TGeoVolume("S09K", shCarbonSupportSt5, kMedCarbon);
1941     TGeoTranslation* trCarbon1St5   = new TGeoTranslation("trCarbon1St5",0.,0., -(nomexthickness+carbonthickness)/2.);
1942     TGeoTranslation* trCarbon2St5   = new TGeoTranslation("trCarbon2St5",0.,0.,  (nomexthickness+carbonthickness)/2.);
1943     voNomexSupportSt5->AddNode(voCarbonSupportSt5,1,trCarbon1St5);
1944     voNomexSupportSt5->AddNode(voCarbonSupportSt5,2,trCarbon2St5);
1945
1946     // Add readout cables
1947     gMC->Gsvolu("S09L","BOX",kCableMaterial,dum,0);
1948
1949     ySlat5 = 0.;
1950     Float_t lCableX = 0.;
1951     Float_t lCableY = 0.;
1952     Float_t lCableZ = 0.;
1953     Float_t cablepar[3] = {supporthlength/2., kCableHeight/2., kCableWidth/2.};
1954     Float_t lCableDY = 0.;
1955     for (i = 0; i<kNslats5; i++){
1956       Int_t iCable = 1;
1957       Int_t cIndex = 0;
1958       ySlat5 += kYpos5[i];
1959
1960       lCableY = ySlat5;
1961
1962       // Cables going out from the start of slat
1963       if(kNPCB5[i]>=4){ // Only if 4 or more pcb
1964         // First top cables
1965         cablepar[0] = (supporthlength-kXpos5[i])/2.;
1966         lCableX = kXpos5[i]/2.;
1967         if(i+1>=kNslats5 || i+2>=kNslats5){ // If no more higher slats, then use distance to lower slat
1968           lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
1969         }
1970         else {
1971           lCableDY = (kYpos5[i+1]+kYpos5[i+2])/2.-cablepar[1];
1972         }
1973         lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
1974         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3);  
1975         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3);
1976         // Then bottom cables
1977         if (i>0) {
1978           if (i==1) { // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
1979             cablepar[0] = (supporthlength-kXpos5[i]-dMotherInner)/2.;
1980             lCableX = (kXpos5[i]+dMotherInner)/2.;
1981             lCableDY = (kYpos5[i]+kYpos5[i])/2.-cablepar[1];
1982           }
1983           else {
1984             lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
1985             if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
1986               lCableDY = lCableY - dMotherInner - cablepar[1];
1987             }
1988           }
1989           gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
1990           gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
1991         }
1992       }
1993       
1994       // Rounded slats have an extra cable starting at second pcb
1995       if(i==1){ 
1996         // Only on top
1997         cablepar[0] = (supporthlength-kPcbLength-kVframeLength)/2.;
1998         lCableX = (kPcbLength+kVframeLength)/2.;
1999         lCableDY = (kYpos5[i+1]+kYpos5[i+2])/2.-cablepar[1]; // half way between 2 slats on same side
2000         lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
2001         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
2002         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
2003       } 
2004
2005       // Cables going out from the end of the slats
2006       // First top cables
2007       cablepar[0] = (supporthlength-(slatLength5[i]+kXpos5[i]+kDslatLength)+kVframeLength)/2.;
2008       lCableX = slatLength5[i]+kXpos5[i]-kVframeLength+kDslatLength+cablepar[0]-supporthlength/2.;
2009       if(i+1>=kNslats5 || i+2>=kNslats5){ // If no more higher slats, then use distance to lower slat
2010         lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
2011       }
2012       else {
2013         lCableDY = (kYpos5[i+1]+kYpos5[i+2])/2.-cablepar[1];
2014       }
2015       lCableZ = TMath::Power(-1,i)*(nomexthickness+carbonthickness+(iCable++)*kCableWidth)/2.;
2016       gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY+lCableDY,lCableZ,0,"ONLY",cablepar,3); 
2017       gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY+lCableDY),lCableZ,0,"ONLY",cablepar,3); 
2018       if(i>0){
2019         if (i==1) { // Rounded slat. Bottom cable starts at dMotherInner (beam pipe)
2020           lCableDY = (kYpos5[i]+kYpos5[i])/2.-cablepar[1];
2021         }
2022         else {
2023           lCableDY = (kYpos5[i]+kYpos5[i-1])/2.-cablepar[1];
2024           if ((lCableY-lCableDY)<(dMotherInner+cablepar[1])){
2025               lCableDY = lCableY - dMotherInner - cablepar[1];
2026           }
2027         }
2028         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,lCableY-lCableDY,lCableZ,0,"ONLY",cablepar,3); 
2029         gMC->Gsposp("S09L",10*i+cIndex++,"S09S",lCableX,-(lCableY-lCableDY),lCableZ,0,"ONLY",cablepar,3); 
2030       }
2031     }
2032
2033     Float_t dzCh9  = dzCh;
2034     TGeoTranslation* trSupport1St5   = new TGeoTranslation("trSupport1St5", supporthlength/2., 0. , dzCh9);
2035     TGeoRotation*    roSupportSt5    = new TGeoRotation("roSupportSt5",90.,180.,-90.);
2036     TGeoCombiTrans*  coSupport2St5   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh9, roSupportSt5);
2037     GetEnvelopes(13)->AddEnvelope("S09S", 0, 1, *trSupport1St5);  
2038     GetEnvelopes(12)->AddEnvelope("S09S", 0, 2, *coSupport2St5);  
2039     GetEnvelopes(15)->AddEnvelope("S09S", 0, 3, *trSupport1St5);   
2040     GetEnvelopes(14)->AddEnvelope("S09S", 0, 4, *coSupport2St5);
2041
2042
2043     // End of pannel support geometry    
2044
2045     // cout << "Geometry for Station 5...... done" << endl;
2046
2047   }
2048
2049   delete [] fStations;
2050
2051 }
2052
2053
2054 //______________________________________________________________________________
2055 void AliMUONSlatGeometryBuilder::SetTransformations()
2056 {
2057 /// Defines the transformations for the station345 chambers.
2058
2059   if (gAlice->GetModule("DIPO")) {
2060     // if DIPO is preset, the whole station will be placed in DDIP volume
2061     SetMotherVolume(4, "DDIP");
2062     SetMotherVolume(5, "DDIP");
2063     SetMotherVolume(6, "DDIP");
2064     SetMotherVolume(7, "DDIP");
2065   }     
2066   SetVolume(4, "SC05I", true);
2067   SetVolume(5, "SC05O", true);
2068   SetVolume(6, "SC06I", true);
2069   SetVolume(7, "SC06O", true);
2070      
2071   if (gAlice->GetModule("SHIL")) {
2072     SetMotherVolume(8, "YOUT2");
2073     SetMotherVolume(9, "YOUT2");
2074     SetMotherVolume(10, "YOUT2");
2075     SetMotherVolume(11, "YOUT2");
2076     SetMotherVolume(12, "YOUT2");
2077     SetMotherVolume(13, "YOUT2");
2078     SetMotherVolume(14, "YOUT2");
2079     SetMotherVolume(15, "YOUT2");
2080   }  
2081
2082   SetVolume( 8, "SC07I", true);
2083   SetVolume( 9, "SC07O", true);
2084   SetVolume(10, "SC08I", true);
2085   SetVolume(11, "SC08O", true);
2086   SetVolume(12, "SC09I", true);
2087   SetVolume(13, "SC09O", true);
2088   SetVolume(14, "SC10I", true);
2089   SetVolume(15, "SC10O", true);
2090
2091 // Stations 345 are not perpendicular to the beam axis
2092 // See AliMUONConstants class
2093   TGeoRotation st345inclination("rot99");
2094   st345inclination.RotateX(AliMUONConstants::St345Inclination());
2095   
2096 // The rotation of the half-chamber is done with respect the center of the chamber.
2097 // the distance beween the roation axis and the chamber position is 
2098 // AliMUONConstants::DzCh()+AliMUONConstants::DzSlat()
2099 // Therefore the position of the half-chamber has to be corrected by a traslation in Z and Y axis
2100   Double_t deltaY = (AliMUONConstants::DzCh()+AliMUONConstants::DzSlat())*
2101     TMath::Sin(AliMUONConstants::St345Inclination() * TMath::Pi()/180.);
2102   Double_t deltaZ = (AliMUONConstants::DzCh()+AliMUONConstants::DzSlat())*
2103     (1.-TMath::Cos(AliMUONConstants::St345Inclination() * TMath::Pi()/180.));
2104
2105
2106   Double_t zpos1= - AliMUONConstants::DefaultChamberZ(4); 
2107   SetTransformation(4, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
2108   SetTransformation(5, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
2109
2110   zpos1= - AliMUONConstants::DefaultChamberZ(5); 
2111   SetTransformation(6, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
2112   SetTransformation(7, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
2113
2114   zpos1 = - AliMUONConstants::DefaultChamberZ(6); 
2115   SetTransformation(8, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
2116   SetTransformation(9, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
2117
2118   zpos1 = - AliMUONConstants::DefaultChamberZ(7); 
2119   SetTransformation(10, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination );
2120   SetTransformation(11, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination );
2121
2122   zpos1 = - AliMUONConstants::DefaultChamberZ(8); 
2123   SetTransformation(12, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
2124   SetTransformation(13, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
2125
2126   zpos1 = - AliMUONConstants::DefaultChamberZ(9); 
2127   SetTransformation(14, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
2128   SetTransformation(15, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
2129
2130 }
2131
2132 //______________________________________________________________________________
2133 void AliMUONSlatGeometryBuilder::SetSensitiveVolumes()
2134 {
2135 /// Defines the sensitive volumes for slat stations chambers.
2136
2137   GetGeometry( 4)->SetSensitiveVolume("S05G");
2138   GetGeometry( 4)->SetSensitiveVolume("SC5G");
2139   GetGeometry( 4)->SetSensitiveVolume("SD5G");
2140   GetGeometry( 5)->SetSensitiveVolume("S05G");
2141   GetGeometry( 5)->SetSensitiveVolume("SC5G");
2142   GetGeometry( 5)->SetSensitiveVolume("SD5G");
2143   GetGeometry( 6)->SetSensitiveVolume("S06G");
2144   GetGeometry( 6)->SetSensitiveVolume("SC6G");
2145   GetGeometry( 6)->SetSensitiveVolume("SD6G");
2146   GetGeometry( 7)->SetSensitiveVolume("S06G");
2147   GetGeometry( 7)->SetSensitiveVolume("SC6G");
2148   GetGeometry( 7)->SetSensitiveVolume("SD6G");
2149   GetGeometry( 8)->SetSensitiveVolume("S07G");
2150   GetGeometry( 8)->SetSensitiveVolume("SD7G");
2151   GetGeometry( 9)->SetSensitiveVolume("S07G");
2152   GetGeometry( 9)->SetSensitiveVolume("SD7G");
2153   GetGeometry(10)->SetSensitiveVolume("S08G");
2154   GetGeometry(10)->SetSensitiveVolume("SD8G");
2155   GetGeometry(11)->SetSensitiveVolume("S08G");
2156   GetGeometry(11)->SetSensitiveVolume("SD8G");
2157   GetGeometry(12)->SetSensitiveVolume("S09G");
2158   GetGeometry(12)->SetSensitiveVolume("SD9G");
2159   GetGeometry(13)->SetSensitiveVolume("S09G");
2160   GetGeometry(13)->SetSensitiveVolume("SD9G");
2161   GetGeometry(14)->SetSensitiveVolume("S10G");
2162   GetGeometry(14)->SetSensitiveVolume("SD0G");
2163   GetGeometry(15)->SetSensitiveVolume("S10G");
2164   GetGeometry(15)->SetSensitiveVolume("SD0G");
2165 }
2166
2167 //______________________________________________________________________________
2168 Int_t  AliMUONSlatGeometryBuilder::ConvertSlatNum(Int_t numslat, Int_t quadnum, Int_t fspq) const
2169 {
2170 /// On-line function establishing the correspondance between numslat (the slat number on a particular quadrant (numslat->0....4 for St3))
2171 /// and slatnum (the slat number on the whole panel (slatnum->1...18 for St3)
2172   numslat += 1;
2173   if (quadnum==2 || quadnum==3) 
2174     numslat += fspq;
2175   else
2176     numslat = fspq + 2-numslat;
2177   numslat -= 1;
2178               
2179   if (quadnum==3 || quadnum==4) numslat += 2*fspq+1;
2180
2181   return numslat;
2182 }