CLHEP 2.0.4.7 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 // 
00007 // Copyright Cornell University 1993, 1996, All Rights Reserved.
00008 // 
00009 // This software written by Nobu Katayama and Mike Smyth, Cornell University.
00010 // 
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions
00013 // are met:
00014 // 1. Redistributions of source code must retain the above copyright
00015 //    notice and author attribution, this list of conditions and the
00016 //    following disclaimer. 
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 //    notice and author attribution, this list of conditions and the
00019 //    following disclaimer in the documentation and/or other materials
00020 //    provided with the distribution.
00021 // 3. Neither the name of the University nor the names of its contributors
00022 //    may be used to endorse or promote products derived from this software
00023 //    without specific prior written permission.
00024 // 
00025 // Creation of derivative forms of this software for commercial
00026 // utilization may be subject to restriction; written permission may be
00027 // obtained from Cornell University.
00028 // 
00029 // CORNELL MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  By way
00030 // of example, but not limitation, CORNELL MAKES NO REPRESENTATIONS OR
00031 // WARRANTIES OF MERCANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT
00032 // THE USE OF THIS SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS,
00033 // COPYRIGHTS, TRADEMARKS, OR OTHER RIGHTS.  Cornell University shall not be
00034 // held liable for any liability with respect to any claim by the user or any
00035 // other party arising from use of the program.
00036 //
00037 // This is the implementation of the HepGenMatrix class.
00038 //
00039 
00040 #ifdef GNUPRAGMA
00041 #pragma implementation
00042 #endif
00043 
00044 #include <string.h>
00045 #include <cmath>
00046 #include <stdlib.h>
00047 
00048 #include "CLHEP/Matrix/defs.h"
00049 #include "CLHEP/Matrix/GenMatrix.h"
00050 #include "CLHEP/Matrix/SymMatrix.h"
00051 #include "CLHEP/Matrix/Matrix.h"
00052 
00053 #ifdef HEP_DEBUG_INLINE
00054 #include "CLHEP/Matrix/GenMatrix.icc"
00055 #endif
00056 
00057 namespace CLHEP {
00058 
00059 #ifdef HEP_THIS_FUNCTION_IS_NOT_NEEDED
00060 static void delete_array(double *m)
00061 {
00062    delete [] m;
00063 }
00064 #endif
00065 
00066 double norm_infinity(const HepGenMatrix &m) {
00067   double max=0,sum;
00068   for(int r=1;r<=m.num_row();r++) {
00069     sum=0;
00070     for(int c=1;c<=m.num_col();c++) {
00071       sum+=fabs(m(r,c));
00072     }
00073     if(sum>max) max=sum;
00074   }
00075   return max;
00076 }
00077 
00078 double norm1(const HepGenMatrix &m) {
00079   double max=0,sum;
00080   for(int c=1;c<=m.num_col();c++) {
00081     sum=0;
00082     for(int r=1;r<=m.num_row();r++)
00083       sum+=fabs(m(r,c));
00084     if(sum>max) max=sum;
00085   }
00086   return max;
00087 }
00088 
00089 double norm(const HepGenMatrix &m) {
00090   HepSymMatrix A(m.num_col(),0);
00091         
00092 // Calculate m.T*m
00093   int r;        
00094   for(r=1;r<=A.num_row();r++)
00095     for(int c=1;c<=r;c++)
00096       for(int i=1;i<=m.num_row();i++)
00097         A.fast(r,c)=m(i,r)*m(i,c);
00098   diagonalize(&A);
00099   double max=fabs(A(1,1));
00100   for(r=2;r<=A.num_row();r++)
00101     if(max<fabs(A(r,r))) max=fabs(A(r,r));
00102   return (sqrt(max));
00103 }
00104 
00105 void HepGenMatrix::error(const char *s)
00106 {
00107   std::cerr << s << std::endl;
00108   std::cerr << "---Exiting to System." << std::endl;
00109   abort();
00110 }
00111 
00112 bool HepGenMatrix::operator== ( const HepGenMatrix& o) const {
00113   if(o.num_row()!=num_row() || o.num_col()!=num_col()) return false;
00114   for (int k1=1; k1<=num_row(); k1++)
00115     for (int k2=1; k2<=num_col(); k2++)
00116       if(o(k1,k2) != (*this)(k1,k2)) return false;
00117   return true;
00118 }
00119 
00120 // implementation using pre-allocated data array
00121 // -----------------------------------------------------------------
00122 
00123 void HepGenMatrix::delete_m(int size, double* m)
00124 {
00125    if (m)
00126    {
00127      if(size > size_max)
00128        delete [] m;
00129    }
00130 }
00131 
00132 double* HepGenMatrix::new_m(int size)
00133 {
00134   /*-ap: data_array is replaced by the std::vector<double>,
00135    *     so we simply return 0 here
00136    * 
00137    *   if (size == 0) return 0;
00138    *   else {
00139    *     if ( size <= size_max ) {
00140    *       memset(data_array, 0, size * sizeof(double));
00141    *       return data_array;
00142    *     } else {
00143    *       double * nnn = new double[size];
00144    *       memset(nnn, 0, size * sizeof(double));
00145    *       return nnn;
00146    *     }
00147    *   }
00148    *-ap end 
00149    */
00150   return 0;
00151 }
00152 
00153 }  // namespace CLHEP
00154 

Generated on Thu Jul 1 22:02:30 2010 for CLHEP by  doxygen 1.4.7