00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00023
00024
00025
00026
00027 TRotMatrix::TRotMatrix()
00028 {
00029
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
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
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
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
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
00113
00114 if (gGeometry) gGeometry->GetListOfMatrices()->Remove(this);
00115 }
00116
00117
00118
00119 Double_t TRotMatrix::Determinant() const
00120 {
00121
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
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
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
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
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
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
00231
00232
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
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
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
00261
00262 } else {
00263 R__b.WriteClassBuffer(TRotMatrix::Class(),this);
00264 }
00265 }