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