00001 #include <iomanip>
00002 #include <assert.h>
00003 #include "TRVector.h"
00004 #include "TError.h"
00005 #include "TString.h"
00006 ClassImp(TRVector);
00007
00008 TRVector::TRVector(Int_t nrows): TRMatrix(nrows,1) {;}
00009
00010 TRVector::TRVector(Int_t nrows,const Double_t *fArray): TRMatrix(nrows,1,fArray){;}
00011
00012 TRVector::TRVector(Int_t nrows,const Float_t *fArray): TRMatrix(nrows,1,fArray){;}
00013
00014 TRVector::TRVector(const TRMatrix& A, ETRMatrixCreatorsOp kop,const TRVector& B) :
00015 TRMatrix(A, kop, B) {assert (kop = kAxB);}
00016
00017 TRVector::TRVector(const TRMatrix& S, Int_t I) {
00018 if (I == 0) {::Error("TRVector::TRVector(const TRMatrix&)", "index i %d out of bounds (size: %d, this: %p)",
00019 I, S.NI(), this); I = 1;}
00020 if (I > S.NI()) {::Error("TRVector::TRVector(const TRMatrix&)", "index i %d out of bounds (size: %d, this: %p)",
00021 I, S.NI(), this); I = 1;}
00022 fNrows = S.NJ();
00023 fNcols = 1;
00024 Set(fNrows,S.GetArray()+S.NJ()*(I-1));
00025 }
00026
00027 TRVector::TRVector(const TRVector& A, ETRMatrixCreatorsOp kop,const TRMatrix& B) {
00028 Int_t NI, NJ, NK;
00029 switch (kop) {
00030 case kAxB:
00031 NI = A.GetNrows(); fNcols = NI;
00032 NJ = A.GetNcols();
00033 assert (NJ == B.GetNrows());
00034 NK = B.GetNcols(); fNrows = NK;
00035 Set(NI*NK);
00036 TCL::mxmpy(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
00037 break;
00038 default:
00039 Error("TRVector(ETRMatrixCreatorsOp)", "operation %d not yet implemented", kop);
00040 }
00041 }
00042
00043 TRVector::TRVector(Int_t nrows,const Char_t *s): TRMatrix(nrows,1,s) {;}
00044
00045 TRVector::TRVector(const TRSymMatrix &S, ETRMatrixCreatorsOp kop,const TRVector& A) :
00046 TRMatrix(S,kop,A) {;}
00047
00048 TRVector::TRVector(const TRVector& A, ETRMatrixCreatorsOp kop,const TRSymMatrix &S) :
00049 TRMatrix(A,kop,S) {;}
00050
00051 TRVector::TRVector(Int_t nrows,Double_t a0, ...) : TRMatrix(nrows,1) {
00052 __VA_LIST__(a0);
00053 }
00054
00055 TRVector::TRVector(const TVector3& A) :TRMatrix(3,1) {
00056 Double_t xyz[3];
00057 A.GetXYZ(xyz);
00058 Set(3,xyz);
00059 }
00060
00061 TRVector::TRVector(const StThreeVectorD& A) :TRMatrix(3,1) {
00062 Set(3,A.xyz());
00063 }
00064
00065 TRVector &TRVector::operator=(const TVector3& A) {
00066 Double_t xyz[3];
00067 A.GetXYZ(xyz);
00068 Set(3,xyz);
00069 fNrows = 3;
00070 fNcols = 1;
00071 return *this;
00072 }
00073
00074 TRVector &TRVector::operator=(const StThreeVectorD& A) {
00075 Set(3,A.xyz());
00076 fNrows = 3;
00077 fNcols = 1;
00078 return *this;
00079 }
00080
00081 ostream& operator<<(ostream& s,const TRVector &target) {
00082 Int_t Nrows = target.GetNrows();
00083 assert(target.GetNcols() == 1);
00084 const Double_t *Array = target.GetArray();
00085 s << "Vector[" << Nrows << "] = ";
00086 if (Array) for (int i = 0; i< Nrows; i++) s << Form("\t%10.3f",Array[i]);
00087 else s << " Empty";
00088
00089 return s;
00090 }
00091
00092 void TRVector::Print(Option_t *opt) const {if (opt) {}; cout << *this << endl;}
00093
00094 TRVector TRVector::Cross(const TRVector& v) const {
00095 assert(fNrows == 3 && fNcols == 1 && v.GetNrows() == 3 && v.GetNcols() == 1);
00096 TRVector out(3);
00097 TMath::Cross(GetArray(),v.GetArray(),out.GetArray());
00098 return out;
00099 }
00100
00101 TRVector TRVector::Unit() const {
00102 Double_t Norm = TMath::Sqrt((*this) * (*this));
00103 return Norm > 0 ? (*this)/Norm : *this;
00104 }