BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//____________________________________________________________________
//  
//  Coordinate system class for Brat Geometry. A coordinate system is
//  defined by it's origin and a transformation matrix. The definition
//  of the matrix is such that 
//  Vector(MasterSystem) = Rotmatrix*Vector(Local System)+Translation
//  Vector(LocalSystem)  = InverseRotMatrix*[vector(msater)-translation];
//  Both the rotmatrix and the inverse is stored internally for fast access.


//____________________________________________________________________
//
// $Id: BrCoordinateSystem.cxx,v 1.2 2002/02/26 08:58:43 cholm Exp $
// $Author: cholm $
// $Date: 2002/02/26 08:58:43 $
// $Copyright: (C) 2002 BRAHMS Collaboration <brahmlib@rhic.bnl.gov>
//
#ifndef BRAT_BrCoordinateSystem
#include "BrCoordinateSystem.h"
#endif
#include <iostream.h>
#include <math.h>

//____________________________________________________________________
ClassImp(BrCoordinateSystem);

//_____________________________________________________________________________
 BrCoordinateSystem::BrCoordinateSystem()
{
  // default constrcutor. Do not use normally. The master system
  // is generated. Used by Root i/o (probably). 
}

//_____________________________________________________________________________
 BrCoordinateSystem::BrCoordinateSystem(const BrVector3D& vector, const BrRotMatrix& rotmatrix){
  // Normal constructor.
  // The vector defines the origin, and the rotation matrix the transformation between
  // systems.
  //
  fOrigin = vector;
  fRotMatrix = rotmatrix;
  SetInverseMatrix();
}

//_____________________________________________________________________________
 BrVector3D BrCoordinateSystem::RotateToMaster(const BrVector3D&
					      vector) const {
//
// Get the vector in the Master System.
//
  BrVector3D tmp;
  Double_t const* RotMatrix;
  RotMatrix = fRotMatrix.GetMatrix();
  tmp[0] = RotMatrix[0]*vector[0]+RotMatrix[3]*vector[1]+RotMatrix[6]*vector[2]; 
  tmp[1] = RotMatrix[1]*vector[0]+RotMatrix[4]*vector[1]+RotMatrix[7]*vector[2]; 
  tmp[2] = RotMatrix[2]*vector[0]+RotMatrix[5]*vector[1]+RotMatrix[8]*vector[2]; 
return tmp;
}
//_____________________________________________________________________________
 BrVector3D BrCoordinateSystem::RotateFromMaster(const BrVector3D&
						vector) const{
  BrVector3D tmp;
  const Double_t* InverseRotMatrix = fInverseRotMatrix.GetMatrix();
  tmp[0] = InverseRotMatrix[0]*vector[0]+InverseRotMatrix[3]*vector[1]+InverseRotMatrix[6]*vector[2]; 
  tmp[1] = InverseRotMatrix[1]*vector[0]+InverseRotMatrix[4]*vector[1]+InverseRotMatrix[7]*vector[2]; 
  tmp[2] = InverseRotMatrix[2]*vector[0]+InverseRotMatrix[5]*vector[1]+InverseRotMatrix[8]*vector[2];
return tmp;
}

