File indexing completed on 2024-04-06 12:31:44
0001 #ifndef VectorDoublet_H
0002 #define VectorDoublet_H
0003
0004 #include "FWCore/Utilities/interface/Visibility.h"
0005 #include "DataFormats/GeometryVector/interface/PreciseFloatType.h"
0006
0007 template <class V1, class V2>
0008 class dso_internal VectorDoublet {
0009 public:
0010 typedef typename V1::ScalarType Scalar1;
0011 typedef typename V2::ScalarType Scalar2;
0012
0013 VectorDoublet() {}
0014 VectorDoublet(const V1& a, const V2& b) : a_(a), b_(b) {}
0015
0016 const V1& first() const { return a_; }
0017 const V2& second() const { return b_; }
0018
0019 VectorDoublet& operator+=(const VectorDoublet& v) {
0020 a_ += v.first();
0021 b_ += v.second();
0022 return *this;
0023 }
0024 VectorDoublet& operator-=(const VectorDoublet& v) {
0025 a_ -= v.first();
0026 b_ -= v.second();
0027 return *this;
0028 }
0029
0030 VectorDoublet operator-() const { return VectorDoublet(-a_, -b_); }
0031
0032 template <class T>
0033 VectorDoublet& operator*=(const T& t) {
0034 a_ *= t;
0035 b_ *= t;
0036 return *this;
0037 }
0038 template <class T>
0039 VectorDoublet& operator/=(const T& t) {
0040 a_ /= t;
0041 b_ /= t;
0042 return *this;
0043 }
0044
0045 typename PreciseFloatType<Scalar1, Scalar2>::Type dot(const VectorDoublet& v) const {
0046 return first() * v.first() + second() * v.second();
0047 }
0048
0049 private:
0050 V1 a_;
0051 V2 b_;
0052 };
0053
0054
0055 template <class V1, class V2>
0056 inline VectorDoublet<V1, V2> operator+(const VectorDoublet<V1, V2>& a, const VectorDoublet<V1, V2>& b) {
0057 return VectorDoublet<V1, V2>(a.first() + b.first(), a.second() + b.second());
0058 }
0059
0060 template <class V1, class V2>
0061 inline VectorDoublet<V1, V2> operator-(const VectorDoublet<V1, V2>& a, const VectorDoublet<V1, V2>& b) {
0062 return VectorDoublet<V1, V2>(a.first() - b.first(), a.second() - b.second());
0063 }
0064
0065
0066
0067
0068 template <class V1, class V2, class Scalar>
0069 inline VectorDoublet<V1, V2> operator*(const VectorDoublet<V1, V2>& v, const Scalar& s) {
0070 return VectorDoublet<V1, V2>(v.first() * s, v.second() * s);
0071 }
0072 template <class V1, class V2, class Scalar>
0073 inline VectorDoublet<V1, V2> operator*(const Scalar& s, const VectorDoublet<V1, V2>& v) {
0074 return VectorDoublet<V1, V2>(v.first() * s, v.second() * s);
0075 }
0076
0077 template <class V1, class V2, class Scalar>
0078 inline VectorDoublet<V1, V2> operator/(const VectorDoublet<V1, V2>& v, const Scalar& s) {
0079 return VectorDoublet<V1, V2>(v.first() / s, v.second() / s);
0080 }
0081
0082 #endif