CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

MatrixMeschach Class Reference

#include <MatrixMeschach.h>

List of all members.

Public Member Functions

void AddData (ALIuint col, ALIuint lin, ALIdouble data)
void Dump (const ALIstring &mtext)
void EliminateColumns (ALIint lin_first, ALIint lin_last)
void EliminateLines (ALIint lin_first, ALIint lin_last)
void inverse ()
const MAT * Mat () const
MAT * MatNonConst () const
 MatrixMeschach ()
 MatrixMeschach (ALIint NoCol, ALIint NoLin)
 MatrixMeschach (const MatrixMeschach &mat)
ALIint NoColumns () const
ALIint NoLines () const
ALIdouble operator() (int i, int j) const
void operator*= (const ALIdouble num)
void operator*= (const MatrixMeschach &mat)
void operator+= (const MatrixMeschach &mat)
MatrixMeschachoperator= (const MatrixMeschach &mat)
void ostrDump (std::ostream &fout, const ALIstring &mtext)
void SetCorrelation (ALIint i1, ALIint i2, ALIdouble corr)
void setMat (MAT *mat)
void setNoColumns (ALIint ncol)
void setNoLines (ALIint nlin)
void transpose ()
 ~MatrixMeschach ()

Private Member Functions

void copy (const MatrixMeschach &mat)

Private Attributes

MAT * _Mat
ALIint _NoColumns
ALIint _NoLines

Detailed Description

Definition at line 24 of file MatrixMeschach.h.


Constructor & Destructor Documentation

MatrixMeschach::MatrixMeschach ( )

Definition at line 16 of file MatrixMeschach.cc.

{
  //-  std::cout << "creating matrix0 " << std::endl;
}
MatrixMeschach::MatrixMeschach ( ALIint  NoCol,
ALIint  NoLin 
)

Definition at line 29 of file MatrixMeschach.cc.

References _Mat, _NoColumns, and _NoLines.

{
  //-  std::cout << "creating matrix " << std::endl;
  _NoLines = NoLin; 
  _NoColumns = NoCol;
  _Mat = m_get( NoLin, NoCol );
  //_data = new ALIdouble[NoCol][NoLin];
}
MatrixMeschach::MatrixMeschach ( const MatrixMeschach mat)

Definition at line 40 of file MatrixMeschach.cc.

References _Mat, _NoColumns, _NoLines, copy(), NoColumns(), and NoLines().

{
  //-  std::cout << "creating matrixc " << std::endl;
  _NoLines = mat._Mat->m; 
  _NoColumns = mat._Mat->n;
  _Mat = m_get( mat.NoLines(), mat.NoColumns() );
  // std::cout <<  "copy const" << mat._Mat << _Mat << NoLines() << NoColumns() << Mat()->m << Mat()->n <<std::endl;
  copy( mat );
}
MatrixMeschach::~MatrixMeschach ( )

Definition at line 22 of file MatrixMeschach.cc.

References _Mat.

{
  //-  std::cout << "deleting matrix " << std::endl;
  M_FREE(_Mat);
}

Member Function Documentation

void MatrixMeschach::AddData ( ALIuint  col,
ALIuint  lin,
ALIdouble  data 
)

Definition at line 273 of file MatrixMeschach.cc.

References _Mat, _NoColumns, _NoLines, dtNoiseDBValidation_cfg::cerr, AlCaHLTBitMon_QueryRunRegistry::data, and exception.

Referenced by EliminateColumns(), EliminateLines(), Fit::FillMatricesWithCalibratedParameters(), Fit::FillMatricesWithMeasurements(), and SetCorrelation().

{
  if ( lin >= _Mat->m || col >= _Mat->n ) {
      std::cerr << "EXITING: matrix has only " << _NoLines << " lines and "
           << _NoColumns << " columns " << std::endl;
      std::cerr << "EXITING: matrix has only " << _Mat->m << " lines and "
           << _Mat->n << " columns " << std::endl;
      std::cerr << " You tried to add data in line " << lin << " and column "
           << col << std::endl;
      std::exception();
  }
  _Mat->me[lin][col] = data;

} 
void MatrixMeschach::copy ( const MatrixMeschach mat) [private]

Definition at line 52 of file MatrixMeschach.cc.

References _Mat, _NoColumns, _NoLines, and MatNonConst().

Referenced by EliminateColumns(), EliminateLines(), MatrixMeschach(), and operator=().

