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