SpaceVectorP.cc 4.47 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// SpaceVector
//
// This is the implementation of the subset of those methods of the Hep3Vector 
// class which originated from the ZOOM SpaceVector class *and* which involve
// intrinsic properties or propeties relative to a second vector.
//

13
#include "CLHEP/Vector/defs.h"
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "CLHEP/Vector/ThreeVector.h"
#include "CLHEP/Vector/ZMxpv.h"

#include <cmath>

namespace CLHEP  {

//-********************************
//		- 5 -
// Intrinsic properties of a vector
// and properties relative to a direction
//
//-********************************

double Hep3Vector::beta() const {
29
  double b = std::sqrt(mag2());
30
31
32
33
34
35
36
37
  if (b >= 1) {
    ZMthrowA (ZMxpvTachyonic(
      "Beta taken for Hep3Vector of at least unit length"));
  }
  return b;
}

double Hep3Vector::gamma() const {
38
  double bbeta = std::sqrt(mag2());
39
  if (bbeta == 1) {
40
41
42
    ZMthrowA (ZMxpvTachyonic(
      "Gamma taken for Hep3Vector of unit magnitude -- infinite result"));
  }
43
  if (bbeta > 1) {
44
45
46
47
    ZMthrowA (ZMxpvTachyonic(
      "Gamma taken for Hep3Vector of more than unit magnitude -- "
      "the sqrt function would return NAN" ));
  }
48
  return 1/std::sqrt(1-bbeta*bbeta);
49
50
51
}

double Hep3Vector::rapidity() const {
52
  if (std::fabs(z()) == 1) {
53
54
55
56
    ZMthrowC (ZMxpvTachyonic(
      "Rapidity in Z direction taken for Hep3Vector with |Z| = 1 -- \n"
      "the log should return infinity"));
  }
57
  if (std::fabs(z()) > 1) {
58
59
60
61
    ZMthrowA (ZMxpvTachyonic(
      "Rapidity in Z direction taken for Hep3Vector with |Z| > 1 -- \n"
      "the log would return a NAN" ));
  }
62
63
  // Want inverse std::tanh(z()):
  return (.5 * std::log((1+z())/(1-z())) );
64
65
66
67
68
69
70
71
72
73
74
75
76
77
}

double Hep3Vector::coLinearRapidity() const {
  double b = beta();
  if (b == 1) {
    ZMthrowA (ZMxpvTachyonic(
      "Co-linear Rapidity taken for Hep3Vector of unit length -- "
      "the log should return infinity"));
  }
  if (b > 1) {
    ZMthrowA (ZMxpvTachyonic(
      "Co-linear Rapidity taken for Hep3Vector of more than unit length -- "
      "the log would return a NAN" ));
  }
78
79
  // Want inverse std::tanh(b):
  return (.5 * std::log((1+b)/(1-b)) );
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
}

//-***********************************************
// Other properties relative to a reference vector
//-***********************************************

Hep3Vector Hep3Vector::project (const Hep3Vector & v2) const {
  double mag2v2 = v2.mag2();
  if (mag2v2 == 0) {
    ZMthrowA (ZMxpvZeroVector(
      "Attempt to take projection of vector against zero reference vector "));
    return project();
  }
  return ( v2 * (dot(v2)/mag2v2) );
}

double Hep3Vector::rapidity(const Hep3Vector & v2) const {
  double vmag = v2.mag();
  if ( vmag == 0 ) {
    ZMthrowA (ZMxpvZeroVector(
      "Rapidity taken with respect to zero vector" ));
    return 0;    
  }
103
  double z1 = dot(v2)/vmag;
104
  if (std::fabs(z1) >= 1) {
105
106
107
108
    ZMthrowA (ZMxpvTachyonic(
      "Rapidity taken for too large a Hep3Vector "
      "-- would return infinity or NAN"));
  }
109
110
  // Want inverse std::tanh(z1):
  return (.5 * std::log((1+z1)/(1-z1)) );
111
112
113
}

double Hep3Vector::eta(const Hep3Vector & v2) const {
114
  // Defined as    -std::log ( std::tan ( .5* theta(u) ) );
115
116
  //
  // Quicker is to use cosTheta:
117
  // std::tan (theta/2) = std::sin(theta)/(1 + std::cos(theta))
118

119
  double r1   = getR();
120
  double v2r = v2.mag();
121
  if ( (r1 == 0) || (v2r == 0) ) {
122
123
124
125
    ZMthrowA (ZMxpvAmbiguousAngle(
      "Cannot find pseudorapidity of a zero vector relative to a vector"));
    return 0.;
  }
126
  double c  = dot(v2)/(r1*v2r);
127
128
129
130
131
132
  if ( c >= 1 ) {
    c = 1; 	//-| We don't want to return NAN because of roundoff
    ZMthrowC (ZMxpvInfinity(
      "Pseudorapidity of vector relative to parallel vector -- "
      "will give infinite result"));
   			    // We can just go on; tangent will be 0, so
133
			    // std::log (tangent) will be -INFINITY, so result
134
135
136
137
138
139
140
141
142
143
144
145
146
147
			    // will be +INFINITY.
  }
  if ( c <= -1 ) {
    ZMthrowC (ZMxpvInfinity(
      "Pseudorapidity of vector relative to anti-parallel vector -- "
      "will give negative infinite result"));
    			//-| We don't want to return NAN because of roundoff
    return ( negativeInfinity() );
			    //  If we just went on, the tangent would be NAN
			    //  so return would be NAN.  But the proper limit
			    // of tan is +Infinity, so the return should be
			    // -INFINITY.
  }

148
149
  double tangent = std::sqrt (1-c*c) / ( 1 + c );
  return (- std::log (tangent));
150
151
152
153
154

} /* eta (u) */


}  // namespace CLHEP