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