Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:25

0001 /*
0002  * VMatrix.h
0003  *
0004  *  Created on: Feb 15, 2012
0005  *      Author: kleinwrt
0006  */
0007 
0008 /** \file
0009  *  VMatrix definition.
0010  *
0011  *  \author Claus Kleinwort, DESY, 2011 (Claus.Kleinwort@desy.de)
0012  *
0013  *  \copyright
0014  *  Copyright (c) 2011 - 2016 Deutsches Elektronen-Synchroton,
0015  *  Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY \n\n
0016  *  This library is free software; you can redistribute it and/or modify
0017  *  it under the terms of the GNU Library General Public License as
0018  *  published by the Free Software Foundation; either version 2 of the
0019  *  License, or (at your option) any later version. \n\n
0020  *  This library is distributed in the hope that it will be useful,
0021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0023  *  GNU Library General Public License for more details. \n\n
0024  *  You should have received a copy of the GNU Library General Public
0025  *  License along with this program (see the file COPYING.LIB for more
0026  *  details); if not, write to the Free Software Foundation, Inc.,
0027  *  675 Mass Ave, Cambridge, MA 02139, USA.
0028  */
0029 
0030 #ifndef VMATRIX_H_
0031 #define VMATRIX_H_
0032 
0033 #include<iostream>
0034 #include<iomanip>
0035 #include<vector>
0036 #include<cstring>
0037 #include<math.h>
0038 
0039 //! Namespace for the general broken lines package
0040 namespace gbl {
0041 
0042 /// Simple Vector based on std::vector<double>
0043 class VVector {
0044 public:
0045     VVector(const unsigned int nRows = 0);
0046     VVector(const VVector &aVector);
0047     virtual ~VVector();
0048     void resize(const unsigned int nRows);
0049     VVector getVec(unsigned int len, unsigned int start = 0) const;
0050     void putVec(const VVector &aVector, unsigned int start = 0);
0051     inline double &operator()(unsigned int i);
0052     inline double operator()(unsigned int i) const;
0053     unsigned int getNumRows() const;
0054     void print() const;
0055     VVector operator-(const VVector &aVector) const;
0056     VVector &operator=(const VVector &aVector);
0057 private:
0058     unsigned int numRows; ///< Number of rows
0059     std::vector<double> theVec; ///< Data
0060 };
0061 
0062 /// Simple Matrix based on std::vector<double>
0063 class VMatrix {
0064 public:
0065     VMatrix(const unsigned int nRows = 0, const unsigned int nCols = 0);
0066     VMatrix(const VMatrix &aMatrix);
0067     virtual ~VMatrix();
0068     void resize(const unsigned int nRows, const unsigned int nCols);
0069     VMatrix transpose() const;
0070     inline double &operator()(unsigned int i, unsigned int j);
0071     inline double operator()(unsigned int i, unsigned int j) const;
0072     unsigned int getNumRows() const;
0073     unsigned int getNumCols() const;
0074     void print() const;
0075     VVector operator*(const VVector &aVector) const;
0076     VMatrix operator*(const VMatrix &aMatrix) const;
0077     VMatrix operator+(const VMatrix &aMatrix) const;
0078     VMatrix &operator=(const VMatrix &aMatrix);
0079 private:
0080     unsigned int numRows; ///< Number of rows
0081     unsigned int numCols; ///< Number of columns
0082     std::vector<double> theVec; ///< Data
0083 };
0084 
0085 /// Simple symmetric Matrix based on std::vector<double>
0086 class VSymMatrix {
0087 public:
0088     VSymMatrix(const unsigned int nRows = 0);
0089     virtual ~VSymMatrix();
0090     void resize(const unsigned int nRows);
0091     unsigned int invert();
0092     inline double &operator()(unsigned int i, unsigned int j);
0093     inline double operator()(unsigned int i, unsigned int j) const;
0094     unsigned int getNumRows() const;
0095     void print() const;
0096     VSymMatrix operator-(const VMatrix &aMatrix) const;
0097     VVector operator*(const VVector &aVector) const;
0098     VMatrix operator*(const VMatrix &aMatrix) const;
0099 private:
0100     unsigned int numRows; ///< Number of rows
0101     std::vector<double> theVec; ///< Data (symmetric storage)
0102 };
0103 
0104 /// access element (i,j)
0105 inline double &VMatrix::operator()(unsigned int iRow, unsigned int iCol) {
0106     return theVec[numCols * iRow + iCol];
0107 }
0108 
0109 /// access element (i,j)
0110 inline double VMatrix::operator()(unsigned int iRow, unsigned int iCol) const {
0111     return theVec[numCols * iRow + iCol];
0112 }
0113 
0114 /// access element (i)
0115 inline double &VVector::operator()(unsigned int iRow) {
0116     return theVec[iRow];
0117 }
0118 
0119 /// access element (i)
0120 inline double VVector::operator()(unsigned int iRow) const {
0121     return theVec[iRow];
0122 }
0123 
0124 /// access element (i,j) assuming i>=j
0125 inline double &VSymMatrix::operator()(unsigned int iRow, unsigned int iCol) {
0126     return theVec[(iRow * iRow + iRow) / 2 + iCol]; // assuming iCol <= iRow
0127 }
0128 
0129 /// access element (i,j) assuming i>=j
0130 inline double VSymMatrix::operator()(unsigned int iRow,
0131         unsigned int iCol) const {
0132     return theVec[(iRow * iRow + iRow) / 2 + iCol]; // assuming iCol <= iRow
0133 }
0134 }
0135 #endif /* VMATRIX_H_ */