CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Vector.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // CLASSDOC OFF
00003 // ---------------------------------------------------------------------------
00004 // CLASSDOC ON
00005 //
00006 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00007 // 
00008 // 
00009 // Copyright Cornell University 1993, 1996, All Rights Reserved.
00010 // 
00011 // This software written by Nobu Katayama and Mike Smyth, Cornell University.
00012 // 
00013 // Redistribution and use in source and binary forms, with or without
00014 // modification, are permitted provided that the following conditions
00015 // are met:
00016 // 1. Redistributions of source code must retain the above copyright
00017 //    notice and author attribution, this list of conditions and the
00018 //    following disclaimer. 
00019 // 2. Redistributions in binary form must reproduce the above copyright
00020 //    notice and author attribution, this list of conditions and the
00021 //    following disclaimer in the documentation and/or other materials
00022 //    provided with the distribution.
00023 // 3. Neither the name of the University nor the names of its contributors
00024 //    may be used to endorse or promote products derived from this software
00025 //    without specific prior written permission.
00026 // 
00027 // Creation of derivative forms of this software for commercial
00028 // utilization may be subject to restriction; written permission may be
00029 // obtained from Cornell University.
00030 // 
00031 // CORNELL MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  By way
00032 // of example, but not limitation, CORNELL MAKES NO REPRESENTATIONS OR
00033 // WARRANTIES OF MERCANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT
00034 // THE USE OF THIS SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS,
00035 // COPYRIGHTS, TRADEMARKS, OR OTHER RIGHTS.  Cornell University shall not be
00036 // held liable for any liability with respect to any claim by the user or any
00037 // other party arising from use of the program.
00038 //
00039 //   Although Vector and Matrix class are very much related, I like the typing
00040 //   information I get by making them different types. It is usually an error
00041 //   to use a Matrix where a Vector is expected, except in the case that the
00042 //   Matrix is a single column.  But this case can be taken care of by using
00043 //   constructors as conversions.  For this same reason, I don't want to make
00044 //   a Vector a derived class of Matrix.
00045 //
00046 
00047 #ifndef _Vector_H_
00048 #define _Vector_H_
00049 
00050 #ifdef GNUPRAGMA
00051 #pragma interface
00052 #endif
00053 
00054 #include "CLHEP/Matrix/defs.h"
00055 #include "CLHEP/Matrix/GenMatrix.h"
00056 
00057 namespace CLHEP {
00058 
00059 class HepRandom;
00060 
00061 class HepMatrix;
00062 class HepSymMatrix;
00063 class HepDiagMatrix;
00064 class Hep3Vector;
00065 
00070 class HepVector : public HepGenMatrix {
00071 public:
00072    inline HepVector();
00073    // Default constructor. Gives vector of length 0.
00074    // Another Vector can be assigned to it.
00075 
00076    explicit HepVector(int p);
00077    HepVector(int p, int);
00078    // Constructor. Gives vector of length p.
00079 
00080    HepVector(int p, HepRandom &r);
00081 
00082    HepVector(const HepVector &v);
00083    HepVector(const HepMatrix &m);
00084    // Copy constructors.
00085    // Note that there is an assignment operator for v = Hep3Vector.
00086 
00087    virtual ~HepVector();
00088    // Destructor.
00089 
00090    inline const double & operator()(int row) const;
00091    inline double & operator()(int row);
00092    // Read or write a matrix element. 
00093    // ** Note that the indexing starts from (1). **
00094    
00095    inline const double & operator[](int row) const;
00096    inline double & operator[](int row);
00097    // Read and write an element of a Vector.
00098    // ** Note that the indexing starts from [0]. **
00099 
00100    virtual const double & operator()(int row, int col) const;
00101    virtual double & operator()(int row, int col);
00102    // Read or write a matrix element. 
00103    // ** Note that the indexing starts from (1,1). **
00104    // Allows accessing Vector using GenMatrix
00105 
00106    HepVector & operator*=(double t);
00107    // Multiply a Vector by a floating number. 
00108 
00109    HepVector & operator/=(double t); 
00110    // Divide a Vector by a floating number.
00111 
00112    HepVector & operator+=( const HepMatrix &v2);
00113    HepVector & operator+=( const HepVector &v2);
00114    HepVector & operator-=( const HepMatrix &v2);
00115    HepVector & operator-=( const HepVector &v2);
00116    // Add or subtract a Vector.
00117 
00118    HepVector & operator=( const HepVector &m2);
00119    // Assignment operators.
00120 
00121    HepVector& operator=(const HepMatrix &);
00122    HepVector& operator=(const Hep3Vector &);
00123    // assignment operators from other classes.
00124 
00125    HepVector operator- () const;
00126    // unary minus, ie. flip the sign of each element.
00127 
00128    HepVector apply(double (*f)(double, int)) const;
00129    // Apply a function to all elements.
00130 
00131    HepVector sub(int min_row, int max_row) const;
00132    // Returns a sub vector.
00133    HepVector sub(int min_row, int max_row);
00134    // SGI CC bug. I have to have both with/without const. I should not need
00135    // one without const.
00136 
00137    void sub(int row, const HepVector &v1);
00138    // Replaces a sub vector of a Vector with v1.
00139 
00140    inline double normsq() const;
00141    // Returns norm squared.
00142 
00143    inline double norm() const;
00144    // Returns norm.
00145 
00146    virtual int num_row() const;
00147    // Returns number of rows.
00148 
00149    virtual int num_col() const;
00150    // Number of columns. Always returns 1. Provided for compatibility with
00151    // GenMatrix. 
00152 
00153    HepMatrix T() const;
00154    // Returns the transpose of a Vector. Note that the returning type is
00155    // Matrix.
00156 
00157    friend inline void swap(HepVector &v1, HepVector &v2);
00158    // Swaps two vectors.
00159 
00160 protected:
00161    virtual int num_size() const;
00162 
00163 private:
00164    virtual void invert(int&);
00165    // produces an error. Demanded by GenMatrix
00166 
00167    friend class HepDiagMatrix;
00168    friend class HepSymMatrix;
00169    friend class HepMatrix;
00170    // friend classes
00171 
00172    friend double dot(const HepVector &v1, const HepVector &v2);
00173    // f = v1 * v2;
00174 
00175    friend HepVector operator+(const HepVector &v1, const HepVector &v2);
00176    friend HepVector operator-(const HepVector &v1, const HepVector &v2);
00177    friend HepVector operator*(const HepSymMatrix &m1, const HepVector &m2);
00178    friend HepVector operator*(const HepDiagMatrix &m1, const HepVector &m2);
00179    friend HepMatrix operator*(const HepVector &m1, const HepMatrix &m2);
00180    friend HepVector operator*(const HepMatrix &m1, const HepVector &m2);
00181 
00182    friend HepVector solve(const HepMatrix &a, const HepVector &v);
00183    friend void tridiagonal(HepSymMatrix *a,HepMatrix *hsm);
00184    friend void row_house(HepMatrix *,const HepMatrix &, double, int, int,
00185                          int, int);
00186    friend void row_house(HepMatrix *,const HepVector &, double, int, int);
00187    friend void back_solve(const HepMatrix &R, HepVector *b);
00188    friend void col_house(HepMatrix *,const HepMatrix &,double, int, int,
00189                          int, int);
00190    friend HepVector house(const HepSymMatrix &a,int row,int col);
00191    friend HepVector house(const HepMatrix &a,int row,int col);
00192    friend void house_with_update(HepMatrix *a,int row,int col);
00193    friend HepSymMatrix vT_times_v(const HepVector &v);
00194    friend HepVector qr_solve(HepMatrix *, const HepVector &);
00195 
00196 #ifdef DISABLE_ALLOC
00197    std::vector<double > m;
00198 #else
00199    std::vector<double,Alloc<double,25> > m;
00200 #endif
00201    int nrow;
00202 };
00203 
00204 //
00205 // Operations other than member functions
00206 //
00207 
00208 std::ostream& operator<<(std::ostream &s, const HepVector &v);
00209 // Write out Matrix, SymMatrix, DiagMatrix and Vector into ostream.
00210 
00211 HepVector operator*(const HepMatrix &m1, const HepVector &m2);
00212 HepVector operator*(double t, const HepVector &v1);
00213 HepVector operator*(const HepVector &v1, double t);
00214 // Multiplication operators.
00215 // Note that m *= x is always faster than m = m * x.
00216 
00217 HepVector operator/(const HepVector &v1, double t);
00218 // Divide by a real number.
00219 
00220 HepVector operator+(const HepMatrix &m1, const HepVector &v2);
00221 HepVector operator+(const HepVector &v1, const HepMatrix &m2);
00222 HepVector operator+(const HepVector &v1, const HepVector &v2);
00223 // Addition operators
00224 
00225 HepVector operator-(const HepMatrix &m1, const HepVector &v2);
00226 HepVector operator-(const HepVector &v1, const HepMatrix &m2);
00227 HepVector operator-(const HepVector &v1, const HepVector &v2);
00228 // subtraction operators
00229 
00230 HepVector dsum(const HepVector &s1, const HepVector &s2);
00231 // Direct sum of two vectors;
00232 
00233 }  // namespace CLHEP
00234 
00235 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00236 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00237 using namespace CLHEP;
00238 #endif
00239 
00240 #include "CLHEP/Matrix/Vector.icc"
00241 
00242 #endif 

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