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