{
  //  if( ALIUtils::debug >= 5) std::cout <<  "copy matrix" << mat._Mat << " " << _Mat << " L " << mat.NoLines() << " C " << mat.NoColumns() << " l " <<  mat.Mat()->m << " c " << mat.Mat()->n <<std::endl;

  for( ALIint lin=0; lin < _NoLines; lin++ ) {
    for( ALIint col=0;  col < _NoColumns; col++ ) {
      _Mat->me[lin][col] = mat.MatNonConst()->me[lin][col];
    } 
  }
  //   m_copy( mat._Mat, _Mat );
} 
void MatrixMeschach::Dump ( const ALIstring mtext)
void MatrixMeschach::EliminateColumns ( ALIint  lin_first,
ALIint  lin_last 
)

Definition at line 333 of file MatrixMeschach.cc.

References _Mat, _NoColumns, _NoLines, AddData(), dtNoiseDBValidation_cfg::cerr, copy(), gather_cfg::cout, ALIUtils::debug, Dump(), findQualityFiles::jj, Mat(), NoColumns(), and NoLines().

{
  //-  return;
  if ( lin_last < lin_first ) {
      std::cerr << "EXITING: cannot Eliminate Lines in matrix if first line is " << 
      lin_first << " and lastt line is " << lin_last << std::endl;
      //t      std::exception();
      return;
  }
  ALIint dif = (lin_last - lin_first) + 1; 
  ALIint newANolin = NoLines();
  ALIint newANocol = NoColumns() - dif;
  MatrixMeschach newmat( newANolin, newANocol );
  ALIint jjn = 0;
  for ( ALIint jj=0; jj<NoColumns(); jj++) {
      if( jj < lin_first  || jj > lin_last ) { 
          for ( ALIint ii=0; ii<NoLines(); ii++) {
              newmat.AddData( ii, jjn, (*this)(ii,jj) );
               if(ALIUtils::debug >= 9) std::cout << ii << jjn << "nmat" << newmat.Mat()->me[ii][jjn] << std::endl;
          }
          jjn++;
      }
  }
  M_FREE( _Mat );
  _Mat = m_get( newANolin, newANocol );
  copy( newmat );
  _NoLines = _Mat->m; 
  _NoColumns = _Mat->n;
  Dump( "newnewmat" );
}
void MatrixMeschach::EliminateLines ( ALIint  lin_first,
ALIint  lin_last 
)

Definition at line 299 of file MatrixMeschach.cc.

References _Mat, _NoColumns, _NoLines, AddData(), dtNoiseDBValidation_cfg::cerr, copy(), gather_cfg::cout, ALIUtils::debug, Dump(), findQualityFiles::jj, Mat(), NoColumns(), and NoLines().

{
  //-  return;
  if ( lin_last < lin_first ) {
       std::cerr << "EXITING: cannot Eliminate Lines in matrix if first line is " << 
      lin_first << " and lastt line is " << lin_last << std::endl;
      //t          std::exception();
       return;
  }
  ALIint dif = (lin_last - lin_first) + 1; 
  ALIint newANolin = NoLines() - dif; 
  ALIint newANocol = NoColumns();
  MatrixMeschach newmat( newANolin, newANocol );
  ALIint iin = 0;
  for ( ALIint ii=0; ii<NoLines(); ii++) {
      if( ii < lin_first  || ii > lin_last ) { 
          for ( ALIint jj=0; jj<NoColumns(); jj++) {
              newmat.AddData(iin, jj, (*this)(ii,jj) );
                if(ALIUtils::debug >= 9) std::cout << iin << jj << "nmat" << newmat.Mat()->me[iin][jj] << std::endl;
          }
          iin++;
      }
  }
  M_FREE( _Mat );
  _Mat = m_get( newANolin, newANocol );
  copy( newmat );
  _NoLines = _Mat->m; 
  _NoColumns = _Mat->n;
  Dump( "newnewmat" );

}
void MatrixMeschach::inverse ( )

Definition at line 259 of file MatrixMeschach.cc.

References _Mat, _NoColumns, _NoLines, gather_cfg::cout, and ALIUtils::debug.

Referenced by Fit::multiplyMatrices(), and Fit::PropagateErrors().

{
  if(ALIUtils::debug >= 9) std::cout << "inverse" << _NoLines << "C" << _NoColumns << std::endl;
   MAT* tempmat = m_get(_NoLines, _NoColumns);
   ALIdouble factor = 1000.;
   (*this) *= 1./factor;
   m_inverse( _Mat, tempmat );
   m_copy( tempmat, _Mat );
   (*this) *= 1./factor;
  M_FREE(tempmat);
}
const MAT* MatrixMeschach::Mat ( ) const [inline]
MAT* MatrixMeschach::MatNonConst ( ) const [inline]

