]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDUtility.cxx
402775df6d62b26447a9e8c18d40348df46f461a
[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 "AliPMDUtility.h"
26 #include "TMath.h"
27 #include <stdio.h>
28 #include <math.h>
29
30
31 ClassImp(AliPMDUtility)
32
33 AliPMDUtility::AliPMDUtility()
34 {
35   // Default constructor
36   fPx    = 0.;
37   fPy    = 0.;
38   fPz    = 0.;
39   fTheta = 0.;
40   fEta   = 0.;
41   fPhi   = 0.;
42 }
43
44 AliPMDUtility::AliPMDUtility(Float_t px, Float_t py, Float_t pz)
45 {
46   // Constructor
47   fPx = px;
48   fPy = py;
49   fPz = pz;
50   fTheta = 0.;
51   fEta   = 0.;
52   fPhi   = 0.;
53 }
54
55 AliPMDUtility::~AliPMDUtility()
56 {
57   // Default destructor
58 }
59
60 void AliPMDUtility::RectGeomCellPos(Int_t ism, Int_t xpad, Int_t ypad, Float_t &xpos, Float_t &ypos)
61 {
62   // This routine finds the cell eta,phi for the new PMD rectangular 
63   // geometry in ALICE
64   // Authors : Bedanga Mohanty and Dipak Mishra - 29.4.2003
65   // modified by B. K. Nandi for change of coordinate sys
66   //
67   // SMA  ---> Supermodule Type A           ( SM - 0)
68   // SMAR ---> Supermodule Type A ROTATED   ( SM - 1)
69   // SMB  ---> Supermodule Type B           ( SM - 2)
70   // SMBR ---> Supermodule Type B ROTATED   ( SM - 3)
71   //
72   // ism   : Serial module number from 0 to 23 for each plane
73
74  
75   // Corner positions (x,y) of the 24 unit moudles in ALICE PMD
76
77   double xcorner[24] =
78     {
79       74.8833,  53.0045, 31.1255,    //Type-A
80       74.8833,  53.0045, 31.1255,    //Type-A
81       -74.8833, -53.0044, -31.1255,  //Type-AR
82       -74.8833, -53.0044, -31.1255,  //Type-AR
83       8.9165, -33.7471,            //Type-B
84       8.9165, -33.7471,            //Type-B
85       8.9165, -33.7471,            //Type-B
86       -8.9165, 33.7471,            //Type-BR
87       -8.9165, 33.7471,            //Type-BR
88       -8.9165, 33.7471,            //Type-BR
89     };
90
91   
92   double ycorner[24] =
93     {
94       86.225,  86.225,  86.225,      //Type-A
95       37.075,  37.075,  37.075,      //Type-A
96       -86.225, -86.225, -86.225,     //Type-AR
97       -37.075, -37.075, -37.075,     //Type-AR
98       86.225,  86.225,               //Type-B
99       61.075,  61.075,               //Type-B
100       35.925,  35.925,               //Type-B
101       -86.225, -86.225,              //Type-BR
102       -61.075, -61.075,              //Type-BR
103       -35.925, -35.925               //Type-BR
104     };
105
106   
107   const Float_t kSqroot3      = 1.73205;  // sqrt(3.);
108   const Float_t kCellRadius   = 0.25;
109   
110   //
111   //Every even row of cells is shifted and placed
112   //in geant so this condition
113   //
114   Float_t cellRadius = 0.25;
115   Float_t shift = 0.0;
116   if(xpad%2 == 0)
117     {
118       shift = -cellRadius/2.0;
119     }
120   else
121     {
122       shift = 0.0;
123     }
124
125
126   if(ism < 6)
127     {
128       ypos = ycorner[ism] - (Float_t) xpad*kCellRadius*2.0 + shift;
129       xpos = xcorner[ism] - (Float_t) ypad*kSqroot3*kCellRadius;
130     }
131   else if(ism >=6 && ism < 12)
132     {
133       ypos = ycorner[ism] + (Float_t) xpad*kCellRadius*2.0 + shift;
134       xpos = xcorner[ism] + (Float_t) ypad*kSqroot3*kCellRadius;
135     }
136   else if(ism >= 12 && ism < 18)
137     {
138       ypos = ycorner[ism] - (Float_t) xpad*kCellRadius*2.0 + shift;
139       xpos = xcorner[ism] - (Float_t) ypad*kSqroot3*kCellRadius;
140     }
141   else if(ism >= 18 && ism < 24)
142     {
143       ypos = ycorner[ism] + (Float_t) xpad*kCellRadius*2.0 + shift;
144       xpos = xcorner[ism] + (Float_t) ypad*kSqroot3*kCellRadius;
145     }
146
147 }
148
149 void AliPMDUtility::RectGeomCellPos(Int_t ism, Float_t xpad, Float_t ypad, Float_t &xpos, Float_t &ypos)
150 {
151   // If the xpad and ypad inputs are float, then 0.5 is added to it
152   // to find the layer which is shifted.
153   // This routine finds the cell eta,phi for the new PMD rectangular 
154   // geometry in ALICE
155   // Authors : Bedanga Mohanty and Dipak Mishra - 29.4.2003
156   // modified by B. K. Nnadi for change of coordinate sys
157   //
158   // SMA  ---> Supermodule Type A           ( SM - 0)
159   // SMAR ---> Supermodule Type A ROTATED   ( SM - 1)
160   // SMB  ---> Supermodule Type B           ( SM - 2)
161   // SMBR ---> Supermodule Type B ROTATED   ( SM - 3)
162   //
163   // ism   : Serial Module number from 0 to 23 for each plane
164
165   // Corner positions (x,y) of the 24 unit moudles in ALICE PMD
166
167   double xcorner[24] =
168     {
169       74.8833,  53.0045, 31.1255,    //Type-A
170       74.8833,  53.0045, 31.1255,    //Type-A
171       -74.8833, -53.0044, -31.1255,  //Type-AR
172       -74.8833, -53.0044, -31.1255,  //Type-AR
173       8.9165, -33.7471,            //Type-B
174       8.9165, -33.7471,            //Type-B
175       8.9165, -33.7471,            //Type-B
176       -8.9165, 33.7471,            //Type-BR
177       -8.9165, 33.7471,            //Type-BR
178       -8.9165, 33.7471,            //Type-BR
179     };
180
181   
182
183   double ycorner[24] =
184     {
185       86.225,  86.225,  86.225,      //Type-A
186       37.075,  37.075,  37.075,      //Type-A
187       -86.225, -86.225, -86.225,     //Type-AR
188       -37.075, -37.075, -37.075,     //Type-AR
189       86.225,  86.225,               //Type-B
190       61.075,  61.075,               //Type-B
191       35.925,  35.925,               //Type-B
192       -86.225, -86.225,              //Type-BR
193       -61.075, -61.075,              //Type-BR
194       -35.925, -35.925               //Type-BR
195     };
196
197
198   const Float_t kSqroot3    = 1.73205;  // sqrt(3.);
199   const Float_t kCellRadius = 0.25;
200   
201   //
202   //Every even row of cells is shifted and placed
203   //in geant so this condition
204   //
205   Float_t cellRadius = 0.25;
206   Float_t shift = 0.0;
207   Int_t iirow = (Int_t) (xpad+0.5);
208   if(iirow%2 == 0)
209     {
210       shift = -cellRadius/2.0;
211     }
212   else
213     {
214       shift = 0.0;
215     }
216
217   if(ism < 6)
218     {
219       ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
220       xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
221     }
222   else if(ism >=6 && ism < 12)
223     {
224       ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
225       xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
226     }
227   else if(ism >= 12 && ism < 18)
228     {
229       ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
230       xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
231     }
232   else if(ism >= 18 && ism < 24)
233     {
234       ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
235       xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
236     }
237
238 }
239
240 void AliPMDUtility::SetPxPyPz(Float_t px, Float_t py, Float_t pz)
241 {
242   fPx = px;
243   fPy = py;
244   fPz = pz;
245 }
246
247 void AliPMDUtility::SetXYZ(Float_t xpos, Float_t ypos, Float_t zpos)
248 {
249   fPx = xpos;
250   fPy = ypos;
251   fPz = zpos;
252 }
253 void AliPMDUtility::CalculateEta()
254 {
255   Float_t rpxpy, theta, eta;
256
257   rpxpy  = TMath::Sqrt(fPx*fPx + fPy*fPy);
258   theta  = TMath::ATan2(rpxpy,fPz);
259   eta    = -TMath::Log(TMath::Tan(0.5*theta));
260   fTheta = theta;
261   fEta   = eta;
262 }
263 void AliPMDUtility::CalculatePhi()
264 {
265   Float_t pybypx, phi = 0., phi1;
266
267   if(fPx==0)
268     {
269       if(fPy>0) phi = 90.;
270       if(fPy<0) phi = 270.;
271     }
272   if(fPx != 0)
273     {
274       pybypx = fPy/fPx;
275       if(pybypx < 0) pybypx = - pybypx;
276       phi1 = TMath::ATan(pybypx)*180./3.14159;
277
278       if(fPx > 0 && fPy > 0) phi = phi1;        // 1st Quadrant
279       if(fPx < 0 && fPy > 0) phi = 180 - phi1;  // 2nd Quadrant
280       if(fPx < 0 && fPy < 0) phi = 180 + phi1;  // 3rd Quadrant
281       if(fPx > 0 && fPy < 0) phi = 360 - phi1;  // 4th Quadrant
282
283     }
284   phi = phi*3.14159/180.;
285
286   fPhi = phi;
287
288 }
289 void AliPMDUtility::CalculateEtaPhi()
290 {
291   Float_t rpxpy, theta, eta;
292   Float_t pybypx, phi = 0., phi1;
293
294   rpxpy = TMath::Sqrt(fPx*fPx + fPy*fPy);
295   theta = TMath::ATan2(rpxpy,fPz);
296   eta   = -TMath::Log(TMath::Tan(0.5*theta));
297   
298   if(fPx==0)
299     {
300       if(fPy>0) phi = 90.;
301       if(fPy<0) phi = 270.;
302     }
303   if(fPx != 0)
304     {
305       pybypx = fPy/fPx;
306       if(pybypx < 0) pybypx = - pybypx;
307       phi1 = TMath::ATan(pybypx)*180./3.14159;
308       if(fPx > 0 && fPy > 0) phi = phi1;        // 1st Quadrant
309       if(fPx < 0 && fPy > 0) phi = 180 - phi1;  // 2nd Quadrant
310       if(fPx < 0 && fPy < 0) phi = 180 + phi1;  // 3rd Quadrant
311       if(fPx > 0 && fPy < 0) phi = 360 - phi1;  // 4th Quadrant
312
313     }
314   phi = phi*3.14159/180.;
315
316   fTheta = theta;
317   fEta   = eta;
318   fPhi   = phi;
319 }
320 Float_t AliPMDUtility::GetTheta() const
321 {
322   return fTheta;
323 }
324 Float_t AliPMDUtility::GetEta() const
325 {
326   return fEta;
327 }
328 Float_t AliPMDUtility::GetPhi() const
329 {
330   return fPhi;
331 }
332