00001
00002
00004
00005 #ifndef EVENTPRIMITIVES_AMGMATRIXPLUGIN_H
00006 #define EVENTPRIMITIVES_AMGMATRIXPLUGIN_H
00007
00008
00009
00013
00014
00016 inline const PlainObject unit() const {
00017 return (*this).normalized();
00018 }
00019
00021 inline Scalar mag() const {
00022 return (*this).norm();
00023 }
00024
00026 inline Scalar mag2() const {
00027 return (*this).squaredNorm();
00028 }
00029
00031 inline Scalar perp() const {
00032 if (this->rows() < 2) return 0.;
00033 return std::sqrt( (*this)[0]*(*this)[0]+(*this)[1]*(*this)[1] );
00034 }
00035
00037 inline Scalar perp2() const {
00038 if (this->rows() < 2) return 0.;
00039 return ( (*this)[0]*(*this)[0]+(*this)[1]*(*this)[1] );
00040 }
00041
00042 inline Scalar perp2(const MatrixBase<Derived>& vec){
00043 if (this->rows() < 2) return 0.;
00044 Scalar tot = vec.mag2();
00045 if(tot>0){
00046 Scalar s = this->dot(vec);
00047 return this->mag2()-s*s/tot;
00048 }
00049 return this->mag2();
00050 }
00051 inline Scalar perp(const MatrixBase<Derived>& vec){
00052 return std::sqrt(this->perp2(vec));
00053 }
00054
00056 inline Scalar phi() const {
00057 if (this->rows() < 2) return 0.;
00058 return std::atan2((*this)[1],(*this)[0]);
00059 }
00060
00062 inline Scalar theta() const {
00063 if (this->rows() < 3) return 0.;
00064 return std::atan2(std::sqrt((*this)[0]*(*this)[0]+(*this)[1]*(*this)[1]),(*this)[2]);
00065 }
00066
00068 inline Scalar eta() const {
00069 return -std::log(std::tan(this->theta()*.5));
00070 }
00071
00072 inline Scalar deltaR(const MatrixBase<Derived>& vec){
00073 if (this->rows() < 2) return 0.;
00074 double a = this->eta() - vec.eta();
00075 double b = this->deltaPhi(vec);
00076 return std::sqrt ( a*a + b*b );
00077 }
00078
00079 inline Scalar deltaPhi(const MatrixBase<Derived>& vec){
00080 if (this->rows() < 2) return 0.;
00081 double dphi = vec.phi() - this->phi();
00082 if ( dphi > M_PI ) {
00083 dphi -= M_PI*2;
00084 } else if ( dphi <= -M_PI ) {
00085 dphi += M_PI*2;
00086 }
00087 return dphi;
00088 }
00089
00090
00091
00093 void fillSymmetric(size_t i, size_t j, Scalar value) {
00094 (*this)(i,j) = value;
00095 (*this)(j,i) = value;
00096 }
00097
00098
00099
00100 template<typename OtherDerived>
00101 inline Matrix<Scalar, OtherDerived::RowsAtCompileTime, OtherDerived::RowsAtCompileTime>
00102 similarity(const MatrixBase<OtherDerived>& m) const
00103 {
00104 return m * ( this->derived() * m.transpose() );
00105 }
00106
00108 template<typename OtherDerived>
00109 inline Matrix<Scalar, OtherDerived::RowsAtCompileTime, OtherDerived::RowsAtCompileTime>
00110 similarityT(const MatrixBase<OtherDerived>& m) const
00111 {
00112 return m.transpose() * ( this->derived() * m );
00113 }
00114
00115
00116
00117 #endif