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.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/RotationX.cc (Version 11.3.0) and /externals/clhep/src/RotationX.cc (Version 10.6)


  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 HepRotationX 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/RotationX.h"                14 #include "CLHEP/Vector/RotationX.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 HepRotationX::HepRotationX(double ddelta) :        31 HepRotationX::HepRotationX(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 HepRotationX & HepRotationX::set ( double ddel     35 HepRotationX & HepRotationX::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  HepRotationX::phi() const {                42 double  HepRotationX::phi() const {
 39   if ( (its_d > 0) && (its_d < CLHEP::pi) ) {      43   if ( (its_d > 0) && (its_d < CLHEP::pi) ) {
 40     return CLHEP::pi;                              44     return CLHEP::pi;
 41   } else {                                         45   } else {
 42     return 0.0;                                    46     return 0.0;
 43   }                                                47   }
 44 }  // HepRotationX::phi()                          48 }  // HepRotationX::phi()
 45                                                    49 
 46 double  HepRotationX::theta() const {              50 double  HepRotationX::theta() const {
 47   return  std::fabs( its_d );                      51   return  std::fabs( its_d );
 48 }  // HepRotationX::theta()                        52 }  // HepRotationX::theta()
 49                                                    53 
 50 double  HepRotationX::psi() const {                54 double  HepRotationX::psi() const {
 51   if ( (its_d > 0) && (its_d < CLHEP::pi) ) {      55   if ( (its_d > 0) && (its_d < CLHEP::pi) ) {
 52     return CLHEP::pi;                              56     return CLHEP::pi;
 53   } else {                                         57   } else {
 54     return 0.0;                                    58     return 0.0;
 55   }                                                59   }
 56 }  // HepRotationX::psi()                          60 }  // HepRotationX::psi()
 57                                                    61 
 58 HepEulerAngles HepRotationX::eulerAngles() con     62 HepEulerAngles HepRotationX::eulerAngles() const {
 59   return HepEulerAngles(  phi(), theta(),  psi     63   return HepEulerAngles(  phi(), theta(),  psi() );
 60 }  // HepRotationX::eulerAngles()                  64 }  // HepRotationX::eulerAngles()
 61                                                    65 
 62                                                    66 
 63 // From the defining code in the implementatio     67 // From the defining code in the implementation of CLHEP (in Rotation.cc)
 64 // it is clear that thetaX, phiX form the pola     68 // it is clear that thetaX, phiX form the polar angles in the original
 65 // coordinate system of the new X axis (and si     69 // coordinate system of the new X axis (and similarly for phiY and phiZ).
 66 //                                                 70 //
 67 // This code is taken directly from the origin     71 // This code is taken directly from the original CLHEP. However, there are as
 68 // shown opportunities for significant speed i     72 // shown opportunities for significant speed improvement.
 69                                                    73 
 70 double HepRotationX::phiX() const {                74 double HepRotationX::phiX() const {
 71   return (yx() == 0.0 && xx() == 0.0) ? 0.0 :      75   return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
 72       // or ---- return 0;                         76       // or ---- return 0;
 73 }                                                  77 }
 74                                                    78 
 75 double HepRotationX::phiY() const {                79 double HepRotationX::phiY() const {
 76   return (yy() == 0.0 && xy() == 0.0) ? 0.0 :      80   return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
 77     // or ----  return (yy() == 0.0) ? 0.0 : s     81     // or ----  return (yy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
 78 }                                                  82 }
 79                                                    83 
 80 double HepRotationX::phiZ() const {                84 double HepRotationX::phiZ() const {
 81   return (yz() == 0.0 && xz() == 0.0) ? 0.0 :      85   return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
 82     // or ----  return (yz() == 0.0) ? 0.0 : s     86     // or ----  return (yz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
 83 }                                                  87 }
 84                                                    88 
 85 double HepRotationX::thetaX() const {              89 double HepRotationX::thetaX() const {
 86   return safe_acos(zx());                          90   return safe_acos(zx());
 87     // or ----  return CLHEP::halfpi;              91     // or ----  return CLHEP::halfpi;
 88 }                                                  92 }
 89                                                    93 
 90 double HepRotationX::thetaY() const {              94 double HepRotationX::thetaY() const {
 91   return safe_acos(zy());                          95   return safe_acos(zy());
 92 }                                                  96 }
 93                                                    97 
 94 double HepRotationX::thetaZ() const {              98 double HepRotationX::thetaZ() const {
 95   return safe_acos(zz());                          99   return safe_acos(zz());  
 96     // or ---- return d;                          100     // or ---- return d;
 97 }                                                 101 }
 98                                                   102 
 99 void HepRotationX::setDelta ( double ddelta )     103 void HepRotationX::setDelta ( double ddelta ) {
100   set(ddelta);                                    104   set(ddelta);
101 }                                                 105 }
102                                                   106 
103 void HepRotationX::decompose                      107 void HepRotationX::decompose
104   (HepAxisAngle & rotation, Hep3Vector & boost    108   (HepAxisAngle & rotation, Hep3Vector & boost) const {
105   boost.set(0,0,0);                               109   boost.set(0,0,0);
106   rotation = axisAngle();                         110   rotation = axisAngle();
107 }                                                 111 }
108                                                   112 
109 void HepRotationX::decompose                      113 void HepRotationX::decompose
110   (Hep3Vector & boost, HepAxisAngle & rotation    114   (Hep3Vector & boost, HepAxisAngle & rotation) const {
111   boost.set(0,0,0);                               115   boost.set(0,0,0);
112   rotation = axisAngle();                         116   rotation = axisAngle();
113 }                                                 117 }
114                                                   118 
115 void HepRotationX::decompose                      119 void HepRotationX::decompose
116         (HepRotation & rotation, HepBoost & bo    120         (HepRotation & rotation, HepBoost & boost) const {
117   boost.set(0,0,0);                               121   boost.set(0,0,0);
118   rotation = HepRotation(*this);                  122   rotation = HepRotation(*this);
119 }                                                 123 } 
120                                                   124 
121 void HepRotationX::decompose                      125 void HepRotationX::decompose
122         (HepBoost & boost, HepRotation & rotat    126         (HepBoost & boost, HepRotation & rotation) const {
123   boost.set(0,0,0);                               127   boost.set(0,0,0);
124   rotation = HepRotation(*this);                  128   rotation = HepRotation(*this);
125 }                                                 129 }
126                                                   130 
127 double HepRotationX::distance2( const HepRotat    131 double HepRotationX::distance2( const HepRotationX & r  ) const {
128   double answer = 2.0 * ( 1.0 - ( its_s * r.it    132   double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ;
129   return (answer >= 0) ? answer : 0;              133   return (answer >= 0) ? answer : 0;
130 }                                                 134 }
131                                                   135 
132 double HepRotationX::distance2( const HepRotat    136 double HepRotationX::distance2( const HepRotation & r  ) const {
133   double sum =        r.xx() +                    137   double sum =        r.xx() + 
134                       yy() * r.yy() + yz() * r    138                       yy() * r.yy() + yz() * r.yz()
135                     + zy() * r.zy() + zz() * r    139                     + zy() * r.zy() + zz() * r.zz();
136   double answer = 3.0 - sum;                      140   double answer = 3.0 - sum;
137   return (answer >= 0 ) ? answer : 0;             141   return (answer >= 0 ) ? answer : 0;
138 }                                                 142 }
139                                                   143 
140 double HepRotationX::distance2( const HepLoren    144 double HepRotationX::distance2( const HepLorentzRotation & lt  ) const {
141   HepAxisAngle a;                                 145   HepAxisAngle a; 
142   Hep3Vector   b;                                 146   Hep3Vector   b;
143   lt.decompose(b, a);                             147   lt.decompose(b, a);
144   double bet = b.beta();                          148   double bet = b.beta();
145   double bet2 = bet*bet;                          149   double bet2 = bet*bet;
146   HepRotation r(a);                               150   HepRotation r(a);
147   return bet2/(1-bet2) + distance2(r);            151   return bet2/(1-bet2) + distance2(r);
148 }                                                 152 }
149                                                   153 
150 double HepRotationX::distance2( const HepBoost    154 double HepRotationX::distance2( const HepBoost & lt ) const {
151   return distance2( HepLorentzRotation(lt));      155   return distance2( HepLorentzRotation(lt));
152 }                                                 156 }
153                                                   157 
154 double HepRotationX::howNear( const HepRotatio    158 double HepRotationX::howNear( const HepRotationX & r ) const {
155   return std::sqrt(distance2(r));                 159   return std::sqrt(distance2(r));
156 }                                                 160 }
157 double HepRotationX::howNear( const HepRotatio    161 double HepRotationX::howNear( const HepRotation & r ) const {
158   return std::sqrt(distance2(r));                 162   return std::sqrt(distance2(r));
159 }                                                 163 }
160 double HepRotationX::howNear( const HepBoost &    164 double HepRotationX::howNear( const HepBoost & b ) const {
161   return std::sqrt(distance2(b));                 165   return std::sqrt(distance2(b));
162 }                                                 166 }
163 double HepRotationX::howNear( const HepLorentz    167 double HepRotationX::howNear( const HepLorentzRotation & lt ) const {
164   return std::sqrt(distance2(lt));                168   return std::sqrt(distance2(lt));
165 }                                                 169 }
166 bool HepRotationX::isNear(const HepRotationX &    170 bool HepRotationX::isNear(const HepRotationX & r,double epsilon)const{
167   return (distance2(r) <= epsilon*epsilon);       171   return (distance2(r) <= epsilon*epsilon);
168 }                                                 172 }
169 bool HepRotationX::isNear(const HepRotation &     173 bool HepRotationX::isNear(const HepRotation & r,double epsilon) const{
170   return (distance2(r) <= epsilon*epsilon);       174   return (distance2(r) <= epsilon*epsilon);
171 }                                                 175 }
172 bool HepRotationX::isNear( const HepBoost & lt    176 bool HepRotationX::isNear( const HepBoost & lt,double epsilon) const {
173   return (distance2(lt) <= epsilon*epsilon);      177   return (distance2(lt) <= epsilon*epsilon);
174 }                                                 178 }
175                                                   179 
176 bool HepRotationX::isNear( const HepLorentzRot    180 bool HepRotationX::isNear( const HepLorentzRotation & lt,
177                                      double ep    181                                      double epsilon ) const {
178   return (distance2(lt) <= epsilon*epsilon);      182   return (distance2(lt) <= epsilon*epsilon);
179 }                                                 183 }
180                                                   184 
181 double HepRotationX::norm2() const {              185 double HepRotationX::norm2() const {
182   return 2.0 - 2.0 * its_c;                       186   return 2.0 - 2.0 * its_c;
183 }                                                 187 }
184                                                   188 
185 std::ostream & HepRotationX::print( std::ostre    189 std::ostream & HepRotationX::print( std::ostream & os ) const {
186   os << "\nRotation about X (" << its_d <<        190   os << "\nRotation about X (" << its_d << 
187     ") [cos d = " << its_c << " sin d = " << i    191     ") [cos d = " << its_c << " sin d = " << its_s << "]\n";
188   return os;                                      192   return os;
189 }                                                 193 }
190                                                   194 
191 }  // namespace CLHEP                             195 }  // namespace CLHEP
192                                                   196 
193                                                   197