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