CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
matutil.cc
Go to the documentation of this file.
1 //
2 // $Id: matutil.cc,v 1.1 2011/05/26 09:47:00 mseidel Exp $
3 //
4 // File: src/matutil.cc
5 // Purpose: Define matrix types for the hitfit package, and supply a few
6 // additional operations.
7 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
8 //
9 // CMSSW File : src/matutil.cc
10 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
11 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
12 //
13 
39 #include <cassert>
40 
41 
42 namespace hitfit {
43 
44 
46 //
47 // Purpose: Constructor.
48 // Does not initialize the vector.
49 //
50 // Inputs:
51 // cols - The length of the vector.
52 //
53  : Matrix (1, cols)
54 {
55 }
56 
57 
58 Row_Vector::Row_Vector (int cols, int /*init*/)
59 //
60 // Purpose: Constructor.
61 // Initializes the vector to 0.
62 //
63 // Inputs:
64 // cols - The length of the vector.
65 // init - Dummy. Should be 0.
66 //
67  : Matrix (1, cols, 0)
68 {
69 }
70 
71 
73 //
74 // Purpose: Copy constructor.
75 // Raises an assertion if M does not have exactly one row.
76 //
77 // Inputs:
78 // m - The matrix to copy.
79 // Must have exactly one row.
80 //
81  : Matrix (m)
82 {
83  assert (m.num_row() == 1);
84 }
85 
86 
87 const double& Row_Vector::operator() (int col) const
88 //
89 // Purpose: Element access.
90 //
91 // Inputs:
92 // col - The column to access. Indexing starts with 1.
93 //
94 // Returns:
95 // Const reference to the selected element.
96 //
97 {
98  return HepMatrix::operator() (1, col);
99 }
100 
101 
102 double& Row_Vector::operator() (int col)
103 //
104 // Purpose: Element access.
105 //
106 // Inputs:
107 // col - The column to access. Indexing starts with 1.
108 //
109 // Returns:
110 // Reference to the selected element.
111 //
112 {
113  return HepMatrix::operator() (1, col);
114 }
115 
116 
117 const double& Row_Vector::operator() (int row, int col) const
118 //
119 // Purpose: Element access.
120 //
121 // Inputs:
122 // row - The row to access. Indexing starts with 1.
123 // col - The column to access. Indexing starts with 1.
124 //
125 // Returns:
126 // Const reference to the selected element.
127 //
128 {
129  return HepMatrix::operator() (row, col);
130 }
131 
132 
133 double& Row_Vector::operator() (int row, int col)
134 //
135 // Purpose: Element access.
136 //
137 // Inputs:
138 // row - The row to access. Indexing starts with 1.
139 // col - The column to access. Indexing starts with 1.
140 //
141 // Returns:
142 // Reference to the selected element.
143 //
144 {
145  return HepMatrix::operator() (row, col);
146 }
147 
148 
150 //
151 // Purpose: Assignment operator.
152 // Raises an assertion if M does not have exactly one row.
153 //
154 // Inputs:
155 // m - The matrix to copy.
156 // Must have exactly one row.
157 //
158 // Returns:
159 // This object.
160 //
161 {
162  assert (m.num_row() == 1);
163  *((Matrix*)this) = m;
164  return *this;
165 }
166 
167 
168 void clear (CLHEP::HepGenMatrix& m)
169 //
170 // Purpose: Reset the matrix M to zero.
171 //
172 // Inputs:
173 // m - The matrix to reset.
174 //
175 {
176  int nrow = m.num_row();
177  int ncol = m.num_col();
178  for (int i=1; i <= nrow; i++)
179  for (int j=1; j <= ncol; j++)
180  m(i, j) = 0;
181 }
182 
183 
184 double scalar (const CLHEP::HepGenMatrix& m)
185 //
186 // Purpose: Return the 1x1 matrix M as a scalar.
187 // Raise an assertion if M is not 1x1.
188 //
189 // Inputs:
190 // m - The matrix to convert.
191 // Must be 1x1.
192 //
193 // Returns:
194 // m(1,1)
195 //
196 {
197  assert (m.num_row() == 1 && m.num_col() == 1);
198  return m (1, 1);
199 }
200 
201 
202 } // namespace hitfit
int i
Definition: DBlmapReader.cc:9
Define matrix types for the HitFit package, and supply a few additional operations.
CLHEP::HepMatrix Matrix
Definition: matutil.h:66
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
Row_Vector & operator=(const Matrix &m)
Assignment operator, will raise an assertion if m doesn&#39;t have exactly one row.
Definition: matutil.cc:149
const double & operator()(int col) const
Direct element access, indexing starts from 1.
Definition: matutil.cc:87
int j
Definition: DBlmapReader.cc:9
Row_Vector(int cols)
Constructor, instantiate an unitialized matrix.
Definition: matutil.cc:45
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:84
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:184