Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:40

0001 // -*- C++ -*-
0002 // $Id: LorentzVector.icc,v 1.3 2010/06/16 17:15:57 garren Exp $
0003 // ---------------------------------------------------------------------------
0004 //
0005 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
0006 // 
0007 // This is the definitions of the inline member functions of the
0008 // HepLorentzVector class.
0009 //
0010 
0011 #include "CLHEP/Vector/ZMxpv.h"
0012 
0013 #include <cmath>
0014 
0015 namespace CLHEP {
0016 
0017 inline double HepLorentzVector::x() const { return pp.x(); }
0018 inline double HepLorentzVector::y() const { return pp.y(); }
0019 inline double HepLorentzVector::z() const { return pp.z(); }
0020 inline double HepLorentzVector::t() const { return ee; }
0021 
0022 inline HepLorentzVector::
0023 HepLorentzVector(double x1, double y1, double z1, double t1)
0024   : pp(x1, y1, z1), ee(t1) {}
0025 
0026 inline HepLorentzVector:: HepLorentzVector(double x1, double y1, double z1)
0027   : pp(x1, y1, z1), ee(0) {}
0028 
0029 inline HepLorentzVector:: HepLorentzVector(double t1)
0030   : pp(0, 0, 0), ee(t1) {}
0031 
0032 inline HepLorentzVector:: HepLorentzVector()
0033   : pp(0, 0, 0), ee(0) {}
0034 
0035 inline HepLorentzVector::HepLorentzVector(const Hep3Vector & p, double e1)
0036   : pp(p), ee(e1) {}
0037 
0038 inline HepLorentzVector::HepLorentzVector(double e1, const Hep3Vector & p)
0039   : pp(p), ee(e1) {}
0040 
0041 inline HepLorentzVector::HepLorentzVector(const HepLorentzVector & p)
0042   : pp(p.x(), p.y(), p.z()), ee(p.t()) {}
0043 
0044 inline HepLorentzVector::~HepLorentzVector() {}
0045 
0046 inline HepLorentzVector::operator const Hep3Vector & () const {return pp;}
0047 inline HepLorentzVector::operator Hep3Vector & () { return pp; }
0048 
0049 inline void HepLorentzVector::setX(double a) { pp.setX(a); } 
0050 inline void HepLorentzVector::setY(double a) { pp.setY(a); }
0051 inline void HepLorentzVector::setZ(double a) { pp.setZ(a); }
0052 inline void HepLorentzVector::setT(double a) { ee = a;}
0053 
0054 inline double HepLorentzVector::px() const { return pp.x(); }
0055 inline double HepLorentzVector::py() const { return pp.y(); }
0056 inline double HepLorentzVector::pz() const { return pp.z(); }
0057 inline double HepLorentzVector::e()  const { return ee; }
0058 
0059 inline void HepLorentzVector::setPx(double a) { pp.setX(a); } 
0060 inline void HepLorentzVector::setPy(double a) { pp.setY(a); }
0061 inline void HepLorentzVector::setPz(double a) { pp.setZ(a); }
0062 inline void HepLorentzVector::setE(double a)  { ee = a;}
0063 
0064 inline Hep3Vector HepLorentzVector::vect() const { return pp; } 
0065 inline void HepLorentzVector::setVect(const Hep3Vector &p) { pp = p; } 
0066 
0067 inline double HepLorentzVector::theta() const { return pp.theta(); }
0068 inline double HepLorentzVector::cosTheta() const { return pp.cosTheta(); }
0069 inline double HepLorentzVector::phi() const { return pp.phi(); }
0070 inline double HepLorentzVector::rho() const { return pp.mag(); }
0071 
0072 inline void HepLorentzVector::setTheta(double a) { pp.setTheta(a); }
0073 inline void HepLorentzVector::setPhi(double a) { pp.setPhi(a); }
0074 inline void HepLorentzVector::setRho(double a) { pp.setMag(a); }
0075 
0076 double & HepLorentzVector::operator [] (int i)       { return (*this)(i); }
0077 double   HepLorentzVector::operator [] (int i) const { return (*this)(i); }
0078 
0079 inline HepLorentzVector &
0080 HepLorentzVector::operator = (const HepLorentzVector & q) {
0081   pp = q.vect();
0082   ee = q.t();
0083   return *this;
0084 }
0085 
0086 inline HepLorentzVector
0087 HepLorentzVector::operator + (const HepLorentzVector & q) const {
0088   return HepLorentzVector(x()+q.x(), y()+q.y(), z()+q.z(), t()+q.t());
0089 }
0090 
0091 inline HepLorentzVector &
0092 HepLorentzVector::operator += (const HepLorentzVector & q) {
0093   pp += q.vect();
0094   ee += q.t();
0095   return *this;
0096 }
0097 
0098 inline HepLorentzVector
0099 HepLorentzVector::operator - (const HepLorentzVector & q) const {
0100   return HepLorentzVector(x()-q.x(), y()-q.y(), z()-q.z(), t()-q.t());
0101 }
0102 
0103 inline HepLorentzVector &
0104 HepLorentzVector::operator -= (const HepLorentzVector & q) {
0105   pp -= q.vect();
0106   ee -= q.t();
0107   return *this;
0108 }
0109 
0110 inline HepLorentzVector HepLorentzVector::operator - () const {
0111   return HepLorentzVector(-x(), -y(), -z(), -t());
0112 }
0113 
0114 inline HepLorentzVector& HepLorentzVector::operator *= (double a) {
0115   pp *= a;
0116   ee *= a;
0117   return *this;
0118 }
0119 
0120 inline bool
0121 HepLorentzVector::operator == (const HepLorentzVector & q) const {
0122   return (vect()==q.vect() && t()==q.t());
0123 }
0124 
0125 inline bool
0126 HepLorentzVector::operator != (const HepLorentzVector & q) const {
0127   return (vect()!=q.vect() || t()!=q.t());
0128 }
0129 
0130 inline double HepLorentzVector::perp2() const   { return pp.perp2(); }
0131 inline double HepLorentzVector::perp()  const   { return pp.perp(); }
0132 inline void HepLorentzVector::setPerp(double a) { pp.setPerp(a); }
0133 
0134 inline double HepLorentzVector::perp2(const Hep3Vector &v1) const {
0135   return pp.perp2(v1);
0136 }
0137 
0138 inline double HepLorentzVector::perp(const Hep3Vector &v1) const {
0139   return pp.perp(v1);
0140 }
0141 
0142 inline double HepLorentzVector::angle(const Hep3Vector &v1) const {
0143   return pp.angle(v1);
0144 }
0145 
0146 inline double HepLorentzVector::mag2() const {
0147   return metric*(t()*t() - pp.mag2());
0148 }
0149 
0150 inline double HepLorentzVector::mag() const {
0151   double mmm = m2();
0152   return mmm < 0.0 ? -std::sqrt(-mmm) : std::sqrt(mmm);
0153 }
0154 
0155 inline double HepLorentzVector::m2() const { 
0156   return t()*t() - pp.mag2();
0157 }
0158 
0159 inline double HepLorentzVector::m() const { return mag(); }
0160 
0161 inline double HepLorentzVector::mt2() const {
0162   return e()*e() - pz()*pz();
0163 }
0164 
0165 inline double HepLorentzVector::mt() const {
0166   double mmm = mt2();
0167   return mmm < 0.0 ? -std::sqrt(-mmm) : std::sqrt(mmm);
0168 }
0169 
0170 inline double HepLorentzVector::et2() const {
0171   double pt2 = pp.perp2();
0172   return pt2 == 0 ? 0 : e()*e() * pt2/(pt2+z()*z());
0173 }
0174 
0175 inline double HepLorentzVector::et() const {
0176   double etet = et2();
0177   return e() < 0.0 ? -std::sqrt(etet) : std::sqrt(etet);
0178 }
0179 
0180 inline double HepLorentzVector::et2(const Hep3Vector & v1) const {
0181   double pt2 = pp.perp2(v1);
0182   double pv = pp.dot(v1.unit());
0183   return pt2 == 0 ? 0 : e()*e() * pt2/(pt2+pv*pv);
0184 }
0185 
0186 inline double HepLorentzVector::et(const Hep3Vector & v1) const {
0187   double etet = et2(v1);
0188   return e() < 0.0 ? -std::sqrt(etet) : std::sqrt(etet);
0189 }
0190 
0191 inline void 
0192 HepLorentzVector::setVectMag(const Hep3Vector & spatial, double magnitude) {
0193   setVect(spatial);
0194   setT(std::sqrt(magnitude * magnitude + spatial * spatial));
0195 }
0196 
0197 inline void 
0198 HepLorentzVector::setVectM(const Hep3Vector & spatial, double mass) {
0199   setVectMag(spatial, mass);
0200 }
0201 
0202 inline double HepLorentzVector::dot(const HepLorentzVector & q) const {
0203   return metric*(t()*q.t() - z()*q.z() - y()*q.y() - x()*q.x());
0204 }
0205 
0206 inline double
0207 HepLorentzVector::operator * (const HepLorentzVector & q) const {
0208   return dot(q);
0209 }
0210 
0211 inline double HepLorentzVector::plus() const {
0212   return t() + z();
0213 }
0214 
0215 inline double HepLorentzVector::minus() const {
0216   return t() - z();
0217 }
0218 
0219 inline HepLorentzVector & HepLorentzVector::boost(const Hep3Vector & b) {
0220   return boost(b.x(), b.y(), b.z());
0221 }
0222 
0223 inline double HepLorentzVector::pseudoRapidity() const {
0224   return pp.pseudoRapidity();
0225 }
0226 
0227 inline double HepLorentzVector::eta() const {
0228   return pp.pseudoRapidity();
0229 }
0230 
0231 inline double HepLorentzVector::eta( const Hep3Vector & ref ) const {
0232   return pp.eta( ref );
0233 }
0234 
0235 inline HepLorentzVector &
0236 HepLorentzVector::operator *= (const HepRotation & m1) {
0237   pp.transform(m1);
0238   return *this;
0239 }
0240 
0241 inline HepLorentzVector &
0242 HepLorentzVector::transform(const HepRotation & m1) {
0243   pp.transform(m1);
0244   return *this;
0245 }
0246 
0247 inline HepLorentzVector operator * (const HepLorentzVector & p, double a) {
0248   return HepLorentzVector(a*p.x(), a*p.y(), a*p.z(), a*p.t());
0249 }
0250 
0251 inline HepLorentzVector operator * (double a, const HepLorentzVector & p) {
0252   return HepLorentzVector(a*p.x(), a*p.y(), a*p.z(), a*p.t());
0253 }
0254 
0255 // The following were added when ZOOM PhysicsVectors was merged in:
0256 
0257 inline HepLorentzVector::HepLorentzVector( 
0258     double x1, double y1, double z1, Tcomponent t1 ) :
0259     pp(x1, y1, z1), ee(t1) {}
0260 
0261 inline void HepLorentzVector::set(
0262     double x1, double y1, double z1, Tcomponent t1 ) {
0263   pp.set(x1,y1,z1);
0264   ee = t1;
0265 }
0266 
0267 inline void HepLorentzVector::set(
0268         double x1, double y1, double z1, double t1 ) {
0269   set (x1,y1,z1,Tcomponent(t1));
0270 }
0271 
0272 inline HepLorentzVector::HepLorentzVector( 
0273     Tcomponent t1, double x1, double y1, double z1 ) :
0274         pp(x1, y1, z1), ee(t1) {}   
0275 
0276 inline void HepLorentzVector::set(
0277     Tcomponent t1, double x1, double y1, double z1 ) {
0278   pp.set(x1,y1,z1);
0279   ee = t1;
0280 }
0281 
0282 inline void HepLorentzVector::set( Tcomponent t1 ) {
0283   pp.set(0, 0, 0);
0284   ee = t1;
0285 }
0286 
0287 inline void HepLorentzVector::set( double t1 ) {
0288   pp.set(0, 0, 0);
0289   ee = t1;
0290 }
0291 
0292 inline HepLorentzVector::HepLorentzVector( Tcomponent t1 ) : 
0293     pp(0, 0, 0), ee(t1) {}
0294 
0295 inline void HepLorentzVector::set( const Hep3Vector & v1 ) {
0296   pp = v1;
0297   ee = 0;
0298 }
0299 
0300 inline HepLorentzVector::HepLorentzVector( const Hep3Vector & v1 ) : 
0301     pp(v1), ee(0) {}
0302 
0303 inline void HepLorentzVector::setV(const Hep3Vector & v1) {
0304   pp = v1;
0305 }
0306 
0307 inline HepLorentzVector & HepLorentzVector::operator=(const Hep3Vector & v1) {
0308   pp = v1;
0309   ee = 0;
0310   return *this;
0311 }
0312 
0313 inline double HepLorentzVector::getX() const { return pp.x(); }
0314 inline double HepLorentzVector::getY() const { return pp.y(); }
0315 inline double HepLorentzVector::getZ() const { return pp.z(); }
0316 inline double HepLorentzVector::getT() const { return ee; }
0317 
0318 inline Hep3Vector HepLorentzVector::getV() const { return pp; } 
0319 inline Hep3Vector HepLorentzVector::v() const { return pp; } 
0320 
0321 inline void HepLorentzVector::set(double t1, const Hep3Vector & v1) {
0322   pp = v1;
0323   ee = t1;
0324 }
0325 
0326 inline void HepLorentzVector::set(const Hep3Vector & v1, double t1) {
0327   pp = v1;
0328   ee = t1;
0329 }
0330 
0331 inline void HepLorentzVector::setV( double x1,
0332              double y1,
0333              double z1 ) { pp.set(x1, y1, z1); }
0334 
0335 inline void HepLorentzVector::setRThetaPhi 
0336         ( double r, double ttheta, double phi1 ) 
0337                          { pp.setRThetaPhi( r, ttheta, phi1 ); }
0338 
0339 inline void HepLorentzVector::setREtaPhi 
0340         ( double r, double eta1, double phi1 ) 
0341                          { pp.setREtaPhi( r, eta1, phi1 ); }
0342 
0343 inline void HepLorentzVector::setRhoPhiZ
0344         ( double rho1, double phi1, double z1 )
0345                          { pp.setRhoPhiZ ( rho1, phi1, z1 ); }
0346 
0347 inline bool HepLorentzVector::isTimelike() const {
0348   return restMass2() > 0;
0349 }  
0350 
0351 inline bool  HepLorentzVector::isSpacelike() const {
0352   return restMass2() < 0;
0353 }
0354 
0355 inline bool  HepLorentzVector::isLightlike(double epsilon) const {
0356   return std::fabs(restMass2()) < 2.0 * epsilon * ee * ee;
0357 }
0358 
0359 inline double HepLorentzVector::diff2( const HepLorentzVector & w ) const {
0360     return metric*( (ee-w.ee)*(ee-w.ee) - (pp-w.pp).mag2() );
0361 }
0362 
0363 inline double HepLorentzVector::delta2Euclidean 
0364                     ( const HepLorentzVector & w ) const {
0365     return (ee-w.ee)*(ee-w.ee) + (pp-w.pp).mag2();
0366 }
0367 
0368 inline double HepLorentzVector::euclideanNorm2()  const {
0369   return ee*ee + pp.mag2();
0370 }
0371 
0372 inline double HepLorentzVector::euclideanNorm()  const {
0373   return std::sqrt(euclideanNorm2());
0374 }
0375 
0376 inline double HepLorentzVector::restMass2()      const { return m2(); }
0377 inline double HepLorentzVector::invariantMass2() const { return m2(); }
0378 
0379 inline double HepLorentzVector::restMass() const {
0380     if( t() < 0.0 ) ZMthrowC(ZMxpvNegativeMass(
0381               "E^2-p^2 < 0 for this particle. Magnitude returned."));
0382     return t() < 0.0 ? -m() : m();
0383 }
0384 
0385 inline double HepLorentzVector::invariantMass() const {
0386     if( t() < 0.0 ) ZMthrowC(ZMxpvNegativeMass(
0387               "E^2-p^2 < 0 for this particle. Magnitude returned."));
0388     return t() < 0.0 ? -m() : m();
0389 }
0390 
0391 inline double HepLorentzVector::invariantMass2
0392                     (const HepLorentzVector & w) const {
0393   return (*this + w).m2();
0394 } /* invariantMass2 */
0395 
0396 //-*********
0397 // boostOf()
0398 //-*********
0399 
0400 // Each of these is a shell over a boost method.
0401 
0402 inline HepLorentzVector boostXOf
0403     (const HepLorentzVector & vec, double bbeta) {
0404   HepLorentzVector vv (vec);
0405   return vv.boostX (bbeta);
0406 }
0407 
0408 inline HepLorentzVector boostYOf
0409     (const HepLorentzVector & vec, double bbeta) {
0410   HepLorentzVector vv (vec);
0411   return vv.boostY (bbeta);
0412 }
0413 
0414 inline HepLorentzVector boostZOf
0415     (const HepLorentzVector & vec, double bbeta) {
0416   HepLorentzVector vv (vec);
0417   return vv.boostZ (bbeta);
0418 }
0419 
0420 inline HepLorentzVector boostOf
0421     (const HepLorentzVector & vec, const Hep3Vector & betaVector ) {
0422   HepLorentzVector vv (vec);
0423   return vv.boost (betaVector);
0424 }
0425 
0426 inline HepLorentzVector boostOf
0427     (const HepLorentzVector & vec, const Hep3Vector & aaxis,  double bbeta) {
0428   HepLorentzVector vv (vec);
0429   return vv.boost (aaxis, bbeta);
0430 }
0431 
0432 }  // namespace CLHEP