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