#include "Riostream.h"
#include "TMath.h"
#include "TText.h"
#include "TLine.h"
#include <stdio.h>
#include <math.h>
#include "AliPMDUtility.h"
ClassImp(AliPMDUtility)
AliPMDUtility::AliPMDUtility():
fPx(0.),
fPy(0.),
fPz(0.),
fTheta(0.),
fEta(0.),
fPhi(0.),
fWriteModule(1)
{
for (Int_t i = 0; i < 4; i++)
{
for (Int_t j = 0; j < 3; j++)
{
fSecTr[i][j] = 0.;
}
}
}
AliPMDUtility::AliPMDUtility(Float_t px, Float_t py, Float_t pz):
fPx(px),
fPy(py),
fPz(pz),
fTheta(0.),
fEta(0.),
fPhi(0.),
fWriteModule(1)
{
for (Int_t i = 0; i < 4; i++)
{
for (Int_t j = 0; j < 3; j++)
{
fSecTr[i][j] = 0.;
}
}
}
AliPMDUtility::AliPMDUtility(const AliPMDUtility &pmdutil):
TObject(pmdutil),
fPx(pmdutil.fPx),
fPy(pmdutil.fPy),
fPz(pmdutil.fPz),
fTheta(pmdutil.fTheta),
fEta(pmdutil.fEta),
fPhi(pmdutil.fPhi),
fWriteModule(pmdutil.fWriteModule)
{
for (Int_t i = 0; i < 4; i++)
{
for (Int_t j = 0; j < 3; j++)
{
fSecTr[i][j] = pmdutil.fSecTr[i][j];
}
}
}
AliPMDUtility & AliPMDUtility::operator=(const AliPMDUtility &pmdutil)
{
if(this != &pmdutil)
{
fPx = pmdutil.fPx;
fPy = pmdutil.fPy;
fPz = pmdutil.fPz;
fTheta = pmdutil.fTheta;
fEta = pmdutil.fEta;
fPhi = pmdutil.fPhi;
fWriteModule = pmdutil.fWriteModule;
for (Int_t i = 0; i < 4; i++)
{
for (Int_t j = 0; j < 3; j++)
{
fSecTr[i][j] = pmdutil.fSecTr[i][j];
}
}
}
return *this;
}
AliPMDUtility::~AliPMDUtility()
{
}
void AliPMDUtility::RectGeomCellPos(Int_t ism, Int_t xpad, Int_t ypad, Float_t &xpos, Float_t &ypos)
{
double xcorner[24] =
{
74.8833, 53.0045, 31.1255,
74.8833, 53.0045, 31.1255,
-74.8833, -53.0044, -31.1255,
-74.8833, -53.0044, -31.1255,
8.9165, -33.7471,
8.9165, -33.7471,
8.9165, -33.7471,
-8.9165, 33.7471,
-8.9165, 33.7471,
-8.9165, 33.7471,
};
double ycorner[24] =
{
86.225, 86.225, 86.225,
37.075, 37.075, 37.075,
-86.225, -86.225, -86.225,
-37.075, -37.075, -37.075,
86.225, 86.225,
61.075, 61.075,
35.925, 35.925,
-86.225, -86.225,
-61.075, -61.075,
-35.925, -35.925
};
const Float_t kSqroot3 = 1.73205;
const Float_t kCellRadius = 0.25;
Float_t cellRadius = 0.25;
Float_t shift = 0.0;
if(xpad%2 == 0)
{
shift = -cellRadius/2.0;
}
else
{
shift = 0.0;
}
if(ism < 6)
{
ypos = ycorner[ism] - (Float_t) xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] - (Float_t) ypad*kSqroot3*kCellRadius;
}
else if(ism >=6 && ism < 12)
{
ypos = ycorner[ism] + (Float_t) xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] + (Float_t) ypad*kSqroot3*kCellRadius;
}
else if(ism >= 12 && ism < 18)
{
ypos = ycorner[ism] - (Float_t) xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] - (Float_t) ypad*kSqroot3*kCellRadius;
}
else if(ism >= 18 && ism < 24)
{
ypos = ycorner[ism] + (Float_t) xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] + (Float_t) ypad*kSqroot3*kCellRadius;
}
if(ism < 6)
{
xpos += fSecTr[0][0];
ypos += fSecTr[0][1];
}
else if(ism >= 6 && ism < 12)
{
xpos += fSecTr[1][0];
ypos += fSecTr[1][1];
}
else if(ism >=12 && ism < 18)
{
xpos += fSecTr[2][0];
ypos += fSecTr[2][1];
}
else if(ism >= 18 && ism < 24)
{
xpos += fSecTr[3][0];
ypos += fSecTr[3][1];
}
}
void AliPMDUtility::RectGeomCellPos(Int_t ism, Float_t xpad, Float_t ypad, Float_t &xpos, Float_t &ypos)
{
double xcorner[24] =
{
74.8833, 53.0045, 31.1255,
74.8833, 53.0045, 31.1255,
-74.8833, -53.0044, -31.1255,
-74.8833, -53.0044, -31.1255,
8.9165, -33.7471,
8.9165, -33.7471,
8.9165, -33.7471,
-8.9165, 33.7471,
-8.9165, 33.7471,
-8.9165, 33.7471,
};
double ycorner[24] =
{
86.225, 86.225, 86.225,
37.075, 37.075, 37.075,
-86.225, -86.225, -86.225,
-37.075, -37.075, -37.075,
86.225, 86.225,
61.075, 61.075,
35.925, 35.925,
-86.225, -86.225,
-61.075, -61.075,
-35.925, -35.925
};
const Float_t kSqroot3 = 1.73205;
const Float_t kCellRadius = 0.25;
Float_t cellRadius = 0.25;
Float_t shift = 0.0;
Int_t iirow = (Int_t) (xpad+0.5);
if(iirow%2 == 0)
{
shift = -cellRadius/2.0;
}
else
{
shift = 0.0;
}
if(ism < 6)
{
ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
}
else if(ism >=6 && ism < 12)
{
ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
}
else if(ism >= 12 && ism < 18)
{
ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
}
else if(ism >= 18 && ism < 24)
{
ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
}
if(ism < 6)
{
xpos += fSecTr[0][0];
ypos += fSecTr[0][1];
}
else if(ism >= 6 && ism < 12)
{
xpos += fSecTr[1][0];
ypos += fSecTr[1][1];
}
else if(ism >=12 && ism < 18)
{
xpos += fSecTr[2][0];
ypos += fSecTr[2][1];
}
else if(ism >= 18 && ism < 24)
{
xpos += fSecTr[3][0];
ypos += fSecTr[3][1];
}
}
void AliPMDUtility::RectGeomCellPos(Int_t ism, Float_t xpad,
Float_t ypad, Float_t &xpos,
Float_t &ypos, Float_t & zpos)
{
double xcorner[24] =
{
74.8833, 53.0045, 31.1255,
74.8833, 53.0045, 31.1255,
-74.8833, -53.0044, -31.1255,
-74.8833, -53.0044, -31.1255,
8.9165, -33.7471,
8.9165, -33.7471,
8.9165, -33.7471,
-8.9165, 33.7471,
-8.9165, 33.7471,
-8.9165, 33.7471,
};
double ycorner[24] =
{
86.225, 86.225, 86.225,
37.075, 37.075, 37.075,
-86.225, -86.225, -86.225,
-37.075, -37.075, -37.075,
86.225, 86.225,
61.075, 61.075,
35.925, 35.925,
-86.225, -86.225,
-61.075, -61.075,
-35.925, -35.925
};
const Float_t kSqroot3 = 1.73205;
const Float_t kCellRadius = 0.25;
Float_t cellRadius = 0.25;
Float_t shift = 0.0;
Int_t iirow = (Int_t) (xpad+0.5);
if(iirow%2 == 0)
{
shift = -cellRadius/2.0;
}
else
{
shift = 0.0;
}
if(ism < 6)
{
ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
}
else if(ism >=6 && ism < 12)
{
ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
}
else if(ism >= 12 && ism < 18)
{
ypos = ycorner[ism] - xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] - ypad*kSqroot3*kCellRadius;
}
else if(ism >= 18 && ism < 24)
{
ypos = ycorner[ism] + xpad*kCellRadius*2.0 + shift;
xpos = xcorner[ism] + ypad*kSqroot3*kCellRadius;
}
if(ism < 6)
{
xpos += fSecTr[0][0];
ypos += fSecTr[0][1];
zpos += fSecTr[0][2];
}
else if(ism >= 6 && ism < 12)
{
xpos += fSecTr[1][0];
ypos += fSecTr[1][1];
zpos += fSecTr[1][2];
}
else if(ism >=12 && ism < 18)
{
xpos += fSecTr[2][0];
ypos += fSecTr[2][1];
zpos += fSecTr[2][2];
}
else if(ism >= 18 && ism < 24)
{
xpos += fSecTr[3][0];
ypos += fSecTr[3][1];
zpos += fSecTr[3][2];
}
}
void AliPMDUtility::GenerateBoundaryPoints(Int_t ism, Float_t &x1ism,
Float_t &y1ism, Float_t &x2ism,
Float_t &y2ism)
{
Float_t xism = 0, yism = 0;
Float_t dxism = 0., dyism = 0.;
const Float_t kRad = 0.25;
const Float_t kSqRoot3 = 1.732050808;
const Float_t kDia = 0.50;
const Double_t kXcorner[24] =
{
74.8833, 53.0045, 31.1255,
74.8833, 53.0045, 31.1255,
-74.8833, -53.0044, -31.1255,
-74.8833, -53.0044, -31.1255,
8.9165, -33.7471,
8.9165, -33.7471,
8.9165, -33.7471,
-8.9165, 33.7471,
-8.9165, 33.7471,
-8.9165, 33.7471,
};
const Double_t kYcorner[24] =
{
86.225, 86.225, 86.225,
37.075, 37.075, 37.075,
-86.225, -86.225, -86.225,
-37.075, -37.075, -37.075,
86.225, 86.225,
61.075, 61.075,
35.925, 35.925,
-86.225, -86.225,
-61.075, -61.075,
-35.925, -35.925
};
if (ism > 23) ism -= 24;
if (ism < 6)
{
xism = kXcorner[ism] + kRad;
yism = kYcorner[ism] + kRad;
dxism = -kRad*kSqRoot3*48.;
dyism = -kDia*96. - kRad;
}
if (ism >= 6 && ism < 12)
{
xism = kXcorner[ism] - kRad;
yism = kYcorner[ism] - kRad;
dxism = kRad*kSqRoot3*48.;
dyism = kDia*96. + kRad;
}
if (ism >= 12 && ism < 18)
{
xism = kXcorner[ism] + kRad;
yism = kYcorner[ism] + kRad;
dxism = -kRad*kSqRoot3*96.;
dyism = -kDia*48. - kRad;
}
if (ism >= 18 && ism < 24)
{
xism = kXcorner[ism] - kRad;
yism = kYcorner[ism] - kRad;
dxism = kRad*kSqRoot3*96.;
dyism = kDia*48. + kRad;
}
x1ism = xism;
x2ism = xism + dxism;
y1ism = yism;
y2ism = yism + dyism;
}
void AliPMDUtility::DrawPMDModule(Int_t idet)
{
Float_t x1ism = 0., x2ism = 0., y1ism = 0., y2ism = 0.;
Float_t deltaX = 0., deltaY = 0.;
TLine t;
t.SetLineColor(2);
TText tt;
tt.SetTextColor(4);
Char_t smnumber[10];
for(Int_t ism=0; ism < 24; ism++)
{
GenerateBoundaryPoints(ism, x1ism, y1ism, x2ism, y2ism);
deltaX = (x2ism - x1ism)/2.;
deltaY = (y2ism - y1ism)/2.;
if (fWriteModule == 1)
{
if(idet == 0)
{
snprintf(smnumber,10,"%d",ism);
}
else if (idet == 1)
{
snprintf(smnumber,10,"%d",24+ism);
}
tt.DrawText(x1ism+deltaX,y1ism+deltaY,smnumber);
}
t.DrawLine(x1ism, y1ism, x1ism, y2ism);
t.DrawLine(x1ism, y1ism, x2ism, y1ism);
t.DrawLine(x2ism, y1ism, x2ism, y2ism);
t.DrawLine(x1ism, y2ism, x2ism, y2ism);
}
}
void AliPMDUtility::ApplyVertexCorrection(Float_t vertex[], Float_t xpos,
Float_t ypos, Float_t zpos)
{
fPx = xpos - vertex[0];
fPy = ypos - vertex[1];
fPz = zpos - vertex[2];
}
void AliPMDUtility::ApplyAlignment(Double_t sectr[][3])
{
for (Int_t isector=0; isector<4; isector++)
{
for(Int_t ixyz=0; ixyz < 3; ixyz++)
{
fSecTr[isector][ixyz] = (Float_t) sectr[isector][ixyz];
}
}
}
void AliPMDUtility::SetPxPyPz(Float_t px, Float_t py, Float_t pz)
{
fPx = px;
fPy = py;
fPz = pz;
}
void AliPMDUtility::SetXYZ(Float_t xpos, Float_t ypos, Float_t zpos)
{
fPx = xpos;
fPy = ypos;
fPz = zpos;
}
void AliPMDUtility::SetWriteModule(Int_t wrmod)
{
fWriteModule = wrmod;
}
void AliPMDUtility::CalculateEta()
{
Float_t rpxpy = TMath::Sqrt(fPx*fPx + fPy*fPy);
Float_t theta = TMath::ATan2(rpxpy,fPz);
Float_t eta = -TMath::Log(TMath::Tan(0.5*theta));
fTheta = theta;
fEta = eta;
}
void AliPMDUtility::CalculatePhi()
{
Float_t pybypx = 0., phi = 0., phi1 = 0.;
if(fPx==0)
{
if(fPy>0) phi = 90.;
if(fPy<0) phi = 270.;
}
if(fPx != 0)
{
pybypx = fPy/fPx;
if(pybypx < 0) pybypx = - pybypx;
phi1 = TMath::ATan(pybypx)*180./3.14159;
if(fPx > 0 && fPy > 0) phi = phi1;
if(fPx < 0 && fPy > 0) phi = 180 - phi1;
if(fPx < 0 && fPy < 0) phi = 180 + phi1;
if(fPx > 0 && fPy < 0) phi = 360 - phi1;
}
phi = phi*3.14159/180.;
fPhi = phi;
}
void AliPMDUtility::CalculateEtaPhi()
{
Float_t pybypx = 0., phi = 0., phi1 = 0.;
Float_t rpxpy = TMath::Sqrt(fPx*fPx + fPy*fPy);
Float_t theta = TMath::ATan2(rpxpy,fPz);
Float_t eta = -TMath::Log(TMath::Tan(0.5*theta));
if(fPx == 0)
{
if(fPy>0) phi = 90.;
if(fPy<0) phi = 270.;
}
if(fPx != 0)
{
pybypx = fPy/fPx;
if(pybypx < 0) pybypx = - pybypx;
phi1 = TMath::ATan(pybypx)*180./3.14159;
if(fPx > 0 && fPy > 0) phi = phi1;
if(fPx < 0 && fPy > 0) phi = 180 - phi1;
if(fPx < 0 && fPy < 0) phi = 180 + phi1;
if(fPx > 0 && fPy < 0) phi = 360 - phi1;
}
phi = phi*3.14159/180.;
fTheta = theta;
fEta = eta;
fPhi = phi;
}
void AliPMDUtility::CalculateXY(Float_t eta, Float_t phi, Float_t zpos)
{
Float_t xpos = 0., ypos = 0.;
fEta = eta;
fPhi = phi;
fPx = xpos;
fPy = ypos;
fPz = zpos;
}
void AliPMDUtility::GetEtaIndexXY(Int_t smn, Int_t row, Int_t col, Float_t &xp, Float_t &yp, Double_t &eta, Int_t &etaindex) {
Float_t xx = 0., yy = 0.;
Int_t xpad = -1, ypad = -1;
if(smn <12) {
xpad = col;
ypad = row;
}
else if(smn >=12 && smn < 24) {
xpad = row;
ypad = col;
}
RectGeomCellPos(smn,xpad,ypad,xx,yy);
xp = xx;
yp = yy;
Float_t rpxpy = TMath::Sqrt(xx*xx + yy*yy);
Float_t theta = TMath::ATan2(rpxpy,365.0);
eta = -TMath::Log(TMath::Tan(0.5*theta));
Int_t etaBin = -1;
if( eta > 2.1 && eta < 2.3) etaBin = 0;
else if( eta > 2.3 && eta < 2.5) etaBin = 1;
else if( eta > 2.5 && eta < 2.7) etaBin = 2;
else if( eta > 2.7 && eta < 2.9) etaBin = 3;
else if( eta > 2.9 && eta < 3.1) etaBin = 4;
else if( eta > 3.1 && eta < 3.3) etaBin = 5;
else if( eta > 3.3 && eta < 3.5) etaBin = 6;
else if( eta > 3.5 && eta < 3.7) etaBin = 7;
else if( eta > 3.7 && eta < 3.9) etaBin = 8;
else if( eta > 3.9 && eta < 4.1) etaBin = 9;
else etaBin = 13;
etaindex = etaBin;
}
Float_t AliPMDUtility::GetTheta() const
{
return fTheta;
}
Float_t AliPMDUtility::GetEta() const
{
return fEta;
}
Float_t AliPMDUtility::GetPhi() const
{
return fPhi;
}
Float_t AliPMDUtility::GetX() const
{
return fPx;
}
Float_t AliPMDUtility::GetY() const
{
return fPy;
}
Float_t AliPMDUtility::GetZ() const
{
return fPz;
}