EvtMatrix< T > Class Template Reference

#include <EvtMatrix.hh>

List of all members.

Public Member Functions

 EvtMatrix ()
 ~EvtMatrix ()
void setRange (int range)
T & operator() (int row, int col)
T * operator[] (int row)
det ()
EvtMatrixmin (int row, int col)
EvtMatrixinverse ()
std::string dump ()

Private Attributes

T ** _mat
int _range

Friends

template<class M>
EvtMatrix< M > * operator * (const EvtMatrix< M > &left, const EvtMatrix< M > &right)


Detailed Description

template<class T>
class EvtMatrix< T >

Definition at line 22 of file EvtMatrix.hh.


Constructor & Destructor Documentation

template<class T>
EvtMatrix< T >::EvtMatrix (  )  [inline]

Definition at line 28 of file EvtMatrix.hh.

00028 : _range( 0 ) {};

template<class T>
EvtMatrix< T >::~EvtMatrix (  ) 

Definition at line 73 of file EvtMatrix.hh.

References EvtMatrix< T >::_mat, and EvtMatrix< T >::_range.

00074 {
00075   for( int row = 0; row < _range; row++ )
00076     delete[] _mat[ row ];
00077   delete[] _mat;
00078 }


Member Function Documentation

template<class T>
T EvtMatrix< T >::det (  ) 

Definition at line 97 of file EvtMatrix.hh.

References EvtMatrix< T >::_mat, EvtMatrix< T >::_range, EvtMatrix< T >::det(), EvtMatrix< T >::min(), and T.

Referenced by EvtMatrix< T >::det(), and EvtMatrix< T >::inverse().

00098 {
00099   if ( _range == 1 )
00100     return _mat[ 0 ][ 0 ];
00101 
00102   // There's no need to define the range 2 determinant manually, but it may
00103   //    speed up the calculation.
00104   if ( _range == 2 )
00105     return _mat[ 0 ][ 0 ] * _mat[ 1 ][ 1 ] - _mat[ 0 ][ 1 ] * _mat[ 1 ][ 0 ];
00106 
00107   T sum = 0.;
00108 
00109   for ( int col = 0; col < _range; col++ )
00110     {
00111       EvtMatrix< T >* minor = min( 0, col );
00112       sum += std::pow( -1., col ) * _mat[ 0 ][ col ] * minor->det();
00113       delete minor;
00114     }
00115 
00116   return sum;
00117 }

template<class T>
std::string EvtMatrix< T >::dump (  ) 

Definition at line 81 of file EvtMatrix.hh.

References EvtMatrix< T >::_mat, and EvtMatrix< T >::_range.

00082 {
00083   std::ostringstream str;
00084 
00085   for ( int row = 0; row < _range; row++ )
00086     {
00087       str << "|";
00088       for ( int col = 0; col < _range; col++ )
00089         str << "\t" << _mat[ row ][ col ];
00090       str << "\t|" << std::endl;
00091     }
00092 
00093   return str.str();
00094 }

template<class T>
EvtMatrix< T > * EvtMatrix< T >::inverse (  ) 

Definition at line 140 of file EvtMatrix.hh.

References EvtMatrix< T >::_mat, EvtMatrix< T >::_range, EvtMatrix< T >::det(), EvtMatrix< T >::min(), EvtMatrix< T >::setRange(), and T.

Referenced by EvtDalitzReso::Fvector().

00141 {
00142   EvtMatrix< T >* inv = new EvtMatrix< T >();
00143   inv->setRange( _range );
00144 
00145   if ( det() == 0 )
00146     {
00147       std::cerr << "This matrix has a null determinant and cannot be inverted. Returning zero matrix." << std::endl;
00148       for ( int row = 0; row < _range; row++ )
00149         for ( int col = 0; col < _range; col++ )
00150           (*inv)( row, col ) = 0.;
00151       return inv;
00152     }
00153 
00154   T determinant = det();
00155 
00156   for ( int row = 0; row < _range; row++ )
00157     for ( int col = 0; col < _range; col++ )
00158       {
00159         EvtMatrix< T >* minor = min( row, col );
00160         inv->_mat[col][row] = std::pow( -1., row + col ) * minor->det() / determinant;
00161         delete minor;
00162       }
00163 
00164   return inv;
00165 }

