Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:20:04

0001 
0002 /***********************************************************************
0003 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors       *
0004 *                                                                      *
0005 * This file is part of EvtGen.                                         *
0006 *                                                                      *
0007 * EvtGen is free software: you can redistribute it and/or modify       *
0008 * it under the terms of the GNU General Public License as published by *
0009 * the Free Software Foundation, either version 3 of the License, or    *
0010 * (at your option) any later version.                                  *
0011 *                                                                      *
0012 * EvtGen is distributed in the hope that it will be useful,            *
0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
0015 * GNU General Public License for more details.                         *
0016 *                                                                      *
0017 * You should have received a copy of the GNU General Public License    *
0018 * along with EvtGen.  If not, see <https://www.gnu.org/licenses/>.     *
0019 ***********************************************************************/
0020 
0021 #ifndef EVTVECTOR4R_HH
0022 #define EVTVECTOR4R_HH
0023 
0024 #include <iostream>
0025 #include <math.h>
0026 
0027 class EvtVector3R;
0028 
0029 class EvtVector4R {
0030     inline friend EvtVector4R operator*( double d, const EvtVector4R& v2 );
0031     inline friend EvtVector4R operator*( const EvtVector4R& v2, double d );
0032     inline friend EvtVector4R operator/( const EvtVector4R& v2, double d );
0033     inline friend double operator*( const EvtVector4R& v1, const EvtVector4R& v2 );
0034     inline friend EvtVector4R operator+( const EvtVector4R& v1,
0035                                          const EvtVector4R& v2 );
0036     inline friend EvtVector4R operator-( const EvtVector4R& v1,
0037                                          const EvtVector4R& v2 );
0038 
0039   public:
0040     EvtVector4R();
0041     EvtVector4R( double e, double px, double py, double pz );
0042     inline void set( int i, double d );
0043     inline void set( double e, double px, double py, double pz );
0044     inline EvtVector4R& operator*=( double c );
0045     inline EvtVector4R& operator/=( double c );
0046     inline EvtVector4R& operator+=( const EvtVector4R& v2 );
0047     inline EvtVector4R& operator-=( const EvtVector4R& v2 );
0048     inline double get( int i ) const;
0049     inline double cont( const EvtVector4R& v4 ) const;
0050     friend std::ostream& operator<<( std::ostream& s, const EvtVector4R& v );
0051     double mass2() const;
0052     double mass() const;
0053     void applyRotateEuler( double alpha, double beta, double gamma );
0054     void applyBoostTo( const EvtVector4R& p4, bool inverse = false );
0055     void applyBoostTo( const EvtVector3R& boost, bool inverse = false );
0056     EvtVector4R cross( const EvtVector4R& v2 );
0057     double dot( const EvtVector4R& v2 ) const;
0058     double d3mag() const;
0059 
0060     // Added by AJB - calculate scalars in the rest frame of the current object
0061     double scalartripler3( const EvtVector4R& p1, const EvtVector4R& p2,
0062                            const EvtVector4R& p3 ) const;
0063     double dotr3( const EvtVector4R& p1, const EvtVector4R& p2 ) const;
0064     double mag2r3( const EvtVector4R& p1 ) const;
0065     double magr3( const EvtVector4R& p1 ) const;
0066 
0067   private:
0068     double v[4];
0069 
0070     inline double Square( double x ) const { return x * x; }
0071 };
0072 
0073 EvtVector4R rotateEuler( const EvtVector4R& rs, double alpha, double beta,
0074                          double gamma );
0075 EvtVector4R boostTo( const EvtVector4R& rs, const EvtVector4R& p4,
0076                      bool inverse = false );
0077 EvtVector4R boostTo( const EvtVector4R& rs, const EvtVector3R& boost,
0078                      bool inverse = false );
0079 
0080 inline EvtVector4R& EvtVector4R::operator+=( const EvtVector4R& v2 )
0081 {
0082     v[0] += v2.v[0];
0083     v[1] += v2.v[1];
0084     v[2] += v2.v[2];
0085     v[3] += v2.v[3];
0086 
0087     return *this;
0088 }
0089 
0090 inline EvtVector4R& EvtVector4R::operator-=( const EvtVector4R& v2 )
0091 {
0092     v[0] -= v2.v[0];
0093     v[1] -= v2.v[1];
0094     v[2] -= v2.v[2];
0095     v[3] -= v2.v[3];
0096 
0097     return *this;
0098 }
0099 
0100 inline double EvtVector4R::mass2() const
0101 {
0102     return v[0] * v[0] - v[1] * v[1] - v[2] * v[2] - v[3] * v[3];
0103 }
0104 
0105 inline EvtVector4R operator*( double c, const EvtVector4R& v2 )
0106 {
0107     return EvtVector4R( v2 ) *= c;
0108 }
0109 
0110 inline EvtVector4R operator*( const EvtVector4R& v2, double c )
0111 {
0112     return EvtVector4R( v2 ) *= c;
0113 }
0114 
0115 inline EvtVector4R operator/( const EvtVector4R& v2, double c )
0116 {
0117     return EvtVector4R( v2 ) /= c;
0118 }
0119 
0120 inline EvtVector4R& EvtVector4R::operator*=( double c )
0121 {
0122     v[0] *= c;
0123     v[1] *= c;
0124     v[2] *= c;
0125     v[3] *= c;
0126 
0127     return *this;
0128 }
0129 
0130 inline EvtVector4R& EvtVector4R::operator/=( double c )
0131 {
0132     double cinv = 1.0 / c;
0133     v[0] *= cinv;
0134     v[1] *= cinv;
0135     v[2] *= cinv;
0136     v[3] *= cinv;
0137 
0138     return *this;
0139 }
0140 
0141 inline double operator*( const EvtVector4R& v1, const EvtVector4R& v2 )
0142 {
0143     return v1.v[0] * v2.v[0] - v1.v[1] * v2.v[1] - v1.v[2] * v2.v[2] -
0144            v1.v[3] * v2.v[3];
0145 }
0146 
0147 inline double EvtVector4R::cont( const EvtVector4R& v4 ) const
0148 {
0149     return v[0] * v4.v[0] - v[1] * v4.v[1] - v[2] * v4.v[2] - v[3] * v4.v[3];
0150 }
0151 
0152 inline EvtVector4R operator-( const EvtVector4R& v1, const EvtVector4R& v2 )
0153 {
0154     return EvtVector4R( v1 ) -= v2;
0155 }
0156 
0157 inline EvtVector4R operator+( const EvtVector4R& v1, const EvtVector4R& v2 )
0158 {
0159     return EvtVector4R( v1 ) += v2;
0160 }
0161 
0162 inline double EvtVector4R::get( int i ) const
0163 {
0164     return v[i];
0165 }
0166 
0167 inline void EvtVector4R::set( int i, double d )
0168 {
0169     v[i] = d;
0170 }
0171 
0172 inline void EvtVector4R::set( double e, double p1, double p2, double p3 )
0173 {
0174     v[0] = e;
0175     v[1] = p1;
0176     v[2] = p2;
0177     v[3] = p3;
0178 }
0179 
0180 #endif