Forgot to check in this the last time. Some changes in AliL3MemHandler as
[u/mrichter/AliRoot.git] / HLT / src / AliL3Transform.cxx
CommitLineData
256c7399 1// $Id$
b661165c 2// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
494fad94 3//*-- Copyright &copy ASV
a4e75a99 4// changes done by Constantin Loizides <mailto:loizides@ikf.physik.uni-frankfurt.de>
256c7399 5
108615fc 6
7#include "AliL3Logging.h"
8#include "AliL3Transform.h"
108615fc 9#include <math.h>
b661165c 10
11//_____________________________________________________________
108615fc 12// AliL3Transform
13//
14// Transformation class for ALICE TPC.
494fad94 15//
16// Class which contains all detector specific parameters for the TPC,
17// and different useful functions for coordinate transforms.
18//
19// The class is completely static, which means that no object needs
20// to be instantiated. Function calls should then be done like:
21//
22// AliL3Transform::GetEta(xyz);
23//
24// IMPORTANT: If used as is, default detector parameters will be used,
25// and you really have to make sure that these correspond to
26// the AliROOT version you are currently working on!!
27// You should therefore always initialize the parameters by
28//
29// AliL3Transform::Init(path);
30//
31// where path is a char*, giving the path to where file containing
32// the detector parameter is located. This file should be called
33// "l3transform.config", and can be created with macro exa/Make_Init.C.
34
35ClassImp(AliL3Transform)
36
37Int_t AliL3Transform::fVersion = 0;
38Int_t AliL3Transform::fNTimeBins = 446 ;
39Int_t AliL3Transform::fNRowLow = 64 ;
40Int_t AliL3Transform::fNRowUp = 112 ;
41Int_t AliL3Transform::fNSectorLow = 36 ;
42Int_t AliL3Transform::fNSectorUp = 36 ;
43Int_t AliL3Transform::fNSector = 72 ;
44Double_t AliL3Transform::fPadPitchWidthLow = 0.400000 ;
45Double_t AliL3Transform::fPadPitchWidthUp = 0.600000 ;
46Double_t AliL3Transform::fZWidth = 0.56599998474121093750 ;
47Double_t AliL3Transform::fZSigma = 0.22880849748219134199 ;
48Double_t AliL3Transform::fZOffset = 0.68642549244657402596;
49Double_t AliL3Transform::fZLength = 250.;
50Int_t AliL3Transform::fNSlice = 36 ;
51Int_t AliL3Transform::fNRow = 176 ;
52Double_t AliL3Transform::fNRotShift = 0.5 ;
53Double_t AliL3Transform::fPi = 3.141592653589793 ;
54Double_t AliL3Transform::fX[176] = {84.570007324218750,
55 85.320007324218750,
56 86.070007324218750,
57 86.820007324218750,
58 87.570007324218750,
59 88.320007324218750,
60 89.070007324218750,
61 89.820007324218750,
62 90.570007324218750,
63 91.320007324218750,
64 92.070007324218750,
65 92.820007324218750,
66 93.570007324218750,
67 94.320007324218750,
68 95.070007324218750,
69 95.820007324218750,
70 96.570007324218750,
71 97.320007324218750,
72 98.070007324218750,
73 98.820007324218750,
74 99.570007324218750,
75 100.320007324218750,
76 101.070007324218750,
77 101.820007324218750,
78 102.570007324218750,
79 103.320007324218750,
80 104.070007324218750,
81 104.820007324218750,
82 105.570007324218750,
83 106.320007324218750,
84 107.070007324218750,
85 107.820007324218750,
86 108.570007324218750,
87 109.320007324218750,
88 110.070007324218750,
89 110.820007324218750,
90 111.570007324218750,
91 112.320007324218750,
92 113.070007324218750,
93 113.820007324218750,
94 114.570007324218750,
95 115.320007324218750,
96 116.070007324218750,
97 116.820007324218750,
98 117.570007324218750,
99 118.320007324218750,
100 119.070007324218750,
101 119.820007324218750,
102 120.570007324218750,
103 121.320007324218750,
104 122.070007324218750,
105 122.820007324218750,
106 123.570007324218750,
107 124.320007324218750,
108 125.070007324218750,
109 125.820007324218750,
110 126.570007324218750,
111 127.320007324218750,
112 128.070007324218750,
113 128.820007324218750,
114 129.570007324218750,
115 130.320007324218750,
116 131.070007324218750,
117 131.820007324218750,
118 135.054992675781250,
119 136.054992675781250,
120 137.054992675781250,
121 138.054992675781250,
122 139.054992675781250,
123 140.054992675781250,
124 141.054992675781250,
125 142.054992675781250,
126 143.054992675781250,
127 144.054992675781250,
128 145.054992675781250,
129 146.054992675781250,
130 147.054992675781250,
131 148.054992675781250,
132 149.054992675781250,
133 150.054992675781250,
134 151.054992675781250,
135 152.054992675781250,
136 153.054992675781250,
137 154.054992675781250,
138 155.054992675781250,
139 156.054992675781250,
140 157.054992675781250,
141 158.054992675781250,
142 159.054992675781250,
143 160.054992675781250,
144 161.054992675781250,
145 162.054992675781250,
146 163.054992675781250,
147 164.054992675781250,
148 165.054992675781250,
149 166.054992675781250,
150 167.054992675781250,
151 168.054992675781250,
152 169.054992675781250,
153 170.054992675781250,
154 171.054992675781250,
155 172.054992675781250,
156 173.054992675781250,
157 174.054992675781250,
158 175.054992675781250,
159 176.054992675781250,
160 177.054992675781250,
161 178.054992675781250,
162 179.054992675781250,
163 180.054992675781250,
164 181.054992675781250,
165 182.054992675781250,
166 183.054992675781250,
167 184.054992675781250,
168 185.054992675781250,
169 186.054992675781250,
170 187.054992675781250,
171 188.054992675781250,
172 189.054992675781250,
173 190.054992675781250,
174 191.054992675781250,
175 192.054992675781250,
176 193.054992675781250,
177 194.054992675781250,
178 195.054992675781250,
179 196.054992675781250,
180 197.054992675781250,
181 198.054992675781250,
182 199.054992675781250,
183 200.054992675781250,
184 201.054992675781250,
185 202.054992675781250,
186 203.054992675781250,
187 204.054992675781250,
188 205.054992675781250,
189 206.054992675781250,
190 207.054992675781250,
191 208.054992675781250,
192 209.054992675781250,
193 210.054992675781250,
194 211.054992675781250,
195 212.054992675781250,
196 213.054992675781250,
197 214.054992675781250,
198 215.054992675781250,
199 216.054992675781250,
200 217.054992675781250,
201 218.054992675781250,
202 219.054992675781250,
203 220.054992675781250,
204 221.054992675781250,
205 222.054992675781250,
206 223.054992675781250,
207 224.054992675781250,
208 225.054992675781250,
209 226.054992675781250,
210 227.054992675781250,
211 228.054992675781250,
212 229.054992675781250,
213 230.054992675781250,
214 231.054992675781250,
215 232.054992675781250,
216 233.054992675781250,
217 234.054992675781250,
218 235.054992675781250,
219 236.054992675781250,
220 237.054992675781250,
221 238.054992675781250,
222 239.054992675781250,
223 240.054992675781250,
224 241.054992675781250,
225 242.054992675781250,
226 243.054992675781250,
227 244.054992675781250,
228 245.054992675781250,
229 246.054992675781250,
230};
231
232Int_t AliL3Transform::fNPads[176] = {67,
233 67,
234 67,
235 69,
236 69,
237 69,
238 71,
239 71,
240 71,
241 73,
242 73,
243 73,
244 75,
245 75,
246 75,
247 77,
248 77,
249 77,
250 79,
251 79,
252 79,
253 81,
254 81,
255 81,
256 83,
257 83,
258 83,
259 85,
260 85,
261 85,
262 87,
263 87,
264 87,
265 89,
266 89,
267 89,
268 91,
269 91,
270 91,
271 93,
272 93,
273 93,
274 95,
275 95,
276 95,
277 97,
278 97,
279 97,
280 99,
281 99,
282 99,
283 101,
284 101,
285 101,
286 103,
287 103,
288 103,
289 105,
290 105,
291 105,
292 107,
293 107,
294 107,
295 109,
296 73,
297 75,
298 75,
299 75,
300 77,
301 77,
302 77,
303 77,
304 79,
305 79,
306 79,
307 81,
308 81,
309 81,
310 83,
311 83,
312 83,
313 83,
314 85,
315 85,
316 85,
317 87,
318 87,
319 87,
320 87,
321 89,
322 89,
323 89,
324 91,
325 91,
326 91,
327 93,
328 93,
329 93,
330 93,
331 95,
332 95,
333 95,
334 97,
335 97,
336 97,
337 97,
338 99,
339 99,
340 99,
341 101,
342 101,
343 101,
344 103,
345 103,
346 103,
347 103,
348 105,
349 105,
350 105,
351 107,
352 107,
353 107,
354 107,
355 109,
356 109,
357 109,
358 111,
359 111,
360 111,
361 113,
362 113,
363 113,
364 113,
365 115,
366 115,
367 115,
368 117,
369 117,
370 117,
371 117,
372 119,
373 119,
374 119,
375 121,
376 121,
377 121,
378 123,
379 123,
380 123,
381 123,
382 125,
383 125,
384 125,
385 127,
386 127,
387 127,
388 127,
389 129,
390 129,
391 129,
392 131,
393 131,
394 131,
395 133,
396 133,
397 133,
398 133,
399 135,
400 135,
401 135,
402 137,
403 137,
404 137,
405 137,
406 139,
407 139,
408};
409
410
411
412void AliL3Transform::Init(const Char_t* path)
f59eed2d 413{
494fad94 414 //Overwrite the parameters with values stored in file "l3transform.config" in path.
415 //If file does not exist, old default values will be used.
b25c64e5 416
f59eed2d 417 Char_t *pathname=new Char_t[1024];
a4e75a99 418 strcpy(pathname,path);
419 strcat(pathname,"/l3transform.config");
494fad94 420
a4e75a99 421 FILE *fptr=fopen(pathname,"r");
422 if(!fptr){
b25c64e5 423 LOG(AliL3Log::kWarning,"AliL3Transform::Init","File Open")
424 <<"Pointer to Config File \""<<pathname<<"\" 0x0!"<<ENDLOG;
a4e75a99 425 return;
426 }
427
f59eed2d 428 Char_t d1[250], d2[100], d3[100];
429 Int_t dummy=0;
430 Double_t ddummy=0.0;
a4e75a99 431
432 while(!feof(fptr)) {
433 fscanf(fptr,"%s",d1);
434
435 if(strcmp(d1,"fNTimeBins")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNTimeBins=(Int_t)dummy;}
436 else if(strcmp(d1,"fNRowLow")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowLow=(Int_t)dummy;}
437 else if(strcmp(d1,"fNRowUp")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRowUp=(Int_t)dummy;}
438 else if(strcmp(d1,"fNSectorLow")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSectorLow=(Int_t)dummy;}
439 else if(strcmp(d1,"fNSectorUp")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSectorUp=(Int_t)dummy;}
440 else if(strcmp(d1,"fNSector")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSector=(Int_t)dummy;}
441 else if(strcmp(d1,"fPadPitchWidthLow")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fPadPitchWidthLow=(Double_t)ddummy;}
442 else if(strcmp(d1,"fPadPitchWidthUp")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fPadPitchWidthUp=(Double_t)ddummy;}
443 else if(strcmp(d1,"fZWidth")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZWidth=(Double_t)ddummy;}
444 else if(strcmp(d1,"fZSigma")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZSigma=(Double_t)ddummy;}
740da2a6 445 else if(strcmp(d1,"fZLength")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZLength=(Double_t)ddummy;}
446 else if(strcmp(d1,"fZOffset")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fZOffset=(Double_t)ddummy;}
a4e75a99 447 else if(strcmp(d1,"fNSlice")==0){fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNSlice=(Int_t)dummy;}
448 else if(strcmp(d1,"fNRow")==0){
449 fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNRow=(Int_t)dummy;
450 if(fNRow!=176){
451 LOG(AliL3Log::kError,"AliL3Transform::Init","Overflow")<<"Number of PadRows should be 176! Check and fgrep the code for 176 to see the consequences of this major change!"<<ENDLOG;
452 }
453 }
454 else if(strcmp(d1,"fNRotShift")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fNRotShift=(Double_t)ddummy;}
455 else if(strcmp(d1,"fPi")==0){fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fPi=(Double_t)ddummy;}
456 else if(strcmp(d1,"fX[0]")==0){
457 fscanf(fptr,"%s %lf %s",d2,&ddummy,d3);fX[0]=(Double_t)ddummy;
740da2a6 458 for(Int_t i=1;i<fNRow;i++){fscanf(fptr,"%s %s %lf %s",d1,d2,&ddummy,d3);fX[i]=(Double_t)ddummy;}
a4e75a99 459 }
460 else if(strcmp(d1,"fNPads[0]")==0){
461 fscanf(fptr,"%s %d %s",d2,&dummy,d3);fNPads[0]=(Int_t)dummy;
462 for(Int_t i=1;i<fNRow;i++){fscanf(fptr,"%s %s %d %s",d1,d2,&dummy,d3);fNPads[i]=(Int_t)dummy;}
463 }
464 }
465
a4e75a99 466 fclose(fptr);
467 delete pathname;
89693986 468 fVersion=1; //new version
494fad94 469
a4e75a99 470}
471
89693986 472
108615fc 473Double_t AliL3Transform::GetEta(Float_t *xyz)
474{
475 Double_t r3 = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]+xyz[2]*xyz[2]);
476 Double_t eta = 0.5 * log((r3+xyz[2])/(r3-xyz[2]));
477 return eta;
478}
479
740da2a6 480void AliL3Transform::XYZtoRPhiEta(Float_t *rpe, Float_t *xyz)
481{
482 rpe[0] = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]+xyz[2]*xyz[2]);
483 rpe[1] = atan2(xyz[1],xyz[0]);
484 rpe[2] = 0.5 * log((rpe[0]+xyz[2])/(rpe[0]-xyz[2]));
485}
486
3a1c3849 487Double_t AliL3Transform::GetEta(Int_t padrow,Int_t pad,Int_t time)
bd7e82e0 488{
489 Float_t xyz[3];
3a1c3849 490 Int_t sector,row;
491 Slice2Sector(0,padrow,sector,row);
492 Raw2Local(xyz,sector,row,pad,time);
bd7e82e0 493
494 return GetEta(xyz);
495}
496
108615fc 497Double_t AliL3Transform::GetPhi(Float_t *xyz)
498{
108615fc 499 Double_t phi = atan2(xyz[1],xyz[0]);
500 //if(phi<0) phi=phi+2*TMath::Pi();
501 return phi;
502}
503
494fad94 504Bool_t AliL3Transform::Slice2Sector(Int_t slice, Int_t slicerow, Int_t & sector, Int_t &row)
505{
108615fc 506 if(slicerow<0&&slicerow>=fNRow) return kFALSE;
507 if(slice<0||slice>=fNSlice) return kFALSE;
508
509 if(slicerow<fNRowLow){
510 sector = slice;
511 row = slicerow;
512 }
513 else {
514 sector = slice+fNSlice;
515 row = slicerow-fNRowLow;
516 }
517 return kTRUE;
518}
519
494fad94 520Bool_t AliL3Transform::Sector2Slice(Int_t & slice, Int_t sector)
521{
108615fc 522 if(sector<0||sector>=fNSector) return kFALSE;
523 if(sector<fNSectorLow) slice = sector;
524 else slice = sector - fNSectorLow;
525 return kTRUE;
526}
527
494fad94 528Bool_t AliL3Transform::Sector2Slice(Int_t & slice, Int_t & slicerow,Int_t sector, Int_t row)
529{
108615fc 530 if(sector<0||sector>=fNSector||row<0) return kFALSE;
531 if(sector<fNSectorLow){
532 if(row>=fNRowLow) return kFALSE;
533 slice = sector;
534 slicerow = row;
535 }
536 else{
537 if(row>=fNRowUp) return kFALSE;
538 slice = sector - fNSectorLow;
539 slicerow = row + fNRowLow;
540 }
541 return kTRUE;
542}
543
544Double_t AliL3Transform::Row2X(Int_t slicerow){
545 if(slicerow<0||slicerow>=fNRow) return 0;
546 return fX[slicerow];
547}
548
549void AliL3Transform::Local2Global(Float_t *xyz,Int_t slice)
550{
551 //Transformation to global coordinate system
552 Float_t x0 = xyz[0];
553 Float_t y0 = xyz[1];
554 Float_t cs,sn;
494fad94 555 cs = cos( (2*fPi/18) * (slice+fNRotShift) );
556 sn = sin( (2*fPi/18) * (slice+fNRotShift) );
108615fc 557 xyz[0]=x0*cs-y0*sn;
558 xyz[1]=x0*sn+y0*cs;
559 xyz[2]=xyz[2];//global z=local z
560}
561
562void AliL3Transform::Local2GlobalAngle(Float_t *angle,Int_t slice){
740da2a6 563 angle[0] = fmod(angle[0]+(slice+fNRotShift)*(2*fPi/18),2*fPi);
108615fc 564}
565
566void AliL3Transform::Global2LocalAngle(Float_t *angle,Int_t slice){
740da2a6 567 angle[0] = angle[0]-(slice+fNRotShift)*(2*fPi/18);
108615fc 568 if(angle[0]<0) angle[0]+=2*fPi;
569}
570
571void AliL3Transform::Raw2Local(Float_t *xyz,Int_t sector,Int_t row,Float_t pad,Float_t time)
572{
573 //Transformation from rawdata to local coordinate system
574
575 Int_t slice,slicerow;
576 Sector2Slice(slice, slicerow, sector, row);
577
740da2a6 578 //X-Value
108615fc 579 xyz[0]=Row2X(slicerow);
740da2a6 580
581 //Y-Value
108615fc 582 Int_t npads= fNPads[slicerow];
583 if(sector<fNSectorLow)
584 xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthLow;
585 else
586 xyz[1]=(pad-0.5*(npads-1))*fPadPitchWidthUp;
740da2a6 587
588 //Z-Value (remember PULSA Delay)
589 //xyz[2]=fZWidth*time-3.*fZSigma;
590 xyz[2]=fZWidth*time-fZOffset;
0e0b1e59 591 if(slice < 18)
740da2a6 592 xyz[2]=fZLength-xyz[2];
0e0b1e59 593 else
740da2a6 594 xyz[2]=xyz[2]-fZLength;
494fad94 595
108615fc 596}
597
598void AliL3Transform::Local2Global(Float_t *xyz,Int_t sector,Int_t row)
599{
600 //Transformation to global coordinate system
601 Int_t slice,slicerow;
602 Sector2Slice(slice, slicerow, sector, row);
603 Float_t r=Row2X(slicerow);
494fad94 604 Float_t cs = cos( (2*fPi/18) * (slice+fNRotShift) );
605 Float_t sn = sin( (2*fPi/18) * (slice+fNRotShift) );
108615fc 606
607 xyz[0]=r*cs-xyz[1]*sn;
608 xyz[1]=r*sn+xyz[1]*cs;
609 xyz[2]=xyz[2];//global z=local z
610}
611
612Double_t AliL3Transform::GetMaxY(Int_t slicerow)
613{
494fad94 614
108615fc 615 if(slicerow < fNRowLow)
616 return fPadPitchWidthLow*fNPads[slicerow]/2;
617
618 else
619 return fPadPitchWidthUp*fNPads[slicerow]/2;
494fad94 620
108615fc 621}
622
2342214c 623void AliL3Transform::Global2Local(Float_t *xyz,Int_t sector,Bool_t isSlice)
108615fc 624{
2342214c 625
108615fc 626 Int_t slice;
2342214c 627 if(!isSlice)
628 Sector2Slice(slice, sector);
629 else
630 slice = sector;
494fad94 631 Float_t cs = cos( (2*fPi/18) * (slice+fNRotShift) );
632 Float_t sn = sin( (2*fPi/18) * (slice+fNRotShift) );
108615fc 633 Float_t x1 = xyz[0]*cs + xyz[1]*sn;
634 Float_t y1 = -xyz[0]*sn + xyz[1]*cs;
635 xyz[0] = x1;
636 xyz[1] = y1;
637}
638
639void AliL3Transform::Raw2Global(Float_t *xyz,Int_t sector,Int_t row,Float_t pad,Float_t time)
640{
641 //Transformation from raw to global coordinates
642
643 Raw2Local(xyz,sector,row,pad,time);
644 Local2Global(xyz,sector,row);
645}
646
647void AliL3Transform::Local2Raw(Float_t *xyz,Int_t sector,Int_t row)
648{
649 //Transformation from local coordinates to raw
494fad94 650
108615fc 651 Int_t slice,slicerow;
652 Sector2Slice(slice, slicerow, sector, row);
653
654 if(sector<fNSectorLow)
655 xyz[1]=xyz[1]/fPadPitchWidthLow+0.5*(fNPads[slicerow]-1);
656 else
657 xyz[1]=xyz[1]/fPadPitchWidthUp+0.5*(fNPads[slicerow]-1);
658 Int_t sign=-1;
659 Int_t nis=fNSectorLow;
660 Int_t nos=fNSectorUp;
661
662 if ((sector<nis/2) || ((sector-nis)<nos/2)) sign=1;
1727f1c9 663 xyz[2]=fZLength-sign*xyz[2];
664 xyz[2]=(xyz[2]+fZOffset)/fZWidth;
494fad94 665
108615fc 666}
667
668void AliL3Transform::Global2Raw(Float_t *xyz,Int_t sector,Int_t row)
669{
670 //Transformation from global coordinates to raw.
671
672 Global2Local(xyz,sector);
673 Local2Raw(xyz,sector,row);
674
675}