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