]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/src/AliL3Transform.cxx
Moving lib*.pkg
[u/mrichter/AliRoot.git] / HLT / src / AliL3Transform.cxx
index 47d37aa85c63fc43192e81b4c4a61fa102fd0ce9..9d671075a561382d934640d2c761e3ae1626b601 100644 (file)
-// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
-//*-- Copyright &copy ASV
+// @(#) $Id$
+
+// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>, Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
+//*-- Copyright &copy ALICE HLT Group
+
+
+#include "AliL3StandardIncludes.h"
+#include "dirent.h"
+
+#ifdef use_aliroot
+#include <AliRun.h>
+#include <AliMagF.h>
+#include <AliTPCParamSR.h>
+#include <AliTPCPRF2D.h>
+#include <AliTPCRF1D.h>
+#endif
+#ifdef use_root
+#include <TFile.h>
+#include <TUnixSystem.h>
+#include <TTimeStamp.h>
+#include <TError.h>
+#endif
 
 #include "AliL3Logging.h"
 #include "AliL3Transform.h"
-//#include <TFile.h>
-#include <math.h>
 
+#if __GNUC__ == 3
+using namespace std;
+#endif
+
+/** \class AliL3Transform 
+<pre>
 //_____________________________________________________________
 // AliL3Transform
 //
 // Transformation class for ALICE TPC.
+//
+// Class which contains all detector specific parameters for the TPC,
+// and different useful functions for coordinate transforms.
+//
+// The class is completely static, which means that no object needs
+// to be instantiated. Function calls should then be done like, e.g.:
+//
+// Double_t eta = AliL3Transform::GetEta(xyz);
+//
+// IMPORTANT: If used as is, default detector parameters will be used,
+//            and you really have to make sure that these correspond to
+//            the AliROOT version you are currently working on!!
+//            You should therefore always initialize the parameters by
+//
+//            AliL3Transform::Init(path);
+// 
+//            where path is a char*, giving the path to where file containing
+//            the detector parameter is located. This file should be called
+//            "l3transform.config", and can be created with the function MakeInitFile.
+//            
+//            You can also force reading the parameters from a AliTPCParam object
+//            by setting the flag;
+//
+//            AliL3Transform::Init(path,kTRUE);
+//
+//            where path is a char* 
+//            either providing the rootfile name containing the geometry or 
+//            the path to the rootfile which should then be called alirunfile.root. 
+//            Note that for both of these cases you have to
+//            compile with USEPACKAGE=ALIROOT set (see level3code/Makefile.conf).
+//
+//            Currently, there are 4 versions of the Transformer:
+//             fVersion==fV_aliroot: ALIROOT-head compatible
+//             fVersion==fV_cosmics: Cosmics data run (2003) compatible
+//             fVersion==fV_default: means no config file has been loaded
+//             fVersion==fV_deprecated: dont use old (before July 2003) style of transformer
+//
+</pre>
+*/
+
+ClassImp(AliL3Transform)
+
+const Double_t AliL3Transform::fAnodeWireSpacing = 0.25; //Taken from the TDR
+const Double_t AliL3Transform::fBFACT = 0.0029980;       //Conversion Factor
+const Double_t AliL3Transform::fPi  =   3.141592653589793;
+const Double_t AliL3Transform::f2Pi = 2*3.141592653589793;
+const Double_t AliL3Transform::fPi2 = 0.5*3.141592653589793;
+const Double_t AliL3Transform::fToDeg = 180/3.141592653589793;
+
+//Defined by HLT and GSI
+Int_t AliL3Transform::fNPatches = 6;
+Int_t AliL3Transform::fRows[6][2] = {{0,29},{30,62},{63,90},{91,116},{117,139},{140,158}}; 
+Int_t AliL3Transform::fNRows[6] = {30,33,28,26,23,19};
+
+// The following definition is generated by MakeInitFile function
+Double_t AliL3Transform::fBField = 0.2;
+Double_t AliL3Transform::fSolenoidBField = 2;
+Double_t AliL3Transform::fBFieldFactor = 1;
+Int_t AliL3Transform::fVersion = fV_default;
+Int_t AliL3Transform::fNTimeBins = 446;
+Int_t AliL3Transform::fNRowLow = 63;
+Int_t AliL3Transform::fNRowUp = 96;
+Int_t AliL3Transform::fNRowUp1 = 64;
+Int_t AliL3Transform::fNRowUp2 = 32;
+Int_t AliL3Transform::fNSectorLow = 36;
+Int_t AliL3Transform::fNSectorUp = 36;
+Int_t AliL3Transform::fNSector = 72;
+Double_t AliL3Transform::fPadPitchWidthLow = 0.4;
+Double_t AliL3Transform::fPadPitchWidthUp = 0.6;
+Double_t AliL3Transform::fZWidth = 0.5660;
+Double_t AliL3Transform::fZSigma = 0.2288;
+Double_t AliL3Transform::fZLength = 250.0000;
+Double_t AliL3Transform::fZOffset = 0.6864;
+Double_t AliL3Transform::fDiffT = 0.0220;
+Double_t AliL3Transform::fDiffL = 0.0220;
+Double_t AliL3Transform::fOmegaTau = 0.1450;
+Double_t AliL3Transform::fInnerPadLength = 0.75;
+Double_t AliL3Transform::fOuter1PadLength = 1.00;
+Double_t AliL3Transform::fOuter2PadLength = 1.50;
+Double_t AliL3Transform::fInnerPRFSigma = 0.203811;
+Double_t AliL3Transform::fOuter1PRFSigma = 0.299325;
+Double_t AliL3Transform::fOuter2PRFSigma = 0.299323;
+Double_t AliL3Transform::fTimeSigma = 0.228809;
+Int_t AliL3Transform::fADCSat = 1024;
+Int_t AliL3Transform::fZeroSup = 0;
+Int_t AliL3Transform::fNSlice = 36;
+Int_t AliL3Transform::fNRow = 159;
+Double_t AliL3Transform::fNRotShift = 0.5;
+Int_t AliL3Transform::fSlice2Sector[36][2] = { { 0, 36}, 
+                                              { 1, 37}, 
+                                              { 2, 38}, 
+                                              { 3, 39}, 
+                                              { 4, 40}, 
+                                              { 5, 41}, 
+                                              { 6, 42}, 
+                                              { 7, 43}, 
+                                              { 8, 44}, 
+                                              { 9, 45}, 
+                                              {10, 46}, 
+                                              {11, 47}, 
+                                              {12, 48}, 
+                                              {13, 49}, 
+                                              {14, 50}, 
+                                              {15, 51}, 
+                                              {16, 52}, 
+                                              {17, 53}, 
+                                              {18, 54}, 
+                                              {19, 55}, 
+                                              {20, 56}, 
+                                              {21, 57}, 
+                                              {22, 58}, 
+                                              {23, 59}, 
+                                              {24, 60}, 
+                                              {25, 61}, 
+                                              {26, 62}, 
+                                              {27, 63}, 
+                                              {28, 64}, 
+                                              {29, 65}, 
+                                              {30, 66}, 
+                                              {31, 67}, 
+                                              {32, 68}, 
+                                              {33, 69}, 
+                                              {34, 70}, 
+                                              {35, 71}
+};
+
+Int_t AliL3Transform::fSector2Slice[72] = { 0, 
+                                           1, 
+                                           2, 
+                                           3, 
+                                           4, 
+                                           5, 
+                                           6, 
+                                           7, 
+                                           8, 
+                                           9, 
+                                           10, 
+                                           11, 
+                                           12, 
+                                           13, 
+                                           14, 
+                                           15, 
+                                           16, 
+                                           17, 
+                                           18, 
+                                           19, 
+                                           20, 
+                                           21, 
+                                           22, 
+                                           23, 
+                                           24, 
+                                           25, 
+                                           26, 
+                                           27, 
+                                           28, 
+                                           29, 
+                                           30, 
+                                           31, 
+                                           32,
+                                           33, 
+                                           34, 
+                                           35, 
+                                           0, 
+                                           1, 
+                                           2, 
+                                           3, 
+                                           4, 
+                                           5, 
+                                           6, 
+                                           7, 
+                                           8, 
+                                           9, 
+                                           10, 
+                                           11, 
+                                           12, 
+                                           13, 
+                                           14, 
+                                           15, 
+                                           16, 
+                                           17, 
+                                           18, 
+                                           19, 
+                                           20, 
+                                           21, 
+                                           22, 
+                                           23, 
+                                           24, 
+                                           25, 
+                                           26, 
+                                           27, 
+                                           28, 
+                                           29, 
+                                           30, 
+                                           31, 
+                                           32, 
+                                           33, 
+                                           34, 
+                                           35 
+};
+
+Int_t AliL3Transform::fSectorLow[72] = { 1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1, 
+                                        1,
+                                        1, 
+                                        1, 
+                                        1, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0,     
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0, 
+                                        0 
+};
+
+Double_t AliL3Transform::fX[159] = { 85.195,
+                                    85.945,
+                                    86.695,
+                                    87.445,
+                                    88.195,
+                                    88.945,
+                                    89.695,
+                                    90.445,
+                                    91.195,
+                                    91.945,
+                                    92.695,
+                                    93.445,
+                                    94.195,
+                                    94.945,
+                                    95.695,
+                                    96.445,
+                                    97.195,
+                                    97.945,
+                                    98.695,
+                                    99.445,
+                                    100.195,
+                                    100.945,
+                                    101.695,
+                                    102.445,
+                                    103.195,
+                                    103.945,
+                                    104.695,
+                                    105.445,
+                                    106.195,
+                                    106.945,
+                                    107.695,
+                                    108.445,
+                                    109.195,
+                                    109.945,
+                                    110.695,
+                                    111.445,
+                                    112.195,
+                                    112.945,
+                                    113.695,
+                                    114.445,
+                                    115.195,
+                                    115.945,
+                                    116.695,
+                                    117.445,
+                                    118.195,
+                                    118.945,
+                                    119.695,
+                                    120.445,
+                                    121.195,
+                                    121.945,
+                                    122.695,
+                                    123.445,
+                                    124.195,
+                                    124.945,
+                                    125.695,
+                                    126.445,
+                                    127.195,
+                                    127.945,
+                                    128.695,
+                                    129.445,
+                                    130.195,
+                                    130.945,
+                                    131.695,
+                                    135.180,
+                                    136.180,
+                                    137.180,
+                                    138.180,
+                                    139.180,
+                                    140.180,
+                                    141.180,
+                                    142.180,
+                                    143.180,
+                                    144.180,
+                                    145.180,
+                                    146.180,
+                                    147.180,
+                                    148.180,
+                                    149.180,
+                                    150.180,
+                                    151.180,
+                                    152.180,
+                                    153.180,
+                                    154.180,
+                                    155.180,
+                                    156.180,
+                                    157.180,
+                                    158.180,
+                                    159.180,
+                                    160.180,
+                                    161.180,
+                                    162.180,
+                                    163.180,
+                                    164.180,
+                                    165.180,
+                                    166.180,
+                                    167.180,
+                                    168.180,
+                                    169.180,
+                                    170.180,
+                                    171.180,
+                                    172.180,
+                                    173.180,
+                                    174.180,
+                                    175.180,
+                                    176.180,
+                                    177.180,
+                                    178.180,
+                                    179.180,
+                                    180.180,
+                                    181.180,
+                                    182.180,
+                                    183.180,
+                                    184.180,
+                                    185.180,
+                                    186.180,
+                                    187.180,
+                                    188.180,
+                                    189.180,
+                                    190.180,
+                                    191.180,
+                                    192.180,
+                                    193.180,
+                                    194.180,
+                                    195.180,
+                                    196.180,
+                                    197.180,
+                                    198.180,
+                                    199.430,
+                                    200.930,
+                                    202.430,
+                                    203.930,
+                                    205.430,
+                                    206.930,
+                                    208.430,
+                                    209.930,
+                                    211.430,
+                                    212.930,
+                                    214.430,
+                                    215.930,
+                                    217.430,
+                                    218.930,
+                                    220.430,
+                                    221.930,
+                                    223.430,
+                                    224.930,
+                                    226.430,
+                                    227.930,
+                                    229.430,
+                                    230.930,
+                                    232.430,
+                                    233.930,
+                                    235.430,
+                                    236.930,
+                                    238.430,
+                                    239.930,
+                                    241.430,
+                                    242.930,
+                                    244.430,
+                                    245.930
+};
+
+Int_t AliL3Transform::fNPads[159] = {67,
+                                     67,
+                                     69,
+                                     69,
+                                     69,
+                                     71,
+                                     71,
+                                     71,
+                                     73,
+                                     73,
+                                     73,
+                                     75,
+                                     75,
+                                     75,
+                                     77,
+                                     77,
+                                     77,
+                                     79,
+                                     79,
+                                     79,
+                                     81,
+                                     81,
+                                     81,
+                                     83,
+                                     83,
+                                     83,
+                                     85,
+                                     85,
+                                     85,
+                                     87,
+                                     87,
+                                     87,
+                                     89,
+                                     89,
+                                     89,
+                                     91,
+                                     91,
+                                     91,
+                                     93,
+                                     93,
+                                     93,
+                                     95,
+                                     95,
+                                     95,
+                                     97,
+                                     97,
+                                     97,
+                                     99,
+                                     99,
+                                     99,
+                                     99,
+                                     101,
+                                     101,
+                                     101,
+                                     103,
+                                     103,
+                                     103,
+                                     105,
+                                     105,
+                                     105,
+                                     107,
+                                     107,
+                                     107,
+                                     73,
+                                     75,
+                                     75,
+                                     75,
+                                     75,
+                                     77,
+                                     77,
+                                     77,
+                                     79,
+                                     79,
+                                     79,
+                                     81,
+                                     81,
+                                     81,
+                                     81,
+                                     83,
+                                     83,
+                                     83,
+                                     85,
+                                     85,
+                                     85,
+                                     85,
+                                     87,
+                                     87,
+                                     87,
+                                     89,
+                                     89,
+                                     89,
+                                     91,
+                                     91,
+                                     91,
+                                     91,
+                                     93,
+                                     93,
+                                     93,
+                                     95,
+                                     95,
+                                     95,
+                                     95,
+                                     97,
+                                     97,
+                                     97,
+                                     99,
+                                     99,
+                                     99,
+                                     101,
+                                     101,
+                                     101,
+                                     101,
+                                     103,
+                                     103,
+                                     103,
+                                     105,
+                                     105,
+                                     105,
+                                     105,
+                                     107,
+                                     107,
+                                     107,
+                                     109,
+                                     109,
+                                     109,
+                                     111,
+                                     111,
+                                     111,
+                                     113,
+                                     113,
+                                     113,
+                                     115,
+                                     115,
+                                     117,
+                                     117,
+                                     119,
+                                     119,
+                                     121,
+                                     121,
+                                     121,
+                                     123,
+                                     123,
+                                     125,
+                                     125,
+                                     127,
+                                     127,
+                                     127,
+                                     129,
+                                     129,
+                                     131,
+                                     131,
+                                     133,
+                                     133,
+                                     135,
+                                     135,
+                                     135,
+                                     137,
+                                     137,
+                                     139
+};
+
+Double_t AliL3Transform::fCos[36] = { 0.9848077297,
+                                     0.8660253882,
+                                     0.6427876353,
+                                     0.3420201540,
+                                     0.0000000000,
+                                     -0.3420201540,
+                                     -0.6427876353,
+                                     -0.8660253882,
+                                     -0.9848077297,
+                                     -0.9848077297,
+                                     -0.8660253882,
+                                     -0.6427876353,
+                                     -0.3420201540,
+                                     -0.0000000000,
+                                     0.3420201540,
+                                     0.6427876353,
+                                     0.8660253882,
+                                     0.9848077297,
+                                     0.9848077297,
+                                     0.8660253882,
+                                     0.6427876353,
+                                     0.3420201540,
+                                     0.0000000000,
+                                     -0.3420201540,
+                                     -0.6427876353,
+                                     -0.8660253882,
+                                     -0.9848077297,
+                                     -0.9848077297,
+                                     -0.8660253882,
+                                     -0.6427876353,
+                                     -0.3420201540,
+                                     -0.0000000000,
+                                     0.3420201540,
+                                     0.6427876353,
+                                     0.8660253882,
+                                     0.9848077297
+};
+
+Double_t AliL3Transform::fSin[36] = { 0.1736481786,
+                                     0.5000000000,
+                                     0.7660444379,
+                                     0.9396926165,
+                                     1.0000000000,
+                                     0.9396926165,
+                                     0.7660444379,
+                                     0.5000000000,
+                                     0.1736481786,
+                                     -0.1736481786,
+                                     -0.5000000000,
+                                     -0.7660444379,
+                                     -0.9396926165,
+                                     -1.0000000000,
+                                     -0.9396926165,
+                                     -0.7660444379,
+                                     -0.5000000000,
+                                     -0.1736481786,
+                                     0.1736481786,
+                                     0.5000000000,
+                                     0.7660444379,
+                                     0.9396926165,
+                                     1.0000000000,
+                                     0.9396926165,
+                                     0.7660444379,
+                                     0.5000000000,
+                                     0.1736481786,
+                                     -0.1736481786,
+                                     -0.5000000000,
+                                     -0.7660444379,
+                                     -0.9396926165,
+                                     -1.0000000000,
+                                     -0.9396926165,
+                                     -0.7660444379,
+                                     -0.5000000000,
+                                     -0.1736481786
+};
+
+Bool_t AliL3Transform::Init(Char_t* path,Bool_t UseAliTPCParam)
+{
+  //Overwrite the parameters with values stored in file "l3transform.config" in path.
+  //If file does not exist, old default values will be used.
+  //If flag UseAliTPCParam is set, the parameters will be read from the the rootfile
+  //which then has to be called path/digitfile.root
+  
+  if(fVersion != fV_default)
+    LOG(AliL3Log::kWarning,"AliL3Transform::Init","Init values")
+      <<AliL3Log::kDec<<"You are initializing the parameters more than once; check your code please! "<<fVersion<<ENDLOG;
+  
+  if(UseAliTPCParam) //use rootfile to generate temporary init file
+    return ReadInit(path);
+
+  //create filename
+  Char_t pathname[1024];
+  strcpy(pathname,path);
+
+  //test whether provided path is the file itself
+  Int_t isdir = 0;
+  DIR *testdir=opendir(pathname);
+  if(testdir){
+    isdir=1;
+    closedir(testdir);
+  }
+
+  if(isdir) strcat(pathname,"/l3transform.config");
+
+  return ReadInitFile(pathname);
+}
 
