File indexing completed on 2025-01-18 10:10:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef ROOT_Math_GenVector_RotationZYX
0019 #define ROOT_Math_GenVector_RotationZYX 1
0020
0021 #include "Math/Math.h"
0022
0023 #include "Math/GenVector/Rotation3D.h"
0024
0025
0026 #include "Math/GenVector/DisplacementVector3D.h"
0027
0028 #include "Math/GenVector/PositionVector3D.h"
0029
0030 #include "Math/GenVector/LorentzVector.h"
0031
0032 #include "Math/GenVector/3DConversions.h"
0033
0034
0035 #include <algorithm>
0036 #include <cassert>
0037 #include <iostream>
0038
0039
0040 namespace ROOT {
0041 namespace Math {
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 class RotationZYX {
0064
0065 public:
0066
0067 typedef double Scalar;
0068
0069
0070
0071
0072
0073
0074
0075 RotationZYX() : fPhi(0.0), fTheta(0.0), fPsi(0.0) { }
0076
0077
0078
0079
0080 RotationZYX( Scalar phi, Scalar theta, Scalar psi ) :
0081 fPhi(phi), fTheta(theta), fPsi(psi)
0082 {Rectify();}
0083
0084
0085
0086
0087
0088
0089 template<class IT>
0090 RotationZYX(IT begin, IT end) { SetComponents(begin,end); }
0091
0092
0093
0094
0095
0096
0097 void Rectify();
0098
0099
0100
0101
0102
0103
0104
0105 template <class OtherRotation>
0106 explicit constexpr RotationZYX(const OtherRotation & r) {gv_detail::convert(r,*this);}
0107
0108
0109
0110
0111
0112 template <class OtherRotation>
0113 RotationZYX & operator=( OtherRotation const & r ) {
0114 gv_detail::convert(r,*this);
0115 return *this;
0116 }
0117
0118
0119
0120
0121
0122
0123
0124
0125 template<class IT>
0126 void SetComponents(IT begin, IT end) {
0127 fPhi = *begin++;
0128 fTheta = *begin++;
0129 fPsi = *begin++;
0130 (void)end;
0131 assert(begin == end);
0132 Rectify();
0133 }
0134
0135
0136
0137
0138
0139 template<class IT>
0140 void GetComponents(IT begin, IT end) const {
0141 *begin++ = fPhi;
0142 *begin++ = fTheta;
0143 *begin++ = fPsi;
0144 (void)end;
0145 assert(begin == end);
0146 }
0147
0148
0149
0150
0151 template<class IT>
0152 void GetComponents(IT begin) const {
0153 *begin++ = fPhi;
0154 *begin++ = fTheta;
0155 *begin = fPsi;
0156 }
0157
0158
0159
0160
0161 void SetComponents(Scalar phi, Scalar theta, Scalar psi) {
0162 fPhi=phi; fTheta=theta; fPsi=psi;
0163 Rectify();
0164 }
0165
0166
0167
0168
0169 void GetComponents(Scalar & phi, Scalar & theta, Scalar & psi) const {
0170 phi=fPhi; theta=fTheta; psi=fPsi;
0171 }
0172
0173
0174
0175
0176 void SetPhi(Scalar phi) { fPhi=phi; Rectify(); }
0177
0178
0179
0180
0181 Scalar Phi() const { return fPhi; }
0182
0183
0184
0185
0186 void SetTheta(Scalar theta) { fTheta=theta; Rectify(); }
0187
0188
0189
0190
0191 Scalar Theta() const { return fTheta; }
0192
0193
0194
0195
0196 void SetPsi(Scalar psi) { fPsi=psi; Rectify(); }
0197
0198
0199
0200
0201 Scalar Psi() const { return fPsi; }
0202
0203
0204
0205
0206
0207
0208
0209 template <class CoordSystem, class U>
0210 DisplacementVector3D<CoordSystem,U>
0211 operator() (const DisplacementVector3D<CoordSystem,U> & v) const {
0212 return Rotation3D(*this) ( v );
0213 }
0214
0215
0216
0217
0218 template <class CoordSystem, class U>
0219 PositionVector3D<CoordSystem, U>
0220 operator() (const PositionVector3D<CoordSystem,U> & v) const {
0221 DisplacementVector3D< Cartesian3D<double>,U > xyz(v);
0222 DisplacementVector3D< Cartesian3D<double>,U > rxyz = operator()(xyz);
0223 return PositionVector3D<CoordSystem,U> ( rxyz );
0224 }
0225
0226
0227
0228
0229 template <class CoordSystem>
0230 LorentzVector<CoordSystem>
0231 operator() (const LorentzVector<CoordSystem> & v) const {
0232 DisplacementVector3D< Cartesian3D<double> > xyz(v.Vect());
0233 xyz = operator()(xyz);
0234 LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
0235 return LorentzVector<CoordSystem> ( xyzt );
0236 }
0237
0238
0239
0240
0241
0242
0243 template <class ForeignVector>
0244 ForeignVector
0245 operator() (const ForeignVector & v) const {
0246 DisplacementVector3D< Cartesian3D<double> > xyz(v);
0247 DisplacementVector3D< Cartesian3D<double> > rxyz = operator()(xyz);
0248 return ForeignVector ( rxyz.X(), rxyz.Y(), rxyz.Z() );
0249 }
0250
0251
0252
0253
0254 template <class AVector>
0255 inline
0256 AVector operator* (const AVector & v) const
0257 {
0258 return operator()(v);
0259 }
0260
0261
0262
0263
0264 void Invert();
0265
0266
0267
0268
0269 RotationZYX Inverse() const {
0270 RotationZYX r(*this);
0271 r.Invert();
0272 return r;
0273 }
0274
0275
0276
0277
0278
0279
0280
0281 RotationZYX operator * (const RotationZYX & e) const;
0282 RotationZYX operator * (const Rotation3D & r) const;
0283 RotationZYX operator * (const AxisAngle & a) const;
0284 RotationZYX operator * (const Quaternion & q) const;
0285 RotationZYX operator * (const EulerAngles & q) const;
0286 RotationZYX operator * (const RotationX & rx) const;
0287 RotationZYX operator * (const RotationY & ry) const;
0288 RotationZYX operator * (const RotationZ & rz) const;
0289
0290
0291
0292
0293 template <class R>
0294 RotationZYX & operator *= (const R & r) { return *this = (*this)*r; }
0295
0296
0297
0298
0299 template <class R>
0300 Scalar Distance ( const R & r ) const {return gv_detail::dist(*this,r);}
0301
0302
0303
0304
0305 bool operator == (const RotationZYX & rhs) const {
0306 if( fPhi != rhs.fPhi ) return false;
0307 if( fTheta != rhs.fTheta ) return false;
0308 if( fPsi != rhs.fPsi ) return false;
0309 return true;
0310 }
0311 bool operator != (const RotationZYX & rhs) const {
0312 return ! operator==(rhs);
0313 }
0314
0315 private:
0316
0317 double fPhi;
0318 double fTheta;
0319 double fPsi;
0320
0321 static double Pi() { return M_PI; }
0322
0323 };
0324
0325
0326
0327
0328 template <class R>
0329 inline
0330 typename RotationZYX::Scalar
0331 Distance ( const RotationZYX& r1, const R & r2) {return gv_detail::dist(r1,r2);}
0332
0333
0334
0335
0336 RotationZYX operator* (RotationX const & r1, RotationZYX const & r2);
0337 RotationZYX operator* (RotationY const & r1, RotationZYX const & r2);
0338 RotationZYX operator* (RotationZ const & r1, RotationZYX const & r2);
0339
0340
0341
0342
0343
0344
0345 std::ostream & operator<< (std::ostream & os, const RotationZYX & e);
0346
0347
0348 }
0349 }
0350
0351 #endif