Geant4-11
G4ErrorSymMatrix.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// Class Description:
28//
29// Simplified version of CLHEP HepSymMatrix class.
30
31// History:
32// - Imported from CLHEP and modified: P. Arce May 2007
33// --------------------------------------------------------------------
34
35#ifndef G4ErrorSymMatrix_hh
36#define G4ErrorSymMatrix_hh
37
38#include <vector>
39#include "globals.hh"
40
41class G4ErrorMatrix;
42
44{
45 public: // with description
47 // Default constructor. Gives 0x0 symmetric matrix.
48 // Another G4ErrorSymMatrix can be assigned to it.
49
50 explicit G4ErrorSymMatrix(G4int p);
52 // Constructor. Gives p x p symmetric matrix.
53 // With a second argument, the matrix is initialized. 0 means a zero
54 // matrix, 1 means the identity matrix.
55
58 // Copy and move constructor.
59
60 // Constructor from DiagMatrix
61
62 virtual ~G4ErrorSymMatrix();
63 // Destructor.
64
65 inline G4int num_row() const;
66 inline G4int num_col() const;
67 // Returns number of rows/columns.
68
69 const G4double& operator()(G4int row, G4int col) const;
71 // Read and write a G4ErrorSymMatrix element.
72 // ** Note that indexing starts from (1,1). **
73
74 const G4double& fast(G4int row, G4int col) const;
76 // fast element access.
77 // Must be row>=col;
78 // ** Note that indexing starts from (1,1). **
79
80 void assign(const G4ErrorMatrix& m2);
81 // Assigns m2 to s, assuming m2 is a symmetric matrix.
82
84 // Another form of assignment. For consistency.
85
87 // Multiply a G4ErrorSymMatrix by a floating number.
88
90 // Divide a G4ErrorSymMatrix by a floating number.
91
94 // Add or subtract a G4ErrorSymMatrix.
95
98 // Assignment and move operators.
99 // Notice that there is no G4ErrorSymMatrix = Matrix.
100
102 // unary minus, ie. flip the sign of each element.
103
105 // Returns the transpose of a G4ErrorSymMatrix (which is itself).
106
108 // Apply a function to all elements of the matrix.
109
112 // Returns m1*s*m1.T().
113
115 // temporary. test of new similarity.
116 // Returns m1.T()*s*m1.
117
118 G4ErrorSymMatrix sub(G4int min_row, G4int max_row) const;
119 // Returns a sub matrix of a G4ErrorSymMatrix.
120
121 void sub(G4int row, const G4ErrorSymMatrix& m1);
122 // Sub matrix of this G4ErrorSymMatrix is replaced with m1.
123
124 G4ErrorSymMatrix sub(G4int min_row, G4int max_row);
125 // SGI CC bug. I have to have both with/without const. I should not need
126 // one without const.
127
128 inline G4ErrorSymMatrix inverse(G4int& ifail) const;
129 // Invert a Matrix. The matrix is not changed
130 // Returns 0 when successful, otherwise non-zero.
131
132 void invert(G4int& ifail);
133 // Invert a Matrix.
134 // N.B. the contents of the matrix are replaced by the inverse.
135 // Returns ierr = 0 when successful, otherwise non-zero.
136 // This method has less overhead then inverse().
137
138 G4double determinant() const;
139 // calculate the determinant of the matrix.
140
141 G4double trace() const;
142 // calculate the trace of the matrix (sum of diagonal elements).
143
145 {
146 public:
149
150 private:
153 };
155 {
156 public:
158 inline const G4double& operator[](G4int) const;
159
160 private:
163 };
164 // helper class to implement m[i][j]
165
168 // Read or write a matrix element.
169 // While it may not look like it, you simply do m[i][j] to get an
170 // element.
171 // ** Note that the indexing starts from [0][0]. **
172
173 // Special-case inversions for 5x5 and 6x6 symmetric positive definite:
174 // These set ifail=0 and invert if the matrix was positive definite;
175 // otherwise ifail=1 and the matrix is left unaltered.
176
177 void invertCholesky5(G4int& ifail);
178 void invertCholesky6(G4int& ifail);
179
180 // Inversions for 5x5 and 6x6 forcing use of specific methods: The
181 // behavior (though not the speed) will be identical to invert(ifail).
182
183 void invertHaywood4(G4int& ifail);
184 void invertHaywood5(G4int& ifail);
185 void invertHaywood6(G4int& ifail);
186 void invertBunchKaufman(G4int& ifail);
187
188 protected:
189 inline G4int num_size() const;
190
191 private:
194 friend class G4ErrorMatrix;
195
198 friend void diag_step(G4ErrorSymMatrix* t, G4int begin, G4int end);
200 G4int end);
203 G4int row, G4int col);
204
206 const G4ErrorSymMatrix& m2);
208 const G4ErrorSymMatrix& m2);
210 const G4ErrorSymMatrix& m2);
212 const G4ErrorMatrix& m2);
213 friend G4ErrorMatrix operator*(const G4ErrorMatrix& m1,
214 const G4ErrorSymMatrix& m2);
215 // Multiply a Matrix by a Matrix or Vector.
216
217 // Returns v * v.T();
218
219 std::vector<G4double> m;
220
222 G4int size; // total number of elements
223
228
233
234 void invert4(G4int& ifail);
235 void invert5(G4int& ifail);
236 void invert6(G4int& ifail);
237};
238
239//
240// Operations other than member functions for Matrix, G4ErrorSymMatrix,
241// DiagMatrix and Vectors
242//
243
244std::ostream& operator<<(std::ostream& s, const G4ErrorSymMatrix& q);
245// Write out Matrix, G4ErrorSymMatrix, DiagMatrix and Vector into ostream.
246
252// Multiplication operators.
253// Note that m *= m1 is always faster than m = m * m1
254
256// s = s1 / t. (s /= t is faster if you can use it.)
257
261 const G4ErrorSymMatrix& s2);
262// Addition operators
263
267 const G4ErrorSymMatrix& s2);
268// subtraction operators
269
271// Direct sum of two symmetric matrices;
272
274// Find the conditon number of a symmetric matrix.
275
278// Implicit symmetric QR step with Wilkinson Shift
279
281// Diagonalize a symmetric matrix.
282// It returns the matrix U so that s_old = U * s_diag * U.T()
283
285 G4int col = 1);
286// Finds and does Householder reflection on matrix.
287
290// Does a Householder tridiagonalization of a symmetric matrix.
291
292#include "G4ErrorSymMatrix.icc"
293
294#endif
void diag_step(G4ErrorSymMatrix *t, G4int begin, G4int end)
void tridiagonal(G4ErrorSymMatrix *a, G4ErrorMatrix *hsm)
G4ErrorMatrix diagonalize(G4ErrorSymMatrix *s)
void house_with_update2(G4ErrorSymMatrix *a, G4ErrorMatrix *v, G4int row=1, G4int col=1)
G4double condition(const G4ErrorSymMatrix &m)
G4ErrorSymMatrix dsum(const G4ErrorSymMatrix &s1, const G4ErrorSymMatrix &s2)
static constexpr double m
Definition: G4SIunits.hh:109
static constexpr double s
Definition: G4SIunits.hh:154
static constexpr double m2
Definition: G4SIunits.hh:110
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
G4ErrorSymMatrix_row_const(const G4ErrorSymMatrix &, G4int)
const G4double & operator[](G4int) const
G4ErrorSymMatrix_row(G4ErrorSymMatrix &, G4int)
void invert6(G4int &ifail)
G4int num_row() const
G4ErrorSymMatrix similarityT(const G4ErrorMatrix &m1) const
friend void diag_step(G4ErrorSymMatrix *t, G4int begin, G4int end)
G4ErrorSymMatrix(G4ErrorSymMatrix &&)=default
void invertCholesky6(G4int &ifail)
void assign(const G4ErrorSymMatrix &m2)
friend G4ErrorSymMatrix operator+(const G4ErrorSymMatrix &m1, const G4ErrorSymMatrix &m2)
void invert(G4int &ifail)
void assign(const G4ErrorMatrix &m2)
G4double trace() const
const G4double & fast(G4int row, G4int col) const
void invertHaywood6(G4int &ifail)
friend void tridiagonal(G4ErrorSymMatrix *a, G4ErrorMatrix *hsm)
void invertHaywood5(G4int &ifail)
friend G4ErrorMatrix diagonalize(G4ErrorSymMatrix *s)
static G4ThreadLocal G4double adjustment5x5
static G4ThreadLocal G4double posDefFraction6x6
static const G4double CHOLESKY_CREEP_5x5
G4ErrorSymMatrix sub(G4int min_row, G4int max_row) const
G4ErrorSymMatrix apply(G4double(*f)(G4double, G4int, G4int)) const
G4ErrorSymMatrix operator-() const
const G4double & operator()(G4int row, G4int col) const
G4double & fast(G4int row, G4int col)
G4double determinant() const
G4ErrorSymMatrix & operator/=(G4double t)
G4ErrorSymMatrix inverse(G4int &ifail) const
G4ErrorSymMatrix & operator*=(G4double t)
friend G4double condition(const G4ErrorSymMatrix &m)
G4ErrorSymMatrix_row_const operator[](G4int) const
std::vector< G4double > m
static G4ThreadLocal G4double adjustment6x6
G4ErrorSymMatrix & operator=(G4ErrorSymMatrix &&)=default
void invertHaywood4(G4int &ifail)
G4ErrorSymMatrix & operator+=(const G4ErrorSymMatrix &m2)
virtual ~G4ErrorSymMatrix()
G4int num_size() const
friend void house_with_update2(G4ErrorSymMatrix *a, G4ErrorMatrix *v, G4int row, G4int col)
static const G4double CHOLESKY_CREEP_6x6
G4ErrorSymMatrix_row operator[](G4int)
G4ErrorSymMatrix & operator-=(const G4ErrorSymMatrix &m2)
static const G4double CHOLESKY_THRESHOLD_6x6
G4ErrorSymMatrix similarity(const G4ErrorMatrix &m1) const
void invert4(G4int &ifail)
void invertCholesky5(G4int &ifail)
G4int num_col() const
static G4ThreadLocal G4double posDefFraction5x5
friend void diag_step(G4ErrorSymMatrix *t, G4ErrorMatrix *u, G4int begin, G4int end)
G4ErrorSymMatrix T() const
G4ErrorSymMatrix & operator=(const G4ErrorSymMatrix &m2)
static const G4double CHOLESKY_THRESHOLD_5x5
friend G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1, const G4ErrorSymMatrix &m2)
void invert5(G4int &ifail)
G4double & operator()(G4int row, G4int col)
void invertBunchKaufman(G4int &ifail)
BasicVector3D< float > operator*(const BasicVector3D< float > &v, double a)
BasicVector3D< float > operator/(const BasicVector3D< float > &v, double a)
BasicVector3D< float > operator-(const BasicVector3D< float > &v)
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
BasicVector3D< float > operator+(const BasicVector3D< float > &v)
#define G4ThreadLocal
Definition: tls.hh:77