Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:03:28

0001 // -*- C++ -*-
0002 // CLASSDOC OFF
0003 // ---------------------------------------------------------------------------
0004 // CLASSDOC ON
0005 //
0006 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
0007 //
0008 //   Although Vector and Matrix class are very much related, I like the typing
0009 //   information I get by making them different types. It is usually an error
0010 //   to use a Matrix where a Vector is expected, except in the case that the
0011 //   Matrix is a single column.  But this case can be taken care of by using
0012 //   constructors as conversions.  For this same reason, I don't want to make
0013 //   a Vector a derived class of Matrix.
0014 //
0015 
0016 #ifndef _Vector_H_
0017 #define _Vector_H_
0018 
0019 #include "CLHEP/Matrix/defs.h"
0020 #include "CLHEP/Matrix/GenMatrix.h"
0021 
0022 namespace CLHEP {
0023 
0024 class HepRandom;
0025 
0026 class HepMatrix;
0027 class HepSymMatrix;
0028 class HepDiagMatrix;
0029 class Hep3Vector;
0030 
0031 /**
0032  * @author
0033  * @ingroup matrix
0034  */
0035 class HepVector : public HepGenMatrix {
0036 public:
0037    inline HepVector();
0038    // Default constructor. Gives vector of length 0.
0039    // Another Vector can be assigned to it.
0040 
0041    explicit HepVector(int p);
0042    HepVector(int p, int);
0043    // Constructor. Gives vector of length p.
0044 
0045    HepVector(int p, HepRandom &r);
0046 
0047    HepVector(const HepVector &v);
0048    HepVector(const HepMatrix &m);
0049    // Copy constructors.
0050    // Note that there is an assignment operator for v = Hep3Vector.
0051 
0052    virtual ~HepVector();
0053    // Destructor.
0054 
0055    inline const double & operator()(int row) const;
0056    inline double & operator()(int row);
0057    // Read or write a matrix element. 
0058    // ** Note that the indexing starts from (1). **
0059    
0060    inline const double & operator[](int row) const;
0061    inline double & operator[](int row);
0062    // Read and write an element of a Vector.
0063    // ** Note that the indexing starts from [0]. **
0064 
0065    virtual const double & operator()(int row, int col) const;
0066    virtual double & operator()(int row, int col);
0067    // Read or write a matrix element. 
0068    // ** Note that the indexing starts from (1,1). **
0069    // Allows accessing Vector using GenMatrix
0070 
0071    HepVector & operator*=(double t);
0072    // Multiply a Vector by a floating number. 
0073 
0074    HepVector & operator/=(double t); 
0075    // Divide a Vector by a floating number.
0076 
0077    HepVector & operator+=( const HepMatrix &v2);
0078    HepVector & operator+=( const HepVector &v2);
0079    HepVector & operator-=( const HepMatrix &v2);
0080    HepVector & operator-=( const HepVector &v2);
0081    // Add or subtract a Vector.
0082 
0083    HepVector & operator=( const HepVector &hm2);
0084    // Assignment operators.
0085 
0086    HepVector& operator=(const HepMatrix &);
0087    HepVector& operator=(const Hep3Vector &);
0088    // assignment operators from other classes.
0089 
0090    HepVector operator- () const;
0091    // unary minus, ie. flip the sign of each element.
0092 
0093    HepVector apply(double (*f)(double, int)) const;
0094    // Apply a function to all elements.
0095 
0096    HepVector sub(int min_row, int max_row) const;
0097    // Returns a sub vector.
0098    HepVector sub(int min_row, int max_row);
0099    // SGI CC bug. I have to have both with/without const. I should not need
0100    // one without const.
0101 
0102    void sub(int row, const HepVector &v1);
0103    // Replaces a sub vector of a Vector with v1.
0104 
0105    inline double normsq() const;
0106    // Returns norm squared.
0107 
0108    inline double norm() const;
0109    // Returns norm.
0110 
0111    virtual int num_row() const;
0112    // Returns number of rows.
0113 
0114    virtual int num_col() const;
0115    // Number of columns. Always returns 1. Provided for compatibility with
0116    // GenMatrix. 
0117 
0118    HepMatrix T() const;
0119    // Returns the transpose of a Vector. Note that the returning type is
0120    // Matrix.
0121 
0122    friend inline void swap(HepVector &v1, HepVector &v2);
0123    // Swaps two vectors.
0124 
0125 protected:
0126    virtual int num_size() const;
0127 
0128 private:
0129    virtual void invert(int&);
0130    // produces an error. Demanded by GenMatrix
0131 
0132    friend class HepDiagMatrix;
0133    friend class HepSymMatrix;
0134    friend class HepMatrix;
0135    // friend classes
0136 
0137    friend double dot(const HepVector &v1, const HepVector &v2);
0138    // f = v1 * v2;
0139 
0140    friend HepVector operator+(const HepVector &v1, const HepVector &v2);
0141    friend HepVector operator-(const HepVector &v1, const HepVector &v2);
0142    friend HepVector operator*(const HepSymMatrix &hm1, const HepVector &hm2);
0143    friend HepVector operator*(const HepDiagMatrix &hm1, const HepVector &hm2);
0144    friend HepMatrix operator*(const HepVector &hm1, const HepMatrix &hm2);
0145    friend HepVector operator*(const HepMatrix &hm1, const HepVector &hm2);
0146 
0147    friend HepVector solve(const HepMatrix &a, const HepVector &v);
0148    friend void tridiagonal(HepSymMatrix *a,HepMatrix *hsm);
0149    friend void row_house(HepMatrix *,const HepMatrix &, double, int, int,
0150              int, int);
0151    friend void row_house(HepMatrix *,const HepVector &, double, int, int);
0152    friend void back_solve(const HepMatrix &R, HepVector *b);
0153    friend void col_house(HepMatrix *,const HepMatrix &,double, int, int,
0154              int, int);
0155    friend HepVector house(const HepSymMatrix &a,int row,int col);
0156    friend HepVector house(const HepMatrix &a,int row,int col);
0157    friend void house_with_update(HepMatrix *a,int row,int col);
0158    friend HepSymMatrix vT_times_v(const HepVector &v);
0159    friend HepVector qr_solve(HepMatrix *, const HepVector &);
0160 
0161 #ifdef DISABLE_ALLOC
0162    std::vector<double > m;
0163 #else
0164    std::vector<double,Alloc<double,25> > m;
0165 #endif
0166    int nrow;
0167 };
0168 
0169 //
0170 // Operations other than member functions
0171 //
0172 
0173 std::ostream& operator<<(std::ostream &s, const HepVector &v);
0174 // Write out Matrix, SymMatrix, DiagMatrix and Vector into ostream.
0175 
0176 HepVector operator*(const HepMatrix &hm1, const HepVector &hm2);
0177 HepVector operator*(double t, const HepVector &v1);
0178 HepVector operator*(const HepVector &v1, double t);
0179 // Multiplication operators.
0180 // Note that m *= x is always faster than m = m * x.
0181 
0182 HepVector operator/(const HepVector &v1, double t);
0183 // Divide by a real number.
0184 
0185 HepVector operator+(const HepMatrix &hm1, const HepVector &v2);
0186 HepVector operator+(const HepVector &v1, const HepMatrix &hm2);
0187 HepVector operator+(const HepVector &v1, const HepVector &v2);
0188 // Addition operators
0189 
0190 HepVector operator-(const HepMatrix &hm1, const HepVector &v2);
0191 HepVector operator-(const HepVector &v1, const HepMatrix &hm2);
0192 HepVector operator-(const HepVector &v1, const HepVector &v2);
0193 // subtraction operators
0194 
0195 HepVector dsum(const HepVector &s1, const HepVector &s2);
0196 // Direct sum of two vectors;
0197 
0198 }  // namespace CLHEP
0199 
0200 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0201 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0202 using namespace CLHEP;
0203 #endif
0204 
0205 #include "CLHEP/Matrix/Vector.icc"
0206 
0207 #endif /*!_Vector_H*/