7 #if defined(ANITA_UTIL_EXISTS) and defined(VECTORIZE) 8 #include "vectormath_trig.h" 13 Vector::Vector(
double x_inp,
double y_inp,
double z_inp) {
17 angles_need_updating =
true;
19 Vector::Vector(
double* xarray) {
23 angles_need_updating =
true;
25 Vector::Vector(
double theta_inp,
double phi_inp) {
27 if (theta_inp < 0.0 || theta_inp > PI) {
29 cout<<
"Error! Attempt to construct Vector from invalid theta!\n";
37 x = sin(theta_inp) * cos(phi_inp);
38 y = sin(theta_inp) * sin(phi_inp);
43 angles_need_updating =
false;
52 angles_need_updating =
false;
56 return Vector(y * vec.z - z * vec.y,
57 -x * vec.z + z * vec.x,
58 x * vec.y - y * vec.x);
61 double Vector::Dot(
const Vector &vec)
const 62 {
return x * vec.x +y * vec.y + z * vec.z ;}
65 double Vector::Mag()
const {
66 return sqrt(x*x + y*y + z*z);
69 double Vector::Angle(
const Vector &vec)
const {
70 return acos(((*
this)*vec) / (this->Mag() * vec.Mag()));
77 temp.SetX(this->GetX());
78 temp.SetY(this->GetY());
79 temp.SetZ(this->GetZ());
82 tnew_x_axis.SetX(new_x_axis.GetX());
83 tnew_x_axis.SetY(new_x_axis.GetY());
84 tnew_x_axis.SetZ(new_x_axis.GetZ());
87 tnew_y_axis.SetX(new_y_axis.GetX());
88 tnew_y_axis.SetY(new_y_axis.GetY());
89 tnew_y_axis.SetZ(new_y_axis.GetZ());
93 r.SetXAxis(tnew_x_axis);
94 r.SetYAxis(tnew_y_axis);
95 r.SetZAxis(tnew_x_axis.Cross(tnew_y_axis));
112 new_vector.SetX(temp.X());
113 new_vector.SetY(temp.Y());
114 new_vector.SetZ(temp.Z());
124 Vector Vector::ChangeCoord(
const Vector &new_z_axis)
const {
126 Vector new_vector = this->RotateY(new_z_axis.Theta());
127 new_vector = new_vector.RotateZ(new_z_axis.Phi());
133 Vector Vector::Unit()
const {
134 return (*
this) / this->Mag();
137 void Vector::Print()
const {
138 cout << x <<
" " << y <<
" " << z <<
"\n";
140 double Vector::Theta()
const {
141 if (angles_need_updating) UpdateThetaPhi();
145 double Vector::Phi()
const {
146 if (angles_need_updating) UpdateThetaPhi();
150 Vector Vector::RotateX(
double angle)
const {
152 double new_y = cos(angle)*y - sin(angle)*z;
153 double new_z = sin(angle)*y + cos(angle)*z;
154 Vector rotated_vector(new_x,new_y,new_z);
155 return rotated_vector;
158 Vector Vector::RotateY(
double angle)
const {
159 double new_x = cos(angle)*x + sin(angle)*z;
161 double new_z = -sin(angle)*x + cos(angle)*z;
162 Vector rotated_vector(new_x,new_y,new_z);
163 return rotated_vector;
166 Vector Vector::RotateZ(
double angle)
const {
170 double cosangle = cos(angle);
171 double sinangle = sin(angle);
172 Vector rotated_vector(cosangle*x - sinangle*y,sinangle*x + cosangle*y,z);
173 return rotated_vector;
176 Vector Vector::Rotate(
const double angle,
const Vector& axis)
const {
179 double length = axis.Mag();
181 double s = sin(angle);
182 double c = cos(angle);
183 double dx = axis.x / length;
184 double dy = axis.y / length;
185 double dz = axis.z / length;
187 double newx = (c+(1-c)*dx*dx) * x + ((1-c)*dx*dy-s*dz) * y + ((1-c)*dx*dz+s*dy) * z;
188 double newy = ((1-c)*dy*dx+s*dz) * x + (c+(1-c)*dy*dy) * y + ((1-c)*dy*dz-s*dx) * z;
189 double newz = ((1-c)*dz*dx-s*dy) * x + ((1-c)*dz*dy+s*dx) * y + (c+(1-c)*dz*dz) * z;
191 return Vector(newx,newy,newz);
194 void Vector::UpdateThetaPhi()
const {
198 double transverse = sqrt(x*x+y*y);
200 #if defined(ANITA_UTIL_EXISTS) and defined(VECTORIZE) 202 Vec2d
Y(transverse,y);
204 Vec2d answer = atan2(
Y,X);
209 theta = atan2(transverse,z);
216 angles_need_updating =
false;
234 ostream& operator <<(ostream& outs,
const Vector& vec) {
235 cout<<vec.x<<
","<<vec.y<<
","<<vec.z;
240 Vector Vector::Orthogonal()
const 244 Double_t xx = fabs(x);
245 Double_t yy = fabs(y);
246 Double_t zz = fabs(z);
248 return xx < zz ?
Vector(0,z,-y) : Vector(y,-x,0);
250 return yy < zz ?
Vector(-z,0,x) : Vector(y,-x,0);
Inelasticity distributions: stores parametrizations and picks inelasticities.
This class represents a three-vector. Operators are overloaded to provide for the familiar operations...