]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFv3.cxx
Added protections against using the wrong version of FRAME
[u/mrichter/AliRoot.git] / TOF / AliTOFv3.cxx
index a7d05b1dd26bfe38cacefbfd7cb8fa1b65da245b..49b26faad59b85ecd35dadc22b07a662bd6db4a9 100644 (file)
@@ -1,27 +1,68 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/*
+$Log$
+Revision 1.11  1999/10/22 08:04:14  fca
+Correct improper use of negative parameters
+
+Revision 1.10  1999/10/16 19:30:06  fca
+Corrected Rotation Matrix and CVS log
+
+Revision 1.9  1999/10/15 15:35:20  fca
+New version for frame1099 with and without holes
+
+Revision 1.8  1999/09/29 09:24:33  fca
+Introduction of the Copyright and cvs Log
+
+*/
+
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
-//  Time Of Flight                                                           //
-//  This class contains the functions for version 3 of the Time Of Flight    //
+//  Time Of Flight: design of C.Williams                FCA                  //
+//  This class contains the functions for version 1 of the Time Of Flight    //
 //  detector.                                                                //
-//                                                                           //
+//
+//  VERSION WITH 5 MODULES AND TILTED STRIPS 
+//  
+//   FULL COVERAGE VERSION
+//
+//   Authors:
+//
+//   Alessio Seganti
+//   Domenico Vicinanza
+//
+//   University of Salerno - Italy
+//
+//
 //Begin_Html
 /*
-<img src="gif/AliTOFv3Class.gif">
+<img src="picts/AliTOFv3Class.gif">
 */
 //End_Html
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "AliTOFv3.h"
-#include <TNode.h>
-#include <TTUBE.h>
 #include "AliRun.h"
-#include "AliMC.h"
+#include "AliConst.h"
  
 ClassImp(AliTOFv3)
  
 //_____________________________________________________________________________
