CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
GenMatrix.cc
Go to the documentation of this file.
1// -*- C++ -*-
2// ---------------------------------------------------------------------------
3//
4// This file is a part of the CLHEP - a Class Library for High Energy Physics.
5//
6// This is the implementation of the HepGenMatrix class.
7//
8
9#include <iostream>
10#include <string.h>
11#include <cmath>
12#include <stdlib.h>
13
14#include "CLHEP/Matrix/GenMatrix.h"
15#include "CLHEP/Matrix/SymMatrix.h"
16#include "CLHEP/Matrix/Matrix.h"
17
18#ifdef HEP_DEBUG_INLINE
19#include "CLHEP/Matrix/GenMatrix.icc"
20#endif
21
22namespace CLHEP {
23
24#ifdef HEP_THIS_FUNCTION_IS_NOT_NEEDED
25static void delete_array(double *hm)
26{
27 delete [] hm;
28}
29#endif
30
31double norm_infinity(const HepGenMatrix &hm) {
32 double max=0,sum;
33 for(int r=1;r<=hm.num_row();r++) {
34 sum=0;
35 for(int c=1;c<=hm.num_col();c++) {
36 sum+=fabs(hm(r,c));
37 }
38 if(sum>max) max=sum;
39 }
40 return max;
41}
42
43double norm1(const HepGenMatrix &hm) {
44 double max=0,sum;
45 for(int c=1;c<=hm.num_col();c++) {
46 sum=0;
47 for(int r=1;r<=hm.num_row();r++)
48 sum+=fabs(hm(r,c));
49 if(sum>max) max=sum;
50 }
51 return max;
52}
53
54double norm(const HepGenMatrix &hm) {
55 HepSymMatrix A(hm.num_col(),0);
56
57// Calculate hm.T*hm
58 int r;
59 for(r=1;r<=A.num_row();r++)
60 for(int c=1;c<=r;c++)
61 for(int i=1;i<=hm.num_row();i++)
62 A.fast(r,c)=hm(i,r)*hm(i,c);
63 diagonalize(&A);
64 double max=fabs(A(1,1));
65 for(r=2;r<=A.num_row();r++)
66 if(max<fabs(A(r,r))) max=fabs(A(r,r));
67 return (sqrt(max));
68}
69
70void HepGenMatrix::error(const char *es)
71{
72 std::cerr << es << std::endl;
73 std::cerr << "---Exiting to System." << std::endl;
74 abort();
75}
76
78 if(o.num_row()!=num_row() || o.num_col()!=num_col()) return false;
79 for (int k1=1; k1<=num_row(); k1++)
80 for (int k2=1; k2<=num_col(); k2++)
81 if(o(k1,k2) != (*this)(k1,k2)) return false;
82 return true;
83}
84
85// implementation using pre-allocated data array
86// -----------------------------------------------------------------
87
88void HepGenMatrix::delete_m(int size, double* hm)
89{
90 if (hm)
91 {
92 if(size > size_max)
93 delete [] hm;
94 }
95}
96
98{
99 /*-ap: data_array is replaced by the std::vector<double>,
100 * so we simply return 0 here
101 *
102 * if (size == 0) return 0;
103 * else {
104 * if ( size <= size_max ) {
105 * memset(data_array, 0, size * sizeof(double));
106 * return data_array;
107 * } else {
108 * double * nnn = new double[size];
109 * memset(nnn, 0, size * sizeof(double));
110 * return nnn;
111 * }
112 * }
113 *-ap end
114 */
115 return 0;
116}
117
118} // namespace CLHEP
119
virtual int num_row() const =0
virtual bool operator==(const HepGenMatrix &) const
Definition: GenMatrix.cc:77
static void error(const char *s)
Definition: GenMatrix.cc:70
virtual int num_col() const =0
double * new_m(int size)
Definition: GenMatrix.cc:97
void delete_m(int size, double *)
Definition: GenMatrix.cc:88
int num_row() const
const double & fast(int row, int col) const
#define abort()
double norm(const HepGenMatrix &m)
Definition: GenMatrix.cc:54
double norm1(const HepGenMatrix &m)
Definition: GenMatrix.cc:43
double norm_infinity(const HepGenMatrix &m)
Definition: GenMatrix.cc:31
HepMatrix diagonalize(HepSymMatrix *s)