Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:56

0001 #ifndef _CLEHP_2_SMATRIX_MIGRATION_H_
0002 #define _CLEHP_2_SMATRIX_MIGRATION_H_
0003 
0004 #include "DataFormats/Math/interface/AlgebraicROOTObjects.h"
0005 
0006 #include "CLHEP/Matrix/Matrix.h"
0007 #include "CLHEP/Matrix/Vector.h"
0008 #include "CLHEP/Matrix/SymMatrix.h"
0009 
0010 #include <cstring>
0011 #include <cassert>
0012 
0013 /*
0014 template <unsigned int N1, unsigned int N2> 
0015     ROOT::Math::SMatrix<double,N1,N2,ROOT::Math::RepStd<double,N1,N2> > clhep2smatrix(const CLHEP::HepMatrix &mt) {
0016         typedef ROOT::Math::SMatrix<double,N1,N2,ROOT::Math::RepStd<double,N1,N2> > RM;
0017         RM rm;
0018         memcpy(rm.Array(), &matmt(1,1), (N1*N2)*sizeof(double));
0019         return rm;
0020     }
0021 template <unsigned int N1> 
0022     ROOT::Math::SMatrix<double,N1,N1,ROOT::Math::RepSym<double,N1> > clhep2smatrix(const CLHEP::HepSymMatrix &mt) {
0023         typedef ROOT::Math::SMatrix<double,N1,N1,ROOT::Math::RepSym<double,N1> > RM;
0024         RM rm;
0025         memcpy(rm.Array(), &matmt(1,1), (D1*D2)*sizeof(double));
0026         return rm;
0027     }
0028 */
0029 
0030 template <unsigned int N1, unsigned int N2>
0031 ROOT::Math::SMatrix<double, N1, N2, typename ROOT::Math::MatRepStd<double, N1, N2> > asSMatrix(
0032     const CLHEP::HepMatrix &m) {
0033   typedef typename ROOT::Math::MatRepStd<double, N1, N2> REP;
0034   assert(m.num_row() == N1);
0035   assert(m.num_col() == N2);
0036   return ROOT::Math::SMatrix<double, N1, N2, REP>(&m(1, 1), REP::kSize);
0037 }
0038 
0039 template <unsigned int N1>
0040 ROOT::Math::SMatrix<double, N1, N1, typename ROOT::Math::MatRepSym<double, N1> > asSMatrix(
0041     const CLHEP::HepSymMatrix &m) {
0042   typedef typename ROOT::Math::MatRepSym<double, N1> REP;
0043   assert(m.num_row() == N1);
0044   return ROOT::Math::SMatrix<double, N1, N1, REP>(&m(1, 1), REP::kSize);
0045 }
0046 
0047 template <unsigned int N1>
0048 ROOT::Math::SVector<double, N1> asSVector(const CLHEP::HepVector &m) {
0049   return ROOT::Math::SVector<double, N1>(&m[0], N1);
0050 }
0051 
0052 template <unsigned int N>
0053 CLHEP::HepVector asHepVector(const ROOT::Math::SVector<double, N> &v) {
0054   CLHEP::HepVector hv(N);
0055   memcpy(&hv[0], &v[0], N * sizeof(double));
0056   return hv;
0057 }
0058 
0059 template <unsigned int N1, unsigned int N2>
0060 CLHEP::HepMatrix asHepMatrix(
0061     const ROOT::Math::SMatrix<double, N1, N2, typename ROOT::Math::MatRepStd<double, N1, N2> > &rm) {
0062   CLHEP::HepMatrix am(N1, N2);
0063   memcpy(&am(1, 1), rm.Array(), N1 * N2 * sizeof(double));
0064   return am;
0065 }
0066 
0067 template <unsigned int N1>
0068 CLHEP::HepSymMatrix asHepMatrix(
0069     const ROOT::Math::SMatrix<double, N1, N1, typename ROOT::Math::MatRepSym<double, N1> > &rm) {
0070   CLHEP::HepSymMatrix am(N1);
0071   memcpy(&am(1, 1), rm.Array(), (N1 * (N1 + 1)) / 2 * sizeof(double));
0072   return am;
0073 }
0074 
0075 #endif