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