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) {
46 inline Hep3Vector operator + (const Hep3Vector & a, const Hep3Vector & b) {
47 return Hep3Vector(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
50 inline Hep3Vector operator - (const Hep3Vector & a, const Hep3Vector & b) {
51 return Hep3Vector(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
54 inline Hep3Vector operator * (const Hep3Vector & p, double a) {
55 return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
58 inline Hep3Vector operator * (double a, const Hep3Vector & p) {
59 return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
62 inline double operator * (const Hep3Vector & a, const Hep3Vector & b) {
66 // --------------------------
67 // Set in various coordinates
68 // --------------------------
70 inline void Hep3Vector::setRThetaPhi
71 ( double r1, double theta1, double phi1 ) {
72 setSpherical (r1, theta1, phi1);
75 inline void Hep3Vector::setREtaPhi
76 ( double r1, double eta1, double phi1 ) {
77 setSpherical (r1, 2*std::atan(std::exp(-eta1)), phi1);
80 inline void Hep3Vector::setRhoPhiZ
81 ( double rho1, double phi1, double z1) {
82 setCylindrical (rho1, phi1, z1);
89 inline Hep3Vector::Hep3Vector()
90 : dx(0.), dy(0.), dz(0.) {}
91 inline Hep3Vector::Hep3Vector(double x1)
92 : dx(x1), dy(0.), dz(0.) {}
93 inline Hep3Vector::Hep3Vector(double x1, double y1)
94 : dx(x1), dy(y1), dz(0.) {}
95 inline Hep3Vector::Hep3Vector(double x1, double y1, double z1)
96 : dx(x1), dy(y1), dz(z1) {}
98 inline Hep3Vector::Hep3Vector(const Hep3Vector & p)
99 : dx(p.dx), dy(p.dy), dz(p.dz) {}
101 inline Hep3Vector::~Hep3Vector() {}
103 inline Hep3Vector & Hep3Vector::operator = (const Hep3Vector & p) {
110 // ------------------
111 // Access to elements
112 // ------------------
116 inline double Hep3Vector::mag2() const { return dx*dx + dy*dy + dz*dz; }
117 inline double Hep3Vector::mag() const { return std::sqrt(mag2()); }
118 inline double Hep3Vector::r() const { return mag(); }
120 inline double Hep3Vector::theta() const {
121 return dx == 0.0 && dy == 0.0 && dz == 0.0 ? 0.0 : std::atan2(perp(),dz);
123 inline double Hep3Vector::phi() const {
124 return dx == 0.0 && dy == 0.0 ? 0.0 : std::atan2(dy,dx);
127 inline double Hep3Vector::getR() const { return mag(); }
128 inline double Hep3Vector::getTheta() const { return theta(); }
129 inline double Hep3Vector::getPhi() const { return phi(); }
130 inline double Hep3Vector::angle() const { return theta(); }
132 inline double Hep3Vector::cosTheta() const {
134 return ptot == 0.0 ? 1.0 : dz/ptot;
137 inline double Hep3Vector::cos2Theta() const {
138 double ptot2 = mag2();
139 return ptot2 == 0.0 ? 1.0 : dz*dz/ptot2;
142 inline void Hep3Vector::setR(double r1) { setMag(r1); }
144 inline void Hep3Vector::setTheta(double th) {
147 setX(ma*std::sin(th)*std::cos(ph));
148 setY(ma*std::sin(th)*std::sin(ph));
149 setZ(ma*std::cos(th));
152 inline void Hep3Vector::setPhi(double ph) {
154 setX(xy*std::cos(ph));
155 setY(xy*std::sin(ph));
160 inline double Hep3Vector::perp2() const { return dx*dx + dy*dy; }
161 inline double Hep3Vector::perp() const { return std::sqrt(perp2()); }
162 inline double Hep3Vector::rho() const { return perp(); }
163 inline double Hep3Vector::eta() const { return pseudoRapidity();}
165 inline double Hep3Vector::getRho() const { return perp(); }
166 inline double Hep3Vector::getEta() const { return pseudoRapidity();}
168 inline void Hep3Vector::setPerp(double r1) {
175 inline void Hep3Vector::setRho(double rho1) { setPerp (rho1); }
181 inline bool Hep3Vector::operator == (const Hep3Vector& v) const {
182 return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
185 inline bool Hep3Vector::operator != (const Hep3Vector& v) const {
186 return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
189 inline double Hep3Vector::getTolerance () {
197 inline Hep3Vector& Hep3Vector::operator += (const Hep3Vector & p) {
204 inline Hep3Vector& Hep3Vector::operator -= (const Hep3Vector & p) {
211 inline Hep3Vector Hep3Vector::operator - () const {
212 return Hep3Vector(-dx, -dy, -dz);
215 inline Hep3Vector& Hep3Vector::operator *= (double a) {
222 // -------------------
223 // Combine two Vectors
224 // -------------------
226 inline double Hep3Vector::diff2(const Hep3Vector & p) const {
227 return (*this-p).mag2();
230 inline double Hep3Vector::dot(const Hep3Vector & p) const {
231 return dx*p.x() + dy*p.y() + dz*p.z();
234 inline Hep3Vector Hep3Vector::cross(const Hep3Vector & p) const {
235 return Hep3Vector(dy*p.z()-p.y()*dz, dz*p.x()-p.z()*dx, dx*p.y()-p.x()*dy);
238 inline double Hep3Vector::perp2(const Hep3Vector & p) const {
239 double tot = p.mag2();
241 return tot > 0.0 ? mag2()-ss*ss/tot : mag2();
244 inline double Hep3Vector::perp(const Hep3Vector & p) const {
245 return std::sqrt(perp2(p));
248 inline Hep3Vector Hep3Vector::perpPart () const {
249 return Hep3Vector (dx, dy, 0);
251 inline Hep3Vector Hep3Vector::project () const {
252 return Hep3Vector (0, 0, dz);
255 inline Hep3Vector Hep3Vector::perpPart (const Hep3Vector & v2) const {
256 return ( *this - project(v2) );
259 inline double Hep3Vector::angle(const Hep3Vector & q) const {
260 return std::acos(cosTheta(q));
263 inline double Hep3Vector::theta(const Hep3Vector & q) const {
267 inline double Hep3Vector::azimAngle(const Hep3Vector & v2) const {
275 inline Hep3Vector Hep3Vector::unit() const {
277 Hep3Vector p(x(),y(),z());
278 return tot > 0.0 ? p *= (1.0/std::sqrt(tot)) : p;
281 inline Hep3Vector Hep3Vector::orthogonal() const {
282 double xx = dx < 0.0 ? -dx : dx;
283 double yy = dy < 0.0 ? -dy : dy;
284 double zz = dz < 0.0 ? -dz : dz;
286 return xx < zz ? Hep3Vector(0,dz,-dy) : Hep3Vector(dy,-dx,0);
288 return yy < zz ? Hep3Vector(-dz,0,dx) : Hep3Vector(dy,-dx,0);