OpMatrix Class Reference

#include <OpMatrix.h>

List of all members.

Public Member Functions

 OpMatrix ()
 OpMatrix (const OpMatrix &)
 OpMatrix (Int_t numRows, Int_t numCols)
 ~OpMatrix ()
virtual void Print (Option_t *option="") const
void Zero ()
Int_t GetNumRows () const
Int_t GetNumCols () const
OpMatrixGetConjugate () const
OpMatrixGetTranspose () const
OpMatrixGetTransposeConjugate () const
OpComplexoperator() (Int_t row, Int_t col) const
OpMatrixoperator= (const OpMatrix &a)
OpMatrix operator+= (const OpMatrix &a)
OpMatrix operator-= (const OpMatrix &a)
OpMatrix operator*= (const OpMatrix &a)
OpMatrix operator*= (const OpComplex &a)
OpMatrix operator/= (const OpComplex &a)

Protected Member Functions

Int_t GetElementIndex (Int_t row, Int_t col) const
void Initialize (Int_t numRows, Int_t numCols)
void InitializeArray (Int_t numRows, Int_t numCols)
void FreeArray ()

Protected Attributes

Int_t fNumRows
Int_t fNumCols
OpComplexfArray

Detailed Description

Definition at line 10 of file OpMatrix.h.


Constructor & Destructor Documentation

OpMatrix::OpMatrix (  ) 

Definition at line 8 of file OpMatrix.cxx.

Referenced by GetConjugate(), GetTranspose(), and GetTransposeConjugate().

00009 {
00010   fNumCols = 0;
00011   fNumRows = 0;
00012   fArray = 0;
00013 }

OpMatrix::OpMatrix ( const OpMatrix copy  ) 

Definition at line 15 of file OpMatrix.cxx.

References fArray, fNumCols, and fNumRows.

00015                                        : TObject(copy)
00016 {
00017   fNumCols = 0;
00018   fNumRows = 0;
00019   fArray = 0;
00020   *this = copy;
00021 }

OpMatrix::OpMatrix ( Int_t  numRows,
Int_t  numCols 
)

Definition at line 24 of file OpMatrix.cxx.

References Initialize().

00025 {
00026 
00027   Initialize(numRows, numCols);
00028 
00029 }

OpMatrix::~OpMatrix (  ) 

Definition at line 45 of file OpMatrix.cxx.

References FreeArray().

00046 {
00047   FreeArray();
00048 }


Member Function Documentation

void OpMatrix::FreeArray (  )  [protected]

Definition at line 50 of file OpMatrix.cxx.

References fArray.

Referenced by operator=(), and ~OpMatrix().

00051 {
00052   if(fArray != 0) delete[] fArray;
00053   fArray = 0;
00054 }

OpMatrix * OpMatrix::GetConjugate (  )  const

Definition at line 229 of file OpMatrix.cxx.

References GetNumCols(), GetNumRows(), and OpMatrix().

Referenced by GetTransposeConjugate().

00230 {
00231   OpMatrix *conjugate = new OpMatrix(GetNumRows(), GetNumCols());
00232 
00233   for(Int_t i = 1; i <= GetNumRows(); i++) {
00234     for(Int_t j = 1; j <= GetNumCols(); j++) {
00235 
00236       (*conjugate)(i, j) = (*this)(i, j).GetConjugate();
00237     }
00238   }
00239   return conjugate;
00240 }

Int_t OpMatrix::GetElementIndex ( Int_t  row,
Int_t  col 
) const [protected]

Definition at line 220 of file OpMatrix.cxx.

References GetNumCols().

Referenced by operator()().

00221 {
00222   Int_t rowElement = row - 1;
00223   Int_t colElement = col - 1;
00224 
00225   return (GetNumCols() * rowElement) + colElement;
00226 }

Int_t OpMatrix::GetNumCols (  )  const

Definition at line 76 of file OpMatrix.cxx.

References fNumCols.

Referenced by GetConjugate(), GetElementIndex(), GetTranspose(), GetTransposeConjugate(), operator*=(), operator+=(), operator-=(), operator/=(), operator=(), Print(), and Zero().

00077 {
00078   return fNumCols;
00079 }

Int_t OpMatrix::GetNumRows (  )  const

Definition at line 71 of file OpMatrix.cxx.

References fNumRows.

Referenced by GetConjugate(), GetTranspose(), GetTransposeConjugate(), operator*=(), operator+=(), operator-=(), operator/=(), operator=(), Print(), and Zero().

00072 {
00073   return fNumRows;
00074 }

