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