template<class T>
EvtMatrix< T > * EvtMatrix< T >::min ( int  row,
int  col 
)

Definition at line 121 of file EvtMatrix.hh.

References EvtMatrix< T >::_mat, EvtMatrix< T >::_range, and EvtMatrix< T >::setRange().

Referenced by EvtMatrix< T >::det(), and EvtMatrix< T >::inverse().

00122 {
00123   EvtMatrix< T >* minor = new EvtMatrix< T >();
00124   minor->setRange( _range - 1 );
00125 
00126   int minIndex = 0;
00127 
00128   for ( int r = 0; r < _range; r++ )
00129     for ( int c = 0; c < _range; c++ )
00130       if ( ( r != row ) && ( c != col ) )
00131         {
00132           (*minor)( minIndex / ( _range - 1 ), minIndex % ( _range - 1 ) ) = _mat[ r ][ c ];
00133           minIndex++;
00134         }
00135 
00136   return minor;
00137 }

template<class T>
T& EvtMatrix< T >::operator() ( int  row,
int  col 
) [inline]

Definition at line 32 of file EvtMatrix.hh.

References EvtMatrix< T >::_mat.

00032 { return _mat[ row ][ col ]; }

template<class T>
T* EvtMatrix< T >::operator[] ( int  row  )  [inline]

Definition at line 33 of file EvtMatrix.hh.

References EvtMatrix< T >::_mat.

00033 { return _mat[ row ];        }

template<class T>
void EvtMatrix< T >::setRange ( int  range  )  [inline]

Definition at line 45 of file EvtMatrix.hh.

References EvtMatrix< T >::_mat, EvtMatrix< T >::_range, and T.

Referenced by EvtDalitzReso::Fvector(), EvtMatrix< T >::inverse(), EvtMatrix< T >::min(), and operator *().

00046 {
00047   // If the range is changed, delete any previous matrix stored
00048   //    and allocate elements with the newly specified range.
00049   if ( _range != range )
00050     {
00051       if ( _range )
00052         {
00053           for ( int row = 0; row < _range; row++ )
00054             delete[] _mat[ row ];
00055           delete[] _mat;
00056         }
00057 
00058       _mat = new T*[ range ];
00059       for ( int row = 0; row < range; row++ )
00060         _mat[ row ] = new T[ range ];
00061 
00062       // Set the new range.
00063       _range = range;
00064     }
00065 
00066   // Since user is willing to change the range, reset the matrix elements.
00067   for ( int row = 0; row < _range; row++ )
00068     for ( int col = 0; col < _range; col++ )
00069       _mat[ row ][ col ] = 0.;
00070 }


Friends And Related Function Documentation

template<class T>
template<class M>
EvtMatrix< M >* operator * ( const EvtMatrix< M > &  left,
const EvtMatrix< M > &  right 
) [friend]


Member Data Documentation

template<class T>
T** EvtMatrix< T >::_mat [private]

Definition at line 25 of file EvtMatrix.hh.

Referenced by EvtMatrix< T >::det(), EvtMatrix< T >::dump(), EvtMatrix< T >::inverse(), EvtMatrix< T >::min(), operator *(), EvtMatrix< T >::operator()(), EvtMatrix< T >::operator[](), EvtMatrix< T >::setRange(), and EvtMatrix< T >::~EvtMatrix().

template<class T>
int EvtMatrix< T >::_range [private]

Definition at line 26 of file EvtMatrix.hh.

Referenced by EvtMatrix< T >::det(), EvtMatrix< T >::dump(), EvtMatrix< T >::inverse(), EvtMatrix< T >::min(), operator *(), EvtMatrix< T >::setRange(), and EvtMatrix< T >::~EvtMatrix().


Generated on Tue Nov 29 23:19:06 2016 for BOSS_7.0.2 by  doxygen 1.4.7