/** University College London Dept of Physics Course in OO 3C59 | all rights reserved 2000 | | Main class to run the Compton experiment Monte-Carlo program | | | Author: P.Clarke */ import java.io.* ; import java.util.*; public class ComptonMonteCarlo { // Main method where program starts public static void main( String[] args) { // ................................................. // Set some fixed numbers double distance = 50.0 ; // distance of pmts from rod double incidentEnergy = 662.0 ; // Energy of source photons on rod double resolution = 80.0 ; // Detector resolution in keV int numberOfEvents = 10000 ; // Number of photons to generate // Ask for some input double electronMass ; double windowWidth ; DataInputStream keyboard = new DataInputStream( System.in ); System.out.println( " Please input the electron mass in keV ") ; try{ electronMass = Double.valueOf( keyboard.readLine() ).doubleValue(); // inputVal = keyboard.readDouble() ; } catch( IOException e ) { System.out.println( " IOExeption caught for electron mass ") ; electronMass = 0.; } System.out.println( " Please input the width of the pmt window in cm "); try{ windowWidth = Double.valueOf( keyboard.readLine() ).doubleValue(); // windowWidth = keyboard.readDouble() ; } catch( IOException e ) { System.out.println( " IOExeption caught for window width ") ; windowWidth = 0.; } System.out.println( " You input "+electronMass+" and "+windowWidth ) ; //electronMass = 500. ; //windowWidth = 5. ; // Create a Rod Rod myRod = new Rod( incidentEnergy, electronMass ) ; // Create a vector of 18 photomultipliers at 10 degree difference from 0-180 Collection detectors = new Vector(); for( double ang=0.; ang < 190.; ang+=10. ) { detectors.add( new PhotoMultiplier( ang, distance, windowWidth, resolution ) ); } // ............................................. // Now run the experiment for many photons for( int ind=0; ind < numberOfEvents ; ++ind ) { // Create a new random photon Photon p = myRod.generatePhoton() ; // Offer it to each photomultiplier in turn Iterator pmt = detectors.iterator() ; while( pmt.hasNext() ) { ((PhotoMultiplier) pmt.next()).tryit( p ) ; } //System.out.print( " New Photon created with angle "+p.angle()+"\n" ) ; } // ........................................... // Finally output the results by asking each pmt in turn for its average energy //std::ofstream outfile( "mcCompton.dat" ) ; // Output Iterator pmt = detectors.iterator() ; while( pmt.hasNext() ) { PhotoMultiplier p = (PhotoMultiplier) pmt.next() ; System.out.println( p.angle()+" "+p.averageEnergy()+" "+resolution+" \n" ); } //outfile << detectors[pmt].angle() << " " // << detectors[pmt].averageEnergy() << " " // << resolution // << std::endl ; // Thats it } }