Definition at line 67 of file MatrixMeschach.h.

References _Mat.

Referenced by copy(), MatrixByMatrix(), operator*(), and Fit::PropagateErrors().

                          {
    return _Mat;
  }
ALIint MatrixMeschach::NoColumns ( ) const [inline]
ALIint MatrixMeschach::NoLines ( ) const [inline]
ALIdouble MatrixMeschach::operator() ( int  i,
int  j 
) const

Definition at line 290 of file MatrixMeschach.cc.

References _Mat, i, and j.

{
  return _Mat->me[i][j];
}  
void MatrixMeschach::operator*= ( const MatrixMeschach mat)

Definition at line 86 of file MatrixMeschach.cc.

References _Mat, _NoColumns, _NoLines, dtNoiseDBValidation_cfg::cerr, gather_cfg::cout, NoColumns(), and NoLines().

{
  //  std::cout << " multiply matrices " << std::endl;

  if( _NoColumns != mat.NoLines() ){
    std::cerr << " !! Trying two multiply two matrices when the number of columns of first one is not equal to number of files of second one " << std::endl;
    std::cout << " multiplying matrix " << _NoLines  << " x " << _NoColumns << " and " << mat.NoLines() << " x " << mat.NoColumns() << " results in " << _NoLines << " x " << mat.NoColumns() << std::endl;
  }
  _NoColumns = mat.NoColumns();

  MAT* tempmat = m_get( _NoColumns, _NoLines );
  m_transp( _Mat, tempmat); 
  //  M_FREE( _Mat );
  _Mat = m_get( _NoLines, mat.NoColumns() );
  mtrm_mlt( tempmat, mat._Mat, _Mat);

  //  _NoColumns = mat.NoColumns(); 
  //  M_FREE(tempmat);
}
void MatrixMeschach::operator*= ( const ALIdouble  num)

Definition at line 126 of file MatrixMeschach.cc.

References _Mat, and findQualityFiles::jj.

{
  for (ALIuint ii=0; ii<_Mat->m; ii++) {
      for (ALIuint jj=0; jj<_Mat->n; jj++) {
          _Mat->me[ii][jj] *= num;
      }
  }

}
void MatrixMeschach::operator+= ( const MatrixMeschach mat)

Definition at line 108 of file MatrixMeschach.cc.

References _Mat, _NoColumns, _NoLines, and dtNoiseDBValidation_cfg::cerr.

{
  if(_NoLines != mat._NoLines  || _NoColumns != mat._NoColumns ) {
    std::cerr << "!!!! cannot sum two matrices with different size" << std::endl
         << "MATRIX 1:" << _NoLines << " X " << _NoColumns << std::endl
         << "MATRIX 2:" << mat._NoLines << " X " << mat._NoColumns << std::endl;
  }
  MAT* tempmat = m_get( _NoColumns, _NoLines );
  m_copy( _Mat, tempmat); 
  M_FREE( _Mat );
  _Mat = m_get( _NoLines, _NoColumns );
  m_add( tempmat, mat._Mat, _Mat);
  M_FREE(tempmat);

}
MatrixMeschach & MatrixMeschach::operator= ( const MatrixMeschach mat)

Definition at line 66 of file MatrixMeschach.cc.

References _Mat, _NoColumns, _NoLines, dtNoiseDBValidation_cfg::cerr, copy(), gather_cfg::cout, ALIUtils::debug, exception, Mat(), NoColumns(), and NoLines().

{
  if ( this == 0 ) {
      std::cerr << "EXITING: trying to use 'operator=' with an MatrixMeschach for which memory space is not reserved!!!!" << std::endl;
      std::exception();
  }
         
  if ( mat._Mat != _Mat ) {
      _NoLines = mat._Mat->m;
      _NoColumns = mat._Mat->n; 
      M_FREE( _Mat );
      _Mat = m_get( mat.NoLines(), mat.NoColumns() );
      copy( mat );
  }
   if(ALIUtils::debug >= 9) std::cout <<  "operator=" << mat._Mat << _Mat << NoLines() << NoColumns() << Mat()->m << Mat()->n <<std::endl;
  return *this;
}
void MatrixMeschach::ostrDump ( std::ostream &  fout,
const ALIstring mtext 
)

Definition at line 372 of file MatrixMeschach.cc.

References _Mat, _NoColumns, _NoLines, and findQualityFiles::jj.

Referenced by Dump(), and Fit::dumpMatrices().

