14 #pragma implementation
17 #include "CLHEP/Vector/ThreeVector.h"
18 #include "CLHEP/Units/PhysicalConstants.h"
25 void Hep3Vector::setMag(
double ma) {
26 double factor = mag();
28 std::cerr <<
"Hep3Vector::setMag() - "
29 <<
"zero vector can't be stretched" << std::endl;
38 double Hep3Vector::operator () (
int i)
const {
47 std::cerr <<
"Hep3Vector::operator () - "
48 <<
"Hep3Vector subscripting: bad index (" << i <<
")"
54 double & Hep3Vector::operator () (
int i) {
65 <<
"Hep3Vector::operator () - "
66 <<
"Hep3Vector subscripting: bad index (" << i <<
")"
72 Hep3Vector & Hep3Vector::rotateUz(
const Hep3Vector& NewUzVector) {
75 double u1 = NewUzVector.x();
76 double u2 = NewUzVector.y();
77 double u3 = NewUzVector.z();
78 double up = u1*u1 + u2*u2;
82 double px = dx, py = dy, pz = dz;
83 dx = (u1*u3*px - u2*py)/up + u1*pz;
84 dy = (u2*u3*px + u1*py)/up + u2*pz;
87 else if (u3 < 0.) { dx = -dx; dz = -dz; }
92 double Hep3Vector::pseudoRapidity()
const {
94 if ( m1== 0 )
return 0.0;
95 if ( m1==
z() )
return 1.0E72;
96 if ( m1== -
z() )
return -1.0E72;
97 return 0.5*std::log( (m1+
z())/(m1-
z()) );
100 std::ostream &
operator<< (std::ostream & os,
const Hep3Vector & v) {
101 return os <<
"(" << v.x() <<
"," << v.y() <<
"," << v.z() <<
")";
105 double & x,
double & y,
double &
z );
107 std::istream &
operator>>(std::istream & is, Hep3Vector & v) {
114 const Hep3Vector
HepXHat(1.0, 0.0, 0.0);
115 const Hep3Vector
HepYHat(0.0, 1.0, 0.0);
116 const Hep3Vector
HepZHat(0.0, 0.0, 1.0);
124 Hep3Vector & Hep3Vector::rotateX (
double phi1) {
125 double sinphi = std::sin(phi1);
126 double cosphi = std::cos(phi1);
128 ty = dy * cosphi - dz * sinphi;
129 dz = dz * cosphi + dy * sinphi;
134 Hep3Vector & Hep3Vector::rotateY (
double phi1) {
135 double sinphi = std::sin(phi1);
136 double cosphi = std::cos(phi1);
138 tz = dz * cosphi - dx * sinphi;
139 dx = dx * cosphi + dz * sinphi;
144 Hep3Vector & Hep3Vector::rotateZ (
double phi1) {
145 double sinphi = std::sin(phi1);
146 double cosphi = std::cos(phi1);
148 tx = dx * cosphi - dy * sinphi;
149 dy = dy * cosphi + dx * sinphi;
154 bool Hep3Vector::isNear(
const Hep3Vector & v,
double epsilon)
const {
155 double limit = dot(v)*epsilon*epsilon;
156 return ( (*
this - v).mag2() <= limit );
159 double Hep3Vector::howNear(
const Hep3Vector & v )
const {
161 double d = (*
this - v).mag2();
163 if ( (vdv > 0) && (d < vdv) ) {
164 return std::sqrt (d/vdv);
165 }
else if ( (vdv == 0) && (d == 0) ) {
172 double Hep3Vector::deltaPhi (
const Hep3Vector & v2)
const {
173 double dphi = v2.getPhi() - getPhi();
175 dphi -= CLHEP::twopi;
177 dphi += CLHEP::twopi;
182 double Hep3Vector::deltaR (
const Hep3Vector & v )
const {
183 double a = eta() - v.eta();
184 double b = deltaPhi(v);
185 return std::sqrt ( a*a + b*b );
188 double Hep3Vector::cosTheta(
const Hep3Vector & q)
const {
190 double ptot2 = mag2()*q.mag2();
194 arg = dot(q)/std::sqrt(ptot2);
195 if(arg > 1.0) arg = 1.0;
196 if(arg < -1.0) arg = -1.0;
201 double Hep3Vector::cos2Theta(
const Hep3Vector & q)
const {
203 double ptot2 = mag2();
204 double qtot2 = q.mag2();
205 if ( ptot2 == 0 || qtot2 == 0 ) {
209 arg = (pdq/ptot2) * (pdq/qtot2);
212 if(arg > 1.0) arg = 1.0;
217 void Hep3Vector::setEta (
double eta1) {
220 if ( (dx == 0) && (dy == 0) ) {
222 std::cerr <<
"Hep3Vector::setEta() - "
223 <<
"Attempt to set eta of zero vector -- vector is unchanged"
227 std::cerr <<
"Hep3Vector::setEta() - "
228 <<
"Attempt to set eta of vector along Z axis -- will use phi = 0"
235 double tanHalfTheta = std::exp ( -eta1 );
237 (1 - tanHalfTheta*tanHalfTheta) / (1 + tanHalfTheta*tanHalfTheta);
239 double rho1 = r1*std::sqrt(1 - cosTheta1*cosTheta1);
240 dy = rho1 * std::sin (phi1);
241 dx = rho1 * std::cos (phi1);
245 void Hep3Vector::setCylTheta (
double theta1) {
249 if ( (dx == 0) && (dy == 0) ) {
251 std::cerr <<
"Hep3Vector::setCylTheta() - "
252 <<
"Attempt to set cylTheta of zero vector -- vector is unchanged"
264 std::cerr <<
"Hep3Vector::setCylTheta() - "
265 <<
"Attempt set cylindrical theta of vector along Z axis "
266 <<
"to a non-trivial value, while keeping rho fixed -- "
267 <<
"will return zero vector" << std::endl;
271 if ( (theta1 < 0) || (theta1 >
CLHEP::pi) ) {
272 std::cerr <<
"Hep3Vector::setCylTheta() - "
273 <<
"Setting Cyl theta of a vector based on a value not in [0, PI]"
277 double phi1 (getPhi());
278 double rho1 = getRho();
279 if ( (theta1 == 0) || (theta1 ==
CLHEP::pi) ) {
280 std::cerr <<
"Hep3Vector::setCylTheta() - "
281 <<
"Attempt to set cylindrical theta to 0 or PI "
282 <<
"while keeping rho fixed -- infinite Z will be computed"
284 dz = (theta1==0) ? 1.0E72 : -1.0E72;
287 dz = rho1 / std::tan (theta1);
288 dy = rho1 * std::sin (phi1);
289 dx = rho1 * std::cos (phi1);
293 void Hep3Vector::setCylEta (
double eta1) {
297 double theta1 = 2 * std::atan ( std::exp (-eta1) );
304 if ( (dx == 0) && (dy == 0) ) {
306 std::cerr <<
"Hep3Vector::setCylEta() - "
307 <<
"Attempt to set cylEta of zero vector -- vector is unchanged"
319 std::cerr <<
"Hep3Vector::setCylEta() - "
320 <<
"Attempt set cylindrical eta of vector along Z axis "
321 <<
"to a non-trivial value, while keeping rho fixed -- "
322 <<
"will return zero vector" << std::endl;
326 double phi1 (getPhi());
327 double rho1 = getRho();
328 dz = rho1 / std::tan (theta1);
329 dy = rho1 * std::sin (phi1);
330 dx = rho1 * std::cos (phi1);
335 Hep3Vector
operator/ (
const Hep3Vector & v1,
double c ) {
341 double oneOverC = 1.0/c;
342 return Hep3Vector ( v1.x() * oneOverC,
347 Hep3Vector & Hep3Vector::operator/= (
double c) {
354 double oneOverC = 1.0/c;
361 double Hep3Vector::tolerance = Hep3Vector::ToleranceTicks * 2.22045e-16;
HepLorentzVector operator/(const HepLorentzVector &w, double c)
const Hep3Vector HepYHat(0.0, 1.0, 0.0)
const Hep3Vector HepXHat(1.0, 0.0, 0.0)
std::istream & operator>>(std::istream &is, HepAxisAngle &aa)
std::ostream & operator<<(std::ostream &os, const HepAxisAngle &aa)
const Hep3Vector HepZHat(0.0, 0.0, 1.0)
void ZMinput3doubles(std::istream &is, const char *type, double &x, double &y, double &z)