CLHEP VERSION 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 //   Although Vector and Matrix class are very much related, I like the typing
00009 //   information I get by making them different types. It is usually an error
00010 //   to use a Matrix where a Vector is expected, except in the case that the
00011 //   Matrix is a single column.  But this case can be taken care of by using
00012 //   constructors as conversions.  For this same reason, I don't want to make
00013 //   a Vector a derived class of Matrix.
00014 //
00015 
00016 #ifndef _Vector_H_
00017 #define _Vector_H_
00018 
00019 #ifdef GNUPRAGMA
00020 #pragma interface
00021 #endif
00022 
00023 #include "CLHEP/Matrix/defs.h"
00024 #include "CLHEP/Matrix/GenMatrix.h"
00025 
00026 namespace CLHEP {
00027 
00028 class HepRandom;
00029 
00030 class HepMatrix;
00031 class HepSymMatrix;
00032 class HepDiagMatrix;
00033 class Hep3Vector;
00034 
00039 class HepVector : public HepGenMatrix {
00040 public:
00041    inline HepVector();
00042    // Default constructor. Gives vector of length 0.
00043    // Another Vector can be assigned to it.
00044 
00045    explicit HepVector(int p);
00046    HepVector(int p, int);
00047    // Constructor. Gives vector of length p.
00048 
00049    HepVector(int p, HepRandom &r);
00050 
00051    HepVector(const HepVector &v);
00052    HepVector(const HepMatrix &m);
00053    // Copy constructors.
00054    // Note that there is an assignment operator for v = Hep3Vector.
00055 
00056    virtual ~HepVector();
00057    // Destructor.
00058 
00059    inline const double & operator()(int row) const;
00060    inline double & operator()(int row);
00061    // Read or write a matrix element. 
00062    // ** Note that the indexing starts from (1). **
00063    
00064    inline const double & operator[](int row) const;
00065    inline double & operator[](int row);
00066    // Read and write an element of a Vector.
00067    // ** Note that the indexing starts from [0]. **
00068 
00069    virtual const double & operator()(int row, int col) const;
00070    virtual double & operator()(int row, int col);
00071    // Read or write a matrix element. 
00072    // ** Note that the indexing starts from (1,1). **
00073    // Allows accessing Vector using GenMatrix
00074 
00075    HepVector & operator*=(double t);
00076    // Multiply a Vector by a floating number. 
00077 
00078    HepVector & operator/=(double t); 
00079    // Divide a Vector by a floating number.
00080 
00081    HepVector & operator+=( const HepMatrix &v2);
00082    HepVector & operator+=( const HepVector &v2);
00083    HepVector & operator-=( const HepMatrix &v2);
00084    HepVector & operator-=( const HepVector &v2);
00085    // Add or subtract a Vector.
00086 
00087    HepVector & operator=( const HepVector &m2);
00088    // Assignment operators.
00089 
00090    HepVector& operator=(const HepMatrix &);
00091    HepVector& operator=(const Hep3Vector &);
00092    // assignment operators from other classes.
00093 
00094    HepVector operator- () const;
00095    // unary minus, ie. flip the sign of each element.
00096 
00097    HepVector apply(double (*f)(double, int)) const;
00098    // Apply a function to all elements.
00099 
00100    HepVector sub(int min_row, int max_row) const;
00101    // Returns a sub vector.
00102    HepVector sub(int min_row, int max_row);
00103    // SGI CC bug. I have to have both with/without const. I should not need
00104    // one without const.
00105 
00106    void sub(int row, const HepVector &v1);
00107    // Replaces a sub vector of a Vector with v1.
00108 
00109    inline double normsq() const;
00110    // Returns norm squared.
00111 
00112    inline double norm() const;
00113    // Returns norm.
00114 
00115    virtual int num_row() const;
00116    // Returns number of rows.
00117 
00118    virtual int num_col() const;
00119    // Number of columns. Always returns 1. Provided for compatibility with
00120    // GenMatrix. 
00121 
00122    HepMatrix T() const;
00123    // Returns the transpose of a Vector. Note that the returning type is
00124    // Matrix.
00125 
00126    friend inline void swap(HepVector &v1, HepVector &v2);
00127    // Swaps two vectors.
00128 
00129 protected:
00130    virtual int num_size() const;
00131 
00132 private:
00133    virtual void invert(int&);
00134    // produces an error. Demanded by GenMatrix
00135 
00136    friend class HepDiagMatrix;
00137    friend class HepSymMatrix;
00138    friend class HepMatrix;
00139    // friend classes
00140 
00141    friend double dot(const HepVector &v1, const HepVector &v2);
00142    // f = v1 * v2;
00143 
00144    friend HepVector operator+(const HepVector &v1, const HepVector &v2);
00145    friend HepVector operator-(const HepVector &v1, const HepVector &v2);
00146    friend HepVector operator*(const HepSymMatrix &m1, const HepVector &m2);
00147    friend HepVector operator*(const HepDiagMatrix &m1, const HepVector &m2);
00148    friend HepMatrix operator*(const HepVector &m1, const HepMatrix &m2);
00149    friend HepVector operator*(const HepMatrix &m1, const HepVector &m2);
00150 
00151    friend HepVector solve(const HepMatrix &a, const HepVector &v);
00152    friend void tridiagonal(HepSymMatrix *a,HepMatrix *hsm);
00153    friend void row_house(HepMatrix *,const HepMatrix &, double, int, int,
00154                          int, int);
00155    friend void row_house(HepMatrix *,const HepVector &, double, int, int);
00156    friend void back_solve(const HepMatrix &R, HepVector *b);
00157    friend void col_house(HepMatrix *,const HepMatrix &,double, int, int,
00158                          int, int);
00159    friend HepVector house(const HepSymMatrix &a,int row,int col);
00160    friend HepVector house(const HepMatrix &a,int row,int col);
00161    friend void house_with_update(HepMatrix *a,int row,int col);
00162    friend HepSymMatrix vT_times_v(const HepVector &v);
00163    friend HepVector qr_solve(HepMatrix *, const HepVector &);
00164 
00165 #ifdef DISABLE_ALLOC
00166    std::vector<double > m;
00167 #else
00168    std::vector<double,Alloc<double,25> > m;
00169 #endif
00170    int nrow;
00171 };
00172 
00173 //
00174 // Operations other than member functions
00175 //
00176 
00177 std::ostream& operator<<(std::ostream &s, const HepVector &v);
00178 // Write out Matrix, SymMatrix, DiagMatrix and Vector into ostream.
00179 
00180 HepVector operator*(const HepMatrix &m1, const HepVector &m2);
00181 HepVector operator*(double t, const HepVector &v1);
00182 HepVector operator*(const HepVector &v1, double t);
00183 // Multiplication operators.
00184 // Note that m *= x is always faster than m = m * x.
00185 
00186 HepVector operator/(const HepVector &v1, double t);
00187 // Divide by a real number.
00188 
00189 HepVector operator+(const HepMatrix &m1, const HepVector &v2);
00190 HepVector operator+(const HepVector &v1, const HepMatrix &m2);
00191 HepVector operator+(const HepVector &v1, const HepVector &v2);
00192 // Addition operators
00193 
00194 HepVector operator-(const HepMatrix &m1, const HepVector &v2);
00195 HepVector operator-(const HepVector &v1, const HepMatrix &m2);
00196 HepVector operator-(const HepVector &v1, const HepVector &v2);
00197 // subtraction operators
00198 
00199 HepVector dsum(const HepVector &s1, const HepVector &s2);
00200 // Direct sum of two vectors;
00201 
00202 }  // namespace CLHEP
00203 
00204 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00205 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00206 using namespace CLHEP;
00207 #endif
00208 
00209 #include "CLHEP/Matrix/Vector.icc"
00210 
00211 #endif 

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7