]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFv3.cxx
e4f27efeddac237cdc2fcfb35e66063d86790f8e
[u/mrichter/AliRoot.git] / TOF / AliTOFv3.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 purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  This class contains the functions for version 3 of the Time Of Flight    //
21 //  detector.                                                                //
22 //                                                                           //
23 //  VERSION WITH 5 MODULES AND TILTED STRIPS                                 //
24 //  HITS DEFINED FOR THIS VERSION                                            //
25 //  HOLES FOR HMPID DETECTOR                                                  //
26 //                                                                           //
27 //   Authors:                                                                //
28 //                                                                           //
29 //   Alessio Seganti                                                         //
30 //   Domenico Vicinanza                                                      //
31 //                                                                           //
32 //   University of Salerno - Italy                                           //
33 //                                                                           //
34 //   Fabrizio Pierella                                                       //
35 //   University of Bologna - Italy                                           //
36 //                                                                           //
37 //                                                                           //
38 //Begin_Html                                                                 //
39 /*                                                                           //
40 <img src="picts/AliTOFv3Class.gif">                                          //
41 */                                                                           //
42 //End_Html                                                                   //
43 //                                                                           //
44 ///////////////////////////////////////////////////////////////////////////////
45
46 #include <Riostream.h>
47 #include <stdlib.h>
48
49 #include <TBRIK.h>
50 #include <TGeometry.h>
51 #include <TLorentzVector.h>
52 #include <TNode.h>
53 #include <TObject.h>
54 #include <TVirtualMC.h>
55
56 #include "AliConst.h"
57 #include "AliRun.h"
58 #include "AliTOFv3.h"
59 #include "AliTOFConstants.h" // AdC
60 #include "AliMC.h"
61  
62 ClassImp(AliTOFv3)
63  
64 //_____________________________________________________________________________
65 AliTOFv3::AliTOFv3()
66 {
67   //
68   // Default constructor
69   //
70 }
71  
72 //_____________________________________________________________________________
73 AliTOFv3::AliTOFv3(const char *name, const char *title)
74         : AliTOF(name,title)
75 {
76   //
77   // Standard constructor
78   //
79   //
80   // Check that FRAME is there otherwise we have no place where to
81   // put TOF
82   AliModule* frame=gAlice->GetModule("FRAME");
83   if(!frame) {
84     Error("Ctor","TOF needs FRAME to be present\n");
85     exit(1);
86   } else
87     if(frame->IsVersion()!=1) {
88       Error("Ctor","FRAME version 1 needed with this version of TOF\n");
89       exit(1);
90     }
91
92 }
93  
94 //_____________________________________________________________________________
95 void AliTOFv3::CreateGeometry()
96 {
97   //
98   // Create geometry for Time Of Flight version 0
99   //
100   //Begin_Html
101   /*
102     <img src="picts/AliTOFv3.gif">
103   */
104   //End_Html
105   //
106   // Creates common geometry
107   //
108   AliTOF::CreateGeometry();
109 }
110  
111 //_____________________________________________________________________________
112 void AliTOFv3::TOFpc(Float_t xtof, Float_t ytof, Float_t zlenC,
113                      Float_t zlenB, Float_t zlenA, Float_t ztof0)
114 {
115   //
116   // Definition of the Time Of Fligh Resistive Plate Chambers
117   // xFLT, yFLT, zFLT - sizes of TOF modules (large)
118   
119   Float_t  ycoor, zcoor;
120   Float_t  par[3];
121   Int_t    *idtmed = fIdtmed->GetArray()-499;
122   Int_t    idrotm[100];
123   Int_t    nrot = 0;
124   Float_t  hTof = fRmax-fRmin;
125   
126   Float_t radius = fRmin+2.;//cm
127   
128   par[0] =  xtof * 0.5;
129   par[1] =  ytof * 0.5;
130   par[2] = zlenC * 0.5;
131   gMC->Gsvolu("FTOC", "BOX ", idtmed[506], par, 3);
132   par[2] = zlenB * 0.5;
133   gMC->Gsvolu("FTOB", "BOX ", idtmed[506], par, 3);
134   par[2] = zlenA * 0.5;
135   gMC->Gsvolu("FTOA", "BOX ", idtmed[506], par, 3);
136   
137   
138   // Positioning of modules
139   
140   Float_t zcor1 = ztof0 - zlenC*0.5;
141   Float_t zcor2 = ztof0 - zlenC - zlenB*0.5;
142   Float_t zcor3 = 0.;
143   
144   AliMatrix(idrotm[0], 90.,  0., 0., 0., 90,-90.);
145   AliMatrix(idrotm[1], 90.,180., 0., 0., 90, 90.);
146   gMC->Gspos("FTOC", 1, "BTO1", 0,  zcor1, 0, idrotm[0], "ONLY");
147   gMC->Gspos("FTOC", 2, "BTO1", 0, -zcor1, 0, idrotm[1], "ONLY");
148   gMC->Gspos("FTOC", 1, "BTO2", 0,  zcor1, 0, idrotm[0], "ONLY");
149   gMC->Gspos("FTOC", 2, "BTO2", 0, -zcor1, 0, idrotm[1], "ONLY");
150   gMC->Gspos("FTOC", 1, "BTO3", 0,  zcor1, 0, idrotm[0], "ONLY");
151   gMC->Gspos("FTOC", 2, "BTO3", 0, -zcor1, 0, idrotm[1], "ONLY");
152   
153   gMC->Gspos("FTOB", 1, "BTO1", 0,  zcor2, 0, idrotm[0], "ONLY");
154   gMC->Gspos("FTOB", 2, "BTO1", 0, -zcor2, 0, idrotm[1], "ONLY");
155   gMC->Gspos("FTOB", 1, "BTO2", 0,  zcor2, 0, idrotm[0], "ONLY");
156   gMC->Gspos("FTOB", 2, "BTO2", 0, -zcor2, 0, idrotm[1], "ONLY");
157   
158   gMC->Gspos("FTOA", 0, "BTO1", 0, zcor3,  0, idrotm[0], "ONLY");
159   gMC->Gspos("FTOA", 0, "BTO2", 0, zcor3,  0, idrotm[0], "ONLY");
160   
161   Float_t db = 0.5;//cm
162   Float_t xFLT, xFST, yFLT, zFLTA, zFLTB, zFLTC;
163   
164   xFLT = fStripLn;
165   yFLT = ytof;
166   zFLTA = zlenA;
167   zFLTB = zlenB;
168   zFLTC = zlenC;
169   
170   xFST = xFLT-fDeadBndX*2;//cm
171   
172   // Sizes of MRPC pads
173   
174   Float_t yPad = 0.505;//cm 
175   
176   // Large not sensitive volumes with Insensitive Freon
177   par[0] = xFLT*0.5;
178   par[1] = yFLT*0.5;
179   
180   if (fDebug) cout << ClassName() <<
181                 cout <<": ************************* TOF geometry **************************"<<endl;
182   
183   par[2] = (zFLTA *0.5);
184   gMC->Gsvolu("FLTA", "BOX ", idtmed[512], par, 3); // Insensitive Freon
185   gMC->Gspos ("FLTA", 0, "FTOA", 0., 0., 0., 0, "ONLY");
186   
187   par[2] = (zFLTB * 0.5);
188   gMC->Gsvolu("FLTB", "BOX ", idtmed[512], par, 3); // Insensitive Freon
189   gMC->Gspos ("FLTB", 0, "FTOB", 0., 0., 0., 0, "ONLY");
190   
191   par[2] = (zFLTC * 0.5);
192   gMC->Gsvolu("FLTC", "BOX ", idtmed[512], par, 3); // Insensitive Freon
193   gMC->Gspos ("FLTC", 0, "FTOC", 0., 0., 0., 0, "ONLY");
194
195   ///// Layers of Aluminum before and after detector /////
196   ///// Aluminum Box for Modules (1.8 mm thickness)  /////
197   ///// lateral walls not simulated for the time being
198   //const Float_t khAlWall = 0.18;
199   // fp to be checked
200   const Float_t khAlWall = 0.11;
201   par[0] = xFLT*0.5;
202   par[1] = khAlWall/2.;//cm
203   ycoor = -yFLT/2 + par[1];
204   par[2] = (zFLTA *0.5);
205   gMC->Gsvolu("FALA", "BOX ", idtmed[508], par, 3); // Alluminium
206   gMC->Gspos ("FALA", 1, "FLTA", 0., ycoor, 0., 0, "ONLY");
207   gMC->Gspos ("FALA", 2, "FLTA", 0.,-ycoor, 0., 0, "ONLY");
208   par[2] = (zFLTB *0.5);
209   gMC->Gsvolu("FALB", "BOX ", idtmed[508], par, 3); // Alluminium 
210   gMC->Gspos ("FALB", 1, "FLTB", 0., ycoor, 0., 0, "ONLY");
211   gMC->Gspos ("FALB", 2, "FLTB", 0.,-ycoor, 0., 0, "ONLY");
212   par[2] = (zFLTC *0.5);
213   gMC->Gsvolu("FALC", "BOX ", idtmed[508], par, 3); // Alluminium
214   gMC->Gspos ("FALC", 1, "FLTC", 0., ycoor, 0., 0, "ONLY");
215   gMC->Gspos ("FALC", 2, "FLTC", 0.,-ycoor, 0., 0, "ONLY");
216   
217   ///////////////// Detector itself //////////////////////
218   
219   const Float_t  kdeadBound  =  fDeadBndZ; //cm non-sensitive between the pad edge 
220   //and the boundary of the strip
221   const Int_t    knx    = fNpadX;          // number of pads along x
222   const Int_t    knz    = fNpadZ;          // number of pads along z
223   const Float_t  kspace = fSpace;            //cm distance from the front plate of the box
224   
225   Float_t zSenStrip  = fZpad*fNpadZ;//cm
226   Float_t stripWidth = zSenStrip + 2*kdeadBound;
227   
228   par[0] = xFLT*0.5;
229   par[1] = yPad*0.5;
230   par[2] = stripWidth*0.5;
231   
232   // new description for strip volume -double stack strip-
233   // -- all constants are expressed in cm
234   // heigth of different layers
235   const Float_t khhony = 0.8     ;   // heigth of HONY  Layer
236   const Float_t khpcby = 0.08    ;   // heigth of PCB   Layer
237   const Float_t khmyly = 0.035   ;   // heigth of MYLAR Layer
238   const Float_t khgraphy = 0.02  ;   // heigth of GRAPHITE Layer
239   const Float_t khglasseiy = 0.135;   // 0.6 Ext. Glass + 1.1 i.e. (Int. Glass/2) (mm)
240   const Float_t khsensmy = 0.11  ;   // heigth of Sensitive Freon Mixture
241   const Float_t kwsensmz = 2*3.5 ;   // cm
242   const Float_t klsensmx = 48*2.5;   // cm
243   const Float_t kwpadz = 3.5;   // cm z dimension of the FPAD volume
244   const Float_t klpadx = 2.5;   // cm x dimension of the FPAD volume
245   
246   // heigth of the FSTR Volume (the strip volume)
247   const Float_t khstripy = 2*khhony+3*khpcby+4*(khmyly+khgraphy+khglasseiy)+2*khsensmy;
248   // width  of the FSTR Volume (the strip volume)
249   const Float_t kwstripz = 10.;
250   // length of the FSTR Volume (the strip volume)
251   const Float_t klstripx = 122.;
252   
253   Float_t parfp[3]={klstripx*0.5,khstripy*0.5,kwstripz*0.5};
254   // coordinates of the strip center in the strip reference frame; used for positioning
255   // internal strip volumes
256   Float_t posfp[3]={0.,0.,0.};  
257   
258   
259   // FSTR volume definition and filling this volume with non sensitive Gas Mixture
260   gMC->Gsvolu("FSTR","BOX",idtmed[512],parfp,3);
261   //-- HONY Layer definition
262   //  parfp[0] = -1;
263   parfp[1] = khhony*0.5;
264   //  parfp[2] = -1;
265   gMC->Gsvolu("FHON","BOX",idtmed[503],parfp,3);
266   // positioning 2 HONY Layers on FSTR volume
267   
268   posfp[1]=-khstripy*0.5+parfp[1];
269   gMC->Gspos("FHON",1,"FSTR",0., posfp[1],0.,0,"ONLY");
270   gMC->Gspos("FHON",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
271   
272   //-- PCB Layer definition 
273   parfp[1] = khpcby*0.5;
274   gMC->Gsvolu("FPCB","BOX",idtmed[504],parfp,3);
275   // positioning 2 PCB Layers on FSTR volume
276   posfp[1]=-khstripy*0.5+khhony+parfp[1];
277   gMC->Gspos("FPCB",1,"FSTR",0., posfp[1],0.,0,"ONLY");
278   gMC->Gspos("FPCB",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
279   // positioning the central PCB layer
280   gMC->Gspos("FPCB",3,"FSTR",0.,0.,0.,0,"ONLY");
281   
282   
283   
284   //-- MYLAR Layer definition
285   parfp[1] = khmyly*0.5;
286   gMC->Gsvolu("FMYL","BOX",idtmed[511],parfp,3);
287   // positioning 2 MYLAR Layers on FSTR volume
288   posfp[1] = -khstripy*0.5+khhony+khpcby+parfp[1];
289   gMC->Gspos("FMYL",1,"FSTR",0., posfp[1],0.,0,"ONLY");
290   gMC->Gspos("FMYL",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
291   // adding further 2 MYLAR Layers on FSTR volume
292   posfp[1] = khpcby*0.5+parfp[1];
293   gMC->Gspos("FMYL",3,"FSTR",0., posfp[1],0.,0,"ONLY");
294   gMC->Gspos("FMYL",4,"FSTR",0.,-posfp[1],0.,0,"ONLY");
295   
296   
297   //-- Graphite Layer definition
298   parfp[1] = khgraphy*0.5;
299   gMC->Gsvolu("FGRP","BOX",idtmed[502],parfp,3);
300   // positioning 2 Graphite Layers on FSTR volume
301   posfp[1] = -khstripy*0.5+khhony+khpcby+khmyly+parfp[1];
302   gMC->Gspos("FGRP",1,"FSTR",0., posfp[1],0.,0,"ONLY");
303   gMC->Gspos("FGRP",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
304   // adding further 2 Graphite Layers on FSTR volume
305   posfp[1] = khpcby*0.5+khmyly+parfp[1];
306   gMC->Gspos("FGRP",3,"FSTR",0., posfp[1],0.,0,"ONLY");
307   gMC->Gspos("FGRP",4,"FSTR",0.,-posfp[1],0.,0,"ONLY");
308   
309   
310   //-- Glass (EXT. +Semi INT.) Layer definition
311   parfp[1] = khglasseiy*0.5;
312   gMC->Gsvolu("FGLA","BOX",idtmed[514],parfp,3);
313   // positioning 2 Glass Layers on FSTR volume
314   posfp[1] = -khstripy*0.5+khhony+khpcby+khmyly+khgraphy+parfp[1];
315   gMC->Gspos("FGLA",1,"FSTR",0., posfp[1],0.,0,"ONLY");
316   gMC->Gspos("FGLA",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
317   // adding further 2 Glass Layers on FSTR volume
318   posfp[1] = khpcby*0.5+khmyly+khgraphy+parfp[1];
319   gMC->Gspos("FGLA",3,"FSTR",0., posfp[1],0.,0,"ONLY");
320   gMC->Gspos("FGLA",4,"FSTR",0.,-posfp[1],0.,0,"ONLY");
321   
322   
323   //-- Sensitive Mixture Layer definition
324   parfp[0] = klsensmx*0.5;
325   parfp[1] = khsensmy*0.5;
326   parfp[2] = kwsensmz*0.5;
327   gMC->Gsvolu("FSEN","BOX",idtmed[513],parfp,3);
328   gMC->Gsvolu("FNSE","BOX",idtmed[512],parfp,3);
329   // positioning 2 gas Layers on FSTR volume
330   // the upper is insensitive freon
331   // while the remaining is sensitive
332   posfp[1] = khpcby*0.5+khmyly+khgraphy+khglasseiy+parfp[1];
333   gMC->Gspos("FNSE",0,"FSTR", 0., posfp[1],0.,0,"ONLY");
334   gMC->Gspos("FSEN",0,"FSTR", 0.,-posfp[1],0.,0,"ONLY");
335   
336   // dividing FSEN along z in knz=2 and along x in knx=48
337   gMC->Gsdvn("FSEZ","FSEN",knz,3);
338   gMC->Gsdvn("FSEX","FSEZ",knx,1);
339   
340   // FPAD volume definition
341   parfp[0] = klpadx*0.5;   
342   parfp[1] = khsensmy*0.5;
343   parfp[2] = kwpadz*0.5;
344   gMC->Gsvolu("FPAD","BOX",idtmed[513],parfp,3);
345   // positioning the FPAD volumes on previous divisions
346   gMC->Gspos("FPAD",0,"FSEX",0.,0.,0.,0,"ONLY");
347   
348   ////  Positioning the Strips  (FSTR) in the FLT volumes  /////
349   
350   // Plate A (Central) 
351   
352   Float_t t = zFLTC+zFLTB+zFLTA*0.5+ 2*db;//Half Width of Barrel
353   
354   Float_t gap  = fGapA+0.5; //cm  updated distance between the strip axis
355   Float_t zpos = 0;
356   Float_t ang  = 0;
357   Int_t j=1; // AdC
358   nrot  = 0;
359   zcoor = 0;
360   ycoor = -14.5 + kspace ; //2 cm over front plate
361
362   AliMatrix (idrotm[0],  90.,  0.,90.,90.,0., 90.);  
363
364   Int_t centerLoc= (Int_t)(fNStripA/2.) + 1; // AdC
365
366   //gMC->Gspos("FSTR",j,"FLTA",0.,ycoor, 0.,idrotm[0],"ONLY");
367   gMC->Gspos("FSTR",centerLoc,"FLTA",0.,ycoor, 0.,idrotm[0],"ONLY"); // AdC
368   if(fDebug>=1) {
369     printf("%s: %f,  St. %2i, Pl.3 ",ClassName(),ang*kRaddeg,j); // AdC
370     printf("y = %f,  z = %f, zpos = %f \n",ycoor,zcoor,zpos);
371   }
372   zcoor -= zSenStrip;
373   //j++; // AdC
374   Int_t upDown = -1; // upDown=-1 -> Upper strip
375                      // upDown=+1 -> Lower strip
376   do{
377     ang = atan(zcoor/radius);
378     ang *= kRaddeg;
379     AliMatrix (idrotm[nrot],  90.,  0.,90.-ang,90.,-ang, 90.);  
380     AliMatrix (idrotm[nrot+1],90.,180.,90.+ang,90., ang, 90.);
381     ang /= kRaddeg;
382     ycoor = -14.5+ kspace; //2 cm over front plate
383     ycoor += (1-(upDown+1)/2)*gap;
384     //gMC->Gspos("FSTR",j  ,"FLTA",0.,ycoor, zcoor,idrotm[nrot],  "ONLY");
385     //gMC->Gspos("FSTR",j+1,"FLTA",0.,ycoor,-zcoor,idrotm[nrot+1],"ONLY");
386     gMC->Gspos("FSTR",centerLoc-j,"FLTA",0.,ycoor, zcoor,idrotm[nrot],  "ONLY"); // AdC
387     gMC->Gspos("FSTR",centerLoc+j,"FLTA",0.,ycoor,-zcoor,idrotm[nrot+1],"ONLY"); // AdC
388     if(fDebug>=1) {
389       printf("%s: %f,  St. %2i, Pl.3 ",ClassName(),ang*kRaddeg,j); // AdC
390       printf("y = %f,  z = %f, zpos = %f \n",ycoor,zcoor,zpos);
391     }
392     j++; //j += 2; // AdC
393     upDown*= -1; // Alternate strips 
394     zcoor = zcoor-(zSenStrip/2)/TMath::Cos(ang)-
395       upDown*gap*TMath::Tan(ang)-
396       (zSenStrip/2)/TMath::Cos(ang);
397   } while (zcoor-(stripWidth/2)*TMath::Cos(ang)>-t+zFLTC+zFLTB+db*2);
398   
399   zcoor = zcoor+(zSenStrip/2)/TMath::Cos(ang)+
400     upDown*gap*TMath::Tan(ang)+
401     (zSenStrip/2)/TMath::Cos(ang);
402   
403   gap = fGapB;
404   zcoor = zcoor-(zSenStrip/2)/TMath::Cos(ang)-
405     upDown*gap*TMath::Tan(ang)-
406     (zSenStrip/2)/TMath::Cos(ang);
407   
408   ang = atan(zcoor/radius);
409   ang *= kRaddeg;
410   AliMatrix (idrotm[nrot],  90.,  0.,90.-ang,90.,-ang, 90.);  
411   AliMatrix (idrotm[nrot+1],90.,180.,90.+ang,90., ang, 90.);
412   ang /= kRaddeg;
413   
414   ycoor = -14.5+ kspace; //2 cm over front plate
415   ycoor += (1-(upDown+1)/2)*gap;
416   //gMC->Gspos("FSTR",j  ,"FLTA",0.,ycoor, zcoor,idrotm[nrot],  "ONLY");
417   //gMC->Gspos("FSTR",j+1,"FLTA",0.,ycoor,-zcoor,idrotm[nrot+1],"ONLY");
418   gMC->Gspos("FSTR",centerLoc-j,"FLTA",0.,ycoor, zcoor,idrotm[nrot],  "ONLY"); // AdC
419   gMC->Gspos("FSTR",centerLoc+j,"FLTA",0.,ycoor,-zcoor,idrotm[nrot+1],"ONLY"); // AdC
420   if(fDebug>=1) {   
421     printf("%s: %f,  St. %2i, Pl.3 ",ClassName(),ang*kRaddeg,j); // AdC
422     printf("y = %f,  z = %f, zpos = %f \n",ycoor,zcoor,zpos); 
423   }
424   ycoor = -hTof/2.+ kspace;//2 cm over front plate
425   
426   // Plate  B
427   
428   nrot = 0;
429   Int_t i=1; // AdC
430   upDown = 1;
431   Float_t deadRegion = 1.0;//cm
432   
433   zpos = zcoor - (zSenStrip/2)/TMath::Cos(ang)-
434     upDown*gap*TMath::Tan(ang)-
435     (zSenStrip/2)/TMath::Cos(ang)-
436     deadRegion/TMath::Cos(ang);
437   
438   ang = atan(zpos/radius);
439   ang *= kRaddeg;
440   AliMatrix (idrotm[nrot], 90., 0., 90.-ang,90.,ang, 270.);
441   ang /= kRaddeg;
442   ycoor = -hTof*0.5+ kspace ; //2 cm over front plate
443   ycoor += (1-(upDown+1)/2)*gap;
444   zcoor = zpos+(zFLTA*0.5+zFLTB*0.5+db); // Moves to the system of the modulus FLTB
445   gMC->Gspos("FSTR",i, "FLTB", 0., ycoor, zcoor,idrotm[nrot], "ONLY");
446   if(fDebug>=1) {   
447     printf("%s: %f,  St. %2i, Pl.4 ",ClassName(),ang*kRaddeg,i); 
448     printf("y = %f,  z = %f, zpos = %f \n",ycoor,zcoor,zpos);
449    }
450   i++;
451   upDown*=-1;
452   
453   do {
454     zpos = zpos - (zSenStrip/2)/TMath::Cos(ang)-
455       upDown*gap*TMath::Tan(ang)-
456       (zSenStrip/2)/TMath::Cos(ang);
457     ang = atan(zpos/radius);
458     ang *= kRaddeg;
459     AliMatrix (idrotm[nrot], 90., 0., 90.-ang,90.,ang, 270.);
460     ang /= kRaddeg;
461     Float_t deltaSpaceinB=-0.5; // [cm] to avoid overlaps with the end of freon frame
462     Float_t deltaGapinB=0.5;    // [cm] to avoid overlaps in between initial strips
463     ycoor = -hTof*0.5+ kspace+deltaSpaceinB ; //2 cm over front plate
464     ycoor += (1-(upDown+1)/2)*(gap+deltaGapinB);
465     zcoor = zpos+(zFLTA*0.5+zFLTB*0.5+db); // Moves to the system of the modulus FLTB
466     gMC->Gspos("FSTR",i, "FLTB", 0., ycoor, zcoor,idrotm[nrot], "ONLY");
467     if(fDebug>=1) { 
468       printf("%s: %f,  St. %2i, Pl.4 ",ClassName(),ang*kRaddeg,i);
469       printf("y = %f,  z = %f, zpos = %f \n",ycoor,zcoor,zpos);
470     }
471     upDown*=-1;
472     i++;
473   } while (TMath::Abs(ang*kRaddeg)<22.5);
474   //till we reach a tilting angle of 22.5 degrees
475   
476   ycoor = -hTof*0.5+ kspace ; //2 cm over front plate
477   zpos = zpos - zSenStrip/TMath::Cos(ang);
478   // this avoid overlaps in between outer strips in plate B
479   Float_t deltaMovingUp=0.8;    // [cm]
480   Float_t deltaMovingDown=-0.5; // [cm]
481   
482   do {
483     ang = atan(zpos/radius);
484     ang *= kRaddeg;
485     AliMatrix (idrotm[nrot], 90., 0., 90.-ang,90.,ang, 270.);
486     ang /= kRaddeg;
487     zcoor = zpos+(zFLTB/2+zFLTA/2+db);
488     gMC->Gspos("FSTR",i, "FLTB", 0., ycoor+deltaMovingDown+deltaMovingUp, zcoor,idrotm[nrot], "ONLY");
489     deltaMovingUp+=0.8; // update delta moving toward the end of the plate
490     zpos = zpos - zSenStrip/TMath::Cos(ang);
491     if(fDebug>=1) { 
492       printf("%s: %f,  St. %2i, Pl.4 ",ClassName(),ang*kRaddeg,i);
493       printf("y = %f,  z = %f, zpos = %f \n",ycoor,zcoor,zpos);
494     }
495     i++;
496     
497   }  while (zpos-stripWidth*0.5/TMath::Cos(ang)>-t+zFLTC+db);
498   
499   // Plate  C
500   
501   zpos = zpos + zSenStrip/TMath::Cos(ang);
502   
503   zpos = zpos - (zSenStrip/2)/TMath::Cos(ang)+
504     gap*TMath::Tan(ang)-
505     (zSenStrip/2)/TMath::Cos(ang);
506   
507   nrot = 0;
508   i=0;
509   Float_t deltaGap=-2.5; // [cm] update distance from strip center and plate
510   ycoor= -hTof*0.5+kspace+gap+deltaGap;
511   
512   do {
513     i++;
514     ang = atan(zpos/radius);
515     ang *= kRaddeg;
516     AliMatrix (idrotm[nrot], 90., 0., 90.-ang,90.,ang, 270.);
517     ang /= kRaddeg;
518     zcoor = zpos+(zFLTC*0.5+zFLTB+zFLTA*0.5+db*2);
519     gMC->Gspos("FSTR",i, "FLTC", 0., ycoor, zcoor,idrotm[nrot], "ONLY");
520     if(fDebug>=1) { 
521       printf("%s: %f,  St. %2i, Pl.5 ",ClassName(),ang*kRaddeg,i);
522       printf("y = %f,  z = %f, zpos = %f \n",ycoor,zcoor,zpos);
523     }
524     zpos = zpos - zSenStrip/TMath::Cos(ang);
525   }  while (zpos-stripWidth*TMath::Cos(ang)*0.5>-t);
526
527
528   ////////// Layers after strips /////////////////
529   // Al Layer thickness (2.3mm) factor 0.7
530   
531   Float_t overSpace = fOverSpc;//cm
532   
533   par[0] = xFLT*0.5;
534   par[1] = 0.115*0.7; // factor 0.7
535   par[2] = (zFLTA *0.5);
536   ycoor = -yFLT/2 + overSpace + par[1];
537   gMC->Gsvolu("FPEA", "BOX ", idtmed[508], par, 3); // Al
538   gMC->Gspos ("FPEA", 0, "FLTA", 0., ycoor, 0., 0, "ONLY");
539   par[2] = (zFLTB *0.5);
540   gMC->Gsvolu("FPEB", "BOX ", idtmed[508], par, 3); // Al
541   gMC->Gspos ("FPEB", 0, "FLTB", 0., ycoor, 0., 0, "ONLY");
542   par[2] = (zFLTC *0.5);
543   gMC->Gsvolu("FPEC", "BOX ", idtmed[508], par, 3); // Al
544   gMC->Gspos ("FPEC", 0, "FLTC", 0., ycoor, 0., 0, "ONLY");
545
546
547   // plexiglass thickness: 1.5 mm ; factor 0.3
548   ycoor += par[1];
549   par[0] = xFLT*0.5;
550   par[1] = 0.075*0.3; // factor 0.3 
551   par[2] = (zFLTA *0.5);
552   ycoor += par[1];
553   gMC->Gsvolu("FECA", "BOX ", idtmed[505], par, 3); // Plexigl.
554   gMC->Gspos ("FECA", 0, "FLTA", 0., ycoor, 0., 0, "ONLY");
555   par[2] = (zFLTB *0.5);
556   gMC->Gsvolu("FECB", "BOX ", idtmed[505], par, 3); // Plexigl.
557   gMC->Gspos ("FECB", 0, "FLTB", 0., ycoor, 0., 0, "ONLY");
558   par[2] = (zFLTC *0.5);
559   gMC->Gsvolu("FECC", "BOX ", idtmed[505], par, 3); // Plexigl.
560   gMC->Gspos ("FECC", 0, "FLTC", 0., ycoor, 0., 0, "ONLY");
561   
562   // frame of Air
563   ycoor += par[1];
564   par[0] = xFLT*0.5;
565   par[1] = (yFLT/2-ycoor-khAlWall)*0.5; // Aluminum layer considered (0.18 cm)
566   par[2] = (zFLTA *0.5);
567   ycoor += par[1];
568   gMC->Gsvolu("FAIA", "BOX ", idtmed[500], par, 3); // Air
569   gMC->Gspos ("FAIA", 0, "FLTA", 0., ycoor, 0., 0, "ONLY");
570   par[2] = (zFLTB *0.5);
571   gMC->Gsvolu("FAIB", "BOX ", idtmed[500], par, 3); // Air
572   gMC->Gspos ("FAIB", 0, "FLTB", 0., ycoor, 0., 0, "ONLY");
573   par[2] = (zFLTC *0.5);
574   gMC->Gsvolu("FAIC", "BOX ", idtmed[500], par, 3); // Air
575   gMC->Gspos ("FAIC", 0, "FLTC", 0., ycoor, 0., 0, "ONLY");
576
577   
578   // start with cards and cooling tubes
579   // finally, cards, cooling tubes and layer for thermal dispersion
580   // 3 volumes
581   // card volume definition
582   
583   // see GEOM200 in GEANT manual
584   AliMatrix(idrotm[98], 90., 0., 90., 90., 0., 0.); // 0 deg
585   
586   Float_t cardpar[3];
587   cardpar[0]= 61.;
588   cardpar[1]= 5.;
589   cardpar[2]= 0.1;
590   gMC->Gsvolu("FCAR", "BOX ", idtmed[504], cardpar, 3); // PCB Card 
591   //alu plate volume definition
592   cardpar[1]= 3.5;
593   cardpar[2]= 0.05;
594   gMC->Gsvolu("FALP", "BOX ", idtmed[508], cardpar, 3); // Alu Plate
595   
596   
597   // central module positioning (FAIA)
598   Float_t cardpos[3], aplpos2, stepforcardA=6.625;
599   cardpos[0]= 0.;
600   cardpos[1]= -0.5;
601   cardpos[2]= -53.;
602   Float_t aplpos1 = -2.;
603   Int_t icard;
604   for (icard=0; icard<15; ++icard) {
605     cardpos[2]= cardpos[2]+stepforcardA;
606     aplpos2 = cardpos[2]+0.15;
607     gMC->Gspos("FCAR",icard,"FAIA",cardpos[0],cardpos[1],cardpos[2],idrotm[98],"ONLY"); 
608     gMC->Gspos("FALP",icard,"FAIA",cardpos[0],aplpos1,aplpos2,idrotm[98],"ONLY");
609     
610   }
611   
612   
613   // intermediate module positioning (FAIB)
614   Float_t stepforcardB= 7.05;
615   cardpos[2]= -70.5;
616   for (icard=0; icard<19; ++icard) {
617     cardpos[2]= cardpos[2]+stepforcardB;
618     aplpos2 = cardpos[2]+0.15;  
619     gMC->Gspos("FCAR",icard,"FAIB",cardpos[0],cardpos[1],cardpos[2],idrotm[98],"ONLY");
620     gMC->Gspos("FALP",icard,"FAIB",cardpos[0],aplpos1,aplpos2,idrotm[98],"ONLY");
621   }
622   
623   
624   // outer module positioning (FAIC)
625   Float_t stepforcardC= 8.45238;
626   cardpos[2]= -88.75;
627   for (icard=0; icard<20; ++icard) {
628     cardpos[2]= cardpos[2]+stepforcardC;
629     aplpos2 = cardpos[2]+0.15;
630     gMC->Gspos("FCAR",icard,"FAIC",cardpos[0],cardpos[1],cardpos[2],idrotm[98],"ONLY");
631     gMC->Gspos("FALP",icard,"FAIC",cardpos[0],aplpos1,aplpos2,idrotm[98],"ONLY");
632   }
633   
634   // tube volume definition
635   Float_t tubepar[3];
636   tubepar[0]= 0.;
637   tubepar[1]= 0.4;
638   tubepar[2]= 61.;
639   gMC->Gsvolu("FTUB", "TUBE", idtmed[516], tubepar, 3); // cooling tubes (steel)
640   tubepar[0]= 0.;
641   tubepar[1]= 0.35;
642   tubepar[2]= 61.;
643   gMC->Gsvolu("FITU", "TUBE", idtmed[515], tubepar, 3); // cooling water
644   // positioning water tube into the steel one
645   gMC->Gspos("FITU",1,"FTUB",0.,0.,0.,0,"ONLY");
646   
647   
648   // rotation matrix
649   AliMatrix(idrotm[99], 180., 90., 90., 90., 90., 0.);
650   // central module positioning (FAIA)
651   Float_t tubepos[3], tdis=0.6;
652   tubepos[0]= 0.;
653   tubepos[1]= cardpos[1];
654   tubepos[2]= -53.+tdis;
655   //  tub1pos = 5.;
656   Int_t itub;
657   for (itub=0; itub<15; ++itub) {
658     tubepos[2]= tubepos[2]+stepforcardA;
659     gMC->Gspos("FTUB",itub,"FAIA",tubepos[0],tubepos[1],tubepos[2],idrotm[99],
660                "ONLY");
661   }
662   
663   
664   // intermediate module positioning (FAIB)
665   tubepos[2]= -70.5+tdis;
666   for (itub=0; itub<19; ++itub) {
667     tubepos[2]= tubepos[2]+stepforcardB;
668     gMC->Gspos("FTUB",itub,"FAIB",tubepos[0],tubepos[1],tubepos[2],idrotm[99],
669                "ONLY");
670   }
671   
672   // outer module positioning (FAIC)
673   tubepos[2]= -88.75+tdis;
674   for (itub=0; itub<20; ++itub) {
675     tubepos[2]= tubepos[2]+stepforcardC;
676     gMC->Gspos("FTUB",itub,"FAIC",tubepos[0],tubepos[1],tubepos[2],idrotm[99],
677                "ONLY");
678   }
679
680 }
681
682 //_____________________________________________________________________________
683 void AliTOFv3::DrawModule() const
684 {
685   //
686   // Draw a shaded view of the Time Of Flight version 3
687   //
688   // Set everything unseen
689   gMC->Gsatt("*", "seen", -1);
690   // 
691   // Set ALIC mother transparent
692   gMC->Gsatt("ALIC","SEEN",0);
693   //
694   // Set the volumes visible
695   gMC->Gsatt("ALIC","SEEN",0);
696
697   gMC->Gsatt("FTOA","SEEN",1);
698   gMC->Gsatt("FTOB","SEEN",1);
699   gMC->Gsatt("FTOC","SEEN",1);
700   gMC->Gsatt("FLTA","SEEN",1);
701   gMC->Gsatt("FLTB","SEEN",1);
702   gMC->Gsatt("FLTC","SEEN",1);
703   gMC->Gsatt("FPLA","SEEN",1);
704   gMC->Gsatt("FPLB","SEEN",1);
705   gMC->Gsatt("FPLC","SEEN",1);
706   gMC->Gsatt("FSTR","SEEN",1);
707   gMC->Gsatt("FPEA","SEEN",1);
708   gMC->Gsatt("FPEB","SEEN",1);
709   gMC->Gsatt("FPEC","SEEN",1);
710   
711   gMC->Gsatt("FLZ1","SEEN",0);
712   gMC->Gsatt("FLZ2","SEEN",0);
713   gMC->Gsatt("FLZ3","SEEN",0);
714   gMC->Gsatt("FLX1","SEEN",0);
715   gMC->Gsatt("FLX2","SEEN",0);
716   gMC->Gsatt("FLX3","SEEN",0);
717   gMC->Gsatt("FPAD","SEEN",0);
718
719   gMC->Gdopt("hide", "on");
720   gMC->Gdopt("shad", "on");
721   gMC->Gsatt("*", "fill", 7);
722   gMC->SetClipBox(".");
723   gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
724   gMC->DefaultRange();
725   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
726   gMC->Gdhead(1111, "Time Of Flight");
727   gMC->Gdman(18, 4, "MAN");
728   gMC->Gdopt("hide","off");
729 }
730 //_____________________________________________________________________________
731 void AliTOFv3::DrawDetectorModules()
732 {
733 //
734 // Draw a shaded view of the TOF detector version 3
735 //
736  
737 //Set ALIC mother transparent
738  gMC->Gsatt("ALIC","SEEN",0);
739
740 //
741 //Set volumes visible
742 // 
743 //=====> Level 1
744   // Level 1 for TOF volumes
745   gMC->Gsatt("B077","seen",0);
746  
747  
748 //==========> Level 2
749   // Level 2
750   gMC->Gsatt("B076","seen",-1); // all B076 sub-levels skipped -
751   gMC->Gsatt("B071","seen",0);
752   gMC->Gsatt("B074","seen",0);
753   gMC->Gsatt("B075","seen",0);
754   gMC->Gsatt("B080","seen",0); // B080 does not has sub-level                
755
756
757   // Level 2 of B071
758   gMC->Gsatt("B063","seen",-1); // all B063 sub-levels skipped   -
759   gMC->Gsatt("B065","seen",-1); // all B065 sub-levels skipped   -
760   gMC->Gsatt("B067","seen",-1); // all B067 sub-levels skipped   -
761   gMC->Gsatt("B069","seen",-1); // all B069 sub-levels skipped   -
762   gMC->Gsatt("B056","seen",0);  // B056 does not has sub-levels  -
763   gMC->Gsatt("B059","seen",-1); // all B059 sub-levels skipped   -
764   gMC->Gsatt("B072","seen",-1); // all B072 sub-levels skipped   -
765   gMC->Gsatt("BTR1","seen",0);  // BTR1 do not have sub-levels   -
766   gMC->Gsatt("BTO1","seen",0);
767
768  
769   // Level 2 of B074
770   gMC->Gsatt("BTR2","seen",0); // BTR2 does not has sub-levels -
771   gMC->Gsatt("BTO2","seen",0);
772
773   // Level 2 of B075
774   gMC->Gsatt("BTR3","seen",0); // BTR3 do not have sub-levels -
775   gMC->Gsatt("BTO3","seen",0);
776
777 // ==================> Level 3
778   // Level 3 of B071 / Level 2 of BTO1
779   gMC->Gsatt("FTOC","seen",-2);
780   gMC->Gsatt("FTOB","seen",-2);
781   gMC->Gsatt("FTOA","seen",-2);
782  
783   // Level 3 of B074 / Level 2 of BTO2
784   // -> cfr previous settings
785  
786   // Level 3 of B075 / Level 2 of BTO3
787   // -> cfr previous settings
788
789   gMC->Gdopt("hide","on");
790   gMC->Gdopt("shad","on");
791   gMC->Gsatt("*", "fill", 5);
792   gMC->SetClipBox(".");
793   gMC->SetClipBox("*", 0, 1000, 0, 1000, 0, 1000);
794   gMC->DefaultRange();
795   gMC->Gdraw("alic", 45, 40, 0, 10, 10, .015, .015);
796   gMC->Gdhead(1111,"TOF detector V1");
797   gMC->Gdman(18, 4, "MAN");
798   gMC->Gdopt("hide","off");
799 }                                 
800
801 //_____________________________________________________________________________
802 void AliTOFv3::DrawDetectorStrips()
803 {
804 //
805 // Draw a shaded view of the TOF strips for version 3
806 //
807  
808 //Set ALIC mother transparent
809  gMC->Gsatt("ALIC","SEEN",0);
810
811 //
812 //Set volumes visible 
813 //=====> Level 1
814   // Level 1 for TOF volumes
815   gMC->Gsatt("B077","seen",0);
816   
817 //==========> Level 2
818   // Level 2
819   gMC->Gsatt("B076","seen",-1); // all B076 sub-levels skipped -
820   gMC->Gsatt("B071","seen",0);
821   gMC->Gsatt("B074","seen",0);
822   gMC->Gsatt("B075","seen",0);
823   gMC->Gsatt("B080","seen",0); // B080 does not has sub-level
824
825   // Level 2 of B071
826   gMC->Gsatt("B063","seen",-1); // all B063 sub-levels skipped   -
827   gMC->Gsatt("B065","seen",-1); // all B065 sub-levels skipped   -
828   gMC->Gsatt("B067","seen",-1); // all B067 sub-levels skipped   -
829   gMC->Gsatt("B069","seen",-1); // all B069 sub-levels skipped   -
830   gMC->Gsatt("B056","seen",0);  // B056 does not has sub-levels  -
831   gMC->Gsatt("B059","seen",-1); // all B059 sub-levels skipped   -
832   gMC->Gsatt("B072","seen",-1); // all B072 sub-levels skipped   -
833   gMC->Gsatt("BTR1","seen",0);  // BTR1 do not have sub-levels   -
834   gMC->Gsatt("BTO1","seen",0);
835
836 // ==================> Level 3
837   // Level 3 of B071 / Level 2 of BTO1
838   gMC->Gsatt("FTOC","seen",0);
839   gMC->Gsatt("FTOB","seen",0);
840   gMC->Gsatt("FTOA","seen",0);
841  
842   // Level 3 of B074 / Level 2 of BTO2
843   // -> cfr previous settings
844  
845   // Level 3 of B075 / Level 2 of BTO3
846   // -> cfr previous settings
847
848
849 // ==========================> Level 4
850   // Level 4 of B071 / Level 3 of BTO1 / Level 2 of FTOC
851   gMC->Gsatt("FLTC","seen",0);
852   // Level 4 of B071 / Level 3 of BTO1 / Level 2 of FTOB
853   gMC->Gsatt("FLTB","seen",0);
854   // Level 4 of B071 / Level 3 of BTO1 / Level 2 of FTOA
855   gMC->Gsatt("FLTA","seen",0);
856  
857   // Level 4 of B074 / Level 3 of BTO2 / Level 2 of FTOC
858   // -> cfr previous settings
859   // Level 4 of B074 / Level 3 of BTO2 / Level 2 of FTOB
860   // -> cfr previous settings
861  
862   // Level 4 of B075 / Level 3 of BTO3 / Level 2 of FTOC
863   // -> cfr previous settings
864
865 //======================================> Level 5
866   // Level 5 of B071 / Level 4 of BTO1 / Level 3 of FTOC / Level 2 of FLTC
867   gMC->Gsatt("FALC","seen",0); // no children for FALC
868   gMC->Gsatt("FSTR","seen",-2);
869   gMC->Gsatt("FPEC","seen",0); // no children for FPEC
870   gMC->Gsatt("FECC","seen",0); // no children for FECC
871   gMC->Gsatt("FWAC","seen",0); // no children for FWAC
872   gMC->Gsatt("FAIC","seen",0); // no children for FAIC
873
874   // Level 5 of B071 / Level 4 of BTO1 / Level 3 of FTOB / Level 2 of FLTB
875   gMC->Gsatt("FALB","seen",0); // no children for FALB
876 //-->  gMC->Gsatt("FSTR","seen",-2);
877
878
879   // -> cfr previous settings
880   gMC->Gsatt("FPEB","seen",0); // no children for FPEB
881   gMC->Gsatt("FECB","seen",0); // no children for FECB
882   gMC->Gsatt("FWAB","seen",0); // no children for FWAB
883   gMC->Gsatt("FAIB","seen",0); // no children for FAIB
884  
885   // Level 5 of B071 / Level 4 of BTO1 / Level 3 of FTOA / Level 2 of FLTA
886   gMC->Gsatt("FALA","seen",0); // no children for FALB
887 //-->  gMC->Gsatt("FSTR","seen",-2);
888   // -> cfr previous settings
889   gMC->Gsatt("FPEA","seen",0); // no children for FPEA
890   gMC->Gsatt("FECA","seen",0); // no children for FECA
891   gMC->Gsatt("FWAA","seen",0); // no children for FWAA
892   gMC->Gsatt("FAIA","seen",0); // no children for FAIA
893
894   // Level 2 of B074
895   gMC->Gsatt("BTR2","seen",0); // BTR2 does not has sub-levels -
896   gMC->Gsatt("BTO2","seen",0);
897
898   // Level 2 of B075
899   gMC->Gsatt("BTR3","seen",0); // BTR3 do not have sub-levels -
900   gMC->Gsatt("BTO3","seen",0);
901
902 // for others Level 5, cfr. previous settings
903
904   gMC->Gdopt("hide","on");
905   gMC->Gdopt("shad","on");
906   gMC->Gsatt("*", "fill", 5);
907   gMC->SetClipBox(".");
908   gMC->SetClipBox("*", 0, 1000, 0, 1000, 0, 1000);
909   gMC->DefaultRange();
910   gMC->Gdraw("alic", 45, 40, 0, 10, 10, .015, .015);
911   gMC->Gdhead(1111,"TOF Strips V1");
912   gMC->Gdman(18, 4, "MAN");
913   gMC->Gdopt("hide","off");
914 }
915
916 //_____________________________________________________________________________
917 void AliTOFv3::CreateMaterials()
918 {
919   //
920   // Define materials for the Time Of Flight
921   //
922   AliTOF::CreateMaterials();
923 }
924  
925 //_____________________________________________________________________________
926 void AliTOFv3::Init()
927 {
928   //
929   // Initialise the detector after the geometry has been defined
930   //
931   if(fDebug) {
932     printf("%s: **************************************"
933            "  TOF  "
934            "**************************************\n",ClassName());
935     printf("\n%s   Version 3 of TOF initialing, "
936                 "TOF with holes for HMPID detector\n",ClassName());
937   }
938
939   AliTOF::Init();
940
941   fIdFTOA = gMC->VolId("FTOA");
942   fIdFTOB = gMC->VolId("FTOB");
943   fIdFTOC = gMC->VolId("FTOC");
944   fIdFLTA = gMC->VolId("FLTA");
945   fIdFLTB = gMC->VolId("FLTB");
946   fIdFLTC = gMC->VolId("FLTC");
947
948  if(fDebug) {
949     printf("%s: **************************************"
950            "  TOF  "
951            "**************************************\n",ClassName());
952  }
953 }
954  
955 //_____________________________________________________________________________
956 void AliTOFv3::StepManager()
957 {
958   //
959   // Procedure called at each step in the Time Of Flight
960   //
961   TLorentzVector mom, pos;
962   Float_t xm[3],pm[3],xpad[3],ppad[3];
963   Float_t hits[13],phi,phid,z;
964   Int_t   vol[5];
965   Int_t   sector, plate, padx, padz, strip;
966   Int_t   copy, padzid, padxid, stripid, i;
967   Int_t   *idtmed = fIdtmed->GetArray()-499;
968   Float_t incidenceAngle;
969   
970   if(gMC->CurrentMedium()==idtmed[513] && 
971      gMC->IsTrackEntering() && gMC->TrackCharge()
972      && gMC->CurrentVolID(copy)==fIdSens) 
973   {    
974     // getting information about hit volumes
975     
976     padzid=gMC->CurrentVolOffID(2,copy);
977     padz=copy;
978     
979     padxid=gMC->CurrentVolOffID(1,copy);
980     padx=copy;
981     
982     stripid=gMC->CurrentVolOffID(4,copy);
983     strip=copy;  
984
985     gMC->TrackPosition(pos);
986     gMC->TrackMomentum(mom);
987
988 //    Double_t NormPos=1./pos.Rho();
989     Double_t normMom=1./mom.Rho();
990
991 //  getting the cohordinates in pad ref system
992     xm[0] = (Float_t)pos.X();
993     xm[1] = (Float_t)pos.Y();
994     xm[2] = (Float_t)pos.Z();
995
996     pm[0] = (Float_t)mom.X()*normMom;
997     pm[1] = (Float_t)mom.Y()*normMom;
998     pm[2] = (Float_t)mom.Z()*normMom;
999  
1000     gMC->Gmtod(xm,xpad,1);
1001     gMC->Gmtod(pm,ppad,2);
1002
1003     incidenceAngle = TMath::ACos(ppad[1])*kRaddeg;
1004
1005     z = pos[2];
1006
1007     plate = 0;
1008     if (TMath::Abs(z) <=  fZlenA*0.5)  plate = 2; //3; // AdC
1009     if (z < (fZlenA*0.5+fZlenB) && 
1010         z >  fZlenA*0.5)               plate = 1; //4; // AdC
1011     if (z >-(fZlenA*0.5+fZlenB) &&
1012         z < -fZlenA*0.5)               plate = 3; //2; // AdC
1013     if (z > (fZlenA*0.5+fZlenB))       plate = 0; //5; // AdC
1014     if (z <-(fZlenA*0.5+fZlenB))       plate = 4; //1; // AdC
1015
1016     if (plate==0) strip=AliTOFConstants::fgkNStripC-strip; // AdC
1017     else if (plate==1) strip=AliTOFConstants::fgkNStripB-strip; // AdC
1018     else strip--; // AdC
1019
1020     if (z<=0.) padx=AliTOFConstants::fgkNpadX-padx; // AdC
1021     else padx--; // AdC
1022
1023     if (plate==3 || plate==4) padz=AliTOFConstants::fgkNpadZ-padz; // AdC
1024     else padz--; // AdC
1025
1026     phi = pos.Phi();
1027     if (phi>=0.) phid = phi*kRaddeg; //+180.; // AdC
1028     else phid = phi*kRaddeg + 360.; // AdC
1029     sector = Int_t (phid/20.);
1030     //sector++; // AdC
1031
1032     for(i=0;i<3;++i) {
1033       hits[i]   = pos[i];
1034       hits[i+3] = pm[i];
1035     }
1036
1037     hits[6] = mom.Rho();
1038     hits[7] = pos[3];
1039     hits[8] = xpad[0];
1040     hits[9] = xpad[1];
1041     hits[10]= xpad[2];
1042     hits[11]= incidenceAngle;
1043     hits[12]= gMC->Edep();
1044     
1045     vol[0]= sector;
1046     vol[1]= plate;
1047     vol[2]= strip;
1048     vol[3]= padx;
1049     vol[4]= padz;
1050     
1051     AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(),vol, hits);
1052   }
1053 }