TRotMatrix.cxx

Go to the documentation of this file.
00001 // @(#)root/g3d:$Id: TRotMatrix.cxx 31808 2009-12-10 15:20:21Z couet $
00002 // Author: Rene Brun   14/09/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TGeometry.h"
00013 #include "TRotMatrix.h"
00014 #include "TClass.h"
00015 #include "TMath.h"
00016 
00017 ClassImp(TRotMatrix)
00018 
00019 
00020 //______________________________________________________________________________
00021 //
00022 // Manages a detector rotation matrix. See class TGeometry.
00023 //
00024 
00025 
00026 //______________________________________________________________________________
00027 TRotMatrix::TRotMatrix()
00028 {
00029    // RotMatrix default constructor.
00030 
00031    for (int i=0;i<9;i++) fMatrix[i] = 0;
00032    fNumber = 0;
00033    fPhi    = 0;
00034    fPsi    = 0;
00035    fTheta  = 0;
00036    fType   = 0;
00037 }
00038 
00039 
00040 //______________________________________________________________________________
00041 TRotMatrix::TRotMatrix(const char *name, const char *title, Double_t *matrix)
00042            :TNamed(name,title)
00043 {
00044    // RotMatrix normal constructor.
00045 
00046    if (!matrix) { Error("ctor","No rotation is supplied"); return; }
00047 
00048    SetMatrix(matrix);
00049    if (!gGeometry) gGeometry = new TGeometry();
00050    fNumber = gGeometry->GetListOfMatrices()->GetSize();
00051    gGeometry->GetListOfMatrices()->Add(this);
00052 }
00053 
00054 
00055 //______________________________________________________________________________
00056 TRotMatrix::TRotMatrix(const char *name, const char *title, Double_t theta, Double_t phi, Double_t psi)
00057            :TNamed(name,title)
00058 {
00059    // RotMatrix normal constructor.
00060 
00061    printf("ERROR: This form of TRotMatrix constructor not implemented yet\n");
00062 
00063    Int_t i;
00064    fTheta  = theta;
00065    fPhi    = phi;
00066    fPsi    = psi;
00067    fType   = 2;
00068    for (i=0;i<9;i++) fMatrix[i] = 0;
00069    fMatrix[0] = 1;   fMatrix[4] = 1;   fMatrix[8] = 1;
00070 
00071    if (!gGeometry) gGeometry = new TGeometry();
00072    fNumber = gGeometry->GetListOfMatrices()->GetSize();
00073    gGeometry->GetListOfMatrices()->Add(this);
00074 }
00075 
00076 
00077 //______________________________________________________________________________
00078 TRotMatrix::TRotMatrix(const char *name, const char *title, Double_t theta1, Double_t phi1
00079                                                   , Double_t theta2, Double_t phi2
00080                                                   , Double_t theta3, Double_t phi3)
00081                 :TNamed(name,title)
00082 {
00083    // RotMatrix normal constructor defined a la GEANT.
00084    //
00085    // The TRotMatrix constructor with six angles uses the GEANT convention:
00086    //
00087    // theta1 is the polar angle of the x-prim axis in the main reference system
00088    // (MRS), theta2 and theta3 have the same meaning for the y-prim and z-prim
00089    // axis.
00090    //
00091    // Phi1 is the azimuthal angle of the x-prim in the MRS and phi2 and phi3
00092    // have the same meaning for y-prim and z-prim.
00093    //
00094    //
00095    // for example, the unit matrix is defined in the following way.
00096    //
00097    //     x-prim || x, y-prim || y, z-prim || z
00098    //
00099    //     means:  theta1=90, theta2=90, theta3=0, phi1=0, phi2=90, phi3=0
00100 
00101    SetAngles(theta1,phi1,theta2,phi2,theta3,phi3);
00102 
00103    if (!gGeometry) gGeometry = new TGeometry();
00104    fNumber = gGeometry->GetListOfMatrices()->GetSize();
00105    gGeometry->GetListOfMatrices()->Add(this);
00106 }
00107 
00108 
00109 //______________________________________________________________________________
00110 TRotMatrix::~TRotMatrix()
00111 {
00112    // RotMatrix default destructor.
00113 
00114    if (gGeometry) gGeometry->GetListOfMatrices()->Remove(this);
00115 }
00116 
00117 
00118 //______________________________________________________________________________
00119 Double_t  TRotMatrix::Determinant() const
00120 {
00121    // Determinant() returns the value of the determiant of this matrix
00122 
00123    return
00124       fMatrix[0] * (fMatrix[4]*fMatrix[8] - fMatrix[7]*fMatrix[5])
00125     - fMatrix[3] * (fMatrix[1]*fMatrix[8] - fMatrix[7]*fMatrix[2])
00126     + fMatrix[6] * (fMatrix[1]*fMatrix[5] - fMatrix[4]*fMatrix[2]);
00127 }
00128 
00129 
00130 //______________________________________________________________________________
00131 Double_t* TRotMatrix::GetGLMatrix(Double_t *rGLMatrix) const
00132 {
00133    //  Convert this matrix to the OpenGL [4x4]
00134    //
00135    //  [  fMatrix[0]   fMatrix[1]   fMatrix[2]    0  ]
00136    //  [  fMatrix[3]   fMatrix[4]   fMatrix[5]    0  ]
00137    //  [  fMatrix[6]   fMatrix[7]   fMatrix[8]    0  ]
00138    //  [     0             0           0          1  ]
00139    //
00140    //  Input:
00141    //  -----
00142    //  Double_t *rGLMatrix - pointer to Double_t 4x4 buffer array
00143    //
00144    //  Return:
00145    //  ------
00146    //  Double_t pointer to the input buffer
00147 
00148    Double_t *glmatrix = rGLMatrix;
00149    const Double_t *matrix   = fMatrix;
00150    if (rGLMatrix)
00151    {
00152       for (Int_t i=0;i<3;i++) {
00153          for (Int_t j=0;j<3;j++) memcpy(glmatrix,matrix,3*sizeof(Double_t));
00154          matrix   += 3;
00155          glmatrix += 3;
00156          *glmatrix = 0.0;
00157          glmatrix++;
00158       }
00159       for (Int_t j=0;j<3;j++) {
00160          *glmatrix = 0.0;
00161          glmatrix++;
00162       }
00163       *glmatrix = 1.0;
00164    }
00165    return rGLMatrix;
00166 }
00167 
00168 
00169 //______________________________________________________________________________
00170 const Double_t* TRotMatrix::SetAngles(Double_t theta1, Double_t phi1,
00171                 Double_t theta2, Double_t phi2,Double_t theta3, Double_t phi3)
00172 {
00173    // theta1 is the polar angle of the x-prim axis in the main reference system
00174    // (MRS), theta2 and theta3 have the same meaning for the y-prim and z-prim
00175    // axis.
00176    //
00177    // Phi1 is the azimuthal angle of the x-prim in the MRS and phi2 and phi3
00178    // have the same meaning for y-prim and z-prim.
00179    //
00180    //
00181    // for example, the unit matrix is defined in the following way.
00182    //
00183    //     x-prim || x, y-prim || y, z-prim || z
00184    //
00185    //     means:  theta1=90, theta2=90, theta3=0, phi1=0, phi2=90, phi3=0
00186 
00187    const Double_t degrad = 0.0174532925199432958;
00188 
00189    fTheta  = theta1;
00190    fPhi    = phi1;
00191    fPsi    = theta2;
00192 
00193    fType   = 2;
00194    if (!strcmp(GetName(),"Identity")) fType = 0;
00195 
00196    fMatrix[0] = TMath::Sin(theta1*degrad)*TMath::Cos(phi1*degrad);
00197    fMatrix[1] = TMath::Sin(theta1*degrad)*TMath::Sin(phi1*degrad);
00198    fMatrix[2] = TMath::Cos(theta1*degrad);
00199    fMatrix[3] = TMath::Sin(theta2*degrad)*TMath::Cos(phi2*degrad);
00200    fMatrix[4] = TMath::Sin(theta2*degrad)*TMath::Sin(phi2*degrad);
00201    fMatrix[5] = TMath::Cos(theta2*degrad);
00202    fMatrix[6] = TMath::Sin(theta3*degrad)*TMath::Cos(phi3*degrad);
00203    fMatrix[7] = TMath::Sin(theta3*degrad)*TMath::Sin(phi3*degrad);
00204    fMatrix[8] = TMath::Cos(theta3*degrad);
00205 
00206    SetReflection();
00207    return fMatrix;
00208 }
00209 
00210 
00211 //______________________________________________________________________________
00212 void TRotMatrix::SetMatrix(const Double_t *matrix)
00213 {
00214    // copy predefined 3x3 matrix into TRotMatrix object
00215 
00216    fTheta  = 0;
00217    fPhi    = 0;
00218    fPsi    = 0;
00219    fType   = 0;
00220    if (!matrix) return;
00221    fType   = 2;
00222    memcpy(fMatrix,matrix,9*sizeof(Double_t));
00223    SetReflection();
00224 }
00225 
00226 
00227 //______________________________________________________________________________
00228 void TRotMatrix::SetReflection()
00229 {
00230    // SetReflection() -  checks whether the determinant of this
00231    //                    matrix defines the reflection transformation
00232    //                    and set the "reflection" flag if any
00233 
00234    ResetBit(kReflection);
00235    if (Determinant() < 0) { fType=1; SetBit(kReflection);}
00236 }
00237 
00238 
00239 //______________________________________________________________________________
00240 void TRotMatrix::Streamer(TBuffer &R__b)
00241 {
00242    // Stream an object of class TRotMatrix.
00243 
00244    if (R__b.IsReading()) {
00245       UInt_t R__s, R__c;
00246       Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00247       if (R__v > 1) {
00248          R__b.ReadClassBuffer(TRotMatrix::Class(), this, R__v, R__s, R__c);
00249          return;
00250       }
00251       //====process old versions before automatic schema evolution
00252       TNamed::Streamer(R__b);
00253       R__b >> fNumber;
00254       R__b >> fType;
00255       R__b >> fTheta;
00256       R__b >> fPhi;
00257       R__b >> fPsi;
00258       R__b.ReadStaticArray(fMatrix);
00259       R__b.CheckByteCount(R__s, R__c, TRotMatrix::IsA());
00260       //====end of old versions
00261       
00262    } else {
00263       R__b.WriteClassBuffer(TRotMatrix::Class(),this);
00264    }
00265 }

Generated on Tue Jul 5 14:16:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1