-AliTOFv3::AliTOFv3() : AliTOF()
+AliTOFv3::AliTOFv3()
 {
   //
   // Default constructor
@@ -41,237 +82,389 @@ AliTOFv3::AliTOFv3(const char *name, const char *title)
 void AliTOFv3::CreateGeometry()
 {
   //
-  // Create geometry for Time Of Flight version 2
+  // Create geometry for Time Of Flight version 0
   //
   //Begin_Html
   /*
-    <img src="gif/AliTOFv3.gif">
+    <img src="picts/AliTOFv3.gif">
   */
   //End_Html
   //
-
-  //
-  // Create common geometry between version 2 and 3
+  // Creates common geometry
   //
   AliTOF::CreateGeometry();
 }
  
 //_____________________________________________________________________________
-void AliTOFv3::TOFpc(Float_t xm, Float_t ym, Float_t zm0,
-                    Float_t zm1, Float_t zm2)
+void AliTOFv3::TOFpc(Float_t xtof, Float_t ytof, Float_t zlen1,
+                    Float_t zlen2, Float_t zlen3, Float_t ztof0)
 {
   //
-  // Definition of the Time Of Fligh Parallel Plate Chambers
-  //
-
-  AliMC* pMC = AliMC::GetMC();
+  // Definition of the Time Of Fligh Resistive Plate Chambers
+  // xFLT, yFLT, zFLT - sizes of TOF modules (large)
   
-  Int_t inum;
-  Float_t xcor, zcor, ytop;
-  Int_t inum1;
-  Float_t xcor1, xcor2, ycoor;
-  Float_t stepx, stepz, dx, dy, dz, xp, yp, zp, shiftx, shiftz, ywidth;
-  Float_t shiftx1, shiftx2, xad, zad;
-  Int_t ink;
+  Float_t  ycoor, zcoor;
   Float_t par[10];
-  Int_t inz;
-  Float_t xzd;
-  Int_t nxp, npx, npz;
-  Float_t xsz, ysz, zsz;
-  Int_t nzp0, nzp1, nzp2;
   
-  Int_t *idtmed = gAlice->Idtmed();
+  Int_t *idtmed = fIdtmed->GetArray()-499;
+
+  Int_t idrotm[100];
+  Int_t nrot = 0;
   
-  // X size of PPC plate 
-  xsz = 54.;
-  // Y size of PPC plate 
-  ysz = .2;
-  // Z size of PPC plate 
-  zsz = 48.;
-  // First return additional shift along X 
-  xad = 1.5;
-  // Second return additional shift along X 
-  xzd = .5;
-  // Return additional shift along Z 
-  zad = .25;
-  // Width of DME box 
-  ywidth = 4.;
-  // X size of PPC chamber 
-  xp = 5.7;
-  // Y size of PPC chamber 
-  yp = .32;
-  // Z size of PPC chamber 
-  zp = 5.7;
-  // Frame width along X,Y and Z axis of PPC chambers 
-  dx = .2;
-  dy = .1;
-  dz = .2;
-  // No sensitive volumes with DME 
-  par[0] = xm / 2.;
-  par[1] = ywidth / 2.;
-  par[2] = zm0 / 2.;
-  ycoor = ym / 3. - ywidth / 2.;
-  pMC->Gsvolu("FBT1", "BOX ", idtmed[505], par, 3);
-  pMC->Gspos("FBT1", 0, "FTO1", 0., 0., 0., 0, "ONLY");
-  par[2] = zm1 / 2.;
-  pMC->Gsvolu("FBT2", "BOX ", idtmed[505], par, 3);
-  pMC->Gspos("FBT2", 1, "FTO2", 0., 0., 0., 0, "ONLY");
-  par[2] = zm2 / 2.;
-  pMC->Gsvolu("FBT3", "BOX ", idtmed[505], par, 3);
-  pMC->Gspos("FBT3", 2, "FTO3", 0., 0., 0., 0, "ONLY");
-  // Electronic plate 
-  par[1] = ysz / 2.;
-  par[2] = zm0 / 2.;
-  ycoor = ywidth / 2. - ysz / 2.;
-  pMC->Gsvolu("FPE1", "BOX ", idtmed[504], par, 3);
-  pMC->Gspos("FPE1", 0, "FBT1", 0., ycoor, 0., 0, "ONLY");
-  pMC->Gspos("FPE1", 1, "FBT1", 0., -ycoor, 0., 0, "ONLY");
-  par[2] = zm1 / 2.;
-  pMC->Gsvolu("FPE2", "BOX ", idtmed[504], par, 3);
-  pMC->Gspos("FPE2", 0, "FBT2", 0., ycoor, 0., 0, "ONLY");
-  pMC->Gspos("FPE2", 1, "FBT2", 0., -ycoor, 0., 0, "ONLY");
-  par[2] = zm2 / 2.;
-  pMC->Gsvolu("FPE3", "BOX ", idtmed[504], par, 3);
-  pMC->Gspos("FPE3", 0, "FBT3", 0., ycoor, 0., 0, "ONLY");
-  pMC->Gspos("FPE3", 1, "FBT3", 0., -ycoor, 0., 0, "ONLY");
-  // Electronic insensitive volumes 
-  par[1] = yp / 2.;
-  par[2] = zm0 / 2.;
-  ytop = ywidth / 2. - (ysz * 2 + yp) / 2.;
-  pMC->Gsvolu("FST1", "BOX ", idtmed[505], par, 3);
-  pMC->Gsvolu("FLT1", "BOX ", idtmed[505], par, 3);
-  pMC->Gspos("FST1", 0, "FBT1", 0., ytop, 0., 0, "ONLY");
-  pMC->Gspos("FLT1", 0, "FBT1", 0., -ytop, 0., 0, "ONLY");
-  par[2] = zm1 / 2.;
-  pMC->Gsvolu("FST2", "BOX ", idtmed[505], par, 3);
-  pMC->Gsvolu("FLT2", "BOX ", idtmed[505], par, 3);
-  pMC->Gspos("FST2", 0, "FBT2", 0., ytop, 0., 0, "ONLY");
-  pMC->Gspos("FLT2", 0, "FBT2", 0., -ytop, 0., 0, "ONLY");
-  par[2] = zm2 / 2.;
-  pMC->Gsvolu("FST3", "BOX ", idtmed[505], par, 3);
-  pMC->Gsvolu("FLT3", "BOX ", idtmed[505], par, 3);
-  pMC->Gspos("FST3", 0, "FBT3", 0., ytop, 0., 0, "ONLY");
-  pMC->Gspos("FLT3", 0, "FBT3", 0., -ytop, 0., 0, "ONLY");
-  // PPC-plate number along X axis 
-  nxp = Int_t (xm / xsz);
-  // PPC-plate number along Z axis 
-  nzp0 = Int_t (zm0 / zsz);
-  nzp1 = Int_t (zm1 / zsz);
-  nzp2 = Int_t (zm2 / zsz);
-  // Position of big PPC-plate 
-  par[0] = xm * .5 / nxp;
-  par[2] = zm0 * .5 / nzp0;
-  pMC->Gsvolu("FSK1", "BOX ", idtmed[505], par, 3);
-  pMC->Gsvolu("FLK1", "BOX ", idtmed[505], par, 3);
-  inum = 0;
-  for (ink = 1; ink <= nxp; ++ink) {
-    xcor = xm * .5 * ((ink * 2 - 1) / (Float_t) nxp - 1.);
-    for (inz = 1; inz <= nzp0; ++inz) {
-      zcor = zm0 * .5 * ((inz * 2 - 1) / (Float_t) nzp0 - 1.);
-      ++inum;
-      pMC->Gspos("FSK1", inum, "FST1", xcor, 0., zcor, 0, "ONLY");
-      pMC->Gspos("FLK1", inum, "FLT1", xcor, 0., zcor, 0, "ONLY");
-    }
-    for (inz = 1; inz <= nzp1; ++inz) {
-      zcor = zm1 * .5 * ((inz * 2 - 1) / (Float_t) nzp1 - 1.);
-      ++inum;
-      pMC->Gspos("FSK1", inum, "FST2", xcor, 0., zcor, 0, "ONLY");
-      pMC->Gspos("FLK1", inum, "FLT2", xcor, 0., zcor, 0, "ONLY");
-    }
-    for (inz = 1; inz <= nzp2; ++inz) {
-      zcor = zm2 * .5 * ((inz * 2 - 1) / (Float_t) nzp2 - 1.);
-      ++inum;
-      pMC->Gspos("FSK1", inum, "FST3", xcor, 0., zcor, 0, "ONLY");
-      pMC->Gspos("FLK1", inum, "FLT3", xcor, 0., zcor, 0, "ONLY");
-    }
-  }
-  par[0] = xsz / 2.;
-  par[1] = yp / 2.;
-  par[2] = zsz / 2.;
-  pMC->Gsvolu("FSL1", "BOX ", idtmed[505], par, 3);
-  pMC->Gsvolu("FLL1", "BOX ", idtmed[505], par, 3);
-  shiftx = (xp / 2. + xad / 2.) / 2.;
-  shiftz = (zm0 / nzp0 - zsz) / 2.;
-  pMC->Gspos("FSL1", 0, "FSK1", -shiftx, 0., -shiftz, 0, "ONLY");
-  pMC->Gspos("FLL1", 0, "FLK1", shiftx, 0., shiftz, 0, "ONLY");
-  // PPC position on PPC-plate 
-  npx = 4;
-  npz = 8;
-  par[0] = xp / 2.;
-  par[1] = yp / 2.;
-  par[2] = zp / 2.;
-  stepx = (xad + xzd + xp * 2) / 2.;
-  stepz = (zp + zad) / 2.;
-  shiftz = npz * (zad + zp) / 2.;
-  shiftx = npx * (xp * 2 + xad + xzd) / 2.;
-  shiftx1 = (xp * 2 + xzd + xad) / 2. - xp / 2.;
-  shiftx2 = (xp * 2 + xzd + xad) / 2. - xp / 2. - xzd;
-  pMC->Gsvolu("FPG1", "BOX ", idtmed[507], par, 3);
-  for (ink = 1; ink <= npx; ++ink) {
-    xcor1 = -shiftx + stepx * (ink * 2 - 1) - shiftx1;
-    xcor2 = -shiftx + stepx * (ink * 2 - 1) + shiftx2;
-    for (inz = 1; inz <= npz; ++inz) {
-      zcor = -shiftz + stepz * (inz * 2 - 1);
-      ++inum;
-      inum1 = npx * npz + inum;
-      pMC->Gspos("FPG1", inum, "FSL1", xcor1, 0., zcor, 0, "ONLY");
-      pMC->Gspos("FPG1", inum1, "FSL1", xcor2, 0., zcor, 0, "ONLY");
-      pMC->Gspos("FPG1", inum, "FLL1", xcor1, 0., zcor, 0, "ONLY");
-      pMC->Gspos("FPG1", inum1, "FLL1", xcor2, 0., zcor, 0, "ONLY");
-    }
-  }
-  par[0] = xp / 2. - dx;
-  par[1] = yp / 2. - dy;
-  par[2] = zp / 2. - dz;
-  pMC->Gsvolu("FPG2", "BOX ", idtmed[509], par, 3);
-  pMC->Gspos("FPG2", 0, "FPG1", 0., 0., 0., 0, "ONLY");
+
+
+  par[0] =  xtof / 2.;
+  par[1] =  ytof / 2.;
+  par[2] = zlen1 / 2.;
+  gMC->Gsvolu("FTO1", "BOX ", idtmed[506], par, 3);
+  par[2] = zlen2 / 2.;
+  gMC->Gsvolu("FTO2", "BOX ", idtmed[506], par, 3);
+  par[2] = zlen3 / 2.;
+  gMC->Gsvolu("FTO3", "BOX ", idtmed[506], par, 3);
+
+
+// Positioning of modules
+
+   Float_t zcor1 = ztof0 - zlen1/2;
+   Float_t zcor2 = ztof0 - zlen1 - zlen2/2.;
+   Float_t zcor3 = 0.;
+
+   AliMatrix(idrotm[0], 90., 0., 0., 0., 90, -90.);
+   AliMatrix(idrotm[1], 90., 180., 0., 0., 90, 90.);
+   gMC->Gspos("FTO1", 1, "BTO1", 0,  zcor1, 0, idrotm[0], "ONLY");
+   gMC->Gspos("FTO1", 2, "BTO1", 0, -zcor1, 0, idrotm[1], "ONLY");
+   gMC->Gspos("FTO1", 1, "BTO2", 0,  zcor1, 0, idrotm[0], "ONLY");
+   gMC->Gspos("FTO1", 2, "BTO2", 0, -zcor1, 0, idrotm[1], "ONLY");
+   gMC->Gspos("FTO1", 1, "BTO3", 0,  zcor1, 0, idrotm[0], "ONLY");
+   gMC->Gspos("FTO1", 2, "BTO3", 0, -zcor1, 0, idrotm[1], "ONLY");
+
+   gMC->Gspos("FTO2", 1, "BTO1", 0,  zcor2, 0, idrotm[0], "ONLY");
+   gMC->Gspos("FTO2", 2, "BTO1", 0, -zcor2, 0, idrotm[1], "ONLY");
+   gMC->Gspos("FTO2", 1, "BTO2", 0,  zcor2, 0, idrotm[0], "ONLY");
+   gMC->Gspos("FTO2", 2, "BTO2", 0, -zcor2, 0, idrotm[1], "ONLY");
+   gMC->Gspos("FTO2", 1, "BTO3", 0,  zcor2, 0, idrotm[0], "ONLY");
+   gMC->Gspos("FTO2", 2, "BTO3", 0, -zcor2, 0, idrotm[1], "ONLY");
+
+   gMC->Gspos("FTO3", 0, "BTO1", 0, zcor3,  0, idrotm[0], "ONLY");
+   gMC->Gspos("FTO3", 0, "BTO2", 0, zcor3,  0, idrotm[0], "ONLY");
+   gMC->Gspos("FTO3", 0, "BTO3", 0, zcor3,  0, idrotm[0], "ONLY");
+
+// Subtraction the distance to TOF module boundaries 
+
+  Float_t db = 7.;
+  Float_t xFLT, yFLT, zFLT1, zFLT2, zFLT3;
+
+  xFLT = xtof -(.5 +.5)*2;
+  yFLT = ytof;
+  zFLT1 = zlen1 - db;
+  zFLT2 = zlen2 - db;
+  zFLT3 = zlen3 - db;
+
+// Sizes of MRPC pads
+
+  Float_t yPad = 0.505; 
+  
+// Large not sensitive volumes with CO2 
+  par[0] = xFLT/2;
+  par[1] = yFLT/2;
+
+  cout <<"************************* TOF geometry **************************"<<endl;
+
+  par[2] = (zFLT1 / 2.);
+  gMC->Gsvolu("FLT1", "BOX ", idtmed[506], par, 3); // CO2
+  gMC->Gspos("FLT1", 0, "FTO1", 0., 0., 0., 0, "ONLY");
+
+  par[2] = (zFLT2 / 2.);
+  gMC->Gsvolu("FLT2", "BOX ", idtmed[506], par, 3); // CO2
+  gMC->Gspos("FLT2", 0, "FTO2", 0., 0., 0., 0, "ONLY");
+
+  par[2] = (zFLT3 / 2.); 
+  gMC->Gsvolu("FLT3", "BOX ", idtmed[506], par, 3); // CO2
+  gMC->Gspos("FLT3", 0, "FTO3", 0., 0., 0., 0, "ONLY");
+
+////////// Layers before detector ////////////////////
+
+// Alluminium layer in front 1.0 mm thick at the beginning
+  par[0] = -1;
+  par[1] = 0.1;
+  par[2] = -1;
+  ycoor = -yFLT/2 + par[1];
+  gMC->Gsvolu("FMY1", "BOX ", idtmed[508], par, 3); // Alluminium
+  gMC->Gspos("FMY1", 0, "FLT1", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FMY2", "BOX ", idtmed[508], par, 3); // Alluminium
+  gMC->Gspos("FMY2", 0, "FLT2", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FMY3", "BOX ", idtmed[508], par, 3); // Alluminium 
+  gMC->Gspos("FMY3", 0, "FLT3", 0., ycoor, 0., 0, "ONLY");
+
+// Honeycomb layer (1cm of special polyethilene)
+  ycoor = ycoor + par[1];
+  par[0] = -1;
+  par[1] = 0.5;
+  par[2] = -1;
+  ycoor = ycoor + par[1];
+  gMC->Gsvolu("FPL1", "BOX ", idtmed[503], par, 3); // Hony
+  gMC->Gspos("FPL1", 0, "FLT1", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FPL2", "BOX ", idtmed[503], par, 3); // Hony
+  gMC->Gspos("FPL2", 0, "FLT2", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FPL3", "BOX ", idtmed[503], par, 3); // Hony
+  gMC->Gspos("FPL3", 0, "FLT3", 0., ycoor, 0., 0, "ONLY");
+
+///////////////// Detector itself //////////////////////
+
+  const Float_t StripWidth = 7.81;//cm
+  const Float_t DeadBound = 1.;//cm non-sensitive between the pad edge and the boundary of the strip
+  const Int_t nx = 40; // number of pads along x
+  const Int_t nz = 2;  // number of pads along z
+  const Float_t Gap=4.; //cm  distance between the strip axis
+  const Float_t Space = 5.5; //cm distance from the front plate of the box
+
+  Float_t zSenStrip;
+  zSenStrip = StripWidth-2*DeadBound;//cm
+
+  par[0] = xFLT/2;
+  par[1] = yPad/2; 
+  par[2] = StripWidth/2.;
+  
+  // Glass Layer of detector
+  gMC->Gsvolu("FSTR","BOX",idtmed[514],par,3);
+
+  // Freon for non-sesitive boundaries
+  par[0] = xFLT/2;
+  par[1] = 0.110/2;
+  par[2] = -1;
+  gMC->Gsvolu("FNSF","BOX",idtmed[512],par,3);
+  gMC->Gspos("FNSF",0,"FSTR",0.,0.,0.,0,"ONLY");
+  // Mylar for non-sesitive boundaries
+  par[1] = 0.025;
+  gMC->Gsvolu("FMYI","BOX",idtmed[510],par,3); 
+  gMC->Gspos("FMYI",0,"FNSF",0.,0.,0.,0,"ONLY");
+
+  // Mylar for outer layers
+  par[1] = 0.035/2;
+  ycoor = -yPad/2.+par[1];
+  gMC->Gsvolu("FMYX","BOX",idtmed[510],par,3);
+  gMC->Gspos("FMYX",1,"FSTR",0.,ycoor,0.,0,"ONLY");
+  gMC->Gspos("FMYX",2,"FSTR",0.,-ycoor,0.,0,"ONLY");
+  ycoor += par[1];
+  // Graphyte layers
+  par[1] = 0.003/2;
+  ycoor += par[1];
+  gMC->Gsvolu("FGRL","BOX",idtmed[502],par,3);
+  gMC->Gspos("FGRL",1,"FSTR",0.,ycoor,0.,0,"ONLY");
+  gMC->Gspos("FGRL",2,"FSTR",0.,-ycoor,0.,0,"ONLY");
+
+  // Freon sensitive layer
+  par[0] = -1;
+  par[1] = 0.110/2.;
+  par[2] = zSenStrip/2.;
+  gMC->Gsvolu("FCFC","BOX",idtmed[513],par,3);
+  gMC->Gspos("FCFC",0,"FNSF",0.,0.,0.,0,"ONLY");
+  
+  // Pad definition x & z
+  gMC->Gsdvn("FLZ","FCFC", nz, 3); 
+  gMC->Gsdvn("FLX","FLZ" , nx, 1); 
+
+  // MRPC pixel itself 
+  par[0] = -1;
+  par[1] = -1; 
+  par[2] = -1;
+  gMC->Gsvolu("FPAD", "BOX ", idtmed[513], par, 3);
+  gMC->Gspos("FPAD", 0, "FLX", 0., 0., 0., 0, "ONLY");
+
+
+////  Positioning the Strips  (FSTR) in the FLT volumes  /////
+
+  // 3 (Central) Plate 
+  Float_t t = zFLT1+zFLT2+zFLT3/2.+7.*2.5;//Half Width of Barrel
+  Float_t zpos = 0;
+  Float_t ang;
+  Float_t Offset;  
+  Float_t last;
+  nrot = 0;
+  Int_t i=1,j=1;
+  zcoor=0;
+  Int_t UpDown=-1; // UpDown=-1 -> Upper strip, UpDown=+1 -> Lower strip
+  do{
+     ang = atan(zcoor/t);
+     ang = ang * kRaddeg;
+     AliMatrix (idrotm[nrot]  ,90.,  0.,90.-ang,90.,-ang,90.);
+     AliMatrix (idrotm[nrot+1],90.,180.,90.+ang,90., ang,90.);
+     ycoor = -29./2.+ Space; //2 cm over front plate
+     ycoor += (1-(UpDown+1)/2)*Gap;
+     gMC->Gspos("FSTR",j,"FLT3",0.,ycoor,zcoor,idrotm[nrot],"ONLY");
+     gMC->Gspos("FSTR",j+1,"FLT3",0.,ycoor,-zcoor,idrotm[nrot+1],"ONLY");
+     ang  = ang / kRaddeg;     
+     zcoor=zcoor-(zSenStrip/2)/TMath::Cos(ang)+UpDown*Gap*TMath::Tan(ang)-(zSenStrip/2)/TMath::Cos(ang);
+     UpDown*= -1; // Alternate strips 
+     i++;
+     j+=2;
+  } while (zcoor-(StripWidth/2)*TMath::Cos(ang)>-t+zFLT1+zFLT2+7*2.5);
+  
+  ycoor = -29./2.+ Space; //2 cm over front plate
+
+  // Plate  2
+  zpos = -zFLT3/2-7;
+  ang = atan(zpos/sqrt(2*t*t-zpos*zpos));
+  Offset = StripWidth*TMath::Cos(ang)/2;
+  zpos -= Offset;
+  nrot = 0;
+  i=1;
+  // UpDown has not to be reinitialized, so that the arrangement of the strips can continue coherently
+
+  do {
+     ang = atan(zpos/sqrt(2*t*t-zpos*zpos));
+     ang = ang*kRaddeg;
+     AliMatrix (idrotm[nrot], 90., 0., 90.-ang,90.,ang, 270.);
+     ycoor = -29./2.+ Space ; //2 cm over front plate
+     ycoor += (1-(UpDown+1)/2)*Gap;
+     zcoor = zpos+(zFLT3/2.+7+zFLT2/2); // Moves to the system of the centre of the modulus FLT2
+     gMC->Gspos("FSTR",i, "FLT2", 0., ycoor, zcoor,idrotm[nrot], "ONLY");
+     ang  = ang/kRaddeg;
+     zpos = zpos - (zSenStrip/2)/TMath::Cos(ang)+UpDown*Gap*TMath::Tan(ang)-(zSenStrip/2)/TMath::Cos(ang);
+     last = StripWidth*TMath::Cos(ang)/2;
+     UpDown*=-1;
+     i++; 
+  } while (zpos-(StripWidth/2)*TMath::Cos(ang)>-t+zFLT1+7);
+
+  // Plate  1
+  zpos = -t+zFLT1+3.5;
+  ang = atan(zpos/sqrt(2*t*t-zpos*zpos));
+  Offset = StripWidth*TMath::Cos(ang)/2.;
+  zpos -= Offset;
+  nrot = 0;
+  i=0;
+  ycoor= -29./2.+Space+Gap/2;
+
+ do {
+     ang = atan(zpos/sqrt(2*t*t-zpos*zpos));
+     ang = ang*kRaddeg;
+     AliMatrix (idrotm[nrot], 90., 0., 90.-ang,90.,ang, 270.);
+     i++;
+     zcoor = zpos+(zFLT1/2+zFLT2+zFLT3/2+7.*2.);
+     gMC->Gspos("FSTR",i, "FLT1", 0., ycoor, zcoor,idrotm[nrot], "ONLY");
+     ang  = ang/kRaddeg;
+     zpos = zpos - zSenStrip/TMath::Cos(ang);
+     last = StripWidth*TMath::Cos(ang)/2.;
+  }  while (zpos>-t+7.+last);
+
+printf("#######################################################\n");
+printf("     Distance from the bound of the FLT3: %f cm \n",t+zpos-(zSenStrip/2)/TMath::Cos(ang));
+     ang = atan(zpos/sqrt(2*t*t-zpos*zpos));
+     zpos = zpos - zSenStrip/TMath::Cos(ang);
+printf("NEXT Distance from the bound of the FLT3: %f cm \n",t+zpos-(zSenStrip/2)/TMath::Cos(ang));
+printf("#######################################################\n");
+
+////////// Layers after detector /////////////////
+
+// Honeycomb layer after (3cm)
+
+  Float_t OverSpace = Space + 7.3;
+///  StripWidth*TMath::Sin(ang) + 1.3;
+
+  par[0] = -1;
+  par[1] = 0.6;
+  par[2] = -1;
+  ycoor = -yFLT/2 + OverSpace + par[1];
+  gMC->Gsvolu("FPE1", "BOX ", idtmed[503], par, 3); // Hony
+  gMC->Gspos("FPE1", 0, "FLT1", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FPE2", "BOX ", idtmed[503], par, 3); // Hony
+  gMC->Gspos("FPE2", 0, "FLT2", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FPE3", "BOX ", idtmed[503], par, 3); // Hony
+  gMC->Gspos("FPE3", 0, "FLT3", 0., ycoor, 0., 0, "ONLY");
+
+// Electronics (Cu) after
+  ycoor += par[1];
+  par[0] = -1;
+  par[1] = 1.43*0.05 / 2.; // 5% of X0
+  par[2] = -1;
+  ycoor += par[1];
+  gMC->Gsvolu("FEC1", "BOX ", idtmed[501], par, 3); // Cu
+  gMC->Gspos("FEC1", 0, "FLT1", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FEC2", "BOX ", idtmed[501], par, 3); // Cu
+  gMC->Gspos("FEC2", 0, "FLT2", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FEC3", "BOX ", idtmed[501], par, 3); // Cu
+  gMC->Gspos("FEC3", 0, "FLT3", 0., ycoor, 0., 0, "ONLY");
+
+// Cooling water after
+  ycoor += par[1];
+  par[0] = -1;
+  par[1] = 36.1*0.02 / 2.; // 2% of X0
+  par[2] = -1;
+  ycoor += par[1];
+  gMC->Gsvolu("FWA1", "BOX ", idtmed[515], par, 3); // Water
+  gMC->Gspos("FWA1", 0, "FLT1", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FWA2", "BOX ", idtmed[515], par, 3); // Water
+  gMC->Gspos("FWA2", 0, "FLT2", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FWA3", "BOX ", idtmed[515], par, 3); // Water
+  gMC->Gspos("FWA3", 0, "FLT3", 0., ycoor, 0., 0, "ONLY");
+
+//back plate honycomb (2cm)
+  par[0] = -1;
+  par[1] = 2 / 2.;
+  par[2] = -1;
+  ycoor = yFLT/2 - par[1];
+  gMC->Gsvolu("FEG1", "BOX ", idtmed[503], par, 3); // Hony
+  gMC->Gspos("FEG1", 0, "FLT1", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FEG2", "BOX ", idtmed[503], par, 3); // Hony
+  gMC->Gspos("FEG2", 0, "FLT2", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FEG3", "BOX ", idtmed[503], par, 3); // Hony
+  gMC->Gspos("FEG3", 0, "FLT3", 0., ycoor, 0., 0, "ONLY");
 }
 
 //_____________________________________________________________________________
-void AliTOFv3::DrawDetector()
+void AliTOFv3::DrawModule()
 {
   //
-  // Draw a shaded view of the Time Of Flight version 3
+  // Draw a shaded view of the Time Of Flight version 1
   //
-
-  AliMC* pMC = AliMC::GetMC();
-  
   // Set everything unseen
-  pMC->Gsatt("*", "seen", -1);
+  gMC->Gsatt("*", "seen", -1);
   // 
   // Set ALIC mother transparent
-  pMC->Gsatt("ALIC","SEEN",0);
+  gMC->Gsatt("ALIC","SEEN",0);
   //
   // Set the volumes visible
-  pMC->Gsatt("ALIC","SEEN",0);
-  pMC->Gsatt("FBAR","SEEN",0);
-  pMC->Gsatt("FTO1","SEEN",0);
-  pMC->Gsatt("FTO2","SEEN",0);
-  pMC->Gsatt("FTO3","SEEN",0);
-  pMC->Gsatt("FBT1","SEEN",0);
-  pMC->Gsatt("FBT2","SEEN",0);
-  pMC->Gsatt("FBT3","SEEN",0);
-  pMC->Gsatt("FST1","SEEN",0);
-  pMC->Gsatt("FLT1","SEEN",0);
-  pMC->Gsatt("FST2","SEEN",0);
-  pMC->Gsatt("FLT2","SEEN",0);
-  pMC->Gsatt("FST3","SEEN",0);
-  pMC->Gsatt("FLT3","SEEN",0);
-  pMC->Gsatt("FSK1","SEEN",0);
-  pMC->Gsatt("FLK1","SEEN",0);
-  pMC->Gsatt("FSL1","SEEN",1);
-  pMC->Gsatt("FLL1","SEEN",1);
+  gMC->Gsatt("ALIC","SEEN",0);
+  gMC->Gsatt("FBAR","SEEN",1);
+  gMC->Gsatt("FTO1","SEEN",1);
+  gMC->Gsatt("FTO2","SEEN",1);
+  gMC->Gsatt("FTO3","SEEN",1);
+  gMC->Gsatt("FBT1","SEEN",1);
+  gMC->Gsatt("FBT2","SEEN",1);
+  gMC->Gsatt("FBT3","SEEN",1);
+  gMC->Gsatt("FDT1","SEEN",1);
+  gMC->Gsatt("FDT2","SEEN",1);
+  gMC->Gsatt("FDT3","SEEN",1);
+  gMC->Gsatt("FLT1","SEEN",1);
+  gMC->Gsatt("FLT2","SEEN",1);
+  gMC->Gsatt("FLT3","SEEN",1);
+  gMC->Gsatt("FPL1","SEEN",1);
+  gMC->Gsatt("FPL2","SEEN",1);
+  gMC->Gsatt("FPL3","SEEN",1);
+  gMC->Gsatt("FLD1","SEEN",1);
+  gMC->Gsatt("FLD2","SEEN",1);
+  gMC->Gsatt("FLD3","SEEN",1);
+  gMC->Gsatt("FLZ1","SEEN",1);
+  gMC->Gsatt("FLZ2","SEEN",1);
+  gMC->Gsatt("FLZ3","SEEN",1);
+  gMC->Gsatt("FLX1","SEEN",1);
+  gMC->Gsatt("FLX2","SEEN",1);
+  gMC->Gsatt("FLX3","SEEN",1);
+  gMC->Gsatt("FPA0","SEEN",1);
   //
-  pMC->Gdopt("hide", "on");
-  pMC->Gdopt("shad", "on");
-  pMC->Gsatt("*", "fill", 7);
-  pMC->SetClipBox(".");
-  pMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
-  pMC->DefaultRange();
-  pMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
-  pMC->Gdhead(1111, "Time Of Flight");
-  pMC->Gdman(18, 4, "MAN");
-  pMC->Gdopt("hide","off");
+  gMC->Gdopt("hide", "on");
+  gMC->Gdopt("shad", "on");
+  gMC->Gsatt("*", "fill", 7);
+  gMC->SetClipBox(".");
+  gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
+  gMC->DefaultRange();
+  gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
+  gMC->Gdhead(1111, "Time Of Flight");
+  gMC->Gdman(18, 4, "MAN");
+  gMC->Gdopt("hide","off");
 }
 
 //_____________________________________________________________________________
@@ -280,7 +473,7 @@ void AliTOFv3::CreateMaterials()
   //
   // Define materials for the Time Of Flight
   //
-   AliTOF::CreateMaterials();
+  AliTOF::CreateMaterials();
 }
  
 //_____________________________________________________________________________
@@ -289,15 +482,36 @@ void AliTOFv3::Init()
   //
   // Initialise the detector after the geometry has been defined
   //
+  printf("**************************************"
+        "  TOF  "
+        "**************************************\n");
+  printf("\n     Version 3 of TOF initialing, "
+        "symmetric TOF\n\n");
 
-  AliMC* pMC = AliMC::GetMC();
-  
   AliTOF::Init();
-  fIdFTO2=pMC->VolId("FTO2");
-  fIdFTO3=pMC->VolId("FTO3");
-  fIdFLT1=pMC->VolId("FLT1");
-  fIdFLT2=pMC->VolId("FLT2");
-  fIdFLT3=pMC->VolId("FLT3");
+
+  //
+  // Check that FRAME is there otherwise we have no place where to
+  // put TOF
+  AliModule* FRAME=gAlice->GetModule("FRAME");
+  if(!FRAME) {
+    Error("Ctor","TOF needs FRAME to be present\n");
+    exit(1);
+  } else 
+    if(FRAME->IsVersion()!=1) {
+      Error("Ctor","FRAME version 1 needed with this version of TOF\n");
+      exit(1);
+    }
+
+  fIdFTO2=gMC->VolId("FTO2");
+  fIdFTO3=gMC->VolId("FTO3");
+  fIdFLT1=gMC->VolId("FLT1");
+  fIdFLT2=gMC->VolId("FLT2");
+  fIdFLT3=gMC->VolId("FLT3");
+
+  printf("**************************************"
+        "  TOF  "
+        "**************************************\n");
 }
  
 //_____________________________________________________________________________
@@ -306,38 +520,47 @@ void AliTOFv3::StepManager()
   //
   // Procedure called at each step in the Time Of Flight
   //
+  TLorentzVector mom, pos;
   Float_t hits[8];
   Int_t vol[3];
-  Int_t copy, id;
-  AliMC *pMC= AliMC::GetMC();
-  Int_t *idtmed = gAlice->Idtmed();
-  if(pMC->GetMedium()==idtmed[510-1] && 
-     pMC->TrackEntering() && pMC->TrackCharge()
-     && pMC->CurrentVol(0,copy)==fIdSens) {
+  Int_t copy, id, i;
+  Int_t *idtmed = fIdtmed->GetArray()-499;
+  if(gMC->GetMedium()==idtmed[514-1] && 
+     gMC->IsTrackEntering() && gMC->TrackCharge()
+     && gMC->CurrentVolID(copy)==fIdSens) {
     TClonesArray &lhits = *fHits;
     //
     // Record only charged tracks at entrance
-    pMC->CurrentVolOff(1,0,copy);
+    gMC->CurrentVolOffID(1,copy);
     vol[2]=copy;
-    pMC->CurrentVolOff(3,0,copy);
+    gMC->CurrentVolOffID(3,copy);
     vol[1]=copy;
-    id=pMC->CurrentVolOff(6,0,copy);
+    id=gMC->CurrentVolOffID(8,copy);
     vol[0]=copy;
     if(id==fIdFTO3) {
       vol[0]+=22;
-      id=pMC->CurrentVolOff(4,0,copy);
+      id=gMC->CurrentVolOffID(5,copy);
       if(id==fIdFLT3) vol[1]+=6;
     } else if (id==fIdFTO2) {
       vol[0]+=20;
-      id=pMC->CurrentVolOff(4,0,copy);
+      id=gMC->CurrentVolOffID(5,copy);
       if(id==fIdFLT2) vol[1]+=8;
     } else {
-      id=pMC->CurrentVolOff(4,0,copy);
+      id=gMC->CurrentVolOffID(5,copy);
       if(id==fIdFLT1) vol[1]+=14;
     }
-    pMC->TrackPosition(hits);
-    pMC->TrackMomentum(&hits[3]);
-    hits[7]=pMC->TrackTime();
+    gMC->TrackPosition(pos);
+    gMC->TrackMomentum(mom);
+    //
+    Double_t ptot=mom.Rho();
+    Double_t norm=1/ptot;
+    for(i=0;i<3;++i) {
+      hits[i]=pos[i];
+      hits[i+3]=mom[i]*norm;
+    }
+    hits[6]=ptot;
+    hits[7]=pos[3];
     new(lhits[fNhits++]) AliTOFhit(fIshunt,gAlice->CurrentTrack(),vol,hits);
   }
 }
+