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