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