Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:13

0001 // @(#)root/mathcore:$Id$
0002 // Authors: W. Brown, M. Fischler, L. Moneta    2005
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2005 , LCG ROOT MathLib Team                         *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 // Header file for class Translation3D
0012 //
0013 // Created by: Lorenzo Moneta  October 21 2005
0014 //
0015 //
0016 #ifndef ROOT_Math_GenVector_Translation3D
0017 #define ROOT_Math_GenVector_Translation3D  1
0018 
0019 
0020 #include "Math/GenVector/DisplacementVector3D.h"
0021 
0022 #include "Math/GenVector/Plane3D.h"
0023 
0024 #include "Math/GenVector/PositionVector3Dfwd.h"
0025 
0026 #include "Math/GenVector/LorentzVectorfwd.h"
0027 
0028 #include <iostream>
0029 #include <type_traits>
0030 
0031 namespace ROOT {
0032 
0033 namespace Math {
0034 
0035 namespace Impl {
0036 
0037 //____________________________________________________________________________________________________
0038 /**
0039     Class describing a 3 dimensional translation. It can be combined (using the operator *)
0040     with the ROOT::Math::Rotation3D  classes and ROOT::Math::Transform3D to obtained combined
0041     transformations and to operate on points and vectors.
0042     Note that a the translation applied to a Vector object (DisplacementVector3D and LorentzVector classes)
0043     performs a noop, i.e. it returns the same vector. A translation can be applied only to the Point objects
0044     (PositionVector3D classes).
0045 
0046     @ingroup GenVector
0047 
0048     @sa Overview of the @ref GenVector "physics vector library"
0049 
0050 */
0051 
0052 template <typename T = double>
0053 class Translation3D {
0054 
0055 public:
0056    typedef T Scalar;
0057 
0058    typedef DisplacementVector3D<Cartesian3D<T>, DefaultCoordinateSystemTag> Vector;
0059 
0060    /**
0061        Default constructor ( zero translation )
0062    */
0063    Translation3D() {}
0064 
0065    /**
0066       Construct given a pair of pointers or iterators defining the
0067       beginning and end of an array of 3 Scalars representing the z,y,z of the translation vector
0068    */
0069    template<class IT>
0070    Translation3D(IT begin, IT end)
0071    {
0072       fVect.SetCoordinates(begin,end);
0073    }
0074 
0075    /**
0076       Construct from x,y,z values representing the translation
0077    */
0078    Translation3D(T dx, T dy, T dz) : fVect(Vector(dx, dy, dz)) {}
0079 
0080    /**
0081       Construct from any Displacement vector in ant tag and coordinate system
0082    */
0083    template<class CoordSystem, class Tag>
0084    explicit constexpr Translation3D( const DisplacementVector3D<CoordSystem,Tag> & v) :
0085       fVect(Vector(v.X(),v.Y(),v.Z()))
0086    { }
0087 
0088 
0089    /**
0090       Construct transformation from one coordinate system defined one point (the origin)
0091        to a new coordinate system defined by other point (origin )
0092       @param p1  point defining origin of original reference system
0093       @param p2  point defining origin of transformed reference system
0094 
0095    */
0096    template <class CoordSystem, class Tag>
0097    Translation3D(const PositionVector3D<CoordSystem, Tag> &p1, const PositionVector3D<CoordSystem, Tag> &p2)
0098       : fVect(p2 - p1)
0099    { }
0100 
0101 
0102    // use compiler generated copy ctor, copy assignment and dtor
0103 
0104 
0105    // ======== Components ==============
0106 
0107    /**
0108        return a const reference to the underline vector representing the translation
0109    */
0110    const Vector & Vect() const { return fVect; }
0111 
0112    /**
0113       Set the 3  components given an iterator to the start of
0114       the desired data, and another to the end (3 past start).
0115    */
0116    template<class IT>
0117    void SetComponents(IT begin, IT end) {
0118       fVect.SetCoordinates(begin,end);
0119    }
0120 
0121    /**
0122       Get the 3  components into data specified by an iterator begin
0123       and another to the end of the desired data (12 past start).
0124    */
0125    template<class IT>
0126    void GetComponents(IT begin, IT end) const {
0127       fVect.GetCoordinates(begin,end);
0128    }
0129 
0130    /**
0131       Get the 3 matrix components into data specified by an iterator begin
0132    */
0133    template<class IT>
0134    void GetComponents(IT begin) const {
0135       fVect.GetCoordinates(begin);
0136    }
0137 
0138 
0139    /**
0140       Set the components from 3 scalars
0141    */
0142    void SetComponents(T dx, T dy, T dz) { fVect.SetCoordinates(dx, dy, dz); }
0143 
0144    /**
0145       Get the components into 3 scalars
0146    */
0147    void GetComponents(T &dx, T &dy, T &dz) const { fVect.GetCoordinates(dx, dy, dz); }
0148 
0149    /**
0150       Set the XYZ vector components from 3 scalars
0151    */
0152    void SetXYZ(T dx, T dy, T dz) { fVect.SetXYZ(dx, dy, dz); }
0153 
0154    // operations on points and vectors
0155 
0156 
0157    /**
0158       Transformation operation for Position Vector in any coordinate system and default tag
0159    */
0160    template<class CoordSystem, class Tag >
0161    PositionVector3D<CoordSystem,Tag> operator() (const PositionVector3D <CoordSystem,Tag> & p) const {
0162       return PositionVector3D<CoordSystem, Tag>(p.X() + fVect.X(), p.Y() + fVect.Y(), p.Z() + fVect.Z());
0163    }
0164    /**
0165      Transformation operation
0166    */
0167    template <class CoordSystem, class Tag>
0168    PositionVector3D<CoordSystem, Tag> operator*(const PositionVector3D<CoordSystem, Tag> &v) const
0169    {
0170       return operator()(v);
0171    }
0172 
0173    /**
0174       Transformation operation for Displacement Vector in any coordinate system and default tag
0175       For the Displacement Vectors no translation apply so return the vector itself
0176    */
0177    template<class CoordSystem, class Tag >
0178    DisplacementVector3D<CoordSystem,Tag> operator() (const DisplacementVector3D <CoordSystem,Tag> & v) const {
0179       return  v;
0180    }
0181    /**
0182      Transformation operation
0183    */
0184    template <class CoordSystem, class Tag>
0185    DisplacementVector3D<CoordSystem, Tag> operator*(const DisplacementVector3D<CoordSystem, Tag> &v) const
0186    {
0187       return operator()(v);
0188    }
0189 
0190    /**
0191       Transformation operation for points between different coordinate system tags
0192    */
0193    template<class CoordSystem, class Tag1, class Tag2 >
0194    void Transform (const PositionVector3D <CoordSystem,Tag1> & p1, PositionVector3D <CoordSystem,Tag2> & p2  ) const {
0195       PositionVector3D <CoordSystem,Tag2> tmp;
0196       tmp.SetXYZ( p1.X(), p1.Y(), p1.Z() );
0197       p2 =  operator()(tmp);
0198     }
0199 
0200    /**
0201       Transformation operation for Displacement Vector of different coordinate systems
0202    */
0203     template <class CoordSystem, class Tag1, class Tag2>
0204     void Transform(const DisplacementVector3D<CoordSystem, Tag1> &v1, DisplacementVector3D<CoordSystem, Tag2> &v2) const
0205     {
0206        // just copy v1 in v2
0207        v2.SetXYZ(v1.X(), v1.Y(), v1.Z());
0208    }
0209 
0210    /**
0211       Transformation operation for a Lorentz Vector in any  coordinate system
0212       A LorentzVector contains a displacement vector so no translation applies as well
0213    */
0214    template <class CoordSystem>
0215    LorentzVector<CoordSystem> operator()(const LorentzVector<CoordSystem> &q) const
0216    {
0217       return q;
0218    }
0219    /**
0220      Transformation operation
0221    */
0222    template <class CoordSystem>
0223    LorentzVector<CoordSystem> operator*(const LorentzVector<CoordSystem> &q) const
0224    {
0225       return operator()(q);
0226    }
0227 
0228    /**
0229       Transformation on a 3D plane
0230    */
0231    Plane3D<T> operator()(const Plane3D<T> &plane) const
0232    {
0233       // transformations on a 3D plane
0234       const Vector n = plane.Normal();
0235       // take a point on the plane. Use origin projection on the plane
0236       // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1
0237       const T                          d = plane.HesseDistance();
0238       PositionVector3D<Cartesian3D<T>> p(-d * n.X(), -d * n.Y(), -d * n.Z());
0239       return PLANE(operator()(n), operator()(p));
0240    }
0241 
0242    /**
0243       multiply (combine) with another transformation in place
0244    */
0245    Translation3D<T> &operator*=(const Translation3D<T> &t)
0246    {
0247       fVect+= t.Vect();
0248       return *this;
0249    }
0250 
0251    /**
0252       multiply (combine) two transformations
0253    */
0254    Translation3D<T> operator*(const Translation3D<T> &t) const { return Translation3D<T>(fVect + t.Vect()); }
0255 
0256    /**
0257        Invert the transformation in place
0258    */
0259    void Invert() {
0260       SetComponents( -fVect.X(), -fVect.Y(),-fVect.Z() );
0261    }
0262 
0263    /**
0264       Return the inverse of the transformation.
0265    */
0266    Translation3D<T> Inverse() const { return Translation3D<T>(-fVect.X(), -fVect.Y(), -fVect.Z()); }
0267 
0268    /**
0269       Equality/inequality operators
0270    */
0271    bool operator==(const Translation3D<T> &rhs) const
0272    {
0273       if( fVect != rhs.fVect )  return false;
0274       return true;
0275    }
0276 
0277    bool operator!=(const Translation3D<T> &rhs) const { return !operator==(rhs); }
0278 
0279 private:
0280 
0281    Vector fVect;   // internal 3D vector representing the translation
0282 
0283 };
0284 
0285 
0286 
0287 
0288 
0289 // global functions
0290 
0291 // TODO - I/O should be put in the manipulator form
0292 
0293 template <class T>
0294 std::ostream &operator<<(std::ostream &os, const Translation3D<T> &t)
0295 {
0296    // TODO - this will need changing for machine-readable issues
0297    //        and even the human readable form needs formatting improvements
0298 
0299    T m[3];
0300    t.GetComponents(m, m + 3);
0301    return os << "\n" << m[0] << "  " << m[1] << "  " << m[2] << "\n";
0302 }
0303 
0304 // need a function Transform = Translation * Rotation ???
0305 
0306 } // end namespace Impl
0307 
0308 // typedefs for double and float versions
0309 typedef Impl::Translation3D<double> Translation3D;
0310 typedef Impl::Translation3D<float>  Translation3DF;
0311 
0312 } // end namespace Math
0313 
0314 } // end namespace ROOT
0315 
0316 
0317 #endif /* ROOT_Math_GenVector_Translation3D */