File indexing completed on 2025-12-15 10:28:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef ROOT_Math_GenVector_RotationZ
0018 #define ROOT_Math_GenVector_RotationZ 1
0019
0020
0021 #include "Math/GenVector/Cartesian3D.h"
0022 #include "Math/GenVector/DisplacementVector3D.h"
0023 #include "Math/GenVector/PositionVector3D.h"
0024 #include "Math/GenVector/LorentzVector.h"
0025 #include "Math/GenVector/3DDistances.h"
0026
0027 #include "Math/GenVector/RotationZfwd.h"
0028
0029 #include "TMath.h"
0030 #include <cmath>
0031
0032 namespace ROOT {
0033 namespace Math {
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 class RotationZ {
0047
0048 public:
0049
0050 typedef double Scalar;
0051
0052
0053
0054
0055
0056
0057
0058 RotationZ() : fAngle(0), fSin(0), fCos(1) { }
0059
0060
0061
0062
0063 explicit RotationZ( Scalar angle ) : fAngle(angle),
0064 fSin(std::sin(angle)),
0065 fCos(std::cos(angle))
0066 {
0067 Rectify();
0068 }
0069
0070
0071
0072
0073
0074
0075 void Rectify() {
0076 if (std::fabs(fAngle) >= TMath::Pi()) {
0077 double x = fAngle / TMath::TwoPi();
0078 fAngle = TMath::TwoPi() * (x + std::floor(.5 - x));
0079 fSin = std::sin(fAngle);
0080 fCos = std::cos(fAngle);
0081 }
0082 }
0083
0084
0085
0086
0087
0088
0089 void SetAngle (Scalar angle) {
0090 fSin=std::sin(angle);
0091 fCos=std::cos(angle);
0092 fAngle= angle;
0093 Rectify();
0094 }
0095 void SetComponents (Scalar angle) { SetAngle(angle); }
0096
0097
0098
0099
0100 void GetAngle(Scalar &angle) const { using std::atan2; angle = atan2(fSin, fCos); }
0101 void GetComponents ( Scalar & angle ) const { GetAngle(angle); }
0102
0103
0104
0105
0106 Scalar Angle() const { using std::atan2; return atan2(fSin, fCos); }
0107
0108
0109
0110
0111 Scalar SinAngle () const { return fSin; }
0112 Scalar CosAngle () const { return fCos; }
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128 template <class CoordSystem, class U>
0129 DisplacementVector3D<CoordSystem,U>
0130 operator() (const DisplacementVector3D<CoordSystem,U> & v) const {
0131 DisplacementVector3D< Cartesian3D<double>,U > xyz;
0132 xyz.SetXYZ( fCos*v.x()-fSin*v.y(), fCos*v.y()+fSin*v.x(), v.z() );
0133 return DisplacementVector3D<CoordSystem,U>(xyz);
0134 }
0135
0136
0137
0138
0139 template <class CoordSystem, class U>
0140 PositionVector3D<CoordSystem, U>
0141 operator() (const PositionVector3D<CoordSystem,U> & v) const {
0142 DisplacementVector3D< Cartesian3D<double>,U > xyz(v);
0143 DisplacementVector3D< Cartesian3D<double>,U > rxyz = operator()(xyz);
0144 return PositionVector3D<CoordSystem,U> ( rxyz );
0145 }
0146
0147
0148
0149
0150 template <class CoordSystem>
0151 LorentzVector<CoordSystem>
0152 operator() (const LorentzVector<CoordSystem> & v) const {
0153 DisplacementVector3D< Cartesian3D<double> > xyz(v.Vect());
0154 xyz = operator()(xyz);
0155 LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
0156 return LorentzVector<CoordSystem> ( xyzt );
0157 }
0158
0159
0160
0161
0162
0163
0164 template <class ForeignVector>
0165 ForeignVector
0166 operator() (const ForeignVector & v) const {
0167 DisplacementVector3D< Cartesian3D<double> > xyz(v);
0168 DisplacementVector3D< Cartesian3D<double> > rxyz = operator()(xyz);
0169 return ForeignVector ( rxyz.X(), rxyz.Y(), rxyz.Z() );
0170 }
0171
0172
0173
0174
0175 template <class AVector>
0176 inline
0177 AVector operator* (const AVector & v) const
0178 {
0179 return operator()(v);
0180 }
0181
0182
0183
0184
0185 void Invert() { fAngle = -fAngle; fSin = -fSin; }
0186
0187
0188
0189
0190 RotationZ Inverse() const { RotationZ t(*this); t.Invert(); return t; }
0191
0192
0193
0194
0195
0196
0197 RotationZ operator * (const RotationZ & r) const {
0198 RotationZ ans;
0199 double x = (fAngle + r.fAngle) / TMath::TwoPi();
0200 ans.fAngle = TMath::TwoPi() * (x + std::floor(.5 - x));
0201 ans.fSin = fSin*r.fCos + fCos*r.fSin;
0202 ans.fCos = fCos*r.fCos - fSin*r.fSin;
0203 return ans;
0204 }
0205
0206
0207
0208
0209 RotationZ & operator *= (const RotationZ & r) { return *this = (*this)*r; }
0210
0211
0212
0213
0214 bool operator == (const RotationZ & rhs) const {
0215 if( fAngle != rhs.fAngle ) return false;
0216 return true;
0217 }
0218 bool operator != (const RotationZ & rhs) const {
0219 return ! operator==(rhs);
0220 }
0221
0222 private:
0223
0224 Scalar fAngle;
0225 Scalar fSin;
0226 Scalar fCos;
0227
0228 };
0229
0230
0231
0232
0233
0234
0235 template <class R>
0236 inline
0237 typename RotationZ::Scalar
0238 Distance ( const RotationZ& r1, const R & r2) {return gv_detail::dist(r1,r2);}
0239
0240
0241
0242
0243
0244
0245 inline
0246 std::ostream & operator<< (std::ostream & os, const RotationZ & r) {
0247 os << " RotationZ(" << r.Angle() << ") ";
0248 return os;
0249 }
0250
0251
0252 }
0253 }
0254
0255 #endif