CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/TrackPropagation/RungeKutta/src/VectorDoublet.h

Go to the documentation of this file.
00001 #ifndef VectorDoublet_H
00002 #define VectorDoublet_H
00003 
00004 #include "FWCore/Utilities/interface/Visibility.h"
00005 #include "DataFormats/GeometryVector/interface/PreciseFloatType.h"
00006 
00007 template <class V1, class V2>
00008 class dso_internal VectorDoublet {
00009 public:
00010 
00011   typedef typename V1::ScalarType Scalar1;
00012   typedef typename V2::ScalarType Scalar2;
00013 
00014   VectorDoublet() {}
00015   VectorDoublet( const V1& a, const V2& b) : a_(a), b_(b) {}
00016 
00017   const V1& first() const {return a_;}
00018   const V2& second() const {return b_;}
00019 
00020   VectorDoublet& operator+= ( const VectorDoublet& v) {
00021     a_ += v.first();
00022     b_ += v.second();
00023     return *this;
00024   } 
00025   VectorDoublet& operator-= ( const VectorDoublet& v) {
00026     a_ -= v.first();
00027     b_ -= v.second();
00028     return *this;
00029   } 
00030 
00031   VectorDoublet operator-() const { return VectorDoublet( -a_, -b_);}
00032 
00033   template <class T>
00034   VectorDoublet& operator*= ( const T& t) {
00035     a_ *= t;
00036     b_ *= t;
00037     return *this;
00038   } 
00039   template <class T>
00040   VectorDoublet& operator/= ( const T& t) {
00041     a_ /= t;
00042     b_ /= t;
00043     return *this;
00044   } 
00045 
00046   typename PreciseFloatType<Scalar1,Scalar2>::Type dot( const VectorDoublet& v) const { 
00047     return first()*v.first() + second()*v.second();
00048   }
00049 
00050 private:
00051 
00052   V1 a_;
00053   V2 b_;
00054 
00055 };
00056 
00058 template <class V1, class V2>
00059 inline VectorDoublet<V1,V2>
00060 operator+( const VectorDoublet<V1,V2>& a, const VectorDoublet<V1,V2>& b) {
00061   return VectorDoublet<V1,V2>(a.first()+b.first(), a.second()+b.second());
00062 }
00063 
00064 template <class V1, class V2>
00065 inline VectorDoublet<V1,V2>
00066 operator-( const VectorDoublet<V1,V2>& a, const VectorDoublet<V1,V2>& b) {
00067   return VectorDoublet<V1,V2>(a.first()-b.first(), a.second()-b.second());
00068 }
00069 
00073 template <class V1, class V2, class Scalar>
00074 inline VectorDoublet<V1,V2> operator*( const VectorDoublet<V1,V2>& v, const Scalar& s) {
00075   return VectorDoublet<V1,V2>( v.first()*s, v.second()*s);
00076 }
00077 template <class V1, class V2, class Scalar>
00078 inline VectorDoublet<V1,V2> operator*( const Scalar& s, const VectorDoublet<V1,V2>& v) {
00079   return VectorDoublet<V1,V2>( v.first()*s, v.second()*s);
00080 }
00081 
00082 template <class V1, class V2, class Scalar>
00083 inline VectorDoublet<V1,V2> operator/( const VectorDoublet<V1,V2>& v, const Scalar& s) {
00084   return VectorDoublet<V1,V2>( v.first()/s, v.second()/s);
00085 }
00086 
00087 #endif