File indexing completed on 2025-01-18 10:10:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef ROOT_Math_GenVector_CylindricalEta3D
0021 #define ROOT_Math_GenVector_CylindricalEta3D 1
0022
0023 #include "Math/Math.h"
0024
0025 #include "Math/GenVector/etaMax.h"
0026
0027
0028 #include <limits>
0029 #include <cmath>
0030
0031
0032 namespace ROOT {
0033
0034 namespace Math {
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 template <class T>
0048 class CylindricalEta3D {
0049
0050 public :
0051
0052 typedef T Scalar;
0053 static constexpr unsigned int Dimension = 3U;
0054
0055
0056
0057
0058 CylindricalEta3D() : fRho(0), fEta(0), fPhi(0) { }
0059
0060
0061
0062
0063 CylindricalEta3D(Scalar rho, Scalar eta, Scalar phi) :
0064 fRho(rho), fEta(eta), fPhi(phi) { Restrict(); }
0065
0066
0067
0068
0069
0070 template <class CoordSystem >
0071 explicit CylindricalEta3D( const CoordSystem & v ) :
0072 fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() )
0073 {
0074 using std::log;
0075 static Scalar bigEta = Scalar(-0.3) * log(std::numeric_limits<Scalar>::epsilon());
0076 if (std::fabs(fEta) > bigEta) {
0077
0078
0079
0080 fRho *= v.Z() / Z();
0081 }
0082 }
0083
0084
0085
0086
0087
0088
0089
0090 CylindricalEta3D(const CylindricalEta3D & v) :
0091 fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() ) { }
0092
0093
0094
0095
0096 CylindricalEta3D & operator= (const CylindricalEta3D & v) {
0097 fRho = v.Rho();
0098 fEta = v.Eta();
0099 fPhi = v.Phi();
0100 return *this;
0101 }
0102
0103
0104
0105
0106 void SetCoordinates( const Scalar src[] )
0107 { fRho=src[0]; fEta=src[1]; fPhi=src[2]; Restrict(); }
0108
0109
0110
0111
0112 void GetCoordinates( Scalar dest[] ) const
0113 { dest[0] = fRho; dest[1] = fEta; dest[2] = fPhi; }
0114
0115
0116
0117
0118 void SetCoordinates(Scalar rho, Scalar eta, Scalar phi)
0119 { fRho=rho; fEta=eta; fPhi=phi; Restrict(); }
0120
0121
0122
0123
0124 void GetCoordinates(Scalar& rho, Scalar& eta, Scalar& phi) const
0125 {rho=fRho; eta=fEta; phi=fPhi;}
0126
0127 private:
0128 inline static Scalar pi() { return M_PI; }
0129 inline void Restrict() {
0130 using std::floor;
0131 if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi();
0132 return;
0133 }
0134 public:
0135
0136
0137
0138 T Rho() const { return fRho; }
0139 T Eta() const { return fEta; }
0140 T Phi() const { return fPhi; }
0141 T X() const { using std::cos; return fRho * cos(fPhi); }
0142 T Y() const { using std::sin; return fRho * sin(fPhi); }
0143 T Z() const
0144 {
0145 using std::sinh;
0146 return fRho > 0 ? fRho * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax<T>() : fEta + etaMax<T>();
0147 }
0148 T R() const
0149 {
0150 using std::cosh;
0151 return fRho > 0 ? fRho * cosh(fEta)
0152 : fEta > etaMax<T>() ? fEta - etaMax<T>() : fEta < -etaMax<T>() ? -fEta - etaMax<T>() : 0;
0153 }
0154 T Mag2() const
0155 {
0156 const Scalar r = R();
0157 return r * r;
0158 }
0159 T Perp2() const { return fRho*fRho; }
0160 T Theta() const { using std::atan; return fRho > 0 ? 2 * atan(exp(-fEta)) : (fEta >= 0 ? 0 : pi()); }
0161
0162
0163
0164
0165
0166
0167
0168 void SetRho(T rho) {
0169 fRho = rho;
0170 }
0171
0172
0173
0174
0175 void SetEta(T eta) {
0176 fEta = eta;
0177 }
0178
0179
0180
0181
0182 void SetPhi(T phi) {
0183 fPhi = phi;
0184 Restrict();
0185 }
0186
0187
0188
0189
0190 void SetXYZ(Scalar x, Scalar y, Scalar z);
0191
0192
0193
0194
0195
0196
0197 void Scale (T a) {
0198 if (a < 0) {
0199 Negate();
0200 a = -a;
0201 }
0202
0203 if (fRho > 0) {
0204 fRho *= a;
0205 } else if ( fEta > etaMax<T>() ) {
0206 fEta = ( fEta-etaMax<T>())*a + etaMax<T>();
0207 } else if ( fEta < -etaMax<T>() ) {
0208 fEta = ( fEta+etaMax<T>())*a - etaMax<T>();
0209 }
0210
0211 }
0212
0213
0214
0215
0216 void Negate ( ) {
0217 fPhi = ( fPhi > 0 ? fPhi - pi() : fPhi + pi() );
0218 fEta = -fEta;
0219 }
0220
0221
0222
0223
0224
0225 template <class CoordSystem >
0226 CylindricalEta3D & operator= ( const CoordSystem & c ) {
0227 fRho = c.Rho();
0228 fEta = c.Eta();
0229 fPhi = c.Phi();
0230 return *this;
0231 }
0232
0233
0234
0235
0236
0237
0238 bool operator==(const CylindricalEta3D & rhs) const {
0239 return fRho == rhs.fRho && fEta == rhs.fEta && fPhi == rhs.fPhi;
0240 }
0241 bool operator!= (const CylindricalEta3D & rhs) const
0242 {return !(operator==(rhs));}
0243
0244
0245
0246
0247
0248
0249 T x() const { return X();}
0250 T y() const { return Y();}
0251 T z() const { return Z(); }
0252
0253
0254
0255
0256
0257 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
0258
0259
0260
0261 void SetX(Scalar x);
0262
0263 void SetY(Scalar y);
0264
0265 void SetZ(Scalar z);
0266
0267 void SetR(Scalar r);
0268
0269 void SetTheta(Scalar theta);
0270
0271
0272 #endif
0273
0274
0275 private:
0276 T fRho;
0277 T fEta;
0278 T fPhi;
0279
0280 };
0281
0282 }
0283
0284 }
0285
0286
0287
0288
0289 #include "Math/GenVector/Cartesian3D.h"
0290
0291 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
0292 #include "Math/GenVector/GenVector_exception.h"
0293 #include "Math/GenVector/Polar3D.h"
0294 #endif
0295
0296 namespace ROOT {
0297
0298 namespace Math {
0299
0300 template <class T>
0301 void CylindricalEta3D<T>::SetXYZ(Scalar xx, Scalar yy, Scalar zz) {
0302 *this = Cartesian3D<Scalar>(xx, yy, zz);
0303 }
0304
0305 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
0306
0307
0308
0309
0310
0311 template <class T>
0312 void CylindricalEta3D<T>::SetX(Scalar xx) {
0313 GenVector_exception e("CylindricalEta3D::SetX() is not supposed to be called");
0314 throw e;
0315 Cartesian3D<Scalar> v(*this); v.SetX(xx);
0316 *this = CylindricalEta3D<Scalar>(v);
0317 }
0318 template <class T>
0319 void CylindricalEta3D<T>::SetY(Scalar yy) {
0320 GenVector_exception e("CylindricalEta3D::SetY() is not supposed to be called");
0321 throw e;
0322 Cartesian3D<Scalar> v(*this); v.SetY(yy);
0323 *this = CylindricalEta3D<Scalar>(v);
0324 }
0325 template <class T>
0326 void CylindricalEta3D<T>::SetZ(Scalar zz) {
0327 GenVector_exception e("CylindricalEta3D::SetZ() is not supposed to be called");
0328 throw e;
0329 Cartesian3D<Scalar> v(*this); v.SetZ(zz);
0330 *this = CylindricalEta3D<Scalar>(v);
0331 }
0332 template <class T>
0333 void CylindricalEta3D<T>::SetR(Scalar r) {
0334 GenVector_exception e("CylindricalEta3D::SetR() is not supposed to be called");
0335 throw e;
0336 Polar3D<Scalar> v(*this); v.SetR(r);
0337 *this = CylindricalEta3D<Scalar>(v);
0338 }
0339 template <class T>
0340 void CylindricalEta3D<T>::SetTheta(Scalar theta) {
0341 GenVector_exception e("CylindricalEta3D::SetTheta() is not supposed to be called");
0342 throw e;
0343 Polar3D<Scalar> v(*this); v.SetTheta(theta);
0344 *this = CylindricalEta3D<Scalar>(v);
0345 }
0346
0347 #endif
0348
0349
0350 }
0351
0352 }
0353
0354
0355
0356 #endif