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