Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:19

0001 //
0002 //
0003 // File: src/matutil.cc
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 // CMSSW File      : src/matutil.cc
0009 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
0010 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0011 //
0012 
0013 /**
0014     @file matutil.cc
0015 
0016     @brief Define matrix types for the HitFit package, and supply a few
0017     additional operations.  See the documentation for the header file
0018     matutil.h for details.
0019 
0020     @author Scott Stuart Snyder <snyder@bnl.gov>
0021 
0022     @par Creation date:
0023     July 2000.
0024 
0025     @par Modification History:
0026     Apr 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0027     Imported to CMSSW.<br>
0028     Nov 2009: Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>:
0029     Added doxygen tags for automatic generation of documentation.
0030 
0031     @par Terms of Usage:
0032     With consent for the original author (Scott Snyder).
0033 
0034  */
0035 
0036 #include "TopQuarkAnalysis/TopHitFit/interface/matutil.h"
0037 #include <cassert>
0038 
0039 namespace hitfit {
0040 
0041   Row_Vector::Row_Vector(int cols)
0042       //
0043       // Purpose: Constructor.
0044       //          Does not initialize the vector.
0045       //
0046       // Inputs:
0047       //   cols -        The length of the vector.
0048       //
0049       : Matrix(1, cols) {}
0050 
0051   Row_Vector::Row_Vector(int cols, int /*init*/)
0052       //
0053       // Purpose: Constructor.
0054       //          Initializes the vector to 0.
0055       //
0056       // Inputs:
0057       //   cols -        The length of the vector.
0058       //   init -        Dummy.  Should be 0.
0059       //
0060       : Matrix(1, cols, 0) {}
0061 
0062   Row_Vector::Row_Vector(const Matrix& m)
0063       //
0064       // Purpose: Copy constructor.
0065       //          Raises an assertion if M does not have exactly one row.
0066       //
0067       // Inputs:
0068       //   m -           The matrix to copy.
0069       //                 Must have exactly one row.
0070       //
0071       : Matrix(m) {
0072     assert(m.num_row() == 1);
0073   }
0074 
0075   const double& Row_Vector::operator()(int col) const
0076   //
0077   // Purpose: Element access.
0078   //
0079   // Inputs:
0080   //   col -         The column to access.  Indexing starts with 1.
0081   //
0082   // Returns:
0083   //   Const reference to the selected element.
0084   //
0085   {
0086     return HepMatrix::operator()(1, col);
0087   }
0088 
0089   double& Row_Vector::operator()(int col)
0090   //
0091   // Purpose: Element access.
0092   //
0093   // Inputs:
0094   //   col -         The column to access.  Indexing starts with 1.
0095   //
0096   // Returns:
0097   //   Reference to the selected element.
0098   //
0099   {
0100     return HepMatrix::operator()(1, col);
0101   }
0102 
0103   const double& Row_Vector::operator()(int row, int col) const
0104   //
0105   // Purpose: Element access.
0106   //
0107   // Inputs:
0108   //   row -         The row to access.  Indexing starts with 1.
0109   //   col -         The column to access.  Indexing starts with 1.
0110   //
0111   // Returns:
0112   //   Const reference to the selected element.
0113   //
0114   {
0115     return HepMatrix::operator()(row, col);
0116   }
0117 
0118   double& Row_Vector::operator()(int row, int col)
0119   //
0120   // Purpose: Element access.
0121   //
0122   // Inputs:
0123   //   row -         The row to access.  Indexing starts with 1.
0124   //   col -         The column to access.  Indexing starts with 1.
0125   //
0126   // Returns:
0127   //   Reference to the selected element.
0128   //
0129   {
0130     return HepMatrix::operator()(row, col);
0131   }
0132 
0133   Row_Vector& Row_Vector::operator=(const Matrix& m)
0134   //
0135   // Purpose: Assignment operator.
0136   //          Raises an assertion if M does not have exactly one row.
0137   //
0138   // Inputs:
0139   //   m -           The matrix to copy.
0140   //                 Must have exactly one row.
0141   //
0142   // Returns:
0143   //   This object.
0144   //
0145   {
0146     assert(m.num_row() == 1);
0147     *((Matrix*)this) = m;
0148     return *this;
0149   }
0150 
0151   void clear(CLHEP::HepGenMatrix& m)
0152   //
0153   // Purpose: Reset the matrix M to zero.
0154   //
0155   // Inputs:
0156   //   m -           The matrix to reset.
0157   //
0158   {
0159     int nrow = m.num_row();
0160     int ncol = m.num_col();
0161     for (int i = 1; i <= nrow; i++)
0162       for (int j = 1; j <= ncol; j++)
0163         m(i, j) = 0;
0164   }
0165 
0166   double scalar(const CLHEP::HepGenMatrix& m)
0167   //
0168   // Purpose: Return the 1x1 matrix M as a scalar.
0169   //          Raise an assertion if M is not 1x1.
0170   //
0171   // Inputs:
0172   //   m -           The matrix to convert.
0173   //                 Must be 1x1.
0174   //
0175   // Returns:
0176   //   m(1,1)
0177   //
0178   {
0179     assert(m.num_row() == 1 && m.num_col() == 1);
0180     return m(1, 1);
0181   }
0182 
0183 }  // namespace hitfit