/** University College London Dept of Physics Course in OO 3C59 | all rights reserved 2000 | | Utility: The Rod class | | This class simulates the combination of the radioactive sourse and the | scattering rod. | | Its main function is to provide Photons on demand with an angular | distribution corresponding to that of the real scattered photons | in the experiment | | Author: P.Clarke */ //package uk.ac.ucl.hep.ComptonMC ; import java.lang.Math ; public class Rod { private double m_sourceEnergy ; // energy of photons from the radioactive source private double m_electronMass ; // Electron mass in kev private RanCom m_angleGenerator; // Helper to generate random angle //------------- // Constructor. public Rod( double sourceEnergy, double electronMass ) { m_sourceEnergy = sourceEnergy ; m_electronMass = electronMass ; m_angleGenerator = new RanCom( m_sourceEnergy, m_electronMass ) ; } //------------- // Private methods to help out // This one calculates the energy corresponding to the scattering angle private double calculateEnergy( double angle ) { double angleInRadians = angle * Math.PI / 180.0 ; double invE = (1.0/m_sourceEnergy) + (1.0/m_electronMass) - ( Math.cos( angleInRadians ) / m_electronMass ) ; return 1.0/invE ; } // ------------------------- // Main method to return a new photon to the client with an angle and energy // corresponding to the true compton scattering distribution public Photon generatePhoton() { // Generate a new random angle double angle = m_angleGenerator.scatter( ) ; // Calculate the corresponding energy double energy = this.calculateEnergy( angle ) ; // Create and return a photon Photon p = new Photon( energy, angle ) ; return p ; } }