00001
00014 #include <math.h>
00015 #include <map>
00016 #include <vector>
00017
00018
00019 #include <CLHEP/Random/RandomEngine.h>
00020 #include <CLHEP/Random/RandGeneral.h>
00021
00022 #include "CrElectron.h"
00023 #include "CrElectronPrimary.h"
00024 #include "CrElectronSplash.h"
00025 #include "CrElectronReentrant.h"
00026
00027 #include "CrSpectrum.h"
00028
00029
00030 #include "SpectrumFactory.h"
00031
00032 static SpectrumFactory<CrElectron> factory;
00033 const ISpectrumFactory& CrElectronFactory = factory;
00034
00035
00036
00037
00038 CrElectron::CrElectron(const std::string& paramstring)
00039 : m_component(0)
00040 {
00041 std::vector<float> params;
00042
00043 parseParamList(paramstring,params);
00044
00045 int flag = params.empty() || params[0]==0 ? 7 : params[0];
00046
00047
00048 if(flag& 1) m_subComponents.push_back(new CrElectronPrimary);
00049 if(flag& 2) m_subComponents.push_back(new CrElectronReentrant);
00050 if(flag& 4) m_subComponents.push_back(new CrElectronSplash);
00051
00052 }
00053
00054
00055 CrElectron::~CrElectron()
00056 {
00057 std::vector<CrSpectrum*>::iterator i;
00058 for (i = m_subComponents.begin(); i != m_subComponents.end(); i++){
00059 delete *i;
00060 }
00061 }
00062
00063
00064 CrSpectrum* CrElectron::selectComponent(HepRandomEngine* engine)
00065 {
00066 std::map<CrSpectrum*,double> integ_flux;
00067 double total_flux = 0;
00068 std::vector<CrSpectrum*>::iterator i;
00069 for (i = m_subComponents.begin(); i != m_subComponents.end(); i++){
00070 total_flux += (*i)->flux();
00071 integ_flux[*i] = total_flux;
00072 }
00073
00074 double rnum = engine->flat() * total_flux;
00075 for (i = m_subComponents.begin(); i != m_subComponents.end(); i++){
00076 if (integ_flux[*i] >= rnum) { break; }
00077 }
00078
00079 m_component = *i;
00080
00081 return *i;
00082 }
00083
00084
00085 double CrElectron::energySrc(HepRandomEngine* engine)
00086 {
00087
00088 selectComponent(engine);
00089
00090 return m_component->energySrc(engine);
00091 }
00092
00093
00094 std::pair<double,double> CrElectron::dir(double energy, HepRandomEngine* engine)
00095
00096 {
00097 if (!m_component){ selectComponent(engine); }
00098
00099 return m_component->dir(energy, engine);
00100 }
00101
00102
00103 CrSpectrum* CrElectron::component() const
00104 {
00105 return m_component;
00106 }
00107
00108 double CrElectron::flux ( ) const
00109 {
00110 double total_flux = 0;
00111 std::vector<CrSpectrum*>::const_iterator i;
00112 for (i = m_subComponents.begin(); i != m_subComponents.end(); i++){
00113 total_flux += (*i)->flux();
00114 }
00115 return total_flux;
00116 }
00117
00118 double CrElectron::solidAngle( )const
00119 {
00120 return 4 *M_PI;
00121 }
00122