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