{
  fout << "DUMPM@@@@@    " << mtext << "    @@@@@" << std::endl;
  fout << "Matrix is (_Mat)" << _Mat->m << "x" << _Mat->n << std::endl;
  fout << "Matrix is " << _NoLines << "x" << _NoColumns << std::endl;
  for (ALIuint ii=0; ii<_Mat->m; ii++) {
    for (ALIuint jj=0; jj<_Mat->n; jj++) {
      fout << std::setw(8) << _Mat->me[ii][jj] << " ";
    }
    fout << std::endl;
  }
  //  m_output(_Mat);

}
void MatrixMeschach::SetCorrelation ( ALIint  i1,
ALIint  i2,
ALIdouble  corr 
)

Definition at line 389 of file MatrixMeschach.cc.

References AddData(), gather_cfg::cout, ALIUtils::debug, and mathSSE::sqrt().

Referenced by Fit::setCorrelationFromParamFitted().

{  
  AddData(i1,i2,corr * sqrt( (*this)(i1,i1)*(*this)(i2,i2) ) );
  AddData(i2,i1,corr * sqrt( (*this)(i1,i1)*(*this)(i2,i2) ) );
   if(ALIUtils::debug >= 9) std::cout << i1<< i2<< corr << "CORR" << (*this)(i1,i1) << " " << (*this)(i2,i2) << std::endl;
  //-  std::cout << (*this)(i1,i1)*(*this)(i2,i2)  << std::endl;
  //- std::cout << sqrt( (*this)(i1,i1)*(*this)(i2,i2) ) << std::endl;
   if(ALIUtils::debug >= 9) std::cout << corr * sqrt( (*this)(i1,i1)*(*this)(i2,i2) ) << std::endl;

}
void MatrixMeschach::setMat ( MAT *  mat) [inline]

Definition at line 64 of file MatrixMeschach.h.

References _Mat.

Referenced by MatrixByMatrix(), and operator*().

                        {
    _Mat = mat;
  }
void MatrixMeschach::setNoColumns ( ALIint  ncol) [inline]

Definition at line 55 of file MatrixMeschach.h.

References _NoColumns.

Referenced by MatrixByMatrix(), and operator*().

                                  {
    _NoColumns = ncol; 
  }
void MatrixMeschach::setNoLines ( ALIint  nlin) [inline]

Definition at line 58 of file MatrixMeschach.h.

References _NoLines.

                                {
    _NoLines = nlin;
  }
void MatrixMeschach::transpose ( )

Definition at line 217 of file MatrixMeschach.cc.

References _Mat, _NoColumns, and _NoLines.

Referenced by Fit::getFitQuality(), Fit::GetSChi2(), and Fit::multiplyMatrices().

{
  //   if(ALIUtils::debug >= 9)
  /*  std::cout << "transposed"  <<_NoLines<<_NoColumns;
  MAT* tempmat = m_get(_NoColumns, _NoLines);
  m_transp( _Mat, tempmat );
  std::cout << "transposed"  <<_NoLines<<_NoColumns;
  M_FREE( _Mat );
  _Mat = m_get(_NoColumns, _NoLines);
  std::cout << "transposed"  <<_NoLines<<_NoColumns;
  m_copy( tempmat, _Mat );
  std::cout << "transposed"  <<_NoLines<<_NoColumns;
  int ntemp = _NoLines;
  _NoLines = _NoColumns;
  _NoColumns = ntemp;
  M_FREE(tempmat);
  */

  //-  std::cout << "transposed"  <<_NoLines<<_NoColumns;
  MAT* tempmat = m_get(_NoColumns, _NoLines);
  m_transp( _Mat, tempmat );
  //-  std::cout << "transposed"  <<_NoLines<<_NoColumns;
  M_FREE( _Mat );
  _Mat = m_get(_NoColumns, _NoLines);
  //- std::cout << "transposed"  <<_NoLines<<_NoColumns;
  for( ALIint lin=0; lin < _NoColumns; lin++ ) {
    for( ALIint col=0;  col < _NoLines; col++ ) {
      //-  std::cout << "setting mat "  << lin << " " << col << std::endl;
      _Mat->me[lin][col] = tempmat->me[lin][col];
    }
  }
  //  m_copy( tempmat, _Mat );
  //-  std::cout << "transposed"  <<_NoLines<<_NoColumns;
  int ntemp = _NoLines;
  _NoLines = _NoColumns;
  _NoColumns = ntemp;
  M_FREE(tempmat);
 
}

Member Data Documentation

MAT* MatrixMeschach::_Mat [private]