1 /**********************************************/
3 /* FILE: AliGTransform.cxx */
4 /* PURPOSE: To define the relative positions */
7 /* COMPILER: CC for HP-UX 9.x and 10. */
8 /* AUTHOR: Joana && David */
9 /* DATE: May 28, 1999 */
10 /* ADDRESS: jesanto@cern.ch, dcollado@cern.ch */
12 /**********************************************/
21 #include "AliGTransform.h"
23 ClassImp(AliGTransform)
25 //----------------------------------------------------------------------
27 AliGTransform::AliGTransform()
29 /* Default Constructor */
43 //----------------------------------------------------------------------
45 //----------------------------------------------------------------------
47 AliGTransform::AliGTransform(AliGTransform *tra)
49 /* Copy Constructor */
51 fMatrix = tra->fMatrix;
58 //----------------------------------------------------------------------}
60 AliGTransform::AliGTransform(Text_t* name, Text_t* title) : TNamed(name,title)
64 //float matrix[16] = {1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.}
65 fMatrix = new TVector(0,15,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1., "END");
74 //----------------------------------------------------------------------
76 AliGTransform::AliGTransform(Text_t* name, Text_t* title, Text_t *expression): TNamed(name, title)
79 fExpression = expression;
81 //float matrix[16] = {1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.};
82 //fMatrix = new TArrayF(16,matrix);
83 fMatrix = new TVector(0,15,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,
86 BuildMatrix(fX,fY,fZ,fTheta,fPsi,fPhi);
90 //----------------------------------------------------------------------
92 AliGTransform::AliGTransform(Text_t* name,Text_t* title, Text_t *axis, Float_t angle) : TNamed(name, title)
98 if (!strcmp(axis,"X")) {
104 if (!strcmp(axis,"Y")) {
110 if (!strcmp(axis,"Z")) {
117 //cout << "fTheta" << fTheta << endl;
118 //cout << "fPsi" << fPsi << endl;
119 //cout << "fPhi" << fPhi << endl;
122 BuildMatrix(fX,fY,fZ,fTheta,fPsi,fPhi);
127 //----------------------------------------------------------------------
129 AliGTransform::AliGTransform( Text_t* name, Text_t* title, Float_t theta1,Float_t phi1,
132 Float_t theta3,Float_t phi3
133 ) : TNamed(name,title)
135 const Double_t degrad = 0.0174532925199432958;
136 float a1=0.,a2=0.,a3=0.,b1=0.,b2=0.,b3=0.,c1=0.,c2=0.,c3=0.;
141 a1 = TMath::Sin(theta1*degrad)*TMath::Cos(phi1*degrad);
142 a2 = TMath::Sin(theta1*degrad)*TMath::Sin(phi1*degrad);
143 a3 = TMath::Cos(theta1*degrad);
144 b1 = TMath::Sin(theta2*degrad)*TMath::Cos(phi2*degrad);
145 b2 = TMath::Sin(theta2*degrad)*TMath::Sin(phi2*degrad);
146 b3 = TMath::Cos(theta2*degrad);
147 c1 = TMath::Sin(theta3*degrad)*TMath::Cos(phi3*degrad);
148 c2 = TMath::Sin(theta3*degrad)*TMath::Sin(phi3*degrad);
149 c3 = TMath::Cos(theta3*degrad);
151 // fMatrix = new TVector(0,15,a1,a2,a3,0.,b1,b2,b3,0.,c1,c2,c3,0.,0.,0.,0.,1., "END");
152 fMatrix = new TVector(0,15,a1,b1,c1,0.,a2,b2,c2,0.,a3,b3,c3,0.,0.,0.,0.,1., "END");
154 //----------------------------------------------------------------------
155 AliGTransform::AliGTransform( Text_t* name, Text_t* title, Float_t a1,Float_t a2,Float_t a3,Float_t b1,Float_t b2,
156 Float_t b3,Float_t c1,Float_t c2,Float_t c3,Float_t Dx,Float_t
157 Dy,Float_t Dz) : TNamed(name,title)
161 fMatrix = new TVector(0,15,a1,a2,a3,Dx,b1,b2,b3,Dy,c1,c2,c3,Dz,0.,0.,0.,1., "END");
165 //----------------------------------------------------------------------
167 AliGTransform::~AliGTransform() {
169 if(fMatrix) delete fMatrix;
172 //----------------------------------------------------------------------
174 void AliGTransform::CheckExpression()
175 /*Extracts the transformation arguments from the expression given in the
179 TString* string = new TString(fExpression);
181 float Dx, Dy, Dz,theta, psi,phi;
184 if (strstr(*string, "+")) {
185 sscanf( *string, "TRA %f %f %f + ROT %f %f %f ", &Dx, &Dy, &Dz, &theta, &psi, &phi );
187 if( sscanf(*string, "TRA %f %f %f", &Dx, &Dy, &Dz ) == EOF )
188 printf( "Error! Must introduce 3 distances\n" );
190 if( sscanf(*string, "ROT %f %f %f", &theta, &psi, &phi ) == EOF )
191 printf( "Error! Must introduce 3 angles\n" );
201 if( strstr(*string,"TRA") ) {
202 sscanf( *string, "TRA %f %f %f", &Dx, &Dy, &Dz );
204 if( sscanf(*string, "TRA %f %f %f", &Dx, &Dy, &Dz ) == EOF )
205 printf( "Error! Must introduce 3 distances\n" );
213 if( strstr(*string,"ROT") ) {
214 sscanf( *string, "ROT %f %f %f", &theta, &psi, &phi );
216 if( sscanf(*string, "ROT %f %f %f", &theta, &psi, &phi ) == EOF )
217 printf( "Error! Must introduce 3 angles\n" );
230 //----------------------------------------------------------------------
232 void AliGTransform::BuildMatrix(Float_t Dx=0., Float_t Dy=0., Float_t Dz=0., Float_t
233 theta=0., Float_t psi=0.,Float_t phi=0. )
235 /* Builds the 4X4 matrix of a transformation */
238 float a1=0.,a2=0.,a3=0.,b1=0.,b2=0.,b3=0.,c1=0.,c2=0.,c3=0.;
240 const Double_t degrad = 0.0174532925199432958;
243 TMath::Cos(phi*degrad)*TMath::Cos(psi*degrad)*TMath::Cos(theta*degrad) -
244 TMath::Sin(phi*degrad)*TMath::Sin(theta*degrad);
246 TMath::Cos(phi*degrad)*TMath::Cos(psi*degrad)*TMath::Sin(theta*degrad) +
247 TMath::Sin(phi*degrad)*TMath::Cos(theta*degrad);
248 a3 = - TMath::Cos(phi*degrad)*TMath::Sin(psi*degrad);
249 b1 = - TMath::Sin(phi*degrad)*TMath::Cos(psi*degrad)*TMath::Cos(theta*degrad) -
250 TMath::Cos(phi*degrad)*TMath::Sin(theta*degrad);
251 b2 = - TMath::Sin(phi*degrad)*TMath::Cos(psi*degrad)*TMath::Sin(theta*degrad) +
252 TMath::Cos(phi*degrad)*TMath::Cos(theta*degrad);
253 b3 = TMath::Sin(phi*degrad)*TMath::Sin(psi*degrad);
254 c1 = TMath::Sin(psi*degrad)*TMath::Cos(theta*degrad);
255 c2 = TMath::Sin(psi*degrad)*TMath::Sin(theta*degrad);
256 c3 = TMath::Cos(psi*degrad);
260 TMath::Cos(psi*degrad)*TMath::Cos(phi*degrad);
262 TMath::Cos(psi*degrad)*TMath::Sin(phi*degrad);
263 a3 = - TMath::Sin(psi*degrad);
264 b1 = TMath::Sin(theta*degrad)*TMath::Sin(psi*degrad)*TMath::Cos(phi*degrad) -
265 TMath::Cos(theta*degrad)*TMath::Sin(phi*degrad);
266 b2 = TMath::Sin(theta*degrad)*TMath::Sin(psi*degrad)*TMath::Sin(phi*degrad) +
267 TMath::Cos(theta*degrad)*TMath::Cos(phi*degrad);
268 b3 = TMath::Sin(theta*degrad)*TMath::Cos(psi*degrad);
270 TMath::Cos(theta*degrad)*TMath::Sin(psi*degrad)*TMath::Cos(phi*degrad) +
271 TMath::Sin(theta*degrad)*TMath::Sin(phi*degrad);
273 TMath::Cos(theta*degrad)*TMath::Sin(psi*degrad)*TMath::Sin(phi*degrad) -
274 TMath::Sin(theta*degrad)*TMath::Cos(phi*degrad);
275 c3 = TMath::Cos(theta*degrad)*TMath::Sin(psi*degrad);
277 fMatrix = new TVector(0,15,a1,a2,a3,Dx,b1,b2,b3,Dy,c1,c2,c3,Dz,0.,0.,0.,1., "END");
281 //----------------------------------------------------------------------
285 void AliGTransform::CheckExpression( Text_t* expression )
288 float theta, phi, psi,Dx, Dy, Dz;
290 TString* string = new TString( expression );
293 if( strstr(*string,"ROT") ) {
294 sscanf( *string, "ROT%c", &axis );
298 sscanf( *string, "ROTA%f %f %f", &phi, &psi, &theta );
299 if( (!psi) || (!theta) || (!phi) )
300 printf("Error! Must introduce 3 angles\n");
304 sscanf( *string, "ROTX%f", &theta );
306 printf("Error! Must introduce 1 angle\n");
310 sscanf( *string, "ROTY%f", &theta);
312 printf("Error! Must introduce 1 angle\n");
316 sscanf( *string, "ROTZ%f", &theta );
318 printf("Error! Must introduce 1 angle\n");
322 printf("Unrecognised rotation around axis %c\n",axis);
326 if( strstr(*string, "TRA") ) {
327 sscanf( *string, "TRA %f %f %f", &Dx, &Dy, &Dz );
328 if( sscanf(*string, "TRA %f %f %f", &Dx, &Dy, &Dz) == EOF )
329 printf("Error! Must introduce 3 distances\n");
330 printf( "%f%f%f\n", Dx, Dy, Dz );
333 printf( "ERROR!\n" );