00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <cmath>
00012
00013 namespace CLHEP {
00014
00015
00016
00017
00018
00019
00020
00021 inline double & Hep3Vector::operator[] (int i) { return operator()(i); }
00022 inline double Hep3Vector::operator[] (int i) const { return operator()(i); }
00023
00024 inline double Hep3Vector::x() const { return dx; }
00025 inline double Hep3Vector::y() const { return dy; }
00026 inline double Hep3Vector::z() const { return dz; }
00027
00028 inline double Hep3Vector::getX() const { return dx; }
00029 inline double Hep3Vector::getY() const { return dy; }
00030 inline double Hep3Vector::getZ() const { return dz; }
00031
00032 inline void Hep3Vector::setX(double x1) { dx = x1; }
00033 inline void Hep3Vector::setY(double y1) { dy = y1; }
00034 inline void Hep3Vector::setZ(double z1) { dz = z1; }
00035
00036 inline void Hep3Vector::set(double x1, double y1, double z1) {
00037 dx = x1;
00038 dy = y1;
00039 dz = z1;
00040 }
00041
00042
00043
00044
00045
00046 inline Hep3Vector operator + (const Hep3Vector & a, const Hep3Vector & b) {
00047 return Hep3Vector(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
00048 }
00049
00050 inline Hep3Vector operator - (const Hep3Vector & a, const Hep3Vector & b) {
00051 return Hep3Vector(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
00052 }
00053
00054 inline Hep3Vector operator * (const Hep3Vector & p, double a) {
00055 return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
00056 }
00057
00058 inline Hep3Vector operator * (double a, const Hep3Vector & p) {
00059 return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
00060 }
00061
00062 inline double operator * (const Hep3Vector & a, const Hep3Vector & b) {
00063 return a.dot(b);
00064 }
00065
00066
00067
00068
00069
00070 inline void Hep3Vector::setRThetaPhi
00071 ( double r1, double theta1, double phi1 ) {
00072 setSpherical (r1, theta1, phi1);
00073 }
00074
00075 inline void Hep3Vector::setREtaPhi
00076 ( double r1, double eta1, double phi1 ) {
00077 setSpherical (r1, 2*std::atan(std::exp(-eta1)), phi1);
00078 }
00079
00080 inline void Hep3Vector::setRhoPhiZ
00081 ( double rho1, double phi1, double z1) {
00082 setCylindrical (rho1, phi1, z1);
00083 }
00084
00085
00086
00087
00088
00089 inline Hep3Vector::Hep3Vector()
00090 : dx(0.), dy(0.), dz(0.) {}
00091 inline Hep3Vector::Hep3Vector(double x1)
00092 : dx(x1), dy(0.), dz(0.) {}
00093 inline Hep3Vector::Hep3Vector(double x1, double y1)
00094 : dx(x1), dy(y1), dz(0.) {}
00095 inline Hep3Vector::Hep3Vector(double x1, double y1, double z1)
00096 : dx(x1), dy(y1), dz(z1) {}
00097
00098 inline Hep3Vector::Hep3Vector(const Hep3Vector & p)
00099 : dx(p.dx), dy(p.dy), dz(p.dz) {}
00100
00101 inline Hep3Vector::~Hep3Vector() {}
00102
00103 inline Hep3Vector & Hep3Vector::operator = (const Hep3Vector & p) {
00104 dx = p.dx;
00105 dy = p.dy;
00106 dz = p.dz;
00107 return *this;
00108 }
00109
00110
00111
00112
00113
00114
00115
00116 inline double Hep3Vector::mag2() const { return dx*dx + dy*dy + dz*dz; }
00117 inline double Hep3Vector::mag() const { return std::sqrt(mag2()); }
00118 inline double Hep3Vector::r() const { return mag(); }
00119
00120 inline double Hep3Vector::theta() const {
00121 return dx == 0.0 && dy == 0.0 && dz == 0.0 ? 0.0 : std::atan2(perp(),dz);
00122 }
00123 inline double Hep3Vector::phi() const {
00124 return dx == 0.0 && dy == 0.0 ? 0.0 : std::atan2(dy,dx);
00125 }
00126
00127 inline double Hep3Vector::getR() const { return mag(); }
00128 inline double Hep3Vector::getTheta() const { return theta(); }
00129 inline double Hep3Vector::getPhi() const { return phi(); }
00130 inline double Hep3Vector::angle() const { return theta(); }
00131
00132 inline double Hep3Vector::cosTheta() const {
00133 double ptot = mag();
00134 return ptot == 0.0 ? 1.0 : dz/ptot;
00135 }
00136
00137 inline double Hep3Vector::cos2Theta() const {
00138 double ptot2 = mag2();
00139 return ptot2 == 0.0 ? 1.0 : dz*dz/ptot2;
00140 }
00141
00142 inline void Hep3Vector::setR(double r1) { setMag(r1); }
00143
00144 inline void Hep3Vector::setTheta(double th) {
00145 double ma = mag();
00146 double ph = phi();
00147 setX(ma*std::sin(th)*std::cos(ph));
00148 setY(ma*std::sin(th)*std::sin(ph));
00149 setZ(ma*std::cos(th));
00150 }
00151
00152 inline void Hep3Vector::setPhi(double ph) {
00153 double xy = perp();
00154 setX(xy*std::cos(ph));
00155 setY(xy*std::sin(ph));
00156 }
00157
00158
00159
00160 inline double Hep3Vector::perp2() const { return dx*dx + dy*dy; }
00161 inline double Hep3Vector::perp() const { return std::sqrt(perp2()); }
00162 inline double Hep3Vector::rho() const { return perp(); }
00163 inline double Hep3Vector::eta() const { return pseudoRapidity();}
00164
00165 inline double Hep3Vector::getRho() const { return perp(); }
00166 inline double Hep3Vector::getEta() const { return pseudoRapidity();}
00167
00168 inline void Hep3Vector::setPerp(double r1) {
00169 double p = perp();
00170 if (p != 0.0) {
00171 dx *= r1/p;
00172 dy *= r1/p;
00173 }
00174 }
00175 inline void Hep3Vector::setRho(double rho1) { setPerp (rho1); }
00176
00177
00178
00179
00180
00181 inline bool Hep3Vector::operator == (const Hep3Vector& v) const {
00182 return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
00183 }
00184
00185 inline bool Hep3Vector::operator != (const Hep3Vector& v) const {
00186 return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
00187 }
00188
00189 inline double Hep3Vector::getTolerance () {
00190 return tolerance;
00191 }
00192
00193
00194
00195
00196
00197 inline Hep3Vector& Hep3Vector::operator += (const Hep3Vector & p) {
00198 dx += p.x();
00199 dy += p.y();
00200 dz += p.z();
00201 return *this;
00202 }
00203
00204 inline Hep3Vector& Hep3Vector::operator -= (const Hep3Vector & p) {
00205 dx -= p.x();
00206 dy -= p.y();
00207 dz -= p.z();
00208 return *this;
00209 }
00210
00211 inline Hep3Vector Hep3Vector::operator - () const {
00212 return Hep3Vector(-dx, -dy, -dz);
00213 }
00214
00215 inline Hep3Vector& Hep3Vector::operator *= (double a) {
00216 dx *= a;
00217 dy *= a;
00218 dz *= a;
00219 return *this;
00220 }
00221
00222
00223
00224
00225
00226 inline double Hep3Vector::diff2(const Hep3Vector & p) const {
00227 return (*this-p).mag2();
00228 }
00229
00230 inline double Hep3Vector::dot(const Hep3Vector & p) const {
00231 return dx*p.x() + dy*p.y() + dz*p.z();
00232 }
00233
00234 inline Hep3Vector Hep3Vector::cross(const Hep3Vector & p) const {
00235 return Hep3Vector(dy*p.z()-p.y()*dz, dz*p.x()-p.z()*dx, dx*p.y()-p.x()*dy);
00236 }
00237
00238 inline double Hep3Vector::perp2(const Hep3Vector & p) const {
00239 double tot = p.mag2();
00240 double ss = dot(p);
00241 return tot > 0.0 ? mag2()-ss*ss/tot : mag2();
00242 }
00243
00244 inline double Hep3Vector::perp(const Hep3Vector & p) const {
00245 return std::sqrt(perp2(p));
00246 }
00247
00248 inline Hep3Vector Hep3Vector::perpPart () const {
00249 return Hep3Vector (dx, dy, 0);
00250 }
00251 inline Hep3Vector Hep3Vector::project () const {
00252 return Hep3Vector (0, 0, dz);
00253 }
00254
00255 inline Hep3Vector Hep3Vector::perpPart (const Hep3Vector & v2) const {
00256 return ( *this - project(v2) );
00257 }
00258
00259 inline double Hep3Vector::angle(const Hep3Vector & q) const {
00260 return std::acos(cosTheta(q));
00261 }
00262
00263 inline double Hep3Vector::theta(const Hep3Vector & q) const {
00264 return angle(q);
00265 }
00266
00267 inline double Hep3Vector::azimAngle(const Hep3Vector & v2) const {
00268 return deltaPhi(v2);
00269 }
00270
00271
00272
00273
00274
00275 inline Hep3Vector Hep3Vector::unit() const {
00276 double tot = mag2();
00277 Hep3Vector p(x(),y(),z());
00278 return tot > 0.0 ? p *= (1.0/std::sqrt(tot)) : p;
00279 }
00280
00281 inline Hep3Vector Hep3Vector::orthogonal() const {
00282 double xx = dx < 0.0 ? -dx : dx;
00283 double yy = dy < 0.0 ? -dy : dy;
00284 double zz = dz < 0.0 ? -dz : dz;
00285 if (xx < yy) {
00286 return xx < zz ? Hep3Vector(0,dz,-dy) : Hep3Vector(dy,-dx,0);
00287 }else{
00288 return yy < zz ? Hep3Vector(-dz,0,dx) : Hep3Vector(dy,-dx,0);
00289 }
00290 }
00291
00292 }