]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - PMD/AliPMDUtility.cxx
Bugfixes and additional protection (Cvetan and Marian)
[u/mrichter/AliRoot.git] / PMD / AliPMDUtility.cxx
... / ...
CommitLineData
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
31ClassImp(AliPMDUtility)
32
33AliPMDUtility::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
44AliPMDUtility::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
55AliPMDUtility::~AliPMDUtility()
56{
57 // Default destructor
58}
59void AliPMDUtility::HexGeomCellPos(Int_t ism, Int_t xpad, Int_t ypad, Float_t &xpos, Float_t &ypos)
60{
61 // This converts PMD cluster or CELL coordinates
62 // to Global coordinates.
63 // Written by Prof. S.C. Phatak
64
65 const Float_t kCellDia = 0.5;
66 const Float_t kPi = TMath::Pi(); //3.14159;
67 const Double_t kSqroot3by2 = 0.8660254; // sqrth = sqrt(3.)/2.
68
69 Int_t i;
70 Int_t j = xpad;
71 Int_t k = ypad;
72
73 /*
74 Supermodeule number starting from 0
75 ism --> supermodule no ( 0 - 26 )
76 idet --> detector ( pmd or cpv : not required now )
77 j --> xpad ( goes from 1 to 72 )
78 k --> ypad ( goes from 1 to 72 )
79 xp --> global x coordinate
80 yp --> global y coordinate
81
82 (xp0,yp0) corner positions of all supermodules in global
83 coordinate system. That is the origin
84 of the local ( supermodule ) coordinate system.
85 */
86
87 Float_t xp0[27] =
88 {
89 -17.9084, 18.2166, 54.3416, -35.9709, 0.154144,
90 36.2791, -54.0334, -17.9084, 18.2166, 36.7791,
91 18.7166, 0.654194, 72.9041, 54.8416, 36.7792,
92 109.029, 90.9666, 72.9042, -18.8708, -36.9334,
93 -54.996, -36.9332, -54.9958, -73.0584, -54.9956,
94 -73.0582, -91.1208
95 };
96
97 Float_t yp0[27] =
98 {
99 -32.1395, -32.1395, -32.1395, -63.4247, -63.4247,
100 -63.4247, -94.7098, -94.7098, -94.7098, 0.545689,
101 31.8309, 63.1161, 0.545632, 31.8308, 63.116,
102 0.545573, 31.8308, 63.116, 31.5737, 0.288616,
103 -30.9965, 62.859, 31.5738, 0.288733, 94.1442,
104 62.8591, 31.574
105 };
106
107 /*
108 angles of rotation for three sets of supermodules
109 The angle is same for first nine, next nine and last nine
110 supermodules
111 */
112
113 Float_t th[3] = {0., -2.*kPi/3., 2.*kPi/3.};
114 Float_t xr, yr, xinit, yinit, cs, sn;
115
116 /*
117 xinit and yinit are coordinates of the cell in local coordinate system
118 */
119
120 xinit = (j)*kCellDia+(k)/2.*kCellDia;
121 yinit = kSqroot3by2*(k)/2.;
122 i=ism/9;
123 cs=cos(th[i]);
124 sn=sin(th[i]);
125 //
126 // rotate first
127 //
128 xr=cs*xinit+sn*yinit;
129 yr=-sn*xinit+cs*yinit;
130 //
131 // then translate
132 //
133 xpos=xr+xp0[ism];
134 ypos=yr+yp0[ism];
135
136}
137
138void AliPMDUtility::RectGeomCellPos(Int_t ism, Int_t ium, Int_t xpad, Int_t ypad, Float_t &xpos, Float_t &ypos)
139{
140 // This routine finds the cell eta,phi for the new PMD rectangular
141 // geometry in ALICE
142 // Authors : Bedanga Mohanty and Dipak Mishra - 29.4.2003
143 // modified by B. K. Nnadi for change of coordinate sys
144 //
145 // SMA ---> Supermodule Type A ( SM - 0)
146 // SMAR ---> Supermodule Type A ROTATED ( SM - 1)
147 // SMB ---> Supermodule Type B ( SM - 2)
148 // SMBR ---> Supermodule Type B ROTATED ( SM - 3)
149 //
150 // ism : number of supermodules in one plane = 4
151 // ium : number of unitmodules in one SM = 6
152 // gbum : (global) unit module numbering in a supermodule
153 //
154
155 Int_t gbum = ism*6 + ium;
156 Int_t irow = xpad;
157 Int_t icol = ypad;
158
159 // Corner positions (x,y) of the 24 unit moudles in ALICE PMD
160
161 Double_t xcorner[24] =
162 {
163 85.15, 60.85, 36.55, 85.15, 60.85, 36.55, //SMA
164 -85.15, -60.85, -36.55, -85.15, -60.85, -36.55, //SMAR
165 84.90, 36.60, 84.90, 36.60, 84.90, 36.60, //SMB
166 -84.90, -36.60, -84.90, -36.60, -84.90, -36.60 //SMBR
167 };
168
169 Double_t ycorner[24] =
170 {
171 32.45708755, 32.45708755, 32.45708755, //SMA
172 -9.30645245, -9.30645245, -9.30645245, //SMA
173 -32.45708755, -32.45708755, -32.45708755, //SMAR
174 9.30645245, 9.30645245, 9.30645245, //SMAR
175 -31.63540818, -31.63540818, -52.61435544, //SMB
176 -52.61435544, -73.59330270, -73.59330270, //SMB
177 31.63540818, 31.63540818, 52.61435544, //SMBR
178 52.61435544, 73.59330270, 73.59330270 //SMBR
179 };
180
181 const Float_t kSqroot3 = 1.73205; // sqrt(3.);
182 const Float_t kCellRadius = 0.25;
183
184 //
185 //Every even row of cells is shifted and placed
186 //in geant so this condition
187 //
188 Float_t shift = 0.0;
189 if(irow%2 == 0)
190 {
191 shift = 0.25;
192 }
193 else
194 {
195 shift = 0.0;
196 }
197 if(ism == 0 || ism == 2)
198 {
199 ypos = ycorner[gbum] +
200 irow*kCellRadius*kSqroot3;
201
202 xpos = xcorner[gbum] -
203 icol*2.0*kCellRadius - shift;
204 }
205 else if(ism == 1 || ism == 3)
206 {
207 ypos = ycorner[gbum] -
208 irow*kCellRadius*kSqroot3;
209
210 xpos = xcorner[gbum] +
211 icol*2.0*kCellRadius + shift;
212 }
213}
214
215void AliPMDUtility::RectGeomCellPos(Int_t ism, Int_t ium, Float_t xpad, Float_t ypad, Float_t &xpos, Float_t &ypos)
216{
217 // If the xpad and ypad inputs are float, then 0.5 is added to it
218 // to find the layer which is shifted.
219 // This routine finds the cell eta,phi for the new PMD rectangular
220 // geometry in ALICE
221 // Authors : Bedanga Mohanty and Dipak Mishra - 29.4.2003
222 // modified by B. K. Nnadi for change of coordinate sys
223 //
224 // SMA ---> Supermodule Type A ( SM - 0)
225 // SMAR ---> Supermodule Type A ROTATED ( SM - 1)
226 // SMB ---> Supermodule Type B ( SM - 2)
227 // SMBR ---> Supermodule Type B ROTATED ( SM - 3)
228 //
229 // ism : number of supermodules in one plane = 4
230 // ium : number of unitmodules in one SM = 6
231 // gbum : (global) unit module numbering in a supermodule
232 //
233
234 Int_t gbum = ism*6 + ium;
235 Float_t irow = xpad;
236 Float_t icol = ypad;
237
238 // Corner positions (x,y) of the 24 unit moudles in ALICE PMD
239
240 Double_t xcorner[24] =
241 {
242 85.15, 60.85, 36.55, 85.15, 60.85, 36.55, //SMA
243 -85.15, -60.85, -36.55, -85.15, -60.85, -36.55, //SMAR
244 84.90, 36.60, 84.90, 36.60, 84.90, 36.60, //SMB
245 -84.90, -36.60, -84.90, -36.60, -84.90, -36.60 //SMBR
246 };
247
248 Double_t ycorner[24] =
249 {
250 32.45708755, 32.45708755, 32.45708755, //SMA
251 -9.30645245, -9.30645245, -9.30645245, //SMA
252 -32.45708755, -32.45708755, -32.45708755, //SMAR
253 9.30645245, 9.30645245, 9.30645245, //SMAR
254 -31.63540818, -31.63540818, -52.61435544, //SMB
255 -52.61435544, -73.59330270, -73.59330270, //SMB
256 31.63540818, 31.63540818, 52.61435544, //SMBR
257 52.61435544, 73.59330270, 73.59330270 //SMBR
258 };
259
260 const Float_t kSqroot3 = 1.73205; // sqrt(3.);
261 const Float_t kCellRadius = 0.25;
262
263 //
264 //Every even row of cells is shifted and placed
265 //in geant so this condition
266 //
267 Float_t shift = 0.0;
268 Int_t iirow = (Int_t) (irow+0.5);
269 if(iirow%2 == 0)
270 {
271 shift = 0.25;
272 }
273 else
274 {
275 shift = 0.0;
276 }
277 if(ism == 0 || ism == 2)
278 {
279 ypos = ycorner[gbum] +
280 irow*kCellRadius*kSqroot3;
281
282 xpos = xcorner[gbum] -
283 icol*2.0*kCellRadius - shift;
284 }
285 else if(ism == 1 || ism == 3)
286 {
287 ypos = ycorner[gbum] -
288 irow*kCellRadius*kSqroot3;
289
290 xpos = xcorner[gbum] +
291 icol*2.0*kCellRadius + shift;
292 }
293}
294
295void AliPMDUtility::SetPxPyPz(Float_t px, Float_t py, Float_t pz)
296{
297 fPx = px;
298 fPy = py;
299 fPz = pz;
300}
301
302void AliPMDUtility::SetXYZ(Float_t xpos, Float_t ypos, Float_t zpos)
303{
304 fPx = xpos;
305 fPy = ypos;
306 fPz = zpos;
307}
308void AliPMDUtility::CalculateEta()
309{
310 Float_t rpxpy, theta, eta;
311
312 rpxpy = TMath::Sqrt(fPx*fPx + fPy*fPy);
313 theta = TMath::ATan2(rpxpy,fPz);
314 eta = -TMath::Log(TMath::Tan(0.5*theta));
315 fTheta = theta;
316 fEta = eta;
317}
318void AliPMDUtility::CalculatePhi()
319{
320 Float_t pybypx, phi = 0., phi1;
321
322 if(fPx==0)
323 {
324 if(fPy>0) phi = 90.;
325 if(fPy<0) phi = 270.;
326 }
327 if(fPx != 0)
328 {
329 pybypx = fPy/fPx;
330 if(pybypx < 0) pybypx = - pybypx;
331 phi1 = TMath::ATan(pybypx)*180./3.14159;
332
333 if(fPx > 0 && fPy > 0) phi = phi1; // 1st Quadrant
334 if(fPx < 0 && fPy > 0) phi = 180 - phi1; // 2nd Quadrant
335 if(fPx < 0 && fPy < 0) phi = 180 + phi1; // 3rd Quadrant
336 if(fPx > 0 && fPy < 0) phi = 360 - phi1; // 4th Quadrant
337
338 }
339 phi = phi*3.14159/180.;
340
341 fPhi = phi;
342
343}
344void AliPMDUtility::CalculateEtaPhi()
345{
346 Float_t rpxpy, theta, eta;
347 Float_t pybypx, phi = 0., phi1;
348
349 rpxpy = TMath::Sqrt(fPx*fPx + fPy*fPy);
350 theta = TMath::ATan2(rpxpy,fPz);
351 eta = -TMath::Log(TMath::Tan(0.5*theta));
352
353 if(fPx==0)
354 {
355 if(fPy>0) phi = 90.;
356 if(fPy<0) phi = 270.;
357 }
358 if(fPx != 0)
359 {
360 pybypx = fPy/fPx;
361 if(pybypx < 0) pybypx = - pybypx;
362 phi1 = TMath::ATan(pybypx)*180./3.14159;
363 if(fPx > 0 && fPy > 0) phi = phi1; // 1st Quadrant
364 if(fPx < 0 && fPy > 0) phi = 180 - phi1; // 2nd Quadrant
365 if(fPx < 0 && fPy < 0) phi = 180 + phi1; // 3rd Quadrant
366 if(fPx > 0 && fPy < 0) phi = 360 - phi1; // 4th Quadrant
367
368 }
369 phi = phi*3.14159/180.;
370
371 fTheta = theta;
372 fEta = eta;
373 fPhi = phi;
374}
375Float_t AliPMDUtility::GetTheta() const
376{
377 return fTheta;
378}
379Float_t AliPMDUtility::GetEta() const
380{
381 return fEta;
382}
383Float_t AliPMDUtility::GetPhi() const
384{
385 return fPhi;
386}
387