2// ---------------------------------------------------------------------------
4// This file is a part of the CLHEP - a Class Library for High Energy Physics.
6// This is the definitions of the inline member functions of the
20inline double & Hep3Vector::operator[] (int i) { return data[i]; }
21inline double Hep3Vector::operator[] (int i) const { return data[i]; }
23inline double Hep3Vector::x() const { return (*this)[X]; }
24inline double Hep3Vector::y() const { return (*this)[Y]; }
25inline double Hep3Vector::z() const { return (*this)[Z]; }
27inline double Hep3Vector::getX() const { return (*this)[X]; }
28inline double Hep3Vector::getY() const { return (*this)[Y]; }
29inline double Hep3Vector::getZ() const { return (*this)[Z]; }
31inline void Hep3Vector::setX(double x) { (*this)[X] = x; }
32inline void Hep3Vector::setY(double y) { (*this)[Y] = y; }
33inline void Hep3Vector::setZ(double z) { (*this)[Z] = z; }
35inline void Hep3Vector::set(double x, double y, double z) {
41inline double Hep3Vector::operator () (int i) const {
45inline double & Hep3Vector::operator () (int i) {
53inline Hep3Vector operator + (const Hep3Vector & a, const Hep3Vector & b) {
54 return Hep3Vector(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
57inline Hep3Vector operator - (const Hep3Vector & a, const Hep3Vector & b) {
58 return Hep3Vector(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
61inline Hep3Vector operator * (const Hep3Vector & p, double a) {
62 return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
65inline Hep3Vector operator * (double a, const Hep3Vector & p) {
66 return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
69inline double operator * (const Hep3Vector & a, const Hep3Vector & b) {
73// --------------------------
74// Set in various coordinates
75// --------------------------
77inline void Hep3Vector::setRThetaPhi
78 ( double r1, double theta1, double phi1 ) {
79 setSpherical (r1, theta1, phi1);
82inline void Hep3Vector::setREtaPhi
83 ( double r1, double eta1, double phi1 ) {
84 setSpherical (r1, 2*std::atan(std::exp(-eta1)), phi1);
87inline void Hep3Vector::setRhoPhiZ
88 ( double rho1, double phi1, double z1) {
89 setCylindrical (rho1, phi1, z1);
96inline Hep3Vector::Hep3Vector()
97 : data{0.0, 0.0, 0.0} {}
98inline Hep3Vector::Hep3Vector(double x)
99 : data{ x , 0.0, 0.0} {}
100inline Hep3Vector::Hep3Vector(double x, double y)
101 : data{ x , y , 0.0} {}
102inline Hep3Vector::Hep3Vector(double x, double y, double z)
103 : data{ x , y , z } {}
105inline Hep3Vector::Hep3Vector(const Hep3Vector & p)
106 : data{p.x(), p.y(), p.z()} {}
108inline Hep3Vector::~Hep3Vector() {}
110inline Hep3Vector & Hep3Vector::operator = (const Hep3Vector & p) {
111 set(p.x(), p.y(), p.z());
121inline double Hep3Vector::mag2() const { return x()*x() + y()*y() + z()*z(); }
122inline double Hep3Vector::mag() const { return std::sqrt(mag2()); }
123inline double Hep3Vector::r() const { return mag(); }
125inline double Hep3Vector::theta() const {
126 return x() == 0.0 && y() == 0.0 && z() == 0.0 ? 0.0 : std::atan2(perp(),z());
128inline double Hep3Vector::phi() const {
129 return x() == 0.0 && y() == 0.0 ? 0.0 : std::atan2(y(),x());
132inline double Hep3Vector::getR() const { return mag(); }
133inline double Hep3Vector::getTheta() const { return theta(); }
134inline double Hep3Vector::getPhi() const { return phi(); }
135inline double Hep3Vector::angle() const { return theta(); }
137inline double Hep3Vector::cosTheta() const {
139 return ptot == 0.0 ? 1.0 : z()/ptot;
142inline double Hep3Vector::cos2Theta() const {
143 double ptot2 = mag2();
144 return ptot2 == 0.0 ? 1.0 : z()*z()/ptot2;
147inline void Hep3Vector::setR(double r1) { setMag(r1); }
149inline void Hep3Vector::setTheta(double th) {
152 setX(ma*std::sin(th)*std::cos(ph));
153 setY(ma*std::sin(th)*std::sin(ph));
154 setZ(ma*std::cos(th));
157inline void Hep3Vector::setPhi(double ph) {
159 setX(xy*std::cos(ph));
160 setY(xy*std::sin(ph));
165inline double Hep3Vector::perp2() const { return x()*x() + y()*y(); }
166inline double Hep3Vector::perp() const { return std::sqrt(perp2()); }
167inline double Hep3Vector::rho() const { return perp(); }
168inline double Hep3Vector::eta() const { return pseudoRapidity();}
170inline double Hep3Vector::getRho() const { return perp(); }
171inline double Hep3Vector::getEta() const { return pseudoRapidity();}
173inline void Hep3Vector::setPerp(double r1) {
180inline void Hep3Vector::setRho(double rho1) { setPerp (rho1); }
186inline bool Hep3Vector::operator == (const Hep3Vector& v) const {
187 return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
190inline bool Hep3Vector::operator != (const Hep3Vector& v) const {
191 return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
194inline double Hep3Vector::getTolerance () {
202inline Hep3Vector& Hep3Vector::operator += (const Hep3Vector & p) {
209inline Hep3Vector& Hep3Vector::operator -= (const Hep3Vector & p) {
216inline Hep3Vector Hep3Vector::operator - () const {
217 return Hep3Vector(-x(), -y(), -z());
220inline Hep3Vector& Hep3Vector::operator *= (double a) {
227// -------------------
228// Combine two Vectors
229// -------------------
231inline double Hep3Vector::diff2(const Hep3Vector & p) const {
232 return (*this-p).mag2();
235inline double Hep3Vector::dot(const Hep3Vector & p) const {
236 return x()*p.x() + y()*p.y() + z()*p.z();
239inline Hep3Vector Hep3Vector::cross(const Hep3Vector & p) const {
240 return Hep3Vector(y()*p.z()-p.y()*z(), z()*p.x()-p.z()*x(), x()*p.y()-p.x()*y());
243inline double Hep3Vector::perp2(const Hep3Vector & p) const {
244 double tot = p.mag2();
246 return tot > 0.0 ? mag2()-ss*ss/tot : mag2();
249inline double Hep3Vector::perp(const Hep3Vector & p) const {
250 return std::sqrt(perp2(p));
253inline Hep3Vector Hep3Vector::perpPart () const {
254 return Hep3Vector (x(), y(), 0);
256inline Hep3Vector Hep3Vector::project () const {
257 return Hep3Vector (0, 0, z());
260inline Hep3Vector Hep3Vector::perpPart (const Hep3Vector & v2) const {
261 return ( *this - project(v2) );
264inline double Hep3Vector::angle(const Hep3Vector & q) const {
265 return std::acos(cosTheta(q));
268inline double Hep3Vector::theta(const Hep3Vector & q) const {
272inline double Hep3Vector::azimAngle(const Hep3Vector & v2) const {
280inline Hep3Vector Hep3Vector::unit() const {
282 Hep3Vector p(x(),y(),z());
283 return tot > 0.0 ? p *= (1.0/std::sqrt(tot)) : p;
286inline Hep3Vector Hep3Vector::orthogonal() const {
287 double xx = x() < 0.0 ? -x() : x();
288 double yy = y() < 0.0 ? -y() : y();
289 double zz = z() < 0.0 ? -z() : z();
291 return xx < zz ? Hep3Vector(0,z(),-y()) : Hep3Vector(y(),-x(),0);
293 return yy < zz ? Hep3Vector(-z(),0,x()) : Hep3Vector(y(),-x(),0);