OpMatrix * OpMatrix::GetTranspose (  )  const

Definition at line 243 of file OpMatrix.cxx.

References GetNumCols(), GetNumRows(), and OpMatrix().

00244 {
00245   OpMatrix *transpose = new OpMatrix(GetNumCols(), GetNumRows());
00246   for(Int_t i = 1; i <= transpose->GetNumRows(); i++) {
00247     for(Int_t j = 1; j <= transpose->GetNumCols(); j++) {
00248       (*transpose)(i, j) = (*this)(j, i);
00249     }
00250   }
00251 
00252   return transpose;
00253 }

OpMatrix * OpMatrix::GetTransposeConjugate (  )  const

Definition at line 256 of file OpMatrix.cxx.

References GetConjugate(), GetNumCols(), GetNumRows(), and OpMatrix().

Referenced by OpProbability::Calculate_H_Matrix(), and OpProbability::GetProbability().

00257 {
00258 
00259   OpMatrix *transposeConj = new OpMatrix(GetNumCols(), GetNumRows());
00260 
00261   for(Int_t i = 1; i <= transposeConj->GetNumRows(); i++) {
00262     for(Int_t j = 1; j <= transposeConj->GetNumCols(); j++) {
00263 
00264       (*transposeConj)(i, j) = (*this)(j, i).GetConjugate();
00265     }
00266   }
00267   
00268   return transposeConj;
00269 }

void OpMatrix::Initialize ( Int_t  numRows,
Int_t  numCols 
) [protected]

Definition at line 31 of file OpMatrix.cxx.

References InitializeArray().

Referenced by OpMatrix().

00032 {
00033   InitializeArray(numRows, numCols);
00034 }

void OpMatrix::InitializeArray ( Int_t  numRows,
Int_t  numCols 
) [protected]

Definition at line 37 of file OpMatrix.cxx.

References fArray, fNumCols, and fNumRows.

Referenced by Initialize(), and operator=().

00038 {
00039   fNumRows = numRows;
00040   fNumCols = numCols;
00041   fArray = new OpComplex[fNumRows * fNumCols];
00042 }

OpComplex & OpMatrix::operator() ( Int_t  row,
Int_t  col 
) const

Definition at line 81 of file OpMatrix.cxx.

References Error, fArray, fNumCols, fNumRows, and GetElementIndex().

00082 {
00083 
00084   if(row > 0 && row <= fNumRows 
00085      && col > 0 && col <= fNumCols) {
00086     Int_t index = GetElementIndex(row, col);
00087     return fArray[index];
00088   }
00089   else {
00090     Error("operator ()", 
00091           "Out of bounds");
00092     static OpComplex dummy;
00093     return dummy;
00094   }
00095   //TD: ADD ELSE CONDITION FOR OUT OF BOUNDS ERROR
00096 }

OpMatrix OpMatrix::operator*= ( const OpComplex a  ) 

Definition at line 155 of file OpMatrix.cxx.

References GetNumCols(), and GetNumRows().

00156 {
00157 
00158   for(Int_t i = 1; i <= this->GetNumRows(); i++) {
00159     for(Int_t j = 1; j <= this->GetNumCols(); j++) {
00160       (*this)(i,j) = a * (*this)(i, j);
00161     }
00162   }
00163 
00164 
00165   return *this;
00166 }

OpMatrix OpMatrix::operator*= ( const OpMatrix a  ) 

Definition at line 181 of file OpMatrix.cxx.

References MuELoss::a, Error, GetNumCols(), GetNumRows(), and Munits::m.

00182 {
00183   if(this->GetNumCols() != a.GetNumRows()) {
00184     Error("operator *", 
00185           "Num. cols in left matrix doesn't match num. rows in right.");
00186   }
00187 
00188   OpMatrix tmpMatrix(this->GetNumRows(), this->GetNumCols());
00189 
00190   for(Int_t i = 1; i <= this->GetNumRows(); i++) {
00191     OpComplex *rowVector = new OpComplex[this->GetNumCols() + 1];
00192     for(Int_t j = 1; j <= this->GetNumCols(); j++) {
00193       rowVector[j] = (*this)(i,j);
00194     }
00195     
00196     for(Int_t k = 1; k <= a.GetNumCols(); k++) {
00197       OpComplex *colVector = new OpComplex[a.GetNumRows() + 1];
00198       for(Int_t l = 1; l <= a.GetNumRows(); l++) {
00199         colVector[l] = a(l, k);
00200       }
00201 
00202       for(Int_t m = 1; m <= a.GetNumRows(); m++) {
00203         tmpMatrix(i, k) = tmpMatrix(i, k) 
00204           + rowVector[m] * colVector[m];
00205       }
00206 
00207       delete [] colVector;
00208     }
00209 
00210     delete [] rowVector;
00211   }
00212 
00213   *this = tmpMatrix;
00214 
00215   return *this;
00216 
00217 }

