7 #include "AliMatrixSq.h"
11 class AliSymMatrix : public AliMatrixSq {
15 AliSymMatrix(Int_t size);
16 AliSymMatrix(const AliSymMatrix &mat);
17 virtual ~AliSymMatrix();
19 void Clear(Option_t* option="");
22 Int_t GetSize() const {return fNrowIndex;}
23 Float_t GetDensity() const;
24 AliSymMatrix& operator=(const AliSymMatrix& src);
25 Double_t operator()(Int_t rown, Int_t coln) const;
26 Double_t& operator()(Int_t rown, Int_t coln);
28 Double_t DiagElem(Int_t r) const {return (*(const AliSymMatrix*)this)(r,r);}
29 Double_t& DiagElem(Int_t r) {return (*this)(r,r);}
31 void Print(Option_t* option="") const;
32 void AddRows(int nrows=1);
34 void Scale(Double_t coeff);
35 void MultiplyByVec(Double_t* vecIn, Double_t* vecOut) const;
36 void MultiplyByVec(TVectorD &vecIn, TVectorD &vecOut) const;
38 // ---------------------------------- Dummy methods of MatrixBase
39 virtual const Double_t *GetMatrixArray () const {return fElems;};
40 virtual Double_t *GetMatrixArray () {return (Double_t*)fElems;}
41 virtual const Int_t *GetRowIndexArray() const {Error("GetRowIndexArray","Dummy"); return 0;};
42 virtual Int_t *GetRowIndexArray() {Error("GetRowIndexArray","Dummy"); return 0;};
43 virtual const Int_t *GetColIndexArray() const {Error("GetColIndexArray","Dummy"); return 0;};
44 virtual Int_t *GetColIndexArray() {Error("GetColIndexArray","Dummy"); return 0;};
45 virtual TMatrixDBase &SetRowIndexArray(Int_t *) {Error("SetRowIndexArray","Dummy"); return *this;}
46 virtual TMatrixDBase &SetColIndexArray(Int_t *) {Error("SetColIndexArray","Dummy"); return *this;}
47 virtual TMatrixDBase &GetSub(Int_t,Int_t,Int_t,Int_t,TMatrixDBase &,Option_t *) const {Error("GetSub","Dummy"); return *((TMatrixDBase*)this);}
48 virtual TMatrixDBase &SetSub(Int_t,Int_t,const TMatrixDBase &) {Error("GetSub","Dummy"); return *this;}
49 virtual TMatrixDBase &ResizeTo (Int_t,Int_t,Int_t) {Error("ResizeTo","Dummy"); return *this;}
50 virtual TMatrixDBase &ResizeTo (Int_t,Int_t,Int_t,Int_t,Int_t) {Error("ResizeTo","Dummy"); return *this;}
52 // ----------------------------- Choleski methods ----------------------------------------
53 AliSymMatrix* DecomposeChol(); //Obtain Cholesky decomposition L matrix
54 void InvertChol(AliSymMatrix* mchol); //Invert using provided Choleski decomposition
55 Bool_t InvertChol(); //Invert
56 Bool_t SolveChol(Double_t *brhs, Bool_t invert=kFALSE);
57 Bool_t SolveChol(Double_t *brhs, Double_t *bsol,Bool_t invert=kFALSE);
58 Bool_t SolveChol(TVectorD &brhs, Bool_t invert=kFALSE);
59 Bool_t SolveChol(TVectorD &brhs, TVectorD& bsol,Bool_t invert=kFALSE);
61 int SolveSpmInv(double *vecB, Bool_t stabilize=kTRUE);
64 virtual Int_t GetIndex(Int_t row,Int_t col) const;
65 Double_t GetEl(Int_t row, Int_t col) const {return operator()(row,col);}
66 void SetEl(Int_t row, Int_t col,Double_t val) {operator()(row,col) = val;}
69 Double_t* fElems; // Elements booked by constructor
70 Double_t** fElemsAdd; // Elements (rows) added dynamicaly
72 static AliSymMatrix* fgBuffer; // buffer for fast solution
73 static Int_t fgCopyCnt; // matrix copy counter
74 ClassDef(AliSymMatrix,0) //Symmetric Matrix Class
78 //___________________________________________________________
79 inline Int_t AliSymMatrix::GetIndex(Int_t row,Int_t col) const
81 // lower triangle is actually filled
82 return ((row*(row+1))>>1) + col;
85 //___________________________________________________________
86 inline Double_t AliSymMatrix::operator()(Int_t row, Int_t col) const
89 if (row<col) Swap(row,col);
90 if (row>=fNrowIndex) return 0;
91 return (const Double_t&) (row<fNcols ? fElems[GetIndex(row,col)] : (fElemsAdd[row-fNcols])[col]);
94 //___________________________________________________________
95 inline Double_t& AliSymMatrix::operator()(Int_t row, Int_t col)
97 if (row<col) Swap(row,col);
98 if (row>=fNrowIndex) AddRows(row-fNrowIndex+1);
99 return (row<fNcols ? fElems[GetIndex(row,col)] : (fElemsAdd[row-fNcols])[col]);
102 //___________________________________________________________
103 inline void AliSymMatrix::MultiplyByVec(TVectorD &vecIn, TVectorD &vecOut) const
105 MultiplyByVec(vecIn.GetMatrixArray(), vecOut.GetMatrixArray());
108 //___________________________________________________________
109 inline void AliSymMatrix::Scale(Double_t coeff)
111 for (int i=fNrowIndex;i--;) for (int j=i;j--;) { double& el = operator()(i,j); if (el) el *= coeff;}