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.

More ImplementationDesign decisionsRecallImplementationclass Hep3VectorF {public:float mag();float phi();float cosTheta();// much more not shownprivate:float fx, fy, fz;};inline float Hep3VectorF::mag() {return sqrt(fx*fx + fy*fy + fz*fz);}inline float Hep3VectorF::phi() {return fx == 0.0 && fy == 0.0 ? 0.0 : atan2(fy,fx)}inline float Hep3VectorF::cosTheta() {float ptot = mag();return ptot == 0.0 ? 1.0 : fz/ptot;}• note how object calls its own member function• examples of letting object do <strong>the</strong> workFortran stylecommon/points/hits(3,100)real*4 hitsreal*4 x, y, z, r! do some workx = hits(1,i) ! or from ZEBRA banky = hits(2,i)z = hits(3,i)r = sqrt(x*x + y*y + z*z);Ano<strong>the</strong>r Fortran stylecommon/points/hits(3,100)real*4 hitsreal*4 x, y, z, r! do some workx = hits(1,i)y = hits(2,i)z = hits(3,i)r = mag(x, y, z) ! or mag(hits(1,i))Mark II VECSUB stylecommon/points/hits(3,100)real*4 r! do some workr = hitsmag(i)<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 78 Paul F. Kunz<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 79 Paul F. Kunz

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

Saved successfully!

Ooh no, something went wrong!