]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCTransform.cxx
The present commit corresponds to an important change in the way the
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCTransform.cxx
1
2 // @(#) $Id$
3 // Original: AliHLTTransform.cxx,v 1.53 2005/06/14 10:55:21 cvetan 
4
5 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>, Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
6 //*-- Copyright &copy ALICE HLT Group
7
8
9 #include "dirent.h"
10
11 #ifdef use_aliroot
12 #include <AliRun.h>
13 #include <AliMagF.h>
14 #include <AliTPCParamSR.h>
15 #include <AliTPCPRF2D.h>
16 #include <AliTPCRF1D.h>
17 #endif
18 #ifdef use_root
19 #include <TError.h>
20 #include <TFile.h>
21 #include <TGeoGlobalMagField.h>
22 #include <TTimeStamp.h>
23 #include <TUnixSystem.h>
24 #endif
25
26 #include "AliHLTTPCLogging.h"
27 #include "AliHLTTPCTransform.h"
28
29 #if defined(__GNUC__) && __GNUC__ >= 3
30 using namespace std;
31 #endif
32
33 /** \class AliHLTTPCTransform 
34 <pre>
35 //_____________________________________________________________
36 // AliHLTTPCTransform
37 //
38 // Transformation class for ALICE TPC.
39 //
40 // Class which contains all detector specific parameters for the TPC,
41 // and different useful functions for coordinate transforms.
42 //
43 // The class is completely static, which means that no object needs
44 // to be instantiated. Function calls should then be done like, e.g.:
45 //
46 // Double_t eta = AliHLTTPCTransform::GetEta(xyz);
47 //
48 // IMPORTANT: If used as is, default detector parameters will be used,
49 //            and you really have to make sure that these correspond to
50 //            the AliROOT version you are currently working on!!
51 //            You should therefore always initialize the parameters by
52 //
53 //            AliHLTTPCTransform::Init(path);
54 // 
55 //            where path is a char*, giving the path to where file containing
56 //            the detector parameter is located. This file should be called
57 //            "l3transform.config", and can be created with the function MakeInitFile.
58 //            
59 //            You can also force reading the parameters from a AliTPCParam object
60 //            by setting the flag;
61 //
62 //            AliHLTTPCTransform::Init(path,kTRUE);
63 //
64 //            where path is a char* 
65 //            either providing the rootfile name containing the geometry or 
66 //            the path to the rootfile which should then be called alirunfile.root. 
67 //            Note that for both of these cases you have to
68 //            compile with USEPACKAGE=ALIROOT set (see level3code/Makefile.conf).
69 //
70 //            Currently, there are 4 versions of the Transformer:
71 //             fVersion==kValiroot: ALIROOT-head compatible
72 //             fVersion==kVcosmics: Cosmics data run (2003) compatible
73 //             fVersion==kVdefault: means no config file has been loaded
74 //             fVersion==kVdeprecated: dont use old (before July 2003) style of transformer
75 //
76 </pre>
77 * @ingroup alihlt_tpc
78 */
79
80 ClassImp(AliHLTTPCTransform)
81
82 AliHLTTPCTransform::AliHLTTPCTransform()
83 {
84 }
85
86 const Double_t AliHLTTPCTransform::fgkAnodeWireSpacing = 0.25; //Taken from the TDR
87 const Double_t AliHLTTPCTransform::fgkBFACT = 0.0029980;       //Conversion Factor
88 const Double_t AliHLTTPCTransform::fgkPi  =   3.141592653589793;
89 const Double_t AliHLTTPCTransform::fgk2Pi = 2*3.141592653589793;
90 const Double_t AliHLTTPCTransform::fgkPi2 = 0.5*3.141592653589793;
91 const Double_t AliHLTTPCTransform::fgkToDeg = 180/3.141592653589793;
92
93 //Defined by HLT and GSI
94 Int_t AliHLTTPCTransform::fgNPatches = 6;
95 #if 0
96 // Old format, corresponding to IntegrTest-5 code and data
97 Int_t AliHLTTPCTransform::fgRows[6][2] = {{0,29},{30,62},{63,90},{91,116},{117,139},{140,158}}; 
98 Int_t AliHLTTPCTransform::fgNRows[6] = {30,33,28,26,23,19};
99 #else
100 // New data corresponding to simulated raw data 2004-08-20, provided by Thomas Kuhr
101 Int_t AliHLTTPCTransform::fgRows[6][2] = {{0,30},{30,62},{63,90},{90,116},{117,139},{139,158}}; 
102 Int_t AliHLTTPCTransform::fgNRows[6] = {31,33,28,27,23,20};
103 #endif
104
105 // The following definition is generated by MakeInitFile function
106 Double_t AliHLTTPCTransform::fgBField = 0.5;
107 Double_t AliHLTTPCTransform::fgSolenoidBField = 5;
108 Double_t AliHLTTPCTransform::fgBFieldFactor = 1;
109 Int_t AliHLTTPCTransform::fgVersion = kVdefault;
110 Int_t AliHLTTPCTransform::fgNTimeBins = 1024; //  = 1024; //446
111 Int_t AliHLTTPCTransform::fgNRowLow = 63;
112 Int_t AliHLTTPCTransform::fgNRowUp = 96;
113 Int_t AliHLTTPCTransform::fgNRowUp1 = 64;
114 Int_t AliHLTTPCTransform::fgNRowUp2 = 32;
115 Int_t AliHLTTPCTransform::fgNSectorLow = 36;
116 Int_t AliHLTTPCTransform::fgNSectorUp = 36;
117 Int_t AliHLTTPCTransform::fgNSector = 72;
118 Double_t AliHLTTPCTransform::fgPadPitchWidthLow = 0.4;
119 Double_t AliHLTTPCTransform::fgPadPitchWidthUp = 0.6;
120 Double_t AliHLTTPCTransform::fgZSigma = 0.2288;
121 Double_t AliHLTTPCTransform::fgZLength = 250.0000;
122 Double_t AliHLTTPCTransform::fgZWidth = AliHLTTPCTransform::fgZLength / (Double_t)AliHLTTPCTransform::fgNTimeBins ;//0.5660; // 0.2435; // 0.5660 // Width of time bins
123 Double_t AliHLTTPCTransform::fgZOffset = 0.6864;
124 Double_t AliHLTTPCTransform::fgDiffT = 0.0220;
125 Double_t AliHLTTPCTransform::fgDiffL = 0.0220;
126 Double_t AliHLTTPCTransform::fgOmegaTau = 0.1450;
127 Double_t AliHLTTPCTransform::fgInnerPadLength = 0.75;
128 Double_t AliHLTTPCTransform::fgOuter1PadLength = 1.00;
129 Double_t AliHLTTPCTransform::fgOuter2PadLength = 1.50;
130 Double_t AliHLTTPCTransform::fgInnerPRFSigma = 0.203811;
131 Double_t AliHLTTPCTransform::fgOuter1PRFSigma = 0.299325;
132 Double_t AliHLTTPCTransform::fgOuter2PRFSigma = 0.299323;
133 Double_t AliHLTTPCTransform::fgTimeSigma = 0.228809;
134 Int_t AliHLTTPCTransform::fgADCSat = 1024;
135 Int_t AliHLTTPCTransform::fgZeroSup = 0;
136 Int_t AliHLTTPCTransform::fgNSlice = 36;
137 Int_t AliHLTTPCTransform::fgNRow = 159;
138 Double_t AliHLTTPCTransform::fgNRotShift = 0.5;
139 Int_t AliHLTTPCTransform::fgSlice2Sector[36][2] = { { 0, 36}, 
140                                                { 1, 37}, 
141                                                { 2, 38}, 
142                                                { 3, 39}, 
143                                                { 4, 40}, 
144                                                { 5, 41}, 
145                                                { 6, 42}, 
146                                                { 7, 43}, 
147                                                { 8, 44}, 
148                                                { 9, 45}, 
149                                                {10, 46}, 
150                                                {11, 47}, 
151                                                {12, 48}, 
152                                                {13, 49}, 
153                                                {14, 50}, 
154                                                {15, 51}, 
155                                                {16, 52}, 
156                                                {17, 53}, 
157                                                {18, 54}, 
158                                                {19, 55}, 
159                                                {20, 56}, 
160                                                {21, 57}, 
161                                                {22, 58}, 
162                                                {23, 59}, 
163                                                {24, 60}, 
164                                                {25, 61}, 
165                                                {26, 62}, 
166                                                {27, 63}, 
167                                                {28, 64}, 
168                                                {29, 65}, 
169                                                {30, 66}, 
170                                                {31, 67}, 
171                                                {32, 68}, 
172                                                {33, 69}, 
173                                                {34, 70}, 
174                                                {35, 71}
175 };
176
177 Int_t AliHLTTPCTransform::fgSector2Slice[72] = { 0, 
178                                             1, 
179                                             2, 
180                                             3, 
181                                             4, 
182                                             5, 
183                                             6, 
184                                             7, 
185                                             8, 
186                                             9, 
187                                             10, 
188                                             11, 
189                                             12, 
190                                             13, 
191                                             14, 
192                                             15, 
193                                             16, 
194                                             17, 
195                                             18, 
196                                             19, 
197                                             20, 
198                                             21, 
199                                             22, 
200                                             23, 
201                                             24, 
202                                             25, 
203                                             26, 
204                                             27, 
205                                             28, 
206                                             29, 
207                                             30, 
208                                             31, 
209                                             32,
210                                             33, 
211                                             34, 
212                                             35, 
213                                             0, 
214                                             1, 
215                                             2, 
216                                             3, 
217                                             4, 
218                                             5, 
219                                             6, 
220                                             7, 
221                                             8, 
222                                             9, 
223                                             10, 
224                                             11, 
225                                             12, 
226                                             13, 
227                                             14, 
228                                             15, 
229                                             16, 
230                                             17, 
231                                             18, 
232                                             19, 
233                                             20, 
234                                             21, 
235                                             22, 
236                                             23, 
237                                             24, 
238                                             25, 
239                                             26, 
240                                             27, 
241                                             28, 
242                                             29, 
243                                             30, 
244                                             31, 
245                                             32, 
246                                             33, 
247                                             34, 
248                                             35 
249 };
250
251 Int_t AliHLTTPCTransform::fgSectorLow[72] = { 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                                          1, 
286                                          1, 
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                                          0, 
322                                          0 
323 };
324
325 Double_t AliHLTTPCTransform::fgX[159] = { 85.195,
326                                      85.945,
327                                      86.695,
328                                      87.445,
329                                      88.195,
330                                      88.945,
331                                      89.695,
332                                      90.445,
333                                      91.195,
334                                      91.945,
335                                      92.695,
336                                      93.445,
337                                      94.195,
338                                      94.945,
339                                      95.695,
340                                      96.445,
341                                      97.195,
342                                      97.945,
343                                      98.695,
344                                      99.445,
345                                      100.195,
346                                      100.945,
347                                      101.695,
348                                      102.445,
349                                      103.195,
350                                      103.945,
351                                      104.695,
352                                      105.445,
353                                      106.195,
354                                      106.945,
355                                      107.695,
356                                      108.445,
357                                      109.195,
358                                      109.945,
359                                      110.695,
360                                      111.445,
361                                      112.195,
362                                      112.945,
363                                      113.695,
364                                      114.445,
365                                      115.195,
366                                      115.945,
367                                      116.695,
368                                      117.445,
369                                      118.195,
370                                      118.945,
371                                      119.695,
372                                      120.445,
373                                      121.195,
374                                      121.945,
375                                      122.695,
376                                      123.445,
377                                      124.195,
378                                      124.945,
379                                      125.695,
380                                      126.445,
381                                      127.195,
382                                      127.945,
383                                      128.695,
384                                      129.445,
385                                      130.195,
386                                      130.945,
387                                      131.695,
388                                      135.180,
389                                      136.180,
390                                      137.180,
391                                      138.180,
392                                      139.180,
393                                      140.180,
394                                      141.180,
395                                      142.180,
396                                      143.180,
397                                      144.180,
398                                      145.180,
399                                      146.180,
400                                      147.180,
401                                      148.180,
402                                      149.180,
403                                      150.180,
404                                      151.180,
405                                      152.180,
406                                      153.180,
407                                      154.180,
408                                      155.180,
409                                      156.180,
410                                      157.180,
411                                      158.180,
412                                      159.180,
413                                      160.180,
414                                      161.180,
415                                      162.180,
416                                      163.180,
417                                      164.180,
418                                      165.180,
419                                      166.180,
420                                      167.180,
421                                      168.180,
422                                      169.180,
423                                      170.180,
424                                      171.180,
425                                      172.180,
426                                      173.180,
427                                      174.180,
428                                      175.180,
429                                      176.180,
430                                      177.180,
431                                      178.180,
432                                      179.180,
433                                      180.180,
434                                      181.180,
435                                      182.180,
436                                      183.180,
437                                      184.180,
438                                      185.180,
439                                      186.180,
440                                      187.180,
441                                      188.180,
442                                      189.180,
443                                      190.180,
444                                      191.180,
445                                      192.180,
446                                      193.180,
447                                      194.180,
448                                      195.180,
449                                      196.180,
450                                      197.180,
451                                      198.180,
452                                      199.430,
453                                      200.930,
454                                      202.430,
455                                      203.930,
456                                      205.430,
457                                      206.930,
458                                      208.430,
459                                      209.930,
460                                      211.430,
461                                      212.930,
462                                      214.430,
463                                      215.930,
464                                      217.430,
465                                      218.930,
466                                      220.430,
467                                      221.930,
468                                      223.430,
469                                      224.930,
470                                      226.430,
471                                      227.930,
472                                      229.430,
473                                      230.930,
474                                      232.430,
475                                      233.930,
476                                      235.430,
477                                      236.930,
478                                      238.430,
479                                      239.930,
480                                      241.430,
481                                      242.930,
482                                      244.430,
483                                      245.930
484 };
485
486 #if 1
487 // New  number of pads changed 2006-04-15 Jochen Thaeder
488 // changed according to formula in AliTPCROC.cxx
489 // according to real Pad Distribution on build TPC
490 Int_t AliHLTTPCTransform::fgNPads[159] = {68,
491                                      68,
492                                      68,
493                                      68,
494                                      70,
495                                      70,
496                                      70,
497                                      72,
498                                      72,
499                                      72,
500                                      74,
501                                      74,
502                                      74,
503                                      76,
504                                      76,
505                                      76,
506                                      78,
507                                      78,
508                                      78,
509                                      80,
510                                      80,
511                                      80,
512                                      82,
513                                      82,
514                                      82,
515                                      84,
516                                      84,
517                                      84,
518                                      86,
519                                      86,
520                                      86,
521                                      88,
522                                      88,
523                                      88,
524                                      90,
525                                      90,
526                                      90,
527                                      92,
528                                      92,
529                                      92,
530                                      94,
531                                      94,
532                                      94,
533                                      96,
534                                      96,
535                                      96,
536                                      98,
537                                      98,
538                                      98,
539                                      100,
540                                      100,
541                                      100,
542                                      102,
543                                      102,
544                                      102,
545                                      104,
546                                      104,
547                                      104,
548                                      106,
549                                      106,
550                                      106,
551                                      108,
552                                      108,
553                                      74,
554                                      76,
555                                      76,
556                                      76,
557                                      76,
558                                      78,
559                                      78,
560                                      78,
561                                      80,
562                                      80,
563                                      80,
564                                      80,
565                                      82,
566                                      82,
567                                      82,
568                                      84,
569                                      84,
570                                      84,
571                                      86,
572                                      86,
573                                      86,
574                                      86,
575                                      88,
576                                      88,
577                                      88,
578                                      90,
579                                      90,
580                                      90,
581                                      90,
582                                      92,
583                                      92,
584                                      92,
585                                      94,
586                                      94,
587                                      94,
588                                      96,
589                                      96,
590                                      96,
591                                      96,
592                                      98,
593                                      98,
594                                      98,
595                                      100,
596                                      100,
597                                      100,
598                                      100,
599                                      102,
600                                      102,
601                                      102,
602                                      104,
603                                      104,
604                                      104,
605                                      106,
606                                      106,
607                                      106,
608                                      106,
609                                      108,
610                                      108,
611                                      108,
612                                      110,
613                                      110,
614                                      110,
615                                      110,
616                                      112,
617                                      112,
618                                      114,
619                                      114,
620                                      114,
621                                      116,
622                                      116,
623                                      118,
624                                      118,
625                                      120,
626                                      120,
627                                      122,
628                                      122,
629                                      122,
630                                      124,
631                                      124,
632                                      126,
633                                      126,
634                                      128,
635                                      128,
636                                      130,
637                                      130,
638                                      130,
639                                      132,
640                                      132,
641                                      134,
642                                      134,
643                                      136,
644                                      136,
645                                      138,
646                                      138,
647                                      138,
648                                      140
649 };
650
651 #else
652 //   OLD  number of pads changed 2006-04-15 Jochen Thaeder
653 Int_t AliHLTTPCTransform::fgNPads[159] = {67,
654                                      67,
655                                      69,
656                                      69,
657                                      69,
658                                      71,
659                                      71,
660                                      71,
661                                      73,
662                                      73,
663                                      73,
664                                      75,
665                                      75,
666                                      75,
667                                      77,
668                                      77,
669                                      77,
670                                      79,
671                                      79,
672                                      79,
673                                      81,
674                                      81,
675                                      81,
676                                      83,
677                                      83,
678                                      83,
679                                      85,
680                                      85,
681                                      85,
682                                      87,
683                                      87,
684                                      87,
685                                      89,
686                                      89,
687                                      89,
688                                      91,
689                                      91,
690                                      91,
691                                      93,
692                                      93,
693                                      93,
694                                      95,
695                                      95,
696                                      95,
697                                      97,
698                                      97,
699                                      97,
700                                      99,
701                                      99,
702                                      99,
703                                      99,
704                                      101,
705                                      101,
706                                      101,
707                                      103,
708                                      103,
709                                      103,
710                                      105,
711                                      105,
712                                      105,
713                                      107,
714                                      107,
715                                      107,
716                                      73,
717                                      75,
718                                      75,
719                                      75,
720                                      75,
721                                      77,
722                                      77,
723                                      77,
724                                      79,
725                                      79,
726                                      79,
727                                      81,
728                                      81,
729                                      81,
730                                      81,
731                                      83,
732                                      83,
733                                      83,
734                                      85,
735                                      85,
736                                      85,
737                                      85,
738                                      87,
739                                      87,
740                                      87,
741                                      89,
742                                      89,
743                                      89,
744                                      91,
745                                      91,
746                                      91,
747                                      91,
748                                      93,
749                                      93,
750                                      93,
751                                      95,
752                                      95,
753                                      95,
754                                      95,
755                                      97,
756                                      97,
757                                      97,
758                                      99,
759                                      99,
760                                      99,
761                                      101,
762                                      101,
763                                      101,
764                                      101,
765                                      103,
766                                      103,
767                                      103,
768                                      105,
769                                      105,
770                                      105,
771                                      105,
772                                      107,
773                                      107,
774                                      107,
775                                      109,
776                                      109,
777                                      109,
778                                      111,
779                                      111,
780                                      111,
781                                      113,
782                                      113,
783                                      113,
784                                      115,
785                                      115,
786                                      117,
787                                      117,
788                                      119,
789                                      119,
790                                      121,
791                                      121,
792                                      121,
793                                      123,
794                                      123,
795                                      125,
796                                      125,
797                                      127,
798                                      127,
799                                      127,
800                                      129,
801                                      129,
802                                      131,
803                                      131,
804                                      133,
805                                      133,
806                                      135,
807                                      135,
808                                      135,
809                                      137,
810                                      137,
811                                      139
812 };
813 #endif
814
815 Double_t AliHLTTPCTransform::fgCos[36] = { 0.9848077297,
816                                       0.8660253882,
817                                       0.6427876353,
818                                       0.3420201540,
819                                       0.0000000000,
820                                       -0.3420201540,
821                                       -0.6427876353,
822                                       -0.8660253882,
823                                       -0.9848077297,
824                                       -0.9848077297,
825                                       -0.8660253882,
826                                       -0.6427876353,
827                                       -0.3420201540,
828                                       -0.0000000000,
829                                       0.3420201540,
830                                       0.6427876353,
831                                       0.8660253882,
832                                       0.9848077297,
833                                       0.9848077297,
834                                       0.8660253882,
835                                       0.6427876353,
836                                       0.3420201540,
837                                       0.0000000000,
838                                       -0.3420201540,
839                                       -0.6427876353,
840                                       -0.8660253882,
841                                       -0.9848077297,
842                                       -0.9848077297,
843                                       -0.8660253882,
844                                       -0.6427876353,
845                                       -0.3420201540,
846                                       -0.0000000000,
847                                       0.3420201540,
848                                       0.6427876353,
849                                       0.8660253882,
850                                       0.9848077297
851 };
852
853 Double_t AliHLTTPCTransform::fgSin[36] = { 0.1736481786,
854                                       0.5000000000,
855                                       0.7660444379,
856                                       0.9396926165,
857                                       1.0000000000,
858                                       0.9396926165,
859                                       0.7660444379,
860                                       0.5000000000,
861                                       0.1736481786,
862                                       -0.1736481786,
863                                       -0.5000000000,
864                                       -0.7660444379,
865                                       -0.9396926165,
866                                       -1.0000000000,
867                                       -0.9396926165,
868                                       -0.7660444379,
869                                       -0.5000000000,
870                                       -0.1736481786,
871                                       0.1736481786,
872                                       0.5000000000,
873                                       0.7660444379,
874                                       0.9396926165,
875                                       1.0000000000,
876                                       0.9396926165,
877                                       0.7660444379,
878                                       0.5000000000,
879                                       0.1736481786,
880                                       -0.1736481786,
881                                       -0.5000000000,
882                                       -0.7660444379,
883                                       -0.9396926165,
884                                       -1.0000000000,
885                                       -0.9396926165,
886                                       -0.7660444379,
887                                       -0.5000000000,
888                                       -0.1736481786
889 };
890
891 #ifdef use_aliroot
892 Bool_t AliHLTTPCTransform::Init(AliRunLoader *runLoader)
893
894   //init with runloader
895   if(!runLoader) {
896     LOG(AliHLTTPCLog::kFatal,"AliHLTTPCTransform::Init","RunLoader")
897       <<" Missing RunLoader! 0x0"<<ENDLOG;
898     return kFALSE;
899   }
900  
901   if(fgVersion != kVdefault)
902     LOG(AliHLTTPCLog::kWarning,"AliHLTTPCTransform::Init","Init values")
903       <<AliHLTTPCLog::kDec<<"You are initializing the parameters more than once; check your code please! "<<fgVersion<<ENDLOG;
904
905   TDirectory* savedir1 = gDirectory;
906   runLoader->CdGAFile();
907   AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get(GetParamName());
908   savedir1->cd();
909   if(!param)
910     {
911       LOG(AliHLTTPCLog::kFatal,"AliHLTTPCTransform::Init","File")
912         <<"No TPC parameters found!"<<ENDLOG;
913       return kFALSE;
914     }
915
916   AliTPCPRF2D    * prfinner    = new AliTPCPRF2D;
917   AliTPCPRF2D    * prfouter1   = new AliTPCPRF2D;
918   AliTPCPRF2D    * prfouter2   = new AliTPCPRF2D;  
919   AliTPCRF1D     * rf    = new AliTPCRF1D(kTRUE);
920   rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
921   rf->SetOffset(3*param->GetZSigma());
922   rf->Update();
923   
924   TDirectory *savedir2=gDirectory;
925   TFile *prf_file = TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
926   if (!prf_file->IsOpen()) 
927     { 
928       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Init","File")
929         <<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !"<<ENDLOG;
930       return kFALSE;
931     }
932   prfinner ->Read("prf_07504_Gati_056068_d02");
933   prfouter1->Read("prf_10006_Gati_047051_d03");
934   prfouter2->Read("prf_15006_Gati_047051_d03");  
935   prf_file->Close();
936   savedir2->cd();
937   
938   param->SetInnerPRF(prfinner);
939   param->SetOuter1PRF(prfouter1); 
940   param->SetOuter2PRF(prfouter2);
941   param->SetTimeRF(rf);
942   
943   fgNTimeBins = param->GetMaxTBin()+1;
944   fgNRowLow = param->GetNRowLow();
945   fgNRowUp  = param->GetNRowUp();
946   fgNRowUp1 = param->GetNRowUp1();
947   fgNRowUp2 = param->GetNRowUp2();
948   fgNRow= fgNRowLow + fgNRowUp;
949   if(fgNRow!=159){
950     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Init","fNRow")
951       <<"Number of rows have changed in ALIROOT"<<ENDLOG;
952     return kFALSE;
953   }
954   
955   fgNSectorLow = param->GetNInnerSector();
956   fgNSectorUp = param->GetNOuterSector();
957   fgNSector = fgNSectorLow + fgNSectorUp;
958
959   //test whether they were changes to the rotation shift
960   fgNRotShift=0;
961   Float_t irotshift = param->GetInnerAngleShift(); //shift angle
962   Float_t orotshift = param->GetOuterAngleShift(); //shift angle
963   const Float_t kDegtoRad = 0.01745329251994;
964   Int_t shift1=TMath::Nint(irotshift/kDegtoRad);
965   Int_t shift2=TMath::Nint(orotshift/kDegtoRad+0.1);
966   if((shift1!=shift2) || (shift1!=10)){
967     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Init","Rotshiftangle")
968       <<"Rotation shift angle has changed in ALIROOT"<<ENDLOG;
969     return kFALSE;
970   } else {
971     fgNRotShift=0.5; //our version of the shift angle
972   }
973   
974   fgVersion=kValiroot;
975   AliMagF* mag = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
976   double fc = mag ? mag->GetFactorSol() : 0;
977   double bz = mag ? -mag->SolenoidField() : 0;
978   if (fc!=0) bz/=fc;
979   SetBFieldFactor( fc );
980   SetSolenoidBField( bz );
981   fgPadPitchWidthLow=param->GetInnerPadPitchWidth();
982   fgPadPitchWidthUp=param->GetOuterPadPitchWidth();
983   fgZWidth=param->GetZWidth();
984   fgZSigma=param->GetZSigma();
985   // Matthias 24.04.2007 a default parameter has been added to GetZLength
986   // reverting some of Mareks changes
987   // TODO: we have to use the method correctly and put the slice no into it
988   //fgZLength=param->GetZLength(0)+0.275;
989   fgZLength=param->GetZLength()+0.275;
990   fgZOffset=param->GetZOffset();
991   fgDiffT=param->GetDiffT();
992   fgDiffL=param->GetDiffL();
993   fgOmegaTau=param->GetOmegaTau();
994   fgInnerPadLength=param->GetInnerPadLength();
995   fgOuter1PadLength=param->GetOuter1PadLength();
996   fgOuter2PadLength=param->GetOuter2PadLength();
997   fgInnerPRFSigma=param->GetInnerPRF()->GetSigmaX();
998   fgOuter1PRFSigma=param->GetOuter1PRF()->GetSigmaX();
999   fgOuter2PRFSigma=param->GetOuter2PRF()->GetSigmaX();
1000   fgTimeSigma=param->GetTimeRF()->GetSigma();
1001   fgADCSat=param->GetADCSat();
1002   fgZeroSup=param->GetZeroSup();
1003   fgNSlice=fgNSectorLow;
1004     
1005   //now do the arrays
1006   for(Int_t i=0;i<fgNRow;i++){
1007     Int_t sec,row;
1008     if( i < fgNRowLow){sec =0;row =i;}
1009     else{sec = fgNSectorLow;row =i-fgNRowLow;}
1010     fgX[i]=param->GetPadRowRadii(sec,row);
1011   } 
1012   for(Int_t i=0;i<fgNRow;i++){
1013     Int_t sec,row;
1014     if( i < fgNRowLow){sec =0;row =i;}
1015     else{sec = fgNSectorLow;row =i-fgNRowLow;}
1016     fgNPads[i]=param->GetNPads(sec,row);
1017   }
1018   for(Int_t i=0;i<fgNSector;i++){
1019     if(i<fgNSectorLow) fgSectorLow[i]=1;
1020     else fgSectorLow[i]=0;
1021   }
1022
1023   return kTRUE;
1024
1025   /* not needed 
1026   TTimeStamp time;
1027   Char_t tmpfile[1024];
1028   sprintf(tmpfile,"./l3transform.config-%d",(Int_t)time.GetSec());
1029
1030   return SaveInitFile(tmpfile);
1031   */
1032 }
1033 #endif
1034
1035 Bool_t AliHLTTPCTransform::Init(Char_t* path,Bool_t UseAliTPCParam)
1036 {
1037   //Overwrite the parameters with values stored in file "l3transform.config" in path.
1038   //If file does not exist, old default values will be used.
1039   //If flag UseAliTPCParam is set, the parameters will be read from the the rootfile
1040   //which then has to be called path/digitfile.root
1041   
1042   if(fgVersion != kVdefault)
1043     LOG(AliHLTTPCLog::kWarning,"AliHLTTPCTransform::Init","Init values")
1044       <<AliHLTTPCLog::kDec<<"You are initializing the parameters more than once; check your code please! "<<fgVersion<<ENDLOG;
1045   
1046   if(UseAliTPCParam) //use rootfile to generate temporary init file
1047     return ReadInit(path);
1048
1049   //create filename
1050   Char_t pathname[1024];
1051   strcpy(pathname,path);
1052
1053   //test whether provided path is the file itself
1054   Int_t isdir = 0;
1055   DIR *testdir=opendir(pathname);
1056   if(testdir){
1057     isdir=1;
1058     closedir(testdir);
1059   }
1060
1061   if(isdir) strcat(pathname,"/l3transform.config");
1062
1063   return ReadInitFile(pathname);
1064 }
1065
1066 Bool_t AliHLTTPCTransform::ReadInitFile(Char_t* pathname)
1067 {
1068   //read transformer settings from pathname
1069   FILE *fptr=fopen(pathname,"r");
1070   if(!fptr){
1071     LOG(AliHLTTPCLog::kWarning,"AliHLTTPCTransform::ReadInitFile","File Open")
1072       <<"Pointer to Config File \""<<pathname<<"\" 0x0!"<<ENDLOG;
1073     return kFALSE;
1074   }
1075
1076   Char_t d1[250], d2[100], d3[100];
1077   Int_t dummy=0;
1078   Double_t ddummy=0.0;
1079
1080   while(!feof(fptr)) {
1081     fscanf(fptr,"%s",d1);
1082     if(strcmp(d1,"fVersion")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgVersion=dummy;}
1083     else if(strcmp(d1,"fBFieldFactor")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgBFieldFactor=(Double_t)ddummy;}
1084     else if(strcmp(d1,"fSolenoidBField")==0)
1085       {
1086         fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);
1087         fgSolenoidBField=(Double_t)ddummy;
1088       }
1089     else if(strcmp(d1,"fNTimeBins")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNTimeBins=(Int_t)dummy;}
1090     else if(strcmp(d1,"fNRowLow")==0)
1091       {
1092         fscanf(fptr,"%s %d %s",d2,&dummy,d3);
1093         fgNRowLow=(Int_t)dummy;
1094         if(fgNRowLow != 63)
1095           LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::ReadInitFile","Overflow")
1096             <<"Number of inner PadRows should be 63! Check and fgrep the code for 63 to see the consequences of this major change!"<<ENDLOG;
1097       }
1098     else if(strcmp(d1,"fNRowUp")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNRowUp=(Int_t)dummy;}
1099     else if(strcmp(d1,"fNRowUp1")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNRowUp1=(Int_t)dummy;}
1100     else if(strcmp(d1,"fNRowUp2")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNRowUp2=(Int_t)dummy;}
1101     else if(strcmp(d1,"fNSectorLow")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNSectorLow=(Int_t)dummy;}
1102     else if(strcmp(d1,"fNSectorUp")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNSectorUp=(Int_t)dummy;}
1103     else if(strcmp(d1,"fNSector")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNSector=(Int_t)dummy;}
1104     else if(strcmp(d1,"fPadPitchWidthLow")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgPadPitchWidthLow=(Double_t)ddummy;}
1105     else if(strcmp(d1,"fPadPitchWidthUp")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgPadPitchWidthUp=(Double_t)ddummy;}
1106     else if(strcmp(d1,"fZWidth")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgZWidth=(Double_t)ddummy;}
1107     else if(strcmp(d1,"fZSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgZSigma=(Double_t)ddummy;}
1108     else if(strcmp(d1,"fZLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgZLength=(Double_t)ddummy;}
1109     else if(strcmp(d1,"fZOffset")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgZOffset=(Double_t)ddummy;}
1110     else if(strcmp(d1,"fNSlice")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNSlice=(Int_t)dummy;}
1111     else if(strcmp(d1,"fDiffT")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgDiffT=(Double_t)ddummy;}
1112     else if(strcmp(d1,"fDiffL")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgDiffL=(Double_t)ddummy;}
1113     else if(strcmp(d1,"fOmegaTau")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgOmegaTau=(Double_t)ddummy;}
1114     else if(strcmp(d1,"fInnerPadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgInnerPadLength=(Double_t)ddummy;}
1115     else if(strcmp(d1,"fOuter1PadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgOuter1PadLength=(Double_t)ddummy;}
1116     else if(strcmp(d1,"fOuter2PadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgOuter2PadLength=(Double_t)ddummy;}
1117     else if(strcmp(d1,"fInnerPRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgInnerPRFSigma=(Double_t)ddummy;}
1118     else if(strcmp(d1,"fOuter1PRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgOuter1PRFSigma=(Double_t)ddummy;}
1119     else if(strcmp(d1,"fOuter2PRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgOuter2PRFSigma=(Double_t)ddummy;}
1120     else if(strcmp(d1,"fTimeSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgTimeSigma=(Double_t)ddummy;}
1121     else if(strcmp(d1,"fADCSat")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgADCSat=(Int_t)dummy;}
1122     else if(strcmp(d1,"fZeroSup")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgZeroSup=(Int_t)dummy;}
1123     else if(strcmp(d1,"fNRow")==0){
1124       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNRow=(Int_t)dummy;
1125       if(fgNRow!=159){
1126         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;
1127       }
1128     }
1129     else if(strcmp(d1,"fNRotShift")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgNRotShift=(Double_t)ddummy;}
1130     else if(strcmp(d1,"fX[0]")==0){
1131       fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgX[0]=(Double_t)ddummy;
1132       for(Int_t i=1;i<fgNRow;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fgX[i]=(Double_t)ddummy;}
1133     }
1134     else if(strcmp(d1,"fNPads[0]")==0){
1135       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNPads[0]=(Int_t)dummy;
1136       for(Int_t i=1;i<fgNRow;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fgNPads[i]=(Int_t)dummy;}
1137     }
1138     else if(strcmp(d1,"fNRows[0]")==0){
1139       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgNRows[0]=(Int_t)dummy;
1140       for(Int_t i=1;i<fgNPatches;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fgNRows[i]=(Int_t)dummy;}
1141     }
1142     else if(strcmp(d1,"fRows[0][0]")==0){
1143       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgRows[0][0]=(Int_t)dummy;
1144       fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fgRows[0][1]=(Int_t)dummy;
1145       for(Int_t i=1;i<fgNPatches;i++){
1146         fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fgRows[i][0]=(Int_t)dummy;
1147         fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fgRows[i][1]=(Int_t)dummy;
1148       }
1149     }
1150     else if(strcmp(d1,"fSlice2Sector[0][0]")==0){
1151       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgSlice2Sector[0][0]=(Int_t)dummy;
1152       fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fgSlice2Sector[0][1]=(Int_t)dummy;
1153       for(Int_t i=1;i<fgNSlice;i++){
1154         fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fgSlice2Sector[i][0]=(Int_t)dummy;
1155         fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fgSlice2Sector[i][1]=(Int_t)dummy;
1156       }
1157     }
1158     else if(strcmp(d1,"fSector2Slice[0]")==0){
1159       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgSector2Slice[0]=(Int_t)dummy;
1160       for(Int_t i=1;i<fgNSector;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fgSector2Slice[i]=(Int_t)dummy;}
1161     }
1162     else if(strcmp(d1,"fSectorLow[0]")==0){
1163       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fgSectorLow[0]=(Int_t)dummy;
1164       for(Int_t i=1;i<fgNSector;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fgSectorLow[i]=(Int_t)dummy;}
1165     }
1166     else if(strcmp(d1,"fCos[0]")==0){
1167       fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgCos[0]=(Double_t)ddummy;
1168       for(Int_t i=1;i<fgNSlice;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fgCos[i]=(Double_t)ddummy;}
1169     }
1170     else if(strcmp(d1,"fSin[0]")==0){
1171       fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fgSin[0]=(Double_t)ddummy;
1172       for(Int_t i=1;i<fgNSlice;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fgSin[i]=(Double_t)ddummy;}
1173     }
1174   }
1175   fclose(fptr);
1176
1177   //The first multiplier gives the scale factor used to modify the field map 
1178   //defined by the second multiplier.
1179   fgBField=fgBFieldFactor*fgSolenoidBField*0.1;
1180
1181   //Test if new config file has been used.
1182   if(fgVersion==kVdeprecated){
1183     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::ReadInitFile","Version")
1184       <<"Version is deprecated, you have to create a new config file."<<ENDLOG;
1185     return kFALSE;
1186   }
1187
1188   LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTransform::ReadInitFile","Config")
1189     <<"Successfully loaded values from config file \""<<pathname<<"\""<<ENDLOG;
1190
1191   return kTRUE;
1192 }
1193
1194 Bool_t AliHLTTPCTransform::ReadInit(Char_t *path)
1195 {
1196   //Read all the parameters from a aliroot file, and store it in a temporary 
1197   //file which is read by Init. Use this if you want to read the parameters from
1198   //the rootfile "every" time.
1199   
1200 #ifndef use_aliroot
1201   LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::ReadInit","Version")
1202     <<"You have to compile with use_aliroot flag in order to read from AliROOT file"<<ENDLOG;
1203   return kFALSE;
1204 #else
1205   Char_t filename[1024];
1206   //first test whether provided path is the rootfile itself
1207   Int_t saveErrIgLevel=gErrorIgnoreLevel;
1208   gErrorIgnoreLevel=kFatal; //dont report errors
1209   TFile *rootfile = TFile::Open(path);
1210   if(!rootfile || rootfile->IsZombie()) 
1211     { //ok assume its path to alirunfile file
1212       sprintf(filename,"%s/alirunfile.root",path); //create rootfile name
1213     } else { //path contains itself the rootfile name
1214       rootfile->Close();
1215       sprintf(filename,"%s",path); 
1216     }
1217   gErrorIgnoreLevel=saveErrIgLevel;
1218
1219   //finally make dummy init file /tmp/$USER/l3transform.config-`date`
1220   Char_t tmppath[1024];
1221   sprintf(tmppath,"/tmp/%s",gSystem->Getenv("USER"));
1222   gSystem->mkdir(tmppath);
1223   TTimeStamp time;
1224   Char_t tmpfile[1024];
1225   sprintf(tmpfile,"%s/l3transform.config-%d",tmppath,(Int_t)time.GetSec());
1226   return MakeInitFile(filename,tmpfile);
1227 #endif  
1228 }
1229
1230 Bool_t AliHLTTPCTransform::MakeInitFile(Char_t *rootfilename,Char_t *filename)
1231 {
1232   //Get the parameters from rootfile, and store it on the file "l3transform.config"
1233   //which is being read by Init. fVersion will be kV_aliroot!
1234   
1235 #ifndef use_aliroot
1236   LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::MakeInitFile","Version")
1237     <<"You have to compile with use_aliroot flag in order to use this function"<<ENDLOG;
1238   return kFALSE;
1239 #else
1240   TFile *rootfile = TFile::Open(rootfilename);
1241   if(!rootfile)
1242     {
1243       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::MakeInitFile","File")
1244         <<"Could not open file: "<<rootfilename<<ENDLOG;
1245       return kFALSE;
1246     }
1247   AliRun *lgAlice = (AliRun*)rootfile->Get("gAlice");
1248   if(!lgAlice)
1249     {
1250       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::MakeInitFile","File")
1251         <<"No lgAlice in file: "<<rootfilename<<ENDLOG;
1252       return kFALSE;
1253     }  
1254   AliTPCParamSR *param=(AliTPCParamSR*)rootfile->Get(GetParamName());
1255   if(!param)
1256     {
1257       LOG(AliHLTTPCLog::kWarning,"AliHLTTPCTransform::MakeInitFile","File")
1258         <<"No TPC parameters found in \""<<rootfilename
1259         <<"\", creating standard parameters "
1260         <<"which might not be what you want!"<<ENDLOG;
1261       param=new AliTPCParamSR;
1262     }
1263
1264   AliTPCPRF2D    * prfinner    = new AliTPCPRF2D;
1265   AliTPCPRF2D    * prfouter1   = new AliTPCPRF2D;
1266   AliTPCPRF2D    * prfouter2   = new AliTPCPRF2D;  
1267   AliTPCRF1D     * rf    = new AliTPCRF1D(kTRUE);
1268   rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1269   rf->SetOffset(3*param->GetZSigma());
1270   rf->Update();
1271   
1272   TDirectory *savedir=gDirectory;
1273   TFile *prf_file = TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1274   if (!prf_file->IsOpen()) 
1275     { 
1276       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::MakeInitFile","File")
1277         <<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !"<<ENDLOG;
1278       return kFALSE;
1279     }
1280   prfinner ->Read("prf_07504_Gati_056068_d02");
1281   prfouter1->Read("prf_10006_Gati_047051_d03");
1282   prfouter2->Read("prf_15006_Gati_047051_d03");  
1283   prf_file->Close();
1284   savedir->cd();
1285   
1286   param->SetInnerPRF(prfinner);
1287   param->SetOuter1PRF(prfouter1); 
1288   param->SetOuter2PRF(prfouter2);
1289   param->SetTimeRF(rf);
1290   
1291   fgNTimeBins = param->GetMaxTBin()+1;
1292   fgNRowLow = param->GetNRowLow();
1293   fgNRowUp  = param->GetNRowUp();
1294   fgNRowUp1 = param->GetNRowUp1();
1295   fgNRowUp2 = param->GetNRowUp2();
1296   fgNRow= fgNRowLow + fgNRowUp;
1297   if(fgNRow!=159){
1298     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::MakeInitFile","fNRow")
1299       <<"Number of rows have changed in ALIROOT"<<ENDLOG;
1300     return kFALSE;
1301   }
1302   
1303   fgNSectorLow = param->GetNInnerSector();
1304   fgNSectorUp = param->GetNOuterSector();
1305   fgNSector = fgNSectorLow + fgNSectorUp;
1306
1307   //test whether they were changes to the rotation shift
1308   fgNRotShift=0;
1309   Float_t irotshift = param->GetInnerAngleShift(); //shift angle
1310   Float_t orotshift = param->GetOuterAngleShift(); //shift angle
1311   const Float_t kDegtoRad = 0.01745329251994;
1312   Int_t shift1=TMath::Nint(irotshift/kDegtoRad);
1313   Int_t shift2=TMath::Nint(orotshift/kDegtoRad+0.1);
1314   if((shift1!=shift2) || (shift1!=10)){
1315     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::MakeInitFile","Rotshiftangle")
1316       <<"Rotation shift angle has changed in ALIROOT"<<ENDLOG;
1317     return kFALSE;
1318   } else {
1319     fgNRotShift=0.5; //our version of the shift angle
1320   }
1321   
1322   fgVersion=kValiroot;
1323   AliMagF* mag = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
1324   double fc = mag ? mag->GetFactorSol() : 0;
1325   double bz = mag ? -mag->SolenoidField() : 0;
1326   if (fc!=0) bz/=fc;
1327   SetBFieldFactor( fc );
1328   SetSolenoidBField( bz );
1329
1330   //   SetBFieldFactor((Double_t)l((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Factor());
1331   //   SetSolenoidBField(-
1332   //                (Double_t)l((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->SolenoidField()/
1333   //                (Double_t)l((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Factor()
1334   //                );
1335   fgPadPitchWidthLow=param->GetInnerPadPitchWidth();
1336   fgPadPitchWidthUp=param->GetOuterPadPitchWidth();
1337   fgZWidth=param->GetZWidth();
1338   fgZSigma=param->GetZSigma();
1339   // Matthias 24.04.2007 a default parameter has been added to GetZLength
1340   // reverting some of Mareks changes
1341   // TODO: we have to use the method correctly and put the slice no into it
1342   //fgZLength=param->GetZLength(0)+0.275;
1343   fgZLength=param->GetZLength()+0.275;
1344   fgZOffset=param->GetZOffset();
1345   fgDiffT=param->GetDiffT();
1346   fgDiffL=param->GetDiffL();
1347   fgOmegaTau=param->GetOmegaTau();
1348   fgInnerPadLength=param->GetInnerPadLength();
1349   fgOuter1PadLength=param->GetOuter1PadLength();
1350   fgOuter2PadLength=param->GetOuter2PadLength();
1351   fgInnerPRFSigma=param->GetInnerPRF()->GetSigmaX();
1352   fgOuter1PRFSigma=param->GetOuter1PRF()->GetSigmaX();
1353   fgOuter2PRFSigma=param->GetOuter2PRF()->GetSigmaX();
1354   fgTimeSigma=param->GetTimeRF()->GetSigma();
1355   fgADCSat=param->GetADCSat();
1356   fgZeroSup=param->GetZeroSup();
1357   fgNSlice=fgNSectorLow;
1358     
1359   //now do the arrays
1360   for(Int_t i=0;i<fgNRow;i++){
1361     Int_t sec,row;
1362     if( i < fgNRowLow){sec =0;row =i;}
1363     else{sec = fgNSectorLow;row =i-fgNRowLow;}
1364     fgX[i]=param->GetPadRowRadii(sec,row);
1365   } 
1366   for(Int_t i=0;i<fgNRow;i++){
1367     Int_t sec,row;
1368     if( i < fgNRowLow){sec =0;row =i;}
1369     else{sec = fgNSectorLow;row =i-fgNRowLow;}
1370     fgNPads[i]=param->GetNPads(sec,row);
1371   }
1372   for(Int_t i=0;i<fgNSector;i++){
1373     if(i<fgNSectorLow) fgSectorLow[i]=1;
1374     else fgSectorLow[i]=0;
1375   }
1376
1377   delete lgAlice;
1378   rootfile->Close();
1379   delete rootfile;
1380
1381   return SaveInitFile(filename);
1382 #endif
1383 }
1384
1385 Bool_t AliHLTTPCTransform::SaveInitFile(Char_t *filenamepath)
1386 {
1387   //store the parameters in the file "filenamepath"
1388   
1389   FILE *f = fopen(filenamepath,"w");
1390   if(!f){
1391     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::SaveInitFile","File")
1392         <<"Could not open file: "<<filenamepath<<ENDLOG;
1393     return kFALSE;
1394   }
1395
1396   fprintf(f,"void AliHLTTPCTransform::Init(){\n");
1397   fprintf(f,"  fVersion = %d;\n", fgVersion); 
1398   fprintf(f,"  fBFieldFactor = %.3f;\n",fgBFieldFactor);
1399   fprintf(f,"  fSolenoidBField = %.3f;\n",fgSolenoidBField);
1400   fprintf(f,"  fNTimeBins = %d;\n",fgNTimeBins);
1401   fprintf(f,"  fNRowLow = %d;\n",fgNRowLow);
1402   fprintf(f,"  fNRowUp = %d;\n",fgNRowUp);
1403   fprintf(f,"  fNRowUp1 = %d;\n",fgNRowUp1);
1404   fprintf(f,"  fNRowUp2 = %d;\n",fgNRowUp2);
1405   fprintf(f,"  fNSectorLow = %d;\n",fgNSectorLow);
1406   fprintf(f,"  fNSectorUp = %d;\n",fgNSectorUp);
1407   fprintf(f,"  fNSector = %d;\n",fgNSector);
1408   fprintf(f,"  fPadPitchWidthLow = %.3f;\n",fgPadPitchWidthLow);
1409   fprintf(f,"  fPadPitchWidthUp = %.3f;\n",fgPadPitchWidthUp);
1410   fprintf(f,"  fZWidth = %.4f;\n",fgZWidth);
1411   fprintf(f,"  fZSigma = %.4f;\n",fgZSigma);
1412   fprintf(f,"  fZLength = %.4f;\n",fgZLength);
1413   fprintf(f,"  fZOffset = %.4f;\n",fgZOffset);
1414   fprintf(f,"  fDiffT = %.4f;\n",fgDiffT);
1415   fprintf(f,"  fDiffL = %.4f;\n",fgDiffL);
1416   fprintf(f,"  fOmegaTau = %.4f;\n",fgOmegaTau);
1417   fprintf(f,"  fInnerPadLength = %.3f;\n",fgInnerPadLength);
1418   fprintf(f,"  fOuter1PadLength = %.3f;\n",fgOuter1PadLength);
1419   fprintf(f,"  fOuter2PadLength = %.3f;\n",fgOuter2PadLength);
1420   fprintf(f,"  fInnerPRFSigma = %.6f;\n",fgInnerPRFSigma);
1421   fprintf(f,"  fOuter1PRFSigma = %.6f;\n",fgOuter1PRFSigma);
1422   fprintf(f,"  fOuter2PRFSigma = %.6f;\n",fgOuter2PRFSigma);
1423   fprintf(f,"  fTimeSigma = %.6f;\n",fgTimeSigma);
1424   fprintf(f,"  fADCSat = %d;\n",fgADCSat);
1425   fprintf(f,"  fZeroSup = %d;\n",fgZeroSup);
1426   fprintf(f,"  fNSlice = %d;\n",fgNSlice);
1427   fprintf(f,"  fNRow = %d;\n",fgNRow);
1428   fprintf(f,"  fNRotShift = %.2f;\n",fgNRotShift);
1429   //now do the arrays
1430   for(Int_t i=0;i<fgNRow;i++){
1431     fprintf(f,"  fX[%d] = %3.2f;\n",i,fgX[i]);
1432   } 
1433   for(Int_t i=0;i<fgNRow;i++){
1434     fprintf(f,"  fNPads[%d] = %d;\n",i,fgNPads[i]);
1435   }
1436
1437   //Slice/Sector dont belong to aliroot, but we want to be flexible
1438   for(Int_t i=0;i<fgNSlice;i++){
1439     fprintf(f,"  fSlice2Sector[%d][0] = %d;\n",i,fgSlice2Sector[i][0]);
1440     fprintf(f,"  fSlice2Sector[%d][1] = %d;\n",i,fgSlice2Sector[i][1]);
1441   }  
1442   for(Int_t i=0;i<fgNSector;i++){
1443     fprintf(f,"  fSector2Slice[%d] = %d;\n",i,fgSector2Slice[i]);
1444   }  
1445   for(Int_t i=0;i<fgNSector;i++){
1446     fprintf(f,"  fSectorLow[%d] = %d;\n",i,fgSectorLow[i]);
1447   }  
1448
1449   //Patches also dont really belong to the aliroot settings (but nevermind)
1450   for(Int_t i=0;i<fgNPatches;i++){
1451     fprintf(f,"  fNRows[%d] = %d;\n",i,fgNRows[i]);
1452   }  
1453   for(Int_t i=0;i<fgNPatches;i++){
1454     fprintf(f,"  fRows[%d][0] = %d;\n",i,fgRows[i][0]);
1455     fprintf(f,"  fRows[%d][1] = %d;\n",i,fgRows[i][1]);
1456   }  
1457
1458   //Rotation shift is an addon, too
1459   for(Int_t i=0;i<fgNSlice;i++){
1460     Float_t cs = cos( (2*fgkPi/18) * (i+fgNRotShift) );
1461     fprintf(f,"  fCos[%d] = %.10f;\n",i,cs);
1462   }
1463   for(Int_t i=0;i<fgNSlice;i++){
1464     Float_t sn = sin( (2*fgkPi/18) * (i+fgNRotShift) );
1465     fprintf(f,"  fSin[%d] = %.10f;\n",i,sn);
1466   }
1467
1468   fprintf(f,"}\n");
1469   fclose(f);
1470
1471   LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTransform::SaveInitFile","File created")
1472     <<"Init file \""<<filenamepath<<"\" created"<<ENDLOG;
1473
1474   return kTRUE;
1475 }
1476
1477 Int_t AliHLTTPCTransform::GetNPads(Int_t row)
1478 {
1479   //get number of pads per row
1480   if(row < 0 || row >= fgNRow)
1481     {
1482       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetNPads","Row")
1483         <<AliHLTTPCLog::kDec<<"Wrong row "<<row<<ENDLOG;
1484       return 0;
1485     }
1486
1487   return fgNPads[row];
1488 }
1489
1490 Int_t AliHLTTPCTransform::GetNumberOfPatches() {
1491   return fgNPatches;
1492 }
1493
1494 Int_t AliHLTTPCTransform::GetFirstRow(Int_t patch)
1495 {
1496   //get first row per patch
1497
1498   if(patch==-1)
1499     return 0;
1500   else if(patch < -1 || patch >= 6)
1501     {
1502       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetFirstRow","Patch")
1503         <<AliHLTTPCLog::kDec<<"Wrong patch "<<patch<<ENDLOG;
1504       return 0;
1505     }
1506   else
1507     return fgRows[patch][0];
1508 }
1509
1510 Int_t AliHLTTPCTransform::GetLastRow(Int_t patch)
1511 {
1512   //get last row per patch
1513   if(patch==-1)
1514     return fgRows[5][1];
1515   else if(patch < -1 || patch >= 6)
1516     {
1517       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetLastRow","Patch")
1518         <<AliHLTTPCLog::kDec<<"Wrong patch "<<patch<<ENDLOG;
1519       return 0;
1520     }
1521   else
1522     return fgRows[patch][1];
1523 }
1524
1525 Int_t AliHLTTPCTransform::GetFirstRowOnDDL(Int_t patch)
1526 {
1527   //get first row per patch
1528
1529   if(patch==-1)
1530     return 0;
1531   else if(patch < -1 || patch >= 6)
1532     {
1533       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetFirstRow","Patch")
1534         <<AliHLTTPCLog::kDec<<"Wrong patch "<<patch<<ENDLOG;
1535       return 0;
1536     }
1537   else
1538     {
1539       if(patch==1) return fgRows[patch][0]+1;
1540       return fgRows[patch][0];
1541     }
1542 }
1543
1544 Int_t AliHLTTPCTransform::GetLastRowOnDDL(Int_t patch)
1545 {
1546   //get last row per patch
1547   if(patch==-1)
1548     return fgRows[5][1];
1549   else if(patch < -1 || patch >= 6)
1550     {
1551       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetLastRow","Patch")
1552         <<AliHLTTPCLog::kDec<<"Wrong patch "<<patch<<ENDLOG;
1553       return 0;
1554     }
1555   else
1556     {
1557       if(patch==2 || patch==4) return fgRows[patch][1]-1;
1558       return fgRows[patch][1];
1559     }
1560 }
1561
1562 Int_t AliHLTTPCTransform::GetNRows(Int_t patch)
1563 {
1564   //get number of rows per patch
1565   if(patch==-1)
1566     return fgNRow;
1567   else if(patch < -1 || patch >= 6)
1568     {
1569       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetNRows","Patch")
1570         <<AliHLTTPCLog::kDec<<"Wrong patch "<<patch<<ENDLOG;
1571       return 0;
1572     }
1573   else
1574     return fgNRows[patch];
1575 }
1576
1577 Int_t AliHLTTPCTransform::GetPadRow(Float_t xvalue)
1578 {
1579   //Find the padrow number corresponding to cartesian _local_ x value
1580   if(xvalue < 0 || xvalue > 250)
1581     {
1582       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetPadRow","X-value")
1583         <<AliHLTTPCLog::kDec<<"Suspicious x-value, make sure it is in local coordinate! "
1584         <<xvalue<<ENDLOG;
1585       return -1;
1586     }
1587   
1588   Int_t x = (Int_t)rint(xvalue*10);
1589   if(x < (Int_t)rint(fgX[1]*10))
1590     return 0;
1591   else if(x > (Int_t)rint(fgX[fgNRow-2]*10))
1592     return fgNRow-1;
1593   else
1594     {
1595       Int_t padrow=1; //Of course, a more clever algorithm could help here
1596       while(padrow < fgNRow-2)
1597         {
1598           if(x > (Int_t)rint(fgX[padrow-1]*10) && x < (Int_t)rint(fgX[padrow+1]*10))
1599             break;
1600           padrow++;
1601         }
1602       return padrow;
1603     }
1604 }
1605
1606 Int_t AliHLTTPCTransform::GetPatch(Int_t padrow)
1607 {
1608   //get patch for padrow
1609   if(padrow < 0 || padrow >= fgNRow)
1610     {
1611       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetPatch","Padrow")
1612         <<AliHLTTPCLog::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
1613       return -2;
1614     }
1615   Int_t patch=0;
1616   while(patch < fgNPatches)
1617     {
1618       if(padrow >= fgRows[patch][0] && padrow <= fgRows[patch][1])
1619         break;
1620       patch++;
1621     }
1622   return patch;
1623 }
1624
1625 Double_t AliHLTTPCTransform::GetPadLength(Int_t padrow)
1626 {
1627   //get pad length for padrow
1628   if(padrow >= fgNRow){
1629       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetPadLength","Padrow")
1630         <<AliHLTTPCLog::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
1631       return 0;
1632     }
1633
1634   if(padrow < fgNRowLow)
1635     return fgInnerPadLength;
1636   if(padrow >= fgNRowLow && padrow < fgNRowLow + fgNRowUp1 - 1)
1637     return fgOuter1PadLength;
1638   if(padrow >= fgNRowLow + fgNRowUp1 - 1)
1639     return fgOuter2PadLength;
1640
1641   //should never happen
1642   LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetPadLength","Padrow")
1643     <<AliHLTTPCLog::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
1644   return -1.0; 
1645 }
1646
1647 Double_t AliHLTTPCTransform::GetPadPitchWidth(Int_t patch)
1648 {
1649   //get pad patch width for patch
1650   if(patch < 0 || patch > fgNPatches)
1651     {
1652       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetPadPitchWidth","patct")
1653         <<AliHLTTPCLog::kDec<<"Wrong patch "<<patch<<ENDLOG;
1654       return -1;
1655     }
1656   return patch < 2 ? fgPadPitchWidthLow : fgPadPitchWidthUp;  
1657 }
1658
1659 Double_t AliHLTTPCTransform::GetParSigmaY2(Int_t padrow,Float_t z,Float_t angle)
1660 {
1661   //Calculate the expected transverse cluster width as a function of 
1662   //drift distance and crossing angle.
1663   //z = local z-coordinate of cluster
1664   //angle = track crossing angle with normal to padrow plane
1665   //return value = sigma^2 (cartesian coordinates)
1666
1667   Double_t drift;
1668   if(z > 0)
1669     drift = fgZLength - z;
1670   else
1671     drift = fgZLength + z;
1672   
1673   Double_t t1 = GetPRFSigma(padrow)*GetPRFSigma(padrow);
1674   Double_t t2 = fgDiffT*fgDiffT*drift;
1675   Double_t t3 = GetPadLength(padrow)*GetPadLength(padrow)*tan(angle)*tan(angle)/12;
1676   Double_t t4 = fgkAnodeWireSpacing*fgkAnodeWireSpacing*(tan(angle) - fgOmegaTau)*(tan(angle) - fgOmegaTau)/12;
1677
1678   return (t1 + t2 + t3 + t4);
1679 }
1680
1681 Double_t AliHLTTPCTransform::GetParSigmaZ2(Int_t padrow,Float_t z,Float_t tgl)
1682 {
1683   //Calculate the expected longitudinal cluster width as a function of 
1684   //drift distance and track crossing angle.
1685   //z = local z-coordinate of cluster
1686   //tgl = tan(dipangle) 
1687   //return value = sigma^2 (cartesian coordinates)
1688
1689   Double_t drift;
1690   if(z > 0)
1691     drift = AliHLTTPCTransform::GetZLength()-0.275 - z;
1692   else
1693     drift = AliHLTTPCTransform::GetZLength()-0.302 + z;
1694   
1695   Double_t t1 = fgZSigma*fgZSigma;
1696   Double_t t2 = fgDiffL*fgDiffL*drift;
1697   Double_t t3 = GetPadLength(padrow)*GetPadLength(padrow)*tgl*tgl/12;
1698   
1699   return (t1 + t2 + t3);
1700 }
1701
1702 Double_t AliHLTTPCTransform::GetPRFSigma(Int_t padrow)
1703 {
1704   //get sigma of pad response function for padrow
1705
1706   if(padrow >= fgNRow){
1707     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetPRFSigma","Padrow")
1708       <<AliHLTTPCLog::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
1709     return 0;
1710   }
1711   if(padrow < fgNRowLow)
1712     return fgInnerPRFSigma;
1713   if(padrow >= fgNRowLow && padrow < fgNRowLow + fgNRowUp1 - 1)
1714     return fgOuter1PRFSigma;
1715   if(padrow >= fgNRowLow + fgNRowUp1 - 1)
1716     return fgOuter2PRFSigma;
1717
1718   //should never happen
1719   LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetPRFSigma","Padrow")
1720     <<AliHLTTPCLog::kDec<<"Wrong padrow "<<padrow<<ENDLOG;
1721   return -1.; 
1722 }
1723
1724 Double_t AliHLTTPCTransform::GetEta(Float_t *xyz)
1725 {
1726   //get eta
1727   Double_t r3 = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]+xyz[2]*xyz[2]);
1728   Double_t eta = 0.5 * log((r3+xyz[2])/(r3-xyz[2]));
1729   return eta;
1730 }
1731
1732 void AliHLTTPCTransform::XYZtoRPhiEta(Float_t *rpe, Float_t *xyz)
1733 {
1734   //transform xyz into rpe
1735   rpe[0] = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]+xyz[2]*xyz[2]);
1736   rpe[1] = atan2(xyz[1],xyz[0]);
1737   rpe[2] = 0.5 * log((rpe[0]+xyz[2])/(rpe[0]-xyz[2]));
1738 }
1739
1740 Double_t AliHLTTPCTransform::GetEta(Int_t slice,Int_t padrow,Int_t pad,Int_t time)
1741 {
1742   //get eta
1743   Float_t xyz[3];
1744   Int_t sector,row;
1745   Slice2Sector(slice,padrow,sector,row);
1746   Raw2Local(xyz,sector,row,pad,time);
1747   
1748   return GetEta(xyz);
1749 }
1750
1751 Double_t AliHLTTPCTransform::GetPhi(Float_t *xyz)
1752 {
1753   //get phi
1754   Double_t phi = atan2(xyz[1],xyz[0]);
1755   return phi;
1756 }
1757
1758 Bool_t AliHLTTPCTransform::Slice2Sector(Int_t slice, Int_t slicerow, Int_t & sector, Int_t &row)
1759 {
1760   //slice no to sector number
1761   //row no to local sector row no
1762   if(slicerow<0&&slicerow>=fgNRow){
1763     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Slice2Sector","Slicerow")
1764       <<AliHLTTPCLog::kDec<<"Wrong slicerow "<<slicerow<<ENDLOG;
1765     return kFALSE;
1766   }
1767   if(slice<0||slice>=fgNSlice){
1768     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Slice2Sector","Slice")
1769       <<AliHLTTPCLog::kDec<<"Wrong slice "<<slice<<ENDLOG;
1770     return kFALSE;
1771   }
1772
1773   if(slicerow<fgNRowLow){
1774     sector = fgSlice2Sector[slice][0];
1775     row    = slicerow;
1776   }
1777   else {
1778     sector = fgSlice2Sector[slice][1];
1779     row    = slicerow-fgNRowLow;
1780   }
1781
1782   return kTRUE;
1783 }
1784
1785 Bool_t AliHLTTPCTransform::Sector2Slice(Int_t & slice, Int_t  sector)
1786 {
1787   //sector to slice
1788   if(sector<0||sector>=fgNSector){
1789     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Sector2Slice","Sector")
1790       <<AliHLTTPCLog::kDec<<"Wrong sector "<<sector<<ENDLOG;
1791     return kFALSE;
1792   }
1793
1794   slice=fgSector2Slice[sector];
1795
1796   return kTRUE;
1797 }
1798
1799 Bool_t AliHLTTPCTransform::Sector2Slice(Int_t & slice, Int_t & slicerow, Int_t sector, Int_t row)
1800 {
1801   //sector to slice
1802   if(sector<0 || sector>=fgNSector){
1803     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Sector2Slice","Sector")
1804       <<AliHLTTPCLog::kDec<<"Wrong sector "<<sector<<ENDLOG;
1805     return kFALSE;
1806   }
1807   if(row<0){
1808     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Sector2Slice","Row")
1809       <<AliHLTTPCLog::kDec<<"Wrong row "<<row<<ENDLOG;
1810     return kFALSE;
1811   }
1812
1813   if(fgSectorLow[sector]){
1814     if(row>=fgNRowLow){
1815       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Sector2Slice","Row")
1816         <<AliHLTTPCLog::kDec<<"Wrong row "<<row<<ENDLOG;
1817       return kFALSE;
1818     }
1819     slice = fgSector2Slice[sector];
1820     slicerow = row;
1821   }
1822   else{
1823     if(row>=fgNRowUp){
1824       LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Sector2Slice","Row")
1825         <<AliHLTTPCLog::kDec<<"Wrong row "<<row<<ENDLOG;
1826       return kFALSE;
1827     }
1828     slice = fgSector2Slice[sector];
1829     slicerow = row + fgNRowLow;
1830   }
1831
1832   return kTRUE;
1833 }
1834
1835 Double_t AliHLTTPCTransform::GetMaxY(Int_t slicerow)
1836 {
1837   //get maximum y value (for slice 0)
1838   if (slicerow>=fgNRow) {
1839     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetMaxY","Slicerow")
1840       <<AliHLTTPCLog::kDec<<"slicerow out of range"<<slicerow<<ENDLOG;
1841   }
1842  if(slicerow < fgNRowLow)
1843      return fgPadPitchWidthLow*fgNPads[slicerow]/2; 
1844  
1845  else
1846      return fgPadPitchWidthUp*fgNPads[slicerow]/2;
1847
1848 }
1849
1850 Double_t AliHLTTPCTransform::Row2X(Int_t slicerow)
1851 {
1852   //slicerow to X value (slice 0)
1853   if(slicerow<0||slicerow>=fgNRow){
1854     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::Row2X","Slicerow")
1855       <<AliHLTTPCLog::kDec<<"Wrong slicerow "<<slicerow<<ENDLOG;
1856     return 0;
1857   }
1858   return fgX[slicerow];
1859 }
1860
1861 Double_t AliHLTTPCTransform::GetZFast(Int_t slice, Int_t time, Float_t vertex)
1862 {
1863   //get z value
1864   Double_t z=fgZWidth*time-fgZOffset;
1865   if(slice < 18)
1866     z=fgZLength-z-vertex;
1867   else
1868     z=z-fgZLength-vertex;
1869   return z;
1870 }
1871
1872 void AliHLTTPCTransform::Local2Global(Float_t *xyz,Int_t slice)
1873 {
1874   //Transformation to global coordinate system
1875   Float_t x0 = xyz[0];
1876   Float_t y0 = xyz[1];
1877
1878   xyz[0]=x0*fgCos[slice]-y0*fgSin[slice];
1879   xyz[1]=x0*fgSin[slice]+y0*fgCos[slice];
1880   xyz[2]=xyz[2];//global z=local z
1881 }
1882
1883 void AliHLTTPCTransform::Local2GlobalAngle(Float_t *angle,Int_t slice)
1884 {
1885   //get angle global
1886   angle[0] = fmod(angle[0]+(slice+fgNRotShift)*(2*fgkPi/18),2*fgkPi);
1887 }
1888
1889 void AliHLTTPCTransform::Global2LocalAngle(Float_t *angle,Int_t slice)
1890 {
1891   //get angle local
1892   angle[0] = angle[0]-(slice+fgNRotShift)*(2*fgkPi/18);
1893   if(angle[0]<0) angle[0]+=2*fgkPi;
1894 }
1895
1896 void AliHLTTPCTransform::Raw2Local(Float_t *xyz,Int_t sector,Int_t row,Float_t pad,Float_t time)
1897 {
1898   //Transformation from rawdata to local coordinate system
1899   
1900   Int_t slice,slicerow;
1901   if (Sector2Slice(slice, slicerow, sector, row)==kFALSE) return;
1902
1903   //X-Value
1904   xyz[0]=Row2X(slicerow); 
1905
1906   //Y-Value
1907   if (slicerow>=fgNRow) {
1908     LOG(AliHLTTPCLog::kError,"AliHLTTPCTransform::GetMaxY","Slicerow")
1909       <<AliHLTTPCLog::kDec<<"slicerow out of range"<<slicerow<<ENDLOG;
1910     return;
1911   }
1912   Int_t npads= fgNPads[slicerow];
1913
1914   if(fgSectorLow[sector])
1915     xyz[1]=(pad-0.5*(npads-1))*fgPadPitchWidthLow;
1916   else
1917     xyz[1]=(pad-0.5*(npads-1))*fgPadPitchWidthUp;
1918
1919   //Z-Value (remember PULSA Delay)
1920   if(slice < 18)
1921     xyz[2]=GetZLength()-GetZWidth()*time+GetZOffset();
1922   else
1923     xyz[2]=GetZWidth()*time-GetZOffset()-GetZLength();
1924 }
1925
1926 void AliHLTTPCTransform::Raw2Local(Float_t *xyz,Int_t sector,Int_t row,Int_t pad,Int_t time)
1927 {
1928   //Transformation from rawdata to local coordinate system
1929   
1930   Int_t slice,slicerow;
1931   Sector2Slice(slice, slicerow, sector, row);  
1932
1933   //X-Value
1934   xyz[0]=Row2X(slicerow); 
1935
1936   //Y-Value
1937   Int_t npads= fgNPads[slicerow];
1938
1939   if(fgSectorLow[sector])
1940     xyz[1]=(pad-0.5*(npads-1))*fgPadPitchWidthLow;
1941   else
1942     xyz[1]=(pad-0.5*(npads-1))*fgPadPitchWidthUp;
1943
1944   //Z-Value (remember PULSA Delay)
1945   if(slice < 18)
1946     xyz[2]=GetZLength()-GetZWidth()*time+GetZOffset();
1947   else
1948     xyz[2]=GetZWidth()*time-GetZOffset()-GetZLength();
1949 }
1950
1951 void AliHLTTPCTransform::RawHLT2Local(Float_t *xyz,Int_t slice,
1952                                Int_t slicerow,Float_t pad,Float_t time)
1953 {
1954   //Transformation from HLT rawdata to local coordinate system
1955   
1956   //X-Value
1957   xyz[0]=Row2X(slicerow); 
1958
1959   //Y-Value
1960   Int_t npads= fgNPads[slicerow];
1961   if(slicerow<fgNRowLow)
1962     xyz[1]=(pad-0.5*(npads-1))*fgPadPitchWidthLow;
1963   else
1964     xyz[1]=(pad-0.5*(npads-1))*fgPadPitchWidthUp;
1965
1966   //Z-Value
1967   if(slice < 18)
1968     xyz[2]=GetZLength()-GetZWidth()*time+GetZOffset();
1969   else
1970     xyz[2]=GetZWidth()*time-GetZOffset()-GetZLength();
1971 }
1972
1973 void AliHLTTPCTransform::RawHLT2Local(Float_t *xyz,Int_t slice,
1974                                Int_t slicerow,Int_t pad,Int_t time)
1975 {
1976   //Transformation from HLT rawdata to local coordinate system
1977   
1978   //X-Value
1979   xyz[0]=Row2X(slicerow); 
1980
1981   //Y-Value
1982   Int_t npads= fgNPads[slicerow];
1983   if(slicerow<fgNRowLow)
1984     xyz[1]=(pad-0.5*(npads-1))*fgPadPitchWidthLow;
1985   else
1986     xyz[1]=(pad-0.5*(npads-1))*fgPadPitchWidthUp;
1987
1988   //Z-Value
1989   if(slice < 18)
1990     xyz[2]=GetZLength()-GetZWidth()*time+GetZOffset();
1991   else
1992     xyz[2]=GetZWidth()*time-GetZOffset()-GetZLength();
1993 }
1994
1995 void AliHLTTPCTransform::Local2Global(Float_t *xyz,Int_t sector,Int_t row)
1996 {
1997   //Transformation to global coordinate system
1998   Int_t slice,slicerow;
1999   Sector2Slice(slice, slicerow, sector, row);  
2000   Float_t r=Row2X(slicerow); //have to get x value first
2001                              
2002   xyz[0]=r*fgCos[slice]-xyz[1]*fgSin[slice];
2003   xyz[1]=r*fgSin[slice]+xyz[1]*fgCos[slice];
2004   xyz[2]=xyz[2];//global z=local z
2005 }
2006
2007 void AliHLTTPCTransform::LocHLT2Global(Float_t *xyz,Int_t slice,Int_t slicerow)
2008 {
2009   //Transformation from HLT to global coordinate system
2010   Float_t r=Row2X(slicerow); //have to get x value first
2011                              
2012   xyz[0]=r*fgCos[slice]-xyz[1]*fgSin[slice];
2013   xyz[1]=r*fgSin[slice]+xyz[1]*fgCos[slice];
2014   xyz[2]=xyz[2];//global z=local z
2015 }
2016
2017 void AliHLTTPCTransform::Global2Local(Float_t *xyz,Int_t sector)
2018 { //check code
2019   Int_t slice;
2020   Sector2Slice(slice, sector);  
2021
2022   Float_t x1 =  xyz[0]*fgCos[slice] + xyz[1]*fgSin[slice];
2023   Float_t y1 = -xyz[0]*fgSin[slice] + xyz[1]*fgCos[slice];
2024   xyz[0] = x1;
2025   xyz[1] = y1;
2026 }
2027
2028 void AliHLTTPCTransform::Global2LocHLT(Float_t *xyz,Int_t slice)
2029 {
2030   Float_t x1 =  xyz[0]*fgCos[slice] + xyz[1]*fgSin[slice];
2031   Float_t y1 = -xyz[0]*fgSin[slice] + xyz[1]*fgCos[slice];
2032   xyz[0] = x1;
2033   xyz[1] = y1;
2034 }
2035
2036 void AliHLTTPCTransform::Raw2Global(Float_t *xyz,Int_t sector,Int_t row,Float_t pad,Float_t time)
2037 {
2038   //Transformation from raw to global coordinates
2039  
2040   Raw2Local(xyz,sector,row,pad,time);
2041   Local2Global(xyz,sector,row);
2042 }
2043
2044 void AliHLTTPCTransform::Raw2Global(Float_t *xyz,Int_t sector,Int_t row,Int_t pad,Int_t time)
2045 {
2046   //Transformation from raw to global coordinates
2047  
2048   Raw2Local(xyz,sector,row,pad,time);
2049   Local2Global(xyz,sector,row);
2050 }
2051
2052 void AliHLTTPCTransform::RawHLT2Global(Float_t *xyz,Int_t slice,
2053                                    Int_t slicerow,Float_t pad,Float_t time)
2054 {
2055   //Transformation from raw to global coordinates
2056  
2057   RawHLT2Local(xyz,slice,slicerow,pad,time);
2058   LocHLT2Global(xyz,slice,slicerow);
2059 }
2060
2061 void AliHLTTPCTransform::RawHLT2Global(Float_t *xyz,Int_t slice,
2062                                    Int_t slicerow,Int_t pad,Int_t time)
2063 {
2064   //Transformation from raw to global coordinates
2065  
2066   RawHLT2Local(xyz,slice,slicerow,pad,time);
2067   LocHLT2Global(xyz,slice,slicerow);
2068 }
2069
2070 void AliHLTTPCTransform::Local2Raw(Float_t *xyz,Int_t sector,Int_t row)
2071 {
2072   //Transformation from local coordinates to raw
2073
2074   Int_t slice,slicerow;
2075   Sector2Slice(slice, slicerow, sector, row);  
2076    
2077   xyz[0]=slicerow;
2078
2079   if(fgSectorLow[sector])
2080     xyz[1]=xyz[1]/fgPadPitchWidthLow+0.5*(fgNPads[slicerow]-1);
2081   else
2082     xyz[1]=xyz[1]/fgPadPitchWidthUp+0.5*(fgNPads[slicerow]-1);
2083
2084   if(slice < 18)
2085     xyz[2]=(GetZLength()-xyz[2]+GetZOffset())/GetZWidth();
2086   else
2087     xyz[2]=(GetZLength()+xyz[2]+GetZOffset())/GetZWidth();
2088 }
2089
2090 void AliHLTTPCTransform::LocHLT2Raw(Float_t *xyz,Int_t slice,Int_t slicerow)
2091 {
2092   //Transformation from local coordinates to raw
2093
2094   xyz[0]=slicerow;
2095
2096   if(slicerow<fgNRowLow)
2097     xyz[1]=xyz[1]/fgPadPitchWidthLow+0.5*(fgNPads[slicerow]-1);
2098   else
2099     xyz[1]=xyz[1]/fgPadPitchWidthUp+0.5*(fgNPads[slicerow]-1);
2100
2101   if(slice < 18)
2102     xyz[2]=(GetZLength()-xyz[2]+GetZOffset())/GetZWidth();
2103   else
2104     xyz[2]=(GetZLength()+xyz[2]+GetZOffset())/GetZWidth();
2105 }
2106
2107 void AliHLTTPCTransform::Global2Raw(Float_t *xyz,Int_t sector,Int_t row)
2108 {
2109   //Transformation from global coordinates to raw. 
2110
2111   Global2Local(xyz,sector);
2112   Local2Raw(xyz,sector,row);
2113 }
2114
2115 void AliHLTTPCTransform::Global2HLT(Float_t *xyz,Int_t slice,Int_t slicerow)
2116 {
2117   //Transformation from global coordinates to raw. 
2118
2119   Global2LocHLT(xyz,slice);
2120   LocHLT2Raw(xyz,slice,slicerow);
2121 }
2122
2123 void AliHLTTPCTransform::PrintCompileOptions()
2124 {
2125   //print compile options
2126 #if defined(__GNUC__)
2127   cout << "Compiler (g++) version used: " << __GNUC__ << endl;
2128 #endif
2129
2130 #ifdef no_root
2131   cout << "STANDALONE version: -Dno_root was given." << endl;
2132 #else
2133   const Char_t *roottest="$ROOTSYS/bin/root -n -b -q  | grep Version | cut -b 17-25 | cut -d\" \" -f1";
2134 #ifdef use_aliroot
2135 #ifdef use_cvs
2136   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";
2137 #else
2138   const Char_t *aliroottest="Unknown";
2139 #endif
2140   cout << "ALIROOT version: -Duse_aliroot and -Duse_root was given." << endl;
2141   cout << "Root Version: " << ROOTVERSION << " found " << flush;
2142   gSystem->Exec(roottest);
2143
2144   cout << "AliRoot Version: " << ALIROOTVERSION << " found " << flush;
2145   gSystem->Exec(aliroottest);
2146 #else
2147   cout << "ROOT version: -Duse_root was given." << endl;
2148   cout << "Root Version: " << ROOTVERSION << " found " << flush;
2149   gSystem->Exec(roottest);
2150 #endif
2151 #endif
2152
2153 #ifdef do_mc
2154   cout << "Using Monte Carlo Info: -Ddo_mc was given." << endl;
2155 #else
2156   cout << "NOT using Monte Carlo Info: -Ddo_mc was not given." << endl;
2157 #endif
2158
2159 #ifdef INCLUDE_TPC_HOUGH
2160   cout << "Including support for TPC Hough transformations." << endl;
2161 #ifdef ROWHOUGHPARAMS
2162   cout << "Using extended AliHLTTPCTrackSegmentData: -DROWHOUGHPARAMS was given." << endl;
2163 #else
2164   cout << "NOT using extended AliHLTTPCTrackSegmentData: -DROWHOUGHPARAMS was not given." << endl;
2165 #endif
2166 #else
2167   cout << "NOT including any support for TPC Hough transformations." << endl;
2168 #endif // INCLUDE_TPC_HOUGH
2169
2170 }