ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpaceVectorP.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SpaceVectorP.cc
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 
18 
19 #include <cmath>
20 
21 namespace CLHEP {
22 
23 //-********************************
24 // - 5 -
25 // Intrinsic properties of a vector
26 // and properties relative to a direction
27 //
28 //-********************************
29 
30 double Hep3Vector::beta() const {
31  double b = std::sqrt(mag2());
32 // if (b >= 1) {
33 // std::cerr << "Hep3Vector::beta() - "
34 // << "Beta taken for Hep3Vector of at least unit length" << std::endl;
35 // }
36  return b;
37 }
38 
39 double Hep3Vector::gamma() const {
40  double bbeta = std::sqrt(mag2());
41 // if (bbeta == 1) {
42 // std::cerr << "Hep3Vector::gamma() - "
43 // << "Gamma taken for Hep3Vector of unit magnitude -- infinite result"
44 // << std::endl;
45 // }
46 // if (bbeta > 1) {
47 // std::cerr << "Hep3Vector::gamma() - "
48 // << "Gamma taken for Hep3Vector of more than unit magnitude -- \n"
49 // << "the sqrt function would return NAN" << std::endl;
50 // }
51  return 1/std::sqrt(1-bbeta*bbeta);
52 }
53 
54 double Hep3Vector::rapidity() const {
55 // if (std::fabs(dz) == 1) {
56 // std::cerr << "Hep3Vector::rapidity() - "
57 // << "Rapidity in Z direction taken for Hep3Vector with |Z| = 1 -- \n"
58 // << "the log should return infinity" <, std::endl;
59 // }
60 // if (std::fabs(dz) > 1) {
61 // std::cerr << "Hep3Vector::rapidity() - "
62 // << "Rapidity in Z direction taken for Hep3Vector with |Z| > 1 -- \n"
63 // << "the log would return a NAN" << std::endl;
64 // }
65  // Want inverse std::tanh(dz):
66  return (.5 * std::log((1+dz)/(1-dz)) );
67 }
68 
70  double b = beta();
71 // if (b == 1) {
72 // std::cerr << "Hep3Vector::coLinearRapidity() - "
73 // << "Co-linear Rapidity taken for Hep3Vector of unit length -- \n"
74 // << "the log should return infinity" << std::endl;
75 // }
76 // if (b > 1) {
77 // std::cerr << "Hep3Vector::coLinearRapidity() - "
78 // << "Co-linear Rapidity taken for Hep3Vector of more than unit length -- \n"
79 // << "the log would return a NAN" << std::endl;
80 // }
81  // Want inverse std::tanh(b):
82  return (.5 * std::log((1+b)/(1-b)) );
83 }
84 
85 //-***********************************************
86 // Other properties relative to a reference vector
87 //-***********************************************
88 
90  double mag2v2 = v2.mag2();
91  if (mag2v2 == 0) {
92  std::cerr << "Hep3Vector::project() - "
93  << "Attempt to take projection of vector against zero reference vector"
94  << std::endl;
95  return project();
96  }
97  return ( v2 * (dot(v2)/mag2v2) );
98 }
99 
100 double Hep3Vector::rapidity(const Hep3Vector & v2) const {
101  double vmag = v2.mag();
102  if ( vmag == 0 ) {
103  std::cerr << "Hep3Vector::rapidity() - "
104  << "Rapidity taken with respect to zero vector" << std::endl;
105  return 0;
106  }
107  double z1 = dot(v2)/vmag;
108 // if (std::fabs(z1) >= 1) {
109 // std::cerr << "Hep3Vector::rapidity() - "
110 // << "Rapidity taken for too large a Hep3Vector "
111 // << "-- would return infinity or NAN" << std::endl;
112 // }
113  // Want inverse std::tanh(z):
114  return (.5 * std::log((1+z1)/(1-z1)) );
115 }
116 
117 double Hep3Vector::eta(const Hep3Vector & v2) const {
118  // Defined as -std::log ( std::tan ( .5* theta(u) ) );
119  //
120  // Quicker is to use cosTheta:
121  // std::tan (theta/2) = std::sin(theta)/(1 + std::cos(theta))
122 
123  double r1 = getR();
124  double v2r = v2.mag();
125  if ( (r1 == 0) || (v2r == 0) ) {
126  std::cerr << "Hep3Vector::eta() - "
127  << "Cannot find pseudorapidity of a zero vector relative to a vector"
128  << std::endl;
129  return 0.;
130  }
131  double c = dot(v2)/(r1*v2r);
132  if ( c >= 1 ) {
133  c = 1; //-| We don't want to return NAN because of roundoff
134  std::cerr << "Hep3Vector::eta() - "
135  << "Pseudorapidity of vector relative to parallel vector -- \n"
136  << "will give infinite result" << std::endl;
137  // We can just go on; tangent will be 0, so
138  // std::log (tangent) will be -INFINITY, so result
139  // will be +INFINITY.
140  }
141  if ( c <= -1 ) {
142  std::cerr << "Hep3Vector::eta() - "
143  << "Pseudorapidity of vector relative to anti-parallel vector -- \n"
144  << "will give negative infinite result"<< std::endl;
145  //-| We don't want to return NAN because of roundoff
146  return ( negativeInfinity() );
147  // If we just went on, the tangent would be NAN
148  // so return would be NAN. But the proper limit
149  // of tan is +Infinity, so the return should be
150  // -INFINITY.
151  }
152 
153  double tangent = std::sqrt (1-c*c) / ( 1 + c );
154  return (- std::log (tangent));
155 
156 } /* eta (u) */
157 
158 
159 } // namespace CLHEP