OpMatrix OpMatrix::operator+= ( const OpMatrix a  ) 

Definition at line 118 of file OpMatrix.cxx.

References MuELoss::a, Error, fNumCols, fNumRows, GetNumCols(), and GetNumRows().

00119 {
00120 
00121   if(this->GetNumRows() != a.GetNumRows() 
00122      || this->GetNumCols() != a.GetNumCols()) {
00123     Error("operator +", 
00124           "Num. rows and num. columns in each matrix don't match");
00125   }
00126 
00127   for(Int_t row = 1; row <= fNumRows; row++) {
00128     for(Int_t col = 1; col <= fNumCols; col++) {
00129       (*this)(row, col) = (*this)(row, col) + a(row, col);
00130     }
00131   }
00132 
00133   return *this;
00134 }

OpMatrix OpMatrix::operator-= ( const OpMatrix a  ) 

Definition at line 138 of file OpMatrix.cxx.

References MuELoss::a, Error, fNumCols, fNumRows, GetNumCols(), and GetNumRows().

00139 {
00140   if(this->GetNumRows() != a.GetNumRows() 
00141      || this->GetNumCols() != a.GetNumCols()) {
00142     Error("operator +", 
00143           "Num. rows and num. columns in each matrix don't match");
00144   }
00145 
00146   for(Int_t row = 1; row <= fNumRows; row++) {
00147     for(Int_t col = 1; col <= fNumCols; col++) {
00148       (*this)(row, col) = (*this)(row, col) - a(row, col);
00149     }
00150   }
00151 
00152   return *this;
00153 }

OpMatrix OpMatrix::operator/= ( const OpComplex a  ) 

Definition at line 169 of file OpMatrix.cxx.

References GetNumCols(), and GetNumRows().

00170 {
00171   for(Int_t i = 1; i <= this->GetNumRows(); i++) {
00172     for(Int_t j = 1; j <= this->GetNumCols(); j++) {
00173       (*this)(i,j) = (*this)(i, j) / a;
00174     }
00175   }
00176 
00177   return *this;
00178 }

OpMatrix & OpMatrix::operator= ( const OpMatrix a  ) 

Definition at line 100 of file OpMatrix.cxx.

References MuELoss::a, fNumCols, fNumRows, FreeArray(), GetNumCols(), GetNumRows(), and InitializeArray().

00101 {
00102   if(this != &a) {
00103 
00104       this->FreeArray();
00105       this->InitializeArray(a.GetNumRows(), a.GetNumCols());
00106       
00107       for(Int_t row = 1; row <= fNumRows; row++) {
00108         for(Int_t col = 1; col <= fNumCols; col++) {
00109           (*this)(row, col) = a(row, col);
00110         }
00111       }
00112     }
00113 
00114   return *this;
00115 }

void OpMatrix::Print ( Option_t *  option = ""  )  const [virtual]

Definition at line 56 of file OpMatrix.cxx.

References GetNumCols(), and GetNumRows().

Referenced by OpProbability::PrintResults().

00057 {
00058   cout << "\n" << endl;
00059   
00060   for(Int_t row = 1; row <= GetNumRows(); row++) {
00061     for(Int_t col = 1; col <= GetNumCols(); col++) {
00062       cout << (*this)(row, col).Re() << " + i" 
00063            << (*this)(row, col).Im() << "     ";
00064     }
00065     cout << endl;
00066   }
00067   cout << "\n" << endl;
00068 }

void OpMatrix::Zero (  ) 

Definition at line 273 of file OpMatrix.cxx.

References GetNumCols(), and GetNumRows().

Referenced by OpProbability::Calculate_X_Matrix().

00274 {
00275   OpComplex z(0, 0);
00276 
00277   for(Int_t i = 1; i <= GetNumRows(); i++) {
00278     for(Int_t j = 1; j <= GetNumCols(); j++) {
00279 
00280       (*this)(i, j) = z;
00281     }
00282   }
00283 
00284 }


Member Data Documentation

Definition at line 47 of file OpMatrix.h.

Referenced by FreeArray(), InitializeArray(), operator()(), and OpMatrix().

Int_t OpMatrix::fNumCols [protected]
Int_t OpMatrix::fNumRows [protected]

The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1