Update geometry for station 3,4,5 (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 "AliRun.h"
30
31 ClassImp(AliMUONSlatGeometryBuilder)
32
33 //Int_t   ConvertSlatNum(Int_t numslat, Int_t quadnum, Int_t fspq);
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 idCopper = idtmed[1110];
104      Int_t idGlass  = idtmed[1111];
105      Int_t idCarbon = idtmed[1112];
106      Int_t idRoha   = idtmed[1113];
107      Int_t idGas    = idtmed[1108]; // medium 9 = Ar-CO2 gas (80%+20%)
108      Int_t idAir    = idtmed[1100]; // medium 1
109
110       // sensitive area: 40*40 cm**2
111      const Float_t kSensLength = 40.; 
112      const Float_t kSensHeight = 40.; 
113      const Float_t kSensWidth  = 0.5; // according to TDR fig 2.120 
114      const Int_t kSensMaterial = idGas;
115      const Float_t kYoverlap   = 1.5; 
116
117      // PCB dimensions in cm; width: 30 mum copper   
118      const Float_t kPcbLength  = kSensLength; 
119      const Float_t kPcbHeight  = 60.; 
120      const Float_t kPcbWidth   = 0.003;   
121      const Int_t kPcbMaterial  = idCopper;
122
123      // Insulating material: 200 mum glass fiber glued to pcb  
124      const Float_t kInsuLength = kPcbLength; 
125      const Float_t kInsuHeight = kPcbHeight; 
126      const Float_t kInsuWidth  = 0.020;   
127      const Int_t kInsuMaterial = idGlass;
128
129      // Carbon fiber panels: 200mum carbon/epoxy skin   
130      const Float_t kPanelLength = kSensLength; 
131      const Float_t kPanelHeight = kSensHeight; 
132      const Float_t kPanelWidth  = 0.020;      
133      const Int_t kPanelMaterial = idCarbon;
134
135      // rohacell between the two carbon panels   
136      const Float_t kRohaLength = kSensLength; 
137      const Float_t kRohaHeight = kSensHeight; 
138      const Float_t kRohaWidth  = 0.5;
139      const Int_t kRohaMaterial = idRoha;
140
141      // Frame around the slat: 2 sticks along length,2 along height  
142      // H: the horizontal ones 
143      const Float_t kHframeLength = kPcbLength; 
144      const Float_t kHframeHeight = 1.5; 
145      const Float_t kHframeWidth  = kSensWidth; 
146      const Int_t kHframeMaterial = idGlass;
147
148      // V: the vertical ones 
149      const Float_t kVframeLength = 4.0; 
150      const Float_t kVframeHeight = kSensHeight + kHframeHeight; 
151      const Float_t kVframeWidth  = kSensWidth;
152      const Int_t kVframeMaterial = idGlass;
153
154      // B: the horizontal border filled with rohacell 
155      const Float_t kBframeLength = kHframeLength; 
156      const Float_t kBframeHeight = (kPcbHeight - kSensHeight)/2. - kHframeHeight; 
157      const Float_t kBframeWidth  = kHframeWidth;
158      const Int_t kBframeMaterial = idRoha;
159
160      // NULOC: 30 mum copper + 200 mum vetronite (same radiation length as 14mum copper)
161      const Float_t kNulocLength = 2.5; 
162      const Float_t kNulocHeight = 7.5; 
163      const Float_t kNulocWidth  = 0.0030 + 0.0014; // equivalent copper width of vetronite; 
164      const Int_t   kNulocMaterial = idCopper;
165
166      const Float_t kSlatHeight = kPcbHeight; 
167      const Float_t kSlatWidth = kSensWidth + 2.*(kPcbWidth + kInsuWidth + 
168                                                2.* kPanelWidth + kRohaWidth);
169      const Int_t kSlatMaterial = idAir;
170      const Float_t kDslatLength = 2.5;//kVframeLength; // border on left and right 
171
172      Float_t spar[3];  
173      Int_t i, j;
174      Int_t detElemId;
175
176      // the panel volume contains the rohacell
177
178      Float_t twidth = 2 * kPanelWidth + kRohaWidth; 
179      Float_t panelpar[3] = { kPanelLength/2., kPanelHeight/2., twidth/2. }; 
180      Float_t rohapar[3] = { kRohaLength/2., kRohaHeight/2., kRohaWidth/2. }; 
181
182      // insulating material contains PCB-> gas-> 2 borders filled with rohacell
183
184      twidth = 2*(kInsuWidth + kPcbWidth) + kSensWidth;  
185      Float_t insupar[3] = { kInsuLength/2., kInsuHeight/2., twidth/2. }; 
186      twidth -= 2 * kInsuWidth; 
187      Float_t pcbpar[3] = { kPcbLength/2., kPcbHeight/2., twidth/2. }; 
188      Float_t senspar[3] = { kSensLength/2., kSensHeight/2., kSensWidth/2. }; 
189      Float_t theight = 2*kHframeHeight + kSensHeight;
190      Float_t hFramepar[3]={kHframeLength/2., theight/2., kHframeWidth/2.}; 
191      Float_t bFramepar[3]={kBframeLength/2., kBframeHeight/2., kBframeWidth/2.}; 
192      Float_t vFramepar[3]={kVframeLength/2., kVframeHeight/2., kVframeWidth/2.};
193      Float_t nulocpar[3]={kNulocLength/2., kNulocHeight/2., kNulocWidth/2.}; 
194      Float_t xx;
195      Float_t xxmax = (kBframeLength - kNulocLength)/2.; 
196      Int_t index=0;
197       
198     AliMUONChamber *iChamber, *iChamber1, *iChamber2;
199
200     Int_t* fStations = new Int_t[5];
201     for (Int_t i=0; i<5; i++) fStations[i] = 1;
202     //    fStations[2] = 1;
203
204     if (fStations[2])
205     {
206 //********************************************************************
207 //                            Station 3                             **
208 //********************************************************************
209      // indices 1 and 2 for first and second chambers in the station
210      // iChamber (first chamber) kept for other quanties than Z,
211      // assumed to be the same in both chambers
212
213      iChamber = GetChamber(4);
214      iChamber1 = iChamber;
215      iChamber2 = GetChamber(5);
216      
217      //iChamber1->GetGeometry()->SetDebug(kTRUE);
218      //iChamber2->GetGeometry()->SetDebug(kTRUE);
219
220      if (gAlice->GetModule("DIPO")) {
221        // if DIPO is preset, the whole station will be placed in DDIP volume
222        iChamber1->GetGeometry()->SetMotherVolume("DDIP");
223        iChamber2->GetGeometry()->SetMotherVolume("DDIP");
224      }
225
226
227      // volumes for slat geometry (xx=5,..,10 chamber id): 
228      // Sxx0 Sxx1 Sxx2 Sxx3  -->   Slat Mother volumes 
229      // SxxG                          -->   Sensitive volume (gas)
230      // SxxP                          -->   PCB (copper) 
231      // SxxI                          -->   Insulator (vetronite) 
232      // SxxC                          -->   Carbon panel 
233      // SxxR                          -->   Rohacell
234      // SxxH, SxxV                    -->   Horizontal and Vertical frames (vetronite)
235      // SB5x                          -->   Volumes for the 35 cm long PCB
236      // slat dimensions: slat is a MOTHER volume!!! made of air
237
238      // only for chamber 5: slat 1 has a PCB shorter by 5cm!
239
240      Float_t tlength = 35.;
241      Float_t panelpar2[3]  = { tlength/2., panelpar[1],  panelpar[2]}; 
242      Float_t rohapar2[3]   = { tlength/2., rohapar[1],   rohapar[2]}; 
243      Float_t insupar2[3]   = { tlength/2., insupar[1],   insupar[2]}; 
244      Float_t pcbpar2[3]    = { tlength/2., pcbpar[1],    pcbpar[2]}; 
245      Float_t senspar2[3]   = { tlength/2., senspar[1],   senspar[2]}; 
246      Float_t hFramepar2[3] = { tlength/2., hFramepar[1], hFramepar[2]}; 
247      Float_t bFramepar2[3] = { tlength/2., bFramepar[1], bFramepar[2]}; 
248      Float_t *dum=0;
249
250      const Int_t kNslats3 = 5;  // number of slats per quadrant
251      const Int_t kNPCB3[kNslats3] = {4,4,4,3,2}; // n PCB per slat
252      const Float_t kXpos3[kNslats3] = {0., 0., 0., 0., 0.};//{31., 0., 0., 0., 0.};
253      Float_t slatLength3[kNslats3]; 
254
255      // create and position the slat (mother) volumes 
256
257      char idSlatCh5[5];
258      char idSlatCh6[5];
259      Float_t xSlat3;
260      Float_t angle = 0.;
261      Float_t spar2[3];
262      for (i = 0; i < kNslats3; i++){
263        slatLength3[i] = kPcbLength * kNPCB3[i] + 2. * kDslatLength; 
264        xSlat3 = slatLength3[i]/2. + kVframeLength/2. + kXpos3[i]; 
265        Float_t ySlat31 =  kSensHeight * i - kYoverlap * i; 
266        Float_t ySlat32 = -kSensHeight * i + kYoverlap * i; 
267        spar[0] = slatLength3[i]/2.; 
268        spar[1] = kSlatHeight/2.;
269        spar[2] = kSlatWidth/2. * 1.01; 
270        // take away 5 cm from the first slat in chamber 5
271        Float_t xSlat32 = 0;
272        if (i==0 || i==1 || i==2) { // 1 pcb is shortened by 5cm
273          spar2[0] = spar[0]-5./2.;
274          xSlat32 = xSlat3;// - 5/2.;
275        } else {
276          spar2[0] = spar[0];
277          xSlat32 = xSlat3;
278        }
279        spar2[1] = spar[1];
280        spar2[2] = spar[2]; 
281        Float_t dzCh3=spar[2] * 1.01;
282        // zSlat to be checked (odd downstream or upstream?)
283        Float_t zSlat = (i%2 ==0)? -spar[2] : spar[2]; 
284
285        sprintf(idSlatCh5,"LA%d",kNslats3-1+i);
286        gMC->Gsvolu(idSlatCh5,"BOX",kSlatMaterial,spar2,3);
287        detElemId = 500 + i + kNslats3-1;
288        GetEnvelopes(4)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat32, ySlat31, zSlat+2.*dzCh3),
289                                                  TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
290
291        sprintf(idSlatCh5,"LA%d",3*kNslats3-2+i);
292        gMC->Gsvolu(idSlatCh5,"BOX",kSlatMaterial,spar2,3);
293        detElemId = 550 + i + kNslats3-1;
294        GetEnvelopes(4)->AddEnvelope(idSlatCh5,  detElemId, true, TGeoTranslation(-xSlat32, ySlat31, zSlat-2.*dzCh3),
295                                                  TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
296
297        if (i > 0) { 
298          sprintf(idSlatCh5,"LA%d",kNslats3-1-i);
299          gMC->Gsvolu(idSlatCh5,"BOX",kSlatMaterial,spar2,3);
300          detElemId = 500 - i + kNslats3-1;
301          GetEnvelopes(4)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(xSlat32, ySlat32, zSlat+2.*dzCh3), 
302                                                    TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
303
304          sprintf(idSlatCh5,"LA%d",3*kNslats3-2-i);
305          gMC->Gsvolu(idSlatCh5,"BOX",kSlatMaterial,spar2,3);
306          detElemId = 550 - i + kNslats3-1;
307          GetEnvelopes(4)->AddEnvelope(idSlatCh5, detElemId, true, TGeoTranslation(-xSlat32, ySlat32, zSlat-2.*dzCh3),
308                                                    TGeoRotation("rot4",90,180+angle,90,270+angle,0,0) );
309        }
310
311        sprintf(idSlatCh6,"LB%d",kNslats3-1+i);  
312
313        gMC->Gsvolu(idSlatCh6,"BOX",kSlatMaterial,spar2,3);
314        detElemId = 600 + i  + kNslats3-1;
315        GetEnvelopes(5)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, ySlat31, zSlat+2.*dzCh3),
316                                                  TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
317        sprintf(idSlatCh6,"LB%d",3*kNslats3-2+i);
318
319        gMC->Gsvolu(idSlatCh6,"BOX",kSlatMaterial,spar2,3);
320        detElemId = 650 + i + kNslats3-1;
321        GetEnvelopes(5)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, ySlat31, zSlat-2.*dzCh3),
322                                                  TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) );
323
324        if (i > 0) { 
325          sprintf(idSlatCh6,"LB%d",kNslats3-1-i);
326          gMC->Gsvolu(idSlatCh6,"BOX",kSlatMaterial,spar2,3);
327          detElemId = 600 - i + kNslats3-1;
328          GetEnvelopes(5)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(xSlat3, ySlat32, zSlat+2.*dzCh3),
329                                                    TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
330
331          sprintf(idSlatCh6,"LB%d",3*kNslats3-2-i);
332          gMC->Gsvolu(idSlatCh6,"BOX",kSlatMaterial,spar2,3);
333          detElemId = 650 - i + kNslats3-1;
334          GetEnvelopes(5)->AddEnvelope(idSlatCh6, detElemId, true, TGeoTranslation(-xSlat3, ySlat32, zSlat-2.*dzCh3),
335                                                    TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) );
336        }
337      }
338      
339      // create the panel volume 
340  
341      gMC->Gsvolu("S05C","BOX",kPanelMaterial,panelpar,3);
342      gMC->Gsvolu("SB5C","BOX",kPanelMaterial,panelpar2,3);
343      gMC->Gsvolu("S06C","BOX",kPanelMaterial,panelpar,3);
344  
345      // create the rohacell volume 
346
347      gMC->Gsvolu("S05R","BOX",kRohaMaterial,rohapar,3);
348      gMC->Gsvolu("SB5R","BOX",kRohaMaterial,rohapar2,3);
349      gMC->Gsvolu("S06R","BOX",kRohaMaterial,rohapar,3);
350  
351      // create the insulating material volume 
352
353      gMC->Gsvolu("S05I","BOX",kInsuMaterial,insupar,3);
354      gMC->Gsvolu("SB5I","BOX",kInsuMaterial,insupar2,3);
355      gMC->Gsvolu("S06I","BOX",kInsuMaterial,insupar,3);
356  
357      // create the PCB volume 
358
359      gMC->Gsvolu("S05P","BOX",kPcbMaterial,pcbpar,3);
360      gMC->Gsvolu("SB5P","BOX",kPcbMaterial,pcbpar2,3);
361      gMC->Gsvolu("S06P","BOX",kPcbMaterial,pcbpar,3);
362  
363      // create the sensitive volumes,
364
365      gMC->Gsvolu("S05G","BOX",kSensMaterial,dum,0);
366      gMC->Gsvolu("S06G","BOX",kSensMaterial,dum,0);
367
368      // create the vertical frame volume 
369
370      gMC->Gsvolu("S05V","BOX",kVframeMaterial,vFramepar,3);
371      gMC->Gsvolu("S06V","BOX",kVframeMaterial,vFramepar,3);
372
373      // create the horizontal frame volume 
374
375      gMC->Gsvolu("S05H","BOX",kHframeMaterial,hFramepar,3);
376      gMC->Gsvolu("SB5H","BOX",kHframeMaterial,hFramepar2,3);
377      gMC->Gsvolu("S06H","BOX",kHframeMaterial,hFramepar,3);
378  
379      // create the horizontal border volume 
380
381      gMC->Gsvolu("S05B","BOX",kBframeMaterial,bFramepar,3);
382      gMC->Gsvolu("SB5B","BOX",kBframeMaterial,bFramepar2,3);
383      gMC->Gsvolu("S06B","BOX",kBframeMaterial,bFramepar,3);
384  
385      index = 0; 
386      for (i = 0; i<kNslats3; i++){
387        for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
388
389          if (i == 0 && quadrant == 2) continue;
390          if (i == 0 && quadrant == 4) continue;
391
392          sprintf(idSlatCh5,"LA%d",ConvertSlatNum(i,quadrant,kNslats3-1));
393          sprintf(idSlatCh6,"LB%d",ConvertSlatNum(i,quadrant,kNslats3-1));
394          Float_t xvFrame  = (slatLength3[i] - kVframeLength)/2.;
395          Float_t xvFrame2  = xvFrame;
396
397          if (i == 0 || i == 1 || i == 2) xvFrame2 -= 5./2.;
398
399          // position the vertical frames 
400          if ( i > 2) { 
401            GetEnvelopes(4)->AddEnvelopeConstituent("S05V", idSlatCh5, 
402                                                    (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
403            GetEnvelopes(4)->AddEnvelopeConstituent("S05V", idSlatCh5, 
404                                                    (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
405            GetEnvelopes(5)->AddEnvelopeConstituent("S06V", idSlatCh6, 
406                                                    (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
407            GetEnvelopes(5)->AddEnvelopeConstituent("S06V", idSlatCh6, 
408                                                    (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));    
409          } 
410
411          if (i == 2) {
412            GetEnvelopes(4)->AddEnvelopeConstituent("S05V", idSlatCh5, 
413                                                    (2*i-1)*10+quadrant,TGeoTranslation(xvFrame2,0.,0.));
414            GetEnvelopes(4)->AddEnvelopeConstituent("S05V", idSlatCh5, 
415                                                    (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
416            GetEnvelopes(5)->AddEnvelopeConstituent("S06V", idSlatCh6, 
417                                                    (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
418            GetEnvelopes(5)->AddEnvelopeConstituent("S06V", idSlatCh6, 
419                                                    (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
420          }
421
422          if (i == 0 || i == 1) { // no rounded spacer for the moment (Ch. Finck)
423            GetEnvelopes(4)->AddEnvelopeConstituent("S05V", idSlatCh5, 
424                                                    (2*i-1)*10+quadrant,TGeoTranslation(xvFrame2,0.,0.));
425            GetEnvelopes(5)->AddEnvelopeConstituent("S06V", idSlatCh6, 
426                                                    (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
427          }
428
429          // position the panels and the insulating material 
430          for (j = 0; j < kNPCB3[i]; j++){
431            if (i == 1 && j == 0) continue;
432            if (i == 0 && j == 0) continue;
433            index++;
434            Float_t xx = kSensLength * (-kNPCB3[i]/2. + j + 0.5); 
435            Float_t xx2 = xx - 5/2.; 
436          
437            Float_t zPanel = spar[2] - panelpar[2]; 
438
439            if ( (i == 0 || i == 1 || i == 2) && j == kNPCB3[i]-1) { // 1 pcb is shortened by 5cm 
440              GetEnvelopes(4)->AddEnvelopeConstituent("SB5C", idSlatCh5, 2*index-1,TGeoTranslation(xx2,0.,zPanel));
441              GetEnvelopes(4)->AddEnvelopeConstituent("SB5C", idSlatCh5, 2*index,TGeoTranslation(xx2,0.,-zPanel));
442              GetEnvelopes(4)->AddEnvelopeConstituent("SB5I", idSlatCh5, index,TGeoTranslation(xx2,0.,0.));
443            }
444            else if ( (i == 0 || i == 1 || i == 2) && j < kNPCB3[i]-1) {
445              GetEnvelopes(4)->AddEnvelopeConstituent("S05C", idSlatCh5, 2*index-1,TGeoTranslation(xx,0.,zPanel));
446              GetEnvelopes(4)->AddEnvelopeConstituent("S05C", idSlatCh5, 2*index,TGeoTranslation(xx,0.,-zPanel));
447              GetEnvelopes(4)->AddEnvelopeConstituent("S05I", idSlatCh5, index,TGeoTranslation(xx,0.,0.));
448            }
449            else {
450              GetEnvelopes(4)->AddEnvelopeConstituent("S05C", idSlatCh5, 2*index-1,TGeoTranslation(xx,0.,zPanel));
451              GetEnvelopes(4)->AddEnvelopeConstituent("S05C", idSlatCh5, 2*index,TGeoTranslation(xx,0.,-zPanel));
452              GetEnvelopes(4)->AddEnvelopeConstituent("S05I", idSlatCh5, index,TGeoTranslation(xx,0.,0.));
453            }
454            GetEnvelopes(5)->AddEnvelopeConstituent("S06C", idSlatCh6, 2*index-1,TGeoTranslation(xx,0.,zPanel));
455            GetEnvelopes(5)->AddEnvelopeConstituent("S06C", idSlatCh6, 2*index,TGeoTranslation(xx,0.,-zPanel));
456            GetEnvelopes(5)->AddEnvelopeConstituent("S06I", idSlatCh6, index,TGeoTranslation(xx,0.,0.));
457  
458          } 
459        }
460      }
461
462      // position the rohacell volume inside the panel volume
463      gMC->Gspos("S05R",1,"S05C",0.,0.,0.,0,"ONLY"); 
464      gMC->Gspos("SB5R",1,"SB5C",0.,0.,0.,0,"ONLY"); 
465      gMC->Gspos("S06R",1,"S06C",0.,0.,0.,0,"ONLY"); 
466   
467      // position the PCB volume inside the insulating material volume
468      gMC->Gspos("S05P",1,"S05I",0.,0.,0.,0,"ONLY"); 
469      gMC->Gspos("SB5P",1,"SB5I",0.,0.,0.,0,"ONLY"); 
470      gMC->Gspos("S06P",1,"S06I",0.,0.,0.,0,"ONLY"); 
471   
472      // position the horizontal frame volume inside the PCB volume
473      gMC->Gspos("S05H",1,"S05P",0.,0.,0.,0,"ONLY"); 
474      gMC->Gspos("SB5H",1,"SB5P",0.,0.,0.,0,"ONLY"); 
475      gMC->Gspos("S06H",1,"S06P",0.,0.,0.,0,"ONLY"); 
476   
477      // position the sensitive volume inside the horizontal frame volume
478      gMC->Gsposp("S05G",1,"S05H",0.,0.,0.,0,"ONLY",senspar,3); 
479      gMC->Gsposp("S05G",1,"SB5H",0.,0.,0.,0,"ONLY",senspar2,3); 
480      gMC->Gsposp("S06G",1,"S06H",0.,0.,0.,0,"ONLY",senspar,3); 
481   
482  
483      // position the border volumes inside the PCB volume
484      Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
485      gMC->Gspos("S05B",1,"S05P",0., yborder,0.,0,"ONLY"); 
486      gMC->Gspos("S05B",2,"S05P",0.,-yborder,0.,0,"ONLY"); 
487      gMC->Gspos("SB5B",1,"SB5P",0., yborder,0.,0,"ONLY"); 
488      gMC->Gspos("SB5B",2,"SB5P",0.,-yborder,0.,0,"ONLY"); 
489
490      gMC->Gspos("S06B",1,"S06P",0., yborder,0.,0,"ONLY"); 
491      gMC->Gspos("S06B",2,"S06P",0.,-yborder,0.,0,"ONLY"); 
492   
493      // create the NULOC volume and position it in the horizontal frame
494      gMC->Gsvolu("S05N","BOX",kNulocMaterial,nulocpar,3);
495      gMC->Gsvolu("S06N","BOX",kNulocMaterial,nulocpar,3);
496      index = 0;
497      Float_t xxmax2 = xxmax - 5./2.;
498      for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
499        index++; 
500        gMC->Gspos("S05N",2*index-1,"S05B", xx, 0.,-kBframeWidth/4., 0, "ONLY");
501        gMC->Gspos("S05N",2*index  ,"S05B", xx, 0., kBframeWidth/4., 0, "ONLY");
502        gMC->Gspos("S06N",2*index-1,"S06B", xx, 0.,-kBframeWidth/4., 0, "ONLY");
503        gMC->Gspos("S06N",2*index  ,"S06B", xx, 0., kBframeWidth/4., 0, "ONLY");
504        if (xx > -xxmax2 && xx< xxmax2) {
505          gMC->Gspos("S05N",2*index-1,"SB5B", xx, 0.,-kBframeWidth/4., 0, "ONLY");
506          gMC->Gspos("S05N",2*index  ,"SB5B", xx, 0., kBframeWidth/4., 0, "ONLY");
507        }
508      }
509
510      // position the volumes approximating the circular section of the pipe
511      Float_t yoffs = kSensHeight/2.-kYoverlap; 
512      Float_t epsilon = 0.001; 
513      Int_t ndiv = 6;
514      Double_t divpar[3];
515      Double_t dydiv= kSensHeight/ndiv;
516      Double_t ydiv = yoffs -dydiv/2.;
517      Int_t imax = 0; 
518      imax = 1; 
519      Double_t rmin = 31.5;  // Corrected in sep04 from PQ-LAT-SR2 de CEA-DSM-DAPNIA-SIS/BE ph HARDY 19-Oct-2002 slat 
520      Double_t xdiv = 0.;
521      for (Int_t idiv = 0;idiv < ndiv; idiv++){ 
522        ydiv += dydiv;
523        xdiv = 0.; 
524        if (ydiv < rmin) xdiv = rmin * TMath::Sin( TMath::ACos(ydiv/rmin) );
525        divpar[0] = (kPcbLength-xdiv)/2.; 
526        divpar[1] = dydiv/2. - epsilon;
527        divpar[2] = kSensWidth/2.; 
528        Float_t xvol = (kPcbLength+xdiv)/2.;
529        Float_t yvol = ydiv; 
530
531        // Volumes close to the beam pipe for slat i=1 so 4 slats per chamber
532        for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
533          sprintf(idSlatCh5,"LA%d",ConvertSlatNum(1,quadrant,kNslats3-1));
534          sprintf(idSlatCh6,"LB%d",ConvertSlatNum(1,quadrant,kNslats3-1));
535
536          GetEnvelopes(4)->AddEnvelopeConstituentParam("S05G", idSlatCh5, quadrant*100+imax+4*idiv+1,
537                         TGeoTranslation(xvol-(kPcbLength * (kNPCB3[1])/2.),yvol-kPcbLength+kYoverlap,0.),3,divpar);
538
539          GetEnvelopes(5)->AddEnvelopeConstituentParam("S06G", idSlatCh6,  quadrant*100+imax+4*idiv+1,
540                         TGeoTranslation(xvol-kPcbLength * kNPCB3[1]/2.,yvol-kPcbLength+kYoverlap,0.),3,divpar);
541        }
542      }
543
544      // Volumes close to the beam pipe for slat i=0 so 2 slats per chamber (Lattes centrales de la station 3)
545      //      Gines Martinez, Subatech sep 04
546      // 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
547      // Cette code a ete ecrit suivant le plan PQ-LAT-SR1 de CEA-DSM-DAPNIA-SIS/BE ph HARDY 8-Oct-2002
548      // Rmin = 31.5 cm
549      Double_t rmin_122000SR1 = 31.5; //in cm  
550      ndiv  = 9; 
551      dydiv = kSensHeight/ndiv;           // Vertical size of the box volume approximating the rounded PCB
552      ydiv  = -kSensHeight/2 + dydiv/2.-kYoverlap;   // Initializing vertical position of the volume from bottom
553      xdiv  = 0.;                         // Initializing horizontal position of the box volumes
554      for (Int_t idiv=0;idiv<ndiv; idiv++){ 
555        xdiv = TMath::Abs( rmin_122000SR1 * TMath::Sin( TMath::ACos(ydiv/rmin_122000SR1) ) );
556        divpar[0] = (kPcbLength-xdiv)/2.; // Dimension of the box volume
557        divpar[1] = dydiv/2. - epsilon;
558        divpar[2] = kSensWidth/2.; 
559        Float_t xvol = (kPcbLength+xdiv)/2.; //2D traslition for positionning of box volume
560        Float_t yvol =  ydiv;
561        Int_t side;
562        for (side = 1; side <= 2; side++) {
563          sprintf(idSlatCh5,"LA%d",4);      
564          sprintf(idSlatCh6,"LB%d",4);
565          if(side == 2) {
566            sprintf(idSlatCh5,"LA%d",13);           
567            sprintf(idSlatCh6,"LB%d",13);
568          }         
569          GetEnvelopes(4)->AddEnvelopeConstituentParam("S05G", idSlatCh5,500+side*100+imax+4*idiv+1,
570                         TGeoTranslation(xvol-(kPcbLength * (kNPCB3[0])/2.),yvol+kYoverlap,0.),3,divpar);
571
572          GetEnvelopes(5)->AddEnvelopeConstituentParam("S06G", idSlatCh6,500+side*100+imax+4*idiv+1,
573                         TGeoTranslation(xvol-kPcbLength * kNPCB3[0]/2.,yvol+kYoverlap,0.),3,divpar);
574        }
575        ydiv += dydiv; // Going from bottom to top
576      }
577      // cout << "Geometry for Station 3...... done" << endl;    
578     }
579     
580     if (fStations[3]) {
581
582
583 // //********************************************************************
584 // //                            Station 4                             **
585 // //********************************************************************
586 //      // indices 1 and 2 for first and second chambers in the station
587 //      // iChamber (first chamber) kept for other quanties than Z,
588 //      // assumed to be the same in both chambers
589 //      corrected geometry (JP. Cussonneau, Ch. Finck)
590  
591      iChamber = GetChamber(6);
592      iChamber1 = iChamber;
593      iChamber2 = GetChamber(7);
594
595      const Int_t kNslats4 = 7;  // number of slats per quadrant
596      const Int_t kNPCB4[kNslats4] = {5,6,5,5,4,3,2}; // n PCB per slat
597      const Float_t kXpos4[kNslats4] = {38.5, 0., 0., 0., 0., 0., 0.};
598      Float_t slatLength4[kNslats4];     
599
600 //      // create and position the slat (mother) volumes 
601
602      char idSlatCh7[5];
603      char idSlatCh8[5];
604      Float_t xSlat4;
605      Float_t ySlat4;
606      angle = 0.;
607
608      for (i = 0; i<kNslats4; i++){
609        slatLength4[i] = kPcbLength * kNPCB4[i] + 2. * kDslatLength; 
610        xSlat4 = slatLength4[i]/2. + kVframeLength/2. + kXpos4[i]; 
611        ySlat4 = kSensHeight * i - kYoverlap *i;
612        
613        spar[0] = slatLength4[i]/2.; 
614        spar[1] = kSlatHeight/2.;
615        spar[2] = kSlatWidth/2.*1.01; 
616        Float_t dzCh4 = spar[2]*1.01;
617        // zSlat to be checked (odd downstream or upstream?)
618        Float_t zSlat = (i%2 ==0)? spar[2] : -spar[2]; 
619
620        sprintf(idSlatCh7,"LC%d",kNslats4-1+i);
621        gMC->Gsvolu(idSlatCh7,"BOX",kSlatMaterial,spar,3);
622        detElemId = 700 + i + kNslats4-1;
623        GetEnvelopes(6)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, ySlat4, zSlat+2.*dzCh4),
624                                                  TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
625
626        sprintf(idSlatCh7,"LC%d",3*kNslats4-2+i);
627        gMC->Gsvolu(idSlatCh7,"BOX",kSlatMaterial,spar,3);
628        detElemId = 750 + i + kNslats4-1;
629        GetEnvelopes(6)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(-xSlat4, ySlat4, zSlat-2.*dzCh4),
630                                                  TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
631  
632        if (i > 0) { 
633          sprintf(idSlatCh7,"LC%d",kNslats4-1-i);
634          gMC->Gsvolu(idSlatCh7,"BOX",kSlatMaterial,spar,3);
635          detElemId = 700 - i + kNslats4-1;
636          GetEnvelopes(6)->AddEnvelope(idSlatCh7, detElemId, true, TGeoTranslation(xSlat4, -ySlat4, zSlat+2.*dzCh4),
637                                                    TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
638
639          sprintf(idSlatCh7,"LC%d",3*kNslats4-2-i);
640          detElemId = 750 - i + kNslats4-1;
641          gMC->Gsvolu(idSlatCh7,"BOX",kSlatMaterial,spar,3);
642          GetEnvelopes(6)->AddEnvelope(idSlatCh7, detElemId, true, 
643                                                    TGeoTranslation(-xSlat4, -ySlat4, zSlat-2.*dzCh4),
644                                                    TGeoRotation("rot4",90,180+angle,90,270+angle,0,0) );
645        }
646
647        sprintf(idSlatCh8,"LD%d",kNslats4-1+i);
648        gMC->Gsvolu(idSlatCh8,"BOX",kSlatMaterial,spar,3);
649        detElemId = 800 + i + kNslats4-1;
650        GetEnvelopes(7)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, ySlat4, zSlat+2.*dzCh4),
651                                                  TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
652
653        sprintf(idSlatCh8,"LD%d",3*kNslats4-2+i);
654        detElemId = 850 + i + kNslats4-1;
655        gMC->Gsvolu(idSlatCh8,"BOX",kSlatMaterial,spar,3);
656        GetEnvelopes(7)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, ySlat4, zSlat-2.*dzCh4),
657                                                  TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) );
658        if (i > 0) { 
659          sprintf(idSlatCh8,"LD%d",kNslats4-1-i);
660          detElemId = 800 - i + kNslats4-1;
661          gMC->Gsvolu(idSlatCh8,"BOX",kSlatMaterial,spar,3);
662          GetEnvelopes(7)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(xSlat4, -ySlat4, zSlat+2.*dzCh4),
663                                                    TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
664          sprintf(idSlatCh8,"LD%d",3*kNslats4-2-i);
665          detElemId = 850 - i + kNslats4-1;
666          gMC->Gsvolu(idSlatCh8,"BOX",kSlatMaterial,spar,3);
667          GetEnvelopes(7)->AddEnvelope(idSlatCh8, detElemId, true, TGeoTranslation(-xSlat4, -ySlat4, zSlat-2.*dzCh4),
668                                                    TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) );
669        }
670      }
671      
672      // create the panel volume 
673  
674      gMC->Gsvolu("S07C","BOX",kPanelMaterial,panelpar,3);
675      gMC->Gsvolu("S08C","BOX",kPanelMaterial,panelpar,3);
676
677      // create the rohacell volume 
678
679      gMC->Gsvolu("S07R","BOX",kRohaMaterial,rohapar,3);
680      gMC->Gsvolu("S08R","BOX",kRohaMaterial,rohapar,3);
681
682      // create the insulating material volume 
683
684      gMC->Gsvolu("S07I","BOX",kInsuMaterial,insupar,3);
685      gMC->Gsvolu("S08I","BOX",kInsuMaterial,insupar,3);
686
687      // create the PCB volume 
688
689      gMC->Gsvolu("S07P","BOX",kPcbMaterial,pcbpar,3);
690      gMC->Gsvolu("S08P","BOX",kPcbMaterial,pcbpar,3);
691  
692      // create the sensitive volumes,
693
694      gMC->Gsvolu("S07G","BOX",kSensMaterial,dum,0);
695      gMC->Gsvolu("S08G","BOX",kSensMaterial,dum,0);
696
697      // create the vertical frame volume 
698
699      gMC->Gsvolu("S07V","BOX",kVframeMaterial,vFramepar,3);
700      gMC->Gsvolu("S08V","BOX",kVframeMaterial,vFramepar,3);
701
702      // create the horizontal frame volume 
703
704      gMC->Gsvolu("S07H","BOX",kHframeMaterial,hFramepar,3);
705      gMC->Gsvolu("S08H","BOX",kHframeMaterial,hFramepar,3);
706
707      // create the horizontal border volume 
708
709      gMC->Gsvolu("S07B","BOX",kBframeMaterial,bFramepar,3);
710      gMC->Gsvolu("S08B","BOX",kBframeMaterial,bFramepar,3);
711
712      index = 0; 
713      for (i = 0; i < kNslats4; i++){
714        for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
715
716          if (i == 0 && quadrant == 2) continue;
717          if (i == 0 && quadrant == 4) continue;
718
719          sprintf(idSlatCh7,"LC%d",ConvertSlatNum(i,quadrant,kNslats4-1));
720          sprintf(idSlatCh8,"LD%d",ConvertSlatNum(i,quadrant,kNslats4-1));
721          Float_t xvFrame  = (slatLength4[i] - kVframeLength)/2.;
722
723          // position the vertical frames 
724          if (i != 1) { 
725            GetEnvelopes(6)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
726            GetEnvelopes(6)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
727            GetEnvelopes(7)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
728            GetEnvelopes(7)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
729          } else { // no rounded spacer yet
730            GetEnvelopes(6)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
731            // GetEnvelopes(6)->AddEnvelopeConstituent("S07V", idSlatCh7, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
732            GetEnvelopes(7)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
733            // GetEnvelopes(7)->AddEnvelopeConstituent("S08V", idSlatCh8, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
734          }
735          // position the panels and the insulating material 
736          for (j = 0; j < kNPCB4[i]; j++){
737            if (i == 1 && j == 0) continue;
738            index++;
739            Float_t xx = kSensLength * (-kNPCB4[i]/2.+j+.5); 
740
741            Float_t zPanel = spar[2] - panelpar[2]; 
742            GetEnvelopes(6)->AddEnvelopeConstituent("S07C", idSlatCh7, 2*index-1,TGeoTranslation(xx,0.,zPanel));
743            GetEnvelopes(6)->AddEnvelopeConstituent("S07C", idSlatCh7, 2*index,TGeoTranslation(xx,0.,-zPanel));
744            GetEnvelopes(6)->AddEnvelopeConstituent("S07I", idSlatCh7, index,TGeoTranslation(xx,0.,0.));
745            GetEnvelopes(7)->AddEnvelopeConstituent("S08C", idSlatCh8, 2*index-1,TGeoTranslation(xx,0.,zPanel));
746            GetEnvelopes(7)->AddEnvelopeConstituent("S08C", idSlatCh8, 2*index,TGeoTranslation(xx,0.,-zPanel));
747            GetEnvelopes(7)->AddEnvelopeConstituent("S08I", idSlatCh8, index,TGeoTranslation(xx,0.,0.));
748          }
749        } 
750      }
751
752      // position the rohacell volume inside the panel volume
753      gMC->Gspos("S07R",1,"S07C",0.,0.,0.,0,"ONLY"); 
754      gMC->Gspos("S08R",1,"S08C",0.,0.,0.,0,"ONLY"); 
755
756      // position the PCB volume inside the insulating material volume
757      gMC->Gspos("S07P",1,"S07I",0.,0.,0.,0,"ONLY"); 
758      gMC->Gspos("S08P",1,"S08I",0.,0.,0.,0,"ONLY"); 
759      // position the horizontal frame volume inside the PCB volume
760      gMC->Gspos("S07H",1,"S07P",0.,0.,0.,0,"ONLY"); 
761      gMC->Gspos("S08H",1,"S08P",0.,0.,0.,0,"ONLY"); 
762      // position the sensitive volume inside the horizontal frame volume
763      gMC->Gsposp("S07G",1,"S07H",0.,0.,0.,0,"ONLY",senspar,3); 
764      gMC->Gsposp("S08G",1,"S08H",0.,0.,0.,0,"ONLY",senspar,3); 
765      // position the border volumes inside the PCB volume
766      Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
767      gMC->Gspos("S07B",1,"S07P",0., yborder,0.,0,"ONLY"); 
768      gMC->Gspos("S07B",2,"S07P",0.,-yborder,0.,0,"ONLY"); 
769      gMC->Gspos("S08B",1,"S08P",0., yborder,0.,0,"ONLY"); 
770      gMC->Gspos("S08B",2,"S08P",0.,-yborder,0.,0,"ONLY"); 
771
772 //      // create the NULOC volume and position it in the horizontal frame
773
774      gMC->Gsvolu("S07N","BOX",kNulocMaterial,nulocpar,3);
775      gMC->Gsvolu("S08N","BOX",kNulocMaterial,nulocpar,3);
776      index = 0;
777      for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
778        index++; 
779        gMC->Gspos("S07N",2*index-1,"S07B", xx, 0.,-kBframeWidth/4., 0, "ONLY");
780        gMC->Gspos("S07N",2*index  ,"S07B", xx, 0., kBframeWidth/4., 0, "ONLY");
781        gMC->Gspos("S08N",2*index-1,"S08B", xx, 0.,-kBframeWidth/4., 0, "ONLY");
782        gMC->Gspos("S08N",2*index  ,"S08B", xx, 0., kBframeWidth/4., 0, "ONLY");
783      }
784
785 //      // position the volumes approximating the circular section of the pipe
786      Float_t yoffs = kSensHeight/2. - kYoverlap; 
787      Float_t epsilon = 0.001; 
788      Int_t ndiv = 10;
789      Double_t divpar[3];
790      Double_t dydiv= kSensHeight/ndiv;
791      Double_t ydiv = yoffs -dydiv;
792      Int_t imax=0; 
793      imax = 1; 
794      Float_t rmin = 39.5;
795      Float_t shiftR = 0.;
796      for (Int_t idiv = 0; idiv < ndiv; idiv++){ 
797        ydiv += dydiv;
798        Float_t xdiv = 0.; 
799        if (ydiv < rmin) xdiv = rmin * TMath::Sin( TMath::ACos(ydiv/rmin) );
800        divpar[0] = (kPcbLength-xdiv-shiftR)/2.; 
801        divpar[1] = dydiv/2. - epsilon;
802        divpar[2] = kSensWidth/2.; 
803        Float_t xvol = (kPcbLength+xdiv)/2.+shiftR;
804        Float_t yvol = ydiv + dydiv/2.;
805        
806        for (Int_t quadrant=1; quadrant<=4; quadrant++) {
807          sprintf(idSlatCh7,"LC%d",ConvertSlatNum(1,quadrant,kNslats4-1));
808          sprintf(idSlatCh8,"LD%d",ConvertSlatNum(1,quadrant,kNslats4-1));
809          
810          GetEnvelopes(6)->AddEnvelopeConstituentParam("S07G",idSlatCh7, quadrant*100+imax+4*idiv+1,
811                                                       TGeoTranslation(xvol-kPcbLength * kNPCB4[1]/2.,yvol-kPcbLength+kYoverlap,0.),3,divpar);
812          
813          GetEnvelopes(7)->AddEnvelopeConstituentParam("S08G", idSlatCh8, quadrant*100+imax+4*idiv+1,
814                                                       TGeoTranslation(xvol-kPcbLength * kNPCB4[1]/2.,yvol-kPcbLength+kYoverlap,0.),3,divpar);
815        }
816      }
817      // cout << "Geometry for Station 4...... done" << endl;
818
819     }
820     
821     if (fStations[4]) {
822       
823
824 // //********************************************************************
825 // //                            Station 5                             **
826 // //********************************************************************
827 //      // indices 1 and 2 for first and second chambers in the station
828 //      // iChamber (first chamber) kept for other quanties than Z,
829 //      // assumed to be the same in both chambers
830 //      corrected geometry (JP. Cussonneau, Ch. Finck)
831
832      iChamber = GetChamber(8);
833      iChamber1 = iChamber;
834      iChamber2 = GetChamber(9);
835  
836      const Int_t kNslats5 = 7;  // number of slats per quadrant
837      const Int_t kNPCB5[kNslats5] = {5,6,6,6,5,4,3}; // n PCB per slat
838      const Float_t kXpos5[kNslats5] = {38.5, 0., 0., 0., 0., 0., 0.};
839      Float_t slatLength5[kNslats5]; 
840
841 //      // create and position the slat (mother) volumes 
842
843      char idSlatCh9[5];
844      char idSlatCh10[5];
845      Float_t xSlat5;
846      Float_t ySlat5;
847      angle = 0.;
848
849      for (i = 0; i < kNslats5; i++){
850        slatLength5[i] = kPcbLength * kNPCB5[i] + 2. * kDslatLength; 
851        xSlat5 = slatLength5[i]/2. + kVframeLength/2. +kXpos5[i]; 
852        ySlat5 = kSensHeight * i - kYoverlap * i;
853  
854        spar[0] = slatLength5[i]/2.; 
855        spar[1] = kSlatHeight/2.;
856        spar[2] = kSlatWidth/2. * 1.01; 
857        Float_t dzCh5 = spar[2]*1.01;
858        // zSlat to be checked (odd downstream or upstream?)
859        Float_t zSlat = (i%2 ==0)? -spar[2] : spar[2]; 
860
861        sprintf(idSlatCh9,"LE%d",kNslats5-1+i);
862        detElemId = 900 + i + kNslats5-1;
863        gMC->Gsvolu(idSlatCh9,"BOX",kSlatMaterial,spar,3);
864        GetEnvelopes(8)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, ySlat5, zSlat+2.*dzCh5),
865                                                  TGeoRotation("rot1",90,angle,90,90+angle,0,0) );
866
867        sprintf(idSlatCh9,"LE%d",3*kNslats5-2+i);
868        detElemId = 950 + i + kNslats5-1;
869        gMC->Gsvolu(idSlatCh9,"BOX",kSlatMaterial,spar,3);
870        GetEnvelopes(8)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat-2.*dzCh5),
871                                                  TGeoRotation("rot2",90,180+angle,90,90+angle,180,0) );
872  
873        if (i > 0) { 
874          sprintf(idSlatCh9,"LE%d",kNslats5-1-i);
875          detElemId = 900 - i + kNslats5-1;
876          gMC->Gsvolu(idSlatCh9,"BOX",kSlatMaterial,spar,3);
877          GetEnvelopes(8)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, zSlat+2.*dzCh5),
878                                                    TGeoRotation("rot3",90,angle,90,270+angle,180,0) );
879
880          sprintf(idSlatCh9,"LE%d",3*kNslats5-2-i);
881          detElemId = 950 - i + kNslats5-1;
882          gMC->Gsvolu(idSlatCh9,"BOX",kSlatMaterial,spar,3);
883          GetEnvelopes(8)->AddEnvelope(idSlatCh9, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat-2.*dzCh5),
884                                                    TGeoRotation("rot4",90,180+angle,90,270+angle,0,0)  );
885        }
886
887        sprintf(idSlatCh10,"LF%d",kNslats5-1+i);
888        detElemId = 1000 + i + kNslats5-1;
889        gMC->Gsvolu(idSlatCh10,"BOX",kSlatMaterial,spar,3);
890        GetEnvelopes(9)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, ySlat5, zSlat+2.*dzCh5),
891                                                  TGeoRotation("rot5",90,angle,90,90+angle,0,0) );
892
893        sprintf(idSlatCh10,"LF%d",3*kNslats5-2+i);
894        detElemId = 1050 + i + kNslats5-1;
895        gMC->Gsvolu(idSlatCh10,"BOX",kSlatMaterial,spar,3);
896        GetEnvelopes(9)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, ySlat5, zSlat-2.*dzCh5),
897                                                  TGeoRotation("rot6",90,180+angle,90,90+angle,180,0) );
898
899        if (i > 0) { 
900          sprintf(idSlatCh10,"LF%d",kNslats5-1-i);
901          detElemId = 1000 - i + kNslats5-1;
902          gMC->Gsvolu(idSlatCh10,"BOX",kSlatMaterial,spar,3);
903          GetEnvelopes(9)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(xSlat5, -ySlat5, zSlat+2.*dzCh5),
904                                                    TGeoRotation("rot7",90,angle,90,270+angle,180,0) );
905          sprintf(idSlatCh10,"LF%d",3*kNslats5-2-i);
906          detElemId = 1050 - i + kNslats5-1;
907          gMC->Gsvolu(idSlatCh10,"BOX",kSlatMaterial,spar,3);
908          GetEnvelopes(9)->AddEnvelope(idSlatCh10, detElemId, true, TGeoTranslation(-xSlat5, -ySlat5, zSlat-2.*dzCh5),
909                                                    TGeoRotation("rot8",90,180+angle,90,270+angle,0,0) );
910        }
911      }
912      //      // create the panel volume 
913  
914      gMC->Gsvolu("S09C","BOX",kPanelMaterial,panelpar,3);
915      gMC->Gsvolu("S10C","BOX",kPanelMaterial,panelpar,3);
916
917      // create the rohacell volume 
918
919      gMC->Gsvolu("S09R","BOX",kRohaMaterial,rohapar,3);
920      gMC->Gsvolu("S10R","BOX",kRohaMaterial,rohapar,3);
921
922      // create the insulating material volume 
923
924      gMC->Gsvolu("S09I","BOX",kInsuMaterial,insupar,3);
925      gMC->Gsvolu("S10I","BOX",kInsuMaterial,insupar,3);
926
927      // create the PCB volume 
928
929      gMC->Gsvolu("S09P","BOX",kPcbMaterial,pcbpar,3);
930      gMC->Gsvolu("S10P","BOX",kPcbMaterial,pcbpar,3);
931  
932      // create the sensitive volumes,
933
934      gMC->Gsvolu("S09G","BOX",kSensMaterial,dum,0);
935      gMC->Gsvolu("S10G","BOX",kSensMaterial,dum,0);
936
937      // create the vertical frame volume 
938
939      gMC->Gsvolu("S09V","BOX",kVframeMaterial,vFramepar,3);
940      gMC->Gsvolu("S10V","BOX",kVframeMaterial,vFramepar,3);
941
942      // create the horizontal frame volume 
943
944      gMC->Gsvolu("S09H","BOX",kHframeMaterial,hFramepar,3);
945      gMC->Gsvolu("S10H","BOX",kHframeMaterial,hFramepar,3);
946
947      // create the horizontal border volume 
948
949      gMC->Gsvolu("S09B","BOX",kBframeMaterial,bFramepar,3);
950      gMC->Gsvolu("S10B","BOX",kBframeMaterial,bFramepar,3);
951
952      index = 0; 
953      for (i = 0; i < kNslats5; i++){
954        for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
955
956          if (i == 0 && quadrant == 2) continue;
957          if (i == 0 && quadrant == 4) continue;
958
959          sprintf(idSlatCh9,"LE%d",ConvertSlatNum(i,quadrant,kNslats5-1));
960          sprintf(idSlatCh10,"LF%d",ConvertSlatNum(i,quadrant,kNslats5-1));
961          Float_t xvFrame  = (slatLength5[i] - kVframeLength)/2.;
962
963          // position the vertical frames 
964          if (i != 1) { 
965            GetEnvelopes(8)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
966            GetEnvelopes(8)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
967            GetEnvelopes(9)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
968            GetEnvelopes(9)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
969          } else {  // no rounded spacer yet
970            GetEnvelopes(8)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
971            //      GetEnvelopes(8)->AddEnvelopeConstituent("S09V", idSlatCh9, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
972            GetEnvelopes(9)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i-1)*10+quadrant,TGeoTranslation(xvFrame,0.,0.));
973            //      GetEnvelopes(9)->AddEnvelopeConstituent("S10V", idSlatCh10, (2*i)*10+quadrant,TGeoTranslation(-xvFrame,0.,0.));
974          }
975
976          // position the panels and the insulating material 
977          for (j = 0; j < kNPCB5[i]; j++){
978            if (i == 1 && j == 0) continue;
979            index++;
980            Float_t xx = kSensLength * (-kNPCB5[i]/2.+j+.5); 
981
982            Float_t zPanel = spar[2] - panelpar[2]; 
983            GetEnvelopes(8)->AddEnvelopeConstituent("S09C", idSlatCh9, 2*index-1,TGeoTranslation(xx,0.,zPanel));
984            GetEnvelopes(8)->AddEnvelopeConstituent("S09C", idSlatCh9, 2*index,TGeoTranslation(xx,0.,-zPanel));
985            GetEnvelopes(8)->AddEnvelopeConstituent("S09I", idSlatCh9, index,TGeoTranslation(xx,0.,0.));
986            GetEnvelopes(9)->AddEnvelopeConstituent("S10C", idSlatCh10, 2*index-1,TGeoTranslation(xx,0.,zPanel));
987            GetEnvelopes(9)->AddEnvelopeConstituent("S10C", idSlatCh10, 2*index,TGeoTranslation(xx,0.,-zPanel));
988            GetEnvelopes(9)->AddEnvelopeConstituent("S10I", idSlatCh10, index,TGeoTranslation(xx,0.,0.));
989          }
990        } 
991      }
992
993      // position the rohacell volume inside the panel volume
994      gMC->Gspos("S09R",1,"S09C",0.,0.,0.,0,"ONLY"); 
995      gMC->Gspos("S10R",1,"S10C",0.,0.,0.,0,"ONLY"); 
996
997      // position the PCB volume inside the insulating material volume
998      gMC->Gspos("S09P",1,"S09I",0.,0.,0.,0,"ONLY"); 
999      gMC->Gspos("S10P",1,"S10I",0.,0.,0.,0,"ONLY"); 
1000      // position the horizontal frame volume inside the PCB volume
1001      gMC->Gspos("S09H",1,"S09P",0.,0.,0.,0,"ONLY"); 
1002      gMC->Gspos("S10H",1,"S10P",0.,0.,0.,0,"ONLY"); 
1003      // position the sensitive volume inside the horizontal frame volume
1004      gMC->Gsposp("S09G",1,"S09H",0.,0.,0.,0,"ONLY",senspar,3); 
1005      gMC->Gsposp("S10G",1,"S10H",0.,0.,0.,0,"ONLY",senspar,3); 
1006      // position the border volumes inside the PCB volume
1007      Float_t yborder = ( kPcbHeight - kBframeHeight ) / 2.; 
1008      gMC->Gspos("S09B",1,"S09P",0., yborder,0.,0,"ONLY"); 
1009      gMC->Gspos("S09B",2,"S09P",0.,-yborder,0.,0,"ONLY"); 
1010      gMC->Gspos("S10B",1,"S10P",0., yborder,0.,0,"ONLY"); 
1011      gMC->Gspos("S10B",2,"S10P",0.,-yborder,0.,0,"ONLY"); 
1012
1013      //      // create the NULOC volume and position it in the horizontal frame
1014
1015      gMC->Gsvolu("S09N","BOX",kNulocMaterial,nulocpar,3);
1016      gMC->Gsvolu("S10N","BOX",kNulocMaterial,nulocpar,3);
1017      index = 0;
1018      for (xx = -xxmax; xx <= xxmax; xx += 2*kNulocLength) { 
1019        index++; 
1020        gMC->Gspos("S09N",2*index-1,"S09B", xx, 0.,-kBframeWidth/4., 0, "ONLY");
1021        gMC->Gspos("S09N",2*index  ,"S09B", xx, 0., kBframeWidth/4., 0, "ONLY");
1022        gMC->Gspos("S10N",2*index-1,"S10B", xx, 0.,-kBframeWidth/4., 0, "ONLY");
1023        gMC->Gspos("S10N",2*index  ,"S10B", xx, 0., kBframeWidth/4., 0, "ONLY");
1024      }
1025
1026      //      // position the volumes approximating the circular section of the pipe
1027      Float_t yoffs = kSensHeight/2. - kYoverlap; 
1028      Float_t epsilon = 0.001; 
1029      Int_t ndiv = 10;
1030      Double_t divpar[3];
1031      Double_t dydiv = kSensHeight/ndiv;
1032      Double_t ydiv = yoffs -dydiv;
1033      Int_t imax = 0; 
1034      //     for (Int_t islat=0; islat<kNslats3; islat++) imax += kNPCB3[islat]; 
1035      imax = 1; 
1036      Float_t rmin = 40.;
1037      Float_t shiftR = 0.;
1038      for (Int_t idiv = 0;idiv < ndiv; idiv++){ 
1039        ydiv += dydiv;
1040        Float_t xdiv = 0.; 
1041        if (ydiv < rmin) xdiv = rmin * TMath::Sin( TMath::ACos(ydiv/rmin) );
1042        divpar[0] = (kPcbLength-xdiv-shiftR)/2.; 
1043        divpar[1] = dydiv/2. - epsilon;
1044        divpar[2] = kSensWidth/2.; 
1045        Float_t xvol = (kPcbLength+xdiv)/2.+ shiftR;
1046        Float_t yvol = ydiv + dydiv/2.;
1047
1048        for (Int_t quadrant = 1; quadrant <= 4; quadrant++) {
1049          sprintf(idSlatCh9,"LE%d",ConvertSlatNum(1,quadrant,kNslats5-1));
1050          sprintf(idSlatCh10,"LF%d",ConvertSlatNum(1,quadrant,kNslats5-1));
1051
1052          GetEnvelopes(8)->AddEnvelopeConstituentParam("S09G", idSlatCh9, quadrant*100+imax+4*idiv+1,
1053                                                       TGeoTranslation(xvol-kPcbLength * kNPCB5[1]/2.,yvol-kPcbLength+kYoverlap,0.),3,divpar);
1054          GetEnvelopes(9)->AddEnvelopeConstituentParam("S10G", idSlatCh10,  quadrant*100+imax+4*idiv+1,
1055                                                       TGeoTranslation(xvol-kPcbLength * kNPCB5[1]/2.,yvol-kPcbLength+kYoverlap,0.),3,divpar);
1056        }
1057      }
1058      // cout << "Geometry for Station 5...... done" << endl;
1059
1060     }
1061 }
1062
1063
1064 //______________________________________________________________________________
1065 void AliMUONSlatGeometryBuilder::SetTransformations()
1066 {
1067 // Defines the transformations for the station2 chambers.
1068 // ---
1069
1070   AliMUONChamber* iChamber1 = GetChamber(4);
1071   Double_t zpos1 = - iChamber1->Z(); 
1072   iChamber1->GetGeometry()
1073     ->SetTranslation(TGeoTranslation(0., 0., zpos1));
1074
1075   AliMUONChamber* iChamber2 = GetChamber(5);
1076   Double_t zpos2 = - iChamber2->Z(); 
1077   iChamber2->GetGeometry()
1078     ->SetTranslation(TGeoTranslation(0., 0., zpos2));
1079
1080  iChamber1 = GetChamber(6);
1081   zpos1 = - iChamber1->Z(); 
1082   iChamber1->GetGeometry()
1083     ->SetTranslation(TGeoTranslation(0., 0., zpos1));
1084
1085   iChamber2 = GetChamber(7);
1086   zpos2 = - iChamber2->Z(); 
1087   iChamber2->GetGeometry()
1088     ->SetTranslation(TGeoTranslation(0., 0., zpos2));
1089
1090  iChamber1 = GetChamber(8);
1091   zpos1 = - iChamber1->Z(); 
1092   iChamber1->GetGeometry()
1093     ->SetTranslation(TGeoTranslation(0., 0., zpos1));
1094
1095   iChamber2 = GetChamber(9);
1096   zpos2 = - iChamber2->Z(); 
1097   iChamber2->GetGeometry()
1098     ->SetTranslation(TGeoTranslation(0., 0., zpos2));
1099
1100 }
1101
1102 //______________________________________________________________________________
1103 void AliMUONSlatGeometryBuilder::SetSensitiveVolumes()
1104 {
1105 // Defines the sensitive volumes for slat stations chambers.
1106 // ---
1107
1108   GetChamber(4)->GetGeometry()->SetSensitiveVolume("S05G");
1109   GetChamber(5)->GetGeometry()->SetSensitiveVolume("S06G");
1110   GetChamber(6)->GetGeometry()->SetSensitiveVolume("S07G");
1111   GetChamber(7)->GetGeometry()->SetSensitiveVolume("S08G");
1112   GetChamber(8)->GetGeometry()->SetSensitiveVolume("S09G");
1113   GetChamber(9)->GetGeometry()->SetSensitiveVolume("S10G");
1114 }
1115
1116 //______________________________________________________________________________
1117 Int_t  AliMUONSlatGeometryBuilder::ConvertSlatNum(Int_t numslat, Int_t quadnum, Int_t fspq) const
1118 {
1119 // On-line function establishing the correspondance between numslat (the slat number on a particular quadrant (numslat->0....4 for St3))
1120 // and slatnum (the slat number on the whole panel (slatnum->1...18 for St3)
1121   numslat += 1;
1122   if (quadnum==2 || quadnum==3) 
1123     numslat += fspq;
1124   else
1125     numslat = fspq + 2-numslat;
1126   numslat -= 1;
1127               
1128   if (quadnum==3 || quadnum==4) numslat += 2*fspq+1;
1129
1130   return numslat;
1131 }