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