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