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