63b30966a47335b2941d90a53fe57c56f28306ee
[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   // B: the horizontal border filled with rohacell: ok Ch. Finck
173   const Float_t kBframeLength = kHframeLength; 
174   const Float_t kBframeHeight = (kPcbHeight - kSensHeight)/2. - kHframeHeight; 
175   const Float_t kBframeWidth  = kHframeWidth;
176   const Int_t kBframeMaterial = idRoha;
177
178   // NULOC: 30 mum copper + 200 mum vetronite (same radiation length as 14mum copper) for electronics
179   const Float_t kNulocLength   = 2.5; 
180   const Float_t kNulocHeight   = kBframeHeight;
181   const Float_t kNulocWidth    = 0.0030 + 0.0014; // equivalent copper width of vetronite; 
182   const Int_t   kNulocMaterial = idCopper;
183
184   // Slat parameters
185   const Float_t kSlatHeight = kPcbHeight; 
186   const Float_t kSlatWidth  = kSensWidth + 2.*(kPcbWidth + kInsuWidth + kPanelWidth 
187                                                + kNomexBWidth); //replaced rohacell with Nomex Ch. Finck 
188   // const Int_t   kSlatMaterial = idAir;
189   const Float_t kDslatLength  = -1.25; // position of the slat respect to the beam plane (half vertical spacer) Ch. Finck
190   Float_t zSlat               = AliMUONConstants::DzSlat();// implemented Ch. Finck
191   Float_t dzCh                = AliMUONConstants::DzCh();
192
193   Float_t spar[3];  
194   Int_t i, j;
195   Int_t detElemId;
196   Int_t moduleId;
197
198   // the panel volume contains the nomex
199   Float_t panelpar[3] = { kPanelLength/2., kPanelHeight/2., kPanelWidth/2. }; 
200   Float_t nomexpar[3] = { kNomexLength/2., kNomexHeight/2., kNomexWidth/2. }; 
201   Float_t twidth =  kPanelWidth +  kNomexBWidth; 
202   Float_t nomexbpar[3] = {kNomexLength/2., kNomexHeight/2.,twidth/2. };// bulk nomex 
203
204   // insulating material contains PCB-> gas   
205   twidth = 2*(kInsuWidth + kPcbWidth) + kSensWidth ; 
206   Float_t insupar[3] = {kInsuLength/2., kInsuHeight/2., twidth/2. }; 
207   twidth -= 2 * kInsuWidth; 
208   Float_t pcbpar[3]  = {kPcbLength/2., kPcbHeight/2., twidth/2. }; 
209   Float_t senspar[3] = {kSensLength/2., kSensHeight/2., kSensWidth/2. }; 
210   Float_t theight    = 2 * kHframeHeight + kSensHeight;
211   Float_t hFramepar[3] = {kHframeLength/2., theight/2., kHframeWidth/2.}; 
212   Float_t bFramepar[3] = {kBframeLength/2., kBframeHeight/2., kBframeWidth/2.}; 
213   Float_t vFramepar[3] = {kVframeLength/2., kVframeHeight/2., kVframeWidth/2.};
214   Float_t nulocpar[3]  = {kNulocLength/2.,  kNulocHeight/2.,  kNulocWidth/2.}; 
215
216   Float_t xx;
217   Float_t xxmax = (kBframeLength - kNulocLength)/2.; 
218   Int_t index=0;
219   Int_t* fStations = new Int_t[5];
220   for (Int_t i=0; i<5; i++) fStations[i] = 1;
221   fStations[2] = 1;
222      
223   if (fStations[2])
224     {
225       //********************************************************************
226       //                            Station 3                             **
227       //********************************************************************
228       // Mother volume for each chamber in St3 is an envelop (or assembly)
229       // There is one assembly mother per half a chamber
230       // Mother volume for each chamber in St3 is an envelop (or assembly)
231       // There is one assembly mother per half a chamber  called SC05I, SC05O, SC06I and SC06O
232       // volumes for slat geometry (xx=5,..,10 chamber id): 
233       // Sxx0 Sxx1 Sxx2 Sxx3  -->   Slat Mother volumes 
234       // SxxG                          -->   Sensitive volume (gas)
235       // SxxP                          -->   PCB (copper) 
236       // SxxI                          -->   Insulator (G10) 
237       // SxxC                          -->   Carbon panel 
238       // SxxN                          -->   Nomex comb
239       // SxxX                          -->   Nomex bulk
240       // SxxH, SxxV                    -->   Horizontal and Vertical frames (Noryl)
241       // SB5x                          -->   Volumes for the 35 cm long PCB
242       // slat dimensions: slat is a MOTHER volume!!! made of air
243       // Only for chamber 5: slat 1 has a PCB shorter by 5cm!
244
245       Float_t tlength = 35.;
246       Float_t panelpar2[3]  = { tlength/2., panelpar[1],  panelpar[2]}; 
247       Float_t nomexpar2[3]  = { tlength/2., nomexpar[1],  nomexpar[2]}; 
248       Float_t nomexbpar2[3] = { tlength/2., nomexbpar[1],  nomexbpar[2]}; 
249       Float_t insupar2[3]   = { tlength/2., insupar[1],   insupar[2]}; 
250       Float_t pcbpar2[3]    = { tlength/2., pcbpar[1],    pcbpar[2]}; 
251       Float_t senspar2[3]   = { tlength/2., senspar[1],   senspar[2]}; 
252       Float_t hFramepar2[3] = { tlength/2., hFramepar[1], hFramepar[2]}; 
253       Float_t bFramepar2[3] = { tlength/2., bFramepar[1], bFramepar[2]}; 
254       Float_t *dum=0;
255       Float_t pcbDLength3   = (kPcbLength - tlength);
256
257       const Int_t   kNslats3         = 5;  // number of slats per quadrant
258       const Int_t   kNPCB3[kNslats3] = {4, 4, 4, 3, 2}; // n PCB per slat
259       const Float_t kXpos3[kNslats3] = {0., 0., 0., 0., 0.};//{31., 0., 0., 0., 0.};
260       const Float_t kYpos3[kNslats3] = {0, 37.8, 37.7, 37.3, 33.7};
261       Float_t slatLength3[kNslats3]; 
262
263       // create and position the slat (mother) volumes 
264
265       char idSlatCh5[5];
266       char idSlatCh6[5];
267       Float_t xSlat3;
268       Float_t ySlat3 = 0;
269       Float_t angle = 0.;
270       Float_t spar2[3];
271       for (i = 0; i < kNslats3; i++){
272
273         slatLength3[i] = kPcbLength * kNPCB3[i] + 2.* kVframeLength; 
274         xSlat3 = slatLength3[i]/2. +  kDslatLength + kXpos3[i]; 
275         ySlat3 += kYpos3[i];
276
277         spar[0] = slatLength3[i]/2.; 
278         spar[1] = kSlatHeight/2.;
279         spar[2] = kSlatWidth/2.; 
280         // take away 5 cm from the first slat in chamber 5
281         if (i == 0 || i == 1 || i == 2) { // 1 pcb is shortened by 5cm
282           spar2[0] = spar[0] - pcbDLength3/2.;
283         } else {
284           spar2[0] = spar[0];
285         }
286         spar2[1] = spar[1];
287         spar2[2] = spar[2]; 
288         Float_t dzCh3 = dzCh; 
289         Float_t zSlat3 = (i%2 ==0)? -zSlat : zSlat; // seems not that zSlat3 = zSlat4 & 5 refering to plan PQ7EN345-6 ?
290
291         sprintf(idSlatCh5,"LA%d",i+kNslats3-1);
292         detElemId = 509 - (i + kNslats3-1-4);
293         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
294         if (detElemId % 2 == 0)
295             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
296                                                 TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
297         else
298             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
299                                                 TGeoRotation("rot1",90,angle,90,270+angle,180,0) ); 
300
301         sprintf(idSlatCh5,"LA%d",3*kNslats3-2+i);
302         detElemId = 500 + (i + kNslats3-1-4);
303         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
304         if (detElemId % 2 == 0)
305             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
306                                                 TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );
307         else
308             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
309                                                 TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
310
311         if (i > 0) { 
312           sprintf(idSlatCh5,"LA%d",kNslats3-1-i);
313           detElemId = 509 + (i + kNslats3-1-4);
314           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
315           if (detElemId % 2 == 0 && detElemId != 510)
316               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3), 
317                                                   TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
318           else
319               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3), 
320                                                   TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
321
322           sprintf(idSlatCh5,"LA%d",3*kNslats3-2-i);
323           detElemId = 518 - (i + kNslats3-1-4);
324           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
325           if (detElemId % 2 == 1 && detElemId != 517)
326               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
327                                                   TGeoRotation("rot4",90,180+angle,90,90+angle,180,0) );
328           else
329               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
330                                                   TGeoRotation("rot4",90,180+angle,90,270+angle,0,0) );   
331         }
332
333         sprintf(idSlatCh6,"LB%d",kNslats3-1+i);  
334         detElemId = 609 - (i  + kNslats3-1-4);
335         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
336         if (detElemId % 2 == 0)
337             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
338                                      TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
339         else
340             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, ySlat3, -zSlat3 + dzCh3),
341                                      TGeoRotation("rot5",90,angle,90,270+angle,180,0) );
342
343         sprintf(idSlatCh6,"LB%d",3*kNslats3-2+i);
344         detElemId = 600 + (i + kNslats3-1-4);
345         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
346         if (detElemId % 2 == 0)
347             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
348                                                 TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
349         else
350             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, ySlat3, zSlat3 - dzCh3),
351                                                 TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) ); 
352
353         if (i > 0) { 
354           sprintf(idSlatCh6,"LB%d",kNslats3-1-i);
355           detElemId = 609 + (i + kNslats3-1-4);
356           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
357           if (detElemId % 2 == 0 && detElemId != 610)
358               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3),
359                                                   TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
360           else
361               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, -ySlat3, -zSlat3 + dzCh3),
362                                                   TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
363           sprintf(idSlatCh6,"LB%d",3*kNslats3-2-i);
364           detElemId = 618 - (i + kNslats3-1-4);
365           moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
366           if (detElemId % 2 == 1 && detElemId != 617)
367               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
368                                                   TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) );
369           else
370               GetEnvelopes(moduleId)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, -ySlat3, zSlat3 - dzCh3),
371                                                   TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) );   
372         }
373       }
374      
375       // create the panel volume 
376  
377       gMC->Gsvolu("S05C","BOX",kCarbonMaterial,panelpar,3);
378       gMC->Gsvolu("SB5C","BOX",kCarbonMaterial,panelpar2,3);
379       gMC->Gsvolu("S06C","BOX",kCarbonMaterial,panelpar,3);
380  
381       // create the nomex volume (honey comb)
382
383       gMC->Gsvolu("S05N","BOX",kNomexMaterial,nomexpar,3);
384       gMC->Gsvolu("SB5N","BOX",kNomexMaterial,nomexpar2,3);
385       gMC->Gsvolu("S06N","BOX",kNomexMaterial,nomexpar,3);
386  
387       // create the nomex volume (bulk)
388
389       gMC->Gsvolu("S05X","BOX",kNomexBMaterial,nomexbpar,3);
390       gMC->Gsvolu("SB5X","BOX",kNomexBMaterial,nomexbpar2,3);
391       gMC->Gsvolu("S06X","BOX",kNomexBMaterial,nomexbpar,3);
392
393       // create the insulating material volume 
394
395       gMC->Gsvolu("S05I","BOX",kInsuMaterial,insupar,3);
396       gMC->Gsvolu("SB5I","BOX",kInsuMaterial,insupar2,3);
397       gMC->Gsvolu("S06I","BOX",kInsuMaterial,insupar,3);
398  
399       // create the PCB volume 
400
401       gMC->Gsvolu("S05P","BOX",kPcbMaterial,pcbpar,3);
402       gMC->Gsvolu("SB5P","BOX",kPcbMaterial,pcbpar2,3);
403       gMC->Gsvolu("S06P","BOX",kPcbMaterial,pcbpar,3);
404  
405       // create the sensitive volumes,
406
407       gMC->Gsvolu("S05G","BOX",kSensMaterial,dum,0);
408       gMC->Gsvolu("S06G","BOX",kSensMaterial,dum,0);
409
410       // create the vertical frame volume 
411
412       gMC->Gsvolu("S05V","BOX",kVframeMaterial,vFramepar,3);
413       gMC->Gsvolu("S06V","BOX",kVframeMaterial,vFramepar,3);
414
415       // create the horizontal frame volume 
416
417       gMC->Gsvolu("S05H","BOX",kHframeMaterial,hFramepar,3);
418       gMC->Gsvolu("SB5H","BOX",kHframeMaterial,hFramepar2,3);
419       gMC->Gsvolu("S06H","BOX",kHframeMaterial,hFramepar,3);
420  
421       // create the horizontal border volume 
422
423       gMC->Gsvolu("S05B","BOX",kBframeMaterial,bFramepar,3);
424       gMC->Gsvolu("SB5B","BOX",kBframeMaterial,bFramepar2,3);
425       gMC->Gsvolu("S06B","BOX",kBframeMaterial,bFramepar,3);
426  
427       index = 0; 
428       for (i = 0; i<kNslats3; i++){
429         for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
430
431           if (i == 0 && quadrant == 2) continue;
432           if (i == 0 && quadrant == 4) continue;
433
434           sprintf(idSlatCh5,"LA%d",ConvertSlatNum(i,quadrant,kNslats3-1));
435           sprintf(idSlatCh6,"LB%d",ConvertSlatNum(i,quadrant,kNslats3-1));
436           Int_t moduleSlatCh5 = GetModuleId(idSlatCh5);
437           Int_t moduleSlatCh6 = GetModuleId(idSlatCh6);
438           Float_t xvFrame  = (slatLength3[i] - kVframeLength)/2.;
439           Float_t xvFrame2  = xvFrame;
440           
441
442           if (i == 0 || i == 1 || i == 2) xvFrame2 -= pcbDLength3/2.;
443
444           // position the vertical frames 
445           if ( i > 2) { 
446             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
447                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
448             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
449                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
450             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
451                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
452             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
453                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));   
454           } 
455
456           if (i == 2) {
457             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
458                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame2,0.,0.));
459             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
460                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
461             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
462                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
463             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06V", idSlatCh6, 
464                                                     (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
465           }
466
467           if (i == 0 || i == 1) { // no rounded spacer for the moment (Ch. Finck)
468             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05V", idSlatCh5, 
469                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame2,0.,0.));
470             GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S06V", idSlatCh6, 
471                                                     (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
472           }
473
474           // position the panels and the insulating material 
475           for (j = 0; j < kNPCB3[i]; j++){
476             if (i == 1 && j == 0) continue;
477             if (i == 0 && j == 0) continue;
478             index++;
479             Float_t xx = kSensLength * (-kNPCB3[i]/2. + j + 0.5); 
480             Float_t xx2 = xx - pcbDLength3/2.; 
481          
482             Float_t zPanel = spar[2] - nomexbpar[2]; 
483
484             if ( (i == 0 || i == 1 || i == 2) && j == kNPCB3[i]-1) { // 1 pcb is shortened by 5cm 
485               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5X", idSlatCh5, 2*index-1,TGeoTranslation(xx2,0.,zPanel));
486               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5X", idSlatCh5, 2*index,TGeoTranslation(xx2,0.,-zPanel));
487               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("SB5I", idSlatCh5, index,TGeoTranslation(xx2,0.,0.));
488             } else {
489               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05X", idSlatCh5, 2*index-1,TGeoTranslation(xx,0.,zPanel));
490               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05X", idSlatCh5, 2*index,TGeoTranslation(xx,0.,-zPanel));
491               GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituent("S05I", idSlatCh5, index,TGeoTranslation(xx,0.,0.));
492             }
493             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06X", idSlatCh6, 2*index-1,TGeoTranslation(xx,0.,zPanel));
494             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06X", idSlatCh6, 2*index,TGeoTranslation(xx,0.,-zPanel));
495             GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituent("S06I", idSlatCh6, index,TGeoTranslation(xx,0.,0.));
496  
497           } 
498         }
499       }
500
501       // position the nomex volume inside the panel volume
502       gMC->Gspos("S05N",1,"S05C",0.,0.,0.,0,"ONLY"); 
503       gMC->Gspos("SB5N",1,"SB5C",0.,0.,0.,0,"ONLY"); 
504       gMC->Gspos("S06N",1,"S06C",0.,0.,0.,0,"ONLY"); 
505   
506       // position panel volume inside the bulk nomex material volume
507       gMC->Gspos("S05C",1,"S05X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
508       gMC->Gspos("SB5C",1,"SB5X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
509       gMC->Gspos("S06C",1,"S06X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
510
511       // position the PCB volume inside the insulating material volume
512       gMC->Gspos("S05P",1,"S05I",0.,0.,0.,0,"ONLY"); 
513       gMC->Gspos("SB5P",1,"SB5I",0.,0.,0.,0,"ONLY"); 
514       gMC->Gspos("S06P",1,"S06I",0.,0.,0.,0,"ONLY"); 
515   
516       // position the horizontal frame volume inside the PCB volume
517       gMC->Gspos("S05H",1,"S05P",0.,0.,0.,0,"ONLY"); 
518       gMC->Gspos("SB5H",1,"SB5P",0.,0.,0.,0,"ONLY"); 
519       gMC->Gspos("S06H",1,"S06P",0.,0.,0.,0,"ONLY"); 
520   
521       // position the sensitive volume inside the horizontal frame volume
522       gMC->Gsposp("S05G",1,"S05H",0.,0.,0.,0,"ONLY",senspar,3); 
523       gMC->Gsposp("S05G",1,"SB5H",0.,0.,0.,0,"ONLY",senspar2,3); 
524       gMC->Gsposp("S06G",1,"S06H",0.,0.,0.,0,"ONLY",senspar,3); 
525   
526  
527       // position the border volumes inside the PCB volume
528       Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
529       gMC->Gspos("S05B",1,"S05P",0., yborder,0.,0,"ONLY"); 
530       gMC->Gspos("S05B",2,"S05P",0.,-yborder,0.,0,"ONLY"); 
531       gMC->Gspos("SB5B",1,"SB5P",0., yborder,0.,0,"ONLY"); 
532       gMC->Gspos("SB5B",2,"SB5P",0.,-yborder,0.,0,"ONLY"); 
533
534       gMC->Gspos("S06B",1,"S06P",0., yborder,0.,0,"ONLY"); 
535       gMC->Gspos("S06B",2,"S06P",0.,-yborder,0.,0,"ONLY"); 
536   
537       // create the NULOC volume and position it in the horizontal frame
538       gMC->Gsvolu("S05E","BOX",kNulocMaterial,nulocpar,3);
539       gMC->Gsvolu("S06E","BOX",kNulocMaterial,nulocpar,3);
540       index = 0;
541       Float_t xxmax2 = xxmax - pcbDLength3/2.;
542       for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
543         index++; 
544         gMC->Gspos("S05E",2*index-1,"S05B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
545         gMC->Gspos("S05E",2*index  ,"S05B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
546         gMC->Gspos("S06E",2*index-1,"S06B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
547         gMC->Gspos("S06E",2*index  ,"S06B", xx, 0., kBframeWidth/2.-  kNulocWidth/2, 0, "ONLY");
548         if (xx > -xxmax2 && xx< xxmax2) {
549           gMC->Gspos("S05E",2*index-1,"SB5B", xx, 0.,-kBframeWidth/2.+ kNulocWidth/2, 0, "ONLY");
550           gMC->Gspos("S05E",2*index  ,"SB5B", xx, 0., kBframeWidth/2.- kNulocWidth/2, 0, "ONLY");
551         }
552      }
553
554       // position the volumes approximating the circular section of the pipe
555       Float_t epsilon = 0.001; 
556       Int_t ndiv = 6;
557       Int_t imax = 1;
558       Double_t divpar[3];
559       Double_t dydiv = kSensHeight/ndiv;
560       Double_t ydiv  = (kSensHeight - dydiv)/2.;
561       Double_t rmin  = AliMUONConstants::Rmin(2);// Same radius for both chamber in St3
562       Double_t xdiv  = 0.;
563       Float_t xvol;
564       Float_t yvol;
565
566       for (Int_t idiv = 0; idiv < ndiv; idiv++){ 
567         ydiv += dydiv;
568         xdiv = 0.; 
569         if (ydiv < rmin) xdiv = rmin * TMath::Sin( TMath::ACos((ydiv-dydiv/2.)/rmin) );
570         divpar[0] = (kPcbLength - xdiv)/2.; 
571         divpar[1] = dydiv/2. - epsilon;
572         divpar[2] = kSensWidth/2.; 
573         xvol = (kPcbLength + xdiv)/2.;
574         yvol = ydiv; 
575
576         // Volumes close to the beam pipe for slat i=1 so 4 slats per chamber
577         for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
578           sprintf(idSlatCh5,"LA%d",ConvertSlatNum(1,quadrant,kNslats3-1));
579           sprintf(idSlatCh6,"LB%d",ConvertSlatNum(1,quadrant,kNslats3-1));
580           Int_t moduleSlatCh5 = GetModuleId(idSlatCh5);
581           Int_t moduleSlatCh6 = GetModuleId(idSlatCh6);
582
583           GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituentParam("S05G", idSlatCh5, quadrant*100+imax+4*idiv+1,
584                                                        TGeoTranslation(xvol-(kPcbLength * kNPCB3[1]/2.),yvol-kPcbLength,0.),3,divpar);
585
586           GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituentParam("S06G", idSlatCh6,  quadrant*100+imax+4*idiv+1,
587                                                        TGeoTranslation(xvol-(kPcbLength * kNPCB3[1]/2.),yvol-kPcbLength,0.),3,divpar);
588         }
589       }
590
591       // Volumes close to the beam pipe for slat i=0 so 2 slats per chamber (central slat for station 3)
592       //      Gines Martinez, Subatech sep 04
593       // 9 box volumes are used to define the PCB closed to the beam pipe of the slat 122000SR1 of chamber 5 and 6 of St3
594       // Accordingly to plan PQ-LAT-SR1 of CEA-DSM-DAPNIA-SIS/BE ph HARDY 8-Oct-2002
595       // Rmin = 31.5 cm
596       rmin = AliMUONConstants::Rmin(2); // Same radius for both chamber in St3
597       ndiv  = 9; 
598       dydiv = kSensHeight/ndiv;           // Vertical size of the box volume approximating the rounded PCB
599       ydiv  = -kSensHeight/2 + dydiv/2.;   // Initializing vertical position of the volume from bottom
600       xdiv  = 0.;                         // Initializing horizontal position of the box volumes
601
602       for (Int_t idiv = 0; idiv < ndiv; idiv++){ 
603         xdiv = TMath::Abs( rmin * TMath::Sin( TMath::ACos(ydiv/rmin) ) );
604         divpar[0] = (kPcbLength - xdiv)/2.; // Dimension of the box volume
605         divpar[1] = dydiv/2. - epsilon;
606         divpar[2] = kSensWidth/2.; 
607         xvol = (kPcbLength + xdiv)/2.; //2D traslition for positionning of box volume
608         yvol =  ydiv;
609         Int_t side;
610         for (side = 1; side <= 2; side++) {
611           sprintf(idSlatCh5,"LA%d",4);     
612           sprintf(idSlatCh6,"LB%d",4);
613           if(side == 2) {
614             sprintf(idSlatCh5,"LA%d",13);          
615             sprintf(idSlatCh6,"LB%d",13);
616           }        
617           Int_t moduleSlatCh5 = GetModuleId(idSlatCh5);
618           Int_t moduleSlatCh6 = GetModuleId(idSlatCh6);
619           GetEnvelopes(moduleSlatCh5)->AddEnvelopeConstituentParam("S05G", idSlatCh5,500+side*100+imax+4*idiv+1,
620                                                        TGeoTranslation(xvol-(kPcbLength * kNPCB3[0]/2.),yvol,0.),3,divpar);
621
622           GetEnvelopes(moduleSlatCh6)->AddEnvelopeConstituentParam("S06G", idSlatCh6,500+side*100+imax+4*idiv+1,
623                                                        TGeoTranslation(xvol-(kPcbLength * kNPCB3[0]/2.),yvol,0.),3,divpar);
624         }
625         ydiv += dydiv; // Going from bottom to top
626       }
627       
628       //
629       //Geometry of the support pannel Verticla length 3.62m, horizontal length 1.62m, internal radius  dMotherInner of SC05 and SC06  (F. Orsini, Saclay)
630       //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
631       // Outer excess and inner recess for mother volume radius
632       // with respect to ROuter and RInner
633       Float_t dMotherInner = AliMUONConstants::Rmin(2)-kRframeHeight; 
634       Float_t nomexthickness = 1.5;
635       Float_t carbonthickness = 0.03;
636       Float_t supporthlength =  162.;  
637       Float_t supportvlength =  362.; 
638  
639       // Generating the composite shape of the carbon and nomex pannels
640       new TGeoBBox("shNomexBoxSt3",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness);
641       new TGeoBBox("shCarbonBoxSt3",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
642       new TGeoTubeSeg("shNomexHoleSt3",0., dMotherInner, nomexthickness/2.+carbonthickness+0.001, -90. ,90.);
643       new TGeoTubeSeg("shCarbonHoleSt3",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
644       TGeoTranslation* trHoleSt3 = new TGeoTranslation("trHoleSt3",-supporthlength/2.,0.,0.); 
645       trHoleSt3->RegisterYourself();
646       TGeoCompositeShape* shNomexSupportSt3  = new TGeoCompositeShape("shNomexSupportSt3","shNomexBoxSt3-shNomexHoleSt3:trHoleSt3");
647       TGeoCompositeShape* shCarbonSupportSt3 = new TGeoCompositeShape("shCarbonSupportSt3","shCarbonBoxSt3-shCarbonHoleSt3:trHoleSt3");
648       
649       // Generating Nomex and Carbon pannel volumes
650       TGeoVolume * voNomexSupportSt3  = new TGeoVolume("S05S", shNomexSupportSt3, kMedNomex);
651       TGeoVolume * voCarbonSupportSt3 = new TGeoVolume("S05K", shCarbonSupportSt3, kMedCarbon);
652       TGeoTranslation *trCarbon1St3   = new TGeoTranslation("trCarbon1St3",0.,0., -(nomexthickness+carbonthickness)/2.);
653       TGeoTranslation *trCarbon2St3   = new TGeoTranslation("trCarbon2St3",0.,0.,  (nomexthickness+carbonthickness)/2.);
654       voNomexSupportSt3->AddNode(voCarbonSupportSt3,1,trCarbon1St3);
655       voNomexSupportSt3->AddNode(voCarbonSupportSt3,2,trCarbon2St3);
656       Float_t dzCh5  = dzCh;
657       TGeoTranslation* trSupport1St3   = new TGeoTranslation("trSupport1St3", supporthlength/2., 0. , dzCh5);
658       TGeoRotation*    roSupportSt3    = new TGeoRotation("roSupportSt3",90.,180.,-90.);
659       TGeoCombiTrans*  coSupport2St3   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh5, roSupportSt3);       
660       GetEnvelopes(5)->AddEnvelope("S05S", 0, 1, *trSupport1St3);  
661       GetEnvelopes(4)->AddEnvelope("S05S", 0, 2, *coSupport2St3);  
662       GetEnvelopes(7)->AddEnvelope("S05S", 0, 3, *trSupport1St3);   
663       GetEnvelopes(6)->AddEnvelope("S05S", 0, 4, *coSupport2St3);  
664       // End of pannel support geometry          
665
666       // cout << "Geometry for Station 3...... done" << endl;   
667     }
668   if (fStations[3]) {
669
670
671     // //********************************************************************
672     // //                            Station 4                             **
673     // //********************************************************************
674     // Mother volume for each chamber in St4 is an envelop (or assembly)
675     // There is one assembly mother per half a chamber  called SC07I, SC07O, SC08I and SC08O
676     // Same volume name definitions as in St3
677     const Int_t   kNslats4          = 7;  // number of slats per quadrant
678     const Int_t   kNPCB4[kNslats4]  = {5, 6, 5, 5, 4, 3, 2}; // n PCB per slat
679     const Float_t kXpos4[kNslats4]  = {38.75, 0., 0., 0., 0., 0., 0.}; // J.C. Correct value
680     const Float_t kYpos41[kNslats4] = {0., 38.2, 34.40, 36.60, 29.3, 37.0, 28.6};
681     const Float_t kYpos42[kNslats4] = {0., 38.2, 37.85, 37.55, 29.4, 37.0, 28.6};
682     Float_t slatLength4[kNslats4];     
683     
684     char idSlatCh7[5];
685     char idSlatCh8[5];
686     Float_t xSlat4;
687     Float_t ySlat41 = 0;
688     Float_t ySlat42 = 0;
689     angle = 0.;
690
691     for (i = 0; i<kNslats4; i++){
692       slatLength4[i] = kPcbLength * kNPCB4[i] + 2. * kVframeLength; 
693       xSlat4 = slatLength4[i]/2. + kDslatLength + kXpos4[i]; 
694       ySlat41 += kYpos41[i];
695       ySlat42 += kYpos42[i];
696
697       spar[0] = slatLength4[i]/2.; 
698       spar[1] = kSlatHeight/2.;
699       spar[2] = kSlatWidth/2.; 
700       Float_t dzCh4 = dzCh;
701       Float_t zSlat4 = (i%2 ==0)? -zSlat : zSlat; 
702
703       sprintf(idSlatCh7,"LC%d",kNslats4-1+i);
704       detElemId = 713 - (i + kNslats4-1-6);
705       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
706       if (detElemId % 2 == 0)
707           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, ySlat41, -zSlat4 + dzCh4),
708                                    TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
709       else
710           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, ySlat41, -zSlat4 + dzCh4),
711                                    TGeoRotation("rot1",90,angle,90,270+angle,180,0) );
712
713       sprintf(idSlatCh7,"LC%d",3*kNslats4-2+i);
714       detElemId = 700 + (i + kNslats4-1-6);
715       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
716       if (detElemId % 2 == 0)
717           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, ySlat41, zSlat4 - dzCh4),
718                                    TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );
719       else
720           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, ySlat41, zSlat4 - dzCh4),
721                                    TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
722       if (i > 0) { 
723         sprintf(idSlatCh7,"LC%d",kNslats4-1-i);
724         detElemId = 713 + (i + kNslats4-1-6);
725         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
726         if (detElemId % 2 == 0 && detElemId != 714)
727             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, -ySlat41, -zSlat4 + dzCh4),
728                                                 TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
729         else
730             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, -ySlat41, -zSlat4 + dzCh4),
731                                                 TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
732         sprintf(idSlatCh7,"LC%d",3*kNslats4-2-i);
733         detElemId = 726 - (i + kNslats4-1-6);
734         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
735         if (detElemId % 2 == 1 && detElemId != 725 )
736             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, -ySlat41, zSlat4 - dzCh4),
737                                      TGeoRotation("rot4",90,180+angle,90,90+angle,180,0) );
738         else
739              GetEnvelopes(moduleId)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, -ySlat41, zSlat4 - dzCh4),
740                                      TGeoRotation("rot4",90,180+angle,90,270+angle,0,0) ); 
741       }
742
743       sprintf(idSlatCh8,"LD%d",kNslats4-1+i);
744       detElemId = 813 - (i + kNslats4-1-6);
745       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
746       if (detElemId % 2 == 0)
747           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, ySlat42, -zSlat4 + dzCh4),
748                                    TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
749       else
750           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, ySlat42, -zSlat4 + dzCh4),
751                                    TGeoRotation("rot5",90,angle,90,270+angle,180,0) ); 
752
753       sprintf(idSlatCh8,"LD%d",3*kNslats4-2+i);
754       detElemId = 800 + (i + kNslats4-1-6);
755       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
756       if (detElemId % 2 == 0)
757           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, ySlat42, zSlat4 - dzCh4),
758                                    TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
759       else
760           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, ySlat42, zSlat4 - dzCh4),
761                                    TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) );
762       if (i > 0) { 
763         sprintf(idSlatCh8,"LD%d",kNslats4-1-i);
764         detElemId = 813 + (i + kNslats4-1-6);
765         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
766         if (detElemId % 2 == 0 && detElemId != 814)
767             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, -ySlat42, -zSlat4 + dzCh4),
768                                                 TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
769         else
770             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, -ySlat42, -zSlat4 + dzCh4),
771                                                 TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
772         sprintf(idSlatCh8,"LD%d",3*kNslats4-2-i);
773         detElemId = 826 - (i + kNslats4-1-6);
774         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
775         if (detElemId % 2 == 1 && detElemId != 825 )
776             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, -ySlat42, zSlat4 - dzCh4),
777                                      TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) ); 
778         else
779             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, -ySlat42, zSlat4 - dzCh4),
780                                      TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) );
781           
782       }
783     }
784      
785     // create the panel volume 
786  
787     gMC->Gsvolu("S07C","BOX",kCarbonMaterial,panelpar,3);
788     gMC->Gsvolu("S08C","BOX",kCarbonMaterial,panelpar,3);
789
790     // create the nomex volume 
791
792     gMC->Gsvolu("S07N","BOX",kNomexMaterial,nomexpar,3);
793     gMC->Gsvolu("S08N","BOX",kNomexMaterial,nomexpar,3);
794
795
796     // create the nomex volume (bulk)
797
798     gMC->Gsvolu("S07X","BOX",kNomexBMaterial,nomexbpar,3);
799     gMC->Gsvolu("S08X","BOX",kNomexBMaterial,nomexbpar,3);
800
801     // create the insulating material volume 
802
803     gMC->Gsvolu("S07I","BOX",kInsuMaterial,insupar,3);
804     gMC->Gsvolu("S08I","BOX",kInsuMaterial,insupar,3);
805
806     // create the PCB volume 
807
808     gMC->Gsvolu("S07P","BOX",kPcbMaterial,pcbpar,3);
809     gMC->Gsvolu("S08P","BOX",kPcbMaterial,pcbpar,3);
810  
811     // create the sensitive volumes,
812
813     gMC->Gsvolu("S07G","BOX",kSensMaterial,dum,0);
814     gMC->Gsvolu("S08G","BOX",kSensMaterial,dum,0);
815
816     // create the vertical frame volume 
817
818     gMC->Gsvolu("S07V","BOX",kVframeMaterial,vFramepar,3);
819     gMC->Gsvolu("S08V","BOX",kVframeMaterial,vFramepar,3);
820
821     // create the horizontal frame volume 
822
823     gMC->Gsvolu("S07H","BOX",kHframeMaterial,hFramepar,3);
824     gMC->Gsvolu("S08H","BOX",kHframeMaterial,hFramepar,3);
825
826     // create the horizontal border volume 
827
828     gMC->Gsvolu("S07B","BOX",kBframeMaterial,bFramepar,3);
829     gMC->Gsvolu("S08B","BOX",kBframeMaterial,bFramepar,3);
830
831     index = 0; 
832     for (i = 0; i < kNslats4; i++){
833       for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
834
835         if (i == 0 && quadrant == 2) continue;
836         if (i == 0 && quadrant == 4) continue;
837
838         sprintf(idSlatCh7,"LC%d",ConvertSlatNum(i,quadrant,kNslats4-1));
839         sprintf(idSlatCh8,"LD%d",ConvertSlatNum(i,quadrant,kNslats4-1));
840         Int_t moduleSlatCh7 = GetModuleId(idSlatCh7);
841         Int_t moduleSlatCh8 = GetModuleId(idSlatCh8);
842
843         Float_t xvFrame  = (slatLength4[i] - kVframeLength)/2.;
844
845         // position the vertical frames 
846         if (i != 1) { 
847           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
848           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
849           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
850           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
851         } else { // no rounded spacer yet
852           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
853           // GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
854           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
855           // GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
856         }
857         // position the panels and the insulating material 
858         for (j = 0; j < kNPCB4[i]; j++){
859           if (i == 1 && j == 0) continue;
860           index++;
861           Float_t xx = kSensLength * (-kNPCB4[i]/2.+j+.5); 
862
863           Float_t zPanel = spar[2] - nomexbpar[2]; 
864           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07X", idSlatCh7, 2*index-1,TGeoTranslation(xx,0.,zPanel));
865           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07X", idSlatCh7, 2*index,TGeoTranslation(xx,0.,-zPanel));
866           GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituent("S07I", idSlatCh7, index,TGeoTranslation(xx,0.,0.));
867           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08X", idSlatCh8, 2*index-1,TGeoTranslation(xx,0.,zPanel));
868           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08X", idSlatCh8, 2*index,TGeoTranslation(xx,0.,-zPanel));
869           GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituent("S08I", idSlatCh8, index,TGeoTranslation(xx,0.,0.));
870         }
871       } 
872     }
873
874     // position the nomex volume inside the panel volume
875     gMC->Gspos("S07N",1,"S07C",0.,0.,0.,0,"ONLY"); 
876     gMC->Gspos("S08N",1,"S08C",0.,0.,0.,0,"ONLY"); 
877
878     // position panel volume inside the bulk nomex material volume
879     gMC->Gspos("S07C",1,"S07X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
880     gMC->Gspos("S08C",1,"S08X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
881
882     // position the PCB volume inside the insulating material volume
883     gMC->Gspos("S07P",1,"S07I",0.,0.,0.,0,"ONLY"); 
884     gMC->Gspos("S08P",1,"S08I",0.,0.,0.,0,"ONLY"); 
885
886     // position the horizontal frame volume inside the PCB volume
887     gMC->Gspos("S07H",1,"S07P",0.,0.,0.,0,"ONLY"); 
888     gMC->Gspos("S08H",1,"S08P",0.,0.,0.,0,"ONLY"); 
889
890     // position the sensitive volume inside the horizontal frame volume
891     gMC->Gsposp("S07G",1,"S07H",0.,0.,0.,0,"ONLY",senspar,3); 
892     gMC->Gsposp("S08G",1,"S08H",0.,0.,0.,0,"ONLY",senspar,3); 
893
894     // position the border volumes inside the PCB volume
895     Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
896     gMC->Gspos("S07B",1,"S07P",0., yborder,0.,0,"ONLY"); 
897     gMC->Gspos("S07B",2,"S07P",0.,-yborder,0.,0,"ONLY"); 
898     gMC->Gspos("S08B",1,"S08P",0., yborder,0.,0,"ONLY"); 
899     gMC->Gspos("S08B",2,"S08P",0.,-yborder,0.,0,"ONLY"); 
900
901     // create the NULOC volume and position it in the horizontal frame
902
903     gMC->Gsvolu("S07E","BOX",kNulocMaterial,nulocpar,3);
904     gMC->Gsvolu("S08E","BOX",kNulocMaterial,nulocpar,3);
905     index = 0;
906     for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
907       index++; 
908       gMC->Gspos("S07E",2*index-1,"S07B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
909       gMC->Gspos("S07E",2*index  ,"S07B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
910       gMC->Gspos("S08E",2*index-1,"S08B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
911       gMC->Gspos("S08E",2*index  ,"S08B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
912     }
913
914     // position the volumes approximating the circular section of the pipe
915
916     Float_t epsilon = 0.001; 
917     Int_t ndiv = 10;
918     Int_t imax = 1; 
919     Double_t divpar[3];
920     Double_t dydiv = kSensHeight/ndiv;
921     Double_t ydiv  = (kSensHeight - dydiv)/2.;
922     Float_t rmin   = AliMUONConstants::Rmin(3); // Same radius for both chamber of St4
923     Float_t xdiv   = 0.; 
924     Float_t xvol;
925     Float_t yvol;
926
927     for (Int_t idiv = 0; idiv < ndiv; idiv++){ 
928       ydiv += dydiv;
929       xdiv = 0.; 
930       if (ydiv < rmin) xdiv = rmin * TMath::Sin( TMath::ACos((ydiv-dydiv/2.)/rmin) );
931       divpar[0] = (kPcbLength - xdiv)/2.; 
932       divpar[1] = dydiv/2. - epsilon;
933       divpar[2] = kSensWidth/2.; 
934       xvol = (kPcbLength + xdiv)/2.;
935       yvol = ydiv ;
936        
937       for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
938         sprintf(idSlatCh7,"LC%d",ConvertSlatNum(1,quadrant,kNslats4-1));
939         sprintf(idSlatCh8,"LD%d",ConvertSlatNum(1,quadrant,kNslats4-1));
940         Int_t moduleSlatCh7 = GetModuleId(idSlatCh7);
941         Int_t moduleSlatCh8 = GetModuleId(idSlatCh8);
942          
943         GetEnvelopes(moduleSlatCh7)->AddEnvelopeConstituentParam("S07G",idSlatCh7, quadrant*100+imax+4*idiv+1,
944                                                      TGeoTranslation(xvol-kPcbLength * kNPCB4[1]/2.,yvol-kPcbLength,0.),3,divpar);
945          
946         GetEnvelopes(moduleSlatCh8)->AddEnvelopeConstituentParam("S08G", idSlatCh8, quadrant*100+imax+4*idiv+1,
947                                                      TGeoTranslation(xvol-kPcbLength * kNPCB4[1]/2.,yvol-kPcbLength,0.),3,divpar);
948       }
949     }
950
951
952    //
953     //Geometry of the support pannel Verticla length 5.3m, horizontal length 2.6m, internal radius  dMotherInner o SC07 and SC08  (F. Orsini, Saclay)
954     //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
955     Float_t dMotherInner =  AliMUONConstants::Rmin(3)-kRframeHeight; 
956     Float_t nomexthickness = 1.5;
957     Float_t carbonthickness = 0.03;
958     Float_t supporthlength =  260.;  
959     Float_t supportvlength =  530.;  
960     // Generating the composite shape of the carbon and nomex pannels
961     new TGeoBBox("shNomexBoxSt4",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness);
962     new TGeoBBox("shCarbonBoxSt4",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
963     new TGeoTubeSeg("shNomexHoleSt4",0., dMotherInner, nomexthickness/2.+carbonthickness+0.001, -90. ,90.);
964     new TGeoTubeSeg("shCarbonHoleSt4",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
965     TGeoTranslation* trHoleSt4 = new TGeoTranslation("trHoleSt4",-supporthlength/2.,0.,0.); 
966     trHoleSt4->RegisterYourself();
967     TGeoCompositeShape* shNomexSupportSt4  = new TGeoCompositeShape("shNomexSupportSt4","shNomexBoxSt4-shNomexHoleSt4:trHoleSt4");
968     TGeoCompositeShape* shCarbonSupportSt4 = new TGeoCompositeShape("shCarbonSupportSt4","shCarbonBoxSt4-shCarbonHoleSt4:trHoleSt4");
969  
970    // Generating Nomex and Carbon pannel volumes
971     TGeoVolume* voNomexSupportSt4   = new TGeoVolume("S07S", shNomexSupportSt4, kMedNomex);
972     TGeoVolume* voCarbonSupportSt4  = new TGeoVolume("S07K", shCarbonSupportSt4, kMedCarbon);
973     TGeoTranslation* trCarbon1St4   = new TGeoTranslation("trCarbon1St4",0.,0., -(nomexthickness+carbonthickness)/2.);
974     TGeoTranslation* trCarbon2St4   = new TGeoTranslation("trCarbon2St4",0.,0.,  (nomexthickness+carbonthickness)/2.);
975     voNomexSupportSt4->AddNode(voCarbonSupportSt4,1,trCarbon1St4);
976     voNomexSupportSt4->AddNode(voCarbonSupportSt4,2,trCarbon2St4);
977     Float_t dzCh7  = dzCh;
978     TGeoTranslation* trSupport1St4   = new TGeoTranslation("trSupport1St4", supporthlength/2., 0. , dzCh7);
979     TGeoRotation*    roSupportSt4    = new TGeoRotation("roSupportSt4",90.,180.,-90.);
980     TGeoCombiTrans*  coSupport2St4   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh7, roSupportSt4); 
981     GetEnvelopes(9)->AddEnvelope("S07S", 0, 1, *trSupport1St4);  
982     GetEnvelopes(8)->AddEnvelope("S07S", 0, 2, *coSupport2St4);  
983     GetEnvelopes(11)->AddEnvelope("S07S", 0, 3, *trSupport1St4);   
984     GetEnvelopes(10)->AddEnvelope("S07S", 0, 4, *coSupport2St4);
985
986     // End of pannel support geometry    
987
988     // cout << "Geometry for Station 4...... done" << endl;
989
990   }
991     
992   if (fStations[4]) {
993       
994
995     // //********************************************************************
996     // //                            Station 5                             **
997     // //********************************************************************
998     // Mother volume for each chamber in St4 is an envelop (or assembly)
999     // There is one assembly mother per half a chamber  called SC09I, SC09O, SC10I and SC10O 
1000     // Same volume name definitions as in St3
1001     
1002     const Int_t   kNslats5         = 7;  // number of slats per quadrant
1003     const Int_t   kNPCB5[kNslats5] = {5, 6, 6, 6, 5, 4, 3}; // n PCB per slat
1004     const Float_t kXpos5[kNslats5] = {38.75, 0., 0., 0., 0., 0., 0.}; // J.C. Correct value  
1005     const Float_t kYpos5[kNslats5] = {0., 38.2, 37.9, 37.6, 37.3, 37.05, 36.75};
1006     Float_t slatLength5[kNslats5]; 
1007
1008
1009     char idSlatCh9[5];
1010     char idSlatCh10[5];
1011     Float_t xSlat5;
1012     Float_t ySlat5 = 0;
1013     angle = 0.;
1014
1015     for (i = 0; i < kNslats5; i++){
1016
1017       slatLength5[i] = kPcbLength * kNPCB5[i] + 2.* kVframeLength; 
1018       xSlat5 = slatLength5[i]/2. + kDslatLength + kXpos5[i]; 
1019       ySlat5 += kYpos5[i];
1020
1021       spar[0] = slatLength5[i]/2.; 
1022       spar[1] = kSlatHeight/2.;
1023       spar[2] = kSlatWidth/2.; 
1024
1025       Float_t dzCh5  = dzCh;
1026       Float_t zSlat5 = (i%2 ==0)? -zSlat : zSlat; 
1027
1028       sprintf(idSlatCh9,"LE%d",kNslats5-1+i);
1029       detElemId = 913 - (i + kNslats5-1-6);
1030       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1031       if (detElemId % 2 == 0)
1032           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1033                                               TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
1034       else
1035           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1036                                               TGeoRotation("rot1",90,angle,90,270+angle,180,0) );
1037       sprintf(idSlatCh9,"LE%d",3*kNslats5-2+i);
1038       detElemId = 900 + (i + kNslats5-1-6);
1039       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1040       if (detElemId % 2 == 0)
1041           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1042                                               TGeoRotation("rot2",90,180+angle,90,270+angle,0,0) );
1043       else
1044           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1045                                               TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
1046       if (i > 0) { 
1047         sprintf(idSlatCh9,"LE%d",kNslats5-1-i);
1048         detElemId = 913 + (i + kNslats5-1-6);
1049         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1050       if (detElemId % 2 == 0  && detElemId != 914)
1051           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1052                                      TGeoRotation("rot3",90,angle,90,90+angle,0,0) );
1053       else
1054           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1055                                      TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
1056         sprintf(idSlatCh9,"LE%d",3*kNslats5-2-i);
1057         detElemId = 926 - (i + kNslats5-1-6);
1058         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1059         if (detElemId % 2 == 1 && detElemId != 925 )
1060             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1061                                                 TGeoRotation("rot4",90,180+angle,90,90+angle,180,0)  );
1062         else
1063             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1064                                                 TGeoRotation("rot4",90,180+angle,90,270+angle,0,0)  );   
1065       }
1066
1067       sprintf(idSlatCh10,"LF%d",kNslats5-1+i);
1068       detElemId = 1013 - (i + kNslats5-1-6);
1069       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1070       if (detElemId % 2 == 0)
1071           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1072                                               TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
1073       else
1074           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, ySlat5, -zSlat5 + dzCh5),
1075                                               TGeoRotation("rot5",90,angle,90,270+angle,180,0) );
1076
1077       sprintf(idSlatCh10,"LF%d",3*kNslats5-2+i);
1078       detElemId = 1000 + (i + kNslats5-1-6);
1079       moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1080       if (detElemId % 2 == 0)
1081           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1082                                               TGeoRotation("rot6",90,180+angle,90,270+angle,0,0) );
1083       else
1084           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat5 - dzCh5),
1085                                               TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) ); 
1086       if (i > 0) { 
1087         sprintf(idSlatCh10,"LF%d",kNslats5-1-i);
1088         detElemId = 1013 + (i + kNslats5-1-6);
1089         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1090       if (detElemId % 2 == 0  && detElemId != 1014)
1091           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1092                                      TGeoRotation("rot7",90,angle,90,90+angle,0,0) );
1093       else
1094           GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, -zSlat5 + dzCh5),
1095                                      TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
1096         sprintf(idSlatCh10,"LF%d",3*kNslats5-2-i);
1097         detElemId = 1026 - (i + kNslats5-1-6);
1098         moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
1099         if (detElemId % 2 == 1 && detElemId != 1025 )
1100             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1101                                               TGeoRotation("rot8",90,180+angle,90,90+angle,180,0) );
1102         else
1103             GetEnvelopes(moduleId)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat5 - dzCh5),
1104                                               TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) ); 
1105       }
1106     }
1107
1108     // create the panel volume 
1109  
1110     gMC->Gsvolu("S09C","BOX",kCarbonMaterial,panelpar,3);
1111     gMC->Gsvolu("S10C","BOX",kCarbonMaterial,panelpar,3);
1112
1113     // create the nomex volume 
1114
1115     gMC->Gsvolu("S09N","BOX",kNomexMaterial,nomexpar,3);
1116     gMC->Gsvolu("S10N","BOX",kNomexMaterial,nomexpar,3);
1117
1118
1119     // create the nomex volume (bulk)
1120
1121     gMC->Gsvolu("S09X","BOX",kNomexBMaterial,nomexbpar,3);
1122     gMC->Gsvolu("S10X","BOX",kNomexBMaterial,nomexbpar,3);
1123
1124     // create the insulating material volume 
1125
1126     gMC->Gsvolu("S09I","BOX",kInsuMaterial,insupar,3);
1127     gMC->Gsvolu("S10I","BOX",kInsuMaterial,insupar,3);
1128
1129     // create the PCB volume 
1130
1131     gMC->Gsvolu("S09P","BOX",kPcbMaterial,pcbpar,3);
1132     gMC->Gsvolu("S10P","BOX",kPcbMaterial,pcbpar,3);
1133  
1134     // create the sensitive volumes,
1135
1136     gMC->Gsvolu("S09G","BOX",kSensMaterial,dum,0);
1137     gMC->Gsvolu("S10G","BOX",kSensMaterial,dum,0);
1138
1139     // create the vertical frame volume 
1140
1141     gMC->Gsvolu("S09V","BOX",kVframeMaterial,vFramepar,3);
1142     gMC->Gsvolu("S10V","BOX",kVframeMaterial,vFramepar,3);
1143
1144     // create the horizontal frame volume 
1145
1146     gMC->Gsvolu("S09H","BOX",kHframeMaterial,hFramepar,3);
1147     gMC->Gsvolu("S10H","BOX",kHframeMaterial,hFramepar,3);
1148
1149     // create the horizontal border volume 
1150
1151     gMC->Gsvolu("S09B","BOX",kBframeMaterial,bFramepar,3);
1152     gMC->Gsvolu("S10B","BOX",kBframeMaterial,bFramepar,3);
1153
1154     index = 0; 
1155     for (i = 0; i < kNslats5; i++){
1156       for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
1157
1158         if (i == 0 && quadrant == 2) continue;
1159         if (i == 0 && quadrant == 4) continue;
1160
1161         sprintf(idSlatCh9,"LE%d",ConvertSlatNum(i,quadrant,kNslats5-1));
1162         sprintf(idSlatCh10,"LF%d",ConvertSlatNum(i,quadrant,kNslats5-1));
1163         Int_t moduleSlatCh9 = GetModuleId(idSlatCh9);
1164         Int_t moduleSlatCh10 = GetModuleId(idSlatCh10);
1165         Float_t xvFrame  = (slatLength5[i] - kVframeLength)/2.; // ok
1166
1167         // position the vertical frames (spacers)
1168         if (i != 1) { 
1169           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1170           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1171           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1172           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1173         } else {  // no rounded spacer yet
1174           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1175           //       GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1176           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
1177           //       GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
1178         }
1179
1180         // position the panels and the insulating material 
1181         for (j = 0; j < kNPCB5[i]; j++){
1182           if (i == 1 && j == 0) continue;
1183           index++;
1184           Float_t xx = kSensLength * (-kNPCB5[i]/2.+j+.5); 
1185
1186           Float_t zPanel = spar[2] - nomexbpar[2]; 
1187           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09X", idSlatCh9, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1188           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09X", idSlatCh9, 2*index,TGeoTranslation(xx,0.,-zPanel));
1189           GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituent("S09I", idSlatCh9, index,TGeoTranslation(xx,0.,0.));
1190
1191           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10X", idSlatCh10, 2*index-1,TGeoTranslation(xx,0.,zPanel));
1192           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10X", idSlatCh10, 2*index,TGeoTranslation(xx,0.,-zPanel));
1193           GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituent("S10I", idSlatCh10, index,TGeoTranslation(xx,0.,0.));
1194         }
1195       } 
1196     }
1197
1198     // position the nomex volume inside the panel volume
1199     gMC->Gspos("S09N",1,"S09C",0.,0.,0.,0,"ONLY"); 
1200     gMC->Gspos("S10N",1,"S10C",0.,0.,0.,0,"ONLY"); 
1201
1202     // position panel  volume inside the bulk nomex material volume
1203     gMC->Gspos("S09C",1,"S09X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1204     gMC->Gspos("S10C",1,"S10X",0.,0.,kNomexBWidth/2.,0,"ONLY"); 
1205
1206     // position the PCB volume inside the insulating material volume
1207     gMC->Gspos("S09P",1,"S09I",0.,0.,0.,0,"ONLY"); 
1208     gMC->Gspos("S10P",1,"S10I",0.,0.,0.,0,"ONLY"); 
1209
1210     // position the horizontal frame volume inside the PCB volume
1211     gMC->Gspos("S09H",1,"S09P",0.,0.,0.,0,"ONLY"); 
1212     gMC->Gspos("S10H",1,"S10P",0.,0.,0.,0,"ONLY"); 
1213
1214     // position the sensitive volume inside the horizontal frame volume
1215     gMC->Gsposp("S09G",1,"S09H",0.,0.,0.,0,"ONLY",senspar,3); 
1216     gMC->Gsposp("S10G",1,"S10H",0.,0.,0.,0,"ONLY",senspar,3); 
1217
1218     // position the border volumes inside the PCB volume
1219     Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
1220     gMC->Gspos("S09B",1,"S09P",0., yborder,0.,0,"ONLY"); 
1221     gMC->Gspos("S09B",2,"S09P",0.,-yborder,0.,0,"ONLY"); 
1222     gMC->Gspos("S10B",1,"S10P",0., yborder,0.,0,"ONLY"); 
1223     gMC->Gspos("S10B",2,"S10P",0.,-yborder,0.,0,"ONLY"); 
1224
1225     //      // create the NULOC volume and position it in the horizontal frame
1226
1227     gMC->Gsvolu("S09E","BOX",kNulocMaterial,nulocpar,3);
1228     gMC->Gsvolu("S10E","BOX",kNulocMaterial,nulocpar,3);
1229     index = 0;
1230     for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
1231       index++; 
1232       gMC->Gspos("S09E",2*index-1,"S09B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
1233       gMC->Gspos("S09E",2*index  ,"S09B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
1234       gMC->Gspos("S10E",2*index-1,"S10B", xx, 0.,-kBframeWidth/2. + kNulocWidth/2, 0, "ONLY");
1235       gMC->Gspos("S10E",2*index  ,"S10B", xx, 0., kBframeWidth/2. - kNulocWidth/2, 0, "ONLY");
1236     }
1237   
1238
1239     // position the volumes approximating the circular section of the pipe
1240     Float_t epsilon = 0.001; 
1241     Int_t ndiv = 10;
1242     Int_t imax = 1; 
1243     Double_t divpar[3];
1244     Double_t dydiv = kSensHeight/ndiv;
1245     Double_t ydiv  = (kSensHeight - dydiv)/2.;
1246     Float_t rmin   = AliMUONConstants::Rmin(4);
1247     Float_t xdiv   = 0.; 
1248     Float_t xvol;
1249     Float_t yvol; 
1250
1251     for (Int_t idiv = 0; idiv < ndiv; idiv++){ 
1252       ydiv += dydiv;
1253       xdiv = 0.; 
1254       if (ydiv < rmin) xdiv = rmin * TMath::Sin( TMath::ACos((ydiv-dydiv/2.)/rmin) );
1255       divpar[0] = (kPcbLength - xdiv)/2.; 
1256       divpar[1] = dydiv/2. - epsilon;
1257       divpar[2] = kSensWidth/2.; 
1258       xvol = (kPcbLength + xdiv)/2.;
1259       yvol = ydiv;
1260
1261       for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
1262         sprintf(idSlatCh9,"LE%d",ConvertSlatNum(1,quadrant,kNslats5-1));
1263         sprintf(idSlatCh10,"LF%d",ConvertSlatNum(1,quadrant,kNslats5-1));
1264         Int_t moduleSlatCh9 = GetModuleId(idSlatCh9);
1265         Int_t moduleSlatCh10 = GetModuleId(idSlatCh10);
1266
1267         GetEnvelopes(moduleSlatCh9)->AddEnvelopeConstituentParam("S09G", idSlatCh9, quadrant*100+imax+4*idiv+1,
1268                                                      TGeoTranslation(xvol-kPcbLength * kNPCB5[1]/2.,yvol-kPcbLength,0.),3,divpar);
1269         GetEnvelopes(moduleSlatCh10)->AddEnvelopeConstituentParam("S10G", idSlatCh10,  quadrant*100+imax+4*idiv+1,
1270                                                      TGeoTranslation(xvol-kPcbLength * kNPCB5[1]/2.,yvol-kPcbLength,0.),3,divpar);
1271       }
1272     }
1273     //
1274     //Geometry of the support pannel Verticla length 5.7m, horizontal length 2.6m, internal radius  dMotherInner o SC09 and SC10  (F. Orsini, Saclay)
1275     //Carbon fiber of 0.3 mm thick (2 layers) and a central layer of Nomex of 15mm thick. 
1276     Float_t dMotherInner =  AliMUONConstants::Rmin(4)-kRframeHeight; 
1277     Float_t nomexthickness = 1.5;
1278     Float_t carbonthickness = 0.03;
1279     Float_t supporthlength =  260.;  
1280     Float_t supportvlength =  570.;  
1281     // Generating the composite shape of the carbon and nomex pannels
1282     new TGeoBBox("shNomexBoxSt5",supporthlength/2., supportvlength/2. ,nomexthickness/2.+carbonthickness);
1283     new TGeoBBox("shCarbonBoxSt5",supporthlength/2., supportvlength/2. ,carbonthickness/2.); 
1284     new TGeoTubeSeg("shNomexHoleSt5",0., dMotherInner, nomexthickness/2.+carbonthickness+0.001, -90. ,90.);
1285     new TGeoTubeSeg("shCarbonHoleSt5",0., dMotherInner, carbonthickness/2.+0.001, -90. ,90.);
1286     TGeoTranslation* trHoleSt5 = new TGeoTranslation("trHoleSt5",-supporthlength/2.,0.,0.); 
1287     trHoleSt5->RegisterYourself();
1288     TGeoCompositeShape* shNomexSupportSt5  = new TGeoCompositeShape("shNomexSupportSt5","shNomexBoxSt5-shNomexHoleSt5:trHoleSt5");
1289     TGeoCompositeShape* shCarbonSupportSt5 = new TGeoCompositeShape("shCarbonSupportSt5","shCarbonBoxSt5-shCarbonHoleSt5:trHoleSt5");
1290  
1291    // Generating Nomex and Carbon pannel volumes
1292     TGeoVolume* voNomexSupportSt5  = new TGeoVolume("S09S", shNomexSupportSt5, kMedNomex);
1293     TGeoVolume* voCarbonSupportSt5 = new TGeoVolume("S09K", shCarbonSupportSt5, kMedCarbon);
1294     TGeoTranslation* trCarbon1St5   = new TGeoTranslation("trCarbon1St5",0.,0., -(nomexthickness+carbonthickness)/2.);
1295     TGeoTranslation* trCarbon2St5   = new TGeoTranslation("trCarbon2St5",0.,0.,  (nomexthickness+carbonthickness)/2.);
1296     voNomexSupportSt5->AddNode(voCarbonSupportSt5,1,trCarbon1St5);
1297     voNomexSupportSt5->AddNode(voCarbonSupportSt5,2,trCarbon2St5);
1298     Float_t dzCh9  = dzCh;
1299     TGeoTranslation* trSupport1St5   = new TGeoTranslation("trSupport1St5", supporthlength/2., 0. , dzCh9);
1300     TGeoRotation*    roSupportSt5    = new TGeoRotation("roSupportSt5",90.,180.,-90.);
1301     TGeoCombiTrans*  coSupport2St5   = new TGeoCombiTrans(-supporthlength/2., 0., -dzCh9, roSupportSt5);
1302     GetEnvelopes(13)->AddEnvelope("S09S", 0, 1, *trSupport1St5);  
1303     GetEnvelopes(12)->AddEnvelope("S09S", 0, 2, *coSupport2St5);  
1304     GetEnvelopes(15)->AddEnvelope("S09S", 0, 3, *trSupport1St5);   
1305     GetEnvelopes(14)->AddEnvelope("S09S", 0, 4, *coSupport2St5);
1306
1307
1308     // End of pannel support geometry    
1309
1310     // cout << "Geometry for Station 5...... done" << endl;
1311
1312   }
1313
1314   delete [] fStations;
1315
1316 }
1317
1318
1319 //______________________________________________________________________________
1320 void AliMUONSlatGeometryBuilder::SetTransformations()
1321 {
1322 /// Defines the transformations for the station345 chambers.
1323
1324   if (gAlice->GetModule("DIPO")) {
1325     // if DIPO is preset, the whole station will be placed in DDIP volume
1326     SetMotherVolume(4, "DDIP");
1327     SetMotherVolume(5, "DDIP");
1328     SetMotherVolume(6, "DDIP");
1329     SetMotherVolume(7, "DDIP");
1330   }     
1331   SetVolume(4, "SC05I", true);
1332   SetVolume(5, "SC05O", true);
1333   SetVolume(6, "SC06I", true);
1334   SetVolume(7, "SC06O", true);
1335      
1336   if (gAlice->GetModule("SHIL")) {
1337     SetMotherVolume(8, "YOUT2");
1338     SetMotherVolume(9, "YOUT2");
1339     SetMotherVolume(10, "YOUT2");
1340     SetMotherVolume(11, "YOUT2");
1341     SetMotherVolume(12, "YOUT2");
1342     SetMotherVolume(13, "YOUT2");
1343     SetMotherVolume(14, "YOUT2");
1344     SetMotherVolume(15, "YOUT2");
1345   }  
1346
1347   SetVolume( 8, "SC07I", true);
1348   SetVolume( 9, "SC07O", true);
1349   SetVolume(10, "SC08I", true);
1350   SetVolume(11, "SC08O", true);
1351   SetVolume(12, "SC09I", true);
1352   SetVolume(13, "SC09O", true);
1353   SetVolume(14, "SC10I", true);
1354   SetVolume(15, "SC10O", true);
1355
1356 // Stations 345 are not perpendicular to the beam axis
1357 // See AliMUONConstants class
1358   TGeoRotation st345inclination("rot99");
1359   st345inclination.RotateX(AliMUONConstants::St345Inclination());
1360   
1361 // The rotation of the half-chamber is done with respect the center of the chamber.
1362 // the distance beween the roation axis and the chamber position is 
1363 // AliMUONConstants::DzCh()+AliMUONConstants::DzSlat()
1364 // Therefore the position of the half-chamber has to be corrected by a traslation in Z and Y axis
1365   Double_t deltaY = (AliMUONConstants::DzCh()+AliMUONConstants::DzSlat())*
1366     TMath::Sin(AliMUONConstants::St345Inclination() * TMath::Pi()/180.);
1367   Double_t deltaZ = (AliMUONConstants::DzCh()+AliMUONConstants::DzSlat())*
1368     (1.-TMath::Cos(AliMUONConstants::St345Inclination() * TMath::Pi()/180.));
1369
1370
1371   Double_t zpos1= - AliMUONConstants::DefaultChamberZ(4); 
1372   SetTransformation(4, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
1373   SetTransformation(5, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
1374
1375   zpos1= - AliMUONConstants::DefaultChamberZ(5); 
1376   SetTransformation(6, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
1377   SetTransformation(7, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
1378
1379   zpos1 = - AliMUONConstants::DefaultChamberZ(6); 
1380   SetTransformation(8, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
1381   SetTransformation(9, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
1382
1383   zpos1 = - AliMUONConstants::DefaultChamberZ(7); 
1384   SetTransformation(10, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination );
1385   SetTransformation(11, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination );
1386
1387   zpos1 = - AliMUONConstants::DefaultChamberZ(8); 
1388   SetTransformation(12, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
1389   SetTransformation(13, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
1390
1391   zpos1 = - AliMUONConstants::DefaultChamberZ(9); 
1392   SetTransformation(14, TGeoTranslation(0., -deltaY, -deltaZ+zpos1), st345inclination);
1393   SetTransformation(15, TGeoTranslation(0.,  deltaY,  deltaZ+zpos1), st345inclination);
1394
1395 }
1396
1397 //______________________________________________________________________________
1398 void AliMUONSlatGeometryBuilder::SetSensitiveVolumes()
1399 {
1400 /// Defines the sensitive volumes for slat stations chambers.
1401
1402   GetGeometry( 4)->SetSensitiveVolume("S05G");
1403   GetGeometry( 5)->SetSensitiveVolume("S05G");
1404   GetGeometry( 6)->SetSensitiveVolume("S06G");
1405   GetGeometry( 7)->SetSensitiveVolume("S06G");
1406   GetGeometry( 8)->SetSensitiveVolume("S07G");
1407   GetGeometry( 9)->SetSensitiveVolume("S07G");
1408   GetGeometry(10)->SetSensitiveVolume("S08G");
1409   GetGeometry(11)->SetSensitiveVolume("S08G");
1410   GetGeometry(12)->SetSensitiveVolume("S09G");
1411   GetGeometry(13)->SetSensitiveVolume("S09G");
1412   GetGeometry(14)->SetSensitiveVolume("S10G");
1413   GetGeometry(15)->SetSensitiveVolume("S10G");
1414 }
1415
1416 //______________________________________________________________________________
1417 Int_t  AliMUONSlatGeometryBuilder::ConvertSlatNum(Int_t numslat, Int_t quadnum, Int_t fspq) const
1418 {
1419 /// On-line function establishing the correspondance between numslat (the slat number on a particular quadrant (numslat->0....4 for St3))
1420 /// and slatnum (the slat number on the whole panel (slatnum->1...18 for St3)
1421   numslat += 1;
1422   if (quadnum==2 || quadnum==3) 
1423     numslat += fspq;
1424   else
1425     numslat = fspq + 2-numslat;
1426   numslat -= 1;
1427               
1428   if (quadnum==3 || quadnum==4) numslat += 2*fspq+1;
1429
1430   return numslat;
1431 }