CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
SpaceVectorD.cc
Go to the documentation of this file.
1// -*- C++ -*-
2// ---------------------------------------------------------------------------
3//
4// This file is a part of the CLHEP - a Class Library for High Energy Physics.
5//
6// This is the implementation of the subset of those methods of the Hep3Vector
7// class which originated from the ZOOM SpaceVector class *and* which involve
8// the esoteric concepts of polar/azimuthal angular decomposition.
9//
10
11#include "CLHEP/Vector/defs.h"
12#include "CLHEP/Vector/ThreeVector.h"
13#include "CLHEP/Vector/ZMxpv.h"
14
15#include <cmath>
16
17namespace CLHEP {
18
19//-*********************************************
20// - 6 -
21// Decomposition of an angle between two vectors
22//
23//-*********************************************
24
25
26double Hep3Vector::polarAngle (const Hep3Vector & v2) const {
27 return std::fabs(v2.getTheta() - getTheta());
28} /* polarAngle */
29
31 const Hep3Vector & ref) const {
32 return std::fabs( v2.angle(ref) - angle(ref) );
33} /* polarAngle (v2, ref) */
34
35// double Hep3Vector::azimAngle (const Hep3Vector & v2) const
36// is now in the .icc file as deltaPhi(v2)
37
39 const Hep3Vector & ref) const {
40
41 Hep3Vector vperp ( perpPart(ref) );
42 if ( vperp.mag2() == 0 ) {
43 ZMthrowC (ZMxpvAmbiguousAngle(
44 "Cannot find azimuthal angle with reference direction parallel to "
45 "vector 1 -- will return zero"));
46 return 0;
47 }
48
49 Hep3Vector v2perp ( v2.perpPart(ref) );
50 if ( v2perp.mag2() == 0 ) {
51 ZMthrowC (ZMxpvAmbiguousAngle(
52 "Cannot find azimuthal angle with reference direction parallel to "
53 "vector 2 -- will return zero"));
54 return 0;
55 }
56
57 double ang = vperp.angle(v2perp);
58
59 // Now compute the sign of the answer: that of U*(VxV2) or
60 // the equivalent expression V*(V2xU).
61
62 if ( dot(v2.cross(ref)) >= 0 ) {
63 return ang;
64 } else {
65 return -ang;
66 }
67
68 //-| Note that if V*(V2xU) is zero, we want to return 0 or PI
69 //-| depending on whether vperp is aligned or antialigned with v2perp.
70 //-| The computed angle() expression does this properly.
71
72} /* azimAngle (v2, ref) */
73
74} // namespace CLHEP
#define ZMthrowC(A)
Definition: ZMxpv.h:133
double azimAngle(const Hep3Vector &v2) const
double mag2() const
double getTheta() const
Hep3Vector cross(const Hep3Vector &) const
double angle(const Hep3Vector &) const
double dot(const Hep3Vector &) const
Hep3Vector perpPart() const
double angle() const
double polarAngle(const Hep3Vector &v2) const
Definition: SpaceVectorD.cc:26