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