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