/* University College London Dept of Physics Course in C++ 3C59 | all rights reserved 2000 | | Utility: The Photomultiplier class | | This file contains the implementation of the methods of the class | | Author: P.Clarke */ #include #include #include "PhotoMultiplier.h" #define M_PI 3.14159 //........................................................... //Constructor PhotoMultiplier::PhotoMultiplier( float centre, float dist, float window, float res ) { //Set the central position of the PMT m_centralAngle = centre ; //Set the acceptance angles float halfAngle = ( atan( window/2.0/dist ) ) * 180.0 / M_PI ; m_lolim = m_centralAngle - halfAngle; m_hilim = m_centralAngle + halfAngle ; //Set the resolution m_resolution = res ; // statistic counters m_totalEnergy = 0.; m_numberDetectedParticles = 0; } //.............................................................. // Method to fire a Photn at the detector void PhotoMultiplier::tryit( Photon& p ) { //Does the supplied particle fall within this range if( (p.angle() > m_lolim) && (p.angle() < m_hilim) ) { //Great - it is accepted. To keep the code simple I delegate the operations //to do with adding this particle to the totals to a private method this->assimilate( p ) ; } } //.................................................................... // Private assimilate method void PhotoMultiplier::assimilate( Photon& p ) { //First increment the number of detected particles m_numberDetectedParticles++ ; //Now smear the energy using the Gaussian class float detectedEnergy ; detectedEnergy = p.energy() + ( m_generator.gauss() * m_resolution ); //Now add this smeared energy to the total m_totalEnergy += detectedEnergy ; } // .............................. // Method to return total number of particles detected int PhotoMultiplier::numberAccepted( ) { return m_numberDetectedParticles ; } // .............................. // Method to return central angle float PhotoMultiplier::angle( ) { return m_centralAngle ; } // .............................. // Method to return average energy float PhotoMultiplier::averageEnergy( ) { float average ; if( m_numberDetectedParticles > 0 ) { average = m_totalEnergy / float(m_numberDetectedParticles) ; } else { average = 0. ; } return average ; }