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