1 #ifndef ALIMATRIXSPARSE_H
2 #define ALIMATRIXSPARSE_H
4 #include "AliMatrixSq.h"
5 #include "AliVectorSparse.h"
8 /**********************************************************************************************/
9 /* Sparse matrix class, used as a global matrix for AliMillePede2 */
11 /* Author: ruben.shahoyan@cern.ch */
13 /**********************************************************************************************/
17 class AliMatrixSparse : public AliMatrixSq
20 AliMatrixSparse() : fVecs(0) {}
21 AliMatrixSparse(Int_t size);
22 AliMatrixSparse(const AliMatrixSparse &mat);
23 virtual ~AliMatrixSparse() {Clear();}
25 AliVectorSparse* GetRow(Int_t ir) const {return (ir<fNcols) ? fVecs[ir] : 0;}
26 AliVectorSparse* GetRowAdd(Int_t ir);
28 void Clear(Option_t* option="");
29 void Reset() {for (int i=fNcols;i--;) GetRow(i)->Reset();}
30 void Print(Option_t* option="") const;
31 AliMatrixSparse& operator=(const AliMatrixSparse& src);
32 Double_t& operator()(Int_t row,Int_t col);
33 Double_t operator()(Int_t row,Int_t col) const;
34 void SetToZero(Int_t row,Int_t col);
35 Float_t GetDensity() const;
37 Double_t DiagElem(Int_t r) const;
38 Double_t& DiagElem(Int_t r);
39 void SortIndices(Bool_t valuesToo=kFALSE);
41 void MultiplyByVec(TVectorD &vecIn, TVectorD &vecOut) const;
42 void MultiplyByVec(Double_t* vecIn, Double_t* vecOut) const;
44 void AddToRow(Int_t r, Double_t *valc,Int_t *indc,Int_t n);
48 AliVectorSparse** fVecs;
50 ClassDef(AliMatrixSparse,0)
53 //___________________________________________________
54 inline void AliMatrixSparse::MultiplyByVec(TVectorD &vecIn, TVectorD &vecOut) const
56 MultiplyByVec((Double_t*)vecIn.GetMatrixArray(),(Double_t*)vecOut.GetMatrixArray());
59 //___________________________________________________
60 inline void AliMatrixSparse::SetToZero(Int_t row,Int_t col)
62 // set existing element to 0
63 if (IsSymmetric() && col>row) Swap(row,col);
64 AliVectorSparse* rowv = GetRow(row);
65 if (rowv) rowv->SetToZero(col);
68 //___________________________________________________
69 inline Double_t AliMatrixSparse::operator()(Int_t row,Int_t col) const
71 // printf("M: find\n");
72 if (IsSymmetric() && col>row) Swap(row,col);
73 AliVectorSparse* rowv = GetRow(row);
75 return rowv->FindIndex(col);
78 //___________________________________________________
79 inline Double_t& AliMatrixSparse::operator()(Int_t row,Int_t col)
81 // printf("M: findindexAdd\n");
82 if (IsSymmetric() && col>row) Swap(row,col);
83 AliVectorSparse* rowv = GetRowAdd(row);
84 return rowv->FindIndexAdd(col);
87 //___________________________________________________
88 inline Double_t AliMatrixSparse::DiagElem(Int_t row) const
90 AliVectorSparse* rowv = GetRow(row);
92 if (IsSymmetric()) return (rowv->GetNElems()>0 && rowv->GetLastIndex()==row) ? rowv->GetLastElem() : 0.;
93 else return rowv->FindIndex(row);
97 //___________________________________________________
98 inline Double_t &AliMatrixSparse::DiagElem(Int_t row)
100 AliVectorSparse* rowv = GetRowAdd(row);
101 if (IsSymmetric()) return (rowv->GetNElems()>0 && rowv->GetLastIndex()==row) ?
102 rowv->GetLastElem() : rowv->FindIndexAdd(row);
103 else return rowv->FindIndexAdd(row);