Preprocessor modified not to send the correct gain file
[u/mrichter/AliRoot.git] / PMD / AliPMDUtility.cxx
CommitLineData
a918d77a 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 **************************************************************************/
638f6e9b 15//-----------------------------------------------------//
16// //
17// //
18// Date : August 05 2003 //
19// //
20// Utility code for ALICE-PMD //
21// //
22//-----------------------------------------------------//
23
a918d77a 24#include "Riostream.h"
638f6e9b 25#include "TMath.h"
2c08d1c1 26#include "TText.h"
27#include "TLine.h"
28
638f6e9b 29#include <stdio.h>
a918d77a 30#include <math.h>
31
2c08d1c1 32#include "AliPMDUtility.h"
33
638f6e9b 34
35ClassImp(AliPMDUtility)
36
5d35baec 37AliPMDUtility::AliPMDUtility():
38 fPx(0.),
39 fPy(0.),
40 fPz(0.),
41 fTheta(0.),
42 fEta(0.),
2c08d1c1 43 fPhi(0.),
44 fWriteModule(1)
638f6e9b 45{
a918d77a 46 // Default constructor
638f6e9b 47}
48
5d35baec 49AliPMDUtility::AliPMDUtility(Float_t px, Float_t py, Float_t pz):
50 fPx(px),
51 fPy(py),
52 fPz(pz),
53 fTheta(0.),
54 fEta(0.),
2c08d1c1 55 fPhi(0.),
56 fWriteModule(1)
638f6e9b 57{
a918d77a 58 // Constructor
638f6e9b 59}
5d35baec 60AliPMDUtility::AliPMDUtility(const AliPMDUtility &pmdutil):
61 fPx(pmdutil.fPx),
62 fPy(pmdutil.fPy),
63 fPz(pmdutil.fPz),
64 fTheta(pmdutil.fTheta),
65 fEta(pmdutil.fEta),
2c08d1c1 66 fPhi(pmdutil.fPhi),
67 fWriteModule(pmdutil.fWriteModule)
5d35baec 68{
69 // copy constructor
70}
71AliPMDUtility & AliPMDUtility::operator=(const AliPMDUtility &pmdutil)
72{
73 // assignment operator
74 if(this != &pmdutil)
75 {
76 fPx = pmdutil.fPx;
77 fPy = pmdutil.fPy;
78 fPz = pmdutil.fPz;
79 fTheta = pmdutil.fTheta;
80 fEta = pmdutil.fEta;
81 fPhi = pmdutil.fPhi;
2c08d1c1 82 fWriteModule = pmdutil.fWriteModule;
5d35baec 83 }
84 return *this;
85}
638f6e9b 86AliPMDUtility::~AliPMDUtility()
87{
a918d77a 88 // Default destructor
638f6e9b 89}
afb8e3a0 90
01c4d84a 91void AliPMDUtility::RectGeomCellPos(Int_t ism, Int_t xpad, Int_t ypad, Float_t &xpos, Float_t &ypos)
afb8e3a0 92{
93 // This routine finds the cell eta,phi for the new PMD rectangular
94 // geometry in ALICE
95 // Authors : Bedanga Mohanty and Dipak Mishra - 29.4.2003
01c4d84a 96 // modified by B. K. Nandi for change of coordinate sys
afb8e3a0 97 //
98 // SMA ---> Supermodule Type A ( SM - 0)
99 // SMAR ---> Supermodule Type A ROTATED ( SM - 1)
100 // SMB ---> Supermodule Type B ( SM - 2)
101 // SMBR ---> Supermodule Type B ROTATED ( SM - 3)
102 //
01c4d84a 103 // ism : Serial module number from 0 to 23 for each plane
afb8e3a0 104
01c4d84a 105
afb8e3a0 106 // Corner positions (x,y) of the 24 unit moudles in ALICE PMD
f117e3aa 107
f117e3aa 108 double xcorner[24] =
109 {
110 74.8833, 53.0045, 31.1255, //Type-A
111 74.8833, 53.0045, 31.1255, //Type-A
112 -74.8833, -53.0044, -31.1255, //Type-AR
113 -74.8833, -53.0044, -31.1255, //Type-AR
114 8.9165, -33.7471, //Type-B
115 8.9165, -33.7471, //Type-B
116 8.9165, -33.7471, //Type-B
117 -8.9165, 33.7471, //Type-BR
118 -8.9165, 33.7471, //Type-BR
119 -8.9165, 33.7471, //Type-BR
120 };
121
afb8e3a0 122
f117e3aa 123 double ycorner[24] =
124 {
125 86.225, 86.225, 86.225, //Type-A
126 37.075, 37.075, 37.075, //Type-A
127 -86.225, -86.225, -86.225, //Type-AR
128 -37.075, -37.075, -37.075, //Type-AR
129 86.225, 86.225, //Type-B
130 61.075, 61.075, //Type-B
131 35.925, 35.925, //Type-B
132 -86.225, -86.225, //Type-BR
133 -61.075, -61.075, //Type-BR
134 -35.925, -35.925 //Type-BR
135 };
136
afb8e3a0 137
a918d77a 138 const Float_t kSqroot3 = 1.73205; // sqrt(3.);
139 const Float_t kCellRadius = 0.25;
afb8e3a0 140
141 //
142 //Every even row of cells is shifted and placed
143 //in geant so this condition
144 //
f117e3aa 145 Float_t cellRadius = 0.25;
a2441c6e 146 Float_t shift = 0.0;
01c4d84a 147 if(xpad%2 == 0)
afb8e3a0 148 {
f117e3aa 149 shift = -cellRadius/2.0;
afb8e3a0 150 }
151 else
152 {
153 shift = 0.0;
154 }
afb8e3a0 155
01c4d84a 156
157 if(ism < 6)
f117e3aa 158 {
01c4d84a 159 ypos = ycorner[ism] - (Float_t) xpad*kCellRadius*2.0 + shift;
160 xpos = xcorner[ism] - (Float_t) ypad*kSqroot3*kCellRadius;
afb8e3a0 161 }
01c4d84a 162 else if(ism >=6 && ism < 12)
afb8e3a0 163 {
01c4d84a 164 ypos = ycorner[ism] + (Float_t) xpad*kCellRadius*2.0 + shift;
165 xpos = xcorner[ism] + (Float_t) ypad*kSqroot3*kCellRadius;
f117e3aa 166 }
01c4d84a 167 else if(ism >= 12 && ism < 18)
f117e3aa 168 {
01c4d84a 169 ypos = ycorner[ism] - (Float_t) xpad*kCellRadius*2.0 + shift;
170 xpos = xcorner[ism] - (Float_t) ypad*kSqroot3*kCellRadius;
a2441c6e 171 }
01c4d84a 172 else if(ism >= 18 && ism < 24)
f117e3aa 173 {
01c4d84a 174 ypos = ycorner[ism] + (Float_t) xpad*kCellRadius*2.0 + shift;
175 xpos = xcorner[ism] + (Float_t) ypad*kSqroot3*kCellRadius;
f117e3aa 176 }
177
a2441c6e 178}
179
01c4d84a 180void AliPMDUtility::RectGeomCellPos(Int_t ism, Float_t xpad, Float_t ypad, Float_t &xpos, Float_t &ypos)
a2441c6e 181{
182 // If the xpad and ypad inputs are float, then 0.5 is added to it
183 // to find the layer which is shifted.
184 // This routine finds the cell eta,phi for the new PMD rectangular
185 // geometry in ALICE
186 // Authors : Bedanga Mohanty and Dipak Mishra - 29.4.2003
187 // modified by B. K. Nnadi for change of coordinate sys
188 //
189 // SMA ---> Supermodule Type A ( SM - 0)
190 // SMAR ---> Supermodule Type A ROTATED ( SM - 1)
191 // SMB ---> Supermodule Type B ( SM - 2)
192 // SMBR ---> Supermodule Type B ROTATED ( SM - 3)
193 //
01c4d84a 194 // ism : Serial Module number from 0 to 23 for each plane
a2441c6e 195
196 // Corner positions (x,y) of the 24 unit moudles in ALICE PMD
f117e3aa 197
f117e3aa 198 double xcorner[24] =
199 {
200 74.8833, 53.0045, 31.1255, //Type-A
201 74.8833, 53.0045, 31.1255, //Type-A
202 -74.8833, -53.0044, -31.1255, //Type-AR
203 -74.8833, -53.0044, -31.1255, //Type-AR
204 8.9165, -33.7471, //Type-B
205 8.9165, -33.7471, //Type-B
206 8.9165, -33.7471, //Type-B
207 -8.9165, 33.7471, //Type-BR
208 -8.9165, 33.7471, //Type-BR
209 -8.9165, 33.7471, //Type-BR
210 };
211
a2441c6e 212
f117e3aa 213
214 double ycorner[24] =
215 {
216 86.225, 86.225, 86.225, //Type-A
217 37.075, 37.075, 37.075, //Type-A
218 -86.225, -86.225, -86.225, //Type-AR
219 -37.075, -37.075, -37.075, //Type-AR
220 86.225, 86.225, //Type-B
221 61.075, 61.075, //Type-B
222 35.925, 35.925, //Type-B
223 -86.225, -86.225, //Type-BR
224 -61.075, -61.075, //Type-BR
225 -35.925, -35.925 //Type-BR
226 };
227
228
a918d77a 229 const Float_t kSqroot3 = 1.73205; // sqrt(3.);
230 const Float_t kCellRadius = 0.25;
a2441c6e 231
232 //
233 //Every even row of cells is shifted and placed
234 //in geant so this condition
235 //
f117e3aa 236 Float_t cellRadius = 0.25;
a2441c6e 237 Float_t shift = 0.0;
01c4d84a 238 Int_t iirow = (Int_t) (xpad+0.5);
a2441c6e 239 if(iirow%2 == 0)
240 {
f117e3aa 241 shift = -cellRadius/2.0;
a2441c6e 242 }
243 else
244 {
245 shift = 0.0;
246 }
a2441c6e 247
01c4d84a 248 if(ism < 6)
f117e3aa 249 {
01c4d84a 250 ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
251 xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
a2441c6e 252 }
01c4d84a 253 else if(ism >=6 && ism < 12)
a2441c6e 254 {
01c4d84a 255 ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
256 xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
f117e3aa 257 }
01c4d84a 258 else if(ism >= 12 && ism < 18)
f117e3aa 259 {
01c4d84a 260 ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
261 xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
f117e3aa 262 }
01c4d84a 263 else if(ism >= 18 && ism < 24)
f117e3aa 264 {
01c4d84a 265 ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
266 xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
afb8e3a0 267 }
f117e3aa 268
afb8e3a0 269}
2c08d1c1 270// -------------------------------------------------------- //
271
272void AliPMDUtility::GenerateBoundaryPoints(Int_t ism, Float_t &x1ism,
273 Float_t &y1ism, Float_t &x2ism,
274 Float_t &y2ism)
275{
276 // Generate bounding-box.
277
278
279 Float_t xism = 0, yism = 0;
89f0ae35 280 Float_t dxism = 0., dyism = 0.;
2c08d1c1 281
282 const Float_t kRad = 0.25;
283 const Float_t kSqRoot3 = 1.732050808;
284 const Float_t kDia = 0.50;
285
286
287 const Double_t kXcorner[24] =
288 {
289 74.8833, 53.0045, 31.1255, //Type-A
290 74.8833, 53.0045, 31.1255, //Type-A
291 -74.8833, -53.0044, -31.1255, //Type-AR
292 -74.8833, -53.0044, -31.1255, //Type-AR
293 8.9165, -33.7471, //Type-B
294 8.9165, -33.7471, //Type-B
295 8.9165, -33.7471, //Type-B
296 -8.9165, 33.7471, //Type-BR
297 -8.9165, 33.7471, //Type-BR
298 -8.9165, 33.7471, //Type-BR
299 };
300
301
302 const Double_t kYcorner[24] =
303 {
304 86.225, 86.225, 86.225, //Type-A
305 37.075, 37.075, 37.075, //Type-A
306 -86.225, -86.225, -86.225, //Type-AR
307 -37.075, -37.075, -37.075, //Type-AR
308 86.225, 86.225, //Type-B
309 61.075, 61.075, //Type-B
310 35.925, 35.925, //Type-B
311 -86.225, -86.225, //Type-BR
312 -61.075, -61.075, //Type-BR
313 -35.925, -35.925 //Type-BR
314 };
315
316
317 if (ism > 23) ism -= 24;
318
319
320 if (ism < 6)
321 {
322 xism = kXcorner[ism] + kRad;
323 yism = kYcorner[ism] + kRad;
324 dxism = -kRad*kSqRoot3*48.;
325 dyism = -kDia*96. - kRad;
326 }
327 if (ism >= 6 && ism < 12)
328 {
329 xism = kXcorner[ism] - kRad;
330 yism = kYcorner[ism] - kRad;
331 dxism = kRad*kSqRoot3*48.;
332 dyism = kDia*96. + kRad;
333 }
334 if (ism >= 12 && ism < 18)
335 {
336 xism = kXcorner[ism] + kRad;
337 yism = kYcorner[ism] + kRad;
338 dxism = -kRad*kSqRoot3*96.;
339 dyism = -kDia*48. - kRad;
340 }
341 if (ism >= 18 && ism < 24)
342 {
343 xism = kXcorner[ism] - kRad;
344 yism = kYcorner[ism] - kRad;
345 dxism = kRad*kSqRoot3*96.;
346 dyism = kDia*48. + kRad;
347 }
348
349 x1ism = xism;
350 x2ism = xism + dxism;
351 y1ism = yism;
352 y2ism = yism + dyism;
353
354}
355// ------------------------------------------------------------------- //
356
27f6261d 357void AliPMDUtility::DrawPMDModule(Int_t idet)
2c08d1c1 358{
359
360 Float_t x1ism, x2ism, y1ism, y2ism;
361 Float_t deltaX, deltaY;
362
363 //TH2F *h2 = new TH2F("h2","Y vs. X",200,-100.,100.,200,-100.,100.);
364 //h2->Draw();
365
366 TLine t;
367 t.SetLineColor(2);
368
369 TText tt;
370 tt.SetTextColor(4);
371
372 Char_t smnumber[10];
373
374 for(Int_t ism=0; ism < 24; ism++)
375 {
376 GenerateBoundaryPoints(ism, x1ism, y1ism, x2ism, y2ism);
377 deltaX = (x2ism - x1ism)/2.;
378 deltaY = (y2ism - y1ism)/2.;
379 if (fWriteModule == 1)
380 {
27f6261d 381 if(idet == 0)
382 {
383 sprintf(smnumber,"%d",ism);
384 }
385 else if (idet == 1)
386 {
387 sprintf(smnumber,"%d",24+ism);
388 }
2c08d1c1 389 tt.DrawText(x1ism+deltaX,y1ism+deltaY,smnumber);
390 }
391 t.DrawLine(x1ism, y1ism, x1ism, y2ism);
392 t.DrawLine(x1ism, y1ism, x2ism, y1ism);
393 t.DrawLine(x2ism, y1ism, x2ism, y2ism);
394 t.DrawLine(x1ism, y2ism, x2ism, y2ism);
395 }
396
397}
398
399// ------------------------------------------------------------------- //
400
401
5d35baec 402void AliPMDUtility::ApplyVertexCorrection(Float_t vertex[], Float_t xpos,
403 Float_t ypos, Float_t zpos)
404{
405 // Not implemented
406 fPx = xpos - vertex[0];
407 fPy = ypos - vertex[1];
408 fPz = zpos - vertex[2];
409}
410void AliPMDUtility::ApplyAlignment()
411{
412 // Not implemented
413}
638f6e9b 414
a918d77a 415void AliPMDUtility::SetPxPyPz(Float_t px, Float_t py, Float_t pz)
638f6e9b 416{
a918d77a 417 fPx = px;
418 fPy = py;
419 fPz = pz;
638f6e9b 420}
421
a918d77a 422void AliPMDUtility::SetXYZ(Float_t xpos, Float_t ypos, Float_t zpos)
638f6e9b 423{
a918d77a 424 fPx = xpos;
425 fPy = ypos;
426 fPz = zpos;
638f6e9b 427}
2c08d1c1 428void AliPMDUtility::SetWriteModule(Int_t wrmod)
429{
430 fWriteModule = wrmod;
431}
638f6e9b 432void AliPMDUtility::CalculateEta()
433{
434 Float_t rpxpy, theta, eta;
435
436 rpxpy = TMath::Sqrt(fPx*fPx + fPy*fPy);
437 theta = TMath::ATan2(rpxpy,fPz);
438 eta = -TMath::Log(TMath::Tan(0.5*theta));
439 fTheta = theta;
440 fEta = eta;
441}
442void AliPMDUtility::CalculatePhi()
443{
444 Float_t pybypx, phi = 0., phi1;
445
446 if(fPx==0)
447 {
448 if(fPy>0) phi = 90.;
449 if(fPy<0) phi = 270.;
450 }
451 if(fPx != 0)
452 {
453 pybypx = fPy/fPx;
454 if(pybypx < 0) pybypx = - pybypx;
455 phi1 = TMath::ATan(pybypx)*180./3.14159;
afb8e3a0 456
457 if(fPx > 0 && fPy > 0) phi = phi1; // 1st Quadrant
458 if(fPx < 0 && fPy > 0) phi = 180 - phi1; // 2nd Quadrant
459 if(fPx < 0 && fPy < 0) phi = 180 + phi1; // 3rd Quadrant
460 if(fPx > 0 && fPy < 0) phi = 360 - phi1; // 4th Quadrant
461
638f6e9b 462 }
463 phi = phi*3.14159/180.;
464
465 fPhi = phi;
466
467}
468void AliPMDUtility::CalculateEtaPhi()
469{
470 Float_t rpxpy, theta, eta;
471 Float_t pybypx, phi = 0., phi1;
472
473 rpxpy = TMath::Sqrt(fPx*fPx + fPy*fPy);
474 theta = TMath::ATan2(rpxpy,fPz);
475 eta = -TMath::Log(TMath::Tan(0.5*theta));
476
5d35baec 477 if(fPx == 0)
638f6e9b 478 {
479 if(fPy>0) phi = 90.;
480 if(fPy<0) phi = 270.;
481 }
482 if(fPx != 0)
483 {
484 pybypx = fPy/fPx;
485 if(pybypx < 0) pybypx = - pybypx;
486 phi1 = TMath::ATan(pybypx)*180./3.14159;
afb8e3a0 487 if(fPx > 0 && fPy > 0) phi = phi1; // 1st Quadrant
488 if(fPx < 0 && fPy > 0) phi = 180 - phi1; // 2nd Quadrant
489 if(fPx < 0 && fPy < 0) phi = 180 + phi1; // 3rd Quadrant
490 if(fPx > 0 && fPy < 0) phi = 360 - phi1; // 4th Quadrant
491
638f6e9b 492 }
493 phi = phi*3.14159/180.;
494
495 fTheta = theta;
496 fEta = eta;
497 fPhi = phi;
498}
5d35baec 499void AliPMDUtility::CalculateXY(Float_t eta, Float_t phi, Float_t zpos)
500{
501 // Not implemented
502
503 // eta = -TMath::Log(TMath::Tan(0.5*theta));
504
505 Float_t xpos = 0., ypos = 0.;
506
507 // Float_t theta = 2.0*TMath::ATan(TMath::Log(-eta));
508
509 fEta = eta;
510 fPhi = phi;
511 fPx = xpos;
512 fPy = ypos;
513 fPz = zpos;
514}
638f6e9b 515Float_t AliPMDUtility::GetTheta() const
516{
517 return fTheta;
518}
519Float_t AliPMDUtility::GetEta() const
520{
521 return fEta;
522}
523Float_t AliPMDUtility::GetPhi() const
524{
525 return fPhi;
526}
5d35baec 527Float_t AliPMDUtility::GetX() const
528{
529 return fPx;
530}
531Float_t AliPMDUtility::GetY() const
532{
533 return fPy;
534}
535Float_t AliPMDUtility::GetZ() const
536{
537 return fPz;
538}
638f6e9b 539
2c08d1c1 540