Diana Software
QMatrixCArray.cc
Go to the documentation of this file.
1 #include <TString.h>
2 #include "QMatrixCArray.hh"
3 
4 ClassImp(Diana::QMatrixCArray)
5 
7 
9 : fDataOwner(true),
10  fSize(0),
11  fNMatrix(0),
12  fNRow(0),
13  fNCol(0),
14  fData(0)
15 {}
17  : fDataOwner(true),
18  fSize(0),
19  fNMatrix(0),
20  fNRow(0),
21  fNCol(0),
22  fData(0)
23 {
24  Resize(in.fNMatrix,in.fNRow,in.fNCol);
25  memcpy(fData,in.fData,fSize*sizeof(double));
26 }
27 QMatrixCArray::QMatrixCArray(UInt_t nMatrix,UInt_t nRow,UInt_t nCol)
28  : fDataOwner(true),
29  fSize(0),
30  fNMatrix(0),
31  fNRow(0),
32  fNCol(0),
33  fData(0)
34 {
35  Resize(nMatrix,nRow,nCol);
36 }
37 
39  Clear();
40 }
43  if(fDataOwner && fData)
45  fNMatrix=0;
46  fSize=0;
47  fNRow=0;
48  fNCol=0;
49  fData=0;
50 }
52  Clear();
53  Resize(in.fNMatrix,in.fNRow,in.fNCol);
54  memcpy(fData,in.fData,fSize*sizeof(double));
55  return *this;
56 }
57 void QMatrixCArray::Resize(UInt_t nMatrix,UInt_t nRow,UInt_t nCol){
58  if(nMatrix == GetNMatrix() && nRow == GetNRow() && nCol == GetNCol())
59  return;
60  if(!fDataOwner)
61  DianaThrow(QError(QERR_SIZE_NOT_MATCH,__FILE__,__LINE__,
62  "Attemp to resize QMatrixCArray when not the "
63  "data owner"));
65  fSize=nMatrix*nRow*nCol*2;
67  fNMatrix=nMatrix;
68  fNRow=nRow;
69  fNCol=nCol;
70 }
71 void QMatrixCArray::Initialize(double Re,double Im) {
72  for(UInt_t i=0;i<fSize;i+=2){
73  fData[i]=Re;fData[i+1]=Im;
74  }
75 }
77  Initialize(Val.Re(),Val.Im());
78 }
80  if(idx>fNMatrix)
81  DianaThrow(QError(QERR_SIZE_NOT_MATCH,__FILE__,__LINE__,
82  Form("Matrix index out of bounds (%ui>%ui)",
83  idx,fNMatrix)));
84  QMatrixC A((gsl_complex *)fData+idx*fNCol,fNRow,fNCol,fNMatrix*fNCol);
85  return A;
86 }
87 const QMatrixC QMatrixCArray::GetMatrix(UInt_t idx) const {
88  if(idx>fNMatrix)
89  DianaThrow(QError(QERR_SIZE_NOT_MATCH,__FILE__,__LINE__,
90  Form("Matrix index out of bounds (%ui>%ui)",
91  idx,fNMatrix)));
92  QMatrixC A((gsl_complex *)fData+idx*fNCol,fNRow,fNCol,fNMatrix*fNCol);
93  return A;
94 }
95 Diana::QVectorC QMatrixCArray::GetVector(UInt_t idx1,UInt_t idx2){
96  if(idx1>fNRow || idx2>fNCol)
97  DianaThrow(QError(QERR_SIZE_NOT_MATCH,__FILE__,__LINE__,
98  Form("Vector indices out of bounds (%ui,%ui)>"
99  "(%ui,%ui)",idx1,idx2,fNRow,fNCol)));
100  QVectorC A((gsl_complex *)fData+idx1*fNCol*fNMatrix+idx2,fNMatrix,fNCol);
101  return A;
102 }
103 const Diana::QVectorC QMatrixCArray::GetVector(UInt_t idx1,UInt_t idx2) const{
104  if(idx1>fNRow || idx2>fNCol)
105  DianaThrow(QError(QERR_SIZE_NOT_MATCH,__FILE__,__LINE__,
106  Form("Vector indices out of bounds (%ui,%ui)>"
107  "(%ui,%ui)",idx1,idx2,fNRow,fNCol)));
108  QVectorC A((gsl_complex *)fData+idx1*fNCol*fNMatrix+idx2,fNMatrix,fNCol);
109  return A;
110 }
112  for(UInt_t i=0;i<GetNMatrix();i++){
113  QMatrixC C=GetMatrix(i);
114  C.Invert();
115  }
116 }
118  for(UInt_t i=1;i<GetNMatrix();i++){
119  QMatrixC C=GetMatrix(i);
120  std::cout<< "CholeskyDecomp Matrix " << i << std::endl;
121  C.CholeskyDecompose();
122  }
123 }
125 ::CholeskySolveX(const Diana::QVectorC &Y,Diana::QVectorC &X) const {
126  if(Y.Size()!=GetNMatrix()*GetNRow())
127  DianaThrow(QError(QERR_SIZE_NOT_MATCH,__FILE__,__LINE__,
128  "CholeskySolveX: Dimensions do not match!"));
129  X.Resize(Y.Size());
130  for(UInt_t i=0;i<GetNMatrix();i++){
131  Diana::QVectorC subX=X.GetSubVector(GetNRow(),i*GetNRow());
132  Diana::QVectorC subY=Y.GetSubVector(GetNRow(),i*GetNRow());
133  Diana::QMatrixC subM=GetMatrix(i);
134  subM.CholeskySolveX(Y,X);
135  }
136 }
double Im(const Diana::QComplex &z)
Function to get the imag part.
Definition: QComplex.cc:262
double Re(const Diana::QComplex &z)
Function to get the real part.
Definition: QComplex.cc:260
#define DianaThrow(obj)
Definition: QDianaDebug.hh:26
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
@ QERR_SIZE_NOT_MATCH
Definition: QError.hh:31
ClassImp(Diana::QMatrixCArray) Q_BEGIN_NAMESPACE QMatrixCArray
Definition: QMatrixCArray.cc:4
double Im() const
Definition: QComplex.cc:73
double Re() const
Definition: QComplex.cc:72
error class with error type and description
Definition: QError.hh:115
An array of complex matrices that have been laid out in memory.
UInt_t fNMatrix
Number of identical matrices.
UInt_t fSize
Number of double values in fData.
Diana::QVectorC GetVector(UInt_t idx1, UInt_t idx2)
Return the vector of values in the (idx1,idx2) position.
Double_t * fData
Pointer to the head of the data.
void Resize(UInt_t nMatrix, UInt_t nRow, UInt_t nCol)
Resize, destroys all data in memory.
UInt_t fNRow
Number of rows in each matrix.
void CholeskyDecompose()
Cholesky decompose the matrices in place.
UInt_t fNCol
Number of columns in each matrix.
UInt_t GetNRow() const
Return the number of rows in each matrix.
QMatrixCArray()
Default ctor.
void Initialize(double Re, double Im=0)
Initialize the values of the matrix.
void Invert()
Invert the matrices in place.
QMatrixC GetMatrix(UInt_t idx)
Return the vector of values in the (idx1,idx2) position.
virtual ~QMatrixCArray()
UInt_t GetNMatrix() const
Return the number of matrices stored.
UInt_t GetNCol() const
Return the number of columns in each matrix.
virtual void CholeskySolveX(const Diana::QVectorC &Y, Diana::QVectorC &X) const
Solve the equation AX=Y for X.
virtual void Clear()
Clear the data in memory.
const QMatrixCArray & operator=(const QMatrixCArray &in)
Interface for complex matrices in Diana analysis.
Definition: QMatrixC.hh:27
virtual const QMatrixC & CholeskyDecompose()
Cholesky Decomposition.
Definition: QMatrixC.cc:537
const QMatrixC & Invert()
inverse
Definition: QMatrixC.cc:453
Interface for complex vectors in Diana analysis.
Definition: QVectorC.hh:25
static void ArrayFree(double *array)
Definition: QVector.cc:72
static double * ArrayAlloc(const UInt_t size)
Definition: QVector.cc:32