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

FluxTestAlg.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/FluxSvc/src/test/FluxTestAlg.cxx,v 1.49 2002/10/13 19:13:47 srobinsn Exp $
00002 
00003 // Include files
00004 #include "FluxSvc/IFluxSvc.h"
00005 #include "FluxSvc/IFlux.h"
00006 
00007 
00008 // Event for creating the McEvent stuff
00009 //#include "Event/TopLevel/Event.h"
00010 #include "Event/TopLevel/MCEvent.h"
00011 #include "Event/MonteCarlo/McParticle.h"
00012 #include "Event/TopLevel/EventModel.h"
00013 #include "Event/TopLevel/Event.h"
00014 
00015 
00016 // Gaudi system includes
00017 #include "GaudiKernel/IDataProviderSvc.h"
00018 #include "GaudiKernel/SmartDataPtr.h"
00019 #include "GaudiKernel/IParticlePropertySvc.h"
00020 #include "GaudiKernel/SmartRefVector.h"
00021 #include "GaudiKernel/MsgStream.h"
00022 #include "GaudiKernel/AlgFactory.h"
00023 #include "GaudiKernel/Algorithm.h"
00024 #include <list>
00025 #include <string>
00026 #include <vector>
00027 #include "GaudiKernel/ParticleProperty.h"
00028 
00029 //#include "FluxAlg.h"
00036 //class ParticleProperty;
00037 
00038 class FluxTestAlg : public Algorithm {
00039     
00040 public:
00042     FluxTestAlg(const std::string& name, ISvcLocator* pSvcLocator); 
00043     
00044     StatusCode initialize();
00045     StatusCode execute();
00046     StatusCode finalize();
00047     
00048     
00049 private:
00050     IFlux* m_flux;
00051     std::string m_source_name;
00052     IParticlePropertySvc * m_partSvc;
00053     std::ostream* m_out;  //for output that looks like the stuff from the astro orbit model test.
00054     std::ostream* m_diffsources; //for output concerning the source used (extra output for diffuse model)
00055 
00056 };
00057 
00058 
00059 static const AlgFactory<FluxTestAlg>  Factory;
00060 const IAlgFactory& FluxTestAlgFactory = Factory;
00061 /*
00062 void WARNING (const char * text ){  std::cerr << "WARNING: " << text << '\n';}
00063 void FATAL(const char* s){std::cerr << "\nERROR: "<< s;}
00064 */
00065 
00066 //------------------------------------------------------------------------------
00067 //
00068 FluxTestAlg::FluxTestAlg(const std::string& name, ISvcLocator* pSvcLocator) :
00069 Algorithm(name, pSvcLocator){
00070     
00071     declareProperty("source_name", m_source_name="default");
00072 }
00073 
00074 
00075 //------------------------------------------------------------------------------
00077 StatusCode FluxTestAlg::initialize() {
00078     
00079     
00080     MsgStream log(msgSvc(), name());
00081     log << MSG::INFO << "initializing..." << endreq;
00082     
00083     // Use the Job options service to set the Algorithm's parameters
00084     setProperties();
00085 
00086     if ( service("ParticlePropertySvc", m_partSvc).isFailure() ){
00087             log << MSG::ERROR << "Couldn't find the ParticlePropertySvc!" << endreq;
00088             return StatusCode::FAILURE;
00089     }
00090 
00091 #if 0 // this does not make sense for testing FluxAlg
00092     //set the output file.
00093     m_out = new std::ofstream("TestOutputData.out");
00094     m_diffsources = new std::ofstream("SourceCharacteristics.out");
00095 
00096     // get the pointer to the flux Service 
00097     IFluxSvc* fsvc;
00098     
00099     // get the service
00100     StatusCode sc = service("FluxSvc", fsvc);
00101     
00102     if( sc.isFailure()) {
00103         log << MSG::ERROR << "Could not find FluxSvc" << endreq;
00104         return sc;
00105     }
00106     
00107     //uncomment this to set the rocking method.
00108     //fsvc->setRockType(GPS::UPDOWN);
00109     
00110     log << MSG::INFO << "loading source..." << endreq;
00111     
00112     
00113     sc =  fsvc->source(m_source_name, m_flux);
00114     if( sc.isFailure()) {
00115         log << MSG::ERROR << "Could not find flux " << m_source_name << endreq;
00116         return sc;
00117     }
00118     
00119     // then do the output here.
00120     log << MSG::INFO << "start of other loops" << endreq;
00121     log << MSG::INFO << "Source title: " << m_flux->title() << endreq;
00122     log << MSG::INFO << "       area: " << m_flux->targetArea() << endreq;
00123     log << MSG::INFO << "       rate: " << m_flux->rate() << endreq;
00124     
00125 #endif   
00126     
00127     return StatusCode::SUCCESS;
00128 }
00129 
00130 
00131 //------------------------------------------------------------------------------
00132 StatusCode FluxTestAlg::execute() {
00133     
00134     StatusCode  sc = StatusCode::SUCCESS;
00135     MsgStream   log( msgSvc(), name() );    
00136     
00137     
00138     Event::McParticleCol* pcol = 0;
00139     eventSvc()->retrieveObject(EventModel::MC::McParticleCol, (DataObject *&)pcol);
00140     
00141     if(pcol==0){ 
00142         log << MSG::ERROR << " Could not find "<< EventModel::MC::McParticleCol << endreq;
00143             return StatusCode::FAILURE;
00144     }
00145 
00146     SmartDataPtr<Event::EventHeader> header(eventSvc(), EventModel::EventHeader);
00147     if( 0==header) {  
00148         log << MSG::ERROR << " Could not find "<< EventModel::EventHeader << endreq;
00149             return StatusCode::FAILURE;
00150     }
00151 
00152 
00153 
00154     Event::McParticleCol::iterator elem = (*pcol).begin();
00155     HepVector3D d = (*elem)->initialFourMomentum().v().unit();
00156     HepVector3D p = (*elem)->finalPosition();
00157     
00158     double energy = (*elem)->initialFourMomentum().e();
00159     /*StdHepId*/int pID = (*elem)->particleProperty();
00160     std::string partName = m_partSvc->findByStdHepID(pID)->particle();
00161     
00162     log << MSG::INFO << partName
00163         << "(" << energy
00164         << " MeV), Launch: " 
00165         << "(" << p.x() <<", "<< p.y() <<", "<<p.z()<<")" 
00166         << " Dir " 
00167         << "(" << d.x() <<", "<< d.y() <<", "<<d.z()<<")"
00168          << ",  Elapsed Time = " << header->time()
00169         << endreq;
00170 
00171 #if 0 // enable for tests: see above
00172     double theta = acos(d.z()/(d.mag()));
00173 
00174     double phi = atan2(d.y(),d.x());
00175 
00176     //and here's the file output.
00177     std::ostream& out = *m_out;
00178         out<<m_flux->time() <<'\t';
00179         out<<d.x() <<'\t';
00180         out<< d.y()<<'\t';
00181         out<< d.z()<<'\t';
00182         out<< theta<<'\t';
00183         out<< phi<<'\t' << std::endl;
00184 #endif
00185     return sc;
00186 }
00187 
00188 
00189 //------------------------------------------------------------------------------
00190 StatusCode FluxTestAlg::finalize() {
00191 #if 0 //enable for tests
00192     std::ostream& diffsources = *m_diffsources;
00193     m_flux->writeSourceCharacteristic(diffsources);
00194     delete m_diffsources;
00195     delete m_out;
00196 #endif
00197     return StatusCode::SUCCESS;
00198 }
00199 
00200 
00201 
00202 
00203 
00204 
00205 

Generated on Wed Oct 16 14:01:29 2002 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001