| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Gaudi::Math::GSL::EigenSystem Class Reference

Helper class with allows to find eigenvalues and eigenvector for symmetrical MathLib matrices ("SMatrix") using GSL library. More...

#include <EigenSystem.h>

List of all members.


Public Types

 MatrixAllocationFailure = 101
 VectorAllocationFailure = 102
 WorkspaceAllocationFailure = 103
 ErrorFromGSL = 199
 ErrorFromGSL + error code.
enum  { MatrixAllocationFailure = 101, VectorAllocationFailure = 102, WorkspaceAllocationFailure = 103, ErrorFromGSL = 199 }
 error codes More...

Public Member Functions

 EigenSystem ()
 Standard constructor.
 ~EigenSystem ()
 destructor
template<class T, unsigned int D>
ROOT::Math::SVector< T, D > eigenValues (const ROOT::Math::SMatrix< T, D, D, ROOT::Math::MatRepSym< T, D > > &mtrx, const bool sorted=true) const
 evaluate the eigenvalues of symmetrical matrix
template<class T, unsigned int D>
StatusCode eigenValues (const ROOT::Math::SMatrix< T, D, D, ROOT::Math::MatRepSym< T, D > > &mtrx, ROOT::Math::SVector< T, D > &vals, const bool sorted=true) const
 evaluate the eigenvalues of symmetrical matrix
template<class T, unsigned int D>
StatusCode eigenVectors (const ROOT::Math::SMatrix< T, D, D, ROOT::Math::MatRepSym< T, D > > &mtrx, ROOT::Math::SVector< T, D > &vals, ROOT::Math::SMatrix< T, D, D > &vecs, const bool sorted=true) const
 evaluate the eigenvalues and eigenvectors of the symmetrical matrix
template<class T, unsigned int D>
StatusCode eigenVectors (const ROOT::Math::SMatrix< T, D, D, ROOT::Math::MatRepSym< T, D > > &mtrx, ROOT::Math::SVector< T, D > &vals, std::vector< ROOT::Math::SVector< T, D > > &vecs, const bool sorted=true) const
 evaluate the eigenvalues and eigenvectors of the symmetrical matrix

Protected Member Functions

StatusCode _fun1 (const bool sorted) const
 find the eigenvalues (& sort them if needed )
StatusCode _fun2 (const bool sorted) const
 find the eigenvalues&eigenvectors (& sort them if needed )

Private Member Functions

template<class T, unsigned int D>
StatusCode _fill (const ROOT::Math::SMatrix< T, D, D, ROOT::Math::MatRepSym< T, D > > &mtrx) const
 fill the internal structures with the input data
StatusCode _check (const unsigned int D) const
 check/adjust the internal structures
StatusCode Exception (const StatusCode &sc) const

Private Attributes

unsigned int m_dim1
 the size of workspace
unsigned int m_dim2
 the size of workspace
gsl_eigen_symm_workspace * m_work1
 workspace itself
gsl_eigen_symmv_workspace * m_work2
 workspace itself
gsl_matrix * m_matrix
 the matrix with input data
gsl_matrix * m_evec
 the matrix with eigenvectors
gsl_vector * m_vector
 the vector with eigenvalues

Detailed Description

Helper class with allows to find eigenvalues and eigenvector for symmetrical MathLib matrices ("SMatrix") using GSL library.

Author:
Vanya BELYAEV
Date:
2006-05-24

Definition at line 41 of file EigenSystem.h.


Member Enumeration Documentation

anonymous enum

error codes

Enumerator:
MatrixAllocationFailure 
VectorAllocationFailure 
WorkspaceAllocationFailure 
ErrorFromGSL  ErrorFromGSL + error code.

Definition at line 45 of file EigenSystem.h.

00046           { 
00047             MatrixAllocationFailure     = 101 , 
00048             VectorAllocationFailure     = 102 , 
00049             WorkspaceAllocationFailure  = 103 , 
00050             // the actual return value is ErrorFromGSL + error code )
00051             ErrorFromGSL                = 199 , 
00052           } ;


