13.07.2015 Views

BABAR C++ Course Running the Examples - HEPHY

BABAR C++ Course Running the Examples - HEPHY

BABAR C++ Course Running the Examples - HEPHY

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Even more of ImplementationWhat’s new?The dot productinline floatHepLorentzVectorF::dot(const HepLorentzVectorF & p) const {return ft*p.t() - z()*p.z() - y()*p.y() - x()*p.x();}• use of accessor functions x(), y(), and z()because data members are private in <strong>the</strong> super class• scope operator :: not needed because <strong>the</strong>sefunctions are unique to <strong>the</strong> base classThe += operatorinline HepLorentzVectorF &HepLorentzVectorF::operator += (const HepLorentzVectorF& p) {Hep3VectorF::operator += (p);ft += p.t();return *this;}• example of directly calling operator functionMany o<strong>the</strong>r functions will not be shownThey implement <strong>the</strong> vector algebra for LorentzvectorsA Lorentz boost functionvoid HepLorentzVectorF::boost(double bx, double by, double bz){double b2 = bx*bx + by*by + bz*bz;register double gamma = 1.0 / sqrt(1.0 - b2);register double bp = bx*x() + by*y() + bz*z();register double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0;}setX(x() + gamma2*bp*bx + gamma*bx*ft);setY(y() + gamma2*bp*by + gamma*by*ft);setZ(z() + gamma2*bp*bz + gamma*bz*ft);ft = gamma*(ft + bp);• register keyword advises compiler that variableshould be optimized in machine registersAlso haveinline Hep3VectorD HepLorentzVectorD::boostVector() const {Hep3VectorD p(x()/dt, y()/dt, z()/dt);return p;}inline void HepLorentzVectorF::boost(const Hep3VectorD & p){boost(p.x(), p.y(), p.z());}• double precision version only<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 138 Paul F. Kunz<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 139 Paul F. Kunz

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!