1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
20 /**********************************************/
22 /* FILE: AliGTransform.cxx */
23 /* PURPOSE: To define the relative positions */
26 /* COMPILER: CC for HP-UX 9.x and 10. */
27 /* AUTHOR: Joana && David */
28 /* DATE: May 28, 1999 */
29 /* ADDRESS: jesanto@cern.ch, dcollado@cern.ch */
31 /**********************************************/
40 #include "AliGTransform.h"
42 ClassImp(AliGTransform)
44 //----------------------------------------------------------------------
46 AliGTransform::AliGTransform()
48 /* Default Constructor */
62 //----------------------------------------------------------------------
64 //----------------------------------------------------------------------
66 AliGTransform::AliGTransform(AliGTransform *tra)
68 /* Copy Constructor */
70 fMatrix = tra->fMatrix;
77 //----------------------------------------------------------------------}
79 AliGTransform::AliGTransform(Text_t* name, Text_t* title) : TNamed(name,title)
83 //float matrix[16] = {1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.}
84 fMatrix = new TVector(0,15,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1., "END");
93 //----------------------------------------------------------------------
95 AliGTransform::AliGTransform(Text_t* name, Text_t* title, Text_t *expression): TNamed(name, title)
98 fExpression = expression;
100 //float matrix[16] = {1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.};
101 //fMatrix = new TArrayF(16,matrix);
102 fMatrix = new TVector(0,15,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,
105 BuildMatrix(fX,fY,fZ,fTheta,fPsi,fPhi);
109 //----------------------------------------------------------------------
111 AliGTransform::AliGTransform(Text_t* name,Text_t* title, Text_t *axis, Float_t angle) : TNamed(name, title)
117 if (!strcmp(axis,"X")) {
123 if (!strcmp(axis,"Y")) {
129 if (!strcmp(axis,"Z")) {
136 //cout << "fTheta" << fTheta << endl;
137 //cout << "fPsi" << fPsi << endl;
138 //cout << "fPhi" << fPhi << endl;
141 BuildMatrix(fX,fY,fZ,fTheta,fPsi,fPhi);
146 //----------------------------------------------------------------------
148 AliGTransform::AliGTransform( Text_t* name, Text_t* title, Float_t theta1,Float_t phi1,
151 Float_t theta3,Float_t phi3
152 ) : TNamed(name,title)
154 const Double_t degrad = 0.0174532925199432958;
155 float a1=0.,a2=0.,a3=0.,b1=0.,b2=0.,b3=0.,c1=0.,c2=0.,c3=0.;
160 a1 = TMath::Sin(theta1*degrad)*TMath::Cos(phi1*degrad);
161 a2 = TMath::Sin(theta1*degrad)*TMath::Sin(phi1*degrad);
162 a3 = TMath::Cos(theta1*degrad);
163 b1 = TMath::Sin(theta2*degrad)*TMath::Cos(phi2*degrad);
164 b2 = TMath::Sin(theta2*degrad)*TMath::Sin(phi2*degrad);
165 b3 = TMath::Cos(theta2*degrad);
166 c1 = TMath::Sin(theta3*degrad)*TMath::Cos(phi3*degrad);
167 c2 = TMath::Sin(theta3*degrad)*TMath::Sin(phi3*degrad);
168 c3 = TMath::Cos(theta3*degrad);
170 // fMatrix = new TVector(0,15,a1,a2,a3,0.,b1,b2,b3,0.,c1,c2,c3,0.,0.,0.,0.,1., "END");
171 fMatrix = new TVector(0,15,a1,b1,c1,0.,a2,b2,c2,0.,a3,b3,c3,0.,0.,0.,0.,1., "END");
173 //----------------------------------------------------------------------
174 AliGTransform::AliGTransform( Text_t* name, Text_t* title, Float_t a1,Float_t a2,Float_t a3,Float_t b1,Float_t b2,
175 Float_t b3,Float_t c1,Float_t c2,Float_t c3,Float_t Dx,Float_t
176 Dy,Float_t Dz) : TNamed(name,title)
180 fMatrix = new TVector(0,15,a1,a2,a3,Dx,b1,b2,b3,Dy,c1,c2,c3,Dz,0.,0.,0.,1., "END");
184 //----------------------------------------------------------------------
186 AliGTransform::~AliGTransform() {
188 if(fMatrix) delete fMatrix;
191 //----------------------------------------------------------------------
193 void AliGTransform::CheckExpression()
194 /*Extracts the transformation arguments from the expression given in the
198 TString* string = new TString(fExpression);
200 float Dx, Dy, Dz,theta, psi,phi;
203 if (strstr(*string, "+")) {
204 sscanf( *string, "TRA %f %f %f + ROT %f %f %f ", &Dx, &Dy, &Dz, &theta, &psi, &phi );
206 if( sscanf(*string, "TRA %f %f %f", &Dx, &Dy, &Dz ) == EOF )
207 printf( "Error! Must introduce 3 distances\n" );
209 if( sscanf(*string, "ROT %f %f %f", &theta, &psi, &phi ) == EOF )
210 printf( "Error! Must introduce 3 angles\n" );
220 if( strstr(*string,"TRA") ) {
221 sscanf( *string, "TRA %f %f %f", &Dx, &Dy, &Dz );
223 if( sscanf(*string, "TRA %f %f %f", &Dx, &Dy, &Dz ) == EOF )
224 printf( "Error! Must introduce 3 distances\n" );
232 if( strstr(*string,"ROT") ) {
233 sscanf( *string, "ROT %f %f %f", &theta, &psi, &phi );
235 if( sscanf(*string, "ROT %f %f %f", &theta, &psi, &phi ) == EOF )
236 printf( "Error! Must introduce 3 angles\n" );
249 //----------------------------------------------------------------------
251 void AliGTransform::BuildMatrix(Float_t Dx=0., Float_t Dy=0., Float_t Dz=0., Float_t
252 theta=0., Float_t psi=0.,Float_t phi=0. )
254 /* Builds the 4X4 matrix of a transformation */
257 float a1=0.,a2=0.,a3=0.,b1=0.,b2=0.,b3=0.,c1=0.,c2=0.,c3=0.;
259 const Double_t degrad = 0.0174532925199432958;
262 TMath::Cos(phi*degrad)*TMath::Cos(psi*degrad)*TMath::Cos(theta*degrad) -
263 TMath::Sin(phi*degrad)*TMath::Sin(theta*degrad);
265 TMath::Cos(phi*degrad)*TMath::Cos(psi*degrad)*TMath::Sin(theta*degrad) +
266 TMath::Sin(phi*degrad)*TMath::Cos(theta*degrad);
267 a3 = - TMath::Cos(phi*degrad)*TMath::Sin(psi*degrad);
268 b1 = - TMath::Sin(phi*degrad)*TMath::Cos(psi*degrad)*TMath::Cos(theta*degrad) -
269 TMath::Cos(phi*degrad)*TMath::Sin(theta*degrad);
270 b2 = - TMath::Sin(phi*degrad)*TMath::Cos(psi*degrad)*TMath::Sin(theta*degrad) +
271 TMath::Cos(phi*degrad)*TMath::Cos(theta*degrad);
272 b3 = TMath::Sin(phi*degrad)*TMath::Sin(psi*degrad);
273 c1 = TMath::Sin(psi*degrad)*TMath::Cos(theta*degrad);
274 c2 = TMath::Sin(psi*degrad)*TMath::Sin(theta*degrad);
275 c3 = TMath::Cos(psi*degrad);
279 TMath::Cos(psi*degrad)*TMath::Cos(phi*degrad);
281 TMath::Cos(psi*degrad)*TMath::Sin(phi*degrad);
282 a3 = - TMath::Sin(psi*degrad);
283 b1 = TMath::Sin(theta*degrad)*TMath::Sin(psi*degrad)*TMath::Cos(phi*degrad) -
284 TMath::Cos(theta*degrad)*TMath::Sin(phi*degrad);
285 b2 = TMath::Sin(theta*degrad)*TMath::Sin(psi*degrad)*TMath::Sin(phi*degrad) +
286 TMath::Cos(theta*degrad)*TMath::Cos(phi*degrad);
287 b3 = TMath::Sin(theta*degrad)*TMath::Cos(psi*degrad);
289 TMath::Cos(theta*degrad)*TMath::Sin(psi*degrad)*TMath::Cos(phi*degrad) +
290 TMath::Sin(theta*degrad)*TMath::Sin(phi*degrad);
292 TMath::Cos(theta*degrad)*TMath::Sin(psi*degrad)*TMath::Sin(phi*degrad) -
293 TMath::Sin(theta*degrad)*TMath::Cos(phi*degrad);
294 c3 = TMath::Cos(theta*degrad)*TMath::Sin(psi*degrad);
296 fMatrix = new TVector(0,15,a1,a2,a3,Dx,b1,b2,b3,Dy,c1,c2,c3,Dz,0.,0.,0.,1., "END");
300 //----------------------------------------------------------------------
304 void AliGTransform::CheckExpression( Text_t* expression )
307 float theta, phi, psi,Dx, Dy, Dz;
309 TString* string = new TString( expression );
312 if( strstr(*string,"ROT") ) {
313 sscanf( *string, "ROT%c", &axis );
317 sscanf( *string, "ROTA%f %f %f", &phi, &psi, &theta );
318 if( (!psi) || (!theta) || (!phi) )
319 printf("Error! Must introduce 3 angles\n");
323 sscanf( *string, "ROTX%f", &theta );
325 printf("Error! Must introduce 1 angle\n");
329 sscanf( *string, "ROTY%f", &theta);
331 printf("Error! Must introduce 1 angle\n");
335 sscanf( *string, "ROTZ%f", &theta );
337 printf("Error! Must introduce 1 angle\n");
341 printf("Unrecognised rotation around axis %c\n",axis);
345 if( strstr(*string, "TRA") ) {
346 sscanf( *string, "TRA %f %f %f", &Dx, &Dy, &Dz );
347 if( sscanf(*string, "TRA %f %f %f", &Dx, &Dy, &Dz) == EOF )
348 printf("Error! Must introduce 3 distances\n");
349 printf( "%f%f%f\n", Dx, Dy, Dz );
352 printf( "ERROR!\n" );