Constructor & Destructor Documentation

Gaudi::Math::GSL::EigenSystem::EigenSystem (  ) 

Standard constructor.

Definition at line 48 of file EigenSystem.cpp.

00049   : m_dim1   ( 0 )
00050   , m_dim2   ( 0 )
00051   , m_work1  ( 0 ) 
00052   , m_work2  ( 0 ) 
00053   , m_matrix ( 0 ) 
00054   , m_evec   ( 0 ) 
00055   , m_vector ( 0 )  
00056 {} ;

Gaudi::Math::GSL::EigenSystem::~EigenSystem (  ) 

destructor

Definition at line 60 of file EigenSystem.cpp.

00061 {
00062   if ( 0 != m_matrix ) { gsl_matrix_free      ( m_matrix ) ; }
00063   if ( 0 != m_evec   ) { gsl_matrix_free      ( m_evec   ) ; }
00064   if ( 0 != m_vector ) { gsl_vector_free      ( m_vector ) ; }
00065   if ( 0 != m_work1  ) { gsl_eigen_symm_free  ( m_work1  ) ; }
00066   if ( 0 != m_work2  ) { gsl_eigen_symmv_free ( m_work2  ) ; }
00067 } ;


Member Function Documentation

template<class T, unsigned int D>
ROOT::Math::SVector<T,D> Gaudi::Math::GSL::EigenSystem::eigenValues ( const ROOT::Math::SMatrix< T, D, D, ROOT::Math::MatRepSym< T, D > > &  mtrx,
const bool  sorted = true 
) const [inline]

evaluate the eigenvalues of symmetrical matrix

  // create the evaluator 
  EigenSystem eval ;

  const Gaudi::SymMatrix3x3 matrix = ... ;
 
  // get the sorted vector of eigenvalues:
  const Gaudi::Vector2 result = eval.eigenValues ( matrix ) ;

Exceptions:
GaudiException is thrown in the case of errors
Parameters:
mtrx (input) the matrix itself
sorted (input) flag to be use for sorting
Returns:
vector of eigenvalues

template<class T, unsigned int D>
StatusCode Gaudi::Math::GSL::EigenSystem::eigenValues ( const ROOT::Math::SMatrix< T, D, D, ROOT::Math::MatRepSym< T, D > > &  mtrx,
ROOT::Math::SVector< T, D > &  vals,
const bool  sorted = true 
) const [inline]

evaluate the eigenvalues of symmetrical matrix

  // create the evaluator 
  EigenSystem eval ;

  const Gaudi::SymMatrix3x3 matrix = ... ;
  Gaudi::Vector3 resutl 
 
  // find the eigenvalues:
  StatusCode sc = eval.eigenValues ( matrix , result ) ;

Parameters:
mtrx (input) the matrix itself
vals (output) the vector fo eigenvalues
sorted (input) flag to be use for sorting
Returns:
status code

template<class T, unsigned int D>
StatusCode Gaudi::Math::GSL::EigenSystem::eigenVectors ( const ROOT::Math::SMatrix< T, D, D, ROOT::Math::MatRepSym< T, D > > &  mtrx,
ROOT::Math::SVector< T, D > &  vals,
ROOT::Math::SMatrix< T, D, D > &  vecs,
const bool  sorted = true 
) const [inline]

evaluate the eigenvalues and eigenvectors of the symmetrical matrix

  // create the evaluator 
  EigenSystem eval ;

  const Gaudi::SymMatrix3x3 matrix = ... ;
  // matrix with eigenvectors: 
  Gaudi::Matrix3x3          vectors ; 
  // vector of eigenvalues:
  Gausi::Vector3            values  ;

  // find the eigenvalues & eigenvectors: 
  StatusCode sc = eval.eigenvectors ( matrix , values , vectors ) ;