//_____________________________________________________________________________
 BrVector3D BrCoordinateSystem::TransformToMaster(const BrVector3D&
						 vector) const{
//
// Consider the Vector as representing a point that is transformed to the
// Master system.
//
  BrVector3D local;  
  const Double_t* RotMatrix;
  RotMatrix = fRotMatrix.GetMatrix();
  local[0] = RotMatrix[0]*vector[0]+RotMatrix[3]*vector[1]+RotMatrix[6]*vector[2]; 
  local[1] = RotMatrix[1]*vector[0]+RotMatrix[4]*vector[1]+RotMatrix[7]*vector[2]; 
  local[2] = RotMatrix[2]*vector[0]+RotMatrix[5]*vector[1]+RotMatrix[8]*vector[2];
  local += fOrigin;
return local;
}
//_____________________________________________________________________________
 BrVector3D BrCoordinateSystem::TransformFromMaster(const BrVector3D&
						   master) const {
  BrVector3D vector(master);
  BrVector3D local;
  vector  -= fOrigin;
  const Double_t* InverseRotMatrix = fInverseRotMatrix.GetMatrix();
  local[0] = InverseRotMatrix[0]*vector[0]+InverseRotMatrix[3]*vector[1]+InverseRotMatrix[6]*vector[2]; 
  local[1] = InverseRotMatrix[1]*vector[0]+InverseRotMatrix[4]*vector[1]+InverseRotMatrix[7]*vector[2]; 
  local[2] = InverseRotMatrix[2]*vector[0]+InverseRotMatrix[5]*vector[1]+InverseRotMatrix[8]*vector[2];
return local;
}
//_____________________________________________________________________________
 void BrCoordinateSystem::SetInverseMatrix(){
//
// private member function to check and set inverse matrix
//

//#define TESTCODE
  const Double_t* RotMatrix;
  RotMatrix = fRotMatrix.GetMatrix();
  Double_t *InverseRotMatrix = fInverseRotMatrix.GetMatrix();
  
  InverseRotMatrix[0]= (RotMatrix[4] * RotMatrix[8] 
			- RotMatrix[5] * RotMatrix[7]);
  InverseRotMatrix[3]= -1. * (RotMatrix[3] * RotMatrix[8] 
			      - RotMatrix[5] * RotMatrix[6]);
  InverseRotMatrix[6]= (RotMatrix[3] * RotMatrix[7] 
			- RotMatrix[6] * RotMatrix[4]);
  InverseRotMatrix[1]= -1. * (RotMatrix[1] * RotMatrix[8]
			      - RotMatrix[2] * RotMatrix[7]);
  InverseRotMatrix[4]= (RotMatrix[0] * RotMatrix[8] 
			- RotMatrix[2] * RotMatrix[6]);
  InverseRotMatrix[7]= -1. * (RotMatrix[0] * RotMatrix[7] 
			      - RotMatrix[1] * RotMatrix[6]);
  InverseRotMatrix[2]= (RotMatrix[1] * RotMatrix[5] - 
			RotMatrix[4] * RotMatrix[2]);
  InverseRotMatrix[5]= -1. * (RotMatrix[0] * RotMatrix[5]
			      - RotMatrix[3] * RotMatrix[2]);
  InverseRotMatrix[8]= (RotMatrix[0] * RotMatrix[4] 
			- RotMatrix[3] * RotMatrix[1]);

#ifdef TESTCODE
  cout << " Inverse matrix, determinant method: " << endl;
  for (Int_t i=0; i<3; i++){
    cout << " Unit vector: " << i << "( ";
    for (Int_t j=0; j<3; j++){
      Int_t index = i*3+j;
      cout << InverseRotMatrix[index] << " ";
    }
    cout << ")" << endl;
  }
#endif

  /*
  InverseRotMatrix[0]=RotMatrix[0];
  InverseRotMatrix[1]=RotMatrix[3];
  InverseRotMatrix[2]=RotMatrix[6];
  InverseRotMatrix[3]=RotMatrix[1];
  InverseRotMatrix[4]=RotMatrix[4];
  InverseRotMatrix[5]=RotMatrix[7];
  InverseRotMatrix[6]=RotMatrix[2];
  InverseRotMatrix[7]=RotMatrix[5];
  InverseRotMatrix[8]=RotMatrix[8];
  */

#ifdef TESTCODE
  {
  cout << " Inverse matrix, transpose method: " << endl;
  for (Int_t i=0; i<3; i++){
    cout << " Unit vector: " << i << "( ";
    for (Int_t j=0; j<3; j++){
      Int_t index = i*3+j;
      cout << InverseRotMatrix[index] << " ";
    }
    cout << ")" << endl;
  }
  }
#endif

#ifdef TESTCODE
  //
  // Used only for development of code. Is ok!
  for(int j=0; j<3; j++){
    for(int k=0;k<3;k++){
     double sum=0.0;
     for(int i=0; i<3 ;i++){
       sum += ( RotMatrix[i*3+j] ) * (InverseRotMatrix[k*3+i]) ;
     }
     cout <<"Sigma("<< j <<","<< k << ") = " << sum << endl;
    }
  }
#endif
}

//______________________________________
 void BrCoordinateSystem::List()
{
  Warning("List", "Obsolete - use Print instead"); 
}

//______________________________________
 void BrCoordinateSystem::Print(Option_t* option) const
{
  cout << "Coordinate system: " << endl
       << fOrigin << endl;
  cout << fRotMatrix << endl;
}
//
//  Static Function
//

