/* University College London Dept of Physics Course in C++ 3C59 | all rights reserved 1999 | | Utility: DECLARATION of the ThreeVector class | | This is the second attempt which now includes some methods, | (but is still incomplete as there are no constructors) | | Author: P.Clarke */ #ifndef _threevec_secondgo_h #define _threevec_secondgo_h 1 #include #include class ThreeVector { private: float px ; float py ; float pz ; public: // To initialise the vector with 3 cartesian momentum components // Note: this method should NOT be used after we have covered constructors void initialise( float qx, float qy, float qz ) { px = qx ; py = qy ; pz = qz ; } // To return the square of the magnitude float magnitudesq( ) { return ( px*px + py*py + pz*pz ) ; } // To return the magnitude float magnitude( ) { return sqrt( magnitudesq( ) ); } // To return the phi angle in the x-y plane float phi( ) { return acos( px / sqrt(px*px + py*py) ) ; } // To perform the dot product of two vectors float dotProduct( ThreeVector t2 ) { return ( px*t2.px + py*t2.py + pz*t2.pz ) ; } // To calculate the angle between two vectors in radians float angle( ThreeVector t2 ) { float angle ; angle = dotProduct( t2 ) / magnitude( ) / t2.magnitude( ) ; angle = acos(angle) ; return angle ; } // To dump out the contents to cout void dump( ) { std::cout << " The vector contents are " << " px= " << px << " py= " << py << " pz= " << pz << std::endl ; } }; #endif