00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef G4ErrorMatrix_hh
00037 #define G4ErrorMatrix_hh
00038
00039 #include <vector>
00040
00041 class G4ErrorSymMatrix;
00042
00043 typedef std::vector<G4double >::iterator G4ErrorMatrixIter;
00044 typedef std::vector<G4double >::const_iterator G4ErrorMatrixConstIter;
00045
00046 class G4ErrorMatrix
00047 {
00048
00049 public:
00050
00051 G4ErrorMatrix();
00052
00053
00054
00055 G4ErrorMatrix(G4int p, G4int q);
00056
00057
00058 G4ErrorMatrix(G4int p, G4int q, G4int i);
00059
00060
00061
00062
00063 G4ErrorMatrix(const G4ErrorMatrix &m1);
00064
00065
00066 G4ErrorMatrix(const G4ErrorSymMatrix &m1);
00067
00068
00069 virtual ~G4ErrorMatrix();
00070
00071
00072 inline virtual G4int num_row() const;
00073
00074
00075 inline virtual G4int num_col() const;
00076
00077
00078 inline virtual const G4double & operator()(G4int row, G4int col) const;
00079 inline virtual G4double & operator()(G4int row, G4int col);
00080
00081
00082
00083 G4ErrorMatrix & operator *= (G4double t);
00084
00085
00086 G4ErrorMatrix & operator /= (G4double t);
00087
00088
00089 G4ErrorMatrix & operator += ( const G4ErrorMatrix &m2);
00090 G4ErrorMatrix & operator += ( const G4ErrorSymMatrix &m2);
00091 G4ErrorMatrix & operator -= ( const G4ErrorMatrix &m2);
00092 G4ErrorMatrix & operator -= ( const G4ErrorSymMatrix &m2);
00093
00094
00095
00096 G4ErrorMatrix & operator = ( const G4ErrorMatrix &m2);
00097 G4ErrorMatrix & operator = ( const G4ErrorSymMatrix &m2);
00098
00099
00100 G4ErrorMatrix operator- () const;
00101
00102
00103 G4ErrorMatrix apply(G4double (*f)(G4double, G4int, G4int)) const;
00104
00105
00106 G4ErrorMatrix T() const;
00107
00108
00109 G4ErrorMatrix sub(G4int min_row, G4int max_row,
00110 G4int min_col, G4int max_col) const;
00111
00112
00113
00114 void sub(G4int row, G4int col, const G4ErrorMatrix &m1);
00115
00116
00117
00118 inline G4ErrorMatrix inverse(G4int& ierr) const;
00119
00120
00121
00122 virtual void invert(G4int& ierr);
00123
00124
00125
00126
00127
00128 G4double determinant() const;
00129
00130
00131 G4double trace() const;
00132
00133
00134 class G4ErrorMatrix_row
00135 {
00136 typedef std::vector<G4double >::const_iterator G4ErrorMatrixConstIter;
00137 public:
00138 inline G4ErrorMatrix_row(G4ErrorMatrix&,G4int);
00139 G4double & operator[](G4int);
00140 private:
00141 G4ErrorMatrix& _a;
00142 G4int _r;
00143 };
00144 class G4ErrorMatrix_row_const
00145 {
00146 public:
00147 inline G4ErrorMatrix_row_const (const G4ErrorMatrix&,G4int);
00148 const G4double & operator[](G4int) const;
00149 private:
00150 const G4ErrorMatrix& _a;
00151 G4int _r;
00152 };
00153
00154
00155 inline G4ErrorMatrix_row operator[] (G4int);
00156 inline const G4ErrorMatrix_row_const operator[] (G4int) const;
00157
00158
00159
00160
00161 protected:
00162
00163 virtual inline G4int num_size() const;
00164 virtual void invertHaywood4(G4int& ierr);
00165 virtual void invertHaywood5(G4int& ierr);
00166 virtual void invertHaywood6(G4int& ierr);
00167
00168 public:
00169
00170 static void error(const char *s);
00171
00172 private:
00173
00174 friend class G4ErrorMatrix_row;
00175 friend class G4ErrorMatrix_row_const;
00176 friend class G4ErrorSymMatrix;
00177
00178
00179 friend G4ErrorMatrix operator+(const G4ErrorMatrix &m1,
00180 const G4ErrorMatrix &m2);
00181 friend G4ErrorMatrix operator-(const G4ErrorMatrix &m1,
00182 const G4ErrorMatrix &m2);
00183 friend G4ErrorMatrix operator*(const G4ErrorMatrix &m1,
00184 const G4ErrorMatrix &m2);
00185 friend G4ErrorMatrix operator*(const G4ErrorMatrix &m1,
00186 const G4ErrorSymMatrix &m2);
00187 friend G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1,
00188 const G4ErrorMatrix &m2);
00189 friend G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1,
00190 const G4ErrorSymMatrix &m2);
00191
00192
00193
00194
00195 friend G4ErrorMatrix qr_solve(G4ErrorMatrix *, const G4ErrorMatrix &b);
00196 friend void tridiagonal(G4ErrorSymMatrix *a,G4ErrorMatrix *hsm);
00197 friend void row_house(G4ErrorMatrix *,const G4ErrorMatrix &, G4double,
00198 G4int, G4int, G4int, G4int);
00199 friend void back_solve(const G4ErrorMatrix &R, G4ErrorMatrix *b);
00200 friend void col_givens(G4ErrorMatrix *A, G4double c,
00201 G4double s, G4int k1, G4int k2,
00202 G4int rowmin, G4int rowmax);
00203
00204
00205 friend void row_givens(G4ErrorMatrix *A, G4double c,
00206 G4double s, G4int k1, G4int k2,
00207 G4int colmin, G4int colmax);
00208 friend void col_house(G4ErrorMatrix *,const G4ErrorMatrix &, G4double,
00209 G4int, G4int, G4int, G4int);
00210 friend void house_with_update(G4ErrorMatrix *a,G4int row,G4int col);
00211 friend void house_with_update(G4ErrorMatrix *a,G4ErrorMatrix *v,
00212 G4int row, G4int col);
00213 friend void house_with_update2(G4ErrorSymMatrix *a,G4ErrorMatrix *v,
00214 G4int row, G4int col);
00215
00216 G4int dfact_matrix(G4double &det, G4int *ir);
00217
00218
00219
00220
00221 G4int dfinv_matrix(G4int *ir);
00222
00223
00224 std::vector<G4double > m;
00225
00226 G4int nrow, ncol;
00227 G4int size;
00228 };
00229
00230
00231
00232 G4ErrorMatrix operator*(const G4ErrorMatrix &m1, const G4ErrorMatrix &m2);
00233 G4ErrorMatrix operator*(G4double t, const G4ErrorMatrix &m1);
00234 G4ErrorMatrix operator*(const G4ErrorMatrix &m1, G4double t);
00235
00236
00237
00238 G4ErrorMatrix operator/(const G4ErrorMatrix &m1, G4double t);
00239
00240
00241 G4ErrorMatrix operator+(const G4ErrorMatrix &m1, const G4ErrorMatrix &m2);
00242
00243
00244
00245 G4ErrorMatrix operator-(const G4ErrorMatrix &m1, const G4ErrorMatrix &m2);
00246
00247
00248
00249 G4ErrorMatrix dsum(const G4ErrorMatrix&, const G4ErrorMatrix&);
00250
00251
00252
00253
00254 std::ostream& operator<<(std::ostream &s, const G4ErrorMatrix &q);
00255
00256
00257
00258
00259
00260
00261 G4ErrorMatrix qr_solve(const G4ErrorMatrix &A, const G4ErrorMatrix &b);
00262 G4ErrorMatrix qr_solve(G4ErrorMatrix *A, const G4ErrorMatrix &b);
00263
00264
00265
00266 G4ErrorMatrix qr_inverse(const G4ErrorMatrix &A);
00267 G4ErrorMatrix qr_inverse(G4ErrorMatrix *A);
00268
00269
00270
00271
00272
00273 void qr_decomp(G4ErrorMatrix *A, G4ErrorMatrix *hsm);
00274 G4ErrorMatrix qr_decomp(G4ErrorMatrix *A);
00275
00276
00277 void back_solve(const G4ErrorMatrix &R, G4ErrorMatrix *b);
00278
00279
00280
00281
00282 void col_house(G4ErrorMatrix *a, const G4ErrorMatrix &v, G4double vnormsq,
00283 G4int row, G4int col, G4int row_start, G4int col_start);
00284 void col_house(G4ErrorMatrix *a, const G4ErrorMatrix &v, G4int row, G4int col,
00285 G4int row_start, G4int col_start);
00286
00287
00288 void col_givens(G4ErrorMatrix *A, G4double c, G4double s,
00289 G4int k1, G4int k2, G4int row_min=1, G4int row_max=0);
00290
00291
00292 void row_givens(G4ErrorMatrix *A, G4double c, G4double s,
00293 G4int k1, G4int k2, G4int col_min=1, G4int col_max=0);
00294
00295
00296 void givens(G4double a, G4double b, G4double *c, G4double *s);
00297
00298
00299
00300
00301 void house_with_update(G4ErrorMatrix *a, G4int row=1, G4int col=1);
00302 void house_with_update(G4ErrorMatrix *a, G4ErrorMatrix *v,
00303 G4int row=1, G4int col=1);
00304
00305
00306 void row_house(G4ErrorMatrix *a, const G4ErrorMatrix &v, G4double vnormsq,
00307 G4int row, G4int col, G4int row_start, G4int col_start);
00308 void row_house(G4ErrorMatrix *a, const G4ErrorMatrix &v, G4int row, G4int col,
00309 G4int row_start, G4int col_start);
00310
00311
00312 #include "G4ErrorMatrix.icc"
00313
00314 #endif