//_______________________________________________________________________
BrCoordinateSystem 
 BrCoordinateSystem::SetRelativeSystem(const BrCoordinateSystem& master, 
				      const BrCoordinateSystem& daughter){
  // Return a coordinate system that describes the daughter system
  // relative to the master system. This can be used when transforming
  // between two relative systems. Example
  //  BrCoordinateSystem t1_system;
  //  BrCoordinateSystem d1_system;
  //  BrCoordinateSystem t1d1_system
  //  t1d1_system = SetRelativeSystem(d1_system, t1_system);
  //  BrVector3D d1_vector = t1td->TransformToMaster(t1_vector);
  //  gives the vector (from T1) in the D1 system.
  // See also the tests TestCoord.cxx in the testdirectory.
  //
  BrCoordinateSystem tmp;
  BrVector3D vdiff = daughter.fOrigin-master.fOrigin;                
  //  Origin for coordinate system in Master system
  Double_t *rotmatrix = tmp.fRotMatrix.GetMatrix();
  const Double_t *master_matrix   = master.fInverseRotMatrix.GetMatrix();
  const Double_t *daughter_matrix = daughter.fRotMatrix.GetMatrix();
  for(int i=0;i<3;i++){
	  for(int j=0;j<3;j++){
		  Double_t sum=0;
		  for (int k=0;k<3;k++) sum+= master_matrix[i+3*k]*daughter_matrix[k+j*3];
		  rotmatrix[i+j*3]=sum;
	  }
  }
  BrVector3D origin;
  {

	  for(int i=0; i<3;i++){
		  Double_t sum=0;
		  for(int k=0;k<3;k++)
		  {
			  sum+=master_matrix[i+k*3]*vdiff(k);
		  }
		  origin[i]=sum;
	  }
  }
  tmp.SetOrigin(origin);
  tmp.SetInverseMatrix();
  return tmp;

}

//_____________________________________________________________________
BrCoordinateSystem & 
BrCoordinateSystem::operator =(const BrCoordinateSystem& system){
  //
  // assignement operator
  //
  fOrigin    = system.fOrigin;
  fRotMatrix = system.fRotMatrix;
  fInverseRotMatrix = system.fInverseRotMatrix;
  return *this;
}


//______________________________________________________________
ostream& operator<< (ostream & os, const BrCoordinateSystem& system)
{
  os << "Coordinatesystem: " << system.GetOrigin() << "n" ;
  os <<	   *(system.GetRotMatrix()) << "n";
  os <<	   *(system.GetInverseRotMatrix()) << "n";
  return os;
 }
//////////////////////////////////////////////////////////////////////////////////////
//
//  $Log: BrCoordinateSystem.cxx,v $
//  Revision 1.2  2002/02/26 08:58:43  cholm
//  Added const'ness to many methods - needed by ISO C++
//
//  Revision 1.1.1.1  2001/06/21 14:55:20  hagel
//  Initial revision of brat2
//
//  Revision 1.6  2000/10/10 18:10:29  videbaek
//  Changed the method name GetRotMatrix to GetMatrix to be symmetric
//  with SetMatrix and to distinguish from BrCoorDianteSystem->GetRotMatrix
//  that return a BrRotMatrix.
//
//  Revision 1.5  2000/07/18 17:53:27  trine
//  Switched to subdeterminant method for calculating inverse matrix - more
//  general than the transpose.
//
//  Revision 1.4  2000/07/16 19:46:17  videbaek
//  Addition for declaring a new rotmatrix by means of two exsisting.
//  Fixing of errors in inverse matrix fro non-simple rotations, and constructor for
//  Rotmatrix using Euler angles. All thanks to Trine Tveter.
//
//  Revision 1.3  1999/12/23 15:55:45  videbaek
//  Added the SetRelativeSystem
//  Fully debugged.
//
//  Revision 1.2  1998/12/21 20:32:04  videbaek
//  coordinate system changes mainly
//
//  Revision 1.1  1998/12/01 20:50:11  videbaek
//  Added several classes to Geometry. Updated source and makefile(s)
//  - BrLine3D
//  - BrCoordinateSystem
//  - BrRotMatrix
//
//

This page automatically generated by script docBrat by Christian Holm

Copyright ; 2002 BRAHMS Collaboration <brahmlib@rcf.rhic.bnl.gov>
Last Update on by

Validate HTML
Validate CSS