#include <math.h>
#include "TFourVectorReal.h"
#include "TFourVectorComplex.h"
#include "TThreeRotation.h"
#include <iostream>
using namespace std;
ClassImp(TThreeRotation)
TThreeVectorReal TThreeRotation::Axis() const
{
Double_t angle(0);
TThreeVectorReal axis;
GetAxis(axis,angle);
return (axis *= angle);
}
void TThreeRotation::GetAxis(TUnitVector &ahat, Double_t &angle) const
{
Double_t traceM = fMatrix[1][1] + fMatrix[2][2] + fMatrix[3][3];
ahat.fVector[1] = fMatrix[2][3] - fMatrix[3][2];
ahat.fVector[2] = fMatrix[3][1] - fMatrix[1][3];
ahat.fVector[3] = fMatrix[1][2] - fMatrix[2][1];
angle = atan2(ahat.Length(),traceM-1);
ahat.Normalize(1);
}
void TThreeRotation::GetEuler
(Double_t &phi, Double_t &theta, Double_t &psi) const
{
TThreeVectorReal v(fMatrix[3][1], fMatrix[3][2], fMatrix[3][3]);
phi = atan2(v.fVector[2],v.fVector[1]);
theta = atan2(v.Rho(),v.fVector[3]);
psi = atan2(fMatrix[2][3],-fMatrix[1][3]);
Double_t cosPhi = cos(phi);
Double_t cosTheta = cos(theta);
Double_t cosPsi = cos(psi);
Double_t sinPhi = sin(phi);
Double_t sinPsi = sin(psi);
Double_t m11 = cosPhi*cosTheta*cosPsi - sinPhi*sinPsi;
Double_t dif = abs(m11 - fMatrix[1][1]);
if (dif > Resolution()) {
Double_t sumPhiPsi = atan2(-fMatrix[2][1],fMatrix[1][1]);
psi = sumPhiPsi - phi;
psi += (psi > -M_PI) ? 0 : 2*M_PI;
psi -= (psi <= M_PI) ? 0 : 2*M_PI;
}
}
TThreeRotation &TThreeRotation::operator=(const TThreeRotation &source)
{
*(TLorentzTransform *)this = (TLorentzTransform)source;
return *this;
}
TThreeRotation &TThreeRotation::operator*=(const TThreeRotation &source)
{
TThreeRotation temp(*this);
for (Int_t i=1; i<4; i++) {
for (Int_t j=1; j<4; j++) {
Double_t sum=0;
for (Int_t k=1; k<4; k++) {
sum += temp.fMatrix[i][k]*source.fMatrix[k][j];
}
fMatrix[i][j] = sum;
}
}
fMatrix[0][0] = 1;
fMatrix[0][1] = fMatrix[1][0] = 0;
fMatrix[0][2] = fMatrix[2][0] = 0;
fMatrix[0][3] = fMatrix[3][0] = 0;
return *this;
}
TThreeRotation &TThreeRotation::Null()
{
TLorentzTransform::Null();
return *this;
}
TThreeRotation &TThreeRotation::Transpose()
{
TLorentzTransform::Transpose();
return *this;
}
TThreeRotation &TThreeRotation::Invert()
{
TLorentzTransform::Invert();
return *this;
}
TThreeRotation &TThreeRotation::SetAxis(const TThreeVectorReal &axis)
{
return SetAxis(axis,axis.Length());
}
TThreeRotation &TThreeRotation::SetAxis(const TUnitVector &ahat,
const Double_t angle)
{
TUnitVector axis(ahat);
axis.Normalize(1);
Double_t c0 = cos(angle);
Double_t c1 = -sin(angle);
Double_t c2 = 1-c0;
fMatrix[0][0] = 1;
fMatrix[0][1] = fMatrix[1][0] = 0;
fMatrix[0][2] = fMatrix[2][0] = 0;
fMatrix[0][3] = fMatrix[3][0] = 0;
fMatrix[1][1] = c0 + c2*axis.fVector[1]*axis.fVector[1];
fMatrix[2][2] = c0 + c2*axis.fVector[2]*axis.fVector[2];
fMatrix[3][3] = c0 + c2*axis.fVector[3]*axis.fVector[3];
fMatrix[1][2] = -c1*axis.fVector[3]
+ c2*axis.fVector[1]*axis.fVector[2];
fMatrix[1][3] = c1*axis.fVector[2]
+ c2*axis.fVector[1]*axis.fVector[3];
fMatrix[2][1] = c1*axis.fVector[3]
+ c2*axis.fVector[1]*axis.fVector[2];
fMatrix[2][3] = -c1*axis.fVector[1]
+ c2*axis.fVector[2]*axis.fVector[3];
fMatrix[3][1] = -c1*axis.fVector[2]
+ c2*axis.fVector[1]*axis.fVector[3];
fMatrix[3][2] = c1*axis.fVector[1]
+ c2*axis.fVector[2]*axis.fVector[3];
return *this;
}
TThreeRotation &TThreeRotation::SetEuler(const Double_t &phi,
const Double_t &theta,
const Double_t &psi)
{
Double_t cosPhi = cos(phi);
Double_t cosTheta = cos(theta);
Double_t cosPsi = cos(psi);
Double_t sinPhi = sin(phi);
Double_t sinTheta = sin(theta);
Double_t sinPsi = sin(psi);
fMatrix[0][0] = 1;
fMatrix[0][1] = fMatrix[1][0] = 0;
fMatrix[0][2] = fMatrix[2][0] = 0;
fMatrix[0][3] = fMatrix[3][0] = 0;
fMatrix[1][1] = cosPhi*cosTheta*cosPsi - sinPhi*sinPsi;
fMatrix[1][2] = sinPhi*cosTheta*cosPsi + cosPhi*sinPsi;
fMatrix[1][3] = -sinTheta*cosPsi;
fMatrix[2][1] = -cosPhi*cosTheta*sinPsi - sinPhi*cosPsi;
fMatrix[2][2] = -sinPhi*cosTheta*sinPsi + cosPhi*cosPsi;
fMatrix[2][3] = sinTheta*sinPsi;
fMatrix[3][1] = cosPhi*sinTheta;
fMatrix[3][2] = sinPhi*sinTheta;
fMatrix[3][3] = cosTheta;
return *this;
}
TThreeVectorReal TThreeRotation::operator*(const TThreeVectorReal &vec) const
{
TThreeVectorReal result;
for (Int_t i=1; i<4; i++) {
Double_t sum=0;
for (Int_t j=1; j<4; j++) {
sum += fMatrix[i][j]*vec.fVector[j];
}
result.fVector[i] = sum;
}
return result;
}
TThreeVectorComplex TThreeRotation::operator*
(const TThreeVectorComplex &vec) const
{
TThreeVectorComplex result;
for (Int_t i=1; i<4; i++) {
Complex_t sum=0;
for (Int_t j=1; j<4; j++) {
sum += fMatrix[i][j]*vec.fVector[j];
}
result.fVector[i] = sum;
}
return result;
}
TThreeRotation TThreeRotation::operator*(const TThreeRotation &rotOp) const
{
TThreeRotation result;
for (Int_t i=1; i<4; i++) {
for (Int_t j=1; j<4; j++) {
Double_t sum=0;
for (Int_t k=1; k<4; k++) {
sum += fMatrix[i][k]*rotOp.fMatrix[k][j];
}
result.fMatrix[i][j] = sum;
}
}
result.fMatrix[0][0] = 1;
result.fMatrix[0][1] = result.fMatrix[1][0] = 0;
result.fMatrix[0][2] = result.fMatrix[2][0] = 0;
result.fMatrix[0][3] = result.fMatrix[3][0] = 0;
return result;
}
void TThreeRotation::Print(Option_t *option)
{
cout << "TThreeRotation matrix" << endl;
cout << "(" << fMatrix[1][1] << ","
<< fMatrix[1][2] << "," << fMatrix[1][3] << ")" << endl;
cout << "(" << fMatrix[2][1] << ","
<< fMatrix[2][2] << "," << fMatrix[2][3] << ")" << endl;
cout << "(" << fMatrix[3][1] << ","
<< fMatrix[3][2] << "," << fMatrix[3][3] << ")" << endl;
}
#ifdef R__HPUX
#endif
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.