]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONv3.cxx
71a67650ade24ad741fa5ff1945d41ea5729b8e8
[u/mrichter/AliRoot.git] / MUON / AliMUONv3.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *      SigmaEffect_thetadegrees                                                                  *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpeateose. It is      *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /////////////////////////////////////////////////////////
19 //  Manager and hits classes for set:MUON version 3    //
20 /////////////////////////////////////////////////////////
21
22 // Old MUONv1 class
23 // (AliMUONv1.h 1.11, AliMUONv1.cxx 1.60)
24 // - now replaced with a new one where geometry and materials
25 // are created using new geometry builders
26 // (See ALIMUON*GeometryBuilder classes)
27 // To be removed later
28
29 #include <TRandom.h>
30 #include <TF1.h>
31 #include <TClonesArray.h>
32 #include <TRandom.h> 
33 #include <TVirtualMC.h>
34
35 #include "AliMUONv3.h"
36 #include "AliConst.h" 
37 #include "AliMUONChamber.h"
38 #include "AliMUONConstants.h"
39 #include "AliMUONFactory.h"
40 #include "AliMUONHit.h"
41 #include "AliMUONTriggerCircuit.h"
42 #include "AliMUONChamberGeometry.h"
43 #include "AliMagF.h"
44 #include "AliRun.h"
45 #include "AliMC.h"
46
47 ClassImp(AliMUONv3)
48  
49 //___________________________________________
50 AliMUONv3::AliMUONv3()
51  : AliMUON(),
52    fTrackMomentum(), fTrackPosition()
53 {
54 // Constructor
55     fChambers   = 0;
56     fStations   = 0;
57     fStepManagerVersionOld  = kFALSE;
58     fAngleEffect = kTRUE;
59     fStepMaxInActiveGas     = 0.6;
60     fStepSum    =  0x0;
61     fDestepSum  =  0x0;
62     fElossRatio =  0x0;
63     fAngleEffect10   = 0x0;
64     fAngleEffectNorma= 0x0;
65
66 //___________________________________________
67 AliMUONv3::AliMUONv3(const char *name, const char *title)
68   : AliMUON(name,title), 
69     fTrackMomentum(), fTrackPosition()
70 {
71 // Constructor
72     // By default include all stations
73     fStations = new Int_t[5];
74     for (Int_t i=0; i<5; i++) fStations[i] = 1;
75
76     AliMUONFactory factory;
77     factory.Build(this, title);
78
79     fStepManagerVersionOld = kFALSE;
80     fAngleEffect = kTRUE;
81     fStepMaxInActiveGas = 0.6;
82
83     fStepSum   = new Float_t [AliMUONConstants::NCh()];
84     fDestepSum = new Float_t [AliMUONConstants::NCh()];
85     for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
86       fStepSum[i] =0.0;
87       fDestepSum[i]=0.0;
88     }
89     // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
90     fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.); 
91     fElossRatio->SetParameter(0,1.02138);
92     fElossRatio->SetParameter(1,-9.54149e-02);
93     fElossRatio->SetParameter(2,+7.83433e-02); 
94     fElossRatio->SetParameter(3,-9.98208e-03);
95     fElossRatio->SetParameter(4,+3.83279e-04);
96
97     // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
98     fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
99     fAngleEffect10->SetParameter(0, 1.90691e+02);
100     fAngleEffect10->SetParameter(1,-6.62258e+01);
101     fAngleEffect10->SetParameter(2,+1.28247e+01);
102     // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)  
103     // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
104     fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
105     fAngleEffectNorma->SetParameter(0,4.148);
106     fAngleEffectNorma->SetParameter(1,-6.809e-01);
107     fAngleEffectNorma->SetParameter(2,5.151e-02);
108     fAngleEffectNorma->SetParameter(3,-1.490e-03);
109 }
110
111 //_____________________________________________________________________________
112 AliMUONv3::AliMUONv3(const AliMUONv3& right) 
113   : AliMUON(right) 
114 {  
115   // copy constructor (not implemented)
116
117   Fatal("AliMUONv3", "Copy constructor not provided.");
118 }
119
120 //_____________________________________________________________________________
121 AliMUONv3& AliMUONv3::operator=(const AliMUONv3& right)
122 {
123   // assignement operator (not implemented)
124
125   // check assignement to self
126   if (this == &right) return *this;
127
128   Fatal("operator =", "Assignement operator not provided.");
129     
130   return *this;  
131 }    
132
133 //___________________________________________
134 void AliMUONv3::CreateGeometry()
135 {
136 //
137 //   Note: all chambers have the same structure, which could be 
138 //   easily parameterised. This was intentionally not done in order
139 //   to give a starting point for the implementation of the actual 
140 //   design of each station. 
141   Int_t *idtmed = fIdtmed->GetArray()-1099;
142
143 //   Distance between Stations
144 //
145      Float_t bpar[3];
146      Float_t tpar[3];
147 //      Float_t pgpar[10];
148      Float_t zpos1, zpos2, zfpos;
149      // Outer excess and inner recess for mother volume radius
150      // with respect to ROuter and RInner
151      Float_t dframep=.001; // Value for station 3 should be 6 ...
152      // Width (RdPhi) of the frame crosses for stations 1 and 2 (cm)
153 //      Float_t dframep1=.001;
154      Float_t dframep1 = 11.0;
155 //      Bool_t frameCrosses=kFALSE;     
156      Bool_t frameCrosses=kTRUE;     
157      Float_t *dum=0;
158      
159 //      Float_t dframez=0.9;
160      // Half of the total thickness of frame crosses (including DAlu)
161      // for each chamber in stations 1 and 2:
162      // 3% of X0 of composite material,
163      // but taken as Aluminium here, with same thickness in number of X0
164      Float_t dframez = 3. * 8.9 / 100;
165 //      Float_t dr;
166      Float_t dstation;
167
168 //
169 //   Rotation matrices in the x-y plane  
170      Int_t idrotm[1199];
171 //   phi=   0 deg
172      AliMatrix(idrotm[1100],  90.,   0., 90.,  90., 0., 0.);
173 //   phi=  90 deg
174      AliMatrix(idrotm[1101],  90.,  90., 90., 180., 0., 0.);
175 //   phi= 180 deg
176      AliMatrix(idrotm[1102],  90., 180., 90., 270., 0., 0.);
177 //   phi= 270 deg
178      AliMatrix(idrotm[1103],  90., 270., 90.,   0., 0., 0.);
179 //
180      Float_t phi=2*TMath::Pi()/12/2;
181
182 //
183 //   pointer to the current chamber
184 //   pointer to the current chamber
185      Int_t idAlu1=idtmed[1103]; // medium 4
186      Int_t idAlu2=idtmed[1104]; // medium 5
187 //     Int_t idAlu1=idtmed[1100];
188 //     Int_t idAlu2=idtmed[1100];
189      Int_t idAir=idtmed[1100]; // medium 1
190 //      Int_t idGas=idtmed[1105]; // medium 6 = Ar-isoC4H10 gas
191      Int_t idGas=idtmed[1108]; // medium 9 = Ar-CO2 gas (80%+20%)
192      
193
194      AliMUONChamber *iChamber, *iChamber1, *iChamber2;
195
196      if (fStations[0]) {
197          
198 //********************************************************************
199 //                            Station 1                             **
200 //********************************************************************
201 //  CONCENTRIC
202      // indices 1 and 2 for first and second chambers in the station
203      // iChamber (first chamber) kept for other quanties than Z,
204      // assumed to be the same in both chambers
205      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[0];
206      iChamber2 =(AliMUONChamber*) (*fChambers)[1];
207      zpos1=iChamber1->Z(); 
208      zpos2=iChamber2->Z();
209      dstation = TMath::Abs(zpos2 - zpos1);
210      // DGas decreased from standard one (0.5)
211      iChamber->SetDGas(0.4); iChamber2->SetDGas(0.4);
212      // DAlu increased from standard one (3% of X0),
213      // because more electronics with smaller pads
214      iChamber->SetDAlu(3.5 * 8.9 / 100.); iChamber2->SetDAlu(3.5 * 8.9 / 100.);
215      zfpos=-(iChamber->DGas()+dframez+iChamber->DAlu())/2;
216      
217 //
218 //   Mother volume
219      tpar[0] = iChamber->RInner()-dframep; 
220      tpar[1] = (iChamber->ROuter()+dframep)/TMath::Cos(phi);
221      tpar[2] = dstation/5;
222
223      gMC->Gsvolu("S01M", "TUBE", idAir, tpar, 3);
224      gMC->Gsvolu("S02M", "TUBE", idAir, tpar, 3);
225      gMC->Gspos("S01M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
226      gMC->Gspos("S02M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");     
227 // // Aluminium frames
228 // // Outer frames
229 //      pgpar[0] = 360/12/2;
230 //      pgpar[1] = 360.;
231 //      pgpar[2] = 12.;
232 //      pgpar[3] =   2;
233 //      pgpar[4] = -dframez/2;
234 //      pgpar[5] = iChamber->ROuter();
235 //      pgpar[6] = pgpar[5]+dframep1;
236 //      pgpar[7] = +dframez/2;
237 //      pgpar[8] = pgpar[5];
238 //      pgpar[9] = pgpar[6];
239 //      gMC->Gsvolu("S01O", "PGON", idAlu1, pgpar, 10);
240 //      gMC->Gsvolu("S02O", "PGON", idAlu1, pgpar, 10);
241 //      gMC->Gspos("S01O",1,"S01M", 0.,0.,-zfpos,  0,"ONLY");
242 //      gMC->Gspos("S01O",2,"S01M", 0.,0.,+zfpos,  0,"ONLY");
243 //      gMC->Gspos("S02O",1,"S02M", 0.,0.,-zfpos,  0,"ONLY");
244 //      gMC->Gspos("S02O",2,"S02M", 0.,0.,+zfpos,  0,"ONLY");
245 // //
246 // // Inner frame
247 //      tpar[0]= iChamber->RInner()-dframep1;
248 //      tpar[1]= iChamber->RInner();
249 //      tpar[2]= dframez/2;
250 //      gMC->Gsvolu("S01I", "TUBE", idAlu1, tpar, 3);
251 //      gMC->Gsvolu("S02I", "TUBE", idAlu1, tpar, 3);
252
253 //      gMC->Gspos("S01I",1,"S01M", 0.,0.,-zfpos,  0,"ONLY");
254 //      gMC->Gspos("S01I",2,"S01M", 0.,0.,+zfpos,  0,"ONLY");
255 //      gMC->Gspos("S02I",1,"S02M", 0.,0.,-zfpos,  0,"ONLY");
256 //      gMC->Gspos("S02I",2,"S02M", 0.,0.,+zfpos,  0,"ONLY");
257 //
258 // Frame Crosses
259      if (frameCrosses) {
260          // outside gas
261          // security for inside mother volume
262          bpar[0] = (iChamber->ROuter() - iChamber->RInner())
263            * TMath::Cos(TMath::ASin(dframep1 /
264                                    (iChamber->ROuter() - iChamber->RInner())))
265            / 2.0;
266          bpar[1] = dframep1/2;
267          // total thickness will be (4 * bpar[2]) for each chamber,
268          // which has to be equal to (2 * dframez) - DAlu
269          bpar[2] = (2.0 * dframez - iChamber->DAlu()) / 4.0;
270          gMC->Gsvolu("S01B", "BOX", idAlu1, bpar, 3);
271          gMC->Gsvolu("S02B", "BOX", idAlu1, bpar, 3);
272          
273          gMC->Gspos("S01B",1,"S01M", -iChamber->RInner()-bpar[0] , 0, zfpos, 
274                     idrotm[1100],"ONLY");
275          gMC->Gspos("S01B",2,"S01M",  iChamber->RInner()+bpar[0] , 0, zfpos, 
276                     idrotm[1100],"ONLY");
277          gMC->Gspos("S01B",3,"S01M", 0, -iChamber->RInner()-bpar[0] , zfpos, 
278                     idrotm[1101],"ONLY");
279          gMC->Gspos("S01B",4,"S01M", 0,  iChamber->RInner()+bpar[0] , zfpos, 
280                     idrotm[1101],"ONLY");
281          gMC->Gspos("S01B",5,"S01M", -iChamber->RInner()-bpar[0] , 0,-zfpos, 
282                     idrotm[1100],"ONLY");
283          gMC->Gspos("S01B",6,"S01M", +iChamber->RInner()+bpar[0] , 0,-zfpos, 
284                     idrotm[1100],"ONLY");
285          gMC->Gspos("S01B",7,"S01M", 0, -iChamber->RInner()-bpar[0] ,-zfpos, 
286                     idrotm[1101],"ONLY");
287          gMC->Gspos("S01B",8,"S01M", 0, +iChamber->RInner()+bpar[0] ,-zfpos, 
288                     idrotm[1101],"ONLY");
289          
290          gMC->Gspos("S02B",1,"S02M", -iChamber->RInner()-bpar[0] , 0, zfpos, 
291                     idrotm[1100],"ONLY");
292          gMC->Gspos("S02B",2,"S02M",  iChamber->RInner()+bpar[0] , 0, zfpos, 
293                     idrotm[1100],"ONLY");
294          gMC->Gspos("S02B",3,"S02M", 0, -iChamber->RInner()-bpar[0] , zfpos, 
295                     idrotm[1101],"ONLY");
296          gMC->Gspos("S02B",4,"S02M", 0,  iChamber->RInner()+bpar[0] , zfpos, 
297                     idrotm[1101],"ONLY");
298          gMC->Gspos("S02B",5,"S02M", -iChamber->RInner()-bpar[0] , 0,-zfpos, 
299                     idrotm[1100],"ONLY");
300          gMC->Gspos("S02B",6,"S02M", +iChamber->RInner()+bpar[0] , 0,-zfpos, 
301                     idrotm[1100],"ONLY");
302          gMC->Gspos("S02B",7,"S02M", 0, -iChamber->RInner()-bpar[0] ,-zfpos, 
303                     idrotm[1101],"ONLY");
304          gMC->Gspos("S02B",8,"S02M", 0, +iChamber->RInner()+bpar[0] ,-zfpos, 
305                     idrotm[1101],"ONLY");
306      }
307 //
308 //   Chamber Material represented by Alu sheet
309      tpar[0]= iChamber->RInner();
310      tpar[1]= iChamber->ROuter();
311      tpar[2] = (iChamber->DGas()+iChamber->DAlu())/2;
312      gMC->Gsvolu("S01A", "TUBE",  idAlu2, tpar, 3);
313      gMC->Gsvolu("S02A", "TUBE",idAlu2, tpar, 3);
314      gMC->Gspos("S01A", 1, "S01M", 0., 0., 0.,  0, "ONLY");
315      gMC->Gspos("S02A", 1, "S02M", 0., 0., 0.,  0, "ONLY");
316 //     
317 //   Sensitive volumes
318      // tpar[2] = iChamber->DGas();
319      tpar[2] = iChamber->DGas()/2;
320      gMC->Gsvolu("S01G", "TUBE", idGas, tpar, 3);
321      gMC->Gsvolu("S02G", "TUBE", idGas, tpar, 3);
322      gMC->Gspos("S01G", 1, "S01A", 0., 0., 0.,  0, "ONLY");
323      gMC->Gspos("S02G", 1, "S02A", 0., 0., 0.,  0, "ONLY");
324 //
325 // Frame Crosses to be placed inside gas
326      // NONE: chambers are sensitive everywhere
327 //      if (frameCrosses) {
328
329 //       dr = (iChamber->ROuter() - iChamber->RInner());
330 //       bpar[0] = TMath::Sqrt(dr*dr-dframep1*dframep1/4)/2;
331 //       bpar[1] = dframep1/2;
332 //       bpar[2] = iChamber->DGas()/2;
333 //       gMC->Gsvolu("S01F", "BOX", idAlu1, bpar, 3);
334 //       gMC->Gsvolu("S02F", "BOX", idAlu1, bpar, 3);
335          
336 //       gMC->Gspos("S01F",1,"S01G", +iChamber->RInner()+bpar[0] , 0, 0, 
337 //                  idrotm[1100],"ONLY");
338 //       gMC->Gspos("S01F",2,"S01G", -iChamber->RInner()-bpar[0] , 0, 0, 
339 //                  idrotm[1100],"ONLY");
340 //       gMC->Gspos("S01F",3,"S01G", 0, +iChamber->RInner()+bpar[0] , 0, 
341 //                  idrotm[1101],"ONLY");
342 //       gMC->Gspos("S01F",4,"S01G", 0, -iChamber->RInner()-bpar[0] , 0, 
343 //                  idrotm[1101],"ONLY");
344          
345 //       gMC->Gspos("S02F",1,"S02G", +iChamber->RInner()+bpar[0] , 0, 0, 
346 //                  idrotm[1100],"ONLY");
347 //       gMC->Gspos("S02F",2,"S02G", -iChamber->RInner()-bpar[0] , 0, 0, 
348 //                  idrotm[1100],"ONLY");
349 //       gMC->Gspos("S02F",3,"S02G", 0, +iChamber->RInner()+bpar[0] , 0, 
350 //                  idrotm[1101],"ONLY");
351 //       gMC->Gspos("S02F",4,"S02G", 0, -iChamber->RInner()-bpar[0] , 0, 
352 //                  idrotm[1101],"ONLY");
353 //      }
354      }
355      if (fStations[1]) {
356          
357 //********************************************************************
358 //                            Station 2                             **
359 //********************************************************************
360      // indices 1 and 2 for first and second chambers in the station
361      // iChamber (first chamber) kept for other quanties than Z,
362      // assumed to be the same in both chambers
363      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[2];
364      iChamber2 =(AliMUONChamber*) (*fChambers)[3];
365      zpos1=iChamber1->Z(); 
366      zpos2=iChamber2->Z();
367      dstation = TMath::Abs(zpos2 - zpos1);
368      // DGas and DAlu not changed from standard values
369      zfpos=-(iChamber->DGas()+dframez+iChamber->DAlu())/2;
370      
371 //
372 //   Mother volume
373      tpar[0] = iChamber->RInner()-dframep; 
374      tpar[1] = (iChamber->ROuter()+dframep)/TMath::Cos(phi);
375      tpar[2] = dstation/5;
376
377      gMC->Gsvolu("S03M", "TUBE", idAir, tpar, 3);
378      gMC->Gsvolu("S04M", "TUBE", idAir, tpar, 3);
379      gMC->Gspos("S03M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
380      gMC->Gspos("S04M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");
381      gMC->Gsbool("S03M", "L3DO");
382      gMC->Gsbool("S03M", "L3O1");
383      gMC->Gsbool("S03M", "L3O2");
384      gMC->Gsbool("S04M", "L3DO");
385      gMC->Gsbool("S04M", "L3O1");
386      gMC->Gsbool("S04M", "L3O2");
387
388 // // Aluminium frames
389 // // Outer frames
390 //      pgpar[0] = 360/12/2;
391 //      pgpar[1] = 360.;
392 //      pgpar[2] = 12.;
393 //      pgpar[3] =   2;
394 //      pgpar[4] = -dframez/2;
395 //      pgpar[5] = iChamber->ROuter();
396 //      pgpar[6] = pgpar[5]+dframep;
397 //      pgpar[7] = +dframez/2;
398 //      pgpar[8] = pgpar[5];
399 //      pgpar[9] = pgpar[6];
400 //      gMC->Gsvolu("S03O", "PGON", idAlu1, pgpar, 10);
401 //      gMC->Gsvolu("S04O", "PGON", idAlu1, pgpar, 10);
402 //      gMC->Gspos("S03O",1,"S03M", 0.,0.,-zfpos,  0,"ONLY");
403 //      gMC->Gspos("S03O",2,"S03M", 0.,0.,+zfpos,  0,"ONLY");
404 //      gMC->Gspos("S04O",1,"S04M", 0.,0.,-zfpos,  0,"ONLY");
405 //      gMC->Gspos("S04O",2,"S04M", 0.,0.,+zfpos,  0,"ONLY");
406 // //
407 // // Inner frame
408 //      tpar[0]= iChamber->RInner()-dframep;
409 //      tpar[1]= iChamber->RInner();
410 //      tpar[2]= dframez/2;
411 //      gMC->Gsvolu("S03I", "TUBE", idAlu1, tpar, 3);
412 //      gMC->Gsvolu("S04I", "TUBE", idAlu1, tpar, 3);
413
414 //      gMC->Gspos("S03I",1,"S03M", 0.,0.,-zfpos,  0,"ONLY");
415 //      gMC->Gspos("S03I",2,"S03M", 0.,0.,+zfpos,  0,"ONLY");
416 //      gMC->Gspos("S04I",1,"S04M", 0.,0.,-zfpos,  0,"ONLY");
417 //      gMC->Gspos("S04I",2,"S04M", 0.,0.,+zfpos,  0,"ONLY");
418 //
419 // Frame Crosses
420      if (frameCrosses) {
421          // outside gas
422          // security for inside mother volume
423          bpar[0] = (iChamber->ROuter() - iChamber->RInner())
424            * TMath::Cos(TMath::ASin(dframep1 /
425                                    (iChamber->ROuter() - iChamber->RInner())))
426            / 2.0;
427          bpar[1] = dframep1/2;
428          // total thickness will be (4 * bpar[2]) for each chamber,
429          // which has to be equal to (2 * dframez) - DAlu
430          bpar[2] = (2.0 * dframez - iChamber->DAlu()) / 4.0;
431          gMC->Gsvolu("S03B", "BOX", idAlu1, bpar, 3);
432          gMC->Gsvolu("S04B", "BOX", idAlu1, bpar, 3);
433          
434          gMC->Gspos("S03B",1,"S03M", -iChamber->RInner()-bpar[0] , 0, zfpos, 
435                     idrotm[1100],"ONLY");
436          gMC->Gspos("S03B",2,"S03M", +iChamber->RInner()+bpar[0] , 0, zfpos, 
437                     idrotm[1100],"ONLY");
438          gMC->Gspos("S03B",3,"S03M", 0, -iChamber->RInner()-bpar[0] , zfpos, 
439                     idrotm[1101],"ONLY");
440          gMC->Gspos("S03B",4,"S03M", 0, +iChamber->RInner()+bpar[0] , zfpos, 
441                     idrotm[1101],"ONLY");
442          gMC->Gspos("S03B",5,"S03M", -iChamber->RInner()-bpar[0] , 0,-zfpos, 
443                     idrotm[1100],"ONLY");
444          gMC->Gspos("S03B",6,"S03M", +iChamber->RInner()+bpar[0] , 0,-zfpos, 
445                     idrotm[1100],"ONLY");
446          gMC->Gspos("S03B",7,"S03M", 0, -iChamber->RInner()-bpar[0] ,-zfpos, 
447                     idrotm[1101],"ONLY");
448          gMC->Gspos("S03B",8,"S03M", 0, +iChamber->RInner()+bpar[0] ,-zfpos, 
449                     idrotm[1101],"ONLY");
450          
451          gMC->Gspos("S04B",1,"S04M", -iChamber->RInner()-bpar[0] , 0, zfpos, 
452                     idrotm[1100],"ONLY");
453          gMC->Gspos("S04B",2,"S04M", +iChamber->RInner()+bpar[0] , 0, zfpos, 
454                     idrotm[1100],"ONLY");
455          gMC->Gspos("S04B",3,"S04M", 0, -iChamber->RInner()-bpar[0] , zfpos, 
456                     idrotm[1101],"ONLY");
457          gMC->Gspos("S04B",4,"S04M", 0, +iChamber->RInner()+bpar[0] , zfpos, 
458                     idrotm[1101],"ONLY");
459          gMC->Gspos("S04B",5,"S04M", -iChamber->RInner()-bpar[0] , 0,-zfpos, 
460                     idrotm[1100],"ONLY");
461          gMC->Gspos("S04B",6,"S04M", +iChamber->RInner()+bpar[0] , 0,-zfpos, 
462                     idrotm[1100],"ONLY");
463          gMC->Gspos("S04B",7,"S04M", 0, -iChamber->RInner()-bpar[0] ,-zfpos, 
464                     idrotm[1101],"ONLY");
465          gMC->Gspos("S04B",8,"S04M", 0, +iChamber->RInner()+bpar[0] ,-zfpos, 
466                     idrotm[1101],"ONLY");
467      }
468 //
469 //   Chamber Material represented by Alu sheet
470      tpar[0]= iChamber->RInner();
471      tpar[1]= iChamber->ROuter();
472      tpar[2] = (iChamber->DGas()+iChamber->DAlu())/2;
473      gMC->Gsvolu("S03A", "TUBE", idAlu2, tpar, 3);
474      gMC->Gsvolu("S04A", "TUBE", idAlu2, tpar, 3);
475      gMC->Gspos("S03A", 1, "S03M", 0., 0., 0.,  0, "ONLY");
476      gMC->Gspos("S04A", 1, "S04M", 0., 0., 0.,  0, "ONLY");
477 //     
478 //   Sensitive volumes
479      // tpar[2] = iChamber->DGas();
480      tpar[2] = iChamber->DGas()/2;
481      gMC->Gsvolu("S03G", "TUBE", idGas, tpar, 3);
482      gMC->Gsvolu("S04G", "TUBE", idGas, tpar, 3);
483      gMC->Gspos("S03G", 1, "S03A", 0., 0., 0.,  0, "ONLY");
484      gMC->Gspos("S04G", 1, "S04A", 0., 0., 0.,  0, "ONLY");
485 //
486 // Frame Crosses to be placed inside gas 
487      // NONE: chambers are sensitive everywhere
488 //      if (frameCrosses) {
489
490 //       dr = (iChamber->ROuter() - iChamber->RInner());
491 //       bpar[0] = TMath::Sqrt(dr*dr-dframep1*dframep1/4)/2;
492 //       bpar[1] = dframep1/2;
493 //       bpar[2] = iChamber->DGas()/2;
494 //       gMC->Gsvolu("S03F", "BOX", idAlu1, bpar, 3);
495 //       gMC->Gsvolu("S04F", "BOX", idAlu1, bpar, 3);
496          
497 //       gMC->Gspos("S03F",1,"S03G", +iChamber->RInner()+bpar[0] , 0, 0, 
498 //                  idrotm[1100],"ONLY");
499 //       gMC->Gspos("S03F",2,"S03G", -iChamber->RInner()-bpar[0] , 0, 0, 
500 //                  idrotm[1100],"ONLY");
501 //       gMC->Gspos("S03F",3,"S03G", 0, +iChamber->RInner()+bpar[0] , 0, 
502 //                  idrotm[1101],"ONLY");
503 //       gMC->Gspos("S03F",4,"S03G", 0, -iChamber->RInner()-bpar[0] , 0, 
504 //                  idrotm[1101],"ONLY");
505          
506 //       gMC->Gspos("S04F",1,"S04G", +iChamber->RInner()+bpar[0] , 0, 0, 
507 //                  idrotm[1100],"ONLY");
508 //       gMC->Gspos("S04F",2,"S04G", -iChamber->RInner()-bpar[0] , 0, 0, 
509 //                  idrotm[1100],"ONLY");
510 //       gMC->Gspos("S04F",3,"S04G", 0, +iChamber->RInner()+bpar[0] , 0, 
511 //                  idrotm[1101],"ONLY");
512 //       gMC->Gspos("S04F",4,"S04G", 0, -iChamber->RInner()-bpar[0] , 0, 
513 //                  idrotm[1101],"ONLY");
514 //      }
515      }
516      // define the id of tracking media:
517      Int_t idCopper = idtmed[1110];
518      Int_t idGlass  = idtmed[1111];
519      Int_t idCarbon = idtmed[1112];
520      Int_t idRoha   = idtmed[1113];
521
522       // sensitive area: 40*40 cm**2
523      const Float_t ksensLength = 40.; 
524      const Float_t ksensHeight = 40.; 
525      const Float_t ksensWidth  = 0.5; // according to TDR fig 2.120 
526      const Int_t ksensMaterial = idGas;
527      const Float_t kyOverlap   = 1.5; 
528
529      // PCB dimensions in cm; width: 30 mum copper   
530      const Float_t kpcbLength  = ksensLength; 
531      const Float_t kpcbHeight  = 60.; 
532      const Float_t kpcbWidth   = 0.003;   
533      const Int_t   kpcbMaterial= idCopper;
534
535      // Insulating material: 200 mum glass fiber glued to pcb  
536      const Float_t kinsuLength = kpcbLength; 
537      const Float_t kinsuHeight = kpcbHeight; 
538      const Float_t kinsuWidth  = 0.020;   
539      const Int_t kinsuMaterial = idGlass;
540
541      // Carbon fiber panels: 200mum carbon/epoxy skin   
542      const Float_t kpanelLength = ksensLength; 
543      const Float_t kpanelHeight = ksensHeight; 
544      const Float_t kpanelWidth  = 0.020;      
545      const Int_t kpanelMaterial = idCarbon;
546
547      // rohacell between the two carbon panels   
548      const Float_t krohaLength = ksensLength; 
549      const Float_t krohaHeight = ksensHeight; 
550      const Float_t krohaWidth  = 0.5;
551      const Int_t krohaMaterial = idRoha;
552
553      // Frame around the slat: 2 sticks along length,2 along height  
554      // H: the horizontal ones 
555      const Float_t khFrameLength = kpcbLength; 
556      const Float_t khFrameHeight = 1.5; 
557      const Float_t khFrameWidth  = ksensWidth; 
558      const Int_t khFrameMaterial = idGlass;
559
560      // V: the vertical ones 
561      const Float_t kvFrameLength = 4.0; 
562      const Float_t kvFrameHeight = ksensHeight + khFrameHeight; 
563      const Float_t kvFrameWidth  = ksensWidth;
564      const Int_t kvFrameMaterial = idGlass;
565
566      // B: the horizontal border filled with rohacell 
567      const Float_t kbFrameLength = khFrameLength; 
568      const Float_t kbFrameHeight = (kpcbHeight - ksensHeight)/2. - khFrameHeight; 
569      const Float_t kbFrameWidth  = khFrameWidth;
570      const Int_t kbFrameMaterial = idRoha;
571
572      // NULOC: 30 mum copper + 200 mum vetronite (same radiation length as 14mum copper)
573      const Float_t knulocLength = 2.5; 
574      const Float_t knulocHeight = 7.5; 
575      const Float_t knulocWidth  = 0.0030 + 0.0014; // equivalent copper width of vetronite; 
576      const Int_t   knulocMaterial = idCopper;
577
578      const Float_t kslatHeight = kpcbHeight; 
579      const Float_t kslatWidth = ksensWidth + 2.*(kpcbWidth + kinsuWidth + 
580                                                2.* kpanelWidth + krohaWidth);
581      const Int_t kslatMaterial = idAir;
582      const Float_t kdSlatLength = kvFrameLength; // border on left and right 
583
584      Float_t spar[3];  
585      Int_t i, j;
586
587      // the panel volume contains the rohacell
588
589      Float_t twidth = 2 * kpanelWidth + krohaWidth; 
590      Float_t panelpar[3] = { kpanelLength/2., kpanelHeight/2., twidth/2. }; 
591      Float_t rohapar[3] = { krohaLength/2., krohaHeight/2., krohaWidth/2. }; 
592
593      // insulating material contains PCB-> gas-> 2 borders filled with rohacell
594
595      twidth = 2*(kinsuWidth + kpcbWidth) + ksensWidth;  
596      Float_t insupar[3] = { kinsuLength/2., kinsuHeight/2., twidth/2. }; 
597      twidth -= 2 * kinsuWidth; 
598      Float_t pcbpar[3] = { kpcbLength/2., kpcbHeight/2., twidth/2. }; 
599      Float_t senspar[3] = { ksensLength/2., ksensHeight/2., ksensWidth/2. }; 
600      Float_t theight = 2*khFrameHeight + ksensHeight;
601      Float_t hFramepar[3]={khFrameLength/2., theight/2., khFrameWidth/2.}; 
602      Float_t bFramepar[3]={kbFrameLength/2., kbFrameHeight/2., kbFrameWidth/2.}; 
603      Float_t vFramepar[3]={kvFrameLength/2., kvFrameHeight/2., kvFrameWidth/2.}; 
604      Float_t nulocpar[3]={knulocLength/2., knulocHeight/2., knulocWidth/2.}; 
605      Float_t xx;
606      Float_t xxmax = (kbFrameLength - knulocLength)/2.; 
607      Int_t index=0;
608      
609      if (fStations[2]) {
610          
611 //********************************************************************
612 //                            Station 3                             **
613 //********************************************************************
614      // indices 1 and 2 for first and second chambers in the station
615      // iChamber (first chamber) kept for other quanties than Z,
616      // assumed to be the same in both chambers
617      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[4];
618      iChamber2 =(AliMUONChamber*) (*fChambers)[5];
619      zpos1=iChamber1->Z(); 
620      zpos2=iChamber2->Z();
621      dstation = TMath::Abs(zpos2 - zpos1);
622
623 //
624 //   Mother volume
625      tpar[0] = iChamber->RInner()-dframep; 
626      tpar[1] = (iChamber->ROuter()+dframep)/TMath::Cos(phi);
627      tpar[2] = dstation/5;
628
629      const char *slats5Mother = "S05M";
630      const char *slats6Mother = "S06M";
631      Float_t zoffs5 = 0;
632      Float_t zoffs6 = 0;
633
634      if (gAlice->GetModule("DIPO")) {
635        slats5Mother="DDIP";
636        slats6Mother="DDIP";
637
638        zoffs5 = TMath::Abs(zpos1);
639        zoffs6 = TMath::Abs(zpos2);
640      }
641
642      else {
643        gMC->Gsvolu("S05M", "TUBE", idAir, tpar, 3);
644        gMC->Gsvolu("S06M", "TUBE", idAir, tpar, 3);
645        gMC->Gspos("S05M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
646        gMC->Gspos("S06M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");
647      }
648
649      // volumes for slat geometry (xx=5,..,10 chamber id): 
650      // Sxx0 Sxx1 Sxx2 Sxx3  -->   Slat Mother volumes 
651      // SxxG                          -->   Sensitive volume (gas)
652      // SxxP                          -->   PCB (copper) 
653      // SxxI                          -->   Insulator (vetronite) 
654      // SxxC                          -->   Carbon panel 
655      // SxxR                          -->   Rohacell
656      // SxxH, SxxV                    -->   Horizontal and Vertical frames (vetronite)
657      // SB5x                          -->   Volumes for the 35 cm long PCB
658      // slat dimensions: slat is a MOTHER volume!!! made of air
659
660      // only for chamber 5: slat 1 has a PCB shorter by 5cm!
661
662      Float_t tlength = 35.;
663      Float_t panelpar2[3]  = { tlength/2., panelpar[1],  panelpar[2]}; 
664      Float_t rohapar2[3]   = { tlength/2., rohapar[1],   rohapar[2]}; 
665      Float_t insupar2[3]   = { tlength/2., insupar[1],   insupar[2]}; 
666      Float_t pcbpar2[3]    = { tlength/2., pcbpar[1],    pcbpar[2]}; 
667      Float_t senspar2[3]   = { tlength/2., senspar[1],   senspar[2]}; 
668      Float_t hFramepar2[3] = { tlength/2., hFramepar[1], hFramepar[2]}; 
669      Float_t bFramepar2[3] = { tlength/2., bFramepar[1], bFramepar[2]}; 
670
671      const Int_t knSlats3 = 5;  // number of slats per quadrant
672      const Int_t knPCB3[knSlats3] = {3,3,4,3,2}; // n PCB per slat
673      const Float_t kxpos3[knSlats3] = {31., 40., 0., 0., 0.};
674      Float_t slatLength3[knSlats3]; 
675
676      // create and position the slat (mother) volumes 
677
678      char volNam5[5];
679      char volNam6[5];
680      Float_t xSlat3;
681
682      Float_t spar2[3];
683      for (i = 0; i<knSlats3; i++){
684        slatLength3[i] = kpcbLength * knPCB3[i] + 2. * kdSlatLength; 
685        xSlat3 = slatLength3[i]/2. - kvFrameLength/2. + kxpos3[i]; 
686        if (i==1 || i==0) slatLength3[i] -=  2. *kdSlatLength; // frame out in PCB with circular border 
687        Float_t ySlat31 =  ksensHeight * i - kyOverlap * i; 
688        Float_t ySlat32 = -ksensHeight * i + kyOverlap * i; 
689        spar[0] = slatLength3[i]/2.; 
690        spar[1] = kslatHeight/2.;
691        spar[2] = kslatWidth/2. * 1.01; 
692        // take away 5 cm from the first slat in chamber 5
693        Float_t xSlat32 = 0;
694        if (i==1 || i==2) { // 1 pcb is shortened by 5cm
695          spar2[0] = spar[0]-5./2.;
696          xSlat32 = xSlat3 - 5/2.;
697        }
698        else {
699          spar2[0] = spar[0];
700          xSlat32 = xSlat3;
701        }
702        spar2[1] = spar[1];
703        spar2[2] = spar[2]; 
704        Float_t dzCh3=spar[2] * 1.01;
705        // zSlat to be checked (odd downstream or upstream?)
706        Float_t zSlat = (i%2 ==0)? -spar[2] : spar[2];
707
708         if (gAlice->GetModule("DIPO")) {zSlat*=-1.;}
709
710        sprintf(volNam5,"S05%d",i);
711        gMC->Gsvolu(volNam5,"BOX",kslatMaterial,spar2,3);
712        gMC->Gspos(volNam5, i*4+1,slats5Mother, -xSlat32, ySlat31, zoffs5-zSlat-2.*dzCh3, 0, "ONLY");
713        gMC->Gspos(volNam5, i*4+2,slats5Mother, +xSlat32, ySlat31, zoffs5-zSlat+2.*dzCh3, 0, "ONLY");
714        
715         if (i>0) { 
716          gMC->Gspos(volNam5, i*4+3,slats5Mother,-xSlat32, ySlat32, zoffs5-zSlat-2.*dzCh3, 0, "ONLY");
717          gMC->Gspos(volNam5, i*4+4,slats5Mother,+xSlat32, ySlat32, zoffs5-zSlat+2.*dzCh3, 0, "ONLY");
718        }
719        sprintf(volNam6,"S06%d",i);
720        gMC->Gsvolu(volNam6,"BOX",kslatMaterial,spar,3);
721        gMC->Gspos(volNam6, i*4+1,slats6Mother,-xSlat3, ySlat31, zoffs6-zSlat-2.*dzCh3, 0, "ONLY");
722        gMC->Gspos(volNam6, i*4+2,slats6Mother,+xSlat3, ySlat31, zoffs6-zSlat+2.*dzCh3, 0, "ONLY");
723        if (i>0) { 
724          gMC->Gspos(volNam6, i*4+3,slats6Mother,-xSlat3, ySlat32, zoffs6-zSlat-2.*dzCh3, 0, "ONLY");
725          gMC->Gspos(volNam6, i*4+4,slats6Mother,+xSlat3, ySlat32, zoffs6-zSlat+2.*dzCh3, 0, "ONLY");
726        }
727      }
728
729      // create the panel volume 
730  
731      gMC->Gsvolu("S05C","BOX",kpanelMaterial,panelpar,3);
732      gMC->Gsvolu("SB5C","BOX",kpanelMaterial,panelpar2,3);
733      gMC->Gsvolu("S06C","BOX",kpanelMaterial,panelpar,3);
734
735      // create the rohacell volume 
736
737      gMC->Gsvolu("S05R","BOX",krohaMaterial,rohapar,3);
738      gMC->Gsvolu("SB5R","BOX",krohaMaterial,rohapar2,3);
739      gMC->Gsvolu("S06R","BOX",krohaMaterial,rohapar,3);
740
741      // create the insulating material volume 
742
743      gMC->Gsvolu("S05I","BOX",kinsuMaterial,insupar,3);
744      gMC->Gsvolu("SB5I","BOX",kinsuMaterial,insupar2,3);
745      gMC->Gsvolu("S06I","BOX",kinsuMaterial,insupar,3);
746
747      // create the PCB volume 
748
749      gMC->Gsvolu("S05P","BOX",kpcbMaterial,pcbpar,3);
750      gMC->Gsvolu("SB5P","BOX",kpcbMaterial,pcbpar2,3);
751      gMC->Gsvolu("S06P","BOX",kpcbMaterial,pcbpar,3);
752  
753      // create the sensitive volumes,
754      gMC->Gsvolu("S05G","BOX",ksensMaterial,dum,0);
755      gMC->Gsvolu("S06G","BOX",ksensMaterial,dum,0);
756
757
758      // create the vertical frame volume 
759
760      gMC->Gsvolu("S05V","BOX",kvFrameMaterial,vFramepar,3);
761      gMC->Gsvolu("S06V","BOX",kvFrameMaterial,vFramepar,3);
762
763      // create the horizontal frame volume 
764
765      gMC->Gsvolu("S05H","BOX",khFrameMaterial,hFramepar,3);
766      gMC->Gsvolu("SB5H","BOX",khFrameMaterial,hFramepar2,3);
767      gMC->Gsvolu("S06H","BOX",khFrameMaterial,hFramepar,3);
768
769      // create the horizontal border volume 
770
771      gMC->Gsvolu("S05B","BOX",kbFrameMaterial,bFramepar,3);
772      gMC->Gsvolu("SB5B","BOX",kbFrameMaterial,bFramepar2,3);
773      gMC->Gsvolu("S06B","BOX",kbFrameMaterial,bFramepar,3);
774
775      index=0; 
776      for (i = 0; i<knSlats3; i++){
777        sprintf(volNam5,"S05%d",i);
778        sprintf(volNam6,"S06%d",i);
779        Float_t xvFrame  = (slatLength3[i] - kvFrameLength)/2.;
780        Float_t xvFrame2  = xvFrame;
781        if ( i==1 || i ==2 ) xvFrame2 -= 5./2.;
782        // position the vertical frames 
783        if (i!=1 && i!=0) { 
784          gMC->Gspos("S05V",2*i-1,volNam5, xvFrame2, 0., 0. , 0, "ONLY");
785          gMC->Gspos("S05V",2*i  ,volNam5,-xvFrame2, 0., 0. , 0, "ONLY");
786          gMC->Gspos("S06V",2*i-1,volNam6, xvFrame, 0., 0. , 0, "ONLY");
787          gMC->Gspos("S06V",2*i  ,volNam6,-xvFrame, 0., 0. , 0, "ONLY");
788        }       
789        // position the panels and the insulating material 
790        for (j=0; j<knPCB3[i]; j++){
791          index++;
792          Float_t xx = ksensLength * (-knPCB3[i]/2.+j+.5); 
793          Float_t xx2 = xx + 5/2.; 
794          
795          Float_t zPanel = spar[2] - panelpar[2]; 
796          if ( (i==1 || i==2) && j == knPCB3[i]-1) { // 1 pcb is shortened by 5cm 
797            gMC->Gspos("SB5C",2*index-1,volNam5, xx, 0., zPanel , 0, "ONLY");
798            gMC->Gspos("SB5C",2*index  ,volNam5, xx, 0.,-zPanel , 0, "ONLY");
799            gMC->Gspos("SB5I",index    ,volNam5, xx, 0., 0      , 0, "ONLY");
800          }
801          else if ( (i==1 || i==2) && j < knPCB3[i]-1) {
802            gMC->Gspos("S05C",2*index-1,volNam5, xx2, 0., zPanel , 0, "ONLY");
803            gMC->Gspos("S05C",2*index  ,volNam5, xx2, 0.,-zPanel , 0, "ONLY");
804            gMC->Gspos("S05I",index    ,volNam5, xx2, 0., 0 , 0, "ONLY");
805          }
806          else {
807            gMC->Gspos("S05C",2*index-1,volNam5, xx, 0., zPanel , 0, "ONLY");
808            gMC->Gspos("S05C",2*index  ,volNam5, xx, 0.,-zPanel , 0, "ONLY");
809            gMC->Gspos("S05I",index    ,volNam5, xx, 0., 0 , 0, "ONLY");
810          }
811          gMC->Gspos("S06C",2*index-1,volNam6, xx, 0., zPanel , 0, "ONLY");
812          gMC->Gspos("S06C",2*index  ,volNam6, xx, 0.,-zPanel , 0, "ONLY");
813          gMC->Gspos("S06I",index,volNam6, xx, 0., 0 , 0, "ONLY");
814        } 
815      }
816      
817      // position the rohacell volume inside the panel volume
818      gMC->Gspos("S05R",1,"S05C",0.,0.,0.,0,"ONLY"); 
819      gMC->Gspos("SB5R",1,"SB5C",0.,0.,0.,0,"ONLY"); 
820      gMC->Gspos("S06R",1,"S06C",0.,0.,0.,0,"ONLY"); 
821
822      // position the PCB volume inside the insulating material volume
823      gMC->Gspos("S05P",1,"S05I",0.,0.,0.,0,"ONLY"); 
824      gMC->Gspos("SB5P",1,"SB5I",0.,0.,0.,0,"ONLY"); 
825      gMC->Gspos("S06P",1,"S06I",0.,0.,0.,0,"ONLY"); 
826      // position the horizontal frame volume inside the PCB volume
827      gMC->Gspos("S05H",1,"S05P",0.,0.,0.,0,"ONLY"); 
828      gMC->Gspos("SB5H",1,"SB5P",0.,0.,0.,0,"ONLY"); 
829      gMC->Gspos("S06H",1,"S06P",0.,0.,0.,0,"ONLY"); 
830      // position the sensitive volume inside the horizontal frame volume
831      gMC->Gsposp("S05G",1,"S05H",0.,0.,0.,0,"ONLY",senspar,3); 
832      gMC->Gsposp("S05G",1,"SB5H",0.,0.,0.,0,"ONLY",senspar2,3); 
833      gMC->Gsposp("S06G",1,"S06H",0.,0.,0.,0,"ONLY",senspar,3); 
834      // position the border volumes inside the PCB volume
835      Float_t yborder = ( kpcbHeight - kbFrameHeight ) / 2.; 
836      gMC->Gspos("S05B",1,"S05P",0., yborder,0.,0,"ONLY"); 
837      gMC->Gspos("S05B",2,"S05P",0.,-yborder,0.,0,"ONLY"); 
838      gMC->Gspos("SB5B",1,"SB5P",0., yborder,0.,0,"ONLY"); 
839      gMC->Gspos("SB5B",2,"SB5P",0.,-yborder,0.,0,"ONLY"); 
840      gMC->Gspos("S06B",1,"S06P",0., yborder,0.,0,"ONLY"); 
841      gMC->Gspos("S06B",2,"S06P",0.,-yborder,0.,0,"ONLY"); 
842
843      // create the NULOC volume and position it in the horizontal frame
844
845      gMC->Gsvolu("S05N","BOX",knulocMaterial,nulocpar,3);
846      gMC->Gsvolu("S06N","BOX",knulocMaterial,nulocpar,3);
847      index = 0;
848      Float_t xxmax2 = xxmax - 5./2.;
849      for (xx = -xxmax; xx<=xxmax; xx+=2*knulocLength) { 
850        index++; 
851        gMC->Gspos("S05N",2*index-1,"S05B", xx, 0.,-kbFrameWidth/4., 0, "ONLY");
852        gMC->Gspos("S05N",2*index  ,"S05B", xx, 0., kbFrameWidth/4., 0, "ONLY");
853        if (xx > -xxmax2 && xx< xxmax2) {
854          gMC->Gspos("S05N",2*index-1,"SB5B", xx, 0.,-kbFrameWidth/4., 0, "ONLY");
855          gMC->Gspos("S05N",2*index  ,"SB5B", xx, 0., kbFrameWidth/4., 0, "ONLY");
856        }
857        gMC->Gspos("S06N",2*index-1,"S06B", xx, 0.,-kbFrameWidth/4., 0, "ONLY");
858        gMC->Gspos("S06N",2*index  ,"S06B", xx, 0., kbFrameWidth/4., 0, "ONLY");
859      }
860      
861      // position the volumes approximating the circular section of the pipe
862      Float_t yoffs = ksensHeight/2. - kyOverlap; 
863      Float_t epsilon = 0.001; 
864      Int_t ndiv=6;
865      Float_t divpar[3];
866      Double_t dydiv= ksensHeight/ndiv;
867      Double_t ydiv = yoffs -dydiv;
868      Int_t imax=0; 
869      imax = 1; 
870      Float_t rmin = 33.; 
871      Float_t z1 = spar[2], z2=2*spar[2]*1.01; 
872      if (gAlice->GetModule("DIPO")) {z1*=-1.;}
873      for (Int_t idiv=0;idiv<ndiv; idiv++){ 
874        ydiv+= dydiv;
875        Float_t xdiv = 0.; 
876        if (ydiv<rmin) xdiv= rmin * TMath::Sin( TMath::ACos(ydiv/rmin) );
877        divpar[0] = (kpcbLength-xdiv)/2.; 
878        divpar[1] = dydiv/2. - epsilon;
879        divpar[2] = ksensWidth/2.; 
880        Float_t xvol=(kpcbLength+xdiv)/2.+1.999;
881        Float_t yvol=ydiv + dydiv/2.; 
882        //printf ("y ll = %f y ur = %f \n",yvol - divpar[1], yvol + divpar[1]); 
883        gMC->Gsposp("S05G",imax+4*idiv+1,slats5Mother,-xvol, yvol, zoffs5-z1-z2, 0, "ONLY",divpar,3);
884        gMC->Gsposp("S06G",imax+4*idiv+1,slats6Mother,-xvol, yvol, zoffs6-z1-z2, 0, "ONLY",divpar,3);
885        gMC->Gsposp("S05G",imax+4*idiv+2,slats5Mother,-xvol,-yvol, zoffs5-z1-z2, 0, "ONLY",divpar,3);
886        gMC->Gsposp("S06G",imax+4*idiv+2,slats6Mother,-xvol,-yvol, zoffs6-z1-z2, 0, "ONLY",divpar,3);
887        gMC->Gsposp("S05G",imax+4*idiv+3,slats5Mother,+xvol, yvol, zoffs5-z1+z2, 0, "ONLY",divpar,3);
888        gMC->Gsposp("S06G",imax+4*idiv+3,slats6Mother,+xvol, yvol, zoffs6-z1+z2, 0, "ONLY",divpar,3);
889        gMC->Gsposp("S05G",imax+4*idiv+4,slats5Mother,+xvol,-yvol, zoffs5-z1+z2, 0, "ONLY",divpar,3);
890        gMC->Gsposp("S06G",imax+4*idiv+4,slats6Mother,+xvol,-yvol, zoffs6-z1+z2, 0, "ONLY",divpar,3);
891      }
892      }
893      
894  if (fStations[3]) {
895
896 //********************************************************************
897 //                            Station 4                             **
898 //********************************************************************
899      // indices 1 and 2 for first and second chambers in the station
900      // iChamber (first chamber) kept for other quanties than Z,
901      // assumed to be the same in both chambers
902      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[6];
903      iChamber2 =(AliMUONChamber*) (*fChambers)[7];
904      zpos1=iChamber1->Z(); 
905      zpos2=iChamber2->Z();
906      dstation = TMath::Abs(zpos2 - zpos1);
907 //      zfpos=-(iChamber->DGas()+dframez+iChamber->DAlu())/2; // not used any more
908      
909 //
910 //   Mother volume
911      tpar[0] = iChamber->RInner()-dframep; 
912      tpar[1] = (iChamber->ROuter()+dframep)/TMath::Cos(phi);
913      tpar[2] = dstation/4;
914
915      gMC->Gsvolu("S07M", "TUBE", idAir, tpar, 3);
916      gMC->Gsvolu("S08M", "TUBE", idAir, tpar, 3);
917      gMC->Gspos("S07M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
918      gMC->Gspos("S08M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");
919      
920
921      const Int_t knSlats4 = 6;  // number of slats per quadrant
922      const Int_t knPCB4[knSlats4] = {4,4,5,5,4,3}; // n PCB per slat
923      const Float_t kxpos4[knSlats4] = {38.5, 40., 0., 0., 0., 0.};
924      Float_t slatLength4[knSlats4];     
925
926      // create and position the slat (mother) volumes 
927
928      char volNam7[5];
929      char volNam8[5];
930      Float_t xSlat4;
931      Float_t ySlat4;
932
933      for (i = 0; i<knSlats4; i++){
934        slatLength4[i] = kpcbLength * knPCB4[i] + 2. * kdSlatLength; 
935        xSlat4 = slatLength4[i]/2. - kvFrameLength/2. + kxpos4[i]; 
936        if (i==1) slatLength4[i] -=  2. *kdSlatLength; // frame out in PCB with circular border 
937        ySlat4 =  ksensHeight * i - kyOverlap *i;
938        
939        spar[0] = slatLength4[i]/2.; 
940        spar[1] = kslatHeight/2.;
941        spar[2] = kslatWidth/2.*1.01; 
942        Float_t dzCh4=spar[2]*1.01;
943        // zSlat to be checked (odd downstream or upstream?)
944        Float_t zSlat = (i%2 ==0)? spar[2] : -spar[2]; 
945        sprintf(volNam7,"S07%d",i);
946        gMC->Gsvolu(volNam7,"BOX",kslatMaterial,spar,3);
947        gMC->Gspos(volNam7, i*4+1,"S07M",-xSlat4, ySlat4, -zSlat-2.*dzCh4, 0, "ONLY");
948        gMC->Gspos(volNam7, i*4+2,"S07M",+xSlat4, ySlat4, -zSlat+2.*dzCh4, 0, "ONLY");
949        if (i>0) { 
950          gMC->Gspos(volNam7, i*4+3,"S07M",-xSlat4,-ySlat4, -zSlat-2.*dzCh4, 0, "ONLY");
951          gMC->Gspos(volNam7, i*4+4,"S07M",+xSlat4,-ySlat4, -zSlat+2.*dzCh4, 0, "ONLY");
952        }
953        sprintf(volNam8,"S08%d",i);
954        gMC->Gsvolu(volNam8,"BOX",kslatMaterial,spar,3);
955        gMC->Gspos(volNam8, i*4+1,"S08M",-xSlat4, ySlat4, -zSlat-2.*dzCh4, 0, "ONLY");
956        gMC->Gspos(volNam8, i*4+2,"S08M",+xSlat4, ySlat4, -zSlat+2.*dzCh4, 0, "ONLY");
957        if (i>0) { 
958          gMC->Gspos(volNam8, i*4+3,"S08M",-xSlat4,-ySlat4, -zSlat-2.*dzCh4, 0, "ONLY");
959          gMC->Gspos(volNam8, i*4+4,"S08M",+xSlat4,-ySlat4, -zSlat+2.*dzCh4, 0, "ONLY");
960        }
961      }
962      
963
964      // create the panel volume 
965  
966      gMC->Gsvolu("S07C","BOX",kpanelMaterial,panelpar,3);
967      gMC->Gsvolu("S08C","BOX",kpanelMaterial,panelpar,3);
968
969      // create the rohacell volume 
970
971      gMC->Gsvolu("S07R","BOX",krohaMaterial,rohapar,3);
972      gMC->Gsvolu("S08R","BOX",krohaMaterial,rohapar,3);
973
974      // create the insulating material volume 
975
976      gMC->Gsvolu("S07I","BOX",kinsuMaterial,insupar,3);
977      gMC->Gsvolu("S08I","BOX",kinsuMaterial,insupar,3);
978
979      // create the PCB volume 
980
981      gMC->Gsvolu("S07P","BOX",kpcbMaterial,pcbpar,3);
982      gMC->Gsvolu("S08P","BOX",kpcbMaterial,pcbpar,3);
983  
984      // create the sensitive volumes,
985
986      gMC->Gsvolu("S07G","BOX",ksensMaterial,dum,0);
987      gMC->Gsvolu("S08G","BOX",ksensMaterial,dum,0);
988
989      // create the vertical frame volume 
990
991      gMC->Gsvolu("S07V","BOX",kvFrameMaterial,vFramepar,3);
992      gMC->Gsvolu("S08V","BOX",kvFrameMaterial,vFramepar,3);
993
994      // create the horizontal frame volume 
995
996      gMC->Gsvolu("S07H","BOX",khFrameMaterial,hFramepar,3);
997      gMC->Gsvolu("S08H","BOX",khFrameMaterial,hFramepar,3);
998
999      // create the horizontal border volume 
1000
1001      gMC->Gsvolu("S07B","BOX",kbFrameMaterial,bFramepar,3);
1002      gMC->Gsvolu("S08B","BOX",kbFrameMaterial,bFramepar,3);
1003
1004      index=0; 
1005      for (i = 0; i<knSlats4; i++){
1006        sprintf(volNam7,"S07%d",i);
1007        sprintf(volNam8,"S08%d",i);
1008        Float_t xvFrame  = (slatLength4[i] - kvFrameLength)/2.;
1009        // position the vertical frames 
1010        if (i!=1 && i!=0) { 
1011          gMC->Gspos("S07V",2*i-1,volNam7, xvFrame, 0., 0. , 0, "ONLY");
1012          gMC->Gspos("S07V",2*i  ,volNam7,-xvFrame, 0., 0. , 0, "ONLY");
1013          gMC->Gspos("S08V",2*i-1,volNam8, xvFrame, 0., 0. , 0, "ONLY");
1014          gMC->Gspos("S08V",2*i  ,volNam8,-xvFrame, 0., 0. , 0, "ONLY");
1015        }
1016        // position the panels and the insulating material 
1017        for (j=0; j<knPCB4[i]; j++){
1018          index++;
1019          Float_t xx = ksensLength * (-knPCB4[i]/2.+j+.5); 
1020
1021          Float_t zPanel = spar[2] - panelpar[2]; 
1022          gMC->Gspos("S07C",2*index-1,volNam7, xx, 0., zPanel , 0, "ONLY");
1023          gMC->Gspos("S07C",2*index  ,volNam7, xx, 0.,-zPanel , 0, "ONLY");
1024          gMC->Gspos("S08C",2*index-1,volNam8, xx, 0., zPanel , 0, "ONLY");
1025          gMC->Gspos("S08C",2*index  ,volNam8, xx, 0.,-zPanel , 0, "ONLY");
1026
1027          gMC->Gspos("S07I",index,volNam7, xx, 0., 0 , 0, "ONLY");
1028          gMC->Gspos("S08I",index,volNam8, xx, 0., 0 , 0, "ONLY");
1029        } 
1030      }
1031
1032      // position the rohacell volume inside the panel volume
1033      gMC->Gspos("S07R",1,"S07C",0.,0.,0.,0,"ONLY"); 
1034      gMC->Gspos("S08R",1,"S08C",0.,0.,0.,0,"ONLY"); 
1035
1036      // position the PCB volume inside the insulating material volume
1037      gMC->Gspos("S07P",1,"S07I",0.,0.,0.,0,"ONLY"); 
1038      gMC->Gspos("S08P",1,"S08I",0.,0.,0.,0,"ONLY"); 
1039      // position the horizontal frame volume inside the PCB volume
1040      gMC->Gspos("S07H",1,"S07P",0.,0.,0.,0,"ONLY"); 
1041      gMC->Gspos("S08H",1,"S08P",0.,0.,0.,0,"ONLY"); 
1042      // position the sensitive volume inside the horizontal frame volume
1043      gMC->Gsposp("S07G",1,"S07H",0.,0.,0.,0,"ONLY",senspar,3); 
1044      gMC->Gsposp("S08G",1,"S08H",0.,0.,0.,0,"ONLY",senspar,3); 
1045      // position the border volumes inside the PCB volume
1046      Float_t yborder = ( kpcbHeight - kbFrameHeight ) / 2.; 
1047      gMC->Gspos("S07B",1,"S07P",0., yborder,0.,0,"ONLY"); 
1048      gMC->Gspos("S07B",2,"S07P",0.,-yborder,0.,0,"ONLY"); 
1049      gMC->Gspos("S08B",1,"S08P",0., yborder,0.,0,"ONLY"); 
1050      gMC->Gspos("S08B",2,"S08P",0.,-yborder,0.,0,"ONLY"); 
1051
1052      // create the NULOC volume and position it in the horizontal frame
1053
1054      gMC->Gsvolu("S07N","BOX",knulocMaterial,nulocpar,3);
1055      gMC->Gsvolu("S08N","BOX",knulocMaterial,nulocpar,3);
1056      index = 0;
1057      for (xx = -xxmax; xx<=xxmax; xx+=2*knulocLength) { 
1058        index++; 
1059        gMC->Gspos("S07N",2*index-1,"S07B", xx, 0.,-kbFrameWidth/4., 0, "ONLY");
1060        gMC->Gspos("S07N",2*index  ,"S07B", xx, 0., kbFrameWidth/4., 0, "ONLY");
1061        gMC->Gspos("S08N",2*index-1,"S08B", xx, 0.,-kbFrameWidth/4., 0, "ONLY");
1062        gMC->Gspos("S08N",2*index  ,"S08B", xx, 0., kbFrameWidth/4., 0, "ONLY");
1063      }
1064
1065      // position the volumes approximating the circular section of the pipe
1066      Float_t yoffs = ksensHeight/2. - kyOverlap; 
1067      Float_t epsilon = 0.001; 
1068      Int_t ndiv=6;
1069      Float_t divpar[3];
1070      Double_t dydiv= ksensHeight/ndiv;
1071      Double_t ydiv = yoffs -dydiv;
1072      Int_t imax=0; 
1073      imax = 1; 
1074      Float_t rmin = 40.; 
1075      Float_t z1 = -spar[2], z2=2*spar[2]*1.01; 
1076      for (Int_t idiv=0;idiv<ndiv; idiv++){ 
1077        ydiv+= dydiv;
1078        Float_t xdiv = 0.; 
1079        if (ydiv<rmin) xdiv= rmin * TMath::Sin( TMath::ACos(ydiv/rmin) );
1080        divpar[0] = (kpcbLength-xdiv)/2.; 
1081        divpar[1] = dydiv/2. - epsilon;
1082        divpar[2] = ksensWidth/2.; 
1083        Float_t xvol=(kpcbLength+xdiv)/2.+1.999;
1084        Float_t yvol=ydiv + dydiv/2.;
1085        gMC->Gsposp("S07G",imax+4*idiv+1,"S07M", -xvol, yvol, -z1-z2, 0, "ONLY",divpar,3);
1086        gMC->Gsposp("S08G",imax+4*idiv+1,"S08M", -xvol, yvol, -z1-z2, 0, "ONLY",divpar,3);
1087        gMC->Gsposp("S07G",imax+4*idiv+2,"S07M", -xvol,-yvol, -z1-z2, 0, "ONLY",divpar,3);
1088        gMC->Gsposp("S08G",imax+4*idiv+2,"S08M", -xvol,-yvol, -z1-z2, 0, "ONLY",divpar,3);
1089        gMC->Gsposp("S07G",imax+4*idiv+3,"S07M", xvol, yvol, -z1+z2, 0, "ONLY",divpar,3);
1090        gMC->Gsposp("S08G",imax+4*idiv+3,"S08M", xvol, yvol, -z1+z2, 0, "ONLY",divpar,3);
1091        gMC->Gsposp("S07G",imax+4*idiv+4,"S07M", xvol,-yvol, -z1+z2, 0, "ONLY",divpar,3);
1092        gMC->Gsposp("S08G",imax+4*idiv+4,"S08M", xvol,-yvol, -z1+z2, 0, "ONLY",divpar,3);
1093      }
1094
1095
1096
1097
1098
1099  }
1100
1101  if (fStations[4]) {
1102      
1103
1104 //********************************************************************
1105 //                            Station 5                             **
1106 //********************************************************************
1107      // indices 1 and 2 for first and second chambers in the station
1108      // iChamber (first chamber) kept for other quanties than Z,
1109      // assumed to be the same in both chambers
1110      iChamber1 = iChamber = (AliMUONChamber*) (*fChambers)[8];
1111      iChamber2 =(AliMUONChamber*) (*fChambers)[9];
1112      zpos1=iChamber1->Z(); 
1113      zpos2=iChamber2->Z();
1114      dstation = TMath::Abs(zpos2 - zpos1);
1115 //      zfpos=-(iChamber->DGas()+dframez+iChamber->DAlu())/2; // not used any more
1116      
1117 //
1118 //   Mother volume
1119      tpar[0] = iChamber->RInner()-dframep; 
1120      tpar[1] = (iChamber->ROuter()+dframep)/TMath::Cos(phi);
1121      tpar[2] = dstation/5.;
1122
1123      gMC->Gsvolu("S09M", "TUBE", idAir, tpar, 3);
1124      gMC->Gsvolu("S10M", "TUBE", idAir, tpar, 3);
1125      gMC->Gspos("S09M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
1126      gMC->Gspos("S10M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");
1127
1128
1129      const Int_t knSlats5 = 7;  // number of slats per quadrant
1130      const Int_t knPCB5[knSlats5] = {5,5,6,6,5,4,3}; // n PCB per slat
1131      const Float_t kxpos5[knSlats5] = {38.5, 40., 0., 0., 0., 0., 0.};
1132      Float_t slatLength5[knSlats5]; 
1133      char volNam9[5];
1134      char volNam10[5];
1135      Float_t xSlat5;
1136      Float_t ySlat5;
1137
1138      for (i = 0; i<knSlats5; i++){
1139        slatLength5[i] = kpcbLength * knPCB5[i] + 2. * kdSlatLength; 
1140        xSlat5 = slatLength5[i]/2. - kvFrameLength/2. +kxpos5[i]; 
1141        if (i==1 || i==0) slatLength5[i] -=  2. *kdSlatLength; // frame out in PCB with circular border 
1142        ySlat5 = ksensHeight * i - kyOverlap * i; 
1143        spar[0] = slatLength5[i]/2.; 
1144        spar[1] = kslatHeight/2.;
1145        spar[2] = kslatWidth/2. * 1.01; 
1146        Float_t dzCh5=spar[2]*1.01;
1147        // zSlat to be checked (odd downstream or upstream?)
1148        Float_t zSlat = (i%2 ==0)? -spar[2] : spar[2]; 
1149        sprintf(volNam9,"S09%d",i);
1150        gMC->Gsvolu(volNam9,"BOX",kslatMaterial,spar,3);
1151        gMC->Gspos(volNam9, i*4+1,"S09M",-xSlat5, ySlat5, -zSlat-2.*dzCh5, 0, "ONLY");
1152        gMC->Gspos(volNam9, i*4+2,"S09M",+xSlat5, ySlat5, -zSlat+2.*dzCh5, 0, "ONLY");
1153        if (i>0) { 
1154            gMC->Gspos(volNam9, i*4+3,"S09M",-xSlat5,-ySlat5, -zSlat-2.*dzCh5, 0, "ONLY");
1155            gMC->Gspos(volNam9, i*4+4,"S09M",+xSlat5,-ySlat5, -zSlat+2.*dzCh5, 0, "ONLY");
1156        }
1157        sprintf(volNam10,"S10%d",i);
1158        gMC->Gsvolu(volNam10,"BOX",kslatMaterial,spar,3);
1159        gMC->Gspos(volNam10, i*4+1,"S10M",-xSlat5, ySlat5, -zSlat-2.*dzCh5, 0, "ONLY");
1160        gMC->Gspos(volNam10, i*4+2,"S10M",+xSlat5, ySlat5, -zSlat+2.*dzCh5, 0, "ONLY");
1161        if (i>0) { 
1162            gMC->Gspos(volNam10, i*4+3,"S10M",-xSlat5,-ySlat5, -zSlat-2.*dzCh5, 0, "ONLY");
1163            gMC->Gspos(volNam10, i*4+4,"S10M",+xSlat5,-ySlat5, -zSlat+2.*dzCh5, 0, "ONLY");
1164        }
1165      }
1166
1167      // create the panel volume 
1168  
1169      gMC->Gsvolu("S09C","BOX",kpanelMaterial,panelpar,3);
1170      gMC->Gsvolu("S10C","BOX",kpanelMaterial,panelpar,3);
1171
1172      // create the rohacell volume 
1173
1174      gMC->Gsvolu("S09R","BOX",krohaMaterial,rohapar,3);
1175      gMC->Gsvolu("S10R","BOX",krohaMaterial,rohapar,3);
1176
1177      // create the insulating material volume 
1178
1179      gMC->Gsvolu("S09I","BOX",kinsuMaterial,insupar,3);
1180      gMC->Gsvolu("S10I","BOX",kinsuMaterial,insupar,3);
1181
1182      // create the PCB volume 
1183
1184      gMC->Gsvolu("S09P","BOX",kpcbMaterial,pcbpar,3);
1185      gMC->Gsvolu("S10P","BOX",kpcbMaterial,pcbpar,3);
1186  
1187      // create the sensitive volumes,
1188
1189      gMC->Gsvolu("S09G","BOX",ksensMaterial,dum,0);
1190      gMC->Gsvolu("S10G","BOX",ksensMaterial,dum,0);
1191
1192      // create the vertical frame volume 
1193
1194      gMC->Gsvolu("S09V","BOX",kvFrameMaterial,vFramepar,3);
1195      gMC->Gsvolu("S10V","BOX",kvFrameMaterial,vFramepar,3);
1196
1197      // create the horizontal frame volume 
1198
1199      gMC->Gsvolu("S09H","BOX",khFrameMaterial,hFramepar,3);
1200      gMC->Gsvolu("S10H","BOX",khFrameMaterial,hFramepar,3);
1201
1202      // create the horizontal border volume 
1203
1204      gMC->Gsvolu("S09B","BOX",kbFrameMaterial,bFramepar,3);
1205      gMC->Gsvolu("S10B","BOX",kbFrameMaterial,bFramepar,3);
1206
1207      index=0; 
1208      for (i = 0; i<knSlats5; i++){
1209        sprintf(volNam9,"S09%d",i);
1210        sprintf(volNam10,"S10%d",i);
1211        Float_t xvFrame  = (slatLength5[i] - kvFrameLength)/2.;
1212        // position the vertical frames 
1213        if (i!=1 && i!=0) { 
1214          gMC->Gspos("S09V",2*i-1,volNam9, xvFrame, 0., 0. , 0, "ONLY");
1215          gMC->Gspos("S09V",2*i  ,volNam9,-xvFrame, 0., 0. , 0, "ONLY");
1216          gMC->Gspos("S10V",2*i-1,volNam10, xvFrame, 0., 0. , 0, "ONLY");
1217          gMC->Gspos("S10V",2*i  ,volNam10,-xvFrame, 0., 0. , 0, "ONLY");
1218        }
1219        
1220        // position the panels and the insulating material 
1221        for (j=0; j<knPCB5[i]; j++){
1222          index++;
1223          Float_t xx = ksensLength * (-knPCB5[i]/2.+j+.5); 
1224
1225          Float_t zPanel = spar[2] - panelpar[2]; 
1226          gMC->Gspos("S09C",2*index-1,volNam9, xx, 0., zPanel , 0, "ONLY");
1227          gMC->Gspos("S09C",2*index  ,volNam9, xx, 0.,-zPanel , 0, "ONLY");
1228          gMC->Gspos("S10C",2*index-1,volNam10, xx, 0., zPanel , 0, "ONLY");
1229          gMC->Gspos("S10C",2*index  ,volNam10, xx, 0.,-zPanel , 0, "ONLY");
1230
1231          gMC->Gspos("S09I",index,volNam9, xx, 0., 0 , 0, "ONLY");
1232          gMC->Gspos("S10I",index,volNam10, xx, 0., 0 , 0, "ONLY");
1233        } 
1234      }
1235
1236      // position the rohacell volume inside the panel volume
1237      gMC->Gspos("S09R",1,"S09C",0.,0.,0.,0,"ONLY"); 
1238      gMC->Gspos("S10R",1,"S10C",0.,0.,0.,0,"ONLY"); 
1239
1240      // position the PCB volume inside the insulating material volume
1241      gMC->Gspos("S09P",1,"S09I",0.,0.,0.,0,"ONLY"); 
1242      gMC->Gspos("S10P",1,"S10I",0.,0.,0.,0,"ONLY"); 
1243      // position the horizontal frame volume inside the PCB volume
1244      gMC->Gspos("S09H",1,"S09P",0.,0.,0.,0,"ONLY"); 
1245      gMC->Gspos("S10H",1,"S10P",0.,0.,0.,0,"ONLY"); 
1246      // position the sensitive volume inside the horizontal frame volume
1247      gMC->Gsposp("S09G",1,"S09H",0.,0.,0.,0,"ONLY",senspar,3); 
1248      gMC->Gsposp("S10G",1,"S10H",0.,0.,0.,0,"ONLY",senspar,3); 
1249      // position the border volumes inside the PCB volume
1250      Float_t yborder = ( kpcbHeight - kbFrameHeight ) / 2.; 
1251      gMC->Gspos("S09B",1,"S09P",0., yborder,0.,0,"ONLY"); 
1252      gMC->Gspos("S09B",2,"S09P",0.,-yborder,0.,0,"ONLY"); 
1253      gMC->Gspos("S10B",1,"S10P",0., yborder,0.,0,"ONLY"); 
1254      gMC->Gspos("S10B",2,"S10P",0.,-yborder,0.,0,"ONLY"); 
1255
1256      // create the NULOC volume and position it in the horizontal frame
1257
1258      gMC->Gsvolu("S09N","BOX",knulocMaterial,nulocpar,3);
1259      gMC->Gsvolu("S10N","BOX",knulocMaterial,nulocpar,3);
1260      index = 0;
1261      for (xx = -xxmax; xx<=xxmax; xx+=2*knulocLength) { 
1262        index++; 
1263        gMC->Gspos("S09N",2*index-1,"S09B", xx, 0.,-kbFrameWidth/4., 0, "ONLY");
1264        gMC->Gspos("S09N",2*index  ,"S09B", xx, 0., kbFrameWidth/4., 0, "ONLY");
1265        gMC->Gspos("S10N",2*index-1,"S10B", xx, 0.,-kbFrameWidth/4., 0, "ONLY");
1266        gMC->Gspos("S10N",2*index  ,"S10B", xx, 0., kbFrameWidth/4., 0, "ONLY");
1267      }
1268      // position the volumes approximating the circular section of the pipe
1269      Float_t yoffs = ksensHeight/2. - kyOverlap; 
1270      Float_t epsilon = 0.001; 
1271      Int_t ndiv=6;
1272      Float_t divpar[3];
1273      Double_t dydiv= ksensHeight/ndiv;
1274      Double_t ydiv = yoffs -dydiv;
1275      Int_t imax=0; 
1276      //     for (Int_t islat=0; islat<knSlats3; islat++) imax += knPCB3[islat]; 
1277      imax = 1; 
1278      Float_t rmin = 40.; 
1279      Float_t z1 = spar[2], z2=2*spar[2]*1.01; 
1280      for (Int_t idiv=0;idiv<ndiv; idiv++){ 
1281        ydiv+= dydiv;
1282        Float_t xdiv = 0.; 
1283        if (ydiv<rmin) xdiv= rmin * TMath::Sin( TMath::ACos(ydiv/rmin) );
1284        divpar[0] = (kpcbLength-xdiv)/2.; 
1285        divpar[1] = dydiv/2. - epsilon;
1286        divpar[2] = ksensWidth/2.; 
1287        Float_t xvol=(kpcbLength+xdiv)/2. + 1.999;
1288        Float_t yvol=ydiv + dydiv/2.;
1289        gMC->Gsposp("S09G",imax+4*idiv+1,"S09M", -xvol, yvol, -z1-z2, 0, "ONLY",divpar,3);
1290        gMC->Gsposp("S10G",imax+4*idiv+1,"S10M", -xvol, yvol, -z1-z2, 0, "ONLY",divpar,3);
1291        gMC->Gsposp("S09G",imax+4*idiv+2,"S09M", -xvol,-yvol, -z1-z2, 0, "ONLY",divpar,3);
1292        gMC->Gsposp("S10G",imax+4*idiv+2,"S10M", -xvol,-yvol, -z1-z2, 0, "ONLY",divpar,3);
1293        gMC->Gsposp("S09G",imax+4*idiv+3,"S09M", +xvol, yvol, -z1+z2, 0, "ONLY",divpar,3);
1294        gMC->Gsposp("S10G",imax+4*idiv+3,"S10M", +xvol, yvol, -z1+z2, 0, "ONLY",divpar,3);
1295        gMC->Gsposp("S09G",imax+4*idiv+4,"S09M", +xvol,-yvol, -z1+z2, 0, "ONLY",divpar,3);
1296        gMC->Gsposp("S10G",imax+4*idiv+4,"S10M", +xvol,-yvol, -z1+z2, 0, "ONLY",divpar,3);
1297      }
1298
1299  }
1300  
1301 //********************************************************************
1302 //                            Trigger                               **
1303 //******************************************************************** 
1304  /* 
1305     zpos1 and zpos2 are the middle of the first and second
1306     planes of station 1 (+1m for second station):
1307     zpos1=(zpos1m+zpos1p)/2=(15999+16071)/2=16035 mm, thick/2=40 mm
1308     zpos2=(zpos2m+zpos2p)/2=(16169+16241)/2=16205 mm, thick/2=40 mm
1309     zposxm and zposxp= middles of gaz gaps within a detection plane
1310     rem: the total thickness accounts for 1 mm of al on both
1311     side of the RPCs (see zpos1 and zpos2)
1312  */
1313
1314 // vertical gap between right and left chambers (kDXZERO*2=4cm)
1315  const Float_t kDXZERO=2.; 
1316 // main distances for chamber definition in first plane/first station
1317  const Float_t kXMIN=34.;       
1318  const Float_t kXMED=51.;                                
1319  const Float_t kXMAX=272.; 
1320 // kXMAX will become 255. in real life. segmentation to be updated accordingly
1321 // (see fig.2-4 & 2-5 of Local Trigger Board PRR)
1322  const Float_t kYMIN=34.;                              
1323  const Float_t kYMAX=51.;                              
1324 // inner/outer radius of flange between beam shield. and chambers (1/station)
1325  const Float_t kRMIN[2]={50.,50.};
1326  const Float_t kRMAX[2]={64.,68.};
1327 // z position of the middle of the gas gap in mother vol 
1328  const Float_t kZm=-3.6;
1329  const Float_t kZp=+3.6;     
1330  
1331  iChamber1 = (AliMUONChamber*) (*fChambers)[10];     
1332  zpos1 = iChamber1->Z();
1333
1334 // ratio of zpos1m/zpos1p and inverse for first plane
1335  Float_t zmp=(zpos1+3.6)/(zpos1-3.6);
1336  Float_t zpm=1./zmp;
1337  
1338  Int_t icount=0; // chamber counter (0 1 2 3)
1339  
1340  for (Int_t istation=0; istation<2; istation++) { // loop on stations    
1341      for (Int_t iplane=0; iplane<2; iplane++) {   // loop on detection planes
1342          
1343          Int_t iVolNum=1; // counter Volume Number
1344          icount = Int_t(iplane*TMath::Power(2,0))+
1345              Int_t(istation*TMath::Power(2,1));
1346          
1347          char volPlane[5]; 
1348          sprintf(volPlane,"SM%d%d",istation+1,iplane+1);
1349          
1350          iChamber = (AliMUONChamber*) (*fChambers)[10+icount];
1351          Float_t zpos = iChamber->Z();       
1352          
1353 // mother volume 
1354          tpar[0] = iChamber->RInner(); 
1355          tpar[1] = iChamber->ROuter(); 
1356          tpar[2] = 4.0;    
1357          gMC->Gsvolu(volPlane,"TUBE",idAir,tpar,3);
1358          
1359 // Flange between beam shielding and RPC 
1360          tpar[0]= kRMIN[istation];
1361          tpar[1]= kRMAX[istation];
1362          tpar[2]= 4.0;
1363          
1364          char volFlange[5];
1365          sprintf(volFlange,"SF%dA",icount+1);    
1366          gMC->Gsvolu(volFlange,"TUBE",idAlu1,tpar,3);     //Al
1367          gMC->Gspos(volFlange,1,volPlane,0.,0.,0.,0,"MANY");
1368          
1369 // scaling factor
1370          Float_t zRatio = zpos / zpos1;
1371          
1372 // chamber prototype
1373          tpar[0]= 0.;
1374          tpar[1]= 0.;
1375          tpar[2]= 0.;
1376          
1377          char volAlu[5]; // Alu
1378          char volBak[5]; // Bakelite
1379          char volGaz[5]; // Gas streamer
1380          
1381          sprintf(volAlu,"SC%dA",icount+1);
1382          sprintf(volBak,"SB%dA",icount+1);
1383          sprintf(volGaz,"SG%dA",icount+1);
1384          
1385          gMC->Gsvolu(volAlu,"BOX",idAlu1,tpar,0);           // Al
1386          gMC->Gsvolu(volBak,"BOX",idtmed[1107],tpar,0);     // Bakelite
1387          gMC->Gsvolu(volGaz,"BOX",idtmed[1106],tpar,0);     // Gas streamer
1388          
1389 // chamber type A
1390          tpar[0] = -1.;
1391          tpar[1] = -1.;
1392          
1393          Float_t xA=(kDXZERO+kXMED+(kXMAX-kXMED)/2.)*zRatio;
1394          Float_t yAm=0.;
1395          Float_t yAp=0.;
1396          
1397          tpar[2] = 0.1;    
1398          gMC->Gsposp(volGaz,1,volBak,0.,0.,0.,0,"ONLY",tpar,3);
1399          tpar[2] = 0.3;
1400          gMC->Gsposp(volBak,1,volAlu,0.,0.,0.,0,"ONLY",tpar,3);
1401          
1402          tpar[2] = 0.4;
1403          tpar[0] = ((kXMAX-kXMED)/2.)*zRatio;
1404          tpar[1] = kYMIN*zRatio;
1405          
1406          gMC->Gsposp(volAlu,iVolNum++,volPlane, -xA,yAm,-kZm,0,"ONLY",tpar,3);
1407          gMC->Gsposp(volAlu,iVolNum++,volPlane,  xA,yAp,-kZp,0,"ONLY",tpar,3);
1408          gMC->Gsbool(volAlu,volFlange);
1409          
1410 // chamber type B    
1411          Float_t tpar1save=tpar[1];
1412          Float_t y1msave=yAm;
1413          Float_t y1psave=yAp;
1414          
1415          tpar[0] = ((kXMAX-kXMIN)/2.) * zRatio;
1416          tpar[1] = ((kYMAX-kYMIN)/2.) * zRatio;
1417          
1418          Float_t xB=(kDXZERO+kXMIN)*zRatio+tpar[0];
1419          Float_t yBp=(y1msave+tpar1save)*zpm+tpar[1];
1420          Float_t yBm=(y1psave+tpar1save)*zmp+tpar[1];    
1421
1422          gMC->Gsposp(volAlu,iVolNum++,volPlane, -xB, yBp,-kZp,0,"ONLY",tpar,3);
1423          gMC->Gsposp(volAlu,iVolNum++,volPlane,  xB, yBm,-kZm,0,"ONLY",tpar,3);
1424          gMC->Gsposp(volAlu,iVolNum++,volPlane, -xB,-yBp,-kZp,0,"ONLY",tpar,3);
1425          gMC->Gsposp(volAlu,iVolNum++,volPlane,  xB,-yBm,-kZm,0,"ONLY",tpar,3);
1426          
1427 // chamber type C (note : same Z than type B)
1428          tpar1save=tpar[1];
1429          y1msave=yBm;
1430          y1psave=yBp;
1431          
1432          tpar[0] = (kXMAX/2)*zRatio;
1433          tpar[1] = (kYMAX/2)*zRatio;
1434          
1435          Float_t xC=kDXZERO*zRatio+tpar[0];
1436          Float_t yCp=(y1psave+tpar1save)*1.+tpar[1];
1437          Float_t yCm=(y1msave+tpar1save)*1.+tpar[1];
1438          
1439          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xC, yCp,-kZp,0,"ONLY",tpar,3);
1440          gMC->Gsposp(volAlu,iVolNum++,volPlane, xC, yCm,-kZm,0,"ONLY",tpar,3);
1441          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xC,-yCp,-kZp,0,"ONLY",tpar,3);
1442          gMC->Gsposp(volAlu,iVolNum++,volPlane, xC,-yCm,-kZm,0,"ONLY",tpar,3);
1443                  
1444 // chamber type D, E and F (same size)        
1445          tpar1save=tpar[1];
1446          y1msave=yCm;
1447          y1psave=yCp;
1448          
1449          tpar[0] = (kXMAX/2.)*zRatio;
1450          tpar[1] =  kYMIN*zRatio;
1451          
1452          Float_t xD=kDXZERO*zRatio+tpar[0];
1453          Float_t yDp=(y1msave+tpar1save)*zpm+tpar[1];
1454          Float_t yDm=(y1psave+tpar1save)*zmp+tpar[1];
1455          
1456          gMC->Gsposp(volAlu,iVolNum++,volPlane, -xD, yDm,-kZm,0,"ONLY",tpar,3);
1457          gMC->Gsposp(volAlu,iVolNum++,volPlane,  xD, yDp,-kZp,0,"ONLY",tpar,3);
1458          gMC->Gsposp(volAlu,iVolNum++,volPlane, -xD,-yDm,-kZm,0,"ONLY",tpar,3);
1459          gMC->Gsposp(volAlu,iVolNum++,volPlane,  xD,-yDp,-kZp,0,"ONLY",tpar,3);
1460          
1461          tpar1save=tpar[1];
1462          y1msave=yDm;
1463          y1psave=yDp;
1464          Float_t yEp=(y1msave+tpar1save)*zpm+tpar[1];
1465          Float_t yEm=(y1psave+tpar1save)*zmp+tpar[1];
1466          
1467          gMC->Gsposp(volAlu,iVolNum++,volPlane, -xD, yEp,-kZp,0,"ONLY",tpar,3);
1468          gMC->Gsposp(volAlu,iVolNum++,volPlane,  xD, yEm,-kZm,0,"ONLY",tpar,3);
1469          gMC->Gsposp(volAlu,iVolNum++,volPlane, -xD,-yEp,-kZp,0,"ONLY",tpar,3);
1470          gMC->Gsposp(volAlu,iVolNum++,volPlane,  xD,-yEm,-kZm,0,"ONLY",tpar,3);
1471          
1472          tpar1save=tpar[1];
1473          y1msave=yEm;
1474          y1psave=yEp;
1475          Float_t yFp=(y1msave+tpar1save)*zpm+tpar[1];
1476          Float_t yFm=(y1psave+tpar1save)*zmp+tpar[1];
1477          
1478          gMC->Gsposp(volAlu,iVolNum++,volPlane, -xD, yFm,-kZm,0,"ONLY",tpar,3);
1479          gMC->Gsposp(volAlu,iVolNum++,volPlane,  xD, yFp,-kZp,0,"ONLY",tpar,3);
1480          gMC->Gsposp(volAlu,iVolNum++,volPlane, -xD,-yFm,-kZm,0,"ONLY",tpar,3);
1481          gMC->Gsposp(volAlu,iVolNum++,volPlane,  xD,-yFp,-kZp,0,"ONLY",tpar,3);
1482
1483 // Positioning plane in ALICE     
1484          gMC->Gspos(volPlane,1,"ALIC",0.,0.,zpos,0,"ONLY");
1485          
1486      } // end loop on detection planes
1487  } // end loop on stations
1488
1489 }
1490
1491  
1492 //___________________________________________
1493 void AliMUONv3::CreateMaterials()
1494 {
1495   // *** DEFINITION OF AVAILABLE MUON MATERIALS *** 
1496   //
1497   //     Ar-CO2 gas (80%+20%)
1498     Float_t ag1[3]   = { 39.95,12.01,16. };
1499     Float_t zg1[3]   = { 18.,6.,8. };
1500     Float_t wg1[3]   = { .8,.0667,.13333 };
1501     Float_t dg1      = .001821;
1502     //
1503     //     Ar-buthane-freon gas -- trigger chambers 
1504     Float_t atr1[4]  = { 39.95,12.01,1.01,19. };
1505     Float_t ztr1[4]  = { 18.,6.,1.,9. };
1506     Float_t wtr1[4]  = { .56,.1262857,.2857143,.028 };
1507     Float_t dtr1     = .002599;
1508     //
1509     //     Ar-CO2 gas 
1510     Float_t agas[3]  = { 39.95,12.01,16. };
1511     Float_t zgas[3]  = { 18.,6.,8. };
1512     Float_t wgas[3]  = { .74,.086684,.173316 };
1513     Float_t dgas     = .0018327;
1514     //
1515     //     Ar-Isobutane gas (80%+20%) -- tracking 
1516     Float_t ag[3]    = { 39.95,12.01,1.01 };
1517     Float_t zg[3]    = { 18.,6.,1. };
1518     Float_t wg[3]    = { .8,.057,.143 };
1519     Float_t dg       = .0019596;
1520     //
1521     //     Ar-Isobutane-Forane-SF6 gas (49%+7%+40%+4%) -- trigger 
1522     Float_t atrig[5] = { 39.95,12.01,1.01,19.,32.066 };
1523     Float_t ztrig[5] = { 18.,6.,1.,9.,16. };
1524     Float_t wtrig[5] = { .49,1.08,1.5,1.84,0.04 };
1525     Float_t dtrig    = .0031463;
1526     //
1527     //     bakelite 
1528
1529     Float_t abak[3] = {12.01 , 1.01 , 16.};
1530     Float_t zbak[3] = {6.     , 1.   , 8.};
1531     Float_t wbak[3] = {6.     , 6.   , 1.}; 
1532     Float_t dbak = 1.4;
1533
1534     Float_t epsil, stmin, deemax, tmaxfd, stemax;
1535
1536     Int_t iSXFLD   = gAlice->Field()->Integ();
1537     Float_t sXMGMX = gAlice->Field()->Max();
1538     //
1539     // --- Define the various materials for GEANT --- 
1540     AliMaterial(9, "ALUMINIUM$", 26.98, 13., 2.7, 8.9, 37.2);
1541     AliMaterial(10, "ALUMINIUM$", 26.98, 13., 2.7, 8.9, 37.2);
1542     AliMaterial(15, "AIR$      ", 14.61, 7.3, .001205, 30423.24, 67500);
1543     AliMixture(19, "Bakelite$", abak, zbak, dbak, -3, wbak);
1544     AliMixture(20, "ArC4H10 GAS$", ag, zg, dg, 3, wg);
1545     AliMixture(21, "TRIG GAS$", atrig, ztrig, dtrig, -5, wtrig);
1546     AliMixture(22, "ArCO2 80%$", ag1, zg1, dg1, 3, wg1);
1547     AliMixture(23, "Ar-freon $", atr1, ztr1, dtr1, 4, wtr1);
1548     AliMixture(24, "ArCO2 GAS$", agas, zgas, dgas, 3, wgas);
1549     // materials for slat: 
1550     //     Sensitive area: gas (already defined) 
1551     //     PCB: copper 
1552     //     insulating material and frame: vetronite
1553     //     walls: carbon, rohacell, carbon 
1554   Float_t aglass[5]={12.01, 28.09, 16.,   10.8,  23.};
1555   Float_t zglass[5]={ 6.,   14.,    8.,    5.,   11.};
1556   Float_t wglass[5]={ 0.5,  0.105, 0.355, 0.03,  0.01};
1557   Float_t dglass=1.74;
1558
1559   // rohacell: C9 H13 N1 O2
1560   Float_t arohac[4] = {12.01,  1.01, 14.010, 16.};
1561   Float_t zrohac[4] = { 6.,    1.,    7.,     8.};
1562   Float_t wrohac[4] = { 9.,   13.,    1.,     2.};
1563   Float_t drohac    = 0.03;
1564
1565   AliMaterial(31, "COPPER$",   63.54,    29.,   8.96,  1.4, 0.);
1566   AliMixture(32, "Vetronite$",aglass, zglass, dglass,    5, wglass);
1567   AliMaterial(33, "Carbon$",   12.01,     6.,  2.265, 18.8, 49.9);
1568   AliMixture(34, "Rohacell$", arohac, zrohac, drohac,   -4, wrohac); 
1569
1570
1571     epsil  = .001; // Tracking precision, 
1572     stemax = -1.;  // Maximum displacement for multiple scat 
1573     tmaxfd = -20.; // Maximum angle due to field deflection 
1574     deemax = -.3;  // Maximum fractional energy loss, DLS 
1575     stmin  = -.8;
1576     //
1577     //    Air 
1578     AliMedium(1, "AIR_CH_US         ", 15, 1, iSXFLD, sXMGMX, tmaxfd, stemax, deemax, epsil, stmin);
1579     //
1580     //    Aluminum 
1581
1582     AliMedium(4, "ALU_CH_US          ", 9, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
1583             fMaxDestepAlu, epsil, stmin);
1584     AliMedium(5, "ALU_CH_US          ", 10, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
1585             fMaxDestepAlu, epsil, stmin);
1586     //
1587     //    Ar-isoC4H10 gas 
1588
1589     AliMedium(6, "AR_CH_US          ", 20, 1, iSXFLD, sXMGMX, tmaxfd, fMaxStepGas, 
1590             fMaxDestepGas, epsil, stmin);
1591 //
1592     //    Ar-Isobuthane-Forane-SF6 gas 
1593
1594     AliMedium(7, "GAS_CH_TRIGGER    ", 21, 1, iSXFLD, sXMGMX, tmaxfd, stemax, deemax, epsil, stmin);
1595
1596     AliMedium(8, "BAKE_CH_TRIGGER   ", 19, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
1597             fMaxDestepAlu, epsil, stmin);
1598
1599     AliMedium(9, "ARG_CO2   ", 22, 1, iSXFLD, sXMGMX, tmaxfd, fMaxStepGas, 
1600             fMaxDestepAlu, epsil, stmin);
1601     // tracking media for slats: check the parameters!! 
1602     AliMedium(11, "PCB_COPPER        ", 31, 0, iSXFLD, sXMGMX, tmaxfd, 
1603               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1604     AliMedium(12, "VETRONITE         ", 32, 0, iSXFLD, sXMGMX, tmaxfd, 
1605               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1606     AliMedium(13, "CARBON            ", 33, 0, iSXFLD, sXMGMX, tmaxfd, 
1607               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1608     AliMedium(14, "Rohacell          ", 34, 0, iSXFLD, sXMGMX, tmaxfd, 
1609               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1610 }
1611
1612 //___________________________________________
1613
1614 void AliMUONv3::Init()
1615 {
1616    // 
1617    // Initialize Tracking Chambers
1618    //
1619
1620    if(fDebug) printf("\n%s: Start Init for version 1 - CPC chamber type\n\n",ClassName());
1621    Int_t i;
1622    for (i=0; i<AliMUONConstants::NCh(); i++) {
1623        ( (AliMUONChamber*) (*fChambers)[i])->Init();
1624    }
1625    
1626    //
1627    // Set the chamber (sensitive region) GEANT identifier
1628    ((AliMUONChamber*)(*fChambers)[0])->GetGeometry()->SetSensitiveVolume("S01G");
1629    ((AliMUONChamber*)(*fChambers)[1])->GetGeometry()->SetSensitiveVolume("S02G");
1630
1631    ((AliMUONChamber*)(*fChambers)[2])->GetGeometry()->SetSensitiveVolume("S03G");
1632    ((AliMUONChamber*)(*fChambers)[3])->GetGeometry()->SetSensitiveVolume("S04G");
1633
1634    ((AliMUONChamber*)(*fChambers)[4])->GetGeometry()->SetSensitiveVolume("S05G");
1635    ((AliMUONChamber*)(*fChambers)[5])->GetGeometry()->SetSensitiveVolume("S06G");
1636
1637    ((AliMUONChamber*)(*fChambers)[6])->GetGeometry()->SetSensitiveVolume("S07G");
1638    ((AliMUONChamber*)(*fChambers)[7])->GetGeometry()->SetSensitiveVolume("S08G");
1639
1640    ((AliMUONChamber*)(*fChambers)[8])->GetGeometry()->SetSensitiveVolume("S09G");
1641    ((AliMUONChamber*)(*fChambers)[9])->GetGeometry()->SetSensitiveVolume("S10G");
1642
1643    ((AliMUONChamber*)(*fChambers)[10])->GetGeometry()->SetSensitiveVolume("SG1A");
1644    ((AliMUONChamber*)(*fChambers)[11])->GetGeometry()->SetSensitiveVolume("SG2A");
1645    ((AliMUONChamber*)(*fChambers)[12])->GetGeometry()->SetSensitiveVolume("SG3A");
1646    ((AliMUONChamber*)(*fChambers)[13])->GetGeometry()->SetSensitiveVolume("SG4A");
1647
1648    if(fDebug) printf("\n%s: Finished Init for version 1 - CPC chamber type\n",ClassName());
1649
1650    //cp 
1651    if(fDebug) printf("\n%s: Start Init for Trigger Circuits\n",ClassName());
1652    for (i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
1653      ( (AliMUONTriggerCircuit*) (*fTriggerCircuits)[i])->Init(i);
1654    }
1655    if(fDebug) printf("%s: Finished Init for Trigger Circuits\n",ClassName());
1656    //cp
1657
1658 }
1659
1660 //_______________________________________________________________________________
1661 Int_t  AliMUONv3::GetChamberId(Int_t volId) const
1662 {
1663 // Check if the volume with specified  volId is a sensitive volume (gas) 
1664 // of some chamber and returns the chamber number;
1665 // if not sensitive volume - return 0.
1666 // ---
1667
1668   for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
1669     if ( ((AliMUONChamber*)(*fChambers)[i-1])->IsSensId(volId) ) return i;
1670
1671   return 0;
1672 }
1673 //_______________________________________________________________________________
1674 void AliMUONv3::StepManager()
1675 {
1676   // Stepmanager for the chambers
1677
1678  if (fStepManagerVersionOld) {
1679     StepManagerOld();
1680     return;
1681   }
1682
1683   // Only charged tracks
1684   if( !(gMC->TrackCharge()) ) return; 
1685   // Only charged tracks
1686   
1687   // Only gas gap inside chamber
1688   // Tag chambers and record hits when track enters 
1689   Int_t   idvol=-1;
1690   Int_t   iChamber=0;
1691   Int_t   id=0;
1692   Int_t   copy;
1693   const  Float_t kBig = 1.e10;
1694
1695   id=gMC->CurrentVolID(copy);
1696   iChamber = GetChamberId(id);
1697   idvol=GetChamberId(id)-1;
1698
1699   if (idvol == -1) return;
1700
1701    if( gMC->IsTrackEntering() ) {
1702      Float_t theta = fTrackMomentum.Theta();
1703      if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
1704   }
1705
1706 //  if (GetDebug()) {
1707 //     Float_t z = ( (AliMUONChamber*)(*fChambers)[idvol])->Z() ;
1708 //      Info("StepManager Step","Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber, z);
1709 //   }  
1710   // Particule id and mass, 
1711   Int_t     ipart = gMC->TrackPid();
1712   Float_t   mass  = gMC->TrackMass();
1713
1714   fDestepSum[idvol]+=gMC->Edep();
1715   // Get current particle id (ipart), track position (pos)  and momentum (mom)
1716   if ( fStepSum[idvol]==0.0 )  gMC->TrackMomentum(fTrackMomentum);
1717   fStepSum[idvol]+=gMC->TrackStep();
1718   
1719 //   if (GetDebug()) {
1720 //     Info("StepManager Step","iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
1721 //       iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg, mass, fStepSum[idvol], gMC->Edep());
1722 //     Info("StepManager Step","Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), fTrackMomentum.Z()) ;
1723 //     gMC->TrackPosition(fTrackPosition);
1724 //     Info("StepManager Step","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
1725 //   }
1726
1727   // Track left chamber or StepSum larger than fStepMaxInActiveGas
1728   if ( gMC->IsTrackExiting() || 
1729        gMC->IsTrackStop() || 
1730        gMC->IsTrackDisappeared()||
1731        (fStepSum[idvol]>fStepMaxInActiveGas) ) {
1732     
1733     if   ( gMC->IsTrackExiting() || 
1734            gMC->IsTrackStop() || 
1735            gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
1736
1737     gMC->TrackPosition(fTrackPosition);
1738     Float_t theta = fTrackMomentum.Theta();
1739     Float_t phi   = fTrackMomentum.Phi();
1740     
1741     TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
1742                                fStepSum[idvol]/2.*sin(theta)*sin(phi),
1743                                fStepSum[idvol]/2.*cos(theta),0.0       );
1744     //     if (GetDebug()) 
1745     //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
1746     //     if (GetDebug()) 
1747     //        Info("StepManager Exit ","Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z()) ;
1748     fTrackPosition-=backToWire;
1749     
1750     //-------------- Angle effect 
1751     // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
1752     
1753     Float_t betaxGamma    = fTrackMomentum.P()/mass;//  pc/mc2
1754     Float_t sigmaEffect10degrees;
1755     Float_t sigmaEffectThetadegrees;
1756     Float_t eLossParticleELossMip;
1757     Float_t yAngleEffect=0.;
1758     Float_t thetawires      =  TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
1759
1760
1761     if (fAngleEffect){
1762     if ( (betaxGamma >3.2)   &&  (thetawires*kRaddeg<=15.) ) {
1763       betaxGamma=TMath::Log(betaxGamma);
1764       eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
1765       // 10 degrees is a reference for a model (arbitrary)
1766       sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
1767       // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
1768       sigmaEffectThetadegrees =  sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg);  // For 5mm gap  
1769       if ( (iChamber==1)  ||  (iChamber==2) )  
1770         sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
1771       yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
1772     }
1773     }
1774     
1775     // One hit per chamber
1776     GetMUONData()->AddHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), iChamber, ipart, 
1777                           fTrackPosition.X(), fTrackPosition.Y()+yAngleEffect, fTrackPosition.Z(), 0.0, 
1778                           fTrackMomentum.P(),theta, phi, fStepSum[idvol], fDestepSum[idvol],
1779                           fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z());
1780 //     if (GetDebug()){
1781 //       Info("StepManager Exit","Particle exiting from chamber %d",iChamber);
1782 //       Info("StepManager Exit","StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]);
1783 //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
1784 //     }
1785     fStepSum[idvol]  =0; // Reset for the next event
1786     fDestepSum[idvol]=0; // Reset for the next event
1787   }
1788 }
1789
1790 //__________________________________________
1791 void AliMUONv3::StepManagerOld()
1792 {
1793   // Old Stepmanager for the chambers
1794   Int_t          copy, id;
1795   static Int_t   idvol;
1796   static Int_t   vol[2];
1797   Int_t          ipart;
1798   TLorentzVector pos;
1799   TLorentzVector mom;
1800   Float_t        theta,phi;
1801   Float_t        destep, step;
1802   
1803   static Float_t sstep;
1804   static Float_t eloss, eloss2, xhit, yhit, zhit, tof, tlength;
1805   const  Float_t kBig = 1.e10;
1806   static Float_t hits[15];
1807
1808   TClonesArray &lhits = *fHits;
1809
1810   //
1811   //
1812   // Only charged tracks
1813   if( !(gMC->TrackCharge()) ) return; 
1814   //
1815   // Only gas gap inside chamber
1816   // Tag chambers and record hits when track enters 
1817   id=gMC->CurrentVolID(copy);
1818   vol[0] = GetChamberId(id);
1819   idvol = vol[0] -1;
1820
1821   if (idvol == -1) return;
1822
1823   //
1824   // Get current particle id (ipart), track position (pos)  and momentum (mom) 
1825   gMC->TrackPosition(pos);
1826   gMC->TrackMomentum(mom);
1827
1828   ipart  = gMC->TrackPid();
1829
1830   //
1831   // momentum loss and steplength in last step
1832   destep = gMC->Edep();
1833   step   = gMC->TrackStep();
1834   // cout<<"------------"<<step<<endl;
1835   //
1836   // record hits when track enters ...
1837   if( gMC->IsTrackEntering()) {
1838
1839       gMC->SetMaxStep(fMaxStepGas);
1840       Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
1841       Double_t rt = TMath::Sqrt(tc);
1842       Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
1843       Double_t tx = mom[0]/pmom;
1844       Double_t ty = mom[1]/pmom;
1845       Double_t tz = mom[2]/pmom;
1846       Double_t s  = ((AliMUONChamber*)(*fChambers)[idvol])
1847           ->ResponseModel()
1848           ->Pitch()/tz;
1849       theta   = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
1850       phi     = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
1851       hits[0] = Float_t(ipart);         // Geant3 particle type
1852       hits[1] = pos[0]+s*tx;            // X-position for hit
1853       hits[2] = pos[1]+s*ty;            // Y-position for hit
1854       hits[3] = pos[2]+s*tz;            // Z-position for hit
1855       hits[4] = theta;                  // theta angle of incidence
1856       hits[5] = phi;                    // phi angle of incidence 
1857       hits[8] = 0;//PadHits does not exist anymore  (Float_t) fNPadHits;    // first padhit
1858       hits[9] = -1;                     // last pad hit
1859       hits[10] = mom[3];                // hit momentum P
1860       hits[11] = mom[0];                // Px
1861       hits[12] = mom[1];                // Py
1862       hits[13] = mom[2];                // Pz
1863       tof=gMC->TrackTime();
1864       hits[14] = tof;                   // Time of flight
1865       tlength  = 0;
1866       eloss    = 0;
1867       eloss2   = 0;
1868       sstep=0;
1869       xhit     = pos[0];
1870       yhit     = pos[1];      
1871       zhit     = pos[2];      
1872       Chamber(idvol).ChargeCorrelationInit();
1873       // Only if not trigger chamber
1874
1875 //       printf("---------------------------\n");
1876 //       printf(">>>> Y =  %f \n",hits[2]);
1877 //       printf("---------------------------\n");
1878     
1879       
1880
1881      //  if(idvol < AliMUONConstants::NTrackingCh()) {
1882 //        //
1883 //        //  Initialize hit position (cursor) in the segmentation model 
1884 //        ((AliMUONChamber*) (*fChambers)[idvol])
1885 //            ->SigGenInit(pos[0], pos[1], pos[2]);
1886 //       } else {
1887 //        //geant3->Gpcxyz();
1888 //        //printf("In the Trigger Chamber #%d\n",idvol-9);
1889 //       }
1890   }
1891   eloss2+=destep;
1892   sstep+=step;
1893
1894   // cout<<sstep<<endl;
1895
1896   // 
1897   // Calculate the charge induced on a pad (disintegration) in case 
1898   //
1899   // Mip left chamber ...
1900   if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
1901       gMC->SetMaxStep(kBig);
1902       eloss   += destep;
1903       tlength += step;
1904       
1905       Float_t x0,y0,z0;
1906       Float_t localPos[3];
1907       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
1908       gMC->Gmtod(globalPos,localPos,1); 
1909
1910       if(idvol < AliMUONConstants::NTrackingCh()) {
1911 // tracking chambers
1912           x0 = 0.5*(xhit+pos[0]);
1913           y0 = 0.5*(yhit+pos[1]);
1914           z0 = 0.5*(zhit+pos[2]);
1915       } else {
1916 // trigger chambers
1917           x0 = xhit;
1918           y0 = yhit;
1919           z0 = 0.;
1920       }
1921       
1922
1923       //      if (eloss >0)  MakePadHits(x0,y0,z0,eloss,tof,idvol);
1924       
1925           
1926       hits[6] = tlength;   // track length
1927       hits[7] = eloss2;    // de/dx energy loss
1928
1929
1930       //      if (fNPadHits > (Int_t)hits[8]) {
1931       //          hits[8] = hits[8]+1;
1932       //          hits[9] = 0: // PadHits does not exist anymore (Float_t) fNPadHits;
1933       //}
1934 //
1935 //    new hit 
1936       
1937       new(lhits[fNhits++]) 
1938           AliMUONHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);
1939       eloss = 0; 
1940       //
1941       // Check additional signal generation conditions 
1942       // defined by the segmentation
1943       // model (boundary crossing conditions)
1944       // only for tracking chambers
1945   } else if 
1946       ((idvol < AliMUONConstants::NTrackingCh()) &&
1947        ((AliMUONChamber*) (*fChambers)[idvol])->SigGenCond(pos[0], pos[1], pos[2]))
1948   {
1949       ((AliMUONChamber*) (*fChambers)[idvol])
1950           ->SigGenInit(pos[0], pos[1], pos[2]);
1951       
1952       Float_t localPos[3];
1953       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
1954       gMC->Gmtod(globalPos,localPos,1); 
1955
1956       eloss    += destep;
1957
1958       // if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
1959       //        MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
1960       xhit     = pos[0];
1961       yhit     = pos[1]; 
1962       zhit     = pos[2];
1963       eloss = 0;
1964       tlength += step ;
1965       //
1966       // nothing special  happened, add up energy loss
1967   } else {        
1968       eloss   += destep;
1969       tlength += step ;
1970   }
1971 }
1972
1973