]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONv1.cxx
MC-dependent part of AliRun extracted in AliMC (F.Carminati)
[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      else {
615        gMC->Gsvolu("S05M", "TUBE", idAir, tpar, 3);
616        gMC->Gsvolu("S06M", "TUBE", idAir, tpar, 3);
617        gMC->Gspos("S05M", 1, "ALIC", 0., 0., zpos1 , 0, "ONLY");
618        gMC->Gspos("S06M", 1, "ALIC", 0., 0., zpos2 , 0, "ONLY");
619      }
620
621      // volumes for slat geometry (xx=5,..,10 chamber id): 
622      // Sxx0 Sxx1 Sxx2 Sxx3  -->   Slat Mother volumes 
623      // SxxG                          -->   Sensitive volume (gas)
624      // SxxP                          -->   PCB (copper) 
625      // SxxI                          -->   Insulator (vetronite) 
626      // SxxC                          -->   Carbon panel 
627      // SxxR                          -->   Rohacell
628      // SxxH, SxxV                    -->   Horizontal and Vertical frames (vetronite)
629      // SB5x                          -->   Volumes for the 35 cm long PCB
630      // slat dimensions: slat is a MOTHER volume!!! made of air
631
632      // only for chamber 5: slat 1 has a PCB shorter by 5cm!
633
634      Float_t tlength = 35.;
635      Float_t panelpar2[3]  = { tlength/2., panelpar[1],  panelpar[2]}; 
636      Float_t rohapar2[3]   = { tlength/2., rohapar[1],   rohapar[2]}; 
637      Float_t insupar2[3]   = { tlength/2., insupar[1],   insupar[2]}; 
638      Float_t pcbpar2[3]    = { tlength/2., pcbpar[1],    pcbpar[2]}; 
639      Float_t senspar2[3]   = { tlength/2., senspar[1],   senspar[2]}; 
640      Float_t hFramepar2[3] = { tlength/2., hFramepar[1], hFramepar[2]}; 
641      Float_t bFramepar2[3] = { tlength/2., bFramepar[1], bFramepar[2]}; 
642
643      const Int_t nSlats3 = 5;  // number of slats per quadrant
644      const Int_t nPCB3[nSlats3] = {3,3,4,3,2}; // n PCB per slat
645      const Float_t xpos3[nSlats3] = {31., 40., 0., 0., 0.};
646      Float_t slatLength3[nSlats3]; 
647
648      // create and position the slat (mother) volumes 
649
650      char volNam5[5];
651      char volNam6[5];
652      Float_t xSlat3;
653
654      Float_t spar2[3];
655      for (i = 0; i<nSlats3; i++){
656        slatLength3[i] = pcbLength * nPCB3[i] + 2. * dSlatLength; 
657        xSlat3 = slatLength3[i]/2. - vFrameLength/2. + xpos3[i]; 
658        if (i==1 || i==0) slatLength3[i] -=  2. *dSlatLength; // frame out in PCB with circular border 
659        Float_t ySlat31 =  sensHeight * i - yOverlap * i; 
660        Float_t ySlat32 = -sensHeight * i + yOverlap * i; 
661        spar[0] = slatLength3[i]/2.; 
662        spar[1] = slatHeight/2.;
663        spar[2] = slatWidth/2. * 1.01; 
664        // take away 5 cm from the first slat in chamber 5
665        Float_t xSlat32 = 0;
666        if (i==1 || i==2) { // 1 pcb is shortened by 5cm
667          spar2[0] = spar[0]-5./2.;
668          xSlat32 = xSlat3 - 5/2.;
669        }
670        else {
671          spar2[0] = spar[0];
672          xSlat32 = xSlat3;
673        }
674        spar2[1] = spar[1];
675        spar2[2] = spar[2]; 
676        Float_t dzCh3=spar[2] * 1.01;
677        // zSlat to be checked (odd downstream or upstream?)
678        Float_t zSlat = (i%2 ==0)? -spar[2] : spar[2]; 
679        sprintf(volNam5,"S05%d",i);
680        gMC->Gsvolu(volNam5,"BOX",slatMaterial,spar2,3);
681        gMC->Gspos(volNam5, i*4+1,slats5Mother, -xSlat32, ySlat31, zoffs5-zSlat-2.*dzCh3, 0, "ONLY");
682        gMC->Gspos(volNam5, i*4+2,slats5Mother, +xSlat32, ySlat31, zoffs5-zSlat+2.*dzCh3, 0, "ONLY");
683        
684        if (i>0) { 
685          gMC->Gspos(volNam5, i*4+3,slats5Mother,-xSlat32, ySlat32, zoffs5-zSlat-2.*dzCh3, 0, "ONLY");
686          gMC->Gspos(volNam5, i*4+4,slats5Mother,+xSlat32, ySlat32, zoffs5-zSlat+2.*dzCh3, 0, "ONLY");
687        }
688        sprintf(volNam6,"S06%d",i);
689        gMC->Gsvolu(volNam6,"BOX",slatMaterial,spar,3);
690        gMC->Gspos(volNam6, i*4+1,slats6Mother,-xSlat3, ySlat31, zoffs6-zSlat-2.*dzCh3, 0, "ONLY");
691        gMC->Gspos(volNam6, i*4+2,slats6Mother,+xSlat3, ySlat31, zoffs6-zSlat+2.*dzCh3, 0, "ONLY");
692        if (i>0) { 
693          gMC->Gspos(volNam6, i*4+3,slats6Mother,-xSlat3, ySlat32, zoffs6-zSlat-2.*dzCh3, 0, "ONLY");
694          gMC->Gspos(volNam6, i*4+4,slats6Mother,+xSlat3, ySlat32, zoffs6-zSlat+2.*dzCh3, 0, "ONLY");
695        }
696      }
697
698      // create the panel volume 
699  
700      gMC->Gsvolu("S05C","BOX",panelMaterial,panelpar,3);
701      gMC->Gsvolu("SB5C","BOX",panelMaterial,panelpar2,3);
702      gMC->Gsvolu("S06C","BOX",panelMaterial,panelpar,3);
703
704      // create the rohacell volume 
705
706      gMC->Gsvolu("S05R","BOX",rohaMaterial,rohapar,3);
707      gMC->Gsvolu("SB5R","BOX",rohaMaterial,rohapar2,3);
708      gMC->Gsvolu("S06R","BOX",rohaMaterial,rohapar,3);
709
710      // create the insulating material volume 
711
712      gMC->Gsvolu("S05I","BOX",insuMaterial,insupar,3);
713      gMC->Gsvolu("SB5I","BOX",insuMaterial,insupar2,3);
714      gMC->Gsvolu("S06I","BOX",insuMaterial,insupar,3);
715
716      // create the PCB volume 
717
718      gMC->Gsvolu("S05P","BOX",pcbMaterial,pcbpar,3);
719      gMC->Gsvolu("SB5P","BOX",pcbMaterial,pcbpar2,3);
720      gMC->Gsvolu("S06P","BOX",pcbMaterial,pcbpar,3);
721  
722      // create the sensitive volumes,
723      gMC->Gsvolu("S05G","BOX",sensMaterial,dum,0);
724      gMC->Gsvolu("S06G","BOX",sensMaterial,dum,0);
725
726
727      // create the vertical frame volume 
728
729      gMC->Gsvolu("S05V","BOX",vFrameMaterial,vFramepar,3);
730      gMC->Gsvolu("S06V","BOX",vFrameMaterial,vFramepar,3);
731
732      // create the horizontal frame volume 
733
734      gMC->Gsvolu("S05H","BOX",hFrameMaterial,hFramepar,3);
735      gMC->Gsvolu("SB5H","BOX",hFrameMaterial,hFramepar2,3);
736      gMC->Gsvolu("S06H","BOX",hFrameMaterial,hFramepar,3);
737
738      // create the horizontal border volume 
739
740      gMC->Gsvolu("S05B","BOX",bFrameMaterial,bFramepar,3);
741      gMC->Gsvolu("SB5B","BOX",bFrameMaterial,bFramepar2,3);
742      gMC->Gsvolu("S06B","BOX",bFrameMaterial,bFramepar,3);
743
744      index=0; 
745      for (i = 0; i<nSlats3; i++){
746        sprintf(volNam5,"S05%d",i);
747        sprintf(volNam6,"S06%d",i);
748        Float_t xvFrame  = (slatLength3[i] - vFrameLength)/2.;
749        Float_t xvFrame2  = xvFrame;
750        if ( i==1 || i ==2 ) xvFrame2 -= 5./2.;
751        // position the vertical frames 
752        if (i!=1 && i!=0) { 
753          gMC->Gspos("S05V",2*i-1,volNam5, xvFrame2, 0., 0. , 0, "ONLY");
754          gMC->Gspos("S05V",2*i  ,volNam5,-xvFrame2, 0., 0. , 0, "ONLY");
755          gMC->Gspos("S06V",2*i-1,volNam6, xvFrame, 0., 0. , 0, "ONLY");
756          gMC->Gspos("S06V",2*i  ,volNam6,-xvFrame, 0., 0. , 0, "ONLY");
757        }       
758        // position the panels and the insulating material 
759        for (j=0; j<nPCB3[i]; j++){
760          index++;
761          Float_t xx = sensLength * (-nPCB3[i]/2.+j+.5); 
762          Float_t xx2 = xx + 5/2.; 
763          
764          Float_t zPanel = spar[2] - panelpar[2]; 
765          if ( (i==1 || i==2) && j == nPCB3[i]-1) { // 1 pcb is shortened by 5cm 
766            gMC->Gspos("SB5C",2*index-1,volNam5, xx, 0., zPanel , 0, "ONLY");
767            gMC->Gspos("SB5C",2*index  ,volNam5, xx, 0.,-zPanel , 0, "ONLY");
768            gMC->Gspos("SB5I",index    ,volNam5, xx, 0., 0      , 0, "ONLY");
769          }
770          else if ( (i==1 || i==2) && j < nPCB3[i]-1) {
771            gMC->Gspos("S05C",2*index-1,volNam5, xx2, 0., zPanel , 0, "ONLY");
772            gMC->Gspos("S05C",2*index  ,volNam5, xx2, 0.,-zPanel , 0, "ONLY");
773            gMC->Gspos("S05I",index    ,volNam5, xx2, 0., 0 , 0, "ONLY");
774          }
775          else {
776            gMC->Gspos("S05C",2*index-1,volNam5, xx, 0., zPanel , 0, "ONLY");
777            gMC->Gspos("S05C",2*index  ,volNam5, xx, 0.,-zPanel , 0, "ONLY");
778            gMC->Gspos("S05I",index    ,volNam5, xx, 0., 0 , 0, "ONLY");
779          }
780          gMC->Gspos("S06C",2*index-1,volNam6, xx, 0., zPanel , 0, "ONLY");
781          gMC->Gspos("S06C",2*index  ,volNam6, xx, 0.,-zPanel , 0, "ONLY");
782          gMC->Gspos("S06I",index,volNam6, xx, 0., 0 , 0, "ONLY");
783        } 
784      }
785      
786      // position the rohacell volume inside the panel volume
787      gMC->Gspos("S05R",1,"S05C",0.,0.,0.,0,"ONLY"); 
788      gMC->Gspos("SB5R",1,"SB5C",0.,0.,0.,0,"ONLY"); 
789      gMC->Gspos("S06R",1,"S06C",0.,0.,0.,0,"ONLY"); 
790
791      // position the PCB volume inside the insulating material volume
792      gMC->Gspos("S05P",1,"S05I",0.,0.,0.,0,"ONLY"); 
793      gMC->Gspos("SB5P",1,"SB5I",0.,0.,0.,0,"ONLY"); 
794      gMC->Gspos("S06P",1,"S06I",0.,0.,0.,0,"ONLY"); 
795      // position the horizontal frame volume inside the PCB volume
796      gMC->Gspos("S05H",1,"S05P",0.,0.,0.,0,"ONLY"); 
797      gMC->Gspos("SB5H",1,"SB5P",0.,0.,0.,0,"ONLY"); 
798      gMC->Gspos("S06H",1,"S06P",0.,0.,0.,0,"ONLY"); 
799      // position the sensitive volume inside the horizontal frame volume
800      gMC->Gsposp("S05G",1,"S05H",0.,0.,0.,0,"ONLY",senspar,3); 
801      gMC->Gsposp("S05G",1,"SB5H",0.,0.,0.,0,"ONLY",senspar2,3); 
802      gMC->Gsposp("S06G",1,"S06H",0.,0.,0.,0,"ONLY",senspar,3); 
803      // position the border volumes inside the PCB volume
804      Float_t yborder = ( pcbHeight - bFrameHeight ) / 2.; 
805      gMC->Gspos("S05B",1,"S05P",0., yborder,0.,0,"ONLY"); 
806      gMC->Gspos("S05B",2,"S05P",0.,-yborder,0.,0,"ONLY"); 
807      gMC->Gspos("SB5B",1,"SB5P",0., yborder,0.,0,"ONLY"); 
808      gMC->Gspos("SB5B",2,"SB5P",0.,-yborder,0.,0,"ONLY"); 
809      gMC->Gspos("S06B",1,"S06P",0., yborder,0.,0,"ONLY"); 
810      gMC->Gspos("S06B",2,"S06P",0.,-yborder,0.,0,"ONLY"); 
811
812      // create the NULOC volume and position it in the horizontal frame
813
814      gMC->Gsvolu("S05N","BOX",nulocMaterial,nulocpar,3);
815      gMC->Gsvolu("S06N","BOX",nulocMaterial,nulocpar,3);
816      index = 0;
817      Float_t xxmax2 = xxmax - 5./2.;
818      for (xx = -xxmax; xx<=xxmax; xx+=2*nulocLength) { 
819        index++; 
820        gMC->Gspos("S05N",2*index-1,"S05B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
821        gMC->Gspos("S05N",2*index  ,"S05B", xx, 0., bFrameWidth/4., 0, "ONLY");
822        if (xx > -xxmax2 && xx< xxmax2) {
823          gMC->Gspos("S05N",2*index-1,"SB5B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
824          gMC->Gspos("S05N",2*index  ,"SB5B", xx, 0., bFrameWidth/4., 0, "ONLY");
825        }
826        gMC->Gspos("S06N",2*index-1,"S06B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
827        gMC->Gspos("S06N",2*index  ,"S06B", xx, 0., bFrameWidth/4., 0, "ONLY");
828      }
829      
830      // position the volumes approximating the circular section of the pipe
831      Float_t yoffs = sensHeight/2. - yOverlap; 
832      Float_t epsilon = 0.001; 
833      Int_t ndiv=6;
834      Float_t divpar[3];
835      Double_t dydiv= sensHeight/ndiv;
836      Double_t ydiv = yoffs -dydiv;
837      Int_t imax=0; 
838      imax = 1; 
839      Float_t rmin = 33.; 
840      Float_t z1 = spar[2], z2=2*spar[2]*1.01; 
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] = (pcbLength-xdiv)/2.; 
846        divpar[1] = dydiv/2. - epsilon;
847        divpar[2] = sensWidth/2.; 
848        Float_t xvol=(pcbLength+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 nSlats4 = 6;  // number of slats per quadrant
890      const Int_t nPCB4[nSlats4] = {4,4,5,5,4,3}; // n PCB per slat
891      const Float_t xpos4[nSlats4] = {38.5, 40., 0., 0., 0., 0.};
892      Float_t slatLength4[nSlats4];     
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<nSlats4; i++){
902        slatLength4[i] = pcbLength * nPCB4[i] + 2. * dSlatLength; 
903        xSlat4 = slatLength4[i]/2. - vFrameLength/2. + xpos4[i]; 
904        if (i==1) slatLength4[i] -=  2. *dSlatLength; // frame out in PCB with circular border 
905        ySlat4 =  sensHeight * i - yOverlap *i;
906        
907        spar[0] = slatLength4[i]/2.; 
908        spar[1] = slatHeight/2.;
909        spar[2] = slatWidth/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",slatMaterial,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",slatMaterial,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",panelMaterial,panelpar,3);
935      gMC->Gsvolu("S08C","BOX",panelMaterial,panelpar,3);
936
937      // create the rohacell volume 
938
939      gMC->Gsvolu("S07R","BOX",rohaMaterial,rohapar,3);
940      gMC->Gsvolu("S08R","BOX",rohaMaterial,rohapar,3);
941
942      // create the insulating material volume 
943
944      gMC->Gsvolu("S07I","BOX",insuMaterial,insupar,3);
945      gMC->Gsvolu("S08I","BOX",insuMaterial,insupar,3);
946
947      // create the PCB volume 
948
949      gMC->Gsvolu("S07P","BOX",pcbMaterial,pcbpar,3);
950      gMC->Gsvolu("S08P","BOX",pcbMaterial,pcbpar,3);
951  
952      // create the sensitive volumes,
953
954      gMC->Gsvolu("S07G","BOX",sensMaterial,dum,0);
955      gMC->Gsvolu("S08G","BOX",sensMaterial,dum,0);
956
957      // create the vertical frame volume 
958
959      gMC->Gsvolu("S07V","BOX",vFrameMaterial,vFramepar,3);
960      gMC->Gsvolu("S08V","BOX",vFrameMaterial,vFramepar,3);
961
962      // create the horizontal frame volume 
963
964      gMC->Gsvolu("S07H","BOX",hFrameMaterial,hFramepar,3);
965      gMC->Gsvolu("S08H","BOX",hFrameMaterial,hFramepar,3);
966
967      // create the horizontal border volume 
968
969      gMC->Gsvolu("S07B","BOX",bFrameMaterial,bFramepar,3);
970      gMC->Gsvolu("S08B","BOX",bFrameMaterial,bFramepar,3);
971
972      index=0; 
973      for (i = 0; i<nSlats4; i++){
974        sprintf(volNam7,"S07%d",i);
975        sprintf(volNam8,"S08%d",i);
976        Float_t xvFrame  = (slatLength4[i] - vFrameLength)/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<nPCB4[i]; j++){
986          index++;
987          Float_t xx = sensLength * (-nPCB4[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 = ( pcbHeight - bFrameHeight ) / 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",nulocMaterial,nulocpar,3);
1023      gMC->Gsvolu("S08N","BOX",nulocMaterial,nulocpar,3);
1024      index = 0;
1025      for (xx = -xxmax; xx<=xxmax; xx+=2*nulocLength) { 
1026        index++; 
1027        gMC->Gspos("S07N",2*index-1,"S07B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
1028        gMC->Gspos("S07N",2*index  ,"S07B", xx, 0., bFrameWidth/4., 0, "ONLY");
1029        gMC->Gspos("S08N",2*index-1,"S08B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
1030        gMC->Gspos("S08N",2*index  ,"S08B", xx, 0., bFrameWidth/4., 0, "ONLY");
1031      }
1032
1033      // position the volumes approximating the circular section of the pipe
1034      Float_t yoffs = sensHeight/2. - yOverlap; 
1035      Float_t epsilon = 0.001; 
1036      Int_t ndiv=6;
1037      Float_t divpar[3];
1038      Double_t dydiv= sensHeight/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] = (pcbLength-xdiv)/2.; 
1049        divpar[1] = dydiv/2. - epsilon;
1050        divpar[2] = sensWidth/2.; 
1051        Float_t xvol=(pcbLength+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 nSlats5 = 7;  // number of slats per quadrant
1098      const Int_t nPCB5[nSlats5] = {5,5,6,6,5,4,3}; // n PCB per slat
1099      const Float_t xpos5[nSlats5] = {38.5, 40., 0., 0., 0., 0., 0.};
1100      Float_t slatLength5[nSlats5]; 
1101      char volNam9[5];
1102      char volNam10[5];
1103      Float_t xSlat5;
1104      Float_t ySlat5;
1105
1106      for (i = 0; i<nSlats5; i++){
1107        slatLength5[i] = pcbLength * nPCB5[i] + 2. * dSlatLength; 
1108        xSlat5 = slatLength5[i]/2. - vFrameLength/2. +xpos5[i]; 
1109        if (i==1 || i==0) slatLength5[i] -=  2. *dSlatLength; // frame out in PCB with circular border 
1110        ySlat5 = sensHeight * i - yOverlap * i; 
1111        spar[0] = slatLength5[i]/2.; 
1112        spar[1] = slatHeight/2.;
1113        spar[2] = slatWidth/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",slatMaterial,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",slatMaterial,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",panelMaterial,panelpar,3);
1138      gMC->Gsvolu("S10C","BOX",panelMaterial,panelpar,3);
1139
1140      // create the rohacell volume 
1141
1142      gMC->Gsvolu("S09R","BOX",rohaMaterial,rohapar,3);
1143      gMC->Gsvolu("S10R","BOX",rohaMaterial,rohapar,3);
1144
1145      // create the insulating material volume 
1146
1147      gMC->Gsvolu("S09I","BOX",insuMaterial,insupar,3);
1148      gMC->Gsvolu("S10I","BOX",insuMaterial,insupar,3);
1149
1150      // create the PCB volume 
1151
1152      gMC->Gsvolu("S09P","BOX",pcbMaterial,pcbpar,3);
1153      gMC->Gsvolu("S10P","BOX",pcbMaterial,pcbpar,3);
1154  
1155      // create the sensitive volumes,
1156
1157      gMC->Gsvolu("S09G","BOX",sensMaterial,dum,0);
1158      gMC->Gsvolu("S10G","BOX",sensMaterial,dum,0);
1159
1160      // create the vertical frame volume 
1161
1162      gMC->Gsvolu("S09V","BOX",vFrameMaterial,vFramepar,3);
1163      gMC->Gsvolu("S10V","BOX",vFrameMaterial,vFramepar,3);
1164
1165      // create the horizontal frame volume 
1166
1167      gMC->Gsvolu("S09H","BOX",hFrameMaterial,hFramepar,3);
1168      gMC->Gsvolu("S10H","BOX",hFrameMaterial,hFramepar,3);
1169
1170      // create the horizontal border volume 
1171
1172      gMC->Gsvolu("S09B","BOX",bFrameMaterial,bFramepar,3);
1173      gMC->Gsvolu("S10B","BOX",bFrameMaterial,bFramepar,3);
1174
1175      index=0; 
1176      for (i = 0; i<nSlats5; i++){
1177        sprintf(volNam9,"S09%d",i);
1178        sprintf(volNam10,"S10%d",i);
1179        Float_t xvFrame  = (slatLength5[i] - vFrameLength)/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<nPCB5[i]; j++){
1190          index++;
1191          Float_t xx = sensLength * (-nPCB5[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 = ( pcbHeight - bFrameHeight ) / 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",nulocMaterial,nulocpar,3);
1227      gMC->Gsvolu("S10N","BOX",nulocMaterial,nulocpar,3);
1228      index = 0;
1229      for (xx = -xxmax; xx<=xxmax; xx+=2*nulocLength) { 
1230        index++; 
1231        gMC->Gspos("S09N",2*index-1,"S09B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
1232        gMC->Gspos("S09N",2*index  ,"S09B", xx, 0., bFrameWidth/4., 0, "ONLY");
1233        gMC->Gspos("S10N",2*index-1,"S10B", xx, 0.,-bFrameWidth/4., 0, "ONLY");
1234        gMC->Gspos("S10N",2*index  ,"S10B", xx, 0., bFrameWidth/4., 0, "ONLY");
1235      }
1236      // position the volumes approximating the circular section of the pipe
1237      Float_t yoffs = sensHeight/2. - yOverlap; 
1238      Float_t epsilon = 0.001; 
1239      Int_t ndiv=6;
1240      Float_t divpar[3];
1241      Double_t dydiv= sensHeight/ndiv;
1242      Double_t ydiv = yoffs -dydiv;
1243      Int_t imax=0; 
1244      //     for (Int_t islat=0; islat<nSlats3; islat++) imax += nPCB3[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] = (pcbLength-xdiv)/2.; 
1253        divpar[1] = dydiv/2. - epsilon;
1254        divpar[2] = sensWidth/2.; 
1255        Float_t xvol=(pcbLength+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  if (fStepManagerVersionOld) {
1645     StepManagerOld();
1646     return;
1647   }
1648
1649   // Only charged tracks
1650   if( !(gMC->TrackCharge()) ) return; 
1651   // Only charged tracks
1652   
1653   // Only gas gap inside chamber
1654   // Tag chambers and record hits when track enters 
1655   Int_t   idvol=-1;
1656   Int_t   iChamber=0;
1657   Int_t   id=0;
1658   Int_t   copy;
1659   const  Float_t kBig = 1.e10;
1660
1661   id=gMC->CurrentVolID(copy);
1662   // printf("id == %d \n",id);
1663   for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++) {
1664     if(id==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()) {
1665       iChamber = i;
1666       idvol  = i-1;
1667     }
1668   }
1669   if (idvol == -1) {
1670     return;
1671   }
1672
1673    if( gMC->IsTrackEntering() ) {
1674      Float_t theta = fTrackMomentum.Theta();
1675      if ( (theta>=10) ) gMC->SetMaxStep(fStepMaxInActiveGas);
1676    }
1677
1678 //  if (GetDebug()) {
1679 //     Float_t z = ( (AliMUONChamber*)(*fChambers)[idvol])->Z() ;
1680 //      Info("StepManager Step","Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber, z);
1681 //   }  
1682   // Particule id and mass, 
1683   Int_t     ipart = gMC->TrackPid();
1684   Float_t   mass  = gMC->TrackMass();
1685
1686   fDestepSum[idvol]+=gMC->Edep();
1687   // Get current particle id (ipart), track position (pos)  and momentum (mom)
1688   if ( fStepSum[idvol]==0.0 )  gMC->TrackMomentum(fTrackMomentum);
1689   fStepSum[idvol]+=gMC->TrackStep();
1690   
1691 //   if (GetDebug()) {
1692 //     Info("StepManager Step","iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
1693 //       iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg, mass, fStepSum[idvol], gMC->Edep());
1694 //     Info("StepManager Step","Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), fTrackMomentum.Z()) ;
1695 //     gMC->TrackPosition(fTrackPosition);
1696 //     Info("StepManager Step","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
1697 //   }
1698
1699   // Track left chamber or StepSum larger than fStepMaxInActiveGas
1700   if ( gMC->IsTrackExiting() || 
1701        gMC->IsTrackStop() || 
1702        gMC->IsTrackDisappeared()||
1703        (fStepSum[idvol]>fStepMaxInActiveGas) ) {
1704     
1705     if   ( gMC->IsTrackExiting() || 
1706            gMC->IsTrackStop() || 
1707            gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
1708
1709     gMC->TrackPosition(fTrackPosition);
1710     Float_t theta = fTrackMomentum.Theta();
1711     Float_t phi   = fTrackMomentum.Phi();
1712     
1713     TLorentzVector BackToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
1714                                fStepSum[idvol]/2.*sin(theta)*sin(phi),
1715                                fStepSum[idvol]/2.*cos(theta),0.0       );
1716     //     if (GetDebug()) 
1717     //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
1718     //     if (GetDebug()) 
1719     //        Info("StepManager Exit ","Track BackToWire %f %f %f",BackToWire.X(),BackToWire.Y(),BackToWire.Z()) ;
1720     fTrackPosition-=BackToWire;
1721     
1722     //-------------- Angle effect 
1723     // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
1724     
1725     Float_t Beta_x_Gamma    = fTrackMomentum.P()/mass;//  pc/mc2
1726     Float_t SigmaEffect_10degrees;
1727     Float_t SigmaEffect_thetadegrees;
1728     Float_t ELossParticle_ELossMip;
1729     Float_t YAngleEffect=0.;
1730     Float_t theta_wires      =  TMath::Abs( TMath::ASin( TMath::Sin(theta) * TMath::Sin(phi) ) );
1731     
1732     if ( (Beta_x_Gamma >3.2)   &&  (theta_wires*kRaddeg<=10) ) {
1733       Beta_x_Gamma=TMath::Log(Beta_x_Gamma);
1734       ELossParticle_ELossMip = fElossRatio->Eval(Beta_x_Gamma);
1735       // 10 degrees is a reference for a model (arbitrary)
1736       SigmaEffect_10degrees=fAngleEffect10->Eval(ELossParticle_ELossMip);// in micrometers
1737       // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
1738       SigmaEffect_thetadegrees =  SigmaEffect_10degrees/fAngleEffectNorma->Eval(theta_wires*kRaddeg);  // For 5mm gap  
1739       if ( (iChamber==1)  ||  (iChamber==2) )  
1740         SigmaEffect_thetadegrees/=(1.09833e+00+1.70000e-02*theta_wires*kRaddeg); // The gap is different (4mm)
1741       YAngleEffect=1.e-04*gRandom->Gaus(0,SigmaEffect_thetadegrees); // Error due to the angle effect in cm
1742     }
1743     
1744     
1745     // One hit per chamber
1746     GetMUONData()->AddHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), iChamber, ipart, 
1747                           fTrackPosition.X(), fTrackPosition.Y()+YAngleEffect, fTrackPosition.Z(), 0.0, 
1748                           fTrackMomentum.P(),theta, phi, fStepSum[idvol], fDestepSum[idvol],
1749                           fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z());
1750 //     if (GetDebug()){
1751 //       Info("StepManager Exit","Particle exiting from chamber %d",iChamber);
1752 //       Info("StepManager Exit","StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]);
1753 //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
1754 //     }
1755     fStepSum[idvol]  =0; // Reset for the next event
1756     fDestepSum[idvol]=0; // Reset for the next event
1757   }
1758 }
1759
1760 //___________________________________________
1761 void AliMUONv1::StepManagerOld()
1762 {
1763   Int_t          copy, id;
1764   static Int_t   idvol;
1765   static Int_t   vol[2];
1766   Int_t          ipart;
1767   TLorentzVector pos;
1768   TLorentzVector mom;
1769   Float_t        theta,phi;
1770   Float_t        destep, step;
1771   
1772   static Float_t Sstep;
1773   static Float_t eloss, eloss2, xhit, yhit, zhit, tof, tlength;
1774   const  Float_t kBig = 1.e10;
1775   static Float_t hits[15];
1776
1777   TClonesArray &lhits = *fHits;
1778
1779   //
1780   //
1781   // Only charged tracks
1782   if( !(gMC->TrackCharge()) ) return; 
1783   //
1784   // Only gas gap inside chamber
1785   // Tag chambers and record hits when track enters 
1786   id=gMC->CurrentVolID(copy);
1787   vol[0] = GetChamberId(id);
1788   idvol = vol[0] -1;
1789
1790   if (idvol == -1) return;
1791
1792   //
1793   // Get current particle id (ipart), track position (pos)  and momentum (mom) 
1794   gMC->TrackPosition(pos);
1795   gMC->TrackMomentum(mom);
1796
1797   ipart  = gMC->TrackPid();
1798
1799   //
1800   // momentum loss and steplength in last step
1801   destep = gMC->Edep();
1802   step   = gMC->TrackStep();
1803   // cout<<"------------"<<step<<endl;
1804   //
1805   // record hits when track enters ...
1806   if( gMC->IsTrackEntering()) {
1807
1808       gMC->SetMaxStep(fMaxStepGas);
1809       Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
1810       Double_t rt = TMath::Sqrt(tc);
1811       Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
1812       Double_t tx = mom[0]/pmom;
1813       Double_t ty = mom[1]/pmom;
1814       Double_t tz = mom[2]/pmom;
1815       Double_t s  = ((AliMUONChamber*)(*fChambers)[idvol])
1816           ->ResponseModel()
1817           ->Pitch()/tz;
1818       theta   = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
1819       phi     = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
1820       hits[0] = Float_t(ipart);         // Geant3 particle type
1821       hits[1] = pos[0]+s*tx;            // X-position for hit
1822       hits[2] = pos[1]+s*ty;            // Y-position for hit
1823       hits[3] = pos[2]+s*tz;            // Z-position for hit
1824       hits[4] = theta;                  // theta angle of incidence
1825       hits[5] = phi;                    // phi angle of incidence 
1826       hits[8] = 0;//PadHits does not exist anymore  (Float_t) fNPadHits;    // first padhit
1827       hits[9] = -1;                     // last pad hit
1828       hits[10] = mom[3];                // hit momentum P
1829       hits[11] = mom[0];                // Px
1830       hits[12] = mom[1];                // Py
1831       hits[13] = mom[2];                // Pz
1832       tof=gMC->TrackTime();
1833       hits[14] = tof;                   // Time of flight
1834       tlength  = 0;
1835       eloss    = 0;
1836       eloss2   = 0;
1837       Sstep=0;
1838       xhit     = pos[0];
1839       yhit     = pos[1];      
1840       zhit     = pos[2];      
1841       Chamber(idvol).ChargeCorrelationInit();
1842       // Only if not trigger chamber
1843
1844 //       printf("---------------------------\n");
1845 //       printf(">>>> Y =  %f \n",hits[2]);
1846 //       printf("---------------------------\n");
1847     
1848       
1849
1850      //  if(idvol < AliMUONConstants::NTrackingCh()) {
1851 //        //
1852 //        //  Initialize hit position (cursor) in the segmentation model 
1853 //        ((AliMUONChamber*) (*fChambers)[idvol])
1854 //            ->SigGenInit(pos[0], pos[1], pos[2]);
1855 //       } else {
1856 //        //geant3->Gpcxyz();
1857 //        //printf("In the Trigger Chamber #%d\n",idvol-9);
1858 //       }
1859   }
1860   eloss2+=destep;
1861   Sstep+=step;
1862
1863   // cout<<Sstep<<endl;
1864
1865   // 
1866   // Calculate the charge induced on a pad (disintegration) in case 
1867   //
1868   // Mip left chamber ...
1869   if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
1870       gMC->SetMaxStep(kBig);
1871       eloss   += destep;
1872       tlength += step;
1873       
1874       Float_t x0,y0,z0;
1875       Float_t localPos[3];
1876       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
1877       gMC->Gmtod(globalPos,localPos,1); 
1878
1879       if(idvol < AliMUONConstants::NTrackingCh()) {
1880 // tracking chambers
1881           x0 = 0.5*(xhit+pos[0]);
1882           y0 = 0.5*(yhit+pos[1]);
1883           z0 = 0.5*(zhit+pos[2]);
1884       } else {
1885 // trigger chambers
1886           x0 = xhit;
1887           y0 = yhit;
1888           z0 = 0.;
1889       }
1890       
1891
1892       //      if (eloss >0)  MakePadHits(x0,y0,z0,eloss,tof,idvol);
1893       
1894           
1895       hits[6] = tlength;   // track length
1896       hits[7] = eloss2;    // de/dx energy loss
1897
1898
1899       //      if (fNPadHits > (Int_t)hits[8]) {
1900       //          hits[8] = hits[8]+1;
1901       //          hits[9] = 0: // PadHits does not exist anymore (Float_t) fNPadHits;
1902       //}
1903 //
1904 //    new hit 
1905       
1906       new(lhits[fNhits++]) 
1907           AliMUONHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);
1908       eloss = 0; 
1909       //
1910       // Check additional signal generation conditions 
1911       // defined by the segmentation
1912       // model (boundary crossing conditions)
1913       // only for tracking chambers
1914   } else if 
1915       ((idvol < AliMUONConstants::NTrackingCh()) &&
1916        ((AliMUONChamber*) (*fChambers)[idvol])->SigGenCond(pos[0], pos[1], pos[2]))
1917   {
1918       ((AliMUONChamber*) (*fChambers)[idvol])
1919           ->SigGenInit(pos[0], pos[1], pos[2]);
1920       
1921       Float_t localPos[3];
1922       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
1923       gMC->Gmtod(globalPos,localPos,1); 
1924
1925       eloss    += destep;
1926
1927       // if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
1928       //        MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
1929       xhit     = pos[0];
1930       yhit     = pos[1]; 
1931       zhit     = pos[2];
1932       eloss = 0;
1933       tlength += step ;
1934       //
1935       // nothing special  happened, add up energy loss
1936   } else {        
1937       eloss   += destep;
1938       tlength += step ;
1939   }
1940 }
1941
1942