StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TRVector.cxx
1 #include <iomanip>
2 #include <assert.h>
3 #include "TRVector.h"
4 #include "TError.h"
5 #include "TString.h"
6 ClassImp(TRVector);
7 //________________________________________________________________________________
8 TRVector::TRVector(Int_t nrows): TRMatrix(nrows,1) {;}
9 //________________________________________________________________________________
10 TRVector::TRVector(Int_t nrows,const Double_t *fArray): TRMatrix(nrows,1,fArray){;}
11 //________________________________________________________________________________
12 TRVector::TRVector(Int_t nrows,const Float_t *fArray): TRMatrix(nrows,1,fArray){;}
13 //________________________________________________________________________________
14 TRVector::TRVector(const TRMatrix& A, ETRMatrixCreatorsOp kop,const TRVector& B) :
15  TRMatrix(A, kop, B) {}
16 //________________________________________________________________________________
17 TRVector::TRVector(const TRMatrix& S, Int_t I) {// get I'th row
18  if (I == 0) {::Error("TRVector::TRVector(const TRMatrix&)", "index i %d out of bounds (size: %d, this: %p)",
19  I, S.NI(), this); I = 1;}
20  if (I > S.NI()) {::Error("TRVector::TRVector(const TRMatrix&)", "index i %d out of bounds (size: %d, this: %p)",
21  I, S.NI(), this); I = 1;}
22  fNrows = S.NJ();
23  fNcols = 1;
24  Set(fNrows,S.GetArray()+S.NJ()*(I-1));
25 }
26 //________________________________________________________________________________
27 TRVector::TRVector(const TRVector& A, ETRMatrixCreatorsOp kop,const TRMatrix& B) {
28  Int_t NI, NJ, NK;
29  switch (kop) {
30  case kAxB:
31  NI = A.GetNrows(); fNcols = NI;
32  NJ = A.GetNcols();
33  assert (NJ == B.GetNrows());
34  NK = B.GetNcols(); fNrows = NK;
35  Set(NI*NK);
36  TCL::mxmpy(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
37  break;
38  default:
39  Error("TRVector(ETRMatrixCreatorsOp)", "operation %d not yet implemented", kop);
40  }
41 }
42 //________________________________________________________________________________
43 TRVector::TRVector(Int_t nrows,const Char_t *s): TRMatrix(nrows,1,s) {;}
44 //________________________________________________________________________________
45 TRVector::TRVector(const TRSymMatrix &S, ETRMatrixCreatorsOp kop,const TRVector& A) :
46  TRMatrix(S,kop,A) {;}
47 //________________________________________________________________________________
48 TRVector::TRVector(const TRVector& A, ETRMatrixCreatorsOp kop,const TRSymMatrix &S) :
49  TRMatrix(A,kop,S) {;}
50 //________________________________________________________________________________
51 TRVector::TRVector(Int_t nrows,Double_t a0, ...) : TRMatrix(nrows,1) {
52  __VA_LIST__(a0);
53 }
54 //________________________________________________________________________________
55 TRVector::TRVector(const TVector3& A) :TRMatrix(3,1) {
56  Double_t xyz[3];
57  A.GetXYZ(xyz);
58  Set(3,xyz);
59 }
60 //________________________________________________________________________________
61 TRVector::TRVector(const StThreeVectorD& A) :TRMatrix(3,1) {
62  Set(3,A.xyz());
63 }
64 //________________________________________________________________________________
65 TRVector &TRVector::operator=(const TVector3& A) {
66  Double_t xyz[3];
67  A.GetXYZ(xyz);
68  Set(3,xyz);
69  fNrows = 3;
70  fNcols = 1;
71  return *this;
72 }
73 //________________________________________________________________________________
74 TRVector &TRVector::operator=(const StThreeVectorD& A) {
75  Set(3,A.xyz());
76  fNrows = 3;
77  fNcols = 1;
78  return *this;
79 }
80 //________________________________________________________________________________
81 ostream& operator<<(ostream& s,const TRVector &target) {
82  Int_t Nrows = target.GetNrows();
83  assert(target.GetNcols() == 1);
84  const Double_t *Array = target.GetArray();
85  s << "Vector[" << Nrows << "] = ";// << endl;
86  if (Array) for (int i = 0; i< Nrows; i++) s << Form("\t%10.3f",Array[i]);
87  else s << " Empty";
88  // s << endl;
89  return s;
90 }
91 //________________________________________________________________________________
92 void TRVector::Print(Option_t *opt) const {if (opt) {}; cout << *this << endl;}
93 //________________________________________________________________________________
94 TRVector TRVector::Cross(const TRVector& v) const {
95  assert(fNrows == 3 && fNcols == 1 && v.GetNrows() == 3 && v.GetNcols() == 1);
96  TRVector out(3);
97  TMath::Cross(GetArray(),v.GetArray(),out.GetArray());
98  return out;
99 }
100 //________________________________________________________________________________
101 TRVector TRVector::Unit() const {
102  Double_t Norm = TMath::Sqrt((*this) * (*this));
103  return Norm > 0 ? (*this)/Norm : *this;
104 }
Definition: FJcore.h:367