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