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