Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CrProton.cxx

Go to the documentation of this file.
00001 //
00002 // CrProton.cc
00003 //
00004 //   The entry-point class for primary particle generators of primary and
00005 //   secondary (i.e. albedo) cosmic-ray protons.
00006 //
00007 
00008 #include <math.h>
00009 #include <map>
00010 #include <vector>
00011 
00012 // CLHEP
00013 #include <CLHEP/Random/RandomEngine.h>
00014 #include <CLHEP/Random/RandGeneral.h>
00015 
00016 #include "CrProton.h"
00017 #include "CrProtonPrimary.h"
00018 #include "CrProtonSplash.h"
00019 #include "CrProtonReentrant.h"
00020 
00021 // derived from CrSpectrum that is derived from Spectrum
00022 #include "CrSpectrum.h"
00023 
00024 // define a factory for anonomous instantiation
00025 #include "SpectrumFactory.h"
00026 
00027 static SpectrumFactory<CrProton> factory;
00028 const ISpectrumFactory& CrProtonFactory = factory;
00029 
00030 
00031 
00032 CrProton::CrProton(const std::string& paramstring)
00033 : m_component(0)
00034 {
00035    std::vector<float> params;
00036 
00037    parseParamList(paramstring,params);
00038 
00039     int flag = params.empty() || params[0]==0 ? 7 : params[0];
00040 
00041     // including each component (primary/re-entrant/splash protons)...
00042    if(flag& 1) m_subComponents.push_back(new CrProtonPrimary);
00043    if(flag& 2) m_subComponents.push_back(new CrProtonReentrant);
00044    if(flag& 4) m_subComponents.push_back(new CrProtonSplash);
00045 }
00046 
00047 
00048 CrProton::~CrProton()
00049 {
00050   std::vector<CrSpectrum*>::iterator  i;
00051   for (i = m_subComponents.begin(); i != m_subComponents.end(); i++){
00052     delete *i;
00053   }
00054 }
00055 
00056 
00057 CrSpectrum* CrProton::selectComponent(HepRandomEngine* engine)
00058 {
00059   std::map<CrSpectrum*,double>       integ_flux;
00060   double                             total_flux = 0;
00061   std::vector<CrSpectrum*>::iterator i;
00062   for (i = m_subComponents.begin(); i != m_subComponents.end(); i++){
00063     total_flux += (*i)->flux();
00064     integ_flux[*i] = total_flux;
00065   }
00066 
00067   double  rnum = engine->flat() * total_flux;
00068   for (i = m_subComponents.begin(); i != m_subComponents.end(); i++){
00069     if (integ_flux[*i] >= rnum) { break; }
00070   }
00071 
00072   m_component = *i;
00073 
00074   return *i;
00075 }
00076 
00077 
00078 double CrProton::energySrc(HepRandomEngine* engine)
00079 {
00080 //THB  if (!m_component){ selectComponent(engine); }
00081  selectComponent(engine);
00082   return m_component->energySrc(engine);
00083 }
00084 
00085 
00086 std::pair<double,double> CrProton::dir(double energy, HepRandomEngine* engine)
00087 // return: cos(zenith_angle) and azimuth [rad]
00088 {
00089   if (!m_component){ selectComponent(engine); }
00090 
00091   return m_component->dir(energy, engine);
00092 }
00093 
00094 
00095 CrSpectrum* CrProton::component() const
00096 {
00097   return m_component;
00098 }
00099 
00100 double CrProton::flux ( ) const
00101 {
00102   double          total_flux = 0;
00103   std::vector<CrSpectrum*>::const_iterator i;
00104   for (i = m_subComponents.begin(); i != m_subComponents.end(); i++){
00105     total_flux += (*i)->flux();
00106   }
00107   return total_flux;
00108 }
00109 
00110 double CrProton::solidAngle( )const
00111 {
00112     return 4*M_PI;
00113 }
00114 

Generated at Wed Nov 21 12:20:33 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000