/* University College London Dept of Physics Course in C++ 3C59 | all rights reserved 2000 | | Utility: The Rod class implementation | | | Author: P.Clarke */ // Random angle generator class sold by Petes Enterprises inc. #include "Rod.h" #include "Photon.h" #define M_PI 3.14159 //--------------------- // Constructor. Note how we also construct the RanCom object. Rod::Rod( float sourceEnergy, float electronMass ) : angleGenerator( sourceEnergy, electronMass ) { m_sourceEnergy = sourceEnergy ; m_electronMass = electronMass ; } //--------------------- // Main method to return a new photon to the client with an angle and energy // corresponding to the true compton scattering distribution Photon Rod::generatePhoton() { // Generate a new random angle float angle = angleGenerator.scatter( ) ; // Calculate the corresponding energy float energy = this->calculateEnergy( angle ) ; // Create and return a photon Photon p( energy, angle ) ; return p ; } //-------------------- // This calculates the energy corresponding to the scattering angle float Rod::calculateEnergy( float angle ) { float angleInRadians = angle * M_PI / 180.0 ; float invE = (1.0/m_sourceEnergy) + (1.0/m_electronMass) - ( cos( angleInRadians ) / m_electronMass ) ; return 1.0/invE ; }