From 76a8f9db222c8a77460591262c3623aadbb87a1b Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 15:40:19 +0000 Subject: [PATCH 01/44] Template the GenVector Plane3D, Transform3D and Translation3D classes on their scalar type --- math/genvector/inc/Math/GenVector/Plane3D.h | 120 +++-- .../inc/Math/GenVector/Transform3D.h | 491 +++++++++++++----- .../inc/Math/GenVector/Translation3D.h | 66 ++- math/genvector/src/Plane3D.cxx | 88 ---- math/genvector/src/Transform3D.cxx | 205 -------- math/genvector/src/Translation3D.cxx | 40 -- 6 files changed, 482 insertions(+), 528 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Plane3D.h b/math/genvector/inc/Math/GenVector/Plane3D.h index a0eda70fd02ce..ffd1ff35737f2 100644 --- a/math/genvector/inc/Math/GenVector/Plane3D.h +++ b/math/genvector/inc/Math/GenVector/Plane3D.h @@ -26,7 +26,7 @@ namespace ROOT { namespace Math { - +namespace Impl { //_______________________________________________________________________________ /** @@ -38,22 +38,24 @@ namespace Math { belonging to plane. More information on the mathematics describing a plane in 3D is available on MathWord. - The Plane3D class contains the 4 scalar values in double which represent the + The Plane3D class contains the 4 scalar values in T which represent the four coefficients, fA, fB, fC, fD. fA, fB, fC are the normal components normalized to 1, i.e. fA**2 + fB**2 + fC**2 = 1 @ingroup GenVector */ + + template class Plane3D { public: // ------ ctors ------ - typedef double Scalar; + typedef T Scalar; - typedef DisplacementVector3D, DefaultCoordinateSystemTag > Vector; - typedef PositionVector3D, DefaultCoordinateSystemTag > Point; + typedef DisplacementVector3D, DefaultCoordinateSystemTag > Vector; + typedef PositionVector3D, DefaultCoordinateSystemTag > Point; @@ -70,12 +72,18 @@ namespace Math { \param c scalar value \param d sxcalar value */ - Plane3D(const Scalar & a, const Scalar & b, const Scalar & c, const Scalar & d); + Plane3D(const Scalar & a, const Scalar & b, const Scalar & c, const Scalar & d) + : fA(a), fB(b), fC(c), fD(d) + { + //renormalize a,b,c to unit + Normalize(); + } + /** constructor a Plane3D from a normal vector and a point coplanar to the plane - \param n normal expressed as a ROOT::Math::DisplacementVector3D > - \param p point expressed as a ROOT::Math::PositionVector3D > + \param n normal expressed as a ROOT::Math::DisplacementVector3D > + \param p point expressed as a ROOT::Math::PositionVector3D > */ Plane3D(const Vector & n, const Point & p ) { @@ -107,9 +115,9 @@ namespace Math { /** constructor from three generic point belonging to the plane - \param p1 point1 expressed as ROOT::Math::DisplacementVector3D > - \param p2 point2 expressed as ROOT::Math::DisplacementVector3D > - \param p3 point3 expressed as ROOT::Math::DisplacementVector3D > + \param p1 point1 expressed as ROOT::Math::DisplacementVector3D > + \param p2 point2 expressed as ROOT::Math::DisplacementVector3D > + \param p3 point3 expressed as ROOT::Math::DisplacementVector3D > */ template Plane3D(const PositionVector3D & p1, const PositionVector3D & p2, const PositionVector3D & p3 ) @@ -182,33 +190,38 @@ namespace Math { normal vector to the plane. \param p Point expressed in Cartesian Coordinates */ - Scalar Distance(const Point & p) const; - + Scalar Distance(const Point & p) const + { + return fA*p.X() + fB*p.Y() + fC*p.Z() + fD; + } + /** Return the distance to a Point described with generic coordinates \param p Point expressed as generic ROOT::Math::PositionVector3D */ - template - Scalar Distance(const PositionVector3D & p) const { + template + Scalar Distance(const PositionVector3D & p) const { return Distance( Point(p.X(), p.Y(), p.Z() ) ); } /** Return the projection of a Cartesian point to a plane - \param p Point expressed as PositionVector3D > + \param p Point expressed as PositionVector3D > */ - Point ProjectOntoPlane(const Point & p) const; + Point ProjectOntoPlane(const Point & p) const + { + const Scalar d = Distance(p); + return XYZPoint( p.X() - fA*d, p.Y() - fB*d, p.Z() - fC*d); + } /** Return the projection of a point to a plane \param p Point expressed as generic ROOT::Math::PositionVector3D */ - template - PositionVector3D ProjectOntoPlane(const PositionVector3D & p) const { - Point pxyz = ProjectOntoPlane(Point(p.X(), p.Y(), p.Z() ) ); - PositionVector3D p2; - p2.SetXYZ( pxyz.X(), pxyz.Y(), pxyz.Z() ); - return p2; + template + PositionVector3D ProjectOntoPlane(const PositionVector3D & p) const { + const Point pxyz = ProjectOntoPlane(Point(p.X(), p.Y(), p.Z() ) ); + return PositionVector3D( pxyz.X(), pxyz.Y(), pxyz.Z() ); } @@ -230,16 +243,46 @@ namespace Math { /** Normalize the normal (a,b,c) plane components */ - void Normalize(); - + void Normalize() + { + // normalize the plane + const Scalar s = std::sqrt( fA*fA + fB*fB + fC*fC ); + // what to do if s = 0 ?? + // CRJ - This does not work with Vc types... ToDo decide how to handle... + //if ( s == 0 ) { fD = 0; return; } + const Scalar w = Scalar(1)/s; + fA *= w; + fB *= w; + fC *= w; + fD *= w; + } private: // internal method to construct class from a vector and a point - void BuildFromVecAndPoint(const Vector & n, const Point & p); + void BuildFromVecAndPoint(const Vector & n, const Point & p) + { + // build from a normal vector and a point + fA = n.X(); + fB = n.Y(); + fC = n.Z(); + fD = - n.Dot(p); + Normalize(); + } + // internal method to construct class from 3 points - void BuildFrom3Points(const Point & p1, const Point & p2, const Point & p3); - + void BuildFrom3Points(const Point & p1, const Point & p2, const Point & p3) + { + // plane from thre points + // normal is (x3-x1) cross (x2 -x1) + const Vector n = (p2-p1).Cross(p3-p1); + fA = n.X(); + fB = n.Y(); + fC = n.Z(); + fD = - n.Dot(p1); + Normalize(); + } + // plane data members the four scalar which satisfies fA*x + fB*y + fC*z + fD = 0 // for every point (x,y,z) belonging to the plane. // fA**2 + fB**2 + fC** =1 plane is stored in normalized form @@ -255,10 +298,23 @@ namespace Math { Stream Output and Input */ // TODO - I/O should be put in the manipulator form - - std::ostream & operator<< (std::ostream & os, const Plane3D & p); - - + template < typename T > + std::ostream & operator<< (std::ostream & os, const Plane3D & p) + { + os << "\n" << p.Normal().X() + << " " << p.Normal().Y() + << " " << p.Normal().Z() + << " " << p.HesseDistance() + << "\n"; + return os; + } + +} // end namespace Impl + +// typedefs for double and float versions +typedef Impl::Plane3D Plane3D; +typedef Impl::Plane3D Plane3DF; + } // end namespace Math } // end namespace ROOT diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index 1071594a8f1d1..6ea7707ff1400 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -45,8 +45,7 @@ namespace ROOT { namespace Math { - - class Plane3D; +namespace Impl { //_________________________________________________________________________________________ @@ -74,13 +73,16 @@ namespace Math { */ +template class Transform3D { public: - typedef DisplacementVector3D, DefaultCoordinateSystemTag > Vector; - typedef PositionVector3D, DefaultCoordinateSystemTag > Point; + typedef T Scalar; + + typedef DisplacementVector3D, DefaultCoordinateSystemTag > Vector; + typedef PositionVector3D, DefaultCoordinateSystemTag > Point; enum ETransform3DMatrixIndex { @@ -119,7 +121,7 @@ class Transform3D { /** Construct from a rotation and then a translation described by a Translation3D class */ - Transform3D( const Rotation3D & r, const Translation3D & t) + Transform3D( const Rotation3D & r, const Translation3D & t) { AssignFrom( r, t.Vect() ); } @@ -143,7 +145,7 @@ class Transform3D { Rotation3D class */ template - Transform3D( const ARotation & r, const Translation3D & t) + Transform3D( const ARotation & r, const Translation3D & t) { AssignFrom( Rotation3D(r), t.Vect() ); } @@ -214,7 +216,7 @@ class Transform3D { Construct from a translation only, represented by a Translation3D class and with an identity rotation */ - explicit Transform3D( const Translation3D & t) { + explicit Transform3D( const Translation3D & t) { AssignFrom(t.Vect()); } @@ -254,7 +256,76 @@ class Transform3D { */ Transform3D (const Point & fr0, const Point & fr1, const Point & fr2, - const Point & to0, const Point & to1, const Point & to2 ); + const Point & to0, const Point & to1, const Point & to2 ) + { + // takes impl. from CLHEP ( E.Chernyaev). To be checked + + Vector x1 = (fr1 - fr0).Unit(); + Vector y1 = (fr2 - fr0).Unit(); + Vector x2 = (to1 - to0).Unit(); + Vector y2 = (to2 - to0).Unit(); + + // C H E C K A N G L E S + + const T cos1 = x1.Dot(y1); + const T cos2 = x2.Dot(y2); + + if (std::fabs(1.0-cos1) <= 0.000001 || std::fabs(1.0-cos2) <= 0.000001) { + std::cerr << "Transform3D: Error : zero angle between axes" << std::endl; + SetIdentity(); + } else { + if (std::fabs(cos1-cos2) > 0.000001) { + std::cerr << "Transform3D: Warning: angles between axes are not equal" + << std::endl; + } + + // F I N D R O T A T I O N M A T R I X + + Vector z1 = (x1.Cross(y1)).Unit(); + y1 = z1.Cross(x1); + + Vector z2 = (x2.Cross(y2)).Unit(); + y2 = z2.Cross(x2); + + T x1x = x1.x(); T x1y = x1.y(); T x1z = x1.z(); + T y1x = y1.x(); T y1y = y1.y(); T y1z = y1.z(); + T z1x = z1.x(); T z1y = z1.y(); T z1z = z1.z(); + + T x2x = x2.x(); T x2y = x2.y(); T x2z = x2.z(); + T y2x = y2.x(); T y2y = y2.y(); T y2z = y2.z(); + T z2x = z2.x(); T z2y = z2.y(); T z2z = z2.z(); + + T detxx = (y1y *z1z - z1y *y1z ); + T detxy = -(y1x *z1z - z1x *y1z ); + T detxz = (y1x *z1y - z1x *y1y ); + T detyx = -(x1y *z1z - z1y *x1z ); + T detyy = (x1x *z1z - z1x *x1z ); + T detyz = -(x1x *z1y - z1x *x1y ); + T detzx = (x1y *y1z - y1y *x1z ); + T detzy = -(x1x *y1z - y1x *x1z ); + T detzz = (x1x *y1y - y1x *x1y ); + + T txx = x2x *detxx + y2x *detyx + z2x *detzx; + T txy = x2x *detxy + y2x *detyy + z2x *detzy; + T txz = x2x *detxz + y2x *detyz + z2x *detzz; + T tyx = x2y *detxx + y2y *detyx + z2y *detzx; + T tyy = x2y *detxy + y2y *detyy + z2y *detzy; + T tyz = x2y *detxz + y2y *detyz + z2y *detzz; + T tzx = x2z *detxx + y2z *detyx + z2z *detzx; + T tzy = x2z *detxy + y2z *detyy + z2z *detzy; + T tzz = x2z *detxz + y2z *detyz + z2z *detzz; + + // S E T T R A N S F O R M A T I O N + + T dx1 = fr0.x(), dy1 = fr0.y(), dz1 = fr0.z(); + T dx2 = to0.x(), dy2 = to0.y(), dz2 = to0.z(); + + SetComponents(txx, txy, txz, dx2-txx*dx1-txy*dy1-txz*dz1, + tyx, tyy, tyz, dy2-tyx*dx1-tyy*dy1-tyz*dz1, + tzx, tzy, tzz, dz2-tzx*dx1-tzy*dy1-tzz*dz1); + } + } + // use compiler generated copy ctor, copy assignmet and dtor @@ -273,9 +344,9 @@ class Transform3D { /** Raw constructor from 12 Scalar components */ - Transform3D(double xx, double xy, double xz, double dx, - double yx, double yy, double yz, double dy, - double zx, double zy, double zz, double dz) + Transform3D(T xx, T xy, T xz, T dx, + T yx, T yy, T yz, T dy, + T zx, T zy, T zz, T dz) { SetComponents (xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz); } @@ -288,7 +359,7 @@ class Transform3D { are described by the 4-th column */ template - Transform3D & operator= (const ForeignMatrix & m) { + Transform3D & operator= (const ForeignMatrix & m) { SetComponents(m); return *this; } @@ -371,9 +442,9 @@ class Transform3D { Set the components from 12 scalars */ void - SetComponents (double xx, double xy, double xz, double dx, - double yx, double yy, double yz, double dy, - double zx, double zy, double zz, double dz) { + SetComponents (T xx, T xy, T xz, T dx, + T yx, T yy, T yz, T dy, + T zx, T zy, T zz, T dz) { fM[kXX]=xx; fM[kXY]=xy; fM[kXZ]=xz; fM[kDX]=dx; fM[kYX]=yx; fM[kYY]=yy; fM[kYZ]=yz; fM[kDY]=dy; fM[kZX]=zx; fM[kZY]=zy; fM[kZZ]=zz; fM[kDZ]=dz; @@ -383,9 +454,9 @@ class Transform3D { Get the components into 12 scalars */ void - GetComponents (double &xx, double &xy, double &xz, double &dx, - double &yx, double &yy, double &yz, double &dy, - double &zx, double &zy, double &zz, double &dz) const { + GetComponents (T &xx, T &xy, T &xz, T &dx, + T &yx, T &yy, T &yz, T &dy, + T &zx, T &zy, T &zz, T &dz) const { xx=fM[kXX]; xy=fM[kXY]; xz=fM[kXZ]; dx=fM[kDX]; yx=fM[kYX]; yy=fM[kYY]; yz=fM[kYZ]; dy=fM[kDY]; zx=fM[kZX]; zy=fM[kZY]; zz=fM[kZZ]; dz=fM[kDZ]; @@ -441,8 +512,8 @@ class Transform3D { /** Get the translation representing the 3D transformation in a Cartesian vector */ - Translation3D Translation() const { - return Translation3D( fM[kDX], fM[kDY], fM[kDZ] ); + Translation3D Translation() const { + return Translation3D( fM[kDX], fM[kDY], fM[kDZ] ); } /** @@ -485,7 +556,7 @@ class Transform3D { */ template PositionVector3D operator() (const PositionVector3D & p) const { - Point xyzNew = operator() ( Point(p) ); + const Point xyzNew = operator() ( Point(p) ); return PositionVector3D (xyzNew); } @@ -494,7 +565,7 @@ class Transform3D { */ template DisplacementVector3D operator() (const DisplacementVector3D & v) const { - Vector xyzNew = operator() ( Vector(v) ); + const Vector xyzNew = operator() ( Vector(v) ); return DisplacementVector3D (xyzNew); } @@ -503,7 +574,7 @@ class Transform3D { */ template void Transform (const PositionVector3D & p1, PositionVector3D & p2 ) const { - Point xyzNew = operator() ( Point(p1.X(), p1.Y(), p1.Z()) ); + const Point xyzNew = operator() ( Point(p1.X(), p1.Y(), p1.Z()) ); p2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() ); } @@ -513,7 +584,7 @@ class Transform3D { */ template void Transform (const DisplacementVector3D & v1, DisplacementVector3D & v2 ) const { - Vector xyzNew = operator() ( Vector(v1.X(), v1.Y(), v1.Z() ) ); + const Vector xyzNew = operator() ( Vector(v1.X(), v1.Y(), v1.Z() ) ); v2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() ); } @@ -522,14 +593,23 @@ class Transform3D { */ template LorentzVector operator() (const LorentzVector & q) const { - Vector xyzNew = operator() ( Vector(q.Vect() ) ); + const Vector xyzNew = operator() ( Vector(q.Vect() ) ); return LorentzVector (xyzNew.X(), xyzNew.Y(), xyzNew.Z(), q.E() ); } /** Transformation on a 3D plane */ - Plane3D operator() (const Plane3D & plane) const; + Plane3D operator() (const Plane3D & plane) const + { + // transformations on a 3D plane + const Vector n = plane.Normal(); + // take a point on the plane. Use origin projection on the plane + // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1 + T d = plane.HesseDistance(); + Point p( - d * n.X() , - d *n.Y(), -d *n.Z() ); + return Plane3D( operator() (n), operator() (p) ); + } // skip transformation for arbitrary vectors - not really defined if point or displacement vectors @@ -550,23 +630,51 @@ class Transform3D { /** multiply (combine) with another transformation in place */ - inline Transform3D & operator *= (const Transform3D & t); + inline Transform3D & operator *= (const Transform3D & t); /** multiply (combine) two transformations */ - inline Transform3D operator * (const Transform3D & t) const; + inline Transform3D operator * (const Transform3D & t) const; /** Invert the transformation in place */ - void Invert(); + void Invert() + { + // + // Name: Transform3D::inverse Date: 24.09.96 + // Author: E.Chernyaev (IHEP/Protvino) Revised: + // + // Function: Find inverse affine transformation. + + const T detxx = fM[kYY]*fM[kZZ] - fM[kYZ]*fM[kZY]; + const T detxy = fM[kYX]*fM[kZZ] - fM[kYZ]*fM[kZX]; + const T detxz = fM[kYX]*fM[kZY] - fM[kYY]*fM[kZX]; + const T det = fM[kXX]*detxx - fM[kXY]*detxy + fM[kXZ]*detxz; + if (det == 0) { + std::cerr << "Transform3D::inverse error: zero determinant" << std::endl; + return; + } + det = 1./det; detxx *= det; detxy *= det; detxz *= det; + const T detyx = (fM[kXY]*fM[kZZ] - fM[kXZ]*fM[kZY] )*det; + const T detyy = (fM[kXX]*fM[kZZ] - fM[kXZ]*fM[kZX] )*det; + const T detyz = (fM[kXX]*fM[kZY] - fM[kXY]*fM[kZX] )*det; + const T detzx = (fM[kXY]*fM[kYZ] - fM[kXZ]*fM[kYY] )*det; + const T detzy = (fM[kXX]*fM[kYZ] - fM[kXZ]*fM[kYX] )*det; + const T detzz = (fM[kXX]*fM[kYY] - fM[kXY]*fM[kYX] )*det; + SetComponents + (detxx, -detyx, detzx, -detxx*fM[kDX]+detyx*fM[kDY]-detzx*fM[kDZ], + -detxy, detyy, -detzy, detxy*fM[kDX]-detyy*fM[kDY]+detzy*fM[kDZ], + detxz, -detyz, detzz, -detxz*fM[kDX]+detyz*fM[kDY]-detzz*fM[kDZ]); + } + /** Return the inverse of the transformation. */ - Transform3D Inverse() const { - Transform3D t(*this); + Transform3D Inverse() const { + Transform3D t(*this); t.Invert(); return t; } @@ -574,29 +682,28 @@ class Transform3D { /** Equality operator. Check equality for each element - To do: use double tolerance + To do: use T tolerance */ - bool operator == (const Transform3D & rhs) const { - if( fM[0] != rhs.fM[0] ) return false; - if( fM[1] != rhs.fM[1] ) return false; - if( fM[2] != rhs.fM[2] ) return false; - if( fM[3] != rhs.fM[3] ) return false; - if( fM[4] != rhs.fM[4] ) return false; - if( fM[5] != rhs.fM[5] ) return false; - if( fM[6] != rhs.fM[6] ) return false; - if( fM[7] != rhs.fM[7] ) return false; - if( fM[8] != rhs.fM[8] ) return false; - if( fM[9] != rhs.fM[9] ) return false; - if( fM[10]!= rhs.fM[10] ) return false; - if( fM[11]!= rhs.fM[11] ) return false; - return true; + bool operator == (const Transform3D & rhs) const { + return ( fM[0] == rhs.fM[0] && + fM[1] == rhs.fM[1] && + fM[2] == rhs.fM[2] && + fM[3] == rhs.fM[3] && + fM[4] == rhs.fM[4] && + fM[5] == rhs.fM[5] && + fM[6] == rhs.fM[6] && + fM[7] == rhs.fM[7] && + fM[8] == rhs.fM[8] && + fM[9] == rhs.fM[9] && + fM[10]== rhs.fM[10] && + fM[11]== rhs.fM[11] ); } /** Inequality operator. Check equality for each element - To do: use double tolerance + To do: use T tolerance */ - bool operator != (const Transform3D & rhs) const { + bool operator != (const Transform3D & rhs) const { return ! operator==(rhs); } @@ -606,27 +713,73 @@ class Transform3D { /** make transformation from first a rotation then a translation */ - void AssignFrom( const Rotation3D & r, const Vector & v); + void AssignFrom( const Rotation3D & r, const Vector & v) + { + // assignment from rotation + translation + + T rotData[9]; + r.GetComponents(rotData, rotData +9); + // first raw + for (int i = 0; i < 3; ++i) + fM[i] = rotData[i]; + // second raw + for (int i = 0; i < 3; ++i) + fM[kYX+i] = rotData[3+i]; + // third raw + for (int i = 0; i < 3; ++i) + fM[kZX+i] = rotData[6+i]; + + // translation data + T vecData[3]; + v.GetCoordinates(vecData, vecData+3); + fM[kDX] = vecData[0]; + fM[kDY] = vecData[1]; + fM[kDZ] = vecData[2]; + } + /** make transformation from only rotations (zero translation) */ - void AssignFrom( const Rotation3D & r); + void AssignFrom( const Rotation3D & r) + { + // assign from only a rotation (null translation) + T rotData[9]; + r.GetComponents(rotData, rotData +9); + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) + fM[4*i + j] = rotData[3*i+j]; + // empty vector data + fM[4*i + 3] = 0; + } + } /** make transformation from only translation (identity rotations) */ - void AssignFrom( const Vector & v); - + void AssignFrom( const Vector & v ) + { + // assign from a translation only (identity rotations) + fM[kXX] = 1.0; fM[kXY] = 0.0; fM[kXZ] = 0.0; fM[kDX] = v.X(); + fM[kYX] = 0.0; fM[kYY] = 1.0; fM[kYZ] = 0.0; fM[kDY] = v.Y(); + fM[kZX] = 0.0; fM[kZY] = 0.0; fM[kZZ] = 1.0; fM[kDZ] = v.Z(); + } + /** Set identity transformation (identity rotation , zero translation) */ - void SetIdentity() ; + void SetIdentity() + { + //set identity ( identity rotation and zero translation) + fM[kXX] = 1.0; fM[kXY] = 0.0; fM[kXZ] = 0.0; fM[kDX] = 0.0; + fM[kYX] = 0.0; fM[kYY] = 1.0; fM[kYZ] = 0.0; fM[kDY] = 0.0; + fM[kZX] = 0.0; fM[kZY] = 0.0; fM[kZZ] = 1.0; fM[kDZ] = 0.0; + } private: - double fM[12]; // transformation elements (3x4 matrix) + T fM[12]; // transformation elements (3x4 matrix) }; @@ -634,8 +787,9 @@ class Transform3D { // inline functions (combination of transformations) - -inline Transform3D & Transform3D::operator *= (const Transform3D & t) + +template +inline Transform3D & Transform3D::operator *= (const Transform3D & t) { // combination of transformations @@ -658,26 +812,26 @@ inline Transform3D & Transform3D::operator *= (const Transform3D & t) } - -inline Transform3D Transform3D::operator * (const Transform3D & t) const +template +inline Transform3D Transform3D::operator * (const Transform3D & t) const { // combination of transformations - return Transform3D(fM[kXX]*t.fM[kXX]+fM[kXY]*t.fM[kYX]+fM[kXZ]*t.fM[kZX], - fM[kXX]*t.fM[kXY]+fM[kXY]*t.fM[kYY]+fM[kXZ]*t.fM[kZY], - fM[kXX]*t.fM[kXZ]+fM[kXY]*t.fM[kYZ]+fM[kXZ]*t.fM[kZZ], - fM[kXX]*t.fM[kDX]+fM[kXY]*t.fM[kDY]+fM[kXZ]*t.fM[kDZ]+fM[kDX], - - fM[kYX]*t.fM[kXX]+fM[kYY]*t.fM[kYX]+fM[kYZ]*t.fM[kZX], - fM[kYX]*t.fM[kXY]+fM[kYY]*t.fM[kYY]+fM[kYZ]*t.fM[kZY], - fM[kYX]*t.fM[kXZ]+fM[kYY]*t.fM[kYZ]+fM[kYZ]*t.fM[kZZ], - fM[kYX]*t.fM[kDX]+fM[kYY]*t.fM[kDY]+fM[kYZ]*t.fM[kDZ]+fM[kDY], - - fM[kZX]*t.fM[kXX]+fM[kZY]*t.fM[kYX]+fM[kZZ]*t.fM[kZX], - fM[kZX]*t.fM[kXY]+fM[kZY]*t.fM[kYY]+fM[kZZ]*t.fM[kZY], - fM[kZX]*t.fM[kXZ]+fM[kZY]*t.fM[kYZ]+fM[kZZ]*t.fM[kZZ], - fM[kZX]*t.fM[kDX]+fM[kZY]*t.fM[kDY]+fM[kZZ]*t.fM[kDZ]+fM[kDZ] ); - + return Transform3D(fM[kXX]*t.fM[kXX]+fM[kXY]*t.fM[kYX]+fM[kXZ]*t.fM[kZX], + fM[kXX]*t.fM[kXY]+fM[kXY]*t.fM[kYY]+fM[kXZ]*t.fM[kZY], + fM[kXX]*t.fM[kXZ]+fM[kXY]*t.fM[kYZ]+fM[kXZ]*t.fM[kZZ], + fM[kXX]*t.fM[kDX]+fM[kXY]*t.fM[kDY]+fM[kXZ]*t.fM[kDZ]+fM[kDX], + + fM[kYX]*t.fM[kXX]+fM[kYY]*t.fM[kYX]+fM[kYZ]*t.fM[kZX], + fM[kYX]*t.fM[kXY]+fM[kYY]*t.fM[kYY]+fM[kYZ]*t.fM[kZY], + fM[kYX]*t.fM[kXZ]+fM[kYY]*t.fM[kYZ]+fM[kYZ]*t.fM[kZZ], + fM[kYX]*t.fM[kDX]+fM[kYY]*t.fM[kDY]+fM[kYZ]*t.fM[kDZ]+fM[kDY], + + fM[kZX]*t.fM[kXX]+fM[kZY]*t.fM[kYX]+fM[kZZ]*t.fM[kZX], + fM[kZX]*t.fM[kXY]+fM[kZY]*t.fM[kYY]+fM[kZZ]*t.fM[kZY], + fM[kZX]*t.fM[kXZ]+fM[kZY]*t.fM[kYZ]+fM[kZZ]*t.fM[kZZ], + fM[kZX]*t.fM[kDX]+fM[kZY]*t.fM[kDY]+fM[kZZ]*t.fM[kDZ]+fM[kDZ] ); + } @@ -693,36 +847,44 @@ inline Transform3D Transform3D::operator * (const Transform3D & t) const combine a translation and a rotation to give a transform3d First the translation then the rotation */ -inline Transform3D operator * (const Rotation3D & r, const Translation3D & t) { - return Transform3D( r, r(t.Vect()) ); +template +inline Transform3D operator * (const Rotation3D & r, const Translation3D & t) { + return Transform3D( r, r(t.Vect()) ); } -inline Transform3D operator * (const RotationX & r, const Translation3D & t) { +template +inline Transform3D operator * (const RotationX & r, const Translation3D & t) { Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D( r3, r3(t.Vect()) ); } -inline Transform3D operator * (const RotationY & r, const Translation3D & t) { +template +inline Transform3D operator * (const RotationY & r, const Translation3D & t) { Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D( r3, r3(t.Vect()) ); } -inline Transform3D operator * (const RotationZ & r, const Translation3D & t) { +template +inline Transform3D operator * (const RotationZ & r, const Translation3D & t) { Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D( r3, r3(t.Vect()) ); } -inline Transform3D operator * (const RotationZYX & r, const Translation3D & t) { +template +inline Transform3D operator * (const RotationZYX & r, const Translation3D & t) { Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D( r3, r3(t.Vect()) ); } -inline Transform3D operator * (const AxisAngle & r, const Translation3D & t) { +template +inline Transform3D operator * (const AxisAngle & r, const Translation3D & t) { Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D( r3, r3(t.Vect()) ); } -inline Transform3D operator * (const EulerAngles & r, const Translation3D & t) { +template +inline Transform3D operator * (const EulerAngles & r, const Translation3D & t) { Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D( r3, r3(t.Vect()) ); } -inline Transform3D operator * (const Quaternion & r, const Translation3D & t) { +template +inline Transform3D operator * (const Quaternion & r, const Translation3D & t) { Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D( r3, r3(t.Vect()) ); } // ------ combination of a rotation (first) and then a translation ------ @@ -731,29 +893,37 @@ inline Transform3D operator * (const Quaternion & r, const Translation3D & t) { combine a rotation and a translation to give a transform3d First a rotation then the translation */ -inline Transform3D operator * (const Translation3D & t, const Rotation3D & r) { - return Transform3D( r, t.Vect()); +template +inline Transform3D operator * (const Translation3D & t, const Rotation3D & r) { + return Transform3D( r, t.Vect()); } -inline Transform3D operator * (const Translation3D & t, const RotationX & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +template +inline Transform3D operator * (const Translation3D & t, const RotationX & r) { + return Transform3D( Rotation3D(r) , t.Vect()); } -inline Transform3D operator * (const Translation3D & t, const RotationY & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +template +inline Transform3D operator * (const Translation3D & t, const RotationY & r) { + return Transform3D( Rotation3D(r) , t.Vect()); } -inline Transform3D operator * (const Translation3D & t, const RotationZ & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +template +inline Transform3D operator * (const Translation3D & t, const RotationZ & r) { + return Transform3D( Rotation3D(r) , t.Vect()); } -inline Transform3D operator * (const Translation3D & t, const RotationZYX & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +template +inline Transform3D operator * (const Translation3D & t, const RotationZYX & r) { + return Transform3D( Rotation3D(r) , t.Vect()); } -inline Transform3D operator * (const Translation3D & t, const EulerAngles & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +template +inline Transform3D operator * (const Translation3D & t, const EulerAngles & r) { + return Transform3D( Rotation3D(r) , t.Vect()); } -inline Transform3D operator * (const Translation3D & t, const Quaternion & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +template +inline Transform3D operator * (const Translation3D & t, const Quaternion & r) { + return Transform3D( Rotation3D(r) , t.Vect()); } -inline Transform3D operator * (const Translation3D & t, const AxisAngle & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +template +inline Transform3D operator * (const Translation3D & t, const AxisAngle & r) { + return Transform3D( Rotation3D(r) , t.Vect()); } // ------ combination of a Transform3D and a pure translation------ @@ -762,17 +932,19 @@ inline Transform3D operator * (const Translation3D & t, const AxisAngle & r) { combine a transformation and a translation to give a transform3d First the translation then the transform3D */ -inline Transform3D operator * (const Transform3D & t, const Translation3D & d) { +template +inline Transform3D operator * (const Transform3D & t, const Translation3D & d) { Rotation3D r = t.Rotation(); - return Transform3D( r, r( d.Vect() ) + t.Translation().Vect() ); + return Transform3D( r, r( d.Vect() ) + t.Translation().Vect() ); } /** combine a translation and a transformation to give a transform3d First the transformation then the translation */ -inline Transform3D operator * (const Translation3D & d, const Transform3D & t) { - return Transform3D( t.Rotation(), t.Translation().Vect() + d.Vect()); +template +inline Transform3D operator * (const Translation3D & d, const Transform3D & t) { + return Transform3D( t.Rotation(), t.Translation().Vect() + d.Vect()); } // ------ combination of a Transform3D and any rotation------ @@ -782,29 +954,37 @@ inline Transform3D operator * (const Translation3D & d, const Transform3D & t) { combine a transformation and a rotation to give a transform3d First the rotation then the transform3D */ -inline Transform3D operator * (const Transform3D & t, const Rotation3D & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +template +inline Transform3D operator * (const Transform3D & t, const Rotation3D & r) { + return Transform3D( t.Rotation()*r , t.Translation() ); } -inline Transform3D operator * (const Transform3D & t, const RotationX & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +template +inline Transform3D operator * (const Transform3D & t, const RotationX & r) { + return Transform3D( t.Rotation()*r , t.Translation() ); } -inline Transform3D operator * (const Transform3D & t, const RotationY & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +template +inline Transform3D operator * (const Transform3D & t, const RotationY & r) { + return Transform3D( t.Rotation()*r , t.Translation() ); } -inline Transform3D operator * (const Transform3D & t, const RotationZ & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +template +inline Transform3D operator * (const Transform3D & t, const RotationZ & r) { + return Transform3D( t.Rotation()*r , t.Translation() ); } -inline Transform3D operator * (const Transform3D & t, const RotationZYX & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +template +inline Transform3D operator * (const Transform3D & t, const RotationZYX & r) { + return Transform3D( t.Rotation()*r , t.Translation() ); } -inline Transform3D operator * (const Transform3D & t, const EulerAngles & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +template +inline Transform3D operator * (const Transform3D & t, const EulerAngles & r) { + return Transform3D( t.Rotation()*r , t.Translation() ); } -inline Transform3D operator * (const Transform3D & t, const AxisAngle & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +template +inline Transform3D operator * (const Transform3D & t, const AxisAngle & r) { + return Transform3D( t.Rotation()*r , t.Translation() ); } -inline Transform3D operator * (const Transform3D & t, const Quaternion & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +template +inline Transform3D operator * (const Transform3D & t, const Quaternion & r) { + return Transform3D( t.Rotation()*r , t.Translation() ); } @@ -813,36 +993,44 @@ inline Transform3D operator * (const Transform3D & t, const Quaternion & r) { combine a rotation and a transformation to give a transform3d First the transformation then the rotation */ -inline Transform3D operator * (const Rotation3D & r, const Transform3D & t) { - return Transform3D( r * t.Rotation(), r * t.Translation().Vect() ); +template +inline Transform3D operator * (const Rotation3D & r, const Transform3D & t) { + return Transform3D( r * t.Rotation(), r * t.Translation().Vect() ); } -inline Transform3D operator * (const RotationX & r, const Transform3D & t) { +template +inline Transform3D operator * (const RotationX & r, const Transform3D & t) { Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); } -inline Transform3D operator * (const RotationY & r, const Transform3D & t) { +template +inline Transform3D operator * (const RotationY & r, const Transform3D & t) { Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); } -inline Transform3D operator * (const RotationZ & r, const Transform3D & t) { +template +inline Transform3D operator * (const RotationZ & r, const Transform3D & t) { Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); } -inline Transform3D operator * (const RotationZYX & r, const Transform3D & t) { +template +inline Transform3D operator * (const RotationZYX & r, const Transform3D & t) { Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); } -inline Transform3D operator * (const EulerAngles & r, const Transform3D & t) { +template +inline Transform3D operator * (const EulerAngles & r, const Transform3D & t) { Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); } -inline Transform3D operator * (const AxisAngle & r, const Transform3D & t) { +template +inline Transform3D operator * (const AxisAngle & r, const Transform3D & t) { Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); } -inline Transform3D operator * (const Quaternion & r, const Transform3D & t) { +template +inline Transform3D operator * (const Quaternion & r, const Transform3D & t) { Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); } @@ -852,10 +1040,27 @@ inline Transform3D operator * (const Quaternion & r, const Transform3D & t) { /** print the 12 components of the Transform3D */ -std::ostream & operator<< (std::ostream & os, const Transform3D & t); +template +std::ostream & operator<< (std::ostream & os, const Transform3D & t) +{ + // TODO - this will need changing for machine-readable issues + // and even the human readable form needs formatting improvements + + T m[12]; + t.GetComponents(m, m+12); + os << "\n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3] ; + os << "\n" << m[4] << " " << m[5] << " " << m[6] << " " << m[7] ; + os << "\n" << m[8] << " " << m[9] << " " << m[10]<< " " << m[11] << "\n"; + return os; +} + +} // end namespace Impl +// typedefs for double and float versions +typedef Impl::Transform3D Transform3D; +typedef Impl::Transform3D Transform3DF; - } // end namespace Math +} // end namespace Math } // end namespace ROOT diff --git a/math/genvector/inc/Math/GenVector/Translation3D.h b/math/genvector/inc/Math/GenVector/Translation3D.h index b7d0d8feff7aa..daa50c613d71d 100644 --- a/math/genvector/inc/Math/GenVector/Translation3D.h +++ b/math/genvector/inc/Math/GenVector/Translation3D.h @@ -19,6 +19,8 @@ #include "Math/GenVector/DisplacementVector3D.h" +#include "Math/GenVector/Plane3D.h" + #include "Math/GenVector/PositionVector3Dfwd.h" #include "Math/GenVector/LorentzVectorfwd.h" @@ -31,10 +33,8 @@ namespace ROOT { namespace Math { - - class Plane3D; - - +namespace Impl { + //____________________________________________________________________________________________________ /** Class describing a 3 dimensional translation. It can be combined (using the operator *) @@ -48,12 +48,15 @@ namespace Math { */ +template class Translation3D { public: - typedef DisplacementVector3D, DefaultCoordinateSystemTag > Vector; + typedef T Scalar; + + typedef DisplacementVector3D, DefaultCoordinateSystemTag > Vector; @@ -76,7 +79,7 @@ class Translation3D { /** Construct from x,y,z values representing the translation */ - Translation3D(double dx, double dy, double dz) : + Translation3D(T dx, T dy, T dz) : fVect( Vector(dx, dy, dz) ) { } @@ -144,7 +147,7 @@ class Translation3D { Set the components from 3 scalars */ void - SetComponents (double dx, double dy, double dz ) { + SetComponents (T dx, T dy, T dz ) { fVect.SetCoordinates(dx,dy,dz); } @@ -152,7 +155,7 @@ class Translation3D { Get the components into 3 scalars */ void - GetComponents (double &dx, double &dy, double &dz) const { + GetComponents (T &dx, T &dy, T &dz) const { fVect.GetCoordinates(dx,dy,dz); } @@ -161,7 +164,7 @@ class Translation3D { Set the XYZ vector components from 3 scalars */ void - SetXYZ (double dx, double dy, double dz ) { + SetXYZ (T dx, T dy, T dz ) { fVect.SetXYZ(dx,dy,dz); } @@ -222,8 +225,16 @@ class Translation3D { /** Transformation on a 3D plane */ - Plane3D operator() (const Plane3D & plane) const; - + Plane3D operator() ( const Plane3D & plane ) const + { + // transformations on a 3D plane + Vector n = plane.Normal(); + // take a point on the plane. Use origin projection on the plane + // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1 + T d = plane.HesseDistance(); + PositionVector3D > p( - d * n.X() , - d *n.Y(), -d *n.Z() ); + return PLANE( operator() (n), operator() (p) ); + } /** Transformation operation for Vectors. Apply same rules as operator() @@ -240,7 +251,7 @@ class Translation3D { /** multiply (combine) with another transformation in place */ - Translation3D & operator *= (const Translation3D & t) { + Translation3D & operator *= (const Translation3D & t) { fVect+= t.Vect(); return *this; } @@ -248,8 +259,8 @@ class Translation3D { /** multiply (combine) two transformations */ - Translation3D operator * (const Translation3D & t) const { - return Translation3D( fVect + t.Vect() ); + Translation3D operator * (const Translation3D & t) const { + return Translation3D( fVect + t.Vect() ); } /** @@ -262,20 +273,20 @@ class Translation3D { /** Return the inverse of the transformation. */ - Translation3D Inverse() const { - return Translation3D( -fVect.X(), -fVect.Y(),-fVect.Z() ); + Translation3D Inverse() const { + return Translation3D( -fVect.X(), -fVect.Y(),-fVect.Z() ); } /** Equality/inequality operators */ - bool operator == (const Translation3D & rhs) const { + bool operator == (const Translation3D & rhs) const { if( fVect != rhs.fVect ) return false; return true; } - bool operator != (const Translation3D & rhs) const { + bool operator != (const Translation3D & rhs) const { return ! operator==(rhs); } @@ -295,11 +306,26 @@ class Translation3D { // TODO - I/O should be put in the manipulator form -std::ostream & operator<< (std::ostream & os, const Translation3D & t); +template +std::ostream & operator<< (std::ostream & os, const Translation3D & t) +{ + // TODO - this will need changing for machine-readable issues + // and even the human readable form needs formatiing improvements + + T m[3]; + t.GetComponents(m, m+3); + return os << "\n" << m[0] << " " << m[1] << " " << m[2] << "\n"; +} // need a function Transform = Translation * Rotation ??? - } // end namespace Math +} // end namespace Impl + +// typedefs for double and float versions +typedef Impl::Translation3D Translation3D; +typedef Impl::Translation3D Translation3DF; + +} // end namespace Math } // end namespace ROOT diff --git a/math/genvector/src/Plane3D.cxx b/math/genvector/src/Plane3D.cxx index 6b8d25c02e65d..d01f62da0f8d1 100644 --- a/math/genvector/src/Plane3D.cxx +++ b/math/genvector/src/Plane3D.cxx @@ -19,91 +19,3 @@ #include - - -namespace ROOT { - -namespace Math { - - -typedef Plane3D::Scalar Scalar; -typedef Plane3D::Point XYZPoint; -typedef Plane3D::Vector XYZVector; - -// ========== Constructors and Assignment ===================== - - -// constructor from 4 scalars numbers (a,b,c,d) -Plane3D::Plane3D(const Scalar & a, const Scalar & b, const Scalar & c, const Scalar & d) : - fA(a), fB(b), fC(c), fD(d) -{ - //renormalize a,b,c to unit - Normalize(); -} - -// internal method to construct from a normal vector and a point -void Plane3D::BuildFromVecAndPoint(const XYZVector & n, const XYZPoint & p ) -{ - // build from a normal vector and a point - fA = n.X(); - fB = n.Y(); - fC = n.Z(); - fD = - n.Dot(p); - Normalize(); -} - -// internl method to construct from three points -void Plane3D::BuildFrom3Points( const XYZPoint & p1, const XYZPoint & p2, const XYZPoint & p3 ) { - - // plane from thre points - // normal is (x3-x1) cross (x2 -x1) - XYZVector n = (p2-p1).Cross(p3-p1); - fA = n.X(); - fB = n.Y(); - fC = n.Z(); - fD = - n.Dot(p1); - Normalize(); -} - -// distance plane- point -Scalar Plane3D::Distance(const XYZPoint & p) const { - return fA*p.X() + fB*p.Y() + fC*p.Z() + fD; -} - -void Plane3D::Normalize() { - // normalize the plane - Scalar s = std::sqrt( fA*fA + fB*fB + fC*fC ); - // what to do if s = 0 ?? - if ( s == 0) { fD = 0; return; } - Scalar w = 1./s; - fA *= w; - fB *= w; - fC *= w; - fD *= w; -} - - -// projection of a point onto the plane -XYZPoint Plane3D::ProjectOntoPlane(const XYZPoint & p) const { - Scalar d = Distance(p); - return XYZPoint( p.X() - fA*d, p.Y() - fB*d, p.Z() - fC*d); -} - - -// output -std::ostream & operator<< (std::ostream & os, const Plane3D & p) { - os << "\n" << p.Normal().X() - << " " << p.Normal().Y() - << " " << p.Normal().Z() - << " " << p.HesseDistance() - << "\n"; - return os; -} - - - - - -} // end namespace Math -} // end namespace ROOT - diff --git a/math/genvector/src/Transform3D.cxx b/math/genvector/src/Transform3D.cxx index 0bc7c83e8e84b..266be6177a4c7 100644 --- a/math/genvector/src/Transform3D.cxx +++ b/math/genvector/src/Transform3D.cxx @@ -21,208 +21,3 @@ #include #include - - - -namespace ROOT { - -namespace Math { - - -typedef Transform3D::Point XYZPoint; -typedef Transform3D::Vector XYZVector; - - -// ========== Constructors and Assignment ===================== - - - -// construct from two ref frames -Transform3D::Transform3D(const XYZPoint & fr0, const XYZPoint & fr1, const XYZPoint & fr2, - const XYZPoint & to0, const XYZPoint & to1, const XYZPoint & to2 ) -{ - // takes impl. from CLHEP ( E.Chernyaev). To be checked - - XYZVector x1,y1,z1, x2,y2,z2; - x1 = (fr1 - fr0).Unit(); - y1 = (fr2 - fr0).Unit(); - x2 = (to1 - to0).Unit(); - y2 = (to2 - to0).Unit(); - - // C H E C K A N G L E S - - double cos1, cos2; - cos1 = x1.Dot(y1); - cos2 = x2.Dot(y2); - - if (std::fabs(1.0-cos1) <= 0.000001 || std::fabs(1.0-cos2) <= 0.000001) { - std::cerr << "Transform3D: Error : zero angle between axes" << std::endl; - SetIdentity(); - } else { - if (std::fabs(cos1-cos2) > 0.000001) { - std::cerr << "Transform3D: Warning: angles between axes are not equal" - << std::endl; - } - - // F I N D R O T A T I O N M A T R I X - - z1 = (x1.Cross(y1)).Unit(); - y1 = z1.Cross(x1); - - z2 = (x2.Cross(y2)).Unit(); - y2 = z2.Cross(x2); - - double x1x = x1.x(); double x1y = x1.y(); double x1z = x1.z(); - double y1x = y1.x(); double y1y = y1.y(); double y1z = y1.z(); - double z1x = z1.x(); double z1y = z1.y(); double z1z = z1.z(); - - double x2x = x2.x(); double x2y = x2.y(); double x2z = x2.z(); - double y2x = y2.x(); double y2y = y2.y(); double y2z = y2.z(); - double z2x = z2.x(); double z2y = z2.y(); double z2z = z2.z(); - - double detxx = (y1y *z1z - z1y *y1z ); - double detxy = -(y1x *z1z - z1x *y1z ); - double detxz = (y1x *z1y - z1x *y1y ); - double detyx = -(x1y *z1z - z1y *x1z ); - double detyy = (x1x *z1z - z1x *x1z ); - double detyz = -(x1x *z1y - z1x *x1y ); - double detzx = (x1y *y1z - y1y *x1z ); - double detzy = -(x1x *y1z - y1x *x1z ); - double detzz = (x1x *y1y - y1x *x1y ); - - double txx = x2x *detxx + y2x *detyx + z2x *detzx; - double txy = x2x *detxy + y2x *detyy + z2x *detzy; - double txz = x2x *detxz + y2x *detyz + z2x *detzz; - double tyx = x2y *detxx + y2y *detyx + z2y *detzx; - double tyy = x2y *detxy + y2y *detyy + z2y *detzy; - double tyz = x2y *detxz + y2y *detyz + z2y *detzz; - double tzx = x2z *detxx + y2z *detyx + z2z *detzx; - double tzy = x2z *detxy + y2z *detyy + z2z *detzy; - double tzz = x2z *detxz + y2z *detyz + z2z *detzz; - - // S E T T R A N S F O R M A T I O N - - double dx1 = fr0.x(), dy1 = fr0.y(), dz1 = fr0.z(); - double dx2 = to0.x(), dy2 = to0.y(), dz2 = to0.z(); - - SetComponents(txx, txy, txz, dx2-txx*dx1-txy*dy1-txz*dz1, - tyx, tyy, tyz, dy2-tyx*dx1-tyy*dy1-tyz*dz1, - tzx, tzy, tzz, dz2-tzx*dx1-tzy*dy1-tzz*dz1); - } -} - - -// inversion (from CLHEP) -void Transform3D::Invert() -{ - // - // Name: Transform3D::inverse Date: 24.09.96 - // Author: E.Chernyaev (IHEP/Protvino) Revised: - // - // Function: Find inverse affine transformation. - - double detxx = fM[kYY]*fM[kZZ] - fM[kYZ]*fM[kZY]; - double detxy = fM[kYX]*fM[kZZ] - fM[kYZ]*fM[kZX]; - double detxz = fM[kYX]*fM[kZY] - fM[kYY]*fM[kZX]; - double det = fM[kXX]*detxx - fM[kXY]*detxy + fM[kXZ]*detxz; - if (det == 0) { - std::cerr << "Transform3D::inverse error: zero determinant" << std::endl; - return; - } - det = 1./det; detxx *= det; detxy *= det; detxz *= det; - double detyx = (fM[kXY]*fM[kZZ] - fM[kXZ]*fM[kZY] )*det; - double detyy = (fM[kXX]*fM[kZZ] - fM[kXZ]*fM[kZX] )*det; - double detyz = (fM[kXX]*fM[kZY] - fM[kXY]*fM[kZX] )*det; - double detzx = (fM[kXY]*fM[kYZ] - fM[kXZ]*fM[kYY] )*det; - double detzy = (fM[kXX]*fM[kYZ] - fM[kXZ]*fM[kYX] )*det; - double detzz = (fM[kXX]*fM[kYY] - fM[kXY]*fM[kYX] )*det; - SetComponents - (detxx, -detyx, detzx, -detxx*fM[kDX]+detyx*fM[kDY]-detzx*fM[kDZ], - -detxy, detyy, -detzy, detxy*fM[kDX]-detyy*fM[kDY]+detzy*fM[kDZ], - detxz, -detyz, detzz, -detxz*fM[kDX]+detyz*fM[kDY]-detzz*fM[kDZ]); -} - - - - -void Transform3D::SetIdentity() -{ - //set identity ( identity rotation and zero translation) - fM[kXX] = 1.0; fM[kXY] = 0.0; fM[kXZ] = 0.0; fM[kDX] = 0.0; - fM[kYX] = 0.0; fM[kYY] = 1.0; fM[kYZ] = 0.0; fM[kDY] = 0.0; - fM[kZX] = 0.0; fM[kZY] = 0.0; fM[kZZ] = 1.0; fM[kDZ] = 0.0; -} - - -void Transform3D::AssignFrom (const Rotation3D & r, const XYZVector & v) -{ - // assignment from rotation + translation - - double rotData[9]; - r.GetComponents(rotData, rotData +9); - // first raw - for (int i = 0; i < 3; ++i) - fM[i] = rotData[i]; - // second raw - for (int i = 0; i < 3; ++i) - fM[kYX+i] = rotData[3+i]; - // third raw - for (int i = 0; i < 3; ++i) - fM[kZX+i] = rotData[6+i]; - - // translation data - double vecData[3]; - v.GetCoordinates(vecData, vecData+3); - fM[kDX] = vecData[0]; - fM[kDY] = vecData[1]; - fM[kDZ] = vecData[2]; -} - - -void Transform3D::AssignFrom(const Rotation3D & r) -{ - // assign from only a rotation (null translation) - double rotData[9]; - r.GetComponents(rotData, rotData +9); - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 3; ++j) - fM[4*i + j] = rotData[3*i+j]; - // empty vector data - fM[4*i + 3] = 0; - } -} - -void Transform3D::AssignFrom(const XYZVector & v) -{ - // assign from a translation only (identity rotations) - fM[kXX] = 1.0; fM[kXY] = 0.0; fM[kXZ] = 0.0; fM[kDX] = v.X(); - fM[kYX] = 0.0; fM[kYY] = 1.0; fM[kYZ] = 0.0; fM[kDY] = v.Y(); - fM[kZX] = 0.0; fM[kZY] = 0.0; fM[kZZ] = 1.0; fM[kDZ] = v.Z(); -} - -Plane3D Transform3D::operator() (const Plane3D & plane) const -{ - // transformations on a 3D plane - XYZVector n = plane.Normal(); - // take a point on the plane. Use origin projection on the plane - // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1 - double d = plane.HesseDistance(); - XYZPoint p( - d * n.X() , - d *n.Y(), -d *n.Z() ); - return Plane3D ( operator() (n), operator() (p) ); -} - -std::ostream & operator<< (std::ostream & os, const Transform3D & t) -{ - // TODO - this will need changing for machine-readable issues - // and even the human readable form needs formatting improvements - - double m[12]; - t.GetComponents(m, m+12); - os << "\n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3] ; - os << "\n" << m[4] << " " << m[5] << " " << m[6] << " " << m[7] ; - os << "\n" << m[8] << " " << m[9] << " " << m[10]<< " " << m[11] << "\n"; - return os; -} - -} // end namespace Math -} // end namespace ROOT diff --git a/math/genvector/src/Translation3D.cxx b/math/genvector/src/Translation3D.cxx index 2a17f3855cefb..af48d665e34d1 100644 --- a/math/genvector/src/Translation3D.cxx +++ b/math/genvector/src/Translation3D.cxx @@ -20,43 +20,3 @@ #include #include - - - - -namespace ROOT { - -namespace Math { - - -typedef Translation3D::Vector XYZVector; -typedef PositionVector3D > XYZPoint; - - -// ========== Constructors and Assignment ===================== - - -Plane3D Translation3D::operator() (const Plane3D & plane) const -{ - // transformations on a 3D plane - XYZVector n = plane.Normal(); - // take a point on the plane. Use origin projection on the plane - // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1 - double d = plane.HesseDistance(); - XYZPoint p( - d * n.X() , - d *n.Y(), -d *n.Z() ); - return Plane3D ( operator() (n), operator() (p) ); -} - -std::ostream & operator<< (std::ostream & os, const Translation3D & t) -{ - // TODO - this will need changing for machine-readable issues - // and even the human readable form needs formatiing improvements - - double m[3]; - t.GetComponents(m, m+3); - os << "\n" << m[0] << " " << m[1] << " " << m[2] << "\n"; - return os; -} - -} // end namespace Math -} // end namespace ROOT From 7e9c2b79b183faae0292b676dbef07a385a4c53a Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 16:02:23 +0000 Subject: [PATCH 02/44] Use the 'using namespace std' trick with Cartesian3D and Plane3D to fix support for Vc types --- .../inc/Math/GenVector/Cartesian3D.h | 31 ++++++++++--------- math/genvector/inc/Math/GenVector/Plane3D.h | 3 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Cartesian3D.h b/math/genvector/inc/Math/GenVector/Cartesian3D.h index dfd87ba911af7..803003a19f443 100644 --- a/math/genvector/inc/Math/GenVector/Cartesian3D.h +++ b/math/genvector/inc/Math/GenVector/Cartesian3D.h @@ -84,7 +84,6 @@ public : return *this; } - /** Set internal data based on an array of 3 Scalar numbers */ @@ -111,11 +110,13 @@ public : Scalar Z() const { return fZ;} Scalar Mag2() const { return fX*fX + fY*fY + fZ*fZ;} Scalar Perp2() const { return fX*fX + fY*fY ;} - Scalar Rho() const { return std::sqrt( Perp2());} - Scalar R() const { return std::sqrt( Mag2());} - Scalar Theta() const { return (fX==0 && fY==0 && fZ==0) ? - 0 : atan2(Rho(),Z());} - Scalar Phi() const { return (fX==0 && fY==0) ? 0 : atan2(fY,fX);} + Scalar Rho() const { using namespace std; return sqrt( Perp2() ); } + Scalar R() const { using namespace std; return sqrt( Mag2() ); } + Scalar Theta() const { using namespace std; + return (fX==Scalar(0) && fY==Scalar(0) && fZ==Scalar(0)) ? + Scalar(0) : atan2(Rho(),Z());} + Scalar Phi() const { using namespace std; + return (fX==Scalar(0) && fY==Scalar(0)) ? Scalar(0) : atan2(fY,fX);} // pseudorapidity Scalar Eta() const { @@ -149,7 +150,7 @@ public : /** scale the vector by a scalar quantity a */ - void Scale(Scalar a) { fX *= a; fY *= a; fZ *= a; } + void Scale(Scalar a) { fX *= a; fY *= a; fZ *= a; } /** negate the vector @@ -190,10 +191,11 @@ public : template explicit Cartesian3D( const Polar3D & v ) : fZ (v.Z()) { - T rho = v.Rho(); // re-using this instead of calling v.X() and v.Y() - // is the speed improvement - fX = rho * std::cos(v.Phi()); - fY = rho * std::sin(v.Phi()); + using namespace std; + const T rho = v.Rho(); // re-using this instead of calling v.X() and v.Y() + // is the speed improvement + fX = rho * cos(v.Phi()); + fY = rho * sin(v.Phi()); } // Technical note: This works even though only Polar3Dfwd.h is // included (and in fact, including Polar3D.h would cause circularity @@ -203,9 +205,10 @@ public : template Cartesian3D & operator = (const Polar3D & v) { - T rho = v.Rho(); - fX = rho * std::cos(v.Phi()); - fY = rho * std::sin(v.Phi()); + using namespace std; + const T rho = v.Rho(); + fX = rho * cos(v.Phi()); + fY = rho * sin(v.Phi()); fZ = v.Z(); return *this; } diff --git a/math/genvector/inc/Math/GenVector/Plane3D.h b/math/genvector/inc/Math/GenVector/Plane3D.h index ffd1ff35737f2..fd32a249646bb 100644 --- a/math/genvector/inc/Math/GenVector/Plane3D.h +++ b/math/genvector/inc/Math/GenVector/Plane3D.h @@ -245,8 +245,9 @@ namespace Impl { */ void Normalize() { + using namespace std; // normalize the plane - const Scalar s = std::sqrt( fA*fA + fB*fB + fC*fC ); + const Scalar s = sqrt( fA*fA + fB*fB + fC*fC ); // what to do if s = 0 ?? // CRJ - This does not work with Vc types... ToDo decide how to handle... //if ( s == 0 ) { fD = 0; return; } From b15d62aebad03d5c5d4e4219c919a9ca29ebff0d Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 16:52:45 +0000 Subject: [PATCH 03/44] Extend the 'using namespace std' trick to a few more classes --- .../inc/Math/GenVector/Cartesian2D.h | 24 +++++----- .../inc/Math/GenVector/Cartesian3D.h | 2 +- .../inc/Math/GenVector/Cylindrical3D.h | 19 +++++--- math/genvector/inc/Math/GenVector/Polar2D.h | 7 +-- .../inc/Math/GenVector/PtEtaPhiE4D.h | 44 +++++++++++-------- math/genvector/inc/Math/GenVector/PxPyPzE4D.h | 23 ++++++---- math/genvector/inc/Math/GenVector/eta.h | 7 +-- 7 files changed, 74 insertions(+), 52 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Cartesian2D.h b/math/genvector/inc/Math/GenVector/Cartesian2D.h index ccccb9e54db53..3a804ae985a4e 100644 --- a/math/genvector/inc/Math/GenVector/Cartesian2D.h +++ b/math/genvector/inc/Math/GenVector/Cartesian2D.h @@ -89,8 +89,9 @@ public : Scalar X() const { return fX;} Scalar Y() const { return fY;} Scalar Mag2() const { return fX*fX + fY*fY; } - Scalar R() const { return std::sqrt( Mag2());} - Scalar Phi() const { return (fX==0 && fY==0) ? 0.0 : atan2(fY,fX);} + Scalar R() const { using namespace std; return sqrt( Mag2()); } + Scalar Phi() const { using namespace std; + return (fX==Scalar(0) && fY==Scalar(0)) ? Scalar(0) : atan2(fY,fX);} /** set the x coordinate value keeping y constant @@ -124,8 +125,9 @@ public : rotate by an angle */ void Rotate(Scalar angle) { - Scalar s = std::sin(angle); - Scalar c = std::cos(angle); + using namespace std; + const Scalar s = sin(angle); + const Scalar c = cos(angle); SetCoordinates( c*fX - s*fY, s*fX + c * fY ); } @@ -161,10 +163,11 @@ public : template explicit Cartesian2D( const Polar2D & v ) { - Scalar r = v.R(); // re-using this instead of calling v.X() and v.Y() + using namespace std; + const Scalar r = v.R(); // re-using this instead of calling v.X() and v.Y() // is the speed improvement - fX = r * std::cos(v.Phi()); - fY = r * std::sin(v.Phi()); + fX = r * cos(v.Phi()); + fY = r * sin(v.Phi()); } // Technical note: This works even though only Polar2Dfwd.h is // included (and in fact, including Polar2D.h would cause circularity @@ -174,9 +177,10 @@ public : template Cartesian2D & operator = (const Polar2D & v) { - Scalar r = v.R(); - fX = r * std::cos(v.Phi()); - fY = r * std::sin(v.Phi()); + using namespace std; + const Scalar r = v.R(); + fX = r * cos(v.Phi()); + fY = r * sin(v.Phi()); return *this; } diff --git a/math/genvector/inc/Math/GenVector/Cartesian3D.h b/math/genvector/inc/Math/GenVector/Cartesian3D.h index 803003a19f443..71b439151e318 100644 --- a/math/genvector/inc/Math/GenVector/Cartesian3D.h +++ b/math/genvector/inc/Math/GenVector/Cartesian3D.h @@ -120,7 +120,7 @@ public : // pseudorapidity Scalar Eta() const { - return Impl::Eta_FromRhoZ ( Rho(),fZ); + return Impl::Eta_FromRhoZ( Rho(), fZ ); } /** diff --git a/math/genvector/inc/Math/GenVector/Cylindrical3D.h b/math/genvector/inc/Math/GenVector/Cylindrical3D.h index 1630c02782d4b..43eb78572fbfe 100644 --- a/math/genvector/inc/Math/GenVector/Cylindrical3D.h +++ b/math/genvector/inc/Math/GenVector/Cylindrical3D.h @@ -106,10 +106,12 @@ public : {rho=fRho; zz=fZ; phi=fPhi;} private: - inline static Scalar pi() { return M_PI; } - inline void Restrict() { + inline static Scalar pi() { return Scalar(M_PI); } + inline void Restrict() + { + using namespace std; if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); return; } public: @@ -120,13 +122,16 @@ public : Scalar Z() const { return fZ; } Scalar Phi() const { return fPhi; } - Scalar X() const { return fRho*std::cos(fPhi); } - Scalar Y() const { return fRho*std::sin(fPhi); } + Scalar X() const { using namespace std; return fRho*cos(fPhi); } + Scalar Y() const { using namespace std; return fRho*sin(fPhi); } Scalar Mag2() const { return fRho*fRho + fZ*fZ; } - Scalar R() const { return std::sqrt( Mag2()); } + Scalar R() const { using namespace std; return sqrt( Mag2()); } Scalar Perp2() const { return fRho*fRho; } - Scalar Theta() const { return (fRho==0 && fZ==0 ) ? 0 : atan2(fRho,fZ); } + Scalar Theta() const { + using namespace std; + return (fRho==Scalar(0) && fZ==Scalar(0) ) ? Scalar(0) : atan2(fRho,fZ); + } // pseudorapidity - use same implementation as in Cartesian3D Scalar Eta() const { diff --git a/math/genvector/inc/Math/GenVector/Polar2D.h b/math/genvector/inc/Math/GenVector/Polar2D.h index 895778d3a55ab..f27ef7e3959b3 100644 --- a/math/genvector/inc/Math/GenVector/Polar2D.h +++ b/math/genvector/inc/Math/GenVector/Polar2D.h @@ -97,8 +97,8 @@ public : Scalar R() const { return fR;} Scalar Phi() const { return fPhi; } - Scalar X() const { return fR*std::cos(fPhi);} - Scalar Y() const { return fR*std::sin(fPhi);} + Scalar X() const { using namespace std; return fR*cos(fPhi);} + Scalar Y() const { using namespace std; return fR*sin(fPhi);} Scalar Mag2() const { return fR*fR;} @@ -134,8 +134,9 @@ public : restrict abgle hi to be between -PI and PI */ inline void Restrict() { + using namespace std; if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); return; } diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h index 539e6ecca22fe..8223e66c4947d 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h @@ -137,15 +137,16 @@ public : // other coordinate representation - Scalar Px() const { return fPt*cos(fPhi);} + Scalar Px() const { using namespace std; return cos(fPhi);} Scalar X () const { return Px(); } - Scalar Py() const { return fPt*sin(fPhi);} + Scalar Py() const { using namespace std; return sin(fPhi);} Scalar Y () const { return Py(); } Scalar Pz() const { - return fPt > 0 ? fPt*std::sinh(fEta) : - fEta == 0 ? 0 : - fEta > 0 ? fEta - etaMax() : - fEta + etaMax() ; + using namespace std; + return ( fPt > 0 ? fPt*sinh(fEta) : + fEta == 0 ? 0 : + fEta > 0 ? fEta - etaMax() : + fEta + etaMax() ); } Scalar Z () const { return Pz(); } @@ -153,10 +154,11 @@ public : magnitude of momentum */ Scalar P() const { - return fPt > 0 ? fPt*std::cosh(fEta) : - fEta > etaMax() ? fEta - etaMax() : - fEta < -etaMax() ? -fEta - etaMax() : - 0 ; + using namespace std; + return ( fPt > 0 ? fPt*cosh(fEta) : + fEta > etaMax() ? fEta - etaMax() : + fEta < -etaMax() ? -fEta - etaMax() : + 0 ); } Scalar R() const { return P(); } @@ -175,13 +177,14 @@ public : invariant mass */ Scalar M() const { + using namespace std; Scalar mm = M2(); if (mm >= 0) { - return std::sqrt(mm); + return sqrt(mm); } else { GenVector::Throw ("PtEtaPhiE4D::M() - Tachyonic:\n" " Pt and Eta give P such that P^2 > E^2, so the mass would be imaginary"); - return -std::sqrt(-mm); + return -sqrt(-mm); } } Scalar Mag() const { return M(); } @@ -201,13 +204,14 @@ public : transverse mass */ Scalar Mt() const { + using namespace std; Scalar mm = Mt2(); if (mm >= 0) { - return std::sqrt(mm); + return sqrt(mm); } else { GenVector::Throw ("PtEtaPhiE4D::Mt() - Tachyonic:\n" " Pt and Eta give Pz such that Pz^2 > E^2, so the mass would be imaginary"); - return -std::sqrt(-mm); + return -sqrt(-mm); } } @@ -218,7 +222,8 @@ public : transverse energy */ Scalar Et() const { - return fE / std::cosh(fEta); // faster using eta + using namespace std; + return fE / cosh(fEta); // faster using eta } /** @@ -230,8 +235,9 @@ public : private: inline static Scalar pi() { return M_PI; } inline void Restrict() { + using namespace std; if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); return; } public: @@ -240,9 +246,9 @@ public : polar angle */ Scalar Theta() const { - if (fPt > 0) return 2* std::atan( exp( - fEta ) ); - if (fEta >= 0) return 0; - return pi(); + using namespace std; + return ( fPt > 0 ? Scalar(2) * atan( exp( - fEta ) ) : + fEta >= 0 ? Scalar(0) : pi() ); } // --------- Set Coordinates of this system --------------- diff --git a/math/genvector/inc/Math/GenVector/PxPyPzE4D.h b/math/genvector/inc/Math/GenVector/PxPyPzE4D.h index ec2a48d983f3d..5ddad92db2c0a 100644 --- a/math/genvector/inc/Math/GenVector/PxPyPzE4D.h +++ b/math/genvector/inc/Math/GenVector/PxPyPzE4D.h @@ -148,13 +148,14 @@ public : invariant mass */ Scalar M() const { + using namespace std; Scalar mm = M2(); if (mm >= 0) { - return std::sqrt(mm); + return sqrt(mm); } else { GenVector::Throw ("PxPyPzE4D::M() - Tachyonic:\n" " P^2 > E^2 so the mass would be imaginary"); - return -std::sqrt(-mm); + return -sqrt(-mm); } } Scalar Mag() const { return M(); } @@ -168,7 +169,7 @@ public : /** Transverse spatial component (P_perp or rho) */ - Scalar Pt() const { return std::sqrt(Perp2());} + Scalar Pt() const { using namespace std; return std::sqrt(Perp2());} Scalar Perp() const { return Pt();} Scalar Rho() const { return Pt();} @@ -181,13 +182,14 @@ public : transverse mass */ Scalar Mt() const { + using namespace std; Scalar mm = Mt2(); - if (mm >= 0) { - return std::sqrt(mm); + if ( mm >= 0 ) { + return sqrt(mm); } else { GenVector::Throw ("PxPyPzE4D::Mt() - Tachyonic:\n" " Pz^2 > E^2 so the transverse mass would be imaginary"); - return -std::sqrt(-mm); + return -sqrt(-mm); } } @@ -204,22 +206,25 @@ public : transverse energy */ Scalar Et() const { + using namespace std; Scalar etet = Et2(); - return fT < 0.0 ? -std::sqrt(etet) : std::sqrt(etet); + return fT < 0.0 ? -sqrt(etet) : sqrt(etet); } /** azimuthal angle */ Scalar Phi() const { - return (fX == 0.0 && fY == 0.0) ? 0 : std::atan2(fY,fX); + using namespace std; + return ( fX == Scalar(0) && fY == Scalar(0) ) ? Scalar(0) : atan2(fY,fX); } /** polar angle */ Scalar Theta() const { - return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : std::atan2(Pt(),fZ); + using namespace std; + return (fX == Scalar(0) && fY == Scalar(0) && fZ == Scalar(0) ) ? Scalar(0) : atan2(Pt(),fZ); } /** diff --git a/math/genvector/inc/Math/GenVector/eta.h b/math/genvector/inc/Math/GenVector/eta.h index 434471771e734..7fa99fddc05ae 100644 --- a/math/genvector/inc/Math/GenVector/eta.h +++ b/math/genvector/inc/Math/GenVector/eta.h @@ -46,15 +46,16 @@ namespace ROOT { */ template inline Scalar Eta_FromRhoZ(Scalar rho, Scalar z) { + using namespace std; if (rho > 0) { // value to control Taylor expansion of sqrt static const Scalar big_z_scaled = - std::pow(std::numeric_limits::epsilon(),static_cast(-.25)); + pow(std::numeric_limits::epsilon(),static_cast(-.25)); Scalar z_scaled = z/rho; - if (std::fabs(z_scaled) < big_z_scaled) { - return std::log(z_scaled+std::sqrt(z_scaled*z_scaled+1.0)); + if (fabs(z_scaled) < big_z_scaled) { + return log(z_scaled+std::sqrt(z_scaled*z_scaled+1.0)); } else { // apply correction using first order Taylor expansion of sqrt return z>0 ? std::log(2.0*z_scaled + 0.5/z_scaled) : -std::log(-2.0*z_scaled); From 2b2fc17e1cc07f91f165d88628c9cd5b042d3bd5 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 17:30:40 +0000 Subject: [PATCH 04/44] Change class to typename --- math/genvector/inc/Math/GenVector/Plane3D.h | 2 +- math/genvector/inc/Math/GenVector/Transform3D.h | 2 +- math/genvector/inc/Math/GenVector/Translation3D.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Plane3D.h b/math/genvector/inc/Math/GenVector/Plane3D.h index fd32a249646bb..c7e2516ba80bb 100644 --- a/math/genvector/inc/Math/GenVector/Plane3D.h +++ b/math/genvector/inc/Math/GenVector/Plane3D.h @@ -45,7 +45,7 @@ namespace Impl { @ingroup GenVector */ - template + template class Plane3D { public: diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index 6ea7707ff1400..baab6c79ea0bd 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -73,7 +73,7 @@ namespace Impl { */ -template +template class Transform3D { diff --git a/math/genvector/inc/Math/GenVector/Translation3D.h b/math/genvector/inc/Math/GenVector/Translation3D.h index daa50c613d71d..21d202fde202a 100644 --- a/math/genvector/inc/Math/GenVector/Translation3D.h +++ b/math/genvector/inc/Math/GenVector/Translation3D.h @@ -48,7 +48,7 @@ namespace Impl { */ -template +template class Translation3D { From 2e74f0d5d25086a288d08d6a91b22a3ea8c54e7a Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 17:47:57 +0000 Subject: [PATCH 05/44] Explicitly cast some constants to the scalar type (needed for Vc types) --- .../inc/Math/GenVector/Transform3D.h | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index baab6c79ea0bd..79660fef4e0fa 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -652,11 +652,11 @@ class Transform3D { const T detxy = fM[kYX]*fM[kZZ] - fM[kYZ]*fM[kZX]; const T detxz = fM[kYX]*fM[kZY] - fM[kYY]*fM[kZX]; const T det = fM[kXX]*detxx - fM[kXY]*detxy + fM[kXZ]*detxz; - if (det == 0) { + if ( det == T(0) ) { std::cerr << "Transform3D::inverse error: zero determinant" << std::endl; return; } - det = 1./det; detxx *= det; detxy *= det; detxz *= det; + det = T(1)/det; detxx *= det; detxy *= det; detxz *= det; const T detyx = (fM[kXY]*fM[kZZ] - fM[kXZ]*fM[kZY] )*det; const T detyy = (fM[kXX]*fM[kZZ] - fM[kXZ]*fM[kZX] )*det; const T detyz = (fM[kXX]*fM[kZY] - fM[kXY]*fM[kZX] )*det; @@ -664,9 +664,9 @@ class Transform3D { const T detzy = (fM[kXX]*fM[kYZ] - fM[kXZ]*fM[kYX] )*det; const T detzz = (fM[kXX]*fM[kYY] - fM[kXY]*fM[kYX] )*det; SetComponents - (detxx, -detyx, detzx, -detxx*fM[kDX]+detyx*fM[kDY]-detzx*fM[kDZ], + ( detxx, -detyx, detzx, -detxx*fM[kDX]+detyx*fM[kDY]-detzx*fM[kDZ], -detxy, detyy, -detzy, detxy*fM[kDX]-detyy*fM[kDY]+detzy*fM[kDZ], - detxz, -detyz, detzz, -detxz*fM[kDX]+detyz*fM[kDY]-detzz*fM[kDZ]); + detxz, -detyz, detzz, -detxz*fM[kDX]+detyz*fM[kDY]-detzz*fM[kDZ]); } @@ -750,19 +750,19 @@ class Transform3D { for (int j = 0; j < 3; ++j) fM[4*i + j] = rotData[3*i+j]; // empty vector data - fM[4*i + 3] = 0; + fM[4*i + 3] = T(0); } } /** make transformation from only translation (identity rotations) */ - void AssignFrom( const Vector & v ) + void AssignFrom( const Vector & v ) { // assign from a translation only (identity rotations) - fM[kXX] = 1.0; fM[kXY] = 0.0; fM[kXZ] = 0.0; fM[kDX] = v.X(); - fM[kYX] = 0.0; fM[kYY] = 1.0; fM[kYZ] = 0.0; fM[kDY] = v.Y(); - fM[kZX] = 0.0; fM[kZY] = 0.0; fM[kZZ] = 1.0; fM[kDZ] = v.Z(); + fM[kXX] = T(1); fM[kXY] = T(0); fM[kXZ] = T(0); fM[kDX] = v.X(); + fM[kYX] = T(0); fM[kYY] = T(1); fM[kYZ] = T(0); fM[kDY] = v.Y(); + fM[kZX] = T(0); fM[kZY] = T(0); fM[kZZ] = T(1); fM[kDZ] = v.Z(); } /** @@ -771,9 +771,9 @@ class Transform3D { void SetIdentity() { //set identity ( identity rotation and zero translation) - fM[kXX] = 1.0; fM[kXY] = 0.0; fM[kXZ] = 0.0; fM[kDX] = 0.0; - fM[kYX] = 0.0; fM[kYY] = 1.0; fM[kYZ] = 0.0; fM[kDY] = 0.0; - fM[kZX] = 0.0; fM[kZY] = 0.0; fM[kZZ] = 1.0; fM[kDZ] = 0.0; + fM[kXX] = T(1); fM[kXY] = T(0); fM[kXZ] = T(0); fM[kDX] = T(0); + fM[kYX] = T(0); fM[kYY] = T(1); fM[kYZ] = T(0); fM[kDY] = T(0); + fM[kZX] = T(0); fM[kZY] = T(0); fM[kZZ] = T(1); fM[kDZ] = T(0); } private: From c3175c6d8219710270f7f9f15ef1c367439160f5 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 19:58:30 +0000 Subject: [PATCH 06/44] Remove empty implementation files --- math/genvector/src/Plane3D.cxx | 21 --------------------- math/genvector/src/Transform3D.cxx | 23 ----------------------- math/genvector/src/Translation3D.cxx | 22 ---------------------- 3 files changed, 66 deletions(-) delete mode 100644 math/genvector/src/Plane3D.cxx delete mode 100644 math/genvector/src/Transform3D.cxx delete mode 100644 math/genvector/src/Translation3D.cxx diff --git a/math/genvector/src/Plane3D.cxx b/math/genvector/src/Plane3D.cxx deleted file mode 100644 index d01f62da0f8d1..0000000000000 --- a/math/genvector/src/Plane3D.cxx +++ /dev/null @@ -1,21 +0,0 @@ -// @(#)root/mathcore:$Id$ -// Authors: W. Brown, M. Fischler, L. Moneta 2005 - -/********************************************************************** - * * - * Copyright (c) 2005 , LCG ROOT MathLib Team * - * * - * * - **********************************************************************/ - -// implementation file for class Plane3D -// -// Created by: Lorenzo Moneta December 2 2005 -// -// - -#include "Math/GenVector/Plane3D.h" - -#include - - diff --git a/math/genvector/src/Transform3D.cxx b/math/genvector/src/Transform3D.cxx deleted file mode 100644 index 266be6177a4c7..0000000000000 --- a/math/genvector/src/Transform3D.cxx +++ /dev/null @@ -1,23 +0,0 @@ -// @(#)root/mathcore:$Id$ -// Authors: W. Brown, M. Fischler, L. Moneta 2005 - -/********************************************************************** - * * - * Copyright (c) 2005 , LCG ROOT MathLib Team * - * * - * * - **********************************************************************/ - -// implementation file for class Transform3D -// -// Created by: Lorenzo Moneta October 27 2005 -// -// -#include "Math/GenVector/GenVectorIO.h" - -#include "Math/GenVector/Transform3D.h" -#include "Math/GenVector/Plane3D.h" - -#include -#include - diff --git a/math/genvector/src/Translation3D.cxx b/math/genvector/src/Translation3D.cxx deleted file mode 100644 index af48d665e34d1..0000000000000 --- a/math/genvector/src/Translation3D.cxx +++ /dev/null @@ -1,22 +0,0 @@ -// @(#)root/mathcore:$Id$ -// Authors: W. Brown, M. Fischler, L. Moneta 2005 - -/********************************************************************** - * * - * Copyright (c) 2005 , LCG ROOT MathLib Team * - * * - * * - **********************************************************************/ - -// implementation file for class Translation3D -// -// Created by: Lorenzo Moneta October 27 2005 -// -// - -#include "Math/GenVector/Translation3D.h" -#include "Math/GenVector/Plane3D.h" -#include "Math/GenVector/PositionVector3D.h" - -#include -#include From 9bdfb8ea841c39098d0b98232d3366dd9d75ff6c Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 22:07:42 +0000 Subject: [PATCH 07/44] Template the Boost classes --- math/genvector/inc/Math/GenVector/Boost.h | 228 ++++++++++++++---- math/genvector/inc/Math/GenVector/BoostX.h | 136 ++++++++--- math/genvector/inc/Math/GenVector/BoostXfwd.h | 2 +- math/genvector/inc/Math/GenVector/BoostY.h | 130 +++++++--- math/genvector/inc/Math/GenVector/BoostZ.h | 126 +++++++--- math/genvector/inc/Math/GenVector/Boostfwd.h | 4 +- math/genvector/src/Boost.cxx | 162 ------------- math/genvector/src/BoostX.cxx | 90 ------- math/genvector/src/BoostY.cxx | 89 ------- math/genvector/src/BoostZ.cxx | 90 ------- 10 files changed, 466 insertions(+), 591 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Boost.h b/math/genvector/inc/Math/GenVector/Boost.h index 87efc3d52db79..b92780714dbc8 100644 --- a/math/genvector/inc/Math/GenVector/Boost.h +++ b/math/genvector/inc/Math/GenVector/Boost.h @@ -26,9 +26,46 @@ #include "Math/GenVector/BoostY.h" #include "Math/GenVector/BoostZ.h" -namespace ROOT { +//#ifdef TEX +/** + + A variable names bgamma appears in several places in this file. A few + words of elaboration are needed to make its meaning clear. On page 69 + of Misner, Thorne and Wheeler, (Exercise 2.7) the elements of the matrix + for a general Lorentz boost are given as + + \f[ \Lambda^{j'}_k = \Lambda^{k'}_j + = (\gamma - 1) n^j n^k + \delta^{jk} \f] + + where the n^i are unit vectors in the direction of the three spatial + axes. Using the definitions, \f$ n^i = \beta_i/\beta \f$ , then, for example, + + \f[ \Lambda_{xy} = (\gamma - 1) n_x n_y + = (\gamma - 1) \beta_x \beta_y/\beta^2 \f] + + By definition, \f[ \gamma^2 = 1/(1 - \beta^2) \f] + + so that \f[ \gamma^2 \beta^2 = \gamma^2 - 1 \f] + + or \f[ \beta^2 = (\gamma^2 - 1)/\gamma^2 \f] + + If we insert this into the expression for \f$ \Lambda_{xy} \f$, we get - namespace Math { + \f[ \Lambda_{xy} = (\gamma - 1) \gamma^2/(\gamma^2 - 1) \beta_x \beta_y \f] + + or, finally + + \f[ \Lambda_{xy} = \gamma^2/(\gamma+1) \beta_x \beta_y \f] + + The expression \f$ \gamma^2/(\gamma+1) \f$ is what we call bgamma in the code below. + + \class ROOT::Math::Boost +*/ +//#endif + +namespace ROOT { +namespace Math { +namespace Impl { //__________________________________________________________________________________________ /** @@ -40,14 +77,14 @@ namespace ROOT { transformations which do not mix space and time components. @ingroup GenVector - */ +template < typename T > class Boost { public: - typedef double Scalar; + typedef T Scalar; enum ELorentzRotationMatrixIndex { kLXX = 0, kLXY = 1, kLXZ = 2, kLXT = 3 @@ -61,6 +98,7 @@ class Boost { , kYY = 4, kYZ = 5, kYT = 6 , kZZ = 7, kZT = 8 , kTT = 9 + , kNElems = 10 }; // ========== Constructors and Assignment ===================== @@ -74,7 +112,7 @@ class Boost { Construct given a three Scalars beta_x, beta_y, and beta_z */ Boost(Scalar beta_x, Scalar beta_y, Scalar beta_z) - { SetComponents(beta_x, beta_y, beta_z); } + { SetComponents(beta_x, beta_y, beta_z); } /** Construct given a beta vector (which must have methods x(), y(), z()) @@ -93,7 +131,7 @@ class Boost { /** copy constructor */ - Boost(Boost const & b) { + Boost( Boost const & b) { *this = b; } @@ -101,9 +139,9 @@ class Boost { Construct from an axial boost */ - explicit Boost( BoostX const & bx ) {SetComponents(bx.BetaVector());} - explicit Boost( BoostY const & by ) {SetComponents(by.BetaVector());} - explicit Boost( BoostZ const & bz ) {SetComponents(bz.BetaVector());} + explicit Boost( BoostX const & bx ) {SetComponents(bx.BetaVector());} + explicit Boost( BoostY const & by ) {SetComponents(by.BetaVector());} + explicit Boost( BoostZ const & bz ) {SetComponents(bz.BetaVector());} // The compiler-generated copy ctor, copy assignment, and dtor are OK. @@ -111,8 +149,8 @@ class Boost { Assignment operator */ Boost & - operator=(Boost const & rhs ) { - for (unsigned int i=0; i < 10; ++i) { + operator=(Boost const & rhs ) { + for (unsigned int i=0; i < kNElems; ++i) { fM[i] = rhs.fM[i]; } return *this; @@ -122,17 +160,34 @@ class Boost { Assign from an axial pure boost */ Boost & - operator=( BoostX const & bx ) { return operator=(Boost(bx)); } + operator=( BoostX const & bx ) { return operator=(Boost(bx)); } Boost & - operator=( BoostY const & by ) { return operator=(Boost(by)); } + operator=( BoostY const & by ) { return operator=(Boost(by)); } Boost & - operator=( BoostZ const & bz ) { return operator=(Boost(bz)); } + operator=( BoostZ const & bz ) { return operator=(Boost(bz)); } /** Re-adjust components to eliminate small deviations from a perfect orthosyplectic matrix. */ - void Rectify(); + void Rectify() { + // Assuming the representation of this is close to a true Lorentz Rotation, + // but may have drifted due to round-off error from many operations, + // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation + // again. + + if (fM[kTT] <= 0) { + GenVector::Throw ( + "Attempt to rectify a boost with non-positive gamma"); + return; + } + DisplacementVector3D< Cartesian3D > beta ( fM[kXT], fM[kYT], fM[kZT] ); + beta /= fM[kTT]; + if ( beta.mag2() >= 1 ) { + beta /= ( beta.R() * ( 1.0 + 1.0e-16 ) ); + } + SetComponents ( beta ); + } // ======== Components ============== @@ -140,13 +195,43 @@ class Boost { Set components from beta_x, beta_y, and beta_z */ void - SetComponents (Scalar beta_x, Scalar beta_y, Scalar beta_z); + SetComponents (Scalar bx, Scalar by, Scalar bz) { + using namespace std; + // set the boost beta as 3 components + Scalar bp2 = bx*bx + by*by + bz*bz; + if ( bp2 >= Scalar(1) ) { + GenVector::Throw ( + "Beta Vector supplied to set Boost represents speed >= c"); + // SetIdentity(); + } + else + { + const Scalar gamma = Scalar(1) / sqrt( Scalar(1) - bp2 ); + const Scalar bgamma = gamma * gamma / ( Scalar(1) + gamma ); + fM[kXX] = Scalar(1) + bgamma * bx * bx; + fM[kYY] = Scalar(1) + bgamma * by * by; + fM[kZZ] = Scalar(1) + bgamma * bz * bz; + fM[kXY] = bgamma * bx * by; + fM[kXZ] = bgamma * bx * bz; + fM[kYZ] = bgamma * by * bz; + fM[kXT] = gamma * bx; + fM[kYT] = gamma * by; + fM[kZT] = gamma * bz; + fM[kTT] = gamma; + } + } /** Get components into beta_x, beta_y, and beta_z */ void - GetComponents (Scalar& beta_x, Scalar& beta_y, Scalar& beta_z) const; + GetComponents (Scalar& bx, Scalar& by, Scalar& bz) const { + // get beta of the boots as 3 components + Scalar gaminv = Scalar(1)/fM[kTT]; + bx = fM[kXT]*gaminv; + by = fM[kYT]*gaminv; + bz = fM[kZT]*gaminv; + } /** Set components from a beta vector @@ -192,7 +277,7 @@ class Boost { */ template void GetComponents(IT begin ) const { - double bx,by,bz = 0; + T bx,by,bz = 0; GetComponents (bx,by,bz); *begin++ = bx; *begin++ = by; @@ -202,8 +287,13 @@ class Boost { /** The beta vector for this boost */ - typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; - XYZVector BetaVector() const; + typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; + XYZVector BetaVector() const { + // get boost beta vector + const Scalar gaminv = Scalar(1)/fM[kTT]; + return DisplacementVector3D< Cartesian3D > + ( fM[kXT]*gaminv, fM[kYT]*gaminv, fM[kZT]*gaminv ); + } /** Get elements of internal 4x4 symmetric representation, into a data @@ -212,7 +302,13 @@ class Boost { that large, then this will lead to undefined behavior. */ void - GetLorentzRotation (Scalar r[]) const; + GetLorentzRotation (Scalar r[]) const { + // get Lorentz rotation corresponding to this boost as an array of 16 values + r[kLXX] = fM[kXX]; r[kLXY] = fM[kXY]; r[kLXZ] = fM[kXZ]; r[kLXT] = fM[kXT]; + r[kLYX] = fM[kXY]; r[kLYY] = fM[kYY]; r[kLYZ] = fM[kYZ]; r[kLYT] = fM[kYT]; + r[kLZX] = fM[kXZ]; r[kLZY] = fM[kYZ]; r[kLZZ] = fM[kZZ]; r[kLZT] = fM[kZT]; + r[kLTX] = fM[kXT]; r[kLTY] = fM[kYT]; r[kLTZ] = fM[kZT]; r[kLTT] = fM[kTT]; + } // =========== operations ============== @@ -220,8 +316,19 @@ class Boost { Lorentz transformation operation on a Minkowski ('Cartesian') LorentzVector */ - LorentzVector< ROOT::Math::PxPyPzE4D > - operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const; + LorentzVector< ROOT::Math::PxPyPzE4D > + operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const { + // apply boost to a PxPyPzE LorentzVector + const Scalar x = v.Px(); + const Scalar y = v.Py(); + const Scalar z = v.Pz(); + const Scalar t = v.E(); + return LorentzVector< PxPyPzE4D > + ( fM[kXX]*x + fM[kXY]*y + fM[kXZ]*z + fM[kXT]*t + , fM[kXY]*x + fM[kYY]*y + fM[kYZ]*z + fM[kYT]*t + , fM[kXZ]*x + fM[kYZ]*y + fM[kZZ]*z + fM[kZT]*t + , fM[kXT]*x + fM[kYT]*y + fM[kZT]*z + fM[kTT]*t ); + } /** Lorentz transformation operation on a LorentzVector in any @@ -230,8 +337,8 @@ class Boost { template LorentzVector operator() (const LorentzVector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + const LorentzVector< PxPyPzE4D > xyzt(v); + const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return LorentzVector ( r_xyzt ); } @@ -243,8 +350,8 @@ class Boost { template Foreign4Vector operator() (const Foreign4Vector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + const LorentzVector< PxPyPzE4D > xyzt(v); + const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() ); } @@ -261,33 +368,51 @@ class Boost { /** Invert a Boost in place */ - void Invert(); - + void Invert() { + // invert in place boost (modifying the object) + fM[kXT] = -fM[kXT]; + fM[kYT] = -fM[kYT]; + fM[kZT] = -fM[kZT]; + } + /** Return inverse of a boost */ - Boost Inverse() const; + Boost Inverse() const { + // return inverse of boost + Boost tmp(*this); + tmp.Invert(); + return tmp; + } /** Equality/inequality operators */ - bool operator == (const Boost & rhs) const { - for (unsigned int i=0; i < 10; ++i) { - if( fM[i] != rhs.fM[i] ) return false; + bool operator == (const Boost & rhs) const { + bool OK = true; + for (unsigned int i=0; i < kNElems; ++i) { + if ( fM[i] != rhs.fM[i] ) { OK = false; break; } } - return true; + return OK; } + bool operator != (const Boost & rhs) const { return ! operator==(rhs); } protected: - void SetIdentity(); + void SetIdentity() { + // set identity boost + fM[kXX] = Scalar(1); fM[kXY] = Scalar(0); fM[kXZ] = Scalar(0); fM[kXT] = Scalar(0); + fM[kYY] = Scalar(1); fM[kYZ] = Scalar(0); fM[kYT] = Scalar(0); + fM[kZZ] = Scalar(1); fM[kZT] = Scalar(0); + fM[kTT] = Scalar(1); + } private: - Scalar fM[10]; + Scalar fM[kNElems]; }; // Boost @@ -298,16 +423,25 @@ class Boost { */ // TODO - I/O should be put in the manipulator form -std::ostream & operator<< (std::ostream & os, const Boost & b); - - -} //namespace Math -} //namespace ROOT - - - - - - +template< typename T > +std::ostream & operator<< (std::ostream & os, const Boost & b ) { + // TODO - this will need changing for machine-readable issues + // and even the human readable form needs formatiing improvements + T m[16]; + b.GetLorentzRotation(m); + os << "\n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3]; + os << "\n" << "\t" << " " << m[5] << " " << m[6] << " " << m[7]; + os << "\n" << "\t" << " " << "\t" << " " << m[10] << " " << m[11]; + os << "\n" << "\t" << " " << "\t" << " " << "\t" << " " << m[15] << "\n"; + return os; +} + +} // namespace Impl + +typedef Impl::Boost Boost; +typedef Impl::Boost BoostF; + +} // namespace Math +} // namespace ROOT #endif /* ROOT_Math_GenVector_Boost */ diff --git a/math/genvector/inc/Math/GenVector/BoostX.h b/math/genvector/inc/Math/GenVector/BoostX.h index cfed6a775acd3..5444cb1e3bbea 100644 --- a/math/genvector/inc/Math/GenVector/BoostX.h +++ b/math/genvector/inc/Math/GenVector/BoostX.h @@ -23,8 +23,8 @@ #include "Math/GenVector/Cartesian3D.h" namespace ROOT { - namespace Math { +namespace Impl { //__________________________________________________________________________________________ /** @@ -34,11 +34,12 @@ namespace Math { @ingroup GenVector */ +template< typename T = double> class BoostX { public: - typedef double Scalar; + typedef T Scalar; enum ELorentzRotationMatrixIndex { kLXX = 0, kLXY = 1, kLXZ = 2, kLXT = 3 @@ -48,10 +49,11 @@ class BoostX { }; enum EBoostMatrixIndex { - kXX = 0, kXY = 1, kXZ = 2, kXT = 3 + kXX = 0, kXY = 1, kXZ = 2, kXT = 3 , kYY = 4, kYZ = 5, kYT = 6 , kZZ = 7, kZT = 8 , kTT = 9 + , kNElems = 10 }; // ========== Constructors and Assignment ===================== @@ -59,7 +61,7 @@ class BoostX { /** Default constructor (identity transformation) */ - BoostX(); + BoostX() : fBeta(0), fGamma(1) {} /** Construct given a Scalar beta_x @@ -73,7 +75,26 @@ class BoostX { Re-adjust components to eliminate small deviations from a perfect orthosyplectic matrix. */ - void Rectify(); + void Rectify() { + // Assuming the representation of this is close to a true Lorentz Rotation, + // but may have drifted due to round-off error from many operations, + // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation + // again. + + if ( fGamma <= Scalar(0) ) { + GenVector::Throw ( + "Attempt to rectify a boost with non-positive gamma"); + } + else + { + Scalar beta = fBeta; + if ( beta >= Scalar(1) ) { + // WTF wrt 1e-16 ... + beta /= ( beta * ( Scalar(1) + Scalar(1.0e-16) ) ); + } + SetComponents ( beta ); + } + } // ======== Components ============== @@ -81,15 +102,29 @@ class BoostX { Set components from a Scalar beta_x */ void - SetComponents (Scalar beta_x); - + SetComponents (Scalar bx) { + using namespace std; + // set component + Scalar bp2 = bx*bx; + if (bp2 >= Scalar(1) ) { + GenVector::Throw ( + "Beta Vector supplied to set BoostX represents speed >= c"); + } + else + { + fBeta = bx; + fGamma = Scalar(1) / sqrt( Scalar(1) - bp2 ); + } + } + /** Get components into a Scalar beta_x */ - void - GetComponents (Scalar& beta_x) const; - - + void GetComponents (Scalar& bx) const { + // get component + bx = fBeta; + } + /** Retrieve the beta of the Boost */ @@ -108,8 +143,11 @@ class BoostX { /** The beta vector for this boost */ - typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; - XYZVector BetaVector() const; + typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; + XYZVector BetaVector() const { + // return beta vector + return DisplacementVector3D< Cartesian3D > ( fBeta, Scalar(0), Scalar(0) ); + } /** Get elements of internal 4x4 symmetric representation, into a data @@ -117,8 +155,13 @@ class BoostX { Note -- 16 Scalars will be written into the array; if the array is not that large, then this will lead to undefined behavior. */ - void - GetLorentzRotation (Scalar r[]) const; + void GetLorentzRotation (Scalar r[]) const { + // get corresponding LorentzRotation + r[kLXX] = fGamma; r[kLXY] = Scalar(0); r[kLXZ] = Scalar(0); r[kLXT] = fGamma*fBeta; + r[kLYX] = Scalar(0); r[kLYY] = Scalar(1); r[kLYZ] = Scalar(0); r[kLYT] = Scalar(0); + r[kLZX] = Scalar(0); r[kLZY] = Scalar(0); r[kLZZ] = Scalar(1); r[kLZT] = Scalar(0); + r[kLTX] = fGamma*fBeta; r[kLTY] = Scalar(0); r[kLTZ] = Scalar(0); r[kLTT] = fGamma; + } // =========== operations ============== @@ -126,8 +169,18 @@ class BoostX { Lorentz transformation operation on a Minkowski ('Cartesian') LorentzVector */ - LorentzVector< ROOT::Math::PxPyPzE4D > - operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const; + LorentzVector< ROOT::Math::PxPyPzE4D > + operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const { + // apply boost to a LV + const Scalar x = v.Px(); + const Scalar t = v.E(); + return LorentzVector< PxPyPzE4D > + ( fGamma*x + fGamma*fBeta*t + , v.Py() + , v.Pz() + , fGamma*fBeta*x + fGamma*t ); + } + /** Lorentz transformation operation on a LorentzVector in any @@ -136,8 +189,8 @@ class BoostX { template LorentzVector operator() (const LorentzVector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + const LorentzVector< PxPyPzE4D > xyzt(v); + const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return LorentzVector ( r_xyzt ); } @@ -149,8 +202,8 @@ class BoostX { template Foreign4Vector operator() (const Foreign4Vector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + const LorentzVector< PxPyPzE4D > xyzt(v); + const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() ); } @@ -158,29 +211,35 @@ class BoostX { Overload operator * for operation on a vector */ template - inline - A4Vector operator* (const A4Vector & v) const + inline A4Vector operator* (const A4Vector & v) const { - return operator()(v); + return operator()(v); } /** Invert a BoostX in place */ - void Invert(); - + void Invert() { + // invert + fBeta = -fBeta; + } + /** Return inverse of a boost */ - BoostX Inverse() const; + BoostX Inverse() const { + // return an inverse boostX + BoostX tmp(*this); + tmp.Invert(); + return tmp; + } /** Equality/inequality operators */ bool operator == (const BoostX & rhs) const { - if( fBeta != rhs.fBeta ) return false; - if( fGamma != rhs.fGamma ) return false; - return true; + return ( fBeta == rhs.fBeta && + fGamma == rhs.fGamma ); } bool operator != (const BoostX & rhs) const { @@ -201,17 +260,18 @@ class BoostX { Stream Output and Input */ // TODO - I/O should be put in the manipulator form +template< typename T> +std::ostream & operator<< (std::ostream & os, const BoostX & b) { + os << " BoostX( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; + return os; +} -std::ostream & operator<< (std::ostream & os, const BoostX & b); - +} //namepsace Impl +typedef Impl::BoostX BoostX; +typedef Impl::BoostX BoostXF; + } //namespace Math } //namespace ROOT - - - - - - #endif /* ROOT_Math_GenVector_BoostX */ diff --git a/math/genvector/inc/Math/GenVector/BoostXfwd.h b/math/genvector/inc/Math/GenVector/BoostXfwd.h index 34b92bc4af279..3800712629cb2 100644 --- a/math/genvector/inc/Math/GenVector/BoostXfwd.h +++ b/math/genvector/inc/Math/GenVector/BoostXfwd.h @@ -13,7 +13,7 @@ namespace ROOT { Class describing a pure Lorentz Boost along the X axis */ -class BoostX; + class BoostX; } // namespace Math } // namespace ROOT diff --git a/math/genvector/inc/Math/GenVector/BoostY.h b/math/genvector/inc/Math/GenVector/BoostY.h index 5aa6a9698fd8b..be3e31eb307e8 100644 --- a/math/genvector/inc/Math/GenVector/BoostY.h +++ b/math/genvector/inc/Math/GenVector/BoostY.h @@ -23,9 +23,9 @@ #include "Math/GenVector/Cartesian3D.h" namespace ROOT { - namespace Math { - +namespace Impl { + //__________________________________________________________________________________________ /** Class representing a Lorentz Boost along the Y axis, by beta. @@ -34,11 +34,12 @@ namespace Math { @ingroup GenVector */ +template< typename T = double> class BoostY { public: - typedef double Scalar; + typedef T Scalar; enum ELorentzRotationMatrixIndex { kLXX = 0, kLXY = 1, kLXZ = 2, kLXT = 3 @@ -52,6 +53,7 @@ class BoostY { , kYY = 4, kYZ = 5, kYT = 6 , kZZ = 7, kZT = 8 , kTT = 9 + , kNElems = 10 }; // ========== Constructors and Assignment ===================== @@ -59,37 +61,66 @@ class BoostY { /** Default constructor (identity transformation) */ - BoostY(); + BoostY() : fBeta(0), fGamma(1) {} /** Construct given a Scalar beta_y */ explicit BoostY(Scalar beta_y) { SetComponents(beta_y); } - // The compiler-generated copy ctor, copy assignment, and dtor are OK. /** Re-adjust components to eliminate small deviations from a perfect orthosyplectic matrix. */ - void Rectify(); + void Rectify() { + // Assuming the representation of this is close to a true Lorentz Rotation, + // but may have drifted due to round-off error from many operations, + // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation + // again. + + if ( fGamma <= Scalar(0) ) { + GenVector::Throw ( + "Attempt to rectify a boost with non-positive gamma"); + } + else + { + Scalar beta = fBeta; + if ( beta >= Scalar(1) ) { + beta /= ( beta * ( Scalar( 1.0 + 1.0e-16 ) ) ); + } + SetComponents ( beta ); + } + } // ======== Components ============== /** Set components from a Scalar beta_y */ - void - SetComponents (Scalar beta_y); + void SetComponents (Scalar by) { + using namespace std; + // set component + const Scalar bp2 = by*by; + if ( bp2 >= Scalar(1) ) { + GenVector::Throw("Beta Vector supplied to set BoostY represents speed >= c"); + } + else + { + fBeta = by; + fGamma = Scalar(1) / sqrt( Scalar(1) -bp2 ); + } + } /** Get components into a Scalar beta_y */ - void - GetComponents (Scalar& beta_y) const; - - + void GetComponents (Scalar& by) const { + // get component + by = fBeta; + } + /** Retrieve the beta of the Boost */ @@ -103,22 +134,30 @@ class BoostY { /** Set the given beta of the Boost */ - void SetBeta(Scalar beta) { SetComponents(beta); } + void SetBeta(Scalar beta) { SetComponents(beta); } /** The beta vector for this boost */ - typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; - XYZVector BetaVector() const; - + typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; + XYZVector BetaVector() const { + // return beta vector + return DisplacementVector3D< Cartesian3D > ( Scalar(0), fBeta, Scalar(0) ); + } + /** Get elements of internal 4x4 symmetric representation, into a data array suitable for direct use as the components of a LorentzRotation Note -- 16 Scalars will be written into the array; if the array is not that large, then this will lead to undefined behavior. */ - void - GetLorentzRotation (Scalar r[]) const; + void GetLorentzRotation (Scalar r[]) const { + // get corresponding LorentzRotation + r[kLXX] = Scalar(1); r[kLXY] = Scalar(0); r[kLXZ] = Scalar(0); r[kLXT] = Scalar(0); + r[kLYX] = Scalar(0); r[kLYY] = fGamma; r[kLYZ] = Scalar(0); r[kLYT] = fGamma*fBeta; + r[kLZX] = Scalar(0); r[kLZY] = Scalar(0); r[kLZZ] = Scalar(1); r[kLZT] = Scalar(0); + r[kLTX] = Scalar(0); r[kLTY] = fGamma*fBeta; r[kLTZ] = Scalar(0); r[kLTT] = fGamma; + } // =========== operations ============== @@ -126,8 +165,17 @@ class BoostY { Lorentz transformation operation on a Minkowski ('Cartesian') LorentzVector */ - LorentzVector< ROOT::Math::PxPyPzE4D > - operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const; + LorentzVector< ROOT::Math::PxPyPzE4D > + operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const { + // apply boost to a LV + const Scalar y = v.Py(); + const Scalar t = v.E(); + return LorentzVector< PxPyPzE4D > + ( v.Px() + , fGamma*y + fGamma*fBeta*t + , v.Pz() + , fGamma*fBeta*y + fGamma*t ); + } /** Lorentz transformation operation on a LorentzVector in any @@ -136,8 +184,8 @@ class BoostY { template LorentzVector operator() (const LorentzVector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return LorentzVector ( r_xyzt ); } @@ -149,8 +197,8 @@ class BoostY { template Foreign4Vector operator() (const Foreign4Vector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() ); } @@ -167,20 +215,27 @@ class BoostY { /** Invert a BoostY in place */ - void Invert(); + void Invert() { + // invert Boost + fBeta = -fBeta; + } /** Return inverse of a rotation */ - BoostY Inverse() const; + BoostY Inverse() const { + // return inverse + BoostY tmp(*this); + tmp.Invert(); + return tmp; + } /** Equality/inequality operators */ bool operator == (const BoostY & rhs) const { - if( fBeta != rhs.fBeta ) return false; - if( fGamma != rhs.fGamma ) return false; - return true; + return ( fBeta == rhs.fBeta && + fGamma == rhs.fGamma ); } bool operator != (const BoostY & rhs) const { return ! operator==(rhs); @@ -199,17 +254,18 @@ class BoostY { Stream Output and Input */ // TODO - I/O should be put in the manipulator form +template< typename T> +std::ostream & operator<< (std::ostream & os, const BoostY & b) { + os << " BoostY( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; + return os; +} + +} //namepsace Impl - std::ostream & operator<< (std::ostream & os, const BoostY & b); - +typedef Impl::BoostY BoostY; +typedef Impl::BoostY BoostYF; } //namespace Math } //namespace ROOT - - - - - - #endif /* ROOT_Math_GenVector_BoostY */ diff --git a/math/genvector/inc/Math/GenVector/BoostZ.h b/math/genvector/inc/Math/GenVector/BoostZ.h index fd5508e47d318..72d18beabf877 100644 --- a/math/genvector/inc/Math/GenVector/BoostZ.h +++ b/math/genvector/inc/Math/GenVector/BoostZ.h @@ -23,8 +23,8 @@ #include "Math/GenVector/Cartesian3D.h" namespace ROOT { - - namespace Math { +namespace Math { +namespace Impl { //__________________________________________________________________________________________ /** @@ -34,11 +34,12 @@ namespace ROOT { @ingroup GenVector */ +template class BoostZ { public: - typedef double Scalar; + typedef T Scalar; enum ELorentzRotationMatrixIndex { kLXX = 0, kLXY = 1, kLXZ = 2, kLXT = 3 @@ -52,6 +53,7 @@ class BoostZ { , kYY = 4, kYZ = 5, kYT = 6 , kZZ = 7, kZT = 8 , kTT = 9 + , kNElems = 10 }; // ========== Constructors and Assignment ===================== @@ -59,7 +61,7 @@ class BoostZ { /** Default constructor (identity transformation) */ - BoostZ(); + BoostZ() : fBeta(0), fGamma(1) {} /** Construct given a Scalar beta_z @@ -73,22 +75,52 @@ class BoostZ { Re-adjust components to eliminate small deviations from a perfect orthosyplectic matrix. */ - void Rectify(); + void Rectify() { + // Assuming the representation of this is close to a true Lorentz Rotation, + // but may have drifted due to round-off error from many operations, + // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation + // again. + + if ( fGamma <= Scalar(0) ) { + GenVector::Throw("Attempt to rectify a boost with non-positive gamma"); + } + else + { + Scalar beta = fBeta; + if ( beta >= Scalar(1) ) { + beta /= ( beta * ( Scalar( 1.0 + 1.0e-16 ) ) ); + } + SetComponents ( beta ); + } + } // ======== Components ============== /** Set components from a Scalar beta_z */ - void - SetComponents (Scalar beta_z); + void SetComponents (Scalar bz) { + using namespace std; + // set component + Scalar bp2 = bz*bz; + if ( bp2 >= Scalar(1) ) + { + GenVector::Throw("Beta Vector supplied to set BoostZ represents speed >= c"); + } + else + { + fBeta = bz; + fGamma = Scalar(1) / sqrt( Scalar(1) - bp2 ); + } + } /** Get components into a Scalar beta_z */ - void - GetComponents (Scalar& beta_z) const; - + void GetComponents (Scalar& bz) const { + // get component + bz = fBeta; + } /** Retrieve the beta of the Boost @@ -108,8 +140,11 @@ class BoostZ { /** The beta vector for this boost */ - typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; - XYZVector BetaVector() const; + typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; + XYZVector BetaVector() const { + // return beta vector + return DisplacementVector3D< Cartesian3D >( Scalar(0), Scalar(0), fBeta ); + } /** Get elements of internal 4x4 symmetric representation, into a data @@ -117,17 +152,30 @@ class BoostZ { Note -- 16 Scalars will be written into the array; if the array is not that large, then this will lead to undefined behavior. */ - void - GetLorentzRotation (Scalar r[]) const; - + void GetLorentzRotation (Scalar r[]) const { + // get corresponding LorentzRotation + r[kLXX] = Scalar(1); r[kLXY] = Scalar(0); r[kLXZ] = Scalar(0); r[kLXT] = Scalar(0) ; + r[kLYX] = Scalar(0); r[kLYY] = Scalar(1); r[kLYZ] = Scalar(0); r[kLYT] = Scalar(0) ; + r[kLZX] = Scalar(0); r[kLZY] = Scalar(0); r[kLZZ] = fGamma; r[kLZT] = fGamma*fBeta; + r[kLTX] = Scalar(0); r[kLTY] = Scalar(0); r[kLTZ] = fGamma*fBeta; r[kLTT] = fGamma; + } + // =========== operations ============== /** Lorentz transformation operation on a Minkowski ('Cartesian') LorentzVector */ - LorentzVector< ROOT::Math::PxPyPzE4D > - operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const; + LorentzVector< ROOT::Math::PxPyPzE4D > + operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const { + // apply boost to a LV + const Scalar z = v.Pz(); + const Scalar t = v.E(); + return LorentzVector< PxPyPzE4D > ( v.Px() + , v.Py() + , fGamma*z + fGamma*fBeta*t + , fGamma*fBeta*z + fGamma*t ); + } /** Lorentz transformation operation on a LorentzVector in any @@ -136,8 +184,8 @@ class BoostZ { template LorentzVector operator() (const LorentzVector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return LorentzVector ( r_xyzt ); } @@ -149,8 +197,8 @@ class BoostZ { template Foreign4Vector operator() (const Foreign4Vector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() ); } @@ -167,20 +215,27 @@ class BoostZ { /** Invert a BoostZ in place */ - void Invert(); + void Invert() { + // invert + fBeta = -fBeta; + } /** Return inverse of a BoostZ */ - BoostZ Inverse() const; - + BoostZ Inverse() const { + // return an inverse boostZ + BoostZ tmp(*this); + tmp.Invert(); + return tmp; + } + /** Equality/inequality operators */ bool operator == (const BoostZ & rhs) const { - if( fBeta != rhs.fBeta ) return false; - if( fGamma != rhs.fGamma ) return false; - return true; + return ( fBeta == rhs.fBeta && + fGamma == rhs.fGamma ); } bool operator != (const BoostZ & rhs) const { return ! operator==(rhs); @@ -199,17 +254,18 @@ class BoostZ { Stream Output and Input */ // TODO - I/O should be put in the manipulator form +template< typename T> +std::ostream & operator<< (std::ostream & os, const BoostZ & b) { + os << " BoostZ( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; + return os; +} -std::ostream & operator<< (std::ostream & os, const BoostZ & b); - +} //namespace Impl +typedef Impl::BoostZ BoostZ; +typedef Impl::BoostZ BoostZF; + } //namespace Math } //namespace ROOT - - - - - - #endif /* ROOT_Math_GenVector_BoostZ */ diff --git a/math/genvector/inc/Math/GenVector/Boostfwd.h b/math/genvector/inc/Math/GenVector/Boostfwd.h index acf0f5b1583b6..1233a2a7130e6 100644 --- a/math/genvector/inc/Math/GenVector/Boostfwd.h +++ b/math/genvector/inc/Math/GenVector/Boostfwd.h @@ -13,8 +13,8 @@ namespace ROOT { Class describing a pure boost in some direction */ -class Boost; - + class Boost; + } // namespace Math } // namespace ROOT diff --git a/math/genvector/src/Boost.cxx b/math/genvector/src/Boost.cxx index 9510558f27f33..7c0b6310bbd9e 100644 --- a/math/genvector/src/Boost.cxx +++ b/math/genvector/src/Boost.cxx @@ -22,165 +22,3 @@ #include #include - -//#ifdef TEX -/** - - A variable names bgamma appears in several places in this file. A few - words of elaboration are needed to make its meaning clear. On page 69 - of Misner, Thorne and Wheeler, (Exercise 2.7) the elements of the matrix - for a general Lorentz boost are given as - - \f[ \Lambda^{j'}_k = \Lambda^{k'}_j - = (\gamma - 1) n^j n^k + \delta^{jk} \f] - - where the n^i are unit vectors in the direction of the three spatial - axes. Using the definitions, \f$ n^i = \beta_i/\beta \f$ , then, for example, - - \f[ \Lambda_{xy} = (\gamma - 1) n_x n_y - = (\gamma - 1) \beta_x \beta_y/\beta^2 \f] - - By definition, \f[ \gamma^2 = 1/(1 - \beta^2) \f] - - so that \f[ \gamma^2 \beta^2 = \gamma^2 - 1 \f] - - or \f[ \beta^2 = (\gamma^2 - 1)/\gamma^2 \f] - - If we insert this into the expression for \f$ \Lambda_{xy} \f$, we get - - \f[ \Lambda_{xy} = (\gamma - 1) \gamma^2/(\gamma^2 - 1) \beta_x \beta_y \f] - - or, finally - - \f[ \Lambda_{xy} = \gamma^2/(\gamma+1) \beta_x \beta_y \f] - - The expression \f$ \gamma^2/(\gamma+1) \f$ is what we call bgamma in the code below. - - \class ROOT::Math::Boost -*/ -//#endif - -namespace ROOT { - -namespace Math { - -void Boost::SetIdentity() { - // set identity boost - fM[kXX] = 1.0; fM[kXY] = 0.0; fM[kXZ] = 0.0; fM[kXT] = 0.0; - fM[kYY] = 1.0; fM[kYZ] = 0.0; fM[kYT] = 0.0; - fM[kZZ] = 1.0; fM[kZT] = 0.0; - fM[kTT] = 1.0; -} - - -void Boost::SetComponents (Scalar bx, Scalar by, Scalar bz) { - // set the boost beta as 3 components - Scalar bp2 = bx*bx + by*by + bz*bz; - if (bp2 >= 1) { - GenVector::Throw ( - "Beta Vector supplied to set Boost represents speed >= c"); - // SetIdentity(); - return; - } - Scalar gamma = 1.0 / std::sqrt(1.0 - bp2); - Scalar bgamma = gamma * gamma / (1.0 + gamma); - fM[kXX] = 1.0 + bgamma * bx * bx; - fM[kYY] = 1.0 + bgamma * by * by; - fM[kZZ] = 1.0 + bgamma * bz * bz; - fM[kXY] = bgamma * bx * by; - fM[kXZ] = bgamma * bx * bz; - fM[kYZ] = bgamma * by * bz; - fM[kXT] = gamma * bx; - fM[kYT] = gamma * by; - fM[kZT] = gamma * bz; - fM[kTT] = gamma; -} - -void Boost::GetComponents (Scalar& bx, Scalar& by, Scalar& bz) const { - // get beta of the boots as 3 components - Scalar gaminv = 1.0/fM[kTT]; - bx = fM[kXT]*gaminv; - by = fM[kYT]*gaminv; - bz = fM[kZT]*gaminv; -} - -DisplacementVector3D< Cartesian3D > -Boost::BetaVector() const { - // get boost beta vector - Scalar gaminv = 1.0/fM[kTT]; - return DisplacementVector3D< Cartesian3D > - ( fM[kXT]*gaminv, fM[kYT]*gaminv, fM[kZT]*gaminv ); -} - -void Boost::GetLorentzRotation (Scalar r[]) const { - // get Lorentz rotation corresponding to this boost as an array of 16 values - r[kLXX] = fM[kXX]; r[kLXY] = fM[kXY]; r[kLXZ] = fM[kXZ]; r[kLXT] = fM[kXT]; - r[kLYX] = fM[kXY]; r[kLYY] = fM[kYY]; r[kLYZ] = fM[kYZ]; r[kLYT] = fM[kYT]; - r[kLZX] = fM[kXZ]; r[kLZY] = fM[kYZ]; r[kLZZ] = fM[kZZ]; r[kLZT] = fM[kZT]; - r[kLTX] = fM[kXT]; r[kLTY] = fM[kYT]; r[kLTZ] = fM[kZT]; r[kLTT] = fM[kTT]; -} - -void Boost::Rectify() { - // Assuming the representation of this is close to a true Lorentz Rotation, - // but may have drifted due to round-off error from many operations, - // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation - // again. - - if (fM[kTT] <= 0) { - GenVector::Throw ( - "Attempt to rectify a boost with non-positive gamma"); - return; - } - DisplacementVector3D< Cartesian3D > beta ( fM[kXT], fM[kYT], fM[kZT] ); - beta /= fM[kTT]; - if ( beta.mag2() >= 1 ) { - beta /= ( beta.R() * ( 1.0 + 1.0e-16 ) ); - } - SetComponents ( beta ); -} - -LorentzVector< PxPyPzE4D > -Boost::operator() (const LorentzVector< PxPyPzE4D > & v) const { - // apply bosost to a PxPyPzE LorentzVector - Scalar x = v.Px(); - Scalar y = v.Py(); - Scalar z = v.Pz(); - Scalar t = v.E(); - return LorentzVector< PxPyPzE4D > - ( fM[kXX]*x + fM[kXY]*y + fM[kXZ]*z + fM[kXT]*t - , fM[kXY]*x + fM[kYY]*y + fM[kYZ]*z + fM[kYT]*t - , fM[kXZ]*x + fM[kYZ]*y + fM[kZZ]*z + fM[kZT]*t - , fM[kXT]*x + fM[kYT]*y + fM[kZT]*z + fM[kTT]*t ); -} - -void Boost::Invert() { - // invert in place boost (modifying the object) - fM[kXT] = -fM[kXT]; - fM[kYT] = -fM[kYT]; - fM[kZT] = -fM[kZT]; -} - -Boost Boost::Inverse() const { - // return inverse of boost - Boost tmp(*this); - tmp.Invert(); - return tmp; -} - - -// ========== I/O ===================== - -std::ostream & operator<< (std::ostream & os, const Boost & b) { - // TODO - this will need changing for machine-readable issues - // and even the human readable form needs formatiing improvements - double m[16]; - b.GetLorentzRotation(m); - os << "\n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3]; - os << "\n" << "\t" << " " << m[5] << " " << m[6] << " " << m[7]; - os << "\n" << "\t" << " " << "\t" << " " << m[10] << " " << m[11]; - os << "\n" << "\t" << " " << "\t" << " " << "\t" << " " << m[15] << "\n"; - return os; -} - -} //namespace Math -} //namespace ROOT diff --git a/math/genvector/src/BoostX.cxx b/math/genvector/src/BoostX.cxx index 758e503aaef95..20563e9dee0f2 100644 --- a/math/genvector/src/BoostX.cxx +++ b/math/genvector/src/BoostX.cxx @@ -22,93 +22,3 @@ #include #include - -namespace ROOT { - -namespace Math { - - -BoostX::BoostX() : fBeta(0.0), fGamma(1.0) {} - -void BoostX::SetComponents (Scalar bx ) { - // set component - Scalar bp2 = bx*bx; - if (bp2 >= 1) { - GenVector::Throw ( - "Beta Vector supplied to set BoostX represents speed >= c"); - return; - } - fBeta = bx; - fGamma = 1.0 / std::sqrt(1.0 - bp2); -} - -void BoostX::GetComponents (Scalar& bx) const { - // get component - bx = fBeta; -} - -DisplacementVector3D< Cartesian3D > -BoostX::BetaVector() const { - // return beta vector - return DisplacementVector3D< Cartesian3D > ( fBeta, 0.0, 0.0 ); -} - -void BoostX::GetLorentzRotation (Scalar r[]) const { - // get corresponding LorentzRotation - r[kLXX] = fGamma; r[kLXY] = 0.0; r[kLXZ] = 0.0; r[kLXT] = fGamma*fBeta; - r[kLYX] = 0.0; r[kLYY] = 1.0; r[kLYZ] = 0.0; r[kLYT] = 0.0; - r[kLZX] = 0.0; r[kLZY] = 0.0; r[kLZZ] = 1.0; r[kLZT] = 0.0; - r[kLTX] = fGamma*fBeta; r[kLTY] = 0.0; r[kLTZ] = 0.0; r[kLTT] = fGamma; -} - -void BoostX::Rectify() { - // Assuming the representation of this is close to a true Lorentz Rotation, - // but may have drifted due to round-off error from many operations, - // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation - // again. - - if (fGamma <= 0) { - GenVector::Throw ( - "Attempt to rectify a boost with non-positive gamma"); - return; - } - Scalar beta = fBeta; - if ( beta >= 1 ) { - beta /= ( beta * ( 1.0 + 1.0e-16 ) ); - } - SetComponents ( beta ); -} - -LorentzVector< PxPyPzE4D > -BoostX::operator() (const LorentzVector< PxPyPzE4D > & v) const { - // apply boost to a LV - Scalar x = v.Px(); - Scalar t = v.E(); - return LorentzVector< PxPyPzE4D > - ( fGamma*x + fGamma*fBeta*t - , v.Py() - , v.Pz() - , fGamma*fBeta*x + fGamma*t ); -} - -void BoostX::Invert() { - // invert - fBeta = -fBeta; -} - -BoostX BoostX::Inverse() const { - // return an inverse boostX - BoostX tmp(*this); - tmp.Invert(); - return tmp; -} - -// ========== I/O ===================== - -std::ostream & operator<< (std::ostream & os, const BoostX & b) { - os << " BoostX( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; - return os; -} - -} //namespace Math -} //namespace ROOT diff --git a/math/genvector/src/BoostY.cxx b/math/genvector/src/BoostY.cxx index 5b79695799c56..7fc82186ff6d6 100644 --- a/math/genvector/src/BoostY.cxx +++ b/math/genvector/src/BoostY.cxx @@ -22,92 +22,3 @@ #include #include - -namespace ROOT { - -namespace Math { - -BoostY::BoostY() : fBeta(0.0), fGamma(1.0) {} - -void BoostY::SetComponents (Scalar by) { - // set component - Scalar bp2 = by*by; - if (bp2 >= 1) { - GenVector::Throw( - "Beta Vector supplied to set BoostY represents speed >= c"); - return; - } - fBeta = by; - fGamma = 1.0 / std::sqrt(1.0-bp2); -} - -void BoostY::GetComponents (Scalar& by) const { - // get component - by = fBeta; -} - -DisplacementVector3D< Cartesian3D > -BoostY::BetaVector() const { - // return beta vector - return DisplacementVector3D< Cartesian3D > ( 0.0, fBeta, 0.0 ); -} - -void BoostY::GetLorentzRotation (Scalar r[]) const { - // get corresponding LorentzRotation - r[kLXX] = 1.0; r[kLXY] = 0.0; r[kLXZ] = 0.0; r[kLXT] = 0.0; - r[kLYX] = 0.0; r[kLYY] = fGamma; r[kLYZ] = 0.0; r[kLYT] = fGamma*fBeta; - r[kLZX] = 0.0; r[kLZY] = 0.0; r[kLZZ] = 1.0; r[kLZT] = 0.0; - r[kLTX] = 0.0; r[kLTY] = fGamma*fBeta; r[kLTZ] = 0.0; r[kLTT] = fGamma; -} - -void BoostY::Rectify() { - // Assuming the representation of this is close to a true Lorentz Rotation, - // but may have drifted due to round-off error from many operations, - // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation - // again. - - if (fGamma <= 0) { - GenVector::Throw ( - "Attempt to rectify a boost with non-positive gamma"); - return; - } - Scalar beta = fBeta; - if ( beta >= 1 ) { - beta /= ( beta * ( 1.0 + 1.0e-16 ) ); - } - SetComponents ( beta ); -} - -LorentzVector< PxPyPzE4D > -BoostY::operator() (const LorentzVector< PxPyPzE4D > & v) const { - // apply boost to a LV - Scalar y = v.Py(); - Scalar t = v.E(); - return LorentzVector< PxPyPzE4D > - ( v.Px() - , fGamma*y + fGamma*fBeta*t - , v.Pz() - , fGamma*fBeta*y + fGamma*t ); -} - -void BoostY::Invert() { - // invert Boost - fBeta = -fBeta; -} - -BoostY BoostY::Inverse() const { - // return inverse - BoostY tmp(*this); - tmp.Invert(); - return tmp; -} - -// ========== I/O ===================== - -std::ostream & operator<< (std::ostream & os, const BoostY & b) { - os << " BoostY( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; - return os; -} - -} //namespace Math -} //namespace ROOT diff --git a/math/genvector/src/BoostZ.cxx b/math/genvector/src/BoostZ.cxx index 5c319f492dd48..d3bdcaa212a94 100644 --- a/math/genvector/src/BoostZ.cxx +++ b/math/genvector/src/BoostZ.cxx @@ -22,93 +22,3 @@ #include #include - -namespace ROOT { - -namespace Math { - -BoostZ::BoostZ() : fBeta(0.0), fGamma(1.0) {} - -void BoostZ::SetComponents (Scalar bz) { - // set component - Scalar bp2 = bz*bz; - if (bp2 >= 1) { - GenVector::Throw ( - "Beta Vector supplied to set BoostZ represents speed >= c"); - return; - } - fBeta = bz; - fGamma = 1.0 / std::sqrt(1.0 - bp2); -} - -void BoostZ::GetComponents (Scalar& bz) const { - // get component - bz = fBeta; -} - -DisplacementVector3D< Cartesian3D > -BoostZ::BetaVector() const { - // return beta vector - return DisplacementVector3D< Cartesian3D > - ( 0.0, 0.0, fBeta ); -} - -void BoostZ::GetLorentzRotation (Scalar r[]) const { - // get corresponding LorentzRotation - r[kLXX] = 1.0; r[kLXY] = 0.0; r[kLXZ] = 0.0; r[kLXT] = 0.0 ; - r[kLYX] = 0.0; r[kLYY] = 1.0; r[kLYZ] = 0.0; r[kLYT] = 0.0 ; - r[kLZX] = 0.0; r[kLZY] = 0.0; r[kLZZ] = fGamma; r[kLZT] = fGamma*fBeta; - r[kLTX] = 0.0; r[kLTY] = 0.0; r[kLTZ] = fGamma*fBeta; r[kLTT] = fGamma; -} - -void BoostZ::Rectify() { - // Assuming the representation of this is close to a true Lorentz Rotation, - // but may have drifted due to round-off error from many operations, - // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation - // again. - - if (fGamma <= 0) { - GenVector::Throw ( - "Attempt to rectify a boost with non-positive gamma"); - return; - } - Scalar beta = fBeta; - if ( beta >= 1 ) { - beta /= ( beta * ( 1.0 + 1.0e-16 ) ); - } - SetComponents ( beta ); -} - -LorentzVector< PxPyPzE4D > -BoostZ::operator() (const LorentzVector< PxPyPzE4D > & v) const { - // apply boost to a LV - Scalar z = v.Pz(); - Scalar t = v.E(); - return LorentzVector< PxPyPzE4D > - ( v.Px() - , v.Py() - , fGamma*z + fGamma*fBeta*t - , fGamma*fBeta*z + fGamma*t ); -} - -void BoostZ::Invert() { - // invert - fBeta = -fBeta; -} - -BoostZ BoostZ::Inverse() const { - // return an inverse boostZ - BoostZ tmp(*this); - tmp.Invert(); - return tmp; -} - -// ========== I/O ===================== - -std::ostream & operator<< (std::ostream & os, const BoostZ & b) { - os << " BoostZ( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; - return os; -} - -} //namespace Math -} //namespace ROOT From c97245c4762bb420da6e7a01b3c6b87cf5024389 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 22:09:00 +0000 Subject: [PATCH 08/44] Remove empty implementation files for Boost classes --- math/genvector/src/BoostX.cxx | 24 ------------------------ math/genvector/src/BoostY.cxx | 24 ------------------------ math/genvector/src/BoostZ.cxx | 24 ------------------------ 3 files changed, 72 deletions(-) delete mode 100644 math/genvector/src/BoostX.cxx delete mode 100644 math/genvector/src/BoostY.cxx delete mode 100644 math/genvector/src/BoostZ.cxx diff --git a/math/genvector/src/BoostX.cxx b/math/genvector/src/BoostX.cxx deleted file mode 100644 index 20563e9dee0f2..0000000000000 --- a/math/genvector/src/BoostX.cxx +++ /dev/null @@ -1,24 +0,0 @@ - // @(#)root/mathcore:$Id$ -// Authors: M. Fischler 2005 - - /********************************************************************** - * * - * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team * - * * - * * - **********************************************************************/ - -// Header file for class BoostX, a 4x4 symmetric matrix representation of -// an axial Lorentz transformation -// -// Created by: Mark Fischler Mon Nov 1 2005 -// -#include "Math/GenVector/BoostX.h" -#include "Math/GenVector/LorentzVector.h" -#include "Math/GenVector/PxPyPzE4D.h" -#include "Math/GenVector/DisplacementVector3D.h" -#include "Math/GenVector/Cartesian3D.h" -#include "Math/GenVector/GenVector_exception.h" - -#include -#include diff --git a/math/genvector/src/BoostY.cxx b/math/genvector/src/BoostY.cxx deleted file mode 100644 index 7fc82186ff6d6..0000000000000 --- a/math/genvector/src/BoostY.cxx +++ /dev/null @@ -1,24 +0,0 @@ -// @(#)root/mathcore:$Id$ -// Authors: M. Fischler 2005 - - /********************************************************************** - * * - * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team * - * * - * * - **********************************************************************/ - -// Header file for class BoostY, a 4x4 symmetric matrix representation of -// an axial Lorentz transformation -// -// Created by: Mark Fischler Mon Nov 1 2005 -// -#include "Math/GenVector/BoostY.h" -#include "Math/GenVector/LorentzVector.h" -#include "Math/GenVector/PxPyPzE4D.h" -#include "Math/GenVector/DisplacementVector3D.h" -#include "Math/GenVector/Cartesian3D.h" -#include "Math/GenVector/GenVector_exception.h" - -#include -#include diff --git a/math/genvector/src/BoostZ.cxx b/math/genvector/src/BoostZ.cxx deleted file mode 100644 index d3bdcaa212a94..0000000000000 --- a/math/genvector/src/BoostZ.cxx +++ /dev/null @@ -1,24 +0,0 @@ -// @(#)root/mathcore:$Id$ -// Authors: M. Fischler 2005 - - /********************************************************************** - * * - * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team * - * * - * * - **********************************************************************/ - -// Header file for class BoostZ, a 4x4 symmetric matrix representation of -// an axial Lorentz transformation -// -// Created by: Mark Fischler Mon Nov 1 2005 -// -#include "Math/GenVector/BoostZ.h" -#include "Math/GenVector/LorentzVector.h" -#include "Math/GenVector/PxPyPzE4D.h" -#include "Math/GenVector/DisplacementVector3D.h" -#include "Math/GenVector/Cartesian3D.h" -#include "Math/GenVector/GenVector_exception.h" - -#include -#include From f12d36832455b6963bee95b7807efafd64488fd1 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 22:13:45 +0000 Subject: [PATCH 09/44] Clean up some indentations --- math/genvector/inc/Math/GenVector/BoostX.h | 10 +++++----- math/genvector/inc/Math/GenVector/BoostY.h | 8 ++++---- math/genvector/inc/Math/GenVector/BoostZ.h | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/BoostX.h b/math/genvector/inc/Math/GenVector/BoostX.h index 5444cb1e3bbea..2776fdfc4942a 100644 --- a/math/genvector/inc/Math/GenVector/BoostX.h +++ b/math/genvector/inc/Math/GenVector/BoostX.h @@ -49,11 +49,11 @@ class BoostX { }; enum EBoostMatrixIndex { - kXX = 0, kXY = 1, kXZ = 2, kXT = 3 - , kYY = 4, kYZ = 5, kYT = 6 - , kZZ = 7, kZT = 8 - , kTT = 9 - , kNElems = 10 + kXX = 0, kXY = 1, kXZ = 2, kXT = 3 + , kYY = 4, kYZ = 5, kYT = 6 + , kZZ = 7, kZT = 8 + , kTT = 9 + , kNElems = 10 }; // ========== Constructors and Assignment ===================== diff --git a/math/genvector/inc/Math/GenVector/BoostY.h b/math/genvector/inc/Math/GenVector/BoostY.h index be3e31eb307e8..f005503d2c88f 100644 --- a/math/genvector/inc/Math/GenVector/BoostY.h +++ b/math/genvector/inc/Math/GenVector/BoostY.h @@ -50,10 +50,10 @@ class BoostY { enum EBoostMatrixIndex { kXX = 0, kXY = 1, kXZ = 2, kXT = 3 - , kYY = 4, kYZ = 5, kYT = 6 - , kZZ = 7, kZT = 8 - , kTT = 9 - , kNElems = 10 + , kYY = 4, kYZ = 5, kYT = 6 + , kZZ = 7, kZT = 8 + , kTT = 9 + , kNElems = 10 }; // ========== Constructors and Assignment ===================== diff --git a/math/genvector/inc/Math/GenVector/BoostZ.h b/math/genvector/inc/Math/GenVector/BoostZ.h index 72d18beabf877..3352b769c3d24 100644 --- a/math/genvector/inc/Math/GenVector/BoostZ.h +++ b/math/genvector/inc/Math/GenVector/BoostZ.h @@ -50,10 +50,10 @@ class BoostZ { enum EBoostMatrixIndex { kXX = 0, kXY = 1, kXZ = 2, kXT = 3 - , kYY = 4, kYZ = 5, kYT = 6 - , kZZ = 7, kZT = 8 - , kTT = 9 - , kNElems = 10 + , kYY = 4, kYZ = 5, kYT = 6 + , kZZ = 7, kZT = 8 + , kTT = 9 + , kNElems = 10 }; // ========== Constructors and Assignment ===================== From bbbbbd083b3abda18dbceba643183e38ce86e6e1 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 22:32:02 +0000 Subject: [PATCH 10/44] Add some missing template types to the Boost classes --- math/genvector/inc/Math/GenVector/Boost.h | 33 +++++++++++----------- math/genvector/inc/Math/GenVector/BoostX.h | 11 ++++---- math/genvector/inc/Math/GenVector/BoostY.h | 11 ++++---- math/genvector/inc/Math/GenVector/BoostZ.h | 4 +-- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Boost.h b/math/genvector/inc/Math/GenVector/Boost.h index b92780714dbc8..9fe66e8c6e10a 100644 --- a/math/genvector/inc/Math/GenVector/Boost.h +++ b/math/genvector/inc/Math/GenVector/Boost.h @@ -148,7 +148,7 @@ class Boost { /** Assignment operator */ - Boost & + Boost & operator=(Boost const & rhs ) { for (unsigned int i=0; i < kNElems; ++i) { fM[i] = rhs.fM[i]; @@ -159,12 +159,12 @@ class Boost { /** Assign from an axial pure boost */ - Boost & - operator=( BoostX const & bx ) { return operator=(Boost(bx)); } - Boost & - operator=( BoostY const & by ) { return operator=(Boost(by)); } - Boost & - operator=( BoostZ const & bz ) { return operator=(Boost(bz)); } + Boost & + operator=( BoostX const & bx ) { return operator=(Boost(bx)); } + Boost & + operator=( BoostY const & by ) { return operator=(Boost(by)); } + Boost & + operator=( BoostZ const & bz ) { return operator=(Boost(bz)); } /** Re-adjust components to eliminate small deviations from a perfect @@ -176,17 +176,18 @@ class Boost { // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation // again. - if (fM[kTT] <= 0) { - GenVector::Throw ( - "Attempt to rectify a boost with non-positive gamma"); - return; + if ( fM[kTT] <= Scalar(0) ) { + GenVector::Throw("Attempt to rectify a boost with non-positive gamma"); } - DisplacementVector3D< Cartesian3D > beta ( fM[kXT], fM[kYT], fM[kZT] ); - beta /= fM[kTT]; - if ( beta.mag2() >= 1 ) { - beta /= ( beta.R() * ( 1.0 + 1.0e-16 ) ); + else + { + DisplacementVector3D< Cartesian3D > beta ( fM[kXT], fM[kYT], fM[kZT] ); + beta /= fM[kTT]; + if ( beta.mag2() >= 1 ) { + beta /= ( beta.R() * Scalar( 1.0 + 1.0e-16 ) ); + } + SetComponents ( beta ); } - SetComponents ( beta ); } // ======== Components ============== diff --git a/math/genvector/inc/Math/GenVector/BoostX.h b/math/genvector/inc/Math/GenVector/BoostX.h index 2776fdfc4942a..ac690d3b22df3 100644 --- a/math/genvector/inc/Math/GenVector/BoostX.h +++ b/math/genvector/inc/Math/GenVector/BoostX.h @@ -82,8 +82,7 @@ class BoostX { // again. if ( fGamma <= Scalar(0) ) { - GenVector::Throw ( - "Attempt to rectify a boost with non-positive gamma"); + GenVector::Throw("Attempt to rectify a boost with non-positive gamma"); } else { @@ -227,9 +226,9 @@ class BoostX { /** Return inverse of a boost */ - BoostX Inverse() const { + BoostX Inverse() const { // return an inverse boostX - BoostX tmp(*this); + BoostX tmp(*this); tmp.Invert(); return tmp; } @@ -237,12 +236,12 @@ class BoostX { /** Equality/inequality operators */ - bool operator == (const BoostX & rhs) const { + bool operator == (const BoostX & rhs) const { return ( fBeta == rhs.fBeta && fGamma == rhs.fGamma ); } - bool operator != (const BoostX & rhs) const { + bool operator != (const BoostX & rhs) const { return ! operator==(rhs); } diff --git a/math/genvector/inc/Math/GenVector/BoostY.h b/math/genvector/inc/Math/GenVector/BoostY.h index f005503d2c88f..ba14af8a19634 100644 --- a/math/genvector/inc/Math/GenVector/BoostY.h +++ b/math/genvector/inc/Math/GenVector/BoostY.h @@ -81,8 +81,7 @@ class BoostY { // again. if ( fGamma <= Scalar(0) ) { - GenVector::Throw ( - "Attempt to rectify a boost with non-positive gamma"); + GenVector::Throw("Attempt to rectify a boost with non-positive gamma"); } else { @@ -223,9 +222,9 @@ class BoostY { /** Return inverse of a rotation */ - BoostY Inverse() const { + BoostY Inverse() const { // return inverse - BoostY tmp(*this); + BoostY tmp(*this); tmp.Invert(); return tmp; } @@ -233,11 +232,11 @@ class BoostY { /** Equality/inequality operators */ - bool operator == (const BoostY & rhs) const { + bool operator == (const BoostY & rhs) const { return ( fBeta == rhs.fBeta && fGamma == rhs.fGamma ); } - bool operator != (const BoostY & rhs) const { + bool operator != (const BoostY & rhs) const { return ! operator==(rhs); } diff --git a/math/genvector/inc/Math/GenVector/BoostZ.h b/math/genvector/inc/Math/GenVector/BoostZ.h index 3352b769c3d24..df82954a7e2be 100644 --- a/math/genvector/inc/Math/GenVector/BoostZ.h +++ b/math/genvector/inc/Math/GenVector/BoostZ.h @@ -233,11 +233,11 @@ class BoostZ { /** Equality/inequality operators */ - bool operator == (const BoostZ & rhs) const { + bool operator == (const BoostZ & rhs) const { return ( fBeta == rhs.fBeta && fGamma == rhs.fGamma ); } - bool operator != (const BoostZ & rhs) const { + bool operator != (const BoostZ & rhs) const { return ! operator==(rhs); } From 9a0ee7727f5880ab759dbbbabb2d1bdb8581c148 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 22:38:43 +0000 Subject: [PATCH 11/44] Remove empty Boost implementation file --- math/genvector/src/Boost.cxx | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 math/genvector/src/Boost.cxx diff --git a/math/genvector/src/Boost.cxx b/math/genvector/src/Boost.cxx deleted file mode 100644 index 7c0b6310bbd9e..0000000000000 --- a/math/genvector/src/Boost.cxx +++ /dev/null @@ -1,24 +0,0 @@ -// @(#)root/mathcore:$Id$ -// Authors: M. Fischler 2005 - - /********************************************************************** - * * - * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team * - * * - * * - **********************************************************************/ - -// Header file for class Boost, a 4x4 symmetric matrix representation of -// an axial Lorentz transformation -// -// Created by: Mark Fischler Mon Nov 1 2005 -// -#include "Math/GenVector/Boost.h" -#include "Math/GenVector/LorentzVector.h" -#include "Math/GenVector/PxPyPzE4D.h" -#include "Math/GenVector/DisplacementVector3D.h" -#include "Math/GenVector/Cartesian3D.h" -#include "Math/GenVector/GenVector_exception.h" - -#include -#include From 371d50d912394bb432a76408df164fc7e55ac8e5 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 22:54:12 +0000 Subject: [PATCH 12/44] Small cleanups --- math/genvector/inc/Math/GenVector/Boost.h | 7 +++---- math/genvector/inc/Math/GenVector/BoostX.h | 9 ++++----- math/genvector/inc/Math/GenVector/BoostY.h | 8 ++++---- math/genvector/inc/Math/GenVector/BoostZ.h | 10 +++++----- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Boost.h b/math/genvector/inc/Math/GenVector/Boost.h index 9fe66e8c6e10a..004e5c347890f 100644 --- a/math/genvector/inc/Math/GenVector/Boost.h +++ b/math/genvector/inc/Math/GenVector/Boost.h @@ -199,10 +199,9 @@ class Boost { SetComponents (Scalar bx, Scalar by, Scalar bz) { using namespace std; // set the boost beta as 3 components - Scalar bp2 = bx*bx + by*by + bz*bz; + const Scalar bp2 = bx*bx + by*by + bz*bz; if ( bp2 >= Scalar(1) ) { - GenVector::Throw ( - "Beta Vector supplied to set Boost represents speed >= c"); + GenVector::Throw("Beta Vector supplied to set Boost represents speed >= c"); // SetIdentity(); } else @@ -228,7 +227,7 @@ class Boost { void GetComponents (Scalar& bx, Scalar& by, Scalar& bz) const { // get beta of the boots as 3 components - Scalar gaminv = Scalar(1)/fM[kTT]; + const Scalar gaminv = Scalar(1)/fM[kTT]; bx = fM[kXT]*gaminv; by = fM[kYT]*gaminv; bz = fM[kZT]*gaminv; diff --git a/math/genvector/inc/Math/GenVector/BoostX.h b/math/genvector/inc/Math/GenVector/BoostX.h index ac690d3b22df3..9cd6c7d02909e 100644 --- a/math/genvector/inc/Math/GenVector/BoostX.h +++ b/math/genvector/inc/Math/GenVector/BoostX.h @@ -104,10 +104,9 @@ class BoostX { SetComponents (Scalar bx) { using namespace std; // set component - Scalar bp2 = bx*bx; - if (bp2 >= Scalar(1) ) { - GenVector::Throw ( - "Beta Vector supplied to set BoostX represents speed >= c"); + const Scalar bp2 = bx*bx; + if ( bp2 >= Scalar(1) ) { + GenVector::Throw("Beta Vector supplied to set BoostX represents speed >= c"); } else { @@ -137,7 +136,7 @@ class BoostX { /** Set the given beta of the Boost */ - void SetBeta(Scalar beta) { SetComponents(beta); } + void SetBeta(Scalar beta) { SetComponents(beta); } /** The beta vector for this boost diff --git a/math/genvector/inc/Math/GenVector/BoostY.h b/math/genvector/inc/Math/GenVector/BoostY.h index ba14af8a19634..dc3fc9286ae7b 100644 --- a/math/genvector/inc/Math/GenVector/BoostY.h +++ b/math/genvector/inc/Math/GenVector/BoostY.h @@ -183,8 +183,8 @@ class BoostY { template LorentzVector operator() (const LorentzVector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + const LorentzVector< PxPyPzE4D > xyzt(v); + const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return LorentzVector ( r_xyzt ); } @@ -196,8 +196,8 @@ class BoostY { template Foreign4Vector operator() (const Foreign4Vector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + const LorentzVector< PxPyPzE4D > xyzt(v); + const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() ); } diff --git a/math/genvector/inc/Math/GenVector/BoostZ.h b/math/genvector/inc/Math/GenVector/BoostZ.h index df82954a7e2be..cc9520b931ac4 100644 --- a/math/genvector/inc/Math/GenVector/BoostZ.h +++ b/math/genvector/inc/Math/GenVector/BoostZ.h @@ -102,7 +102,7 @@ class BoostZ { void SetComponents (Scalar bz) { using namespace std; // set component - Scalar bp2 = bz*bz; + const Scalar bp2 = bz*bz; if ( bp2 >= Scalar(1) ) { GenVector::Throw("Beta Vector supplied to set BoostZ represents speed >= c"); @@ -184,8 +184,8 @@ class BoostZ { template LorentzVector operator() (const LorentzVector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + const LorentzVector< PxPyPzE4D > xyzt(v); + const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return LorentzVector ( r_xyzt ); } @@ -197,8 +197,8 @@ class BoostZ { template Foreign4Vector operator() (const Foreign4Vector & v) const { - LorentzVector< PxPyPzE4D > xyzt(v); - LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + const LorentzVector< PxPyPzE4D > xyzt(v); + const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() ); } From dcb0b30cfd11e737e09c6b169f326eac9a45a941 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 25 Feb 2017 23:05:58 +0000 Subject: [PATCH 13/44] Clean up some initialisations --- math/genvector/inc/Math/GenVector/Boost.h | 12 ++++++------ math/genvector/inc/Math/GenVector/BoostX.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Boost.h b/math/genvector/inc/Math/GenVector/Boost.h index 004e5c347890f..4fd9ee763a8af 100644 --- a/math/genvector/inc/Math/GenVector/Boost.h +++ b/math/genvector/inc/Math/GenVector/Boost.h @@ -183,7 +183,7 @@ class Boost { { DisplacementVector3D< Cartesian3D > beta ( fM[kXT], fM[kYT], fM[kZT] ); beta /= fM[kTT]; - if ( beta.mag2() >= 1 ) { + if ( beta.mag2() >= Scalar(1) ) { beta /= ( beta.R() * Scalar( 1.0 + 1.0e-16 ) ); } SetComponents ( beta ); @@ -277,11 +277,11 @@ class Boost { */ template void GetComponents(IT begin ) const { - T bx,by,bz = 0; - GetComponents (bx,by,bz); - *begin++ = bx; - *begin++ = by; - *begin = bz; + T bx(0), by(0), bz(0); + GetComponents (bx,by,bz); + *begin++ = bx; + *begin++ = by; + *begin = bz; } /** diff --git a/math/genvector/inc/Math/GenVector/BoostX.h b/math/genvector/inc/Math/GenVector/BoostX.h index 9cd6c7d02909e..83983e46e44d6 100644 --- a/math/genvector/inc/Math/GenVector/BoostX.h +++ b/math/genvector/inc/Math/GenVector/BoostX.h @@ -267,7 +267,7 @@ std::ostream & operator<< (std::ostream & os, const BoostX & b) { } //namepsace Impl typedef Impl::BoostX BoostX; -typedef Impl::BoostX BoostXF; +typedef Impl::BoostX BoostXF; } //namespace Math } //namespace ROOT From 14e73b4ef655375706da594ebc02c69a4076ff81 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 27 Feb 2017 19:35:35 +0100 Subject: [PATCH 14/44] Add Scalar/Vector Plane3D::Normalise() methods using SFINAE --- math/genvector/inc/Math/GenVector/BoostZ.h | 1 - math/genvector/inc/Math/GenVector/Plane3D.h | 49 ++++++++++++++++----- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/BoostZ.h b/math/genvector/inc/Math/GenVector/BoostZ.h index cc9520b931ac4..9e7f5f472aa19 100644 --- a/math/genvector/inc/Math/GenVector/BoostZ.h +++ b/math/genvector/inc/Math/GenVector/BoostZ.h @@ -68,7 +68,6 @@ class BoostZ { */ explicit BoostZ(Scalar beta_z) { SetComponents(beta_z); } - // The compiler-generated copy ctor, copy assignment, and dtor are OK. /** diff --git a/math/genvector/inc/Math/GenVector/Plane3D.h b/math/genvector/inc/Math/GenVector/Plane3D.h index c7e2516ba80bb..186bf0642b1f3 100644 --- a/math/genvector/inc/Math/GenVector/Plane3D.h +++ b/math/genvector/inc/Math/GenVector/Plane3D.h @@ -17,6 +17,8 @@ #ifndef ROOT_Math_GenVector_Plane3D #define ROOT_Math_GenVector_Plane3D 1 +#include + #include "Math/GenVector/DisplacementVector3D.h" #include "Math/GenVector/PositionVector3D.h" @@ -62,7 +64,7 @@ namespace Impl { /** default constructor create plane z = 0 */ - Plane3D ( ) : fA(0), fB(0), fC(1.), fD(0) { } + Plane3D() : fA(0), fB(0), fC(1), fD(0) { } /** generic constructors from the four scalar values describing the plane @@ -98,7 +100,7 @@ namespace Impl { \param p point expressed as a generic ROOT::Math::PositionVector3D */ template - Plane3D( const DisplacementVector3D & n, const PositionVector3D & p) + Plane3D( const DisplacementVector3D & n, const PositionVector3D & p ) { BuildFromVecAndPoint( Vector(n), Point(p) ); } @@ -232,7 +234,10 @@ namespace Impl { Exact equality */ bool operator==(const Plane3D & rhs) const { - return fA == rhs.fA && fB == rhs.fB && fC == rhs.fC && fD == rhs.fD; + return ( fA == rhs.fA && + fB == rhs.fB && + fC == rhs.fC && + fD == rhs.fD ); } bool operator!= (const Plane3D & rhs) const { return !(operator==(rhs)); @@ -243,15 +248,39 @@ namespace Impl { /** Normalize the normal (a,b,c) plane components */ - void Normalize() + template< typename SCALAR = T > + typename std::enable_if< std::is_arithmetic::value, void >::type + Normalize() + { + // normalize the plane + const SCALAR s = std::sqrt( fA*fA + fB*fB + fC*fC ); + // what to do if s = 0 ? + if ( s == 0 ) { fD = 0; } + else + { + const SCALAR w = Scalar(1)/s; + fA *= w; + fB *= w; + fC *= w; + fD *= w; + } + } + + /** + Normalize the normal (a,b,c) plane components + */ + template< typename SCALAR = T > + typename std::enable_if< !std::is_arithmetic::value, void >::type + Normalize() { - using namespace std; // normalize the plane - const Scalar s = sqrt( fA*fA + fB*fB + fC*fC ); - // what to do if s = 0 ?? - // CRJ - This does not work with Vc types... ToDo decide how to handle... - //if ( s == 0 ) { fD = 0; return; } - const Scalar w = Scalar(1)/s; + SCALAR s = sqrt( fA*fA + fB*fB + fC*fC ); + // what to do if s = 0 ? + const auto m = ( s == SCALAR(0) ); + // set zero entries to 1 in the vector to avoid /0 later on + s(m) = SCALAR(1); + fD(m) = SCALAR(0); + const SCALAR w = SCALAR(1)/s; fA *= w; fB *= w; fC *= w; From 196a00bb00748ddd68f27077fac994827a31350e Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 27 Feb 2017 22:38:10 +0100 Subject: [PATCH 15/44] Roll back some changes for now, as they are causing problems in the tests. Start with a limited scope and just update Plane3D, Translation3D and Transformation3D --- math/genvector/inc/Math/GenVector/Boost.h | 244 ++++-------------- math/genvector/inc/Math/GenVector/BoostX.h | 144 +++-------- math/genvector/inc/Math/GenVector/BoostXfwd.h | 2 +- math/genvector/inc/Math/GenVector/BoostY.h | 139 +++------- math/genvector/inc/Math/GenVector/BoostZ.h | 137 +++------- math/genvector/inc/Math/GenVector/Boostfwd.h | 4 +- math/genvector/inc/Math/GenVector/Polar2D.h | 7 +- .../inc/Math/GenVector/PtEtaPhiE4D.h | 44 ++-- math/genvector/inc/Math/GenVector/PxPyPzE4D.h | 23 +- .../inc/Math/GenVector/Transform3D.h | 45 ++-- .../inc/Math/GenVector/Translation3D.h | 40 +-- math/genvector/src/Boost.cxx | 186 +++++++++++++ math/genvector/src/BoostX.cxx | 114 ++++++++ math/genvector/src/BoostY.cxx | 113 ++++++++ math/genvector/src/BoostZ.cxx | 114 ++++++++ 15 files changed, 792 insertions(+), 564 deletions(-) create mode 100644 math/genvector/src/Boost.cxx create mode 100644 math/genvector/src/BoostX.cxx create mode 100644 math/genvector/src/BoostY.cxx create mode 100644 math/genvector/src/BoostZ.cxx diff --git a/math/genvector/inc/Math/GenVector/Boost.h b/math/genvector/inc/Math/GenVector/Boost.h index 4fd9ee763a8af..87efc3d52db79 100644 --- a/math/genvector/inc/Math/GenVector/Boost.h +++ b/math/genvector/inc/Math/GenVector/Boost.h @@ -26,46 +26,9 @@ #include "Math/GenVector/BoostY.h" #include "Math/GenVector/BoostZ.h" -//#ifdef TEX -/** - - A variable names bgamma appears in several places in this file. A few - words of elaboration are needed to make its meaning clear. On page 69 - of Misner, Thorne and Wheeler, (Exercise 2.7) the elements of the matrix - for a general Lorentz boost are given as - - \f[ \Lambda^{j'}_k = \Lambda^{k'}_j - = (\gamma - 1) n^j n^k + \delta^{jk} \f] - - where the n^i are unit vectors in the direction of the three spatial - axes. Using the definitions, \f$ n^i = \beta_i/\beta \f$ , then, for example, - - \f[ \Lambda_{xy} = (\gamma - 1) n_x n_y - = (\gamma - 1) \beta_x \beta_y/\beta^2 \f] - - By definition, \f[ \gamma^2 = 1/(1 - \beta^2) \f] - - so that \f[ \gamma^2 \beta^2 = \gamma^2 - 1 \f] - - or \f[ \beta^2 = (\gamma^2 - 1)/\gamma^2 \f] - - If we insert this into the expression for \f$ \Lambda_{xy} \f$, we get - - \f[ \Lambda_{xy} = (\gamma - 1) \gamma^2/(\gamma^2 - 1) \beta_x \beta_y \f] - - or, finally - - \f[ \Lambda_{xy} = \gamma^2/(\gamma+1) \beta_x \beta_y \f] - - The expression \f$ \gamma^2/(\gamma+1) \f$ is what we call bgamma in the code below. - - \class ROOT::Math::Boost -*/ -//#endif - namespace ROOT { -namespace Math { -namespace Impl { + + namespace Math { //__________________________________________________________________________________________ /** @@ -77,14 +40,14 @@ namespace Impl { transformations which do not mix space and time components. @ingroup GenVector + */ -template < typename T > class Boost { public: - typedef T Scalar; + typedef double Scalar; enum ELorentzRotationMatrixIndex { kLXX = 0, kLXY = 1, kLXZ = 2, kLXT = 3 @@ -98,7 +61,6 @@ class Boost { , kYY = 4, kYZ = 5, kYT = 6 , kZZ = 7, kZT = 8 , kTT = 9 - , kNElems = 10 }; // ========== Constructors and Assignment ===================== @@ -112,7 +74,7 @@ class Boost { Construct given a three Scalars beta_x, beta_y, and beta_z */ Boost(Scalar beta_x, Scalar beta_y, Scalar beta_z) - { SetComponents(beta_x, beta_y, beta_z); } + { SetComponents(beta_x, beta_y, beta_z); } /** Construct given a beta vector (which must have methods x(), y(), z()) @@ -131,7 +93,7 @@ class Boost { /** copy constructor */ - Boost( Boost const & b) { + Boost(Boost const & b) { *this = b; } @@ -139,18 +101,18 @@ class Boost { Construct from an axial boost */ - explicit Boost( BoostX const & bx ) {SetComponents(bx.BetaVector());} - explicit Boost( BoostY const & by ) {SetComponents(by.BetaVector());} - explicit Boost( BoostZ const & bz ) {SetComponents(bz.BetaVector());} + explicit Boost( BoostX const & bx ) {SetComponents(bx.BetaVector());} + explicit Boost( BoostY const & by ) {SetComponents(by.BetaVector());} + explicit Boost( BoostZ const & bz ) {SetComponents(bz.BetaVector());} // The compiler-generated copy ctor, copy assignment, and dtor are OK. /** Assignment operator */ - Boost & - operator=(Boost const & rhs ) { - for (unsigned int i=0; i < kNElems; ++i) { + Boost & + operator=(Boost const & rhs ) { + for (unsigned int i=0; i < 10; ++i) { fM[i] = rhs.fM[i]; } return *this; @@ -159,36 +121,18 @@ class Boost { /** Assign from an axial pure boost */ - Boost & - operator=( BoostX const & bx ) { return operator=(Boost(bx)); } - Boost & - operator=( BoostY const & by ) { return operator=(Boost(by)); } - Boost & - operator=( BoostZ const & bz ) { return operator=(Boost(bz)); } + Boost & + operator=( BoostX const & bx ) { return operator=(Boost(bx)); } + Boost & + operator=( BoostY const & by ) { return operator=(Boost(by)); } + Boost & + operator=( BoostZ const & bz ) { return operator=(Boost(bz)); } /** Re-adjust components to eliminate small deviations from a perfect orthosyplectic matrix. */ - void Rectify() { - // Assuming the representation of this is close to a true Lorentz Rotation, - // but may have drifted due to round-off error from many operations, - // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation - // again. - - if ( fM[kTT] <= Scalar(0) ) { - GenVector::Throw("Attempt to rectify a boost with non-positive gamma"); - } - else - { - DisplacementVector3D< Cartesian3D > beta ( fM[kXT], fM[kYT], fM[kZT] ); - beta /= fM[kTT]; - if ( beta.mag2() >= Scalar(1) ) { - beta /= ( beta.R() * Scalar( 1.0 + 1.0e-16 ) ); - } - SetComponents ( beta ); - } - } + void Rectify(); // ======== Components ============== @@ -196,42 +140,13 @@ class Boost { Set components from beta_x, beta_y, and beta_z */ void - SetComponents (Scalar bx, Scalar by, Scalar bz) { - using namespace std; - // set the boost beta as 3 components - const Scalar bp2 = bx*bx + by*by + bz*bz; - if ( bp2 >= Scalar(1) ) { - GenVector::Throw("Beta Vector supplied to set Boost represents speed >= c"); - // SetIdentity(); - } - else - { - const Scalar gamma = Scalar(1) / sqrt( Scalar(1) - bp2 ); - const Scalar bgamma = gamma * gamma / ( Scalar(1) + gamma ); - fM[kXX] = Scalar(1) + bgamma * bx * bx; - fM[kYY] = Scalar(1) + bgamma * by * by; - fM[kZZ] = Scalar(1) + bgamma * bz * bz; - fM[kXY] = bgamma * bx * by; - fM[kXZ] = bgamma * bx * bz; - fM[kYZ] = bgamma * by * bz; - fM[kXT] = gamma * bx; - fM[kYT] = gamma * by; - fM[kZT] = gamma * bz; - fM[kTT] = gamma; - } - } + SetComponents (Scalar beta_x, Scalar beta_y, Scalar beta_z); /** Get components into beta_x, beta_y, and beta_z */ void - GetComponents (Scalar& bx, Scalar& by, Scalar& bz) const { - // get beta of the boots as 3 components - const Scalar gaminv = Scalar(1)/fM[kTT]; - bx = fM[kXT]*gaminv; - by = fM[kYT]*gaminv; - bz = fM[kZT]*gaminv; - } + GetComponents (Scalar& beta_x, Scalar& beta_y, Scalar& beta_z) const; /** Set components from a beta vector @@ -277,23 +192,18 @@ class Boost { */ template void GetComponents(IT begin ) const { - T bx(0), by(0), bz(0); - GetComponents (bx,by,bz); - *begin++ = bx; - *begin++ = by; - *begin = bz; + double bx,by,bz = 0; + GetComponents (bx,by,bz); + *begin++ = bx; + *begin++ = by; + *begin = bz; } /** The beta vector for this boost */ - typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; - XYZVector BetaVector() const { - // get boost beta vector - const Scalar gaminv = Scalar(1)/fM[kTT]; - return DisplacementVector3D< Cartesian3D > - ( fM[kXT]*gaminv, fM[kYT]*gaminv, fM[kZT]*gaminv ); - } + typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; + XYZVector BetaVector() const; /** Get elements of internal 4x4 symmetric representation, into a data @@ -302,13 +212,7 @@ class Boost { that large, then this will lead to undefined behavior. */ void - GetLorentzRotation (Scalar r[]) const { - // get Lorentz rotation corresponding to this boost as an array of 16 values - r[kLXX] = fM[kXX]; r[kLXY] = fM[kXY]; r[kLXZ] = fM[kXZ]; r[kLXT] = fM[kXT]; - r[kLYX] = fM[kXY]; r[kLYY] = fM[kYY]; r[kLYZ] = fM[kYZ]; r[kLYT] = fM[kYT]; - r[kLZX] = fM[kXZ]; r[kLZY] = fM[kYZ]; r[kLZZ] = fM[kZZ]; r[kLZT] = fM[kZT]; - r[kLTX] = fM[kXT]; r[kLTY] = fM[kYT]; r[kLTZ] = fM[kZT]; r[kLTT] = fM[kTT]; - } + GetLorentzRotation (Scalar r[]) const; // =========== operations ============== @@ -316,19 +220,8 @@ class Boost { Lorentz transformation operation on a Minkowski ('Cartesian') LorentzVector */ - LorentzVector< ROOT::Math::PxPyPzE4D > - operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const { - // apply boost to a PxPyPzE LorentzVector - const Scalar x = v.Px(); - const Scalar y = v.Py(); - const Scalar z = v.Pz(); - const Scalar t = v.E(); - return LorentzVector< PxPyPzE4D > - ( fM[kXX]*x + fM[kXY]*y + fM[kXZ]*z + fM[kXT]*t - , fM[kXY]*x + fM[kYY]*y + fM[kYZ]*z + fM[kYT]*t - , fM[kXZ]*x + fM[kYZ]*y + fM[kZZ]*z + fM[kZT]*t - , fM[kXT]*x + fM[kYT]*y + fM[kZT]*z + fM[kTT]*t ); - } + LorentzVector< ROOT::Math::PxPyPzE4D > + operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const; /** Lorentz transformation operation on a LorentzVector in any @@ -337,8 +230,8 @@ class Boost { template LorentzVector operator() (const LorentzVector & v) const { - const LorentzVector< PxPyPzE4D > xyzt(v); - const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return LorentzVector ( r_xyzt ); } @@ -350,8 +243,8 @@ class Boost { template Foreign4Vector operator() (const Foreign4Vector & v) const { - const LorentzVector< PxPyPzE4D > xyzt(v); - const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() ); } @@ -368,51 +261,33 @@ class Boost { /** Invert a Boost in place */ - void Invert() { - // invert in place boost (modifying the object) - fM[kXT] = -fM[kXT]; - fM[kYT] = -fM[kYT]; - fM[kZT] = -fM[kZT]; - } - + void Invert(); + /** Return inverse of a boost */ - Boost Inverse() const { - // return inverse of boost - Boost tmp(*this); - tmp.Invert(); - return tmp; - } + Boost Inverse() const; /** Equality/inequality operators */ - bool operator == (const Boost & rhs) const { - bool OK = true; - for (unsigned int i=0; i < kNElems; ++i) { - if ( fM[i] != rhs.fM[i] ) { OK = false; break; } + bool operator == (const Boost & rhs) const { + for (unsigned int i=0; i < 10; ++i) { + if( fM[i] != rhs.fM[i] ) return false; } - return OK; + return true; } - bool operator != (const Boost & rhs) const { return ! operator==(rhs); } protected: - void SetIdentity() { - // set identity boost - fM[kXX] = Scalar(1); fM[kXY] = Scalar(0); fM[kXZ] = Scalar(0); fM[kXT] = Scalar(0); - fM[kYY] = Scalar(1); fM[kYZ] = Scalar(0); fM[kYT] = Scalar(0); - fM[kZZ] = Scalar(1); fM[kZT] = Scalar(0); - fM[kTT] = Scalar(1); - } + void SetIdentity(); private: - Scalar fM[kNElems]; + Scalar fM[10]; }; // Boost @@ -423,25 +298,16 @@ class Boost { */ // TODO - I/O should be put in the manipulator form -template< typename T > -std::ostream & operator<< (std::ostream & os, const Boost & b ) { - // TODO - this will need changing for machine-readable issues - // and even the human readable form needs formatiing improvements - T m[16]; - b.GetLorentzRotation(m); - os << "\n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3]; - os << "\n" << "\t" << " " << m[5] << " " << m[6] << " " << m[7]; - os << "\n" << "\t" << " " << "\t" << " " << m[10] << " " << m[11]; - os << "\n" << "\t" << " " << "\t" << " " << "\t" << " " << m[15] << "\n"; - return os; -} - -} // namespace Impl - -typedef Impl::Boost Boost; -typedef Impl::Boost BoostF; - -} // namespace Math -} // namespace ROOT +std::ostream & operator<< (std::ostream & os, const Boost & b); + + +} //namespace Math +} //namespace ROOT + + + + + + #endif /* ROOT_Math_GenVector_Boost */ diff --git a/math/genvector/inc/Math/GenVector/BoostX.h b/math/genvector/inc/Math/GenVector/BoostX.h index 83983e46e44d6..cfed6a775acd3 100644 --- a/math/genvector/inc/Math/GenVector/BoostX.h +++ b/math/genvector/inc/Math/GenVector/BoostX.h @@ -23,8 +23,8 @@ #include "Math/GenVector/Cartesian3D.h" namespace ROOT { + namespace Math { -namespace Impl { //__________________________________________________________________________________________ /** @@ -34,12 +34,11 @@ namespace Impl { @ingroup GenVector */ -template< typename T = double> class BoostX { public: - typedef T Scalar; + typedef double Scalar; enum ELorentzRotationMatrixIndex { kLXX = 0, kLXY = 1, kLXZ = 2, kLXT = 3 @@ -50,10 +49,9 @@ class BoostX { enum EBoostMatrixIndex { kXX = 0, kXY = 1, kXZ = 2, kXT = 3 - , kYY = 4, kYZ = 5, kYT = 6 - , kZZ = 7, kZT = 8 - , kTT = 9 - , kNElems = 10 + , kYY = 4, kYZ = 5, kYT = 6 + , kZZ = 7, kZT = 8 + , kTT = 9 }; // ========== Constructors and Assignment ===================== @@ -61,7 +59,7 @@ class BoostX { /** Default constructor (identity transformation) */ - BoostX() : fBeta(0), fGamma(1) {} + BoostX(); /** Construct given a Scalar beta_x @@ -75,25 +73,7 @@ class BoostX { Re-adjust components to eliminate small deviations from a perfect orthosyplectic matrix. */ - void Rectify() { - // Assuming the representation of this is close to a true Lorentz Rotation, - // but may have drifted due to round-off error from many operations, - // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation - // again. - - if ( fGamma <= Scalar(0) ) { - GenVector::Throw("Attempt to rectify a boost with non-positive gamma"); - } - else - { - Scalar beta = fBeta; - if ( beta >= Scalar(1) ) { - // WTF wrt 1e-16 ... - beta /= ( beta * ( Scalar(1) + Scalar(1.0e-16) ) ); - } - SetComponents ( beta ); - } - } + void Rectify(); // ======== Components ============== @@ -101,28 +81,15 @@ class BoostX { Set components from a Scalar beta_x */ void - SetComponents (Scalar bx) { - using namespace std; - // set component - const Scalar bp2 = bx*bx; - if ( bp2 >= Scalar(1) ) { - GenVector::Throw("Beta Vector supplied to set BoostX represents speed >= c"); - } - else - { - fBeta = bx; - fGamma = Scalar(1) / sqrt( Scalar(1) - bp2 ); - } - } - + SetComponents (Scalar beta_x); + /** Get components into a Scalar beta_x */ - void GetComponents (Scalar& bx) const { - // get component - bx = fBeta; - } - + void + GetComponents (Scalar& beta_x) const; + + /** Retrieve the beta of the Boost */ @@ -136,16 +103,13 @@ class BoostX { /** Set the given beta of the Boost */ - void SetBeta(Scalar beta) { SetComponents(beta); } + void SetBeta(Scalar beta) { SetComponents(beta); } /** The beta vector for this boost */ - typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; - XYZVector BetaVector() const { - // return beta vector - return DisplacementVector3D< Cartesian3D > ( fBeta, Scalar(0), Scalar(0) ); - } + typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; + XYZVector BetaVector() const; /** Get elements of internal 4x4 symmetric representation, into a data @@ -153,13 +117,8 @@ class BoostX { Note -- 16 Scalars will be written into the array; if the array is not that large, then this will lead to undefined behavior. */ - void GetLorentzRotation (Scalar r[]) const { - // get corresponding LorentzRotation - r[kLXX] = fGamma; r[kLXY] = Scalar(0); r[kLXZ] = Scalar(0); r[kLXT] = fGamma*fBeta; - r[kLYX] = Scalar(0); r[kLYY] = Scalar(1); r[kLYZ] = Scalar(0); r[kLYT] = Scalar(0); - r[kLZX] = Scalar(0); r[kLZY] = Scalar(0); r[kLZZ] = Scalar(1); r[kLZT] = Scalar(0); - r[kLTX] = fGamma*fBeta; r[kLTY] = Scalar(0); r[kLTZ] = Scalar(0); r[kLTT] = fGamma; - } + void + GetLorentzRotation (Scalar r[]) const; // =========== operations ============== @@ -167,18 +126,8 @@ class BoostX { Lorentz transformation operation on a Minkowski ('Cartesian') LorentzVector */ - LorentzVector< ROOT::Math::PxPyPzE4D > - operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const { - // apply boost to a LV - const Scalar x = v.Px(); - const Scalar t = v.E(); - return LorentzVector< PxPyPzE4D > - ( fGamma*x + fGamma*fBeta*t - , v.Py() - , v.Pz() - , fGamma*fBeta*x + fGamma*t ); - } - + LorentzVector< ROOT::Math::PxPyPzE4D > + operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const; /** Lorentz transformation operation on a LorentzVector in any @@ -187,8 +136,8 @@ class BoostX { template LorentzVector operator() (const LorentzVector & v) const { - const LorentzVector< PxPyPzE4D > xyzt(v); - const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return LorentzVector ( r_xyzt ); } @@ -200,8 +149,8 @@ class BoostX { template Foreign4Vector operator() (const Foreign4Vector & v) const { - const LorentzVector< PxPyPzE4D > xyzt(v); - const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() ); } @@ -209,38 +158,32 @@ class BoostX { Overload operator * for operation on a vector */ template - inline A4Vector operator* (const A4Vector & v) const + inline + A4Vector operator* (const A4Vector & v) const { - return operator()(v); + return operator()(v); } /** Invert a BoostX in place */ - void Invert() { - // invert - fBeta = -fBeta; - } - + void Invert(); + /** Return inverse of a boost */ - BoostX Inverse() const { - // return an inverse boostX - BoostX tmp(*this); - tmp.Invert(); - return tmp; - } + BoostX Inverse() const; /** Equality/inequality operators */ - bool operator == (const BoostX & rhs) const { - return ( fBeta == rhs.fBeta && - fGamma == rhs.fGamma ); + bool operator == (const BoostX & rhs) const { + if( fBeta != rhs.fBeta ) return false; + if( fGamma != rhs.fGamma ) return false; + return true; } - bool operator != (const BoostX & rhs) const { + bool operator != (const BoostX & rhs) const { return ! operator==(rhs); } @@ -258,18 +201,17 @@ class BoostX { Stream Output and Input */ // TODO - I/O should be put in the manipulator form -template< typename T> -std::ostream & operator<< (std::ostream & os, const BoostX & b) { - os << " BoostX( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; - return os; -} -} //namepsace Impl +std::ostream & operator<< (std::ostream & os, const BoostX & b); + -typedef Impl::BoostX BoostX; -typedef Impl::BoostX BoostXF; - } //namespace Math } //namespace ROOT + + + + + + #endif /* ROOT_Math_GenVector_BoostX */ diff --git a/math/genvector/inc/Math/GenVector/BoostXfwd.h b/math/genvector/inc/Math/GenVector/BoostXfwd.h index 3800712629cb2..34b92bc4af279 100644 --- a/math/genvector/inc/Math/GenVector/BoostXfwd.h +++ b/math/genvector/inc/Math/GenVector/BoostXfwd.h @@ -13,7 +13,7 @@ namespace ROOT { Class describing a pure Lorentz Boost along the X axis */ - class BoostX; +class BoostX; } // namespace Math } // namespace ROOT diff --git a/math/genvector/inc/Math/GenVector/BoostY.h b/math/genvector/inc/Math/GenVector/BoostY.h index dc3fc9286ae7b..5aa6a9698fd8b 100644 --- a/math/genvector/inc/Math/GenVector/BoostY.h +++ b/math/genvector/inc/Math/GenVector/BoostY.h @@ -23,9 +23,9 @@ #include "Math/GenVector/Cartesian3D.h" namespace ROOT { + namespace Math { -namespace Impl { - + //__________________________________________________________________________________________ /** Class representing a Lorentz Boost along the Y axis, by beta. @@ -34,12 +34,11 @@ namespace Impl { @ingroup GenVector */ -template< typename T = double> class BoostY { public: - typedef T Scalar; + typedef double Scalar; enum ELorentzRotationMatrixIndex { kLXX = 0, kLXY = 1, kLXZ = 2, kLXT = 3 @@ -50,10 +49,9 @@ class BoostY { enum EBoostMatrixIndex { kXX = 0, kXY = 1, kXZ = 2, kXT = 3 - , kYY = 4, kYZ = 5, kYT = 6 - , kZZ = 7, kZT = 8 - , kTT = 9 - , kNElems = 10 + , kYY = 4, kYZ = 5, kYT = 6 + , kZZ = 7, kZT = 8 + , kTT = 9 }; // ========== Constructors and Assignment ===================== @@ -61,65 +59,37 @@ class BoostY { /** Default constructor (identity transformation) */ - BoostY() : fBeta(0), fGamma(1) {} + BoostY(); /** Construct given a Scalar beta_y */ explicit BoostY(Scalar beta_y) { SetComponents(beta_y); } + // The compiler-generated copy ctor, copy assignment, and dtor are OK. /** Re-adjust components to eliminate small deviations from a perfect orthosyplectic matrix. */ - void Rectify() { - // Assuming the representation of this is close to a true Lorentz Rotation, - // but may have drifted due to round-off error from many operations, - // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation - // again. - - if ( fGamma <= Scalar(0) ) { - GenVector::Throw("Attempt to rectify a boost with non-positive gamma"); - } - else - { - Scalar beta = fBeta; - if ( beta >= Scalar(1) ) { - beta /= ( beta * ( Scalar( 1.0 + 1.0e-16 ) ) ); - } - SetComponents ( beta ); - } - } + void Rectify(); // ======== Components ============== /** Set components from a Scalar beta_y */ - void SetComponents (Scalar by) { - using namespace std; - // set component - const Scalar bp2 = by*by; - if ( bp2 >= Scalar(1) ) { - GenVector::Throw("Beta Vector supplied to set BoostY represents speed >= c"); - } - else - { - fBeta = by; - fGamma = Scalar(1) / sqrt( Scalar(1) -bp2 ); - } - } + void + SetComponents (Scalar beta_y); /** Get components into a Scalar beta_y */ - void GetComponents (Scalar& by) const { - // get component - by = fBeta; - } - + void + GetComponents (Scalar& beta_y) const; + + /** Retrieve the beta of the Boost */ @@ -133,30 +103,22 @@ class BoostY { /** Set the given beta of the Boost */ - void SetBeta(Scalar beta) { SetComponents(beta); } + void SetBeta(Scalar beta) { SetComponents(beta); } /** The beta vector for this boost */ - typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; - XYZVector BetaVector() const { - // return beta vector - return DisplacementVector3D< Cartesian3D > ( Scalar(0), fBeta, Scalar(0) ); - } - + typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; + XYZVector BetaVector() const; + /** Get elements of internal 4x4 symmetric representation, into a data array suitable for direct use as the components of a LorentzRotation Note -- 16 Scalars will be written into the array; if the array is not that large, then this will lead to undefined behavior. */ - void GetLorentzRotation (Scalar r[]) const { - // get corresponding LorentzRotation - r[kLXX] = Scalar(1); r[kLXY] = Scalar(0); r[kLXZ] = Scalar(0); r[kLXT] = Scalar(0); - r[kLYX] = Scalar(0); r[kLYY] = fGamma; r[kLYZ] = Scalar(0); r[kLYT] = fGamma*fBeta; - r[kLZX] = Scalar(0); r[kLZY] = Scalar(0); r[kLZZ] = Scalar(1); r[kLZT] = Scalar(0); - r[kLTX] = Scalar(0); r[kLTY] = fGamma*fBeta; r[kLTZ] = Scalar(0); r[kLTT] = fGamma; - } + void + GetLorentzRotation (Scalar r[]) const; // =========== operations ============== @@ -164,17 +126,8 @@ class BoostY { Lorentz transformation operation on a Minkowski ('Cartesian') LorentzVector */ - LorentzVector< ROOT::Math::PxPyPzE4D > - operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const { - // apply boost to a LV - const Scalar y = v.Py(); - const Scalar t = v.E(); - return LorentzVector< PxPyPzE4D > - ( v.Px() - , fGamma*y + fGamma*fBeta*t - , v.Pz() - , fGamma*fBeta*y + fGamma*t ); - } + LorentzVector< ROOT::Math::PxPyPzE4D > + operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const; /** Lorentz transformation operation on a LorentzVector in any @@ -183,8 +136,8 @@ class BoostY { template LorentzVector operator() (const LorentzVector & v) const { - const LorentzVector< PxPyPzE4D > xyzt(v); - const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return LorentzVector ( r_xyzt ); } @@ -196,8 +149,8 @@ class BoostY { template Foreign4Vector operator() (const Foreign4Vector & v) const { - const LorentzVector< PxPyPzE4D > xyzt(v); - const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() ); } @@ -214,29 +167,22 @@ class BoostY { /** Invert a BoostY in place */ - void Invert() { - // invert Boost - fBeta = -fBeta; - } + void Invert(); /** Return inverse of a rotation */ - BoostY Inverse() const { - // return inverse - BoostY tmp(*this); - tmp.Invert(); - return tmp; - } + BoostY Inverse() const; /** Equality/inequality operators */ - bool operator == (const BoostY & rhs) const { - return ( fBeta == rhs.fBeta && - fGamma == rhs.fGamma ); + bool operator == (const BoostY & rhs) const { + if( fBeta != rhs.fBeta ) return false; + if( fGamma != rhs.fGamma ) return false; + return true; } - bool operator != (const BoostY & rhs) const { + bool operator != (const BoostY & rhs) const { return ! operator==(rhs); } @@ -253,18 +199,17 @@ class BoostY { Stream Output and Input */ // TODO - I/O should be put in the manipulator form -template< typename T> -std::ostream & operator<< (std::ostream & os, const BoostY & b) { - os << " BoostY( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; - return os; -} - -} //namepsace Impl -typedef Impl::BoostY BoostY; -typedef Impl::BoostY BoostYF; + std::ostream & operator<< (std::ostream & os, const BoostY & b); + } //namespace Math } //namespace ROOT + + + + + + #endif /* ROOT_Math_GenVector_BoostY */ diff --git a/math/genvector/inc/Math/GenVector/BoostZ.h b/math/genvector/inc/Math/GenVector/BoostZ.h index 9e7f5f472aa19..fd5508e47d318 100644 --- a/math/genvector/inc/Math/GenVector/BoostZ.h +++ b/math/genvector/inc/Math/GenVector/BoostZ.h @@ -23,8 +23,8 @@ #include "Math/GenVector/Cartesian3D.h" namespace ROOT { -namespace Math { -namespace Impl { + + namespace Math { //__________________________________________________________________________________________ /** @@ -34,12 +34,11 @@ namespace Impl { @ingroup GenVector */ -template class BoostZ { public: - typedef T Scalar; + typedef double Scalar; enum ELorentzRotationMatrixIndex { kLXX = 0, kLXY = 1, kLXZ = 2, kLXT = 3 @@ -50,10 +49,9 @@ class BoostZ { enum EBoostMatrixIndex { kXX = 0, kXY = 1, kXZ = 2, kXT = 3 - , kYY = 4, kYZ = 5, kYT = 6 - , kZZ = 7, kZT = 8 - , kTT = 9 - , kNElems = 10 + , kYY = 4, kYZ = 5, kYT = 6 + , kZZ = 7, kZT = 8 + , kTT = 9 }; // ========== Constructors and Assignment ===================== @@ -61,65 +59,36 @@ class BoostZ { /** Default constructor (identity transformation) */ - BoostZ() : fBeta(0), fGamma(1) {} + BoostZ(); /** Construct given a Scalar beta_z */ explicit BoostZ(Scalar beta_z) { SetComponents(beta_z); } + // The compiler-generated copy ctor, copy assignment, and dtor are OK. /** Re-adjust components to eliminate small deviations from a perfect orthosyplectic matrix. */ - void Rectify() { - // Assuming the representation of this is close to a true Lorentz Rotation, - // but may have drifted due to round-off error from many operations, - // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation - // again. - - if ( fGamma <= Scalar(0) ) { - GenVector::Throw("Attempt to rectify a boost with non-positive gamma"); - } - else - { - Scalar beta = fBeta; - if ( beta >= Scalar(1) ) { - beta /= ( beta * ( Scalar( 1.0 + 1.0e-16 ) ) ); - } - SetComponents ( beta ); - } - } + void Rectify(); // ======== Components ============== /** Set components from a Scalar beta_z */ - void SetComponents (Scalar bz) { - using namespace std; - // set component - const Scalar bp2 = bz*bz; - if ( bp2 >= Scalar(1) ) - { - GenVector::Throw("Beta Vector supplied to set BoostZ represents speed >= c"); - } - else - { - fBeta = bz; - fGamma = Scalar(1) / sqrt( Scalar(1) - bp2 ); - } - } + void + SetComponents (Scalar beta_z); /** Get components into a Scalar beta_z */ - void GetComponents (Scalar& bz) const { - // get component - bz = fBeta; - } + void + GetComponents (Scalar& beta_z) const; + /** Retrieve the beta of the Boost @@ -139,11 +108,8 @@ class BoostZ { /** The beta vector for this boost */ - typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; - XYZVector BetaVector() const { - // return beta vector - return DisplacementVector3D< Cartesian3D >( Scalar(0), Scalar(0), fBeta ); - } + typedef DisplacementVector3D, DefaultCoordinateSystemTag > XYZVector; + XYZVector BetaVector() const; /** Get elements of internal 4x4 symmetric representation, into a data @@ -151,30 +117,17 @@ class BoostZ { Note -- 16 Scalars will be written into the array; if the array is not that large, then this will lead to undefined behavior. */ - void GetLorentzRotation (Scalar r[]) const { - // get corresponding LorentzRotation - r[kLXX] = Scalar(1); r[kLXY] = Scalar(0); r[kLXZ] = Scalar(0); r[kLXT] = Scalar(0) ; - r[kLYX] = Scalar(0); r[kLYY] = Scalar(1); r[kLYZ] = Scalar(0); r[kLYT] = Scalar(0) ; - r[kLZX] = Scalar(0); r[kLZY] = Scalar(0); r[kLZZ] = fGamma; r[kLZT] = fGamma*fBeta; - r[kLTX] = Scalar(0); r[kLTY] = Scalar(0); r[kLTZ] = fGamma*fBeta; r[kLTT] = fGamma; - } - + void + GetLorentzRotation (Scalar r[]) const; + // =========== operations ============== /** Lorentz transformation operation on a Minkowski ('Cartesian') LorentzVector */ - LorentzVector< ROOT::Math::PxPyPzE4D > - operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const { - // apply boost to a LV - const Scalar z = v.Pz(); - const Scalar t = v.E(); - return LorentzVector< PxPyPzE4D > ( v.Px() - , v.Py() - , fGamma*z + fGamma*fBeta*t - , fGamma*fBeta*z + fGamma*t ); - } + LorentzVector< ROOT::Math::PxPyPzE4D > + operator() (const LorentzVector< ROOT::Math::PxPyPzE4D > & v) const; /** Lorentz transformation operation on a LorentzVector in any @@ -183,8 +136,8 @@ class BoostZ { template LorentzVector operator() (const LorentzVector & v) const { - const LorentzVector< PxPyPzE4D > xyzt(v); - const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return LorentzVector ( r_xyzt ); } @@ -196,8 +149,8 @@ class BoostZ { template Foreign4Vector operator() (const Foreign4Vector & v) const { - const LorentzVector< PxPyPzE4D > xyzt(v); - const LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); + LorentzVector< PxPyPzE4D > xyzt(v); + LorentzVector< PxPyPzE4D > r_xyzt = operator()(xyzt); return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() ); } @@ -214,29 +167,22 @@ class BoostZ { /** Invert a BoostZ in place */ - void Invert() { - // invert - fBeta = -fBeta; - } + void Invert(); /** Return inverse of a BoostZ */ - BoostZ Inverse() const { - // return an inverse boostZ - BoostZ tmp(*this); - tmp.Invert(); - return tmp; - } - + BoostZ Inverse() const; + /** Equality/inequality operators */ - bool operator == (const BoostZ & rhs) const { - return ( fBeta == rhs.fBeta && - fGamma == rhs.fGamma ); + bool operator == (const BoostZ & rhs) const { + if( fBeta != rhs.fBeta ) return false; + if( fGamma != rhs.fGamma ) return false; + return true; } - bool operator != (const BoostZ & rhs) const { + bool operator != (const BoostZ & rhs) const { return ! operator==(rhs); } @@ -253,18 +199,17 @@ class BoostZ { Stream Output and Input */ // TODO - I/O should be put in the manipulator form -template< typename T> -std::ostream & operator<< (std::ostream & os, const BoostZ & b) { - os << " BoostZ( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; - return os; -} -} //namespace Impl +std::ostream & operator<< (std::ostream & os, const BoostZ & b); + -typedef Impl::BoostZ BoostZ; -typedef Impl::BoostZ BoostZF; - } //namespace Math } //namespace ROOT + + + + + + #endif /* ROOT_Math_GenVector_BoostZ */ diff --git a/math/genvector/inc/Math/GenVector/Boostfwd.h b/math/genvector/inc/Math/GenVector/Boostfwd.h index 1233a2a7130e6..acf0f5b1583b6 100644 --- a/math/genvector/inc/Math/GenVector/Boostfwd.h +++ b/math/genvector/inc/Math/GenVector/Boostfwd.h @@ -13,8 +13,8 @@ namespace ROOT { Class describing a pure boost in some direction */ - class Boost; - +class Boost; + } // namespace Math } // namespace ROOT diff --git a/math/genvector/inc/Math/GenVector/Polar2D.h b/math/genvector/inc/Math/GenVector/Polar2D.h index f27ef7e3959b3..895778d3a55ab 100644 --- a/math/genvector/inc/Math/GenVector/Polar2D.h +++ b/math/genvector/inc/Math/GenVector/Polar2D.h @@ -97,8 +97,8 @@ public : Scalar R() const { return fR;} Scalar Phi() const { return fPhi; } - Scalar X() const { using namespace std; return fR*cos(fPhi);} - Scalar Y() const { using namespace std; return fR*sin(fPhi);} + Scalar X() const { return fR*std::cos(fPhi);} + Scalar Y() const { return fR*std::sin(fPhi);} Scalar Mag2() const { return fR*fR;} @@ -134,9 +134,8 @@ public : restrict abgle hi to be between -PI and PI */ inline void Restrict() { - using namespace std; if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi(); return; } diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h index 8223e66c4947d..539e6ecca22fe 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h @@ -137,16 +137,15 @@ public : // other coordinate representation - Scalar Px() const { using namespace std; return cos(fPhi);} + Scalar Px() const { return fPt*cos(fPhi);} Scalar X () const { return Px(); } - Scalar Py() const { using namespace std; return sin(fPhi);} + Scalar Py() const { return fPt*sin(fPhi);} Scalar Y () const { return Py(); } Scalar Pz() const { - using namespace std; - return ( fPt > 0 ? fPt*sinh(fEta) : - fEta == 0 ? 0 : - fEta > 0 ? fEta - etaMax() : - fEta + etaMax() ); + return fPt > 0 ? fPt*std::sinh(fEta) : + fEta == 0 ? 0 : + fEta > 0 ? fEta - etaMax() : + fEta + etaMax() ; } Scalar Z () const { return Pz(); } @@ -154,11 +153,10 @@ public : magnitude of momentum */ Scalar P() const { - using namespace std; - return ( fPt > 0 ? fPt*cosh(fEta) : - fEta > etaMax() ? fEta - etaMax() : - fEta < -etaMax() ? -fEta - etaMax() : - 0 ); + return fPt > 0 ? fPt*std::cosh(fEta) : + fEta > etaMax() ? fEta - etaMax() : + fEta < -etaMax() ? -fEta - etaMax() : + 0 ; } Scalar R() const { return P(); } @@ -177,14 +175,13 @@ public : invariant mass */ Scalar M() const { - using namespace std; Scalar mm = M2(); if (mm >= 0) { - return sqrt(mm); + return std::sqrt(mm); } else { GenVector::Throw ("PtEtaPhiE4D::M() - Tachyonic:\n" " Pt and Eta give P such that P^2 > E^2, so the mass would be imaginary"); - return -sqrt(-mm); + return -std::sqrt(-mm); } } Scalar Mag() const { return M(); } @@ -204,14 +201,13 @@ public : transverse mass */ Scalar Mt() const { - using namespace std; Scalar mm = Mt2(); if (mm >= 0) { - return sqrt(mm); + return std::sqrt(mm); } else { GenVector::Throw ("PtEtaPhiE4D::Mt() - Tachyonic:\n" " Pt and Eta give Pz such that Pz^2 > E^2, so the mass would be imaginary"); - return -sqrt(-mm); + return -std::sqrt(-mm); } } @@ -222,8 +218,7 @@ public : transverse energy */ Scalar Et() const { - using namespace std; - return fE / cosh(fEta); // faster using eta + return fE / std::cosh(fEta); // faster using eta } /** @@ -235,9 +230,8 @@ public : private: inline static Scalar pi() { return M_PI; } inline void Restrict() { - using namespace std; if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi(); return; } public: @@ -246,9 +240,9 @@ public : polar angle */ Scalar Theta() const { - using namespace std; - return ( fPt > 0 ? Scalar(2) * atan( exp( - fEta ) ) : - fEta >= 0 ? Scalar(0) : pi() ); + if (fPt > 0) return 2* std::atan( exp( - fEta ) ); + if (fEta >= 0) return 0; + return pi(); } // --------- Set Coordinates of this system --------------- diff --git a/math/genvector/inc/Math/GenVector/PxPyPzE4D.h b/math/genvector/inc/Math/GenVector/PxPyPzE4D.h index 5ddad92db2c0a..ec2a48d983f3d 100644 --- a/math/genvector/inc/Math/GenVector/PxPyPzE4D.h +++ b/math/genvector/inc/Math/GenVector/PxPyPzE4D.h @@ -148,14 +148,13 @@ public : invariant mass */ Scalar M() const { - using namespace std; Scalar mm = M2(); if (mm >= 0) { - return sqrt(mm); + return std::sqrt(mm); } else { GenVector::Throw ("PxPyPzE4D::M() - Tachyonic:\n" " P^2 > E^2 so the mass would be imaginary"); - return -sqrt(-mm); + return -std::sqrt(-mm); } } Scalar Mag() const { return M(); } @@ -169,7 +168,7 @@ public : /** Transverse spatial component (P_perp or rho) */ - Scalar Pt() const { using namespace std; return std::sqrt(Perp2());} + Scalar Pt() const { return std::sqrt(Perp2());} Scalar Perp() const { return Pt();} Scalar Rho() const { return Pt();} @@ -182,14 +181,13 @@ public : transverse mass */ Scalar Mt() const { - using namespace std; Scalar mm = Mt2(); - if ( mm >= 0 ) { - return sqrt(mm); + if (mm >= 0) { + return std::sqrt(mm); } else { GenVector::Throw ("PxPyPzE4D::Mt() - Tachyonic:\n" " Pz^2 > E^2 so the transverse mass would be imaginary"); - return -sqrt(-mm); + return -std::sqrt(-mm); } } @@ -206,25 +204,22 @@ public : transverse energy */ Scalar Et() const { - using namespace std; Scalar etet = Et2(); - return fT < 0.0 ? -sqrt(etet) : sqrt(etet); + return fT < 0.0 ? -std::sqrt(etet) : std::sqrt(etet); } /** azimuthal angle */ Scalar Phi() const { - using namespace std; - return ( fX == Scalar(0) && fY == Scalar(0) ) ? Scalar(0) : atan2(fY,fX); + return (fX == 0.0 && fY == 0.0) ? 0 : std::atan2(fY,fX); } /** polar angle */ Scalar Theta() const { - using namespace std; - return (fX == Scalar(0) && fY == Scalar(0) && fZ == Scalar(0) ) ? Scalar(0) : atan2(Pt(),fZ); + return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : std::atan2(Pt(),fZ); } /** diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index 79660fef4e0fa..d538214daf28b 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -554,21 +554,35 @@ class Transform3D { /** Transformation operation for Position Vector in any coordinate system */ - template + template PositionVector3D operator() (const PositionVector3D & p) const { const Point xyzNew = operator() ( Point(p) ); - return PositionVector3D (xyzNew); + return PositionVector3D (xyzNew); } - + /** + Transformation operation for Position Vector in any coordinate system + */ + template + PositionVector3D operator * ( const PositionVector3D& v ) const { + return operator() (v); + } + /** Transformation operation for Displacement Vector in any coordinate system */ template DisplacementVector3D operator() (const DisplacementVector3D & v) const { const Vector xyzNew = operator() ( Vector(v) ); - return DisplacementVector3D (xyzNew); + return DisplacementVector3D (xyzNew); } - + /** + Transformation operation for Displacement Vector in any coordinate system + */ + template + DisplacementVector3D operator * (const DisplacementVector3D & v) const { + return operator() (v); + } + /** Transformation operation for points between different coordinate system tags */ @@ -596,6 +610,13 @@ class Transform3D { const Vector xyzNew = operator() ( Vector(q.Vect() ) ); return LorentzVector (xyzNew.X(), xyzNew.Y(), xyzNew.Z(), q.E() ); } + /** + Transformation operation for a Lorentz Vector in any coordinate system + */ + template + LorentzVector operator * (const LorentzVector & q) const { + return operator() (q); + } /** Transformation on a 3D plane @@ -611,22 +632,8 @@ class Transform3D { return Plane3D( operator() (n), operator() (p) ); } - // skip transformation for arbitrary vectors - not really defined if point or displacement vectors - // same but with operator * - /** - Transformation operation for Vectors. Apply same rules as operator() - depending on type of vector. - Will work only for DisplacementVector3D, PositionVector3D and LorentzVector - */ - template - AVector operator * (const AVector & v) const { - return operator() (v); - } - - - /** multiply (combine) with another transformation in place */ diff --git a/math/genvector/inc/Math/GenVector/Translation3D.h b/math/genvector/inc/Math/GenVector/Translation3D.h index 21d202fde202a..d1d23c2cb85b6 100644 --- a/math/genvector/inc/Math/GenVector/Translation3D.h +++ b/math/genvector/inc/Math/GenVector/Translation3D.h @@ -26,7 +26,7 @@ #include "Math/GenVector/LorentzVectorfwd.h" #include - +#include namespace ROOT { @@ -183,6 +183,13 @@ class Translation3D { p.Z() + fVect.Z() ) ; return tmp; } + /** + Transformation operation + */ + template + PositionVector3D operator * ( const PositionVector3D & v ) const { + return operator() (v); + } /** Transformation operation for Displacement Vector in any coordinate system and default tag @@ -192,7 +199,14 @@ class Translation3D { DisplacementVector3D operator() (const DisplacementVector3D & v) const { return v; } - + /** + Transformation operation + */ + template + DisplacementVector3D operator * ( const DisplacementVector3D & v ) const { + return operator() (v); + } + /** Transformation operation for points between different coordinate system tags */ @@ -203,7 +217,6 @@ class Translation3D { p2 = operator()(tmp); } - /** Transformation operation for Displacement Vector of different coordinate systems */ @@ -217,10 +230,17 @@ class Translation3D { Transformation operation for a Lorentz Vector in any coordinate system A LorentzVector contains a displacement vector so no translation applies as well */ - template + template LorentzVector operator() (const LorentzVector & q) const { return q; } + /** + Transformation operation + */ + template + LorentzVector operator * ( const LorentzVector & v ) const { + return operator() (v); + } /** Transformation on a 3D plane @@ -236,18 +256,6 @@ class Translation3D { return PLANE( operator() (n), operator() (p) ); } - /** - Transformation operation for Vectors. Apply same rules as operator() - depending on type of vector. - Will work only for DisplacementVector3D, PositionVector3D and LorentzVector - */ - template - AVector operator * (const AVector & v) const { - return operator() (v); - } - - - /** multiply (combine) with another transformation in place */ diff --git a/math/genvector/src/Boost.cxx b/math/genvector/src/Boost.cxx new file mode 100644 index 0000000000000..9510558f27f33 --- /dev/null +++ b/math/genvector/src/Boost.cxx @@ -0,0 +1,186 @@ +// @(#)root/mathcore:$Id$ +// Authors: M. Fischler 2005 + + /********************************************************************** + * * + * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team * + * * + * * + **********************************************************************/ + +// Header file for class Boost, a 4x4 symmetric matrix representation of +// an axial Lorentz transformation +// +// Created by: Mark Fischler Mon Nov 1 2005 +// +#include "Math/GenVector/Boost.h" +#include "Math/GenVector/LorentzVector.h" +#include "Math/GenVector/PxPyPzE4D.h" +#include "Math/GenVector/DisplacementVector3D.h" +#include "Math/GenVector/Cartesian3D.h" +#include "Math/GenVector/GenVector_exception.h" + +#include +#include + +//#ifdef TEX +/** + + A variable names bgamma appears in several places in this file. A few + words of elaboration are needed to make its meaning clear. On page 69 + of Misner, Thorne and Wheeler, (Exercise 2.7) the elements of the matrix + for a general Lorentz boost are given as + + \f[ \Lambda^{j'}_k = \Lambda^{k'}_j + = (\gamma - 1) n^j n^k + \delta^{jk} \f] + + where the n^i are unit vectors in the direction of the three spatial + axes. Using the definitions, \f$ n^i = \beta_i/\beta \f$ , then, for example, + + \f[ \Lambda_{xy} = (\gamma - 1) n_x n_y + = (\gamma - 1) \beta_x \beta_y/\beta^2 \f] + + By definition, \f[ \gamma^2 = 1/(1 - \beta^2) \f] + + so that \f[ \gamma^2 \beta^2 = \gamma^2 - 1 \f] + + or \f[ \beta^2 = (\gamma^2 - 1)/\gamma^2 \f] + + If we insert this into the expression for \f$ \Lambda_{xy} \f$, we get + + \f[ \Lambda_{xy} = (\gamma - 1) \gamma^2/(\gamma^2 - 1) \beta_x \beta_y \f] + + or, finally + + \f[ \Lambda_{xy} = \gamma^2/(\gamma+1) \beta_x \beta_y \f] + + The expression \f$ \gamma^2/(\gamma+1) \f$ is what we call bgamma in the code below. + + \class ROOT::Math::Boost +*/ +//#endif + +namespace ROOT { + +namespace Math { + +void Boost::SetIdentity() { + // set identity boost + fM[kXX] = 1.0; fM[kXY] = 0.0; fM[kXZ] = 0.0; fM[kXT] = 0.0; + fM[kYY] = 1.0; fM[kYZ] = 0.0; fM[kYT] = 0.0; + fM[kZZ] = 1.0; fM[kZT] = 0.0; + fM[kTT] = 1.0; +} + + +void Boost::SetComponents (Scalar bx, Scalar by, Scalar bz) { + // set the boost beta as 3 components + Scalar bp2 = bx*bx + by*by + bz*bz; + if (bp2 >= 1) { + GenVector::Throw ( + "Beta Vector supplied to set Boost represents speed >= c"); + // SetIdentity(); + return; + } + Scalar gamma = 1.0 / std::sqrt(1.0 - bp2); + Scalar bgamma = gamma * gamma / (1.0 + gamma); + fM[kXX] = 1.0 + bgamma * bx * bx; + fM[kYY] = 1.0 + bgamma * by * by; + fM[kZZ] = 1.0 + bgamma * bz * bz; + fM[kXY] = bgamma * bx * by; + fM[kXZ] = bgamma * bx * bz; + fM[kYZ] = bgamma * by * bz; + fM[kXT] = gamma * bx; + fM[kYT] = gamma * by; + fM[kZT] = gamma * bz; + fM[kTT] = gamma; +} + +void Boost::GetComponents (Scalar& bx, Scalar& by, Scalar& bz) const { + // get beta of the boots as 3 components + Scalar gaminv = 1.0/fM[kTT]; + bx = fM[kXT]*gaminv; + by = fM[kYT]*gaminv; + bz = fM[kZT]*gaminv; +} + +DisplacementVector3D< Cartesian3D > +Boost::BetaVector() const { + // get boost beta vector + Scalar gaminv = 1.0/fM[kTT]; + return DisplacementVector3D< Cartesian3D > + ( fM[kXT]*gaminv, fM[kYT]*gaminv, fM[kZT]*gaminv ); +} + +void Boost::GetLorentzRotation (Scalar r[]) const { + // get Lorentz rotation corresponding to this boost as an array of 16 values + r[kLXX] = fM[kXX]; r[kLXY] = fM[kXY]; r[kLXZ] = fM[kXZ]; r[kLXT] = fM[kXT]; + r[kLYX] = fM[kXY]; r[kLYY] = fM[kYY]; r[kLYZ] = fM[kYZ]; r[kLYT] = fM[kYT]; + r[kLZX] = fM[kXZ]; r[kLZY] = fM[kYZ]; r[kLZZ] = fM[kZZ]; r[kLZT] = fM[kZT]; + r[kLTX] = fM[kXT]; r[kLTY] = fM[kYT]; r[kLTZ] = fM[kZT]; r[kLTT] = fM[kTT]; +} + +void Boost::Rectify() { + // Assuming the representation of this is close to a true Lorentz Rotation, + // but may have drifted due to round-off error from many operations, + // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation + // again. + + if (fM[kTT] <= 0) { + GenVector::Throw ( + "Attempt to rectify a boost with non-positive gamma"); + return; + } + DisplacementVector3D< Cartesian3D > beta ( fM[kXT], fM[kYT], fM[kZT] ); + beta /= fM[kTT]; + if ( beta.mag2() >= 1 ) { + beta /= ( beta.R() * ( 1.0 + 1.0e-16 ) ); + } + SetComponents ( beta ); +} + +LorentzVector< PxPyPzE4D > +Boost::operator() (const LorentzVector< PxPyPzE4D > & v) const { + // apply bosost to a PxPyPzE LorentzVector + Scalar x = v.Px(); + Scalar y = v.Py(); + Scalar z = v.Pz(); + Scalar t = v.E(); + return LorentzVector< PxPyPzE4D > + ( fM[kXX]*x + fM[kXY]*y + fM[kXZ]*z + fM[kXT]*t + , fM[kXY]*x + fM[kYY]*y + fM[kYZ]*z + fM[kYT]*t + , fM[kXZ]*x + fM[kYZ]*y + fM[kZZ]*z + fM[kZT]*t + , fM[kXT]*x + fM[kYT]*y + fM[kZT]*z + fM[kTT]*t ); +} + +void Boost::Invert() { + // invert in place boost (modifying the object) + fM[kXT] = -fM[kXT]; + fM[kYT] = -fM[kYT]; + fM[kZT] = -fM[kZT]; +} + +Boost Boost::Inverse() const { + // return inverse of boost + Boost tmp(*this); + tmp.Invert(); + return tmp; +} + + +// ========== I/O ===================== + +std::ostream & operator<< (std::ostream & os, const Boost & b) { + // TODO - this will need changing for machine-readable issues + // and even the human readable form needs formatiing improvements + double m[16]; + b.GetLorentzRotation(m); + os << "\n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3]; + os << "\n" << "\t" << " " << m[5] << " " << m[6] << " " << m[7]; + os << "\n" << "\t" << " " << "\t" << " " << m[10] << " " << m[11]; + os << "\n" << "\t" << " " << "\t" << " " << "\t" << " " << m[15] << "\n"; + return os; +} + +} //namespace Math +} //namespace ROOT diff --git a/math/genvector/src/BoostX.cxx b/math/genvector/src/BoostX.cxx new file mode 100644 index 0000000000000..758e503aaef95 --- /dev/null +++ b/math/genvector/src/BoostX.cxx @@ -0,0 +1,114 @@ + // @(#)root/mathcore:$Id$ +// Authors: M. Fischler 2005 + + /********************************************************************** + * * + * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team * + * * + * * + **********************************************************************/ + +// Header file for class BoostX, a 4x4 symmetric matrix representation of +// an axial Lorentz transformation +// +// Created by: Mark Fischler Mon Nov 1 2005 +// +#include "Math/GenVector/BoostX.h" +#include "Math/GenVector/LorentzVector.h" +#include "Math/GenVector/PxPyPzE4D.h" +#include "Math/GenVector/DisplacementVector3D.h" +#include "Math/GenVector/Cartesian3D.h" +#include "Math/GenVector/GenVector_exception.h" + +#include +#include + +namespace ROOT { + +namespace Math { + + +BoostX::BoostX() : fBeta(0.0), fGamma(1.0) {} + +void BoostX::SetComponents (Scalar bx ) { + // set component + Scalar bp2 = bx*bx; + if (bp2 >= 1) { + GenVector::Throw ( + "Beta Vector supplied to set BoostX represents speed >= c"); + return; + } + fBeta = bx; + fGamma = 1.0 / std::sqrt(1.0 - bp2); +} + +void BoostX::GetComponents (Scalar& bx) const { + // get component + bx = fBeta; +} + +DisplacementVector3D< Cartesian3D > +BoostX::BetaVector() const { + // return beta vector + return DisplacementVector3D< Cartesian3D > ( fBeta, 0.0, 0.0 ); +} + +void BoostX::GetLorentzRotation (Scalar r[]) const { + // get corresponding LorentzRotation + r[kLXX] = fGamma; r[kLXY] = 0.0; r[kLXZ] = 0.0; r[kLXT] = fGamma*fBeta; + r[kLYX] = 0.0; r[kLYY] = 1.0; r[kLYZ] = 0.0; r[kLYT] = 0.0; + r[kLZX] = 0.0; r[kLZY] = 0.0; r[kLZZ] = 1.0; r[kLZT] = 0.0; + r[kLTX] = fGamma*fBeta; r[kLTY] = 0.0; r[kLTZ] = 0.0; r[kLTT] = fGamma; +} + +void BoostX::Rectify() { + // Assuming the representation of this is close to a true Lorentz Rotation, + // but may have drifted due to round-off error from many operations, + // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation + // again. + + if (fGamma <= 0) { + GenVector::Throw ( + "Attempt to rectify a boost with non-positive gamma"); + return; + } + Scalar beta = fBeta; + if ( beta >= 1 ) { + beta /= ( beta * ( 1.0 + 1.0e-16 ) ); + } + SetComponents ( beta ); +} + +LorentzVector< PxPyPzE4D > +BoostX::operator() (const LorentzVector< PxPyPzE4D > & v) const { + // apply boost to a LV + Scalar x = v.Px(); + Scalar t = v.E(); + return LorentzVector< PxPyPzE4D > + ( fGamma*x + fGamma*fBeta*t + , v.Py() + , v.Pz() + , fGamma*fBeta*x + fGamma*t ); +} + +void BoostX::Invert() { + // invert + fBeta = -fBeta; +} + +BoostX BoostX::Inverse() const { + // return an inverse boostX + BoostX tmp(*this); + tmp.Invert(); + return tmp; +} + +// ========== I/O ===================== + +std::ostream & operator<< (std::ostream & os, const BoostX & b) { + os << " BoostX( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; + return os; +} + +} //namespace Math +} //namespace ROOT diff --git a/math/genvector/src/BoostY.cxx b/math/genvector/src/BoostY.cxx new file mode 100644 index 0000000000000..5b79695799c56 --- /dev/null +++ b/math/genvector/src/BoostY.cxx @@ -0,0 +1,113 @@ +// @(#)root/mathcore:$Id$ +// Authors: M. Fischler 2005 + + /********************************************************************** + * * + * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team * + * * + * * + **********************************************************************/ + +// Header file for class BoostY, a 4x4 symmetric matrix representation of +// an axial Lorentz transformation +// +// Created by: Mark Fischler Mon Nov 1 2005 +// +#include "Math/GenVector/BoostY.h" +#include "Math/GenVector/LorentzVector.h" +#include "Math/GenVector/PxPyPzE4D.h" +#include "Math/GenVector/DisplacementVector3D.h" +#include "Math/GenVector/Cartesian3D.h" +#include "Math/GenVector/GenVector_exception.h" + +#include +#include + +namespace ROOT { + +namespace Math { + +BoostY::BoostY() : fBeta(0.0), fGamma(1.0) {} + +void BoostY::SetComponents (Scalar by) { + // set component + Scalar bp2 = by*by; + if (bp2 >= 1) { + GenVector::Throw( + "Beta Vector supplied to set BoostY represents speed >= c"); + return; + } + fBeta = by; + fGamma = 1.0 / std::sqrt(1.0-bp2); +} + +void BoostY::GetComponents (Scalar& by) const { + // get component + by = fBeta; +} + +DisplacementVector3D< Cartesian3D > +BoostY::BetaVector() const { + // return beta vector + return DisplacementVector3D< Cartesian3D > ( 0.0, fBeta, 0.0 ); +} + +void BoostY::GetLorentzRotation (Scalar r[]) const { + // get corresponding LorentzRotation + r[kLXX] = 1.0; r[kLXY] = 0.0; r[kLXZ] = 0.0; r[kLXT] = 0.0; + r[kLYX] = 0.0; r[kLYY] = fGamma; r[kLYZ] = 0.0; r[kLYT] = fGamma*fBeta; + r[kLZX] = 0.0; r[kLZY] = 0.0; r[kLZZ] = 1.0; r[kLZT] = 0.0; + r[kLTX] = 0.0; r[kLTY] = fGamma*fBeta; r[kLTZ] = 0.0; r[kLTT] = fGamma; +} + +void BoostY::Rectify() { + // Assuming the representation of this is close to a true Lorentz Rotation, + // but may have drifted due to round-off error from many operations, + // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation + // again. + + if (fGamma <= 0) { + GenVector::Throw ( + "Attempt to rectify a boost with non-positive gamma"); + return; + } + Scalar beta = fBeta; + if ( beta >= 1 ) { + beta /= ( beta * ( 1.0 + 1.0e-16 ) ); + } + SetComponents ( beta ); +} + +LorentzVector< PxPyPzE4D > +BoostY::operator() (const LorentzVector< PxPyPzE4D > & v) const { + // apply boost to a LV + Scalar y = v.Py(); + Scalar t = v.E(); + return LorentzVector< PxPyPzE4D > + ( v.Px() + , fGamma*y + fGamma*fBeta*t + , v.Pz() + , fGamma*fBeta*y + fGamma*t ); +} + +void BoostY::Invert() { + // invert Boost + fBeta = -fBeta; +} + +BoostY BoostY::Inverse() const { + // return inverse + BoostY tmp(*this); + tmp.Invert(); + return tmp; +} + +// ========== I/O ===================== + +std::ostream & operator<< (std::ostream & os, const BoostY & b) { + os << " BoostY( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; + return os; +} + +} //namespace Math +} //namespace ROOT diff --git a/math/genvector/src/BoostZ.cxx b/math/genvector/src/BoostZ.cxx new file mode 100644 index 0000000000000..5c319f492dd48 --- /dev/null +++ b/math/genvector/src/BoostZ.cxx @@ -0,0 +1,114 @@ +// @(#)root/mathcore:$Id$ +// Authors: M. Fischler 2005 + + /********************************************************************** + * * + * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team * + * * + * * + **********************************************************************/ + +// Header file for class BoostZ, a 4x4 symmetric matrix representation of +// an axial Lorentz transformation +// +// Created by: Mark Fischler Mon Nov 1 2005 +// +#include "Math/GenVector/BoostZ.h" +#include "Math/GenVector/LorentzVector.h" +#include "Math/GenVector/PxPyPzE4D.h" +#include "Math/GenVector/DisplacementVector3D.h" +#include "Math/GenVector/Cartesian3D.h" +#include "Math/GenVector/GenVector_exception.h" + +#include +#include + +namespace ROOT { + +namespace Math { + +BoostZ::BoostZ() : fBeta(0.0), fGamma(1.0) {} + +void BoostZ::SetComponents (Scalar bz) { + // set component + Scalar bp2 = bz*bz; + if (bp2 >= 1) { + GenVector::Throw ( + "Beta Vector supplied to set BoostZ represents speed >= c"); + return; + } + fBeta = bz; + fGamma = 1.0 / std::sqrt(1.0 - bp2); +} + +void BoostZ::GetComponents (Scalar& bz) const { + // get component + bz = fBeta; +} + +DisplacementVector3D< Cartesian3D > +BoostZ::BetaVector() const { + // return beta vector + return DisplacementVector3D< Cartesian3D > + ( 0.0, 0.0, fBeta ); +} + +void BoostZ::GetLorentzRotation (Scalar r[]) const { + // get corresponding LorentzRotation + r[kLXX] = 1.0; r[kLXY] = 0.0; r[kLXZ] = 0.0; r[kLXT] = 0.0 ; + r[kLYX] = 0.0; r[kLYY] = 1.0; r[kLYZ] = 0.0; r[kLYT] = 0.0 ; + r[kLZX] = 0.0; r[kLZY] = 0.0; r[kLZZ] = fGamma; r[kLZT] = fGamma*fBeta; + r[kLTX] = 0.0; r[kLTY] = 0.0; r[kLTZ] = fGamma*fBeta; r[kLTT] = fGamma; +} + +void BoostZ::Rectify() { + // Assuming the representation of this is close to a true Lorentz Rotation, + // but may have drifted due to round-off error from many operations, + // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation + // again. + + if (fGamma <= 0) { + GenVector::Throw ( + "Attempt to rectify a boost with non-positive gamma"); + return; + } + Scalar beta = fBeta; + if ( beta >= 1 ) { + beta /= ( beta * ( 1.0 + 1.0e-16 ) ); + } + SetComponents ( beta ); +} + +LorentzVector< PxPyPzE4D > +BoostZ::operator() (const LorentzVector< PxPyPzE4D > & v) const { + // apply boost to a LV + Scalar z = v.Pz(); + Scalar t = v.E(); + return LorentzVector< PxPyPzE4D > + ( v.Px() + , v.Py() + , fGamma*z + fGamma*fBeta*t + , fGamma*fBeta*z + fGamma*t ); +} + +void BoostZ::Invert() { + // invert + fBeta = -fBeta; +} + +BoostZ BoostZ::Inverse() const { + // return an inverse boostZ + BoostZ tmp(*this); + tmp.Invert(); + return tmp; +} + +// ========== I/O ===================== + +std::ostream & operator<< (std::ostream & os, const BoostZ & b) { + os << " BoostZ( beta: " << b.Beta() << ", gamma: " << b.Gamma() << " ) "; + return os; +} + +} //namespace Math +} //namespace ROOT From 1928c75658f7707b6b22e474ed3bb9326db64428 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 28 Feb 2017 11:22:11 +0100 Subject: [PATCH 16/44] Add specific vectorised implementations of a few methods --- math/genvector/inc/Math/GenVector/Plane3D.h | 22 +- .../inc/Math/GenVector/Transform3D.h | 229 +++++++++++++++--- .../inc/Math/GenVector/Translation3D.h | 30 +-- 3 files changed, 222 insertions(+), 59 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Plane3D.h b/math/genvector/inc/Math/GenVector/Plane3D.h index 186bf0642b1f3..2b89b09777c79 100644 --- a/math/genvector/inc/Math/GenVector/Plane3D.h +++ b/math/genvector/inc/Math/GenVector/Plane3D.h @@ -122,7 +122,9 @@ namespace Impl { \param p3 point3 expressed as ROOT::Math::DisplacementVector3D > */ template - Plane3D(const PositionVector3D & p1, const PositionVector3D & p2, const PositionVector3D & p3 ) + Plane3D( const PositionVector3D & p1, + const PositionVector3D & p2, + const PositionVector3D & p3 ) { BuildFrom3Points( Point(p1.X(), p1.Y(), p1.Z()), Point(p2.X(), p2.Y(), p2.Z()), @@ -213,7 +215,7 @@ namespace Impl { Point ProjectOntoPlane(const Point & p) const { const Scalar d = Distance(p); - return XYZPoint( p.X() - fA*d, p.Y() - fB*d, p.Z() - fC*d); + return XYZPoint( p.X() - fA*d, p.Y() - fB*d, p.Z() - fC*d ); } /** @@ -222,7 +224,7 @@ namespace Impl { */ template PositionVector3D ProjectOntoPlane(const PositionVector3D & p) const { - const Point pxyz = ProjectOntoPlane(Point(p.X(), p.Y(), p.Z() ) ); + const Point pxyz = ProjectOntoPlane( Point( p.X(), p.Y(), p.Z() ) ); return PositionVector3D( pxyz.X(), pxyz.Y(), pxyz.Z() ); } @@ -255,7 +257,7 @@ namespace Impl { // normalize the plane const SCALAR s = std::sqrt( fA*fA + fB*fB + fC*fC ); // what to do if s = 0 ? - if ( s == 0 ) { fD = 0; } + if ( s == SCALAR(0) ) { fD = SCALAR(0); } else { const SCALAR w = Scalar(1)/s; @@ -293,9 +295,9 @@ namespace Impl { void BuildFromVecAndPoint(const Vector & n, const Point & p) { // build from a normal vector and a point - fA = n.X(); - fB = n.Y(); - fC = n.Z(); + fA = n.X(); + fB = n.Y(); + fC = n.Z(); fD = - n.Dot(p); Normalize(); } @@ -306,9 +308,9 @@ namespace Impl { // plane from thre points // normal is (x3-x1) cross (x2 -x1) const Vector n = (p2-p1).Cross(p3-p1); - fA = n.X(); - fB = n.Y(); - fC = n.Z(); + fA = n.X(); + fB = n.Y(); + fC = n.Z(); fD = - n.Dot(p1); Normalize(); } diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index d538214daf28b..7a12176653609 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -36,6 +36,7 @@ #include "Math/GenVector/RotationZfwd.h" #include +#include //#include "Math/Vector3Dfwd.h" @@ -241,22 +242,25 @@ class Transform3D { } #endif - +public: + /** Construct transformation from one coordinate system defined by three points (origin + two axis) to a new coordinate system defined by other three points (origin + axis) + Scalar version. @param fr0 point defining origin of original reference system @param fr1 point defining first axis of original reference system @param fr2 point defining second axis of original reference system @param to0 point defining origin of transformed reference system @param to1 point defining first axis transformed reference system @param to2 point defining second axis transformed reference system - */ + template < typename SCALAR = T > Transform3D - (const Point & fr0, const Point & fr1, const Point & fr2, - const Point & to0, const Point & to1, const Point & to2 ) + ( const Point & fr0, const Point & fr1, const Point & fr2, + const Point & to0, const Point & to1, const Point & to2, + typename std::enable_if::value>::type* = nullptr ) { // takes impl. from CLHEP ( E.Chernyaev). To be checked @@ -270,11 +274,12 @@ class Transform3D { const T cos1 = x1.Dot(y1); const T cos2 = x2.Dot(y2); - if (std::fabs(1.0-cos1) <= 0.000001 || std::fabs(1.0-cos2) <= 0.000001) { + if ( std::fabs( T(1) - cos1 ) <= T(0.000001) || + std::fabs( T(1) - cos2 ) <= T(0.000001) ) { std::cerr << "Transform3D: Error : zero angle between axes" << std::endl; SetIdentity(); } else { - if (std::fabs(cos1-cos2) > 0.000001) { + if ( std::fabs(cos1-cos2) > T(0.000001) ) { std::cerr << "Transform3D: Warning: angles between axes are not equal" << std::endl; } @@ -323,10 +328,101 @@ class Transform3D { SetComponents(txx, txy, txz, dx2-txx*dx1-txy*dy1-txz*dz1, tyx, tyy, tyz, dy2-tyx*dx1-tyy*dy1-tyz*dz1, tzx, tzy, tzz, dz2-tzx*dx1-tzy*dy1-tzz*dz1); + } } + /** + Construct transformation from one coordinate system defined by three + points (origin + two axis) to + a new coordinate system defined by other three points (origin + axis) + Vectorised version. + @param fr0 point defining origin of original reference system + @param fr1 point defining first axis of original reference system + @param fr2 point defining second axis of original reference system + @param to0 point defining origin of transformed reference system + @param to1 point defining first axis transformed reference system + @param to2 point defining second axis transformed reference system + */ + template < typename SCALAR = T > + Transform3D + ( const Point & fr0, const Point & fr1, const Point & fr2, + const Point & to0, const Point & to1, const Point & to2, + typename std::enable_if::value>::type* = nullptr ) + { + // takes impl. from CLHEP ( E.Chernyaev). To be checked + + Vector x1 = (fr1 - fr0).Unit(); + Vector y1 = (fr2 - fr0).Unit(); + Vector x2 = (to1 - to0).Unit(); + Vector y2 = (to2 - to0).Unit(); + + // C H E C K A N G L E S + + const T cos1 = x1.Dot(y1); + const T cos2 = x2.Dot(y2); + + const auto m1 = ( fabs( T(1) - cos1 ) <= T(0.000001) || + fabs( T(1) - cos2 ) <= T(0.000001) ); + + const auto m2 = ( fabs(cos1-cos2) > T(0.000001) ); + if ( any_of(m2) ) { + std::cerr << "Transform3D: Warning: angles between axes are not equal" + << std::endl; + } + + // F I N D R O T A T I O N M A T R I X + + Vector z1 = (x1.Cross(y1)).Unit(); + y1 = z1.Cross(x1); + + Vector z2 = (x2.Cross(y2)).Unit(); + y2 = z2.Cross(x2); + + T x1x = x1.x(); T x1y = x1.y(); T x1z = x1.z(); + T y1x = y1.x(); T y1y = y1.y(); T y1z = y1.z(); + T z1x = z1.x(); T z1y = z1.y(); T z1z = z1.z(); + + T x2x = x2.x(); T x2y = x2.y(); T x2z = x2.z(); + T y2x = y2.x(); T y2y = y2.y(); T y2z = y2.z(); + T z2x = z2.x(); T z2y = z2.y(); T z2z = z2.z(); + + T detxx = (y1y *z1z - z1y *y1z ); + T detxy = -(y1x *z1z - z1x *y1z ); + T detxz = (y1x *z1y - z1x *y1y ); + T detyx = -(x1y *z1z - z1y *x1z ); + T detyy = (x1x *z1z - z1x *x1z ); + T detyz = -(x1x *z1y - z1x *x1y ); + T detzx = (x1y *y1z - y1y *x1z ); + T detzy = -(x1x *y1z - y1x *x1z ); + T detzz = (x1x *y1y - y1x *x1y ); + + T txx = x2x *detxx + y2x *detyx + z2x *detzx; + T txy = x2x *detxy + y2x *detyy + z2x *detzy; + T txz = x2x *detxz + y2x *detyz + z2x *detzz; + T tyx = x2y *detxx + y2y *detyx + z2y *detzx; + T tyy = x2y *detxy + y2y *detyy + z2y *detzy; + T tyz = x2y *detxz + y2y *detyz + z2y *detzz; + T tzx = x2z *detxx + y2z *detyx + z2z *detzx; + T tzy = x2z *detxy + y2z *detyy + z2z *detzy; + T tzz = x2z *detxz + y2z *detyz + z2z *detzz; + + // S E T T R A N S F O R M A T I O N + + T dx1 = fr0.x(), dy1 = fr0.y(), dz1 = fr0.z(); + T dx2 = to0.x(), dy2 = to0.y(), dz2 = to0.z(); + + SetComponents(txx, txy, txz, dx2-txx*dx1-txy*dy1-txz*dz1, + tyx, tyy, tyz, dy2-tyx*dx1-tyy*dy1-tyz*dz1, + tzx, tzy, tzz, dz2-tzx*dx1-tzy*dy1-tzz*dz1); + if ( any_of(m1) ) + { + std::cerr << "Transform3D: Error : zero angle between axes" << std::endl; + SetIdentity(m1); + } + + } // use compiler generated copy ctor, copy assignmet and dtor @@ -407,7 +503,8 @@ class Transform3D { */ template void GetComponents(IT begin) const { - std::copy ( fM, fM+12, begin ); + using namespace std; + copy ( fM, fM+12, begin ); } /** @@ -496,9 +593,9 @@ class Transform3D { */ template AnyRotation Rotation() const { - return AnyRotation(Rotation3D(fM[kXX], fM[kXY], fM[kXZ], - fM[kYX], fM[kYY], fM[kYZ], - fM[kZX], fM[kZY], fM[kZZ] ) ); + return AnyRotation( Rotation3D( fM[kXX], fM[kXY], fM[kXZ], + fM[kYX], fM[kYY], fM[kYZ], + fM[kZX], fM[kZY], fM[kZZ] ) ); } /** @@ -556,8 +653,7 @@ class Transform3D { */ template PositionVector3D operator() (const PositionVector3D & p) const { - const Point xyzNew = operator() ( Point(p) ); - return PositionVector3D (xyzNew); + return PositionVector3D ( operator() ( Point(p) ) ); } /** Transformation operation for Position Vector in any coordinate system @@ -572,8 +668,7 @@ class Transform3D { */ template DisplacementVector3D operator() (const DisplacementVector3D & v) const { - const Vector xyzNew = operator() ( Vector(v) ); - return DisplacementVector3D (xyzNew); + return DisplacementVector3D ( operator() ( Vector(v) ) ); } /** Transformation operation for Displacement Vector in any coordinate system @@ -587,7 +682,8 @@ class Transform3D { Transformation operation for points between different coordinate system tags */ template - void Transform (const PositionVector3D & p1, PositionVector3D & p2 ) const { + void Transform (const PositionVector3D & p1, + PositionVector3D & p2 ) const { const Point xyzNew = operator() ( Point(p1.X(), p1.Y(), p1.Z()) ); p2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() ); } @@ -597,7 +693,8 @@ class Transform3D { Transformation operation for Displacement Vector of different coordinate systems */ template - void Transform (const DisplacementVector3D & v1, DisplacementVector3D & v2 ) const { + void Transform (const DisplacementVector3D & v1, + DisplacementVector3D & v2 ) const { const Vector xyzNew = operator() ( Vector(v1.X(), v1.Y(), v1.Z() ) ); v2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() ); } @@ -608,7 +705,7 @@ class Transform3D { template LorentzVector operator() (const LorentzVector & q) const { const Vector xyzNew = operator() ( Vector(q.Vect() ) ); - return LorentzVector (xyzNew.X(), xyzNew.Y(), xyzNew.Z(), q.E() ); + return LorentzVector ( xyzNew.X(), xyzNew.Y(), xyzNew.Z(), q.E() ); } /** Transformation operation for a Lorentz Vector in any coordinate system @@ -627,7 +724,7 @@ class Transform3D { const Vector n = plane.Normal(); // take a point on the plane. Use origin projection on the plane // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1 - T d = plane.HesseDistance(); + const T d = plane.HesseDistance(); Point p( - d * n.X() , - d *n.Y(), -d *n.Z() ); return Plane3D( operator() (n), operator() (p) ); } @@ -645,9 +742,11 @@ class Transform3D { inline Transform3D operator * (const Transform3D & t) const; /** - Invert the transformation in place + Invert the transformation in place (scalar) */ - void Invert() + template< typename SCALAR = T > + typename std::enable_if< std::is_arithmetic::value, void >::type + Invert() { // // Name: Transform3D::inverse Date: 24.09.96 @@ -655,28 +754,77 @@ class Transform3D { // // Function: Find inverse affine transformation. - const T detxx = fM[kYY]*fM[kZZ] - fM[kYZ]*fM[kZY]; - const T detxy = fM[kYX]*fM[kZZ] - fM[kYZ]*fM[kZX]; - const T detxz = fM[kYX]*fM[kZY] - fM[kYY]*fM[kZX]; - const T det = fM[kXX]*detxx - fM[kXY]*detxy + fM[kXZ]*detxz; + T detxx = fM[kYY]*fM[kZZ] - fM[kYZ]*fM[kZY]; + T detxy = fM[kYX]*fM[kZZ] - fM[kYZ]*fM[kZX]; + T detxz = fM[kYX]*fM[kZY] - fM[kYY]*fM[kZX]; + T det = fM[kXX]*detxx - fM[kXY]*detxy + fM[kXZ]*detxz; if ( det == T(0) ) { std::cerr << "Transform3D::inverse error: zero determinant" << std::endl; return; } - det = T(1)/det; detxx *= det; detxy *= det; detxz *= det; - const T detyx = (fM[kXY]*fM[kZZ] - fM[kXZ]*fM[kZY] )*det; - const T detyy = (fM[kXX]*fM[kZZ] - fM[kXZ]*fM[kZX] )*det; - const T detyz = (fM[kXX]*fM[kZY] - fM[kXY]*fM[kZX] )*det; - const T detzx = (fM[kXY]*fM[kYZ] - fM[kXZ]*fM[kYY] )*det; - const T detzy = (fM[kXX]*fM[kYZ] - fM[kXZ]*fM[kYX] )*det; - const T detzz = (fM[kXX]*fM[kYY] - fM[kXY]*fM[kYX] )*det; + det = T(1)/det; + detxx *= det; detxy *= det; detxz *= det; + T detyx = (fM[kXY]*fM[kZZ] - fM[kXZ]*fM[kZY] )*det; + T detyy = (fM[kXX]*fM[kZZ] - fM[kXZ]*fM[kZX] )*det; + T detyz = (fM[kXX]*fM[kZY] - fM[kXY]*fM[kZX] )*det; + T detzx = (fM[kXY]*fM[kYZ] - fM[kXZ]*fM[kYY] )*det; + T detzy = (fM[kXX]*fM[kYZ] - fM[kXZ]*fM[kYX] )*det; + T detzz = (fM[kXX]*fM[kYY] - fM[kXY]*fM[kYX] )*det; SetComponents ( detxx, -detyx, detzx, -detxx*fM[kDX]+detyx*fM[kDY]-detzx*fM[kDZ], -detxy, detyy, -detzy, detxy*fM[kDX]-detyy*fM[kDY]+detzy*fM[kDZ], - detxz, -detyz, detzz, -detxz*fM[kDX]+detyz*fM[kDY]-detzz*fM[kDZ]); + detxz, -detyz, detzz, -detxz*fM[kDX]+detyz*fM[kDY]-detzz*fM[kDZ] ); } - + /** + Invert the transformation in place (vectorised) + */ + template< typename SCALAR = T > + typename std::enable_if< !std::is_arithmetic::value, void >::type + Invert() + { + // + // Name: Transform3D::inverse Date: 24.09.96 + // Author: E.Chernyaev (IHEP/Protvino) Revised: + // + // Function: Find inverse affine transformation. + + T detxx = fM[kYY]*fM[kZZ] - fM[kYZ]*fM[kZY]; + T detxy = fM[kYX]*fM[kZZ] - fM[kYZ]*fM[kZX]; + T detxz = fM[kYX]*fM[kZY] - fM[kYY]*fM[kZX]; + T det = fM[kXX]*detxx - fM[kXY]*detxy + fM[kXZ]*detxz; + const auto detZmask = ( det == T(0) ); + if ( any_of(detZmask) ) { + std::cerr << "Transform3D::inverse error: zero determinant" << std::endl; + det(detZmask) = T(1); + } + det = T(1)/det; + detxx *= det; detxy *= det; detxz *= det; + T detyx = (fM[kXY]*fM[kZZ] - fM[kXZ]*fM[kZY] )*det; + T detyy = (fM[kXX]*fM[kZZ] - fM[kXZ]*fM[kZX] )*det; + T detyz = (fM[kXX]*fM[kZY] - fM[kXY]*fM[kZX] )*det; + T detzx = (fM[kXY]*fM[kYZ] - fM[kXZ]*fM[kYY] )*det; + T detzy = (fM[kXX]*fM[kYZ] - fM[kXZ]*fM[kYX] )*det; + T detzz = (fM[kXX]*fM[kYY] - fM[kXY]*fM[kYX] )*det; + // Set det=0 cases to 0 + if ( any_of(detZmask) ) { + detxx(detZmask) = T(0); + detxy(detZmask) = T(0); + detxz(detZmask) = T(0); + detyx(detZmask) = T(0); + detyy(detZmask) = T(0); + detyz(detZmask) = T(0); + detzx(detZmask) = T(0); + detzy(detZmask) = T(0); + detzz(detZmask) = T(0); + } + // set final components + SetComponents + ( detxx, -detyx, detzx, -detxx*fM[kDX]+detyx*fM[kDY]-detzx*fM[kDZ], + -detxy, detyy, -detzy, detxy*fM[kDX]-detyy*fM[kDY]+detzy*fM[kDZ], + detxz, -detyz, detzz, -detxz*fM[kDX]+detyz*fM[kDY]-detzz*fM[kDZ] ); + } + /** Return the inverse of the transformation. */ @@ -783,8 +931,21 @@ class Transform3D { fM[kZX] = T(0); fM[kZY] = T(0); fM[kZZ] = T(1); fM[kDZ] = T(0); } -private: + /** + Set identity transformation (identity rotation , zero translation) + vectorised version that sets using a mask + */ + template< typename SCALAR = T > + typename std::enable_if< !std::is_arithmetic::value, void >::type + SetIdentity( const typename SCALAR::mask_type m ) + { + //set identity ( identity rotation and zero translation) + fM[kXX](m) = T(1); fM[kXY](m) = T(0); fM[kXZ](m) = T(0); fM[kDX](m) = T(0); + fM[kYX](m) = T(0); fM[kYY](m) = T(1); fM[kYZ](m) = T(0); fM[kDY](m) = T(0); + fM[kZX](m) = T(0); fM[kZY](m) = T(0); fM[kZZ](m) = T(1); fM[kDZ](m) = T(0); + } +private: T fM[12]; // transformation elements (3x4 matrix) diff --git a/math/genvector/inc/Math/GenVector/Translation3D.h b/math/genvector/inc/Math/GenVector/Translation3D.h index d1d23c2cb85b6..1a4e99e8f82c9 100644 --- a/math/genvector/inc/Math/GenVector/Translation3D.h +++ b/math/genvector/inc/Math/GenVector/Translation3D.h @@ -101,7 +101,8 @@ class Translation3D { */ template - Translation3D (const PositionVector3D & p1, const PositionVector3D & p2 ) : + Translation3D ( const PositionVector3D & p1, + const PositionVector3D & p2 ) : fVect(p2-p1) { } @@ -177,11 +178,9 @@ class Translation3D { */ template PositionVector3D operator() (const PositionVector3D & p) const { - PositionVector3D tmp; - tmp.SetXYZ (p.X() + fVect.X(), - p.Y() + fVect.Y(), - p.Z() + fVect.Z() ) ; - return tmp; + return PositionVector3D ( p.X() + fVect.X(), + p.Y() + fVect.Y(), + p.Z() + fVect.Z() ); } /** Transformation operation @@ -221,9 +220,10 @@ class Translation3D { Transformation operation for Displacement Vector of different coordinate systems */ template - void Transform (const DisplacementVector3D & v1, DisplacementVector3D & v2 ) const { + void Transform ( const DisplacementVector3D & v1, + DisplacementVector3D & v2 ) const { // just copy v1 in v2 - v2.SetXYZ(v1.X(), v1.Y(), v1.Z() ); + v2.SetXYZ( v1.X(), v1.Y(), v1.Z() ); } /** @@ -231,15 +231,15 @@ class Translation3D { A LorentzVector contains a displacement vector so no translation applies as well */ template - LorentzVector operator() (const LorentzVector & q) const { - return q; + LorentzVector operator() ( const LorentzVector & q ) const { + return q; } /** Transformation operation */ template - LorentzVector operator * ( const LorentzVector & v ) const { - return operator() (v); + LorentzVector operator * ( const LorentzVector & q ) const { + return operator() (q); } /** @@ -248,11 +248,11 @@ class Translation3D { Plane3D operator() ( const Plane3D & plane ) const { // transformations on a 3D plane - Vector n = plane.Normal(); + const Vector n = plane.Normal(); // take a point on the plane. Use origin projection on the plane // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1 - T d = plane.HesseDistance(); - PositionVector3D > p( - d * n.X() , - d *n.Y(), -d *n.Z() ); + const T d = plane.HesseDistance(); + PositionVector3D > p( - d * n.X() , - d * n.Y(), - d * n.Z() ); return PLANE( operator() (n), operator() (p) ); } From 5ccdaead1b8aee6a178bbf20d32f7974932f2d06 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 28 Feb 2017 17:36:36 +0100 Subject: [PATCH 17/44] Extend ostream operator for Displacement and Position vectors to support vector Scalar types --- .../inc/Math/GenVector/DisplacementVector3D.h | 61 +++++++++++------- .../inc/Math/GenVector/PositionVector3D.h | 63 ++++++++++++------- 2 files changed, 79 insertions(+), 45 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h index 3fceba90daeb1..024e8c90ebb1d 100644 --- a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h +++ b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h @@ -620,35 +620,52 @@ namespace ROOT { // ------------- I/O to/from streams ------------- template< class char_t, class traits_t, class T, class U > - inline - std::basic_ostream & - operator << ( std::basic_ostream & os + inline + typename std::enable_if< std::is_arithmetic::Scalar>::value, + std::basic_ostream & >::type + operator << ( std::basic_ostream & os , DisplacementVector3D const & v ) { - if( !os ) return os; - - typename T::Scalar a, b, c; - v.GetCoordinates(a, b, c); - - if( detail::get_manip( os, detail::bitforbit ) ) { - detail::set_manip( os, detail::bitforbit, '\00' ); - typedef GenVector_detail::BitReproducible BR; - BR::Output(os, a); - BR::Output(os, b); - BR::Output(os, c); - } - else { - os << detail::get_manip( os, detail::open ) << a - << detail::get_manip( os, detail::sep ) << b - << detail::get_manip( os, detail::sep ) << c - << detail::get_manip( os, detail::close ); + if ( os ) { + + typename T::Scalar a, b, c; + v.GetCoordinates(a, b, c); + + if( detail::get_manip( os, detail::bitforbit ) ) { + detail::set_manip( os, detail::bitforbit, '\00' ); + typedef GenVector_detail::BitReproducible BR; + BR::Output(os, a); + BR::Output(os, b); + BR::Output(os, c); + } + else { + os << detail::get_manip( os, detail::open ) << a + << detail::get_manip( os, detail::sep ) << b + << detail::get_manip( os, detail::sep ) << c + << detail::get_manip( os, detail::close ); + } } - return os; - } // op<< <>() + template< class char_t, class traits_t, class T, class U > + inline + typename std::enable_if< !std::is_arithmetic::Scalar>::value, + std::basic_ostream & >::type + operator << ( std::basic_ostream & os + , DisplacementVector3D const & v + ) + { + if ( os ) { + os << "{ "; + for ( std::size_t i = 0; i < PositionVector3D::Scalar::Size; ++i ) { + os << "(" << v.x()[i] << "," << v.y()[i] << "," << v.z()[i] << ") "; + } + os << "}"; + } + return os; + } // op<< <>() template< class char_t, class traits_t, class T, class U > inline diff --git a/math/genvector/inc/Math/GenVector/PositionVector3D.h b/math/genvector/inc/Math/GenVector/PositionVector3D.h index e27d9dce48887..1d2f5da67b3f9 100644 --- a/math/genvector/inc/Math/GenVector/PositionVector3D.h +++ b/math/genvector/inc/Math/GenVector/PositionVector3D.h @@ -576,36 +576,53 @@ namespace ROOT { // ------------- I/O to/from streams ------------- template< class char_t, class traits_t, class T, class U > - inline - std::basic_ostream & - operator << ( std::basic_ostream & os + inline + typename std::enable_if< std::is_arithmetic::Scalar>::value, + std::basic_ostream & >::type + operator << ( std::basic_ostream & os , PositionVector3D const & v ) { - if( !os ) return os; - - typename T::Scalar a, b, c; - v.GetCoordinates(a, b, c); - - if( detail::get_manip( os, detail::bitforbit ) ) { - detail::set_manip( os, detail::bitforbit, '\00' ); - typedef GenVector_detail::BitReproducible BR; - BR::Output(os, a); - BR::Output(os, b); - BR::Output(os, c); - } - else { - os << detail::get_manip( os, detail::open ) << a - << detail::get_manip( os, detail::sep ) << b - << detail::get_manip( os, detail::sep ) << c - << detail::get_manip( os, detail::close ); + if ( os ) { + + typename T::Scalar a, b, c; + v.GetCoordinates(a, b, c); + + if( detail::get_manip( os, detail::bitforbit ) ) { + detail::set_manip( os, detail::bitforbit, '\00' ); + typedef GenVector_detail::BitReproducible BR; + BR::Output(os, a); + BR::Output(os, b); + BR::Output(os, c); + } + else { + os << detail::get_manip( os, detail::open ) << a + << detail::get_manip( os, detail::sep ) << b + << detail::get_manip( os, detail::sep ) << c + << detail::get_manip( os, detail::close ); + } } - return os; - } // op<< <>() - + template< class char_t, class traits_t, class T, class U > + inline + typename std::enable_if< !std::is_arithmetic::Scalar>::value, + std::basic_ostream & >::type + operator << ( std::basic_ostream & os + , PositionVector3D const & v + ) + { + if ( os ) { + os << "{ "; + for ( std::size_t i = 0; i < PositionVector3D::Scalar::Size; ++i ) { + os << "(" << v.x()[i] << "," << v.y()[i] << "," << v.z()[i] << ") "; + } + os << "}"; + } + return os; + } // op<< <>() + template< class char_t, class traits_t, class T, class U > inline std::basic_istream & From ef1aea9bd247190b5754d26f44435577668b01b8 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 28 Feb 2017 21:27:04 +0100 Subject: [PATCH 18/44] Fix the vector abs method (not fabs) and Vector Unit() for vectorised scalars --- .../inc/Math/GenVector/DisplacementVector3D.h | 33 +++++++++++++------ .../inc/Math/GenVector/Transform3D.h | 6 ++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h index 024e8c90ebb1d..8c4797da0e0f6 100644 --- a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h +++ b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h @@ -249,11 +249,11 @@ namespace ROOT { */ template void GetCoordinates( IT begin) const { - Scalar a,b,c = 0; - GetCoordinates (a,b,c); - *begin++ = a; - *begin++ = b; - *begin = c; + Scalar a,b,c = Scalar(0); + GetCoordinates (a,b,c); + *begin++ = a; + *begin++ = b; + *begin = c; } /** @@ -262,8 +262,8 @@ namespace ROOT { then (x, y, z) are converted to that form) */ DisplacementVector3D& SetXYZ (Scalar a, Scalar b, Scalar c) { - fCoordinates.SetXYZ(a,b,c); - return *this; + fCoordinates.SetXYZ(a,b,c); + return *this; } // ------------------- Equality ----------------- @@ -333,13 +333,26 @@ namespace ROOT { Scalar Perp2() const { return fCoordinates.Perp2();} /** - return unit vector parallel to this + return unit vector parallel to this (scalar) */ - DisplacementVector3D Unit() const { - Scalar tot = R(); + template< typename SCALAR = Scalar > + typename std::enable_if< std::is_arithmetic::value, DisplacementVector3D >::type + Unit() const { + const auto tot = R(); return tot == 0 ? *this : DisplacementVector3D(*this) / tot; } + /** + return unit vector parallel to this (scalar) + */ + template< typename SCALAR = Scalar > + typename std::enable_if< !std::is_arithmetic::value, DisplacementVector3D >::type + Unit() const { + SCALAR tot = R(); + tot( tot == SCALAR(0) ) = SCALAR(1); + return DisplacementVector3D(*this) / tot; + } + // ------ Setting of individual elements present in coordinate system ------ /** diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index 7a12176653609..25c170491c96b 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -362,10 +362,10 @@ class Transform3D { const T cos1 = x1.Dot(y1); const T cos2 = x2.Dot(y2); - const auto m1 = ( fabs( T(1) - cos1 ) <= T(0.000001) || - fabs( T(1) - cos2 ) <= T(0.000001) ); + const auto m1 = ( abs( T(1) - cos1 ) <= T(0.000001) || + abs( T(1) - cos2 ) <= T(0.000001) ); - const auto m2 = ( fabs(cos1-cos2) > T(0.000001) ); + const auto m2 = ( abs(cos1-cos2) > T(0.000001) ); if ( any_of(m2) ) { std::cerr << "Transform3D: Warning: angles between axes are not equal" << std::endl; From 776ce1aaa8d936d5999adc02bd19498b0d8ed077 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 6 Mar 2017 07:46:22 +0000 Subject: [PATCH 19/44] Add override qualifier --- math/genvector/inc/Math/GenVector/BitReproducible.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/genvector/inc/Math/GenVector/BitReproducible.h b/math/genvector/inc/Math/GenVector/BitReproducible.h index f677ecd47b836..721ef4cb98cba 100644 --- a/math/genvector/inc/Math/GenVector/BitReproducible.h +++ b/math/genvector/inc/Math/GenVector/BitReproducible.h @@ -32,7 +32,7 @@ class BitReproducibleException : public std::exception public: BitReproducibleException(const std::string & w) throw() : fMsg(w) {} ~BitReproducibleException() throw() {} - const char* what() const throw() { return fMsg.c_str(); } + const char* what() const throw() override { return fMsg.c_str(); } private: std::string fMsg; }; // DoubConvException From 12b43b00df0f66cfb0d1b7f8b38f1d23388f0205 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 10 Mar 2017 15:15:03 +0000 Subject: [PATCH 20/44] Fix initialisation bug --- math/genvector/inc/Math/GenVector/DisplacementVector3D.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h index 8c4797da0e0f6..e909c7914abd4 100644 --- a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h +++ b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h @@ -249,7 +249,9 @@ namespace ROOT { */ template void GetCoordinates( IT begin) const { - Scalar a,b,c = Scalar(0); + Scalar a = Scalar(0); + Scalar b = Scalar(0); + Scalar c = Scalar(0); GetCoordinates (a,b,c); *begin++ = a; *begin++ = b; From 8367bdf23a70c55d8ba23442a5d13cb0f44f5bce Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 10 Mar 2017 15:21:53 +0000 Subject: [PATCH 21/44] remove space --- math/genvector/inc/Math/GenVector/Cartesian2D.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/genvector/inc/Math/GenVector/Cartesian2D.h b/math/genvector/inc/Math/GenVector/Cartesian2D.h index 3a804ae985a4e..179a9b5ef1652 100644 --- a/math/genvector/inc/Math/GenVector/Cartesian2D.h +++ b/math/genvector/inc/Math/GenVector/Cartesian2D.h @@ -89,7 +89,7 @@ public : Scalar X() const { return fX;} Scalar Y() const { return fY;} Scalar Mag2() const { return fX*fX + fY*fY; } - Scalar R() const { using namespace std; return sqrt( Mag2()); } + Scalar R() const { using namespace std; return sqrt(Mag2()); } Scalar Phi() const { using namespace std; return (fX==Scalar(0) && fY==Scalar(0)) ? Scalar(0) : atan2(fY,fX);} From 0f404ba401fd8717747d1c83df13d2a1b2957b1c Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 10 Mar 2017 16:04:24 +0000 Subject: [PATCH 22/44] Some small changes following review comments --- math/genvector/inc/Math/GenVector/Cartesian3D.h | 3 ++- .../inc/Math/GenVector/PositionVector3D.h | 16 ++++++++++------ math/genvector/inc/Math/GenVector/Transform3D.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Cartesian3D.h b/math/genvector/inc/Math/GenVector/Cartesian3D.h index 71b439151e318..0ea2b38ba8875 100644 --- a/math/genvector/inc/Math/GenVector/Cartesian3D.h +++ b/math/genvector/inc/Math/GenVector/Cartesian3D.h @@ -192,7 +192,8 @@ public : explicit Cartesian3D( const Polar3D & v ) : fZ (v.Z()) { using namespace std; - const T rho = v.Rho(); // re-using this instead of calling v.X() and v.Y() + const T rho = v.Rho(); + // re-using this instead of calling v.X() and v.Y() // is the speed improvement fX = rho * cos(v.Phi()); fY = rho * sin(v.Phi()); diff --git a/math/genvector/inc/Math/GenVector/PositionVector3D.h b/math/genvector/inc/Math/GenVector/PositionVector3D.h index 1d2f5da67b3f9..f9ea49af97986 100644 --- a/math/genvector/inc/Math/GenVector/PositionVector3D.h +++ b/math/genvector/inc/Math/GenVector/PositionVector3D.h @@ -227,11 +227,13 @@ namespace ROOT { */ template void GetCoordinates( IT begin ) const { - Scalar a,b,c = 0; - GetCoordinates (a,b,c); - *begin++ = a; - *begin++ = b; - *begin = c; + Scalar a = Scalar(0); + Scalar b = Scalar(0); + Scalar c = Scalar(0); + GetCoordinates (a,b,c); + *begin++ = a; + *begin++ = b; + *begin = c; } /** @@ -585,7 +587,9 @@ namespace ROOT { { if ( os ) { - typename T::Scalar a, b, c; + typename T::Scalar a = 0; + typename T::Scalar b = 0; + typename T::Scalar c = 0; v.GetCoordinates(a, b, c); if( detail::get_manip( os, detail::bitforbit ) ) { diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index 25c170491c96b..b01fc9c834c76 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -983,7 +983,7 @@ inline Transform3D & Transform3D::operator *= (const Transform3D & t) template inline Transform3D Transform3D::operator * (const Transform3D & t) const { - // combination of transformations + // combination of transformations return Transform3D(fM[kXX]*t.fM[kXX]+fM[kXY]*t.fM[kYX]+fM[kXZ]*t.fM[kZX], fM[kXX]*t.fM[kXY]+fM[kXY]*t.fM[kYY]+fM[kXZ]*t.fM[kZY], From 65a701d55099fd85320439d48e8dd04128a5a967 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 10 Mar 2017 16:20:42 +0000 Subject: [PATCH 23/44] remove spaces --- math/genvector/inc/Math/GenVector/Transform3D.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index b01fc9c834c76..59f12c4e0b163 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -989,17 +989,16 @@ inline Transform3D Transform3D::operator * (const Transform3D & t) con fM[kXX]*t.fM[kXY]+fM[kXY]*t.fM[kYY]+fM[kXZ]*t.fM[kZY], fM[kXX]*t.fM[kXZ]+fM[kXY]*t.fM[kYZ]+fM[kXZ]*t.fM[kZZ], fM[kXX]*t.fM[kDX]+fM[kXY]*t.fM[kDY]+fM[kXZ]*t.fM[kDZ]+fM[kDX], - + fM[kYX]*t.fM[kXX]+fM[kYY]*t.fM[kYX]+fM[kYZ]*t.fM[kZX], fM[kYX]*t.fM[kXY]+fM[kYY]*t.fM[kYY]+fM[kYZ]*t.fM[kZY], fM[kYX]*t.fM[kXZ]+fM[kYY]*t.fM[kYZ]+fM[kYZ]*t.fM[kZZ], fM[kYX]*t.fM[kDX]+fM[kYY]*t.fM[kDY]+fM[kYZ]*t.fM[kDZ]+fM[kDY], - + fM[kZX]*t.fM[kXX]+fM[kZY]*t.fM[kYX]+fM[kZZ]*t.fM[kZX], fM[kZX]*t.fM[kXY]+fM[kZY]*t.fM[kYY]+fM[kZZ]*t.fM[kZY], fM[kZX]*t.fM[kXZ]+fM[kZY]*t.fM[kYZ]+fM[kZZ]*t.fM[kZZ], fM[kZX]*t.fM[kDX]+fM[kZY]*t.fM[kDY]+fM[kZZ]*t.fM[kDZ]+fM[kDZ] ); - } From b8ca8222734e852283879099edd3fb1ba9b313d0 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 11 Mar 2017 15:30:51 +0000 Subject: [PATCH 24/44] Fix formatting using clang-format --- .../inc/Math/GenVector/BitReproducible.h | 4 +- .../inc/Math/GenVector/Cartesian2D.h | 19 +- .../inc/Math/GenVector/Cartesian3D.h | 52 +- .../inc/Math/GenVector/Cylindrical3D.h | 30 +- .../inc/Math/GenVector/DisplacementVector3D.h | 113 +- math/genvector/inc/Math/GenVector/Plane3D.h | 508 +++++---- .../inc/Math/GenVector/PositionVector3D.h | 93 +- .../inc/Math/GenVector/Transform3D.h | 964 +++++++++--------- .../inc/Math/GenVector/Translation3D.h | 124 +-- math/genvector/inc/Math/GenVector/eta.h | 5 +- 10 files changed, 951 insertions(+), 961 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/BitReproducible.h b/math/genvector/inc/Math/GenVector/BitReproducible.h index 721ef4cb98cba..027206bdd642d 100644 --- a/math/genvector/inc/Math/GenVector/BitReproducible.h +++ b/math/genvector/inc/Math/GenVector/BitReproducible.h @@ -32,8 +32,8 @@ class BitReproducibleException : public std::exception public: BitReproducibleException(const std::string & w) throw() : fMsg(w) {} ~BitReproducibleException() throw() {} - const char* what() const throw() override { return fMsg.c_str(); } -private: + const char *what() const throw() override { return fMsg.c_str(); } + private: std::string fMsg; }; // DoubConvException diff --git a/math/genvector/inc/Math/GenVector/Cartesian2D.h b/math/genvector/inc/Math/GenVector/Cartesian2D.h index 179a9b5ef1652..1b90c57dc13c9 100644 --- a/math/genvector/inc/Math/GenVector/Cartesian2D.h +++ b/math/genvector/inc/Math/GenVector/Cartesian2D.h @@ -89,9 +89,16 @@ public : Scalar X() const { return fX;} Scalar Y() const { return fY;} Scalar Mag2() const { return fX*fX + fY*fY; } - Scalar R() const { using namespace std; return sqrt(Mag2()); } - Scalar Phi() const { using namespace std; - return (fX==Scalar(0) && fY==Scalar(0)) ? Scalar(0) : atan2(fY,fX);} + Scalar R() const + { + using namespace std; + return sqrt(Mag2()); + } + Scalar Phi() const + { + using namespace std; + return (fX == Scalar(0) && fY == Scalar(0)) ? Scalar(0) : atan2(fY, fX); + } /** set the x coordinate value keeping y constant @@ -164,7 +171,7 @@ public : explicit Cartesian2D( const Polar2D & v ) { using namespace std; - const Scalar r = v.R(); // re-using this instead of calling v.X() and v.Y() + const Scalar r = v.R(); // re-using this instead of calling v.X() and v.Y() // is the speed improvement fX = r * cos(v.Phi()); fY = r * sin(v.Phi()); @@ -179,8 +186,8 @@ public : { using namespace std; const Scalar r = v.R(); - fX = r * cos(v.Phi()); - fY = r * sin(v.Phi()); + fX = r * cos(v.Phi()); + fY = r * sin(v.Phi()); return *this; } diff --git a/math/genvector/inc/Math/GenVector/Cartesian3D.h b/math/genvector/inc/Math/GenVector/Cartesian3D.h index 0ea2b38ba8875..54cf050e2ce83 100644 --- a/math/genvector/inc/Math/GenVector/Cartesian3D.h +++ b/math/genvector/inc/Math/GenVector/Cartesian3D.h @@ -110,13 +110,26 @@ public : Scalar Z() const { return fZ;} Scalar Mag2() const { return fX*fX + fY*fY + fZ*fZ;} Scalar Perp2() const { return fX*fX + fY*fY ;} - Scalar Rho() const { using namespace std; return sqrt( Perp2() ); } - Scalar R() const { using namespace std; return sqrt( Mag2() ); } - Scalar Theta() const { using namespace std; - return (fX==Scalar(0) && fY==Scalar(0) && fZ==Scalar(0)) ? - Scalar(0) : atan2(Rho(),Z());} - Scalar Phi() const { using namespace std; - return (fX==Scalar(0) && fY==Scalar(0)) ? Scalar(0) : atan2(fY,fX);} + Scalar Rho() const + { + using namespace std; + return sqrt(Perp2()); + } + Scalar R() const + { + using namespace std; + return sqrt(Mag2()); + } + Scalar Theta() const + { + using namespace std; + return (fX == Scalar(0) && fY == Scalar(0) && fZ == Scalar(0)) ? Scalar(0) : atan2(Rho(), Z()); + } + Scalar Phi() const + { + using namespace std; + return (fX == Scalar(0) && fY == Scalar(0)) ? Scalar(0) : atan2(fY, fX); + } // pseudorapidity Scalar Eta() const { @@ -150,7 +163,12 @@ public : /** scale the vector by a scalar quantity a */ - void Scale(Scalar a) { fX *= a; fY *= a; fZ *= a; } + void Scale(Scalar a) + { + fX *= a; + fY *= a; + fZ *= a; + } /** negate the vector @@ -191,12 +209,12 @@ public : template explicit Cartesian3D( const Polar3D & v ) : fZ (v.Z()) { - using namespace std; - const T rho = v.Rho(); - // re-using this instead of calling v.X() and v.Y() - // is the speed improvement - fX = rho * cos(v.Phi()); - fY = rho * sin(v.Phi()); + using namespace std; + const T rho = v.Rho(); + // re-using this instead of calling v.X() and v.Y() + // is the speed improvement + fX = rho * cos(v.Phi()); + fY = rho * sin(v.Phi()); } // Technical note: This works even though only Polar3Dfwd.h is // included (and in fact, including Polar3D.h would cause circularity @@ -206,10 +224,10 @@ public : template Cartesian3D & operator = (const Polar3D & v) { - using namespace std; + using namespace std; const T rho = v.Rho(); - fX = rho * cos(v.Phi()); - fY = rho * sin(v.Phi()); + fX = rho * cos(v.Phi()); + fY = rho * sin(v.Phi()); fZ = v.Z(); return *this; } diff --git a/math/genvector/inc/Math/GenVector/Cylindrical3D.h b/math/genvector/inc/Math/GenVector/Cylindrical3D.h index 43eb78572fbfe..44168bf71e9e7 100644 --- a/math/genvector/inc/Math/GenVector/Cylindrical3D.h +++ b/math/genvector/inc/Math/GenVector/Cylindrical3D.h @@ -107,11 +107,10 @@ public : private: inline static Scalar pi() { return Scalar(M_PI); } - inline void Restrict() + inline void Restrict() { using namespace std; - if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); return; } public: @@ -122,15 +121,28 @@ public : Scalar Z() const { return fZ; } Scalar Phi() const { return fPhi; } - Scalar X() const { using namespace std; return fRho*cos(fPhi); } - Scalar Y() const { using namespace std; return fRho*sin(fPhi); } + Scalar X() const + { + using namespace std; + return fRho * cos(fPhi); + } + Scalar Y() const + { + using namespace std; + return fRho * sin(fPhi); + } Scalar Mag2() const { return fRho*fRho + fZ*fZ; } - Scalar R() const { using namespace std; return sqrt( Mag2()); } + Scalar R() const + { + using namespace std; + return sqrt(Mag2()); + } Scalar Perp2() const { return fRho*fRho; } - Scalar Theta() const { - using namespace std; - return (fRho==Scalar(0) && fZ==Scalar(0) ) ? Scalar(0) : atan2(fRho,fZ); + Scalar Theta() const + { + using namespace std; + return (fRho == Scalar(0) && fZ == Scalar(0)) ? Scalar(0) : atan2(fRho, fZ); } // pseudorapidity - use same implementation as in Cartesian3D diff --git a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h index e909c7914abd4..82a0edc382ed5 100644 --- a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h +++ b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h @@ -249,13 +249,13 @@ namespace ROOT { */ template void GetCoordinates( IT begin) const { - Scalar a = Scalar(0); - Scalar b = Scalar(0); - Scalar c = Scalar(0); - GetCoordinates (a,b,c); - *begin++ = a; - *begin++ = b; - *begin = c; + Scalar a = Scalar(0); + Scalar b = Scalar(0); + Scalar c = Scalar(0); + GetCoordinates(a, b, c); + *begin++ = a; + *begin++ = b; + *begin = c; } /** @@ -264,8 +264,8 @@ namespace ROOT { then (x, y, z) are converted to that form) */ DisplacementVector3D& SetXYZ (Scalar a, Scalar b, Scalar c) { - fCoordinates.SetXYZ(a,b,c); - return *this; + fCoordinates.SetXYZ(a, b, c); + return *this; } // ------------------- Equality ----------------- @@ -337,22 +337,22 @@ namespace ROOT { /** return unit vector parallel to this (scalar) */ - template< typename SCALAR = Scalar > - typename std::enable_if< std::is_arithmetic::value, DisplacementVector3D >::type - Unit() const { - const auto tot = R(); - return tot == 0 ? *this : DisplacementVector3D(*this) / tot; + template + typename std::enable_if::value, DisplacementVector3D>::type Unit() const + { + const auto tot = R(); + return tot == 0 ? *this : DisplacementVector3D(*this) / tot; } /** return unit vector parallel to this (scalar) */ - template< typename SCALAR = Scalar > - typename std::enable_if< !std::is_arithmetic::value, DisplacementVector3D >::type - Unit() const { - SCALAR tot = R(); - tot( tot == SCALAR(0) ) = SCALAR(1); - return DisplacementVector3D(*this) / tot; + template + typename std::enable_if::value, DisplacementVector3D>::type Unit() const + { + SCALAR tot = R(); + tot(tot == SCALAR(0)) = SCALAR(1); + return DisplacementVector3D(*this) / tot; } // ------ Setting of individual elements present in coordinate system ------ @@ -634,53 +634,44 @@ namespace ROOT { // ------------- I/O to/from streams ------------- - template< class char_t, class traits_t, class T, class U > - inline - typename std::enable_if< std::is_arithmetic::Scalar>::value, - std::basic_ostream & >::type - operator << ( std::basic_ostream & os - , DisplacementVector3D const & v - ) + template + inline typename std::enable_if::Scalar>::value, + std::basic_ostream &>::type + operator<<(std::basic_ostream &os, DisplacementVector3D const &v) { - if ( os ) { - - typename T::Scalar a, b, c; - v.GetCoordinates(a, b, c); - - if( detail::get_manip( os, detail::bitforbit ) ) { - detail::set_manip( os, detail::bitforbit, '\00' ); - typedef GenVector_detail::BitReproducible BR; - BR::Output(os, a); - BR::Output(os, b); - BR::Output(os, c); - } - else { - os << detail::get_manip( os, detail::open ) << a - << detail::get_manip( os, detail::sep ) << b - << detail::get_manip( os, detail::sep ) << c - << detail::get_manip( os, detail::close ); - } + if (os) { + + typename T::Scalar a, b, c; + v.GetCoordinates(a, b, c); + + if (detail::get_manip(os, detail::bitforbit)) { + detail::set_manip(os, detail::bitforbit, '\00'); + typedef GenVector_detail::BitReproducible BR; + BR::Output(os, a); + BR::Output(os, b); + BR::Output(os, c); + } else { + os << detail::get_manip(os, detail::open) << a << detail::get_manip(os, detail::sep) << b + << detail::get_manip(os, detail::sep) << c << detail::get_manip(os, detail::close); + } } return os; } // op<< <>() - template< class char_t, class traits_t, class T, class U > - inline - typename std::enable_if< !std::is_arithmetic::Scalar>::value, - std::basic_ostream & >::type - operator << ( std::basic_ostream & os - , DisplacementVector3D const & v - ) + template + inline typename std::enable_if::Scalar>::value, + std::basic_ostream &>::type + operator<<(std::basic_ostream &os, DisplacementVector3D const &v) { - if ( os ) { - os << "{ "; - for ( std::size_t i = 0; i < PositionVector3D::Scalar::Size; ++i ) { - os << "(" << v.x()[i] << "," << v.y()[i] << "," << v.z()[i] << ") "; - } - os << "}"; - } - return os; - } // op<< <>() + if (os) { + os << "{ "; + for (std::size_t i = 0; i < PositionVector3D::Scalar::Size; ++i) { + os << "(" << v.x()[i] << "," << v.y()[i] << "," << v.z()[i] << ") "; + } + os << "}"; + } + return os; + } // op<< <>() template< class char_t, class traits_t, class T, class U > inline diff --git a/math/genvector/inc/Math/GenVector/Plane3D.h b/math/genvector/inc/Math/GenVector/Plane3D.h index 2b89b09777c79..ece88a512573a 100644 --- a/math/genvector/inc/Math/GenVector/Plane3D.h +++ b/math/genvector/inc/Math/GenVector/Plane3D.h @@ -31,297 +31,262 @@ namespace Math { namespace Impl { //_______________________________________________________________________________ - /** - Class describing a geometrical plane in 3 dimensions. - A Plane3D is a 2 dimensional surface spanned by two linearly independent vectors. - The plane is described by the equation - \f$ a*x + b*y + c*z + d = 0 \f$ where (a,b,c) are the components of the - normal vector to the plane \f$ n = (a,b,c) \f$ and \f$ d = - n \dot x \f$, where x is any point - belonging to plane. - More information on the mathematics describing a plane in 3D is available on - MathWord. - The Plane3D class contains the 4 scalar values in T which represent the - four coefficients, fA, fB, fC, fD. fA, fB, fC are the normal components normalized to 1, - i.e. fA**2 + fB**2 + fC**2 = 1 - - @ingroup GenVector - */ - - template - class Plane3D { - - public: +/** + Class describing a geometrical plane in 3 dimensions. + A Plane3D is a 2 dimensional surface spanned by two linearly independent vectors. + The plane is described by the equation + \f$ a*x + b*y + c*z + d = 0 \f$ where (a,b,c) are the components of the + normal vector to the plane \f$ n = (a,b,c) \f$ and \f$ d = - n \dot x \f$, where x is any point + belonging to plane. + More information on the mathematics describing a plane in 3D is available on + MathWord. + The Plane3D class contains the 4 scalar values in T which represent the + four coefficients, fA, fB, fC, fD. fA, fB, fC are the normal components normalized to 1, + i.e. fA**2 + fB**2 + fC**2 = 1 - // ------ ctors ------ + @ingroup GenVector +*/ - typedef T Scalar; +template +class Plane3D { - typedef DisplacementVector3D, DefaultCoordinateSystemTag > Vector; - typedef PositionVector3D, DefaultCoordinateSystemTag > Point; +public: + // ------ ctors ------ + typedef T Scalar; + typedef DisplacementVector3D, DefaultCoordinateSystemTag> Vector; + typedef PositionVector3D, DefaultCoordinateSystemTag> Point; - /** - default constructor create plane z = 0 - */ - Plane3D() : fA(0), fB(0), fC(1), fD(0) { } - - /** - generic constructors from the four scalar values describing the plane - according to the equation ax + by + cz + d = 0 - \param a scalar value - \param b scalar value - \param c scalar value - \param d sxcalar value - */ - Plane3D(const Scalar & a, const Scalar & b, const Scalar & c, const Scalar & d) - : fA(a), fB(b), fC(c), fD(d) - { - //renormalize a,b,c to unit - Normalize(); - } + /** + default constructor create plane z = 0 + */ + Plane3D() : fA(0), fB(0), fC(1), fD(0) {} + /** + generic constructors from the four scalar values describing the plane + according to the equation ax + by + cz + d = 0 + \param a scalar value + \param b scalar value + \param c scalar value + \param d sxcalar value + */ + Plane3D(const Scalar &a, const Scalar &b, const Scalar &c, const Scalar &d) : fA(a), fB(b), fC(c), fD(d) + { + // renormalize a,b,c to unit + Normalize(); + } - /** - constructor a Plane3D from a normal vector and a point coplanar to the plane - \param n normal expressed as a ROOT::Math::DisplacementVector3D > - \param p point expressed as a ROOT::Math::PositionVector3D > - */ - Plane3D(const Vector & n, const Point & p ) - { - BuildFromVecAndPoint( n, p ); - } + /** + constructor a Plane3D from a normal vector and a point coplanar to the plane + \param n normal expressed as a ROOT::Math::DisplacementVector3D > + \param p point expressed as a ROOT::Math::PositionVector3D > + */ + Plane3D(const Vector &n, const Point &p) { BuildFromVecAndPoint(n, p); } + /** + Construct from a generic DisplacementVector3D (normal vector) and PositionVector3D (point coplanar to + the plane) + \param n normal expressed as a generic ROOT::Math::DisplacementVector3D + \param p point expressed as a generic ROOT::Math::PositionVector3D + */ + template + Plane3D(const DisplacementVector3D &n, const PositionVector3D &p) + { + BuildFromVecAndPoint(Vector(n), Point(p)); + } - /** - Construct from a generic DisplacementVector3D (normal vector) and PositionVector3D (point coplanar to - the plane) - \param n normal expressed as a generic ROOT::Math::DisplacementVector3D - \param p point expressed as a generic ROOT::Math::PositionVector3D - */ - template - Plane3D( const DisplacementVector3D & n, const PositionVector3D & p ) - { - BuildFromVecAndPoint( Vector(n), Point(p) ); - } + /** + constructor from three Cartesian point belonging to the plane + \param p1 point1 expressed as a generic ROOT::Math::PositionVector3D + \param p2 point2 expressed as a generic ROOT::Math::PositionVector3D + \param p3 point3 expressed as a generic ROOT::Math::PositionVector3D + */ + Plane3D(const Point &p1, const Point &p2, const Point &p3) { BuildFrom3Points(p1, p2, p3); } - /** - constructor from three Cartesian point belonging to the plane - \param p1 point1 expressed as a generic ROOT::Math::PositionVector3D - \param p2 point2 expressed as a generic ROOT::Math::PositionVector3D - \param p3 point3 expressed as a generic ROOT::Math::PositionVector3D - */ - Plane3D(const Point & p1, const Point & p2, const Point & p3 ) { - BuildFrom3Points(p1,p2,p3); - } + /** + constructor from three generic point belonging to the plane + \param p1 point1 expressed as ROOT::Math::DisplacementVector3D > + \param p2 point2 expressed as ROOT::Math::DisplacementVector3D > + \param p3 point3 expressed as ROOT::Math::DisplacementVector3D > + */ + template + Plane3D(const PositionVector3D &p1, const PositionVector3D &p2, const PositionVector3D &p3) + { + BuildFrom3Points(Point(p1.X(), p1.Y(), p1.Z()), Point(p2.X(), p2.Y(), p2.Z()), Point(p3.X(), p3.Y(), p3.Z())); + } - /** - constructor from three generic point belonging to the plane - \param p1 point1 expressed as ROOT::Math::DisplacementVector3D > - \param p2 point2 expressed as ROOT::Math::DisplacementVector3D > - \param p3 point3 expressed as ROOT::Math::DisplacementVector3D > - */ - template - Plane3D( const PositionVector3D & p1, - const PositionVector3D & p2, - const PositionVector3D & p3 ) - { - BuildFrom3Points( Point(p1.X(), p1.Y(), p1.Z()), - Point(p2.X(), p2.Y(), p2.Z()), - Point(p3.X(), p3.Y(), p3.Z()) ); - } + // compiler-generated copy ctor and dtor are fine. + // ------ assignment ------ + /** + Assignment operator from other Plane3D class + */ + Plane3D &operator=(const Plane3D &plane) + { + fA = plane.fA; + fB = plane.fB; + fC = plane.fC; + fD = plane.fD; + return *this; + } - // compiler-generated copy ctor and dtor are fine. + /** + Return the a coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also the + x-component of the vector perpendicular to the plane. + */ + Scalar A() const { return fA; } - // ------ assignment ------ + /** + Return the b coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also the + y-component of the vector perpendicular to the plane + */ + Scalar B() const { return fB; } - /** - Assignment operator from other Plane3D class - */ - Plane3D & operator= ( const Plane3D & plane) { - fA = plane.fA; - fB = plane.fB; - fC = plane.fC; - fD = plane.fD; - return *this; - } + /** + Return the c coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also the + z-component of the vector perpendicular to the plane + */ + Scalar C() const { return fC; } - /** - Return the a coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also the - x-component of the vector perpendicular to the plane. - */ - Scalar A() const { return fA; } - - /** - Return the b coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also the - y-component of the vector perpendicular to the plane - */ - Scalar B() const { return fB; } - - /** - Return the c coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also the - z-component of the vector perpendicular to the plane - */ - Scalar C() const { return fC; } - - /** - Return the d coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also - the distance from the origin (HesseDistance) - */ - Scalar D() const { return fD; } - - /** - Return normal vector to the plane as Cartesian DisplacementVector - */ - Vector Normal() const { - return Vector(fA, fB, fC); - } + /** + Return the d coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also + the distance from the origin (HesseDistance) + */ + Scalar D() const { return fD; } - /** - Return the Hesse Distance (distance from the origin) of the plane or - the d coefficient expressed in normalize form - */ - Scalar HesseDistance() const { - return fD; - } + /** + Return normal vector to the plane as Cartesian DisplacementVector + */ + Vector Normal() const { return Vector(fA, fB, fC); } + /** + Return the Hesse Distance (distance from the origin) of the plane or + the d coefficient expressed in normalize form + */ + Scalar HesseDistance() const { return fD; } - /** - Return the signed distance to a Point. - The distance is signed positive if the Point is in the same side of the - normal vector to the plane. - \param p Point expressed in Cartesian Coordinates - */ - Scalar Distance(const Point & p) const - { - return fA*p.X() + fB*p.Y() + fC*p.Z() + fD; - } - - /** - Return the distance to a Point described with generic coordinates - \param p Point expressed as generic ROOT::Math::PositionVector3D - */ - template - Scalar Distance(const PositionVector3D & p) const { - return Distance( Point(p.X(), p.Y(), p.Z() ) ); - } + /** + Return the signed distance to a Point. + The distance is signed positive if the Point is in the same side of the + normal vector to the plane. + \param p Point expressed in Cartesian Coordinates + */ + Scalar Distance(const Point &p) const { return fA * p.X() + fB * p.Y() + fC * p.Z() + fD; } - /** - Return the projection of a Cartesian point to a plane - \param p Point expressed as PositionVector3D > - */ - Point ProjectOntoPlane(const Point & p) const - { - const Scalar d = Distance(p); - return XYZPoint( p.X() - fA*d, p.Y() - fB*d, p.Z() - fC*d ); - } + /** + Return the distance to a Point described with generic coordinates + \param p Point expressed as generic ROOT::Math::PositionVector3D + */ + template + Scalar Distance(const PositionVector3D &p) const + { + return Distance(Point(p.X(), p.Y(), p.Z())); + } - /** - Return the projection of a point to a plane - \param p Point expressed as generic ROOT::Math::PositionVector3D - */ - template - PositionVector3D ProjectOntoPlane(const PositionVector3D & p) const { - const Point pxyz = ProjectOntoPlane( Point( p.X(), p.Y(), p.Z() ) ); - return PositionVector3D( pxyz.X(), pxyz.Y(), pxyz.Z() ); - } + /** + Return the projection of a Cartesian point to a plane + \param p Point expressed as PositionVector3D > + */ + Point ProjectOntoPlane(const Point &p) const + { + const Scalar d = Distance(p); + return XYZPoint(p.X() - fA * d, p.Y() - fB * d, p.Z() - fC * d); + } + /** + Return the projection of a point to a plane + \param p Point expressed as generic ROOT::Math::PositionVector3D + */ + template + PositionVector3D ProjectOntoPlane(const PositionVector3D &p) const + { + const Point pxyz = ProjectOntoPlane(Point(p.X(), p.Y(), p.Z())); + return PositionVector3D(pxyz.X(), pxyz.Y(), pxyz.Z()); + } + // ------------------- Equality ----------------- - // ------------------- Equality ----------------- + /** + Exact equality + */ + bool operator==(const Plane3D &rhs) const { return (fA == rhs.fA && fB == rhs.fB && fC == rhs.fC && fD == rhs.fD); } + bool operator!=(const Plane3D &rhs) const { return !(operator==(rhs)); } - /** - Exact equality - */ - bool operator==(const Plane3D & rhs) const { - return ( fA == rhs.fA && - fB == rhs.fB && - fC == rhs.fC && - fD == rhs.fD ); - } - bool operator!= (const Plane3D & rhs) const { - return !(operator==(rhs)); +protected: + /** + Normalize the normal (a,b,c) plane components + */ + template + typename std::enable_if::value, void>::type Normalize() + { + // normalize the plane + const SCALAR s = std::sqrt(fA * fA + fB * fB + fC * fC); + // what to do if s = 0 ? + if (s == SCALAR(0)) { + fD = SCALAR(0); + } else { + const SCALAR w = Scalar(1) / s; + fA *= w; + fB *= w; + fC *= w; + fD *= w; } + } - protected: - - /** - Normalize the normal (a,b,c) plane components - */ - template< typename SCALAR = T > - typename std::enable_if< std::is_arithmetic::value, void >::type - Normalize() - { - // normalize the plane - const SCALAR s = std::sqrt( fA*fA + fB*fB + fC*fC ); - // what to do if s = 0 ? - if ( s == SCALAR(0) ) { fD = SCALAR(0); } - else - { - const SCALAR w = Scalar(1)/s; - fA *= w; - fB *= w; - fC *= w; - fD *= w; - } - } + /** + Normalize the normal (a,b,c) plane components + */ + template + typename std::enable_if::value, void>::type Normalize() + { + // normalize the plane + SCALAR s = sqrt(fA * fA + fB * fB + fC * fC); + // what to do if s = 0 ? + const auto m = (s == SCALAR(0)); + // set zero entries to 1 in the vector to avoid /0 later on + s(m) = SCALAR(1); + fD(m) = SCALAR(0); + const SCALAR w = SCALAR(1) / s; + fA *= w; + fB *= w; + fC *= w; + fD *= w; + } - /** - Normalize the normal (a,b,c) plane components - */ - template< typename SCALAR = T > - typename std::enable_if< !std::is_arithmetic::value, void >::type - Normalize() - { - // normalize the plane - SCALAR s = sqrt( fA*fA + fB*fB + fC*fC ); - // what to do if s = 0 ? - const auto m = ( s == SCALAR(0) ); - // set zero entries to 1 in the vector to avoid /0 later on - s(m) = SCALAR(1); - fD(m) = SCALAR(0); - const SCALAR w = SCALAR(1)/s; - fA *= w; - fB *= w; - fC *= w; - fD *= w; - } +private: + // internal method to construct class from a vector and a point + void BuildFromVecAndPoint(const Vector &n, const Point &p) + { + // build from a normal vector and a point + fA = n.X(); + fB = n.Y(); + fC = n.Z(); + fD = -n.Dot(p); + Normalize(); + } - private: - - // internal method to construct class from a vector and a point - void BuildFromVecAndPoint(const Vector & n, const Point & p) - { - // build from a normal vector and a point - fA = n.X(); - fB = n.Y(); - fC = n.Z(); - fD = - n.Dot(p); - Normalize(); - } - - // internal method to construct class from 3 points - void BuildFrom3Points(const Point & p1, const Point & p2, const Point & p3) - { - // plane from thre points - // normal is (x3-x1) cross (x2 -x1) - const Vector n = (p2-p1).Cross(p3-p1); - fA = n.X(); - fB = n.Y(); - fC = n.Z(); - fD = - n.Dot(p1); - Normalize(); - } - - // plane data members the four scalar which satisfies fA*x + fB*y + fC*z + fD = 0 - // for every point (x,y,z) belonging to the plane. - // fA**2 + fB**2 + fC** =1 plane is stored in normalized form - Scalar fA; - Scalar fB; - Scalar fC; - Scalar fD; + // internal method to construct class from 3 points + void BuildFrom3Points(const Point &p1, const Point &p2, const Point &p3) + { + // plane from thre points + // normal is (x3-x1) cross (x2 -x1) + const Vector n = (p2 - p1).Cross(p3 - p1); + fA = n.X(); + fB = n.Y(); + fC = n.Z(); + fD = -n.Dot(p1); + Normalize(); + } + + // plane data members the four scalar which satisfies fA*x + fB*y + fC*z + fD = 0 + // for every point (x,y,z) belonging to the plane. + // fA**2 + fB**2 + fC** =1 plane is stored in normalized form + Scalar fA; + Scalar fB; + Scalar fC; + Scalar fD; }; // Plane3D<> @@ -330,23 +295,20 @@ namespace Impl { Stream Output and Input */ // TODO - I/O should be put in the manipulator form - template < typename T > - std::ostream & operator<< (std::ostream & os, const Plane3D & p) + template + std::ostream &operator<<(std::ostream &os, const Plane3D &p) { - os << "\n" << p.Normal().X() - << " " << p.Normal().Y() - << " " << p.Normal().Z() - << " " << p.HesseDistance() - << "\n"; - return os; + os << "\n" + << p.Normal().X() << " " << p.Normal().Y() << " " << p.Normal().Z() << " " << p.HesseDistance() << "\n"; + return os; } -} // end namespace Impl + } // end namespace Impl + + // typedefs for double and float versions + typedef Impl::Plane3D Plane3D; + typedef Impl::Plane3D Plane3DF; -// typedefs for double and float versions -typedef Impl::Plane3D Plane3D; -typedef Impl::Plane3D Plane3DF; - } // end namespace Math } // end namespace ROOT diff --git a/math/genvector/inc/Math/GenVector/PositionVector3D.h b/math/genvector/inc/Math/GenVector/PositionVector3D.h index f9ea49af97986..b7fb47c85e24b 100644 --- a/math/genvector/inc/Math/GenVector/PositionVector3D.h +++ b/math/genvector/inc/Math/GenVector/PositionVector3D.h @@ -227,13 +227,13 @@ namespace ROOT { */ template void GetCoordinates( IT begin ) const { - Scalar a = Scalar(0); - Scalar b = Scalar(0); - Scalar c = Scalar(0); - GetCoordinates (a,b,c); - *begin++ = a; - *begin++ = b; - *begin = c; + Scalar a = Scalar(0); + Scalar b = Scalar(0); + Scalar c = Scalar(0); + GetCoordinates(a, b, c); + *begin++ = a; + *begin++ = b; + *begin = c; } /** @@ -577,56 +577,47 @@ namespace ROOT { // ------------- I/O to/from streams ------------- - template< class char_t, class traits_t, class T, class U > - inline - typename std::enable_if< std::is_arithmetic::Scalar>::value, - std::basic_ostream & >::type - operator << ( std::basic_ostream & os - , PositionVector3D const & v - ) + template + inline typename std::enable_if::Scalar>::value, + std::basic_ostream &>::type + operator<<(std::basic_ostream &os, PositionVector3D const &v) { - if ( os ) { - - typename T::Scalar a = 0; - typename T::Scalar b = 0; - typename T::Scalar c = 0; - v.GetCoordinates(a, b, c); - - if( detail::get_manip( os, detail::bitforbit ) ) { - detail::set_manip( os, detail::bitforbit, '\00' ); - typedef GenVector_detail::BitReproducible BR; - BR::Output(os, a); - BR::Output(os, b); - BR::Output(os, c); - } - else { - os << detail::get_manip( os, detail::open ) << a - << detail::get_manip( os, detail::sep ) << b - << detail::get_manip( os, detail::sep ) << c - << detail::get_manip( os, detail::close ); - } + if (os) { + + typename T::Scalar a = 0; + typename T::Scalar b = 0; + typename T::Scalar c = 0; + v.GetCoordinates(a, b, c); + + if (detail::get_manip(os, detail::bitforbit)) { + detail::set_manip(os, detail::bitforbit, '\00'); + typedef GenVector_detail::BitReproducible BR; + BR::Output(os, a); + BR::Output(os, b); + BR::Output(os, c); + } else { + os << detail::get_manip(os, detail::open) << a << detail::get_manip(os, detail::sep) << b + << detail::get_manip(os, detail::sep) << c << detail::get_manip(os, detail::close); + } } return os; } // op<< <>() - template< class char_t, class traits_t, class T, class U > - inline - typename std::enable_if< !std::is_arithmetic::Scalar>::value, - std::basic_ostream & >::type - operator << ( std::basic_ostream & os - , PositionVector3D const & v - ) + template + inline typename std::enable_if::Scalar>::value, + std::basic_ostream &>::type + operator<<(std::basic_ostream &os, PositionVector3D const &v) { - if ( os ) { - os << "{ "; - for ( std::size_t i = 0; i < PositionVector3D::Scalar::Size; ++i ) { - os << "(" << v.x()[i] << "," << v.y()[i] << "," << v.z()[i] << ") "; - } - os << "}"; - } - return os; - } // op<< <>() - + if (os) { + os << "{ "; + for (std::size_t i = 0; i < PositionVector3D::Scalar::Size; ++i) { + os << "(" << v.x()[i] << "," << v.y()[i] << "," << v.z()[i] << ") "; + } + os << "}"; + } + return os; + } // op<< <>() + template< class char_t, class traits_t, class T, class U > inline std::basic_istream & diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index 59f12c4e0b163..4347ac496243c 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -48,7 +48,6 @@ namespace Math { namespace Impl { - //_________________________________________________________________________________________ /** Basic 3D Transformation class describing a rotation and then a translation @@ -77,14 +76,11 @@ namespace Impl { template class Transform3D { - public: - typedef T Scalar; - typedef DisplacementVector3D, DefaultCoordinateSystemTag > Vector; - typedef PositionVector3D, DefaultCoordinateSystemTag > Point; - + typedef DisplacementVector3D, DefaultCoordinateSystemTag> Vector; + typedef PositionVector3D, DefaultCoordinateSystemTag> Point; enum ETransform3DMatrixIndex { kXX = 0, kXY = 1, kXZ = 2, kDX = 3, @@ -122,10 +118,7 @@ class Transform3D { /** Construct from a rotation and then a translation described by a Translation3D class */ - Transform3D( const Rotation3D & r, const Translation3D & t) - { - AssignFrom( r, t.Vect() ); - } + Transform3D(const Rotation3D &r, const Translation3D &t) { AssignFrom(r, t.Vect()); } /** Construct from a rotation (any rotation object) and then a translation @@ -146,7 +139,7 @@ class Transform3D { Rotation3D class */ template - Transform3D( const ARotation & r, const Translation3D & t) + Transform3D(const ARotation &r, const Translation3D &t) { AssignFrom( Rotation3D(r), t.Vect() ); } @@ -217,11 +210,7 @@ class Transform3D { Construct from a translation only, represented by a Translation3D class and with an identity rotation */ - explicit Transform3D( const Translation3D & t) { - AssignFrom(t.Vect()); - } - - + explicit Transform3D(const Translation3D &t) { AssignFrom(t.Vect()); } //#if !defined(__MAKECINT__) && !defined(G__DICTIONARY) // this is ambigous with double * , double * @@ -243,7 +232,6 @@ class Transform3D { #endif public: - /** Construct transformation from one coordinate system defined by three points (origin + two axis) to @@ -256,80 +244,86 @@ class Transform3D { @param to1 point defining first axis transformed reference system @param to2 point defining second axis transformed reference system */ - template < typename SCALAR = T > - Transform3D - ( const Point & fr0, const Point & fr1, const Point & fr2, - const Point & to0, const Point & to1, const Point & to2, - typename std::enable_if::value>::type* = nullptr ) + template + Transform3D(const Point &fr0, const Point &fr1, const Point &fr2, const Point &to0, const Point &to1, + const Point &to2, typename std::enable_if::value>::type * = nullptr) { - // takes impl. from CLHEP ( E.Chernyaev). To be checked - - Vector x1 = (fr1 - fr0).Unit(); - Vector y1 = (fr2 - fr0).Unit(); - Vector x2 = (to1 - to0).Unit(); - Vector y2 = (to2 - to0).Unit(); - - // C H E C K A N G L E S - - const T cos1 = x1.Dot(y1); - const T cos2 = x2.Dot(y2); - - if ( std::fabs( T(1) - cos1 ) <= T(0.000001) || - std::fabs( T(1) - cos2 ) <= T(0.000001) ) { - std::cerr << "Transform3D: Error : zero angle between axes" << std::endl; - SetIdentity(); - } else { - if ( std::fabs(cos1-cos2) > T(0.000001) ) { - std::cerr << "Transform3D: Warning: angles between axes are not equal" - << std::endl; - } - - // F I N D R O T A T I O N M A T R I X - - Vector z1 = (x1.Cross(y1)).Unit(); - y1 = z1.Cross(x1); - - Vector z2 = (x2.Cross(y2)).Unit(); - y2 = z2.Cross(x2); - - T x1x = x1.x(); T x1y = x1.y(); T x1z = x1.z(); - T y1x = y1.x(); T y1y = y1.y(); T y1z = y1.z(); - T z1x = z1.x(); T z1y = z1.y(); T z1z = z1.z(); - - T x2x = x2.x(); T x2y = x2.y(); T x2z = x2.z(); - T y2x = y2.x(); T y2y = y2.y(); T y2z = y2.z(); - T z2x = z2.x(); T z2y = z2.y(); T z2z = z2.z(); - - T detxx = (y1y *z1z - z1y *y1z ); - T detxy = -(y1x *z1z - z1x *y1z ); - T detxz = (y1x *z1y - z1x *y1y ); - T detyx = -(x1y *z1z - z1y *x1z ); - T detyy = (x1x *z1z - z1x *x1z ); - T detyz = -(x1x *z1y - z1x *x1y ); - T detzx = (x1y *y1z - y1y *x1z ); - T detzy = -(x1x *y1z - y1x *x1z ); - T detzz = (x1x *y1y - y1x *x1y ); - - T txx = x2x *detxx + y2x *detyx + z2x *detzx; - T txy = x2x *detxy + y2x *detyy + z2x *detzy; - T txz = x2x *detxz + y2x *detyz + z2x *detzz; - T tyx = x2y *detxx + y2y *detyx + z2y *detzx; - T tyy = x2y *detxy + y2y *detyy + z2y *detzy; - T tyz = x2y *detxz + y2y *detyz + z2y *detzz; - T tzx = x2z *detxx + y2z *detyx + z2z *detzx; - T tzy = x2z *detxy + y2z *detyy + z2z *detzy; - T tzz = x2z *detxz + y2z *detyz + z2z *detzz; - - // S E T T R A N S F O R M A T I O N - - T dx1 = fr0.x(), dy1 = fr0.y(), dz1 = fr0.z(); - T dx2 = to0.x(), dy2 = to0.y(), dz2 = to0.z(); - - SetComponents(txx, txy, txz, dx2-txx*dx1-txy*dy1-txz*dz1, - tyx, tyy, tyz, dy2-tyx*dx1-tyy*dy1-tyz*dz1, - tzx, tzy, tzz, dz2-tzx*dx1-tzy*dy1-tzz*dz1); - - } + // takes impl. from CLHEP ( E.Chernyaev). To be checked + + Vector x1 = (fr1 - fr0).Unit(); + Vector y1 = (fr2 - fr0).Unit(); + Vector x2 = (to1 - to0).Unit(); + Vector y2 = (to2 - to0).Unit(); + + // C H E C K A N G L E S + + const T cos1 = x1.Dot(y1); + const T cos2 = x2.Dot(y2); + + if (std::fabs(T(1) - cos1) <= T(0.000001) || std::fabs(T(1) - cos2) <= T(0.000001)) { + std::cerr << "Transform3D: Error : zero angle between axes" << std::endl; + SetIdentity(); + } else { + if (std::fabs(cos1 - cos2) > T(0.000001)) { + std::cerr << "Transform3D: Warning: angles between axes are not equal" << std::endl; + } + + // F I N D R O T A T I O N M A T R I X + + Vector z1 = (x1.Cross(y1)).Unit(); + y1 = z1.Cross(x1); + + Vector z2 = (x2.Cross(y2)).Unit(); + y2 = z2.Cross(x2); + + T x1x = x1.x(); + T x1y = x1.y(); + T x1z = x1.z(); + T y1x = y1.x(); + T y1y = y1.y(); + T y1z = y1.z(); + T z1x = z1.x(); + T z1y = z1.y(); + T z1z = z1.z(); + + T x2x = x2.x(); + T x2y = x2.y(); + T x2z = x2.z(); + T y2x = y2.x(); + T y2y = y2.y(); + T y2z = y2.z(); + T z2x = z2.x(); + T z2y = z2.y(); + T z2z = z2.z(); + + T detxx = (y1y * z1z - z1y * y1z); + T detxy = -(y1x * z1z - z1x * y1z); + T detxz = (y1x * z1y - z1x * y1y); + T detyx = -(x1y * z1z - z1y * x1z); + T detyy = (x1x * z1z - z1x * x1z); + T detyz = -(x1x * z1y - z1x * x1y); + T detzx = (x1y * y1z - y1y * x1z); + T detzy = -(x1x * y1z - y1x * x1z); + T detzz = (x1x * y1y - y1x * x1y); + + T txx = x2x * detxx + y2x * detyx + z2x * detzx; + T txy = x2x * detxy + y2x * detyy + z2x * detzy; + T txz = x2x * detxz + y2x * detyz + z2x * detzz; + T tyx = x2y * detxx + y2y * detyx + z2y * detzx; + T tyy = x2y * detxy + y2y * detyy + z2y * detzy; + T tyz = x2y * detxz + y2y * detyz + z2y * detzz; + T tzx = x2z * detxx + y2z * detyx + z2z * detzx; + T tzy = x2z * detxy + y2z * detyy + z2z * detzy; + T tzz = x2z * detxz + y2z * detyz + z2z * detzz; + + // S E T T R A N S F O R M A T I O N + + T dx1 = fr0.x(), dy1 = fr0.y(), dz1 = fr0.z(); + T dx2 = to0.x(), dy2 = to0.y(), dz2 = to0.z(); + + SetComponents(txx, txy, txz, dx2 - txx * dx1 - txy * dy1 - txz * dz1, tyx, tyy, tyz, + dy2 - tyx * dx1 - tyy * dy1 - tyz * dz1, tzx, tzy, tzz, dz2 - tzx * dx1 - tzy * dy1 - tzz * dz1); + } } /** @@ -344,84 +338,89 @@ class Transform3D { @param to1 point defining first axis transformed reference system @param to2 point defining second axis transformed reference system */ - template < typename SCALAR = T > - Transform3D - ( const Point & fr0, const Point & fr1, const Point & fr2, - const Point & to0, const Point & to1, const Point & to2, - typename std::enable_if::value>::type* = nullptr ) + template + Transform3D(const Point &fr0, const Point &fr1, const Point &fr2, const Point &to0, const Point &to1, + const Point &to2, typename std::enable_if::value>::type * = nullptr) { - // takes impl. from CLHEP ( E.Chernyaev). To be checked - - Vector x1 = (fr1 - fr0).Unit(); - Vector y1 = (fr2 - fr0).Unit(); - Vector x2 = (to1 - to0).Unit(); - Vector y2 = (to2 - to0).Unit(); - - // C H E C K A N G L E S - - const T cos1 = x1.Dot(y1); - const T cos2 = x2.Dot(y2); - - const auto m1 = ( abs( T(1) - cos1 ) <= T(0.000001) || - abs( T(1) - cos2 ) <= T(0.000001) ); - - const auto m2 = ( abs(cos1-cos2) > T(0.000001) ); - if ( any_of(m2) ) { - std::cerr << "Transform3D: Warning: angles between axes are not equal" - << std::endl; - } - - // F I N D R O T A T I O N M A T R I X - - Vector z1 = (x1.Cross(y1)).Unit(); - y1 = z1.Cross(x1); - - Vector z2 = (x2.Cross(y2)).Unit(); - y2 = z2.Cross(x2); - - T x1x = x1.x(); T x1y = x1.y(); T x1z = x1.z(); - T y1x = y1.x(); T y1y = y1.y(); T y1z = y1.z(); - T z1x = z1.x(); T z1y = z1.y(); T z1z = z1.z(); - - T x2x = x2.x(); T x2y = x2.y(); T x2z = x2.z(); - T y2x = y2.x(); T y2y = y2.y(); T y2z = y2.z(); - T z2x = z2.x(); T z2y = z2.y(); T z2z = z2.z(); - - T detxx = (y1y *z1z - z1y *y1z ); - T detxy = -(y1x *z1z - z1x *y1z ); - T detxz = (y1x *z1y - z1x *y1y ); - T detyx = -(x1y *z1z - z1y *x1z ); - T detyy = (x1x *z1z - z1x *x1z ); - T detyz = -(x1x *z1y - z1x *x1y ); - T detzx = (x1y *y1z - y1y *x1z ); - T detzy = -(x1x *y1z - y1x *x1z ); - T detzz = (x1x *y1y - y1x *x1y ); - - T txx = x2x *detxx + y2x *detyx + z2x *detzx; - T txy = x2x *detxy + y2x *detyy + z2x *detzy; - T txz = x2x *detxz + y2x *detyz + z2x *detzz; - T tyx = x2y *detxx + y2y *detyx + z2y *detzx; - T tyy = x2y *detxy + y2y *detyy + z2y *detzy; - T tyz = x2y *detxz + y2y *detyz + z2y *detzz; - T tzx = x2z *detxx + y2z *detyx + z2z *detzx; - T tzy = x2z *detxy + y2z *detyy + z2z *detzy; - T tzz = x2z *detxz + y2z *detyz + z2z *detzz; - - // S E T T R A N S F O R M A T I O N - - T dx1 = fr0.x(), dy1 = fr0.y(), dz1 = fr0.z(); - T dx2 = to0.x(), dy2 = to0.y(), dz2 = to0.z(); - - SetComponents(txx, txy, txz, dx2-txx*dx1-txy*dy1-txz*dz1, - tyx, tyy, tyz, dy2-tyx*dx1-tyy*dy1-tyz*dz1, - tzx, tzy, tzz, dz2-tzx*dx1-tzy*dy1-tzz*dz1); - - if ( any_of(m1) ) - { - std::cerr << "Transform3D: Error : zero angle between axes" << std::endl; - SetIdentity(m1); - } - + // takes impl. from CLHEP ( E.Chernyaev). To be checked + + Vector x1 = (fr1 - fr0).Unit(); + Vector y1 = (fr2 - fr0).Unit(); + Vector x2 = (to1 - to0).Unit(); + Vector y2 = (to2 - to0).Unit(); + + // C H E C K A N G L E S + + const T cos1 = x1.Dot(y1); + const T cos2 = x2.Dot(y2); + + const auto m1 = (abs(T(1) - cos1) <= T(0.000001) || abs(T(1) - cos2) <= T(0.000001)); + + const auto m2 = (abs(cos1 - cos2) > T(0.000001)); + if (any_of(m2)) { + std::cerr << "Transform3D: Warning: angles between axes are not equal" << std::endl; + } + + // F I N D R O T A T I O N M A T R I X + + Vector z1 = (x1.Cross(y1)).Unit(); + y1 = z1.Cross(x1); + + Vector z2 = (x2.Cross(y2)).Unit(); + y2 = z2.Cross(x2); + + T x1x = x1.x(); + T x1y = x1.y(); + T x1z = x1.z(); + T y1x = y1.x(); + T y1y = y1.y(); + T y1z = y1.z(); + T z1x = z1.x(); + T z1y = z1.y(); + T z1z = z1.z(); + + T x2x = x2.x(); + T x2y = x2.y(); + T x2z = x2.z(); + T y2x = y2.x(); + T y2y = y2.y(); + T y2z = y2.z(); + T z2x = z2.x(); + T z2y = z2.y(); + T z2z = z2.z(); + + T detxx = (y1y * z1z - z1y * y1z); + T detxy = -(y1x * z1z - z1x * y1z); + T detxz = (y1x * z1y - z1x * y1y); + T detyx = -(x1y * z1z - z1y * x1z); + T detyy = (x1x * z1z - z1x * x1z); + T detyz = -(x1x * z1y - z1x * x1y); + T detzx = (x1y * y1z - y1y * x1z); + T detzy = -(x1x * y1z - y1x * x1z); + T detzz = (x1x * y1y - y1x * x1y); + + T txx = x2x * detxx + y2x * detyx + z2x * detzx; + T txy = x2x * detxy + y2x * detyy + z2x * detzy; + T txz = x2x * detxz + y2x * detyz + z2x * detzz; + T tyx = x2y * detxx + y2y * detyx + z2y * detzx; + T tyy = x2y * detxy + y2y * detyy + z2y * detzy; + T tyz = x2y * detxz + y2y * detyz + z2y * detzz; + T tzx = x2z * detxx + y2z * detyx + z2z * detzx; + T tzy = x2z * detxy + y2z * detyy + z2z * detzy; + T tzz = x2z * detxz + y2z * detyz + z2z * detzz; + + // S E T T R A N S F O R M A T I O N + + T dx1 = fr0.x(), dy1 = fr0.y(), dz1 = fr0.z(); + T dx2 = to0.x(), dy2 = to0.y(), dz2 = to0.z(); + + SetComponents(txx, txy, txz, dx2 - txx * dx1 - txy * dy1 - txz * dz1, tyx, tyy, tyz, + dy2 - tyx * dx1 - tyy * dy1 - tyz * dz1, tzx, tzy, tzz, dz2 - tzx * dx1 - tzy * dy1 - tzz * dz1); + + if (any_of(m1)) { + std::cerr << "Transform3D: Error : zero angle between axes" << std::endl; + SetIdentity(m1); + } } // use compiler generated copy ctor, copy assignmet and dtor @@ -440,9 +439,7 @@ class Transform3D { /** Raw constructor from 12 Scalar components */ - Transform3D(T xx, T xy, T xz, T dx, - T yx, T yy, T yz, T dy, - T zx, T zy, T zz, T dz) + Transform3D(T xx, T xy, T xz, T dx, T yx, T yy, T yz, T dy, T zx, T zy, T zz, T dz) { SetComponents (xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz); } @@ -454,8 +451,9 @@ class Transform3D { The 3x3 sub-block is assumed to be the rotation part and the translations vector are described by the 4-th column */ - template - Transform3D & operator= (const ForeignMatrix & m) { + template + Transform3D &operator=(const ForeignMatrix &m) + { SetComponents(m); return *this; } @@ -504,7 +502,7 @@ class Transform3D { template void GetComponents(IT begin) const { using namespace std; - copy ( fM, fM+12, begin ); + copy(fM, fM + 12, begin); } /** @@ -538,10 +536,8 @@ class Transform3D { /** Set the components from 12 scalars */ - void - SetComponents (T xx, T xy, T xz, T dx, - T yx, T yy, T yz, T dy, - T zx, T zy, T zz, T dz) { + void SetComponents(T xx, T xy, T xz, T dx, T yx, T yy, T yz, T dy, T zx, T zy, T zz, T dz) + { fM[kXX]=xx; fM[kXY]=xy; fM[kXZ]=xz; fM[kDX]=dx; fM[kYX]=yx; fM[kYY]=yy; fM[kYZ]=yz; fM[kDY]=dy; fM[kZX]=zx; fM[kZY]=zy; fM[kZZ]=zz; fM[kDZ]=dz; @@ -550,10 +546,8 @@ class Transform3D { /** Get the components into 12 scalars */ - void - GetComponents (T &xx, T &xy, T &xz, T &dx, - T &yx, T &yy, T &yz, T &dy, - T &zx, T &zy, T &zz, T &dz) const { + void GetComponents(T &xx, T &xy, T &xz, T &dx, T &yx, T &yy, T &yz, T &dy, T &zx, T &zy, T &zz, T &dz) const + { xx=fM[kXX]; xy=fM[kXY]; xz=fM[kXZ]; dx=fM[kDX]; yx=fM[kYX]; yy=fM[kYY]; yz=fM[kYZ]; dy=fM[kDY]; zx=fM[kZX]; zy=fM[kZY]; zz=fM[kZZ]; dz=fM[kDZ]; @@ -593,9 +587,7 @@ class Transform3D { */ template AnyRotation Rotation() const { - return AnyRotation( Rotation3D( fM[kXX], fM[kXY], fM[kXZ], - fM[kYX], fM[kYY], fM[kYZ], - fM[kZX], fM[kZY], fM[kZZ] ) ); + return AnyRotation(Rotation3D(fM[kXX], fM[kXY], fM[kXZ], fM[kYX], fM[kYY], fM[kYZ], fM[kZX], fM[kZY], fM[kZZ])); } /** @@ -609,9 +601,7 @@ class Transform3D { /** Get the translation representing the 3D transformation in a Cartesian vector */ - Translation3D Translation() const { - return Translation3D( fM[kDX], fM[kDY], fM[kDZ] ); - } + Translation3D Translation() const { return Translation3D(fM[kDX], fM[kDY], fM[kDZ]); } /** Get the translation representing the 3D transformation in any vector @@ -651,40 +641,43 @@ class Transform3D { /** Transformation operation for Position Vector in any coordinate system */ - template - PositionVector3D operator() (const PositionVector3D & p) const { - return PositionVector3D ( operator() ( Point(p) ) ); + template + PositionVector3D operator()(const PositionVector3D &p) const + { + return PositionVector3D(operator()(Point(p))); } /** Transformation operation for Position Vector in any coordinate system */ - template - PositionVector3D operator * ( const PositionVector3D& v ) const { - return operator() (v); + template + PositionVector3D operator*(const PositionVector3D &v) const + { + return operator()(v); } - + /** Transformation operation for Displacement Vector in any coordinate system */ template DisplacementVector3D operator() (const DisplacementVector3D & v) const { - return DisplacementVector3D ( operator() ( Vector(v) ) ); + return DisplacementVector3D(operator()(Vector(v))); } /** Transformation operation for Displacement Vector in any coordinate system */ - template - DisplacementVector3D operator * (const DisplacementVector3D & v) const { - return operator() (v); + template + DisplacementVector3D operator*(const DisplacementVector3D &v) const + { + return operator()(v); } - + /** Transformation operation for points between different coordinate system tags */ - template - void Transform (const PositionVector3D & p1, - PositionVector3D & p2 ) const { - const Point xyzNew = operator() ( Point(p1.X(), p1.Y(), p1.Z()) ); + template + void Transform(const PositionVector3D &p1, PositionVector3D &p2) const + { + const Point xyzNew = operator()(Point(p1.X(), p1.Y(), p1.Z())); p2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() ); } @@ -692,10 +685,10 @@ class Transform3D { /** Transformation operation for Displacement Vector of different coordinate systems */ - template - void Transform (const DisplacementVector3D & v1, - DisplacementVector3D & v2 ) const { - const Vector xyzNew = operator() ( Vector(v1.X(), v1.Y(), v1.Z() ) ); + template + void Transform(const DisplacementVector3D &v1, DisplacementVector3D &v2) const + { + const Vector xyzNew = operator()(Vector(v1.X(), v1.Y(), v1.Z())); v2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() ); } @@ -704,29 +697,30 @@ class Transform3D { */ template LorentzVector operator() (const LorentzVector & q) const { - const Vector xyzNew = operator() ( Vector(q.Vect() ) ); - return LorentzVector ( xyzNew.X(), xyzNew.Y(), xyzNew.Z(), q.E() ); + const Vector xyzNew = operator()(Vector(q.Vect())); + return LorentzVector(xyzNew.X(), xyzNew.Y(), xyzNew.Z(), q.E()); } /** Transformation operation for a Lorentz Vector in any coordinate system */ - template - LorentzVector operator * (const LorentzVector & q) const { - return operator() (q); + template + LorentzVector operator*(const LorentzVector &q) const + { + return operator()(q); } /** Transformation on a 3D plane */ - Plane3D operator() (const Plane3D & plane) const + Plane3D operator()(const Plane3D &plane) const { - // transformations on a 3D plane - const Vector n = plane.Normal(); - // take a point on the plane. Use origin projection on the plane - // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1 - const T d = plane.HesseDistance(); - Point p( - d * n.X() , - d *n.Y(), -d *n.Z() ); - return Plane3D( operator() (n), operator() (p) ); + // transformations on a 3D plane + const Vector n = plane.Normal(); + // take a point on the plane. Use origin projection on the plane + // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1 + const T d = plane.HesseDistance(); + Point p(-d * n.X(), -d * n.Y(), -d * n.Z()); + return Plane3D(operator()(n), operator()(p)); } // skip transformation for arbitrary vectors - not really defined if point or displacement vectors @@ -734,230 +728,239 @@ class Transform3D { /** multiply (combine) with another transformation in place */ - inline Transform3D & operator *= (const Transform3D & t); + inline Transform3D &operator*=(const Transform3D &t); /** multiply (combine) two transformations */ - inline Transform3D operator * (const Transform3D & t) const; + inline Transform3D operator*(const Transform3D &t) const; /** Invert the transformation in place (scalar) */ - template< typename SCALAR = T > - typename std::enable_if< std::is_arithmetic::value, void >::type - Invert() + template + typename std::enable_if::value, void>::type Invert() { - // - // Name: Transform3D::inverse Date: 24.09.96 - // Author: E.Chernyaev (IHEP/Protvino) Revised: - // - // Function: Find inverse affine transformation. - - T detxx = fM[kYY]*fM[kZZ] - fM[kYZ]*fM[kZY]; - T detxy = fM[kYX]*fM[kZZ] - fM[kYZ]*fM[kZX]; - T detxz = fM[kYX]*fM[kZY] - fM[kYY]*fM[kZX]; - T det = fM[kXX]*detxx - fM[kXY]*detxy + fM[kXZ]*detxz; - if ( det == T(0) ) { - std::cerr << "Transform3D::inverse error: zero determinant" << std::endl; - return; - } - det = T(1)/det; - detxx *= det; detxy *= det; detxz *= det; - T detyx = (fM[kXY]*fM[kZZ] - fM[kXZ]*fM[kZY] )*det; - T detyy = (fM[kXX]*fM[kZZ] - fM[kXZ]*fM[kZX] )*det; - T detyz = (fM[kXX]*fM[kZY] - fM[kXY]*fM[kZX] )*det; - T detzx = (fM[kXY]*fM[kYZ] - fM[kXZ]*fM[kYY] )*det; - T detzy = (fM[kXX]*fM[kYZ] - fM[kXZ]*fM[kYX] )*det; - T detzz = (fM[kXX]*fM[kYY] - fM[kXY]*fM[kYX] )*det; - SetComponents - ( detxx, -detyx, detzx, -detxx*fM[kDX]+detyx*fM[kDY]-detzx*fM[kDZ], - -detxy, detyy, -detzy, detxy*fM[kDX]-detyy*fM[kDY]+detzy*fM[kDZ], - detxz, -detyz, detzz, -detxz*fM[kDX]+detyz*fM[kDY]-detzz*fM[kDZ] ); + // + // Name: Transform3D::inverse Date: 24.09.96 + // Author: E.Chernyaev (IHEP/Protvino) Revised: + // + // Function: Find inverse affine transformation. + + T detxx = fM[kYY] * fM[kZZ] - fM[kYZ] * fM[kZY]; + T detxy = fM[kYX] * fM[kZZ] - fM[kYZ] * fM[kZX]; + T detxz = fM[kYX] * fM[kZY] - fM[kYY] * fM[kZX]; + T det = fM[kXX] * detxx - fM[kXY] * detxy + fM[kXZ] * detxz; + if (det == T(0)) { + std::cerr << "Transform3D::inverse error: zero determinant" << std::endl; + return; + } + det = T(1) / det; + detxx *= det; + detxy *= det; + detxz *= det; + T detyx = (fM[kXY] * fM[kZZ] - fM[kXZ] * fM[kZY]) * det; + T detyy = (fM[kXX] * fM[kZZ] - fM[kXZ] * fM[kZX]) * det; + T detyz = (fM[kXX] * fM[kZY] - fM[kXY] * fM[kZX]) * det; + T detzx = (fM[kXY] * fM[kYZ] - fM[kXZ] * fM[kYY]) * det; + T detzy = (fM[kXX] * fM[kYZ] - fM[kXZ] * fM[kYX]) * det; + T detzz = (fM[kXX] * fM[kYY] - fM[kXY] * fM[kYX]) * det; + SetComponents(detxx, -detyx, detzx, -detxx * fM[kDX] + detyx * fM[kDY] - detzx * fM[kDZ], -detxy, detyy, -detzy, + detxy * fM[kDX] - detyy * fM[kDY] + detzy * fM[kDZ], detxz, -detyz, detzz, + -detxz * fM[kDX] + detyz * fM[kDY] - detzz * fM[kDZ]); } /** Invert the transformation in place (vectorised) */ - template< typename SCALAR = T > - typename std::enable_if< !std::is_arithmetic::value, void >::type - Invert() + template + typename std::enable_if::value, void>::type Invert() { - // - // Name: Transform3D::inverse Date: 24.09.96 - // Author: E.Chernyaev (IHEP/Protvino) Revised: - // - // Function: Find inverse affine transformation. - - T detxx = fM[kYY]*fM[kZZ] - fM[kYZ]*fM[kZY]; - T detxy = fM[kYX]*fM[kZZ] - fM[kYZ]*fM[kZX]; - T detxz = fM[kYX]*fM[kZY] - fM[kYY]*fM[kZX]; - T det = fM[kXX]*detxx - fM[kXY]*detxy + fM[kXZ]*detxz; - const auto detZmask = ( det == T(0) ); - if ( any_of(detZmask) ) { - std::cerr << "Transform3D::inverse error: zero determinant" << std::endl; - det(detZmask) = T(1); - } - det = T(1)/det; - detxx *= det; detxy *= det; detxz *= det; - T detyx = (fM[kXY]*fM[kZZ] - fM[kXZ]*fM[kZY] )*det; - T detyy = (fM[kXX]*fM[kZZ] - fM[kXZ]*fM[kZX] )*det; - T detyz = (fM[kXX]*fM[kZY] - fM[kXY]*fM[kZX] )*det; - T detzx = (fM[kXY]*fM[kYZ] - fM[kXZ]*fM[kYY] )*det; - T detzy = (fM[kXX]*fM[kYZ] - fM[kXZ]*fM[kYX] )*det; - T detzz = (fM[kXX]*fM[kYY] - fM[kXY]*fM[kYX] )*det; - // Set det=0 cases to 0 - if ( any_of(detZmask) ) { - detxx(detZmask) = T(0); - detxy(detZmask) = T(0); - detxz(detZmask) = T(0); - detyx(detZmask) = T(0); - detyy(detZmask) = T(0); - detyz(detZmask) = T(0); - detzx(detZmask) = T(0); - detzy(detZmask) = T(0); - detzz(detZmask) = T(0); - } - // set final components - SetComponents - ( detxx, -detyx, detzx, -detxx*fM[kDX]+detyx*fM[kDY]-detzx*fM[kDZ], - -detxy, detyy, -detzy, detxy*fM[kDX]-detyy*fM[kDY]+detzy*fM[kDZ], - detxz, -detyz, detzz, -detxz*fM[kDX]+detyz*fM[kDY]-detzz*fM[kDZ] ); + // + // Name: Transform3D::inverse Date: 24.09.96 + // Author: E.Chernyaev (IHEP/Protvino) Revised: + // + // Function: Find inverse affine transformation. + + T detxx = fM[kYY] * fM[kZZ] - fM[kYZ] * fM[kZY]; + T detxy = fM[kYX] * fM[kZZ] - fM[kYZ] * fM[kZX]; + T detxz = fM[kYX] * fM[kZY] - fM[kYY] * fM[kZX]; + T det = fM[kXX] * detxx - fM[kXY] * detxy + fM[kXZ] * detxz; + const auto detZmask = (det == T(0)); + if (any_of(detZmask)) { + std::cerr << "Transform3D::inverse error: zero determinant" << std::endl; + det(detZmask) = T(1); + } + det = T(1) / det; + detxx *= det; + detxy *= det; + detxz *= det; + T detyx = (fM[kXY] * fM[kZZ] - fM[kXZ] * fM[kZY]) * det; + T detyy = (fM[kXX] * fM[kZZ] - fM[kXZ] * fM[kZX]) * det; + T detyz = (fM[kXX] * fM[kZY] - fM[kXY] * fM[kZX]) * det; + T detzx = (fM[kXY] * fM[kYZ] - fM[kXZ] * fM[kYY]) * det; + T detzy = (fM[kXX] * fM[kYZ] - fM[kXZ] * fM[kYX]) * det; + T detzz = (fM[kXX] * fM[kYY] - fM[kXY] * fM[kYX]) * det; + // Set det=0 cases to 0 + if (any_of(detZmask)) { + detxx(detZmask) = T(0); + detxy(detZmask) = T(0); + detxz(detZmask) = T(0); + detyx(detZmask) = T(0); + detyy(detZmask) = T(0); + detyz(detZmask) = T(0); + detzx(detZmask) = T(0); + detzy(detZmask) = T(0); + detzz(detZmask) = T(0); + } + // set final components + SetComponents(detxx, -detyx, detzx, -detxx * fM[kDX] + detyx * fM[kDY] - detzx * fM[kDZ], -detxy, detyy, -detzy, + detxy * fM[kDX] - detyy * fM[kDY] + detzy * fM[kDZ], detxz, -detyz, detzz, + -detxz * fM[kDX] + detyz * fM[kDY] - detzz * fM[kDZ]); } - + /** Return the inverse of the transformation. */ - Transform3D Inverse() const { + Transform3D Inverse() const + { Transform3D t(*this); t.Invert(); return t; } - /** Equality operator. Check equality for each element To do: use T tolerance */ - bool operator == (const Transform3D & rhs) const { - return ( fM[0] == rhs.fM[0] && - fM[1] == rhs.fM[1] && - fM[2] == rhs.fM[2] && - fM[3] == rhs.fM[3] && - fM[4] == rhs.fM[4] && - fM[5] == rhs.fM[5] && - fM[6] == rhs.fM[6] && - fM[7] == rhs.fM[7] && - fM[8] == rhs.fM[8] && - fM[9] == rhs.fM[9] && - fM[10]== rhs.fM[10] && - fM[11]== rhs.fM[11] ); + bool operator==(const Transform3D &rhs) const + { + return (fM[0] == rhs.fM[0] && fM[1] == rhs.fM[1] && fM[2] == rhs.fM[2] && fM[3] == rhs.fM[3] && + fM[4] == rhs.fM[4] && fM[5] == rhs.fM[5] && fM[6] == rhs.fM[6] && fM[7] == rhs.fM[7] && + fM[8] == rhs.fM[8] && fM[9] == rhs.fM[9] && fM[10] == rhs.fM[10] && fM[11] == rhs.fM[11]); } /** Inequality operator. Check equality for each element To do: use T tolerance */ - bool operator != (const Transform3D & rhs) const { - return ! operator==(rhs); - } - + bool operator!=(const Transform3D &rhs) const { return !operator==(rhs); } protected: /** make transformation from first a rotation then a translation */ - void AssignFrom( const Rotation3D & r, const Vector & v) + void AssignFrom(const Rotation3D &r, const Vector &v) { - // assignment from rotation + translation - - T rotData[9]; - r.GetComponents(rotData, rotData +9); - // first raw - for (int i = 0; i < 3; ++i) - fM[i] = rotData[i]; - // second raw - for (int i = 0; i < 3; ++i) - fM[kYX+i] = rotData[3+i]; - // third raw - for (int i = 0; i < 3; ++i) - fM[kZX+i] = rotData[6+i]; - - // translation data - T vecData[3]; - v.GetCoordinates(vecData, vecData+3); - fM[kDX] = vecData[0]; - fM[kDY] = vecData[1]; - fM[kDZ] = vecData[2]; + // assignment from rotation + translation + + T rotData[9]; + r.GetComponents(rotData, rotData + 9); + // first raw + for (int i = 0; i < 3; ++i) fM[i] = rotData[i]; + // second raw + for (int i = 0; i < 3; ++i) fM[kYX + i] = rotData[3 + i]; + // third raw + for (int i = 0; i < 3; ++i) fM[kZX + i] = rotData[6 + i]; + + // translation data + T vecData[3]; + v.GetCoordinates(vecData, vecData + 3); + fM[kDX] = vecData[0]; + fM[kDY] = vecData[1]; + fM[kDZ] = vecData[2]; } - /** make transformation from only rotations (zero translation) */ - void AssignFrom( const Rotation3D & r) + void AssignFrom(const Rotation3D &r) { - // assign from only a rotation (null translation) - T rotData[9]; - r.GetComponents(rotData, rotData +9); - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 3; ++j) - fM[4*i + j] = rotData[3*i+j]; - // empty vector data - fM[4*i + 3] = T(0); - } + // assign from only a rotation (null translation) + T rotData[9]; + r.GetComponents(rotData, rotData + 9); + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) fM[4 * i + j] = rotData[3 * i + j]; + // empty vector data + fM[4 * i + 3] = T(0); + } } /** make transformation from only translation (identity rotations) */ - void AssignFrom( const Vector & v ) + void AssignFrom(const Vector &v) { - // assign from a translation only (identity rotations) - fM[kXX] = T(1); fM[kXY] = T(0); fM[kXZ] = T(0); fM[kDX] = v.X(); - fM[kYX] = T(0); fM[kYY] = T(1); fM[kYZ] = T(0); fM[kDY] = v.Y(); - fM[kZX] = T(0); fM[kZY] = T(0); fM[kZZ] = T(1); fM[kDZ] = v.Z(); + // assign from a translation only (identity rotations) + fM[kXX] = T(1); + fM[kXY] = T(0); + fM[kXZ] = T(0); + fM[kDX] = v.X(); + fM[kYX] = T(0); + fM[kYY] = T(1); + fM[kYZ] = T(0); + fM[kDY] = v.Y(); + fM[kZX] = T(0); + fM[kZY] = T(0); + fM[kZZ] = T(1); + fM[kDZ] = v.Z(); } - + /** Set identity transformation (identity rotation , zero translation) */ void SetIdentity() { - //set identity ( identity rotation and zero translation) - fM[kXX] = T(1); fM[kXY] = T(0); fM[kXZ] = T(0); fM[kDX] = T(0); - fM[kYX] = T(0); fM[kYY] = T(1); fM[kYZ] = T(0); fM[kDY] = T(0); - fM[kZX] = T(0); fM[kZY] = T(0); fM[kZZ] = T(1); fM[kDZ] = T(0); + // set identity ( identity rotation and zero translation) + fM[kXX] = T(1); + fM[kXY] = T(0); + fM[kXZ] = T(0); + fM[kDX] = T(0); + fM[kYX] = T(0); + fM[kYY] = T(1); + fM[kYZ] = T(0); + fM[kDY] = T(0); + fM[kZX] = T(0); + fM[kZY] = T(0); + fM[kZZ] = T(1); + fM[kDZ] = T(0); } /** Set identity transformation (identity rotation , zero translation) vectorised version that sets using a mask */ - template< typename SCALAR = T > - typename std::enable_if< !std::is_arithmetic::value, void >::type - SetIdentity( const typename SCALAR::mask_type m ) + template + typename std::enable_if::value, void>::type SetIdentity( + const typename SCALAR::mask_type m) { - //set identity ( identity rotation and zero translation) - fM[kXX](m) = T(1); fM[kXY](m) = T(0); fM[kXZ](m) = T(0); fM[kDX](m) = T(0); - fM[kYX](m) = T(0); fM[kYY](m) = T(1); fM[kYZ](m) = T(0); fM[kDY](m) = T(0); - fM[kZX](m) = T(0); fM[kZY](m) = T(0); fM[kZZ](m) = T(1); fM[kDZ](m) = T(0); + // set identity ( identity rotation and zero translation) + fM[kXX](m) = T(1); + fM[kXY](m) = T(0); + fM[kXZ](m) = T(0); + fM[kDX](m) = T(0); + fM[kYX](m) = T(0); + fM[kYY](m) = T(1); + fM[kYZ](m) = T(0); + fM[kDY](m) = T(0); + fM[kZX](m) = T(0); + fM[kZY](m) = T(0); + fM[kZZ](m) = T(1); + fM[kDZ](m) = T(0); } private: - - T fM[12]; // transformation elements (3x4 matrix) - + T fM[12]; // transformation elements (3x4 matrix) }; // inline functions (combination of transformations) - + template -inline Transform3D & Transform3D::operator *= (const Transform3D & t) +inline Transform3D &Transform3D::operator*=(const Transform3D &t) { // combination of transformations @@ -979,26 +982,25 @@ inline Transform3D & Transform3D::operator *= (const Transform3D & t) return *this; } - template -inline Transform3D Transform3D::operator * (const Transform3D & t) const +inline Transform3D Transform3D::operator*(const Transform3D &t) const { - // combination of transformations - - return Transform3D(fM[kXX]*t.fM[kXX]+fM[kXY]*t.fM[kYX]+fM[kXZ]*t.fM[kZX], - fM[kXX]*t.fM[kXY]+fM[kXY]*t.fM[kYY]+fM[kXZ]*t.fM[kZY], - fM[kXX]*t.fM[kXZ]+fM[kXY]*t.fM[kYZ]+fM[kXZ]*t.fM[kZZ], - fM[kXX]*t.fM[kDX]+fM[kXY]*t.fM[kDY]+fM[kXZ]*t.fM[kDZ]+fM[kDX], - - fM[kYX]*t.fM[kXX]+fM[kYY]*t.fM[kYX]+fM[kYZ]*t.fM[kZX], - fM[kYX]*t.fM[kXY]+fM[kYY]*t.fM[kYY]+fM[kYZ]*t.fM[kZY], - fM[kYX]*t.fM[kXZ]+fM[kYY]*t.fM[kYZ]+fM[kYZ]*t.fM[kZZ], - fM[kYX]*t.fM[kDX]+fM[kYY]*t.fM[kDY]+fM[kYZ]*t.fM[kDZ]+fM[kDY], - - fM[kZX]*t.fM[kXX]+fM[kZY]*t.fM[kYX]+fM[kZZ]*t.fM[kZX], - fM[kZX]*t.fM[kXY]+fM[kZY]*t.fM[kYY]+fM[kZZ]*t.fM[kZY], - fM[kZX]*t.fM[kXZ]+fM[kZY]*t.fM[kYZ]+fM[kZZ]*t.fM[kZZ], - fM[kZX]*t.fM[kDX]+fM[kZY]*t.fM[kDY]+fM[kZZ]*t.fM[kDZ]+fM[kDZ] ); + // combination of transformations + + return Transform3D(fM[kXX] * t.fM[kXX] + fM[kXY] * t.fM[kYX] + fM[kXZ] * t.fM[kZX], + fM[kXX] * t.fM[kXY] + fM[kXY] * t.fM[kYY] + fM[kXZ] * t.fM[kZY], + fM[kXX] * t.fM[kXZ] + fM[kXY] * t.fM[kYZ] + fM[kXZ] * t.fM[kZZ], + fM[kXX] * t.fM[kDX] + fM[kXY] * t.fM[kDY] + fM[kXZ] * t.fM[kDZ] + fM[kDX], + + fM[kYX] * t.fM[kXX] + fM[kYY] * t.fM[kYX] + fM[kYZ] * t.fM[kZX], + fM[kYX] * t.fM[kXY] + fM[kYY] * t.fM[kYY] + fM[kYZ] * t.fM[kZY], + fM[kYX] * t.fM[kXZ] + fM[kYY] * t.fM[kYZ] + fM[kYZ] * t.fM[kZZ], + fM[kYX] * t.fM[kDX] + fM[kYY] * t.fM[kDY] + fM[kYZ] * t.fM[kDZ] + fM[kDY], + + fM[kZX] * t.fM[kXX] + fM[kZY] * t.fM[kYX] + fM[kZZ] * t.fM[kZX], + fM[kZX] * t.fM[kXY] + fM[kZY] * t.fM[kYY] + fM[kZZ] * t.fM[kZY], + fM[kZX] * t.fM[kXZ] + fM[kZY] * t.fM[kYZ] + fM[kZZ] * t.fM[kZZ], + fM[kZX] * t.fM[kDX] + fM[kZY] * t.fM[kDY] + fM[kZZ] * t.fM[kDZ] + fM[kDZ]); } @@ -1015,43 +1017,51 @@ inline Transform3D Transform3D::operator * (const Transform3D & t) con First the translation then the rotation */ template -inline Transform3D operator * (const Rotation3D & r, const Translation3D & t) { - return Transform3D( r, r(t.Vect()) ); +inline Transform3D operator*(const Rotation3D &r, const Translation3D &t) +{ + return Transform3D(r, r(t.Vect())); } template -inline Transform3D operator * (const RotationX & r, const Translation3D & t) { +inline Transform3D operator*(const RotationX &r, const Translation3D &t) +{ Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D(r3, r3(t.Vect())); } template -inline Transform3D operator * (const RotationY & r, const Translation3D & t) { +inline Transform3D operator*(const RotationY &r, const Translation3D &t) +{ Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D(r3, r3(t.Vect())); } template -inline Transform3D operator * (const RotationZ & r, const Translation3D & t) { +inline Transform3D operator*(const RotationZ &r, const Translation3D &t) +{ Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D(r3, r3(t.Vect())); } template -inline Transform3D operator * (const RotationZYX & r, const Translation3D & t) { +inline Transform3D operator*(const RotationZYX &r, const Translation3D &t) +{ Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D(r3, r3(t.Vect())); } template -inline Transform3D operator * (const AxisAngle & r, const Translation3D & t) { +inline Transform3D operator*(const AxisAngle &r, const Translation3D &t) +{ Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D(r3, r3(t.Vect())); } template -inline Transform3D operator * (const EulerAngles & r, const Translation3D & t) { +inline Transform3D operator*(const EulerAngles &r, const Translation3D &t) +{ Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D(r3, r3(t.Vect())); } template -inline Transform3D operator * (const Quaternion & r, const Translation3D & t) { +inline Transform3D operator*(const Quaternion &r, const Translation3D &t) +{ Rotation3D r3(r); - return Transform3D( r3, r3(t.Vect()) ); + return Transform3D(r3, r3(t.Vect())); } // ------ combination of a rotation (first) and then a translation ------ @@ -1061,36 +1071,44 @@ inline Transform3D operator * (const Quaternion & r, const Translation3D & First a rotation then the translation */ template -inline Transform3D operator * (const Translation3D & t, const Rotation3D & r) { - return Transform3D( r, t.Vect()); +inline Transform3D operator*(const Translation3D &t, const Rotation3D &r) +{ + return Transform3D(r, t.Vect()); } template -inline Transform3D operator * (const Translation3D & t, const RotationX & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +inline Transform3D operator*(const Translation3D &t, const RotationX &r) +{ + return Transform3D(Rotation3D(r), t.Vect()); } template -inline Transform3D operator * (const Translation3D & t, const RotationY & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +inline Transform3D operator*(const Translation3D &t, const RotationY &r) +{ + return Transform3D(Rotation3D(r), t.Vect()); } template -inline Transform3D operator * (const Translation3D & t, const RotationZ & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +inline Transform3D operator*(const Translation3D &t, const RotationZ &r) +{ + return Transform3D(Rotation3D(r), t.Vect()); } template -inline Transform3D operator * (const Translation3D & t, const RotationZYX & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +inline Transform3D operator*(const Translation3D &t, const RotationZYX &r) +{ + return Transform3D(Rotation3D(r), t.Vect()); } template -inline Transform3D operator * (const Translation3D & t, const EulerAngles & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +inline Transform3D operator*(const Translation3D &t, const EulerAngles &r) +{ + return Transform3D(Rotation3D(r), t.Vect()); } template -inline Transform3D operator * (const Translation3D & t, const Quaternion & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +inline Transform3D operator*(const Translation3D &t, const Quaternion &r) +{ + return Transform3D(Rotation3D(r), t.Vect()); } template -inline Transform3D operator * (const Translation3D & t, const AxisAngle & r) { - return Transform3D( Rotation3D(r) , t.Vect()); +inline Transform3D operator*(const Translation3D &t, const AxisAngle &r) +{ + return Transform3D(Rotation3D(r), t.Vect()); } // ------ combination of a Transform3D and a pure translation------ @@ -1100,9 +1118,10 @@ inline Transform3D operator * (const Translation3D & t, const AxisAngle & First the translation then the transform3D */ template -inline Transform3D operator * (const Transform3D & t, const Translation3D & d) { +inline Transform3D operator*(const Transform3D &t, const Translation3D &d) +{ Rotation3D r = t.Rotation(); - return Transform3D( r, r( d.Vect() ) + t.Translation().Vect() ); + return Transform3D(r, r(d.Vect()) + t.Translation().Vect()); } /** @@ -1110,8 +1129,9 @@ inline Transform3D operator * (const Transform3D & t, const Translation3D< First the transformation then the translation */ template -inline Transform3D operator * (const Translation3D & d, const Transform3D & t) { - return Transform3D( t.Rotation(), t.Translation().Vect() + d.Vect()); +inline Transform3D operator*(const Translation3D &d, const Transform3D &t) +{ + return Transform3D(t.Rotation(), t.Translation().Vect() + d.Vect()); } // ------ combination of a Transform3D and any rotation------ @@ -1122,36 +1142,44 @@ inline Transform3D operator * (const Translation3D & d, const Transform3D< First the rotation then the transform3D */ template -inline Transform3D operator * (const Transform3D & t, const Rotation3D & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +inline Transform3D operator*(const Transform3D &t, const Rotation3D &r) +{ + return Transform3D(t.Rotation() * r, t.Translation()); } template -inline Transform3D operator * (const Transform3D & t, const RotationX & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +inline Transform3D operator*(const Transform3D &t, const RotationX &r) +{ + return Transform3D(t.Rotation() * r, t.Translation()); } template -inline Transform3D operator * (const Transform3D & t, const RotationY & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +inline Transform3D operator*(const Transform3D &t, const RotationY &r) +{ + return Transform3D(t.Rotation() * r, t.Translation()); } template -inline Transform3D operator * (const Transform3D & t, const RotationZ & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +inline Transform3D operator*(const Transform3D &t, const RotationZ &r) +{ + return Transform3D(t.Rotation() * r, t.Translation()); } template -inline Transform3D operator * (const Transform3D & t, const RotationZYX & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +inline Transform3D operator*(const Transform3D &t, const RotationZYX &r) +{ + return Transform3D(t.Rotation() * r, t.Translation()); } template -inline Transform3D operator * (const Transform3D & t, const EulerAngles & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +inline Transform3D operator*(const Transform3D &t, const EulerAngles &r) +{ + return Transform3D(t.Rotation() * r, t.Translation()); } template -inline Transform3D operator * (const Transform3D & t, const AxisAngle & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +inline Transform3D operator*(const Transform3D &t, const AxisAngle &r) +{ + return Transform3D(t.Rotation() * r, t.Translation()); } template -inline Transform3D operator * (const Transform3D & t, const Quaternion & r) { - return Transform3D( t.Rotation()*r , t.Translation() ); +inline Transform3D operator*(const Transform3D &t, const Quaternion &r) +{ + return Transform3D(t.Rotation() * r, t.Translation()); } @@ -1161,43 +1189,51 @@ inline Transform3D operator * (const Transform3D & t, const Quaternion & r First the transformation then the rotation */ template -inline Transform3D operator * (const Rotation3D & r, const Transform3D & t) { - return Transform3D( r * t.Rotation(), r * t.Translation().Vect() ); +inline Transform3D operator*(const Rotation3D &r, const Transform3D &t) +{ + return Transform3D(r * t.Rotation(), r * t.Translation().Vect()); } template -inline Transform3D operator * (const RotationX & r, const Transform3D & t) { +inline Transform3D operator*(const RotationX &r, const Transform3D &t) +{ Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D(r3d * t.Rotation(), r3d * t.Translation().Vect()); } template -inline Transform3D operator * (const RotationY & r, const Transform3D & t) { +inline Transform3D operator*(const RotationY &r, const Transform3D &t) +{ Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D(r3d * t.Rotation(), r3d * t.Translation().Vect()); } template -inline Transform3D operator * (const RotationZ & r, const Transform3D & t) { +inline Transform3D operator*(const RotationZ &r, const Transform3D &t) +{ Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D(r3d * t.Rotation(), r3d * t.Translation().Vect()); } template -inline Transform3D operator * (const RotationZYX & r, const Transform3D & t) { +inline Transform3D operator*(const RotationZYX &r, const Transform3D &t) +{ Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D(r3d * t.Rotation(), r3d * t.Translation().Vect()); } template -inline Transform3D operator * (const EulerAngles & r, const Transform3D & t) { +inline Transform3D operator*(const EulerAngles &r, const Transform3D &t) +{ Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D(r3d * t.Rotation(), r3d * t.Translation().Vect()); } template -inline Transform3D operator * (const AxisAngle & r, const Transform3D & t) { +inline Transform3D operator*(const AxisAngle &r, const Transform3D &t) +{ Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D(r3d * t.Rotation(), r3d * t.Translation().Vect()); } template -inline Transform3D operator * (const Quaternion & r, const Transform3D & t) { +inline Transform3D operator*(const Quaternion &r, const Transform3D &t) +{ Rotation3D r3d(r); - return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() ); + return Transform3D(r3d * t.Rotation(), r3d * t.Translation().Vect()); } @@ -1208,17 +1244,17 @@ inline Transform3D operator * (const Quaternion & r, const Transform3D & t print the 12 components of the Transform3D */ template -std::ostream & operator<< (std::ostream & os, const Transform3D & t) +std::ostream &operator<<(std::ostream &os, const Transform3D &t) { - // TODO - this will need changing for machine-readable issues - // and even the human readable form needs formatting improvements - - T m[12]; - t.GetComponents(m, m+12); - os << "\n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3] ; - os << "\n" << m[4] << " " << m[5] << " " << m[6] << " " << m[7] ; - os << "\n" << m[8] << " " << m[9] << " " << m[10]<< " " << m[11] << "\n"; - return os; + // TODO - this will need changing for machine-readable issues + // and even the human readable form needs formatting improvements + + T m[12]; + t.GetComponents(m, m + 12); + os << "\n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3]; + os << "\n" << m[4] << " " << m[5] << " " << m[6] << " " << m[7]; + os << "\n" << m[8] << " " << m[9] << " " << m[10] << " " << m[11] << "\n"; + return os; } } // end namespace Impl diff --git a/math/genvector/inc/Math/GenVector/Translation3D.h b/math/genvector/inc/Math/GenVector/Translation3D.h index 1a4e99e8f82c9..c0c6a4a2a5447 100644 --- a/math/genvector/inc/Math/GenVector/Translation3D.h +++ b/math/genvector/inc/Math/GenVector/Translation3D.h @@ -28,13 +28,12 @@ #include #include - namespace ROOT { namespace Math { namespace Impl { - + //____________________________________________________________________________________________________ /** Class describing a 3 dimensional translation. It can be combined (using the operator *) @@ -51,15 +50,10 @@ namespace Impl { template class Translation3D { +public: + typedef T Scalar; - public: - - typedef T Scalar; - - typedef DisplacementVector3D, DefaultCoordinateSystemTag > Vector; - - - + typedef DisplacementVector3D, DefaultCoordinateSystemTag> Vector; /** Default constructor ( zero translation ) @@ -79,10 +73,7 @@ class Translation3D { /** Construct from x,y,z values representing the translation */ - Translation3D(T dx, T dy, T dz) : - fVect( Vector(dx, dy, dz) ) - { } - + Translation3D(T dx, T dy, T dz) : fVect(Vector(dx, dy, dz)) {} /** Construct from any Displacement vector in ant tag and coordinate system @@ -100,10 +91,9 @@ class Translation3D { @param p2 point defining origin of transformed reference system */ - template - Translation3D ( const PositionVector3D & p1, - const PositionVector3D & p2 ) : - fVect(p2-p1) + template + Translation3D(const PositionVector3D &p1, const PositionVector3D &p2) + : fVect(p2 - p1) { } @@ -147,28 +137,17 @@ class Translation3D { /** Set the components from 3 scalars */ - void - SetComponents (T dx, T dy, T dz ) { - fVect.SetCoordinates(dx,dy,dz); - } + void SetComponents(T dx, T dy, T dz) { fVect.SetCoordinates(dx, dy, dz); } /** Get the components into 3 scalars */ - void - GetComponents (T &dx, T &dy, T &dz) const { - fVect.GetCoordinates(dx,dy,dz); - } - + void GetComponents(T &dx, T &dy, T &dz) const { fVect.GetCoordinates(dx, dy, dz); } /** Set the XYZ vector components from 3 scalars */ - void - SetXYZ (T dx, T dy, T dz ) { - fVect.SetXYZ(dx,dy,dz); - } - + void SetXYZ(T dx, T dy, T dz) { fVect.SetXYZ(dx, dy, dz); } // operations on points and vectors @@ -178,16 +157,15 @@ class Translation3D { */ template PositionVector3D operator() (const PositionVector3D & p) const { - return PositionVector3D ( p.X() + fVect.X(), - p.Y() + fVect.Y(), - p.Z() + fVect.Z() ); + return PositionVector3D(p.X() + fVect.X(), p.Y() + fVect.Y(), p.Z() + fVect.Z()); } /** Transformation operation */ - template - PositionVector3D operator * ( const PositionVector3D & v ) const { - return operator() (v); + template + PositionVector3D operator*(const PositionVector3D &v) const + { + return operator()(v); } /** @@ -201,11 +179,12 @@ class Translation3D { /** Transformation operation */ - template - DisplacementVector3D operator * ( const DisplacementVector3D & v ) const { - return operator() (v); + template + DisplacementVector3D operator*(const DisplacementVector3D &v) const + { + return operator()(v); } - + /** Transformation operation for points between different coordinate system tags */ @@ -219,11 +198,11 @@ class Translation3D { /** Transformation operation for Displacement Vector of different coordinate systems */ - template - void Transform ( const DisplacementVector3D & v1, - DisplacementVector3D & v2 ) const { - // just copy v1 in v2 - v2.SetXYZ( v1.X(), v1.Y(), v1.Z() ); + template + void Transform(const DisplacementVector3D &v1, DisplacementVector3D &v2) const + { + // just copy v1 in v2 + v2.SetXYZ(v1.X(), v1.Y(), v1.Z()); } /** @@ -231,35 +210,38 @@ class Translation3D { A LorentzVector contains a displacement vector so no translation applies as well */ template - LorentzVector operator() ( const LorentzVector & q ) const { + LorentzVector operator()(const LorentzVector &q) const + { return q; } /** Transformation operation */ - template - LorentzVector operator * ( const LorentzVector & q ) const { - return operator() (q); + template + LorentzVector operator*(const LorentzVector &q) const + { + return operator()(q); } /** Transformation on a 3D plane */ - Plane3D operator() ( const Plane3D & plane ) const + Plane3D operator()(const Plane3D &plane) const { - // transformations on a 3D plane - const Vector n = plane.Normal(); - // take a point on the plane. Use origin projection on the plane - // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1 - const T d = plane.HesseDistance(); - PositionVector3D > p( - d * n.X() , - d * n.Y(), - d * n.Z() ); - return PLANE( operator() (n), operator() (p) ); + // transformations on a 3D plane + const Vector n = plane.Normal(); + // take a point on the plane. Use origin projection on the plane + // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1 + const T d = plane.HesseDistance(); + PositionVector3D> p(-d * n.X(), -d * n.Y(), -d * n.Z()); + return PLANE(operator()(n), operator()(p)); } /** multiply (combine) with another transformation in place */ - Translation3D & operator *= (const Translation3D & t) { + Translation3D &operator*=(const Translation3D &t) + { fVect+= t.Vect(); return *this; } @@ -267,9 +249,7 @@ class Translation3D { /** multiply (combine) two transformations */ - Translation3D operator * (const Translation3D & t) const { - return Translation3D( fVect + t.Vect() ); - } + Translation3D operator*(const Translation3D &t) const { return Translation3D(fVect + t.Vect()); } /** Invert the transformation in place @@ -281,24 +261,18 @@ class Translation3D { /** Return the inverse of the transformation. */ - Translation3D Inverse() const { - return Translation3D( -fVect.X(), -fVect.Y(),-fVect.Z() ); - } - + Translation3D Inverse() const { return Translation3D(-fVect.X(), -fVect.Y(), -fVect.Z()); } /** Equality/inequality operators */ - bool operator == (const Translation3D & rhs) const { + bool operator==(const Translation3D &rhs) const + { if( fVect != rhs.fVect ) return false; return true; } - bool operator != (const Translation3D & rhs) const { - return ! operator==(rhs); - } - - + bool operator!=(const Translation3D &rhs) const { return !operator==(rhs); } private: @@ -315,13 +289,13 @@ class Translation3D { // TODO - I/O should be put in the manipulator form template -std::ostream & operator<< (std::ostream & os, const Translation3D & t) +std::ostream &operator<<(std::ostream &os, const Translation3D &t) { // TODO - this will need changing for machine-readable issues // and even the human readable form needs formatiing improvements T m[3]; - t.GetComponents(m, m+3); + t.GetComponents(m, m + 3); return os << "\n" << m[0] << " " << m[1] << " " << m[2] << "\n"; } diff --git a/math/genvector/inc/Math/GenVector/eta.h b/math/genvector/inc/Math/GenVector/eta.h index 7fa99fddc05ae..4b31c84f766f7 100644 --- a/math/genvector/inc/Math/GenVector/eta.h +++ b/math/genvector/inc/Math/GenVector/eta.h @@ -50,12 +50,11 @@ namespace ROOT { if (rho > 0) { // value to control Taylor expansion of sqrt - static const Scalar big_z_scaled = - pow(std::numeric_limits::epsilon(),static_cast(-.25)); + static const Scalar big_z_scaled = pow(std::numeric_limits::epsilon(), static_cast(-.25)); Scalar z_scaled = z/rho; if (fabs(z_scaled) < big_z_scaled) { - return log(z_scaled+std::sqrt(z_scaled*z_scaled+1.0)); + return log(z_scaled + std::sqrt(z_scaled * z_scaled + 1.0)); } else { // apply correction using first order Taylor expansion of sqrt return z>0 ? std::log(2.0*z_scaled + 0.5/z_scaled) : -std::log(-2.0*z_scaled); From b32cb6acb2ace2727762bffa3bfbb4c4e9984c65 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 11 Mar 2017 16:01:14 +0000 Subject: [PATCH 25/44] some more 'using namespace std' updates --- .../inc/Math/GenVector/CylindricalEta3D.h | 32 +++++++++++------- .../inc/Math/GenVector/LorentzVector.h | 9 +++-- math/genvector/inc/Math/GenVector/Polar2D.h | 7 ++-- math/genvector/inc/Math/GenVector/Polar3D.h | 13 ++++---- .../inc/Math/GenVector/PtEtaPhiE4D.h | 29 +++++++++------- .../inc/Math/GenVector/PtEtaPhiM4D.h | 25 +++++++++----- math/genvector/inc/Math/GenVector/PxPyPzE4D.h | 23 ++++++++----- math/genvector/inc/Math/GenVector/PxPyPzM4D.h | 20 ++++++----- .../genvector/inc/Math/GenVector/VectorUtil.h | 33 +++++++++++-------- math/genvector/inc/Math/GenVector/eta.h | 10 +++--- 10 files changed, 122 insertions(+), 79 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h index 0b4b0e20739ab..b81d27a3f95ee 100644 --- a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h +++ b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h @@ -69,9 +69,10 @@ public : explicit CylindricalEta3D( const CoordSystem & v ) : fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() ) { + using namespace std; static Scalar bigEta = - -.3f *std::log(std::numeric_limits::epsilon()); - if ( std::fabs(fEta) > bigEta ) { + -.3f *log(std::numeric_limits::epsilon()); + if ( fabs(fEta) > bigEta ) { fRho *= v.Z()/Z(); // This gives a small absolute adjustment in rho, // which, for large eta, results in a significant // improvement in the faithfullness of reproducing z. @@ -124,8 +125,9 @@ public : private: inline static Scalar pi() { return M_PI; } inline void Restrict() { + using namespace std; if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); return; } public: @@ -135,20 +137,26 @@ public : T Rho() const { return fRho; } T Eta() const { return fEta; } T Phi() const { return fPhi; } - T X() const { return fRho*std::cos(fPhi); } - T Y() const { return fRho*std::sin(fPhi); } - T Z() const { return fRho > 0 ? fRho*std::sinh(fEta) : + T X() const { using namespace std; return fRho*cos(fPhi); } + T Y() const { using namespace std; return fRho*sin(fPhi); } + T Z() const { using namespace std; return fRho > 0 ? fRho*sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax() ; } - T R() const { return fRho > 0 ? fRho*std::cosh(fEta) : - fEta > etaMax() ? fEta - etaMax() : - fEta < -etaMax() ? -fEta - etaMax() : - 0 ; } + T R() const { + using namespace std; + return fRho > 0 ? fRho*cosh(fEta) : + fEta > etaMax() ? fEta - etaMax() : + fEta < -etaMax() ? -fEta - etaMax() : + 0 ; + } T Mag2() const { return R()*R(); } T Perp2() const { return fRho*fRho; } - T Theta() const { return fRho > 0 ? 2* std::atan( std::exp( - fEta ) ) : - (fEta >= 0 ? 0 : pi() ); } + T Theta() const { + using namespace std; + return fRho > 0 ? 2* atan( exp( - fEta ) ) : + (fEta >= 0 ? 0 : pi() ); + } // setters (only for data members) diff --git a/math/genvector/inc/Math/GenVector/LorentzVector.h b/math/genvector/inc/Math/GenVector/LorentzVector.h index 026a3593c9133..4aa0a6fad16fc 100644 --- a/math/genvector/inc/Math/GenVector/LorentzVector.h +++ b/math/genvector/inc/Math/GenVector/LorentzVector.h @@ -488,9 +488,10 @@ namespace ROOT { // TODO - It would be good to check that E > Pz and use the Throw() // mechanism or at least load a NAN if not. // We should then move the code to a .cpp file. + using namespace std; Scalar ee = E(); Scalar ppz = Pz(); - return .5f* std::log( (ee+ppz)/(ee-ppz) ); + return Scalar(0.5) * log( (ee+ppz)/(ee-ppz) ); } /** @@ -499,9 +500,10 @@ namespace ROOT { Scalar ColinearRapidity() const { // TODO - It would be good to check that E > P and use the Throw() // mechanism or at least load a NAN if not. + using namespace std; Scalar ee = E(); Scalar pp = P(); - return .5f* std::log( (ee+pp)/(ee-pp) ); + return Scalar(0.5) * log( (ee+pp)/(ee-pp) ); } /** @@ -597,6 +599,7 @@ namespace ROOT { Return Gamma scalar value */ Scalar Gamma() const { + using namespace std; Scalar v2 = P2(); Scalar t2 = E()*E(); if (E() == 0) { @@ -614,7 +617,7 @@ namespace ROOT { else if ( t2 == v2 ) { GenVector::Throw ("LorentzVector::Gamma() - gamma computed for a lightlike LorentzVector. Infinite result"); } - return 1./std::sqrt(1. - v2/t2 ); + return Scalar(1)/sqrt(Scalar(1) - v2/t2 ); } /* gamma */ diff --git a/math/genvector/inc/Math/GenVector/Polar2D.h b/math/genvector/inc/Math/GenVector/Polar2D.h index 895778d3a55ab..f27ef7e3959b3 100644 --- a/math/genvector/inc/Math/GenVector/Polar2D.h +++ b/math/genvector/inc/Math/GenVector/Polar2D.h @@ -97,8 +97,8 @@ public : Scalar R() const { return fR;} Scalar Phi() const { return fPhi; } - Scalar X() const { return fR*std::cos(fPhi);} - Scalar Y() const { return fR*std::sin(fPhi);} + Scalar X() const { using namespace std; return fR*cos(fPhi);} + Scalar Y() const { using namespace std; return fR*sin(fPhi);} Scalar Mag2() const { return fR*fR;} @@ -134,8 +134,9 @@ public : restrict abgle hi to be between -PI and PI */ inline void Restrict() { + using namespace std; if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); return; } diff --git a/math/genvector/inc/Math/GenVector/Polar3D.h b/math/genvector/inc/Math/GenVector/Polar3D.h index 3fa1e66e15922..a43c9ee3f7efb 100644 --- a/math/genvector/inc/Math/GenVector/Polar3D.h +++ b/math/genvector/inc/Math/GenVector/Polar3D.h @@ -109,12 +109,12 @@ public : Scalar R() const { return fR;} Scalar Phi() const { return fPhi; } Scalar Theta() const { return fTheta; } - Scalar Rho() const { return fR*std::sin(fTheta); } - Scalar X() const { return Rho()*std::cos(fPhi);} - Scalar Y() const { return Rho()*std::sin(fPhi);} - Scalar Z() const { return fR*std::cos(fTheta); } + Scalar Rho() const { using namespace std; return fR*sin(fTheta); } + Scalar X() const { using namespace std; return Rho()*cos(fPhi);} + Scalar Y() const { using namespace std; return Rho()*sin(fPhi);} + Scalar Z() const { using namespace std; return fR*cos(fTheta); } Scalar Mag2() const { return fR*fR;} - Scalar Perp2() const { return Rho()*Rho(); } + Scalar Perp2() const { const Scalar r = Rho(); return r*r; } // pseudorapidity Scalar Eta() const @@ -156,8 +156,9 @@ public : private: inline static Scalar pi() { return M_PI; } inline void Restrict() { + using namespace std; if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); return; } diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h index 539e6ecca22fe..3c6e659bbe1df 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h @@ -137,12 +137,13 @@ public : // other coordinate representation - Scalar Px() const { return fPt*cos(fPhi);} + Scalar Px() const { using namespace std; return fPt*cos(fPhi);} Scalar X () const { return Px(); } - Scalar Py() const { return fPt*sin(fPhi);} + Scalar Py() const { using namespace std; return fPt*sin(fPhi);} Scalar Y () const { return Py(); } Scalar Pz() const { - return fPt > 0 ? fPt*std::sinh(fEta) : + using namespace std; + return fPt > 0 ? fPt*sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax() ; @@ -153,7 +154,8 @@ public : magnitude of momentum */ Scalar P() const { - return fPt > 0 ? fPt*std::cosh(fEta) : + using namespace std; + return fPt > 0 ? fPt*cosh(fEta) : fEta > etaMax() ? fEta - etaMax() : fEta < -etaMax() ? -fEta - etaMax() : 0 ; @@ -175,13 +177,14 @@ public : invariant mass */ Scalar M() const { + using namespace std; Scalar mm = M2(); if (mm >= 0) { - return std::sqrt(mm); + return sqrt(mm); } else { GenVector::Throw ("PtEtaPhiE4D::M() - Tachyonic:\n" " Pt and Eta give P such that P^2 > E^2, so the mass would be imaginary"); - return -std::sqrt(-mm); + return -sqrt(-mm); } } Scalar Mag() const { return M(); } @@ -201,13 +204,14 @@ public : transverse mass */ Scalar Mt() const { + using namespace std; Scalar mm = Mt2(); if (mm >= 0) { - return std::sqrt(mm); + return sqrt(mm); } else { GenVector::Throw ("PtEtaPhiE4D::Mt() - Tachyonic:\n" " Pt and Eta give Pz such that Pz^2 > E^2, so the mass would be imaginary"); - return -std::sqrt(-mm); + return -sqrt(-mm); } } @@ -218,7 +222,8 @@ public : transverse energy */ Scalar Et() const { - return fE / std::cosh(fEta); // faster using eta + using namespace std; + return fE / cosh(fEta); // faster using eta } /** @@ -230,8 +235,9 @@ public : private: inline static Scalar pi() { return M_PI; } inline void Restrict() { + using namespace std; if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); return; } public: @@ -240,7 +246,8 @@ public : polar angle */ Scalar Theta() const { - if (fPt > 0) return 2* std::atan( exp( - fEta ) ); + using namespace std; + if (fPt > 0) return 2* atan( exp( - fEta ) ); if (fEta >= 0) return 0; return pi(); } diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h index 5055c33e0eb2d..d628e5e0b6ed0 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h @@ -153,7 +153,8 @@ public : Scalar Py() const { return fPt*sin(fPhi);} Scalar Y () const { return Py(); } Scalar Pz() const { - return fPt > 0 ? fPt*std::sinh(fEta) : + using namespace std; + return fPt > 0 ? fPt*sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax() ; @@ -164,7 +165,8 @@ public : magnitude of momentum */ Scalar P() const { - return fPt > 0 ? fPt*std::cosh(fEta) : + using namespace std; + return fPt > 0 ? fPt*cosh(fEta) : fEta > etaMax() ? fEta - etaMax() : fEta < -etaMax() ? -fEta - etaMax() : 0 ; @@ -188,7 +190,7 @@ public : /** Energy (timelike component of momentum-energy 4-vector) */ - Scalar E() const { return std::sqrt(E2() ); } + Scalar E() const { using namespace std; return sqrt(E2()); } Scalar T() const { return E(); } @@ -216,13 +218,14 @@ public : transverse mass - will be negative if Mt2() is negative */ Scalar Mt() const { + using namespace std; Scalar mm = Mt2(); if (mm >= 0) { - return std::sqrt(mm); + return sqrt(mm); } else { GenVector::Throw ("PtEtaPhiM4D::Mt() - Tachyonic:\n" " Pz^2 > E^2 so the transverse mass would be imaginary"); - return -std::sqrt(-mm); + return -sqrt(-mm); } } @@ -230,22 +233,25 @@ public : transverse energy squared */ Scalar Et2() const { + using namespace std; // a bit faster than et * et - return 2. * E2()/ ( std::cosh(2 * fEta) + 1 ); + return 2. * E2()/ ( cosh(2 * fEta) + 1 ); } /** transverse energy */ Scalar Et() const { - return E() / std::cosh(fEta); + using namespace std; + return E() / cosh(fEta); } private: inline static Scalar pi() { return M_PI; } inline void RestrictPhi() { + using namespace std; if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); return; } // restrict the value of negative mass to avoid unphysical negative E2 values @@ -265,7 +271,8 @@ public : polar angle */ Scalar Theta() const { - if (fPt > 0) return 2* std::atan( exp( - fEta ) ); + using namespace std; + if (fPt > 0) return 2* atan( exp( - fEta ) ); if (fEta >= 0) return 0; return pi(); } diff --git a/math/genvector/inc/Math/GenVector/PxPyPzE4D.h b/math/genvector/inc/Math/GenVector/PxPyPzE4D.h index ec2a48d983f3d..00c0dc2055ebc 100644 --- a/math/genvector/inc/Math/GenVector/PxPyPzE4D.h +++ b/math/genvector/inc/Math/GenVector/PxPyPzE4D.h @@ -135,7 +135,7 @@ public : /** magnitude of spatial components (magnitude of 3-momentum) */ - Scalar P() const { return std::sqrt(P2()); } + Scalar P() const { using namespace std; return sqrt(P2()); } Scalar R() const { return P(); } /** @@ -148,13 +148,14 @@ public : invariant mass */ Scalar M() const { + using namespace std; Scalar mm = M2(); if (mm >= 0) { - return std::sqrt(mm); + return sqrt(mm); } else { GenVector::Throw ("PxPyPzE4D::M() - Tachyonic:\n" " P^2 > E^2 so the mass would be imaginary"); - return -std::sqrt(-mm); + return -sqrt(-mm); } } Scalar Mag() const { return M(); } @@ -168,7 +169,7 @@ public : /** Transverse spatial component (P_perp or rho) */ - Scalar Pt() const { return std::sqrt(Perp2());} + Scalar Pt() const { using namespace std; return sqrt(Perp2());} Scalar Perp() const { return Pt();} Scalar Rho() const { return Pt();} @@ -181,13 +182,14 @@ public : transverse mass */ Scalar Mt() const { + using namespace std; Scalar mm = Mt2(); if (mm >= 0) { - return std::sqrt(mm); + return sqrt(mm); } else { GenVector::Throw ("PxPyPzE4D::Mt() - Tachyonic:\n" " Pz^2 > E^2 so the transverse mass would be imaginary"); - return -std::sqrt(-mm); + return -sqrt(-mm); } } @@ -204,22 +206,25 @@ public : transverse energy */ Scalar Et() const { + using namespace std; Scalar etet = Et2(); - return fT < 0.0 ? -std::sqrt(etet) : std::sqrt(etet); + return fT < 0.0 ? -sqrt(etet) : sqrt(etet); } /** azimuthal angle */ Scalar Phi() const { - return (fX == 0.0 && fY == 0.0) ? 0 : std::atan2(fY,fX); + using namespace std; + return (fX == 0.0 && fY == 0.0) ? 0 : atan2(fY,fX); } /** polar angle */ Scalar Theta() const { - return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : std::atan2(Pt(),fZ); + using namespace std; + return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(),fZ); } /** diff --git a/math/genvector/inc/Math/GenVector/PxPyPzM4D.h b/math/genvector/inc/Math/GenVector/PxPyPzM4D.h index 711c14990ba22..7f8abfb7238d8 100644 --- a/math/genvector/inc/Math/GenVector/PxPyPzM4D.h +++ b/math/genvector/inc/Math/GenVector/PxPyPzM4D.h @@ -154,7 +154,7 @@ public : /** Energy */ - Scalar E() const { return std::sqrt(E2() ); } + Scalar E() const { using namespace std; return sqrt(E2() ); } Scalar T() const { return E();} @@ -166,7 +166,7 @@ public : /** magnitude of spatial components (magnitude of 3-momentum) */ - Scalar P() const { return std::sqrt(P2()); } + Scalar P() const { using namespace std; return sqrt(P2()); } Scalar R() const { return P(); } /** @@ -198,7 +198,7 @@ public : /** Transverse spatial component (P_perp or rho) */ - Scalar Pt() const { return std::sqrt(Perp2());} + Scalar Pt() const { using namespace std; return sqrt(Perp2());} Scalar Perp() const { return Pt();} Scalar Rho() const { return Pt();} @@ -211,13 +211,14 @@ public : transverse mass */ Scalar Mt() const { + using namespace std; Scalar mm = Mt2(); if (mm >= 0) { - return std::sqrt(mm); + return sqrt(mm); } else { GenVector::Throw ("PxPyPzM4D::Mt() - Tachyonic:\n" " Pz^2 > E^2 so the transverse mass would be imaginary"); - return -std::sqrt(-mm); + return -sqrt(-mm); } } @@ -234,22 +235,25 @@ public : transverse energy */ Scalar Et() const { + using namespace std; Scalar etet = Et2(); - return std::sqrt(etet); + return sqrt(etet); } /** azimuthal angle */ Scalar Phi() const { - return (fX == 0.0 && fY == 0.0) ? 0.0 : std::atan2(fY,fX); + using namespace std; + return (fX == 0.0 && fY == 0.0) ? 0.0 : atan2(fY,fX); } /** polar angle */ Scalar Theta() const { - return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : std::atan2(Pt(),fZ); + using namespace std; + return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(),fZ); } /** diff --git a/math/genvector/inc/Math/GenVector/VectorUtil.h b/math/genvector/inc/Math/GenVector/VectorUtil.h index 07a2f6c99d516..e979c5940c3fe 100644 --- a/math/genvector/inc/Math/GenVector/VectorUtil.h +++ b/math/genvector/inc/Math/GenVector/VectorUtil.h @@ -93,7 +93,8 @@ namespace ROOT { */ template inline typename Vector1::Scalar DeltaR( const Vector1 & v1, const Vector2 & v2) { - return std::sqrt( DeltaR2(v1,v2) ); + using namespace std; + return sqrt( DeltaR2(v1,v2) ); } @@ -110,15 +111,14 @@ namespace ROOT { // need to have a specialization for polar Coordinates ?? template double CosTheta( const Vector1 & v1, const Vector2 & v2) { - double arg; + using namespace std; + double arg(0); double v1_r2 = v1.X()*v1.X() + v1.Y()*v1.Y() + v1.Z()*v1.Z(); double v2_r2 = v2.X()*v2.X() + v2.Y()*v2.Y() + v2.Z()*v2.Z(); double ptot2 = v1_r2*v2_r2; - if(ptot2 <= 0) { - arg = 0.0; - }else{ + if ( !(ptot2 <= 0) ) { double pdot = v1.X()*v2.X() + v1.Y()*v2.Y() + v1.Z()*v2.Z(); - arg = pdot/std::sqrt(ptot2); + arg = pdot/sqrt(ptot2); if(arg > 1.0) arg = 1.0; if(arg < -1.0) arg = -1.0; } @@ -136,7 +136,8 @@ namespace ROOT { */ template inline double Angle( const Vector1 & v1, const Vector2 & v2) { - return std::acos( CosTheta(v1, v2) ); + using namespace std; + return acos( CosTheta(v1, v2) ); } /** @@ -194,7 +195,8 @@ namespace ROOT { */ template inline double Perp( const Vector1 & v, const Vector2 & u) { - return std::sqrt(Perp2(v,u) ); + using namespace std; + return sqrt(Perp2(v,u) ); } @@ -213,13 +215,14 @@ namespace ROOT { */ template inline typename Vector1::Scalar InvariantMass( const Vector1 & v1, const Vector2 & v2) { + using namespace std; typedef typename Vector1::Scalar Scalar; Scalar ee = (v1.E() + v2.E() ); Scalar xx = (v1.X() + v2.X() ); Scalar yy = (v1.Y() + v2.Y() ); Scalar zz = (v1.Z() + v2.Z() ); Scalar mm2 = ee*ee - xx*xx - yy*yy - zz*zz; - return mm2 < 0.0 ? -std::sqrt(-mm2) : std::sqrt(mm2); + return mm2 < 0.0 ? -sqrt(-mm2) : sqrt(mm2); // PxPyPzE4D q(xx,yy,zz,ee); // return q.M(); //return ( v1 + v2).mag(); @@ -325,6 +328,7 @@ namespace ROOT { */ template LVector boost(const LVector & v, const BoostVector & b) { + using namespace std; double bx = b.X(); double by = b.Y(); double bz = b.Z(); @@ -333,7 +337,7 @@ namespace ROOT { GenVector::Throw ( "Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - double gamma = 1.0 / std::sqrt(1.0 - b2); + double gamma = 1.0 / sqrt(1.0 - b2); double bp = bx*v.X() + by*v.Y() + bz*v.Z(); double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0; double x2 = v.X() + gamma2*bp*bx + gamma*bx*v.T(); @@ -354,11 +358,12 @@ namespace ROOT { */ template LVector boostX(const LVector & v, T beta) { + using namespace std; if (beta >= 1) { GenVector::Throw ("Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - T gamma = 1.0/ std::sqrt(1.0 - beta*beta); + T gamma = 1.0/ sqrt(1.0 - beta*beta); typename LVector::Scalar x2 = gamma * v.X() + gamma * beta * v.T(); typename LVector::Scalar t2 = gamma * beta * v.X() + gamma * v.T(); @@ -375,11 +380,12 @@ namespace ROOT { */ template LVector boostY(const LVector & v, double beta) { + using namespace std; if (beta >= 1) { GenVector::Throw ("Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - double gamma = 1.0/ std::sqrt(1.0 - beta*beta); + double gamma = 1.0/ sqrt(1.0 - beta*beta); double y2 = gamma * v.Y() + gamma * beta * v.T(); double t2 = gamma * beta * v.Y() + gamma * v.T(); LVector lv; @@ -395,11 +401,12 @@ namespace ROOT { */ template LVector boostZ(const LVector & v, double beta) { + using namespace std; if (beta >= 1) { GenVector::Throw ( "Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - double gamma = 1.0/ std::sqrt(1.0 - beta*beta); + double gamma = 1.0/ sqrt(1.0 - beta*beta); double z2 = gamma * v.Z() + gamma * beta * v.T(); double t2 = gamma * beta * v.Z() + gamma * v.T(); LVector lv; diff --git a/math/genvector/inc/Math/GenVector/eta.h b/math/genvector/inc/Math/GenVector/eta.h index 4b31c84f766f7..78ff9598683b0 100644 --- a/math/genvector/inc/Math/GenVector/eta.h +++ b/math/genvector/inc/Math/GenVector/eta.h @@ -54,10 +54,10 @@ namespace ROOT { Scalar z_scaled = z/rho; if (fabs(z_scaled) < big_z_scaled) { - return log(z_scaled + std::sqrt(z_scaled * z_scaled + 1.0)); + return log(z_scaled + sqrt(z_scaled * z_scaled + 1.0)); } else { // apply correction using first order Taylor expansion of sqrt - return z>0 ? std::log(2.0*z_scaled + 0.5/z_scaled) : -std::log(-2.0*z_scaled); + return z>0 ? log(2.0*z_scaled + 0.5/z_scaled) : -log(-2.0*z_scaled); } } // case vector has rho = 0 @@ -80,8 +80,8 @@ namespace ROOT { */ template inline Scalar Eta_FromTheta(Scalar theta, Scalar r) { - - Scalar tanThetaOver2 = std::tan( theta/2.); + using namespace std; + Scalar tanThetaOver2 = tan( theta/2.); if (tanThetaOver2 == 0) { return r + etaMax(); } @@ -89,7 +89,7 @@ namespace ROOT { return -r - etaMax(); } else { - return -std::log(tanThetaOver2); + return -log(tanThetaOver2); } } From febe783e6e65403649eca01d8da9d02cadfa4409 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 11 Mar 2017 20:54:14 +0000 Subject: [PATCH 26/44] Fix more clang format issues --- .../inc/Math/GenVector/CylindricalEta3D.h | 56 ++++++++++--------- .../inc/Math/GenVector/LorentzVector.h | 6 +- math/genvector/inc/Math/GenVector/Plane3D.h | 1 - math/genvector/inc/Math/GenVector/Polar2D.h | 15 +++-- math/genvector/inc/Math/GenVector/Polar3D.h | 33 ++++++++--- .../inc/Math/GenVector/PtEtaPhiE4D.h | 29 +++++----- .../inc/Math/GenVector/PtEtaPhiM4D.h | 25 ++++----- math/genvector/inc/Math/GenVector/PxPyPzE4D.h | 16 ++++-- math/genvector/inc/Math/GenVector/PxPyPzM4D.h | 22 ++++++-- .../genvector/inc/Math/GenVector/VectorUtil.h | 18 +++--- math/genvector/inc/Math/GenVector/eta.h | 4 +- 11 files changed, 139 insertions(+), 86 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h index b81d27a3f95ee..27e93cd32b9c4 100644 --- a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h +++ b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h @@ -69,13 +69,12 @@ public : explicit CylindricalEta3D( const CoordSystem & v ) : fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() ) { - using namespace std; - static Scalar bigEta = - -.3f *log(std::numeric_limits::epsilon()); - if ( fabs(fEta) > bigEta ) { - fRho *= v.Z()/Z(); // This gives a small absolute adjustment in rho, - // which, for large eta, results in a significant - // improvement in the faithfullness of reproducing z. + using namespace std; + static Scalar bigEta = -.3f * log(std::numeric_limits::epsilon()); + if (fabs(fEta) > bigEta) { + fRho *= v.Z() / Z(); // This gives a small absolute adjustment in rho, + // which, for large eta, results in a significant + // improvement in the faithfullness of reproducing z. } } @@ -126,8 +125,7 @@ public : inline static Scalar pi() { return M_PI; } inline void Restrict() { using namespace std; - if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); return; } public: @@ -137,25 +135,33 @@ public : T Rho() const { return fRho; } T Eta() const { return fEta; } T Phi() const { return fPhi; } - T X() const { using namespace std; return fRho*cos(fPhi); } - T Y() const { using namespace std; return fRho*sin(fPhi); } - T Z() const { using namespace std; return fRho > 0 ? fRho*sinh(fEta) : - fEta == 0 ? 0 : - fEta > 0 ? fEta - etaMax() : - fEta + etaMax() ; } - T R() const { - using namespace std; - return fRho > 0 ? fRho*cosh(fEta) : - fEta > etaMax() ? fEta - etaMax() : - fEta < -etaMax() ? -fEta - etaMax() : - 0 ; + T X() const + { + using namespace std; + return fRho * cos(fPhi); + } + T Y() const + { + using namespace std; + return fRho * sin(fPhi); + } + T Z() const + { + using namespace std; + return fRho > 0 ? fRho * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax(); + } + T R() const + { + using namespace std; + return fRho > 0 ? fRho * cosh(fEta) + : fEta > etaMax() ? fEta - etaMax() : fEta < -etaMax() ? -fEta - etaMax() : 0; } T Mag2() const { return R()*R(); } T Perp2() const { return fRho*fRho; } - T Theta() const { - using namespace std; - return fRho > 0 ? 2* atan( exp( - fEta ) ) : - (fEta >= 0 ? 0 : pi() ); + T Theta() const + { + using namespace std; + return fRho > 0 ? 2 * atan(exp(-fEta)) : (fEta >= 0 ? 0 : pi()); } // setters (only for data members) diff --git a/math/genvector/inc/Math/GenVector/LorentzVector.h b/math/genvector/inc/Math/GenVector/LorentzVector.h index 4aa0a6fad16fc..b7e9ef8a91c0a 100644 --- a/math/genvector/inc/Math/GenVector/LorentzVector.h +++ b/math/genvector/inc/Math/GenVector/LorentzVector.h @@ -491,7 +491,7 @@ namespace ROOT { using namespace std; Scalar ee = E(); Scalar ppz = Pz(); - return Scalar(0.5) * log( (ee+ppz)/(ee-ppz) ); + return Scalar(0.5) * log((ee + ppz) / (ee - ppz)); } /** @@ -503,7 +503,7 @@ namespace ROOT { using namespace std; Scalar ee = E(); Scalar pp = P(); - return Scalar(0.5) * log( (ee+pp)/(ee-pp) ); + return Scalar(0.5) * log((ee + pp) / (ee - pp)); } /** @@ -617,7 +617,7 @@ namespace ROOT { else if ( t2 == v2 ) { GenVector::Throw ("LorentzVector::Gamma() - gamma computed for a lightlike LorentzVector. Infinite result"); } - return Scalar(1)/sqrt(Scalar(1) - v2/t2 ); + return Scalar(1) / sqrt(Scalar(1) - v2 / t2); } /* gamma */ diff --git a/math/genvector/inc/Math/GenVector/Plane3D.h b/math/genvector/inc/Math/GenVector/Plane3D.h index ece88a512573a..93c856b362c13 100644 --- a/math/genvector/inc/Math/GenVector/Plane3D.h +++ b/math/genvector/inc/Math/GenVector/Plane3D.h @@ -288,7 +288,6 @@ class Plane3D { Scalar fC; Scalar fD; - }; // Plane3D<> /** diff --git a/math/genvector/inc/Math/GenVector/Polar2D.h b/math/genvector/inc/Math/GenVector/Polar2D.h index f27ef7e3959b3..5bfe37fcf9205 100644 --- a/math/genvector/inc/Math/GenVector/Polar2D.h +++ b/math/genvector/inc/Math/GenVector/Polar2D.h @@ -97,8 +97,16 @@ public : Scalar R() const { return fR;} Scalar Phi() const { return fPhi; } - Scalar X() const { using namespace std; return fR*cos(fPhi);} - Scalar Y() const { using namespace std; return fR*sin(fPhi);} + Scalar X() const + { + using namespace std; + return fR * cos(fPhi); + } + Scalar Y() const + { + using namespace std; + return fR * sin(fPhi); + } Scalar Mag2() const { return fR*fR;} @@ -135,8 +143,7 @@ public : */ inline void Restrict() { using namespace std; - if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); return; } diff --git a/math/genvector/inc/Math/GenVector/Polar3D.h b/math/genvector/inc/Math/GenVector/Polar3D.h index a43c9ee3f7efb..fd8c014494ade 100644 --- a/math/genvector/inc/Math/GenVector/Polar3D.h +++ b/math/genvector/inc/Math/GenVector/Polar3D.h @@ -109,12 +109,32 @@ public : Scalar R() const { return fR;} Scalar Phi() const { return fPhi; } Scalar Theta() const { return fTheta; } - Scalar Rho() const { using namespace std; return fR*sin(fTheta); } - Scalar X() const { using namespace std; return Rho()*cos(fPhi);} - Scalar Y() const { using namespace std; return Rho()*sin(fPhi);} - Scalar Z() const { using namespace std; return fR*cos(fTheta); } + Scalar Rho() const + { + using namespace std; + return fR * sin(fTheta); + } + Scalar X() const + { + using namespace std; + return Rho() * cos(fPhi); + } + Scalar Y() const + { + using namespace std; + return Rho() * sin(fPhi); + } + Scalar Z() const + { + using namespace std; + return fR * cos(fTheta); + } Scalar Mag2() const { return fR*fR;} - Scalar Perp2() const { const Scalar r = Rho(); return r*r; } + Scalar Perp2() const + { + const Scalar r = Rho(); + return r * r; + } // pseudorapidity Scalar Eta() const @@ -157,8 +177,7 @@ public : inline static Scalar pi() { return M_PI; } inline void Restrict() { using namespace std; - if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); return; } diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h index 3c6e659bbe1df..ee2bf3627c4ec 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h @@ -137,16 +137,21 @@ public : // other coordinate representation - Scalar Px() const { using namespace std; return fPt*cos(fPhi);} + Scalar Px() const + { + using namespace std; + return fPt * cos(fPhi); + } Scalar X () const { return Px(); } - Scalar Py() const { using namespace std; return fPt*sin(fPhi);} + Scalar Py() const + { + using namespace std; + return fPt * sin(fPhi); + } Scalar Y () const { return Py(); } Scalar Pz() const { using namespace std; - return fPt > 0 ? fPt*sinh(fEta) : - fEta == 0 ? 0 : - fEta > 0 ? fEta - etaMax() : - fEta + etaMax() ; + return fPt > 0 ? fPt * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax(); } Scalar Z () const { return Pz(); } @@ -155,10 +160,9 @@ public : */ Scalar P() const { using namespace std; - return fPt > 0 ? fPt*cosh(fEta) : - fEta > etaMax() ? fEta - etaMax() : - fEta < -etaMax() ? -fEta - etaMax() : - 0 ; + return fPt > 0 ? fPt * cosh(fEta) + : fEta > etaMax() ? fEta - etaMax() + : fEta < -etaMax() ? -fEta - etaMax() : 0; } Scalar R() const { return P(); } @@ -236,8 +240,7 @@ public : inline static Scalar pi() { return M_PI; } inline void Restrict() { using namespace std; - if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); return; } public: @@ -247,7 +250,7 @@ public : */ Scalar Theta() const { using namespace std; - if (fPt > 0) return 2* atan( exp( - fEta ) ); + if (fPt > 0) return 2 * atan(exp(-fEta)); if (fEta >= 0) return 0; return pi(); } diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h index d628e5e0b6ed0..03e60b4b5cee7 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h @@ -154,10 +154,7 @@ public : Scalar Y () const { return Py(); } Scalar Pz() const { using namespace std; - return fPt > 0 ? fPt*sinh(fEta) : - fEta == 0 ? 0 : - fEta > 0 ? fEta - etaMax() : - fEta + etaMax() ; + return fPt > 0 ? fPt * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax(); } Scalar Z () const { return Pz(); } @@ -166,10 +163,9 @@ public : */ Scalar P() const { using namespace std; - return fPt > 0 ? fPt*cosh(fEta) : - fEta > etaMax() ? fEta - etaMax() : - fEta < -etaMax() ? -fEta - etaMax() : - 0 ; + return fPt > 0 ? fPt * cosh(fEta) + : fEta > etaMax() ? fEta - etaMax() + : fEta < -etaMax() ? -fEta - etaMax() : 0; } Scalar R() const { return P(); } @@ -190,7 +186,11 @@ public : /** Energy (timelike component of momentum-energy 4-vector) */ - Scalar E() const { using namespace std; return sqrt(E2()); } + Scalar E() const + { + using namespace std; + return sqrt(E2()); + } Scalar T() const { return E(); } @@ -235,7 +235,7 @@ public : Scalar Et2() const { using namespace std; // a bit faster than et * et - return 2. * E2()/ ( cosh(2 * fEta) + 1 ); + return 2. * E2() / (cosh(2 * fEta) + 1); } /** @@ -250,8 +250,7 @@ public : inline static Scalar pi() { return M_PI; } inline void RestrictPhi() { using namespace std; - if ( fPhi <= -pi() || fPhi > pi() ) - fPhi = fPhi - floor( fPhi/(2*pi()) +.5 ) * 2*pi(); + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); return; } // restrict the value of negative mass to avoid unphysical negative E2 values @@ -272,7 +271,7 @@ public : */ Scalar Theta() const { using namespace std; - if (fPt > 0) return 2* atan( exp( - fEta ) ); + if (fPt > 0) return 2 * atan(exp(-fEta)); if (fEta >= 0) return 0; return pi(); } diff --git a/math/genvector/inc/Math/GenVector/PxPyPzE4D.h b/math/genvector/inc/Math/GenVector/PxPyPzE4D.h index 00c0dc2055ebc..ed74a68ccd4a2 100644 --- a/math/genvector/inc/Math/GenVector/PxPyPzE4D.h +++ b/math/genvector/inc/Math/GenVector/PxPyPzE4D.h @@ -135,7 +135,11 @@ public : /** magnitude of spatial components (magnitude of 3-momentum) */ - Scalar P() const { using namespace std; return sqrt(P2()); } + Scalar P() const + { + using namespace std; + return sqrt(P2()); + } Scalar R() const { return P(); } /** @@ -169,7 +173,11 @@ public : /** Transverse spatial component (P_perp or rho) */ - Scalar Pt() const { using namespace std; return sqrt(Perp2());} + Scalar Pt() const + { + using namespace std; + return sqrt(Perp2()); + } Scalar Perp() const { return Pt();} Scalar Rho() const { return Pt();} @@ -216,7 +224,7 @@ public : */ Scalar Phi() const { using namespace std; - return (fX == 0.0 && fY == 0.0) ? 0 : atan2(fY,fX); + return (fX == 0.0 && fY == 0.0) ? 0 : atan2(fY, fX); } /** @@ -224,7 +232,7 @@ public : */ Scalar Theta() const { using namespace std; - return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(),fZ); + return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(), fZ); } /** diff --git a/math/genvector/inc/Math/GenVector/PxPyPzM4D.h b/math/genvector/inc/Math/GenVector/PxPyPzM4D.h index 7f8abfb7238d8..268b34937ef9a 100644 --- a/math/genvector/inc/Math/GenVector/PxPyPzM4D.h +++ b/math/genvector/inc/Math/GenVector/PxPyPzM4D.h @@ -154,7 +154,11 @@ public : /** Energy */ - Scalar E() const { using namespace std; return sqrt(E2() ); } + Scalar E() const + { + using namespace std; + return sqrt(E2()); + } Scalar T() const { return E();} @@ -166,7 +170,11 @@ public : /** magnitude of spatial components (magnitude of 3-momentum) */ - Scalar P() const { using namespace std; return sqrt(P2()); } + Scalar P() const + { + using namespace std; + return sqrt(P2()); + } Scalar R() const { return P(); } /** @@ -198,7 +206,11 @@ public : /** Transverse spatial component (P_perp or rho) */ - Scalar Pt() const { using namespace std; return sqrt(Perp2());} + Scalar Pt() const + { + using namespace std; + return sqrt(Perp2()); + } Scalar Perp() const { return Pt();} Scalar Rho() const { return Pt();} @@ -245,7 +257,7 @@ public : */ Scalar Phi() const { using namespace std; - return (fX == 0.0 && fY == 0.0) ? 0.0 : atan2(fY,fX); + return (fX == 0.0 && fY == 0.0) ? 0.0 : atan2(fY, fX); } /** @@ -253,7 +265,7 @@ public : */ Scalar Theta() const { using namespace std; - return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(),fZ); + return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(), fZ); } /** diff --git a/math/genvector/inc/Math/GenVector/VectorUtil.h b/math/genvector/inc/Math/GenVector/VectorUtil.h index e979c5940c3fe..5bd4e46f4b3fe 100644 --- a/math/genvector/inc/Math/GenVector/VectorUtil.h +++ b/math/genvector/inc/Math/GenVector/VectorUtil.h @@ -94,7 +94,7 @@ namespace ROOT { template inline typename Vector1::Scalar DeltaR( const Vector1 & v1, const Vector2 & v2) { using namespace std; - return sqrt( DeltaR2(v1,v2) ); + return sqrt(DeltaR2(v1, v2)); } @@ -116,9 +116,9 @@ namespace ROOT { double v1_r2 = v1.X()*v1.X() + v1.Y()*v1.Y() + v1.Z()*v1.Z(); double v2_r2 = v2.X()*v2.X() + v2.Y()*v2.Y() + v2.Z()*v2.Z(); double ptot2 = v1_r2*v2_r2; - if ( !(ptot2 <= 0) ) { + if (!(ptot2 <= 0)) { double pdot = v1.X()*v2.X() + v1.Y()*v2.Y() + v1.Z()*v2.Z(); - arg = pdot/sqrt(ptot2); + arg = pdot / sqrt(ptot2); if(arg > 1.0) arg = 1.0; if(arg < -1.0) arg = -1.0; } @@ -137,7 +137,7 @@ namespace ROOT { template inline double Angle( const Vector1 & v1, const Vector2 & v2) { using namespace std; - return acos( CosTheta(v1, v2) ); + return acos(CosTheta(v1, v2)); } /** @@ -196,7 +196,7 @@ namespace ROOT { template inline double Perp( const Vector1 & v, const Vector2 & u) { using namespace std; - return sqrt(Perp2(v,u) ); + return sqrt(Perp2(v, u)); } @@ -337,7 +337,7 @@ namespace ROOT { GenVector::Throw ( "Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - double gamma = 1.0 / sqrt(1.0 - b2); + double gamma = 1.0 / sqrt(1.0 - b2); double bp = bx*v.X() + by*v.Y() + bz*v.Z(); double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0; double x2 = v.X() + gamma2*bp*bx + gamma*bx*v.T(); @@ -363,7 +363,7 @@ namespace ROOT { GenVector::Throw ("Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - T gamma = 1.0/ sqrt(1.0 - beta*beta); + T gamma = 1.0 / sqrt(1.0 - beta * beta); typename LVector::Scalar x2 = gamma * v.X() + gamma * beta * v.T(); typename LVector::Scalar t2 = gamma * beta * v.X() + gamma * v.T(); @@ -385,7 +385,7 @@ namespace ROOT { GenVector::Throw ("Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - double gamma = 1.0/ sqrt(1.0 - beta*beta); + double gamma = 1.0 / sqrt(1.0 - beta * beta); double y2 = gamma * v.Y() + gamma * beta * v.T(); double t2 = gamma * beta * v.Y() + gamma * v.T(); LVector lv; @@ -406,7 +406,7 @@ namespace ROOT { GenVector::Throw ( "Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - double gamma = 1.0/ sqrt(1.0 - beta*beta); + double gamma = 1.0 / sqrt(1.0 - beta * beta); double z2 = gamma * v.Z() + gamma * beta * v.T(); double t2 = gamma * beta * v.Z() + gamma * v.T(); LVector lv; diff --git a/math/genvector/inc/Math/GenVector/eta.h b/math/genvector/inc/Math/GenVector/eta.h index 78ff9598683b0..95e5c79641393 100644 --- a/math/genvector/inc/Math/GenVector/eta.h +++ b/math/genvector/inc/Math/GenVector/eta.h @@ -57,7 +57,7 @@ namespace ROOT { return log(z_scaled + sqrt(z_scaled * z_scaled + 1.0)); } else { // apply correction using first order Taylor expansion of sqrt - return z>0 ? log(2.0*z_scaled + 0.5/z_scaled) : -log(-2.0*z_scaled); + return z > 0 ? log(2.0 * z_scaled + 0.5 / z_scaled) : -log(-2.0 * z_scaled); } } // case vector has rho = 0 @@ -81,7 +81,7 @@ namespace ROOT { template inline Scalar Eta_FromTheta(Scalar theta, Scalar r) { using namespace std; - Scalar tanThetaOver2 = tan( theta/2.); + Scalar tanThetaOver2 = tan(theta / 2.); if (tanThetaOver2 == 0) { return r + etaMax(); } From a628a2afb16211b41de2e914f00ab0a9a23d1d5b Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 11 Mar 2017 21:05:31 +0000 Subject: [PATCH 27/44] fix (hopefully) one more clang format issue --- math/genvector/inc/Math/GenVector/CylindricalEta3D.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h index 27e93cd32b9c4..4a638920cb636 100644 --- a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h +++ b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h @@ -70,11 +70,12 @@ public : fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() ) { using namespace std; - static Scalar bigEta = -.3f * log(std::numeric_limits::epsilon()); + static Scalar bigEta = Scalar(-0.3) * log(std::numeric_limits::epsilon()); if (fabs(fEta) > bigEta) { - fRho *= v.Z() / Z(); // This gives a small absolute adjustment in rho, + // This gives a small absolute adjustment in rho, // which, for large eta, results in a significant // improvement in the faithfullness of reproducing z. + fRho *= v.Z() / Z(); } } From 89b2d2676ef38d8b3d05e83ae4dd2937c9092448 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 11 Mar 2017 21:09:11 +0000 Subject: [PATCH 28/44] clang format is picky... --- math/genvector/inc/Math/GenVector/CylindricalEta3D.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h index 4a638920cb636..cd42dd314d40d 100644 --- a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h +++ b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h @@ -75,7 +75,7 @@ public : // This gives a small absolute adjustment in rho, // which, for large eta, results in a significant // improvement in the faithfullness of reproducing z. - fRho *= v.Z() / Z(); + fRho *= v.Z() / Z(); } } From bd96bd0155803e10f733aeefab60e3dd51eaa0c8 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 13 Mar 2017 10:15:31 +0000 Subject: [PATCH 29/44] revert changes in VectorUtils.h --- .../genvector/inc/Math/GenVector/VectorUtil.h | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/VectorUtil.h b/math/genvector/inc/Math/GenVector/VectorUtil.h index 5bd4e46f4b3fe..07a2f6c99d516 100644 --- a/math/genvector/inc/Math/GenVector/VectorUtil.h +++ b/math/genvector/inc/Math/GenVector/VectorUtil.h @@ -93,8 +93,7 @@ namespace ROOT { */ template inline typename Vector1::Scalar DeltaR( const Vector1 & v1, const Vector2 & v2) { - using namespace std; - return sqrt(DeltaR2(v1, v2)); + return std::sqrt( DeltaR2(v1,v2) ); } @@ -111,14 +110,15 @@ namespace ROOT { // need to have a specialization for polar Coordinates ?? template double CosTheta( const Vector1 & v1, const Vector2 & v2) { - using namespace std; - double arg(0); + double arg; double v1_r2 = v1.X()*v1.X() + v1.Y()*v1.Y() + v1.Z()*v1.Z(); double v2_r2 = v2.X()*v2.X() + v2.Y()*v2.Y() + v2.Z()*v2.Z(); double ptot2 = v1_r2*v2_r2; - if (!(ptot2 <= 0)) { + if(ptot2 <= 0) { + arg = 0.0; + }else{ double pdot = v1.X()*v2.X() + v1.Y()*v2.Y() + v1.Z()*v2.Z(); - arg = pdot / sqrt(ptot2); + arg = pdot/std::sqrt(ptot2); if(arg > 1.0) arg = 1.0; if(arg < -1.0) arg = -1.0; } @@ -136,8 +136,7 @@ namespace ROOT { */ template inline double Angle( const Vector1 & v1, const Vector2 & v2) { - using namespace std; - return acos(CosTheta(v1, v2)); + return std::acos( CosTheta(v1, v2) ); } /** @@ -195,8 +194,7 @@ namespace ROOT { */ template inline double Perp( const Vector1 & v, const Vector2 & u) { - using namespace std; - return sqrt(Perp2(v, u)); + return std::sqrt(Perp2(v,u) ); } @@ -215,14 +213,13 @@ namespace ROOT { */ template inline typename Vector1::Scalar InvariantMass( const Vector1 & v1, const Vector2 & v2) { - using namespace std; typedef typename Vector1::Scalar Scalar; Scalar ee = (v1.E() + v2.E() ); Scalar xx = (v1.X() + v2.X() ); Scalar yy = (v1.Y() + v2.Y() ); Scalar zz = (v1.Z() + v2.Z() ); Scalar mm2 = ee*ee - xx*xx - yy*yy - zz*zz; - return mm2 < 0.0 ? -sqrt(-mm2) : sqrt(mm2); + return mm2 < 0.0 ? -std::sqrt(-mm2) : std::sqrt(mm2); // PxPyPzE4D q(xx,yy,zz,ee); // return q.M(); //return ( v1 + v2).mag(); @@ -328,7 +325,6 @@ namespace ROOT { */ template LVector boost(const LVector & v, const BoostVector & b) { - using namespace std; double bx = b.X(); double by = b.Y(); double bz = b.Z(); @@ -337,7 +333,7 @@ namespace ROOT { GenVector::Throw ( "Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - double gamma = 1.0 / sqrt(1.0 - b2); + double gamma = 1.0 / std::sqrt(1.0 - b2); double bp = bx*v.X() + by*v.Y() + bz*v.Z(); double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0; double x2 = v.X() + gamma2*bp*bx + gamma*bx*v.T(); @@ -358,12 +354,11 @@ namespace ROOT { */ template LVector boostX(const LVector & v, T beta) { - using namespace std; if (beta >= 1) { GenVector::Throw ("Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - T gamma = 1.0 / sqrt(1.0 - beta * beta); + T gamma = 1.0/ std::sqrt(1.0 - beta*beta); typename LVector::Scalar x2 = gamma * v.X() + gamma * beta * v.T(); typename LVector::Scalar t2 = gamma * beta * v.X() + gamma * v.T(); @@ -380,12 +375,11 @@ namespace ROOT { */ template LVector boostY(const LVector & v, double beta) { - using namespace std; if (beta >= 1) { GenVector::Throw ("Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - double gamma = 1.0 / sqrt(1.0 - beta * beta); + double gamma = 1.0/ std::sqrt(1.0 - beta*beta); double y2 = gamma * v.Y() + gamma * beta * v.T(); double t2 = gamma * beta * v.Y() + gamma * v.T(); LVector lv; @@ -401,12 +395,11 @@ namespace ROOT { */ template LVector boostZ(const LVector & v, double beta) { - using namespace std; if (beta >= 1) { GenVector::Throw ( "Beta Vector supplied to set Boost represents speed >= c"); return LVector(); } - double gamma = 1.0 / sqrt(1.0 - beta * beta); + double gamma = 1.0/ std::sqrt(1.0 - beta*beta); double z2 = gamma * v.Z() + gamma * beta * v.T(); double t2 = gamma * beta * v.Z() + gamma * v.T(); LVector lv; From dea8d05bfc71792415c11b7d31cc856727498a97 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 13 Mar 2017 12:18:50 +0000 Subject: [PATCH 30/44] Add new test for GenVector with Vc types --- test/CMakeLists.txt | 14 ++ test/testGenVectorVc.cxx | 305 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 319 insertions(+) create mode 100644 test/testGenVectorVc.cxx diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 214c10ddc0d7e..b2794fdcb50a1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -310,6 +310,20 @@ if(ROOT_vc_FOUND) ROOT_ADD_TEST(test-Vc COMMAND testVc FAILREGEX "FAILED|Error in") endif() +#--Vc GenVector test----------------------------------------------------------------------------------- +if(ROOT_vc_FOUND) + include_directories(${Vc_INCLUDE_DIRS}) + + ROOT_ADD_CXX_FLAG(vc_flags -Wno-unused-parameter) + ROOT_ADD_CXX_FLAG(vc_flags -Wno-missing-braces) + ROOT_ADD_CXX_FLAG(vc_flags -Wno-conditional-uninitialized) + ROOT_ADD_CXX_FLAG(vc_flags -Wno-mismatched-tags) + ROOT_ADD_CXX_FLAG(vc_flags -Wno-undefined-var-template) + set_source_files_properties(testGenVectorVc.cxx PROPERTIES COMPILE_FLAGS "${vc_flags}") + ROOT_EXECUTABLE(testGenVectorVc testGenVectorVc.cxx LIBRARIES GenVector ${Vc_LIBRARIES} BUILTINS Vc) + ROOT_ADD_TEST(test-GenVector-Vc COMMAND testGenVectorVc FAILREGEX "FAILED|Error in") +endif() + #--g2root------------------------------------------------------------------------------------------ if(TARGET g2root) ROOT_ADD_TEST(test-g2root COMMAND g2root) diff --git a/test/testGenVectorVc.cxx b/test/testGenVectorVc.cxx new file mode 100644 index 0000000000000..433c8e9be478e --- /dev/null +++ b/test/testGenVectorVc.cxx @@ -0,0 +1,305 @@ + +// STL +#include +#include +#include +#include +#include + +// Vc +#include + +// ROOT +#include "Math/GenVector/PositionVector3D.h" +#include "Math/GenVector/DisplacementVector3D.h" +#include "Math/GenVector/Plane3D.h" +#include "Math/GenVector/Transform3D.h" + +int compare(double v1, double v2, const std::string &name = "", double scale = 100.0) +{ + // ntest = ntest + 1; + + // numerical double limit for epsilon + const double eps = scale * std::numeric_limits::epsilon(); + int iret = 0; + double delta = v2 - v1; + double d = 0; + if (delta < 0) delta = -delta; + if (v1 == 0 || v2 == 0) { + if (delta > eps) { + iret = 1; + } + } + // skip case v1 or v2 is infinity + else { + d = v1; + + if (v1 < 0) d = -d; + // add also case when delta is small by default + if (delta / d > eps && delta > eps) iret = 1; + } + + if (iret != 0) { + int pr = std::cout.precision(18); + std::cout << "\nDiscrepancy in " << name << "() : " << v1 << " != " << v2 << " discr = " << int(delta / d / eps) + << " (Allowed discrepancy is " << eps << ")\n"; + std::cout.precision(pr); + } + return iret; +} + +// randomn generator +static std::default_random_engine gen; +// Distributions for each member +static std::uniform_real_distribution p_x(-800, 800), p_y(-600, 600), p_z(10000, 10500); +static std::uniform_real_distribution d_x(-0.2, 0.2), d_y(-0.1, 0.1), d_z(0.95, 0.99); +static std::uniform_real_distribution c_x(3100, 3200), c_y(10, 15), c_z(3200, 3300); +static std::uniform_real_distribution r_rad(8500, 8600); +static std::uniform_real_distribution p0(-0.002, 0.002), p1(-0.2, 0.2), p2(0.97, 0.99), p3(-1300, 1300); + +template +class Data { +public: + typedef std::vector> Vector; + +public: + POINT position; + VECTOR direction; + POINT CoC; + PLANE plane; + FTYPE radius{0}; + +public: + template + Data(const INDATA &ind) + : position(ind.position.x(), ind.position.y(), ind.position.z()), + direction(ind.direction.x(), ind.direction.y(), ind.direction.z()), CoC(ind.CoC.x(), ind.CoC.y(), ind.CoC.z()), + plane(ind.plane.A(), ind.plane.B(), ind.plane.C(), ind.plane.D()), radius(ind.radius) + { + } + Data() + : position(p_x(gen), p_y(gen), p_z(gen)), direction(d_x(gen), d_y(gen), d_z(gen)), + CoC(c_x(gen), c_y(gen), c_z(gen)), plane(p0(gen), p1(gen), p2(gen), p3(gen)), radius(r_rad(gen)) + { + } +}; + +template +void fill(const INDATA &in, OUTDATA &out) +{ + out.clear(); + out.reserve(in.size()); + for (const auto &i : in) { + out.emplace_back(i); + } +} + +template +inline + typename std::enable_if::value && + std::is_arithmetic::value && std::is_arithmetic::value, + bool>::type + reflectSpherical(POINT &position, VECTOR &direction, const POINT &CoC, const FTYPE radius) +{ + constexpr FTYPE zero(0), two(2.0), four(4.0), half(0.5); + const FTYPE a = direction.Mag2(); + const VECTOR delta = position - CoC; + const FTYPE b = two * direction.Dot(delta); + const FTYPE c = delta.Mag2() - radius * radius; + const FTYPE discr = b * b - four * a * c; + const bool OK = discr > zero; + if (OK) { + const FTYPE dist = half * (std::sqrt(discr) - b) / a; + // change position to the intersection point + position += dist * direction; + // reflect the vector + // r = u - 2(u.n)n, r=reflection, u=incident, n=normal + const VECTOR normal = position - CoC; + direction -= (two * normal.Dot(direction) / normal.Mag2()) * normal; + } + return OK; +} + +template +inline + typename std::enable_if::value && + !std::is_arithmetic::value && !std::is_arithmetic::value, + typename FTYPE::mask_type>::type + reflectSpherical(POINT &position, VECTOR &direction, const POINT &CoC, const FTYPE radius) +{ + const FTYPE two(2.0), four(4.0), half(0.5); + const FTYPE a = direction.Mag2(); + const VECTOR delta = position - CoC; + const FTYPE b = two * direction.Dot(delta); + const FTYPE c = delta.Mag2() - radius * radius; + FTYPE discr = b * b - four * a * c; + typename FTYPE::mask_type OK = discr > FTYPE::Zero(); + if (any_of(OK)) { + // Zero out the negative values in discr, to prevent sqrt(-ve) + discr(!OK) = FTYPE::Zero(); + // compute the distance + const FTYPE dist = half * (sqrt(discr) - b) / a; + // change position to the intersection point + position += dist * direction; + // reflect the vector + // r = u - 2(u.n)n, r=reflection, u=incident, n=normal + const VECTOR normal = position - CoC; + direction -= (two * normal.Dot(direction) / normal.Mag2()) * normal; + } + // return the mask indicating which results should be used + return OK; +} + +template +inline typename std::enable_if::value && + std::is_arithmetic::value && + std::is_arithmetic::value, + bool>::type +reflectPlane(POINT &position, VECTOR &direction, const PLANE &plane) +{ + constexpr typename POINT::Scalar two(2.0); + const bool OK = true; + // Plane normal + const auto &normal = plane.Normal(); + // compute distance to the plane + const auto scalar = direction.Dot(normal); + const auto distance = -(plane.Distance(position)) / scalar; + // change position to reflection point and update direction + position += distance * direction; + direction -= two * scalar * normal; + return OK; +} + +template +inline typename std::enable_if::value && + !std::is_arithmetic::value && + !std::is_arithmetic::value, + typename FTYPE::mask_type>::type +reflectPlane(POINT &position, VECTOR &direction, const PLANE &plane) +{ + const typename POINT::Scalar two(2.0); + const typename FTYPE::mask_type OK(true); + // Plane normal + const VECTOR normal = plane.Normal(); + // compute distance to the plane + const FTYPE scalar = direction.Dot(normal); + const FTYPE distance = -(plane.Distance(position)) / scalar; + // change position to reflection point and update direction + position += distance * direction; + direction -= two * scalar * normal; + return OK; +} + +template +using Point = ROOT::Math::PositionVector3D, ROOT::Math::DefaultCoordinateSystemTag>; +template +using Vector = ROOT::Math::DisplacementVector3D, ROOT::Math::DefaultCoordinateSystemTag>; +template +using Plane = ROOT::Math::Impl::Plane3D; + +int main(int /*argc*/, char ** /*argv*/) +{ + int ret = 0; + + // must be multiple of 8 + // const unsigned int nPhotons = 96 * 1e2; + const unsigned int nPhotons = 8; + // const unsigned int nPhotons = 8; + std::cout << "Creating " << nPhotons << " random photons ..." << std::endl; + + // Scalar Types + Data, Vector, Plane, double>::Vector scalar_data(nPhotons); + + // Vc Types + Data, Vector, Plane, Vc::double_v>::Vector vc_data; + // Clone the exact random values from the Scalar vector + // Note we are making the same number of entries in the container, but each entry is a vector entry + // with Vc::double_t::Size entries. + fill(scalar_data, vc_data); + + // Loop over the two containers and compare + std::cout << "Ray Tracing :-" << std::endl; + for (size_t i = 0; i < nPhotons; ++i) { + auto &sc = scalar_data[i]; + auto &vc = vc_data[i]; + + // ray tracing + reflectSpherical(sc.position, sc.direction, sc.CoC, sc.radius); + reflectPlane(sc.position, sc.direction, sc.plane); + reflectSpherical(vc.position, vc.direction, vc.CoC, vc.radius); + reflectPlane(vc.position, vc.direction, vc.plane); + + std::cout << "Position " << sc.position << " " << vc.position << std::endl; + std::cout << "Direction " << sc.direction << " " << vc.direction << std::endl; + + for (std::size_t j = 0; j < Vc::double_v::Size; ++j) { + ret |= compare(sc.position.x(), vc.position.x()[j]); + ret |= compare(sc.position.y(), vc.position.y()[j]); + ret |= compare(sc.position.z(), vc.position.z()[j]); + ret |= compare(sc.direction.x(), vc.direction.x()[j]); + ret |= compare(sc.direction.y(), vc.direction.y()[j]); + ret |= compare(sc.direction.z(), vc.direction.z()[j]); + } + } + + // Now test Transformation3D + std::cout << "Transforms :-" << std::endl; + for (size_t i = 0; i < nPhotons; ++i) { + auto &sc = scalar_data[i]; + auto &vc = vc_data[i]; + + // make 6 random scalar Points + Point sp1(p_x(gen), p_y(gen), p_z(gen)); + Point sp2(p_x(gen), p_y(gen), p_z(gen)); + Point sp3(p_x(gen), p_y(gen), p_z(gen)); + Point sp4(p_x(gen), p_y(gen), p_z(gen)); + Point sp5(p_x(gen), p_y(gen), p_z(gen)); + Point sp6(p_x(gen), p_y(gen), p_z(gen)); + // clone to Vc versions + Point vp1(sp1.x(), sp1.y(), sp1.z()); + Point vp2(sp2.x(), sp2.y(), sp2.z()); + Point vp3(sp3.x(), sp3.y(), sp3.z()); + Point vp4(sp4.x(), sp4.y(), sp4.z()); + Point vp5(sp5.x(), sp5.y(), sp5.z()); + Point vp6(sp6.x(), sp6.y(), sp6.z()); + + // Make transformations from points + // note warnings about axis not having the same angles expected here... + // point is to check scalar and vector versions do the same thing + ROOT::Math::Impl::Transform3D st(sp1, sp2, sp3, sp4, sp5, sp6); + ROOT::Math::Impl::Transform3D vt(vp1, vp2, vp3, vp4, vp5, vp6); + + // transform the vectors + const auto sv = st * sc.direction; + const auto vv = vt * vc.direction; + std::cout << "Transformed Direction " << sv << " " << vv << std::endl; + + // invert the transformations + st.Invert(); + vt.Invert(); + + // Move the points back + const auto sv_i = st * sv; + const auto vv_i = vt * vv; + std::cout << "Transformed Back Direction " << sc.direction << " " << sv_i << " " << vv_i << std::endl; + + for (std::size_t j = 0; j < Vc::double_v::Size; ++j) { + ret |= compare(sv.x(), vv.x()[j]); + ret |= compare(sv.y(), vv.y()[j]); + ret |= compare(sv.z(), vv.z()[j]); + ret |= compare(sc.direction.x(), vv_i.x()[j]); + ret |= compare(sc.direction.y(), vv_i.y()[j]); + ret |= compare(sc.direction.z(), vv_i.z()[j]); + } + + ret |= compare(sc.direction.x(), sv_i.x()); + ret |= compare(sc.direction.y(), sv_i.y()); + ret |= compare(sc.direction.z(), sv_i.z()); + } + + if (ret) + std::cerr << "test FAILED !!! " << std::endl; + else + std::cout << "test OK " << std::endl; + return ret; +} From a18221a58ecb1d74dd819f0631feedae84c574dd Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 13 Mar 2017 12:26:44 +0000 Subject: [PATCH 31/44] extend test to 96 photons --- test/testGenVectorVc.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/testGenVectorVc.cxx b/test/testGenVectorVc.cxx index 433c8e9be478e..90b1a612c4496 100644 --- a/test/testGenVectorVc.cxx +++ b/test/testGenVectorVc.cxx @@ -15,7 +15,9 @@ #include "Math/GenVector/Plane3D.h" #include "Math/GenVector/Transform3D.h" -int compare(double v1, double v2, const std::string &name = "", double scale = 100.0) +// note scale here is > 1 as SIMD and scalar floating point calculations not +// expected to be bit wise identical +int compare(double v1, double v2, const std::string &name = "", double scale = 1000.0) { // ntest = ntest + 1; @@ -202,9 +204,7 @@ int main(int /*argc*/, char ** /*argv*/) int ret = 0; // must be multiple of 8 - // const unsigned int nPhotons = 96 * 1e2; - const unsigned int nPhotons = 8; - // const unsigned int nPhotons = 8; + const unsigned int nPhotons = 96; std::cout << "Creating " << nPhotons << " random photons ..." << std::endl; // Scalar Types From eb0b8edb5443ce12ea3f998a3425ee768acca694 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 13 Mar 2017 12:42:51 +0000 Subject: [PATCH 32/44] reorder headers --- test/testGenVectorVc.cxx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/testGenVectorVc.cxx b/test/testGenVectorVc.cxx index 90b1a612c4496..665ffeb398d93 100644 --- a/test/testGenVectorVc.cxx +++ b/test/testGenVectorVc.cxx @@ -1,4 +1,13 @@ +// ROOT +#include "Math/GenVector/PositionVector3D.h" +#include "Math/GenVector/DisplacementVector3D.h" +#include "Math/GenVector/Plane3D.h" +#include "Math/GenVector/Transform3D.h" + +// Vc +#include + // STL #include #include @@ -6,15 +15,6 @@ #include #include -// Vc -#include - -// ROOT -#include "Math/GenVector/PositionVector3D.h" -#include "Math/GenVector/DisplacementVector3D.h" -#include "Math/GenVector/Plane3D.h" -#include "Math/GenVector/Transform3D.h" - // note scale here is > 1 as SIMD and scalar floating point calculations not // expected to be bit wise identical int compare(double v1, double v2, const std::string &name = "", double scale = 1000.0) From 7da1945fead2276102191a9b91d152e2fdaf8345 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 13 Mar 2017 13:33:49 +0000 Subject: [PATCH 33/44] remove comment that number of test photons must be multiple of 8, as no longer true --- test/testGenVectorVc.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/testGenVectorVc.cxx b/test/testGenVectorVc.cxx index 665ffeb398d93..c85102a1c6df9 100644 --- a/test/testGenVectorVc.cxx +++ b/test/testGenVectorVc.cxx @@ -203,8 +203,7 @@ int main(int /*argc*/, char ** /*argv*/) { int ret = 0; - // must be multiple of 8 - const unsigned int nPhotons = 96; + const unsigned int nPhotons = 100; std::cout << "Creating " << nPhotons << " random photons ..." << std::endl; // Scalar Types From a271eabcffad904c727f051b2c850f5bc24c857e Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 13 Mar 2017 20:43:58 +0000 Subject: [PATCH 34/44] Add header includes --- math/genvector/inc/Math/GenVector/Cartesian3D.h | 3 +-- math/genvector/inc/Math/GenVector/Cylindrical3D.h | 2 +- math/genvector/inc/Math/GenVector/CylindricalEta3D.h | 1 + math/genvector/inc/Math/GenVector/LorentzVector.h | 2 +- math/genvector/inc/Math/GenVector/Polar3D.h | 1 + math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h | 2 +- math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h | 2 ++ math/genvector/inc/Math/GenVector/Transform3D.h | 1 + 8 files changed, 9 insertions(+), 5 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Cartesian3D.h b/math/genvector/inc/Math/GenVector/Cartesian3D.h index 54cf050e2ce83..178a806badc9b 100644 --- a/math/genvector/inc/Math/GenVector/Cartesian3D.h +++ b/math/genvector/inc/Math/GenVector/Cartesian3D.h @@ -24,11 +24,10 @@ #include "Math/Math.h" #include - +#include #include "Math/GenVector/eta.h" - namespace ROOT { namespace Math { diff --git a/math/genvector/inc/Math/GenVector/Cylindrical3D.h b/math/genvector/inc/Math/GenVector/Cylindrical3D.h index 44168bf71e9e7..1da51c2802fd7 100644 --- a/math/genvector/inc/Math/GenVector/Cylindrical3D.h +++ b/math/genvector/inc/Math/GenVector/Cylindrical3D.h @@ -21,7 +21,7 @@ #include "Math/GenVector/eta.h" #include - +#include namespace ROOT { diff --git a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h index cd42dd314d40d..6f51bc92e3ff1 100644 --- a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h +++ b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h @@ -26,6 +26,7 @@ #include +#include #include "Math/Math.h" diff --git a/math/genvector/inc/Math/GenVector/LorentzVector.h b/math/genvector/inc/Math/GenVector/LorentzVector.h index b7e9ef8a91c0a..4e43064563c6c 100644 --- a/math/genvector/inc/Math/GenVector/LorentzVector.h +++ b/math/genvector/inc/Math/GenVector/LorentzVector.h @@ -24,7 +24,7 @@ #include "Math/GenVector/GenVectorIO.h" - +#include namespace ROOT { diff --git a/math/genvector/inc/Math/GenVector/Polar3D.h b/math/genvector/inc/Math/GenVector/Polar3D.h index fd8c014494ade..4d5d532b956f9 100644 --- a/math/genvector/inc/Math/GenVector/Polar3D.h +++ b/math/genvector/inc/Math/GenVector/Polar3D.h @@ -23,6 +23,7 @@ #include "Math/GenVector/eta.h" +#include namespace ROOT { diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h index ee2bf3627c4ec..499d74b5e3d50 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h @@ -32,7 +32,7 @@ #include #endif - +#include namespace ROOT { diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h index 03e60b4b5cee7..9e5a7b36bb29a 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h @@ -30,6 +30,8 @@ #include #endif +#include + namespace ROOT { namespace Math { diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index 4347ac496243c..80a23a01f973f 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -37,6 +37,7 @@ #include #include +#include //#include "Math/Vector3Dfwd.h" From decbe11b36df7bf862a67a50738b2e9667ea229d Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 14 Mar 2017 13:18:12 +0000 Subject: [PATCH 35/44] revert back to using std:: as it seems to cause issues with gcc builds. Works with Vc as long as Vc's headers are included first... --- .../inc/Math/GenVector/Cartesian2D.h | 29 +++------ .../inc/Math/GenVector/Cartesian3D.h | 31 +++------ .../inc/Math/GenVector/Cylindrical3D.h | 28 ++------ .../inc/Math/GenVector/CylindricalEta3D.h | 32 +++------ .../inc/Math/GenVector/LorentzVector.h | 21 +++--- math/genvector/inc/Math/GenVector/Polar2D.h | 16 +---- math/genvector/inc/Math/GenVector/Polar3D.h | 38 +++-------- .../inc/Math/GenVector/PtEtaPhiE4D.h | 65 +++++++++---------- .../inc/Math/GenVector/PtEtaPhiM4D.h | 58 +++++++---------- math/genvector/inc/Math/GenVector/PxPyPzE4D.h | 40 ++++-------- math/genvector/inc/Math/GenVector/PxPyPzM4D.h | 36 +++------- .../inc/Math/GenVector/Transform3D.h | 3 +- math/genvector/inc/Math/GenVector/eta.h | 13 ++-- 13 files changed, 138 insertions(+), 272 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/Cartesian2D.h b/math/genvector/inc/Math/GenVector/Cartesian2D.h index 1b90c57dc13c9..adc6e981fb424 100644 --- a/math/genvector/inc/Math/GenVector/Cartesian2D.h +++ b/math/genvector/inc/Math/GenVector/Cartesian2D.h @@ -89,16 +89,8 @@ public : Scalar X() const { return fX;} Scalar Y() const { return fY;} Scalar Mag2() const { return fX*fX + fY*fY; } - Scalar R() const - { - using namespace std; - return sqrt(Mag2()); - } - Scalar Phi() const - { - using namespace std; - return (fX == Scalar(0) && fY == Scalar(0)) ? Scalar(0) : atan2(fY, fX); - } + Scalar R() const { return std::sqrt(Mag2()); } + Scalar Phi() const { return (fX == Scalar(0) && fY == Scalar(0)) ? Scalar(0) : std::atan2(fY, fX); } /** set the x coordinate value keeping y constant @@ -132,10 +124,9 @@ public : rotate by an angle */ void Rotate(Scalar angle) { - using namespace std; - const Scalar s = sin(angle); - const Scalar c = cos(angle); - SetCoordinates( c*fX - s*fY, s*fX + c * fY ); + const Scalar s = std::sin(angle); + const Scalar c = std::cos(angle); + SetCoordinates(c * fX - s * fY, s * fX + c * fY); } /** @@ -170,11 +161,10 @@ public : template explicit Cartesian2D( const Polar2D & v ) { - using namespace std; const Scalar r = v.R(); // re-using this instead of calling v.X() and v.Y() // is the speed improvement - fX = r * cos(v.Phi()); - fY = r * sin(v.Phi()); + fX = r * std::cos(v.Phi()); + fY = r * std::sin(v.Phi()); } // Technical note: This works even though only Polar2Dfwd.h is // included (and in fact, including Polar2D.h would cause circularity @@ -184,10 +174,9 @@ public : template Cartesian2D & operator = (const Polar2D & v) { - using namespace std; const Scalar r = v.R(); - fX = r * cos(v.Phi()); - fY = r * sin(v.Phi()); + fX = r * std::cos(v.Phi()); + fY = r * std::sin(v.Phi()); return *this; } diff --git a/math/genvector/inc/Math/GenVector/Cartesian3D.h b/math/genvector/inc/Math/GenVector/Cartesian3D.h index 178a806badc9b..0e06d8e3b4484 100644 --- a/math/genvector/inc/Math/GenVector/Cartesian3D.h +++ b/math/genvector/inc/Math/GenVector/Cartesian3D.h @@ -109,26 +109,13 @@ public : Scalar Z() const { return fZ;} Scalar Mag2() const { return fX*fX + fY*fY + fZ*fZ;} Scalar Perp2() const { return fX*fX + fY*fY ;} - Scalar Rho() const - { - using namespace std; - return sqrt(Perp2()); - } - Scalar R() const - { - using namespace std; - return sqrt(Mag2()); - } + Scalar Rho() const { return std::sqrt(Perp2()); } + Scalar R() const { return std::sqrt(Mag2()); } Scalar Theta() const { - using namespace std; - return (fX == Scalar(0) && fY == Scalar(0) && fZ == Scalar(0)) ? Scalar(0) : atan2(Rho(), Z()); - } - Scalar Phi() const - { - using namespace std; - return (fX == Scalar(0) && fY == Scalar(0)) ? Scalar(0) : atan2(fY, fX); + return (fX == Scalar(0) && fY == Scalar(0) && fZ == Scalar(0)) ? Scalar(0) : std::atan2(Rho(), Z()); } + Scalar Phi() const { return (fX == Scalar(0) && fY == Scalar(0)) ? Scalar(0) : std::atan2(fY, fX); } // pseudorapidity Scalar Eta() const { @@ -208,12 +195,11 @@ public : template explicit Cartesian3D( const Polar3D & v ) : fZ (v.Z()) { - using namespace std; const T rho = v.Rho(); // re-using this instead of calling v.X() and v.Y() // is the speed improvement - fX = rho * cos(v.Phi()); - fY = rho * sin(v.Phi()); + fX = rho * std::cos(v.Phi()); + fY = rho * std::sin(v.Phi()); } // Technical note: This works even though only Polar3Dfwd.h is // included (and in fact, including Polar3D.h would cause circularity @@ -223,10 +209,9 @@ public : template Cartesian3D & operator = (const Polar3D & v) { - using namespace std; const T rho = v.Rho(); - fX = rho * cos(v.Phi()); - fY = rho * sin(v.Phi()); + fX = rho * std::cos(v.Phi()); + fY = rho * std::sin(v.Phi()); fZ = v.Z(); return *this; } diff --git a/math/genvector/inc/Math/GenVector/Cylindrical3D.h b/math/genvector/inc/Math/GenVector/Cylindrical3D.h index 1da51c2802fd7..91702b3fc7d4a 100644 --- a/math/genvector/inc/Math/GenVector/Cylindrical3D.h +++ b/math/genvector/inc/Math/GenVector/Cylindrical3D.h @@ -109,9 +109,7 @@ public : inline static Scalar pi() { return Scalar(M_PI); } inline void Restrict() { - using namespace std; - if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); - return; + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - std::floor(fPhi / (2 * pi()) + .5) * 2 * pi(); } public: @@ -121,29 +119,13 @@ public : Scalar Z() const { return fZ; } Scalar Phi() const { return fPhi; } - Scalar X() const - { - using namespace std; - return fRho * cos(fPhi); - } - Scalar Y() const - { - using namespace std; - return fRho * sin(fPhi); - } + Scalar X() const { return fRho * std::cos(fPhi); } + Scalar Y() const { return fRho * std::sin(fPhi); } Scalar Mag2() const { return fRho*fRho + fZ*fZ; } - Scalar R() const - { - using namespace std; - return sqrt(Mag2()); - } + Scalar R() const { return std::sqrt(Mag2()); } Scalar Perp2() const { return fRho*fRho; } - Scalar Theta() const - { - using namespace std; - return (fRho == Scalar(0) && fZ == Scalar(0)) ? Scalar(0) : atan2(fRho, fZ); - } + Scalar Theta() const { return (fRho == Scalar(0) && fZ == Scalar(0)) ? Scalar(0) : std::atan2(fRho, fZ); } // pseudorapidity - use same implementation as in Cartesian3D Scalar Eta() const { diff --git a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h index 6f51bc92e3ff1..9c20b7f09e5cc 100644 --- a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h +++ b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h @@ -70,7 +70,6 @@ public : explicit CylindricalEta3D( const CoordSystem & v ) : fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() ) { - using namespace std; static Scalar bigEta = Scalar(-0.3) * log(std::numeric_limits::epsilon()); if (fabs(fEta) > bigEta) { // This gives a small absolute adjustment in rho, @@ -126,8 +125,7 @@ public : private: inline static Scalar pi() { return M_PI; } inline void Restrict() { - using namespace std; - if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - std::floor(fPhi / (2 * pi()) + .5) * 2 * pi(); return; } public: @@ -137,34 +135,24 @@ public : T Rho() const { return fRho; } T Eta() const { return fEta; } T Phi() const { return fPhi; } - T X() const - { - using namespace std; - return fRho * cos(fPhi); - } - T Y() const - { - using namespace std; - return fRho * sin(fPhi); - } + T X() const { return fRho * std::cos(fPhi); } + T Y() const { return fRho * std::sin(fPhi); } T Z() const { - using namespace std; - return fRho > 0 ? fRho * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax(); + return fRho > 0 ? fRho * std::sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax(); } T R() const { - using namespace std; - return fRho > 0 ? fRho * cosh(fEta) + return fRho > 0 ? fRho * std::cosh(fEta) : fEta > etaMax() ? fEta - etaMax() : fEta < -etaMax() ? -fEta - etaMax() : 0; } - T Mag2() const { return R()*R(); } - T Perp2() const { return fRho*fRho; } - T Theta() const + T Mag2() const { - using namespace std; - return fRho > 0 ? 2 * atan(exp(-fEta)) : (fEta >= 0 ? 0 : pi()); + const Scalar r = R(); + return r * r; } + T Perp2() const { return fRho*fRho; } + T Theta() const { return fRho > 0 ? 2 * std::atan(exp(-fEta)) : (fEta >= 0 ? 0 : pi()); } // setters (only for data members) diff --git a/math/genvector/inc/Math/GenVector/LorentzVector.h b/math/genvector/inc/Math/GenVector/LorentzVector.h index 4e43064563c6c..932100493118e 100644 --- a/math/genvector/inc/Math/GenVector/LorentzVector.h +++ b/math/genvector/inc/Math/GenVector/LorentzVector.h @@ -488,10 +488,9 @@ namespace ROOT { // TODO - It would be good to check that E > Pz and use the Throw() // mechanism or at least load a NAN if not. // We should then move the code to a .cpp file. - using namespace std; - Scalar ee = E(); - Scalar ppz = Pz(); - return Scalar(0.5) * log((ee + ppz) / (ee - ppz)); + const Scalar ee = E(); + const Scalar ppz = Pz(); + return Scalar(0.5) * std::log((ee + ppz) / (ee - ppz)); } /** @@ -500,10 +499,9 @@ namespace ROOT { Scalar ColinearRapidity() const { // TODO - It would be good to check that E > P and use the Throw() // mechanism or at least load a NAN if not. - using namespace std; - Scalar ee = E(); - Scalar pp = P(); - return Scalar(0.5) * log((ee + pp) / (ee - pp)); + const Scalar ee = E(); + const Scalar pp = P(); + return Scalar(0.5) * std::log((ee + pp) / (ee - pp)); } /** @@ -599,9 +597,8 @@ namespace ROOT { Return Gamma scalar value */ Scalar Gamma() const { - using namespace std; - Scalar v2 = P2(); - Scalar t2 = E()*E(); + const Scalar v2 = P2(); + const Scalar t2 = std::pow(E(), 2); if (E() == 0) { if ( P2() == 0) { return 1; @@ -617,7 +614,7 @@ namespace ROOT { else if ( t2 == v2 ) { GenVector::Throw ("LorentzVector::Gamma() - gamma computed for a lightlike LorentzVector. Infinite result"); } - return Scalar(1) / sqrt(Scalar(1) - v2 / t2); + return Scalar(1) / std::sqrt(Scalar(1) - v2 / t2); } /* gamma */ diff --git a/math/genvector/inc/Math/GenVector/Polar2D.h b/math/genvector/inc/Math/GenVector/Polar2D.h index 5bfe37fcf9205..64eb7e71206f2 100644 --- a/math/genvector/inc/Math/GenVector/Polar2D.h +++ b/math/genvector/inc/Math/GenVector/Polar2D.h @@ -97,16 +97,8 @@ public : Scalar R() const { return fR;} Scalar Phi() const { return fPhi; } - Scalar X() const - { - using namespace std; - return fR * cos(fPhi); - } - Scalar Y() const - { - using namespace std; - return fR * sin(fPhi); - } + Scalar X() const { return fR * std::cos(fPhi); } + Scalar Y() const { return fR * std::sin(fPhi); } Scalar Mag2() const { return fR*fR;} @@ -142,9 +134,7 @@ public : restrict abgle hi to be between -PI and PI */ inline void Restrict() { - using namespace std; - if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); - return; + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - std::floor(fPhi / (2 * pi()) + .5) * 2 * pi(); } public: diff --git a/math/genvector/inc/Math/GenVector/Polar3D.h b/math/genvector/inc/Math/GenVector/Polar3D.h index 4d5d532b956f9..a92c761ba9d1c 100644 --- a/math/genvector/inc/Math/GenVector/Polar3D.h +++ b/math/genvector/inc/Math/GenVector/Polar3D.h @@ -110,32 +110,12 @@ public : Scalar R() const { return fR;} Scalar Phi() const { return fPhi; } Scalar Theta() const { return fTheta; } - Scalar Rho() const - { - using namespace std; - return fR * sin(fTheta); - } - Scalar X() const - { - using namespace std; - return Rho() * cos(fPhi); - } - Scalar Y() const - { - using namespace std; - return Rho() * sin(fPhi); - } - Scalar Z() const - { - using namespace std; - return fR * cos(fTheta); - } + Scalar Rho() const { return fR * std::sin(fTheta); } + Scalar X() const { return Rho() * std::cos(fPhi); } + Scalar Y() const { return Rho() * std::sin(fPhi); } + Scalar Z() const { return fR * std::cos(fTheta); } Scalar Mag2() const { return fR*fR;} - Scalar Perp2() const - { - const Scalar r = Rho(); - return r * r; - } + Scalar Perp2() const { return std::pow(Rho(), 2); } // pseudorapidity Scalar Eta() const @@ -177,9 +157,7 @@ public : private: inline static Scalar pi() { return M_PI; } inline void Restrict() { - using namespace std; - if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); - return; + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - std::floor(fPhi / (2 * pi()) + .5) * 2 * pi(); } public: @@ -229,8 +207,8 @@ public : // The following make this coordinate system look enough like a CLHEP // vector that an assignment member template can work with either - T x() const { return X();} - T y() const { return Y();} + T x() const { return X(); } + T y() const { return Y(); } T z() const { return Z(); } // ============= Specializations for improved speed ================== diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h index 499d74b5e3d50..bc9a01d479f62 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiE4D.h @@ -137,21 +137,13 @@ public : // other coordinate representation - Scalar Px() const - { - using namespace std; - return fPt * cos(fPhi); - } + Scalar Px() const { return fPt * std::cos(fPhi); } Scalar X () const { return Px(); } - Scalar Py() const - { - using namespace std; - return fPt * sin(fPhi); - } + Scalar Py() const { return fPt * std::sin(fPhi); } Scalar Y () const { return Py(); } Scalar Pz() const { - using namespace std; - return fPt > 0 ? fPt * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax(); + return fPt > 0 ? fPt * std::sinh(fEta) + : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax(); } Scalar Z () const { return Pz(); } @@ -159,8 +151,7 @@ public : magnitude of momentum */ Scalar P() const { - using namespace std; - return fPt > 0 ? fPt * cosh(fEta) + return fPt > 0 ? fPt * std::cosh(fEta) : fEta > etaMax() ? fEta - etaMax() : fEta < -etaMax() ? -fEta - etaMax() : 0; } @@ -169,26 +160,33 @@ public : /** squared magnitude of spatial components (momentum squared) */ - Scalar P2() const { Scalar p = P(); return p*p; } + Scalar P2() const + { + const Scalar p = P(); + return p * p; + } /** vector magnitude squared (or mass squared) */ - Scalar M2() const { Scalar p = P(); return fE*fE - p*p; } + Scalar M2() const + { + const Scalar p = P(); + return fE * fE - p * p; + } Scalar Mag2() const { return M2(); } /** invariant mass */ Scalar M() const { - using namespace std; - Scalar mm = M2(); + const Scalar mm = M2(); if (mm >= 0) { - return sqrt(mm); + return std::sqrt(mm); } else { GenVector::Throw ("PtEtaPhiE4D::M() - Tachyonic:\n" " Pt and Eta give P such that P^2 > E^2, so the mass would be imaginary"); - return -sqrt(-mm); + return -std::sqrt(-mm); } } Scalar Mag() const { return M(); } @@ -208,14 +206,13 @@ public : transverse mass */ Scalar Mt() const { - using namespace std; - Scalar mm = Mt2(); + const Scalar mm = Mt2(); if (mm >= 0) { - return sqrt(mm); + return std::sqrt(mm); } else { GenVector::Throw ("PtEtaPhiE4D::Mt() - Tachyonic:\n" " Pt and Eta give Pz such that Pz^2 > E^2, so the mass would be imaginary"); - return -sqrt(-mm); + return -std::sqrt(-mm); } } @@ -226,22 +223,22 @@ public : transverse energy */ Scalar Et() const { - using namespace std; - return fE / cosh(fEta); // faster using eta + return fE / std::cosh(fEta); // faster using eta } /** transverse energy squared */ - Scalar Et2() const { Scalar et = Et(); return et*et; } - + Scalar Et2() const + { + const Scalar et = Et(); + return et * et; + } private: inline static Scalar pi() { return M_PI; } inline void Restrict() { - using namespace std; - if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); - return; + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - std::floor(fPhi / (2 * pi()) + .5) * 2 * pi(); } public: @@ -249,10 +246,8 @@ public : polar angle */ Scalar Theta() const { - using namespace std; - if (fPt > 0) return 2 * atan(exp(-fEta)); - if (fEta >= 0) return 0; - return pi(); + return ( fPt > 0 ? Scalar(2) * std::atan(std::exp(-fEta)) : + fEta >= 0 ? 0 : pi() ); } // --------- Set Coordinates of this system --------------- diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h index 9e5a7b36bb29a..3cb7094292b47 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h @@ -143,20 +143,20 @@ public : in this coordinate system it can be negagative if set that way. */ Scalar M() const { return fM; } - Scalar Mag() const { return M(); } + Scalar Mag() const { return M(); } Scalar Perp()const { return Pt(); } Scalar Rho() const { return Pt(); } // other coordinate representation - Scalar Px() const { return fPt*cos(fPhi);} + Scalar Px() const { return fPt * std::cos(fPhi); } Scalar X () const { return Px(); } - Scalar Py() const { return fPt*sin(fPhi);} + Scalar Py() const { return fPt * std::sin(fPhi); } Scalar Y () const { return Py(); } Scalar Pz() const { - using namespace std; - return fPt > 0 ? fPt * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax(); + return fPt > 0 ? fPt * std::sinh(fEta) + : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax() : fEta + etaMax(); } Scalar Z () const { return Pz(); } @@ -164,8 +164,7 @@ public : magnitude of momentum */ Scalar P() const { - using namespace std; - return fPt > 0 ? fPt * cosh(fEta) + return fPt > 0 ? fPt * std::cosh(fEta) : fEta > etaMax() ? fEta - etaMax() : fEta < -etaMax() ? -fEta - etaMax() : 0; } @@ -174,7 +173,11 @@ public : /** squared magnitude of spatial components (momentum squared) */ - Scalar P2() const { Scalar p = P(); return p*p; } + Scalar P2() const + { + const Scalar p = P(); + return p * p; + } /** energy squared @@ -188,11 +191,7 @@ public : /** Energy (timelike component of momentum-energy 4-vector) */ - Scalar E() const - { - using namespace std; - return sqrt(E2()); - } + Scalar E() const { return std::sqrt(E2()); } Scalar T() const { return E(); } @@ -220,14 +219,13 @@ public : transverse mass - will be negative if Mt2() is negative */ Scalar Mt() const { - using namespace std; - Scalar mm = Mt2(); + const Scalar mm = Mt2(); if (mm >= 0) { - return sqrt(mm); + return std::sqrt(mm); } else { GenVector::Throw ("PtEtaPhiM4D::Mt() - Tachyonic:\n" " Pz^2 > E^2 so the transverse mass would be imaginary"); - return -sqrt(-mm); + return -std::sqrt(-mm); } } @@ -235,35 +233,31 @@ public : transverse energy squared */ Scalar Et2() const { - using namespace std; // a bit faster than et * et - return 2. * E2() / (cosh(2 * fEta) + 1); + return 2. * E2() / (std::cosh(2 * fEta) + 1); } /** transverse energy */ Scalar Et() const { - using namespace std; - return E() / cosh(fEta); + return E() / std::cosh(fEta); } private: inline static Scalar pi() { return M_PI; } inline void RestrictPhi() { - using namespace std; - if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi(); - return; + if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - std::floor(fPhi / (2 * pi()) + .5) * 2 * pi(); } // restrict the value of negative mass to avoid unphysical negative E2 values // M2 must be less than P2 for the tachionic particles - otherwise use positive values inline void RestrictNegMass() { - if ( fM >=0 ) return; - if ( P2() - fM*fM < 0 ) { - GenVector::Throw ("PtEtaPhiM4D::unphysical value of mass, set to closest physical value"); - fM = - P(); + if (fM < 0) { + if (P2() - fM * fM < 0) { + GenVector::Throw("PtEtaPhiM4D::unphysical value of mass, set to closest physical value"); + fM = -P(); + } } - return; } public: @@ -272,10 +266,8 @@ public : polar angle */ Scalar Theta() const { - using namespace std; - if (fPt > 0) return 2 * atan(exp(-fEta)); - if (fEta >= 0) return 0; - return pi(); + return ( fPt > 0 ? Scalar(2) * atan(exp(-fEta)) : + fEta >= 0 ? 0 : pi() ); } // --------- Set Coordinates of this system --------------- diff --git a/math/genvector/inc/Math/GenVector/PxPyPzE4D.h b/math/genvector/inc/Math/GenVector/PxPyPzE4D.h index ed74a68ccd4a2..6361482864951 100644 --- a/math/genvector/inc/Math/GenVector/PxPyPzE4D.h +++ b/math/genvector/inc/Math/GenVector/PxPyPzE4D.h @@ -135,11 +135,7 @@ public : /** magnitude of spatial components (magnitude of 3-momentum) */ - Scalar P() const - { - using namespace std; - return sqrt(P2()); - } + Scalar P() const { return std::sqrt(P2()); } Scalar R() const { return P(); } /** @@ -151,15 +147,15 @@ public : /** invariant mass */ - Scalar M() const { - using namespace std; - Scalar mm = M2(); + Scalar M() const + { + const Scalar mm = M2(); if (mm >= 0) { - return sqrt(mm); + return std::sqrt(mm); } else { GenVector::Throw ("PxPyPzE4D::M() - Tachyonic:\n" " P^2 > E^2 so the mass would be imaginary"); - return -sqrt(-mm); + return -std::sqrt(-mm); } } Scalar Mag() const { return M(); } @@ -173,11 +169,7 @@ public : /** Transverse spatial component (P_perp or rho) */ - Scalar Pt() const - { - using namespace std; - return sqrt(Perp2()); - } + Scalar Pt() const { return std::sqrt(Perp2()); } Scalar Perp() const { return Pt();} Scalar Rho() const { return Pt();} @@ -190,14 +182,13 @@ public : transverse mass */ Scalar Mt() const { - using namespace std; - Scalar mm = Mt2(); + const Scalar mm = Mt2(); if (mm >= 0) { - return sqrt(mm); + return std::sqrt(mm); } else { GenVector::Throw ("PxPyPzE4D::Mt() - Tachyonic:\n" " Pz^2 > E^2 so the transverse mass would be imaginary"); - return -sqrt(-mm); + return -std::sqrt(-mm); } } @@ -214,25 +205,22 @@ public : transverse energy */ Scalar Et() const { - using namespace std; - Scalar etet = Et2(); - return fT < 0.0 ? -sqrt(etet) : sqrt(etet); + const Scalar etet = Et2(); + return fT < 0.0 ? -std::sqrt(etet) : std::sqrt(etet); } /** azimuthal angle */ Scalar Phi() const { - using namespace std; - return (fX == 0.0 && fY == 0.0) ? 0 : atan2(fY, fX); + return (fX == 0.0 && fY == 0.0) ? 0 : std::atan2(fY, fX); } /** polar angle */ Scalar Theta() const { - using namespace std; - return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(), fZ); + return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : std::atan2(Pt(), fZ); } /** diff --git a/math/genvector/inc/Math/GenVector/PxPyPzM4D.h b/math/genvector/inc/Math/GenVector/PxPyPzM4D.h index 268b34937ef9a..157edffd51821 100644 --- a/math/genvector/inc/Math/GenVector/PxPyPzM4D.h +++ b/math/genvector/inc/Math/GenVector/PxPyPzM4D.h @@ -154,11 +154,7 @@ public : /** Energy */ - Scalar E() const - { - using namespace std; - return sqrt(E2()); - } + Scalar E() const { return std::sqrt(E2()); } Scalar T() const { return E();} @@ -170,11 +166,7 @@ public : /** magnitude of spatial components (magnitude of 3-momentum) */ - Scalar P() const - { - using namespace std; - return sqrt(P2()); - } + Scalar P() const { return std::sqrt(P2()); } Scalar R() const { return P(); } /** @@ -206,11 +198,7 @@ public : /** Transverse spatial component (P_perp or rho) */ - Scalar Pt() const - { - using namespace std; - return sqrt(Perp2()); - } + Scalar Pt() const { return std::sqrt(Perp2()); } Scalar Perp() const { return Pt();} Scalar Rho() const { return Pt();} @@ -223,14 +211,13 @@ public : transverse mass */ Scalar Mt() const { - using namespace std; - Scalar mm = Mt2(); + const Scalar mm = Mt2(); if (mm >= 0) { - return sqrt(mm); + return std::sqrt(mm); } else { GenVector::Throw ("PxPyPzM4D::Mt() - Tachyonic:\n" " Pz^2 > E^2 so the transverse mass would be imaginary"); - return -sqrt(-mm); + return -std::sqrt(-mm); } } @@ -247,25 +234,22 @@ public : transverse energy */ Scalar Et() const { - using namespace std; - Scalar etet = Et2(); - return sqrt(etet); + const Scalar etet = Et2(); + return std::sqrt(etet); } /** azimuthal angle */ Scalar Phi() const { - using namespace std; - return (fX == 0.0 && fY == 0.0) ? 0.0 : atan2(fY, fX); + return (fX == 0.0 && fY == 0.0) ? 0.0 : std::atan2(fY, fX); } /** polar angle */ Scalar Theta() const { - using namespace std; - return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(), fZ); + return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : std::atan2(Pt(), fZ); } /** diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index 80a23a01f973f..68c8bf0d44004 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -502,8 +502,7 @@ class Transform3D { */ template void GetComponents(IT begin) const { - using namespace std; - copy(fM, fM + 12, begin); + std::copy(fM, fM + 12, begin); } /** diff --git a/math/genvector/inc/Math/GenVector/eta.h b/math/genvector/inc/Math/GenVector/eta.h index 95e5c79641393..7cec4a7758dcb 100644 --- a/math/genvector/inc/Math/GenVector/eta.h +++ b/math/genvector/inc/Math/GenVector/eta.h @@ -46,18 +46,18 @@ namespace ROOT { */ template inline Scalar Eta_FromRhoZ(Scalar rho, Scalar z) { - using namespace std; if (rho > 0) { // value to control Taylor expansion of sqrt - static const Scalar big_z_scaled = pow(std::numeric_limits::epsilon(), static_cast(-.25)); + static const Scalar big_z_scaled = + std::pow(std::numeric_limits::epsilon(), static_cast(-.25)); Scalar z_scaled = z/rho; if (fabs(z_scaled) < big_z_scaled) { - return log(z_scaled + sqrt(z_scaled * z_scaled + 1.0)); + return std::log(z_scaled + std::sqrt(z_scaled * z_scaled + 1.0)); } else { // apply correction using first order Taylor expansion of sqrt - return z > 0 ? log(2.0 * z_scaled + 0.5 / z_scaled) : -log(-2.0 * z_scaled); + return z > 0 ? std::log(2.0 * z_scaled + 0.5 / z_scaled) : -std::log(-2.0 * z_scaled); } } // case vector has rho = 0 @@ -80,8 +80,7 @@ namespace ROOT { */ template inline Scalar Eta_FromTheta(Scalar theta, Scalar r) { - using namespace std; - Scalar tanThetaOver2 = tan(theta / 2.); + Scalar tanThetaOver2 = std::tan(theta / 2.); if (tanThetaOver2 == 0) { return r + etaMax(); } @@ -89,7 +88,7 @@ namespace ROOT { return -r - etaMax(); } else { - return -log(tanThetaOver2); + return -std::log(tanThetaOver2); } } From 58c631569d876f180253f1f4cead5c4be3e781dc Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 14 Mar 2017 13:21:50 +0000 Subject: [PATCH 36/44] Include Vc before ROOT in test application. Needed for std:: support... --- test/testGenVectorVc.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/testGenVectorVc.cxx b/test/testGenVectorVc.cxx index c85102a1c6df9..30d001e57b235 100644 --- a/test/testGenVectorVc.cxx +++ b/test/testGenVectorVc.cxx @@ -1,13 +1,13 @@ +// Vc. Must be before the ROOT includes for std:: math functions to work... +#include + // ROOT #include "Math/GenVector/PositionVector3D.h" #include "Math/GenVector/DisplacementVector3D.h" #include "Math/GenVector/Plane3D.h" #include "Math/GenVector/Transform3D.h" -// Vc -#include - // STL #include #include From 17f42a3819d70b280745824812c52c3f22e4cfc6 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 14 Mar 2017 13:36:01 +0000 Subject: [PATCH 37/44] Add some more missing std:: --- math/genvector/inc/Math/GenVector/CylindricalEta3D.h | 2 +- math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h | 2 +- math/genvector/inc/Math/GenVector/RotationX.h | 4 ++-- math/genvector/inc/Math/GenVector/RotationY.h | 4 ++-- math/genvector/inc/Math/GenVector/RotationZ.h | 4 ++-- math/genvector/inc/Math/GenVector/VectorUtil.h | 12 ++++++------ math/genvector/inc/Math/GenVector/eta.h | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h index 9c20b7f09e5cc..dfa958031f0ca 100644 --- a/math/genvector/inc/Math/GenVector/CylindricalEta3D.h +++ b/math/genvector/inc/Math/GenVector/CylindricalEta3D.h @@ -71,7 +71,7 @@ public : fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() ) { static Scalar bigEta = Scalar(-0.3) * log(std::numeric_limits::epsilon()); - if (fabs(fEta) > bigEta) { + if (std::fabs(fEta) > bigEta) { // This gives a small absolute adjustment in rho, // which, for large eta, results in a significant // improvement in the faithfullness of reproducing z. diff --git a/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h b/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h index 3cb7094292b47..277713424ae14 100644 --- a/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h +++ b/math/genvector/inc/Math/GenVector/PtEtaPhiM4D.h @@ -266,7 +266,7 @@ public : polar angle */ Scalar Theta() const { - return ( fPt > 0 ? Scalar(2) * atan(exp(-fEta)) : + return ( fPt > 0 ? Scalar(2) * std::atan(std::exp(-fEta)) : fEta >= 0 ? 0 : pi() ); } diff --git a/math/genvector/inc/Math/GenVector/RotationX.h b/math/genvector/inc/Math/GenVector/RotationX.h index e4768eef07f3c..66b0fc081a32b 100644 --- a/math/genvector/inc/Math/GenVector/RotationX.h +++ b/math/genvector/inc/Math/GenVector/RotationX.h @@ -94,13 +94,13 @@ class RotationX { /** Get the angle */ - void GetAngle ( Scalar & angle ) const { angle = atan2 (fSin,fCos); } + void GetAngle ( Scalar & angle ) const { angle = std::atan2 (fSin,fCos); } void GetComponents ( Scalar & angle ) const { GetAngle(angle); } /** Angle of rotation */ - Scalar Angle () const { return atan2 (fSin,fCos); } + Scalar Angle () const { return std::atan2 (fSin,fCos); } /** Sine or Cosine of the rotation angle diff --git a/math/genvector/inc/Math/GenVector/RotationY.h b/math/genvector/inc/Math/GenVector/RotationY.h index af148e4245859..a71a29e04e268 100644 --- a/math/genvector/inc/Math/GenVector/RotationY.h +++ b/math/genvector/inc/Math/GenVector/RotationY.h @@ -94,13 +94,13 @@ class RotationY { /** Get the angle */ - void GetAngle ( Scalar & angle ) const { angle = atan2 (fSin,fCos); } + void GetAngle ( Scalar & angle ) const { angle = std::atan2 (fSin,fCos); } void GetComponents ( Scalar & angle ) const { GetAngle(angle); } /** Angle of rotation */ - Scalar Angle () const { return atan2 (fSin,fCos); } + Scalar Angle () const { return std::atan2 (fSin,fCos); } /** Sine or Cosine of the rotation angle diff --git a/math/genvector/inc/Math/GenVector/RotationZ.h b/math/genvector/inc/Math/GenVector/RotationZ.h index 1752f1f2cde9f..e9c531db954c4 100644 --- a/math/genvector/inc/Math/GenVector/RotationZ.h +++ b/math/genvector/inc/Math/GenVector/RotationZ.h @@ -94,13 +94,13 @@ class RotationZ { /** Get the angle */ - void GetAngle ( Scalar & angle ) const { angle = atan2 (fSin,fCos); } + void GetAngle ( Scalar & angle ) const { angle = std::atan2 (fSin,fCos); } void GetComponents ( Scalar & angle ) const { GetAngle(angle); } /** Angle of rotation */ - Scalar Angle () const { return atan2 (fSin,fCos); } + Scalar Angle () const { return std::atan2 (fSin,fCos); } /** Sine or Cosine of the rotation angle diff --git a/math/genvector/inc/Math/GenVector/VectorUtil.h b/math/genvector/inc/Math/GenVector/VectorUtil.h index 07a2f6c99d516..d100d90bc1005 100644 --- a/math/genvector/inc/Math/GenVector/VectorUtil.h +++ b/math/genvector/inc/Math/GenVector/VectorUtil.h @@ -251,8 +251,8 @@ namespace ROOT { */ template Vector RotateX(const Vector & v, double alpha) { - double sina = sin(alpha); - double cosa = cos(alpha); + double sina = std::sin(alpha); + double cosa = std::cos(alpha); double y2 = v.Y() * cosa - v.Z()*sina; double z2 = v.Z() * cosa + v.Y() * sina; Vector vrot; @@ -268,8 +268,8 @@ namespace ROOT { */ template Vector RotateY(const Vector & v, double alpha) { - double sina = sin(alpha); - double cosa = cos(alpha); + double sina = std::sin(alpha); + double cosa = std::cos(alpha); double x2 = v.X() * cosa + v.Z() * sina; double z2 = v.Z() * cosa - v.X() * sina; Vector vrot; @@ -285,8 +285,8 @@ namespace ROOT { */ template Vector RotateZ(const Vector & v, double alpha) { - double sina = sin(alpha); - double cosa = cos(alpha); + double sina = std::sin(alpha); + double cosa = std::cos(alpha); double x2 = v.X() * cosa - v.Y() * sina; double y2 = v.Y() * cosa + v.X() * sina; Vector vrot; diff --git a/math/genvector/inc/Math/GenVector/eta.h b/math/genvector/inc/Math/GenVector/eta.h index 7cec4a7758dcb..24ee558efb9e9 100644 --- a/math/genvector/inc/Math/GenVector/eta.h +++ b/math/genvector/inc/Math/GenVector/eta.h @@ -53,7 +53,7 @@ namespace ROOT { std::pow(std::numeric_limits::epsilon(), static_cast(-.25)); Scalar z_scaled = z/rho; - if (fabs(z_scaled) < big_z_scaled) { + if (std::fabs(z_scaled) < big_z_scaled) { return std::log(z_scaled + std::sqrt(z_scaled * z_scaled + 1.0)); } else { // apply correction using first order Taylor expansion of sqrt From 434396d7b101c0f7c5069520c332086c552c4237 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 14 Mar 2017 13:46:05 +0000 Subject: [PATCH 38/44] More math updates --- math/genvector/inc/Math/GenVector/RotationX.h | 4 ++-- math/genvector/inc/Math/GenVector/RotationY.h | 4 ++-- math/genvector/inc/Math/GenVector/RotationZ.h | 4 ++-- math/genvector/inc/Math/GenVector/VectorUtil.h | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/RotationX.h b/math/genvector/inc/Math/GenVector/RotationX.h index 66b0fc081a32b..46724188cd275 100644 --- a/math/genvector/inc/Math/GenVector/RotationX.h +++ b/math/genvector/inc/Math/GenVector/RotationX.h @@ -94,13 +94,13 @@ class RotationX { /** Get the angle */ - void GetAngle ( Scalar & angle ) const { angle = std::atan2 (fSin,fCos); } + void GetAngle(Scalar &angle) const { angle = std::atan2(fSin, fCos); } void GetComponents ( Scalar & angle ) const { GetAngle(angle); } /** Angle of rotation */ - Scalar Angle () const { return std::atan2 (fSin,fCos); } + Scalar Angle() const { return std::atan2(fSin, fCos); } /** Sine or Cosine of the rotation angle diff --git a/math/genvector/inc/Math/GenVector/RotationY.h b/math/genvector/inc/Math/GenVector/RotationY.h index a71a29e04e268..0181a472f52a5 100644 --- a/math/genvector/inc/Math/GenVector/RotationY.h +++ b/math/genvector/inc/Math/GenVector/RotationY.h @@ -94,13 +94,13 @@ class RotationY { /** Get the angle */ - void GetAngle ( Scalar & angle ) const { angle = std::atan2 (fSin,fCos); } + void GetAngle(Scalar &angle) const { angle = std::atan2(fSin, fCos); } void GetComponents ( Scalar & angle ) const { GetAngle(angle); } /** Angle of rotation */ - Scalar Angle () const { return std::atan2 (fSin,fCos); } + Scalar Angle() const { return std::atan2(fSin, fCos); } /** Sine or Cosine of the rotation angle diff --git a/math/genvector/inc/Math/GenVector/RotationZ.h b/math/genvector/inc/Math/GenVector/RotationZ.h index e9c531db954c4..819f819cac62d 100644 --- a/math/genvector/inc/Math/GenVector/RotationZ.h +++ b/math/genvector/inc/Math/GenVector/RotationZ.h @@ -94,13 +94,13 @@ class RotationZ { /** Get the angle */ - void GetAngle ( Scalar & angle ) const { angle = std::atan2 (fSin,fCos); } + void GetAngle(Scalar &angle) const { angle = std::atan2(fSin, fCos); } void GetComponents ( Scalar & angle ) const { GetAngle(angle); } /** Angle of rotation */ - Scalar Angle () const { return std::atan2 (fSin,fCos); } + Scalar Angle() const { return std::atan2(fSin, fCos); } /** Sine or Cosine of the rotation angle diff --git a/math/genvector/inc/Math/GenVector/VectorUtil.h b/math/genvector/inc/Math/GenVector/VectorUtil.h index d100d90bc1005..4f3ac65427737 100644 --- a/math/genvector/inc/Math/GenVector/VectorUtil.h +++ b/math/genvector/inc/Math/GenVector/VectorUtil.h @@ -251,7 +251,7 @@ namespace ROOT { */ template Vector RotateX(const Vector & v, double alpha) { - double sina = std::sin(alpha); + double sina = std::sin(alpha); double cosa = std::cos(alpha); double y2 = v.Y() * cosa - v.Z()*sina; double z2 = v.Z() * cosa + v.Y() * sina; @@ -268,8 +268,8 @@ namespace ROOT { */ template Vector RotateY(const Vector & v, double alpha) { - double sina = std::sin(alpha); - double cosa = std::cos(alpha); + double sina = std::sin(alpha); + double cosa = std::cos(alpha); double x2 = v.X() * cosa + v.Z() * sina; double z2 = v.Z() * cosa - v.X() * sina; Vector vrot; @@ -285,7 +285,7 @@ namespace ROOT { */ template Vector RotateZ(const Vector & v, double alpha) { - double sina = std::sin(alpha); + double sina = std::sin(alpha); double cosa = std::cos(alpha); double x2 = v.X() * cosa - v.Y() * sina; double y2 = v.Y() * cosa + v.X() * sina; From b145899d06f3a77872263b493b567a2e6d469462 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 14 Mar 2017 17:58:28 +0000 Subject: [PATCH 39/44] Change enable_if implementation in GenVector --- .../inc/Math/GenVector/DisplacementVector3D.h | 26 ++++++++++--------- math/genvector/inc/Math/GenVector/Plane3D.h | 8 +++--- .../inc/Math/GenVector/PositionVector3D.h | 18 +++++++------ .../inc/Math/GenVector/Transform3D.h | 21 +++++++-------- 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h index 82a0edc382ed5..648ef6af04c86 100644 --- a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h +++ b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h @@ -337,8 +337,8 @@ namespace ROOT { /** return unit vector parallel to this (scalar) */ - template - typename std::enable_if::value, DisplacementVector3D>::type Unit() const + template ::value>::type * = nullptr> + DisplacementVector3D Unit() const { const auto tot = R(); return tot == 0 ? *this : DisplacementVector3D(*this) / tot; @@ -347,8 +347,8 @@ namespace ROOT { /** return unit vector parallel to this (scalar) */ - template - typename std::enable_if::value, DisplacementVector3D>::type Unit() const + template ::value>::type * = nullptr> + DisplacementVector3D Unit() const { SCALAR tot = R(); tot(tot == SCALAR(0)) = SCALAR(1); @@ -634,10 +634,11 @@ namespace ROOT { // ------------- I/O to/from streams ------------- - template - inline typename std::enable_if::Scalar>::value, - std::basic_ostream &>::type - operator<<(std::basic_ostream &os, DisplacementVector3D const &v) + template ::Scalar>::value>::type * = + nullptr> + std::basic_ostream &operator<<(std::basic_ostream &os, + DisplacementVector3D const &v) { if (os) { @@ -658,10 +659,11 @@ namespace ROOT { return os; } // op<< <>() - template - inline typename std::enable_if::Scalar>::value, - std::basic_ostream &>::type - operator<<(std::basic_ostream &os, DisplacementVector3D const &v) + template ::Scalar>::value>::type * = + nullptr> + std::basic_ostream &operator<<(std::basic_ostream &os, + DisplacementVector3D const &v) { if (os) { os << "{ "; diff --git a/math/genvector/inc/Math/GenVector/Plane3D.h b/math/genvector/inc/Math/GenVector/Plane3D.h index 93c856b362c13..5871d7598b182 100644 --- a/math/genvector/inc/Math/GenVector/Plane3D.h +++ b/math/genvector/inc/Math/GenVector/Plane3D.h @@ -218,8 +218,8 @@ class Plane3D { /** Normalize the normal (a,b,c) plane components */ - template - typename std::enable_if::value, void>::type Normalize() + template ::value>::type * = nullptr> + void Normalize() { // normalize the plane const SCALAR s = std::sqrt(fA * fA + fB * fB + fC * fC); @@ -238,8 +238,8 @@ class Plane3D { /** Normalize the normal (a,b,c) plane components */ - template - typename std::enable_if::value, void>::type Normalize() + template ::value>::type * = nullptr> + void Normalize() { // normalize the plane SCALAR s = sqrt(fA * fA + fB * fB + fC * fC); diff --git a/math/genvector/inc/Math/GenVector/PositionVector3D.h b/math/genvector/inc/Math/GenVector/PositionVector3D.h index b7fb47c85e24b..9a1aa5cb08adc 100644 --- a/math/genvector/inc/Math/GenVector/PositionVector3D.h +++ b/math/genvector/inc/Math/GenVector/PositionVector3D.h @@ -577,10 +577,11 @@ namespace ROOT { // ------------- I/O to/from streams ------------- - template - inline typename std::enable_if::Scalar>::value, - std::basic_ostream &>::type - operator<<(std::basic_ostream &os, PositionVector3D const &v) + template < + class char_t, class traits_t, class T, class U, + typename std::enable_if::Scalar>::value>::type * = nullptr> + std::basic_ostream &operator<<(std::basic_ostream &os, + PositionVector3D const &v) { if (os) { @@ -603,10 +604,11 @@ namespace ROOT { return os; } // op<< <>() - template - inline typename std::enable_if::Scalar>::value, - std::basic_ostream &>::type - operator<<(std::basic_ostream &os, PositionVector3D const &v) + template < + class char_t, class traits_t, class T, class U, + typename std::enable_if::Scalar>::value>::type * = nullptr> + std::basic_ostream &operator<<(std::basic_ostream &os, + PositionVector3D const &v) { if (os) { os << "{ "; diff --git a/math/genvector/inc/Math/GenVector/Transform3D.h b/math/genvector/inc/Math/GenVector/Transform3D.h index 68c8bf0d44004..54a2dee8580d6 100644 --- a/math/genvector/inc/Math/GenVector/Transform3D.h +++ b/math/genvector/inc/Math/GenVector/Transform3D.h @@ -245,9 +245,9 @@ class Transform3D { @param to1 point defining first axis transformed reference system @param to2 point defining second axis transformed reference system */ - template + template ::value>::type * = nullptr> Transform3D(const Point &fr0, const Point &fr1, const Point &fr2, const Point &to0, const Point &to1, - const Point &to2, typename std::enable_if::value>::type * = nullptr) + const Point &to2) { // takes impl. from CLHEP ( E.Chernyaev). To be checked @@ -339,9 +339,9 @@ class Transform3D { @param to1 point defining first axis transformed reference system @param to2 point defining second axis transformed reference system */ - template + template ::value>::type * = nullptr> Transform3D(const Point &fr0, const Point &fr1, const Point &fr2, const Point &to0, const Point &to1, - const Point &to2, typename std::enable_if::value>::type * = nullptr) + const Point &to2) { // takes impl. from CLHEP ( E.Chernyaev). To be checked @@ -738,8 +738,8 @@ class Transform3D { /** Invert the transformation in place (scalar) */ - template - typename std::enable_if::value, void>::type Invert() + template ::value>::type * = nullptr> + void Invert() { // // Name: Transform3D::inverse Date: 24.09.96 @@ -773,8 +773,8 @@ class Transform3D { /** Invert the transformation in place (vectorised) */ - template - typename std::enable_if::value, void>::type Invert() + template ::value>::type * = nullptr> + void Invert() { // // Name: Transform3D::inverse Date: 24.09.96 @@ -931,9 +931,8 @@ class Transform3D { Set identity transformation (identity rotation , zero translation) vectorised version that sets using a mask */ - template - typename std::enable_if::value, void>::type SetIdentity( - const typename SCALAR::mask_type m) + template ::value>::type * = nullptr> + void SetIdentity(const typename SCALAR::mask_type m) { // set identity ( identity rotation and zero translation) fM[kXX](m) = T(1); From ad8d3a5ef827d1cbefe52a44cf9952a622aa3310 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 14 Mar 2017 18:01:07 +0000 Subject: [PATCH 40/44] update comment --- math/genvector/inc/Math/GenVector/DisplacementVector3D.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h index 648ef6af04c86..d197c757dbb1c 100644 --- a/math/genvector/inc/Math/GenVector/DisplacementVector3D.h +++ b/math/genvector/inc/Math/GenVector/DisplacementVector3D.h @@ -345,7 +345,7 @@ namespace ROOT { } /** - return unit vector parallel to this (scalar) + return unit vector parallel to this (vector) */ template ::value>::type * = nullptr> DisplacementVector3D Unit() const From b018a039c306f86a6e882f38fee676a75b6def8f Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 14 Mar 2017 20:07:32 +0000 Subject: [PATCH 41/44] Extend the GenVector Vc test with a timing test that asserts that the expect speed up based on the SIMD register size is observed (with 10% safety factor) --- test/CMakeLists.txt | 2 +- test/testGenVectorVc.cxx | 232 ++++++++++++++++++++++++--------------- 2 files changed, 147 insertions(+), 87 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b2794fdcb50a1..ce569ac3889a3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -320,7 +320,7 @@ if(ROOT_vc_FOUND) ROOT_ADD_CXX_FLAG(vc_flags -Wno-mismatched-tags) ROOT_ADD_CXX_FLAG(vc_flags -Wno-undefined-var-template) set_source_files_properties(testGenVectorVc.cxx PROPERTIES COMPILE_FLAGS "${vc_flags}") - ROOT_EXECUTABLE(testGenVectorVc testGenVectorVc.cxx LIBRARIES GenVector ${Vc_LIBRARIES} BUILTINS Vc) + ROOT_EXECUTABLE(testGenVectorVc testGenVectorVc.cxx LIBRARIES Physics GenVector ${Vc_LIBRARIES} BUILTINS Vc) ROOT_ADD_TEST(test-GenVector-Vc COMMAND testGenVectorVc FAILREGEX "FAILED|Error in") endif() diff --git a/test/testGenVectorVc.cxx b/test/testGenVectorVc.cxx index 30d001e57b235..0c30a3b090d98 100644 --- a/test/testGenVectorVc.cxx +++ b/test/testGenVectorVc.cxx @@ -7,6 +7,7 @@ #include "Math/GenVector/DisplacementVector3D.h" #include "Math/GenVector/Plane3D.h" #include "Math/GenVector/Transform3D.h" +#include "TStopwatch.h" // STL #include @@ -203,97 +204,156 @@ int main(int /*argc*/, char ** /*argv*/) { int ret = 0; - const unsigned int nPhotons = 100; - std::cout << "Creating " << nPhotons << " random photons ..." << std::endl; - - // Scalar Types - Data, Vector, Plane, double>::Vector scalar_data(nPhotons); - - // Vc Types - Data, Vector, Plane, Vc::double_v>::Vector vc_data; - // Clone the exact random values from the Scalar vector - // Note we are making the same number of entries in the container, but each entry is a vector entry - // with Vc::double_t::Size entries. - fill(scalar_data, vc_data); - - // Loop over the two containers and compare - std::cout << "Ray Tracing :-" << std::endl; - for (size_t i = 0; i < nPhotons; ++i) { - auto &sc = scalar_data[i]; - auto &vc = vc_data[i]; - - // ray tracing - reflectSpherical(sc.position, sc.direction, sc.CoC, sc.radius); - reflectPlane(sc.position, sc.direction, sc.plane); - reflectSpherical(vc.position, vc.direction, vc.CoC, vc.radius); - reflectPlane(vc.position, vc.direction, vc.plane); - - std::cout << "Position " << sc.position << " " << vc.position << std::endl; - std::cout << "Direction " << sc.direction << " " << vc.direction << std::endl; - - for (std::size_t j = 0; j < Vc::double_v::Size; ++j) { - ret |= compare(sc.position.x(), vc.position.x()[j]); - ret |= compare(sc.position.y(), vc.position.y()[j]); - ret |= compare(sc.position.z(), vc.position.z()[j]); - ret |= compare(sc.direction.x(), vc.direction.x()[j]); - ret |= compare(sc.direction.y(), vc.direction.y()[j]); - ret |= compare(sc.direction.z(), vc.direction.z()[j]); + { + + const unsigned int nPhotons = 100; + std::cout << "Creating " << nPhotons << " random photons ..." << std::endl; + + // Scalar Types + Data, Vector, Plane, double>::Vector scalar_data(nPhotons); + + // Vc Types + Data, Vector, Plane, Vc::double_v>::Vector vc_data; + // Clone the exact random values from the Scalar vector + // Note we are making the same number of entries in the container, but each entry is a vector entry + // with Vc::double_t::Size entries. + fill(scalar_data, vc_data); + + // Loop over the two containers and compare + std::cout << "Ray Tracing :-" << std::endl; + for (size_t i = 0; i < nPhotons; ++i) { + auto &sc = scalar_data[i]; + auto &vc = vc_data[i]; + + // ray tracing + reflectSpherical(sc.position, sc.direction, sc.CoC, sc.radius); + reflectPlane(sc.position, sc.direction, sc.plane); + reflectSpherical(vc.position, vc.direction, vc.CoC, vc.radius); + reflectPlane(vc.position, vc.direction, vc.plane); + + std::cout << "Position " << sc.position << " " << vc.position << std::endl; + std::cout << "Direction " << sc.direction << " " << vc.direction << std::endl; + + for (std::size_t j = 0; j < Vc::double_v::Size; ++j) { + ret |= compare(sc.position.x(), vc.position.x()[j]); + ret |= compare(sc.position.y(), vc.position.y()[j]); + ret |= compare(sc.position.z(), vc.position.z()[j]); + ret |= compare(sc.direction.x(), vc.direction.x()[j]); + ret |= compare(sc.direction.y(), vc.direction.y()[j]); + ret |= compare(sc.direction.z(), vc.direction.z()[j]); + } + } + + // Now test Transformation3D + std::cout << "Transforms :-" << std::endl; + for (size_t i = 0; i < nPhotons; ++i) { + auto &sc = scalar_data[i]; + auto &vc = vc_data[i]; + + // make 6 random scalar Points + Point sp1(p_x(gen), p_y(gen), p_z(gen)); + Point sp2(p_x(gen), p_y(gen), p_z(gen)); + Point sp3(p_x(gen), p_y(gen), p_z(gen)); + Point sp4(p_x(gen), p_y(gen), p_z(gen)); + Point sp5(p_x(gen), p_y(gen), p_z(gen)); + Point sp6(p_x(gen), p_y(gen), p_z(gen)); + // clone to Vc versions + Point vp1(sp1.x(), sp1.y(), sp1.z()); + Point vp2(sp2.x(), sp2.y(), sp2.z()); + Point vp3(sp3.x(), sp3.y(), sp3.z()); + Point vp4(sp4.x(), sp4.y(), sp4.z()); + Point vp5(sp5.x(), sp5.y(), sp5.z()); + Point vp6(sp6.x(), sp6.y(), sp6.z()); + + // Make transformations from points + // note warnings about axis not having the same angles expected here... + // point is to check scalar and vector versions do the same thing + ROOT::Math::Impl::Transform3D st(sp1, sp2, sp3, sp4, sp5, sp6); + ROOT::Math::Impl::Transform3D vt(vp1, vp2, vp3, vp4, vp5, vp6); + + // transform the vectors + const auto sv = st * sc.direction; + const auto vv = vt * vc.direction; + std::cout << "Transformed Direction " << sv << " " << vv << std::endl; + + // invert the transformations + st.Invert(); + vt.Invert(); + + // Move the points back + const auto sv_i = st * sv; + const auto vv_i = vt * vv; + std::cout << "Transformed Back Direction " << sc.direction << " " << sv_i << " " << vv_i << std::endl; + + for (std::size_t j = 0; j < Vc::double_v::Size; ++j) { + ret |= compare(sv.x(), vv.x()[j]); + ret |= compare(sv.y(), vv.y()[j]); + ret |= compare(sv.z(), vv.z()[j]); + ret |= compare(sc.direction.x(), vv_i.x()[j]); + ret |= compare(sc.direction.y(), vv_i.y()[j]); + ret |= compare(sc.direction.z(), vv_i.z()[j]); + } + + ret |= compare(sc.direction.x(), sv_i.x()); + ret |= compare(sc.direction.y(), sv_i.y()); + ret |= compare(sc.direction.z(), sv_i.z()); } } - // Now test Transformation3D - std::cout << "Transforms :-" << std::endl; - for (size_t i = 0; i < nPhotons; ++i) { - auto &sc = scalar_data[i]; - auto &vc = vc_data[i]; - - // make 6 random scalar Points - Point sp1(p_x(gen), p_y(gen), p_z(gen)); - Point sp2(p_x(gen), p_y(gen), p_z(gen)); - Point sp3(p_x(gen), p_y(gen), p_z(gen)); - Point sp4(p_x(gen), p_y(gen), p_z(gen)); - Point sp5(p_x(gen), p_y(gen), p_z(gen)); - Point sp6(p_x(gen), p_y(gen), p_z(gen)); - // clone to Vc versions - Point vp1(sp1.x(), sp1.y(), sp1.z()); - Point vp2(sp2.x(), sp2.y(), sp2.z()); - Point vp3(sp3.x(), sp3.y(), sp3.z()); - Point vp4(sp4.x(), sp4.y(), sp4.z()); - Point vp5(sp5.x(), sp5.y(), sp5.z()); - Point vp6(sp6.x(), sp6.y(), sp6.z()); - - // Make transformations from points - // note warnings about axis not having the same angles expected here... - // point is to check scalar and vector versions do the same thing - ROOT::Math::Impl::Transform3D st(sp1, sp2, sp3, sp4, sp5, sp6); - ROOT::Math::Impl::Transform3D vt(vp1, vp2, vp3, vp4, vp5, vp6); - - // transform the vectors - const auto sv = st * sc.direction; - const auto vv = vt * vc.direction; - std::cout << "Transformed Direction " << sv << " " << vv << std::endl; - - // invert the transformations - st.Invert(); - vt.Invert(); - - // Move the points back - const auto sv_i = st * sv; - const auto vv_i = vt * vv; - std::cout << "Transformed Back Direction " << sc.direction << " " << sv_i << " " << vv_i << std::endl; - - for (std::size_t j = 0; j < Vc::double_v::Size; ++j) { - ret |= compare(sv.x(), vv.x()[j]); - ret |= compare(sv.y(), vv.y()[j]); - ret |= compare(sv.z(), vv.z()[j]); - ret |= compare(sc.direction.x(), vv_i.x()[j]); - ret |= compare(sc.direction.y(), vv_i.y()[j]); - ret |= compare(sc.direction.z(), vv_i.z()[j]); + // now run some timing tests + { + const unsigned int nPhotons = 96000; // Must be multiple of 16 to avoid padding issues below... + + const unsigned int nTests = 1000; // number of tests to run + + // scalar data + Data, Vector, Plane, double>::Vector scalar_data(nPhotons); + // vector data with total equal number of photons (including vectorised size) + Data, Vector, Plane, Vc::double_v>::Vector vc_data( + nPhotons / Vc::double_v::Size); + + TStopwatch t; + + double best_time_scalar{9e30}, best_time_vector{9e30}; + + // time the scalar implementation + for (unsigned int i = 0; i < nTests; ++i) { + t.Start(); + for (auto &sc : scalar_data) { + reflectSpherical(sc.position, sc.direction, sc.CoC, sc.radius); + reflectPlane(sc.position, sc.direction, sc.plane); + } + t.Stop(); + const auto time = t.RealTime(); + if (time < best_time_scalar) { + best_time_scalar = time; + } } - ret |= compare(sc.direction.x(), sv_i.x()); - ret |= compare(sc.direction.y(), sv_i.y()); - ret |= compare(sc.direction.z(), sv_i.z()); + // time the Vc implementation + for (unsigned int i = 0; i < nTests; ++i) { + t.Start(); + for (auto &vc : vc_data) { + reflectSpherical(vc.position, vc.direction, vc.CoC, vc.radius); + reflectPlane(vc.position, vc.direction, vc.plane); + } + t.Stop(); + const auto time = t.RealTime(); + if (time < best_time_vector) { + best_time_vector = time; + } + } + + std::cout << "Scalar best time = " << best_time_scalar << std::endl; + std::cout << "Vectorised Vc best time = " << best_time_vector << std::endl; + std::cout << "Vectorised Vc SIMD size = " << Vc::double_v::Size << std::endl; + std::cout << "Vectorised Vc speedup = " << best_time_scalar / best_time_vector << std::endl; + + // assert that the vector time is roughly Vc::double_v::Size times smaller than the scalar time + // allow 10% for 'safety' + if ((best_time_vector * Vc::double_v::Size) - best_time_scalar > 0.1 * best_time_scalar) { + ++ret; + } } if (ret) From bb1e386e4be68f75aaf6791b4893de1e4bdaf563 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 14 Mar 2017 20:25:58 +0000 Subject: [PATCH 42/44] add fabs on timing diff and extend Vc genvector expected diff to 25% --- test/testGenVectorVc.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/testGenVectorVc.cxx b/test/testGenVectorVc.cxx index 0c30a3b090d98..c4fa2cea1c497 100644 --- a/test/testGenVectorVc.cxx +++ b/test/testGenVectorVc.cxx @@ -15,6 +15,7 @@ #include #include #include +#include // note scale here is > 1 as SIMD and scalar floating point calculations not // expected to be bit wise identical @@ -350,8 +351,8 @@ int main(int /*argc*/, char ** /*argv*/) std::cout << "Vectorised Vc speedup = " << best_time_scalar / best_time_vector << std::endl; // assert that the vector time is roughly Vc::double_v::Size times smaller than the scalar time - // allow 10% for 'safety' - if ((best_time_vector * Vc::double_v::Size) - best_time_scalar > 0.1 * best_time_scalar) { + // allow 25% for 'safety' + if (std::fabs((best_time_vector * Vc::double_v::Size) - best_time_scalar) > 0.25 * best_time_scalar) { ++ret; } } From 1786383c4665cd6b1325d961139f0e4e3531afa4 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 14 Mar 2017 21:53:35 +0000 Subject: [PATCH 43/44] do not return a failure from the Vc speed test, as test could be run on a VM with poort SIMD support --- test/testGenVectorVc.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/testGenVectorVc.cxx b/test/testGenVectorVc.cxx index c4fa2cea1c497..6eed12b70e773 100644 --- a/test/testGenVectorVc.cxx +++ b/test/testGenVectorVc.cxx @@ -352,9 +352,9 @@ int main(int /*argc*/, char ** /*argv*/) // assert that the vector time is roughly Vc::double_v::Size times smaller than the scalar time // allow 25% for 'safety' - if (std::fabs((best_time_vector * Vc::double_v::Size) - best_time_scalar) > 0.25 * best_time_scalar) { - ++ret; - } + // if (std::fabs((best_time_vector * Vc::double_v::Size) - best_time_scalar) > 0.25 * best_time_scalar) { + // ++ret; + // } } if (ret) From 380dd35cda65cfcfea78af242e8d9fa0b93036fa Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 15 Mar 2017 11:51:39 +0000 Subject: [PATCH 44/44] Update enable_if pattern in GenVector Vc test --- test/testGenVectorVc.cxx | 44 ++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/test/testGenVectorVc.cxx b/test/testGenVectorVc.cxx index 6eed12b70e773..90a2c63225529 100644 --- a/test/testGenVectorVc.cxx +++ b/test/testGenVectorVc.cxx @@ -16,6 +16,7 @@ #include #include #include +#include // note scale here is > 1 as SIMD and scalar floating point calculations not // expected to be bit wise identical @@ -98,12 +99,11 @@ void fill(const INDATA &in, OUTDATA &out) } } -template -inline - typename std::enable_if::value && - std::is_arithmetic::value && std::is_arithmetic::value, - bool>::type - reflectSpherical(POINT &position, VECTOR &direction, const POINT &CoC, const FTYPE radius) +template ::value && + std::is_arithmetic::value && + std::is_arithmetic::value>::type> +inline bool reflectSpherical(POINT &position, VECTOR &direction, const POINT &CoC, const FTYPE radius) { constexpr FTYPE zero(0), two(2.0), four(4.0), half(0.5); const FTYPE a = direction.Mag2(); @@ -124,12 +124,12 @@ inline return OK; } -template -inline - typename std::enable_if::value && - !std::is_arithmetic::value && !std::is_arithmetic::value, - typename FTYPE::mask_type>::type - reflectSpherical(POINT &position, VECTOR &direction, const POINT &CoC, const FTYPE radius) +template ::value && + !std::is_arithmetic::value && + !std::is_arithmetic::value>::type> +inline typename FTYPE::mask_type reflectSpherical(POINT &position, VECTOR &direction, const POINT &CoC, + const FTYPE radius) { const FTYPE two(2.0), four(4.0), half(0.5); const FTYPE a = direction.Mag2(); @@ -154,12 +154,10 @@ inline return OK; } -template -inline typename std::enable_if::value && - std::is_arithmetic::value && - std::is_arithmetic::value, - bool>::type -reflectPlane(POINT &position, VECTOR &direction, const PLANE &plane) +template ::value && + std::is_arithmetic::value>::type> +inline bool reflectPlane(POINT &position, VECTOR &direction, const PLANE &plane) { constexpr typename POINT::Scalar two(2.0); const bool OK = true; @@ -174,12 +172,10 @@ reflectPlane(POINT &position, VECTOR &direction, const PLANE &plane) return OK; } -template -inline typename std::enable_if::value && - !std::is_arithmetic::value && - !std::is_arithmetic::value, - typename FTYPE::mask_type>::type -reflectPlane(POINT &position, VECTOR &direction, const PLANE &plane) +template ::value && + !std::is_arithmetic::value>::type> +inline typename FTYPE::mask_type reflectPlane(POINT &position, VECTOR &direction, const PLANE &plane) { const typename POINT::Scalar two(2.0); const typename FTYPE::mask_type OK(true);