ROOTPWA
TCMatrix.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright 2009 Sebastian Neubert
4 //
5 // This file is part of rootpwa
6 //
7 // rootpwa is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // rootpwa is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
19 //
21 
22 
23 #include "TCMatrix.h"
24 
25 
26 using namespace std;
27 
28 
30 
31 
32 TCMatrix::TCMatrix(const int i,
33  const int j)
34 : _re(i, j),
35  _im(i, j)
36 { }
37 
38 
39 void
40 TCMatrix::set(const int i,
41  const int j,
42  const complex<double>& c)
43 {
44  _re[i][j] = c.real();
45  _im[i][j] = c.imag();
46 }
47 void
48 TCMatrix::set(const int i,
49  const int j,
50  const TComplex& c)
51 {
52  _re[i][j] = c.Re();
53  _im[i][j] = c.Im();
54 }
55 
57 TCMatrix::t() const {
58  TMatrixD ReT(TMatrixD::kTransposed,_re);
59  TMatrixD ImT(TMatrixD::kTransposed,_im);
60  return TCMatrix(ReT,ImT);
61 }
62 
65  TMatrixD ReT(TMatrixD::kTransposed,_re);
66  TMatrixD ImT(_im.GetNcols(),_im.GetNrows());
67  for(int i=0;i<_im.GetNrows();++i){
68  for(int j=0;j<_im.GetNcols();++j){
69  ImT[j][i]= -(_im[i][j]);
70  }
71  }
72  return TCMatrix(ReT,ImT);
73 }
74 
75 
76 TCMatrix operator *(const TCMatrix& c1, const TCMatrix& c2){
77  TCMatrix result(c1.nrows(),c2.ncols());
78  for(int i=0;i<result.nrows();++i){
79  for(int j=0;j<result.ncols();++j){
80  TComplex elem(0,0);
81  for(int k=0;k<c1.ncols();++k){
82  elem+=(c1(i,k))*(c2(k,j));
83  }
84  result.set(i,j,elem);
85  }
86  }
87  return result;
88 }
89 
90 TCMatrix operator -(const TCMatrix& c1, const TCMatrix& c2){
91  TMatrixD Re(c1._re-c2._re);
92  TMatrixD Im(c1._im-c2._im);
93  return TCMatrix(Re,Im);
94 }
95 
96 TCMatrix operator +(const TCMatrix& c1, const TCMatrix& c2){
97  TMatrixD Re(c1._re+c2._re);
98  TMatrixD Im(c1._im+c2._im);
99  return TCMatrix(Re,Im);
100 }