Eigenvectors are returned as columns for the matrix "vecs". This matrix could be easily used to for diagonalization of the initial matrix, e.g.

  // avoid long names:
  using namespace ROOT::Math ;
  // *NUMERICALLY* DIAGONAL MATRIX: 
  Gaudi::SymMatrix3x3 res = 
      Similarity ( Transpose ( vectors ) , matrix ) ;

Parameters:
mtrx (input) the matrix itself
vals (output) the vector fo eigenvalues
vecs (output) the matrix with eigenvectors
sorted (input) flag to be use for sorting
Returns:
status code

template<class T, unsigned int D>
StatusCode Gaudi::Math::GSL::EigenSystem::eigenVectors ( const ROOT::Math::SMatrix< T, D, D, ROOT::Math::MatRepSym< T, D > > &  mtrx,
ROOT::Math::SVector< T, D > &  vals,
std::vector< ROOT::Math::SVector< T, D > > &  vecs,
const bool  sorted = true 
) const [inline]

evaluate the eigenvalues and eigenvectors of the symmetrical matrix

  // create the evaluator 
  EigenSystem eval ;

  const Gaudi::SymMatrix3x3   matrix = ... ;
  // vector  with eigenvectors: 
  std::vector<Gaudi::Vector3> vectors ; 
  // vector of eigenvalues:
  Gaudi::Vector3              values  ;

  // find the eigenvalues & eigenvectors: 
  StatusCode sc = eval.eigenvectors ( matrix , values , vectors ) ;

Parameters:
mtrx (input) the matrix itself
vals (output) the vector fo eigenvalues
vecs (output) the vector of eigenvectors
sorted (input) flag to be use for sorting
Returns:
status code

StatusCode Gaudi::Math::GSL::EigenSystem::_fun1 ( const bool  sorted  )  const [protected]

find the eigenvalues (& sort them if needed )

Definition at line 98 of file EigenSystem.cpp.

00099 {
00100   // check the working space, (re)allocate if needed  
00101   if ( 0 != m_work1 && m_dim1 != m_vector->size ) 
00102   { gsl_eigen_symm_free  ( m_work1 ) ; m_work1 = 0 ; }
00103   if ( 0 == m_work1 ) 
00104   { m_dim1 = m_vector->size ; m_work1 = gsl_eigen_symm_alloc ( m_dim1 ) ; ; }
00105   if ( 0 == m_work1 ) { return StatusCode ( WorkspaceAllocationFailure ) ; }
00106   
00107   const int result = gsl_eigen_symm  ( m_matrix , m_vector , m_work1 ) ;
00108   if ( result ) { return StatusCode ( ErrorFromGSL + result ) ; }
00109   if ( sorted ) { gsl_sort_vector   ( m_vector )  ; }
00110   return StatusCode::SUCCESS ;
00111 } ;

StatusCode Gaudi::Math::GSL::EigenSystem::_fun2 ( const bool  sorted  )  const [protected]

find the eigenvalues&eigenvectors (& sort them if needed )

Definition at line 116 of file EigenSystem.cpp.

00117 {
00118   // check the working space, (re)allocate if needed  
00119   if ( 0 != m_work2 &&  m_dim2 != m_vector->size ) 
00120   { gsl_eigen_symmv_free ( m_work2 ) ; m_work2 = 0 ; }  
00121   if ( 0 == m_work2 ) 
00122   { m_dim2 = m_vector->size ; m_work2 = gsl_eigen_symmv_alloc ( m_dim2 ) ; ; }
00123   if ( 0 == m_work2 ) { return StatusCode ( WorkspaceAllocationFailure ) ; }
00124   
00125   const int result = gsl_eigen_symmv ( m_matrix , m_vector , m_evec , m_work2 ) ;
00126   if ( result ) { return StatusCode ( ErrorFromGSL + result ) ; }
00127   if ( sorted ) 
00128   { gsl_eigen_symmv_sort ( m_vector , m_evec , GSL_EIGEN_SORT_VAL_ASC )  ; }
00129 
00130   return StatusCode::SUCCESS ;
00131 } ;

