Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:16

0001 #ifndef GeometryVector_PV3DBase_h
0002 #define GeometryVector_PV3DBase_h
0003 
0004 #include "DataFormats/GeometryVector/interface/Basic3DVector.h"
0005 #include <iosfwd>
0006 
0007 /** Base class for Point and Vector classes with restricted set of operations and
0008  *  coordinate frame compile time checking.
0009  *  This class restricts the interface of Basic3DVector, removing all algebraic
0010  *  operations and limiting the constructors. The Point and Vector classes
0011  *  inherit from this class, and add the relevant algebraic operations.
0012  */
0013 
0014 template <class T, class PVType, class FrameType>
0015 class PV3DBase {
0016 public:
0017   typedef T ScalarType;
0018   typedef Basic3DVector<T> BasicVectorType;
0019   typedef typename BasicVectorType::Cylindrical Cylindrical;
0020   typedef typename BasicVectorType::Spherical Spherical;
0021   typedef typename BasicVectorType::Polar Polar;
0022   typedef typename BasicVectorType::MathVector MathVector;
0023 
0024   /** default constructor uses default constructor of T to initialize the 
0025    *  components. For built-in floating-point types this means initialization 
0026    * to zero
0027    */
0028   PV3DBase() : theVector() {}
0029 
0030   /// construct from cartesian coordinates
0031   PV3DBase(const T& x, const T& y, const T& z) : theVector(x, y, z) {}
0032 
0033   /** Construct from cylindrical coordinates.
0034    */
0035   PV3DBase(const Cylindrical& set) : theVector(set) {}
0036 
0037   /// construct from polar coordinates
0038   PV3DBase(const Polar& set) : theVector(set) {}
0039 
0040   /** Deprecated construct from polar coordinates, use 
0041    *  constructor from Polar( theta, phi, r) instead. 
0042    */
0043   PV3DBase(const Geom::Theta<T>& th, const Geom::Phi<T>& ph, const T& r) : theVector(th, ph, r) {}
0044 
0045   /** Explicit constructor from BasicVectorType, possibly of different precision
0046    */
0047   template <class U>
0048   explicit PV3DBase(const Basic3DVector<U>& v) : theVector(v) {}
0049 
0050   /** Access to the basic vector, use only when the operations on Point and Vector
0051    *  are too restrictive (preferably never). 
0052    */
0053   const BasicVectorType& basicVector() const { return theVector; }
0054 #ifndef __REFLEX__
0055   MathVector const& mathVector() const { return theVector.v; }
0056   MathVector& mathVector() { return theVector.v; }
0057 #endif
0058 
0059   T x() const { return basicVector().x(); }
0060   T y() const { return basicVector().y(); }
0061   T z() const { return basicVector().z(); }
0062 
0063   T mag2() const { return basicVector().mag2(); }
0064   T mag() const { return basicVector().mag(); }
0065   T barePhi() const { return basicVector().barePhi(); }
0066   Geom::Phi<T> phi() const { return basicVector().phi(); }
0067 
0068   T perp2() const { return basicVector().perp2(); }
0069   T perp() const { return basicVector().perp(); }
0070   T transverse() const { return basicVector().transverse(); }
0071   T bareTheta() const { return basicVector().bareTheta(); }
0072   Geom::Theta<T> theta() const { return basicVector().theta(); }
0073   T eta() const { return basicVector().eta(); }
0074 
0075 protected:
0076   BasicVectorType theVector;
0077 };
0078 
0079 template <class T, class PV, class F>
0080 inline std::ostream& operator<<(std::ostream& s, const PV3DBase<T, PV, F>& v) {
0081   return s << v.basicVector();
0082 }
0083 
0084 #endif  // GeometryVector_PV3DBase_h