]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFv2.cxx
Minor changes to the Digitizer procedure
[u/mrichter/AliRoot.git] / TOF / AliTOFv2.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 /*
17 $Log$
18 Revision 1.20  2001/05/16 14:57:24  alibrary
19 New files for folders and Stack
20
21 Revision 1.19  2001/05/04 10:09:48  vicinanz
22 Major upgrades to the strip structure
23
24 Revision 1.18  2000/12/04 08:48:20  alibrary
25 Fixing problems in the HEAD
26
27 Revision 1.17  2000/10/02 21:28:17  fca
28 Removal of useless dependecies via forward declarations
29
30 Revision 1.16  2000/05/10 16:52:18  vicinanz
31 New TOF version with holes for PHOS/RICH
32
33 Revision 1.14.2.1  2000/05/10 09:37:16  vicinanz
34 New version with Holes for PHOS/RICH
35
36 Revision 1.14  1999/11/05 22:39:06  fca
37 New hits structure
38
39 Revision 1.13  1999/11/02 11:26:39  fca
40 added stdlib.h for exit
41
42 Revision 1.12  1999/11/01 20:41:57  fca
43 Added protections against using the wrong version of FRAME
44
45 Revision 1.11  1999/10/22 08:04:14  fca
46 Correct improper use of negative parameters
47
48 Revision 1.10  1999/10/16 19:30:06  fca
49 Corrected Rotation Matrix and CVS log
50
51 Revision 1.9  1999/10/15 15:35:20  fca
52 New version for frame1099 with and without holes
53
54 Revision 1.8  1999/09/29 09:24:33  fca
55 Introduction of the Copyright and cvs Log
56
57 */
58
59 ///////////////////////////////////////////////////////////////////////////////
60 //                                                                           //
61 //  Time Of Flight: design of C.Williams                                     
62 //                                                                           
63 //  This class contains the functions for version 2 of the Time Of Flight    //
64 //  detector.                                                                //
65 //
66 //  VERSION WITH 5 MODULES AND TILTED STRIPS 
67 //  
68 //  HOLES FOR PHOS AND RICH DETECTOR
69 //
70 //   Authors:
71 //
72 //   Alessio Seganti
73 //   Domenico Vicinanza
74 //
75 //   University of Salerno - Italy
76 //
77 //   Fabrizio Pierella
78 //   University of Bologna - Italy
79 //
80 //
81 //Begin_Html
82 /*
83 <img src="picts/AliTOFv2Class.gif">
84 */
85 //End_Html
86 //                                                                           //
87 ///////////////////////////////////////////////////////////////////////////////
88
89 #include <iostream.h>
90 #include <stdlib.h>
91
92 #include "AliTOFv2.h"
93 #include "TBRIK.h"
94 #include "TGeometry.h"
95 #include "TNode.h"
96 #include <TLorentzVector.h>
97 #include "TObject.h"
98 #include "AliRun.h"
99 #include "AliMC.h"
100 #include "AliMagF.h"
101 #include "AliConst.h"
102
103  
104 ClassImp(AliTOFv2)
105  
106 //_____________________________________________________________________________
107 AliTOFv2::AliTOFv2()
108 {
109   //
110   // Default constructor
111   //
112 }
113  
114 //_____________________________________________________________________________
115 AliTOFv2::AliTOFv2(const char *name, const char *title)
116         : AliTOF(name,title)
117 {
118   //
119   // Standard constructor
120   //
121   //
122   // Check that FRAME is there otherwise we have no place where to
123   // put TOF
124   AliModule* frame=gAlice->GetModule("FRAME");
125   if(!frame) {
126     Error("Ctor","TOF needs FRAME to be present\n");
127     exit(1);
128   } else
129     if(frame->IsVersion()!=1) {
130       Error("Ctor","FRAME version 1 needed with this version of TOF\n");
131       exit(1);
132     }
133
134 }
135
136 //____________________________________________________________________________
137 AliTOFv2::~AliTOFv2()
138 {
139   // destructor
140
141   if ( fHits) {
142     fHits->Delete() ; 
143     delete fHits ;
144     fHits = 0 ; 
145   }
146
147   if ( fSDigits) {
148     fSDigits->Delete() ; 
149     delete fSDigits ;
150     fSDigits = 0 ; 
151   }
152
153   if ( fDigits) {
154     fDigits->Delete() ; 
155     delete fDigits ;
156     fDigits = 0 ; 
157   }
158   
159 }
160
161 //_____________________________________________________________________________
162 void AliTOFv2::BuildGeometry()
163 {
164   //
165   // Build TOF ROOT geometry for the ALICE event display
166   //
167   TNode *node, *top;
168   const int kColorTOF  = 27;
169
170   // Find top TNODE
171   top = gAlice->GetGeometry()->GetNode("alice");
172
173   // Position the different copies
174   const Float_t krTof  =(fRmax+fRmin)/2;
175   const Float_t khTof  = fRmax-fRmin;
176   const Int_t   kNTof = fNTof;
177   const Float_t kPi   = TMath::Pi();
178   const Float_t kangle = 2*kPi/kNTof;
179   Float_t ang;
180
181   // Define TOF basic volume
182   
183   char nodeName0[6], nodeName1[6], nodeName2[6]; 
184   char nodeName3[6], nodeName4[6], rotMatNum[6];
185
186   new TBRIK("S_TOF_C","TOF box","void",
187             120*0.5,khTof*0.5,fZlenC*0.5);
188   new TBRIK("S_TOF_B","TOF box","void",
189             120*0.5,khTof*0.5,fZlenB*0.5);
190   new TBRIK("S_TOF_A","TOF box","void",
191             120*0.5,khTof*0.5,fZlenA*0.5);
192
193   for (Int_t nodeNum=1;nodeNum<19;nodeNum++){
194      
195       if (nodeNum<10) {
196            sprintf(rotMatNum,"rot50%i",nodeNum);
197            sprintf(nodeName0,"FTO00%i",nodeNum);
198            sprintf(nodeName1,"FTO10%i",nodeNum);
199            sprintf(nodeName2,"FTO20%i",nodeNum);
200            sprintf(nodeName3,"FTO30%i",nodeNum);
201            sprintf(nodeName4,"FTO40%i",nodeNum);
202       }
203       if (nodeNum>9) {
204            sprintf(rotMatNum,"rot5%i",nodeNum);
205            sprintf(nodeName0,"FTO0%i",nodeNum);
206            sprintf(nodeName1,"FTO1%i",nodeNum);
207            sprintf(nodeName2,"FTO2%i",nodeNum);
208            sprintf(nodeName3,"FTO3%i",nodeNum);
209            sprintf(nodeName4,"FTO4%i",nodeNum);
210       }
211  
212       new TRotMatrix(rotMatNum,rotMatNum,90,-20*nodeNum,90,90-20*nodeNum,0,0);
213       ang = (4.5-nodeNum) * kangle;
214
215       top->cd();
216       node = new TNode(nodeName0,nodeName0,"S_TOF_C",krTof*TMath::Cos(ang),krTof*TMath::Sin(ang),299.15,rotMatNum);
217       node->SetLineColor(kColorTOF);
218       fNodes->Add(node); 
219
220       top->cd(); 
221       node = new TNode(nodeName1,nodeName1,"S_TOF_C",krTof*TMath::Cos(ang),krTof*TMath::Sin(ang),-299.15,rotMatNum);
222       node->SetLineColor(kColorTOF);
223       fNodes->Add(node); 
224 if (nodeNum !=1 && nodeNum!=2 && nodeNum !=18)
225     {
226       top->cd();
227       node = new TNode(nodeName2,nodeName2,"S_TOF_B",krTof*TMath::Cos(ang),krTof*TMath::Sin(ang),146.45,rotMatNum);
228       node->SetLineColor(kColorTOF);
229       fNodes->Add(node); 
230
231       top->cd();
232       node = new TNode(nodeName3,nodeName3,"S_TOF_B",krTof*TMath::Cos(ang),krTof*TMath::Sin(ang),-146.45,rotMatNum);
233       node->SetLineColor(kColorTOF);
234       fNodes->Add(node); 
235   } // Holes for RICH detector
236
237 if ((nodeNum<8 || nodeNum>12) && nodeNum !=1 && nodeNum!=2 && nodeNum !=18)
238     { 
239       top->cd();
240       node = new TNode(nodeName4,nodeName4,"S_TOF_A",krTof*TMath::Cos(ang),krTof*TMath::Sin(ang),0.,rotMatNum);
241       node->SetLineColor(kColorTOF);
242       fNodes->Add(node); 
243      } // Holes for PHOS detector (+ Holes for RICH detector, central part)
244   } // end loop on nodeNum
245 }
246
247  
248 //_____________________________________________________________________________
249 void AliTOFv2::CreateGeometry()
250 {
251   //
252   // Create geometry for Time Of Flight version 0
253   //
254   //Begin_Html
255   /*
256     <img src="picts/AliTOFv2.gif">
257   */
258   //End_Html
259   //
260   // Creates common geometry
261   //
262   AliTOF::CreateGeometry();
263 }
264  
265 //_____________________________________________________________________________
266 void AliTOFv2::TOFpc(Float_t xtof, Float_t ytof, Float_t zlenC,
267                      Float_t zlenB, Float_t zlenA, Float_t ztof0)
268 {
269   //
270   // Definition of the Time Of Fligh Resistive Plate Chambers
271   // xFLT, yFLT, zFLT - sizes of TOF modules (large)
272   
273   Float_t  ycoor, zcoor;
274   Float_t  par[3];
275   Int_t    *idtmed = fIdtmed->GetArray()-499;
276   Int_t    idrotm[100];
277   Int_t    nrot = 0;
278   Float_t  hTof = fRmax-fRmin;
279   
280   Float_t radius = fRmin+2.;//cm
281
282   par[0] =  xtof * 0.5;
283   par[1] =  ytof * 0.5;
284   par[2] = zlenC * 0.5;
285   gMC->Gsvolu("FTOC", "BOX ", idtmed[506], par, 3);
286   par[2] = zlenB * 0.5;
287   gMC->Gsvolu("FTOB", "BOX ", idtmed[506], par, 3);
288   par[2] = zlenA * 0.5;
289   gMC->Gsvolu("FTOA", "BOX ", idtmed[506], par, 3);
290
291
292 // Positioning of modules
293
294    Float_t zcor1 = ztof0 - zlenC*0.5;
295    Float_t zcor2 = ztof0 - zlenC - zlenB*0.5;
296    Float_t zcor3 = 0.;
297
298    AliMatrix(idrotm[0], 90.,  0., 0., 0., 90,-90.);
299    AliMatrix(idrotm[1], 90.,180., 0., 0., 90, 90.);
300    gMC->Gspos("FTOC", 1, "BTO1", 0,  zcor1, 0, idrotm[0], "ONLY");
301    gMC->Gspos("FTOC", 2, "BTO1", 0, -zcor1, 0, idrotm[1], "ONLY");
302    gMC->Gspos("FTOC", 1, "BTO2", 0,  zcor1, 0, idrotm[0], "ONLY");
303    gMC->Gspos("FTOC", 2, "BTO2", 0, -zcor1, 0, idrotm[1], "ONLY");
304    gMC->Gspos("FTOC", 1, "BTO3", 0,  zcor1, 0, idrotm[0], "ONLY");
305    gMC->Gspos("FTOC", 2, "BTO3", 0, -zcor1, 0, idrotm[1], "ONLY");
306
307    gMC->Gspos("FTOB", 1, "BTO1", 0,  zcor2, 0, idrotm[0], "ONLY");
308    gMC->Gspos("FTOB", 2, "BTO1", 0, -zcor2, 0, idrotm[1], "ONLY");
309    gMC->Gspos("FTOB", 1, "BTO2", 0,  zcor2, 0, idrotm[0], "ONLY");
310    gMC->Gspos("FTOB", 2, "BTO2", 0, -zcor2, 0, idrotm[1], "ONLY");
311
312    gMC->Gspos("FTOA", 0, "BTO1", 0, zcor3,  0, idrotm[0], "ONLY");
313
314   Float_t db = 0.5;//cm
315   Float_t xFLT, xFST, yFLT, zFLTA, zFLTB, zFLTC;
316
317   xFLT = fStripLn;
318   yFLT = ytof;
319   zFLTA = zlenA;
320   zFLTB = zlenB;
321   zFLTC = zlenC;
322
323   xFST = xFLT-fDeadBndX*2;//cm
324
325 // Sizes of MRPC pads
326
327   Float_t yPad = 0.505;//cm 
328   
329 // Large not sensitive volumes with Insensitive Freon
330   par[0] = xFLT*0.5;
331   par[1] = yFLT*0.5;
332   
333   if(fDebug) 
334     cout <<ClassName()
335          <<": ************************* TOF geometry **************************"
336          <<endl;
337
338   par[2] = (zFLTA *0.5);
339   gMC->Gsvolu("FLTA", "BOX ", idtmed[512], par, 3); // Insensitive Freon
340   gMC->Gspos ("FLTA", 0, "FTOA", 0., 0., 0., 0, "ONLY");
341
342   par[2] = (zFLTB * 0.5);
343   gMC->Gsvolu("FLTB", "BOX ", idtmed[512], par, 3); // Insensitive Freon
344   gMC->Gspos ("FLTB", 0, "FTOB", 0., 0., 0., 0, "ONLY");
345
346   par[2] = (zFLTC * 0.5);
347   gMC->Gsvolu("FLTC", "BOX ", idtmed[512], par, 3); // Insensitive Freon
348   gMC->Gspos ("FLTC", 0, "FTOC", 0., 0., 0., 0, "ONLY");
349
350 ////////// Layers of Aluminum before and after detector //////////
351 ////////// Aluminum Box for Modules (2.0 mm thickness)  /////////
352 ////////// lateral walls not simulated
353   par[0] = xFLT*0.5;
354   par[1] = 0.1;//cm
355   ycoor = -yFLT/2 + par[1];
356   par[2] = (zFLTA *0.5);
357   gMC->Gsvolu("FALA", "BOX ", idtmed[508], par, 3); // Alluminium
358   gMC->Gspos ("FALA", 1, "FLTA", 0., ycoor, 0., 0, "ONLY");
359   gMC->Gspos ("FALA", 2, "FLTA", 0.,-ycoor, 0., 0, "ONLY");
360   par[2] = (zFLTB *0.5);
361   gMC->Gsvolu("FALB", "BOX ", idtmed[508], par, 3); // Alluminium 
362   gMC->Gspos ("FALB", 1, "FLTB", 0., ycoor, 0., 0, "ONLY");
363   gMC->Gspos ("FALB", 2, "FLTB", 0.,-ycoor, 0., 0, "ONLY");
364   par[2] = (zFLTC *0.5);
365   gMC->Gsvolu("FALC", "BOX ", idtmed[508], par, 3); // Alluminium
366   gMC->Gspos ("FALC", 1, "FLTC", 0., ycoor, 0., 0, "ONLY");
367   gMC->Gspos ("FALC", 2, "FLTC", 0.,-ycoor, 0., 0, "ONLY");
368   
369 ///////////////// Detector itself //////////////////////
370
371   const Float_t  kdeadBound  =  fDeadBndZ; //cm non-sensitive between the pad edge 
372                                           //and the boundary of the strip
373   const Int_t    knx    = fNpadX;          // number of pads along x
374   const Int_t    knz    = fNpadZ;          // number of pads along z
375   const Float_t  kspace = fSpace;            //cm distance from the front plate of the box
376
377   Float_t zSenStrip  = fZpad*fNpadZ;//cm
378   Float_t stripWidth = zSenStrip + 2*kdeadBound;
379
380   par[0] = xFLT*0.5;
381   par[1] = yPad*0.5; 
382   par[2] = stripWidth*0.5;
383   
384 // new description for strip volume
385 // -- all constants are expressed in cm
386 // heigth of different layers
387   const Float_t khhony = 1.      ;   // heigth of HONY  Layer
388   const Float_t khpcby = 0.15    ;   // heigth of PCB   Layer
389   const Float_t khmyly = 0.035   ;   // heigth of MYLAR Layer
390   const Float_t khgraphy = 0.02  ;   // heigth of GRAPHITE Layer
391   const Float_t khglasseiy = 0.32;   // 2.2 Ext. Glass + 1. Semi Int. Glass (mm)
392   const Float_t khsensmy = 0.11  ;   // heigth of Sensitive Freon Mixture
393   const Float_t kwsensmz = 2*3.5 ;   // cm
394   const Float_t klsensmx = 48*2.5;   // cm
395   const Float_t kwpadz = 3.5;   // cm z dimension of the FPAD volume
396   const Float_t klpadx = 2.5;   // cm x dimension of the FPAD volume
397   
398   // heigth of the FSTR Volume (the strip volume)
399   const Float_t khstripy = 2*(khhony+khpcby+khmyly+khgraphy+khglasseiy)+khsensmy;
400   // width  of the FSTR Volume (the strip volume)
401   const Float_t kwstripz = 10.;
402   // length of the FSTR Volume (the strip volume)
403   const Float_t klstripx = 122.;
404   
405   Float_t parfp[3]={klstripx*0.5,khstripy*0.5,kwstripz*0.5};
406 // coordinates of the strip center in the strip reference frame; used for positioning
407 // internal strip volumes
408   Float_t posfp[3]={0.,0.,0.};   
409   
410   // FSTR volume definition and filling this volume with non sensitive Gas Mixture
411   gMC->Gsvolu("FSTR","BOX",idtmed[512],parfp,3);
412   //-- HONY Layer definition
413 //  parfp[0] = -1;
414   parfp[1] = khhony*0.5;
415 //  parfp[2] = -1;
416   gMC->Gsvolu("FHON","BOX",idtmed[503],parfp,3);
417   // positioning 2 HONY Layers on FSTR volume
418   posfp[1]=-khstripy*0.5+parfp[1];
419   gMC->Gspos("FHON",1,"FSTR",0., posfp[1],0.,0,"ONLY");
420   gMC->Gspos("FHON",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
421   
422   //-- PCB Layer definition 
423   parfp[1] = khpcby*0.5;
424   gMC->Gsvolu("FPCB","BOX",idtmed[504],parfp,3);
425   // positioning 2 PCB Layers on FSTR volume
426   posfp[1]=-khstripy*0.5+khhony+parfp[1];
427   gMC->Gspos("FPCB",1,"FSTR",0., posfp[1],0.,0,"ONLY");
428   gMC->Gspos("FPCB",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
429   
430   //-- MYLAR Layer definition
431   parfp[1] = khmyly*0.5;
432   gMC->Gsvolu("FMYL","BOX",idtmed[511],parfp,3);
433   // positioning 2 MYLAR Layers on FSTR volume
434   posfp[1] = -khstripy*0.5+khhony+khpcby+parfp[1]; 
435   gMC->Gspos("FMYL",1,"FSTR",0., posfp[1],0.,0,"ONLY");
436   gMC->Gspos("FMYL",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
437
438   //-- Graphite Layer definition
439   parfp[1] = khgraphy*0.5;
440   gMC->Gsvolu("FGRP","BOX",idtmed[502],parfp,3);
441   // positioning 2 Graphite Layers on FSTR volume
442   posfp[1] = -khstripy*0.5+khhony+khpcby+khmyly+parfp[1];
443   gMC->Gspos("FGRP",1,"FSTR",0., posfp[1],0.,0,"ONLY");
444   gMC->Gspos("FGRP",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
445
446   //-- Glass (EXT. +Semi INT.) Layer definition
447   parfp[1] = khglasseiy*0.5;
448   gMC->Gsvolu("FGLA","BOX",idtmed[514],parfp,3);
449   // positioning 2 Glass Layers on FSTR volume
450   posfp[1] = -khstripy*0.5+khhony+khpcby+khmyly+khgraphy+parfp[1];
451   gMC->Gspos("FGLA",1,"FSTR",0., posfp[1],0.,0,"ONLY");
452   gMC->Gspos("FGLA",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
453   
454   //-- Sensitive Mixture Layer definition
455   parfp[0] = klsensmx*0.5;
456   parfp[1] = khsensmy*0.5;
457   parfp[2] = kwsensmz*0.5;  
458   gMC->Gsvolu("FSEN","BOX",idtmed[513],parfp,3);
459   // positioning the sensitive gas Layer on FSTR volume
460   gMC->Gspos("FSEN",0,"FSTR",0.,0.,0.,0,"ONLY");
461
462   // dividing FSEN along z in knz=2 and along x in knx=48
463   gMC->Gsdvn("FSEZ","FSEN",knz,3);
464   gMC->Gsdvn("FSEX","FSEZ",knx,1);
465   
466   // FPAD volume definition
467   parfp[0] = klpadx*0.5;    
468   parfp[1] = khsensmy*0.5;
469   parfp[2] = kwpadz*0.5;
470   gMC->Gsvolu("FPAD","BOX",idtmed[513],parfp,3);
471   // positioning the FPAD volumes on previous divisions
472   gMC->Gspos("FPAD",0,"FSEX",0.,0.,0.,0,"ONLY");
473   
474 ////  Positioning the Strips  (FSTR) in the FLT volumes  /////
475
476   // Plate A (Central) 
477   
478   Float_t t = zFLTC+zFLTB+zFLTA*0.5+ 2*db;//Half Width of Barrel
479
480   Float_t gap  = fGapA; //cm  distance between the strip axis
481   Float_t zpos = 0;
482   Float_t ang  = 0;
483   Int_t i=1,j=1;
484   nrot  = 0;
485   zcoor = 0;
486   ycoor = -14.5 + kspace ; //2 cm over front plate
487
488   AliMatrix (idrotm[0],  90.,  0.,90.,90.,0., 90.);   
489   gMC->Gspos("FSTR",j,"FLTA",0.,ycoor, 0.,idrotm[0],"ONLY");
490
491   if(fDebug) {
492      printf("%s: %f,  St. %2i, Pl.3 ",ClassName(),ang*kRaddeg,i); 
493      printf("%s: y = %f,  z = %f, zpos = %f \n",ClassName(),ycoor,zcoor,zpos);
494   }
495
496   zcoor -= zSenStrip;
497   j++;
498   Int_t upDown = -1; // upDown=-1 -> Upper strip
499                      // upDown=+1 -> Lower strip
500   do{
501      ang = atan(zcoor/radius);
502      ang *= kRaddeg;
503      AliMatrix (idrotm[nrot],  90.,  0.,90.-ang,90.,-ang, 90.);   
504      AliMatrix (idrotm[nrot+1],90.,180.,90.+ang,90., ang, 90.);
505      ang /= kRaddeg;
506      ycoor = -14.5+ kspace; //2 cm over front plate
507      ycoor += (1-(upDown+1)/2)*gap;
508      gMC->Gspos("FSTR",j  ,"FLTA",0.,ycoor, zcoor,idrotm[nrot],  "ONLY");
509      gMC->Gspos("FSTR",j+1,"FLTA",0.,ycoor,-zcoor,idrotm[nrot+1],"ONLY");
510
511      if(fDebug) {
512        printf("%s: %f,  St. %2i, Pl.3 ",ClassName(),ang*kRaddeg,i);
513        printf("%s: y = %f,  z = %f, zpos = %f \n",ClassName(),ycoor,zcoor,zpos);
514      }
515
516      j += 2;
517      upDown*= -1; // Alternate strips 
518      zcoor = zcoor-(zSenStrip/2)/TMath::Cos(ang)-
519              upDown*gap*TMath::Tan(ang)-
520              (zSenStrip/2)/TMath::Cos(ang);
521   } while (zcoor-(stripWidth/2)*TMath::Cos(ang)>-t+zFLTC+zFLTB+db*2);
522   
523   zcoor = zcoor+(zSenStrip/2)/TMath::Cos(ang)+
524           upDown*gap*TMath::Tan(ang)+
525           (zSenStrip/2)/TMath::Cos(ang);
526
527   gap = fGapB;
528   zcoor = zcoor-(zSenStrip/2)/TMath::Cos(ang)-
529           upDown*gap*TMath::Tan(ang)-
530           (zSenStrip/2)/TMath::Cos(ang);
531
532   ang = atan(zcoor/radius);
533   ang *= kRaddeg;
534   AliMatrix (idrotm[nrot],  90.,  0.,90.-ang,90.,-ang, 90.);   
535   AliMatrix (idrotm[nrot+1],90.,180.,90.+ang,90., ang, 90.);
536   ang /= kRaddeg;
537           
538   ycoor = -14.5+ kspace; //2 cm over front plate
539   ycoor += (1-(upDown+1)/2)*gap;
540   gMC->Gspos("FSTR",j  ,"FLTA",0.,ycoor, zcoor,idrotm[nrot],  "ONLY");
541   gMC->Gspos("FSTR",j+1,"FLTA",0.,ycoor,-zcoor,idrotm[nrot+1],"ONLY");
542
543   if(fDebug) {   
544      printf("%s: %f,  St. %2i, Pl.3 ",ClassName(),ang*kRaddeg,i);  
545      printf("%s: y = %f,  z = %f, zpos = %f \n",ClassName(),ycoor,zcoor,zpos);  
546   }   
547
548   ycoor = -hTof/2.+ kspace;//2 cm over front plate
549
550   // Plate  B
551
552   nrot = 0;
553   i=1;
554   upDown = 1;
555   Float_t deadRegion = 1.0;//cm
556   
557   zpos = zcoor - (zSenStrip/2)/TMath::Cos(ang)-
558          upDown*gap*TMath::Tan(ang)-
559          (zSenStrip/2)/TMath::Cos(ang)-
560          deadRegion/TMath::Cos(ang);
561
562   ang = atan(zpos/radius);
563   ang *= kRaddeg;
564   AliMatrix (idrotm[nrot], 90., 0., 90.-ang,90.,ang, 270.);
565   ang /= kRaddeg;
566   ycoor = -hTof*0.5+ kspace ; //2 cm over front plate
567   ycoor += (1-(upDown+1)/2)*gap;
568   zcoor = zpos+(zFLTA*0.5+zFLTB*0.5+db); // Moves to the system of the modulus FLTB
569   gMC->Gspos("FSTR",i, "FLTB", 0., ycoor, zcoor,idrotm[nrot], "ONLY");
570
571   if(fDebug) {   
572      printf("%s: %f,  St. %2i, Pl.4 ",ClassName(),ang*kRaddeg,i);
573      printf("%s: y = %f,  z = %f, zpos = %f \n",ClassName(),ycoor,zcoor,zpos);
574   }   
575
576   i++;
577   upDown*=-1;
578
579   do {
580      zpos = zpos - (zSenStrip/2)/TMath::Cos(ang)-
581             upDown*gap*TMath::Tan(ang)-
582             (zSenStrip/2)/TMath::Cos(ang);
583      ang = atan(zpos/radius);
584      ang *= kRaddeg;
585      AliMatrix (idrotm[nrot], 90., 0., 90.-ang,90.,ang, 270.);
586      ang /= kRaddeg;
587      ycoor = -hTof*0.5+ kspace ; //2 cm over front plate
588      ycoor += (1-(upDown+1)/2)*gap;
589      zcoor = zpos+(zFLTA*0.5+zFLTB*0.5+db); // Moves to the system of the modulus FLTB
590      gMC->Gspos("FSTR",i, "FLTB", 0., ycoor, zcoor,idrotm[nrot], "ONLY");
591
592      if(fDebug) {
593        printf("%s: %f,  St. %2i, Pl.4 ",ClassName(),ang*kRaddeg,i);
594        printf("%s: y = %f,  z = %f, zpos = %f \n",ClassName(),ycoor,zcoor,zpos);
595      }
596
597      upDown*=-1;
598      i++;
599   } while (TMath::Abs(ang*kRaddeg)<22.5);
600   //till we reach a tilting angle of 22.5 degrees
601
602   ycoor = -hTof*0.5+ kspace ; //2 cm over front plate
603   zpos = zpos - zSenStrip/TMath::Cos(ang);
604
605   do {
606      ang = atan(zpos/radius);
607      ang *= kRaddeg;
608      AliMatrix (idrotm[nrot], 90., 0., 90.-ang,90.,ang, 270.);
609      ang /= kRaddeg;
610      zcoor = zpos+(zFLTB/2+zFLTA/2+db);
611      gMC->Gspos("FSTR",i, "FLTB", 0., ycoor, zcoor,idrotm[nrot], "ONLY");
612      zpos = zpos - zSenStrip/TMath::Cos(ang);
613      if(fDebug) {
614        printf("%s: %f,  St. %2i, Pl.4 ",ClassName(),ang*kRaddeg,i);
615        printf("%s: y = %f,  z = %f, zpos = %f \n",ClassName(),ycoor,zcoor,zpos);
616      }
617      i++;
618
619   }  while (zpos-stripWidth*0.5/TMath::Cos(ang)>-t+zFLTC+db);
620
621   // Plate  C
622   
623   zpos = zpos + zSenStrip/TMath::Cos(ang);
624
625   zpos = zpos - (zSenStrip/2)/TMath::Cos(ang)+
626          gap*TMath::Tan(ang)-
627          (zSenStrip/2)/TMath::Cos(ang);
628
629   nrot = 0;
630   i=0;
631   ycoor= -hTof*0.5+kspace+gap;
632
633   do {
634      i++;
635      ang = atan(zpos/radius);
636      ang *= kRaddeg;
637      AliMatrix (idrotm[nrot], 90., 0., 90.-ang,90.,ang, 270.);
638      ang /= kRaddeg;
639      zcoor = zpos+(zFLTC*0.5+zFLTB+zFLTA*0.5+db*2);
640      gMC->Gspos("FSTR",i, "FLTC", 0., ycoor, zcoor,idrotm[nrot], "ONLY");
641
642      if(fDebug) {
643        printf("%s: %f,  St. %2i, Pl.5 ",ClassName(),ang*kRaddeg,i);
644        printf("%s: y = %f,  z = %f, zpos = %f \n",ClassName(),ycoor,zcoor,zpos);
645      }
646
647      zpos = zpos - zSenStrip/TMath::Cos(ang);
648   }  while (zpos-stripWidth*TMath::Cos(ang)*0.5>-t);
649
650
651 ////////// Layers after strips /////////////////
652 // honeycomb (Polyethilene) Layer after (1.2cm)
653
654   Float_t overSpace = fOverSpc;//cm
655
656   par[0] = xFLT*0.5;
657   par[1] = 0.6;
658   par[2] = (zFLTA *0.5);
659   ycoor = -yFLT/2 + overSpace + par[1];
660   gMC->Gsvolu("FPEA", "BOX ", idtmed[503], par, 3); // Hony
661   gMC->Gspos ("FPEA", 0, "FLTA", 0., ycoor, 0., 0, "ONLY");
662   par[2] = (zFLTB *0.5);
663   gMC->Gsvolu("FPEB", "BOX ", idtmed[503], par, 3); // Hony
664   gMC->Gspos ("FPEB", 0, "FLTB", 0., ycoor, 0., 0, "ONLY");
665   par[2] = (zFLTC *0.5);
666   gMC->Gsvolu("FPEC", "BOX ", idtmed[503], par, 3); // Hony
667   gMC->Gspos ("FPEC", 0, "FLTC", 0., ycoor, 0., 0, "ONLY");
668
669 // Electronics (Cu) after
670   ycoor += par[1];
671   par[0] = xFLT*0.5;
672   par[1] = 1.43*0.05*0.5; // 5% of X0
673   par[2] = (zFLTA *0.5);
674   ycoor += par[1];
675   gMC->Gsvolu("FECA", "BOX ", idtmed[501], par, 3); // Cu
676   gMC->Gspos ("FECA", 0, "FLTA", 0., ycoor, 0., 0, "ONLY");
677   par[2] = (zFLTB *0.5);
678   gMC->Gsvolu("FECB", "BOX ", idtmed[501], par, 3); // Cu
679   gMC->Gspos ("FECB", 0, "FLTB", 0., ycoor, 0., 0, "ONLY");
680   par[2] = (zFLTC *0.5);
681   gMC->Gsvolu("FECC", "BOX ", idtmed[501], par, 3); // Cu
682   gMC->Gspos ("FECC", 0, "FLTC", 0., ycoor, 0., 0, "ONLY");
683
684 // cooling WAter after
685   ycoor += par[1];
686   par[0] = xFLT*0.5;
687   par[1] = 36.1*0.02*0.5; // 2% of X0
688   par[2] = (zFLTA *0.5);
689   ycoor += par[1];
690   gMC->Gsvolu("FWAA", "BOX ", idtmed[515], par, 3); // Water
691   gMC->Gspos ("FWAA", 0, "FLTA", 0., ycoor, 0., 0, "ONLY");
692   par[2] = (zFLTB *0.5);
693   gMC->Gsvolu("FWAB", "BOX ", idtmed[515], par, 3); // Water
694   gMC->Gspos ("FWAB", 0, "FLTB", 0., ycoor, 0., 0, "ONLY");
695   par[2] = (zFLTC *0.5);
696   gMC->Gsvolu("FWAC", "BOX ", idtmed[515], par, 3); // Water
697   gMC->Gspos ("FWAC", 0, "FLTC", 0., ycoor, 0., 0, "ONLY");
698
699 // frame of Air
700   ycoor += par[1];
701   par[0] = xFLT*0.5;
702   par[1] = (yFLT/2-ycoor-0.2)*0.5; // Aluminum layer considered (0.2 cm)
703   par[2] = (zFLTA *0.5);
704   ycoor += par[1];
705   gMC->Gsvolu("FAIA", "BOX ", idtmed[500], par, 3); // Air
706   gMC->Gspos ("FAIA", 0, "FLTA", 0., ycoor, 0., 0, "ONLY");
707   par[2] = (zFLTB *0.5);
708   gMC->Gsvolu("FAIB", "BOX ", idtmed[500], par, 3); // Air
709   gMC->Gspos ("FAIB", 0, "FLTB", 0., ycoor, 0., 0, "ONLY");
710   par[2] = (zFLTC *0.5);
711   gMC->Gsvolu("FAIC", "BOX ", idtmed[500], par, 3); // Air
712   gMC->Gspos ("FAIC", 0, "FLTC", 0., ycoor, 0., 0, "ONLY");
713 /* fp
714 //Back Plate honycomb (2cm)
715   par[0] = -1;
716   par[1] = 2 *0.5;
717   par[2] = -1;
718   ycoor = yFLT/2 - par[1];
719   gMC->Gsvolu("FBPA", "BOX ", idtmed[503], par, 3); // Hony
720   gMC->Gspos ("FBPA", 0, "FLTA", 0., ycoor, 0., 0, "ONLY");
721   gMC->Gsvolu("FBPB", "BOX ", idtmed[503], par, 3); // Hony
722   gMC->Gspos ("FBPB", 0, "FLTB", 0., ycoor, 0., 0, "ONLY");
723   gMC->Gsvolu("FBPC", "BOX ", idtmed[503], par, 3); // Hony
724   gMC->Gspos ("FBPC", 0, "FLTC", 0., ycoor, 0., 0, "ONLY");
725 fp */
726 }
727
728 //_____________________________________________________________________________
729 void AliTOFv2::DrawModule() const
730 {
731   //
732   // Draw a shaded view of the Time Of Flight version 1
733   //
734   // Set everything unseen
735   gMC->Gsatt("*", "seen", -1);
736   // 
737   // Set ALIC mother transparent
738   gMC->Gsatt("ALIC","SEEN",0);
739   //
740   // Set the volumes visible
741   gMC->Gsatt("ALIC","SEEN",0);
742
743   gMC->Gsatt("FTOA","SEEN",1);
744   gMC->Gsatt("FTOB","SEEN",1);
745   gMC->Gsatt("FTOC","SEEN",1);
746   gMC->Gsatt("FLTA","SEEN",1);
747   gMC->Gsatt("FLTB","SEEN",1);
748   gMC->Gsatt("FLTC","SEEN",1);
749   gMC->Gsatt("FPLA","SEEN",1);
750   gMC->Gsatt("FPLB","SEEN",1);
751   gMC->Gsatt("FPLC","SEEN",1);
752   gMC->Gsatt("FSTR","SEEN",1);
753   gMC->Gsatt("FPEA","SEEN",1);
754   gMC->Gsatt("FPEB","SEEN",1);
755   gMC->Gsatt("FPEC","SEEN",1);
756   
757   gMC->Gsatt("FLZ1","SEEN",0);
758   gMC->Gsatt("FLZ2","SEEN",0);
759   gMC->Gsatt("FLZ3","SEEN",0);
760   gMC->Gsatt("FLX1","SEEN",0);
761   gMC->Gsatt("FLX2","SEEN",0);
762   gMC->Gsatt("FLX3","SEEN",0);
763   gMC->Gsatt("FPAD","SEEN",0);
764
765   gMC->Gdopt("hide", "on");
766   gMC->Gdopt("shad", "on");
767   gMC->Gsatt("*", "fill", 7);
768   gMC->SetClipBox(".");
769   gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
770   gMC->DefaultRange();
771   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
772   gMC->Gdhead(1111, "Time Of Flight");
773   gMC->Gdman(18, 4, "MAN");
774   gMC->Gdopt("hide","off");
775 }
776
777 //_____________________________________________________________________________
778 void AliTOFv2::CreateMaterials()
779 {
780   //
781   // Define materials for the Time Of Flight
782   //
783   AliTOF::CreateMaterials();
784 }
785  
786 //_____________________________________________________________________________
787 void AliTOFv2::Init()
788 {
789   //
790   // Initialise the detector after the geometry has been defined
791   //
792   if(fDebug) {   
793     printf("%s: **************************************"
794            "  TOF  "
795            "**************************************\n",ClassName());
796     printf("\n%s:   Version 2 of TOF initialing, "
797            "TOF with holes for PHOS and RICH \n",ClassName());
798   }  
799
800   AliTOF::Init();
801
802   fIdFTOA = gMC->VolId("FTOA");
803   fIdFTOB = gMC->VolId("FTOB");
804   fIdFTOC = gMC->VolId("FTOC");
805   fIdFLTA = gMC->VolId("FLTA");
806   fIdFLTB = gMC->VolId("FLTB");
807   fIdFLTC = gMC->VolId("FLTC");
808
809   if(fDebug) {
810     printf("%s: **************************************"
811            "  TOF  "
812            "**************************************\n",ClassName());
813   }
814 }
815  
816 //_____________________________________________________________________________
817 void AliTOFv2::StepManager()
818 {
819   //
820   // Procedure called at each step in the Time Of Flight
821   //
822   TLorentzVector mom, pos;
823   Float_t xm[3],pm[3],xpad[3],ppad[3];
824   Float_t hits[13],phi,phid,z;
825   Int_t   vol[5];
826   Int_t   sector, plate, padx, padz, strip;
827   Int_t   copy, padzid, padxid, stripid, i;
828   Int_t   *idtmed = fIdtmed->GetArray()-499;
829   Float_t incidenceAngle;
830   
831   if(gMC->GetMedium()==idtmed[513] && 
832      gMC->IsTrackEntering() && gMC->TrackCharge()
833      && gMC->CurrentVolID(copy)==fIdSens) 
834   {    
835     // getting information about hit volumes
836     
837     padzid=gMC->CurrentVolOffID(2,copy);
838     padz=copy;  
839     
840     padxid=gMC->CurrentVolOffID(1,copy);
841     padx=copy;  
842     
843     stripid=gMC->CurrentVolOffID(4,copy);
844     strip=copy;  
845
846     gMC->TrackPosition(pos);
847     gMC->TrackMomentum(mom);
848
849 //    Double_t NormPos=1./pos.Rho();
850     Double_t normMom=1./mom.Rho();
851
852 //  getting the cohordinates in pad ref system
853     xm[0] = (Float_t)pos.X();
854     xm[1] = (Float_t)pos.Y();
855     xm[2] = (Float_t)pos.Z();
856
857     pm[0] = (Float_t)mom.X()*normMom;
858     pm[1] = (Float_t)mom.Y()*normMom;
859     pm[2] = (Float_t)mom.Z()*normMom;
860  
861     gMC->Gmtod(xm,xpad,1);
862     gMC->Gmtod(pm,ppad,2);
863
864     incidenceAngle = TMath::ACos(ppad[1])*kRaddeg;
865
866     z = pos[2];
867
868     plate = 0;   
869     if (TMath::Abs(z) <=  fZlenA*0.5)  plate = 3;
870     if (z < (fZlenA*0.5+fZlenB) && 
871         z >  fZlenA*0.5)               plate = 4;
872     if (z >-(fZlenA*0.5+fZlenB) &&
873         z < -fZlenA*0.5)               plate = 2;
874     if (z > (fZlenA*0.5+fZlenB))       plate = 5;
875     if (z <-(fZlenA*0.5+fZlenB))       plate = 1;
876
877     phi = pos.Phi();
878     phid = phi*kRaddeg+180.;
879     sector = Int_t (phid/20.);
880     sector++;
881
882     for(i=0;i<3;++i) {
883       hits[i]   = pos[i];
884       hits[i+3] = pm[i];
885     }
886
887     hits[6] = mom.Rho();
888     hits[7] = pos[3];
889     hits[8] = xpad[0];
890     hits[9] = xpad[1];
891     hits[10]= xpad[2];
892     hits[11]= incidenceAngle;
893     hits[12]= gMC->Edep();
894     
895     vol[0]= sector;
896     vol[1]= plate;
897     vol[2]= strip;
898     vol[3]= padx;
899     vol[4]= padz;
900     
901     AddHit(gAlice->CurrentTrack(),vol, hits);
902   }
903 }