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