3 // ---------------------------------------------------------------------------
5 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
7 // This is the definitions of the inline member functions of the
21 inline double & Hep3Vector::operator[] (int i) { return operator()(i); }
22 inline double Hep3Vector::operator[] (int i) const { return operator()(i); }
24 inline double Hep3Vector::x() const { return dx; }
25 inline double Hep3Vector::y() const { return dy; }
26 inline double Hep3Vector::z() const { return dz; }
28 inline double Hep3Vector::getX() const { return dx; }
29 inline double Hep3Vector::getY() const { return dy; }
30 inline double Hep3Vector::getZ() const { return dz; }
32 inline void Hep3Vector::setX(double x1) { dx = x1; }
33 inline void Hep3Vector::setY(double y1) { dy = y1; }
34 inline void Hep3Vector::setZ(double z1) { dz = z1; }
36 inline void Hep3Vector::set(double x1, double y1, double z1) {
42 inline double Hep3Vector::operator () (int i) const {
54 inline double & Hep3Vector::operator () (int i) {
71 inline Hep3Vector operator + (const Hep3Vector & a, const Hep3Vector & b) {
72 return Hep3Vector(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
75 inline Hep3Vector operator - (const Hep3Vector & a, const Hep3Vector & b) {
76 return Hep3Vector(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
79 inline Hep3Vector operator * (const Hep3Vector & p, double a) {
80 return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
83 inline Hep3Vector operator * (double a, const Hep3Vector & p) {
84 return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
87 inline double operator * (const Hep3Vector & a, const Hep3Vector & b) {
91 // --------------------------
92 // Set in various coordinates
93 // --------------------------
95 inline void Hep3Vector::setRThetaPhi
96 ( double r1, double theta1, double phi1 ) {
97 setSpherical (r1, theta1, phi1);
100 inline void Hep3Vector::setREtaPhi
101 ( double r1, double eta1, double phi1 ) {
102 setSpherical (r1, 2*std::atan(std::exp(-eta1)), phi1);
105 inline void Hep3Vector::setRhoPhiZ
106 ( double rho1, double phi1, double z1) {
107 setCylindrical (rho1, phi1, z1);
114 inline Hep3Vector::Hep3Vector()
115 : dx(0.), dy(0.), dz(0.) {}
116 inline Hep3Vector::Hep3Vector(double x1)
117 : dx(x1), dy(0.), dz(0.) {}
118 inline Hep3Vector::Hep3Vector(double x1, double y1)
119 : dx(x1), dy(y1), dz(0.) {}
120 inline Hep3Vector::Hep3Vector(double x1, double y1, double z1)
121 : dx(x1), dy(y1), dz(z1) {}
123 inline Hep3Vector::Hep3Vector(const Hep3Vector & p)
124 : dx(p.dx), dy(p.dy), dz(p.dz) {}
126 inline Hep3Vector::~Hep3Vector() {}
128 inline Hep3Vector & Hep3Vector::operator = (const Hep3Vector & p) {
135 // ------------------
136 // Access to elements
137 // ------------------
141 inline double Hep3Vector::mag2() const { return dx*dx + dy*dy + dz*dz; }
142 inline double Hep3Vector::mag() const { return std::sqrt(mag2()); }
143 inline double Hep3Vector::r() const { return mag(); }
145 inline double Hep3Vector::theta() const {
146 return dx == 0.0 && dy == 0.0 && dz == 0.0 ? 0.0 : std::atan2(perp(),dz);
148 inline double Hep3Vector::phi() const {
149 return dx == 0.0 && dy == 0.0 ? 0.0 : std::atan2(dy,dx);
152 inline double Hep3Vector::getR() const { return mag(); }
153 inline double Hep3Vector::getTheta() const { return theta(); }
154 inline double Hep3Vector::getPhi() const { return phi(); }
155 inline double Hep3Vector::angle() const { return theta(); }
157 inline double Hep3Vector::cosTheta() const {
159 return ptot == 0.0 ? 1.0 : dz/ptot;
162 inline double Hep3Vector::cos2Theta() const {
163 double ptot2 = mag2();
164 return ptot2 == 0.0 ? 1.0 : dz*dz/ptot2;
167 inline void Hep3Vector::setR(double r1) { setMag(r1); }
169 inline void Hep3Vector::setTheta(double th) {
172 setX(ma*std::sin(th)*std::cos(ph));
173 setY(ma*std::sin(th)*std::sin(ph));
174 setZ(ma*std::cos(th));
177 inline void Hep3Vector::setPhi(double ph) {
179 setX(xy*std::cos(ph));
180 setY(xy*std::sin(ph));
185 inline double Hep3Vector::perp2() const { return dx*dx + dy*dy; }
186 inline double Hep3Vector::perp() const { return std::sqrt(perp2()); }
187 inline double Hep3Vector::rho() const { return perp(); }
188 inline double Hep3Vector::eta() const { return pseudoRapidity();}
190 inline double Hep3Vector::getRho() const { return perp(); }
191 inline double Hep3Vector::getEta() const { return pseudoRapidity();}
193 inline void Hep3Vector::setPerp(double r1) {
200 inline void Hep3Vector::setRho(double rho1) { setPerp (rho1); }
206 inline bool Hep3Vector::operator == (const Hep3Vector& v) const {
207 return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
210 inline bool Hep3Vector::operator != (const Hep3Vector& v) const {
211 return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
214 inline double Hep3Vector::getTolerance () {
222 inline Hep3Vector& Hep3Vector::operator += (const Hep3Vector & p) {
229 inline Hep3Vector& Hep3Vector::operator -= (const Hep3Vector & p) {
236 inline Hep3Vector Hep3Vector::operator - () const {
237 return Hep3Vector(-dx, -dy, -dz);
240 inline Hep3Vector& Hep3Vector::operator *= (double a) {
247 // -------------------
248 // Combine two Vectors
249 // -------------------
251 inline double Hep3Vector::diff2(const Hep3Vector & p) const {
252 return (*this-p).mag2();
255 inline double Hep3Vector::dot(const Hep3Vector & p) const {
256 return dx*p.x() + dy*p.y() + dz*p.z();
259 inline Hep3Vector Hep3Vector::cross(const Hep3Vector & p) const {
260 return Hep3Vector(dy*p.z()-p.y()*dz, dz*p.x()-p.z()*dx, dx*p.y()-p.x()*dy);
263 inline double Hep3Vector::perp2(const Hep3Vector & p) const {
264 double tot = p.mag2();
266 return tot > 0.0 ? mag2()-ss*ss/tot : mag2();
269 inline double Hep3Vector::perp(const Hep3Vector & p) const {
270 return std::sqrt(perp2(p));
273 inline Hep3Vector Hep3Vector::perpPart () const {
274 return Hep3Vector (dx, dy, 0);
276 inline Hep3Vector Hep3Vector::project () const {
277 return Hep3Vector (0, 0, dz);
280 inline Hep3Vector Hep3Vector::perpPart (const Hep3Vector & v2) const {
281 return ( *this - project(v2) );
284 inline double Hep3Vector::angle(const Hep3Vector & q) const {
285 return std::acos(cosTheta(q));
288 inline double Hep3Vector::theta(const Hep3Vector & q) const {
292 inline double Hep3Vector::azimAngle(const Hep3Vector & v2) const {
300 inline Hep3Vector Hep3Vector::unit() const {
302 Hep3Vector p(x(),y(),z());
303 return tot > 0.0 ? p *= (1.0/std::sqrt(tot)) : p;
306 inline Hep3Vector Hep3Vector::orthogonal() const {
307 double xx = dx < 0.0 ? -dx : dx;
308 double yy = dy < 0.0 ? -dy : dy;
309 double zz = dz < 0.0 ? -dz : dz;
311 return xx < zz ? Hep3Vector(0,dz,-dy) : Hep3Vector(dy,-dx,0);
313 return yy < zz ? Hep3Vector(-dz,0,dx) : Hep3Vector(dy,-dx,0);