247 #if !defined(ST_NO_NAMESPACES)
251 #ifndef ST_NO_EXCEPTIONS
252 # include <stdexcept>
253 # if !defined(ST_NO_NAMESPACES)
254 using std::out_of_range;
255 using std::domain_error;
259 #include "StThreeVector.hh"
260 #include "StLorentzVector.hh"
268 StMatrix(
size_t p,
size_t q,
size_t init=0);
271 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
281 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
297 unsigned int numRow()
const;
298 unsigned int numCol()
const;
299 unsigned int numSize()
const;
300 unsigned int num_row()
const;
301 unsigned int num_col()
const;
302 unsigned int num_size()
const;
308 const DataType& operator()(
size_t row,
size_t col)
const;
309 DataType& operator()(
size_t row,
size_t col);
315 DataType& operator[](
size_t);
327 const DataType & operator[](
size_t)
const;
345 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
374 StMatrix<DataType> sub(
size_t min_row,
size_t max_row,
size_t min_col,
size_t max_col)
const;
379 void invert(
size_t& ierr);
381 DataType determinant()
const;
384 static void swap(
unsigned int&,
unsigned int&);
385 static void swap(DataType *&, DataType *&);
395 int dfact(DataType &det,
int *ir);
402 unsigned int mRow, mCol;
412 template<
class DataType>
414 : mElement(0), mRow(0), mCol(0), mSize(0) {}
416 template<
class DataType>
421 mElement =
new DataType[mSize];
423 DataType *a = mElement;
424 DataType *b = mElement + mSize;
434 if ( mCol == mRow ) {
436 b = mElement + mSize;
437 for( ; a<b; a+=(mCol+1)) *a = 1.0;
440 #ifndef ST_NO_EXCEPTIONS
441 throw domain_error(
"StMatrix<T>::StMatrix(): Matrix must be NxN");
443 cerr <<
"StMatrix<T>::StMatrix(): Matrix must be NxN" << endl;
448 #ifndef ST_NO_EXCEPTIONS
449 throw domain_error(
"StMatrix<T>::StMatrix(p,q,init): init must be 0 or 1");
451 cerr <<
"StMatrix<T>::StMatrix(p,q,init): init must be 0 or 1" << endl;
458 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
459 template<
class DataType>
462 : mRow(m1.numRow()), mCol(m1.numCol()), mSize(m1.numSize())
464 mElement =
new DataType[mSize];
466 for(
unsigned int ii=0; ii<mRow; ii++)
467 for(
unsigned int jj=0; jj<mCol; jj++)
468 *(mElement+(ii)*mCol+jj) = m1(ii+1,jj+1);
471 template<
class DataType>
473 : mRow(m1.numRow()), mCol(m1.numCol()), mSize(m1.numSize())
475 mElement =
new DataType[mSize];
477 for(
unsigned int ii=0; ii<mRow; ii++)
478 for(
unsigned int jj=0; jj<mCol; jj++)
479 *(mElement+(ii)*mCol+jj) = m1(ii+1,jj+1);
482 template<
class DataType>
484 : mRow(m1.numRow()), mCol(m1.numCol()), mSize(m1.numSize())
486 mElement =
new DataType[mSize];
488 for(
unsigned int ii=0; ii<mRow; ii++)
489 for(
unsigned int jj=0; jj<mCol; jj++)
490 *(mElement+(ii)*mCol+jj) = m1(ii+1,jj+1);
493 template<
class DataType>
495 : mRow(m1.numRow()), mCol(m1.numCol()), mSize(m1.numSize())
497 mElement =
new DataType[mSize];
499 for(
unsigned int ii=0; ii<mRow; ii++)
500 for(
unsigned int jj=0; jj<mCol; jj++)
501 *(mElement+(ii)*mCol+jj) = m1(ii+1,jj+1);
506 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
507 template<
class DataType>
511 if ((
void *)&m1 == (
void *)
this) {
516 mSize = m1.numRow()*m1.numCol();
517 mElement =
new DataType[mSize];
522 for(
unsigned int ii=0; ii<mRow; ii++)
523 for(
unsigned int jj=0; jj<mCol; jj++) {
524 *(mElement+(ii)*mCol+jj) = m1(ii+1,jj+1);
530 template<
class DataType>
533 if ((
void *)&m1 == (
void *)
this) {
538 mSize = m1.numRow()*m1.numCol();
539 mElement =
new DataType[mSize];
544 for(
unsigned int ii=0; ii<mRow; ii++)
545 for(
unsigned int jj=0; jj<mCol; jj++) {
546 *(mElement+(ii)*mCol+jj) = m1(ii+1,jj+1);
551 #else // ST_NO_MEMBER_TEMPLATES
552 template<
class DataType>
555 if ((
void *)&m1 == (
void *)
this) {
560 mSize = m1.numRow()*m1.numCol();
561 mElement =
new DataType[mSize];
566 for(
unsigned int ii=0; ii<mRow; ii++)
567 for(
unsigned int jj=0; jj<mCol; jj++) {
568 *(mElement+(ii)*mCol+jj) = m1(ii+1,jj+1);
573 template<
class DataType>
576 if ((
void *)&m1 == (
void *)
this) {
581 mSize = m1.numRow()*m1.numCol();
582 mElement =
new DataType[mSize];
587 for(
unsigned int ii=0; ii<mRow; ii++)
588 for(
unsigned int jj=0; jj<mCol; jj++) {
589 *(mElement+(ii)*mCol+jj) = m1(ii+1,jj+1);
598 template<
class DataType>
606 template<
class DataType>
609 template<
class DataType>
612 template<
class DataType>
616 template<
class DataType>
619 template<
class DataType>
622 template<
class DataType>
628 template<
class DataType>
631 #ifdef MATRIX_BOUND_CHECK
632 if(row<1 || row>numRow() || col<1 || col>numCol()) {
633 #ifndef ST_NO_EXCEPTIONS
634 throw out_of_range(
"StMatrix<DataType>::operator(): const Bad Index");
636 cerr <<
"StMatrix<DataType>::operator(): const Bad Index" << endl;
640 return *(mElement+(row-1)*mCol+col-1);
643 template<
class DataType>
646 #ifdef MATRIX_BOUND_CHECK
647 if(row<1 || row>mRow || col<1 || col>mCol) {
648 #ifndef ST_NO_EXCEPTIONS
649 throw out_of_range(
"StMatrix<DataType>::operator(): Bad Index");
651 cerr <<
"StMatrix<DataType>::operator(): Bad Index" << endl;
655 return *(mElement+(row-1)*mCol+col-1);
662 template<
class DataType>
665 for(
unsigned int ii=0; ii<mRow; ii++)
666 for(
unsigned int jj=0; jj<mCol; jj++)
667 *(mElement+(ii)*mCol+jj) *= fact;
672 template<
class DataType>
676 #ifndef ST_NO_EXCEPTIONS
677 throw out_of_range(
"StMatrix<T>::operator/=(): Cannot divide by zero!");
679 cerr <<
"StMatrix<T>::operator/=(): Cannot divide by zero!" << endl;
682 for(
unsigned int ii=0; ii<mCol; ii++)
683 for(
unsigned int jj=0; jj<mRow; jj++)
684 *(mElement+(ii)*mCol+jj) /= fact;
689 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
690 template<
class DataType>
694 if(mRow == m2.numRow() && mCol == m2.numCol()) {
695 for(
unsigned int ii=0; ii<mRow; ii++)
696 for(
unsigned int jj=0; jj<mCol; jj++)
697 *(mElement+(ii)*mCol+jj) += m2(ii+1,jj+1);
700 #ifndef ST_NO_EXCEPTIONS
701 throw out_of_range(
"StMatrix<T>::operator+=(): Matrices are not same size!");
703 cerr <<
"StMatrix<T>::operator+=(): Matrices are not same size!" << endl;
709 template<
class DataType>
713 if(mRow == m2.numRow() && mCol == m2.numCol()) {
714 for(
unsigned int ii=0; ii<mRow; ii++)
715 for(
unsigned int jj=0; jj<mCol; jj++)
716 *(mElement+(ii)*mCol+jj) -= m2(ii+1,jj+1);
719 #ifndef ST_NO_EXCEPTIONS
720 throw out_of_range(
"StMatrix<T>::operator-=(): Matrices are not same size!");
722 cerr <<
"StMatrix<T>::operator-=(): Matrices are not same size!" << endl;
728 template<
class DataType>
732 if(mCol == m2.numRow() ) {
734 for(
unsigned int i=0; i<mRow; i++)
735 for(
unsigned int j=0; j<m2.numCol(); j++) {
736 for(
unsigned int kk=0; kk<mCol; kk++)
737 mret(i+1, j+1) += (*(mElement+(i)*mCol+kk))*m2(kk+1,j+1);
742 #ifndef ST_NO_EXCEPTIONS
743 throw out_of_range(
"StMatrix<T>::dot(): incompatible matrix sizes");
745 cerr <<
"StMatrix<T>::dot(): incompatible matrix sizes" << endl;
750 #else // ST_NO_MEMBER_TEMPLATES
752 template<
class DataType>
755 if(mRow == m2.numRow() && mCol == m2.numCol()) {
756 for(
unsigned int ii=0; ii<mRow; ii++)
757 for(
unsigned int jj=0; jj<mCol; jj++)
758 *(mElement+(ii)*mCol+jj) += m2(ii+1,jj+1);
761 #ifndef ST_NO_EXCEPTIONS
762 throw out_of_range(
"StMatrix<float>::operator+=(): Matrices are not same size!");
764 cerr <<
"StMatrix<float>::operator+=(): Matrices are not same size!" << endl;
770 template<
class DataType>
773 if(mRow == m2.numRow() && mCol == m2.numCol()) {
774 for(
unsigned int ii=0; ii<mRow; ii++)
775 for(
unsigned int jj=0; jj<mCol; jj++)
776 *(mElement+(ii)*mCol+jj) += m2(ii+1,jj+1);
779 #ifndef ST_NO_EXCEPTIONS
780 throw out_of_range(
"StMatrix<double>::operator+=(): Matrices are not same size!");
782 cerr <<
"StMatrix<double>::operator+= Matrices are not same size!" << endl;
789 template<
class DataType>
792 if(mRow == m2.numRow() && mCol == m2.numCol()) {
793 for(
unsigned int ii=0; ii<mRow; ii++)
794 for(
unsigned int jj=0; jj<mCol; jj++)
795 *(mElement+(ii)*mCol+jj) -= m2(ii+1,jj+1);
798 #ifndef ST_NO_EXCEPTIONS
799 throw out_of_range(
"StMatrix<float>::operator-=(): Matrices are not same size!");
801 cerr <<
"StMatrix<float>::operator-=(): Matrices are not same size!" << endl;
807 template<
class DataType>
810 if(mRow == m2.numRow() && mCol == m2.numCol()) {
811 for(
unsigned int ii=0; ii<mRow; ii++)
812 for(
unsigned int jj=0; jj<mCol; jj++)
813 *(mElement+(ii)*mCol+jj) -= m2(ii+1,jj+1);
816 #ifndef ST_NO_EXCEPTIONS
817 throw out_of_range(
"StMatrix<double>::operator-=(): Matrices are not same size!");
819 cerr <<
"StMatrix<double>::operator-=(): Matrices are not same size!" << endl;
826 template<
class DataType>
829 if(mCol == m2.numRow() ) {
832 for(
unsigned int i=0; i<mRow; i++)
833 for(
unsigned int j=0; j<m2.numCol(); j++) {
834 for(
unsigned int kk=0; kk<mCol; kk++)
835 mret(i+1, j+1) += (*(mElement+(i)*mCol+kk))*m2(kk+1,j+1);
840 #ifndef ST_NO_EXCEPTIONS
841 throw out_of_range(
"StMatrix<float>::dot(): Incompatible matrix sizes");
843 cerr <<
"StMatrix<float>::dot(): Incompatible matrix sizes" << endl;
849 template<
class DataType>
852 if(mCol == m2.numRow() ) {
855 for(
unsigned int i=0; i<mRow; i++)
856 for(
unsigned int j=0; j<m2.numCol(); j++) {
857 for(
unsigned int kk=0; kk<mCol; kk++)
858 mret(i+1, j+1) += (*(mElement+(i)*mCol+kk))*m2(kk+1,j+1);
863 #ifndef ST_NO_EXCEPTIONS
864 throw out_of_range(
"StMatrix<double>::dot(): Incompatible matrix sizes");
866 cerr <<
"StMatrix<double>::dot(): Incompatible matrix sizes" << endl;
873 #endif // ST_NO_MEMBER_TEMPLATES
875 template<
class DataType>
881 template<
class DataType>
889 template<
class DataType>
892 if (mCol == m1.numCol() && mRow == m1.numRow()) {
893 for(
unsigned int ii=0; ii<mRow; ii++)
894 for(
unsigned int jj=0; jj<mCol; jj++) {
895 if(*(mElement+(ii)*mCol+jj) != m1(ii+1,jj+1))
904 template<
class DataType>
907 return !(*
this == m1);
911 template<
class DataType>
915 DataType *a = mElement;
916 for(
unsigned int ir=1; ir<=mRow; ir++) {
917 for(
unsigned int ic=1; ic<=mCol; ic++) {
918 mret(ir,ic) = (*f)(*(a++), ir, ic);
924 template<
class DataType>
928 DataType *pl = mElement + mSize;
929 DataType *pme = mElement;
930 DataType *pt = mret.mElement;
931 DataType *ptl = mret.mElement + mSize;
932 for (; pme < pl; pme++, pt+=mRow)
940 template<
class DataType>
949 template<
class DataType>
951 size_t min_col,
size_t max_col)
const
954 if(max_row > mRow || max_col > mCol) {
955 #ifndef ST_NO_EXCEPTIONS
956 throw out_of_range(
"StMatrix<DataType>::sub(): Index out of range");
958 cerr <<
"StMatrix<DataType>::sub(): Index out of range" << endl;
961 int nrows = mret.numRow();
962 int ncols = mret.numCol();
963 for(
int ii=0; ii<nrows; ii++)
964 for(
int jj=0; jj<ncols; jj++) {
966 *(mElement+(min_row+ii-1)*mCol+(min_col+jj-1));
971 template<
class DataType>
975 (row+m1.numRow()-1 > mRow) ||
977 (col+m1.numCol()-1 > mCol)) {
978 #ifndef ST_NO_EXCEPTIONS
979 throw out_of_range(
"StMatrix<DataType>::sub(): Index out of range");
981 cerr <<
"StMatrix<DataType>::sub(): Index out of range" << endl;
984 DataType *a = m1.mElement;
985 unsigned int nc = numCol();
986 DataType *b1 = mElement + (row - 1) * nc + col - 1;
988 for(
unsigned int irow=1; irow<=m1.numRow(); irow++) {
990 for(
unsigned int icol=1; icol<=m1.numCol(); icol++) {
998 template<
class DataType>
1006 template<
class DataType>
1009 #ifndef ST_NO_EXCEPTIONS
1010 throw domain_error(
"StMatrix<DataType>::invert(): not a NxN matrix");
1012 cerr <<
"StMatrix<DataType>::invert(): not a NxN matrix" << endl;
1015 static unsigned int max_array = 20;
1016 static int *ir =
new int [max_array+1];
1018 if (mCol > max_array) {
1021 ir =
new int [max_array+1];
1023 DataType t1, t2, t3;
1024 DataType det, temp, s;
1029 DataType c11,c12,c13,c21,c22,c23,c31,c32,c33;
1031 c11 = (*(mElement+4)) * (*(mElement+8)) - (*(mElement+5)) * (*(mElement+7));
1032 c12 = (*(mElement+5)) * (*(mElement+6)) - (*(mElement+3)) * (*(mElement+8));
1033 c13 = (*(mElement+3)) * (*(mElement+7)) - (*(mElement+4)) * (*(mElement+6));
1034 c21 = (*(mElement+7)) * (*(mElement+2)) - (*(mElement+8)) * (*(mElement+1));
1035 c22 = (*(mElement+8)) * (*mElement) - (*(mElement+6)) * (*(mElement+2));
1036 c23 = (*(mElement+6)) * (*(mElement+1)) - (*(mElement+7)) * (*mElement);
1037 c31 = (*(mElement+1)) * (*(mElement+5)) - (*(mElement+2)) * (*(mElement+4));
1038 c32 = (*(mElement+2)) * (*(mElement+3)) - (*mElement) * (*(mElement+5));
1039 c33 = (*mElement) * (*(mElement+4)) - (*(mElement+1)) * (*(mElement+3));
1040 t1 = fabs(*mElement);
1041 t2 = fabs(*(mElement+3));
1042 t3 = fabs(*(mElement+6));
1045 temp = *(mElement+6);
1046 det = c23*c12-c22*c13;
1049 det = c22*c33-c23*c32;
1051 }
else if (t3 >= t2) {
1052 temp = *(mElement+6);
1053 det = c23*c12-c22*c13;
1055 temp = *(mElement+3);
1056 det = c13*c32-c12*c33;
1064 DataType *tmp = mElement;
1079 det = (*mElement)*(*(mElement+3)) - (*(mElement+1))*(*(mElement+2));
1085 temp = s*(*(mElement+3));
1086 *(mElement+1) *= -s;
1087 *(mElement+2) *= -s;
1088 *(mElement+3) = s*(*mElement);
1093 if ((*mElement)==0) {
1097 *mElement = 1.0/(*mElement);
1100 ifail = dfact(det, ir);
1112 template<
class DataType>
1114 static unsigned int max_array = 20;
1115 static int *ir =
new int [max_array+1];
1117 #ifndef ST_NO_EXCEPTIONS
1118 throw out_of_range(
"StMatrix<DataType>::determinant(): not a NxN matrix");
1120 cerr <<
"StMatrix<DataType>::determinant(): not a NxN matrix" << endl;
1123 if (mCol > max_array) {
1126 ir =
new int [max_array+1];
1130 int i = mt.dfact(det, ir);
1131 if(i==0)
return det;
1138 template<
class DataType>
1144 template<
class DataType>
1146 #ifdef MATRIX_BOUND_CHECK
1147 if (_r<0 || _r>=_a.numRow() || c<0 || c>=_a.numCol()) {
1148 #ifndef ST_NO_EXCEPTIONS
1149 throw out_of_range(
"StMatrix<DataType>::operator[]: index out of range");
1151 cerr <<
"StMatrix<DataType>::operator[]: index out of range" << endl;
1155 return *(_a.mElement+_r*_a.mCol+c);
1158 template<
class DataType>
1164 template<
class DataType>
1167 #ifdef MATRIX_BOUND_CHECK
1168 if (_r<0 || _r>=_a.numRow() || c<0 || c>=_a.numCol()) {
1169 #ifndef ST_NO_EXCEPTIONS
1170 throw out_of_range(
"StMatrix<DataType>::operator[]: const index out of range");
1172 cerr <<
"StMatrix<DataType>::operator[]: const index out of range" << endl;
1176 return *(_a.mElement+_r*_a.mCol+c);
1179 template<
class DataType>
1182 StMatrixRow b(*
this,r);
1186 template<
class DataType>
1189 StMatrixRowConst b(*
this,r);
1193 template<
class DataType>
1201 template<
class DataType>
1210 template<
class DataType>
1230 template<
class DataType>
1234 #ifndef ST_NO_EXCEPTIONS
1235 throw domain_error(
"StMatrix<DataType>::dfact(): Matrix not NxN");
1237 cerr <<
"StMatrix<DataType>::dfact(): Matrix not NxN" << endl;
1245 DataType g1 = 1.0e-19;
1246 DataType g2 = 1.0e19;
1253 if (
sizeof(DataType) ==
sizeof(
double))
1254 epsilon = 8*DBL_EPSILON;
1256 epsilon = 8*FLT_EPSILON;
1261 int normal = 0, imposs = -1;
1262 int jrange = 0, jover = 1, junder = -1;
1267 DataType *mj = mElement;
1269 for (
int j=1;j<=n;j++) {
1273 DataType *mij = mj + n + j - 1;
1274 for (
int i=j+1;i<=n;i++) {
1293 DataType *mkl = mElement + (k-1)*n;
1294 for (
int l=1;l<=n;l++) {
1300 ir[nxch] = (((j)<<12)+(k));
1314 if (jfail == jrange) jfail = junder;
1318 if (jfail==jrange) jfail = jover;
1321 DataType *mk = mj + n;
1322 DataType *mkjp = mk + j;
1323 DataType *mjk = mj + j;
1324 for (k=j+1;k<=n;k++) {
1328 DataType *mik = mElement + k - 1;
1329 DataType *mijp = mElement + j;
1332 for (
int i=1;i<j;i++) {
1333 s11 += (*mik) * (*(mji++));
1334 s12 += (*mijp) * (*(mki++));
1339 *(mjk++) = -s11 * (*mjj);
1340 *(mkjp) = -(((*(mjj+1)))*((*(mkjp-1)))+(s12));
1348 if (nxch%2==1) det = -det;
1349 if (jfail !=jrange) det = 0.0;
1354 template<
class DataType>
1358 #ifndef ST_NO_EXCEPTIONS
1359 throw domain_error(
"StMatrix<DataType>::dfinv(): Matrix not NxN");
1361 cerr <<
"StMatrix<DataType>::dfinv(): Matrix not NxN" << endl;
1371 DataType *m11 = mElement;
1372 DataType *m12 = m11 + 1;
1373 DataType *m21 = m11 + n;
1374 DataType *m22 = m12 + n;
1375 *m21 = -(*m22) * (*m11) * (*m21);
1378 DataType *mi = mElement + 2 * n;
1379 DataType *mii= mElement + 2 * n + 2;
1380 DataType *mimim = mElement + n + 1;
1381 for (
int i=3;i<=n;i++) {
1383 DataType *mj = mElement;
1384 DataType *mji = mj + i - 1;
1386 for (
int j=1;j<=im2;j++) {
1389 DataType *mkj = mj + j - 1;
1390 DataType *mik = mi + j - 1;
1391 DataType *mjkp = mj + j;
1392 DataType *mkpi = mj + n + i - 1;
1393 for (
int k=j;k<=im2;k++) {
1394 s31 += (*mkj) * (*(mik++));
1395 s32 += (*(mjkp++)) * (*mkpi);
1399 *mij = -(*mii) * (((*(mij-n)))*( (*(mii-1)))+(s31));
1405 *(mii-1) = -(*mii) * (*mimim) * (*(mii-1));
1406 *(mimim+1) = -(*(mimim+1));
1412 DataType *mi = mElement;
1413 DataType *mii = mElement;
1414 for (
int i=1;i<n;i++) {
1418 for (j=1; j<=i;j++) {
1420 DataType *mikj = mi + n + j - 1;
1421 DataType *miik = mii + 1;
1422 DataType *min_end = mi + n;
1423 for (;miik<min_end;) {
1424 s33 += (*mikj) * (*(miik++));
1429 for (j=1;j<=ni;j++) {
1431 DataType *miik = mii + j;
1432 DataType *mikij = mii + j * n + j;
1433 for (
int k=j;k<=ni;k++) {
1434 s34 += *mikij * (*(miik++));
1443 if (nxch==0)
return 0;
1444 for (
int mm=1;mm<=nxch;mm++) {
1445 int k = nxch - mm + 1;
1449 DataType *mki = mElement + i - 1;
1450 DataType *mkj =mElement + j - 1;
1451 for (k=1; k<=n;k++) {
1464 template<
class DataType>
1472 template<
class DataType>
1480 template<
class DataType>
1490 template<
class DataType>
1495 mret.sub(m1.numRow()+1, m1.numCol()+1, m2);
1506 template<> vector<double> operator*(
const StMatrix<double>& m1,
const vector<double>& v);
1507 template<> vector<double> operator*(
const vector<double>& v,
const StMatrix<double>& m1);
1508 template<> vector<double> operator*(
const StMatrix<double>& m1,
const vector<float>& v);
1509 template<> vector<double> operator*(
const vector<float>& v,
const StMatrix<double>& m1);
1510 template<> vector<double> operator*(
const StMatrix<float>& m1,
const vector<double>& v);
1511 template<> vector<double> operator*(
const vector<double>& v,
const StMatrix<float>& m1);
1512 template<> vector<float> operator*(
const StMatrix<float>& m1,
const vector<float>& v);
1513 template<> vector<float> operator*(
const vector<float>& v,
const StMatrix<float>& m1);
1542 template<> ostream& operator<<(ostream& s, const StMatrix<double>& q);
1543 template<> ostream& operator<<(ostream& s, const StMatrix<float>& q);
1553 template<
class DataType,
class X>
1560 template <
class DataType,
class X>
1561 #ifdef ST_NO_TEMPLATE_DEF_ARGS
1562 vector<DataType, allocator<DataType> >
1563 operator*(
const StMatrix<X>& m1,
const vector<DataType, allocator<DataType> >& v)
1565 vector<DataType> operator*(
const StMatrix<X>& m1,
const vector<DataType>& v)
1568 vector<DataType> mret(m1.numRow());
1569 if(m1.numCol() == v.size() ) {
1570 for (
unsigned int i=0; i<v.size(); i++) {
1572 for(
unsigned int j=0; j<m1.numCol(); j++)
1573 temp += m1(i+1,j+1)*v[j];
1578 #ifndef ST_NO_EXCEPTIONS
1579 throw out_of_range(
"operator*(): StMatrix * STL vector Sizes are incompatible");
1581 cerr <<
"operator*(): StMatrix * STL vector Sizes are incompatible" << endl;
1587 template <
class DataType,
class X>
1588 #ifdef ST_NO_TEMPLATE_DEF_ARGS
1589 vector<DataType, allocator<DataType> >
1590 operator*(
const vector<DataType, allocator<DataType> >& v,
const StMatrix<X>& m1)
1592 vector<DataType> operator*(
const vector<DataType>& v,
const StMatrix<X>& m1)
1596 if(v.size() == m1.numRow()) {
1597 vector<DataType> mret(m1.numCol());
1598 for (
unsigned int i=0; i<m1.numCol(); i++) {
1600 for(
unsigned int j=0; j<m1.numRow(); j++)
1601 temp+=v[j]*m1(j+1,i+1);
1607 #ifndef ST_NO_EXCEPTIONS
1608 throw out_of_range(
"operator*(): STL vector * StMatrix : Matrix Sizes are incompatible");
1610 cerr <<
"operator*(): STL vector * StMatrix : Matrix Sizes are incompatible" << endl;
1612 return vector<DataType>();
1616 template <
class DataType,
class X>
1619 if(m1.numRow() == 3 && m1.numCol() == 3) {
1621 m1[1][0]*v3.x()+m1[1][1]*v3.y()+m1[1][2]*v3.z(),
1622 m1[2][0]*v3.x()+m1[2][1]*v3.y()+m1[2][2]*v3.z());
1625 #ifndef ST_NO_EXCEPTIONS
1626 throw out_of_range(
"operator*(): StMatrix<> * StThreeVector<> : Matrix Must be 3x3.");
1629 cerr <<
"StMatrix<> * StThreeVector<>: Matrix Must be 3x3" << endl;
1636 template <
class DataType,
class X>
1639 if(m1.numRow() == 3 && m1.numCol() == 3) {
1641 m1[0][1]*v3.x()+m1[1][1]*v3.y()+m1[2][1]*v3.z(),
1642 m1[0][2]*v3.x()+m1[1][2]*v3.y()+m1[2][2]*v3.z());
1645 #ifndef ST_NO_EXCEPTIONS
1646 throw out_of_range(
"operator*(): StThreeVector<> * StMatrix<>: Matrix Must be 3x3.");
1649 cerr <<
"operator*(): StThreeVector<> * StMatrix<>: Matrix Must be 3x3" << endl;
1655 template <
class DataType,
class X>
1658 if (m1.numRow() == 4 && m1.numCol() == 4) {
1660 m1[1][0]*v4.x()+m1[1][1]*v4.y()+m1[1][2]*v4.z()+m1[1][3]*v4.t(),
1661 m1[2][0]*v4.x()+m1[2][1]*v4.y()+m1[2][2]*v4.z()+m1[2][3]*v4.t(),
1662 m1[3][0]*v4.x()+m1[3][1]*v4.y()+m1[3][2]*v4.z()+m1[3][3]*v4.t());
1665 #ifndef ST_NO_EXCEPTIONS
1666 throw out_of_range(
"operator*(): StMatrix<> * StLorentzVector<> : Matrix Must be 4x4.");
1669 cerr <<
"operator*(): StMatrix<> * StLorentzVector<>: Matrix Must be 4x4" << endl;
1675 template <
class DataType,
class X>
1678 if (m1.numRow() == 4 && m1.numCol() == 4) {
1680 m1[0][1]*v4.x()+m1[1][1]*v4.y()+m1[2][1]*v4.z()+m1[1][3]*v4.t(),
1681 m1[0][2]*v4.x()+m1[1][2]*v4.y()+m1[2][2]*v4.z()+m1[2][3]*v4.t(),
1682 m1[0][3]*v4.x()+m1[1][3]*v4.y()+m1[2][3]*v4.z()+m1[2][3]*v4.t());
1685 #ifndef ST_NO_EXCEPTIONS
1686 throw out_of_range(
"operator*(): StLorentzVector<> * StMatrix<>: Matrix Must be 3x3.");
1689 cerr <<
"StLorentzVector<> * StMatrix<>: Matrix Must be 3x3" << endl;
1695 template<
class DataType,
class X>
1698 if(m1.numRow() == m2.numRow() && m1.numCol() == m2.numCol()) {
1704 #ifndef ST_NO_EXCEPTIONS
1705 throw out_of_range(
"operator+(): Matrix Sizes must be the same.");
1708 cerr <<
"operator+(): Matrix Sizes must be the same." << endl;
1714 template<
class DataType,
class X>
1717 if(m1.numRow() == m2.numRow() && m1.numCol() == m2.numCol()) {
1721 #ifndef ST_NO_EXCEPTIONS
1722 throw out_of_range(
"operator-(): Matrix Sizes must be the same.");
1725 cerr <<
"operator-(): Matrix Sizes must be the same." << endl;
1732 template<
class DataType>
1733 ostream& operator<<(ostream& s, const StMatrix<DataType>& q)
1739 if(s.flags()&std::ios::fixed)
1740 width = s.precision()+3;
1742 width = s.precision()+7;
1743 for(
unsigned int irow = 1; irow<= q.numRow(); irow++)
1745 for(
unsigned int icol=1; icol<=q.numCol(); icol++)
1748 s << q(irow,icol) <<
" ";
1755 template<
class DataType>
1758 return normInfinity(m1);
1761 template<
class DataType>
1765 for(
unsigned int r=1; r<=m1.numRow(); r++) {
1767 for(
unsigned int c=1; c<=m1.numCol(); c++) {
1770 if(sum>max) max=sum;
1775 template<
class DataType>
1779 for(
unsigned int c=1; c<=m1.numCol(); c++) {
1781 for(
unsigned int r=1; r<=m1.num_row(); r++)
1783 if(sum>max) max=sum;