File indexing completed on 2025-01-18 09:54:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 #ifndef _SYMMatrix_H_
0066 #define _SYMMatrix_H_
0067
0068 #include <vector>
0069
0070 #include "CLHEP/Matrix/defs.h"
0071 #include "CLHEP/Matrix/GenMatrix.h"
0072 #include "CLHEP/Utility/thread_local.h"
0073
0074 namespace CLHEP {
0075
0076 class HepRandom;
0077
0078 class HepMatrix;
0079 class HepDiagMatrix;
0080 class HepVector;
0081
0082
0083
0084
0085
0086 class HepSymMatrix : public HepGenMatrix {
0087 public:
0088 inline HepSymMatrix();
0089
0090
0091
0092 explicit HepSymMatrix(int p);
0093 HepSymMatrix(int p, int);
0094
0095
0096
0097
0098 HepSymMatrix(int p, HepRandom &r);
0099
0100 HepSymMatrix(const HepSymMatrix &hm1);
0101
0102
0103 HepSymMatrix(const HepDiagMatrix &hm1);
0104
0105
0106 virtual ~HepSymMatrix();
0107
0108
0109 inline int num_row() const;
0110 inline int num_col() const;
0111
0112
0113 const double & operator()(int row, int col) const;
0114 double & operator()(int row, int col);
0115
0116
0117
0118 const double & fast(int row, int col) const;
0119 double & fast(int row, int col);
0120
0121
0122
0123
0124 void assign(const HepMatrix &hm2);
0125
0126
0127 void assign(const HepSymMatrix &hm2);
0128
0129
0130 HepSymMatrix & operator*=(double t);
0131
0132
0133 HepSymMatrix & operator/=(double t);
0134
0135
0136 HepSymMatrix & operator+=( const HepSymMatrix &hm2);
0137 HepSymMatrix & operator+=( const HepDiagMatrix &hm2);
0138 HepSymMatrix & operator-=( const HepSymMatrix &hm2);
0139 HepSymMatrix & operator-=( const HepDiagMatrix &hm2);
0140
0141
0142 HepSymMatrix & operator=( const HepSymMatrix &hm2);
0143 HepSymMatrix & operator=( const HepDiagMatrix &hm2);
0144
0145
0146 HepSymMatrix operator- () const;
0147
0148
0149 HepSymMatrix T() const;
0150
0151
0152 HepSymMatrix apply(double (*f)(double, int, int)) const;
0153
0154
0155 HepSymMatrix similarity(const HepMatrix &hm1) const;
0156 HepSymMatrix similarity(const HepSymMatrix &hm1) const;
0157
0158
0159 HepSymMatrix similarityT(const HepMatrix &hm1) const;
0160
0161
0162
0163 double similarity(const HepVector &v) const;
0164
0165
0166 HepSymMatrix sub(int min_row, int max_row) const;
0167
0168 void sub(int row, const HepSymMatrix &hm1);
0169
0170 HepSymMatrix sub(int min_row, int max_row);
0171
0172
0173
0174 inline HepSymMatrix inverse(int &ifail) const;
0175
0176
0177
0178 void invert(int &ifail);
0179
0180
0181
0182
0183
0184 inline void invert();
0185
0186
0187 inline HepSymMatrix inverse() const;
0188
0189
0190 double determinant() const;
0191
0192
0193 double trace() const;
0194
0195
0196 class HepSymMatrix_row {
0197 public:
0198 inline HepSymMatrix_row(HepSymMatrix&,int);
0199 inline double & operator[](int);
0200 private:
0201 HepSymMatrix& _a;
0202 int _r;
0203 };
0204 class HepSymMatrix_row_const {
0205 public:
0206 inline HepSymMatrix_row_const(const HepSymMatrix&,int);
0207 inline const double & operator[](int) const;
0208 private:
0209 const HepSymMatrix& _a;
0210 int _r;
0211 };
0212
0213
0214 inline HepSymMatrix_row operator[] (int);
0215 inline HepSymMatrix_row_const operator[] (int) const;
0216
0217
0218
0219
0220
0221
0222
0223
0224 void invertCholesky5 (int &ifail);
0225 void invertCholesky6 (int &ifail);
0226
0227
0228
0229 void invertHaywood4 (int & ifail);
0230 void invertHaywood5 (int &ifail);
0231 void invertHaywood6 (int &ifail);
0232 void invertBunchKaufman (int &ifail);
0233
0234 protected:
0235 inline int num_size() const;
0236
0237 private:
0238 friend class HepSymMatrix_row;
0239 friend class HepSymMatrix_row_const;
0240 friend class HepMatrix;
0241 friend class HepDiagMatrix;
0242
0243 friend void tridiagonal(HepSymMatrix *a,HepMatrix *hsm);
0244 friend double condition(const HepSymMatrix &m);
0245 friend void diag_step(HepSymMatrix *t,int begin,int end);
0246 friend void diag_step(HepSymMatrix *t,HepMatrix *u,int begin,int end);
0247 friend HepMatrix diagonalize(HepSymMatrix *s);
0248 friend HepVector house(const HepSymMatrix &a,int row,int col);
0249 friend void house_with_update2(HepSymMatrix *a,HepMatrix *v,int row,int col);
0250
0251 friend HepSymMatrix operator+(const HepSymMatrix &hm1,
0252 const HepSymMatrix &hm2);
0253 friend HepSymMatrix operator-(const HepSymMatrix &hm1,
0254 const HepSymMatrix &hm2);
0255 friend HepMatrix operator*(const HepSymMatrix &hm1, const HepSymMatrix &hm2);
0256 friend HepMatrix operator*(const HepSymMatrix &hm1, const HepMatrix &hm2);
0257 friend HepMatrix operator*(const HepMatrix &hm1, const HepSymMatrix &hm2);
0258 friend HepVector operator*(const HepSymMatrix &hm1, const HepVector &hm2);
0259
0260
0261 friend HepSymMatrix vT_times_v(const HepVector &v);
0262
0263
0264 #ifdef DISABLE_ALLOC
0265 std::vector<double > m;
0266 #else
0267 std::vector<double,Alloc<double,25> > m;
0268 #endif
0269 int nrow;
0270 int size_;
0271
0272 static CLHEP_THREAD_LOCAL double posDefFraction5x5;
0273 static CLHEP_THREAD_LOCAL double adjustment5x5;
0274 static const double CHOLESKY_THRESHOLD_5x5;
0275 static const double CHOLESKY_CREEP_5x5;
0276
0277 static CLHEP_THREAD_LOCAL double posDefFraction6x6;
0278 static CLHEP_THREAD_LOCAL double adjustment6x6;
0279 static const double CHOLESKY_THRESHOLD_6x6;
0280 static const double CHOLESKY_CREEP_6x6;
0281
0282 void invert4 (int & ifail);
0283 void invert5 (int & ifail);
0284 void invert6 (int & ifail);
0285
0286 };
0287
0288
0289
0290
0291
0292
0293 std::ostream& operator<<(std::ostream &s, const HepSymMatrix &q);
0294
0295
0296 HepMatrix operator*(const HepMatrix &hm1, const HepSymMatrix &hm2);
0297 HepMatrix operator*(const HepSymMatrix &hm1, const HepMatrix &hm2);
0298 HepMatrix operator*(const HepSymMatrix &hm1, const HepSymMatrix &hm2);
0299 HepSymMatrix operator*(double t, const HepSymMatrix &s1);
0300 HepSymMatrix operator*(const HepSymMatrix &s1, double t);
0301
0302
0303
0304 HepSymMatrix operator/(const HepSymMatrix &hm1, double t);
0305
0306
0307 HepMatrix operator+(const HepMatrix &hm1, const HepSymMatrix &s2);
0308 HepMatrix operator+(const HepSymMatrix &s1, const HepMatrix &hm2);
0309 HepSymMatrix operator+(const HepSymMatrix &s1, const HepSymMatrix &s2);
0310
0311
0312 HepMatrix operator-(const HepMatrix &hm1, const HepSymMatrix &s2);
0313 HepMatrix operator-(const HepSymMatrix &hm1, const HepMatrix &hm2);
0314 HepSymMatrix operator-(const HepSymMatrix &s1, const HepSymMatrix &s2);
0315
0316
0317 HepSymMatrix dsum(const HepSymMatrix &s1, const HepSymMatrix &s2);
0318
0319
0320 double condition(const HepSymMatrix &m);
0321
0322
0323 void diag_step(HepSymMatrix *t, int begin, int end);
0324 void diag_step(HepSymMatrix *t, HepMatrix *u, int begin, int end);
0325
0326
0327 HepMatrix diagonalize(HepSymMatrix *s);
0328
0329
0330
0331 HepVector house(const HepSymMatrix &a, int row=1, int col=1);
0332 void house_with_update2(HepSymMatrix *a, HepMatrix *v, int row=1, int col=1);
0333
0334
0335 void tridiagonal(HepSymMatrix *a, HepMatrix *hsm);
0336 HepMatrix tridiagonal(HepSymMatrix *a);
0337
0338
0339 }
0340
0341 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0342
0343 using namespace CLHEP;
0344 #endif
0345
0346 #ifndef HEP_DEBUG_INLINE
0347 #include "CLHEP/Matrix/SymMatrix.icc"
0348 #endif
0349
0350 #endif