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