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