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10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/clhep/src/RotationZ.cc (Version 11.3.0) and /externals/clhep/src/RotationZ.cc (Version 10.1.p3)


  1 // -*- C++ -*-                                      1 // -*- C++ -*-
  2 // -------------------------------------------      2 // ---------------------------------------------------------------------------
  3 //                                                  3 //
  4 // This file is a part of the CLHEP - a Class       4 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
  5 //                                                  5 //
  6 // This is the implementation of methods of th      6 // This is the implementation of methods of the HepRotationZ class which
  7 // were introduced when ZOOM PhysicsVectors wa      7 // were introduced when ZOOM PhysicsVectors was merged in.
  8 //                                                  8 //
  9                                                     9 
                                                   >>  10 #ifdef GNUPRAGMA
                                                   >>  11 #pragma implementation
                                                   >>  12 #endif
                                                   >>  13 
 10 #include "CLHEP/Vector/RotationZ.h"                14 #include "CLHEP/Vector/RotationZ.h"
 11 #include "CLHEP/Vector/AxisAngle.h"                15 #include "CLHEP/Vector/AxisAngle.h"
 12 #include "CLHEP/Vector/EulerAngles.h"              16 #include "CLHEP/Vector/EulerAngles.h"
 13 #include "CLHEP/Vector/LorentzRotation.h"          17 #include "CLHEP/Vector/LorentzRotation.h"
 14 #include "CLHEP/Units/PhysicalConstants.h"         18 #include "CLHEP/Units/PhysicalConstants.h"
 15                                                    19 
 16 #include <cmath>                                   20 #include <cmath>
 17 #include <stdlib.h>                                21 #include <stdlib.h>
 18 #include <iostream>                                22 #include <iostream>
 19                                                    23 
 20 namespace CLHEP  {                                 24 namespace CLHEP  {
 21                                                    25 
 22 static inline double safe_acos (double x) {        26 static inline double safe_acos (double x) {
 23   if (std::abs(x) <= 1.0) return std::acos(x);     27   if (std::abs(x) <= 1.0) return std::acos(x);
 24   return ( (x>0) ? 0 : CLHEP::pi );                28   return ( (x>0) ? 0 : CLHEP::pi );
 25 }                                                  29 }
 26                                                    30 
 27 HepRotationZ::HepRotationZ(double ddelta) :        31 HepRotationZ::HepRotationZ(double ddelta) : 
 28     its_d(proper(ddelta)), its_s(std::sin(ddel     32     its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta))
 29 {}                                                 33 {}
 30                                                    34 
 31 HepRotationZ & HepRotationZ::set ( double ddel     35 HepRotationZ & HepRotationZ::set ( double ddelta ) {
 32   its_d = proper(ddelta);                          36   its_d = proper(ddelta);
 33   its_s = std::sin(its_d);                         37   its_s = std::sin(its_d);
 34   its_c = std::cos(its_d);                         38   its_c = std::cos(its_d);
 35   return *this;                                    39   return *this;
 36 }                                                  40 }
 37                                                    41 
 38 double  HepRotationZ::phi() const {                42 double  HepRotationZ::phi() const {
 39   return  - its_d/2.0;                             43   return  - its_d/2.0;
 40 }  // HepRotationZ::phi()                          44 }  // HepRotationZ::phi()
 41                                                    45 
 42 double  HepRotationZ::theta() const {              46 double  HepRotationZ::theta() const {
 43   return  0.0 ;                                    47   return  0.0 ;
 44 }  // HepRotationZ::theta()                        48 }  // HepRotationZ::theta()
 45                                                    49 
 46 double  HepRotationZ::psi() const {                50 double  HepRotationZ::psi() const {
 47   return  - its_d/2.0;                             51   return  - its_d/2.0;
 48 }  // HepRotationZ::psi()                          52 }  // HepRotationZ::psi()
 49                                                    53 
 50 HepEulerAngles HepRotationZ::eulerAngles() con     54 HepEulerAngles HepRotationZ::eulerAngles() const {
 51   return HepEulerAngles(  phi(),  theta(),  ps     55   return HepEulerAngles(  phi(),  theta(),  psi() );
 52 }  // HepRotationZ::eulerAngles()                  56 }  // HepRotationZ::eulerAngles()
 53                                                    57 
 54                                                    58 
 55 // From the defining code in the implementatio     59 // From the defining code in the implementation of CLHEP (in Rotation.cc)
 56 // it is clear that thetaX, phiX form the pola     60 // it is clear that thetaX, phiX form the polar angles in the original
 57 // coordinate system of the new X axis (and si     61 // coordinate system of the new X axis (and similarly for phiY and phiZ).
 58 //                                                 62 //
 59 // This code is take directly from CLHEP origi     63 // This code is take directly from CLHEP original.  However, there are as
 60 // shown opportunities for significant speed i     64 // shown opportunities for significant speed improvement.
 61                                                    65 
 62 double HepRotationZ::phiX() const {                66 double HepRotationZ::phiX() const {
 63   return (yx() == 0.0 && xx() == 0.0) ? 0.0 :      67   return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
 64       // or ---- return d;                         68       // or ---- return d;
 65 }                                                  69 }
 66                                                    70 
 67 double HepRotationZ::phiY() const {                71 double HepRotationZ::phiY() const {
 68   return (yy() == 0.0 && xy() == 0.0) ? 0.0 :      72   return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
 69 }                                                  73 }
 70                                                    74 
 71 double HepRotationZ::phiZ() const {                75 double HepRotationZ::phiZ() const {
 72   return (yz() == 0.0 && xz() == 0.0) ? 0.0 :      76   return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
 73     // or ---- return 0.0;                         77     // or ---- return 0.0;
 74 }                                                  78 }
 75                                                    79 
 76 double HepRotationZ::thetaX() const {              80 double HepRotationZ::thetaX() const {
 77   return safe_acos(zx());                          81   return safe_acos(zx());
 78     // or ----  return CLHEP::halfpi;              82     // or ----  return CLHEP::halfpi;
 79 }                                                  83 }
 80                                                    84 
 81 double HepRotationZ::thetaY() const {              85 double HepRotationZ::thetaY() const {
 82   return safe_acos(zy());                          86   return safe_acos(zy());
 83     // or ----  return CLHEP::halfpi;              87     // or ----  return CLHEP::halfpi;
 84 }                                                  88 }
 85                                                    89 
 86 double HepRotationZ::thetaZ() const {              90 double HepRotationZ::thetaZ() const {
 87   return safe_acos(zz());                          91   return safe_acos(zz());  
 88     // or ---- return 0.0;                         92     // or ---- return 0.0;
 89 }                                                  93 }
 90                                                    94 
 91 void HepRotationZ::setDelta ( double ddelta )      95 void HepRotationZ::setDelta ( double ddelta ) {
 92   set(ddelta);                                     96   set(ddelta);
 93 }                                                  97 }
 94                                                    98 
 95 void HepRotationZ::decompose                       99 void HepRotationZ::decompose
 96   (HepAxisAngle & rotation, Hep3Vector & boost    100   (HepAxisAngle & rotation, Hep3Vector & boost) const {
 97   boost.set(0,0,0);                               101   boost.set(0,0,0);
 98   rotation = axisAngle();                         102   rotation = axisAngle();
 99 }                                                 103 }
100                                                   104 
101 void HepRotationZ::decompose                      105 void HepRotationZ::decompose
102   (Hep3Vector & boost, HepAxisAngle & rotation    106   (Hep3Vector & boost, HepAxisAngle & rotation) const {
103   boost.set(0,0,0);                               107   boost.set(0,0,0);
104   rotation = axisAngle();                         108   rotation = axisAngle();
105 }                                                 109 }
106                                                   110  
107 void HepRotationZ::decompose                      111 void HepRotationZ::decompose
108         (HepRotation & rotation, HepBoost & bo    112         (HepRotation & rotation, HepBoost & boost) const {
109   boost.set(0,0,0);                               113   boost.set(0,0,0);
110   rotation = HepRotation(*this);                  114   rotation = HepRotation(*this);
111 }                                                 115 }
112                                                   116                                                                                 
113 void HepRotationZ::decompose                      117 void HepRotationZ::decompose
114         (HepBoost & boost, HepRotation & rotat    118         (HepBoost & boost, HepRotation & rotation) const {
115   boost.set(0,0,0);                               119   boost.set(0,0,0);
116   rotation = HepRotation(*this);                  120   rotation = HepRotation(*this);
117 }                                                 121 }
118                                                   122 
119 double HepRotationZ::distance2( const HepRotat    123 double HepRotationZ::distance2( const HepRotationZ & r  ) const {
120   double answer = 2.0 * ( 1.0 - ( its_s * r.it    124   double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ;
121   return (answer >= 0) ? answer : 0;              125   return (answer >= 0) ? answer : 0;
122 }                                                 126 }
123                                                   127 
124 double HepRotationZ::distance2( const HepRotat    128 double HepRotationZ::distance2( const HepRotation & r  ) const {
125   double sum =    xx() * r.xx() + xy() * r.xy(    129   double sum =    xx() * r.xx() + xy() * r.xy()
126                    + yx() * r.yx() + yy() * r.    130                    + yx() * r.yx() + yy() * r.yy()
127                + r.zz();                          131                + r.zz();
128   double answer = 3.0 - sum;                      132   double answer = 3.0 - sum;
129   return (answer >= 0 ) ? answer : 0;             133   return (answer >= 0 ) ? answer : 0;
130 }                                                 134 }
131                                                   135 
132 double HepRotationZ::distance2( const HepLoren    136 double HepRotationZ::distance2( const HepLorentzRotation & lt  ) const {
133   HepAxisAngle a;                                 137   HepAxisAngle a; 
134   Hep3Vector   b;                                 138   Hep3Vector   b;
135   lt.decompose(b, a);                             139   lt.decompose(b, a);
136   double bet = b.beta();                          140   double bet = b.beta();
137   double bet2 = bet*bet;                          141   double bet2 = bet*bet;
138   HepRotation r(a);                               142   HepRotation r(a);
139   return bet2/(1-bet2) + distance2(r);            143   return bet2/(1-bet2) + distance2(r);
140 }                                                 144 }
141                                                   145 
142 double HepRotationZ::distance2( const HepBoost    146 double HepRotationZ::distance2( const HepBoost & lt ) const {
143   return distance2( HepLorentzRotation(lt));      147   return distance2( HepLorentzRotation(lt));
144 }                                                 148 }
145                                                   149 
146 double HepRotationZ::howNear( const HepRotatio    150 double HepRotationZ::howNear( const HepRotationZ & r ) const {
147   return std::sqrt(distance2(r));                 151   return std::sqrt(distance2(r));
148 }                                                 152 }
149 double HepRotationZ::howNear( const HepRotatio    153 double HepRotationZ::howNear( const HepRotation & r ) const {
150   return std::sqrt(distance2(r));                 154   return std::sqrt(distance2(r));
151 }                                                 155 }
152 double HepRotationZ::howNear( const HepBoost &    156 double HepRotationZ::howNear( const HepBoost & lt ) const {
153   return std::sqrt(distance2(lt));                157   return std::sqrt(distance2(lt));
154 }                                                 158 }
155 double HepRotationZ::howNear( const HepLorentz    159 double HepRotationZ::howNear( const HepLorentzRotation & lt ) const {
156   return std::sqrt(distance2(lt));                160   return std::sqrt(distance2(lt));
157 }                                                 161 }
158 bool HepRotationZ::isNear(const HepRotationZ &    162 bool HepRotationZ::isNear(const HepRotationZ & r,double epsilon)const {
159   return (distance2(r) <= epsilon*epsilon);       163   return (distance2(r) <= epsilon*epsilon);
160 }                                                 164 }
161 bool HepRotationZ::isNear(const HepRotation &     165 bool HepRotationZ::isNear(const HepRotation & r,double epsilon)const {
162   return (distance2(r) <= epsilon*epsilon);       166   return (distance2(r) <= epsilon*epsilon);
163 }                                                 167 }
164 bool HepRotationZ::isNear( const HepBoost & lt    168 bool HepRotationZ::isNear( const HepBoost & lt,double epsilon) const {
165   return (distance2(lt) <= epsilon*epsilon);      169   return (distance2(lt) <= epsilon*epsilon);
166 }                                                 170 }
167 bool HepRotationZ::isNear( const HepLorentzRot    171 bool HepRotationZ::isNear( const HepLorentzRotation & lt,
168                                      double ep    172                                      double epsilon) const {
169   return (distance2(lt) <= epsilon*epsilon);      173   return (distance2(lt) <= epsilon*epsilon);
170 }                                                 174 }
171                                                   175 
172 double HepRotationZ::norm2() const {              176 double HepRotationZ::norm2() const {
173   return 2.0 - 2.0 * its_c;                       177   return 2.0 - 2.0 * its_c;
174 }                                                 178 }
175                                                   179 
176 std::ostream & HepRotationZ::print( std::ostre    180 std::ostream & HepRotationZ::print( std::ostream & os ) const {
177   os << "\nRotation about Z (" << its_d <<        181   os << "\nRotation about Z (" << its_d <<
178                 ") [cos d = " << its_c << " si    182                 ") [cos d = " << its_c << " sin d = " << its_s << "]\n";
179   return os;                                      183   return os;
180 }                                                 184 }
181                                                   185 
182 }  // namespace CLHEP                             186 }  // namespace CLHEP
183                                                   187 
184                                                   188