source: trunk/CLHEP/src/SpaceVectorP.cc

Last change on this file was 4, checked in by Pavel Demin, 16 years ago

first commit

File size: 4.4 KB
Line 
1// -*- C++ -*-
2// ---------------------------------------------------------------------------
3//
4// This file is a part of the CLHEP - a Class Library for High Energy Physics.
5//
6// SpaceVector
7//
8// This is the implementation of the subset of those methods of the Hep3Vector
9// class which originated from the ZOOM SpaceVector class *and* which involve
10// intrinsic properties or propeties relative to a second vector.
11//
12
13#ifdef GNUPRAGMA
14#pragma implementation
15#endif
16
17#include "CLHEP/Vector/defs.h"
18#include "CLHEP/Vector/ThreeVector.h"
19#include "CLHEP/Vector/ZMxpv.h"
20
21#include <cmath>
22
23namespace CLHEP {
24
25//-********************************
26// - 5 -
27// Intrinsic properties of a vector
28// and properties relative to a direction
29//
30//-********************************
31
32double Hep3Vector::beta() const {
33 double b = sqrt(mag2());
34 if (b >= 1) {
35 ZMthrowA (ZMxpvTachyonic(
36 "Beta taken for Hep3Vector of at least unit length"));
37 }
38 return b;
39}
40
41double Hep3Vector::gamma() const {
42 double beta = sqrt(mag2());
43 if (beta == 1) {
44 ZMthrowA (ZMxpvTachyonic(
45 "Gamma taken for Hep3Vector of unit magnitude -- infinite result"));
46 }
47 if (beta > 1) {
48 ZMthrowA (ZMxpvTachyonic(
49 "Gamma taken for Hep3Vector of more than unit magnitude -- "
50 "the sqrt function would return NAN" ));
51 }
52 return 1/sqrt(1-beta*beta);
53}
54
55double Hep3Vector::rapidity() const {
56 if (fabs(dz) == 1) {
57 ZMthrowC (ZMxpvTachyonic(
58 "Rapidity in Z direction taken for Hep3Vector with |Z| = 1 -- \n"
59 "the log should return infinity"));
60 }
61 if (fabs(dz) > 1) {
62 ZMthrowA (ZMxpvTachyonic(
63 "Rapidity in Z direction taken for Hep3Vector with |Z| > 1 -- \n"
64 "the log would return a NAN" ));
65 }
66 // Want inverse tanh(dz):
67 return (.5 * log((1+dz)/(1-dz)) );
68}
69
70double Hep3Vector::coLinearRapidity() const {
71 double b = beta();
72 if (b == 1) {
73 ZMthrowA (ZMxpvTachyonic(
74 "Co-linear Rapidity taken for Hep3Vector of unit length -- "
75 "the log should return infinity"));
76 }
77 if (b > 1) {
78 ZMthrowA (ZMxpvTachyonic(
79 "Co-linear Rapidity taken for Hep3Vector of more than unit length -- "
80 "the log would return a NAN" ));
81 }
82 // Want inverse tanh(b):
83 return (.5 * log((1+b)/(1-b)) );
84}
85
86//-***********************************************
87// Other properties relative to a reference vector
88//-***********************************************
89
90Hep3Vector Hep3Vector::project (const Hep3Vector & v2) const {
91 double mag2v2 = v2.mag2();
92 if (mag2v2 == 0) {
93 ZMthrowA (ZMxpvZeroVector(
94 "Attempt to take projection of vector against zero reference vector "));
95 return project();
96 }
97 return ( v2 * (dot(v2)/mag2v2) );
98}
99
100double Hep3Vector::rapidity(const Hep3Vector & v2) const {
101 double vmag = v2.mag();
102 if ( vmag == 0 ) {
103 ZMthrowA (ZMxpvZeroVector(
104 "Rapidity taken with respect to zero vector" ));
105 return 0;
106 }
107 double z = dot(v2)/vmag;
108 if (fabs(z) >= 1) {
109 ZMthrowA (ZMxpvTachyonic(
110 "Rapidity taken for too large a Hep3Vector "
111 "-- would return infinity or NAN"));
112 }
113 // Want inverse tanh(z):
114 return (.5 * log((1+z)/(1-z)) );
115}
116
117double Hep3Vector::eta(const Hep3Vector & v2) const {
118 // Defined as -log ( tan ( .5* theta(u) ) );
119 //
120 // Quicker is to use cosTheta:
121 // tan (theta/2) = sin(theta)/(1 + cos(theta))
122
123 double r = getR();
124 double v2r = v2.mag();
125 if ( (r == 0) || (v2r == 0) ) {
126 ZMthrowA (ZMxpvAmbiguousAngle(
127 "Cannot find pseudorapidity of a zero vector relative to a vector"));
128 return 0.;
129 }
130 double c = dot(v2)/(r*v2r);
131 if ( c >= 1 ) {
132 c = 1; //-| We don't want to return NAN because of roundoff
133 ZMthrowC (ZMxpvInfinity(
134 "Pseudorapidity of vector relative to parallel vector -- "
135 "will give infinite result"));
136 // We can just go on; tangent will be 0, so
137 // log (tangent) will be -INFINITY, so result
138 // will be +INFINITY.
139 }
140 if ( c <= -1 ) {
141 ZMthrowC (ZMxpvInfinity(
142 "Pseudorapidity of vector relative to anti-parallel vector -- "
143 "will give negative infinite result"));
144 //-| We don't want to return NAN because of roundoff
145 return ( negativeInfinity() );
146 // If we just went on, the tangent would be NAN
147 // so return would be NAN. But the proper limit
148 // of tan is +Infinity, so the return should be
149 // -INFINITY.
150 }
151
152 double tangent = sqrt (1-c*c) / ( 1 + c );
153 return (- log (tangent));
154
155} /* eta (u) */
156
157
158} // namespace CLHEP
Note: See TracBrowser for help on using the repository browser.