c35c155351aff8bd7505bdf2dea50fd8d8ea5310
[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>
4 //*-- Copyright &copy ASV
5 // changes done by Constantin Loizides <mailto:loizides@ikf.physik.uni-frankfurt.de>
6
7 #include "AliL3StandardIncludes.h"
8
9 #ifdef use_aliroot
10 #include <AliRun.h>
11 #include <AliMagF.h>
12 #include <AliTPCParamSR.h>
13 #include <AliTPCPRF2D.h>
14 #include <AliTPCRF1D.h>
15 #include <TFile.h>
16 #endif
17
18 #include "AliL3Logging.h"
19 #include "AliL3Transform.h"
20
21 /** \class AliL3Transform 
22 //<pre>
23 //_____________________________________________________________
24 // AliL3Transform
25 //
26 // Transformation class for ALICE TPC.
27 //
28 // Class which contains all detector specific parameters for the TPC,
29 // and different useful functions for coordinate transforms.
30 //
31 // The class is completely static, which means that no object needs
32 // to be instantiated. Function calls should then be done like, e.g.:
33 //
34 // Double_t eta = AliL3Transform::GetEta(xyz);
35 //
36 // IMPORTANT: If used as is, default detector parameters will be used,
37 //            and you really have to make sure that these correspond to
38 //            the AliROOT version you are currently working on!!
39 //            You should therefore always initialize the parameters by
40 //
41 //            AliL3Transform::Init(path);
42 // 
43 //            where path is a char*, giving the path to where file containing
44 //            the detector parameter is located. This file should be called
45 //            "l3transform.config", and can be created with the function MakeInitFile.
46 //            
47 //            You can also force reading the parameters from a AliTPCParam object
48 //            by setting the flag;
49 //
50 //            AliL3Transform::Init(filename,kTRUE);
51 //
52 //            where filename is a char* providing the path to the rootfile which 
53 //            should be called digitfile.root. Note that in this case you have to
54 //            compile with USEPACKAGE=ALIROOT set (see level3code/Makefile.conf).
55 //</pre>
56 */
57
58 ClassImp(AliL3Transform)
59
60 // Defined by HLT group
61 Int_t AliL3Transform::fRows[6][2] = {{0,31},{32,62},{63,86},{87,110},{111,134},{135,158}}; //Defined by us
62 Int_t AliL3Transform::fNRows[6] = {32,31,24,24,24,24}; //Defined by us
63 Double_t AliL3Transform::fAnodeWireSpacing = 0.25; //Taken from the TDR
64
65 // The following definition is generated by Make_Init macro in exa
66 const Double_t AliL3Transform::fBFACT = 0.0029980;
67 Double_t AliL3Transform::fBField = 0.2;
68 Int_t AliL3Transform::fVersion = 0;
69 Int_t AliL3Transform::fNPatches = 6;
70 Int_t AliL3Transform::fBFieldFactor = 1 ;
71 Int_t AliL3Transform::fNTimeBins = 446 ;
72 Int_t AliL3Transform::fNRowLow = 63 ;
73 Int_t AliL3Transform::fNRowUp = 96 ;
74 Int_t AliL3Transform::fNRowUp1 = 64 ;
75 Int_t AliL3Transform::fNRowUp2 = 32 ;
76 Int_t AliL3Transform::fNSectorLow = 36 ;
77 Int_t AliL3Transform::fNSectorUp = 36 ;
78 Int_t AliL3Transform::fNSector = 72 ;
79 Double_t AliL3Transform::fPadPitchWidthLow = 0.400000 ;
80 Double_t AliL3Transform::fPadPitchWidthUp = 0.600000 ;
81 Double_t AliL3Transform::fZWidth = 0.56599998474121093750 ;
82 Double_t AliL3Transform::fZSigma = 0.22880849748219134199 ;
83 Double_t AliL3Transform::fZLength = 250.00000000000000000000 ;
84 Double_t AliL3Transform::fZOffset = 0.68642549244657402596 ;
85 Double_t AliL3Transform::fDiffT = 0.02199999988079071045 ;
86 Double_t AliL3Transform::fDiffL = 0.02199999988079071045 ;
87 Double_t AliL3Transform::fInnerPadLength = 0.750000 ;
88 Double_t AliL3Transform::fOuter1PadLength = 1.000000 ;
89 Double_t AliL3Transform::fOuter2PadLength = 1.500000 ;
90 Double_t AliL3Transform::fInnerPRFSigma = 0.20381128787994384766 ;
91 Double_t AliL3Transform::fOuter1PRFSigma = 0.29932481050491333008 ;
92 Double_t AliL3Transform::fOuter2PRFSigma = 0.29932320117950439453 ;
93 Double_t AliL3Transform::fTimeSigma = 0.22880862653255462646 ;
94 Int_t AliL3Transform::fNSlice = 36 ;
95 Int_t AliL3Transform::fNRow = 159 ;
96 Double_t AliL3Transform::fNRotShift = 0.5 ;
97 Double_t AliL3Transform::fPi = 3.141592653589793 ;
98 Double_t AliL3Transform::fX[159] = {85.194999694824219,
99                                     85.944999694824219,
100                                     86.694999694824219,
101                                     87.444999694824219,
102                                     88.194999694824219,
103                                     88.944999694824219,
104                                     89.694999694824219,
105                                     90.444999694824219,
106                                     91.194999694824219,
107                                     91.944999694824219,
108                                     92.694999694824219,
109                                     93.444999694824219,
110                                     94.194999694824219,
111                                     94.944999694824219,
112                                     95.694999694824219,
113                                     96.444999694824219,
114                                     97.194999694824219,
115                                     97.944999694824219,
116                                     98.694999694824219,
117                                     99.444999694824219,
118                                     100.194999694824219,
119                                     100.944999694824219,
120                                     101.694999694824219,
121                                     102.444999694824219,
122                                     103.194999694824219,
123                                     103.944999694824219,
124                                     104.694999694824219,
125                                     105.444999694824219,
126                                     106.194999694824219,
127                                     106.944999694824219,
128                                     107.694999694824219,
129                                     108.444999694824219,
130                                     109.194999694824219,
131                                     109.944999694824219,
132                                     110.694999694824219,
133                                     111.444999694824219,
134                                     112.194999694824219,
135                                     112.944999694824219,
136                                     113.694999694824219,
137                                     114.444999694824219,
138                                     115.194999694824219,
139                                     115.944999694824219,
140                                     116.694999694824219,
141                                     117.444999694824219,
142                                     118.194999694824219,
143                                     118.944999694824219,
144                                     119.694999694824219,
145                                     120.444999694824219,
146                                     121.194999694824219,
147                                     121.944999694824219,
148                                     122.694999694824219,
149                                     123.444999694824219,
150                                     124.194999694824219,
151                                     124.944999694824219,
152                                     125.694999694824219,
153                                     126.444999694824219,
154                                     127.194999694824219,
155                                     127.944999694824219,
156                                     128.695007324218750,
157                                     129.445007324218750,
158                                     130.195007324218750,
159                                     130.945007324218750,
160                                     131.695007324218750,
161                                     135.180007934570312,
162                                     136.180007934570312,
163                                     137.180007934570312,
164                                     138.180007934570312,
165                                     139.180007934570312,
166                                     140.180007934570312,
167                                     141.180007934570312,
168                                     142.180007934570312,
169                                     143.180007934570312,
170                                     144.180007934570312,
171                                     145.180007934570312,
172                                     146.180007934570312,
173                                     147.180007934570312,
174                                     148.180007934570312,
175                                     149.180007934570312,
176                                     150.180007934570312,
177                                     151.180007934570312,
178                                     152.180007934570312,
179                                     153.180007934570312,
180                                     154.180007934570312,
181                                     155.180007934570312,
182                                     156.180007934570312,
183                                     157.180007934570312,
184                                     158.180007934570312,
185                                     159.180007934570312,
186                                     160.180007934570312,
187                                     161.180007934570312,
188                                     162.180007934570312,
189                                     163.180007934570312,
190                                     164.180007934570312,
191                                     165.180007934570312,
192                                     166.180007934570312,
193                                     167.180007934570312,
194                                     168.180007934570312,
195                                     169.180007934570312,
196                                     170.180007934570312,
197                                     171.180007934570312,
198                                     172.180007934570312,
199                                     173.180007934570312,
200                                     174.180007934570312,
201                                     175.180007934570312,
202                                     176.180007934570312,
203                                     177.180007934570312,
204                                     178.180007934570312,
205                                     179.180007934570312,
206                                     180.180007934570312,
207                                     181.180007934570312,
208                                     182.180007934570312,
209                                     183.180007934570312,
210                                     184.180007934570312,
211                                     185.180007934570312,
212                                     186.180007934570312,
213                                     187.180007934570312,
214                                     188.180007934570312,
215                                     189.180007934570312,
216                                     190.180007934570312,
217                                     191.180007934570312,
218                                     192.180007934570312,
219                                     193.180007934570312,
220                                     194.180007934570312,
221                                     195.180007934570312,
222                                     196.180007934570312,
223                                     197.180007934570312,
224                                     198.180007934570312,
225                                     199.430007934570312,
226                                     200.930007934570312,
227                                     202.430007934570312,
228                                     203.930007934570312,
229                                     205.430007934570312,
230                                     206.930007934570312,
231                                     208.430007934570312,
232                                     209.930007934570312,
233                                     211.430007934570312,
234                                     212.930007934570312,
235                                     214.430007934570312,
236                                     215.930007934570312,
237                                     217.430007934570312,
238                                     218.930007934570312,
239                                     220.430007934570312,
240                                     221.930007934570312,
241                                     223.430007934570312,
242                                     224.930007934570312,
243                                     226.430007934570312,
244                                     227.930007934570312,
245                                     229.430007934570312,
246                                     230.930007934570312,
247                                     232.430007934570312,
248                                     233.930007934570312,
249                                     235.430007934570312,
250                                     236.930007934570312,
251                                     238.430007934570312,
252                                     239.930007934570312,
253                                     241.430007934570312,
254                                     242.930007934570312,
255                                     244.430007934570312,
256                                     245.930007934570312
257 };
258
259 Int_t AliL3Transform::fNPads[159] = {67,
260                                      67,
261                                      69,
262                                      69,
263                                      69,
264                                      71,
265                                      71,
266                                      71,
267                                      73,
268                                      73,
269                                      73,
270                                      75,
271                                      75,
272                                      75,
273                                      77,
274                                      77,
275                                      77,
276                                      79,
277                                      79,
278                                      79,
279                                      81,
280                                      81,
281                                      81,
282                                      83,
283                                      83,
284                                      83,
285                                      85,
286                                      85,
287                                      85,
288                                      87,
289                                      87,
290                                      87,
291                                      89,
292                                      89,
293                                      89,
294                                      91,
295                                      91,
296                                      91,
297                                      93,
298                                      93,
299                                      93,
300                                      95,
301                                      95,
302                                      95,
303                                      97,
304                                      97,
305                                      97,
306                                      99,
307                                      99,
308                                      99,
309                                      99,
310                                      101,
311                                      101,
312                                      101,
313                                      103,
314                                      103,
315                                      103,
316                                      105,
317                                      105,
318                                      105,
319                                      107,
320                                      107,
321                                      107,
322                                      73,
323                                      75,
324                                      75,
325                                      75,
326                                      75,
327                                      77,
328                                      77,
329                                      77,
330                                      79,
331                                      79,
332                                      79,
333                                      81,
334                                      81,
335                                      81,
336                                      81,
337                                      83,
338                                      83,
339                                      83,
340                                      85,
341                                      85,
342                                      85,
343                                      85,
344                                      87,
345                                      87,
346                                      87,
347                                      89,
348                                      89,
349                                      89,
350                                      91,
351                                      91,
352                                      91,
353                                      91,
354                                      93,
355                                      93,
356                                      93,
357                                      95,
358                                      95,
359                                      95,
360                                      95,
361                                      97,
362                                      97,
363                                      97,
364                                      99,
365                                      99,
366                                      99,
367                                      101,
368                                      101,
369                                      101,
370                                      101,
371                                      103,
372                                      103,
373                                      103,
374                                      105,
375                                      105,
376                                      105,
377                                      105,
378                                      107,
379                                      107,
380                                      107,
381                                      109,
382                                      109,
383                                      109,
384                                      111,
385                                      111,
386                                      111,
387                                      113,
388                                      113,
389                                      113,
390                                      115,
391                                      115,
392                                      117,
393                                      117,
394                                      119,
395                                      119,
396                                      121,
397                                      121,
398                                      121,
399                                      123,
400                                      123,
401                                      125,
402                                      125,
403                                      127,
404                                      127,
405                                      127,
406                                      129,
407                                      129,
408                                      131,
409                                      131,
410                                      133,
411                                      133,
412                                      135,
413                                      135,
414                                      135,
415                                      137,
416                                      137,
417                                      139
418 };
419
420 void AliL3Transform::Init(Char_t* path,Bool_t UseAliTPCParam)
421 {
422   //Overwrite the parameters with values stored in file "l3transform.config" in path.
423   //If file does not exist, old default values will be used.
424   //If flag UseAliTPCParam is set, the parameters will be read from the the rootfile
425   //which then has to be called path/digitfile.root
426   
427   if(fVersion != 0)
428     LOG(AliL3Log::kWarning,"AliL3Transform::Init","Init values")
429       <<"You are initializing the parameters more than once; check your code please! "<<fVersion<<ENDLOG;
430   
431   if(UseAliTPCParam)
432     {
433       ReadInit(path);
434       return;
435     }
436
437   Char_t *pathname=new Char_t[1024];
438   strcpy(pathname,path);
439   strcat(pathname,"/l3transform.config");
440   
441   FILE *fptr=fopen(pathname,"r");
442   if(!fptr){
443     LOG(AliL3Log::kWarning,"AliL3Transform::Init","File Open")
444       <<"Pointer to Config File \""<<pathname<<"\" 0x0!"<<ENDLOG;
445     return;
446   }
447
448   Char_t d1[250], d2[100], d3[100];
449   Int_t dummy=0;
450   Double_t ddummy=0.0;
451
452   while(!feof(fptr)) {
453     fscanf(fptr,"%s",d1);
454
455     if(strcmp(d1,"fBFieldFactor")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fBFieldFactor=(Int_t)dummy;fBField=fBFieldFactor*0.2;}
456     else if(strcmp(d1,"fNTimeBins")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNTimeBins=(Int_t)dummy;}
457     else if(strcmp(d1,"fNRowLow")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowLow=(Int_t)dummy;}    
458     if(fNRowLow != 63)
459       LOG(AliL3Log::kError,"AliL3Transform::Init","Overflow")
460         <<"Number of inner PadRows should be 63! Check and fgrep the code for 63 to see the consequences of this major change!"<<ENDLOG;
461     else if(strcmp(d1,"fNRowUp")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowUp=(Int_t)dummy;}
462     else if(strcmp(d1,"fNRowUp1")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowUp1=(Int_t)dummy;}
463     else if(strcmp(d1,"fNRowUp2")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowUp2=(Int_t)dummy;}
464     else if(strcmp(d1,"fNSectorLow")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSectorLow=(Int_t)dummy;}
465     else if(strcmp(d1,"fNSectorUp")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSectorUp=(Int_t)dummy;}
466     else if(strcmp(d1,"fNSector")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSector=(Int_t)dummy;}
467     else if(strcmp(d1,"fPadPitchWidthLow")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fPadPitchWidthLow=(Double_t)ddummy;}
468     else if(strcmp(d1,"fPadPitchWidthUp")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fPadPitchWidthUp=(Double_t)ddummy;}
469     else if(strcmp(d1,"fZWidth")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZWidth=(Double_t)ddummy;}
470     else if(strcmp(d1,"fZSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZSigma=(Double_t)ddummy;}
471     else if(strcmp(d1,"fZLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZLength=(Double_t)ddummy;}
472     else if(strcmp(d1,"fZOffset")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZOffset=(Double_t)ddummy;}
473     else if(strcmp(d1,"fNSlice")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSlice=(Int_t)dummy;}
474     else if(strcmp(d1,"fDiffT")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fDiffT=(Double_t)ddummy;}
475     else if(strcmp(d1,"fDiffL")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fDiffL=(Double_t)ddummy;}
476     else if(strcmp(d1,"fInnerPadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fInnerPadLength=(Double_t)ddummy;}
477     else if(strcmp(d1,"fOuter1PadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter1PadLength=(Double_t)ddummy;}
478     else if(strcmp(d1,"fOuter2PadLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter2PadLength=(Double_t)ddummy;}
479     else if(strcmp(d1,"fInnerPRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fInnerPRFSigma=(Double_t)ddummy;}
480     else if(strcmp(d1,"fOuter1PRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter1PRFSigma=(Double_t)ddummy;}
481     else if(strcmp(d1,"fOuter2PRFSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fOuter2PRFSigma=(Double_t)ddummy;}
482     else if(strcmp(d1,"fTimeSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fTimeSigma=(Double_t)ddummy;}
483     else if(strcmp(d1,"fNRow")==0){
484       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRow=(Int_t)dummy;
485       if(fNRow!=159){
486         LOG(AliL3Log::kError,"AliL3Transform::Init","Overflow")<<"Number of PadRows should be 159! Check and fgrep the code for 159 to see the consequences of this major change!"<<ENDLOG;
487       }
488     }
489     else if(strcmp(d1,"fNRotShift")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fNRotShift=(Double_t)ddummy;}
490     else if(strcmp(d1,"fPi")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fPi=(Double_t)ddummy;}
491     else if(strcmp(d1,"fX[0]")==0){
492       fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fX[0]=(Double_t)ddummy;
493       for(Int_t i=1;i<fNRow;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fX[i]=(Double_t)ddummy;}
494     }
495     else if(strcmp(d1,"fNPads[0]")==0){
496       fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNPads[0]=(Int_t)dummy;
497       for(Int_t i=1;i<fNRow;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fNPads[i]=(Int_t)dummy;}
498     }
499   }
500
501   fclose(fptr);
502   delete pathname;
503   fVersion++; //new version
504 }
505 void AliL3Transform::ReadInit(Char_t *path)
506 {
507   //Read all the parameters from a aliroot file, and store it in a temporary 
508   //file which is read by Init. Use this if you want to read the parameters from
509   //the rootfile "every" time.
510   
511 #ifndef use_aliroot
512   LOG(AliL3Log::kError,"AliL3Transform::ReadInit","Version")
513     <<"You have to compile with use_aliroot flag in order to read from AliROOT file"<<ENDLOG;
514   return;
515 #else
516   Char_t filename[1024];
517   sprintf(filename,"%s/alirunfile.root",path);
518   MakeInitFile(filename,"/tmp/");
519   Init("/tmp/");
520 #endif  
521 }
522
523 void AliL3Transform::MakeInitFile(Char_t *filename,Char_t *path)
524 {
525   //Get the parameters from rootfile, and store it on the file "l3transform.config"
526   //which is being read by Init.
527   
528 #ifndef use_aliroot
529   LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","Version")
530     <<"You have to compile with use_aliroot flag in order to use this function"<<ENDLOG;
531   return;
532 #else
533   TFile *rootfile = TFile::Open(filename);
534   AliRun *gAlice = (AliRun*)rootfile->Get("gAlice");
535   if(!gAlice)
536     {
537       LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","File")
538         <<"No gAlice in file: "<<filename<<ENDLOG;
539       return;
540     }  
541   AliTPCParamSR *param=(AliTPCParamSR*)rootfile->Get(GetParamName());
542   if(!param)
543     {
544       LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","File")
545         <<"No TPC parameters found"<<ENDLOG;
546       return;
547     }
548   
549   AliTPCPRF2D    * prfinner   = new AliTPCPRF2D;
550   AliTPCPRF2D    * prfouter1   = new AliTPCPRF2D;
551   AliTPCPRF2D    * prfouter2   = new AliTPCPRF2D;  
552   AliTPCRF1D     * rf    = new AliTPCRF1D(kTRUE);
553   rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
554   rf->SetOffset(3*param->GetZSigma());
555   rf->Update();
556   
557   TDirectory *savedir=gDirectory;
558   TFile *prf_file = TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
559   if (!prf_file->IsOpen()) 
560     { 
561       LOG(AliL3Log::kError,"AliL3Transform::MakeInitFile","File")
562         <<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !"<<ENDLOG;
563       return;
564     }
565   prfinner->Read("prf_07504_Gati_056068_d02");
566   prfouter1->Read("prf_10006_Gati_047051_d03");
567   prfouter2->Read("prf_15006_Gati_047051_d03");  
568   prf_file->Close();
569   savedir->cd();
570   
571   param->SetInnerPRF(prfinner);
572   param->SetOuter1PRF(prfouter1); 
573   param->SetOuter2PRF(prfouter2);
574   param->SetTimeRF(rf);
575   
576   Int_t nTimeBins = param->GetMaxTBin()+1;
577   Int_t nRowLow = param->GetNRowLow();
578   Int_t nRowUp  = param->GetNRowUp();
579   Int_t nRowUp1 = param->GetNRowUp1();
580   Int_t nRowUp2 = param->GetNRowUp2();
581   Int_t nRow= fNRowLow + fNRowUp;
582   Int_t nSectorLow = param->GetNInnerSector();
583   Int_t nSectorUp = param->GetNOuterSector();
584   Int_t nSector = fNSectorLow + fNSectorUp;
585     
586   Char_t tofile[100];
587   sprintf(tofile,"%s/l3transform.config",path);
588   FILE *f = fopen(tofile,"w");
589   fprintf(f,"void AliL3Transform::Init(){\n");
590
591   fprintf(f,"  fBFieldFactor = %d ;\n",(Int_t)gAlice->Field()->Factor());
592   fprintf(f,"  //sector:\n");
593   fprintf(f,"  fNTimeBins = %d ;\n",nTimeBins);
594   fprintf(f,"  fNRowLow = %d ;\n",nRowLow);
595   fprintf(f,"  fNRowUp = %d ;\n",nRowUp);
596   fprintf(f,"  fNRowUp1 = %d ;\n",nRowUp1);
597   fprintf(f,"  fNRowUp2 = %d ;\n",nRowUp2);
598   fprintf(f,"  fNSectorLow = %d ;\n",nSectorLow);
599   fprintf(f,"  fNSectorUp = %d ;\n",nSectorUp);
600   fprintf(f,"  fNSector = %d ;\n",nSector);
601   fprintf(f,"  fPadPitchWidthLow = %f ;\n",param->GetInnerPadPitchWidth());
602   fprintf(f,"  fPadPitchWidthUp = %f ;\n",param->GetOuterPadPitchWidth());
603   fprintf(f,"  fZWidth = %.20f ;\n",param->GetZWidth());
604   fprintf(f,"  fZSigma = %.20f ;\n",param->GetZSigma());
605   fprintf(f,"  fZLength = %.20f ;\n",param->GetZLength());
606   fprintf(f,"  fZOffset = %.20f ;\n",param->GetZOffset());
607   fprintf(f,"  fDiffT = %.20f ;\n",param->GetDiffT());
608   fprintf(f,"  fDiffL = %.20f ;\n",param->GetDiffL());
609   fprintf(f,"  fInnerPadLength = %f ;\n",param->GetInnerPadLength());
610   fprintf(f,"  fOuter1PadLength = %f ;\n",param->GetOuter1PadLength());
611   fprintf(f,"  fOuter2PadLength = %f ;\n",param->GetOuter2PadLength());
612   fprintf(f,"  fInnerPRFSigma = %.20f ;\n",param->GetInnerPRF()->GetSigmaX());
613   fprintf(f,"  fOuter1PRFSigma = %.20f ;\n",param->GetOuter1PRF()->GetSigmaX());
614   fprintf(f,"  fOuter2PRFSigma = %.20f ;\n",param->GetOuter2PRF()->GetSigmaX());
615   
616   fprintf(f,"  fTimeSigma = %.20f ;\n",param->GetTimeRF()->GetSigma());
617   
618   fprintf(f,"\n  //slices:\n");
619   fprintf(f,"  fNSlice = %d ;\n",nSectorLow);
620   fprintf(f,"  fNRow = %d ;\n",nRow);
621
622   //rotation shift put in by hand -> Constantin 
623   fprintf(f,"  fNRotShift = 0.5 ;\n");
624
625   fprintf(f,"  fPi = %.15f ;\n",TMath::Pi());
626   
627   for(Int_t i=0;i<nRow;i++){
628     Int_t sec,row;
629     if( i < nRowLow){sec =0;row =i;}
630     else{sec = nSectorLow;row =i-nRowLow;}
631     fprintf(f,"  fX[%d] = %3.15f ;\n",i,param->GetPadRowRadii(sec,row));
632   }
633   for(Int_t i=0;i<nRow;i++){
634     Int_t sec,row;
635     if( i < nRowLow){sec =0;row =i;}
636     else{sec = nSectorLow;row =i-nRowLow;}
637     fprintf(f,"  fNPads[%d] = %d ;\n",i,param->GetNPads(sec,row));
638   }
639   
640   fprintf(f,"}\n");
641   fclose(f);
642 #endif
643 }
644
645 Double_t AliL3Transform::GetPadLength(Int_t padrow)
646 {
647   if(padrow >= fNRow)
648     return 0;
649   if(padrow < fNRowLow)
650     return fInnerPadLength;
651   if(padrow >= fNRowLow && padrow < fNRowLow + fNRowUp1 - 1)
652     return fOuter1PadLength;
653   if(padrow >= fNRowLow + fNRowUp1 - 1)
654     return fOuter2PadLength;
655
656   return -1.0; //should never happen
657 }
658
659 Double_t AliL3Transform::GetPRFSigma(Int_t padrow)
660 {
661   if(padrow >= fNRow)
662     return 0;
663   if(padrow < fNRowLow)
664     return fInnerPRFSigma;
665   if(padrow >= fNRowLow && padrow < fNRowLow + fNRowUp1 - 1)
666     return fOuter1PRFSigma;
667   if(padrow >= fNRowLow + fNRowUp1 - 1)
668     return fOuter2PRFSigma;
669
670   return -1.; //should never happen
671 }
672
673 Double_t AliL3Transform::GetEta(Float_t *xyz)
674 {
675   Double_t r3 = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]+xyz[2]*xyz[2]);
676   Double_t eta = 0.5 * log((r3+xyz[2])/(r3-xyz[2]));
677   return eta;
678 }
679
680 void AliL3Transform::XYZtoRPhiEta(Float_t *rpe, Float_t *xyz)
681 {
682   rpe[0] = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]+xyz[2]*xyz[2]);
683   rpe[1] = atan2(xyz[1],xyz[0]);
684   rpe[2] = 0.5 * log((rpe[0]+xyz[2])/(rpe[0]-xyz[2]));
685 }
686
687 Double_t AliL3Transform::GetEta(Int_t padrow,Int_t pad,Int_t time)
688 {
689   Float_t xyz[3];
690   Int_t sector,row;
691   Slice2Sector(0,padrow,sector,row);
692   Raw2Local(xyz,sector,row,pad,time);
693   
694   return GetEta(xyz);
695 }
696
697 Double_t AliL3Transform::GetPhi(Float_t *xyz)
698 {
699   Double_t phi = atan2(xyz[1],xyz[0]);
700   //if(phi<0) phi=phi+2*TMath::Pi();
701   return phi;
702 }
703
704 Bool_t AliL3Transform::Slice2Sector(Int_t slice, Int_t slicerow, Int_t & sector, Int_t &row)
705 {
706   if(slicerow<0&&slicerow>=fNRow) return kFALSE;
707   if(slice<0||slice>=fNSlice) return kFALSE;
708
709   if(slicerow<fNRowLow){
710     sector = slice;
711     row    = slicerow;
712   }
713   else {
714     sector = slice+fNSlice;
715     row    = slicerow-fNRowLow;
716   }
717   return kTRUE;
718 }
719
720 Bool_t AliL3Transform::Sector2Slice(Int_t & slice, Int_t  sector)
721 {
722   if(sector<0||sector>=fNSector) return kFALSE;
723   if(sector<fNSectorLow) slice = sector;
724   else          slice = sector - fNSectorLow;
725   return kTRUE;
726 }
727
728 Bool_t AliL3Transform::Sector2Slice(Int_t & slice, Int_t & slicerow,Int_t  sector, Int_t row)
729 {
730   if(sector<0||sector>=fNSector||row<0) return kFALSE;
731   if(sector<fNSectorLow){
732     if(row>=fNRowLow) return kFALSE;
733     slice = sector;
734     slicerow = row;
735   }
736   else{
737     if(row>=fNRowUp) return kFALSE;
738     slice = sector - fNSectorLow;
739     slicerow = row + fNRowLow;
740   }
741   return kTRUE;
742 }
743
744 Double_t AliL3Transform::Row2X(Int_t slicerow){
745   if(slicerow<0||slicerow>=fNRow) return 0;
746   return fX[slicerow];
747 }
748
749 void AliL3Transform::Local2Global(Float_t *xyz,Int_t slice)
750 {
751   //Transformation to global coordinate system
752   Float_t x0 = xyz[0];
753   Float_t y0 = xyz[1];
754   Float_t cs,sn;
755   cs = cos( (2*fPi/18) * (slice+fNRotShift) );
756   sn = sin( (2*fPi/18) * (slice+fNRotShift) );
757   xyz[0]=x0*cs-y0*sn;
758   xyz[1]=x0*sn+y0*cs;
759   xyz[2]=xyz[2];//global z=local z
760 }
761
762 void AliL3Transform::Local2GlobalAngle(Float_t *angle,Int_t slice){
763   angle[0] = fmod(angle[0]+(slice+fNRotShift)*(2*fPi/18),2*fPi);
764 }
765
766 void AliL3Transform::Global2LocalAngle(Float_t *angle,Int_t slice){
767   angle[0] = angle[0]-(slice+fNRotShift)*(2*fPi/18);
768   if(angle[0]<0) angle[0]+=2*fPi;
769 }
770
771 void AliL3Transform::Raw2Local(Float_t *xyz,Int_t sector,Int_t row,Float_t pad,Float_t time)
772 {
773   //Transformation from rawdata to local coordinate system
774   
775   Int_t slice,slicerow;
776   Sector2Slice(slice, slicerow, sector, row);  
777
778   //X-Value
779   xyz[0]=Row2X(slicerow); 
780
781   //Y-Value
782   Int_t npads= fNPads[slicerow];
783   if(sector<fNSectorLow)
784     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthLow;
785   else
786     xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthUp;
787
788   //Z-Value (remember PULSA Delay)
789   //xyz[2]=fZWidth*time-3.*fZSigma;
790   xyz[2]=fZWidth*time-fZOffset;
791   if(slice < 18)
792     xyz[2]=fZLength-xyz[2];
793   else
794     xyz[2]=xyz[2]-fZLength;
795   
796 }
797
798 void AliL3Transform::Local2Global(Float_t *xyz,Int_t sector,Int_t row)
799 {
800   //Transformation to global coordinate system
801   Int_t slice,slicerow;
802   Sector2Slice(slice, slicerow, sector, row);  
803   Float_t r=Row2X(slicerow);
804   Float_t cs = cos( (2*fPi/18) * (slice+fNRotShift) );
805   Float_t sn = sin( (2*fPi/18) * (slice+fNRotShift) );
806
807   xyz[0]=r*cs-xyz[1]*sn;
808   xyz[1]=r*sn+xyz[1]*cs;
809   xyz[2]=xyz[2];//global z=local z
810 }
811
812 Double_t AliL3Transform::GetMaxY(Int_t slicerow)
813 {
814
815  if(slicerow < fNRowLow)
816      return fPadPitchWidthLow*fNPads[slicerow]/2; 
817  
818  else
819      return fPadPitchWidthUp*fNPads[slicerow]/2;
820
821 }
822
823 void AliL3Transform::Global2Local(Float_t *xyz,Int_t sector,Bool_t isSlice)
824 {
825   
826   Int_t slice;
827   if(!isSlice)
828     Sector2Slice(slice, sector);  
829   else
830     slice = sector;
831   Float_t cs = cos( (2*fPi/18) * (slice+fNRotShift) );
832   Float_t sn = sin( (2*fPi/18) * (slice+fNRotShift) );
833   Float_t x1 = xyz[0]*cs + xyz[1]*sn;
834   Float_t y1 = -xyz[0]*sn + xyz[1]*cs;
835   xyz[0] = x1;
836   xyz[1] = y1;
837 }
838
839 void AliL3Transform::Raw2Global(Float_t *xyz,Int_t sector,Int_t row,Float_t pad,Float_t time)
840 {
841   //Transformation from raw to global coordinates
842   
843   Raw2Local(xyz,sector,row,pad,time);
844   Local2Global(xyz,sector,row);
845 }
846
847 void AliL3Transform::Local2Raw(Float_t *xyz,Int_t sector,Int_t row)
848 {
849   //Transformation from local coordinates to raw
850
851   Int_t slice,slicerow;
852   Sector2Slice(slice, slicerow, sector, row);  
853    
854   if(sector<fNSectorLow)
855     xyz[1]=xyz[1]/fPadPitchWidthLow+0.5*(fNPads[slicerow]-1);
856   else
857     xyz[1]=xyz[1]/fPadPitchWidthUp+0.5*(fNPads[slicerow]-1);
858   Int_t sign=-1;
859   Int_t nis=fNSectorLow;
860   Int_t nos=fNSectorUp;
861  
862   if ((sector<nis/2) || ((sector-nis)<nos/2)) sign=1; 
863   xyz[2]=fZLength-sign*xyz[2];
864   xyz[2]=(xyz[2]+fZOffset)/fZWidth;
865
866 }
867
868 void AliL3Transform::Global2Raw(Float_t *xyz,Int_t sector,Int_t row)
869 {
870   //Transformation from global coordinates to raw. 
871
872   Global2Local(xyz,sector);
873   Local2Raw(xyz,sector,row);
874
875 }