]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/src/AliL3Transform.cxx
Added support for static libraries,
[u/mrichter/AliRoot.git] / HLT / src / AliL3Transform.cxx
1 // @(#) $Id$
2
3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>, Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
4 //*-- Copyright &copy ALICE HLT Group
5
6
7 #include "AliL3StandardIncludes.h"
8 #include "dirent.h"
9
10 #ifdef use_aliroot
11 #include <AliRun.h>
12 #include <AliMagF.h>
13 #include <AliTPCParamSR.h>
14 #include <AliTPCPRF2D.h>
15 #include <AliTPCRF1D.h>
16 #endif
17 #ifdef use_root
18 #include <TFile.h>
19 #include <TUnixSystem.h>
20 #include <TTimeStamp.h>
21 #include <TError.h>
22 #endif
23
24 #include "AliL3Logging.h"
25 #include "AliL3Transform.h"
26
27 #if GCCVERSION == 3
28 using namespace std;
29 #endif
30
31 /** \class AliL3Transform 
32 <pre>
33 //_____________________________________________________________
34 // AliL3Transform
35 //
36 // Transformation class for ALICE TPC.
37 //
38 // Class which contains all detector specific parameters for the TPC,
39 // and different useful functions for coordinate transforms.
40 //
41 // The class is completely static, which means that no object needs
42 // to be instantiated. Function calls should then be done like, e.g.:
43 //
44 // Double_t eta = AliL3Transform::GetEta(xyz);
45 //
46 // IMPORTANT: If used as is, default detector parameters will be used,
47 //            and you really have to make sure that these correspond to
48 //            the AliROOT version you are currently working on!!
49 //            You should therefore always initialize the parameters by
50 //
51 //            AliL3Transform::Init(path);
52 // 
53 //            where path is a char*, giving the path to where file containing
54 //            the detector parameter is located. This file should be called
55 //            "l3transform.config", and can be created with the function MakeInitFile.
56 //            
57 //            You can also force reading the parameters from a AliTPCParam object
58 //            by setting the flag;
59 //
60 //            AliL3Transform::Init(path,kTRUE);
61 //
62 //            where path is a char* 
63 //            either providing the rootfile name containing the geometry or 
64 //            the path to the rootfile which should then be called alirunfile.root. 
65 //            Note that for both of these cases you have to
66 //            compile with USEPACKAGE=ALIROOT set (see level3code/Makefile.conf).
67 //
68 //            Currently, there are 4 versions of the Transformer:
69 //             fVersion==fV_aliroot: ALIROOT-head compatible
70 //             fVersion==fV_cosmics: Cosmics data run (2003) compatible
71 //             fVersion==fV_default: means no config file has been loaded
72 //             fVersion==fV_deprecated: dont use old (before July 2003) style of transformer
73 //
74 </pre>
75 */
76
77
78 ClassImp(AliL3Transform)
79
80
81 const Double_t AliL3Transform::fAnodeWireSpacing = 0.25; //Taken from the TDR
82 const Double_t AliL3Transform::fBFACT = 0.0029980;       //Conversion Factor
83 const Double_t AliL3Transform::fPi  =   3.141592653589793;
84 const Double_t AliL3Transform::f2Pi = 2*3.141592653589793;
85 const Double_t AliL3Transform::fPi2 = 0.5*3.141592653589793;
86 const Double_t AliL3Transform::fToDeg = 180/3.141592653589793;
87
88 //Defined by HLT and GSI
89 Int_t AliL3Transform::fNPatches = 6;
90 Int_t AliL3Transform::fRows[6][2] = {{0,29},{30,62},{63,90},{91,116},{117,139},{140,158}}; 
91 Int_t AliL3Transform::fNRows[6] = {30,33,28,26,23,19};
92
93 // The following definition is generated by MakeInitFile function
94 Double_t AliL3Transform::fBField = 0.2;
95 Double_t AliL3Transform::fSolenoidBField = 2;
96 Double_t AliL3Transform::fBFieldFactor = 1;
97 Int_t AliL3Transform::fVersion = fV_default;
98 Int_t AliL3Transform::fNTimeBins = 446;
99 Int_t AliL3Transform::fNRowLow = 63;
100 Int_t AliL3Transform::fNRowUp = 96;
101 Int_t AliL3Transform::fNRowUp1 = 64;
102 Int_t AliL3Transform::fNRowUp2 = 32;
103 Int_t AliL3Transform::fNSectorLow = 36;
104 Int_t AliL3Transform::fNSectorUp = 36;
105 Int_t AliL3Transform::fNSector = 72;
106 Double_t AliL3Transform::fPadPitchWidthLow = 0.4;
107 Double_t AliL3Transform::fPadPitchWidthUp = 0.6;
108 Double_t AliL3Transform::fZWidth = 0.5660;
109 Double_t AliL3Transform::fZSigma = 0.2288;
110 Double_t AliL3Transform::fZLength = 250.0000;
111 Double_t AliL3Transform::fZOffset = 0.6864;
112 Double_t AliL3Transform::fDiffT = 0.0220;
113 Double_t AliL3Transform::fDiffL = 0.0220;
114 Double_t AliL3Transform::fOmegaTau = 0.1450;
115 Double_t AliL3Transform::fInnerPadLength = 0.75;
116 Double_t AliL3Transform::fOuter1PadLength = 1.00;
117 Double_t AliL3Transform::fOuter2PadLength = 1.50;
118 Double_t AliL3Transform::fInnerPRFSigma = 0.203811;
119 Double_t AliL3Transform::fOuter1PRFSigma = 0.299325;
120 Double_t AliL3Transform::fOuter2PRFSigma = 0.299323;
121 Double_t AliL3Transform::fTimeSigma = 0.228809;
122 Int_t AliL3Transform::fADCSat = 1024;
123 Int_t AliL3Transform::fZeroSup = 0;
124 Int_t AliL3Transform::fNSlice = 36;
125 Int_t AliL3Transform::fNRow = 159;
126 Double_t AliL3Transform::fNRotShift = 0.5;
127 Int_t AliL3Transform::fSlice2Sector[36][2] = { { 0, 36}, 
128                                                { 1, 37}, 
129                                                { 2, 38}, 
130                                                { 3, 39}, 
131                                                { 4, 40}, 
132                                                { 5, 41}, 
133                                                { 6, 42}, 
134                                                { 7, 43}, 
135                                                { 8, 44}, 
136                                                { 9, 45}, 
137                                                {10, 46}, 
138                                                {11, 47}, 
139                                                {12, 48}, 
140                                                {13, 49}, 
141                                                {14, 50}, 
142                                                {15, 51}, 
143                                                {16, 52}, 
144                                                {17, 53}, 
145                                                {18, 54}, 
146                                                {19, 55}, 
147                                                {20, 56}, 
148                                                {21, 57}, 
149                                                {22, 58}, 
150                                                {23, 59}, 
151                                                {24, 60}, 
152                                                {25, 61}, 
153                                                {26, 62}, 
154                                                {27, 63}, 
155                                                {28, 64}, 
156                                                {29, 65}, 
157                                                {30, 66}, 
158                                                {31, 67}, 
159                                                {32, 68}, 
160                                                {33, 69}, 
161                                                {34, 70}, 
162                                                {35, 71}
163 };
164
165 Int_t AliL3Transform::fSector2Slice[72] = { 0, 
166                                             1, 
167                                             2, 
168                                             3, 
169                                             4, 
170                                             5, 
171                                             6, 
172                                             7, 
173                                             8, 
174                                             9, 
175                                             10, 
176                                             11, 
177                                             12, 
178                                             13, 
179                                             14, 
180                                             15, 
181                                             16, 
182                                             17, 
183                                             18, 
184                                             19, 
185                                             20, 
186                                             21, 
187                                             22, 
188                                             23, 
189                                             24, 
190                                             25, 
191                                             26, 
192                                             27, 
193                                             28, 
194                                             29, 
195                                             30, 
196                                             31, 
197                                             32,
198                                             33, 
199                                             34, 
200                                             35, 
201                                             0, 
202                                             1, 
203                                             2, 
204                                             3, 
205                                             4, 
206                                             5, 
207                                             6, 
208                                             7, 
209                                             8, 
210                                             9, 
211                                             10, 
212                                             11, 
213                                             12, 
214                                             13, 
215                                             14, 
216                                             15, 
217                                             16, 
218                                             17, 
219                                             18, 
220                                             19, 
221                                             20, 
222                                             21, 
223                                             22, 
224                                             23, 
225                                             24, 
226                                             25, 
227                                             26, 
228                                             27, 
229                                             28, 
230                                             29, 
231                                             30, 
232                                             31, 
233                                             32, 
234                                             33, 
235                                             34, 
236                                             35 
237 };
238
239 Int_t AliL3Transform::fSectorLow[72] = { 1, 
240                                          1, 
241                                          1, 
242                                          1, 
243                                          1, 
244                                          1, 
245                                          1, 
246                                          1, 
247                                          1, 
248                                          1, 
249                                          1, 
250                                          1, 
251                                          1, 
252                                          1, 
253                                          1, 
254                                          1, 
255                                          1, 
256                                          1, 
257                                          1, 
258                                          1, 
259                                          1, 
260                                          1, 
261                                          1, 
262                                          1, 
263                                          1, 
264                                          1, 
265                                          1, 
266                                          1, 
267                                          1, 
268                                          1, 
269                                          1, 
270                                          1, 
271                                          1,
272                                          1, 
273                                          1, 
274                                          1, 
275                                          0, 
276                                          0, 
277                                          0, 
278                                          0, 
279                                          0, 
280                                          0, 
281                                          0, 
282                                          0, 
283                                          0, 
284                                          0, 
285                                          0, 
286                                          0, 
287                                          0, 
288                                          0, 
289                                          0, 
290                                          0, 
291                                          0, 
292                                          0, 
293                                          0, 
294                                          0, 
295                                          0, 
296                                          0, 
297                                          0, 
298                                          0, 
299                                          0, 
300                                          0, 
301                                          0,     
302                                          0, 
303                                          0, 
304                                          0, 
305                                          0, 
306                                          0, 
307                                          0, 
308                                          0, 
309                                          0, 
310                                          0 
311 };
312
313 Double_t AliL3Transform::fX[159] = { 85.195,
314                                      85.945,
315                                      86.695,
316                                      87.445,
317                                      88.195,
318                                      88.945,
319                                      89.695,
320                                      90.445,
321                                      91.195,
322                                      91.945,
323                                      92.695,
324                                      93.445,
325                                      94.195,
326                                      94.945,
327                                      95.695,
328                                      96.445,
329                                      97.195,
330                                      97.945,
331                                      98.695,
332                                      99.445,
333                                      100.195,
334                                      100.945,
335                                      101.695,
336                                      102.445,
337                                      103.195,
338                                      103.945,
339                                      104.695,
340                                      105.445,
341                                      106.195,
342                                      106.945,
343                                      107.695,
344                                      108.445,
345                                      109.195,
346                                      109.945,
347                                      110.695,
348                                      111.445,
349                                      112.195,
350                                      112.945,
351                                      113.695,
352                                      114.445,
353                                      115.195,
354                                      115.945,
355                                      116.695,
356                                      117.445,
357                                      118.195,
358                                      118.945,
359                                      119.695,
360                                      120.445,
361                                      121.195,
362                                      121.945,
363                                      122.695,
364                                      123.445,
365                                      124.195,
366                                      124.945,
367                                      125.695,
368                                      126.445,
369                                      127.195,
370                                      127.945,
371                                      128.695,
372                                      129.445,
373                                      130.195,
374                                      130.945,
375                                      131.695,
376                                      135.180,
377                                      136.180,
378                                      137.180,
379                                      138.180,
380                                      139.180,
381                                      140.180,
382                                      141.180,
383                                      142.180,
384                                      143.180,
385                                      144.180,
386                                      145.180,
387                                      146.180,
388                                      147.180,
389                                      148.180,
390                                      149.180,
391                                      150.180,
392                                      151.180,
393                                      152.180,
394                                      153.180,
395                                      154.180,
396                                      155.180,
397                                      156.180,
398                                      157.180,
399                                      158.180,
400                                      159.180,
401                                      160.180,
402                                      161.180,
403                                      162.180,
404                                      163.180,
405                                      164.180,
406                                      165.180,
407                                      166.180,
408                                      167.180,
409                                      168.180,
410                                      169.180,
411                                      170.180,
412                                      171.180,
413                                      172.180,
414                                      173.180,
415                                      174.180,
416                                      175.180,
417                                      176.180,
418                                      177.180,
419                                      178.180,
420                                      179.180,
421                                      180.180,
422                                      181.180,
423                                      182.180,
424                                      183.180,
425                                      184.180,
426                                      185.180,
427                                      186.180,
428                                      187.180,
429                                      188.180,
430                                      189.180,
431                                      190.180,
432                                      191.180,
433                                      192.180,
434                                      193.180,
435                                      194.180,
436                                      195.180,
437                                      196.180,
438                                      197.180,
439                                      198.180,
440                                      199.430,
441                                      200.930,
442                                      202.430,
443                                      203.930,
444                                      205.430,
445                                      206.930,
446                                      208.430,
447                                      209.930,
448                                      211.430,
449                                      212.930,
450                                      214.430,
451                                      215.930,
452                                      217.430,
453                                      218.930,
454                                      220.430,
455                                      221.930,
456                                      223.430,
457                                      224.930,
458                                      226.430,
459                                      227.930,
460                                      229.430,
461                                      230.930,
462                                      232.430,
463                                      233.930,
464                                      235.430,
465                                      236.930,
466                                      238.430,
467                                      239.930,
468                                      241.430,
469                                      242.930,
470                                      244.430,
471                                      245.930
472 };
473
474 Int_t AliL3Transform::fNPads[159] = {67,
475                                      67,
476                                      69,
477                                      69,
478                                      69,
479                                      71,
480                                      71,
481                                      71,
482                                      73,
483                                      73,
484                                      73,
485                                      75,
486                                      75,
487                                      75,
488                                      77,
489                                      77,
490                                      77,
491                                      79,
492                                      79,
493                                      79,
494                                      81,
495                                      81,
496                                      81,
497                                      83,
498                                      83,
499                                      83,
500                                      85,
501                                      85,
502                                      85,
503                                      87,
504                                      87,
505                                      87,
506                                      89,
507                                      89,
508                                      89,
509                                      91,
510                                      91,
511                                      91,
512                                      93,
513                                      93,
514                                      93,
515                                      95,
516                                      95,
517                                      95,
518                                      97,
519                                      97,
520                                      97,
521                                      99,
522                                      99,
523                                      99,
524                                      99,
525                                      101,
526                                      101,
527                                      101,
528                                      103,
529                                      103,
530                                      103,
531                                      105,
532                                      105,
533                                      105,
534                                      107,
535                                      107,
536                                      107,
537                                      73,
538                                      75,
539                                      75,
540                                      75,
541                                      75,
542                                      77,
543                                      77,
544                                      77,
545                                      79,
546                                      79,
547                                      79,
548                                      81,
549                                      81,
550                                      81,
551                                      81,
552                                      83,
553                                      83,
554                                      83,
555                                      85,
556                                      85,
557                                      85,
558                                      85,
559                                      87,
560                                      87,
561                                      87,
562                                      89,
563                                      89,
564                                      89,
565                                      91,
566                                      91,
567                                      91,
568                                      91,
569                                      93,
570                                      93,
571                                      93,
572                                      95,
573                                      95,
574                                      95,
575                                      95,
576                                      97,
577                                      97,
578                                      97,
579                                      99,
580                                      99,
581                                      99,
582                                      101,
583                                      101,
584                                      101,
585                                      101,
586                                      103,
587                                      103,
588                                      103,
589                                      105,
590                                      105,
591                                      105,
592                                      105,
593                                      107,
594                                      107,
595                                      107,
596                                      109,
597                                      109,
598                                      109,
599                                      111,
600                                      111,
601                                      111,
602                                      113,
603                                      113,
604                                      113,
605                                      115,
606                                      115,
607                                      117,
608                                      117,
609                                      119,
610                                      119,
611                                      121,
612                                      121,
613                                      121,
614                                      123,
615                                      123,
616                                      125,
617                                      125,
618                                      127,
619                                      127,
620                                      127,
621                                      129,
622                                      129,
623                                      131,
624                                      131,
625                                      133,
626                                      133,
627                                      135,
628                                      135,
629                                      135,
630                                      137,
631                                      137,
632                                      139
633 };
634
635 Double_t AliL3Transform::fCos[36] = { 0.9848077297,
636                                       0.8660253882,
637                                       0.6427876353,
638                                       0.3420201540,
639                                       0.0000000000,
640                                       -0.3420201540,
641                                       -0.6427876353,
642                                       -0.8660253882,
643                                       -0.9848077297,
644                                       -0.9848077297,
645                                       -0.8660253882,
646                                       -0.6427876353,
647                                       -0.3420201540,
648                                       -0.0000000000,
649                                       0.3420201540,
650                                       0.6427876353,
651                                       0.8660253882,
652                                       0.9848077297,
653                                       0.9848077297,
654                                       0.8660253882,
655                                       0.6427876353,
656                                       0.3420201540,
657                                       0.0000000000,
658                                       -0.3420201540,
659                                       -0.6427876353,
660                                       -0.8660253882,
661                                       -0.9848077297,
662                                       -0.9848077297,
663                                       -0.8660253882,
664                                       -0.6427876353,
665                                       -0.3420201540,
666                                       -0.0000000000,
667                                       0.3420201540,
668                                       0.6427876353,
669                                       0.8660253882,
670                                       0.9848077297
671 };
672
673 Double_t AliL3Transform::fSin[36] = { 0.1736481786,
674                                       0.5000000000,
675                                       0.7660444379,
676                                       0.9396926165,
677                                       1.0000000000,
678                                       0.9396926165,
679                                       0.7660444379,
680                                       0.5000000000,
681                                       0.1736481786,
682                                       -0.1736481786,
683                                       -0.5000000000,
684                                       -0.7660444379,
685                                       -0.9396926165,
686                                       -1.0000000000,
687                                       -0.9396926165,
688                                       -0.7660444379,
689                                       -0.5000000000,
690                                       -0.1736481786,
691                                       0.1736481786,
692                                       0.5000000000,
693                                       0.7660444379,
694                                       0.9396926165,
695                                       1.0000000000,
696                                       0.9396926165,
697                                       0.7660444379,
698                                       0.5000000000,
699                                       0.1736481786,
700                                       -0.1736481786,
701                                       -0.5000000000,
702                                       -0.7660444379,
703                                       -0.9396926165,
704                                       -1.0000000000,
705                                       -0.9396926165,
706                                       -0.7660444379,
707                                       -0.5000000000,
708                                       -0.1736481786
709 };
710
711 Bool_t AliL3Transform::Init(Char_t* path,Bool_t UseAliTPCParam)
712 {
713   //Overwrite the parameters with values stored in file "l3transform.config" in path.
714   //If file does not exist, old default values will be used.
715   //If flag UseAliTPCParam is set, the parameters will be read from the the rootfile
716   //which then has to be called path/digitfile.root
717   
718   if(fVersion != fV_default)
719     LOG(AliL3Log::kWarning,"AliL3Transform::Init","Init values")
720       <<AliL3Log::kDec<<"You are initializing the parameters more than once; check your code please! "<<fVersion<<ENDLOG;
721   
722   if(UseAliTPCParam) //use rootfile to generate temporary init file
723     return ReadInit(path);
724
725   //create filename
726   Char_t pathname[1024];
727   strcpy(pathname,path);
728
729   //test whether provided path is the file itself
730   Int_t isdir = 0;
731   DIR *testdir=opendir(pathname);
732   if(testdir){
733     isdir=1;
734     closedir(testdir);
735   }
736
737   if(isdir) strcat(pathname,"/l3transform.config");
738
739   return ReadInitFile(pathname);
740 }
741
742 Bool_t AliL3Transform::ReadInitFile(Char_t* pathname)
743 {
744   //read transformer settings from pathname
745
746   FILE *fptr=fopen(pathname,"r");
747   if(!fptr){
748     LOG(AliL3Log::kWarning,"AliL3Transform::ReadInitFile","File Open")
749       <<"Pointer to Config File \""<<pathname<<"\" 0x0!"<<ENDLOG;
750     return kFALSE;
751   }
752
753   Char_t d1[250], d2[100], d3[100];
754   Int_t dummy=0;
755   Double_t ddummy=0.0;
756
757   while(!feof(fptr)) {
758     fscanf(fptr,"%s",d1);
759     if(strcmp(d1,"fVersion")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fVersion=dummy;}
760     else if(strcmp(d1,"fBFieldFactor")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fBFieldFactor=(Double_t)ddummy;}
761     else if(strcmp(d1,"fSolenoidBField")==0)
762       {
763         fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);
764         fSolenoidBField=(Double_t)ddummy;
765       }
766     else if(strcmp(d1,"fNTimeBins")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNTimeBins=(Int_t)dummy;}
767     else if(strcmp(d1,"fNRowLow")==0)
768       {
769         fscanf(fptr,"%s %d %s",d2,&dummy,d3);
770         fNRowLow=(Int_t)dummy;
771         if(fNRowLow != 63)
772           LOG(AliL3Log::kError,"AliL3Transform::ReadInitFile","Overflow")
773             <<"Number of inner PadRows should be 63! Check and fgrep the code for 63 to see the consequences of this major change!"<<ENDLOG;
774       }
775     else if(strcmp(d1,"fNRowUp")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowUp=(Int_t)dummy;}
776     else if(strcmp(d1,"fNRowUp1")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowUp1=(Int_t)dummy;}
777     else if(strcmp(d1,"fNRowUp2")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowUp2=(Int_t)dummy;}
778     else if(strcmp(d1,"fNSectorLow")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSectorLow=(Int_t)dummy;}
779     else if(strcmp(d1,"fNSectorUp")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSectorUp=(Int_t)dummy;}
780     else if(strcmp(d1,"fNSector")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSector=(Int_t)dummy;}
781     else if(strcmp(d1,"fPadPitchWidthLow")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fPadPitchWidthLow=(Double_t)ddummy;}
782     else if(strcmp(d1,"fPadPitchWidthUp")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fPadPitchWidthUp=(Double_t)ddummy;}
783     else if(strcmp(d1,"fZWidth")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZWidth=(Double_t)ddummy;}
784     else if(strcmp(d1,"fZSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZSigma=(Double_t)ddummy;}
785     else if(strcmp(d1,"fZLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZLength=(Double_t)ddummy;}
786     else if(strcmp(d1,"fZOffset")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZOffset=(Double_t)ddummy;}
787     else if(strcmp(d1,"fNSlice")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSlice=(Int_t)dummy;}
788     else if(strcmp(d1,"fDiffT")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fDiffT=(Double_t)ddummy;}
789     else if(strcmp(d1,"fDiffL")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fDiffL=(Double_t)ddummy;}
790     else if(strcmp(d1,"fOmegaTau")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOmegaTau=(Double_t)ddummy;}
791     else if(strcmp(d1,"fInnerPadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fInnerPadLength=(Double_t)ddummy;}
792     else if(strcmp(d1,"fOuter1PadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter1PadLength=(Double_t)ddummy;}
793     else if(strcmp(d1,"fOuter2PadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter2PadLength=(Double_t)ddummy;}
794     else if(strcmp(d1,"fInnerPRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fInnerPRFSigma=(Double_t)ddummy;}
795     else if(strcmp(d1,"fOuter1PRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter1PRFSigma=(Double_t)ddummy;}
796     else if(strcmp(d1,"fOuter2PRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter2PRFSigma=(Double_t)ddummy;}
797     else if(strcmp(d1,"fTimeSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fTimeSigma=(Double_t)ddummy;}
798     else if(strcmp(d1,"fADCSat")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fADCSat=(Int_t)dummy;}
799     else if(strcmp(d1,"fZeroSup")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fZeroSup=(Int_t)dummy;}
800     else if(strcmp(d1,"fNRow")==0){
801       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRow=(Int_t)dummy;
802       if(fNRow!=159){
803         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;
804       }
805     }
806     else if(strcmp(d1,"fNRotShift")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fNRotShift=(Double_t)ddummy;}
807     else if(strcmp(d1,"fX[0]")==0){
808       fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fX[0]=(Double_t)ddummy;
809       for(Int_t i=1;i<fNRow;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fX[i]=(Double_t)ddummy;}
810     }
811     else if(strcmp(d1,"fNPads[0]")==0){
812       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNPads[0]=(Int_t)dummy;
813       for(Int_t i=1;i<fNRow;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fNPads[i]=(Int_t)dummy;}
814     }
815     else if(strcmp(d1,"fNRows[0]")==0){
816       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRows[0]=(Int_t)dummy;
817       for(Int_t i=1;i<fNPatches;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fNRows[i]=(Int_t)dummy;}
818     }
819     else if(strcmp(d1,"fRows[0][0]")==0){
820       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fRows[0][0]=(Int_t)dummy;
821       fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fRows[0][1]=(Int_t)dummy;
822       for(Int_t i=1;i<fNPatches;i++){
823         fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fRows[i][0]=(Int_t)dummy;
824         fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fRows[i][1]=(Int_t)dummy;
825       }
826     }
827     else if(strcmp(d1,"fSlice2Sector[0][0]")==0){
828       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fSlice2Sector[0][0]=(Int_t)dummy;
829       fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fSlice2Sector[0][1]=(Int_t)dummy;
830       for(Int_t i=1;i<fNSlice;i++){
831         fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fSlice2Sector[i][0]=(Int_t)dummy;
832         fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fSlice2Sector[i][1]=(Int_t)dummy;
833       }
834     }
835     else if(strcmp(d1,"fSector2Slice[0]")==0){
836       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fSector2Slice[0]=(Int_t)dummy;
837       for(Int_t i=1;i<fNSector;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fSector2Slice[i]=(Int_t)dummy;}
838     }
839     else if(strcmp(d1,"fSectorLow[0]")==0){
840       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fSectorLow[0]=(Int_t)dummy;
841       for(Int_t i=1;i<fNSector;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fSectorLow[i]=(Int_t)dummy;}
842     }
843     else if(strcmp(d1,"fCos[0]")==0){
844       fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fCos[0]=(Double_t)ddummy;
845       for(Int_t i=1;i<fNSlice;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fCos[i]=(Double_t)ddummy;}
846     }
847     else if(strcmp(d1,"fSin[0]")==0){
848       fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fSin[0]=(Double_t)ddummy;
849       for(Int_t i=1;i<fNSlice;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fSin[i]=(Double_t)ddummy;}
850     }
851   }
852   fclose(fptr);
853
854   //The first multiplier gives the scale factor used to modify the field map 
855   //defined by the second multiplier.
856   fBField=fBFieldFactor*fSolenoidBField*0.1;
857
858   //Test if new config file has been used.
859   if(fVersion==fV_deprecated){
860     LOG(AliL3Log::kError,"AliL3Transform::ReadInitFile","Version")
861       <<"Version is deprecated, you have to create a new config file."<<ENDLOG;
862     return kFALSE;
863   }
864
865   LOG(AliL3Log::kInformational,"AliL3Transform::ReadInitFile","Config")
866     <<"Successfully loaded values from config file \""<<pathname<<"\""<<ENDLOG;
867
868   return kTRUE;
869 }
870
871 Bool_t AliL3Transform::ReadInit(Char_t *path)
872 {
873   //Read all the parameters from a aliroot file, and store it in a temporary 
874   //file which is read by Init. Use this if you want to read the parameters from
875   //the rootfile "every" time.
876   
877 #ifndef use_aliroot
878   LOG(AliL3Log::kError,"AliL3Transform::ReadInit","Version")
879     <<"You have to compile with use_aliroot flag in order to read from AliROOT file"<<ENDLOG;
880   return kFALSE;
881 #else
882   Char_t filename[1024];
883   //first test whether provided path is the rootfile itself
884   Int_t saveErrIgLevel=gErrorIgnoreLevel;
885   gErrorIgnoreLevel=kFatal; //dont report errors
886   TFile *rootfile = TFile::Open(path);
887   if(!rootfile || rootfile->IsZombie()) 
888     { //ok assume its path to alirunfile file
889       sprintf(filename,"%s/alirunfile.root",path); //create rootfile name
890     } else { //path contains itself the rootfile name
891       rootfile->Close();
892       sprintf(filename,"%s",path); 
893     }
894   gErrorIgnoreLevel=saveErrIgLevel;
895
896   //finally make dummy init file /tmp/$USER/l3transform.config-`date`
897   Char_t tmppath[1024];
898   sprintf(tmppath,"/tmp/%s",gSystem->Getenv("USER"));
899   gSystem->mkdir(tmppath);
900   TTimeStamp time;
901   Char_t tmpfile[1024];
902   sprintf(tmpfile,"%s/l3transform.config-%d",tmppath,(Int_t)time.GetSec());
903   return MakeInitFile(filename,tmpfile);
904 #endif  
905 }
906
907 Bool_t AliL3Transform::MakeInitFile(Char_t *rootfilename,Char_t *filename)
908 {
909   //Get the parameters from rootfile, and store it on the file "l3transform.config"
910   //which is being read by Init. fVersion will be fV_aliroot!
911   
912 #ifndef use_aliroot
913   LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","Version")
914     <<"You have to compile with use_aliroot flag in order to use this function"<<ENDLOG;
915   return kFALSE;
916 #else
917   TFile *rootfile = TFile::Open(rootfilename);
918   if(!rootfile)
919     {
920       LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","File")
921         <<"Could not open file: "<<rootfilename<<ENDLOG;
922       return kFALSE;
923     }
924   AliRun *gAlice = (AliRun*)rootfile->Get("gAlice");
925   if(!gAlice)
926     {
927       LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","File")
928         <<"No gAlice in file: "<<rootfilename<<ENDLOG;
929       return kFALSE;
930     }  
931   AliTPCParamSR *param=(AliTPCParamSR*)rootfile->Get(GetParamName());
932   if(!param)
933     {
934       LOG(AliL3Log::kWarning,"AliL3Transform::MakeInitFile","File")
935         <<"No TPC parameters found in \""<<rootfilename
936         <<"\", creating standard parameters "
937         <<"which might not be what you want!"<<ENDLOG;
938       param=new AliTPCParamSR;
939     }
940
941   AliTPCPRF2D    * prfinner    = new AliTPCPRF2D;
942   AliTPCPRF2D    * prfouter1   = new AliTPCPRF2D;
943   AliTPCPRF2D    * prfouter2   = new AliTPCPRF2D;  
944   AliTPCRF1D     * rf    = new AliTPCRF1D(kTRUE);
945   rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
946   rf->SetOffset(3*param->GetZSigma());
947   rf->Update();
948   
949   TDirectory *savedir=gDirectory;
950   TFile *prf_file = TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
951   if (!prf_file->IsOpen()) 
952     { 
953       LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","File")
954         <<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !"<<ENDLOG;
955       return kFALSE;
956     }
957   prfinner ->Read("prf_07504_Gati_056068_d02");
958   prfouter1->Read("prf_10006_Gati_047051_d03");
959   prfouter2->Read("prf_15006_Gati_047051_d03");  
960   prf_file->Close();
961   savedir->cd();
962   
963   param->SetInnerPRF(prfinner);
964   param->SetOuter1PRF(prfouter1); 
965   param->SetOuter2PRF(prfouter2);
966   param->SetTimeRF(rf);
967   
968   fNTimeBins = param->GetMaxTBin()+1;
969   fNRowLow = param->GetNRowLow();
970   fNRowUp  = param->GetNRowUp();
971   fNRowUp1 = param->GetNRowUp1();
972   fNRowUp2 = param->GetNRowUp2();
973   fNRow= fNRowLow + fNRowUp;
974   if(fNRow!=159){
975     LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","fNRow")
976       <<"Number of rows have changed in ALIROOT"<<ENDLOG;
977     return kFALSE;
978   }
979   
980   fNSectorLow = param->GetNInnerSector();
981   fNSectorUp = param->GetNOuterSector();
982   fNSector = fNSectorLow + fNSectorUp;
983
984   //test whether they were changes to the rotation shift
985   fNRotShift=0;
986   Float_t irotshift = param->GetInnerAngleShift(); //shift angle
987   Float_t orotshift = param->GetOuterAngleShift(); //shift angle
988   const Float_t kDegtoRad = 0.01745329251994;
989   Int_t shift1=TMath::Nint(irotshift/kDegtoRad);
990   Int_t shift2=TMath::Nint(orotshift/kDegtoRad+0.1);
991   if((shift1!=shift2) || (shift1!=10)){
992     LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","Rotshiftangle")
993       <<"Rotation shift angle has changed in ALIROOT"<<ENDLOG;
994     return kFALSE;
995   } else {
996     fNRotShift=0.5; //our version of the shift angle
997   }
998   
999   fVersion=fV_aliroot;
1000   SetBFieldFactor((Double_t)gAlice->Field()->Factor());
1001   SetSolenoidBField((Double_t)gAlice->Field()->SolenoidField());
1002   fPadPitchWidthLow=param->GetInnerPadPitchWidth();
1003   fPadPitchWidthUp=param->GetOuterPadPitchWidth();
1004   fZWidth=param->GetZWidth();
1005   fZSigma=param->GetZSigma();
1006   fZLength=param->GetZLength();
1007   fZOffset=param->GetZOffset();
1008   fDiffT=param->GetDiffT();
1009   fDiffL=param->GetDiffL();
1010   fOmegaTau=param->GetOmegaTau();
1011   fInnerPadLength=param->GetInnerPadLength();
1012   fOuter1PadLength=param->GetOuter1PadLength();
1013   fOuter2PadLength=param->GetOuter2PadLength();
1014   fInnerPRFSigma=param->GetInnerPRF()->GetSigmaX();
1015   fOuter1PRFSigma=param->GetOuter1PRF()->GetSigmaX();
1016   fOuter2PRFSigma=param->GetOuter2PRF()->GetSigmaX();
1017   fTimeSigma=param->GetTimeRF()->GetSigma();
1018   fADCSat=param->GetADCSat();
1019   fZeroSup=param->GetZeroSup();
1020   fNSlice=fNSectorLow;
1021     
1022   //now do the arrays
1023   for(Int_t i=0;i<fNRow;i++){
1024     Int_t sec,row;
1025     if( i < fNRowLow){sec =0;row =i;}
1026     else{sec = fNSectorLow;row =i-fNRowLow;}
1027     fX[i]=param->GetPadRowRadii(sec,row);
1028   } 
1029   for(Int_t i=0;i<fNRow;i++){
1030     Int_t sec,row;
1031     if( i < fNRowLow){sec =0;row =i;}
1032     else{sec = fNSectorLow;row =i-fNRowLow;}
1033     fNPads[i]=param->GetNPads(sec,row);
1034   }
1035   for(Int_t i=0;i<fNSector;i++){
1036     if(i<fNSectorLow) fSectorLow[i]=1;
1037     else fSectorLow[i]=0;
1038   }
1039   return SaveInitFile(filename);
1040 #endif
1041 }
1042
1043 Bool_t AliL3Transform::SaveInitFile(Char_t *filenamepath)
1044 {
1045   //store the parameters in the file "filenamepath"
1046   
1047   FILE *f = fopen(filenamepath,"w");
1048   if(!f){
1049     LOG(AliL3Log::kError,"AliL3Transform::SaveInitFile","File")
1050         <<"Could not open file: "<<filenamepath<<ENDLOG;
1051     return kFALSE;
1052   }
1053
1054   fprintf(f,"void AliL3Transform::Init(){\n");
1055   fprintf(f,"  fVersion = %d;\n", fVersion); 
1056   fprintf(f,"  fBFieldFactor = %.3f;\n",fBFieldFactor);
1057   fprintf(f,"  fSolenoidBField = %.3f;\n",fSolenoidBField);
1058   fprintf(f,"  fNTimeBins = %d;\n",fNTimeBins);
1059   fprintf(f,"  fNRowLow = %d;\n",fNRowLow);
1060   fprintf(f,"  fNRowUp = %d;\n",fNRowUp);
1061   fprintf(f,"  fNRowUp1 = %d;\n",fNRowUp1);
1062   fprintf(f,"  fNRowUp2 = %d;\n",fNRowUp2);
1063   fprintf(f,"  fNSectorLow = %d;\n",fNSectorLow);
1064   fprintf(f,"  fNSectorUp = %d;\n",fNSectorUp);
1065   fprintf(f,"  fNSector = %d;\n",fNSector);
1066   fprintf(f,"  fPadPitchWidthLow = %.3f;\n",fPadPitchWidthLow);
1067   fprintf(f,"  fPadPitchWidthUp = %.3f;\n",fPadPitchWidthUp);
1068   fprintf(f,"  fZWidth = %.4f;\n",fZWidth);
1069   fprintf(f,"  fZSigma = %.4f;\n",fZSigma);
1070   fprintf(f,"  fZLength = %.4f;\n",fZLength);
1071   fprintf(f,"  fZOffset = %.4f;\n",fZOffset);
1072   fprintf(f,"  fDiffT = %.4f;\n",fDiffT);
1073   fprintf(f,"  fDiffL = %.4f;\n",fDiffL);
1074   fprintf(f,"  fOmegaTau = %.4f;\n",fOmegaTau);
1075   fprintf(f,"  fInnerPadLength = %.3f;\n",fInnerPadLength);
1076   fprintf(f,"  fOuter1PadLength = %.3f;\n",fOuter1PadLength);
1077   fprintf(f,"  fOuter2PadLength = %.3f;\n",fOuter2PadLength);
1078   fprintf(f,"  fInnerPRFSigma = %.6f;\n",fInnerPRFSigma);
1079   fprintf(f,"  fOuter1PRFSigma = %.6f;\n",fOuter1PRFSigma);
1080   fprintf(f,"  fOuter2PRFSigma = %.6f;\n",fOuter2PRFSigma);
1081   fprintf(f,"  fTimeSigma = %.6f;\n",fTimeSigma);
1082   fprintf(f,"  fADCSat = %d;\n",fADCSat);
1083   fprintf(f,"  fZeroSup = %d;\n",fZeroSup);
1084   fprintf(f,"  fNSlice = %d;\n",fNSlice);
1085   fprintf(f,"  fNRow = %d;\n",fNRow);
1086   fprintf(f,"  fNRotShift = %.2f;\n",fNRotShift);
1087   //now do the arrays
1088   for(Int_t i=0;i<fNRow;i++){
1089     fprintf(f,"  fX[%d] = %3.2f;\n",i,fX[i]);
1090   } 
1091   for(Int_t i=0;i<fNRow;i++){
1092     fprintf(f,"  fNPads[%d] = %d;\n",i,fNPads[i]);
1093   }
1094
1095   //Slice/Sector dont belong to aliroot, but we want to be flexible
1096   for(Int_t i=0;i<fNSlice;i++){
1097     fprintf(f,"  fSlice2Sector[%d][0] = %d;\n",i,fSlice2Sector[i][0]);
1098     fprintf(f,"  fSlice2Sector[%d][1] = %d;\n",i,fSlice2Sector[i][1]);
1099   }  
1100   for(Int_t i=0;i<fNSector;i++){
1101     fprintf(f,"  fSector2Slice[%d] = %d;\n",i,fSector2Slice[i]);
1102   }  
1103   for(Int_t i=0;i<fNSector;i++){
1104     fprintf(f,"  fSectorLow[%d] = %d;\n",i,fSectorLow[i]);
1105   }  
1106
1107   //Patches also dont really belong to the aliroot settings (but nevermind)
1108   for(Int_t i=0;i<fNPatches;i++){
1109     fprintf(f,"  fNRows[%d] = %d;\n",i,fNRows[i]);
1110   }  
1111   for(Int_t i=0;i<fNPatches;i++){
1112     fprintf(f,"  fRows[%d][0] = %d;\n",i,fRows[i][0]);
1113     fprintf(f,"  fRows[%d][1] = %d;\n",i,fRows[i][1]);
1114   }  
1115
1116   //Rotation shift is an addon, too
1117   for(Int_t i=0;i<fNSlice;i++){
1118     Float_t cs = cos( (2*fPi/18) * (i+fNRotShift) );
1119     fprintf(f,"  fCos[%d] = %.10f;\n",i,cs);
1120   }
1121   for(Int_t i=0;i<fNSlice;i++){
1122     Float_t sn = sin( (2*fPi/18) * (i+fNRotShift) );
1123     fprintf(f,"  fSin[%d] = %.10f;\n",i,sn);
1124   }
1125
1126   fprintf(f,"}\n");
1127   fclose(f);
1128
1129   LOG(AliL3Log::kInformational,"AliL3Transform::SaveInitFile","File created")
1130     <<"Init file \""<<filenamepath<<"\" created"<<ENDLOG;
1131
1132   return kTRUE;
1133 }
1134
1135 Int_t AliL3Transform::GetNPads(Int_t row)
1136 {
1137   if(row < 0 || row >= fNRow)
1138     {
1139       LOG(AliL3Log::kError,"AliL3Transform::GetNPads","Row")
1140         <<AliL3Log::kDec<<"Wrong row "<<row<<ENDLOG;
1141       return 0;
1142     }
1143
1144   return fNPads[row];
1145 }
1146
1147 Int_t AliL3Transform::GetFirstRow(Int_t patch)
1148 {
1149   if(patch==-1)
1150     return 0;
1151   else if(patch < -1 || patch >= 6)
1152     {
1153       LOG(AliL3Log::kError,"AliL3Transform::GetFirstRow","Patch")
1154         <<AliL3Log::kDec<<"Wrong patch "<<patch<<ENDLOG;
1155       return 0;
1156     }
1157   else
1158     return fRows[patch][0];
1159 }
1160
1161 Int_t AliL3Transform::GetLastRow(Int_t patch)
1162 {
1163   if(patch==-1)
1164     return fRows[5][1];
1165   else if(patch < -1 || patch >= 6)
1166     {
1167       LOG(AliL3Log::kError,"AliL3Transform::GetLastRow","Patch")
1168         <<AliL3Log::kDec<<"Wrong patch "<<patch<<ENDLOG;
1169       return 0;
1170     }
1171   else
1172     return fRows[patch][1];
1173 }
1174
1175 Int_t AliL3Transform::GetNRows(Int_t patch)
1176 {
1177   if(patch==-1)
1178     return fNRow;
1179   else if(patch < -1 || patch >= 6)
1180     {
1181       LOG(AliL3Log::kError,"AliL3Transform::GetNRows","Patch")
1182         <<AliL3Log::kDec<<"Wrong patch "<<patch<<ENDLOG;
1183       return 0;
1184     }
1185   else
1186     return fNRows[patch];
1187 }
1188
1189 Int_t AliL3Transform::GetPadRow(Float_t xvalue)
1190 {
1191   //Find the padrow number corresponding to cartesian _local_ x value
1192
1193   if(xvalue < 0 || xvalue > 250)
1194     {
1195       LOG(AliL3Log::kError,"AliL3Transform::GetPadRow","X-value")
1196         <<AliL3Log::kDec<<"Suspicious x-value, make sure it is in local coordinate! "
1197         <<xvalue<<ENDLOG;
1198       return -1;
1199     }
1200   
1201   Int_t x = (Int_t)rint(xvalue*10);
1202   if(x < (Int_t)rint(fX[1]*10))
1203     return 0;
1204   else if(x > (Int_t)rint(fX[fNRow-2]*10))
1205     return fNRow-1;
1206   else
1207     {
1208       Int_t padrow=1; //Of course, a more clever algorithm could help here
1209       while(padrow < fNRow-2)
1210         {
1211           if(x > (Int_t)rint(fX[padrow-1]*10) && x < (Int_t)rint(fX[padrow+1]*10))
1212             break;
1213           padrow++;
1214         }
1215       return padrow;
1216     }
1217 }
1218
1219 Int_t AliL3Transform::GetPatch(Int_t padrow)
1220 {
1221   if(padrow < 0 || padrow >= fNRow)
1222     {
1223       LOG(AliL3Log::kError,"AliL3Transform::GetPatch","Padrow")
1224         <<AliL3Log::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
1225       return -2;
1226     }
1227   Int_t patch=0;
1228   while(patch < fNPatches)
1229     {
1230       if(padrow >= fRows[patch][0] && padrow <= fRows[patch][1])
1231         break;
1232       patch++;
1233     }
1234   return patch;
1235 }
1236
1237 Double_t AliL3Transform::GetPadLength(Int_t padrow)
1238 {
1239   if(padrow >= fNRow){
1240       LOG(AliL3Log::kError,"AliL3Transform::GetPadLength","Padrow")
1241         <<AliL3Log::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
1242       return 0;
1243     }
1244
1245   if(padrow < fNRowLow)
1246     return fInnerPadLength;
1247   if(padrow >= fNRowLow && padrow < fNRowLow + fNRowUp1 - 1)
1248     return fOuter1PadLength;
1249   if(padrow >= fNRowLow + fNRowUp1 - 1)
1250     return fOuter2PadLength;
1251
1252   //should never happen
1253   LOG(AliL3Log::kError,"AliL3Transform::GetPadLength","Padrow")
1254     <<AliL3Log::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
1255   return -1.0; 
1256 }
1257
1258 Double_t AliL3Transform::GetPadPitchWidth(Int_t patch)
1259 {
1260   if(patch < 0 || patch > fNPatches)
1261     {
1262       LOG(AliL3Log::kError,"AliL3Transform::GetPadPitchWidth","patct")
1263         <<AliL3Log::kDec<<"Wrong patch "<<patch<<ENDLOG;
1264       return -1;
1265     }
1266   return patch < 2 ? fPadPitchWidthLow : fPadPitchWidthUp;  
1267 }
1268
1269 Double_t AliL3Transform::GetParSigmaY2(Int_t padrow,Float_t z,Float_t angle)
1270 {
1271   //Calculate the expected transverse cluster width as a function of 
1272   //drift distance and crossing angle.
1273   //z = local z-coordinate of cluster
1274   //angle = track crossing angle with normal to padrow plane
1275   //return value = sigma^2 (cartesian coordinates)
1276
1277   Double_t drift;
1278   if(z > 0)
1279     drift = fZLength - z;
1280   else
1281     drift = fZLength + z;
1282   
1283   Double_t t1 = GetPRFSigma(padrow)*GetPRFSigma(padrow);
1284   Double_t t2 = fDiffT*fDiffT*drift;
1285   Double_t t3 = GetPadLength(padrow)*GetPadLength(padrow)*tan(angle)*tan(angle)/12;
1286   Double_t t4 = fAnodeWireSpacing*fAnodeWireSpacing*(tan(angle) - fOmegaTau)*(tan(angle) - fOmegaTau)/12;
1287
1288   return (t1 + t2 + t3 + t4);
1289 }
1290
1291 Double_t AliL3Transform::GetParSigmaZ2(Int_t padrow,Float_t z,Float_t tgl)
1292 {
1293   //Calculate the expected longitudinal cluster width as a function of 
1294   //drift distance and track crossing angle.
1295   //z = local z-coordinate of cluster
1296   //tgl = tan(dipangle) 
1297   //return value = sigma^2 (cartesian coordinates)
1298
1299   Double_t drift;
1300   if(z > 0)
1301     drift = AliL3Transform::GetZLength() - z;
1302   else
1303     drift = AliL3Transform::GetZLength() + z;
1304   
1305   Double_t t1 = fZSigma*fZSigma;
1306   Double_t t2 = fDiffL*fDiffL*drift;
1307   Double_t t3 = GetPadLength(padrow)*GetPadLength(padrow)*tgl*tgl/12;
1308   
1309   return (t1 + t2 + t3);
1310 }
1311
1312 Double_t AliL3Transform::GetPRFSigma(Int_t padrow)
1313 {
1314   if(padrow >= fNRow){
1315     LOG(AliL3Log::kError,"AliL3Transform::GetPRFSigma","Padrow")
1316       <<AliL3Log::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
1317     return 0;
1318   }
1319   if(padrow < fNRowLow)
1320     return fInnerPRFSigma;
1321   if(padrow >= fNRowLow && padrow < fNRowLow + fNRowUp1 - 1)
1322     return fOuter1PRFSigma;
1323   if(padrow >= fNRowLow + fNRowUp1 - 1)
1324     return fOuter2PRFSigma;
1325
1326   //should never happen
1327   LOG(AliL3Log::kError,"AliL3Transform::GetPRFSigma","Padrow")
1328     <<AliL3Log::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
1329   return -1.; 
1330 }
1331
1332 Double_t AliL3Transform::GetEta(Float_t *xyz)
1333 {
1334   Double_t r3 = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]+xyz[2]*xyz[2]);
1335   Double_t eta = 0.5 * log((r3+xyz[2])/(r3-xyz[2]));
1336   return eta;
1337 }
1338
1339 void AliL3Transform::XYZtoRPhiEta(Float_t *rpe, Float_t *xyz)
1340 {
1341   rpe[0] = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]+xyz[2]*xyz[2]);
1342   rpe[1] = atan2(xyz[1],xyz[0]);
1343   rpe[2] = 0.5 * log((rpe[0]+xyz[2])/(rpe[0]-xyz[2]));
1344 }
1345
1346 Double_t AliL3Transform::GetEta(Int_t slice,Int_t padrow,Int_t pad,Int_t time)
1347 {
1348   Float_t xyz[3];
1349   Int_t sector,row;
1350   Slice2Sector(slice,padrow,sector,row);
1351   Raw2Local(xyz,sector,row,pad,time);
1352   
1353   return GetEta(xyz);
1354 }
1355
1356 Double_t AliL3Transform::GetPhi(Float_t *xyz)
1357 {
1358   Double_t phi = atan2(xyz[1],xyz[0]);
1359   return phi;
1360 }
1361
1362 Bool_t AliL3Transform::Slice2Sector(Int_t slice, Int_t slicerow, Int_t & sector, Int_t &row)
1363 {
1364   if(slicerow<0&&slicerow>=fNRow){
1365     LOG(AliL3Log::kError,"AliL3Transform::Slice2Sector","Slicerow")
1366       <<AliL3Log::kDec<<"Wrong slicerow "<<slicerow<<ENDLOG;
1367     return kFALSE;
1368   }
1369   if(slice<0||slice>=fNSlice){
1370     LOG(AliL3Log::kError,"AliL3Transform::Slice2Sector","Slice")
1371       <<AliL3Log::kDec<<"Wrong slice "<<slice<<ENDLOG;
1372     return kFALSE;
1373   }
1374
1375   if(slicerow<fNRowLow){
1376     sector = fSlice2Sector[slice][0];
1377     row    = slicerow;
1378   }
1379   else {
1380     sector = fSlice2Sector[slice][1];
1381     row    = slicerow-fNRowLow;
1382   }
1383
1384   return kTRUE;
1385 }
1386
1387 Bool_t AliL3Transform::Sector2Slice(Int_t & slice, Int_t  sector)
1388 {
1389   if(sector<0||sector>=fNSector){
1390     LOG(AliL3Log::kError,"AliL3Transform::Sector2Slice","Sector")
1391       <<AliL3Log::kDec<<"Wrong sector "<<sector<<ENDLOG;
1392     return kFALSE;
1393   }
1394
1395   slice=fSector2Slice[sector];
1396
1397   return kTRUE;
1398 }
1399
1400 Bool_t AliL3Transform::Sector2Slice(Int_t & slice, Int_t & slicerow, Int_t sector, Int_t row)
1401 {
1402   if(sector<0 || sector>=fNSector){
1403     LOG(AliL3Log::kError,"AliL3Transform::Sector2Slice","Sector")
1404       <<AliL3Log::kDec<<"Wrong sector "<<sector<<ENDLOG;
1405     return kFALSE;
1406   }
1407   if(row<0){
1408     LOG(AliL3Log::kError,"AliL3Transform::Sector2Slice","Row")
1409       <<AliL3Log::kDec<<"Wrong row "<<row<<ENDLOG;
1410     return kFALSE;
1411   }
1412
1413   if(fSectorLow[sector]){
1414     if(row>=fNRowLow){
1415       LOG(AliL3Log::kError,"AliL3Transform::Sector2Slice","Row")
1416         <<AliL3Log::kDec<<"Wrong row "<<row<<ENDLOG;
1417       return kFALSE;
1418     }
1419     slice = fSector2Slice[sector];
1420     slicerow = row;
1421   }
1422   else{
1423     if(row>=fNRowUp){
1424       LOG(AliL3Log::kError,"AliL3Transform::Sector2Slice","Row")
1425         <<AliL3Log::kDec<<"Wrong row "<<row<<ENDLOG;
1426       return kFALSE;
1427     }
1428     slice = fSector2Slice[sector];
1429     slicerow = row + fNRowLow;
1430   }
1431
1432   return kTRUE;
1433 }
1434
1435 Double_t AliL3Transform::GetMaxY(Int_t slicerow)
1436 {
1437  if(slicerow < fNRowLow)
1438      return fPadPitchWidthLow*fNPads[slicerow]/2; 
1439  
1440  else
1441      return fPadPitchWidthUp*fNPads[slicerow]/2;
1442
1443 }
1444
1445 Double_t AliL3Transform::Row2X(Int_t slicerow){
1446   if(slicerow<0||slicerow>=fNRow){
1447     LOG(AliL3Log::kError,"AliL3Transform::Row2X","Slicerow")
1448       <<AliL3Log::kDec<<"Wrong slicerow "<<slicerow<<ENDLOG;
1449     return 0;
1450   }
1451   return fX[slicerow];
1452 }
1453
1454 Double_t AliL3Transform::GetZFast(Int_t slice, Int_t time, Float_t vertex)
1455 {
1456   Double_t ret=0;
1457   if(slice < 18)
1458     ret=fZLength-fZWidth*time+fZOffset;
1459   else
1460     ret=fZWidth*time-fZOffset-fZLength;
1461   return ret;
1462 }
1463
1464 void AliL3Transform::Local2Global(Float_t *xyz,Int_t slice)
1465 {
1466   //Transformation to global coordinate system
1467   Float_t x0 = xyz[0];
1468   Float_t y0 = xyz[1];
1469
1470   xyz[0]=x0*fCos[slice]-y0*fSin[slice];
1471   xyz[1]=x0*fSin[slice]+y0*fCos[slice];
1472   xyz[2]=xyz[2];//global z=local z
1473 }
1474
1475 void AliL3Transform::Local2GlobalAngle(Float_t *angle,Int_t slice){
1476   angle[0] = fmod(angle[0]+(slice+fNRotShift)*(2*fPi/18),2*fPi);
1477 }
1478
1479 void AliL3Transform::Global2LocalAngle(Float_t *angle,Int_t slice){
1480   angle[0] = angle[0]-(slice+fNRotShift)*(2*fPi/18);
1481   if(angle[0]<0) angle[0]+=2*fPi;
1482 }
1483
1484 void AliL3Transform::Raw2Local(Float_t *xyz,Int_t sector,Int_t row,Float_t pad,Float_t time)
1485 {
1486   //Transformation from rawdata to local coordinate system
1487   
1488   Int_t slice,slicerow;
1489   Sector2Slice(slice, slicerow, sector, row);  
1490
1491   //X-Value
1492   xyz[0]=Row2X(slicerow); 
1493
1494   //Y-Value
1495   Int_t npads= fNPads[slicerow];
1496
1497   if(fSectorLow[sector])
1498     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthLow;
1499   else
1500     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthUp;
1501
1502   //Z-Value (remember PULSA Delay)
1503   if(slice < 18)
1504     xyz[2]=fZLength-fZWidth*time+fZOffset;
1505   else
1506     xyz[2]=fZWidth*time-fZOffset-fZLength;
1507 }
1508
1509 void AliL3Transform::Raw2Local(Float_t *xyz,Int_t sector,Int_t row,Int_t pad,Int_t time)
1510 {
1511   //Transformation from rawdata to local coordinate system
1512   
1513   Int_t slice,slicerow;
1514   Sector2Slice(slice, slicerow, sector, row);  
1515
1516   //X-Value
1517   xyz[0]=Row2X(slicerow); 
1518
1519   //Y-Value
1520   Int_t npads= fNPads[slicerow];
1521
1522   if(fSectorLow[sector])
1523     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthLow;
1524   else
1525     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthUp;
1526
1527   //Z-Value (remember PULSA Delay)
1528   if(slice < 18)
1529     xyz[2]=fZLength-fZWidth*time+fZOffset;
1530   else
1531     xyz[2]=fZWidth*time-fZOffset-fZLength;
1532 }
1533
1534 void AliL3Transform::RawHLT2Local(Float_t *xyz,Int_t slice,
1535                                Int_t slicerow,Float_t pad,Float_t time)
1536 {
1537   //Transformation from HLT rawdata to local coordinate system
1538   
1539   //X-Value
1540   xyz[0]=Row2X(slicerow); 
1541
1542   //Y-Value
1543   Int_t npads= fNPads[slicerow];
1544   if(slicerow<fNRowLow)
1545     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthLow;
1546   else
1547     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthUp;
1548
1549   //Z-Value
1550   if(slice < 18)
1551     xyz[2]=fZLength-fZWidth*time+fZOffset;
1552   else
1553     xyz[2]=fZWidth*time-fZOffset-fZLength;
1554 }
1555
1556 void AliL3Transform::RawHLT2Local(Float_t *xyz,Int_t slice,
1557                                Int_t slicerow,Int_t pad,Int_t time)
1558 {
1559   //Transformation from HLT rawdata to local coordinate system
1560   
1561   //X-Value
1562   xyz[0]=Row2X(slicerow); 
1563
1564   //Y-Value
1565   Int_t npads= fNPads[slicerow];
1566   if(slicerow<fNRowLow)
1567     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthLow;
1568   else
1569     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthUp;
1570
1571   //Z-Value
1572   if(slice < 18)
1573     xyz[2]=fZLength-fZWidth*time+fZOffset;
1574   else
1575     xyz[2]=fZWidth*time-fZOffset-fZLength;
1576 }
1577
1578 void AliL3Transform::Local2Global(Float_t *xyz,Int_t sector,Int_t row)
1579 {
1580   //Transformation to global coordinate system
1581   Int_t slice,slicerow;
1582   Sector2Slice(slice, slicerow, sector, row);  
1583   Float_t r=Row2X(slicerow); //have to get x value first
1584                              
1585   xyz[0]=r*fCos[slice]-xyz[1]*fSin[slice];
1586   xyz[1]=r*fSin[slice]+xyz[1]*fCos[slice];
1587   xyz[2]=xyz[2];//global z=local z
1588 }
1589
1590 void AliL3Transform::LocHLT2Global(Float_t *xyz,Int_t slice,Int_t slicerow)
1591 {
1592   //Transformation from HLT to global coordinate system
1593   Float_t r=Row2X(slicerow); //have to get x value first
1594                              
1595   xyz[0]=r*fCos[slice]-xyz[1]*fSin[slice];
1596   xyz[1]=r*fSin[slice]+xyz[1]*fCos[slice];
1597   xyz[2]=xyz[2];//global z=local z
1598 }
1599
1600 void AliL3Transform::Global2Local(Float_t *xyz,Int_t sector)
1601 { //check code
1602   Int_t slice;
1603   //if(!isSlice)
1604     Sector2Slice(slice, sector);  
1605     //else
1606     //slice = sector;
1607
1608   Float_t x1 =  xyz[0]*fCos[slice] + xyz[1]*fSin[slice];
1609   Float_t y1 = -xyz[0]*fSin[slice] + xyz[1]*fCos[slice];
1610   xyz[0] = x1;
1611   xyz[1] = y1;
1612 }
1613
1614 void AliL3Transform::Global2LocHLT(Float_t *xyz,Int_t slice)
1615 {
1616   Float_t x1 =  xyz[0]*fCos[slice] + xyz[1]*fSin[slice];
1617   Float_t y1 = -xyz[0]*fSin[slice] + xyz[1]*fCos[slice];
1618   xyz[0] = x1;
1619   xyz[1] = y1;
1620 }
1621
1622 void AliL3Transform::Raw2Global(Float_t *xyz,Int_t sector,Int_t row,Float_t pad,Float_t time)
1623 {
1624   //Transformation from raw to global coordinates
1625  
1626   Raw2Local(xyz,sector,row,pad,time);
1627   Local2Global(xyz,sector,row);
1628 }
1629
1630 void AliL3Transform::Raw2Global(Float_t *xyz,Int_t sector,Int_t row,Int_t pad,Int_t time)
1631 {
1632   //Transformation from raw to global coordinates
1633  
1634   Raw2Local(xyz,sector,row,pad,time);
1635   Local2Global(xyz,sector,row);
1636 }
1637
1638 void AliL3Transform::RawHLT2Global(Float_t *xyz,Int_t slice,
1639                                    Int_t slicerow,Float_t pad,Float_t time)
1640 {
1641   //Transformation from raw to global coordinates
1642  
1643   RawHLT2Local(xyz,slice,slicerow,pad,time);
1644   LocHLT2Global(xyz,slice,slicerow);
1645 }
1646
1647 void AliL3Transform::RawHLT2Global(Float_t *xyz,Int_t slice,
1648                                    Int_t slicerow,Int_t pad,Int_t time)
1649 {
1650   //Transformation from raw to global coordinates
1651  
1652   RawHLT2Local(xyz,slice,slicerow,pad,time);
1653   LocHLT2Global(xyz,slice,slicerow);
1654 }
1655
1656 void AliL3Transform::Local2Raw(Float_t *xyz,Int_t sector,Int_t row)
1657 {
1658   //Transformation from local coordinates to raw
1659
1660   Int_t slice,slicerow;
1661   Sector2Slice(slice, slicerow, sector, row);  
1662    
1663   xyz[0]=slicerow;
1664
1665   if(fSectorLow[sector])
1666     xyz[1]=xyz[1]/fPadPitchWidthLow+0.5*(fNPads[slicerow]-1);
1667   else
1668     xyz[1]=xyz[1]/fPadPitchWidthUp+0.5*(fNPads[slicerow]-1);
1669
1670   if(slice < 18)
1671     xyz[2]=(fZLength-xyz[2]+fZOffset)/fZWidth;
1672   else
1673     xyz[2]=(fZLength+xyz[2]+fZOffset)/fZWidth;
1674 }
1675
1676 void AliL3Transform::LocHLT2Raw(Float_t *xyz,Int_t slice,Int_t slicerow)
1677 {
1678   //Transformation from local coordinates to raw
1679
1680   xyz[0]=slicerow;
1681
1682   if(slicerow<fNRowLow)
1683     xyz[1]=xyz[1]/fPadPitchWidthLow+0.5*(fNPads[slicerow]-1);
1684   else
1685     xyz[1]=xyz[1]/fPadPitchWidthUp+0.5*(fNPads[slicerow]-1);
1686
1687   if(slice < 18)
1688     xyz[2]=(fZLength-xyz[2]+fZOffset)/fZWidth;
1689   else
1690     xyz[2]=(fZLength+xyz[2]+fZOffset)/fZWidth;
1691 }
1692
1693 void AliL3Transform::Global2Raw(Float_t *xyz,Int_t sector,Int_t row)
1694 {
1695   //Transformation from global coordinates to raw. 
1696
1697   Global2Local(xyz,sector);
1698   Local2Raw(xyz,sector,row);
1699 }
1700
1701 void AliL3Transform::Global2HLT(Float_t *xyz,Int_t slice,Int_t slicerow)
1702 {
1703   //Transformation from global coordinates to raw. 
1704
1705   Global2LocHLT(xyz,slice);
1706   LocHLT2Raw(xyz,slice,slicerow);
1707 }
1708
1709 void AliL3Transform::PrintCompileOptions()
1710 {
1711   cout << "Compiler (g++) version used: " << GCCVERSION << endl;
1712
1713 #ifdef no_root
1714   cout << "STANDALONE version: -Dno_root was given." << endl;
1715 #else
1716   const Char_t *roottest="$ROOTSYS/bin/root -n -b -q  | grep Version | cut -b 17-25 | cut -d\" \" -f1";
1717 #ifdef use_aliroot
1718 #ifdef use_cvs
1719   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";
1720 #else
1721   const Char_t *aliroottest="Unknown";
1722 #endif
1723   cout << "ALIROOT version: -Duse_aliroot and -Duse_root was given." << endl;
1724   cout << "Root Version: " << ROOTVERSION << " found " << flush;
1725   gSystem->Exec(roottest);
1726
1727   cout << "AliRoot Version: " << ALIROOTVERSION << " found " << flush;
1728   gSystem->Exec(aliroottest);
1729 #else
1730   cout << "ROOT version: -Duse_root was given." << endl;
1731   cout << "Root Version: " << ROOTVERSION << " found " << flush;
1732   gSystem->Exec(roottest);
1733 #endif
1734 #endif
1735
1736 #ifdef do_mc
1737   cout << "Using Monte Carlo Info: -Ddo_mc was given." << endl;
1738 #else
1739   cout << "NOT using Monte Carlo Info: -Ddo_mc was not given." << endl;
1740 #endif
1741
1742 #ifdef use_logging
1743   cout << "Using logging classes (MLUC): -Duse_logging was given." << endl;
1744 #else
1745   cout << "NOT using logging classes (MLUC): -Duse_logging not was given." << endl;
1746 #endif
1747 }