]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFv6T0.cxx
Last moment fixes and changes from v4-05-Release (Silvia)
[u/mrichter/AliRoot.git] / TOF / AliTOFv6T0.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.2  2007/05/04 12:59:22  arcelli
19 Change the TOF SM paths for misalignment (one layer up)
20
21 Revision 1.1  2007/05/02 17:32:58  decaro
22 TOF geometry description as installed (G. Cara Romeo, A. De Caro)
23
24 Revision 0.1 2007 March G. Cara Romeo and A. De Caro
25         Implemented a more realistic TOF geometry description,
26         in terms of:
27            - material badget,
28            - services and front end electronics description,
29            - TOF crate readout modules
30              (added volume FTOS in ALIC_1/BBMO_1/BBCE_%i -for i=1,...,18-,
31               and in ALIC_1/BFMO_%i -for i=19,...,36- volumes)
32         As the 5th version in terms of geometrical positioning of volumes.
33
34 */
35
36 ///////////////////////////////////////////////////////////////////////////////
37 //                                                                           //
38 //  This class contains the functions for version 6 of the Time Of Flight    //
39 //  detector.                                                                //
40 //                                                                           //
41 //  VERSION WITH 6 MODULES AND TILTED STRIPS                                 //
42 //                                                                           //
43 //  FULL COVERAGE VERSION + OPTION for PHOS holes                            //
44 //                                                                           //
45 //                                                                           //
46 //Begin_Html                                                                 //
47 /*                                                                           //
48 <img src="picts/AliTOFv6T0Class.gif">                                        //
49 */                                                                           //
50 //End_Html                                                                   //
51 //                                                                           //
52 ///////////////////////////////////////////////////////////////////////////////
53
54 #include "TBRIK.h"
55 #include "TGeometry.h"
56 #include "TLorentzVector.h"
57 #include "TNode.h"
58 #include "TVirtualMC.h"
59 #include "TGeoManager.h"
60
61 #include "AliConst.h"
62 #include "AliLog.h"
63 #include "AliMagF.h"
64 #include "AliMC.h"
65 #include "AliRun.h"
66
67 #include "AliTOFGeometry.h"
68 #include "AliTOFGeometryV5.h"
69 #include "AliTOFv6T0.h"
70
71 extern TDirectory *gDirectory;
72 extern TVirtualMC *gMC;
73 extern TGeoManager *gGeoManager;
74
75 extern AliRun *gAlice;
76
77 ClassImp(AliTOFv6T0)
78
79 //_____________________________________________________________________________
80   AliTOFv6T0::AliTOFv6T0():
81   fIdFTOA(-1),
82   fIdFTOB(-1),
83   fIdFTOC(-1),
84   fIdFLTA(-1),
85   fIdFLTB(-1),
86   fIdFLTC(-1),
87   fTOFHoles(kFALSE)
88 {
89   //
90   // Default constructor
91   //
92 }
93  
94 //_____________________________________________________________________________
95 AliTOFv6T0::AliTOFv6T0(const char *name, const char *title):
96   AliTOF(name,title,"tzero"),
97   fIdFTOA(-1),
98   fIdFTOB(-1),
99   fIdFTOC(-1),
100   fIdFLTA(-1),
101   fIdFLTB(-1),
102   fIdFLTC(-1),
103   fTOFHoles(kFALSE)
104 {
105   //
106   // Standard constructor
107   //
108   //
109   // Check that FRAME is there otherwise we have no place where to
110   // put TOF
111
112
113   AliModule* frame = (AliModule*)gAlice->GetModule("FRAME");
114   if(!frame) {
115     AliFatal("TOF needs FRAME to be present");
116   } else{
117     
118     if (fTOFGeometry) delete fTOFGeometry;
119     fTOFGeometry = new AliTOFGeometryV5();
120
121     if(frame->IsVersion()==1) {
122       AliDebug(1,Form("Frame version %d", frame->IsVersion())); 
123       AliDebug(1,"Full Coverage for TOF");
124       fTOFHoles=false;}    
125     else {
126       AliDebug(1,Form("Frame version %d", frame->IsVersion())); 
127       AliDebug(1,"TOF with Holes for PHOS");
128       fTOFHoles=true;}      
129   }
130   fTOFGeometry->SetHoles(fTOFHoles);
131
132   //AliTOF::fTOFGeometry = fTOFGeometry;
133
134   // Save the geometry
135   TDirectory* saveDir = gDirectory;
136   gAlice->GetRunLoader()->CdGAFile();
137   fTOFGeometry->Write("TOFgeometry");
138   saveDir->cd();
139
140
141
142 //_____________________________________________________________________________
143 void AliTOFv6T0::AddAlignableVolumes() const
144 {
145   //
146   // Create entries for alignable volumes associating the symbolic volume
147   // name with the corresponding volume path. Needs to be syncronized with
148   // eventual changes in the geometry.
149   //
150
151   TString volPath;
152   TString symName;
153
154   TString vpL0  = "ALIC_1/B077_1/BSEGMO";
155   TString vpL1 = "_1/BTOF";
156   TString vpL2 = "_1";
157   TString vpL3 = "/FTOA_0";
158   TString vpL4 = "/FLTA_0/FSTR_";
159
160   TString snSM  = "TOF/sm";
161   TString snSTRIP = "/strip";
162
163   Int_t nSectors=fTOFGeometry->NSectors();
164   Int_t nStrips =fTOFGeometry->NStripA()+
165                  2*fTOFGeometry->NStripB()+
166                  2*fTOFGeometry->NStripC();
167
168   //
169   // The TOF MRPC Strips
170   // The symbolic names are: TOF/sm00/strip01
171   //                           ...
172   //                         TOF/sm17/strip91
173  
174   Int_t imod=0;
175
176   for (Int_t isect = 0; isect < nSectors; isect++) {
177     for (Int_t istr = 1; istr <= nStrips; istr++) {
178       
179       volPath  = vpL0;
180       volPath += isect;
181       volPath += vpL1;
182       volPath += isect;
183       volPath += vpL2;
184       volPath += vpL3;
185       volPath += vpL4;
186       volPath += istr;
187
188       
189       symName  = snSM;
190       symName += Form("%02d",isect);
191       symName += snSTRIP;
192       symName += Form("%02d",istr);
193             
194       AliDebug(2,"--------------------------------------------"); 
195       AliDebug(2,Form("Alignable object %d", imod)); 
196       AliDebug(2,Form("volPath=%s\n",volPath.Data()));
197       AliDebug(2,Form("symName=%s\n",symName.Data()));
198       AliDebug(2,"--------------------------------------------"); 
199               
200       gGeoManager->SetAlignableEntry(symName.Data(),volPath.Data());
201       imod++;
202     }
203   }
204
205
206   //
207   // The TOF supermodules
208   // The symbolic names are: TOF/sm00
209   //                           ...
210   //                         TOF/sm17
211   //
212   for (Int_t isect = 0; isect < nSectors; isect++) {
213
214     volPath  = vpL0;
215     volPath += isect;
216     volPath += vpL1;
217     volPath += isect;
218     volPath += vpL2;
219
220     symName  = snSM;
221     symName += Form("%02d",isect);
222
223       AliDebug(2,"--------------------------------------------"); 
224       AliDebug(2,Form("Alignable object %d", isect+imod)); 
225       AliDebug(2,Form("volPath=%s\n",volPath.Data()));
226       AliDebug(2,Form("symName=%s\n",symName.Data()));
227       AliDebug(2,"--------------------------------------------"); 
228               
229     gGeoManager->SetAlignableEntry(symName.Data(),volPath.Data());
230
231   }
232   
233 }
234 //____________________________________________________________________________
235 void AliTOFv6T0::BuildGeometry()
236 {
237   //
238   // Build TOF ROOT geometry for the ALICE event display
239   //
240   TNode *node, *top;
241   const int kColorTOF  = 27;
242   
243   TGeometry *globalGeometry = (TGeometry*)gAlice->GetGeometry();
244
245   // Find top TNODE
246   top = globalGeometry->GetNode("alice");
247   
248   // Position the different copies
249   const Float_t krTof  =(fTOFGeometry->Rmax()+fTOFGeometry->Rmin())/2.;
250   const Float_t khTof  = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
251   const Int_t   kNTof  = fTOFGeometry->NSectors();
252   const Float_t kangle = k2PI/kNTof;
253
254   const Float_t kInterCentrModBorder1 = 49.5;
255   const Float_t kInterCentrModBorder2 = 57.5;
256
257   Float_t ang;
258   
259   // define offset for nodes
260   Float_t zOffsetB = (fTOFGeometry->ZlenA()*0.5 + (kInterCentrModBorder1+kInterCentrModBorder2)*0.5)*0.5;
261   Float_t zOffsetA = 0.;
262   // Define TOF basic volume
263   
264   char nodeName0[16], nodeName1[16], nodeName2[16];
265   char nodeName3[16], nodeName4[16], rotMatNum[16];
266
267   if (fTOFHoles) {
268     new TBRIK("S_TOF_B","TOF box","void",
269               fTOFGeometry->StripLength()*0.5, khTof*0.5, fTOFGeometry->ZlenB()*0.5);
270     new TBRIK("S_TOF_C","TOF box","void",
271               fTOFGeometry->StripLength()*0.5, khTof*0.5, fTOFGeometry->ZlenB()*0.5);
272   }
273   new TBRIK("S_TOF_A","TOF box","void",
274             fTOFGeometry->StripLength()*0.5, khTof*0.5, fTOFGeometry->ZlenA()*0.5);
275   
276   for (Int_t nodeNum=1;nodeNum<kNTof+1;nodeNum++){
277     
278     if (nodeNum<10) {
279       sprintf(rotMatNum,"rot50%i",nodeNum);
280       sprintf(nodeName0,"FTO00%i",nodeNum);
281       sprintf(nodeName1,"FTO10%i",nodeNum);
282       sprintf(nodeName2,"FTO20%i",nodeNum);
283       sprintf(nodeName3,"FTO30%i",nodeNum);
284       sprintf(nodeName4,"FTO40%i",nodeNum);
285     }
286     if (nodeNum>9) {
287       sprintf(rotMatNum,"rot5%i",nodeNum);
288       sprintf(nodeName0,"FTO0%i",nodeNum);
289       sprintf(nodeName1,"FTO1%i",nodeNum);
290       sprintf(nodeName2,"FTO2%i",nodeNum);
291       sprintf(nodeName3,"FTO3%i",nodeNum);
292       sprintf(nodeName4,"FTO4%i",nodeNum);
293     }
294     
295     new TRotMatrix(rotMatNum,rotMatNum,90,-20*nodeNum,90,90-20*nodeNum,0,0);
296     ang = (4.5-nodeNum) * kangle;
297
298     if (fTOFHoles) {   
299       top->cd();
300       node = new TNode(nodeName2,nodeName2,"S_TOF_B", krTof*TMath::Cos(ang), krTof*TMath::Sin(ang), zOffsetB,rotMatNum);
301       node->SetLineColor(kColorTOF);
302       fNodes->Add(node);
303       
304       top->cd();
305       node = new TNode(nodeName3,nodeName3,"S_TOF_C", krTof*TMath::Cos(ang), krTof*TMath::Sin(ang),-zOffsetB,rotMatNum);
306       node->SetLineColor(kColorTOF);
307       fNodes->Add(node);
308     }
309
310     top->cd();
311     node = new TNode(nodeName4,nodeName4,"S_TOF_A", krTof*TMath::Cos(ang), krTof*TMath::Sin(ang), zOffsetA,rotMatNum);
312     node->SetLineColor(kColorTOF);
313     fNodes->Add(node);
314   } // end loop on nodeNum
315
316 }
317
318 //_____________________________________________________________________________
319 void AliTOFv6T0::CreateGeometry()
320 {
321   //
322   // Create geometry for Time Of Flight version 0
323   //
324   //Begin_Html
325   /*
326     <img src="picts/AliTOFv6T0.gif">
327   */
328   //End_Html
329   //
330   // Creates common geometry
331   //
332   AliTOF::CreateGeometry();
333 }
334  
335
336 //_____________________________________________________________________________
337 void AliTOFv6T0::TOFpc(Float_t xtof, Float_t ytof, Float_t zlenA)
338 {
339   //
340   // Definition of the Time Of Fligh Resistive Plate Chambers
341   //
342
343   const Float_t kPi = TMath::Pi();
344
345   const Float_t kInterCentrModBorder1 = 49.5;
346   const Float_t kInterCentrModBorder2 = 57.5;
347   const Float_t kExterInterModBorder1 = 196.0;
348   const Float_t kExterInterModBorder2 = 203.5;
349
350   const Float_t kLengthExInModBorder  = 4.7;
351   const Float_t kLengthInCeModBorder  = 7.0;
352
353   // module wall thickness (cm)
354   const Float_t kModuleWallThickness = 0.33;
355
356   // honeycomb layer between strips and cards (cm)
357   const Float_t kHoneycombLayerThickness = 2.;
358
359   AliDebug(1, "************************* TOF geometry **************************");
360   AliDebug(1,Form(" xtof   %d",  xtof));
361   AliDebug(1,Form(" ytof   %d",  ytof));
362   AliDebug(1,Form(" zlenA   %d", zlenA));
363   AliDebug(2,Form(" zlenA*0.5 = %d", zlenA*0.5));
364   
365   // Definition of the of fibre glass modules (FTOA, FTOB and FTOC)
366     
367   Float_t  xcoor, ycoor, zcoor;
368   Float_t  par[3];
369   Int_t    *idtmed = fIdtmed->GetArray()-499;
370   Int_t    idrotm[100];
371
372   par[0] = xtof * 0.5;
373   par[1] = ytof * 0.25;
374   par[2] = zlenA * 0.5;
375   gMC->Gsvolu("FTOA", "BOX ", idtmed[503], par, 3);  // fibre glass
376    
377   if (fTOFHoles) {
378     par[0] =  xtof * 0.5;
379     par[1] =  ytof * 0.25;
380     par[2] = (zlenA*0.5 - kInterCentrModBorder1)*0.5;
381     gMC->Gsvolu("FTOB", "BOX ", idtmed[503], par, 3);  // fibre glass
382     gMC->Gsvolu("FTOC", "BOX ", idtmed[503], par, 3);  // fibre glass
383   }
384
385   // New supermodule card section description
386   //  2 cm  honeycomb layer between strips and cards
387   par[0] = xtof*0.5 + 2.;
388   par[1] = kHoneycombLayerThickness*0.5;
389   par[2] = zlenA*0.5 + 2.;
390   gMC->Gsvolu("FPEA", "BOX ", idtmed[506], par, 3);    // Al + Cu honeycomb
391   if (fTOFHoles) {
392     //par[0] = xtof*0.5 + 2.;
393     //par[1] = kHoneycombLayerThickness*0.5;
394     par[2] = (zlenA*0.5 - kInterCentrModBorder1)*0.5 + 2.;
395     gMC->Gsvolu("FPEB", "BOX ", idtmed[506], par, 3);  // Al + Cu honeycomb
396   }
397
398   // Definition of the air card containers (FAIA and FAIB)
399
400   par[0] = xtof*0.5;
401   par[1] = (ytof*0.5 - kHoneycombLayerThickness)*0.5;
402   par[2] = zlenA*0.5;
403   gMC->Gsvolu("FAIA", "BOX ", idtmed[500], par, 3);                // Air
404   if (fTOFHoles) gMC->Gsvolu("FAIB", "BOX ", idtmed[500], par, 3); // Air
405
406   // Positioning of fibre glass modules (FTOA, FTOB and FTOC) and
407   // card containers (FPEA, FAIA and FAIB)
408
409   //AliMatrix(idrotm[0], 90.,  0., 0., 0., 90.,-90.);
410   AliMatrix(idrotm[0], 90.,  0., 0., 0., 90.,270.);
411   xcoor = 0.;
412   for(Int_t isec=0; isec<fTOFGeometry->NSectors(); isec++){
413     if(fTOFSectors[isec]==-1)continue;
414     char name[16];
415     sprintf(name, "BTOF%d",isec);
416     if (fTOFHoles && (isec==11||isec==12)) {
417     //if (fTOFHoles && (isec==16||isec==17)) { \\Old 6h convention
418       //xcoor = 0.;
419       ycoor = (zlenA*0.5 + kInterCentrModBorder1)*0.5;
420       zcoor = -ytof * 0.25;
421       gMC->Gspos("FTOB", 0, name, xcoor, ycoor, zcoor, idrotm[0], "ONLY");
422       gMC->Gspos("FTOC", 0, name, xcoor,-ycoor, zcoor, idrotm[0], "ONLY");
423       //xcoor = 0.;
424       //ycoor = (zlenA*0.5 + kInterCentrModBorder1)*0.5;
425       zcoor = kHoneycombLayerThickness*0.5;
426       gMC->Gspos("FPEB", 1, name, xcoor, ycoor, zcoor, idrotm[0], "ONLY");
427       gMC->Gspos("FPEB", 2, name, xcoor,-ycoor, zcoor, idrotm[0], "ONLY");
428       //xcoor = 0.;
429       ycoor = 0.;
430       zcoor = kHoneycombLayerThickness + (ytof*0.5 - kHoneycombLayerThickness)*0.5;
431       gMC->Gspos("FAIB", 0, name, xcoor, ycoor, zcoor, idrotm[0], "ONLY");
432     }
433     else {
434       //xcoor = 0.;
435       ycoor = 0.;
436       zcoor = -ytof * 0.25;
437       gMC->Gspos("FTOA", 0, name, xcoor, ycoor, zcoor, idrotm[0], "ONLY");
438       //xcoor = 0.;
439       //ycoor = 0.;
440       zcoor = kHoneycombLayerThickness*0.5;
441       gMC->Gspos("FPEA", 0, name, xcoor, ycoor, zcoor, idrotm[0], "ONLY");
442       //xcoor = 0.;
443       //ycoor = 0.;
444       zcoor = kHoneycombLayerThickness + (ytof*0.5 - kHoneycombLayerThickness)*0.5;
445       gMC->Gspos("FAIA", 0, name, xcoor, ycoor, zcoor, idrotm[0], "ONLY");
446     }
447   }
448
449   // Definition and positioning
450   // of the not sensitive volumes with Insensitive Freon (FLTA, FLTB and FLTC)
451
452   Float_t xFLT, yFLT, zFLTA;
453   
454   xFLT  = xtof     - kModuleWallThickness*2.;
455   yFLT  = ytof*0.5 - kModuleWallThickness;
456   zFLTA = zlenA    - kModuleWallThickness*2.;
457   
458   par[0] = xFLT*0.5;
459   par[1] = yFLT*0.5;
460   par[2] = zFLTA*0.5;
461   gMC->Gsvolu("FLTA", "BOX ", idtmed[507], par, 3); //  Freon mix
462
463   xcoor = 0.;
464   ycoor = kModuleWallThickness*0.5;
465   zcoor = 0.;
466   gMC->Gspos ("FLTA", 0, "FTOA", xcoor, ycoor, zcoor, 0, "ONLY");
467
468   if (fTOFHoles) {
469     par[2] = (zlenA*0.5 - kInterCentrModBorder1 - kModuleWallThickness)*0.5;
470     gMC->Gsvolu("FLTB", "BOX ", idtmed[507], par, 3); // Freon mix
471     gMC->Gsvolu("FLTC", "BOX ", idtmed[507], par, 3); // Freon mix
472
473     //xcoor = 0.;
474     //ycoor = kModuleWallThickness*0.5;
475     //zcoor = 0.;
476     gMC->Gspos ("FLTB", 0, "FTOB", xcoor, ycoor, zcoor, 0, "ONLY");
477     gMC->Gspos ("FLTC", 0, "FTOC", xcoor, ycoor, zcoor, 0, "ONLY");
478   }
479
480   Float_t alpha, tgal, beta, tgbe, trpa[11];
481
482   // Definition and positioning
483   // of the fibre glass walls between central and intermediate modules (FWZ1 and FWZ2)
484
485   tgal = (yFLT - 2.*kLengthInCeModBorder)/(kInterCentrModBorder2 - kInterCentrModBorder1);
486   alpha = TMath::ATan(tgal);
487   beta = (kPi*0.5 - alpha)*0.5;
488   tgbe = TMath::Tan(beta);
489   trpa[0]  = xFLT*0.5;
490   trpa[1]  = 0.;
491   trpa[2]  = 0.;
492   trpa[3]  = kModuleWallThickness;
493   trpa[4]  = (kLengthInCeModBorder - kModuleWallThickness*tgbe)*0.5;
494   trpa[5]  = (kLengthInCeModBorder + kModuleWallThickness*tgbe)*0.5;
495   trpa[6]  = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
496   trpa[7]  = kModuleWallThickness;
497   trpa[8]  = (kLengthInCeModBorder - kModuleWallThickness*tgbe)*0.5;
498   trpa[9]  = (kLengthInCeModBorder + kModuleWallThickness*tgbe)*0.5;
499   trpa[10] = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
500   gMC->Gsvolu("FWZ1","TRAP", idtmed[503], trpa, 11);   // fibre glass
501
502   AliMatrix (idrotm[1],90., 90.,180.,0.,90.,180.);
503   AliMatrix (idrotm[4],90., 90.,  0.,0.,90.,  0.);
504
505   xcoor = 0.;
506   ycoor = -(yFLT - kLengthInCeModBorder)*0.5;
507   zcoor = kInterCentrModBorder1;
508   gMC->Gspos("FWZ1", 1,"FLTA", xcoor, ycoor, zcoor,idrotm[1],"ONLY");
509   gMC->Gspos("FWZ1", 2,"FLTA", xcoor, ycoor,-zcoor,idrotm[4],"ONLY");
510
511   AliMatrix (idrotm[2],90.,270.,  0.,0.,90.,180.);
512   AliMatrix (idrotm[5],90.,270.,180.,0.,90.,  0.);
513
514   xcoor = 0.;
515   ycoor = (yFLT - kLengthInCeModBorder)*0.5;
516   zcoor = kInterCentrModBorder2;
517   gMC->Gspos("FWZ1", 3,"FLTA", xcoor, ycoor, zcoor,idrotm[2],"ONLY");
518   gMC->Gspos("FWZ1", 4,"FLTA", xcoor, ycoor,-zcoor,idrotm[5],"ONLY");
519
520   trpa[0] = 0.5*(kInterCentrModBorder2 - kInterCentrModBorder1)/TMath::Cos(alpha);
521   trpa[1] = kModuleWallThickness;
522   trpa[2] = xFLT*0.5;
523   trpa[3] = -beta*kRaddeg;
524   trpa[4] = 0.;
525   trpa[5] = 0.;
526   gMC->Gsvolu("FWZ2","PARA", idtmed[503], trpa, 6);    // fibre glass
527
528   AliMatrix (idrotm[3],     alpha*kRaddeg,90.,90.+alpha*kRaddeg,90.,90.,180.);
529   AliMatrix (idrotm[6],180.-alpha*kRaddeg,90.,90.-alpha*kRaddeg,90.,90.,  0.);
530
531   xcoor = 0.;
532   ycoor = 0.;
533   zcoor = (kInterCentrModBorder2 + kInterCentrModBorder1)*0.5;
534   gMC->Gspos("FWZ2", 1,"FLTA", xcoor, ycoor, zcoor,idrotm[3],"ONLY");
535   gMC->Gspos("FWZ2", 2,"FLTA", xcoor, ycoor,-zcoor,idrotm[6],"ONLY");
536
537   // Definition and positioning
538   // of the fibre glass walls between intermediate and lateral modules (FWZ3 and FWZ4)
539
540   tgal = (yFLT - 2.*kLengthExInModBorder)/(kExterInterModBorder2 - kExterInterModBorder1);
541   alpha = TMath::ATan(tgal);
542   beta = (kPi*0.5 - alpha)*0.5;
543   tgbe = TMath::Tan(beta);
544   trpa[0]  = xFLT*0.5;
545   trpa[1]  = 0.;
546   trpa[2]  = 0.;
547   trpa[3]  = kModuleWallThickness;
548   trpa[4]  = (kLengthExInModBorder - kModuleWallThickness*tgbe)*0.5;
549   trpa[5]  = (kLengthExInModBorder + kModuleWallThickness*tgbe)*0.5;
550   trpa[6]  = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
551   trpa[7]  = kModuleWallThickness;
552   trpa[8]  = (kLengthExInModBorder - kModuleWallThickness*tgbe)*0.5;
553   trpa[9]  = (kLengthExInModBorder + kModuleWallThickness*tgbe)*0.5;
554   trpa[10] = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
555   gMC->Gsvolu("FWZ3","TRAP", idtmed[503], trpa, 11);    // fibre glass
556
557   xcoor = 0.;
558   ycoor = (yFLT - kLengthExInModBorder)*0.5;
559   zcoor = kExterInterModBorder1;
560   gMC->Gspos("FWZ3", 1,"FLTA", xcoor, ycoor, zcoor,idrotm[5],"ONLY");
561   gMC->Gspos("FWZ3", 2,"FLTA", xcoor, ycoor,-zcoor,idrotm[2],"ONLY");
562
563   if (fTOFHoles) {
564     //xcoor = 0.;
565     //ycoor = (yFLT - kLengthExInModBorder)*0.5;
566     zcoor = -kExterInterModBorder1 + (zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5;
567     gMC->Gspos("FWZ3", 5,"FLTB", xcoor, ycoor, zcoor,idrotm[2],"ONLY");
568     gMC->Gspos("FWZ3", 6,"FLTC", xcoor, ycoor,-zcoor,idrotm[5],"ONLY");
569   }
570
571   //xcoor = 0.;
572   ycoor = -(yFLT - kLengthExInModBorder)*0.5;
573   zcoor = kExterInterModBorder2;
574   gMC->Gspos("FWZ3", 3,"FLTA", xcoor, ycoor, zcoor,idrotm[4],"ONLY");
575   gMC->Gspos("FWZ3", 4,"FLTA", xcoor, ycoor,-zcoor,idrotm[1],"ONLY");
576
577   if (fTOFHoles) {
578     //xcoor = 0.;
579     //ycoor = -(yFLT - kLengthExInModBorder)*0.5;
580     zcoor = -kExterInterModBorder2 + (zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5;
581     gMC->Gspos("FWZ3", 7,"FLTB", xcoor, ycoor, zcoor,idrotm[1],"ONLY");
582     gMC->Gspos("FWZ3", 8,"FLTC", xcoor, ycoor,-zcoor,idrotm[4],"ONLY");
583   }
584
585   trpa[0] = 0.5*(kExterInterModBorder2 - kExterInterModBorder1)/TMath::Cos(alpha);
586   trpa[1] = kModuleWallThickness;
587   trpa[2] = xFLT*0.5;
588   trpa[3] = -beta*kRaddeg;
589   trpa[4] = 0.;
590   trpa[5] = 0.;
591   gMC->Gsvolu("FWZ4","PARA", idtmed[503], trpa, 6);    // fibre glass
592
593   AliMatrix (idrotm[13],alpha*kRaddeg,90.,90.+alpha*kRaddeg,90.,90.,180.);
594   AliMatrix (idrotm[16],180.-alpha*kRaddeg,90.,90.-alpha*kRaddeg,90.,90.,0.);
595
596   //xcoor = 0.;
597   ycoor = 0.;
598   zcoor = (kExterInterModBorder2 + kExterInterModBorder1)*0.5;
599   gMC->Gspos("FWZ4", 1,"FLTA", xcoor, ycoor, zcoor,idrotm[16],"ONLY");
600   gMC->Gspos("FWZ4", 2,"FLTA", xcoor, ycoor,-zcoor,idrotm[13],"ONLY");
601
602   if (fTOFHoles) {
603     //xcoor = 0.;
604     //ycoor = 0.;
605     zcoor = -(kExterInterModBorder2 + kExterInterModBorder1)*0.5 +
606       (zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5;
607     gMC->Gspos("FWZ4", 3,"FLTB", xcoor, ycoor, zcoor,idrotm[13],"ONLY");
608     gMC->Gspos("FWZ4", 4,"FLTC", xcoor, ycoor,-zcoor,idrotm[16],"ONLY");
609   }
610
611
612   ///////////////// Detector itself //////////////////////
613
614   const Int_t    knx   = fTOFGeometry->NpadX();  // number of pads along x
615   const Int_t    knz   = fTOFGeometry->NpadZ();  // number of pads along z
616   const Float_t  kPadX = fTOFGeometry->XPad();   // pad length along x
617   const Float_t  kPadZ = fTOFGeometry->ZPad();   // pad length along z
618
619   // new description for strip volume -double stack strip-
620   // -- all constants are expressed in cm
621   // heigth of different layers
622   const Float_t khhony   = 1.0;       // heigth of HONY  Layer
623   const Float_t khpcby   = 0.08;      // heigth of PCB   Layer
624   const Float_t khrgly   = 0.055;     // heigth of RED GLASS  Layer
625
626   const Float_t khfiliy  = 0.125;     // heigth of FISHLINE  Layer
627   const Float_t khglassy = 0.160*0.5; // heigth of GLASS  Layer
628   const Float_t khglfy   = khfiliy+2.*khglassy; // heigth of GLASS+FISHLINE  Layer
629
630   const Float_t khcpcby  = 0.16;      // heigth of PCB  Central Layer
631   const Float_t kwhonz   = 8.1;       // z dimension of HONEY  Layer
632   const Float_t kwpcbz1  = 10.6;      // z dimension of PCB  Lower Layer
633   const Float_t kwpcbz2  = 11.6;      // z dimension of PCB  Upper Layer
634   const Float_t kwcpcbz  = 13.;       // z dimension of PCB  Central Layer
635   const Float_t kwrglz   = 8.;        // z dimension of RED GLASS  Layer
636   const Float_t kwglfz   = 7.;        // z dimension of GLASS+FISHLN Layer
637   const Float_t klsensmx = knx*kPadX; // length of Sensitive Layer
638   const Float_t khsensmy = 0.05;      // heigth of Sensitive Layer
639   const Float_t kwsensmz = knz*kPadZ; // width of Sensitive Layer
640
641   // heigth of the FSTR Volume (the strip volume)
642   const Float_t khstripy = 2.*khhony+2.*khpcby+4.*khrgly+2.*khglfy+khcpcby;
643
644   // width  of the FSTR Volume (the strip volume)
645   const Float_t kwstripz = kwcpcbz;
646   // length of the FSTR Volume (the strip volume)
647   const Float_t klstripx = fTOFGeometry->StripLength();
648   
649   Float_t parfp[3]={klstripx*0.5, khstripy*0.5, kwstripz*0.5};
650   // Coordinates of the strip center in the strip reference frame;
651   // used for positioning internal strip volumes
652   Float_t posfp[3]={0.,0.,0.};
653
654   // FSTR volume definition-filling this volume with non sensitive Gas Mixture
655   gMC->Gsvolu("FSTR","BOX",idtmed[507],parfp,3); // Freon mix
656
657   //-- HONY Layer definition
658   //parfp[0] = klstripx*0.5;
659   parfp[1] = khhony*0.5;
660   parfp[2] = kwhonz*0.5;
661   gMC->Gsvolu("FHON","BOX",idtmed[501],parfp,3); // honeycomb (Nomex)
662   // positioning 2 HONY Layers on FSTR volume
663   //posfp[0] = 0.;
664   posfp[1] =-khstripy*0.5+parfp[1];
665   //posfp[2] = 0.;
666   gMC->Gspos("FHON",1,"FSTR",0., posfp[1],0.,0,"ONLY");
667   gMC->Gspos("FHON",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
668   
669   //-- PCB Layer definition
670   //parfp[0] = klstripx*0.5;
671   parfp[1] = khpcby*0.5;
672   parfp[2] = kwpcbz1*0.5;
673   gMC->Gsvolu("FPC1","BOX",idtmed[502],parfp,3); // G10
674   //parfp[0] = klstripx*0.5;
675   //parfp[1] = khpcby*0.5;
676   parfp[2] = kwpcbz2*0.5;
677   gMC->Gsvolu("FPC2","BOX",idtmed[502],parfp,3); // G10
678   // positioning 2 PCB Layers on FSTR volume
679   //posfp[0] = 0.;
680   posfp[1] =-khstripy*0.5+khhony+parfp[1];
681   //posfp[2] = 0.;
682   gMC->Gspos("FPC1",1,"FSTR",0.,-posfp[1],0.,0,"ONLY");
683   gMC->Gspos("FPC2",1,"FSTR",0., posfp[1],0.,0,"ONLY");
684
685   //-- central PCB layer definition
686   //parfp[0] = klstripx*0.5;
687   parfp[1] = khcpcby*0.5;
688   parfp[2] = kwcpcbz*0.5;
689   gMC->Gsvolu("FPCB","BOX",idtmed[502],parfp,3); // G10
690   // positioning the central PCB layer
691   gMC->Gspos("FPCB",1,"FSTR",0.,0.,0.,0,"ONLY");
692
693   //      Sensitive volume
694   Float_t parfs[3] = {klsensmx*0.5, khsensmy*0.5, kwsensmz*0.5};
695   gMC->Gsvolu("FSEN","BOX",idtmed[508],parfs,3); // sensitive
696   // dividing FSEN along z in knz=2 and along x in knx=48
697   gMC->Gsdvn("FSEZ","FSEN",knz,3);
698   gMC->Gsdvn("FPAD","FSEZ",knx,1);
699   // positioning a Sensitive layer inside FPCB
700   gMC->Gspos("FSEN",1,"FPCB",0.,0.,0.,0,"ONLY");
701
702   //-- RED GLASS Layer definition
703   //parfp[0] = klstripx*0.5;
704   parfp[1] = khrgly*0.5;
705   parfp[2] = kwrglz*0.5;
706   gMC->Gsvolu("FRGL","BOX",idtmed[509],parfp,3); // glass
707   // positioning 4 RED GLASS Layers on FSTR volume
708   //posfp[0] = 0.;
709   posfp[1] = -khstripy*0.5+khhony+khpcby+parfp[1];
710   //posfp[2] = 0.;
711   gMC->Gspos("FRGL",1,"FSTR",0., posfp[1],0.,0,"ONLY");
712   gMC->Gspos("FRGL",4,"FSTR",0.,-posfp[1],0.,0,"ONLY");
713   //posfp[0] = 0.;
714   posfp[1] = (khcpcby+khrgly)*0.5;
715   //posfp[2] = 0.;
716   gMC->Gspos("FRGL",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
717   gMC->Gspos("FRGL",3,"FSTR",0., posfp[1],0.,0,"ONLY");
718
719   //-- GLASS+FISHLINE Layer definition
720   //parfp[0] = klstripx*0.5;
721   parfp[1] = khglfy*0.5;
722   parfp[2] = kwglfz*0.5;
723   gMC->Gsvolu("FGLF","BOX",idtmed[504],parfp,3);
724
725   // positioning 2 GLASS+FISHLINE Layers on FSTR volume
726   //posfp[0] = 0.;
727   posfp[1] = (khcpcby + khglfy)*0.5 + khrgly;
728   //posfp[2] = 0.;
729   gMC->Gspos("FGLF",1,"FSTR",0.,-posfp[1],0.,0,"ONLY");
730   gMC->Gspos("FGLF",2,"FSTR",0., posfp[1],0.,0,"ONLY");
731
732   //  Positioning the Strips (FSTR volumes) in the FLT volumes
733   Int_t maxStripNumbers [5] ={fTOFGeometry->NStripC(),
734                               fTOFGeometry->NStripB(),
735                               fTOFGeometry->NStripA(),
736                               fTOFGeometry->NStripB(),
737                               fTOFGeometry->NStripC()};
738
739   Int_t totalStrip = 0;
740   Float_t xpos, zpos, ypos, ang;
741   for(Int_t iplate = 0; iplate < fTOFGeometry->NPlates(); iplate++){
742     if (iplate>0) totalStrip += maxStripNumbers[iplate-1];
743     for(Int_t istrip = 0; istrip < maxStripNumbers[iplate]; istrip++){
744
745       ang = fTOFGeometry->GetAngles(iplate,istrip);
746       AliDebug(1, Form(" iplate = %1i, istrip = %2i ---> ang = %f", iplate, istrip, ang));
747  
748       if (ang>0.)       AliMatrix (idrotm[istrip+totalStrip+1],90.,0.,90.+ang,90., ang, 90.);
749       else if (ang==0.) AliMatrix (idrotm[istrip+totalStrip+1],90.,0.,90.,90., 0., 0.);
750       else if (ang<0.)  AliMatrix (idrotm[istrip+totalStrip+1],90.,0.,90.+ang,90.,-ang,270.);
751
752       xpos = 0.;
753       zpos = fTOFGeometry->GetDistances(iplate,istrip);
754       ypos = fTOFGeometry->GetHeights(iplate,istrip) + yFLT*0.5;
755
756       gMC->Gspos("FSTR",istrip+totalStrip+1,"FLTA", xpos, ypos,-zpos,idrotm[istrip+totalStrip+1],  "ONLY");
757
758       if (fTOFHoles) {
759         if (istrip+totalStrip+1>53)
760           gMC->Gspos("FSTR",istrip+totalStrip+1,"FLTC", xpos, ypos,-zpos-(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[istrip+totalStrip+1],"ONLY");
761         if (istrip+totalStrip+1<39)
762           gMC->Gspos("FSTR",istrip+totalStrip+1,"FLTB", xpos, ypos,-zpos+(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[istrip+totalStrip+1],"ONLY");
763       }
764     }
765   }
766
767   // Definition of the cards, cooling tubes and layer for thermal dispersion
768   // (3 volumes)
769
770   // card volume definition
771   Float_t carpar[3] = {9.5, 5.75, 0.5};
772   gMC->Gsvolu("FCA1", "BOX ", idtmed[514], carpar, 3);   // PCB+Alu small Card 
773   carpar[0] = 19.25;
774   //carpar[1] =  5.75;
775   //carpar[2] =  0.5;
776   gMC->Gsvolu("FCA2", "BOX ", idtmed[514], carpar, 3);   // PCB+Alu long Card 
777
778   // tube volume definition
779   Float_t tubepar[3] = {0., 0.4, xFLT*0.5-15.};
780   gMC->Gsvolu("FTUB", "TUBE", idtmed[513], tubepar, 3);  // copper cooling tubes
781   //tubepar[0]= 0.;
782   tubepar[1]= 0.3;
783   //tubepar[2]= xFLT*0.5 - 15.;
784   gMC->Gsvolu("FITU", "TUBE", idtmed[510], tubepar, 3);  // cooling water
785   // Positioning of the water tube into the steel one
786   gMC->Gspos("FITU",1,"FTUB",0.,0.,0.,0,"ONLY");
787
788   // cable
789   Float_t cbpar[3] = {0., 0.5, tubepar[2]};
790   gMC->Gsvolu("FCAB", "TUBE", idtmed[511], cbpar, 3);    // copper+alu
791
792   // Alluminium components
793   Float_t lonpar[3] = {tubepar[2], 6.15, 0.7};
794   gMC->Gsvolu("FTLN", "BOX ", idtmed[505], lonpar, 3);   // alluminium
795   lonpar[0] = 2.;
796   lonpar[1] = 1.;
797   lonpar[2] = zlenA*0.5;
798   gMC->Gsvolu("FLON", "BOX ", idtmed[505], lonpar, 3);   // alluminium
799
800   // rotation matrix
801   AliMatrix(idrotm[99], 180., 90., 90., 90., 90., 0.);
802
803   // cards, tubes, cables  positioning
804   Float_t carpos[3], rowstep = 6.66, ytub= 3.65, ycab= ytub-3.;
805   Float_t rowgap[5] = {13.5, 22.9, 16.94, 23.8, 20.4};
806   Int_t row, rowb[5] = {6, 7, 6, 19, 7}, nrow;
807   carpos[0] = 25. - xtof*0.5;
808   carpos[1] = (11.5 - (ytof*0.5 - kHoneycombLayerThickness))*0.5;
809   row = 1;
810   for (Int_t sg= -1; sg< 2; sg+= 2) {
811     carpos[2] = sg*zlenA*0.5;
812     for (Int_t nb=0; nb<5; ++nb) {
813       carpos[2] = carpos[2] - sg*(rowgap[nb] - rowstep);
814       nrow = row + rowb[nb];
815       for ( ; row < nrow ; ++row) {
816         carpos[2] -= sg*rowstep;
817         gMC->Gspos("FCA1",2*row-1, "FAIA", carpos[0],carpos[1],carpos[2], 0,"ONLY");
818         gMC->Gspos("FCA1",  2*row, "FAIA",-carpos[0],carpos[1],carpos[2], 0,"ONLY");
819         gMC->Gspos("FCA2", row, "FAIA", 0., carpos[1], carpos[2], 0, "ONLY");
820         gMC->Gspos("FTUB", row, "FAIA", 0., ytub, carpos[2]-sg, idrotm[99], "ONLY");
821         gMC->Gspos("FCAB", row, "FAIA", 0., ycab, carpos[2]-sg, idrotm[99], "ONLY");
822       }
823     }
824     gMC->Gspos("FTLN", 5+4*sg, "FAIA", 0., -0.1, 369.9*sg, 0, "ONLY");
825     gMC->Gspos("FTLN", 5+3*sg, "FAIA", 0., -0.1, 366.9*sg, 0, "ONLY");
826     gMC->Gspos("FTLN", 5+2*sg, "FAIA", 0., -0.1, 198.8*sg, 0, "ONLY");
827     gMC->Gspos("FTLN",   5+sg, "FAIA", 0., -0.1, 56.82*sg, 0, "ONLY");
828   }
829   gMC->Gspos("FCA1", 181, "FAIA", carpos[0],carpos[1],0., 0,"ONLY");
830   gMC->Gspos("FCA1", 182, "FAIA",-carpos[0],carpos[1],0., 0,"ONLY");
831   gMC->Gspos("FCA2",  91, "FAIA",  0., carpos[1], 0., 0, "ONLY");
832   gMC->Gspos("FTUB",  91, "FAIA",  0., ytub, 1., idrotm[99], "ONLY");
833   gMC->Gspos("FCAB",  91, "FAIA",  0., ycab, 1., idrotm[99], "ONLY");
834   gMC->Gspos("FLON",   1, "FAIA",-24., ytub+1.4, 0., 0, "MANY");
835   gMC->Gspos("FLON",   2, "FAIA", 24., ytub+1.4, 0., 0, "MANY");
836   if (fTOFHoles) {
837     row = 1;
838     for (Int_t sg= -1; sg< 2; sg+= 2) {
839       carpos[2] = sg*zlenA*0.5;
840       for (Int_t nb=0; nb<4; ++nb) {
841         carpos[2] = carpos[2] - sg*(rowgap[nb] - rowstep);
842         nrow = row + rowb[nb];
843         for ( ; row < nrow ; ++row) {
844           carpos[2] -= sg*rowstep;
845           gMC->Gspos("FCA1",2*row-1, "FAIB", carpos[0],carpos[1],carpos[2], 0,"ONLY");
846           gMC->Gspos("FCA1",  2*row, "FAIB",-carpos[0],carpos[1],carpos[2], 0,"ONLY");
847           gMC->Gspos("FCA2", row, "FAIB", 0., carpos[1], carpos[2], 0, "ONLY");
848           gMC->Gspos("FTUB", row, "FAIB", 0., ytub,carpos[2]-sg, idrotm[99], "ONLY");
849           gMC->Gspos("FCAB", row, "FAIB", 0., ycab,carpos[2]-sg, idrotm[99], "ONLY");
850         }
851       }
852       gMC->Gspos("FTLN", 5+4*sg, "FAIB", 0., -0.1, 369.9*sg, 0, "ONLY");
853       gMC->Gspos("FTLN", 5+3*sg, "FAIB", 0., -0.1, 366.9*sg, 0, "ONLY");
854       gMC->Gspos("FTLN", 5+2*sg, "FAIB", 0., -0.1, 198.8*sg, 0, "ONLY");
855       gMC->Gspos("FTLN",   5+sg, "FAIB", 0., -0.1, 56.82*sg, 0, "ONLY");
856     }
857   gMC->Gspos("FLON", 1, "FAIB",-24., ytub+1.4, 0., 0, "MANY");
858   gMC->Gspos("FLON", 2, "FAIB", 24., ytub+1.4, 0., 0, "MANY");
859   }
860
861   // Cables and tubes on the side blocks
862   const Float_t kcbll   = zlenA*0.5; // length of block
863   const Float_t kcbllh  = zlenA*0.5 - kInterCentrModBorder2; // length  of block in case of hole
864   const Float_t kcblw   = 13.5;      // width of block
865   const Float_t kcblh1  = 2.;        // min. heigth of block
866   const Float_t kcblh2  = 12.3;      // max. heigth of block
867   // volume definition
868   Float_t cblpar[11];
869   tgal =  (kcblh2 - kcblh1)/(2.*kcbll);
870   cblpar[0] = kcblw *0.5;
871   cblpar[1] = 0.;
872   cblpar[2] = 0.;
873   cblpar[3] = kcbll *0.5;
874   cblpar[4] = kcblh1 *0.5;
875   cblpar[5] = kcblh2 *0.5;
876   cblpar[6] = TMath::ATan(tgal)*kRaddeg;
877   cblpar[7] = kcbll *0.5;
878   cblpar[8] = kcblh1 *0.5;
879   cblpar[9] = kcblh2 *0.5;
880   cblpar[10]= cblpar[6];
881   gMC->Gsvolu("FCBL", "TRAP", idtmed[512], cblpar, 11); // cables & tubes mix 
882   Float_t sawpar[3] = {0.5, kcblh2*0.5, kcbll};
883   gMC->Gsvolu("FSAW", "BOX ", idtmed[505], sawpar,  3); // Side Al walls
884   // volume positioning
885   AliMatrix(idrotm[7], 90., 90., 180., 0., 90., 180.);
886   AliMatrix(idrotm[8], 90., 90., 0., 0., 90., 0.);
887   xcoor = (xtof-kcblw)*0.5 - 2.*sawpar[0];
888   ycoor = (kcblh1+kcblh2)*0.25 - (ytof*0.5 - kHoneycombLayerThickness)*0.5;
889   zcoor = kcbll*0.5;
890   gMC->Gspos("FCBL", 1, "FAIA", -xcoor, ycoor, -zcoor, idrotm[7], "ONLY");
891   gMC->Gspos("FCBL", 2, "FAIA",  xcoor, ycoor, -zcoor, idrotm[7], "ONLY");
892   gMC->Gspos("FCBL", 3, "FAIA", -xcoor, ycoor,  zcoor, idrotm[8], "ONLY");
893   gMC->Gspos("FCBL", 4, "FAIA",  xcoor, ycoor,  zcoor, idrotm[8], "ONLY");
894   xcoor = xtof*0.5-sawpar[0];
895   ycoor = (kcblh2 - ytof*0.5 + kHoneycombLayerThickness)*0.5;
896   gMC->Gspos("FSAW", 1, "FAIA", -xcoor, ycoor, 0., 0, "ONLY");
897   gMC->Gspos("FSAW", 2, "FAIA",  xcoor, ycoor, 0., 0, "ONLY");
898   if (fTOFHoles) {
899     cblpar[3] = kcbllh *0.5;
900     cblpar[5] = kcblh1*0.5 + kcbllh*tgal;
901     cblpar[7] = kcbllh *0.5;
902     cblpar[9] = cblpar[5];
903     gMC->Gsvolu("FCBB", "TRAP", idtmed[512], cblpar, 11); // cables & tubes mix
904     xcoor = (xtof - kcblw)*0.5 - 2.*sawpar[0];
905     ycoor = (kcblh1 + 2.*cblpar[5])*0.25 - (ytof*0.5 - kHoneycombLayerThickness)*0.5;
906     zcoor = kcbll-kcbllh*0.5;
907     gMC->Gspos("FCBB", 1, "FAIB", -xcoor, ycoor, -zcoor, idrotm[7], "ONLY");
908     gMC->Gspos("FCBB", 2, "FAIB",  xcoor, ycoor, -zcoor, idrotm[7], "ONLY");
909     gMC->Gspos("FCBB", 3, "FAIB", -xcoor, ycoor,  zcoor, idrotm[8], "ONLY");
910     gMC->Gspos("FCBB", 4, "FAIB",  xcoor, ycoor,  zcoor, idrotm[8], "ONLY");
911     xcoor = xtof*0.5 - sawpar[0];
912     ycoor = (kcblh2 - ytof*0.5 + kHoneycombLayerThickness)*0.5;
913     gMC->Gspos("FSAW", 1, "FAIB", -xcoor, ycoor, 0., 0, "ONLY");
914     gMC->Gspos("FSAW", 2, "FAIB",  xcoor, ycoor, 0., 0, "ONLY");
915   }
916
917   // TOF Supermodule cover definition and positioning
918   Float_t covpar[3] = {xtof*0.5, 0.1, zlenA*0.5};
919   gMC->Gsvolu("FCOV", "BOX ", idtmed[505], covpar, 3);    // Al cover
920   xcoor = 0.;
921   ycoor = 12.5*0.5 - 0.1;
922   zcoor = 0.;
923   gMC->Gspos("FCOV", 0, "FAIA", xcoor, ycoor, zcoor, 0, "ONLY");
924   if (fTOFHoles) gMC->Gspos("FCOV", 0, "FAIB", xcoor, ycoor, zcoor, 0, "ONLY");
925
926   // Services Volumes
927
928   // Empty crate weight: 50 Kg, electronics cards + cables ~ 52 Kg.
929   // Per each side (A and C) the total weight is: 2x102 ~ 204 Kg.
930   // ... + weight of the connection pannel for the steel cooling system (Cr 18%, Ni 12%, Fe 70%)
931   // + other remaining elements + various supports
932
933   // Each FEA card weight + all supports
934   // (including all bolts and not including the cable connectors)
935   //  353.1 g.
936   // Per each strip there are 4 FEA cards, then
937   // the total weight of the front-end electonics section is: 353.1 g x 4 = 1412.4 g.
938
939   Float_t serpar[3] = {29.*0.5, 121.*0.5, 90.*0.5};
940   gMC->Gsvolu("FTOS", "BOX ", idtmed[515], serpar, 3); // Al + Cu + steel
941   zcoor = (118.-90.)*0.5;
942   Float_t phi = -10.,  ra = fTOFGeometry->Rmin() + ytof*0.5;
943   for (Int_t i = 0; i < fTOFGeometry->NSectors(); i++) {
944     phi += 20.;
945     xcoor = ra * TMath::Cos(phi * kDegrad);
946     ycoor = ra * TMath::Sin(phi * kDegrad);
947     AliMatrix(idrotm[20+i], 90., phi, 90., phi + 270., 0., 0.);
948     gMC->Gspos("FTOS", i, "BFMO", xcoor, ycoor, zcoor, idrotm[20+i], "ONLY");      
949   }
950   zcoor = (90. - 223.)*0.5;
951   gMC->Gspos("FTOS", 1, "BBCE", ra, 0., zcoor, 0, "ONLY");
952
953 }
954 //_____________________________________________________________________________
955 void AliTOFv6T0::DrawModule() const
956 {
957   //
958   // Draw a shaded view of the Time Of Flight version 5
959   //
960
961   // Set everything unseen
962   gMC->Gsatt("*", "seen", -1);
963
964   //
965   //Set volumes visible
966   // 
967
968   //Set ALIC mother transparent
969   gMC->Gsatt("ALIC","SEEN", 0);
970
971 //=====> Level 1
972   // Level 1 for TOF volumes
973   gMC->Gsatt("B077","seen", 0);
974
975 //=====> Level 2
976   // Level 2 for TOF volumes
977   gMC->Gsatt("B071","seen", 0);
978   gMC->Gsatt("B074","seen", 0);
979   gMC->Gsatt("B075","seen", 0);
980   gMC->Gsatt("B076","seen",-1); // all B076 sub-levels skipped -
981   gMC->Gsatt("B080","seen", 0);  // B080 does not has sub-level                
982
983   // Level 2 of B071
984   gMC->Gsatt("B056","seen", 0);  // B056 does not has sub-levels  -
985   gMC->Gsatt("B063","seen",-1); // all B063 sub-levels skipped   -
986   gMC->Gsatt("B065","seen",-1); // all B065 sub-levels skipped   -
987   gMC->Gsatt("B067","seen",-1); // all B067 sub-levels skipped   -
988   gMC->Gsatt("B072","seen",-1); // all B072 sub-levels skipped   -
989
990   char name[16];
991   for (Int_t isec=0; isec<fTOFGeometry->NSectors(); isec++) {
992     sprintf(name, "BREF%d",isec);
993     gMC->Gsatt(name,"seen", 0);  // all BREF%d sub-levels skipped   -
994     sprintf(name, "BTRD%d",isec);
995     gMC->Gsatt(name,"seen", 0);  // all BTRD%d sub-levels skipped   -
996     sprintf(name, "BTOF%d",isec);
997     gMC->Gsatt(name,"seen",-2);  // all BTOF%d sub-levels skipped   -
998   }
999
1000   gMC->Gdopt("hide", "on");
1001   gMC->Gdopt("shad", "on");
1002   gMC->Gsatt("*", "fill", 7);
1003   gMC->SetClipBox(".");
1004   gMC->SetClipBox("*", 100, 1000, 100, 1000, 100, 1000);
1005   gMC->DefaultRange();
1006   gMC->Gdraw("alic", 40, 30, 0, 10, 9.5, .018, .018);
1007   gMC->Gdhead(1111, "Time Of Flight");
1008   gMC->Gdman(18, 3, "MAN");
1009   gMC->Gdopt("hide","off");
1010 }
1011 //_____________________________________________________________________________
1012 void AliTOFv6T0::DrawDetectorModules() const
1013 {
1014   //
1015   // Draw a shaded view of the TOF detector SuperModules version 5
1016   //
1017  
1018   // Set everything unseen
1019   gMC->Gsatt("*", "seen", -1);
1020
1021   //
1022   //Set volumes visible
1023   // 
1024
1025   //Set ALIC mother transparent
1026   gMC->Gsatt("ALIC","SEEN", 0);
1027
1028 //=====> Level 1
1029   // Level 1 for TOF volumes
1030   gMC->Gsatt("B077","seen", 0);
1031
1032 //=====> Level 2
1033   // Level 2 for TOF volumes
1034   gMC->Gsatt("B071","seen", 0);
1035   gMC->Gsatt("B074","seen", 0);
1036   gMC->Gsatt("B075","seen", 0);
1037   gMC->Gsatt("B076","seen",-1); // all B076 sub-levels skipped -
1038   gMC->Gsatt("B080","seen", 0);  // B080 does not has sub-level                
1039
1040   // Level 2 of B071
1041   gMC->Gsatt("B056","seen", 0);  // B056 does not has sub-levels  -
1042   gMC->Gsatt("B063","seen",-1); // all B063 sub-levels skipped   -
1043   gMC->Gsatt("B065","seen",-1); // all B065 sub-levels skipped   -
1044   gMC->Gsatt("B067","seen",-1); // all B067 sub-levels skipped   -
1045   gMC->Gsatt("B072","seen",-1); // all B072 sub-levels skipped   -
1046
1047   char name[16];
1048   for (Int_t isec=0; isec<fTOFGeometry->NSectors(); isec++) {
1049     sprintf(name, "BREF%d",isec);
1050     gMC->Gsatt(name,"seen", 0);  // all BREF%d sub-levels skipped   -
1051     sprintf(name, "BTRD%d",isec);
1052     gMC->Gsatt(name,"seen", 0);  // all BTRD%d sub-levels skipped   -
1053     sprintf(name, "BTOF%d",isec);
1054     gMC->Gsatt(name,"seen", 0);  // all BTOF%d sub-levels skipped   -
1055   }
1056
1057   // Level 3 of B071, B075 and B074
1058   gMC->Gsatt("FTOA","seen",-2);  // all FTOA sub-levels skipped   -
1059   if (fTOFHoles) gMC->Gsatt("FTOB","seen",-2);  // all FTOB sub-levels skipped   -
1060   if (fTOFHoles) gMC->Gsatt("FTOC","seen",-2);  // all FTOC sub-levels skipped   -
1061
1062   // Level 3 of B071, B075 and B074
1063   gMC->Gsatt("FAIA","seen",-1);  // all FAIA sub-levels skipped   -
1064   if (fTOFHoles) gMC->Gsatt("FAIB","seen",-1);  // all FAIB sub-levels skipped   -
1065
1066   // Level 3 of B071, B075 and B074
1067   gMC->Gsatt("FPEA","seen",1);  // all FPEA sub-levels skipped   -
1068   if (fTOFHoles) gMC->Gsatt("FPEB","seen",1);  // all FPEB sub-levels skipped   -
1069
1070   gMC->Gdopt("hide","on");
1071   gMC->Gdopt("shad","on");
1072   gMC->Gsatt("*", "fill", 5);
1073   gMC->SetClipBox(".");
1074   gMC->SetClipBox("*", 100, 1000, 100, 1000, 0, 1000);
1075   gMC->DefaultRange();
1076   gMC->Gdraw("alic", 40, 30, 0, 10, 9.5, .018, .018);
1077   gMC->Gdhead(1111,"TOF detector");
1078   gMC->Gdman(18, 3, "MAN");
1079   gMC->Gdopt("hide","off");
1080 }                                 
1081
1082 //_____________________________________________________________________________
1083 void AliTOFv6T0::DrawDetectorStrips() const
1084 {
1085   //
1086   // Draw a shaded view of the TOF strips for version 5
1087   //
1088
1089   // Set everything unseen
1090   gMC->Gsatt("*", "seen", -1);
1091
1092   //
1093   //Set volumes visible
1094   // 
1095   
1096   //Set ALIC mother transparent
1097   gMC->Gsatt("ALIC","SEEN", 0);
1098   
1099 //=====> Level 1
1100   // Level 1 for TOF volumes
1101   gMC->Gsatt("B077","seen", 0);
1102
1103 //=====> Level 2
1104   // Level 2 for TOF volumes
1105   gMC->Gsatt("B071","seen", 0);
1106   gMC->Gsatt("B074","seen", 0);
1107   gMC->Gsatt("B075","seen", 0);
1108   gMC->Gsatt("B076","seen",-1); // all B076 sub-levels skipped -
1109   gMC->Gsatt("B080","seen", 0);  // B080 does not has sub-level                
1110
1111   // Level 2 of B071
1112   gMC->Gsatt("B063","seen",-1); // all B063 sub-levels skipped   -
1113   gMC->Gsatt("B065","seen",-1); // all B065 sub-levels skipped   -
1114   gMC->Gsatt("B067","seen",-1); // all B067 sub-levels skipped   -
1115   gMC->Gsatt("B056","seen", 0);  // B056 does not has sub-levels  -
1116   gMC->Gsatt("B072","seen",-1); // all B072 sub-levels skipped   -
1117
1118   char name[16];
1119   for (Int_t isec=0; isec<fTOFGeometry->NSectors(); isec++) {
1120     sprintf(name, "BREF%d",isec);
1121     gMC->Gsatt(name,"seen", 0);  // all BREF%d sub-levels skipped   -
1122     sprintf(name, "BTRD%d",isec);
1123     gMC->Gsatt(name,"seen", 0);  // all BTRD%d sub-levels skipped   -
1124     sprintf(name, "BTOF%d",isec);
1125     gMC->Gsatt(name,"seen", 0);  // all BTOF%d sub-levels skipped   -
1126   }
1127
1128   // Level 3 of B071, B074 and B075
1129   gMC->Gsatt("FTOA","SEEN", 0);
1130   if (fTOFHoles) gMC->Gsatt("FTOB","SEEN", 0);
1131   if (fTOFHoles) gMC->Gsatt("FTOC","SEEN", 0);
1132
1133   // Level 4 of B071, B074 and B075
1134   gMC->Gsatt("FLTA","SEEN", 0);
1135   if (fTOFHoles) gMC->Gsatt("FLTB","SEEN", 0);
1136   if (fTOFHoles) gMC->Gsatt("FLTC","SEEN", 0);
1137
1138   // Level 5 of B071, B074 and B075
1139   gMC->Gsatt("FAIA","SEEN", 0);
1140   if (fTOFHoles) gMC->Gsatt("FAIB","SEEN", 0);
1141
1142   gMC->Gsatt("FPEA","SEEN", 1);
1143   if (fTOFHoles) gMC->Gsatt("FPEB","SEEN", 1);
1144
1145   gMC->Gsatt("FSTR","SEEN",-2);  // all FSTR sub-levels skipped   -
1146
1147   gMC->Gsatt("FWZ1","SEEN", 1);
1148   gMC->Gsatt("FWZ2","SEEN", 1);
1149   gMC->Gsatt("FWZ3","SEEN", 1);
1150   gMC->Gsatt("FWZ4","SEEN", 1);
1151
1152
1153   // Level 2 of FAIA
1154   // Level 2 of FAIB
1155   gMC->Gsatt("FCA1","SEEN", 0);
1156   gMC->Gsatt("FCA2","SEEN", 0);
1157   gMC->Gsatt("FCAB","SEEN", 0);
1158   gMC->Gsatt("FTUB","SEEN",-1);  // all FTUB sub-levels skipped   -
1159   gMC->Gsatt("FTLN","SEEN", 0);
1160   gMC->Gsatt("FLTN","SEEN", 0);
1161   gMC->Gsatt("FCBL","SEEN", 0);
1162   gMC->Gsatt("FSAW","SEEN", 0);
1163   gMC->Gsatt("FCOV","SEEN", 0);
1164   if (fTOFHoles) gMC->Gsatt("FCBB","SEEN", 0);
1165
1166   // Level 2 of FTUB
1167   gMC->Gsatt("FITU","SEEN", 0);
1168
1169   // Level 2 of FSTR
1170   gMC->Gsatt("FHON","SEEN", 1);
1171   gMC->Gsatt("FPC1","SEEN", 1);
1172   gMC->Gsatt("FPC2","SEEN", 1);
1173   gMC->Gsatt("FPCB","SEEN", 1);
1174   gMC->Gsatt("FRGL","SEEN", 1);
1175   gMC->Gsatt("FGLF","SEEN", 1);
1176
1177   // Level 2 of FPCB => Level 3 of FSTR
1178   gMC->Gsatt("FSEN","SEEN", 0);
1179   gMC->Gsatt("FSEZ","SEEN", 0);
1180   gMC->Gsatt("FPAD","SEEN", 1);
1181
1182   gMC->Gdopt("hide","on");
1183   gMC->Gdopt("shad","on");
1184   gMC->Gsatt("*", "fill", 5);
1185   gMC->SetClipBox(".");
1186   gMC->SetClipBox("*", 0, 1000, 0, 1000, 0, 1000);
1187   gMC->DefaultRange();
1188   gMC->Gdraw("alic", 40, 30, 0, 10, 9.5, .018, .018);
1189   gMC->Gdhead(1111,"TOF Strips");
1190   gMC->Gdman(18, 3, "MAN");
1191   gMC->Gdopt("hide","off");
1192 }
1193
1194 //_____________________________________________________________________________
1195 void AliTOFv6T0::CreateMaterials()
1196 {
1197   //
1198   // Define materials for the Time Of Flight
1199   //
1200
1201   //AliTOF::CreateMaterials();
1202
1203   AliMagF *magneticField = (AliMagF*)gAlice->Field();
1204
1205   Int_t   isxfld = magneticField->Integ();
1206   Float_t sxmgmx = magneticField->Max();
1207
1208   Float_t we[7], na[7];
1209
1210   //--- Quartz (SiO2) to simulate float glass
1211   //    density tuned to have correct float glass 
1212   //    radiation length
1213   Float_t   aq[2] = { 28.09,16. };
1214   Float_t   zq[2] = { 14.,8. };
1215   Float_t   wq[2] = { 1.,2. };
1216   //Float_t   dq = 2.55; // std value: 2.2
1217   Float_t   dq = 2.7;    // (+5.9%)
1218   Int_t nq = -2;
1219
1220   // --- Nomex
1221   Float_t anox[4] = {12.01,1.01,16.00,14.01};
1222   Float_t znox[4] = { 6.,  1.,  8.,  7.};
1223   Float_t wnox[4] = {14., 22., 2., 2.};
1224   //Float_t dnox  = 0.048; //old value
1225   Float_t dnox  = 0.22;    // (x 4.6)
1226   Int_t nnox   = -4;
1227
1228   // --- glass+freon { Si, O, C, F, H, S }
1229   Float_t agfr[6]= {28.09,16.00,12.01,19.00,1.01,32.065};
1230   Float_t zgfr[6]= {14.,  8.,  6.,  9.,  1.,  16.};
1231   Float_t wgfr[6]= {0.465, 0.530, 0.000484, 0.00383, 4.0e-05, 0.000646};
1232   Int_t ngfr  = 6;
1233   AliDebug(1,Form("wgfr: %d  %d  %d  %d  %d %d", wgfr[0], wgfr[1], wgfr[2], wgfr[3], wgfr[4], wgfr[5]));
1234   //Float_t dgfr = 1.35; // + FISHLINE (old value)
1235   Float_t dgfr = 1.6;    // + FISHLINE(+18.5 %)
1236
1237   // --- G10  {Si, O, C, H, O}
1238   Float_t ag10[5] = {28.09,16.00,12.01,1.01,16.00};
1239   Float_t zg10[5] = {14., 8., 6., 1., 8.};
1240   Float_t wmatg10[5];
1241   Int_t nlmatg10 = 5;
1242   na[0]= 1. ,   na[1]= 2. ,   na[2]= 0. ,   na[3]= 0. ,   na[4]= 0.;
1243   MaterialMixer(we,ag10,na,5);
1244   wmatg10[0]= we[0]*0.6;
1245   wmatg10[1]= we[1]*0.6;
1246   na[0]= 0. ,   na[1]= 0. ,   na[2]= 14. ,   na[3]= 20. ,   na[4]= 3.;
1247   MaterialMixer(we,ag10,na,5);
1248   wmatg10[2]= we[2]*0.4;
1249   wmatg10[3]= we[3]*0.4;
1250   wmatg10[4]= we[4]*0.4;
1251   AliDebug(1,Form("wg10  %d  %d  %d  %d  %d", wmatg10[0], wmatg10[1], wmatg10[2], wmatg10[3], wmatg10[4]));
1252   //  Float_t densg10 = 1.7; //old value
1253   Float_t densg10 = 2.0; // (+17.8%)
1254
1255   // -- Water
1256   Float_t awa[2] = {  1., 16. };
1257   Float_t zwa[2] = {  1.,  8. };
1258   Float_t wwa[2] = {  2.,  1. };
1259   Float_t dwa    = 1.0;
1260   Int_t nwa = -2;
1261
1262   // AIR
1263   Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
1264   Float_t zAir[4]={6.,7.,8.,18.};
1265   Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
1266   Float_t dAir   = 1.20479E-3;
1267
1268   // --- fibre glass
1269   Float_t afg[4] = {28.09,16.00,12.01,1.01};
1270   Float_t zfg[4] = {14., 8., 6., 1.};
1271   Float_t wfg[4] = {0.12906,0.29405,0.51502,0.06187};
1272   //Float_t dfg    = 1.111;
1273   Float_t dfg    = 2.; // (+1.8%)
1274   Int_t nfg      = 4;
1275
1276   // --- Freon C2F4H2 + SF6
1277   Float_t afre[4]= {12.01,1.01,19.00,32.07};
1278   Float_t zfre[4]= { 6., 1., 9., 16.};
1279   Float_t wfre[4]= {0.21250,0.01787,0.74827,0.021355};
1280   Float_t densfre= 0.00375;
1281   Int_t nfre     = 4;
1282
1283   // --- Al + Cu + G10  {Al, Cu, Si, O, C, H, O}
1284   Float_t acar[7]= {26.98,63.55,28.09,16.00,12.01,1.01,16.00};
1285   Float_t zcar[7]= {13., 29., 14., 8., 6., 1., 8.};
1286   Float_t wcar[7];
1287   wcar[0]= 0.7;
1288   wcar[1]= 0.05;
1289   wcar[2]= 0.25*wmatg10[0];
1290   wcar[3]= 0.25*wmatg10[1];
1291   wcar[4]= 0.25*wmatg10[2];
1292   wcar[5]= 0.25*wmatg10[3];
1293   wcar[6]= 0.25*wmatg10[4];
1294   AliDebug(1,Form("wcar  %d  %d  %d  %d  %d  %d  %d", wcar[0], wcar[1], wcar[2], wcar[3], wcar[4], wcar[5], wcar[6]));
1295   Float_t dcar= 1.9;
1296
1297   // --- Cables, tubes {Al, Cu} ---
1298   Float_t acbt[2]= {26.98,63.55};
1299   Float_t zcbt[2]= {13., 29.};
1300   //Float_t wcbt[2]= {0.541,0.459};
1301   Float_t wcbt[2]= {0.407,0.593};
1302   //Float_t decbt  = 0.95;
1303   Float_t decbt  = 0.68;
1304
1305   // --- Cable {Al, Cu}
1306   Float_t wcb[2] = {0.165,0.835};
1307   Float_t decb   = 0.962;
1308
1309   // --- Honeycomb layer {Al, Cu}
1310   Float_t whon[2]= {0.9,0.1};
1311   //Float_t dhon   = 0.44;
1312   Float_t dhon   = 1.095; // (x 2.56)
1313
1314   // --- Crates boxes {Al, Cu, Fe, Cr, Ni}
1315   Float_t acra[5]= {26.98,63.55,55.845,52.00,58.69};
1316   Float_t zcra[5]= {13., 29., 26., 24., 28.};
1317   Float_t wcra[5]= {0.7,0.2,0.07,0.018,0.012};
1318   Float_t dcra   = 0.77;
1319
1320   AliMixture ( 0, "Air$", aAir, zAir, dAir, 4, wAir);
1321   AliMixture ( 1, "Nomex$", anox, znox, dnox, nnox, wnox);
1322   AliMixture ( 2, "G10$", ag10, zg10, densg10, nlmatg10, wmatg10);
1323   AliMixture ( 3, "fibre glass$", afg, zfg, dfg, nfg, wfg);
1324   AliMaterial( 4, "Al $", 26.98, 13., 2.7, 8.9, 37.2);
1325   AliMixture ( 5, "Al+Cu honeycomb$", acbt, zcbt, dhon, 2, whon);
1326   AliMixture ( 6, "Freon$", afre, zfre, densfre, nfre, wfre);
1327   AliMixture ( 7, "Glass$", aq, zq, dq, nq, wq);
1328   AliMixture ( 8, "glass-freon$", agfr, zgfr, dgfr, ngfr, wgfr);
1329   AliMixture ( 9, "Water$",  awa, zwa, dwa, nwa, wwa);
1330   AliMixture (10, "Al+Cu$", acbt, zcbt, decbt, 2, wcbt);
1331   AliMaterial(11, "Cu $", 63.54, 29., 3.392, 1.43, 10.);
1332   AliMixture (12, "Al+Cu (cable)$", acbt, zcbt, decb, 2, wcb);
1333   AliMixture (13, "Al+Cu+G10$", acar, zcar, dcar, 7, wcar);
1334   AliMixture (14, "Al+Cu+steel$", acra, zcra, dcra, 5, wcra);
1335
1336   Float_t epsil, stmin, deemax, stemax;
1337
1338   //   STD data
1339   //  EPSIL  = 0.1   ! Tracking precision,
1340   //  STEMAX = 0.1   ! Maximum displacement for multiple scattering
1341   //  DEEMAX = 0.1   ! Maximum fractional energy loss, DLS
1342   //  STMIN  = 0.1
1343
1344   // TOF data
1345   epsil  = .001;  // Tracking precision,
1346   stemax = -1.;   // Maximum displacement for multiple scattering
1347   deemax = -.3;   // Maximum fractional energy loss, DLS
1348   stmin  = -.8;
1349
1350   AliMedium( 1, "Air$",         0, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1351   AliMedium( 2,"Nomex$",        1, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1352   AliMedium( 3,"G10$",          2, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1353   AliMedium( 4,"fibre glass$",  3, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1354   AliMedium( 5,"glass-freon$",  8, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1355   AliMedium( 6,"Al Frame$",     4, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1356   AliMedium( 7,"honeycomb$",    5, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1357   AliMedium( 8,"Fre$",          6, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1358   AliMedium( 9,"Cu-S$",        11, 1, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1359   AliMedium(10,"Glass$",        7, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1360   AliMedium(11,"Water$",        9, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1361   AliMedium(12,"Cable$",       12, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1362   AliMedium(13,"Al+Cables$",   10, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1363   AliMedium(14,"Copper$",      11, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1364   AliMedium(15,"Cards$",       13, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1365   AliMedium(16,"Crates$",      14, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
1366
1367 }
1368 //_____________________________________________________________________________
1369 void AliTOFv6T0::Init()
1370 {
1371   //
1372   // Initialise the detector after the geometry has been defined
1373   //
1374   AliDebug(1, "**************************************"
1375            "  TOF  "
1376            "**************************************");
1377   AliDebug(1, "  Version 4 of TOF initialing, "
1378            "symmetric TOF - Full Coverage version");
1379   
1380   AliTOF::Init();
1381   
1382   fIdFTOA = gMC->VolId("FTOA");
1383   if (fTOFHoles) {
1384     fIdFTOB = gMC->VolId("FTOB");
1385     fIdFTOC = gMC->VolId("FTOC");
1386   }
1387   fIdFLTA = gMC->VolId("FLTA");
1388   if (fTOFHoles) {
1389     fIdFLTB = gMC->VolId("FLTB");
1390     fIdFLTC = gMC->VolId("FLTC");
1391   }
1392
1393   AliDebug(1, "**************************************"
1394            "  TOF  "
1395            "**************************************");
1396 }
1397  
1398 //_____________________________________________________________________________
1399 void AliTOFv6T0::StepManager()
1400 {
1401
1402   //
1403   // Procedure called at each step in the Time Of Flight
1404   //
1405
1406   TLorentzVector mom, pos;
1407   Float_t xm[3],pm[3],xpad[3],ppad[3];
1408   Float_t hits[14];
1409   Int_t   vol[5];
1410   Int_t   sector, plate, padx, padz, strip;
1411   Int_t   copy, padzid, padxid, stripid, i;
1412   Int_t   *idtmed = fIdtmed->GetArray()-499;
1413   Float_t incidenceAngle;
1414
1415   const char* volpath;
1416
1417   Int_t index = 0;
1418
1419   if(
1420      gMC->IsTrackEntering()
1421      && gMC->TrackCharge()
1422      //&& gMC->GetMedium()==idtmed[508]
1423      && gMC->CurrentMedium()==idtmed[508]
1424      && gMC->CurrentVolID(copy)==fIdSens
1425      )
1426   {
1427
1428     AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
1429
1430     AddTrackReference(mcApplication->GetCurrentTrackNumber());
1431     //AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
1432
1433     // getting information about hit volumes
1434     
1435     padzid=gMC->CurrentVolOffID(1,copy);
1436     padz=copy;
1437     padz--;
1438
1439     padxid=gMC->CurrentVolOffID(0,copy);
1440     padx=copy; 
1441     padx--;
1442     
1443     stripid=gMC->CurrentVolOffID(4,copy);
1444     strip=copy; 
1445     strip--;
1446
1447     gMC->TrackPosition(pos);
1448     gMC->TrackMomentum(mom);
1449
1450     Double_t normMom=1./mom.Rho();
1451
1452     //  getting the coordinates in pad ref system
1453
1454     xm[0] = (Float_t)pos.X();
1455     xm[1] = (Float_t)pos.Y();
1456     xm[2] = (Float_t)pos.Z();
1457
1458     pm[0] = (Float_t)mom.X()*normMom;
1459     pm[1] = (Float_t)mom.Y()*normMom;
1460     pm[2] = (Float_t)mom.Z()*normMom;
1461  
1462     gMC->Gmtod(xm,xpad,1); // from MRS to DRS: coordinates convertion
1463     gMC->Gmtod(pm,ppad,2); // from MRS to DRS: direction cosinus convertion
1464
1465
1466     if (TMath::Abs(ppad[1])>1) {
1467       AliWarning("Abs(ppad) > 1");
1468       ppad[1]=TMath::Sign((Float_t)1,ppad[1]);
1469     }
1470     incidenceAngle = TMath::ACos(ppad[1])*kRaddeg;
1471
1472     plate = -1;
1473     if      (strip <  fTOFGeometry->NStripC()) {
1474       plate = 0;
1475       //strip = strip;
1476     }
1477     else if (strip >= fTOFGeometry->NStripC() && 
1478              strip <  fTOFGeometry->NStripC() + fTOFGeometry->NStripB()) {
1479       plate = 1;
1480       strip = strip - fTOFGeometry->NStripC();
1481     }
1482     else if (strip >= fTOFGeometry->NStripC() + fTOFGeometry->NStripB() &&
1483              strip <  fTOFGeometry->NStripC() + fTOFGeometry->NStripB() + fTOFGeometry->NStripA()) {
1484       plate = 2;
1485       strip = strip - fTOFGeometry->NStripC() - fTOFGeometry->NStripB();
1486     }
1487     else if (strip >= fTOFGeometry->NStripC() + fTOFGeometry->NStripB() + fTOFGeometry->NStripA() &&
1488              strip <  fTOFGeometry->NStripC() + fTOFGeometry->NStripB() + fTOFGeometry->NStripA() + fTOFGeometry->NStripB()) {
1489       plate = 3;
1490       strip = strip - fTOFGeometry->NStripC() - fTOFGeometry->NStripB() - fTOFGeometry->NStripA();
1491     }
1492     else                                {
1493       plate = 4;
1494       strip = strip - fTOFGeometry->NStripC() - fTOFGeometry->NStripB() - fTOFGeometry->NStripA() - fTOFGeometry->NStripB();
1495     }
1496
1497     volpath=gMC->CurrentVolOffName(7);
1498     index=atoi(&volpath[4]);
1499     sector=-1;
1500     sector=index;
1501
1502     //Old 6h convention
1503     // if(index<5){
1504     //   sector=index+13;
1505     //  }
1506     // else{
1507     //   sector=index-5;
1508     // } 
1509  
1510     for(i=0;i<3;++i) {
1511       hits[i]   = pos[i];
1512       hits[i+3] = pm[i];
1513     }
1514
1515     hits[6] = mom.Rho();
1516     hits[7] = pos[3];
1517     hits[8] = xpad[0];
1518     hits[9] = xpad[1];
1519     hits[10]= xpad[2];
1520     hits[11]= incidenceAngle;
1521     hits[12]= gMC->Edep();
1522     hits[13]= gMC->TrackLength();
1523     
1524     vol[0]= sector;
1525     vol[1]= plate;
1526     vol[2]= strip;
1527     vol[3]= padx;
1528     vol[4]= padz;    
1529
1530     AddT0Hit(mcApplication->GetCurrentTrackNumber(),vol, hits);
1531     //AddT0Hit(gAlice->GetMCApp()->GetCurrentTrackNumber(),vol, hits);
1532   }
1533 }
1534 //-------------------------------------------------------------------
1535 void AliTOFv6T0::MaterialMixer(Float_t* p,Float_t* a,Float_t* m,Int_t n) const
1536 {
1537   // a[] atomic weights vector      (in)
1538   //     (atoms present in more compound appear separately)
1539   // m[] number of corresponding atoms in the compound  (in)
1540   Float_t t = 0.;
1541   for (Int_t i = 0; i < n; ++i) {
1542     p[i] = a[i]*m[i];
1543     t  += p[i];
1544   }
1545   for (Int_t i = 0; i < n; ++i) {
1546     p[i] = p[i]/t;
1547     //AliDebug(1,Form((\n weight[%i] = %f (,i,p[i]));
1548   }
1549 }