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

EventSource.cxx

Go to the documentation of this file.
00001 //  $Header: /nfs/slac/g/glast/ground/cvs/flux/src/EventSource.cxx,v 1.4 2001/06/16 13:26:00 burnett Exp $
00002 
00003 #include "../flux/EventSource.h"
00004 
00005 #include "dom/DOM_Element.hpp"
00006 #include "xml/Dom.h"
00007 #include "flux/GPS.h"
00008 #include "flux/Orbit.h"
00009 #include "CLHEP/Random/RandExponential.h"
00010 
00011 #include <strstream>
00012 
00013 unsigned int  EventSource::s_id = 0;
00014 double  EventSource::s_total_area = 6.; // area in m^2
00015 
00016 EventSource::EventSource (double aFlux, unsigned acode)
00017   :  m_enabled(true), m_flux(aFlux), m_solid_angle(1.), m_code(acode)
00018 {
00019   std::strstream  s;
00020 
00021   s << "Source_" << (++s_id) << '\0';
00022   if (acode == 0) code(s_id); // automatically assign event codes...
00023 
00024   m_name = s.str();
00025   s.freeze(false);
00026 }
00027 
00028 EventSource::EventSource (const DOM_Element& xelem)
00029   :  m_enabled(true), m_flux(1.), m_solid_angle(1.), m_code(0)
00030 {
00031   m_name = xml::Dom::getAttribute(xelem, "name");
00032   m_flux = atof (xml::Dom::getAttribute(xelem, "flux").c_str());
00033 
00034   std::string code_str = xml::Dom::getAttribute(xelem, "code");
00035   if (code_str != std::string("")) {
00036     m_code = atoi(code_str.c_str());
00037   }
00038   else  {
00039     m_code = ++s_id;
00040   }
00041 
00042   // this is set by default to be overriden when the solid_angle 
00043   // element is present...
00044   DOM_Element   angles = 
00045     xml::Dom::findFirstChildByName(xelem, "solid_angle");
00046 
00047   if (angles != DOM_Element()) {
00048     double  mincos = atof(xml::Dom::getAttribute(angles, "mincos").c_str());
00049     double  maxcos = atof(xml::Dom::getAttribute(angles, "maxcos").c_str());
00050 
00051     m_solid_angle = (maxcos - mincos)*2*M_PI;
00052   }
00053   else if (xml::Dom::findFirstChildByName(xelem, "direction") != DOM_Element())
00054     m_solid_angle = 1.;
00055 }
00056 
00057 
00058 EventSource::~EventSource()
00059 {}
00060 
00061 double EventSource::flux () const
00062 {
00063   return m_flux;  // default if not overridden
00064 }
00065 
00066 void   EventSource::flux (double value) {
00067   m_flux = value;
00068 }
00069 
00070 GPStime EventSource::interval ()
00071 {
00072   double  r = rate();
00073 
00074   if (r > 0) {
00075     return  RandExponential::shoot(1./r);
00076   } else if (r < 0) {
00077     return 1./r;
00078   } else return -1.;
00079 }
00080 
00081 double  EventSource::rate ( double solid_angle, double fluxval )
00082 {
00083   double  r = solid_angle*fluxval*s_total_area;   
00084   // integral of the flux*cross-sectional-area over
00085   // the solid angle (which is passed in as an integral)
00086   m_solid_angle = solid_angle;
00087   flux( fluxval );
00088   return  r;
00089 }
00090 
00091 double  EventSource::rate ( )const
00092 {
00093   return enabled()? (solidAngle()*flux()*s_total_area) :0;
00094 }
00095 
00096 void    EventSource::rate ( double rate )
00097 {
00098   flux(  rate/(m_solid_angle*s_total_area) );
00099 }
00100 
00101 Orbit*  EventSource::makeOrbit () const
00102 {
00103   return new Orbit;
00104 }
00105 
00106 
00107 
00108 // UI titles
00109 std::string EventSource::fullTitle () const 
00110 { return std::string("EventSource");   }
00111 std::string EventSource::displayTitle () const  {  return m_name; }

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