]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDUtility.cxx
updates from Salvatore
[u/mrichter/AliRoot.git] / PMD / AliPMDUtility.cxx
1 /***************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 //-----------------------------------------------------//
16 //                                                     //
17 //                                                     //
18 //  Date   : August 05 2003                            //
19 //                                                     //
20 //  Utility code for ALICE-PMD                         //
21 //                                                     //
22 //-----------------------------------------------------//
23
24 #include "Riostream.h"
25 #include "TMath.h"
26 #include "TText.h"
27 #include "TLine.h"
28
29 #include <stdio.h>
30 #include <math.h>
31
32 #include "AliPMDUtility.h"
33
34 ClassImp(AliPMDUtility)
35
36 AliPMDUtility::AliPMDUtility():
37   fPx(0.),
38   fPy(0.),
39   fPz(0.),
40   fTheta(0.),
41   fEta(0.),
42   fPhi(0.),
43   fWriteModule(1)
44 {
45   // Default constructor
46   for (Int_t i = 0; i < 4; i++)
47     {
48       for (Int_t j = 0; j < 3; j++)
49         {
50           fSecTr[i][j] = 0.;
51         }
52     }
53
54 }
55
56 AliPMDUtility::AliPMDUtility(Float_t px, Float_t py, Float_t pz):
57   fPx(px),
58   fPy(py),
59   fPz(pz),
60   fTheta(0.),
61   fEta(0.),
62   fPhi(0.),
63   fWriteModule(1)
64 {
65   // Constructor
66   for (Int_t i = 0; i < 4; i++)
67     {
68       for (Int_t j = 0; j < 3; j++)
69         {
70           fSecTr[i][j] = 0.;
71         }
72     }
73
74 }
75 AliPMDUtility::AliPMDUtility(const AliPMDUtility &pmdutil):
76   TObject(pmdutil),
77   fPx(pmdutil.fPx),
78   fPy(pmdutil.fPy),
79   fPz(pmdutil.fPz),
80   fTheta(pmdutil.fTheta),
81   fEta(pmdutil.fEta),
82   fPhi(pmdutil.fPhi),
83   fWriteModule(pmdutil.fWriteModule)
84 {
85   // copy constructor
86     for (Int_t i = 0; i < 4; i++)
87     {
88       for (Int_t j = 0; j < 3; j++)
89         {
90           fSecTr[i][j] = pmdutil.fSecTr[i][j];
91         }
92     }
93
94 }
95 AliPMDUtility & AliPMDUtility::operator=(const AliPMDUtility &pmdutil)
96 {
97   // assignment operator
98   if(this != &pmdutil)
99     {
100       fPx = pmdutil.fPx;
101       fPy = pmdutil.fPy;
102       fPz = pmdutil.fPz;
103       fTheta = pmdutil.fTheta;
104       fEta = pmdutil.fEta;
105       fPhi = pmdutil.fPhi;
106       fWriteModule = pmdutil.fWriteModule;
107       for (Int_t i = 0; i < 4; i++)
108         {
109           for (Int_t j = 0; j < 3; j++)
110             {
111               fSecTr[i][j] = pmdutil.fSecTr[i][j];
112             }
113         }
114
115     }
116   return *this;
117 }
118 AliPMDUtility::~AliPMDUtility()
119 {
120   // Default destructor
121 }
122
123 void AliPMDUtility::RectGeomCellPos(Int_t ism, Int_t xpad, Int_t ypad, Float_t &xpos, Float_t &ypos)
124 {
125   // This routine finds the cell eta,phi for the new PMD rectangular 
126   // geometry in ALICE
127   // Authors : Bedanga Mohanty and Dipak Mishra - 29.4.2003
128   // modified by B. K. Nandi for change of coordinate sys
129   //
130   // SMA  ---> Supermodule Type A           ( SM - 0)
131   // SMAR ---> Supermodule Type A ROTATED   ( SM - 1)
132   // SMB  ---> Supermodule Type B           ( SM - 2)
133   // SMBR ---> Supermodule Type B ROTATED   ( SM - 3)
134   //
135   // ism   : Serial module number from 0 to 23 for each plane
136
137  
138   // Corner positions (x,y) of the 24 unit moudles in ALICE PMD
139
140   double xcorner[24] =
141     {
142       74.8833,  53.0045, 31.1255,    //Type-A
143       74.8833,  53.0045, 31.1255,    //Type-A
144       -74.8833, -53.0044, -31.1255,  //Type-AR
145       -74.8833, -53.0044, -31.1255,  //Type-AR
146       8.9165, -33.7471,            //Type-B
147       8.9165, -33.7471,            //Type-B
148       8.9165, -33.7471,            //Type-B
149       -8.9165, 33.7471,            //Type-BR
150       -8.9165, 33.7471,            //Type-BR
151       -8.9165, 33.7471,            //Type-BR
152     };
153
154   
155   double ycorner[24] =
156     {
157       86.225,  86.225,  86.225,      //Type-A
158       37.075,  37.075,  37.075,      //Type-A
159       -86.225, -86.225, -86.225,     //Type-AR
160       -37.075, -37.075, -37.075,     //Type-AR
161       86.225,  86.225,               //Type-B
162       61.075,  61.075,               //Type-B
163       35.925,  35.925,               //Type-B
164       -86.225, -86.225,              //Type-BR
165       -61.075, -61.075,              //Type-BR
166       -35.925, -35.925               //Type-BR
167     };
168
169   
170   const Float_t kSqroot3      = 1.73205;  // sqrt(3.);
171   const Float_t kCellRadius   = 0.25;
172   
173   //
174   //Every even row of cells is shifted and placed
175   //in geant so this condition
176   //
177   Float_t cellRadius = 0.25;
178   Float_t shift = 0.0;
179   if(xpad%2 == 0)
180     {
181       shift = -cellRadius/2.0;
182     }
183   else
184     {
185       shift = 0.0;
186     }
187
188
189   if(ism < 6)
190     {
191       ypos = ycorner[ism] - (Float_t) xpad*kCellRadius*2.0 + shift;
192       xpos = xcorner[ism] - (Float_t) ypad*kSqroot3*kCellRadius;
193     }
194   else if(ism >=6 && ism < 12)
195     {
196       ypos = ycorner[ism] + (Float_t) xpad*kCellRadius*2.0 + shift;
197       xpos = xcorner[ism] + (Float_t) ypad*kSqroot3*kCellRadius;
198     }
199   else if(ism >= 12 && ism < 18)
200     {
201       ypos = ycorner[ism] - (Float_t) xpad*kCellRadius*2.0 + shift;
202       xpos = xcorner[ism] - (Float_t) ypad*kSqroot3*kCellRadius;
203     }
204   else if(ism >= 18 && ism < 24)
205     {
206       ypos = ycorner[ism] + (Float_t) xpad*kCellRadius*2.0 + shift;
207       xpos = xcorner[ism] + (Float_t) ypad*kSqroot3*kCellRadius;
208     }
209   // Apply the alignment here to the x, y values
210   if(ism < 6)
211     {
212       xpos += fSecTr[0][0];
213       ypos += fSecTr[0][1];
214     }
215   else if(ism >= 6 && ism < 12)
216     {
217       xpos += fSecTr[1][0];
218       ypos += fSecTr[1][1];
219     }
220   else if(ism >=12 && ism < 18)
221     {
222       xpos += fSecTr[2][0];
223       ypos += fSecTr[2][1];
224     }
225   else if(ism >= 18 && ism < 24)
226     {
227       xpos += fSecTr[3][0];
228       ypos += fSecTr[3][1];
229     }
230
231 }
232 // ---------------------------------------------------------- 
233 void AliPMDUtility::RectGeomCellPos(Int_t ism, Float_t xpad, Float_t ypad, Float_t &xpos, Float_t &ypos)
234 {
235   // If the xpad and ypad inputs are float, then 0.5 is added to it
236   // to find the layer which is shifted.
237   // This routine finds the cell eta,phi for the new PMD rectangular 
238   // geometry in ALICE
239   // Authors : Bedanga Mohanty and Dipak Mishra - 29.4.2003
240   // modified by B. K. Nnadi for change of coordinate sys
241   //
242   // SMA  ---> Supermodule Type A           ( SM - 0)
243   // SMAR ---> Supermodule Type A ROTATED   ( SM - 1)
244   // SMB  ---> Supermodule Type B           ( SM - 2)
245   // SMBR ---> Supermodule Type B ROTATED   ( SM - 3)
246   //
247   // ism   : Serial Module number from 0 to 23 for each plane
248
249   // Corner positions (x,y) of the 24 unit moudles in ALICE PMD
250
251   double xcorner[24] =
252     {
253       74.8833,  53.0045, 31.1255,    //Type-A
254       74.8833,  53.0045, 31.1255,    //Type-A
255       -74.8833, -53.0044, -31.1255,  //Type-AR
256       -74.8833, -53.0044, -31.1255,  //Type-AR
257       8.9165, -33.7471,            //Type-B
258       8.9165, -33.7471,            //Type-B
259       8.9165, -33.7471,            //Type-B
260       -8.9165, 33.7471,            //Type-BR
261       -8.9165, 33.7471,            //Type-BR
262       -8.9165, 33.7471,            //Type-BR
263     };
264
265   
266
267   double ycorner[24] =
268     {
269       86.225,  86.225,  86.225,      //Type-A
270       37.075,  37.075,  37.075,      //Type-A
271       -86.225, -86.225, -86.225,     //Type-AR
272       -37.075, -37.075, -37.075,     //Type-AR
273       86.225,  86.225,               //Type-B
274       61.075,  61.075,               //Type-B
275       35.925,  35.925,               //Type-B
276       -86.225, -86.225,              //Type-BR
277       -61.075, -61.075,              //Type-BR
278       -35.925, -35.925               //Type-BR
279     };
280
281
282   const Float_t kSqroot3    = 1.73205;  // sqrt(3.);
283   const Float_t kCellRadius = 0.25;
284   
285   //
286   //Every even row of cells is shifted and placed
287   //in geant so this condition
288   //
289   Float_t cellRadius = 0.25;
290   Float_t shift = 0.0;
291   Int_t iirow = (Int_t) (xpad+0.5);
292   if(iirow%2 == 0)
293     {
294       shift = -cellRadius/2.0;
295     }
296   else
297     {
298       shift = 0.0;
299     }
300
301   if(ism < 6)
302     {
303       ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
304       xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
305     }
306   else if(ism >=6 && ism < 12)
307     {
308       ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
309       xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
310     }
311   else if(ism >= 12 && ism < 18)
312     {
313       ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
314       xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
315     }
316   else if(ism >= 18 && ism < 24)
317     {
318       ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
319       xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
320     }
321
322   // Apply the alignment here to the x, y values
323   if(ism < 6)
324     {
325       xpos += fSecTr[0][0];
326       ypos += fSecTr[0][1];
327     }
328   else if(ism >= 6 && ism < 12)
329     {
330       xpos += fSecTr[1][0];
331       ypos += fSecTr[1][1];
332     }
333   else if(ism >=12 && ism < 18)
334     {
335       xpos += fSecTr[2][0];
336       ypos += fSecTr[2][1];
337     }
338   else if(ism >= 18 && ism < 24)
339     {
340       xpos += fSecTr[3][0];
341       ypos += fSecTr[3][1];
342     }
343
344 }
345
346 // -------------------------------------------------------- //
347
348 void AliPMDUtility::RectGeomCellPos(Int_t ism, Float_t xpad,
349                                     Float_t ypad, Float_t &xpos,
350                                     Float_t &ypos, Float_t & zpos)
351 {
352   // If the xpad and ypad inputs are float, then 0.5 is added to it
353   // to find the layer which is shifted.
354   // This routine finds the cell eta,phi for the new PMD rectangular 
355   // geometry in ALICE
356   // Authors : Bedanga Mohanty and Dipak Mishra - 29.4.2003
357   // modified by B. K. Nnadi for change of coordinate sys
358   //
359   // SMA  ---> Supermodule Type A           ( SM - 0)
360   // SMAR ---> Supermodule Type A ROTATED   ( SM - 1)
361   // SMB  ---> Supermodule Type B           ( SM - 2)
362   // SMBR ---> Supermodule Type B ROTATED   ( SM - 3)
363   //
364   // ism   : Serial Module number from 0 to 23 for each plane
365
366   // Corner positions (x,y) of the 24 unit moudles in ALICE PMD
367
368   double xcorner[24] =
369     {
370       74.8833,  53.0045, 31.1255,    //Type-A
371       74.8833,  53.0045, 31.1255,    //Type-A
372       -74.8833, -53.0044, -31.1255,  //Type-AR
373       -74.8833, -53.0044, -31.1255,  //Type-AR
374       8.9165, -33.7471,            //Type-B
375       8.9165, -33.7471,            //Type-B
376       8.9165, -33.7471,            //Type-B
377       -8.9165, 33.7471,            //Type-BR
378       -8.9165, 33.7471,            //Type-BR
379       -8.9165, 33.7471,            //Type-BR
380     };
381
382   
383
384   double ycorner[24] =
385     {
386       86.225,  86.225,  86.225,      //Type-A
387       37.075,  37.075,  37.075,      //Type-A
388       -86.225, -86.225, -86.225,     //Type-AR
389       -37.075, -37.075, -37.075,     //Type-AR
390       86.225,  86.225,               //Type-B
391       61.075,  61.075,               //Type-B
392       35.925,  35.925,               //Type-B
393       -86.225, -86.225,              //Type-BR
394       -61.075, -61.075,              //Type-BR
395       -35.925, -35.925               //Type-BR
396     };
397
398
399   const Float_t kSqroot3    = 1.73205;  // sqrt(3.);
400   const Float_t kCellRadius = 0.25;
401   
402   //
403   //Every even row of cells is shifted and placed
404   //in geant so this condition
405   //
406   Float_t cellRadius = 0.25;
407   Float_t shift = 0.0;
408   Int_t iirow = (Int_t) (xpad+0.5);
409   if(iirow%2 == 0)
410     {
411       shift = -cellRadius/2.0;
412     }
413   else
414     {
415       shift = 0.0;
416     }
417
418   if(ism < 6)
419     {
420       ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
421       xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
422     }
423   else if(ism >=6 && ism < 12)
424     {
425       ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
426       xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
427     }
428   else if(ism >= 12 && ism < 18)
429     {
430       ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
431       xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
432     }
433   else if(ism >= 18 && ism < 24)
434     {
435       ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
436       xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
437     }
438
439   // Apply the alignment here to the x, y, and z values
440   if(ism < 6)
441     {
442       xpos += fSecTr[0][0];
443       ypos += fSecTr[0][1];
444       zpos += fSecTr[0][2];
445     }
446   else if(ism >= 6 && ism < 12)
447     {
448       xpos += fSecTr[1][0];
449       ypos += fSecTr[1][1];
450       zpos += fSecTr[1][2];
451     }
452   else if(ism >=12 && ism < 18)
453     {
454       xpos += fSecTr[2][0];
455       ypos += fSecTr[2][1];
456       zpos += fSecTr[2][2];
457     }
458   else if(ism >= 18 && ism < 24)
459     {
460       xpos += fSecTr[3][0];
461       ypos += fSecTr[3][1];
462       zpos += fSecTr[3][2];
463     }
464
465
466
467 }
468 // -------------------------------------------------------- //
469
470 void AliPMDUtility::GenerateBoundaryPoints(Int_t ism, Float_t &x1ism, 
471                                            Float_t &y1ism, Float_t &x2ism,
472                                            Float_t &y2ism)
473 {
474   // Generate bounding-box.
475
476
477     Float_t xism = 0, yism = 0;
478     Float_t dxism = 0., dyism = 0.;
479
480     const Float_t kRad     = 0.25;
481     const Float_t kSqRoot3 = 1.732050808;
482     const Float_t kDia     = 0.50;
483
484
485   const Double_t kXcorner[24] =
486     {
487       74.8833,  53.0045, 31.1255,    //Type-A
488       74.8833,  53.0045, 31.1255,    //Type-A
489       -74.8833, -53.0044, -31.1255,  //Type-AR
490       -74.8833, -53.0044, -31.1255,  //Type-AR
491       8.9165, -33.7471,            //Type-B
492       8.9165, -33.7471,            //Type-B
493       8.9165, -33.7471,            //Type-B
494       -8.9165, 33.7471,            //Type-BR
495       -8.9165, 33.7471,            //Type-BR
496       -8.9165, 33.7471,            //Type-BR
497     };
498
499
500   const Double_t kYcorner[24] =
501     {
502       86.225,  86.225,  86.225,      //Type-A
503       37.075,  37.075,  37.075,      //Type-A
504       -86.225, -86.225, -86.225,     //Type-AR
505       -37.075, -37.075, -37.075,     //Type-AR
506       86.225,  86.225,               //Type-B
507       61.075,  61.075,               //Type-B
508       35.925,  35.925,               //Type-B
509       -86.225, -86.225,              //Type-BR
510       -61.075, -61.075,              //Type-BR
511       -35.925, -35.925               //Type-BR
512     };
513
514
515   if (ism > 23) ism -= 24;
516
517
518   if (ism < 6)
519     {
520       xism  = kXcorner[ism] + kRad;
521       yism  = kYcorner[ism] + kRad;
522       dxism = -kRad*kSqRoot3*48.;
523       dyism = -kDia*96. - kRad;
524   }
525   if (ism >= 6 && ism < 12)
526     {
527       xism  = kXcorner[ism] - kRad;
528       yism  = kYcorner[ism] - kRad;
529       dxism = kRad*kSqRoot3*48.;
530       dyism = kDia*96. + kRad;
531   }
532   if (ism >= 12 && ism < 18)
533     {
534       xism  = kXcorner[ism] + kRad;
535       yism  = kYcorner[ism] + kRad;
536       dxism = -kRad*kSqRoot3*96.;
537       dyism = -kDia*48. - kRad;
538   }
539   if (ism >= 18 && ism < 24)
540     {
541       xism  = kXcorner[ism] - kRad;
542       yism  = kYcorner[ism] - kRad;
543       dxism = kRad*kSqRoot3*96.;
544       dyism = kDia*48. + kRad;
545   }
546
547   x1ism = xism;
548   x2ism = xism + dxism;
549   y1ism = yism;
550   y2ism = yism + dyism;
551
552 }
553 // ------------------------------------------------------------------- //
554
555 void AliPMDUtility::DrawPMDModule(Int_t idet)
556 {
557
558     Float_t x1ism = 0., x2ism = 0., y1ism = 0., y2ism = 0.;
559     Float_t deltaX = 0., deltaY = 0.;
560     
561     //TH2F *h2 = new TH2F("h2","Y vs. X",200,-100.,100.,200,-100.,100.);
562     //h2->Draw();
563
564     TLine t;
565     t.SetLineColor(2);
566
567     TText tt;
568     tt.SetTextColor(4);
569
570     Char_t smnumber[10];
571
572     for(Int_t ism=0; ism < 24; ism++)
573     {
574         GenerateBoundaryPoints(ism, x1ism, y1ism, x2ism, y2ism);
575         deltaX = (x2ism - x1ism)/2.;
576         deltaY = (y2ism - y1ism)/2.;
577         if (fWriteModule == 1)
578         {
579           if(idet == 0)
580             {
581               snprintf(smnumber,10,"%d",ism);
582             }
583           else if (idet == 1)
584             {
585               snprintf(smnumber,10,"%d",24+ism);
586             }
587             tt.DrawText(x1ism+deltaX,y1ism+deltaY,smnumber);
588         }
589         t.DrawLine(x1ism, y1ism, x1ism, y2ism);
590         t.DrawLine(x1ism, y1ism, x2ism, y1ism);
591         t.DrawLine(x2ism, y1ism, x2ism, y2ism);
592         t.DrawLine(x1ism, y2ism, x2ism, y2ism);
593     }
594
595 }
596
597 // ------------------------------------------------------------------- //
598
599
600 void AliPMDUtility::ApplyVertexCorrection(Float_t vertex[], Float_t xpos,
601                                           Float_t ypos, Float_t zpos)
602 {
603   // Not implemented
604   fPx = xpos - vertex[0];
605   fPy = ypos - vertex[1];
606   fPz = zpos - vertex[2];
607 }
608 void AliPMDUtility::ApplyAlignment(Double_t sectr[][3])
609 {
610   // Get the alignment stuff here
611
612   for (Int_t isector=0; isector<4; isector++)
613     {
614       for(Int_t ixyz=0; ixyz < 3; ixyz++)
615         {
616           fSecTr[isector][ixyz] = (Float_t) sectr[isector][ixyz];
617         }
618     }
619 }
620
621 void AliPMDUtility::SetPxPyPz(Float_t px, Float_t py, Float_t pz)
622 {
623   fPx = px;
624   fPy = py;
625   fPz = pz;
626 }
627
628 void AliPMDUtility::SetXYZ(Float_t xpos, Float_t ypos, Float_t zpos)
629 {
630   fPx = xpos;
631   fPy = ypos;
632   fPz = zpos;
633 }
634 void AliPMDUtility::SetWriteModule(Int_t wrmod)
635 {
636     fWriteModule = wrmod;
637 }
638 void AliPMDUtility::CalculateEta()
639 {
640   Float_t rpxpy  = TMath::Sqrt(fPx*fPx + fPy*fPy);
641   Float_t theta  = TMath::ATan2(rpxpy,fPz);
642   Float_t eta    = -TMath::Log(TMath::Tan(0.5*theta));
643   fTheta = theta;
644   fEta   = eta;
645 }
646 void AliPMDUtility::CalculatePhi()
647 {
648   Float_t pybypx = 0., phi = 0., phi1 = 0.;
649
650   if(fPx==0)
651     {
652       if(fPy>0) phi = 90.;
653       if(fPy<0) phi = 270.;
654     }
655   if(fPx != 0)
656     {
657       pybypx = fPy/fPx;
658       if(pybypx < 0) pybypx = - pybypx;
659       phi1 = TMath::ATan(pybypx)*180./3.14159;
660
661       if(fPx > 0 && fPy > 0) phi = phi1;        // 1st Quadrant
662       if(fPx < 0 && fPy > 0) phi = 180 - phi1;  // 2nd Quadrant
663       if(fPx < 0 && fPy < 0) phi = 180 + phi1;  // 3rd Quadrant
664       if(fPx > 0 && fPy < 0) phi = 360 - phi1;  // 4th Quadrant
665
666     }
667   phi = phi*3.14159/180.;
668
669   fPhi = phi;
670
671 }
672 void AliPMDUtility::CalculateEtaPhi()
673 {
674   Float_t pybypx = 0., phi = 0., phi1 = 0.;
675
676   Float_t rpxpy = TMath::Sqrt(fPx*fPx + fPy*fPy);
677   Float_t theta = TMath::ATan2(rpxpy,fPz);
678   Float_t eta   = -TMath::Log(TMath::Tan(0.5*theta));
679   
680   if(fPx == 0)
681     {
682       if(fPy>0) phi = 90.;
683       if(fPy<0) phi = 270.;
684     }
685   if(fPx != 0)
686     {
687       pybypx = fPy/fPx;
688       if(pybypx < 0) pybypx = - pybypx;
689       phi1 = TMath::ATan(pybypx)*180./3.14159;
690       if(fPx > 0 && fPy > 0) phi = phi1;        // 1st Quadrant
691       if(fPx < 0 && fPy > 0) phi = 180 - phi1;  // 2nd Quadrant
692       if(fPx < 0 && fPy < 0) phi = 180 + phi1;  // 3rd Quadrant
693       if(fPx > 0 && fPy < 0) phi = 360 - phi1;  // 4th Quadrant
694
695     }
696   phi = phi*3.14159/180.;
697
698   fTheta = theta;
699   fEta   = eta;
700   fPhi   = phi;
701 }
702 void AliPMDUtility::CalculateXY(Float_t eta, Float_t phi, Float_t zpos)
703 {
704   // Not implemented
705
706   //  eta   = -TMath::Log(TMath::Tan(0.5*theta));
707
708   Float_t xpos = 0., ypos = 0.;
709
710   //  Float_t theta = 2.0*TMath::ATan(TMath::Log(-eta));
711
712   fEta = eta;
713   fPhi = phi;
714   fPx  = xpos;
715   fPy  = ypos;
716   fPz  = zpos;
717 }
718
719 void AliPMDUtility::GetEtaIndexXY(Int_t smn, Int_t row, Int_t col, Float_t &xp, Float_t &yp, Double_t &eta, Int_t &etaindex) {
720   // Takes smn, row, col
721   // Calculates x, y, eta and etabin into 10. 
722   // Use only in raw Data.
723
724   Float_t xx = 0., yy = 0.;
725   Int_t xpad = -1, ypad = -1;
726   
727   if(smn <12) {
728     xpad = col;
729     ypad = row;
730   }
731   else if(smn >=12 && smn < 24) {
732     xpad = row;
733     ypad = col;
734   }
735  
736  
737
738   RectGeomCellPos(smn,xpad,ypad,xx,yy); 
739   xp = xx;
740   yp = yy;
741
742   Float_t rpxpy  = TMath::Sqrt(xx*xx + yy*yy);
743   Float_t theta  = TMath::ATan2(rpxpy,365.0);
744   eta    = -TMath::Log(TMath::Tan(0.5*theta));
745
746   Int_t etaBin = -1;  
747
748   if( eta > 2.1 && eta < 2.3) etaBin = 0;
749   else if( eta > 2.3 && eta < 2.5) etaBin = 1;
750   else if( eta > 2.5 && eta < 2.7) etaBin = 2;
751   else if( eta > 2.7 && eta < 2.9) etaBin = 3;
752   else if( eta > 2.9 && eta < 3.1) etaBin = 4;
753   else if( eta > 3.1 && eta < 3.3) etaBin = 5;
754   else if( eta > 3.3 && eta < 3.5) etaBin = 6;
755   else if( eta > 3.5 && eta < 3.7) etaBin = 7;
756   else if( eta > 3.7 && eta < 3.9) etaBin = 8;
757   else if( eta > 3.9 && eta < 4.1) etaBin = 9;
758   else etaBin = 13;
759
760   etaindex = etaBin;
761
762
763 }
764
765 //_____________________________________________________
766
767 Float_t AliPMDUtility::GetTheta() const
768 {
769   return fTheta;
770 }
771 Float_t AliPMDUtility::GetEta() const
772 {
773   return fEta;
774 }
775 Float_t AliPMDUtility::GetPhi() const
776 {
777   return fPhi;
778 }
779 Float_t AliPMDUtility::GetX() const
780 {
781   return fPx;
782 }
783 Float_t AliPMDUtility::GetY() const
784 {
785   return fPy;
786 }
787 Float_t AliPMDUtility::GetZ() const
788 {
789   return fPz;
790 }
791 //--------------------------------------------------------------------//