template<class T, unsigned int D>
StatusCode Gaudi::Math::GSL::EigenSystem::_fill ( const ROOT::Math::SMatrix< T, D, D, ROOT::Math::MatRepSym< T, D > > &  mtrx  )  const [inline, private]

fill the internal structures with the input data

StatusCode Gaudi::Math::GSL::EigenSystem::_check ( const unsigned int  D  )  const [private]

check/adjust the internal structures

Definition at line 72 of file EigenSystem.cpp.

00073 {
00074   // check existing GSL matrix, (re)allocate if needed  
00075   if ( 0 != m_matrix && ( D != m_matrix->size1 || D != m_matrix->size2 ) ) 
00076   { gsl_matrix_free ( m_matrix ) ; m_matrix = 0 ; }
00077   if ( 0 == m_matrix   ) { m_matrix = gsl_matrix_alloc ( D , D ) ; }
00078   if ( 0 == m_matrix   ) { return StatusCode ( MatrixAllocationFailure    ) ; }
00079   
00080   // check existing GSL matrix, (re)allocate if needed 
00081   if ( 0 != m_evec && ( D != m_evec->size1 || D != m_evec->size2 ) ) 
00082   { gsl_matrix_free ( m_evec ) ; m_evec = 0 ; }
00083   if ( 0 == m_evec     ) { m_evec = gsl_matrix_alloc   ( D , D ) ; }
00084   if ( 0 == m_evec     ) { return StatusCode ( MatrixAllocationFailure    ) ; }
00085   
00086   // check the GSL vector, (re)allocate if needed 
00087   if ( 0 != m_vector && D != m_vector->size )
00088   { gsl_vector_free ( m_vector ) ; m_vector = 0 ; }
00089   if ( 0 == m_vector   ) { m_vector = gsl_vector_alloc ( D ) ; }
00090   if ( 0 == m_vector   ) { return StatusCode ( VectorAllocationFailure    ) ; }
00091  
00092   return StatusCode::SUCCESS ;
00093 } ;

StatusCode Gaudi::Math::GSL::EigenSystem::Exception ( const StatusCode sc  )  const [private]

Definition at line 136 of file EigenSystem.cpp.

00137 {
00138   throw GaudiException
00139     ("Error from Gaudi::Math::GSL::EigenSystem" , "*GSL*" , sc ) ;
00140   return sc ;
00141 };


Member Data Documentation

unsigned int Gaudi::Math::GSL::EigenSystem::m_dim1 [mutable, private]

the size of workspace

Definition at line 212 of file EigenSystem.h.

unsigned int Gaudi::Math::GSL::EigenSystem::m_dim2 [mutable, private]

the size of workspace

Definition at line 213 of file EigenSystem.h.

gsl_eigen_symm_workspace* Gaudi::Math::GSL::EigenSystem::m_work1 [mutable, private]

workspace itself

Definition at line 215 of file EigenSystem.h.

gsl_eigen_symmv_workspace* Gaudi::Math::GSL::EigenSystem::m_work2 [mutable, private]

workspace itself

Definition at line 217 of file EigenSystem.h.

gsl_matrix* Gaudi::Math::GSL::EigenSystem::m_matrix [mutable, private]

the matrix with input data

Definition at line 219 of file EigenSystem.h.

gsl_matrix* Gaudi::Math::GSL::EigenSystem::m_evec [mutable, private]

the matrix with eigenvectors

Definition at line 221 of file EigenSystem.h.

gsl_vector* Gaudi::Math::GSL::EigenSystem::m_vector [mutable, private]

the vector with eigenvalues

Definition at line 223 of file EigenSystem.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:02:58 2011 for LHCbMath by doxygen 1.4.7