New version of geometry for stations 3-5 "Slats" (A. de Falco)
[u/mrichter/AliRoot.git] / MUON / AliMUONv1.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpeateose. It is      *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.16  2000/11/08 13:01:40  morsch
19 Chamber half-planes of stations 3-5 at different z-positions.
20
21 Revision 1.15  2000/11/06 11:39:02  morsch
22 Bug in StepManager() corrected.
23
24 Revision 1.14  2000/11/06 09:16:50  morsch
25 Avoid overlap of slat volumes.
26
27 Revision 1.13  2000/10/26 07:33:44  morsch
28 Correct x-position of slats in station 5.
29
30 Revision 1.12  2000/10/25 19:55:35  morsch
31 Switches for each station individually for debug and lego.
32
33 Revision 1.11  2000/10/22 16:44:01  morsch
34 Update of slat geometry for stations 3,4,5 (A. deFalco)
35
36 Revision 1.10  2000/10/12 16:07:04  gosset
37 StepManager:
38 * SigGenCond only called for tracking chambers,
39   hence no more division by 0,
40   and may use last ALIROOT/dummies.C with exception handling;
41 * "10" replaced by "AliMUONConstants::NTrackingCh()".
42
43 Revision 1.9  2000/10/06 15:37:22  morsch
44 Problems with variable redefinition in for-loop solved.
45 Variable names starting with u-case letters changed to l-case.
46
47 Revision 1.8  2000/10/06 09:06:31  morsch
48 Include Slat chambers (stations 3-5) into geometry (A. de Falco)
49
50 Revision 1.7  2000/10/02 21:28:09  fca
51 Removal of useless dependecies via forward declarations
52
53 Revision 1.6  2000/10/02 17:20:45  egangler
54 Cleaning of the code (continued ) :
55 -> coding conventions
56 -> void Streamers
57 -> some useless includes removed or replaced by "class" statement
58
59 Revision 1.5  2000/06/28 15:16:35  morsch
60 (1) Client code adapted to new method signatures in AliMUONSegmentation (see comments there)
61 to allow development of slat-muon chamber simulation and reconstruction code in the MUON
62 framework. The changes should have no side effects (mostly dummy arguments).
63 (2) Hit disintegration uses 3-dim hit coordinates to allow simulation
64 of chambers with overlapping modules (MakePadHits, Disintegration).
65
66 Revision 1.4  2000/06/26 14:02:38  morsch
67 Add class AliMUONConstants with MUON specific constants using static memeber data and access methods.
68
69 Revision 1.3  2000/06/22 14:10:05  morsch
70 HP scope problems corrected (PH)
71
72 Revision 1.2  2000/06/15 07:58:49  morsch
73 Code from MUON-dev joined
74
75 Revision 1.1.2.14  2000/06/14 14:37:25  morsch
76 Initialization of TriggerCircuit added (PC)
77
78 Revision 1.1.2.13  2000/06/09 21:55:47  morsch
79 Most coding rule violations corrected.
80
81 Revision 1.1.2.12  2000/05/05 11:34:29  morsch
82 Log inside comments.
83
84 Revision 1.1.2.11  2000/05/05 10:06:48  morsch
85 Coding Rule violations regarding trigger section corrected (CP)
86 Log messages included.
87 */
88
89 /////////////////////////////////////////////////////////
90 //  Manager and hits classes for set:MUON version 0    //
91 /////////////////////////////////////////////////////////
92
93 #include <TTUBE.h>
94 #include <TNode.h> 
95 #include <TRandom.h> 
96 #include <TLorentzVector.h> 
97 #include <iostream.h>
98
99 #include "AliMUONv1.h"
100 #include "AliRun.h"
101 #include "AliMC.h"
102 #include "AliMagF.h"
103 #include "AliCallf77.h"
104 #include "AliConst.h" 
105 #include "AliMUONChamber.h"
106 #include "AliMUONHit.h"
107 #include "AliMUONPadHit.h"
108 #include "AliMUONConstants.h"
109 #include "AliMUONTriggerCircuit.h"
110
111 ClassImp(AliMUONv1)
112  
113 //___________________________________________
114 AliMUONv1::AliMUONv1() : AliMUON()
115 {
116 // Constructor
117     fChambers = 0;
118 }
119  
120 //___________________________________________
121 AliMUONv1::AliMUONv1(const char *name, const char *title)
122        : AliMUON(name,title)
123 {
124 // Constructor
125 }
126
127 //___________________________________________
128 void AliMUONv1::CreateGeometry()
129 {
130 //
131 //   Note: all chambers have the same structure, which could be 
132 //   easily parameterised. This was intentionally not done in order
133 //   to give a starting point for the implementation of the actual 
134 //   design of each station. 
135   Int_t *idtmed = fIdtmed->GetArray()-1099;
136
137 //   Distance between Stations
138 //
139      Float_t bpar[3];
140      Float_t tpar[3];
141      Float_t pgpar[10];
142      Float_t zpos1, zpos2, zfpos;
143      Float_t dframep=.001; // Value for station 3 should be 6 ...
144      Float_t dframep1=.001;
145 //     Bool_t frames=kTRUE;
146      Bool_t frames=kFALSE;     
147      
148      Float_t dframez=0.9;
149      Float_t dr;
150      Float_t dstation;
151
152 //
153 //   Rotation matrices in the x-y plane  
154      Int_t idrotm[1199];
155 //   phi=   0 deg
156      AliMatrix(idrotm[1100],  90.,   0., 90.,  90., 0., 0.);
157 //   phi=  90 deg
158      AliMatrix(idrotm[1101],  90.,  90., 90., 180., 0., 0.);
159 //   phi= 180 deg
160      AliMatrix(idrotm[1102],  90., 180., 90., 270., 0., 0.);
161 //   phi= 270 deg
162      AliMatrix(idrotm[1103],  90., 270., 90.,   0., 0., 0.);
163 //
164      Float_t phi=2*TMath::Pi()/12/2;
165
166 //
167 //   pointer to the current chamber
168 //   pointer to the current chamber
169      Int_t idAlu1=idtmed[1103];
170      Int_t idAlu2=idtmed[1104];
171 //     Int_t idAlu1=idtmed[1100];
172 //     Int_t idAlu2=idtmed[1100];
173      Int_t idAir=idtmed[1100];
174      Int_t idGas=idtmed[1105];
175      
176
177      AliMUONChamber *iChamber, *iChamber1, *iChamber2;
178      Int_t stations[5] = {1, 1, 1, 1, 1};
179      
180      if (stations[0]) {
181          
182 //********************************************************************
183 //                            Station 1                             **
184 //********************************************************************
185 //  CONCENTRIC
186      // indices 1 and 2 for first and second chambers in the station
187      // iChamber (first chamber) kept for other quanties than Z,
188      // assumed to be the same in both chambers
189      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[0];
190      iChamber2 =(AliMUONChamber*) (*fChambers)[1];
191      zpos1=iChamber1->Z(); 
192      zpos2=iChamber2->Z();
193      dstation = zpos2 - zpos1;
194      zfpos=-(iChamber->DGas()+dframez+iChamber->DAlu())/2;
195      
196 //
197 //   Mother volume
198      tpar[0] = iChamber->RInner()-dframep1; 
199      tpar[1] = (iChamber->ROuter()+dframep1)/TMath::Cos(phi);
200      tpar[2] = dstation/5;
201
202      gMC->Gsvolu("C01M", "TUBE", idAir, tpar, 3);
203      gMC->Gsvolu("C02M", "TUBE", idAir, tpar, 3);
204      gMC->Gspos("C01M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
205      gMC->Gspos("C02M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");     
206 // Aluminium frames
207 // Outer frames
208      pgpar[0] = 360/12/2;
209      pgpar[1] = 360.;
210      pgpar[2] = 12.;
211      pgpar[3] =   2;
212      pgpar[4] = -dframez/2;
213      pgpar[5] = iChamber->ROuter();
214      pgpar[6] = pgpar[5]+dframep1;
215      pgpar[7] = +dframez/2;
216      pgpar[8] = pgpar[5];
217      pgpar[9] = pgpar[6];
218      gMC->Gsvolu("C01O", "PGON", idAlu1, pgpar, 10);
219      gMC->Gsvolu("C02O", "PGON", idAlu1, pgpar, 10);
220      gMC->Gspos("C01O",1,"C01M", 0.,0.,-zfpos,  0,"ONLY");
221      gMC->Gspos("C01O",2,"C01M", 0.,0.,+zfpos,  0,"ONLY");
222      gMC->Gspos("C02O",1,"C02M", 0.,0.,-zfpos,  0,"ONLY");
223      gMC->Gspos("C02O",2,"C02M", 0.,0.,+zfpos,  0,"ONLY");
224 //
225 // Inner frame
226      tpar[0]= iChamber->RInner()-dframep1;
227      tpar[1]= iChamber->RInner();
228      tpar[2]= dframez/2;
229      gMC->Gsvolu("C01I", "TUBE", idAlu1, tpar, 3);
230      gMC->Gsvolu("C02I", "TUBE", idAlu1, tpar, 3);
231
232      gMC->Gspos("C01I",1,"C01M", 0.,0.,-zfpos,  0,"ONLY");
233      gMC->Gspos("C01I",2,"C01M", 0.,0.,+zfpos,  0,"ONLY");
234      gMC->Gspos("C02I",1,"C02M", 0.,0.,-zfpos,  0,"ONLY");
235      gMC->Gspos("C02I",2,"C02M", 0.,0.,+zfpos,  0,"ONLY");
236 //
237 // Frame Crosses
238      if (frames) {
239
240          bpar[0] = (iChamber->ROuter() - iChamber->RInner())/2;
241          bpar[1] = dframep1/2;
242          bpar[2] = dframez/2;
243          gMC->Gsvolu("C01B", "BOX", idAlu1, bpar, 3);
244          gMC->Gsvolu("C02B", "BOX", idAlu1, bpar, 3);
245          
246          gMC->Gspos("C01B",1,"C01M", +iChamber->RInner()+bpar[0] , 0,-zfpos, 
247                     idrotm[1100],"ONLY");
248          gMC->Gspos("C01B",2,"C01M", -iChamber->RInner()-bpar[0] , 0,-zfpos, 
249                     idrotm[1100],"ONLY");
250          gMC->Gspos("C01B",3,"C01M", 0, +iChamber->RInner()+bpar[0] ,-zfpos, 
251                     idrotm[1101],"ONLY");
252          gMC->Gspos("C01B",4,"C01M", 0, -iChamber->RInner()-bpar[0] ,-zfpos, 
253                     idrotm[1101],"ONLY");
254          gMC->Gspos("C01B",5,"C01M", +iChamber->RInner()+bpar[0] , 0,+zfpos, 
255                     idrotm[1100],"ONLY");
256          gMC->Gspos("C01B",6,"C01M", -iChamber->RInner()-bpar[0] , 0,+zfpos, 
257                     idrotm[1100],"ONLY");
258          gMC->Gspos("C01B",7,"C01M", 0, +iChamber->RInner()+bpar[0] ,+zfpos, 
259                     idrotm[1101],"ONLY");
260          gMC->Gspos("C01B",8,"C01M", 0, -iChamber->RInner()-bpar[0] ,+zfpos, 
261                     idrotm[1101],"ONLY");
262          
263          gMC->Gspos("C02B",1,"C02M", +iChamber->RInner()+bpar[0] , 0,-zfpos, 
264                     idrotm[1100],"ONLY");
265          gMC->Gspos("C02B",2,"C02M", -iChamber->RInner()-bpar[0] , 0,-zfpos, 
266                     idrotm[1100],"ONLY");
267          gMC->Gspos("C02B",3,"C02M", 0, +iChamber->RInner()+bpar[0] ,-zfpos, 
268                     idrotm[1101],"ONLY");
269          gMC->Gspos("C02B",4,"C02M", 0, -iChamber->RInner()-bpar[0] ,-zfpos, 
270                     idrotm[1101],"ONLY");
271          gMC->Gspos("C02B",5,"C02M", +iChamber->RInner()+bpar[0] , 0,+zfpos, 
272                     idrotm[1100],"ONLY");
273          gMC->Gspos("C02B",6,"C02M", -iChamber->RInner()-bpar[0] , 0,+zfpos, 
274                     idrotm[1100],"ONLY");
275          gMC->Gspos("C02B",7,"C02M", 0, +iChamber->RInner()+bpar[0] ,+zfpos, 
276                     idrotm[1101],"ONLY");
277          gMC->Gspos("C02B",8,"C02M", 0, -iChamber->RInner()-bpar[0] ,+zfpos, 
278                     idrotm[1101],"ONLY");
279      }
280 //
281 //   Chamber Material represented by Alu sheet
282      tpar[0]= iChamber->RInner();
283      tpar[1]= iChamber->ROuter();
284      tpar[2] = (iChamber->DGas()+iChamber->DAlu())/2;
285      gMC->Gsvolu("C01A", "TUBE",  idAlu2, tpar, 3);
286      gMC->Gsvolu("C02A", "TUBE",idAlu2, tpar, 3);
287      gMC->Gspos("C01A", 1, "C01M", 0., 0., 0.,  0, "ONLY");
288      gMC->Gspos("C02A", 1, "C02M", 0., 0., 0.,  0, "ONLY");
289 //     
290 //   Sensitive volumes
291      // tpar[2] = iChamber->DGas();
292      tpar[2] = iChamber->DGas()/2;
293      gMC->Gsvolu("C01G", "TUBE", idtmed[1108], tpar, 3);
294      gMC->Gsvolu("C02G", "TUBE", idtmed[1108], tpar, 3);
295      gMC->Gspos("C01G", 1, "C01A", 0., 0., 0.,  0, "ONLY");
296      gMC->Gspos("C02G", 1, "C02A", 0., 0., 0.,  0, "ONLY");
297 //
298 // Frame Crosses to be placed inside gas 
299      if (frames) {
300
301          dr = (iChamber->ROuter() - iChamber->RInner());
302          bpar[0] = TMath::Sqrt(dr*dr-dframep1*dframep1/4)/2;
303          bpar[1] = dframep1/2;
304          bpar[2] = iChamber->DGas()/2;
305          gMC->Gsvolu("C01F", "BOX", idAlu1, bpar, 3);
306          gMC->Gsvolu("C02F", "BOX", idAlu1, bpar, 3);
307          
308          gMC->Gspos("C01F",1,"C01G", +iChamber->RInner()+bpar[0] , 0, 0, 
309                     idrotm[1100],"ONLY");
310          gMC->Gspos("C01F",2,"C01G", -iChamber->RInner()-bpar[0] , 0, 0, 
311                     idrotm[1100],"ONLY");
312          gMC->Gspos("C01F",3,"C01G", 0, +iChamber->RInner()+bpar[0] , 0, 
313                     idrotm[1101],"ONLY");
314          gMC->Gspos("C01F",4,"C01G", 0, -iChamber->RInner()-bpar[0] , 0, 
315                     idrotm[1101],"ONLY");
316          
317          gMC->Gspos("C02F",1,"C02G", +iChamber->RInner()+bpar[0] , 0, 0, 
318                     idrotm[1100],"ONLY");
319          gMC->Gspos("C02F",2,"C02G", -iChamber->RInner()-bpar[0] , 0, 0, 
320                     idrotm[1100],"ONLY");
321          gMC->Gspos("C02F",3,"C02G", 0, +iChamber->RInner()+bpar[0] , 0, 
322                     idrotm[1101],"ONLY");
323          gMC->Gspos("C02F",4,"C02G", 0, -iChamber->RInner()-bpar[0] , 0, 
324                     idrotm[1101],"ONLY");
325      }
326      }
327      if (stations[1]) {
328          
329 //********************************************************************
330 //                            Station 2                             **
331 //********************************************************************
332      // indices 1 and 2 for first and second chambers in the station
333      // iChamber (first chamber) kept for other quanties than Z,
334      // assumed to be the same in both chambers
335      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[2];
336      iChamber2 =(AliMUONChamber*) (*fChambers)[3];
337      zpos1=iChamber1->Z(); 
338      zpos2=iChamber2->Z();
339      dstation = zpos2 - zpos1;
340      zfpos=-(iChamber->DGas()+dframez+iChamber->DAlu())/2;
341      
342 //
343 //   Mother volume
344      tpar[0] = iChamber->RInner()-dframep; 
345      tpar[1] = (iChamber->ROuter()+dframep)/TMath::Cos(phi);
346      tpar[2] = dstation/5;
347
348      gMC->Gsvolu("C03M", "TUBE", idAir, tpar, 3);
349      gMC->Gsvolu("C04M", "TUBE", idAir, tpar, 3);
350      gMC->Gspos("C03M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
351      gMC->Gspos("C04M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");
352
353 // Aluminium frames
354 // Outer frames
355      pgpar[0] = 360/12/2;
356      pgpar[1] = 360.;
357      pgpar[2] = 12.;
358      pgpar[3] =   2;
359      pgpar[4] = -dframez/2;
360      pgpar[5] = iChamber->ROuter();
361      pgpar[6] = pgpar[5]+dframep;
362      pgpar[7] = +dframez/2;
363      pgpar[8] = pgpar[5];
364      pgpar[9] = pgpar[6];
365      gMC->Gsvolu("C03O", "PGON", idAlu1, pgpar, 10);
366      gMC->Gsvolu("C04O", "PGON", idAlu1, pgpar, 10);
367      gMC->Gspos("C03O",1,"C03M", 0.,0.,-zfpos,  0,"ONLY");
368      gMC->Gspos("C03O",2,"C03M", 0.,0.,+zfpos,  0,"ONLY");
369      gMC->Gspos("C04O",1,"C04M", 0.,0.,-zfpos,  0,"ONLY");
370      gMC->Gspos("C04O",2,"C04M", 0.,0.,+zfpos,  0,"ONLY");
371 //
372 // Inner frame
373      tpar[0]= iChamber->RInner()-dframep;
374      tpar[1]= iChamber->RInner();
375      tpar[2]= dframez/2;
376      gMC->Gsvolu("C03I", "TUBE", idAlu1, tpar, 3);
377      gMC->Gsvolu("C04I", "TUBE", idAlu1, tpar, 3);
378
379      gMC->Gspos("C03I",1,"C03M", 0.,0.,-zfpos,  0,"ONLY");
380      gMC->Gspos("C03I",2,"C03M", 0.,0.,+zfpos,  0,"ONLY");
381      gMC->Gspos("C04I",1,"C04M", 0.,0.,-zfpos,  0,"ONLY");
382      gMC->Gspos("C04I",2,"C04M", 0.,0.,+zfpos,  0,"ONLY");
383 //
384 // Frame Crosses
385      if (frames) {
386
387          bpar[0] = (iChamber->ROuter() - iChamber->RInner())/2;
388          bpar[1] = dframep/2;
389          bpar[2] = dframez/2;
390          gMC->Gsvolu("C03B", "BOX", idAlu1, bpar, 3);
391          gMC->Gsvolu("C04B", "BOX", idAlu1, bpar, 3);
392          
393          gMC->Gspos("C03B",1,"C03M", +iChamber->RInner()+bpar[0] , 0,-zfpos, 
394                     idrotm[1100],"ONLY");
395          gMC->Gspos("C03B",2,"C03M", -iChamber->RInner()-bpar[0] , 0,-zfpos, 
396                     idrotm[1100],"ONLY");
397          gMC->Gspos("C03B",3,"C03M", 0, +iChamber->RInner()+bpar[0] ,-zfpos, 
398                     idrotm[1101],"ONLY");
399          gMC->Gspos("C03B",4,"C03M", 0, -iChamber->RInner()-bpar[0] ,-zfpos, 
400                     idrotm[1101],"ONLY");
401          gMC->Gspos("C03B",5,"C03M", +iChamber->RInner()+bpar[0] , 0,+zfpos, 
402                     idrotm[1100],"ONLY");
403          gMC->Gspos("C03B",6,"C03M", -iChamber->RInner()-bpar[0] , 0,+zfpos, 
404                     idrotm[1100],"ONLY");
405          gMC->Gspos("C03B",7,"C03M", 0, +iChamber->RInner()+bpar[0] ,+zfpos, 
406                     idrotm[1101],"ONLY");
407          gMC->Gspos("C03B",8,"C03M", 0, -iChamber->RInner()-bpar[0] ,+zfpos, 
408                     idrotm[1101],"ONLY");
409          
410          gMC->Gspos("C04B",1,"C04M", +iChamber->RInner()+bpar[0] , 0,-zfpos, 
411                     idrotm[1100],"ONLY");
412          gMC->Gspos("C04B",2,"C04M", -iChamber->RInner()-bpar[0] , 0,-zfpos, 
413                     idrotm[1100],"ONLY");
414          gMC->Gspos("C04B",3,"C04M", 0, +iChamber->RInner()+bpar[0] ,-zfpos, 
415                     idrotm[1101],"ONLY");
416          gMC->Gspos("C04B",4,"C04M", 0, -iChamber->RInner()-bpar[0] ,-zfpos, 
417                     idrotm[1101],"ONLY");
418          gMC->Gspos("C04B",5,"C04M", +iChamber->RInner()+bpar[0] , 0,+zfpos, 
419                     idrotm[1100],"ONLY");
420          gMC->Gspos("C04B",6,"C04M", -iChamber->RInner()-bpar[0] , 0,+zfpos, 
421                     idrotm[1100],"ONLY");
422          gMC->Gspos("C04B",7,"C04M", 0, +iChamber->RInner()+bpar[0] ,+zfpos, 
423                     idrotm[1101],"ONLY");
424          gMC->Gspos("C04B",8,"C04M", 0, -iChamber->RInner()-bpar[0] ,+zfpos, 
425                     idrotm[1101],"ONLY");
426      }
427 //
428 //   Chamber Material represented by Alu sheet
429      tpar[0]= iChamber->RInner();
430      tpar[1]= iChamber->ROuter();
431      tpar[2] = (iChamber->DGas()+iChamber->DAlu())/2;
432      gMC->Gsvolu("C03A", "TUBE", idAlu2, tpar, 3);
433      gMC->Gsvolu("C04A", "TUBE", idAlu2, tpar, 3);
434      gMC->Gspos("C03A", 1, "C03M", 0., 0., 0.,  0, "ONLY");
435      gMC->Gspos("C04A", 1, "C04M", 0., 0., 0.,  0, "ONLY");
436 //     
437 //   Sensitive volumes
438      // tpar[2] = iChamber->DGas();
439      tpar[2] = iChamber->DGas()/2;
440      gMC->Gsvolu("C03G", "TUBE", idGas, tpar, 3);
441      gMC->Gsvolu("C04G", "TUBE", idGas, tpar, 3);
442      gMC->Gspos("C03G", 1, "C03A", 0., 0., 0.,  0, "ONLY");
443      gMC->Gspos("C04G", 1, "C04A", 0., 0., 0.,  0, "ONLY");
444
445      if (frames) {
446 //
447 // Frame Crosses to be placed inside gas 
448          dr = (iChamber->ROuter() - iChamber->RInner());
449          bpar[0] = TMath::Sqrt(dr*dr-dframep*dframep/4)/2;
450          bpar[1] = dframep/2;
451          bpar[2] = iChamber->DGas()/2;
452          gMC->Gsvolu("C03F", "BOX", idAlu1, bpar, 3);
453          gMC->Gsvolu("C04F", "BOX", idAlu1, bpar, 3);
454          
455          gMC->Gspos("C03F",1,"C03G", +iChamber->RInner()+bpar[0] , 0, 0, 
456                     idrotm[1100],"ONLY");
457          gMC->Gspos("C03F",2,"C03G", -iChamber->RInner()-bpar[0] , 0, 0, 
458                     idrotm[1100],"ONLY");
459          gMC->Gspos("C03F",3,"C03G", 0, +iChamber->RInner()+bpar[0] , 0, 
460                     idrotm[1101],"ONLY");
461          gMC->Gspos("C03F",4,"C03G", 0, -iChamber->RInner()-bpar[0] , 0, 
462                     idrotm[1101],"ONLY");
463          
464          gMC->Gspos("C04F",1,"C04G", +iChamber->RInner()+bpar[0] , 0, 0, 
465                     idrotm[1100],"ONLY");
466          gMC->Gspos("C04F",2,"C04G", -iChamber->RInner()-bpar[0] , 0, 0, 
467                     idrotm[1100],"ONLY");
468          gMC->Gspos("C04F",3,"C04G", 0, +iChamber->RInner()+bpar[0] , 0, 
469                     idrotm[1101],"ONLY");
470          gMC->Gspos("C04F",4,"C04G", 0, -iChamber->RInner()-bpar[0] , 0, 
471                     idrotm[1101],"ONLY");
472      }
473      }
474      // define the id of tracking media:
475      Int_t idCopper = idtmed[1110];
476      Int_t idGlass  = idtmed[1111];
477      Int_t idCarbon = idtmed[1112];
478      Int_t idRoha   = idtmed[1113];
479
480       // sensitive area: 40*40 cm**2
481      const Float_t sensLength = 40.; 
482      const Float_t sensHeight = 40.; 
483      const Float_t sensWidth  = 0.5; // according to TDR fig 2.120 
484      const Int_t sensMaterial = idGas;
485      const Float_t yOverlap   = 1.5; 
486
487      // PCB dimensions in cm; width: 30 mum copper   
488      const Float_t pcbLength  = sensLength; 
489      const Float_t pcbHeight  = 60.; 
490      const Float_t pcbWidth   = 0.003;   
491      const Int_t pcbMaterial  = idCopper;
492
493      // Insulating material: 200 mum glass fiber glued to pcb  
494      const Float_t insuLength = pcbLength; 
495      const Float_t insuHeight = pcbHeight; 
496      const Float_t insuWidth  = 0.020;   
497      const Int_t insuMaterial = idGlass;
498
499      // Carbon fiber panels: 200mum carbon/epoxy skin   
500      const Float_t panelLength = sensLength; 
501      const Float_t panelHeight = sensHeight; 
502      const Float_t panelWidth  = 0.020;      
503      const Int_t panelMaterial = idCarbon;
504
505      // rohacell between the two carbon panels   
506      const Float_t rohaLength = sensLength; 
507      const Float_t rohaHeight = sensHeight; 
508      const Float_t rohaWidth  = 0.5;
509      const Int_t rohaMaterial = idRoha;
510
511      // Frame around the slat: 2 sticks along length,2 along height  
512      // H: the horizontal ones 
513      const Float_t hFrameLength = pcbLength; 
514      const Float_t hFrameHeight = 1.5; 
515      const Float_t hFrameWidth  = sensWidth; 
516      const Int_t hFrameMaterial = idGlass;
517
518      // V: the vertical ones 
519      const Float_t vFrameLength = 4.0; 
520      const Float_t vFrameHeight = sensHeight + hFrameHeight; 
521      const Float_t vFrameWidth  = sensWidth;
522      const Int_t vFrameMaterial = idGlass;
523
524      // B: the horizontal border filled with rohacell 
525      const Float_t bFrameLength = hFrameLength; 
526      const Float_t bFrameHeight = (pcbHeight - sensHeight)/2. - hFrameHeight; 
527      const Float_t bFrameWidth  = hFrameWidth;
528      const Int_t bFrameMaterial = idRoha;
529
530      // NULOC: 30 mum copper + 200 mum vetronite (same radiation length as 14mum copper)
531      const Float_t nulocLength = 2.5; 
532      const Float_t nulocHeight = 7.5; 
533      const Float_t nulocWidth  = 0.0030 + 0.0014; // equivalent copper width of vetronite; 
534      const Int_t   nulocMaterial = idCopper;
535
536      const Float_t slatHeight = pcbHeight; 
537      const Float_t slatWidth = sensWidth + 2.*(pcbWidth + insuWidth + 
538                                                2.* panelWidth + rohaWidth);
539      const Int_t slatMaterial = idAir;
540      const Float_t dSlatLength = vFrameLength; // border on left and right 
541
542      Float_t spar[3];  
543      Int_t i, j;
544
545      // the panel volume contains the rohacell
546
547      Float_t twidth = 2 * panelWidth + rohaWidth; 
548      Float_t panelpar[3] = { panelLength/2., panelHeight/2., twidth/2. }; 
549      Float_t rohapar[3] = { rohaLength/2., rohaHeight/2., rohaWidth/2. }; 
550
551      // insulating material contains PCB-> gas-> 2 borders filled with rohacell
552
553      twidth = 2*(insuWidth + pcbWidth) + sensWidth;  
554      Float_t insupar[3] = { insuLength/2., insuHeight/2., twidth/2. }; 
555      twidth -= 2 * insuWidth; 
556      Float_t pcbpar[3] = { pcbLength/2., pcbHeight/2., twidth/2. }; 
557      Float_t senspar[3] = { sensLength/2., sensHeight/2., sensWidth/2. }; 
558      Float_t theight = 2*hFrameHeight + sensHeight;
559      Float_t hFramepar[3]={hFrameLength/2., theight/2., hFrameWidth/2.}; 
560      Float_t bFramepar[3]={bFrameLength/2., bFrameHeight/2., bFrameWidth/2.}; 
561      Float_t vFramepar[3]={vFrameLength/2., vFrameHeight/2., vFrameWidth/2.}; 
562      Float_t nulocpar[3]={nulocLength/2., nulocHeight/2., nulocWidth/2.}; 
563      Float_t xx;
564      Float_t xxmax = (bFrameLength - nulocLength)/2.; 
565      Int_t index=0;
566      
567      if (stations[2]) {
568          
569 //********************************************************************
570 //                            Station 3                             **
571 //********************************************************************
572      // indices 1 and 2 for first and second chambers in the station
573      // iChamber (first chamber) kept for other quanties than Z,
574      // assumed to be the same in both chambers
575      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[4];
576      iChamber2 =(AliMUONChamber*) (*fChambers)[5];
577      zpos1=iChamber1->Z(); 
578      zpos2=iChamber2->Z();
579      dstation = zpos2 - zpos1;
580
581      zfpos=-(iChamber->DGas()+dframez+iChamber->DAlu())/2;
582 //
583 //   Mother volume
584      tpar[0] = iChamber->RInner()-dframep; 
585      tpar[1] = (iChamber->ROuter()+dframep)/TMath::Cos(phi);
586      tpar[2] = dstation/4;
587      gMC->Gsvolu("C05M", "TUBE", idAir, tpar, 3);
588      gMC->Gsvolu("C06M", "TUBE", idAir, tpar, 3);
589      gMC->Gspos("C05M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
590      gMC->Gspos("C06M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");
591  
592      // volumes for slat geometry (xx=5,..,10 chamber id): 
593      // Sxx0 Sxx1 Sxx2 Sxx3  -->   Slat Mother volumes 
594      // SxxG                          -->   Sensitive volume (gas)
595      // SxxP                          -->   PCB (copper) 
596      // SxxI                          -->   Insulator (vetronite) 
597      // SxxC                          -->   Carbon panel 
598      // SxxR                          -->   Rohacell
599      // SxxH, SxxV                    -->   Horizontal and Vertical frames (vetronite)
600
601      // slat dimensions: slat is a MOTHER volume!!! made of air
602
603
604      const Int_t nSlats3 = 4;  // number of slats per quadrant
605      const Int_t nPCB3[nSlats3] = {3,4,3,2}; // n PCB per slat
606      Float_t slatLength3[nSlats3]; 
607
608      // create and position the slat (mother) volumes 
609
610      char volNam5[5];
611      char volNam6[5];
612      Float_t xSlat3;
613
614      for (i = 0; i<nSlats3; i++){
615        slatLength3[i] = pcbLength * nPCB3[i] + 2. * dSlatLength; 
616        xSlat3 = slatLength3[i]/2. - vFrameLength/2.; 
617
618        if (i==0) { 
619          xSlat3 += 40.;
620          slatLength3[i] -= 2. *dSlatLength; 
621        }
622        Float_t ySlat31 =  sensHeight * (i+0.5) - yOverlap * i - yOverlap/2.; 
623        Float_t ySlat32 = -sensHeight * (i+0.5) + yOverlap * i + yOverlap/2.; 
624        spar[0] = slatLength3[i]/2.; 
625        spar[1] = slatHeight/2.;
626        spar[2] = slatWidth/2. * 1.01; 
627        Float_t dzCh3=spar[2] * 1.01;
628        // zSlat to be checked (odd downstream or upstream?)
629        Float_t zSlat = (i%2 ==0)? -spar[2] : spar[2]; 
630        sprintf(volNam5,"S05%d",i);
631        gMC->Gsvolu(volNam5,"BOX",slatMaterial,spar,3);
632        gMC->Gspos(volNam5, i*4+1,"C05M", xSlat3, ySlat31, zSlat+2.*dzCh3, 0, "ONLY");
633        gMC->Gspos(volNam5, i*4+2,"C05M",-xSlat3, ySlat31, zSlat-2.*dzCh3, 0, "ONLY");
634        gMC->Gspos(volNam5, i*4+3,"C05M", xSlat3, ySlat32,-zSlat+2.*dzCh3, 0, "ONLY");
635        gMC->Gspos(volNam5, i*4+4,"C05M",-xSlat3, ySlat32,-zSlat-2.*dzCh3, 0, "ONLY");
636        sprintf(volNam6,"S06%d",i);
637        gMC->Gsvolu(volNam6,"BOX",slatMaterial,spar,3);
638        gMC->Gspos(volNam6, i*4+1,"C06M", xSlat3, ySlat31, zSlat+2.*dzCh3, 0, "ONLY");
639        gMC->Gspos(volNam6, i*4+2,"C06M",-xSlat3, ySlat31, zSlat-2.*dzCh3, 0, "ONLY");
640        gMC->Gspos(volNam6, i*4+3,"C06M", xSlat3, ySlat32,-zSlat+2.*dzCh3, 0, "ONLY");
641        gMC->Gspos(volNam6, i*4+4,"C06M",-xSlat3, ySlat32,-zSlat-2.*dzCh3, 0, "ONLY");
642        // 1st pcb in 1st slat made by some rectangular divisions
643
644      }
645
646      // create the panel volume 
647  
648      gMC->Gsvolu("S05C","BOX",panelMaterial,panelpar,3);
649      gMC->Gsvolu("S06C","BOX",panelMaterial,panelpar,3);
650
651      // create the rohacell volume 
652
653      gMC->Gsvolu("S05R","BOX",rohaMaterial,rohapar,3);
654      gMC->Gsvolu("S06R","BOX",rohaMaterial,rohapar,3);
655
656      // create the insulating material volume 
657
658      gMC->Gsvolu("S05I","BOX",insuMaterial,insupar,3);
659      gMC->Gsvolu("S06I","BOX",insuMaterial,insupar,3);
660
661      // create the PCB volume 
662
663      gMC->Gsvolu("S05P","BOX",pcbMaterial,pcbpar,3);
664      gMC->Gsvolu("S06P","BOX",pcbMaterial,pcbpar,3);
665  
666      // create the sensitive volumes,
667      gMC->Gsvolu("S05G","BOX",sensMaterial,0,0);
668      gMC->Gsvolu("S06G","BOX",sensMaterial,0,0);
669
670
671      // create the vertical frame volume 
672
673      gMC->Gsvolu("S05V","BOX",vFrameMaterial,vFramepar,3);
674      gMC->Gsvolu("S06V","BOX",vFrameMaterial,vFramepar,3);
675
676      // create the horizontal frame volume 
677
678      gMC->Gsvolu("S05H","BOX",hFrameMaterial,hFramepar,3);
679      gMC->Gsvolu("S06H","BOX",hFrameMaterial,hFramepar,3);
680
681      // create the horizontal border volume 
682
683      gMC->Gsvolu("S05B","BOX",bFrameMaterial,bFramepar,3);
684      gMC->Gsvolu("S06B","BOX",bFrameMaterial,bFramepar,3);
685
686      index=0; 
687      for (i = 0; i<nSlats3; i++){
688        sprintf(volNam5,"S05%d",i);
689        sprintf(volNam6,"S06%d",i);
690        Float_t xvFrame  = (slatLength3[i] - vFrameLength)/2.;
691        // position the vertical frames 
692        if (i>0) { 
693          gMC->Gspos("S05V",2*i-1,volNam5, xvFrame, 0., 0. , 0, "ONLY");
694          gMC->Gspos("S05V",2*i  ,volNam5,-xvFrame, 0., 0. , 0, "ONLY");
695          gMC->Gspos("S06V",2*i-1,volNam6, xvFrame, 0., 0. , 0, "ONLY");
696          gMC->Gspos("S06V",2*i  ,volNam6,-xvFrame, 0., 0. , 0, "ONLY");
697        }       
698        // position the panels and the insulating material 
699        for (j=0; j<nPCB3[i]; j++){
700          index++;
701          Float_t xx = sensLength * (-nPCB3[i]/2.+j+.5); 
702          
703          Float_t zPanel = spar[2] - panelpar[2]; 
704          gMC->Gspos("S05C",2*index-1,volNam5, xx, 0., zPanel , 0, "ONLY");
705          gMC->Gspos("S05C",2*index  ,volNam5, xx, 0.,-zPanel , 0, "ONLY");
706          gMC->Gspos("S06C",2*index-1,volNam6, xx, 0., zPanel , 0, "ONLY");
707          gMC->Gspos("S06C",2*index  ,volNam6, xx, 0.,-zPanel , 0, "ONLY");
708
709          gMC->Gspos("S05I",index,volNam5, xx, 0., 0 , 0, "ONLY");
710          gMC->Gspos("S06I",index,volNam6, xx, 0., 0 , 0, "ONLY");
711        } 
712      }
713
714      // position the rohacell volume inside the panel volume
715      gMC->Gspos("S05R",1,"S05C",0.,0.,0.,0,"ONLY"); 
716      gMC->Gspos("S06R",1,"S06C",0.,0.,0.,0,"ONLY"); 
717
718      // position the PCB volume inside the insulating material volume
719      gMC->Gspos("S05P",1,"S05I",0.,0.,0.,0,"ONLY"); 
720      gMC->Gspos("S06P",1,"S06I",0.,0.,0.,0,"ONLY"); 
721      // position the horizontal frame volume inside the PCB volume
722      gMC->Gspos("S05H",1,"S05P",0.,0.,0.,0,"ONLY"); 
723      gMC->Gspos("S06H",1,"S06P",0.,0.,0.,0,"ONLY"); 
724      // position the sensitive volume inside the horizontal frame volume
725      gMC->Gsposp("S05G",1,"S05H",0.,0.,0.,0,"ONLY",senspar,3); 
726      gMC->Gsposp("S06G",1,"S06H",0.,0.,0.,0,"ONLY",senspar,3); 
727      // position the border volumes inside the PCB volume
728      Float_t yborder = ( pcbHeight - bFrameHeight ) / 2.; 
729      gMC->Gspos("S05B",1,"S05P",0., yborder,0.,0,"ONLY"); 
730      gMC->Gspos("S05B",2,"S05P",0.,-yborder,0.,0,"ONLY"); 
731      gMC->Gspos("S06B",1,"S06P",0., yborder,0.,0,"ONLY"); 
732      gMC->Gspos("S06B",2,"S06P",0.,-yborder,0.,0,"ONLY"); 
733
734      // create the NULOC volume and position it in the horizontal frame
735
736      gMC->Gsvolu("S05N","BOX",nulocMaterial,nulocpar,3);
737      gMC->Gsvolu("S06N","BOX",nulocMaterial,nulocpar,3);
738      index = 0;
739      for (xx = -xxmax; xx<=xxmax; xx+=3*nulocLength) { 
740        index++; 
741        gMC->Gspos("S05N",2*index-1,"S05B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
742        gMC->Gspos("S05N",2*index  ,"S05B", xx, 0., bFrameWidth/4., 0, "ONLY");
743        gMC->Gspos("S06N",2*index-1,"S06B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
744        gMC->Gspos("S06N",2*index  ,"S06B", xx, 0., bFrameWidth/4., 0, "ONLY");
745      }
746
747      
748      // position the volumes approximating the circular section of the pipe
749      Float_t epsilon = 0.001; 
750      Int_t ndiv=6;
751      Float_t divpar[3];
752      Double_t dydiv= sensHeight/ndiv;
753      Double_t ydiv = -dydiv - yOverlap/2.;
754      Int_t imax=0; 
755      //     for (Int_t islat=0; islat<nSlats3; islat++) imax += nPCB3[islat]; 
756      imax = 1; 
757      Float_t rmin = 35.; 
758      Float_t z1 = -spar[2], z2=slatWidth; 
759      for (Int_t idiv=0;idiv<ndiv; idiv++){ 
760        ydiv+= dydiv;
761        Float_t xdiv =0; 
762        if (ydiv<rmin) xdiv= rmin * TMath::Sin( TMath::ACos(ydiv/rmin) );
763        divpar[0] = (pcbLength-xdiv)/2.; 
764        divpar[1] = dydiv/2. - epsilon;
765        divpar[2] = sensWidth/2.; 
766        Float_t xvol=(pcbLength+xdiv)/2.;
767        Float_t yvol=ydiv + dydiv/2.;
768        gMC->Gsposp("S05G",imax+4*idiv+1,"C05M", xvol, yvol, z1+z2, 0, "ONLY",divpar,3);
769        gMC->Gsposp("S06G",imax+4*idiv+1,"C06M", xvol, yvol, z1+z2, 0, "ONLY",divpar,3);
770        gMC->Gsposp("S05G",imax+4*idiv+2,"C05M", xvol,-yvol, z2-z1, 0, "ONLY",divpar,3);
771        gMC->Gsposp("S06G",imax+4*idiv+2,"C06M", xvol,-yvol, z2-z1, 0, "ONLY",divpar,3);
772        gMC->Gsposp("S05G",imax+4*idiv+3,"C05M",-xvol, yvol,-z2+z1, 0, "ONLY",divpar,3);
773        gMC->Gsposp("S06G",imax+4*idiv+3,"C06M",-xvol, yvol,-z2+z1, 0, "ONLY",divpar,3);
774        gMC->Gsposp("S05G",imax+4*idiv+4,"C05M",-xvol,-yvol,-z1-z2, 0, "ONLY",divpar,3);
775        gMC->Gsposp("S06G",imax+4*idiv+4,"C06M",-xvol,-yvol,-z1-z2, 0, "ONLY",divpar,3);
776      }
777      }
778      
779
780  if (stations[3]) {
781
782 //********************************************************************
783 //                            Station 4                             **
784 //********************************************************************
785      // indices 1 and 2 for first and second chambers in the station
786      // iChamber (first chamber) kept for other quanties than Z,
787      // assumed to be the same in both chambers
788      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[6];
789      iChamber2 =(AliMUONChamber*) (*fChambers)[7];
790      zpos1=iChamber1->Z(); 
791      zpos2=iChamber2->Z();
792      dstation = zpos2 - zpos1;
793      zfpos=-(iChamber->DGas()+dframez+iChamber->DAlu())/2;
794      
795 //
796 //   Mother volume
797      tpar[0] = iChamber->RInner()-dframep; 
798      tpar[1] = (iChamber->ROuter()+dframep)/TMath::Cos(phi);
799      tpar[2] = 3.252;
800
801      gMC->Gsvolu("C07M", "TUBE", idAir, tpar, 3);
802      gMC->Gsvolu("C08M", "TUBE", idAir, tpar, 3);
803      gMC->Gspos("C07M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
804      gMC->Gspos("C08M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");
805      
806
807      const Int_t nSlats4 = 6;  // number of slats per quadrant
808      const Int_t nPCB4[nSlats4] = {4,5,5,4,3,2}; // n PCB per slat
809
810      // slat dimensions: slat is a MOTHER volume!!! made of air
811      Float_t slatLength4[nSlats4];     
812
813      // create and position the slat (mother) volumes 
814
815      char volNam7[5];
816      char volNam8[5];
817      Float_t xSlat4;
818      Float_t ySlat4;
819
820      for (i = 0; i<nSlats4; i++){
821          slatLength4[i] = pcbLength * nPCB4[i] + 2. * dSlatLength; 
822          xSlat4 = slatLength4[i]/2. - vFrameLength/2.; 
823          if (i==0) xSlat4 += 37.5;
824          if (i==1) xSlat4 += 32;   // to be checked 
825          ySlat4 =  sensHeight * i - yOverlap *i;
826          
827          spar[0] = slatLength4[i]/2.; 
828          spar[1] = slatHeight/2.;
829          spar[2] = slatWidth/2.*1.01; 
830          Float_t dzCh4=spar[2]*1.01;
831          // zSlat to be checked (odd downstream or upstream?)
832          Float_t zSlat = (i%2 ==0)? spar[2] : -spar[2]; 
833          sprintf(volNam7,"S07%d",i);
834          gMC->Gsvolu(volNam7,"BOX",slatMaterial,spar,3);
835          gMC->Gspos(volNam7, i*4+1,"C07M", xSlat4, ySlat4, zSlat+2.*dzCh4, 0, "ONLY");
836          gMC->Gspos(volNam7, i*4+2,"C07M",-xSlat4, ySlat4, zSlat-2.*dzCh4, 0, "ONLY");
837          if (i>0) { 
838            gMC->Gspos(volNam7, i*4+3,"C07M", xSlat4,-ySlat4, zSlat+2.*dzCh4, 0, "ONLY");
839            gMC->Gspos(volNam7, i*4+4,"C07M",-xSlat4,-ySlat4, zSlat-2.*dzCh4, 0, "ONLY");
840          }
841          sprintf(volNam8,"S08%d",i);
842          gMC->Gsvolu(volNam8,"BOX",slatMaterial,spar,3);
843          gMC->Gspos(volNam8, i*4+1,"C08M", xSlat4, ySlat4, zSlat+2.*dzCh4, 0, "ONLY");
844          gMC->Gspos(volNam8, i*4+2,"C08M",-xSlat4, ySlat4, zSlat-2.*dzCh4, 0, "ONLY");
845          if (i>0) { 
846            gMC->Gspos(volNam8, i*4+3,"C08M", xSlat4,-ySlat4, zSlat+2.*dzCh4, 0, "ONLY");
847            gMC->Gspos(volNam8, i*4+4,"C08M",-xSlat4,-ySlat4, zSlat-2.*dzCh4, 0, "ONLY");
848          }
849      }
850
851
852      // create the panel volume 
853  
854      gMC->Gsvolu("S07C","BOX",panelMaterial,panelpar,3);
855      gMC->Gsvolu("S08C","BOX",panelMaterial,panelpar,3);
856
857      // create the rohacell volume 
858
859      gMC->Gsvolu("S07R","BOX",rohaMaterial,rohapar,3);
860      gMC->Gsvolu("S08R","BOX",rohaMaterial,rohapar,3);
861
862      // create the insulating material volume 
863
864      gMC->Gsvolu("S07I","BOX",insuMaterial,insupar,3);
865      gMC->Gsvolu("S08I","BOX",insuMaterial,insupar,3);
866
867      // create the PCB volume 
868
869      gMC->Gsvolu("S07P","BOX",pcbMaterial,pcbpar,3);
870      gMC->Gsvolu("S08P","BOX",pcbMaterial,pcbpar,3);
871  
872      // create the sensitive volumes,
873
874      gMC->Gsvolu("S07G","BOX",sensMaterial,0,0);
875      gMC->Gsvolu("S08G","BOX",sensMaterial,0,0);
876      //     gMC->Gsvolu("S07G","BOX",sensMaterial,senspar,3);
877      //     gMC->Gsvolu("S08G","BOX",sensMaterial,senspar,3);
878
879
880
881      // create the vertical frame volume 
882
883      gMC->Gsvolu("S07V","BOX",vFrameMaterial,vFramepar,3);
884      gMC->Gsvolu("S08V","BOX",vFrameMaterial,vFramepar,3);
885
886      // create the horizontal frame volume 
887
888      gMC->Gsvolu("S07H","BOX",hFrameMaterial,hFramepar,3);
889      gMC->Gsvolu("S08H","BOX",hFrameMaterial,hFramepar,3);
890
891      // create the horizontal border volume 
892
893      gMC->Gsvolu("S07B","BOX",bFrameMaterial,bFramepar,3);
894      gMC->Gsvolu("S08B","BOX",bFrameMaterial,bFramepar,3);
895
896      index=0; 
897      for (i = 0; i<nSlats4; i++){
898        sprintf(volNam7,"S07%d",i);
899        sprintf(volNam8,"S08%d",i);
900        Float_t xvFrame  = (slatLength4[i] - vFrameLength)/2.;
901        // position the vertical frames 
902        gMC->Gspos("S07V",2*i-1,volNam7, xvFrame, 0., 0. , 0, "ONLY");
903        gMC->Gspos("S07V",2*i  ,volNam7,-xvFrame, 0., 0. , 0, "ONLY");
904        gMC->Gspos("S08V",2*i-1,volNam8, xvFrame, 0., 0. , 0, "ONLY");
905        gMC->Gspos("S08V",2*i  ,volNam8,-xvFrame, 0., 0. , 0, "ONLY");
906        
907        // position the panels and the insulating material 
908        for (j=0; j<nPCB4[i]; j++){
909          index++;
910          Float_t xx = sensLength * (-nPCB4[i]/2.+j+.5); 
911
912          Float_t zPanel = spar[2] - panelpar[2]; 
913          gMC->Gspos("S07C",2*index-1,volNam7, xx, 0., zPanel , 0, "ONLY");
914          gMC->Gspos("S07C",2*index  ,volNam7, xx, 0.,-zPanel , 0, "ONLY");
915          gMC->Gspos("S08C",2*index-1,volNam8, xx, 0., zPanel , 0, "ONLY");
916          gMC->Gspos("S08C",2*index  ,volNam8, xx, 0.,-zPanel , 0, "ONLY");
917
918          gMC->Gspos("S07I",index,volNam7, xx, 0., 0 , 0, "ONLY");
919          gMC->Gspos("S08I",index,volNam8, xx, 0., 0 , 0, "ONLY");
920        } 
921      }
922
923      // position the rohacell volume inside the panel volume
924      gMC->Gspos("S07R",1,"S07C",0.,0.,0.,0,"ONLY"); 
925      gMC->Gspos("S08R",1,"S08C",0.,0.,0.,0,"ONLY"); 
926
927      // position the PCB volume inside the insulating material volume
928      gMC->Gspos("S07P",1,"S07I",0.,0.,0.,0,"ONLY"); 
929      gMC->Gspos("S08P",1,"S08I",0.,0.,0.,0,"ONLY"); 
930      // position the horizontal frame volume inside the PCB volume
931      gMC->Gspos("S07H",1,"S07P",0.,0.,0.,0,"ONLY"); 
932      gMC->Gspos("S08H",1,"S08P",0.,0.,0.,0,"ONLY"); 
933      // position the sensitive volume inside the horizontal frame volume
934      gMC->Gsposp("S07G",1,"S07H",0.,0.,0.,0,"ONLY",senspar,3); 
935      gMC->Gsposp("S08G",1,"S08H",0.,0.,0.,0,"ONLY",senspar,3); 
936      // gMC->Gspos("S07G",1,"S07H",0.,0.,0.,0,"ONLY"); 
937      // gMC->Gspos("S08G",1,"S08H",0.,0.,0.,0,"ONLY"); 
938      // position the border volumes inside the PCB volume
939      Float_t yborder = ( pcbHeight - bFrameHeight ) / 2.; 
940      gMC->Gspos("S07B",1,"S07P",0., yborder,0.,0,"ONLY"); 
941      gMC->Gspos("S07B",2,"S07P",0.,-yborder,0.,0,"ONLY"); 
942      gMC->Gspos("S08B",1,"S08P",0., yborder,0.,0,"ONLY"); 
943      gMC->Gspos("S08B",2,"S08P",0.,-yborder,0.,0,"ONLY"); 
944
945      // create the NULOC volume and position it in the horizontal frame
946
947      gMC->Gsvolu("S07N","BOX",nulocMaterial,nulocpar,3);
948      gMC->Gsvolu("S08N","BOX",nulocMaterial,nulocpar,3);
949      index = 0;
950      for (xx = -xxmax; xx<=xxmax; xx+=3*nulocLength) { 
951        index++; 
952        gMC->Gspos("S07N",2*index-1,"S07B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
953        gMC->Gspos("S07N",2*index  ,"S07B", xx, 0., bFrameWidth/4., 0, "ONLY");
954        gMC->Gspos("S08N",2*index-1,"S08B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
955        gMC->Gspos("S08N",2*index  ,"S08B", xx, 0., bFrameWidth/4., 0, "ONLY");
956      }
957  }
958
959  if (stations[4]) {
960      
961
962 //********************************************************************
963 //                            Station 5                             **
964 //********************************************************************
965      // indices 1 and 2 for first and second chambers in the station
966      // iChamber (first chamber) kept for other quanties than Z,
967      // assumed to be the same in both chambers
968      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[8];
969      iChamber2 =(AliMUONChamber*) (*fChambers)[9];
970      zpos1=iChamber1->Z(); 
971      zpos2=iChamber2->Z();
972      dstation = zpos2 - zpos1;
973      zfpos=-(iChamber->DGas()+dframez+iChamber->DAlu())/2;
974      
975 //
976 //   Mother volume
977      tpar[0] = iChamber->RInner()-dframep; 
978      tpar[1] = (iChamber->ROuter()+dframep)/TMath::Cos(phi);
979      tpar[2] = dstation/5.;
980
981      gMC->Gsvolu("C09M", "TUBE", idAir, tpar, 3);
982      gMC->Gsvolu("C10M", "TUBE", idAir, tpar, 3);
983      gMC->Gspos("C09M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
984      gMC->Gspos("C10M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");
985
986
987      const Int_t nSlats5 = 7;  // number of slats per quadrant
988      const Int_t nPCB5[nSlats5] = {7,7,6,6,5,4,2}; // n PCB per slat
989
990      // slat dimensions: slat is a MOTHER volume!!! made of air
991      Float_t slatLength5[nSlats5]; 
992      char volNam9[5];
993      char volNam10[5];
994      Float_t xSlat5;
995      Float_t ySlat5;
996
997      for (i = 0; i<nSlats5; i++){
998        slatLength5[i] = pcbLength * nPCB5[i] + 2. * dSlatLength; 
999        xSlat5 = slatLength5[i]/2. - vFrameLength/2.; 
1000        if (i==0) xSlat5 += 37.5;
1001        if (i==1) xSlat5 += 32;   // to be checked 
1002        ySlat5 = sensHeight * i - yOverlap * i; 
1003        spar[0] = slatLength5[i]/2.; 
1004        spar[1] = slatHeight/2.;
1005        spar[2] = slatWidth/2. * 1.01; 
1006        Float_t dzCh5=spar[2]*1.01;
1007        // zSlat to be checked (odd downstream or upstream?)
1008        Float_t zSlat = (i%2 ==0)? -spar[2] : spar[2]; 
1009        sprintf(volNam9,"S09%d",i);
1010        gMC->Gsvolu(volNam9,"BOX",slatMaterial,spar,3);
1011        gMC->Gspos(volNam9, i*4+1,"C09M", xSlat5, ySlat5, zSlat+2.*dzCh5, 0, "ONLY");
1012        gMC->Gspos(volNam9, i*4+2,"C09M",-xSlat5, ySlat5, zSlat-2.*dzCh5, 0, "ONLY");
1013        if (i>0) { 
1014            gMC->Gspos(volNam9, i*4+3,"C09M", xSlat5,-ySlat5, zSlat+2.*dzCh5, 0, "ONLY");
1015            gMC->Gspos(volNam9, i*4+4,"C09M",-xSlat5,-ySlat5, zSlat-2.*dzCh5, 0, "ONLY");
1016        }
1017        sprintf(volNam10,"S10%d",i);
1018        gMC->Gsvolu(volNam10,"BOX",slatMaterial,spar,3);
1019        gMC->Gspos(volNam10, i*4+1,"C10M", xSlat5, ySlat5, zSlat+2.*dzCh5, 0, "ONLY");
1020        gMC->Gspos(volNam10, i*4+2,"C10M",-xSlat5, ySlat5, zSlat-2.*dzCh5, 0, "ONLY");
1021        if (i>0) { 
1022            gMC->Gspos(volNam10, i*4+3,"C10M", xSlat5,-ySlat5, zSlat+2.*dzCh5, 0, "ONLY");
1023            gMC->Gspos(volNam10, i*4+4,"C10M",-xSlat5,-ySlat5, zSlat-2.*dzCh5, 0, "ONLY");
1024        }
1025      }
1026
1027      // create the panel volume 
1028  
1029      gMC->Gsvolu("S09C","BOX",panelMaterial,panelpar,3);
1030      gMC->Gsvolu("S10C","BOX",panelMaterial,panelpar,3);
1031
1032      // create the rohacell volume 
1033
1034      gMC->Gsvolu("S09R","BOX",rohaMaterial,rohapar,3);
1035      gMC->Gsvolu("S10R","BOX",rohaMaterial,rohapar,3);
1036
1037      // create the insulating material volume 
1038
1039      gMC->Gsvolu("S09I","BOX",insuMaterial,insupar,3);
1040      gMC->Gsvolu("S10I","BOX",insuMaterial,insupar,3);
1041
1042      // create the PCB volume 
1043
1044      gMC->Gsvolu("S09P","BOX",pcbMaterial,pcbpar,3);
1045      gMC->Gsvolu("S10P","BOX",pcbMaterial,pcbpar,3);
1046  
1047      // create the sensitive volumes,
1048
1049      gMC->Gsvolu("S09G","BOX",sensMaterial,0,0);
1050      gMC->Gsvolu("S10G","BOX",sensMaterial,0,0);
1051      // gMC->Gsvolu("S09G","BOX",sensMaterial,senspar,3);
1052      // gMC->Gsvolu("S10G","BOX",sensMaterial,senspar,3);
1053
1054
1055      // create the vertical frame volume 
1056
1057      gMC->Gsvolu("S09V","BOX",vFrameMaterial,vFramepar,3);
1058      gMC->Gsvolu("S10V","BOX",vFrameMaterial,vFramepar,3);
1059
1060      // create the horizontal frame volume 
1061
1062      gMC->Gsvolu("S09H","BOX",hFrameMaterial,hFramepar,3);
1063      gMC->Gsvolu("S10H","BOX",hFrameMaterial,hFramepar,3);
1064
1065      // create the horizontal border volume 
1066
1067      gMC->Gsvolu("S09B","BOX",bFrameMaterial,bFramepar,3);
1068      gMC->Gsvolu("S10B","BOX",bFrameMaterial,bFramepar,3);
1069
1070      index=0; 
1071      for (i = 0; i<nSlats5; i++){
1072        sprintf(volNam9,"S09%d",i);
1073        sprintf(volNam10,"S10%d",i);
1074        Float_t xvFrame  = (slatLength5[i] - vFrameLength)/2.;
1075        // position the vertical frames 
1076        gMC->Gspos("S09V",2*i-1,volNam9, xvFrame, 0., 0. , 0, "ONLY");
1077        gMC->Gspos("S09V",2*i  ,volNam9,-xvFrame, 0., 0. , 0, "ONLY");
1078        gMC->Gspos("S10V",2*i-1,volNam10, xvFrame, 0., 0. , 0, "ONLY");
1079        gMC->Gspos("S10V",2*i  ,volNam10,-xvFrame, 0., 0. , 0, "ONLY");
1080        
1081        // position the panels and the insulating material 
1082        for (j=0; j<nPCB5[i]; j++){
1083          index++;
1084          Float_t xx = sensLength * (-nPCB5[i]/2.+j+.5); 
1085
1086          Float_t zPanel = spar[2] - panelpar[2]; 
1087          gMC->Gspos("S09C",2*index-1,volNam9, xx, 0., zPanel , 0, "ONLY");
1088          gMC->Gspos("S09C",2*index  ,volNam9, xx, 0.,-zPanel , 0, "ONLY");
1089          gMC->Gspos("S10C",2*index-1,volNam10, xx, 0., zPanel , 0, "ONLY");
1090          gMC->Gspos("S10C",2*index  ,volNam10, xx, 0.,-zPanel , 0, "ONLY");
1091
1092          gMC->Gspos("S09I",index,volNam9, xx, 0., 0 , 0, "ONLY");
1093          gMC->Gspos("S10I",index,volNam10, xx, 0., 0 , 0, "ONLY");
1094        } 
1095      }
1096
1097      // position the rohacell volume inside the panel volume
1098      gMC->Gspos("S09R",1,"S09C",0.,0.,0.,0,"ONLY"); 
1099      gMC->Gspos("S10R",1,"S10C",0.,0.,0.,0,"ONLY"); 
1100
1101      // position the PCB volume inside the insulating material volume
1102      gMC->Gspos("S09P",1,"S09I",0.,0.,0.,0,"ONLY"); 
1103      gMC->Gspos("S10P",1,"S10I",0.,0.,0.,0,"ONLY"); 
1104      // position the horizontal frame volume inside the PCB volume
1105      gMC->Gspos("S09H",1,"S09P",0.,0.,0.,0,"ONLY"); 
1106      gMC->Gspos("S10H",1,"S10P",0.,0.,0.,0,"ONLY"); 
1107      // position the sensitive volume inside the horizontal frame volume
1108      gMC->Gsposp("S09G",1,"S09H",0.,0.,0.,0,"ONLY",senspar,3); 
1109      gMC->Gsposp("S10G",1,"S10H",0.,0.,0.,0,"ONLY",senspar,3); 
1110      // gMC->Gspos("S09G",1,"S09H",0.,0.,0.,0,"ONLY"); 
1111      // gMC->Gspos("S10G",1,"S10H",0.,0.,0.,0,"ONLY"); 
1112      // position the border volumes inside the PCB volume
1113      Float_t yborder = ( pcbHeight - bFrameHeight ) / 2.; 
1114      gMC->Gspos("S09B",1,"S09P",0., yborder,0.,0,"ONLY"); 
1115      gMC->Gspos("S09B",2,"S09P",0.,-yborder,0.,0,"ONLY"); 
1116      gMC->Gspos("S10B",1,"S10P",0., yborder,0.,0,"ONLY"); 
1117      gMC->Gspos("S10B",2,"S10P",0.,-yborder,0.,0,"ONLY"); 
1118
1119      // create the NULOC volume and position it in the horizontal frame
1120
1121      gMC->Gsvolu("S09N","BOX",nulocMaterial,nulocpar,3);
1122      gMC->Gsvolu("S10N","BOX",nulocMaterial,nulocpar,3);
1123      index = 0;
1124      for (xx = -xxmax; xx<=xxmax; xx+=3*nulocLength) { 
1125        index++; 
1126        gMC->Gspos("S09N",2*index-1,"S09B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
1127        gMC->Gspos("S09N",2*index  ,"S09B", xx, 0., bFrameWidth/4., 0, "ONLY");
1128        gMC->Gspos("S10N",2*index-1,"S10B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
1129        gMC->Gspos("S10N",2*index  ,"S10B", xx, 0., bFrameWidth/4., 0, "ONLY");
1130      }
1131  }
1132  
1133
1134 ///////////////////////////////////////
1135 // GEOMETRY FOR THE TRIGGER CHAMBERS //
1136 ///////////////////////////////////////
1137
1138 // 03/00 P. Dupieux : introduce a slighly more realistic  
1139 //                    geom. of the trigger readout planes with
1140 //                    2 Zpos per trigger plane (alternate
1141 //                    between left and right of the trigger)  
1142
1143 //  Parameters of the Trigger Chambers
1144
1145                 
1146      const Float_t kXMC1MIN=34.;       
1147      const Float_t kXMC1MED=51.;                                
1148      const Float_t kXMC1MAX=272.;                               
1149      const Float_t kYMC1MIN=34.;                              
1150      const Float_t kYMC1MAX=51.;                              
1151      const Float_t kRMIN1=50.;
1152      const Float_t kRMAX1=62.;
1153      const Float_t kRMIN2=50.;
1154      const Float_t kRMAX2=66.;
1155
1156 //   zposition of the middle of the gas gap in mother vol 
1157      const Float_t kZMCm=-3.6;
1158      const Float_t kZMCp=+3.6;
1159
1160
1161 // TRIGGER STATION 1 - TRIGGER STATION 1 - TRIGGER STATION 1
1162
1163      // iChamber 1 and 2 for first and second chambers in the station
1164      // iChamber (first chamber) kept for other quanties than Z,
1165      // assumed to be the same in both chambers
1166      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[10];
1167      iChamber2 =(AliMUONChamber*) (*fChambers)[11]; 
1168
1169      // 03/00 
1170      // zpos1 and zpos2 are now the middle of the first and second
1171      // plane of station 1 : 
1172      // zpos1=(16075+15995)/2=16035 mm, thick/2=40 mm
1173      // zpos2=(16225+16145)/2=16185 mm, thick/2=40 mm
1174      //
1175      // zpos1m=15999 mm , zpos1p=16071 mm (middles of gas gaps)
1176      // zpos2m=16149 mm , zpos2p=16221 mm (middles of gas gaps)
1177      // rem : the total thickness accounts for 1 mm of al on both 
1178      // side of the RPCs (see zpos1 and zpos2), as previously
1179
1180      zpos1=iChamber1->Z();
1181      zpos2=iChamber2->Z();
1182
1183
1184 // Mother volume definition     
1185      tpar[0] = iChamber->RInner(); 
1186      tpar[1] = iChamber->ROuter();
1187      tpar[2] = 4.0;    
1188      gMC->Gsvolu("CM11", "TUBE", idAir, tpar, 3);
1189      gMC->Gsvolu("CM12", "TUBE", idAir, tpar, 3);
1190      
1191 // Definition of the flange between the beam shielding and the RPC 
1192      tpar[0]= kRMIN1;
1193      tpar[1]= kRMAX1;
1194      tpar[2]= 4.0;
1195    
1196      gMC->Gsvolu("CF1A", "TUBE", idAlu1, tpar, 3);     //Al
1197      gMC->Gspos("CF1A", 1, "CM11", 0., 0., 0., 0, "MANY");
1198      gMC->Gspos("CF1A", 2, "CM12", 0., 0., 0., 0, "MANY");
1199
1200
1201 // FIRST PLANE OF STATION 1
1202
1203 //   ratios of zpos1m/zpos1p and inverse for first plane
1204      Float_t zmp=(zpos1-3.6)/(zpos1+3.6);
1205      Float_t zpm=1./zmp;
1206    
1207
1208 // Definition of prototype for chambers in the first plane     
1209           
1210      tpar[0]= 0.;
1211      tpar[1]= 0.;
1212      tpar[2]= 0.;
1213           
1214      gMC->Gsvolu("CC1A", "BOX ", idAlu1, tpar, 0);           //Al    
1215      gMC->Gsvolu("CB1A", "BOX ", idtmed[1107], tpar, 0);     //Bakelite 
1216      gMC->Gsvolu("CG1A", "BOX ", idtmed[1106], tpar, 0);     //Gas streamer
1217
1218 // chamber type A
1219      tpar[0] = -1.;
1220      tpar[1] = -1.;
1221      
1222      const Float_t kXMC1A=kXMC1MED+(kXMC1MAX-kXMC1MED)/2.;
1223      const Float_t kYMC1Am=0.;
1224      const Float_t kYMC1Ap=0.;
1225           
1226      tpar[2] = 0.1;    
1227      gMC->Gsposp("CG1A", 1, "CB1A", 0., 0., 0., 0, "ONLY",tpar,3);
1228      tpar[2] = 0.3;
1229      gMC->Gsposp("CB1A", 1, "CC1A", 0., 0., 0., 0, "ONLY",tpar,3);
1230
1231      tpar[2] = 0.4;
1232      tpar[0] = (kXMC1MAX-kXMC1MED)/2.;
1233      tpar[1] = kYMC1MIN;
1234
1235      gMC->Gsposp("CC1A", 1, "CM11",kXMC1A,kYMC1Am,kZMCm, 0, "ONLY", tpar, 3);
1236      gMC->Gsposp("CC1A", 2, "CM11",-kXMC1A,kYMC1Ap,kZMCp, 0, "ONLY", tpar, 3);
1237      
1238 //  chamber type B    
1239      Float_t tpar1save=tpar[1];
1240      Float_t y1msave=kYMC1Am;
1241      Float_t y1psave=kYMC1Ap;
1242  
1243      tpar[0] = (kXMC1MAX-kXMC1MIN)/2.;
1244      tpar[1] = (kYMC1MAX-kYMC1MIN)/2.;
1245      
1246      const Float_t kXMC1B=kXMC1MIN+tpar[0];
1247      const Float_t kYMC1Bp=(y1msave+tpar1save)*zpm+tpar[1];
1248      const Float_t kYMC1Bm=(y1psave+tpar1save)*zmp+tpar[1];
1249
1250      gMC->Gsposp("CC1A", 3, "CM11",kXMC1B,kYMC1Bp,kZMCp, 0, "ONLY", tpar, 3);
1251      gMC->Gsposp("CC1A", 4, "CM11",-kXMC1B,kYMC1Bm,kZMCm, 0, "ONLY", tpar, 3);
1252      gMC->Gsposp("CC1A", 5, "CM11",kXMC1B,-kYMC1Bp,kZMCp, 0, "ONLY", tpar, 3);
1253      gMC->Gsposp("CC1A", 6, "CM11",-kXMC1B,-kYMC1Bm,kZMCm, 0, "ONLY", tpar, 3);
1254      
1255 //  chamber type C  (end of type B !!)      
1256      tpar1save=tpar[1];
1257      y1msave=kYMC1Bm;
1258      y1psave=kYMC1Bp;
1259
1260      tpar[0] = kXMC1MAX/2;
1261      tpar[1] = kYMC1MAX/2;
1262      
1263      const Float_t kXMC1C=tpar[0];
1264 // warning : same Z than type B
1265      const Float_t kYMC1Cp=(y1psave+tpar1save)*1.+tpar[1];
1266      const Float_t kYMC1Cm=(y1msave+tpar1save)*1.+tpar[1];
1267      
1268      gMC->Gsposp("CC1A", 7, "CM11",kXMC1C,kYMC1Cp,kZMCp, 0, "ONLY", tpar, 3);
1269      gMC->Gsposp("CC1A", 8, "CM11",-kXMC1C,kYMC1Cm,kZMCm, 0, "ONLY", tpar, 3);
1270      gMC->Gsposp("CC1A", 9, "CM11",kXMC1C,-kYMC1Cp,kZMCp, 0, "ONLY", tpar, 3);
1271      gMC->Gsposp("CC1A", 10, "CM11",-kXMC1C,-kYMC1Cm,kZMCm, 0, "ONLY", tpar, 3);
1272      
1273 //  chamber type D, E and F (same size)        
1274      tpar1save=tpar[1];
1275      y1msave=kYMC1Cm;
1276      y1psave=kYMC1Cp;
1277
1278      tpar[0] = kXMC1MAX/2.;
1279      tpar[1] = kYMC1MIN;
1280      
1281      const Float_t kXMC1D=tpar[0];
1282      const Float_t kYMC1Dp=(y1msave+tpar1save)*zpm+tpar[1];
1283      const Float_t kYMC1Dm=(y1psave+tpar1save)*zmp+tpar[1];
1284      
1285      gMC->Gsposp("CC1A", 11, "CM11",kXMC1D,kYMC1Dm,kZMCm, 0, "ONLY", tpar, 3);
1286      gMC->Gsposp("CC1A", 12, "CM11",-kXMC1D,kYMC1Dp,kZMCp, 0, "ONLY", tpar, 3);
1287      gMC->Gsposp("CC1A", 13, "CM11",kXMC1D,-kYMC1Dm,kZMCm, 0, "ONLY", tpar, 3);
1288      gMC->Gsposp("CC1A", 14, "CM11",-kXMC1D,-kYMC1Dp,kZMCp, 0, "ONLY", tpar, 3);
1289
1290
1291      tpar1save=tpar[1];
1292      y1msave=kYMC1Dm;
1293      y1psave=kYMC1Dp;
1294      const Float_t kYMC1Ep=(y1msave+tpar1save)*zpm+tpar[1];
1295      const Float_t kYMC1Em=(y1psave+tpar1save)*zmp+tpar[1];
1296      
1297      gMC->Gsposp("CC1A", 15, "CM11",kXMC1D,kYMC1Ep,kZMCp, 0, "ONLY", tpar, 3);
1298      gMC->Gsposp("CC1A", 16, "CM11",-kXMC1D,kYMC1Em,kZMCm, 0, "ONLY", tpar, 3);
1299      gMC->Gsposp("CC1A", 17, "CM11",kXMC1D,-kYMC1Ep,kZMCp, 0, "ONLY", tpar, 3);
1300      gMC->Gsposp("CC1A", 18, "CM11",-kXMC1D,-kYMC1Em,kZMCm, 0, "ONLY", tpar, 3);
1301
1302      tpar1save=tpar[1];
1303      y1msave=kYMC1Em;
1304      y1psave=kYMC1Ep;
1305      const Float_t kYMC1Fp=(y1msave+tpar1save)*zpm+tpar[1];
1306      const Float_t kYMC1Fm=(y1psave+tpar1save)*zmp+tpar[1];
1307     
1308      gMC->Gsposp("CC1A", 19, "CM11",kXMC1D,kYMC1Fm,kZMCm, 0, "ONLY", tpar, 3);
1309      gMC->Gsposp("CC1A", 20, "CM11",-kXMC1D,kYMC1Fp,kZMCp, 0, "ONLY", tpar, 3);
1310      gMC->Gsposp("CC1A", 21, "CM11",kXMC1D,-kYMC1Fm,kZMCm, 0, "ONLY", tpar, 3);
1311      gMC->Gsposp("CC1A", 22, "CM11",-kXMC1D,-kYMC1Fp,kZMCp, 0, "ONLY", tpar, 3);
1312
1313 // Positioning first plane in ALICE     
1314      gMC->Gspos("CM11", 1, "ALIC", 0., 0., zpos1, 0, "ONLY");
1315
1316 // End of geometry definition for the first plane of station 1
1317
1318
1319
1320 // SECOND PLANE OF STATION 1 : proj ratio = zpos2/zpos1
1321
1322      const Float_t kZ12=zpos2/zpos1;
1323       
1324 // Definition of prototype for chambers in the second plane of station 1    
1325           
1326      tpar[0]= 0.;
1327      tpar[1]= 0.;
1328      tpar[2]= 0.;
1329           
1330      gMC->Gsvolu("CC2A", "BOX ", idAlu1, tpar, 0);           //Al    
1331      gMC->Gsvolu("CB2A", "BOX ", idtmed[1107], tpar, 0);     //Bakelite 
1332      gMC->Gsvolu("CG2A", "BOX ", idtmed[1106], tpar, 0);     //Gas streamer
1333
1334 // chamber type A
1335      tpar[0] = -1.;
1336      tpar[1] = -1.;
1337      
1338      const Float_t kXMC2A=kXMC1A*kZ12;
1339      const Float_t kYMC2Am=0.;
1340      const Float_t kYMC2Ap=0.;
1341           
1342      tpar[2] = 0.1;    
1343      gMC->Gsposp("CG2A", 1, "CB2A", 0., 0., 0., 0, "ONLY",tpar,3);
1344      tpar[2] = 0.3;
1345      gMC->Gsposp("CB2A", 1, "CC2A", 0., 0., 0., 0, "ONLY",tpar,3);
1346
1347      tpar[2] = 0.4;
1348      tpar[0] = ((kXMC1MAX-kXMC1MED)/2.)*kZ12;
1349      tpar[1] = kYMC1MIN*kZ12;
1350
1351      gMC->Gsposp("CC2A", 1, "CM12",kXMC2A,kYMC2Am,kZMCm, 0, "ONLY", tpar, 3);
1352      gMC->Gsposp("CC2A", 2, "CM12",-kXMC2A,kYMC2Ap,kZMCp, 0, "ONLY", tpar, 3);
1353      
1354
1355 //  chamber type B    
1356
1357      tpar[0] = ((kXMC1MAX-kXMC1MIN)/2.)*kZ12;
1358      tpar[1] = ((kYMC1MAX-kYMC1MIN)/2.)*kZ12;
1359      
1360      const Float_t kXMC2B=kXMC1B*kZ12;
1361      const Float_t kYMC2Bp=kYMC1Bp*kZ12;
1362      const Float_t kYMC2Bm=kYMC1Bm*kZ12;
1363      gMC->Gsposp("CC2A", 3, "CM12",kXMC2B,kYMC2Bp,kZMCp, 0, "ONLY", tpar, 3);
1364      gMC->Gsposp("CC2A", 4, "CM12",-kXMC2B,kYMC2Bm,kZMCm, 0, "ONLY", tpar, 3);
1365      gMC->Gsposp("CC2A", 5, "CM12",kXMC2B,-kYMC2Bp,kZMCp, 0, "ONLY", tpar, 3);
1366      gMC->Gsposp("CC2A", 6, "CM12",-kXMC2B,-kYMC2Bm,kZMCm, 0, "ONLY", tpar, 3);
1367
1368      
1369 //  chamber type C   (end of type B !!)     
1370
1371      tpar[0] = (kXMC1MAX/2)*kZ12;
1372      tpar[1] = (kYMC1MAX/2)*kZ12;
1373      
1374      const Float_t kXMC2C=kXMC1C*kZ12;
1375      const Float_t kYMC2Cp=kYMC1Cp*kZ12;
1376      const Float_t kYMC2Cm=kYMC1Cm*kZ12;     
1377      gMC->Gsposp("CC2A", 7, "CM12",kXMC2C,kYMC2Cp,kZMCp, 0, "ONLY", tpar, 3);
1378      gMC->Gsposp("CC2A", 8, "CM12",-kXMC2C,kYMC2Cm,kZMCm, 0, "ONLY", tpar, 3);
1379      gMC->Gsposp("CC2A", 9, "CM12",kXMC2C,-kYMC2Cp,kZMCp, 0, "ONLY", tpar, 3);
1380      gMC->Gsposp("CC2A", 10, "CM12",-kXMC2C,-kYMC2Cm,kZMCm, 0, "ONLY", tpar, 3);
1381      
1382 //  chamber type D, E and F (same size)        
1383
1384      tpar[0] = (kXMC1MAX/2.)*kZ12;
1385      tpar[1] = kYMC1MIN*kZ12;
1386      
1387      const Float_t kXMC2D=kXMC1D*kZ12;
1388      const Float_t kYMC2Dp=kYMC1Dp*kZ12;
1389      const Float_t kYMC2Dm=kYMC1Dm*kZ12;     
1390      gMC->Gsposp("CC2A", 11, "CM12",kXMC2D,kYMC2Dm,kZMCm, 0, "ONLY", tpar, 3);
1391      gMC->Gsposp("CC2A", 12, "CM12",-kXMC2D,kYMC2Dp,kZMCp, 0, "ONLY", tpar, 3);
1392      gMC->Gsposp("CC2A", 13, "CM12",kXMC2D,-kYMC2Dm,kZMCm, 0, "ONLY", tpar, 3);
1393      gMC->Gsposp("CC2A", 14, "CM12",-kXMC2D,-kYMC2Dp,kZMCp, 0, "ONLY", tpar, 3);
1394
1395      const Float_t kYMC2Ep=kYMC1Ep*kZ12;
1396      const Float_t kYMC2Em=kYMC1Em*kZ12;
1397      gMC->Gsposp("CC2A", 15, "CM12",kXMC2D,kYMC2Ep,kZMCp, 0, "ONLY", tpar, 3);
1398      gMC->Gsposp("CC2A", 16, "CM12",-kXMC2D,kYMC2Em,kZMCm, 0, "ONLY", tpar, 3);
1399      gMC->Gsposp("CC2A", 17, "CM12",kXMC2D,-kYMC2Ep,kZMCp, 0, "ONLY", tpar, 3);
1400      gMC->Gsposp("CC2A", 18, "CM12",-kXMC2D,-kYMC2Em,kZMCm, 0, "ONLY", tpar, 3);
1401
1402
1403      const Float_t kYMC2Fp=kYMC1Fp*kZ12;
1404      const Float_t kYMC2Fm=kYMC1Fm*kZ12;
1405      gMC->Gsposp("CC2A", 19, "CM12",kXMC2D,kYMC2Fm,kZMCm, 0, "ONLY", tpar, 3);
1406      gMC->Gsposp("CC2A", 20, "CM12",-kXMC2D,kYMC2Fp,kZMCp, 0, "ONLY", tpar, 3);
1407      gMC->Gsposp("CC2A", 21, "CM12",kXMC2D,-kYMC2Fm,kZMCm, 0, "ONLY", tpar, 3);
1408      gMC->Gsposp("CC2A", 22, "CM12",-kXMC2D,-kYMC2Fp,kZMCp, 0, "ONLY", tpar, 3);
1409
1410 // Positioning second plane of station 1 in ALICE     
1411      
1412      gMC->Gspos("CM12", 1, "ALIC", 0., 0., zpos2, 0, "ONLY");
1413
1414 // End of geometry definition for the second plane of station 1
1415
1416
1417
1418 // TRIGGER STATION 2 - TRIGGER STATION 2 - TRIGGER STATION 2    
1419
1420      // 03/00 
1421      // zpos3 and zpos4 are now the middle of the first and second
1422      // plane of station 2 : 
1423      // zpos3=(17075+16995)/2=17035 mm, thick/2=40 mm
1424      // zpos4=(17225+17145)/2=17185 mm, thick/2=40 mm
1425      //
1426      // zpos3m=16999 mm , zpos3p=17071 mm (middles of gas gaps)
1427      // zpos4m=17149 mm , zpos4p=17221 mm (middles of gas gaps)
1428      // rem : the total thickness accounts for 1 mm of al on both 
1429      // side of the RPCs (see zpos3 and zpos4), as previously
1430      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[12];
1431      iChamber2 =(AliMUONChamber*) (*fChambers)[13];
1432      Float_t zpos3=iChamber1->Z();
1433      Float_t zpos4=iChamber2->Z();
1434
1435
1436 // Mother volume definition     
1437      tpar[0] = iChamber->RInner(); 
1438      tpar[1] = iChamber->ROuter();
1439      tpar[2] = 4.0;    
1440  
1441      gMC->Gsvolu("CM21", "TUBE", idAir, tpar, 3);
1442      gMC->Gsvolu("CM22", "TUBE", idAir, tpar, 3);
1443      
1444 // Definition of the flange between the beam shielding and the RPC 
1445 //  ???? interface shielding
1446
1447      tpar[0]= kRMIN2;
1448      tpar[1]= kRMAX2;
1449      tpar[2]= 4.0;
1450    
1451      gMC->Gsvolu("CF2A", "TUBE", idAlu1, tpar, 3);            //Al
1452      gMC->Gspos("CF2A", 1, "CM21", 0., 0., 0., 0, "MANY");
1453      gMC->Gspos("CF2A", 2, "CM22", 0., 0., 0., 0, "MANY");
1454     
1455
1456
1457 // FIRST PLANE OF STATION 2 : proj ratio = zpos3/zpos1
1458
1459      const Float_t kZ13=zpos3/zpos1; 
1460
1461 // Definition of prototype for chambers in the first plane of station 2       
1462      tpar[0]= 0.;
1463      tpar[1]= 0.;
1464      tpar[2]= 0.;
1465           
1466      gMC->Gsvolu("CC3A", "BOX ", idAlu1, tpar, 0);           //Al  
1467      gMC->Gsvolu("CB3A", "BOX ", idtmed[1107], tpar, 0);     //Bakelite 
1468      gMC->Gsvolu("CG3A", "BOX ", idtmed[1106], tpar, 0);     //Gas streamer
1469
1470
1471 // chamber type A
1472      tpar[0] = -1.;
1473      tpar[1] = -1.;
1474      
1475      const Float_t kXMC3A=kXMC1A*kZ13;
1476      const Float_t kYMC3Am=0.;
1477      const Float_t kYMC3Ap=0.;
1478           
1479      tpar[2] = 0.1;    
1480      gMC->Gsposp("CG3A", 1, "CB3A", 0., 0., 0., 0, "ONLY",tpar,3);
1481      tpar[2] = 0.3;
1482      gMC->Gsposp("CB3A", 1, "CC3A", 0., 0., 0., 0, "ONLY",tpar,3);
1483
1484      tpar[2] = 0.4;
1485      tpar[0] = ((kXMC1MAX-kXMC1MED)/2.)*kZ13;
1486      tpar[1] = kYMC1MIN*kZ13;
1487      gMC->Gsposp("CC3A", 1, "CM21",kXMC3A,kYMC3Am,kZMCm, 0, "ONLY", tpar, 3);
1488      gMC->Gsposp("CC3A", 2, "CM21",-kXMC3A,kYMC3Ap,kZMCp, 0, "ONLY", tpar, 3);
1489
1490      
1491 //  chamber type B    
1492      tpar[0] = ((kXMC1MAX-kXMC1MIN)/2.)*kZ13;
1493      tpar[1] = ((kYMC1MAX-kYMC1MIN)/2.)*kZ13;
1494      
1495      const Float_t kXMC3B=kXMC1B*kZ13;
1496      const Float_t kYMC3Bp=kYMC1Bp*kZ13;
1497      const Float_t kYMC3Bm=kYMC1Bm*kZ13;
1498      gMC->Gsposp("CC3A", 3, "CM21",kXMC3B,kYMC3Bp,kZMCp, 0, "ONLY", tpar, 3);
1499      gMC->Gsposp("CC3A", 4, "CM21",-kXMC3B,kYMC3Bm,kZMCm, 0, "ONLY", tpar, 3);
1500      gMC->Gsposp("CC3A", 5, "CM21",kXMC3B,-kYMC3Bp,kZMCp, 0, "ONLY", tpar, 3);
1501      gMC->Gsposp("CC3A", 6, "CM21",-kXMC3B,-kYMC3Bm,kZMCm, 0, "ONLY", tpar, 3);
1502
1503      
1504 //  chamber type C  (end of type B !!)      
1505      tpar[0] = (kXMC1MAX/2)*kZ13;
1506      tpar[1] = (kYMC1MAX/2)*kZ13;
1507      
1508      const Float_t kXMC3C=kXMC1C*kZ13;
1509      const Float_t kYMC3Cp=kYMC1Cp*kZ13;
1510      const Float_t kYMC3Cm=kYMC1Cm*kZ13;     
1511      gMC->Gsposp("CC3A", 7, "CM21",kXMC3C,kYMC3Cp,kZMCp, 0, "ONLY", tpar, 3);
1512      gMC->Gsposp("CC3A", 8, "CM21",-kXMC3C,kYMC3Cm,kZMCm, 0, "ONLY", tpar, 3);
1513      gMC->Gsposp("CC3A", 9, "CM21",kXMC3C,-kYMC3Cp,kZMCp, 0, "ONLY", tpar, 3);
1514      gMC->Gsposp("CC3A", 10, "CM21",-kXMC3C,-kYMC3Cm,kZMCm, 0, "ONLY", tpar, 3);
1515      
1516
1517 //  chamber type D, E and F (same size)         
1518
1519      tpar[0] = (kXMC1MAX/2.)*kZ13;
1520      tpar[1] = kYMC1MIN*kZ13;
1521      
1522      const Float_t kXMC3D=kXMC1D*kZ13;
1523      const Float_t kYMC3Dp=kYMC1Dp*kZ13;
1524      const Float_t kYMC3Dm=kYMC1Dm*kZ13;          
1525      gMC->Gsposp("CC3A", 11, "CM21",kXMC3D,kYMC3Dm,kZMCm, 0, "ONLY", tpar, 3);
1526      gMC->Gsposp("CC3A", 12, "CM21",-kXMC3D,kYMC3Dp,kZMCp, 0, "ONLY", tpar, 3);
1527      gMC->Gsposp("CC3A", 13, "CM21",kXMC3D,-kYMC3Dm,kZMCm, 0, "ONLY", tpar, 3);
1528      gMC->Gsposp("CC3A", 14, "CM21",-kXMC3D,-kYMC3Dp,kZMCp, 0, "ONLY", tpar, 3);
1529
1530      const Float_t kYMC3Ep=kYMC1Ep*kZ13;
1531      const Float_t kYMC3Em=kYMC1Em*kZ13;
1532      gMC->Gsposp("CC3A", 15, "CM21",kXMC3D,kYMC3Ep,kZMCp, 0, "ONLY", tpar, 3);
1533      gMC->Gsposp("CC3A", 16, "CM21",-kXMC3D,kYMC3Em,kZMCm, 0, "ONLY", tpar, 3);
1534      gMC->Gsposp("CC3A", 17, "CM21",kXMC3D,-kYMC3Ep,kZMCp, 0, "ONLY", tpar, 3);
1535      gMC->Gsposp("CC3A", 18, "CM21",-kXMC3D,-kYMC3Em,kZMCm, 0, "ONLY", tpar, 3);
1536
1537      const Float_t kYMC3Fp=kYMC1Fp*kZ13;
1538      const Float_t kYMC3Fm=kYMC1Fm*kZ13;
1539      gMC->Gsposp("CC3A", 19, "CM21",kXMC3D,kYMC3Fm,kZMCm, 0, "ONLY", tpar, 3);
1540      gMC->Gsposp("CC3A", 20, "CM21",-kXMC3D,kYMC3Fp,kZMCp, 0, "ONLY", tpar, 3);
1541      gMC->Gsposp("CC3A", 21, "CM21",kXMC3D,-kYMC3Fm,kZMCm, 0, "ONLY", tpar, 3);
1542      gMC->Gsposp("CC3A", 22, "CM21",-kXMC3D,-kYMC3Fp,kZMCp, 0, "ONLY", tpar, 3);
1543        
1544
1545 // Positioning first plane of station 2 in ALICE
1546      
1547      gMC->Gspos("CM21", 1, "ALIC", 0., 0., zpos3, 0, "ONLY");
1548
1549 // End of geometry definition for the first plane of station 2
1550
1551
1552
1553
1554 // SECOND PLANE OF STATION 2 : proj ratio = zpos4/zpos1
1555
1556      const Float_t kZ14=zpos4/zpos1;
1557      
1558 // Definition of prototype for chambers in the second plane of station 2    
1559           
1560      tpar[0]= 0.;
1561      tpar[1]= 0.;
1562      tpar[2]= 0.;
1563           
1564      gMC->Gsvolu("CC4A", "BOX ", idAlu1, tpar, 0);           //Al      
1565      gMC->Gsvolu("CB4A", "BOX ", idtmed[1107], tpar, 0);     //Bakelite 
1566      gMC->Gsvolu("CG4A", "BOX ", idtmed[1106], tpar, 0);     //Gas streamer
1567
1568 // chamber type A
1569      tpar[0] = -1.;
1570      tpar[1] = -1.;
1571      
1572      const Float_t kXMC4A=kXMC1A*kZ14;
1573      const Float_t kYMC4Am=0.;
1574      const Float_t kYMC4Ap=0.;
1575           
1576      tpar[2] = 0.1;    
1577      gMC->Gsposp("CG4A", 1, "CB4A", 0., 0., 0., 0, "ONLY",tpar,3);
1578      tpar[2] = 0.3;
1579      gMC->Gsposp("CB4A", 1, "CC4A", 0., 0., 0., 0, "ONLY",tpar,3);
1580
1581      tpar[2] = 0.4;
1582      tpar[0] = ((kXMC1MAX-kXMC1MED)/2.)*kZ14;
1583      tpar[1] = kYMC1MIN*kZ14;
1584      gMC->Gsposp("CC4A", 1, "CM22",kXMC4A,kYMC4Am,kZMCm, 0, "ONLY", tpar, 3);
1585      gMC->Gsposp("CC4A", 2, "CM22",-kXMC4A,kYMC4Ap,kZMCp, 0, "ONLY", tpar, 3);
1586      
1587
1588 //  chamber type B    
1589      tpar[0] = ((kXMC1MAX-kXMC1MIN)/2.)*kZ14;
1590      tpar[1] = ((kYMC1MAX-kYMC1MIN)/2.)*kZ14;
1591      
1592      const Float_t kXMC4B=kXMC1B*kZ14;
1593      const Float_t kYMC4Bp=kYMC1Bp*kZ14;
1594      const Float_t kYMC4Bm=kYMC1Bm*kZ14;
1595      gMC->Gsposp("CC4A", 3, "CM22",kXMC4B,kYMC4Bp,kZMCp, 0, "ONLY", tpar, 3);
1596      gMC->Gsposp("CC4A", 4, "CM22",-kXMC4B,kYMC4Bm,kZMCm, 0, "ONLY", tpar, 3);
1597      gMC->Gsposp("CC4A", 5, "CM22",kXMC4B,-kYMC4Bp,kZMCp, 0, "ONLY", tpar, 3);
1598      gMC->Gsposp("CC4A", 6, "CM22",-kXMC4B,-kYMC4Bm,kZMCm, 0, "ONLY", tpar, 3);
1599
1600      
1601 //  chamber type C   (end of type B !!)      
1602      tpar[0] =(kXMC1MAX/2)*kZ14;
1603      tpar[1] =  (kYMC1MAX/2)*kZ14;
1604      
1605      const Float_t kXMC4C=kXMC1C*kZ14;
1606      const Float_t kYMC4Cp=kYMC1Cp*kZ14;
1607      const Float_t kYMC4Cm=kYMC1Cm*kZ14;     
1608      gMC->Gsposp("CC4A", 7, "CM22",kXMC4C,kYMC4Cp,kZMCp, 0, "ONLY", tpar, 3);
1609      gMC->Gsposp("CC4A", 8, "CM22",-kXMC4C,kYMC4Cm,kZMCm, 0, "ONLY", tpar, 3);
1610      gMC->Gsposp("CC4A", 9, "CM22",kXMC4C,-kYMC4Cp,kZMCp, 0, "ONLY", tpar, 3);
1611      gMC->Gsposp("CC4A", 10, "CM22",-kXMC4C,-kYMC4Cm,kZMCm, 0, "ONLY", tpar, 3);
1612
1613      
1614 //  chamber type D, E and F (same size)      
1615      tpar[0] = (kXMC1MAX/2.)*kZ14;
1616      tpar[1] =  kYMC1MIN*kZ14;
1617      
1618      const Float_t kXMC4D=kXMC1D*kZ14;
1619      const Float_t kYMC4Dp=kYMC1Dp*kZ14;
1620      const Float_t kYMC4Dm=kYMC1Dm*kZ14;          
1621      gMC->Gsposp("CC4A", 11, "CM22",kXMC4D,kYMC4Dm,kZMCm, 0, "ONLY", tpar, 3);
1622      gMC->Gsposp("CC4A", 12, "CM22",-kXMC4D,kYMC4Dp,kZMCp, 0, "ONLY", tpar, 3);
1623      gMC->Gsposp("CC4A", 13, "CM22",kXMC4D,-kYMC4Dm,kZMCm, 0, "ONLY", tpar, 3);
1624      gMC->Gsposp("CC4A", 14, "CM22",-kXMC4D,-kYMC4Dp,kZMCp, 0, "ONLY", tpar, 3);
1625
1626      const Float_t kYMC4Ep=kYMC1Ep*kZ14;
1627      const Float_t kYMC4Em=kYMC1Em*kZ14;          
1628      gMC->Gsposp("CC4A", 15, "CM22",kXMC4D,kYMC4Ep,kZMCp, 0, "ONLY", tpar, 3);
1629      gMC->Gsposp("CC4A", 16, "CM22",-kXMC4D,kYMC4Em,kZMCm, 0, "ONLY", tpar, 3);
1630      gMC->Gsposp("CC4A", 17, "CM22",kXMC4D,-kYMC4Ep,kZMCp, 0, "ONLY", tpar, 3);
1631      gMC->Gsposp("CC4A", 18, "CM22",-kXMC4D,-kYMC4Em,kZMCm, 0, "ONLY", tpar, 3);
1632
1633      const Float_t kYMC4Fp=kYMC1Fp*kZ14;
1634      const Float_t kYMC4Fm=kYMC1Fm*kZ14;          
1635      gMC->Gsposp("CC4A", 19, "CM22",kXMC4D,kYMC4Fm,kZMCm, 0, "ONLY", tpar, 3);
1636      gMC->Gsposp("CC4A", 20, "CM22",-kXMC4D,kYMC4Fp,kZMCp, 0, "ONLY", tpar, 3);
1637      gMC->Gsposp("CC4A", 21, "CM22",kXMC4D,-kYMC4Fm,kZMCm, 0, "ONLY", tpar, 3);
1638      gMC->Gsposp("CC4A", 22, "CM22",-kXMC4D,-kYMC4Fp,kZMCp, 0, "ONLY", tpar, 3);
1639      
1640
1641 // Positioning second plane of station 2 in ALICE
1642      
1643      gMC->Gspos("CM22", 1, "ALIC", 0., 0., zpos4, 0, "ONLY");
1644
1645 // End of geometry definition for the second plane of station 2
1646
1647 // End of trigger geometry definition
1648
1649 }
1650
1651
1652  
1653 //___________________________________________
1654 void AliMUONv1::CreateMaterials()
1655 {
1656   // *** DEFINITION OF AVAILABLE MUON MATERIALS *** 
1657   //
1658   //     Ar-CO2 gas 
1659     Float_t ag1[3]   = { 39.95,12.01,16. };
1660     Float_t zg1[3]   = { 18.,6.,8. };
1661     Float_t wg1[3]   = { .8,.0667,.13333 };
1662     Float_t dg1      = .001821;
1663     //
1664     //     Ar-buthane-freon gas -- trigger chambers 
1665     Float_t atr1[4]  = { 39.95,12.01,1.01,19. };
1666     Float_t ztr1[4]  = { 18.,6.,1.,9. };
1667     Float_t wtr1[4]  = { .56,.1262857,.2857143,.028 };
1668     Float_t dtr1     = .002599;
1669     //
1670     //     Ar-CO2 gas 
1671     Float_t agas[3]  = { 39.95,12.01,16. };
1672     Float_t zgas[3]  = { 18.,6.,8. };
1673     Float_t wgas[3]  = { .74,.086684,.173316 };
1674     Float_t dgas     = .0018327;
1675     //
1676     //     Ar-Isobutane gas (80%+20%) -- tracking 
1677     Float_t ag[3]    = { 39.95,12.01,1.01 };
1678     Float_t zg[3]    = { 18.,6.,1. };
1679     Float_t wg[3]    = { .8,.057,.143 };
1680     Float_t dg       = .0019596;
1681     //
1682     //     Ar-Isobutane-Forane-SF6 gas (49%+7%+40%+4%) -- trigger 
1683     Float_t atrig[5] = { 39.95,12.01,1.01,19.,32.066 };
1684     Float_t ztrig[5] = { 18.,6.,1.,9.,16. };
1685     Float_t wtrig[5] = { .49,1.08,1.5,1.84,0.04 };
1686     Float_t dtrig    = .0031463;
1687     //
1688     //     bakelite 
1689
1690     Float_t abak[3] = {12.01 , 1.01 , 16.};
1691     Float_t zbak[3] = {6.     , 1.   , 8.};
1692     Float_t wbak[3] = {6.     , 6.   , 1.}; 
1693     Float_t dbak = 1.4;
1694
1695     Float_t epsil, stmin, deemax, tmaxfd, stemax;
1696
1697     Int_t iSXFLD   = gAlice->Field()->Integ();
1698     Float_t sXMGMX = gAlice->Field()->Max();
1699     //
1700     // --- Define the various materials for GEANT --- 
1701     AliMaterial(9, "ALUMINIUM$", 26.98, 13., 2.7, 8.9, 37.2);
1702     AliMaterial(10, "ALUMINIUM$", 26.98, 13., 2.7, 8.9, 37.2);
1703     AliMaterial(15, "AIR$      ", 14.61, 7.3, .001205, 30423.24, 67500);
1704     AliMixture(19, "Bakelite$", abak, zbak, dbak, -3, wbak);
1705     AliMixture(20, "ArC4H10 GAS$", ag, zg, dg, 3, wg);
1706     AliMixture(21, "TRIG GAS$", atrig, ztrig, dtrig, -5, wtrig);
1707     AliMixture(22, "ArCO2 80%$", ag1, zg1, dg1, 3, wg1);
1708     AliMixture(23, "Ar-freon $", atr1, ztr1, dtr1, 4, wtr1);
1709     AliMixture(24, "ArCO2 GAS$", agas, zgas, dgas, 3, wgas);
1710     // materials for slat: 
1711     //     Sensitive area: gas (already defined) 
1712     //     PCB: copper 
1713     //     insulating material and frame: vetronite
1714     //     walls: carbon, rohacell, carbon 
1715   Float_t aglass[5]={12.01, 28.09, 16.,   10.8,  23.};
1716   Float_t zglass[5]={ 6.,   14.,    8.,    5.,   11.};
1717   Float_t wglass[5]={ 0.5,  0.105, 0.355, 0.03,  0.01};
1718   Float_t dglass=1.74;
1719
1720   // rohacell: C9 H13 N1 O2
1721   Float_t arohac[4] = {12.01,  1.01, 14.010, 16.};
1722   Float_t zrohac[4] = { 6.,    1.,    7.,     8.};
1723   Float_t wrohac[4] = { 9.,   13.,    1.,     2.};
1724   Float_t drohac    = 0.03;
1725
1726   AliMaterial(31, "COPPER$",   63.54,    29.,   8.96,  1.4, 0.);
1727   AliMixture(32, "Vetronite$",aglass, zglass, dglass,    5, wglass);
1728   AliMaterial(33, "Carbon$",   12.01,     6.,  2.265, 18.8, 49.9);
1729   AliMixture(34, "Rohacell$", arohac, zrohac, drohac,   -4, wrohac); 
1730
1731
1732     epsil  = .001; // Tracking precision, 
1733     stemax = -1.;  // Maximum displacement for multiple scat 
1734     tmaxfd = -20.; // Maximum angle due to field deflection 
1735     deemax = -.3;  // Maximum fractional energy loss, DLS 
1736     stmin  = -.8;
1737     //
1738     //    Air 
1739     AliMedium(1, "AIR_CH_US         ", 15, 1, iSXFLD, sXMGMX, tmaxfd, stemax, deemax, epsil, stmin);
1740     //
1741     //    Aluminum 
1742
1743     AliMedium(4, "ALU_CH_US          ", 9, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
1744             fMaxDestepAlu, epsil, stmin);
1745     AliMedium(5, "ALU_CH_US          ", 10, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
1746             fMaxDestepAlu, epsil, stmin);
1747     //
1748     //    Ar-isoC4H10 gas 
1749
1750     AliMedium(6, "AR_CH_US          ", 20, 1, iSXFLD, sXMGMX, tmaxfd, fMaxStepGas, 
1751             fMaxDestepGas, epsil, stmin);
1752 //
1753     //    Ar-Isobuthane-Forane-SF6 gas 
1754
1755     AliMedium(7, "GAS_CH_TRIGGER    ", 21, 1, iSXFLD, sXMGMX, tmaxfd, stemax, deemax, epsil, stmin);
1756
1757     AliMedium(8, "BAKE_CH_TRIGGER   ", 19, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
1758             fMaxDestepAlu, epsil, stmin);
1759
1760     AliMedium(9, "ARG_CO2   ", 22, 1, iSXFLD, sXMGMX, tmaxfd, fMaxStepGas, 
1761             fMaxDestepAlu, epsil, stmin);
1762     // tracking media for slats: check the parameters!! 
1763     AliMedium(11, "PCB_COPPER        ", 31, 0, iSXFLD, sXMGMX, tmaxfd, 
1764               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1765     AliMedium(12, "VETRONITE         ", 32, 0, iSXFLD, sXMGMX, tmaxfd, 
1766               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1767     AliMedium(13, "CARBON            ", 33, 0, iSXFLD, sXMGMX, tmaxfd, 
1768               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1769     AliMedium(14, "Rohacell          ", 34, 0, iSXFLD, sXMGMX, tmaxfd, 
1770               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1771 }
1772
1773 //___________________________________________
1774
1775 void AliMUONv1::Init()
1776 {
1777    // 
1778    // Initialize Tracking Chambers
1779    //
1780
1781    printf("\n\n\n Start Init for version 1 - CPC chamber type\n\n\n");
1782    Int_t i;
1783    for (i=0; i<AliMUONConstants::NCh(); i++) {
1784        ( (AliMUONChamber*) (*fChambers)[i])->Init();
1785    }
1786    
1787    //
1788    // Set the chamber (sensitive region) GEANT identifier
1789    AliMC* gMC = AliMC::GetMC(); 
1790    ((AliMUONChamber*)(*fChambers)[0])->SetGid(gMC->VolId("C01G"));
1791    ((AliMUONChamber*)(*fChambers)[1])->SetGid(gMC->VolId("C02G"));
1792
1793    ((AliMUONChamber*)(*fChambers)[2])->SetGid(gMC->VolId("C03G"));
1794    ((AliMUONChamber*)(*fChambers)[3])->SetGid(gMC->VolId("C04G"));
1795
1796    ((AliMUONChamber*)(*fChambers)[4])->SetGid(gMC->VolId("S05G"));
1797    ((AliMUONChamber*)(*fChambers)[5])->SetGid(gMC->VolId("S06G"));
1798
1799    ((AliMUONChamber*)(*fChambers)[6])->SetGid(gMC->VolId("S07G"));
1800    ((AliMUONChamber*)(*fChambers)[7])->SetGid(gMC->VolId("S08G"));
1801
1802    ((AliMUONChamber*)(*fChambers)[8])->SetGid(gMC->VolId("S09G"));
1803    ((AliMUONChamber*)(*fChambers)[9])->SetGid(gMC->VolId("S10G"));
1804
1805    ((AliMUONChamber*)(*fChambers)[10])->SetGid(gMC->VolId("CG1A"));
1806    ((AliMUONChamber*)(*fChambers)[11])->SetGid(gMC->VolId("CG2A"));
1807    ((AliMUONChamber*)(*fChambers)[12])->SetGid(gMC->VolId("CG3A"));
1808    ((AliMUONChamber*)(*fChambers)[13])->SetGid(gMC->VolId("CG4A"));
1809
1810    printf("\n\n\n Finished Init for version 0 - CPC chamber type\n\n\n");
1811
1812    //cp 
1813    printf("\n\n\n Start Init for Trigger Circuits\n\n\n");
1814    for (i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
1815      ( (AliMUONTriggerCircuit*) (*fTriggerCircuits)[i])->Init(i);
1816    }
1817    printf(" Finished Init for Trigger Circuits\n\n\n");
1818    //cp
1819
1820 }
1821
1822 //___________________________________________
1823 void AliMUONv1::StepManager()
1824 {
1825   Int_t          copy, id;
1826   static Int_t   idvol;
1827   static Int_t   vol[2];
1828   Int_t          ipart;
1829   TLorentzVector pos;
1830   TLorentzVector mom;
1831   Float_t        theta,phi;
1832   Float_t        destep, step;
1833   
1834   static Float_t eloss, eloss2, xhit, yhit, zhit, tof, tlength;
1835   const  Float_t kBig=1.e10;
1836   //  modifs perso
1837   static Float_t hits[15];
1838
1839   TClonesArray &lhits = *fHits;
1840
1841   //
1842   // Set maximum step size for gas
1843   // numed=gMC->GetMedium();
1844   //
1845   // Only charged tracks
1846   if( !(gMC->TrackCharge()) ) return; 
1847   //
1848   // Only gas gap inside chamber
1849   // Tag chambers and record hits when track enters 
1850   idvol=-1;
1851   id=gMC->CurrentVolID(copy);
1852   
1853     for (Int_t i=1; i<=AliMUONConstants::NCh(); i++) {
1854       if(id==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()){ 
1855           vol[0]=i; 
1856           idvol=i-1;
1857       }
1858     }
1859     if (idvol == -1) return;
1860   //
1861   // Get current particle id (ipart), track position (pos)  and momentum (mom) 
1862   gMC->TrackPosition(pos);
1863   gMC->TrackMomentum(mom);
1864
1865   ipart  = gMC->TrackPid();
1866   //Int_t ipart1 = gMC->IdFromPDG(ipart);
1867   //printf("ich, ipart %d %d \n",vol[0],ipart1);
1868
1869   //
1870   // momentum loss and steplength in last step
1871   destep = gMC->Edep();
1872   step   = gMC->TrackStep();
1873   
1874   //
1875   // record hits when track enters ...
1876   if( gMC->IsTrackEntering()) {
1877       gMC->SetMaxStep(fMaxStepGas);
1878       Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
1879       Double_t rt = TMath::Sqrt(tc);
1880       Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
1881       Double_t tx=mom[0]/pmom;
1882       Double_t ty=mom[1]/pmom;
1883       Double_t tz=mom[2]/pmom;
1884       Double_t s=((AliMUONChamber*)(*fChambers)[idvol])
1885           ->ResponseModel()
1886           ->Pitch()/tz;
1887       theta   = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
1888       phi     = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
1889       hits[0] = Float_t(ipart);         // Geant3 particle type
1890       hits[1] = pos[0]+s*tx;                 // X-position for hit
1891       hits[2] = pos[1]+s*ty;                 // Y-position for hit
1892       hits[3] = pos[2]+s*tz;                 // Z-position for hit
1893       hits[4] = theta;                  // theta angle of incidence
1894       hits[5] = phi;                    // phi angle of incidence 
1895       hits[8] = (Float_t) fNPadHits;   // first padhit
1896       hits[9] = -1;                     // last pad hit
1897
1898       // modifs perso
1899       hits[10] = mom[3]; // hit momentum P
1900       hits[11] = mom[0]; // Px/P
1901       hits[12] = mom[1]; // Py/P
1902       hits[13] = mom[2]; // Pz/P
1903       // fin modifs perso
1904       tof=gMC->TrackTime();
1905       hits[14] = tof;    // Time of flight
1906       // phi angle of incidence
1907       tlength = 0;
1908       eloss   = 0;
1909       eloss2  = 0;
1910       xhit    = pos[0];
1911       yhit    = pos[1];      
1912       zhit    = pos[2];      
1913       // Only if not trigger chamber
1914
1915       
1916       
1917
1918       if(idvol<AliMUONConstants::NTrackingCh()) {
1919           //
1920           //  Initialize hit position (cursor) in the segmentation model 
1921           ((AliMUONChamber*) (*fChambers)[idvol])
1922               ->SigGenInit(pos[0], pos[1], pos[2]);
1923       } else {
1924           //geant3->Gpcxyz();
1925           //printf("In the Trigger Chamber #%d\n",idvol-9);
1926       }
1927   }
1928   eloss2+=destep;
1929   
1930   // 
1931   // Calculate the charge induced on a pad (disintegration) in case 
1932   //
1933   // Mip left chamber ...
1934   if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
1935       gMC->SetMaxStep(kBig);
1936       eloss   += destep;
1937       tlength += step;
1938       
1939       Float_t x0,y0,z0;
1940       Float_t localPos[3];
1941       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
1942       gMC->Gmtod(globalPos,localPos,1); 
1943
1944       if(idvol<AliMUONConstants::NTrackingCh()) {
1945 // tracking chambers
1946           x0 = 0.5*(xhit+pos[0]);
1947           y0 = 0.5*(yhit+pos[1]);
1948           z0 = 0.5*(zhit+pos[2]);
1949           //      z0 = localPos[2];
1950       } else {
1951 // trigger chambers
1952           x0=xhit;
1953           y0=yhit;
1954 //        z0=yhit;
1955           z0=0.;
1956       }
1957       
1958
1959       if (eloss >0)  MakePadHits(x0,y0,z0,eloss,tof,idvol);
1960       
1961           
1962       hits[6]=tlength;
1963       hits[7]=eloss2;
1964       if (fNPadHits > (Int_t)hits[8]) {
1965           hits[8]= hits[8]+1;
1966           hits[9]= (Float_t) fNPadHits;
1967       }
1968     
1969       new(lhits[fNhits++]) 
1970           AliMUONHit(fIshunt,gAlice->CurrentTrack(),vol,hits);
1971       eloss = 0; 
1972       //
1973       // Check additional signal generation conditions 
1974       // defined by the segmentation
1975       // model (boundary crossing conditions)
1976       // only for tracking chambers
1977   } else if 
1978       ((idvol < AliMUONConstants::NTrackingCh()) &&
1979        ((AliMUONChamber*) (*fChambers)[idvol])->SigGenCond(pos[0], pos[1], pos[2]))
1980   {
1981       ((AliMUONChamber*) (*fChambers)[idvol])
1982           ->SigGenInit(pos[0], pos[1], pos[2]);
1983       
1984       Float_t localPos[3];
1985       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
1986       gMC->Gmtod(globalPos,localPos,1); 
1987
1988
1989       if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
1990         MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
1991       xhit     = pos[0];
1992       yhit     = pos[1]; 
1993       zhit     = pos[2]; 
1994       eloss    = destep;
1995       tlength += step ;
1996       //
1997       // nothing special  happened, add up energy loss
1998   } else {        
1999       eloss   += destep;
2000       tlength += step ;
2001   }
2002 }
2003
2004