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