Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:10

0001 //////////////////////////////////////////////////////////////////////////
0002 // SimpleVector.h
0003 //////////////////////////////////////////////////////////////////////////
0004 #ifndef  HEPMC_SIMPLEVECTOR_H
0005 #define  HEPMC_SIMPLEVECTOR_H
0006 
0007 //////////////////////////////////////////////////////////////////////////
0008 // garren@fnal.gov, July 2006
0009 //
0010 // This header provides a place to hold the doubles which are part of one of 
0011 // three types of physics vectors:
0012 //    momentum 4 vector 
0013 //    position or displacement 4 vector
0014 //    position or displacement 3 vector
0015 //
0016 // For compatibility with existing code, 
0017 // the basic expected geometrical access methods are povided 
0018 // Also, both FourVector and ThreeVector have a templated constructor that will 
0019 // take another vector (HepLorentzVector, GenVector, ...)
0020 //    --> this vector must have the following methods: x(), y(), z()
0021 //    -->  FourVector also requires the t() method
0022 //
0023 //////////////////////////////////////////////////////////////////////////
0024 
0025 
0026 #include "HepMC/enable_if.h"
0027 #include "HepMC/is_arithmetic.h"
0028 
0029 
0030 namespace HepMC {
0031 
0032 //! FourVector is a simple representation of a physics 4 vector
0033 
0034 ///
0035 /// \class  FourVector
0036 /// For compatibility with existing code, 
0037 /// the basic expected geometrical access methods are povided.
0038 /// Also, there is a templated constructor that will 
0039 /// take another vector (HepLorentzVector, GenVector, ...)
0040 /// which must have the following methods: x(), y(), z(), t().
0041 ///
0042 class FourVector {
0043 
0044 public:
0045 
0046   /// constructor requiring at least x, y, and z
0047   FourVector( double xin, double yin, double zin, double tin=0) 
0048   : m_x(xin), m_y(yin), m_z(zin), m_t(tin) {}
0049 
0050   /// constructor requiring only t 
0051   FourVector(double tin)
0052   : m_x(0), m_y(0), m_z(0), m_t(tin) {}
0053 
0054   FourVector() 
0055   : m_x(0), m_y(0), m_z(0), m_t(0) {}
0056 
0057   /// templated constructor
0058   /// this is used ONLY if T is not arithmetic
0059   template <class T >
0060   FourVector( const T& v,
0061          typename detail::disable_if< detail::is_arithmetic<T>::value, void >::type * = 0 )
0062   : m_x(v.x()), m_y(v.y()), m_z(v.z()), m_t(v.t()) {}
0063 
0064   /// copy constructor
0065   FourVector(const FourVector & v)
0066   : m_x(v.x()), m_y(v.y()), m_z(v.z()), m_t(v.t()) {}
0067 
0068   void swap( FourVector & other );  //!< swap
0069 
0070   double px() const { return m_x; }  //!< return px
0071   double py() const { return m_y; }  //!< return py
0072   double pz() const { return m_z; }  //!< return pz
0073   double e()  const { return m_t; }  //!< return E
0074 
0075   double x() const { return m_x; }  //!< return x
0076   double y() const { return m_y; }  //!< return y
0077   double z() const { return m_z; }  //!< return z
0078   double t() const { return m_t; }  //!< return t
0079 
0080   double m2() const;  //!< Invariant mass squared.
0081   double m() const;   //!< Invariant mass. If m2() is negative then -sqrt(-m2()) is returned.
0082 
0083   double perp2() const;  //!< Transverse component of the spatial vector squared.
0084   double perp() const;   //!< Transverse component of the spatial vector (R in cylindrical system).
0085 
0086   // Get spatial vector components in spherical coordinate system.
0087   double theta() const;  //!< The polar angle.
0088   double phi() const;  //!< The azimuth angle.
0089   double rho() const;  //!< spatial vector component magnitude
0090 
0091   FourVector & operator = (const FourVector &); //!< make a copy
0092 
0093   bool operator == (const FourVector &) const; //!< equality
0094   bool operator != (const FourVector &) const; //!< inequality
0095 
0096   double pseudoRapidity() const;  //!< Returns the pseudo-rapidity, i.e. -ln(tan(theta/2))
0097   double eta() const;             //!< Pseudorapidity (of the space part)
0098 
0099   /// set x, y, z, and t
0100   void set        (double x, double y, double z, double  t);
0101 
0102   void setX(double xin) { m_x=xin; }  //!< set x
0103   void setY(double yin) { m_y=yin; }  //!< set y
0104   void setZ(double zin) { m_z=zin; }  //!< set z
0105   void setT(double tin) { m_t=tin; }  //!< set t
0106 
0107   void setPx(double xin) { m_x=xin; }  //!< set px
0108   void setPy(double yin) { m_y=yin; }  //!< set py
0109   void setPz(double zin) { m_z=zin; }  //!< set pz
0110   void setE(double tin)  { m_t=tin; }  //!< set E
0111 
0112 private:
0113 
0114   double m_x;
0115   double m_y;
0116   double m_z;
0117   double m_t;
0118   
0119 };
0120 
0121 //! ThreeVector is a simple representation of a position or displacement 3 vector
0122 
0123 ///
0124 /// \class  ThreeVector
0125 /// For compatibility with existing code, 
0126 /// the basic expected geometrical access methods are povided.
0127 /// Also, there is a templated constructor that will 
0128 /// take another vector (HepLorentzVector, GenVector, ...)
0129 /// which must have the following methods: x(), y(), z().
0130 ///
0131 class ThreeVector {
0132 
0133 public:
0134 
0135   /// construct using x, y, and z (only x is required)
0136   ThreeVector( double xin, double yin =0, double zin =0 ) 
0137   : m_x(xin), m_y(yin), m_z(zin) {}
0138 
0139   ThreeVector( ) 
0140   : m_x(0), m_y(0), m_z(0) {}
0141   
0142   /// templated constructor
0143   /// this is used ONLY if T is not arithmetic
0144   template <class T >
0145   ThreeVector( const T& v,
0146          typename detail::disable_if< detail::is_arithmetic<T>::value, void >::type * = 0 )
0147   : m_x(v.x()), m_y(v.y()), m_z(v.z()) {}
0148 
0149   /// copy constructor
0150   ThreeVector(const ThreeVector & v)
0151   : m_x(v.x()), m_y(v.y()), m_z(v.z()) {}
0152 
0153   void swap( ThreeVector & other );  //!< swap
0154 
0155   double x() const { return m_x; }  //!< return x
0156   double y() const { return m_y; }  //!< return y
0157   double z() const { return m_z; }  //!< return z
0158 
0159   void setX(double xin) { m_x=xin; }  //!< set x
0160   void setY(double yin) { m_y=yin; }  //!< set y
0161   void setZ(double zin) { m_z=zin; }  //!< set z
0162   void set( double x, double y, double z);   //!< set x, y, and z
0163 
0164   double phi()   const;  //!< The azimuth angle.
0165   double theta() const;  //!< The polar angle.
0166   double r()     const;  //!< The magnitude
0167 
0168   void setPhi(double);  //!< Set phi keeping magnitude and theta constant (BaBar).
0169   void setTheta(double);  //!< Set theta keeping magnitude and phi constant (BaBar).
0170 
0171   double perp2() const;  //!< The transverse component squared (rho^2 in cylindrical coordinate system).
0172   double perp() const;  //!< The transverse component (rho in cylindrical coordinate system).
0173 
0174   ThreeVector & operator = (const ThreeVector &); //!< make a copy
0175 
0176   bool operator == (const ThreeVector &) const; //!< equality
0177   bool operator != (const ThreeVector &) const; //!< inequality
0178 
0179 private:
0180 
0181   double m_x;
0182   double m_y;
0183   double m_z;
0184 
0185 };  
0186 
0187 
0188 } // HepMC
0189 
0190 #include "HepMC/SimpleVector.icc"
0191 
0192 #endif  // HEPMC_SIMPLEVECTOR_H
0193