source: trunk/CLHEP/src/SpaceVectorD.cc@ 9

Last change on this file since 9 was 4, checked in by Pavel Demin, 17 years ago

first commit

File size: 2.1 KB
Line 
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#ifdef GNUPRAGMA
12#pragma implementation
13#endif
14
15#include "CLHEP/Vector/defs.h"
16#include "CLHEP/Vector/ThreeVector.h"
17#include "CLHEP/Vector/ZMxpv.h"
18
19#include <cmath>
20
21namespace CLHEP {
22
23//-*********************************************
24// - 6 -
25// Decomposition of an angle between two vectors
26//
27//-*********************************************
28
29
30double Hep3Vector::polarAngle (const Hep3Vector & v2) const {
31 return fabs(v2.getTheta() - getTheta());
32} /* polarAngle */
33
34double Hep3Vector::polarAngle (const Hep3Vector & v2,
35 const Hep3Vector & ref) const {
36 return fabs( v2.angle(ref) - angle(ref) );
37} /* polarAngle (v2, ref) */
38
39// double Hep3Vector::azimAngle (const Hep3Vector & v2) const
40// is now in the .icc file as deltaPhi(v2)
41
42double Hep3Vector::azimAngle (const Hep3Vector & v2,
43 const Hep3Vector & ref) const {
44
45 Hep3Vector vperp ( perpPart(ref) );
46 if ( vperp.mag2() == 0 ) {
47 ZMthrowC (ZMxpvAmbiguousAngle(
48 "Cannot find azimuthal angle with reference direction parallel to "
49 "vector 1 -- will return zero"));
50 return 0;
51 }
52
53 Hep3Vector v2perp ( v2.perpPart(ref) );
54 if ( v2perp.mag2() == 0 ) {
55 ZMthrowC (ZMxpvAmbiguousAngle(
56 "Cannot find azimuthal angle with reference direction parallel to "
57 "vector 2 -- will return zero"));
58 return 0;
59 }
60
61 double ang = vperp.angle(v2perp);
62
63 // Now compute the sign of the answer: that of U*(VxV2) or
64 // the equivalent expression V*(V2xU).
65
66 if ( dot(v2.cross(ref)) >= 0 ) {
67 return ang;
68 } else {
69 return -ang;
70 }
71
72 //-| Note that if V*(V2xU) is zero, we want to return 0 or PI
73 //-| depending on whether vperp is aligned or antialigned with v2perp.
74 //-| The computed angle() expression does this properly.
75
76} /* azimAngle (v2, ref) */
77
78} // namespace CLHEP
Note: See TracBrowser for help on using the repository browser.