CMS 3D CMS Logo

matutil.h
Go to the documentation of this file.
1 //
2 //
3 // File: hitfit/matutil.h
4 // Purpose: Define matrix types for the hitfit package, and supply a few
5 // additional operations.
6 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
7 //
8 // This file defines the types `Matrix', `Column_Vector', `Row_Vector',
9 // and `Diagonal_Matrix', to be used in hitfit code. These are based
10 // on the corresponding CLHEP matrix classes (except that we need
11 // to create our own row vector class, since CLHEP doesn't have that
12 // concept). We also provide a handful of operations that are missing
13 // in CLHEP.
14 //
15 // CMSSW File : interface/matutil.h
16 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
17 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
18 //
19 
48 #ifndef HITFIT_MATUTIL_H
49 #define HITFIT_MATUTIL_H
50 
51 // We want bounds checking.
52 #define MATRIX_BOUND_CHECK
53 
54 //#include "CLHEP/config/CLHEP.h"
55 #include "CLHEP/Matrix/Matrix.h"
56 #include "CLHEP/Matrix/Vector.h"
57 #include "CLHEP/Matrix/DiagMatrix.h"
58 
59 namespace hitfit {
60 
61  // We use these CLHEP classes as-is.
62  typedef CLHEP::HepMatrix Matrix;
63  typedef CLHEP::HepVector Column_Vector;
64  typedef CLHEP::HepDiagMatrix Diagonal_Matrix;
65 
66  // CLHEP doesn't have a row-vector class, so make our own.
67  // This is only a simple wrapper around Matrix that tries to constrain
68  // the shape to a row vector. It will raise an assertion if you try
69  // to assign to it something that isn't a row vector.
79  class Row_Vector : public Matrix
80  //
81  // Purpose: Simple Row_Vector wrapper for CLHEP matrix class.
82  //
83  {
84  public:
85  // Constructor. Gives an uninitialized 1 x cols matrix.
92  explicit Row_Vector(int cols);
93 
94  // Constructor. Gives a 1 x cols matrix, initialized to zero.
95  // The INIT argument is just a dummy; give it a value of 0.
104  explicit Row_Vector(int cols, int init);
105 
106  // Copy constructor. Will raise an assertion if M doesn't have
107  // exactly one row.
114  Row_Vector(const Matrix& m);
115 
116  // Element access.
117  // ** Note that the indexing starts from (1). **
123  const double& operator()(int col) const;
124 
130  double& operator()(int col);
131 
132  // Element access.
133  // ** Note that the indexing starts from (1,1). **
141  const double& operator()(int row, int col) const override;
142 
150  double& operator()(int row, int col) override;
151 
152  // Assignment. Will raise an assertion if M doesn't have
153  // exactly one row.
160  Row_Vector& operator=(const Matrix& m);
161  };
162 
163  // Additional operations.
164 
165  // Reset all elements of a matrix to 0.
171  void clear(CLHEP::HepGenMatrix& m);
172 
173  // Check that M has dimensions 1x1. If so, return the single element
174  // as a scalar. Otherwise, raise an assertion failure.
181  double scalar(const CLHEP::HepGenMatrix& m);
182 
183 } // namespace hitfit
184 
185 #endif // not HITFIT_MATUTIL_H
const double & operator()(int col) const
Direct element access, indexing starts from 1.
Definition: matutil.cc:75
CLHEP::HepVector Column_Vector
Definition: matutil.h:63
CLHEP::HepMatrix Matrix
Definition: matutil.h:62
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:151
Row_Vector & operator=(const Matrix &m)
Assignment operator, will raise an assertion if m doesn&#39;t have exactly one row.
Definition: matutil.cc:133
Definition: init.py:1
Row_Vector(int cols)
Constructor, instantiate an unitialized matrix.
Definition: matutil.cc:41
CLHEP::HepDiagMatrix Diagonal_Matrix
Definition: matutil.h:64
col
Definition: cuy.py:1009
Row-vector class. CLHEP doesn&#39;t have a row-vector class, so HitFit uses its own. This is only a simpl...
Definition: matutil.h:79
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:166