]>
Commit | Line | Data |
---|---|---|
8a9ab0eb | 1 | #ifndef ALIMATRIXSPARSE_H |
2 | #define ALIMATRIXSPARSE_H | |
3 | ||
4 | #include "AliMatrixSq.h" | |
de34b538 | 5 | #include "AliVectorSparse.h" |
8a9ab0eb | 6 | |
7 | ||
de34b538 | 8 | /**********************************************************************************************/ |
9 | /* Sparse matrix class, used as a global matrix for AliMillePede2 */ | |
10 | /* */ | |
11 | /* Author: ruben.shahoyan@cern.ch */ | |
12 | /* */ | |
13 | /**********************************************************************************************/ | |
8a9ab0eb | 14 | |
8a9ab0eb | 15 | |
8a9ab0eb | 16 | // |
17 | class AliMatrixSparse : public AliMatrixSq | |
18 | { | |
19 | public: | |
20 | AliMatrixSparse() : fVecs(0) {} | |
21 | AliMatrixSparse(Int_t size); | |
22 | AliMatrixSparse(const AliMatrixSparse &mat); | |
23 | virtual ~AliMatrixSparse() {Clear();} | |
24 | // | |
25 | AliVectorSparse* GetRow(Int_t ir) const {return (ir<fNcols) ? fVecs[ir] : 0;} | |
26 | AliVectorSparse* GetRowAdd(Int_t ir); | |
3bc5dd7d | 27 | // |
28 | virtual Int_t GetSize() const {return fNrows;} | |
29 | virtual Int_t GetNRows() const {return fNrows;} | |
30 | virtual Int_t GetNCols() const {return fNcols;} | |
31 | // | |
8a9ab0eb | 32 | void Clear(Option_t* option=""); |
33 | void Reset() {for (int i=fNcols;i--;) GetRow(i)->Reset();} | |
34 | void Print(Option_t* option="") const; | |
35 | AliMatrixSparse& operator=(const AliMatrixSparse& src); | |
36 | Double_t& operator()(Int_t row,Int_t col); | |
37 | Double_t operator()(Int_t row,Int_t col) const; | |
f748efd7 | 38 | void SetToZero(Int_t row,Int_t col); |
8a9ab0eb | 39 | Float_t GetDensity() const; |
40 | // | |
41 | Double_t DiagElem(Int_t r) const; | |
42 | Double_t& DiagElem(Int_t r); | |
43 | void SortIndices(Bool_t valuesToo=kFALSE); | |
44 | // | |
551c9e69 | 45 | void MultiplyByVec(const TVectorD &vecIn, TVectorD &vecOut) const; |
46 | void MultiplyByVec(const Double_t* vecIn, Double_t* vecOut) const; | |
de34b538 | 47 | // |
48 | void AddToRow(Int_t r, Double_t *valc,Int_t *indc,Int_t n); | |
8a9ab0eb | 49 | // |
50 | protected: | |
51 | // | |
52 | AliVectorSparse** fVecs; | |
53 | // | |
54 | ClassDef(AliMatrixSparse,0) | |
55 | }; | |
56 | ||
de34b538 | 57 | //___________________________________________________ |
551c9e69 | 58 | inline void AliMatrixSparse::MultiplyByVec(const TVectorD &vecIn, TVectorD &vecOut) const |
de34b538 | 59 | { |
339fbe23 | 60 | // multiplication |
de34b538 | 61 | MultiplyByVec((Double_t*)vecIn.GetMatrixArray(),(Double_t*)vecOut.GetMatrixArray()); |
62 | } | |
63 | ||
8a9ab0eb | 64 | //___________________________________________________ |
f748efd7 | 65 | inline void AliMatrixSparse::SetToZero(Int_t row,Int_t col) |
8a9ab0eb | 66 | { |
67 | // set existing element to 0 | |
68 | if (IsSymmetric() && col>row) Swap(row,col); | |
69 | AliVectorSparse* rowv = GetRow(row); | |
f748efd7 | 70 | if (rowv) rowv->SetToZero(col); |
8a9ab0eb | 71 | } |
72 | ||
73 | //___________________________________________________ | |
74 | inline Double_t AliMatrixSparse::operator()(Int_t row,Int_t col) const | |
75 | { | |
76 | // printf("M: find\n"); | |
77 | if (IsSymmetric() && col>row) Swap(row,col); | |
78 | AliVectorSparse* rowv = GetRow(row); | |
79 | if (!rowv) return 0; | |
80 | return rowv->FindIndex(col); | |
81 | } | |
82 | ||
83 | //___________________________________________________ | |
84 | inline Double_t& AliMatrixSparse::operator()(Int_t row,Int_t col) | |
85 | { | |
86 | // printf("M: findindexAdd\n"); | |
87 | if (IsSymmetric() && col>row) Swap(row,col); | |
88 | AliVectorSparse* rowv = GetRowAdd(row); | |
3bc5dd7d | 89 | if (col>=fNcols) fNcols = col+1; |
8a9ab0eb | 90 | return rowv->FindIndexAdd(col); |
91 | } | |
92 | ||
93 | //___________________________________________________ | |
94 | inline Double_t AliMatrixSparse::DiagElem(Int_t row) const | |
95 | { | |
339fbe23 | 96 | // get diag elem |
8a9ab0eb | 97 | AliVectorSparse* rowv = GetRow(row); |
98 | if (!rowv) return 0; | |
99 | if (IsSymmetric()) return (rowv->GetNElems()>0 && rowv->GetLastIndex()==row) ? rowv->GetLastElem() : 0.; | |
100 | else return rowv->FindIndex(row); | |
101 | // | |
102 | } | |
103 | ||
104 | //___________________________________________________ | |
105 | inline Double_t &AliMatrixSparse::DiagElem(Int_t row) | |
106 | { | |
339fbe23 | 107 | // get diag elem |
8a9ab0eb | 108 | AliVectorSparse* rowv = GetRowAdd(row); |
3bc5dd7d | 109 | if (row>=fNcols) fNcols = row+1; |
110 | if (IsSymmetric()) { | |
111 | return (rowv->GetNElems()>0 && rowv->GetLastIndex()==row) ? | |
8a9ab0eb | 112 | rowv->GetLastElem() : rowv->FindIndexAdd(row); |
3bc5dd7d | 113 | } |
8a9ab0eb | 114 | else return rowv->FindIndexAdd(row); |
115 | // | |
116 | } | |
117 | ||
de34b538 | 118 | |
8a9ab0eb | 119 | #endif |
120 |