CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

GenMatrix.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // ---------------------------------------------------------------------------
00003 //
00004 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00005 //
00006 // This is the implementation of the HepGenMatrix class.
00007 //
00008 
00009 #ifdef GNUPRAGMA
00010 #pragma implementation
00011 #endif
00012 
00013 #include <string.h>
00014 #include <cmath>
00015 #include <stdlib.h>
00016 
00017 #include "CLHEP/Matrix/defs.h"
00018 #include "CLHEP/Matrix/GenMatrix.h"
00019 #include "CLHEP/Matrix/SymMatrix.h"
00020 #include "CLHEP/Matrix/Matrix.h"
00021 
00022 #ifdef HEP_DEBUG_INLINE
00023 #include "CLHEP/Matrix/GenMatrix.icc"
00024 #endif
00025 
00026 namespace CLHEP {
00027 
00028 #ifdef HEP_THIS_FUNCTION_IS_NOT_NEEDED
00029 static void delete_array(double *m)
00030 {
00031    delete [] m;
00032 }
00033 #endif
00034 
00035 double norm_infinity(const HepGenMatrix &m) {
00036   double max=0,sum;
00037   for(int r=1;r<=m.num_row();r++) {
00038     sum=0;
00039     for(int c=1;c<=m.num_col();c++) {
00040       sum+=fabs(m(r,c));
00041     }
00042     if(sum>max) max=sum;
00043   }
00044   return max;
00045 }
00046 
00047 double norm1(const HepGenMatrix &m) {
00048   double max=0,sum;
00049   for(int c=1;c<=m.num_col();c++) {
00050     sum=0;
00051     for(int r=1;r<=m.num_row();r++)
00052       sum+=fabs(m(r,c));
00053     if(sum>max) max=sum;
00054   }
00055   return max;
00056 }
00057 
00058 double norm(const HepGenMatrix &m) {
00059   HepSymMatrix A(m.num_col(),0);
00060         
00061 // Calculate m.T*m
00062   int r;        
00063   for(r=1;r<=A.num_row();r++)
00064     for(int c=1;c<=r;c++)
00065       for(int i=1;i<=m.num_row();i++)
00066         A.fast(r,c)=m(i,r)*m(i,c);
00067   diagonalize(&A);
00068   double max=fabs(A(1,1));
00069   for(r=2;r<=A.num_row();r++)
00070     if(max<fabs(A(r,r))) max=fabs(A(r,r));
00071   return (sqrt(max));
00072 }
00073 
00074 void HepGenMatrix::error(const char *s)
00075 {
00076   std::cerr << s << std::endl;
00077   std::cerr << "---Exiting to System." << std::endl;
00078   abort();
00079 }
00080 
00081 bool HepGenMatrix::operator== ( const HepGenMatrix& o) const {
00082   if(o.num_row()!=num_row() || o.num_col()!=num_col()) return false;
00083   for (int k1=1; k1<=num_row(); k1++)
00084     for (int k2=1; k2<=num_col(); k2++)
00085       if(o(k1,k2) != (*this)(k1,k2)) return false;
00086   return true;
00087 }
00088 
00089 // implementation using pre-allocated data array
00090 // -----------------------------------------------------------------
00091 
00092 void HepGenMatrix::delete_m(int size, double* m)
00093 {
00094    if (m)
00095    {
00096      if(size > size_max)
00097        delete [] m;
00098    }
00099 }
00100 
00101 double* HepGenMatrix::new_m(int )
00102 {
00103   /*-ap: data_array is replaced by the std::vector<double>,
00104    *     so we simply return 0 here
00105    * 
00106    *   if (size == 0) return 0;
00107    *   else {
00108    *     if ( size <= size_max ) {
00109    *       memset(data_array, 0, size * sizeof(double));
00110    *       return data_array;
00111    *     } else {
00112    *       double * nnn = new double[size];
00113    *       memset(nnn, 0, size * sizeof(double));
00114    *       return nnn;
00115    *     }
00116    *   }
00117    *-ap end 
00118    */
00119   return 0;
00120 }
00121 
00122 }  // namespace CLHEP
00123 

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7