Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:15

0001 //
0002 //
0003 // File: hitfit/matutil.h
0004 // Purpose: Define matrix types for the hitfit package, and supply a few
0005 //          additional operations.
0006 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
0007 //
0008 // This file defines the types `Matrix', `Column_Vector', `Row_Vector',
0009 // and `Diagonal_Matrix', to be used in hitfit code.  These are based
0010 // on the corresponding CLHEP matrix classes (except that we need
0011 // to create our own row vector class, since CLHEP doesn't have that
0012 // concept).  We also provide a handful of operations that are missing
0013 // in CLHEP.
0014 //
0015 // CMSSW File      : interface/matutil.h
0016 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
0017 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0018 //
0019 
0020 /**
0021     @file matutil.h
0022 
0023     @brief Define matrix types for the HitFit package, and supply a few
0024     additional operations.
0025 
0026     This file defines the type <i>Matrix</i>, <i>Column_Vector</i>,
0027     <i>Row_Vector</i>, and <i>Diagonal_Matrix</i>, to be used in HitFit code.
0028     These are based on the corresponding CLHEP matrix classes (except that
0029     HitFit uses its own row vector class, since CLHEP doesn't have that concept).
0030     Also provided are a handful of operations that are missing in CLHEP.
0031 
0032     @author Scott Stuart Snyder <snyder@bnl.gov>
0033 
0034     @par Creation date:
0035     July 2000.
0036 
0037     @par Modification History:
0038     Apr 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0039     Imported to CMSSW.<br>
0040     Nov 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0041     Added doxygen tags for automatic generation of documentation.
0042 
0043     @par Terms of Usage:
0044     With consent for the original author (Scott Snyder).
0045 
0046  */
0047 
0048 #ifndef HITFIT_MATUTIL_H
0049 #define HITFIT_MATUTIL_H
0050 
0051 // We want bounds checking.
0052 #define MATRIX_BOUND_CHECK
0053 
0054 //#include "CLHEP/config/CLHEP.h"
0055 #include "CLHEP/Matrix/Matrix.h"
0056 #include "CLHEP/Matrix/Vector.h"
0057 #include "CLHEP/Matrix/DiagMatrix.h"
0058 
0059 namespace hitfit {
0060 
0061   // We use these CLHEP classes as-is.
0062   typedef CLHEP::HepMatrix Matrix;
0063   typedef CLHEP::HepVector Column_Vector;
0064   typedef CLHEP::HepDiagMatrix Diagonal_Matrix;
0065 
0066   // CLHEP doesn't have a row-vector class, so make our own.
0067   // This is only a simple wrapper around Matrix that tries to constrain
0068   // the shape to a row vector.  It will raise an assertion if you try
0069   // to assign to it something that isn't a row vector.
0070   /**
0071     @class Row_Vector
0072 
0073     @brief Row-vector class.  CLHEP doesn't have a row-vector class,
0074     so HitFit uses its own. This is only a simple wrapper around Matrix
0075     that tries to constrain the shape to a row vector.  It will raise
0076     an assertion if you try to assign to it something that isn't a row
0077     vector.
0078  */
0079   class Row_Vector : public Matrix
0080   //
0081   // Purpose: Simple Row_Vector wrapper for CLHEP matrix class.
0082   //
0083   {
0084   public:
0085     // Constructor.  Gives an uninitialized 1 x cols matrix.
0086     /**
0087      @brief Constructor, instantiate an unitialized
0088      \f$1 \times \mathrm{cols}\f$ matrix.
0089 
0090      @param cols The number of columns (the length of the vector).
0091    */
0092     explicit Row_Vector(int cols);
0093 
0094     // Constructor.  Gives a 1 x cols matrix, initialized to zero.
0095     // The INIT argument is just a dummy; give it a value of 0.
0096     /**
0097      @brief Constructor, instantiate an unitialized
0098      \f$1 \times \mathrm{cols}\f$ matrix, and initialized it to zero.
0099 
0100      @param cols The number of columns (the length of the vector).
0101 
0102      @param init A dummy argument, should always be zero.
0103    */
0104     explicit Row_Vector(int cols, int init);
0105 
0106     // Copy constructor.  Will raise an assertion if M doesn't have
0107     // exactly one row.
0108     /**
0109      @brief Copy constructor, will raise an assertion if <i>m</i>
0110      doesn't have exactly one row.
0111 
0112      @param m The matrix to copy, must have exactly one row.
0113    */
0114     Row_Vector(const Matrix& m);
0115 
0116     // Element access.
0117     // ** Note that the indexing starts from (1). **
0118     /**
0119      @brief Direct element access, indexing starts from 1.
0120 
0121      @param col The column to access.
0122    */
0123     const double& operator()(int col) const;
0124 
0125     /**
0126      @brief Direct element access, indexing starts from 1.
0127 
0128      @param col The column to access.
0129    */
0130     double& operator()(int col);
0131 
0132     // Element access.
0133     // ** Note that the indexing starts from (1,1). **
0134     /**
0135      @brief Direct element access, indexing starts from (1,1).
0136 
0137      @param row The row to access.
0138 
0139      @param col The column to access.
0140    */
0141     const double& operator()(int row, int col) const override;
0142 
0143     /**
0144      @brief Direct element access, indexing starts from (1,1).
0145 
0146      @param row The row to access.
0147 
0148      @param col The column to access.
0149    */
0150     double& operator()(int row, int col) override;
0151 
0152     // Assignment.  Will raise an assertion if M doesn't have
0153     // exactly one row.
0154     /**
0155      @brief Assignment operator, will raise an assertion if <i>m</i>
0156      doesn't have exactly one row.
0157 
0158      @param m The matrix to copy, must have exactly one row.
0159    */
0160     Row_Vector& operator=(const Matrix& m);
0161   };
0162 
0163   // Additional operations.
0164 
0165   // Reset all elements of a matrix to 0.
0166   /**
0167     @brief Helper function: Reset all elements of a matrix to 0.
0168 
0169     @param m The matrix to reset.
0170  */
0171   void clear(CLHEP::HepGenMatrix& m);
0172 
0173   // Check that M has dimensions 1x1.  If so, return the single element
0174   // as a scalar.  Otherwise, raise an assertion failure.
0175   /**
0176     @brief Return the \f$1 \times 1\f$ matrix as a scalar.
0177     Raise an assertion if the matris is not \f$1 \times 1\f$.
0178 
0179     @param m The matrix to convert, must be \f$1 \times 1\f$.
0180  */
0181   double scalar(const CLHEP::HepGenMatrix& m);
0182 
0183 }  // namespace hitfit
0184 
0185 #endif  // not HITFIT_MATUTIL_H