00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <vector>
00015
00016
00017
00018 #include "gsl/gsl_eigen.h"
00019 #include "gsl/gsl_sort_vector.h"
00020
00021
00022
00023 #include "Math/SMatrix.h"
00024 #include "Math/SVector.h"
00025
00026
00027
00028 #include "GaudiKernel/StatusCode.h"
00029 #include "GaudiKernel/GaudiException.h"
00030
00031
00032
00033 #include "LHCbMath/EigenSystem.h"
00034 #include "LHCbMath/EigenSystem.icpp"
00035
00036
00037
00043
00044
00045
00046
00047
00048 Gaudi::Math::GSL::EigenSystem::EigenSystem()
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 {} ;
00057
00058
00059
00060 Gaudi::Math::GSL::EigenSystem::~EigenSystem()
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 } ;
00068
00069
00070
00071 StatusCode Gaudi::Math::GSL::EigenSystem::_check
00072 ( const unsigned int D ) const
00073 {
00074
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
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
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 } ;
00094
00095
00096
00097 StatusCode Gaudi::Math::GSL::EigenSystem::_fun1
00098 ( const bool sorted ) const
00099 {
00100
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 } ;
00112
00114
00115 StatusCode Gaudi::Math::GSL::EigenSystem::_fun2
00116 ( const bool sorted ) const
00117 {
00118
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 } ;
00132
00133
00134
00135 StatusCode Gaudi::Math::GSL::EigenSystem::Exception
00136 ( const StatusCode& sc ) const
00137 {
00138 throw GaudiException
00139 ("Error from Gaudi::Math::GSL::EigenSystem" , "*GSL*" , sc ) ;
00140 return sc ;
00141 };
00142
00143
00144
00145
00146
00147
00148