-ClassImp(AliL3Transform);
+Bool_t AliL3Transform::ReadInitFile(Char_t* pathname)
+{
+  //read transformer settings from pathname
+
+  FILE *fptr=fopen(pathname,"r");
+  if(!fptr){
+    LOG(AliL3Log::kWarning,"AliL3Transform::ReadInitFile","File Open")
+      <<"Pointer to Config File \""<<pathname<<"\" 0x0!"<<ENDLOG;
+    return kFALSE;
+  }
+
+  Char_t d1[250], d2[100], d3[100];
+  Int_t dummy=0;
+  Double_t ddummy=0.0;
+
+  while(!feof(fptr)) {
+    fscanf(fptr,"%s",d1);
+    if(strcmp(d1,"fVersion")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fVersion=dummy;}
+    else if(strcmp(d1,"fBFieldFactor")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fBFieldFactor=(Double_t)ddummy;}
+    else if(strcmp(d1,"fSolenoidBField")==0)
+      {
+       fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);
+       fSolenoidBField=(Double_t)ddummy;
+      }
+    else if(strcmp(d1,"fNTimeBins")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNTimeBins=(Int_t)dummy;}
+    else if(strcmp(d1,"fNRowLow")==0)
+      {
+       fscanf(fptr,"%s %d %s",d2,&dummy,d3);
+       fNRowLow=(Int_t)dummy;
+       if(fNRowLow != 63)
+         LOG(AliL3Log::kError,"AliL3Transform::ReadInitFile","Overflow")
+           <<"Number of inner PadRows should be 63! Check and fgrep the code for 63 to see the consequences of this major change!"<<ENDLOG;
+      }
+    else if(strcmp(d1,"fNRowUp")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowUp=(Int_t)dummy;}
+    else if(strcmp(d1,"fNRowUp1")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowUp1=(Int_t)dummy;}
+    else if(strcmp(d1,"fNRowUp2")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowUp2=(Int_t)dummy;}
+    else if(strcmp(d1,"fNSectorLow")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSectorLow=(Int_t)dummy;}
+    else if(strcmp(d1,"fNSectorUp")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSectorUp=(Int_t)dummy;}
+    else if(strcmp(d1,"fNSector")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSector=(Int_t)dummy;}
+    else if(strcmp(d1,"fPadPitchWidthLow")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fPadPitchWidthLow=(Double_t)ddummy;}
+    else if(strcmp(d1,"fPadPitchWidthUp")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fPadPitchWidthUp=(Double_t)ddummy;}
+    else if(strcmp(d1,"fZWidth")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZWidth=(Double_t)ddummy;}
+    else if(strcmp(d1,"fZSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZSigma=(Double_t)ddummy;}
+    else if(strcmp(d1,"fZLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZLength=(Double_t)ddummy;}
+    else if(strcmp(d1,"fZOffset")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZOffset=(Double_t)ddummy;}
+    else if(strcmp(d1,"fNSlice")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSlice=(Int_t)dummy;}
+    else if(strcmp(d1,"fDiffT")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fDiffT=(Double_t)ddummy;}
+    else if(strcmp(d1,"fDiffL")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fDiffL=(Double_t)ddummy;}
+    else if(strcmp(d1,"fOmegaTau")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOmegaTau=(Double_t)ddummy;}
+    else if(strcmp(d1,"fInnerPadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fInnerPadLength=(Double_t)ddummy;}
+    else if(strcmp(d1,"fOuter1PadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter1PadLength=(Double_t)ddummy;}
+    else if(strcmp(d1,"fOuter2PadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter2PadLength=(Double_t)ddummy;}
+    else if(strcmp(d1,"fInnerPRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fInnerPRFSigma=(Double_t)ddummy;}
+    else if(strcmp(d1,"fOuter1PRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter1PRFSigma=(Double_t)ddummy;}
+    else if(strcmp(d1,"fOuter2PRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter2PRFSigma=(Double_t)ddummy;}
+    else if(strcmp(d1,"fTimeSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fTimeSigma=(Double_t)ddummy;}
+    else if(strcmp(d1,"fADCSat")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fADCSat=(Int_t)dummy;}
+    else if(strcmp(d1,"fZeroSup")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fZeroSup=(Int_t)dummy;}
+    else if(strcmp(d1,"fNRow")==0){
+      fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRow=(Int_t)dummy;
+      if(fNRow!=159){
+       LOG(AliL3Log::kError,"AliL3Transform::ReadInitFile","Overflow")<<"Number of PadRows should be 159! Check and fgrep the code for 159 to see the consequences of this major change!"<<ENDLOG;
+      }
+    }
+    else if(strcmp(d1,"fNRotShift")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fNRotShift=(Double_t)ddummy;}
+    else if(strcmp(d1,"fX[0]")==0){
+      fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fX[0]=(Double_t)ddummy;
+      for(Int_t i=1;i<fNRow;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fX[i]=(Double_t)ddummy;}
+    }
+    else if(strcmp(d1,"fNPads[0]")==0){
+      fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNPads[0]=(Int_t)dummy;
+      for(Int_t i=1;i<fNRow;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fNPads[i]=(Int_t)dummy;}
+    }
+    else if(strcmp(d1,"fNRows[0]")==0){
+      fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRows[0]=(Int_t)dummy;
+      for(Int_t i=1;i<fNPatches;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fNRows[i]=(Int_t)dummy;}
+    }
+    else if(strcmp(d1,"fRows[0][0]")==0){
+      fscanf(fptr,"%s %d %s",d2,&dummy,d3);fRows[0][0]=(Int_t)dummy;
+      fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fRows[0][1]=(Int_t)dummy;
+      for(Int_t i=1;i<fNPatches;i++){
+       fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fRows[i][0]=(Int_t)dummy;
+       fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fRows[i][1]=(Int_t)dummy;
+      }
+    }
+    else if(strcmp(d1,"fSlice2Sector[0][0]")==0){
+      fscanf(fptr,"%s %d %s",d2,&dummy,d3);fSlice2Sector[0][0]=(Int_t)dummy;
+      fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fSlice2Sector[0][1]=(Int_t)dummy;
+      for(Int_t i=1;i<fNSlice;i++){
+       fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fSlice2Sector[i][0]=(Int_t)dummy;
+       fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fSlice2Sector[i][1]=(Int_t)dummy;
+      }
+    }
+    else if(strcmp(d1,"fSector2Slice[0]")==0){
+      fscanf(fptr,"%s %d %s",d2,&dummy,d3);fSector2Slice[0]=(Int_t)dummy;
+      for(Int_t i=1;i<fNSector;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fSector2Slice[i]=(Int_t)dummy;}
+    }
+    else if(strcmp(d1,"fSectorLow[0]")==0){
+      fscanf(fptr,"%s %d %s",d2,&dummy,d3);fSectorLow[0]=(Int_t)dummy;
+      for(Int_t i=1;i<fNSector;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fSectorLow[i]=(Int_t)dummy;}
+    }
+    else if(strcmp(d1,"fCos[0]")==0){
+      fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fCos[0]=(Double_t)ddummy;
+      for(Int_t i=1;i<fNSlice;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fCos[i]=(Double_t)ddummy;}
+    }
+    else if(strcmp(d1,"fSin[0]")==0){
+      fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fSin[0]=(Double_t)ddummy;
+      for(Int_t i=1;i<fNSlice;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fSin[i]=(Double_t)ddummy;}
+    }
+  }
+  fclose(fptr);
+
+  //The first multiplier gives the scale factor used to modify the field map 
+  //defined by the second multiplier.
+  fBField=fBFieldFactor*fSolenoidBField*0.1;
+
+  //Test if new config file has been used.
+  if(fVersion==fV_deprecated){
+    LOG(AliL3Log::kError,"AliL3Transform::ReadInitFile","Version")
+      <<"Version is deprecated, you have to create a new config file."<<ENDLOG;
+    return kFALSE;
+  }
 
+  LOG(AliL3Log::kInformational,"AliL3Transform::ReadInitFile","Config")
+    <<"Successfully loaded values from config file \""<<pathname<<"\""<<ENDLOG;
 
-AliL3Transform::AliL3Transform(){
-  //constructor
-  Init();
+  return kTRUE;
 }
 
+Bool_t AliL3Transform::ReadInit(Char_t *path)
+{
+  //Read all the parameters from a aliroot file, and store it in a temporary 
+  //file which is read by Init. Use this if you want to read the parameters from
+  //the rootfile "every" time.
+  
+#ifndef use_aliroot
+  LOG(AliL3Log::kError,"AliL3Transform::ReadInit","Version")
+    <<"You have to compile with use_aliroot flag in order to read from AliROOT file"<<ENDLOG;
+  return kFALSE;
+#else
+  Char_t filename[1024];
+  //first test whether provided path is the rootfile itself
+  Int_t saveErrIgLevel=gErrorIgnoreLevel;
+  gErrorIgnoreLevel=kFatal; //dont report errors
+  TFile *rootfile = TFile::Open(path);
+  if(!rootfile || rootfile->IsZombie()) 
+    { //ok assume its path to alirunfile file
+      sprintf(filename,"%s/alirunfile.root",path); //create rootfile name
+    } else { //path contains itself the rootfile name
+      rootfile->Close();
+      sprintf(filename,"%s",path); 
+    }
+  gErrorIgnoreLevel=saveErrIgLevel;
 
-AliL3Transform::~AliL3Transform(){
+  //finally make dummy init file /tmp/$USER/l3transform.config-`date`
+  Char_t tmppath[1024];
+  sprintf(tmppath,"/tmp/%s",gSystem->Getenv("USER"));
+  gSystem->mkdir(tmppath);
+  TTimeStamp time;
+  Char_t tmpfile[1024];
+  sprintf(tmpfile,"%s/l3transform.config-%d",tmppath,(Int_t)time.GetSec());
+  return MakeInitFile(filename,tmpfile);
+#endif  
 }
 
-void AliL3Transform::Init(){
-  //sector:
-  fNTimeBins = 446;
-  fNRowLow = 64;
-  fNRowUp = 112;
-  fNSectorLow = 36;
-  fNSectorUp = 36;
-  fNSector = 72;
-  fPadPitchWidthLow = 0.400000;
-  fPadPitchWidthUp = 0.600000;
-  fZWidth = 0.56599998474121093750;
-  fZSigma = 0.22880849748219134199;
+Bool_t AliL3Transform::MakeInitFile(Char_t *rootfilename,Char_t *filename)
+{
+  //Get the parameters from rootfile, and store it on the file "l3transform.config"
+  //which is being read by Init. fVersion will be fV_aliroot!
+  
+#ifndef use_aliroot
+  LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","Version")
+    <<"You have to compile with use_aliroot flag in order to use this function"<<ENDLOG;
+  return kFALSE;
+#else
+  TFile *rootfile = TFile::Open(rootfilename);
+  if(!rootfile)
+    {
+      LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","File")
+       <<"Could not open file: "<<rootfilename<<ENDLOG;
+      return kFALSE;
+    }
+  AliRun *gAlice = (AliRun*)rootfile->Get("gAlice");
+  if(!gAlice)
+    {
+      LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","File")
+       <<"No gAlice in file: "<<rootfilename<<ENDLOG;
+      return kFALSE;
+    }  
+  AliTPCParamSR *param=(AliTPCParamSR*)rootfile->Get(GetParamName());
+  if(!param)
+    {
+      LOG(AliL3Log::kWarning,"AliL3Transform::MakeInitFile","File")
+       <<"No TPC parameters found in \""<<rootfilename
+        <<"\", creating standard parameters "
+       <<"which might not be what you want!"<<ENDLOG;
+      param=new AliTPCParamSR;
+    }
 
-  //slices:
-  fNSlice = 36;
-  fNRow = 176;
-  fPi = 3.141592653589793;
-/*
-  for(Int_t i=0;i<36;i++){
-    fCos[i] = cos(fPi/9*i);
-    fSin[i] = sin(fPi/9*i);
+  AliTPCPRF2D    * prfinner    = new AliTPCPRF2D;
+  AliTPCPRF2D    * prfouter1   = new AliTPCPRF2D;
+  AliTPCPRF2D    * prfouter2   = new AliTPCPRF2D;  
+  AliTPCRF1D     * rf    = new AliTPCRF1D(kTRUE);
+  rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
+  rf->SetOffset(3*param->GetZSigma());
+  rf->Update();
+  
+  TDirectory *savedir=gDirectory;
+  TFile *prf_file = TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
+  if (!prf_file->IsOpen()) 
+    { 
+      LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","File")
+       <<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !"<<ENDLOG;
+      return kFALSE;
+    }
+  prfinner ->Read("prf_07504_Gati_056068_d02");
+  prfouter1->Read("prf_10006_Gati_047051_d03");
+  prfouter2->Read("prf_15006_Gati_047051_d03");  
+  prf_file->Close();
+  savedir->cd();
+  
+  param->SetInnerPRF(prfinner);
+  param->SetOuter1PRF(prfouter1); 
+  param->SetOuter2PRF(prfouter2);
+  param->SetTimeRF(rf);
+  
+  fNTimeBins = param->GetMaxTBin()+1;
+  fNRowLow = param->GetNRowLow();
+  fNRowUp  = param->GetNRowUp();
+  fNRowUp1 = param->GetNRowUp1();
+  fNRowUp2 = param->GetNRowUp2();
+  fNRow= fNRowLow + fNRowUp;
+  if(fNRow!=159){
+    LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","fNRow")
+      <<"Number of rows have changed in ALIROOT"<<ENDLOG;
+    return kFALSE;
   }
-*/
-  for(Int_t i=0;i<36;i++){
-    fCos[i] = cos( (2*fPi/18) * (i+0.5) );
-    fSin[i] = sin( (2*fPi/18) * (i+0.5) );
+  
+  fNSectorLow = param->GetNInnerSector();
+  fNSectorUp = param->GetNOuterSector();
+  fNSector = fNSectorLow + fNSectorUp;
+
+  //test whether they were changes to the rotation shift
+  fNRotShift=0;
+  Float_t irotshift = param->GetInnerAngleShift(); //shift angle
+  Float_t orotshift = param->GetOuterAngleShift(); //shift angle
+  const Float_t kDegtoRad = 0.01745329251994;
+  Int_t shift1=TMath::Nint(irotshift/kDegtoRad);
+  Int_t shift2=TMath::Nint(orotshift/kDegtoRad+0.1);
+  if((shift1!=shift2) || (shift1!=10)){
+    LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","Rotshiftangle")
+      <<"Rotation shift angle has changed in ALIROOT"<<ENDLOG;
+    return kFALSE;
+  } else {
+    fNRotShift=0.5; //our version of the shift angle
+  }
+  
+  fVersion=fV_aliroot;
+  SetBFieldFactor((Double_t)gAlice->Field()->Factor());
+  SetSolenoidBField((Double_t)gAlice->Field()->SolenoidField());
+  fPadPitchWidthLow=param->GetInnerPadPitchWidth();
+  fPadPitchWidthUp=param->GetOuterPadPitchWidth();
+  fZWidth=param->GetZWidth();
+  fZSigma=param->GetZSigma();
+  fZLength=param->GetZLength();
+  fZOffset=param->GetZOffset();
+  fDiffT=param->GetDiffT();
+  fDiffL=param->GetDiffL();
+  fOmegaTau=param->GetOmegaTau();
+  fInnerPadLength=param->GetInnerPadLength();
+  fOuter1PadLength=param->GetOuter1PadLength();
+  fOuter2PadLength=param->GetOuter2PadLength();
+  fInnerPRFSigma=param->GetInnerPRF()->GetSigmaX();
+  fOuter1PRFSigma=param->GetOuter1PRF()->GetSigmaX();
+  fOuter2PRFSigma=param->GetOuter2PRF()->GetSigmaX();
+  fTimeSigma=param->GetTimeRF()->GetSigma();
+  fADCSat=param->GetADCSat();
+  fZeroSup=param->GetZeroSup();
+  fNSlice=fNSectorLow;
+    
+  //now do the arrays
+  for(Int_t i=0;i<fNRow;i++){
+    Int_t sec,row;
+    if( i < fNRowLow){sec =0;row =i;}
+    else{sec = fNSectorLow;row =i-fNRowLow;}
+    fX[i]=param->GetPadRowRadii(sec,row);
+  } 
+  for(Int_t i=0;i<fNRow;i++){
+    Int_t sec,row;
+    if( i < fNRowLow){sec =0;row =i;}
+    else{sec = fNSectorLow;row =i-fNRowLow;}
+    fNPads[i]=param->GetNPads(sec,row);
+  }
+  for(Int_t i=0;i<fNSector;i++){
+    if(i<fNSectorLow) fSectorLow[i]=1;
+    else fSectorLow[i]=0;
+  }
+  return SaveInitFile(filename);
+#endif
+}
+
+Bool_t AliL3Transform::SaveInitFile(Char_t *filenamepath)
+{
+  //store the parameters in the file "filenamepath"
+  
+  FILE *f = fopen(filenamepath,"w");
+  if(!f){
+    LOG(AliL3Log::kError,"AliL3Transform::SaveInitFile","File")
+       <<"Could not open file: "<<filenamepath<<ENDLOG;
+    return kFALSE;
+  }
+
+  fprintf(f,"void AliL3Transform::Init(){\n");
+  fprintf(f,"  fVersion = %d;\n", fVersion); 
+  fprintf(f,"  fBFieldFactor = %.3f;\n",fBFieldFactor);
+  fprintf(f,"  fSolenoidBField = %.3f;\n",fSolenoidBField);
+  fprintf(f,"  fNTimeBins = %d;\n",fNTimeBins);
+  fprintf(f,"  fNRowLow = %d;\n",fNRowLow);
+  fprintf(f,"  fNRowUp = %d;\n",fNRowUp);
+  fprintf(f,"  fNRowUp1 = %d;\n",fNRowUp1);
+  fprintf(f,"  fNRowUp2 = %d;\n",fNRowUp2);
+  fprintf(f,"  fNSectorLow = %d;\n",fNSectorLow);
+  fprintf(f,"  fNSectorUp = %d;\n",fNSectorUp);
+  fprintf(f,"  fNSector = %d;\n",fNSector);
+  fprintf(f,"  fPadPitchWidthLow = %.3f;\n",fPadPitchWidthLow);
+  fprintf(f,"  fPadPitchWidthUp = %.3f;\n",fPadPitchWidthUp);
+  fprintf(f,"  fZWidth = %.4f;\n",fZWidth);
+  fprintf(f,"  fZSigma = %.4f;\n",fZSigma);
+  fprintf(f,"  fZLength = %.4f;\n",fZLength);
+  fprintf(f,"  fZOffset = %.4f;\n",fZOffset);
+  fprintf(f,"  fDiffT = %.4f;\n",fDiffT);
+  fprintf(f,"  fDiffL = %.4f;\n",fDiffL);
+  fprintf(f,"  fOmegaTau = %.4f;\n",fOmegaTau);
+  fprintf(f,"  fInnerPadLength = %.3f;\n",fInnerPadLength);
+  fprintf(f,"  fOuter1PadLength = %.3f;\n",fOuter1PadLength);
+  fprintf(f,"  fOuter2PadLength = %.3f;\n",fOuter2PadLength);
+  fprintf(f,"  fInnerPRFSigma = %.6f;\n",fInnerPRFSigma);
+  fprintf(f,"  fOuter1PRFSigma = %.6f;\n",fOuter1PRFSigma);
+  fprintf(f,"  fOuter2PRFSigma = %.6f;\n",fOuter2PRFSigma);
+  fprintf(f,"  fTimeSigma = %.6f;\n",fTimeSigma);
+  fprintf(f,"  fADCSat = %d;\n",fADCSat);
+  fprintf(f,"  fZeroSup = %d;\n",fZeroSup);
+  fprintf(f,"  fNSlice = %d;\n",fNSlice);
+  fprintf(f,"  fNRow = %d;\n",fNRow);
+  fprintf(f,"  fNRotShift = %.2f;\n",fNRotShift);
+  //now do the arrays
+  for(Int_t i=0;i<fNRow;i++){
+    fprintf(f,"  fX[%d] = %3.2f;\n",i,fX[i]);
+  } 
+  for(Int_t i=0;i<fNRow;i++){
+    fprintf(f,"  fNPads[%d] = %d;\n",i,fNPads[i]);
+  }
+
+  //Slice/Sector dont belong to aliroot, but we want to be flexible
+  for(Int_t i=0;i<fNSlice;i++){
+    fprintf(f,"  fSlice2Sector[%d][0] = %d;\n",i,fSlice2Sector[i][0]);
+    fprintf(f,"  fSlice2Sector[%d][1] = %d;\n",i,fSlice2Sector[i][1]);
+  }  
+  for(Int_t i=0;i<fNSector;i++){
+    fprintf(f,"  fSector2Slice[%d] = %d;\n",i,fSector2Slice[i]);
+  }  
+  for(Int_t i=0;i<fNSector;i++){
+    fprintf(f,"  fSectorLow[%d] = %d;\n",i,fSectorLow[i]);
+  }  
+
+  //Patches also dont really belong to the aliroot settings (but nevermind)
+  for(Int_t i=0;i<fNPatches;i++){
+    fprintf(f,"  fNRows[%d] = %d;\n",i,fNRows[i]);
+  }  
+  for(Int_t i=0;i<fNPatches;i++){
+    fprintf(f,"  fRows[%d][0] = %d;\n",i,fRows[i][0]);
+    fprintf(f,"  fRows[%d][1] = %d;\n",i,fRows[i][1]);
+  }  
+
+  //Rotation shift is an addon, too
+  for(Int_t i=0;i<fNSlice;i++){
+    Float_t cs = cos( (2*fPi/18) * (i+fNRotShift) );
+    fprintf(f,"  fCos[%d] = %.10f;\n",i,cs);
+  }
+  for(Int_t i=0;i<fNSlice;i++){
+    Float_t sn = sin( (2*fPi/18) * (i+fNRotShift) );
+    fprintf(f,"  fSin[%d] = %.10f;\n",i,sn);
   }
 
-  fX[0] = 84.570007324218750;
-  fX[1] = 85.320007324218750;
-  fX[2] = 86.070007324218750;
-  fX[3] = 86.820007324218750;
-  fX[4] = 87.570007324218750;
-  fX[5] = 88.320007324218750;
-  fX[6] = 89.070007324218750;
-  fX[7] = 89.820007324218750;
-  fX[8] = 90.570007324218750;
-  fX[9] = 91.320007324218750;
-  fX[10] = 92.070007324218750;
-  fX[11] = 92.820007324218750;
-  fX[12] = 93.570007324218750;
-  fX[13] = 94.320007324218750;
-  fX[14] = 95.070007324218750;
-  fX[15] = 95.820007324218750;
-  fX[16] = 96.570007324218750;
-  fX[17] = 97.320007324218750;
-  fX[18] = 98.070007324218750;
-  fX[19] = 98.820007324218750;
-  fX[20] = 99.570007324218750;
-  fX[21] = 100.320007324218750;
-  fX[22] = 101.070007324218750;
-  fX[23] = 101.820007324218750;
-  fX[24] = 102.570007324218750;
-  fX[25] = 103.320007324218750;
-  fX[26] = 104.070007324218750;
-  fX[27] = 104.820007324218750;
-  fX[28] = 105.570007324218750;
-  fX[29] = 106.320007324218750;
-  fX[30] = 107.070007324218750;
-  fX[31] = 107.820007324218750;
-  fX[32] = 108.570007324218750;
-  fX[33] = 109.320007324218750;
-  fX[34] = 110.070007324218750;
-  fX[35] = 110.820007324218750;
-  fX[36] = 111.570007324218750;
-  fX[37] = 112.320007324218750;
-  fX[38] = 113.070007324218750;
-  fX[39] = 113.820007324218750;
-  fX[40] = 114.570007324218750;
-  fX[41] = 115.320007324218750;
-  fX[42] = 116.070007324218750;
-  fX[43] = 116.820007324218750;
-  fX[44] = 117.570007324218750;
-  fX[45] = 118.320007324218750;
-  fX[46] = 119.070007324218750;
-  fX[47] = 119.820007324218750;
-  fX[48] = 120.570007324218750;
-  fX[49] = 121.320007324218750;
-  fX[50] = 122.070007324218750;
-  fX[51] = 122.820007324218750;
-  fX[52] = 123.570007324218750;
-  fX[53] = 124.320007324218750;
-  fX[54] = 125.070007324218750;
-  fX[55] = 125.820007324218750;
-  fX[56] = 126.570007324218750;
-  fX[57] = 127.320007324218750;
-  fX[58] = 128.070007324218750;
-  fX[59] = 128.820007324218750;
-  fX[60] = 129.570007324218750;
-  fX[61] = 130.320007324218750;
-  fX[62] = 131.070007324218750;
-  fX[63] = 131.820007324218750;
-  fX[64] = 135.054992675781250;
-  fX[65] = 136.054992675781250;
-  fX[66] = 137.054992675781250;
-  fX[67] = 138.054992675781250;
-  fX[68] = 139.054992675781250;
-  fX[69] = 140.054992675781250;
-  fX[70] = 141.054992675781250;
-  fX[71] = 142.054992675781250;
-  fX[72] = 143.054992675781250;
-  fX[73] = 144.054992675781250;
-  fX[74] = 145.054992675781250;
-  fX[75] = 146.054992675781250;
-  fX[76] = 147.054992675781250;
-  fX[77] = 148.054992675781250;
-  fX[78] = 149.054992675781250;
-  fX[79] = 150.054992675781250;
-  fX[80] = 151.054992675781250;
-  fX[81] = 152.054992675781250;
-  fX[82] = 153.054992675781250;
-  fX[83] = 154.054992675781250;
-  fX[84] = 155.054992675781250;
-  fX[85] = 156.054992675781250;
-  fX[86] = 157.054992675781250;
-  fX[87] = 158.054992675781250;
-  fX[88] = 159.054992675781250;
-  fX[89] = 160.054992675781250;
-  fX[90] = 161.054992675781250;
-  fX[91] = 162.054992675781250;
-  fX[92] = 163.054992675781250;
-  fX[93] = 164.054992675781250;
-  fX[94] = 165.054992675781250;
-  fX[95] = 166.054992675781250;
-  fX[96] = 167.054992675781250;
-  fX[97] = 168.054992675781250;
-  fX[98] = 169.054992675781250;
-  fX[99] = 170.054992675781250;
-  fX[100] = 171.054992675781250;
-  fX[101] = 172.054992675781250;
-  fX[102] = 173.054992675781250;
-  fX[103] = 174.054992675781250;
-  fX[104] = 175.054992675781250;
-  fX[105] = 176.054992675781250;
-  fX[106] = 177.054992675781250;
-  fX[107] = 178.054992675781250;
-  fX[108] = 179.054992675781250;
-  fX[109] = 180.054992675781250;
-  fX[110] = 181.054992675781250;
-  fX[111] = 182.054992675781250;
-  fX[112] = 183.054992675781250;
-  fX[113] = 184.054992675781250;
-  fX[114] = 185.054992675781250;
-  fX[115] = 186.054992675781250;
-  fX[116] = 187.054992675781250;
-  fX[117] = 188.054992675781250;
-  fX[118] = 189.054992675781250;
-  fX[119] = 190.054992675781250;
-  fX[120] = 191.054992675781250;
-  fX[121] = 192.054992675781250;
-  fX[122] = 193.054992675781250;
-  fX[123] = 194.054992675781250;
-  fX[124] = 195.054992675781250;
-  fX[125] = 196.054992675781250;
-  fX[126] = 197.054992675781250;
-  fX[127] = 198.054992675781250;
-  fX[128] = 199.054992675781250;
-  fX[129] = 200.054992675781250;
-  fX[130] = 201.054992675781250;
-  fX[131] = 202.054992675781250;
-  fX[132] = 203.054992675781250;
-  fX[133] = 204.054992675781250;
-  fX[134] = 205.054992675781250;
-  fX[135] = 206.054992675781250;
-  fX[136] = 207.054992675781250;
-  fX[137] = 208.054992675781250;
-  fX[138] = 209.054992675781250;
-  fX[139] = 210.054992675781250;
-  fX[140] = 211.054992675781250;
-  fX[141] = 212.054992675781250;
-  fX[142] = 213.054992675781250;
-  fX[143] = 214.054992675781250;
-  fX[144] = 215.054992675781250;
-  fX[145] = 216.054992675781250;
-  fX[146] = 217.054992675781250;
-  fX[147] = 218.054992675781250;
-  fX[148] = 219.054992675781250;
-  fX[149] = 220.054992675781250;
-  fX[150] = 221.054992675781250;
-  fX[151] = 222.054992675781250;
-  fX[152] = 223.054992675781250;
-  fX[153] = 224.054992675781250;
-  fX[154] = 225.054992675781250;
-  fX[155] = 226.054992675781250;
-  fX[156] = 227.054992675781250;
-  fX[157] = 228.054992675781250;
-  fX[158] = 229.054992675781250;
-  fX[159] = 230.054992675781250;
-  fX[160] = 231.054992675781250;
-  fX[161] = 232.054992675781250;
-  fX[162] = 233.054992675781250;
-  fX[163] = 234.054992675781250;
-  fX[164] = 235.054992675781250;
-  fX[165] = 236.054992675781250;
-  fX[166] = 237.054992675781250;
-  fX[167] = 238.054992675781250;
-  fX[168] = 239.054992675781250;
-  fX[169] = 240.054992675781250;
-  fX[170] = 241.054992675781250;
-  fX[171] = 242.054992675781250;
-  fX[172] = 243.054992675781250;
-  fX[173] = 244.054992675781250;
-  fX[174] = 245.054992675781250;
-  fX[175] = 246.054992675781250;
-  fNPads[0] = 67;
-  fNPads[1] = 67;
-  fNPads[2] = 67;
-  fNPads[3] = 69;
-  fNPads[4] = 69;
-  fNPads[5] = 69;
-  fNPads[6] = 71;
-  fNPads[7] = 71;
-  fNPads[8] = 71;
-  fNPads[9] = 73;
-  fNPads[10] = 73;
-  fNPads[11] = 73;
-  fNPads[12] = 75;
-  fNPads[13] = 75;
-  fNPads[14] = 75;
-  fNPads[15] = 77;
-  fNPads[16] = 77;
-  fNPads[17] = 77;
-  fNPads[18] = 79;
-  fNPads[19] = 79;
-  fNPads[20] = 79;
-  fNPads[21] = 81;
-  fNPads[22] = 81;
-  fNPads[23] = 81;
-  fNPads[24] = 83;
-  fNPads[25] = 83;
-  fNPads[26] = 83;
-  fNPads[27] = 85;
-  fNPads[28] = 85;
-  fNPads[29] = 85;
-  fNPads[30] = 87;
-  fNPads[31] = 87;
-  fNPads[32] = 87;
-  fNPads[33] = 89;
-  fNPads[34] = 89;
-  fNPads[35] = 89;
-  fNPads[36] = 91;
-  fNPads[37] = 91;
-  fNPads[38] = 91;
-  fNPads[39] = 93;
-  fNPads[40] = 93;
-  fNPads[41] = 93;
-  fNPads[42] = 95;
-  fNPads[43] = 95;
-  fNPads[44] = 95;
-  fNPads[45] = 97;
-  fNPads[46] = 97;
-  fNPads[47] = 97;
-  fNPads[48] = 99;
-  fNPads[49] = 99;
-  fNPads[50] = 99;
-  fNPads[51] = 101;
-  fNPads[52] = 101;
-  fNPads[53] = 101;
-  fNPads[54] = 103;
-  fNPads[55] = 103;
-  fNPads[56] = 103;
-  fNPads[57] = 105;
-  fNPads[58] = 105;
-  fNPads[59] = 105;
-  fNPads[60] = 107;
-  fNPads[61] = 107;
-  fNPads[62] = 107;
-  fNPads[63] = 109;
-  fNPads[64] = 73;
-  fNPads[65] = 75;
-  fNPads[66] = 75;
-  fNPads[67] = 75;
-  fNPads[68] = 77;
-  fNPads[69] = 77;
-  fNPads[70] = 77;
-  fNPads[71] = 77;
-  fNPads[72] = 79;
-  fNPads[73] = 79;
-  fNPads[74] = 79;
-  fNPads[75] = 81;
-  fNPads[76] = 81;
-  fNPads[77] = 81;
-  fNPads[78] = 83;
-  fNPads[79] = 83;
-  fNPads[80] = 83;
-  fNPads[81] = 83;
-  fNPads[82] = 85;
-  fNPads[83] = 85;
-  fNPads[84] = 85;
-  fNPads[85] = 87;
-  fNPads[86] = 87;
-  fNPads[87] = 87;
-  fNPads[88] = 87;
-  fNPads[89] = 89;
-  fNPads[90] = 89;
-  fNPads[91] = 89;
-  fNPads[92] = 91;
-  fNPads[93] = 91;
-  fNPads[94] = 91;
-  fNPads[95] = 93;
-  fNPads[96] = 93;
-  fNPads[97] = 93;
-  fNPads[98] = 93;
-  fNPads[99] = 95;
-  fNPads[100] = 95;
-  fNPads[101] = 95;
-  fNPads[102] = 97;
-  fNPads[103] = 97;
-  fNPads[104] = 97;
-  fNPads[105] = 97;
-  fNPads[106] = 99;
-  fNPads[107] = 99;
-  fNPads[108] = 99;
-  fNPads[109] = 101;
-  fNPads[110] = 101;
-  fNPads[111] = 101;
-  fNPads[112] = 103;
-  fNPads[113] = 103;
-  fNPads[114] = 103;
-  fNPads[115] = 103;
-  fNPads[116] = 105;
-  fNPads[117] = 105;
-  fNPads[118] = 105;
-  fNPads[119] = 107;
-  fNPads[120] = 107;
-  fNPads[121] = 107;
-  fNPads[122] = 107;
-  fNPads[123] = 109;
-  fNPads[124] = 109;
-  fNPads[125] = 109;
-  fNPads[126] = 111;
-  fNPads[127] = 111;
-  fNPads[128] = 111;
-  fNPads[129] = 113;
-  fNPads[130] = 113;
-  fNPads[131] = 113;
-  fNPads[132] = 113;
-  fNPads[133] = 115;
-  fNPads[134] = 115;
-  fNPads[135] = 115;
-  fNPads[136] = 117;
-  fNPads[137] = 117;
-  fNPads[138] = 117;
-  fNPads[139] = 117;
-  fNPads[140] = 119;
-  fNPads[141] = 119;
-  fNPads[142] = 119;
-  fNPads[143] = 121;
-  fNPads[144] = 121;
-  fNPads[145] = 121;
-  fNPads[146] = 123;
-  fNPads[147] = 123;
-  fNPads[148] = 123;
-  fNPads[149] = 123;
-  fNPads[150] = 125;
-  fNPads[151] = 125;
-  fNPads[152] = 125;
-  fNPads[153] = 127;
-  fNPads[154] = 127;
-  fNPads[155] = 127;
-  fNPads[156] = 127;
-  fNPads[157] = 129;
-  fNPads[158] = 129;
-  fNPads[159] = 129;
-  fNPads[160] = 131;
-  fNPads[161] = 131;
-  fNPads[162] = 131;
-  fNPads[163] = 133;
-  fNPads[164] = 133;
-  fNPads[165] = 133;
-  fNPads[166] = 133;
-  fNPads[167] = 135;
-  fNPads[168] = 135;
-  fNPads[169] = 135;
-  fNPads[170] = 137;
-  fNPads[171] = 137;
-  fNPads[172] = 137;
-  fNPads[173] = 137;
-  fNPads[174] = 139;
-  fNPads[175] = 139;
+  fprintf(f,"}\n");
+  fclose(f);
+
+  LOG(AliL3Log::kInformational,"AliL3Transform::SaveInitFile","File created")
+    <<"Init file \""<<filenamepath<<"\" created"<<ENDLOG;
+
+  return kTRUE;
+}
+
+Int_t AliL3Transform::GetNPads(Int_t row)
+{
+  if(row < 0 || row >= fNRow)
+    {
+      LOG(AliL3Log::kError,"AliL3Transform::GetNPads","Row")
+       <<AliL3Log::kDec<<"Wrong row "<<row<<ENDLOG;
+      return 0;
+    }
+
+  return fNPads[row];
+}
+
+Int_t AliL3Transform::GetFirstRow(Int_t patch)
+{
+  if(patch==-1)
+    return 0;
+  else if(patch < -1 || patch >= 6)
+    {
+      LOG(AliL3Log::kError,"AliL3Transform::GetFirstRow","Patch")
+       <<AliL3Log::kDec<<"Wrong patch "<<patch<<ENDLOG;
+      return 0;
+    }
+  else
+    return fRows[patch][0];
+}
+
+Int_t AliL3Transform::GetLastRow(Int_t patch)
+{
+  if(patch==-1)
+    return fRows[5][1];
+  else if(patch < -1 || patch >= 6)
+    {
+      LOG(AliL3Log::kError,"AliL3Transform::GetLastRow","Patch")
+       <<AliL3Log::kDec<<"Wrong patch "<<patch<<ENDLOG;
+      return 0;
+    }
+  else
+    return fRows[patch][1];
+}
+
+Int_t AliL3Transform::GetNRows(Int_t patch)
+{
+  if(patch==-1)
+    return fNRow;
+  else if(patch < -1 || patch >= 6)
+    {
+      LOG(AliL3Log::kError,"AliL3Transform::GetNRows","Patch")
+       <<AliL3Log::kDec<<"Wrong patch "<<patch<<ENDLOG;
+      return 0;
+    }
+  else
+    return fNRows[patch];
+}
+
+Int_t AliL3Transform::GetPadRow(Float_t xvalue)
+{
+  //Find the padrow number corresponding to cartesian _local_ x value
+
+  if(xvalue < 0 || xvalue > 250)
+    {
+      LOG(AliL3Log::kError,"AliL3Transform::GetPadRow","X-value")
+       <<AliL3Log::kDec<<"Suspicious x-value, make sure it is in local coordinate! "
+       <<xvalue<<ENDLOG;
+      return -1;
+    }
+  
+  Int_t x = (Int_t)rint(xvalue*10);
+  if(x < (Int_t)rint(fX[1]*10))
+    return 0;
+  else if(x > (Int_t)rint(fX[fNRow-2]*10))
+    return fNRow-1;
+  else
+    {
+      Int_t padrow=1; //Of course, a more clever algorithm could help here
+      while(padrow < fNRow-2)
+       {
+         if(x > (Int_t)rint(fX[padrow-1]*10) && x < (Int_t)rint(fX[padrow+1]*10))
+           break;
+         padrow++;
+       }
+      return padrow;
+    }
+}
+
+Int_t AliL3Transform::GetPatch(Int_t padrow)
+{
+  if(padrow < 0 || padrow >= fNRow)
+    {
+      LOG(AliL3Log::kError,"AliL3Transform::GetPatch","Padrow")
+       <<AliL3Log::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
+      return -2;
+    }
+  Int_t patch=0;
+  while(patch < fNPatches)
+    {
+      if(padrow >= fRows[patch][0] && padrow <= fRows[patch][1])
+       break;
+      patch++;
+    }
+  return patch;
+}
+
+Double_t AliL3Transform::GetPadLength(Int_t padrow)
+{
+  if(padrow >= fNRow){
+      LOG(AliL3Log::kError,"AliL3Transform::GetPadLength","Padrow")
+       <<AliL3Log::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
+      return 0;
+    }
+
+  if(padrow < fNRowLow)
+    return fInnerPadLength;
+  if(padrow >= fNRowLow && padrow < fNRowLow + fNRowUp1 - 1)
+    return fOuter1PadLength;
+  if(padrow >= fNRowLow + fNRowUp1 - 1)
+    return fOuter2PadLength;
+
+  //should never happen
+  LOG(AliL3Log::kError,"AliL3Transform::GetPadLength","Padrow")
+    <<AliL3Log::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
+  return -1.0; 
+}
+
+Double_t AliL3Transform::GetPadPitchWidth(Int_t patch)
+{
+  if(patch < 0 || patch > fNPatches)
+    {
+      LOG(AliL3Log::kError,"AliL3Transform::GetPadPitchWidth","patct")
+       <<AliL3Log::kDec<<"Wrong patch "<<patch<<ENDLOG;
+      return -1;
+    }
+  return patch < 2 ? fPadPitchWidthLow : fPadPitchWidthUp;  
+}
+
+Double_t AliL3Transform::GetParSigmaY2(Int_t padrow,Float_t z,Float_t angle)
+{
+  //Calculate the expected transverse cluster width as a function of 
+  //drift distance and crossing angle.
+  //z = local z-coordinate of cluster
+  //angle = track crossing angle with normal to padrow plane
+  //return value = sigma^2 (cartesian coordinates)
+
+  Double_t drift;
+  if(z > 0)
+    drift = fZLength - z;
+  else
+    drift = fZLength + z;
+  
+  Double_t t1 = GetPRFSigma(padrow)*GetPRFSigma(padrow);
+  Double_t t2 = fDiffT*fDiffT*drift;
+  Double_t t3 = GetPadLength(padrow)*GetPadLength(padrow)*tan(angle)*tan(angle)/12;
+  Double_t t4 = fAnodeWireSpacing*fAnodeWireSpacing*(tan(angle) - fOmegaTau)*(tan(angle) - fOmegaTau)/12;
+
+  return (t1 + t2 + t3 + t4);
+}
+
+Double_t AliL3Transform::GetParSigmaZ2(Int_t padrow,Float_t z,Float_t tgl)
+{
+  //Calculate the expected longitudinal cluster width as a function of 
+  //drift distance and track crossing angle.
+  //z = local z-coordinate of cluster
+  //tgl = tan(dipangle) 
+  //return value = sigma^2 (cartesian coordinates)
+
+  Double_t drift;
+  if(z > 0)
+    drift = AliL3Transform::GetZLength() - z;
+  else
+    drift = AliL3Transform::GetZLength() + z;
+  
+  Double_t t1 = fZSigma*fZSigma;
+  Double_t t2 = fDiffL*fDiffL*drift;
+  Double_t t3 = GetPadLength(padrow)*GetPadLength(padrow)*tgl*tgl/12;
+  
+  return (t1 + t2 + t3);
+}
+
+Double_t AliL3Transform::GetPRFSigma(Int_t padrow)
+{
+  if(padrow >= fNRow){
+    LOG(AliL3Log::kError,"AliL3Transform::GetPRFSigma","Padrow")
+      <<AliL3Log::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
+    return 0;
+  }
+  if(padrow < fNRowLow)
+    return fInnerPRFSigma;
+  if(padrow >= fNRowLow && padrow < fNRowLow + fNRowUp1 - 1)
+    return fOuter1PRFSigma;
+  if(padrow >= fNRowLow + fNRowUp1 - 1)
+    return fOuter2PRFSigma;
+
+  //should never happen
+  LOG(AliL3Log::kError,"AliL3Transform::GetPRFSigma","Padrow")
+    <<AliL3Log::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
+  return -1.; 
 }
 
 Double_t AliL3Transform::GetEta(Float_t *xyz)
@@ -412,87 +1334,148 @@ Double_t AliL3Transform::GetEta(Float_t *xyz)
   return eta;
 }
 
-Double_t AliL3Transform::GetEta(Int_t padrow,Int_t pad,Int_t time)
+void AliL3Transform::XYZtoRPhiEta(Float_t *rpe, Float_t *xyz)
+{
+  rpe[0] = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]+xyz[2]*xyz[2]);
+  rpe[1] = atan2(xyz[1],xyz[0]);
+  rpe[2] = 0.5 * log((rpe[0]+xyz[2])/(rpe[0]-xyz[2]));
+}
+
+Double_t AliL3Transform::GetEta(Int_t slice,Int_t padrow,Int_t pad,Int_t time)
 {
   Float_t xyz[3];
   Int_t sector,row;
-  Slice2Sector(0,padrow,sector,row);
+  Slice2Sector(slice,padrow,sector,row);
   Raw2Local(xyz,sector,row,pad,time);
   
   return GetEta(xyz);
 }
 
-
 Double_t AliL3Transform::GetPhi(Float_t *xyz)
 {
-  
   Double_t phi = atan2(xyz[1],xyz[0]);
-  //if(phi<0) phi=phi+2*TMath::Pi();
   return phi;
 }
 
-
-Bool_t AliL3Transform::Slice2Sector(Int_t slice, Int_t slicerow, Int_t & sector, Int_t &row) const{
-  if(slicerow<0&&slicerow>=fNRow) return kFALSE;
-  if(slice<0||slice>=fNSlice) return kFALSE;
+Bool_t AliL3Transform::Slice2Sector(Int_t slice, Int_t slicerow, Int_t & sector, Int_t &row)
+{
+  if(slicerow<0&&slicerow>=fNRow){
+    LOG(AliL3Log::kError,"AliL3Transform::Slice2Sector","Slicerow")
+      <<AliL3Log::kDec<<"Wrong slicerow "<<slicerow<<ENDLOG;
+    return kFALSE;
+  }
+  if(slice<0||slice>=fNSlice){
+    LOG(AliL3Log::kError,"AliL3Transform::Slice2Sector","Slice")
+      <<AliL3Log::kDec<<"Wrong slice "<<slice<<ENDLOG;
+    return kFALSE;
+  }
 
   if(slicerow<fNRowLow){
-    sector = slice;
+    sector = fSlice2Sector[slice][0];
     row    = slicerow;
   }
   else {
-    sector = slice+fNSlice;
+    sector = fSlice2Sector[slice][1];
     row    = slicerow-fNRowLow;
   }
+
   return kTRUE;
 }
 
-Bool_t AliL3Transform::Sector2Slice(Int_t & slice, Int_t  sector) const{
-  if(sector<0||sector>=fNSector) return kFALSE;
-  if(sector<fNSectorLow) slice = sector;
-  else          slice = sector - fNSectorLow;
+Bool_t AliL3Transform::Sector2Slice(Int_t & slice, Int_t  sector)
+{
+  if(sector<0||sector>=fNSector){
+    LOG(AliL3Log::kError,"AliL3Transform::Sector2Slice","Sector")
+      <<AliL3Log::kDec<<"Wrong sector "<<sector<<ENDLOG;
+    return kFALSE;
+  }
+
+  slice=fSector2Slice[sector];
+
   return kTRUE;
 }
 
-Bool_t AliL3Transform::Sector2Slice(Int_t & slice, Int_t & slicerow,Int_t  sector, Int_t row) const{
-  if(sector<0||sector>=fNSector||row<0) return kFALSE;
-  if(sector<fNSectorLow){
-    if(row>=fNRowLow) return kFALSE;
-    slice = sector;
+Bool_t AliL3Transform::Sector2Slice(Int_t & slice, Int_t & slicerow, Int_t sector, Int_t row)
+{
+  if(sector<0 || sector>=fNSector){
+    LOG(AliL3Log::kError,"AliL3Transform::Sector2Slice","Sector")
+      <<AliL3Log::kDec<<"Wrong sector "<<sector<<ENDLOG;
+    return kFALSE;
+  }
+  if(row<0){
+    LOG(AliL3Log::kError,"AliL3Transform::Sector2Slice","Row")
+      <<AliL3Log::kDec<<"Wrong row "<<row<<ENDLOG;
+    return kFALSE;
+  }
+
+  if(fSectorLow[sector]){
+    if(row>=fNRowLow){
+      LOG(AliL3Log::kError,"AliL3Transform::Sector2Slice","Row")
+       <<AliL3Log::kDec<<"Wrong row "<<row<<ENDLOG;
+      return kFALSE;
+    }
+    slice = fSector2Slice[sector];
     slicerow = row;
   }
   else{
-    if(row>=fNRowUp) return kFALSE;
-    slice = sector - fNSectorLow;
+    if(row>=fNRowUp){
+      LOG(AliL3Log::kError,"AliL3Transform::Sector2Slice","Row")
+       <<AliL3Log::kDec<<"Wrong row "<<row<<ENDLOG;
+      return kFALSE;
+    }
+    slice = fSector2Slice[sector];
     slicerow = row + fNRowLow;
   }
+
   return kTRUE;
 }
 
+Double_t AliL3Transform::GetMaxY(Int_t slicerow)
+{
+ if(slicerow < fNRowLow)
+     return fPadPitchWidthLow*fNPads[slicerow]/2; 
+ else
+     return fPadPitchWidthUp*fNPads[slicerow]/2;
+
+}
+
 Double_t AliL3Transform::Row2X(Int_t slicerow){
-  if(slicerow<0||slicerow>=fNRow) return 0;
+  if(slicerow<0||slicerow>=fNRow){
+    LOG(AliL3Log::kError,"AliL3Transform::Row2X","Slicerow")
+      <<AliL3Log::kDec<<"Wrong slicerow "<<slicerow<<ENDLOG;
+    return 0;
+  }
   return fX[slicerow];
 }
 
+Double_t AliL3Transform::GetZFast(Int_t slice, Int_t time, Float_t vertex)
+{
+  Double_t ret=0;
+  if(slice < 18)
+    ret=fZLength-fZWidth*time+fZOffset;
+  else
+    ret=fZWidth*time-fZOffset-fZLength;
+  return ret;
+}
+
 void AliL3Transform::Local2Global(Float_t *xyz,Int_t slice)
 {
   //Transformation to global coordinate system
   Float_t x0 = xyz[0];
   Float_t y0 = xyz[1];
-  Float_t cs,sn;
-  cs = fCos[slice];
-  sn = fSin[slice];
-  xyz[0]=x0*cs-y0*sn;
-  xyz[1]=x0*sn+y0*cs;
+
+  xyz[0]=x0*fCos[slice]-y0*fSin[slice];
+  xyz[1]=x0*fSin[slice]+y0*fCos[slice];
   xyz[2]=xyz[2];//global z=local z
 }
 
 void AliL3Transform::Local2GlobalAngle(Float_t *angle,Int_t slice){
-  angle[0] = fmod(angle[0]+(slice+0.5)*(2*fPi/18),2*fPi);
+  angle[0] = fmod(angle[0]+(slice+fNRotShift)*(2*fPi/18),2*fPi);
 }
 
 void AliL3Transform::Global2LocalAngle(Float_t *angle,Int_t slice){
-  angle[0] = angle[0]-(slice+0.5)*(2*fPi/18);
+  angle[0] = angle[0]-(slice+fNRotShift)*(2*fPi/18);
   if(angle[0]<0) angle[0]+=2*fPi;
 }
 
@@ -503,27 +1486,91 @@ void AliL3Transform::Raw2Local(Float_t *xyz,Int_t sector,Int_t row,Float_t pad,F
   Int_t slice,slicerow;
   Sector2Slice(slice, slicerow, sector, row);  
 
+  //X-Value
   xyz[0]=Row2X(slicerow); 
+
+  //Y-Value
   Int_t npads= fNPads[slicerow];
-  if(sector<fNSectorLow)
+
+  if(fSectorLow[sector])
     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthLow;
   else
     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthUp;
-  xyz[2]=fZWidth*time-3.*fZSigma;
-  Int_t sign=1;
-  
-  
+
+  //Z-Value (remember PULSA Delay)
   if(slice < 18)
-    sign = 1;
+    xyz[2]=fZLength-fZWidth*time+fZOffset;
   else
-    sign = -1;
+    xyz[2]=fZWidth*time-fZOffset-fZLength;
+}
+
+void AliL3Transform::Raw2Local(Float_t *xyz,Int_t sector,Int_t row,Int_t pad,Int_t time)
+{
+  //Transformation from rawdata to local coordinate system
   
-  xyz[2]=sign*(250.-xyz[2]);
+  Int_t slice,slicerow;
+  Sector2Slice(slice, slicerow, sector, row);  
+
+  //X-Value
+  xyz[0]=Row2X(slicerow); 
+
+  //Y-Value
+  Int_t npads= fNPads[slicerow];
+
+  if(fSectorLow[sector])
+    xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthLow;
+  else
+    xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthUp;
+
+  //Z-Value (remember PULSA Delay)
+  if(slice < 18)
+    xyz[2]=fZLength-fZWidth*time+fZOffset;
+  else
+    xyz[2]=fZWidth*time-fZOffset-fZLength;
+}
+
+void AliL3Transform::RawHLT2Local(Float_t *xyz,Int_t slice,
+                               Int_t slicerow,Float_t pad,Float_t time)
+{
+  //Transformation from HLT rawdata to local coordinate system
   
-  //Int_t nis=fNSectorLow;
-  //Int_t nos=fNSectorUp;
-  //if((sector<nis)/2 || ((sector-nis)<nos/2)) sign=1;
+  //X-Value
+  xyz[0]=Row2X(slicerow); 
+
+  //Y-Value
+  Int_t npads= fNPads[slicerow];
+  if(slicerow<fNRowLow)
+    xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthLow;
+  else
+    xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthUp;
+
+  //Z-Value
+  if(slice < 18)
+    xyz[2]=fZLength-fZWidth*time+fZOffset;
+  else
+    xyz[2]=fZWidth*time-fZOffset-fZLength;
+}
+
+void AliL3Transform::RawHLT2Local(Float_t *xyz,Int_t slice,
+                               Int_t slicerow,Int_t pad,Int_t time)
+{
+  //Transformation from HLT rawdata to local coordinate system
   
+  //X-Value
+  xyz[0]=Row2X(slicerow); 
+
+  //Y-Value
+  Int_t npads= fNPads[slicerow];
+  if(slicerow<fNRowLow)
+    xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthLow;
+  else
+    xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthUp;
+
+  //Z-Value
+  if(slice < 18)
+    xyz[2]=fZLength-fZWidth*time+fZOffset;
+  else
+    xyz[2]=fZWidth*time-fZOffset-fZLength;
 }
 
 void AliL3Transform::Local2Global(Float_t *xyz,Int_t sector,Int_t row)
@@ -531,37 +1578,41 @@ void AliL3Transform::Local2Global(Float_t *xyz,Int_t sector,Int_t row)
   //Transformation to global coordinate system
   Int_t slice,slicerow;
   Sector2Slice(slice, slicerow, sector, row);  
-  Float_t r=Row2X(slicerow);
-  Float_t cs = fCos[slice];
-  Float_t sn = fSin[slice];
-
-  xyz[0]=r*cs-xyz[1]*sn;
-  xyz[1]=r*sn+xyz[1]*cs;
+  Float_t r=Row2X(slicerow); //have to get x value first
+                             
+  xyz[0]=r*fCos[slice]-xyz[1]*fSin[slice];
+  xyz[1]=r*fSin[slice]+xyz[1]*fCos[slice];
   xyz[2]=xyz[2];//global z=local z
 }
 
-Double_t AliL3Transform::GetMaxY(Int_t slicerow)
+void AliL3Transform::LocHLT2Global(Float_t *xyz,Int_t slice,Int_t slicerow)
 {
- if(slicerow < fNRowLow)
-     return fPadPitchWidthLow*fNPads[slicerow]/2; 
- else
-     return fPadPitchWidthUp*fNPads[slicerow]/2;
+  //Transformation from HLT to global coordinate system
+  Float_t r=Row2X(slicerow); //have to get x value first
+                             
+  xyz[0]=r*fCos[slice]-xyz[1]*fSin[slice];
+  xyz[1]=r*fSin[slice]+xyz[1]*fCos[slice];
+  xyz[2]=xyz[2];//global z=local z
 }
 
-void AliL3Transform::Global2Local(Float_t *xyz,Int_t sector,Bool_t isSlice)
-{
-  
+void AliL3Transform::Global2Local(Float_t *xyz,Int_t sector)
+{ //check code
   Int_t slice;
-  if(!isSlice)
+  //if(!isSlice)
     Sector2Slice(slice, sector);  
-  else
-    slice = sector;
-  Float_t cs = fCos[slice];
-  Float_t sn = fSin[slice];
-  Float_t x1 = xyz[0]*cs + xyz[1]*sn;
-  Float_t y1 = -xyz[0]*sn + xyz[1]*cs;
+    //else
+    //slice = sector;
+
+  Float_t x1 =  xyz[0]*fCos[slice] + xyz[1]*fSin[slice];
+  Float_t y1 = -xyz[0]*fSin[slice] + xyz[1]*fCos[slice];
+  xyz[0] = x1;
+  xyz[1] = y1;
+}
+
+void AliL3Transform::Global2LocHLT(Float_t *xyz,Int_t slice)
+{
+  Float_t x1 =  xyz[0]*fCos[slice] + xyz[1]*fSin[slice];
+  Float_t y1 = -xyz[0]*fSin[slice] + xyz[1]*fCos[slice];
   xyz[0] = x1;
   xyz[1] = y1;
 }
@@ -569,29 +1620,72 @@ void AliL3Transform::Global2Local(Float_t *xyz,Int_t sector,Bool_t isSlice)
 void AliL3Transform::Raw2Global(Float_t *xyz,Int_t sector,Int_t row,Float_t pad,Float_t time)
 {
   //Transformation from raw to global coordinates
-  
   Raw2Local(xyz,sector,row,pad,time);
   Local2Global(xyz,sector,row);
 }
 
+void AliL3Transform::Raw2Global(Float_t *xyz,Int_t sector,Int_t row,Int_t pad,Int_t time)
+{
+  //Transformation from raw to global coordinates
+  Raw2Local(xyz,sector,row,pad,time);
+  Local2Global(xyz,sector,row);
+}
+
+void AliL3Transform::RawHLT2Global(Float_t *xyz,Int_t slice,
+                                   Int_t slicerow,Float_t pad,Float_t time)
+{
+  //Transformation from raw to global coordinates
+  RawHLT2Local(xyz,slice,slicerow,pad,time);
+  LocHLT2Global(xyz,slice,slicerow);
+}
+
+void AliL3Transform::RawHLT2Global(Float_t *xyz,Int_t slice,
+                                   Int_t slicerow,Int_t pad,Int_t time)
+{
+  //Transformation from raw to global coordinates
+  RawHLT2Local(xyz,slice,slicerow,pad,time);
+  LocHLT2Global(xyz,slice,slicerow);
+}
+
 void AliL3Transform::Local2Raw(Float_t *xyz,Int_t sector,Int_t row)
 {
   //Transformation from local coordinates to raw
-  
+
   Int_t slice,slicerow;
   Sector2Slice(slice, slicerow, sector, row);  
    
-  if(sector<fNSectorLow)
+  xyz[0]=slicerow;
+
+  if(fSectorLow[sector])
     xyz[1]=xyz[1]/fPadPitchWidthLow+0.5*(fNPads[slicerow]-1);
   else
     xyz[1]=xyz[1]/fPadPitchWidthUp+0.5*(fNPads[slicerow]-1);
-  Int_t sign=-1;
-  Int_t nis=fNSectorLow;
-  Int_t nos=fNSectorUp;
-  if ((sector<nis/2) || ((sector-nis)<nos/2)) sign=1; 
-  xyz[2]=250-sign*xyz[2];
-  xyz[2]=(xyz[2]+3.*fZSigma)/fZWidth;
+
+  if(slice < 18)
+    xyz[2]=(fZLength-xyz[2]+fZOffset)/fZWidth;
+  else
+    xyz[2]=(fZLength+xyz[2]+fZOffset)/fZWidth;
+}
+
+void AliL3Transform::LocHLT2Raw(Float_t *xyz,Int_t slice,Int_t slicerow)
+{
+  //Transformation from local coordinates to raw
+
+  xyz[0]=slicerow;
+
+  if(slicerow<fNRowLow)
+    xyz[1]=xyz[1]/fPadPitchWidthLow+0.5*(fNPads[slicerow]-1);
+  else
+    xyz[1]=xyz[1]/fPadPitchWidthUp+0.5*(fNPads[slicerow]-1);
+
+  if(slice < 18)
+    xyz[2]=(fZLength-xyz[2]+fZOffset)/fZWidth;
+  else
+    xyz[2]=(fZLength+xyz[2]+fZOffset)/fZWidth;
 }
 
 void AliL3Transform::Global2Raw(Float_t *xyz,Int_t sector,Int_t row)
@@ -600,5 +1694,65 @@ void AliL3Transform::Global2Raw(Float_t *xyz,Int_t sector,Int_t row)
 
   Global2Local(xyz,sector);
   Local2Raw(xyz,sector,row);
+}
+
+void AliL3Transform::Global2HLT(Float_t *xyz,Int_t slice,Int_t slicerow)
+{
+  //Transformation from global coordinates to raw. 
+
+  Global2LocHLT(xyz,slice);
+  LocHLT2Raw(xyz,slice,slicerow);
+}
+
+void AliL3Transform::PrintCompileOptions()
+{
+  cout << "Compiler (g++) version used: " << __GNUC__ << endl;
+
+#ifdef no_root
+  cout << "STANDALONE version: -Dno_root was given." << endl;
+#else
+  const Char_t *roottest="$ROOTSYS/bin/root -n -b -q  | grep Version | cut -b 17-25 | cut -d\" \" -f1";
+#ifdef use_aliroot
+#ifdef use_cvs
+  const Char_t *aliroottest="if test -n \"`cd $ALICE_ROOT/STEER/ && cvs stat AliRun.cxx | grep \"Sticky Tag\" | grep none`\"; then echo HEAD; else cd $ALICE_ROOT/STEER/ && cvs stat AliRun.cxx | grep \"Sticky Tag\" | cut -b 18- | cut -d\" \" -f1; fi";
+#else
+  const Char_t *aliroottest="Unknown";
+#endif
+  cout << "ALIROOT version: -Duse_aliroot and -Duse_root was given." << endl;
+  cout << "Root Version: " << ROOTVERSION << " found " << flush;
+  gSystem->Exec(roottest);
+
+  cout << "AliRoot Version: " << ALIROOTVERSION << " found " << flush;
+  gSystem->Exec(aliroottest);
+#else
+  cout << "ROOT version: -Duse_root was given." << endl;
+  cout << "Root Version: " << ROOTVERSION << " found " << flush;
+  gSystem->Exec(roottest);
+#endif
+#endif
+
+#ifdef do_mc
+  cout << "Using Monte Carlo Info: -Ddo_mc was given." << endl;
+#else
+  cout << "NOT using Monte Carlo Info: -Ddo_mc was not given." << endl;
+#endif
+
+#ifdef ROWHOUGH
+  cout << "Using row transformer version: -DROWHOUGH was given." << endl;
+#else
+  cout << "NOT using row transformer version: -DROWHOUGH was not given." << endl;
+#endif
+
+#ifdef use_newio
+  cout << "Using NEWIO version: -Duse_newio was given." << endl;
+#else
+  cout << "NOT using NEWIO version: -Duse_newio was not given." << endl;
+#endif
+
+#ifdef use_logging
+  cout << "Using logging classes (MLUC): -Duse_logging was given." << endl;
+#else
+  cout << "NOT using logging classes (MLUC): -Duse_logging not was given." << endl;
+#endif
 
 }