902f0209a440ef2c1eaa0f90ae0070d783a79a5a
[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 //                            Trigger                               **
1238 //******************************************************************** 
1239
1240  /* 
1241     zpos1 and zpos2 are the middle of the first and second
1242     planes of station 1 (+1m for second station):
1243     zpos1=(zpos1m+zpos1p)/2=(15999+16071)/2=16035 mm, thick/2=40 mm
1244     zpos2=(zpos2m+zpos2p)/2=(16169+16241)/2=16205 mm, thick/2=40 mm
1245     zposxm and zposxp= middles of gaz gaps within a detection plane
1246     rem: the total thickness accounts for 1 mm of al on both
1247     side of the RPCs (see zpos1 and zpos2)
1248  */
1249
1250 // vertical gap between right and left chambers (kDXZERO*2=4cm)
1251  const Float_t kDXZERO=2.; 
1252 // main distances for chamber definition in first plane/first station
1253  const Float_t kXMIN=34.;       
1254  const Float_t kXMED=51.;                                
1255  const Float_t kXMAX=272.; 
1256 // kXMAX will become 255. in real life. segmentation to be updated accordingly
1257 // (see fig.2-4 & 2-5 of Local Trigger Board PRR)
1258  const Float_t kYMIN=34.;                              
1259  const Float_t kYMAX=51.;                              
1260 // inner/outer radius of flange between beam shield. and chambers (1/station)
1261  const Float_t kRMIN[2]={50.,50.};
1262  const Float_t kRMAX[2]={64.,68.};
1263 // z position of the middle of the gas gap in mother vol 
1264  const Float_t kZm=-3.6;
1265  const Float_t kZp=+3.6;     
1266  
1267  iChamber1 = (AliMUONChamber*) (*fChambers)[10];     
1268  zpos1 = iChamber1->Z();
1269
1270 // ratio of zpos1m/zpos1p and inverse for first plane
1271  Float_t zmp=(zpos1-3.6)/(zpos1+3.6);
1272  Float_t zpm=1./zmp;
1273  
1274  Int_t icount=0; // chamber counter (0 1 2 3)
1275  
1276  for (Int_t istation=0; istation<2; istation++) { // loop on stations    
1277      for (Int_t iplane=0; iplane<2; iplane++) {   // loop on detection planes
1278          
1279          Int_t iVolNum=1; // counter Volume Number
1280          icount = Int_t(iplane*TMath::Power(2,0))+
1281              Int_t(istation*TMath::Power(2,1));
1282          
1283          char volPlane[5]; 
1284          sprintf(volPlane,"SM%d%d",istation+1,iplane+1);
1285          
1286          iChamber = (AliMUONChamber*) (*fChambers)[10+icount];
1287          Float_t zpos = iChamber->Z();       
1288          
1289 // mother volume 
1290          tpar[0] = iChamber->RInner(); 
1291          tpar[1] = iChamber->ROuter(); 
1292          tpar[2] = 4.0;    
1293          gMC->Gsvolu(volPlane,"TUBE",idAir,tpar,3);
1294          
1295 // Flange between beam shielding and RPC 
1296          tpar[0]= kRMIN[istation];
1297          tpar[1]= kRMAX[istation];
1298          tpar[2]= 4.0;
1299          
1300          char volFlange[5];
1301          sprintf(volFlange,"SF%dA",icount+1);    
1302          gMC->Gsvolu(volFlange,"TUBE",idAlu1,tpar,3);     //Al
1303          gMC->Gspos(volFlange,1,volPlane,0.,0.,0.,0,"MANY");
1304          
1305 // scaling factor
1306          Float_t zRatio = zpos / zpos1;
1307          
1308 // chamber prototype
1309          tpar[0]= 0.;
1310          tpar[1]= 0.;
1311          tpar[2]= 0.;
1312          
1313          char volAlu[5]; // Alu
1314          char volBak[5]; // Bakelite
1315          char volGaz[5]; // Gas streamer
1316          
1317          sprintf(volAlu,"SC%dA",icount+1);
1318          sprintf(volBak,"SB%dA",icount+1);
1319          sprintf(volGaz,"SG%dA",icount+1);
1320          
1321          gMC->Gsvolu(volAlu,"BOX",idAlu1,tpar,0);           // Al
1322          gMC->Gsvolu(volBak,"BOX",idtmed[1107],tpar,0);     // Bakelite
1323          gMC->Gsvolu(volGaz,"BOX",idtmed[1106],tpar,0);     // Gas streamer
1324          
1325 // chamber type A
1326          tpar[0] = -1.;
1327          tpar[1] = -1.;
1328          
1329          Float_t xA=(kDXZERO+kXMED+(kXMAX-kXMED)/2.)*zRatio;
1330          Float_t yAm=0.;
1331          Float_t yAp=0.;
1332          
1333          tpar[2] = 0.1;    
1334          gMC->Gsposp(volGaz,1,volBak,0.,0.,0.,0,"ONLY",tpar,3);
1335          tpar[2] = 0.3;
1336          gMC->Gsposp(volBak,1,volAlu,0.,0.,0.,0,"ONLY",tpar,3);
1337          
1338          tpar[2] = 0.4;
1339          tpar[0] = ((kXMAX-kXMED)/2.)*zRatio;
1340          tpar[1] = kYMIN*zRatio;
1341          
1342          gMC->Gsposp(volAlu,iVolNum++,volPlane, xA,yAm,kZm,0,"ONLY",tpar,3);
1343          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xA,yAp,kZp,0,"ONLY",tpar,3);
1344          gMC->Gsbool(volAlu,volFlange);
1345          
1346 // chamber type B    
1347          Float_t tpar1save=tpar[1];
1348          Float_t y1msave=yAm;
1349          Float_t y1psave=yAp;
1350          
1351          tpar[0] = ((kXMAX-kXMIN)/2.) * zRatio;
1352          tpar[1] = ((kYMAX-kYMIN)/2.) * zRatio;
1353          
1354          Float_t xB=(kDXZERO+kXMIN)*zRatio+tpar[0];
1355          Float_t yBp=(y1msave+tpar1save)*zpm+tpar[1];
1356          Float_t yBm=(y1psave+tpar1save)*zmp+tpar[1];    
1357
1358          gMC->Gsposp(volAlu,iVolNum++,volPlane, xB, yBp,kZp,0,"ONLY",tpar,3);
1359          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xB, yBm,kZm,0,"ONLY",tpar,3);
1360          gMC->Gsposp(volAlu,iVolNum++,volPlane, xB,-yBp,kZp,0,"ONLY",tpar,3);
1361          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xB,-yBm,kZm,0,"ONLY",tpar,3);
1362          
1363 // chamber type C (note : same Z than type B)
1364          tpar1save=tpar[1];
1365          y1msave=yBm;
1366          y1psave=yBp;
1367          
1368          tpar[0] = (kXMAX/2)*zRatio;
1369          tpar[1] = (kYMAX/2)*zRatio;
1370          
1371          Float_t xC=kDXZERO*zRatio+tpar[0];
1372          Float_t yCp=(y1psave+tpar1save)*1.+tpar[1];
1373          Float_t yCm=(y1msave+tpar1save)*1.+tpar[1];
1374          
1375          gMC->Gsposp(volAlu,iVolNum++,volPlane, xC, yCp,kZp,0,"ONLY",tpar,3);
1376          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xC, yCm,kZm,0,"ONLY",tpar,3);
1377          gMC->Gsposp(volAlu,iVolNum++,volPlane, xC,-yCp,kZp,0,"ONLY",tpar,3);
1378          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xC,-yCm,kZm,0,"ONLY",tpar,3);
1379                  
1380 // chamber type D, E and F (same size)        
1381          tpar1save=tpar[1];
1382          y1msave=yCm;
1383          y1psave=yCp;
1384          
1385          tpar[0] = (kXMAX/2.)*zRatio;
1386          tpar[1] =  kYMIN*zRatio;
1387          
1388          Float_t xD=kDXZERO*zRatio+tpar[0];
1389          Float_t yDp=(y1msave+tpar1save)*zpm+tpar[1];
1390          Float_t yDm=(y1psave+tpar1save)*zmp+tpar[1];
1391          
1392          gMC->Gsposp(volAlu,iVolNum++,volPlane, xD, yDm,kZm,0,"ONLY",tpar,3);
1393          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD, yDp,kZp,0,"ONLY",tpar,3);
1394          gMC->Gsposp(volAlu,iVolNum++,volPlane, xD,-yDm,kZm,0,"ONLY",tpar,3);
1395          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD,-yDp,kZp,0,"ONLY",tpar,3);
1396          
1397          tpar1save=tpar[1];
1398          y1msave=yDm;
1399          y1psave=yDp;
1400          Float_t yEp=(y1msave+tpar1save)*zpm+tpar[1];
1401          Float_t yEm=(y1psave+tpar1save)*zmp+tpar[1];
1402          
1403          gMC->Gsposp(volAlu,iVolNum++,volPlane, xD, yEp,kZp,0,"ONLY",tpar,3);
1404          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD, yEm,kZm,0,"ONLY",tpar,3);
1405          gMC->Gsposp(volAlu,iVolNum++,volPlane, xD,-yEp,kZp,0,"ONLY",tpar,3);
1406          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD,-yEm,kZm,0,"ONLY",tpar,3);
1407          
1408          tpar1save=tpar[1];
1409          y1msave=yEm;
1410          y1psave=yEp;
1411          Float_t yFp=(y1msave+tpar1save)*zpm+tpar[1];
1412          Float_t yFm=(y1psave+tpar1save)*zmp+tpar[1];
1413          
1414          gMC->Gsposp(volAlu,iVolNum++,volPlane, xD, yFm,kZm,0,"ONLY",tpar,3);
1415          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD, yFp,kZp,0,"ONLY",tpar,3);
1416          gMC->Gsposp(volAlu,iVolNum++,volPlane, xD,-yFm,kZm,0,"ONLY",tpar,3);
1417          gMC->Gsposp(volAlu,iVolNum++,volPlane,-xD,-yFp,kZp,0,"ONLY",tpar,3);
1418
1419 // Positioning plane in ALICE     
1420          gMC->Gspos(volPlane,1,"ALIC",0.,0.,zpos,0,"ONLY");
1421          
1422      } // end loop on detection planes
1423  } // end loop on stations
1424
1425 }
1426
1427  
1428 //___________________________________________
1429 void AliMUONv1::CreateMaterials()
1430 {
1431   // *** DEFINITION OF AVAILABLE MUON MATERIALS *** 
1432   //
1433   //     Ar-CO2 gas (80%+20%)
1434     Float_t ag1[3]   = { 39.95,12.01,16. };
1435     Float_t zg1[3]   = { 18.,6.,8. };
1436     Float_t wg1[3]   = { .8,.0667,.13333 };
1437     Float_t dg1      = .001821;
1438     //
1439     //     Ar-buthane-freon gas -- trigger chambers 
1440     Float_t atr1[4]  = { 39.95,12.01,1.01,19. };
1441     Float_t ztr1[4]  = { 18.,6.,1.,9. };
1442     Float_t wtr1[4]  = { .56,.1262857,.2857143,.028 };
1443     Float_t dtr1     = .002599;
1444     //
1445     //     Ar-CO2 gas 
1446     Float_t agas[3]  = { 39.95,12.01,16. };
1447     Float_t zgas[3]  = { 18.,6.,8. };
1448     Float_t wgas[3]  = { .74,.086684,.173316 };
1449     Float_t dgas     = .0018327;
1450     //
1451     //     Ar-Isobutane gas (80%+20%) -- tracking 
1452     Float_t ag[3]    = { 39.95,12.01,1.01 };
1453     Float_t zg[3]    = { 18.,6.,1. };
1454     Float_t wg[3]    = { .8,.057,.143 };
1455     Float_t dg       = .0019596;
1456     //
1457     //     Ar-Isobutane-Forane-SF6 gas (49%+7%+40%+4%) -- trigger 
1458     Float_t atrig[5] = { 39.95,12.01,1.01,19.,32.066 };
1459     Float_t ztrig[5] = { 18.,6.,1.,9.,16. };
1460     Float_t wtrig[5] = { .49,1.08,1.5,1.84,0.04 };
1461     Float_t dtrig    = .0031463;
1462     //
1463     //     bakelite 
1464
1465     Float_t abak[3] = {12.01 , 1.01 , 16.};
1466     Float_t zbak[3] = {6.     , 1.   , 8.};
1467     Float_t wbak[3] = {6.     , 6.   , 1.}; 
1468     Float_t dbak = 1.4;
1469
1470     Float_t epsil, stmin, deemax, tmaxfd, stemax;
1471
1472     Int_t iSXFLD   = gAlice->Field()->Integ();
1473     Float_t sXMGMX = gAlice->Field()->Max();
1474     //
1475     // --- Define the various materials for GEANT --- 
1476     AliMaterial(9, "ALUMINIUM$", 26.98, 13., 2.7, 8.9, 37.2);
1477     AliMaterial(10, "ALUMINIUM$", 26.98, 13., 2.7, 8.9, 37.2);
1478     AliMaterial(15, "AIR$      ", 14.61, 7.3, .001205, 30423.24, 67500);
1479     AliMixture(19, "Bakelite$", abak, zbak, dbak, -3, wbak);
1480     AliMixture(20, "ArC4H10 GAS$", ag, zg, dg, 3, wg);
1481     AliMixture(21, "TRIG GAS$", atrig, ztrig, dtrig, -5, wtrig);
1482     AliMixture(22, "ArCO2 80%$", ag1, zg1, dg1, 3, wg1);
1483     AliMixture(23, "Ar-freon $", atr1, ztr1, dtr1, 4, wtr1);
1484     AliMixture(24, "ArCO2 GAS$", agas, zgas, dgas, 3, wgas);
1485     // materials for slat: 
1486     //     Sensitive area: gas (already defined) 
1487     //     PCB: copper 
1488     //     insulating material and frame: vetronite
1489     //     walls: carbon, rohacell, carbon 
1490   Float_t aglass[5]={12.01, 28.09, 16.,   10.8,  23.};
1491   Float_t zglass[5]={ 6.,   14.,    8.,    5.,   11.};
1492   Float_t wglass[5]={ 0.5,  0.105, 0.355, 0.03,  0.01};
1493   Float_t dglass=1.74;
1494
1495   // rohacell: C9 H13 N1 O2
1496   Float_t arohac[4] = {12.01,  1.01, 14.010, 16.};
1497   Float_t zrohac[4] = { 6.,    1.,    7.,     8.};
1498   Float_t wrohac[4] = { 9.,   13.,    1.,     2.};
1499   Float_t drohac    = 0.03;
1500
1501   AliMaterial(31, "COPPER$",   63.54,    29.,   8.96,  1.4, 0.);
1502   AliMixture(32, "Vetronite$",aglass, zglass, dglass,    5, wglass);
1503   AliMaterial(33, "Carbon$",   12.01,     6.,  2.265, 18.8, 49.9);
1504   AliMixture(34, "Rohacell$", arohac, zrohac, drohac,   -4, wrohac); 
1505
1506
1507     epsil  = .001; // Tracking precision, 
1508     stemax = -1.;  // Maximum displacement for multiple scat 
1509     tmaxfd = -20.; // Maximum angle due to field deflection 
1510     deemax = -.3;  // Maximum fractional energy loss, DLS 
1511     stmin  = -.8;
1512     //
1513     //    Air 
1514     AliMedium(1, "AIR_CH_US         ", 15, 1, iSXFLD, sXMGMX, tmaxfd, stemax, deemax, epsil, stmin);
1515     //
1516     //    Aluminum 
1517
1518     AliMedium(4, "ALU_CH_US          ", 9, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
1519             fMaxDestepAlu, epsil, stmin);
1520     AliMedium(5, "ALU_CH_US          ", 10, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
1521             fMaxDestepAlu, epsil, stmin);
1522     //
1523     //    Ar-isoC4H10 gas 
1524
1525     AliMedium(6, "AR_CH_US          ", 20, 1, iSXFLD, sXMGMX, tmaxfd, fMaxStepGas, 
1526             fMaxDestepGas, epsil, stmin);
1527 //
1528     //    Ar-Isobuthane-Forane-SF6 gas 
1529
1530     AliMedium(7, "GAS_CH_TRIGGER    ", 21, 1, iSXFLD, sXMGMX, tmaxfd, stemax, deemax, epsil, stmin);
1531
1532     AliMedium(8, "BAKE_CH_TRIGGER   ", 19, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
1533             fMaxDestepAlu, epsil, stmin);
1534
1535     AliMedium(9, "ARG_CO2   ", 22, 1, iSXFLD, sXMGMX, tmaxfd, fMaxStepGas, 
1536             fMaxDestepAlu, epsil, stmin);
1537     // tracking media for slats: check the parameters!! 
1538     AliMedium(11, "PCB_COPPER        ", 31, 0, iSXFLD, sXMGMX, tmaxfd, 
1539               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1540     AliMedium(12, "VETRONITE         ", 32, 0, iSXFLD, sXMGMX, tmaxfd, 
1541               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1542     AliMedium(13, "CARBON            ", 33, 0, iSXFLD, sXMGMX, tmaxfd, 
1543               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1544     AliMedium(14, "Rohacell          ", 34, 0, iSXFLD, sXMGMX, tmaxfd, 
1545               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
1546 }
1547
1548 //___________________________________________
1549
1550 void AliMUONv1::Init()
1551 {
1552    // 
1553    // Initialize Tracking Chambers
1554    //
1555
1556    if(fDebug) printf("\n%s: Start Init for version 1 - CPC chamber type\n\n",ClassName());
1557    Int_t i;
1558    for (i=0; i<AliMUONConstants::NCh(); i++) {
1559        ( (AliMUONChamber*) (*fChambers)[i])->Init();
1560    }
1561    
1562    //
1563    // Set the chamber (sensitive region) GEANT identifier
1564    ((AliMUONChamber*)(*fChambers)[0])->SetGid(gMC->VolId("S01G"));
1565    ((AliMUONChamber*)(*fChambers)[1])->SetGid(gMC->VolId("S02G"));
1566
1567    ((AliMUONChamber*)(*fChambers)[2])->SetGid(gMC->VolId("S03G"));
1568    ((AliMUONChamber*)(*fChambers)[3])->SetGid(gMC->VolId("S04G"));
1569
1570    ((AliMUONChamber*)(*fChambers)[4])->SetGid(gMC->VolId("S05G"));
1571    ((AliMUONChamber*)(*fChambers)[5])->SetGid(gMC->VolId("S06G"));
1572
1573    ((AliMUONChamber*)(*fChambers)[6])->SetGid(gMC->VolId("S07G"));
1574    ((AliMUONChamber*)(*fChambers)[7])->SetGid(gMC->VolId("S08G"));
1575
1576    ((AliMUONChamber*)(*fChambers)[8])->SetGid(gMC->VolId("S09G"));
1577    ((AliMUONChamber*)(*fChambers)[9])->SetGid(gMC->VolId("S10G"));
1578
1579    ((AliMUONChamber*)(*fChambers)[10])->SetGid(gMC->VolId("SG1A"));
1580    ((AliMUONChamber*)(*fChambers)[11])->SetGid(gMC->VolId("SG2A"));
1581    ((AliMUONChamber*)(*fChambers)[12])->SetGid(gMC->VolId("SG3A"));
1582    ((AliMUONChamber*)(*fChambers)[13])->SetGid(gMC->VolId("SG4A"));
1583
1584    if(fDebug) printf("\n%s: Finished Init for version 1 - CPC chamber type\n",ClassName());
1585
1586    //cp 
1587    if(fDebug) printf("\n%s: Start Init for Trigger Circuits\n",ClassName());
1588    for (i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
1589      ( (AliMUONTriggerCircuit*) (*fTriggerCircuits)[i])->Init(i);
1590    }
1591    if(fDebug) printf("%s: Finished Init for Trigger Circuits\n",ClassName());
1592    //cp
1593
1594 }
1595 //___________________________________________
1596 void AliMUONv1::StepManager()
1597 {
1598   if (fStepManagerVersionOld) {
1599     StepManagerOld();
1600     return;
1601   }
1602   // Volume id
1603   Int_t   copy, id;
1604   Int_t   idvol;
1605   Int_t   iChamber=0;
1606   // Particule id, pos and mom vectors, 
1607   // theta, phi angles with respect the normal of the chamber, 
1608   // spatial step, delta_energy and time of flight
1609   Int_t          ipart;
1610   TLorentzVector pos, mom;
1611   Float_t        theta, phi, tof;
1612   Float_t        destep, step;
1613   const  Float_t kBig = 1.e10;
1614
1615   // Only charged tracks
1616   if( !(gMC->TrackCharge()) ) return; 
1617
1618   // Only gas gap inside chamber
1619   // Tag chambers and record hits when track enters 
1620   idvol=-1;
1621   id=gMC->CurrentVolID(copy);
1622   for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++) {
1623     if(id==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()) {
1624       iChamber = i;
1625       idvol  = i-1;
1626     }
1627   }
1628   if (idvol == -1) return;
1629
1630
1631   // record hits when track enters ...
1632   if( gMC->IsTrackEntering()) gMC->SetMaxStep(fStepMaxInActiveGas);  
1633
1634   if (gMC->TrackStep() > 0.) {
1635     // Get current particle id (ipart), track position (pos)  and momentum (mom)
1636     gMC->TrackPosition(pos);
1637     gMC->TrackMomentum(mom);
1638     ipart    = gMC->TrackPid();
1639     theta    = mom.Theta()*kRaddeg;     // theta of track
1640     phi      = mom.Phi()  *kRaddeg;     // phi of the track
1641     tof      = gMC->TrackTime();        // Time of flight
1642     //
1643     // momentum loss and steplength in last step
1644     destep = gMC->Edep();
1645     step   = gMC->TrackStep();
1646     //new hit
1647
1648     GetMUONData()->AddHit(fIshunt, gAlice->GetCurrentTrackNumber(), iChamber, ipart, 
1649                           pos.X(), pos.Y(), pos.Z(), tof, mom.P(), 
1650                           theta, phi, step, destep);
1651   }
1652   // Track left chamber ...
1653   if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
1654     gMC->SetMaxStep(kBig);
1655   }
1656     
1657 }
1658
1659 Int_t  AliMUONv1::GetChamberId(Int_t volId) const
1660 {
1661 // Check if the volume with specified  volId is a sensitive volume (gas) 
1662 // of some chamber and returns the chamber number;
1663 // if not sensitive volume - return 0.
1664 // ---
1665
1666   for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
1667     if (volId==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()) return i;
1668
1669   return 0;
1670 }
1671
1672 //___________________________________________
1673 void AliMUONv1::StepManagerOld()
1674 {
1675   Int_t          copy, id;
1676   static Int_t   idvol;
1677   static Int_t   vol[2];
1678   Int_t          ipart;
1679   TLorentzVector pos;
1680   TLorentzVector mom;
1681   Float_t        theta,phi;
1682   Float_t        destep, step;
1683
1684   static Float_t eloss, eloss2, xhit, yhit, zhit, tof, tlength;
1685   const  Float_t kBig = 1.e10;
1686   static Float_t hits[15];
1687
1688   TClonesArray &lhits = *fHits;
1689
1690   //
1691   //
1692   // Only charged tracks
1693   if( !(gMC->TrackCharge()) ) return; 
1694   //
1695   // Only gas gap inside chamber
1696   // Tag chambers and record hits when track enters 
1697   id=gMC->CurrentVolID(copy);
1698   vol[0] = GetChamberId(id);
1699   idvol = vol[0] -1;
1700
1701   if (idvol == -1) return;
1702
1703   //
1704   // Get current particle id (ipart), track position (pos)  and momentum (mom) 
1705   gMC->TrackPosition(pos);
1706   gMC->TrackMomentum(mom);
1707
1708   ipart  = gMC->TrackPid();
1709
1710   //
1711   // momentum loss and steplength in last step
1712   destep = gMC->Edep();
1713   step   = gMC->TrackStep();
1714   
1715   //
1716   // record hits when track enters ...
1717   if( gMC->IsTrackEntering()) {
1718       gMC->SetMaxStep(fMaxStepGas);
1719       Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
1720       Double_t rt = TMath::Sqrt(tc);
1721       Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
1722       Double_t tx = mom[0]/pmom;
1723       Double_t ty = mom[1]/pmom;
1724       Double_t tz = mom[2]/pmom;
1725       Double_t s  = ((AliMUONChamber*)(*fChambers)[idvol])
1726           ->ResponseModel()
1727           ->Pitch()/tz;
1728       theta   = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
1729       phi     = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
1730       hits[0] = Float_t(ipart);         // Geant3 particle type
1731       hits[1] = pos[0]+s*tx;            // X-position for hit
1732       hits[2] = pos[1]+s*ty;            // Y-position for hit
1733       hits[3] = pos[2]+s*tz;            // Z-position for hit
1734       hits[4] = theta;                  // theta angle of incidence
1735       hits[5] = phi;                    // phi angle of incidence 
1736       hits[8] = 0;//PadHits does not exist anymore  (Float_t) fNPadHits;    // first padhit
1737       hits[9] = -1;                     // last pad hit
1738       hits[10] = mom[3];                // hit momentum P
1739       hits[11] = mom[0];                // Px
1740       hits[12] = mom[1];                // Py
1741       hits[13] = mom[2];                // Pz
1742       tof=gMC->TrackTime();
1743       hits[14] = tof;                   // Time of flight
1744       tlength  = 0;
1745       eloss    = 0;
1746       eloss2   = 0;
1747       xhit     = pos[0];
1748       yhit     = pos[1];      
1749       zhit     = pos[2];      
1750       Chamber(idvol).ChargeCorrelationInit();
1751       // Only if not trigger chamber
1752
1753       
1754       
1755
1756       if(idvol < AliMUONConstants::NTrackingCh()) {
1757           //
1758           //  Initialize hit position (cursor) in the segmentation model 
1759           ((AliMUONChamber*) (*fChambers)[idvol])
1760               ->SigGenInit(pos[0], pos[1], pos[2]);
1761       } else {
1762           //geant3->Gpcxyz();
1763           //printf("In the Trigger Chamber #%d\n",idvol-9);
1764       }
1765   }
1766   eloss2+=destep;
1767   
1768   // 
1769   // Calculate the charge induced on a pad (disintegration) in case 
1770   //
1771   // Mip left chamber ...
1772   if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
1773       gMC->SetMaxStep(kBig);
1774       eloss   += destep;
1775       tlength += step;
1776       
1777       Float_t x0,y0,z0;
1778       Float_t localPos[3];
1779       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
1780       gMC->Gmtod(globalPos,localPos,1); 
1781
1782       if(idvol < AliMUONConstants::NTrackingCh()) {
1783 // tracking chambers
1784           x0 = 0.5*(xhit+pos[0]);
1785           y0 = 0.5*(yhit+pos[1]);
1786           z0 = 0.5*(zhit+pos[2]);
1787       } else {
1788 // trigger chambers
1789           x0 = xhit;
1790           y0 = yhit;
1791           z0 = 0.;
1792       }
1793       
1794
1795       //      if (eloss >0)  MakePadHits(x0,y0,z0,eloss,tof,idvol);
1796       
1797           
1798       hits[6] = tlength;   // track length
1799       hits[7] = eloss2;    // de/dx energy loss
1800
1801       //      if (fNPadHits > (Int_t)hits[8]) {
1802       //          hits[8] = hits[8]+1;
1803       //          hits[9] = 0: // PadHits does not exist anymore (Float_t) fNPadHits;
1804       //}
1805 //
1806 //    new hit 
1807       
1808       new(lhits[fNhits++]) 
1809           AliMUONHit(fIshunt, gAlice->GetCurrentTrackNumber(), vol,hits);
1810       eloss = 0; 
1811       //
1812       // Check additional signal generation conditions 
1813       // defined by the segmentation
1814       // model (boundary crossing conditions)
1815       // only for tracking chambers
1816   } else if 
1817       ((idvol < AliMUONConstants::NTrackingCh()) &&
1818        ((AliMUONChamber*) (*fChambers)[idvol])->SigGenCond(pos[0], pos[1], pos[2]))
1819   {
1820       ((AliMUONChamber*) (*fChambers)[idvol])
1821           ->SigGenInit(pos[0], pos[1], pos[2]);
1822       
1823       Float_t localPos[3];
1824       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
1825       gMC->Gmtod(globalPos,localPos,1); 
1826
1827       eloss    += destep;
1828
1829       // if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
1830       //        MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
1831       xhit     = pos[0];
1832       yhit     = pos[1]; 
1833       zhit     = pos[2];
1834       eloss = 0;
1835       tlength += step ;
1836       //
1837       // nothing special  happened, add up energy loss
1838   } else {        
1839       eloss   += destep;
1840       tlength += step ;
1841   }
1842 }
1843
1844