8#include "CLHEP/Geometry/defs.h"
9#include "CLHEP/Geometry/BasicVector3D.h"
15 float ma = mag(), dz = z();
16 if (ma == 0)
return 0;
17 if (ma == dz)
return FLT_MAX;
18 if (ma == -dz)
return -FLT_MAX;
19 return 0.5*std::log((ma+dz)/(ma-dz));
27 double tanHalfTheta = std::exp(-a);
28 double tanHalfTheta2 = tanHalfTheta * tanHalfTheta;
29 double cosTheta1 = (1 - tanHalfTheta2) / (1 + tanHalfTheta2);
30 double rh = ma * std::sqrt(1 - cosTheta1*cosTheta1);
32 set(rh*std::cos(ph), rh*std::sin(ph), ma*cosTheta1);
39 double ptot = mag()*v.
mag();
42 if(cosa > 1) cosa = 1;
43 if(cosa < -1) cosa = -1;
45 return std::acos(cosa);
51 double sina = std::sin(a), cosa = std::cos(a), dy = y(), dz = z();
52 setY(dy*cosa-dz*sina);
53 setZ(dz*cosa+dy*sina);
60 double sina = std::sin(a), cosa = std::cos(a), dz = z(), dx = x();
61 setZ(dz*cosa-dx*sina);
62 setX(dx*cosa+dz*sina);
69 double sina = std::sin(a), cosa = std::cos(a), dx = x(), dy = y();
70 setX(dx*cosa-dy*sina);
71 setY(dy*cosa+dx*sina);
79 if (a == 0)
return *
this;
80 double cx = v.
x(), cy = v.
y(), cz = v.
z();
81 double ll = std::sqrt(cx*cx + cy*cy + cz*cz);
83 std::cerr <<
"BasicVector<float>::rotate() : zero axis" << std::endl;
86 double cosa = std::cos(a), sina = std::sin(a);
87 cx /= ll; cy /= ll; cz /= ll;
89 double xx = cosa + (1-cosa)*cx*cx;
90 double xy = (1-cosa)*cx*cy - sina*cz;
91 double xz = (1-cosa)*cx*cz + sina*cy;
93 double yx = (1-cosa)*cy*cx + sina*cz;
94 double yy = cosa + (1-cosa)*cy*cy;
95 double yz = (1-cosa)*cy*cz - sina*cx;
97 double zx = (1-cosa)*cz*cx - sina*cy;
98 double zy = (1-cosa)*cz*cy + sina*cx;
99 double zz = cosa + (1-cosa)*cz*cz;
101 cx = x(); cy = y(); cz = z();
102 set(xx*cx+xy*cy+xz*cz, yx*cx+yy*cy+yz*cz, zx*cx+zy*cy+zz*cz);
110 return os <<
"(" << a.
x() <<
"," << a.
y() <<
"," << a.
z() <<
")";
127 if (is.fail() || c !=
'(' ) {
129 <<
"Could not find required opening parenthesis "
130 <<
"in input of a BasicVector3D<float>"
135 is >> x >> std::ws >> c;
136 if (is.fail() || c !=
',' ) {
138 <<
"Could not find x value and required trailing comma "
139 <<
"in input of a BasicVector3D<float>"
144 is >> y >> std::ws >> c;
145 if (is.fail() || c !=
',' ) {
147 <<
"Could not find y value and required trailing comma "
148 <<
"in input of a BasicVector3D<float>"
153 is >> z >> std::ws >> c;
154 if (is.fail() || c !=
')' ) {
156 <<
"Could not find z value and required close parenthesis "
157 <<
"in input of a BasicVector3D<float>"
171 double ma = mag(), dz = z();
172 if (ma == 0)
return 0;
173 if (ma == dz)
return DBL_MAX;
174 if (ma == -dz)
return -DBL_MAX;
175 return 0.5*std::log((ma+dz)/(ma-dz));
183 double tanHalfTheta = std::exp(-a);
184 double tanHalfTheta2 = tanHalfTheta * tanHalfTheta;
185 double cosTheta1 = (1 - tanHalfTheta2) / (1 + tanHalfTheta2);
186 double rh = ma * std::sqrt(1 - cosTheta1*cosTheta1);
188 set(rh*std::cos(ph), rh*std::sin(ph), ma*cosTheta1);
195 double ptot = mag()*v.
mag();
198 if(cosa > 1) cosa = 1;
199 if(cosa < -1) cosa = -1;
201 return std::acos(cosa);
207 double sina = std::sin(a), cosa = std::cos(a), dy = y(), dz = z();
208 setY(dy*cosa-dz*sina);
209 setZ(dz*cosa+dy*sina);
216 double sina = std::sin(a), cosa = std::cos(a), dz = z(), dx = x();
217 setZ(dz*cosa-dx*sina);
218 setX(dx*cosa+dz*sina);
225 double sina = std::sin(a), cosa = std::cos(a), dx = x(), dy = y();
226 setX(dx*cosa-dy*sina);
227 setY(dy*cosa+dx*sina);
235 if (a == 0)
return *
this;
236 double cx = v.
x(), cy = v.
y(), cz = v.
z();
237 double ll = std::sqrt(cx*cx + cy*cy + cz*cz);
239 std::cerr <<
"BasicVector<double>::rotate() : zero axis" << std::endl;
242 double cosa = std::cos(a), sina = std::sin(a);
243 cx /= ll; cy /= ll; cz /= ll;
245 double xx = cosa + (1-cosa)*cx*cx;
246 double xy = (1-cosa)*cx*cy - sina*cz;
247 double xz = (1-cosa)*cx*cz + sina*cy;
249 double yx = (1-cosa)*cy*cx + sina*cz;
250 double yy = cosa + (1-cosa)*cy*cy;
251 double yz = (1-cosa)*cy*cz - sina*cx;
253 double zx = (1-cosa)*cz*cx - sina*cy;
254 double zy = (1-cosa)*cz*cy + sina*cx;
255 double zz = cosa + (1-cosa)*cz*cz;
257 cx = x(); cy = y(); cz = z();
258 set(xx*cx+xy*cy+xz*cz, yx*cx+yy*cy+yz*cz, zx*cx+zy*cy+zz*cz);
266 return os <<
"(" << a.
x() <<
"," << a.
y() <<
"," << a.
z() <<
")";
283 if (is.fail() || c !=
'(' ) {
285 <<
"Could not find required opening parenthesis "
286 <<
"in input of a BasicVector3D<double>"
291 is >> x >> std::ws >> c;
292 if (is.fail() || c !=
',' ) {
294 <<
"Could not find x value and required trailing comma "
295 <<
"in input of a BasicVector3D<double>"
300 is >> y >> std::ws >> c;
301 if (is.fail() || c !=
',' ) {
303 <<
"Could not find y value and required trailing comma "
304 <<
"in input of a BasicVector3D<double>"
309 is >> z >> std::ws >> c;
310 if (is.fail() || c !=
')' ) {
312 <<
"Could not find z value and required close parenthesis "
313 <<
"in input of a BasicVector3D<double>"
BasicVector3D< T > & rotateZ(T a)
BasicVector3D< T > & rotateX(T a)
BasicVector3D< T > & rotate(T a, const BasicVector3D< T > &v)
T angle(const BasicVector3D< T > &v) const
BasicVector3D< T > & rotateY(T a)
std::istream & operator>>(std::istream &is, BasicVector3D< float > &a)
std::ostream & operator<<(std::ostream &os, const BasicVector3D< float > &a)