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

ExposureAlg.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/FluxSvc/src/ExposureAlg.cxx,v 1.9 2002/10/07 23:42:20 srobinsn Exp $
00002 
00003 // Include files
00004 // Gaudi system includes
00005 #include "GaudiKernel/MsgStream.h"
00006 #include "GaudiKernel/AlgFactory.h"
00007 #include "GaudiKernel/IDataProviderSvc.h"
00008 #include "GaudiKernel/SmartDataPtr.h"
00009 #include "GaudiKernel/IParticlePropertySvc.h"
00010 #include "GaudiKernel/ParticleProperty.h"
00011 #include "GaudiKernel/SmartRefVector.h"
00012 
00013 #include "astro/SkyDir.h"
00014 #include "astro/EarthCoordinate.h"
00015 #include "astro/SolarSystem.h"
00016 #include "astro/EarthOrbit.h"
00017 // Event for creating the McEvent stuff
00018 #include "Event/TopLevel/MCEvent.h"
00019 #include "Event/MonteCarlo/McParticle.h"
00020 #include "Event/TopLevel/EventModel.h"
00021 #include "Event/MonteCarlo/D2Entry.h"
00022 
00023 //flux
00024 #include "FluxSvc.h"
00025 #include "FluxSvc/IFlux.h"
00026 #include "Spectrum.h"
00027 #include "SpectrumFactory.h"
00028 #include "GPS.h"
00029 
00030 //for instantiation of the new spectrum.
00031 #include "FluxSvc/ISpectrum.h"
00032 #include "FluxSvc/ISpectrumFactory.h" 
00033 
00034 #include "astro/EarthOrbit.h"
00035 
00036 #include "CLHEP/Vector/LorentzVector.h"
00037 
00038 #include <cassert>
00039 #include <vector>
00040 
00041 #include "ExposureAlg.h"
00042 //------------------------------------------------------------------------
00043 
00044 static const AlgFactory<ExposureAlg>  Factory;
00045 const IAlgFactory& ExposureAlgFactory = Factory;
00046 
00047 //------------------------------------------------------------------------
00049 ExposureAlg::ExposureAlg(const std::string& name, ISvcLocator* pSvcLocator)
00050 :Algorithm(name, pSvcLocator), m_out(0)
00051 {
00052     // declare properties with setProperties calls
00053     declareProperty("source_name",  m_source_name="default");
00054     
00055 }
00056 
00057 //------------------------------------------------------------------------
00059 StatusCode ExposureAlg::initialize(){
00060     StatusCode  sc = StatusCode::SUCCESS;
00061     MsgStream log(msgSvc(), name());
00062     log << MSG::INFO << "initialize" << endreq;
00063 
00064     // Use the Job options service to set the Algorithm's parameters
00065     setProperties();
00066     
00067     if ( service("FluxSvc", m_fluxSvc).isFailure() ){
00068         log << MSG::ERROR << "Couldn't find the FluxSvc!" << endreq;
00069         return StatusCode::FAILURE;
00070     }
00071 
00072     //TODO: set the file name from a property
00073     m_out = new std::ofstream("orbitFromAlg.out");
00074     m_fluxSvc->setRockType(GPS::SLEWING);
00075 
00076     return sc;
00077 }
00078 
00079 
00080 //------------------------------------------------------------------------
00082 StatusCode ExposureAlg::execute()
00083 {
00084     using namespace astro;
00085     StatusCode  sc = StatusCode::SUCCESS;
00086     MsgStream   log( msgSvc(), name() );
00087     double currentTime;
00088     //-----------------------------------------------------------------------
00089     
00090     Event::McParticleCol* pcol = new Event::McParticleCol;
00091     eventSvc()->retrieveObject("/Event/MC/McParticleCol",(DataObject *&)pcol);
00092     //only make a new source if one does not already exist.
00093     if(pcol==0){
00094         //FluxAlg didn't do anything.  proceed.
00095         
00096         //if the flux had changed, something changed the source type.
00097         if(m_fluxSvc->currentFlux() == m_flux){
00098             m_flux->generate();
00099             currentTime = m_flux->time();
00100         }else{
00101             m_flux = m_fluxSvc->currentFlux();
00102             m_flux->generate();
00103             currentTime = m_flux->time();
00104         }
00105     }else{
00106         //FluxAlg is taking care of the particle, so do nothing but get the current time.
00107         currentTime = m_fluxSvc->currentFlux()->time();
00108     }   
00109 
00110     //now, only do the rest of this algorithm if we have a timetick particle.
00111     std::string particleName = m_fluxSvc->currentFlux()->particleName();
00112     if(particleName != "TimeTick"){
00113         log << MSG::DEBUG << particleName << " Not a timetick particle, no D2Database entry created, continuing..." << endreq;
00114         return StatusCode::SUCCESS;
00115     }
00116 
00117     //by now, we should know that we have the appropriate particle to make a D2Entry with.
00118     double secondsperday = 60.*60.*24.;
00119 
00120     // here we get the time characteristics
00121 
00122     
00123     EarthOrbit orb; //for the following line - this should have a better implementation.
00124     double julianDate = orb.dateFromSeconds(currentTime);
00125 
00126     //NOTE: this gets an interval from the last time that a TimeTick particle came to this one.
00127     //in other words, the timeTick particles define the beginning and ends of intervals.
00128     double intrvalstart = m_lasttime;
00129     //then get the end of the interval (this can be made into whatever).
00130     double intrvalend = currentTime;
00131     //get the livetime from the source itself.
00132     double livetime = intrvalend - m_lasttime;
00133     //..and reset the time of this event to be the "last time" for next time.
00134     m_lasttime = intrvalend;
00135 
00136     intrvalstart = orb.dateFromSeconds(intrvalstart);
00137     intrvalend = orb.dateFromSeconds(intrvalend);
00138 
00139     //and here the pointing characteristics of the LAT.
00140     GPS::instance()->getPointingCharacteristics(currentTime);
00141     //EarthOrbit orbt;
00142     Hep3Vector location = GPS::instance()->position(currentTime);
00143     
00144     // hold onto the cartesian location of the LAT
00145     double posx = location.x(); 
00146     double posy = location.y(); 
00147     double posz = location.z(); 
00148     std::cout << std::endl;
00149     double rax = GPS::instance()->RAX();
00150     double raz = GPS::instance()->RAZ();
00151     double decx = GPS::instance()->DECX();
00152     double decz = GPS::instance()->DECZ();
00153     double razenith = GPS::instance()->RAZenith();
00154     double deczenith = GPS::instance()->DECZenith();
00155     
00156     EarthCoordinate earthpos(location,julianDate);
00157     double lat = earthpos.latitude();
00158     double lon = earthpos.longitude();
00159     double alt = earthpos.altitude();
00160     bool SAA = earthpos.insideSAA();
00161     
00162     SolarSystem sstm;
00163     
00164     double ramoon = sstm.direction(astro::SolarSystem::Moon,julianDate).ra();
00165     double decmoon = sstm.direction(astro::SolarSystem::Moon,julianDate).dec();
00166     double rasun = sstm.direction(astro::SolarSystem::Sun,julianDate).ra();
00167     double decsun = sstm.direction(astro::SolarSystem::Sun,julianDate).dec();
00168     
00169     // Here the TDS is prepared to receive hits vectors
00170     // Check for the MC branch - it will be created if it is not available
00171     
00172     DataObject *mc = new Event::D2EntryCol;
00173     sc=eventSvc()->registerObject(EventModel::MC::Event , mc);
00174     //if(sc.isFailure()) {
00175     //    log << MSG::ERROR << EventModel::MC::Event  <<" could not be registered on data store" << endreq;
00176     //    return sc;
00177     //}
00178     
00179     // Here the TDS receives the exposure data
00180     Event::D2EntryCol* exposureDBase = new Event::D2EntryCol;
00181     sc=eventSvc()->registerObject(EventModel::MC::D2EntryCol , exposureDBase);
00182     if(sc.isFailure()) {
00183         log << MSG::ERROR << EventModel::MC::D2EntryCol  <<" could not be entered into existing data store" << endreq;
00184         return sc;
00185     }
00186     
00187     Event::D2Entry* entry = new Event::D2Entry;
00188     
00189     exposureDBase->push_back(entry);
00190 
00191     entry->init(posx, posy, posz,rax,raz,decx,decz,razenith,deczenith,lat,
00192         lon,alt,intrvalstart,intrvalend,
00193         livetime,ramoon,decmoon,rasun,decsun,
00194         SAA);
00195     
00196     // now we'll retreive the data from the TDS as a check.
00197     Event::D2EntryCol* elist = new Event::D2EntryCol;
00198     eventSvc()->retrieveObject("/Event/MC/D2EntryCol",(DataObject *&)elist);
00199     
00200     Event::D2EntryCol::iterator curEntry = (*elist).begin();
00201     //some test output - to show that the data got onto the TDS
00202     (*curEntry)->writeOut(log);
00203 
00204     SkyDir curDir(raz,decz);
00205     SkyDir xDir(rax,decx);
00206 
00207     SkyDir sunDir(rasun,decsun);
00208     //Rotation galtoglast(m_fluxSvc->transformGlastToGalactic(currentTime).inverse);
00209     sunDir()=(m_fluxSvc->transformGlastToGalactic(currentTime).inverse())*sunDir();
00210      
00211     //and here's the file output.
00212     std::ostream& out = *m_out;
00213         out<<intrvalstart <<'\t';
00214         out<<intrvalend <<'\t';
00215         out<< posx<<'\t';
00216         out<< posy<<'\t';
00217         out<< posz<<'\t';
00218         out<<raz<<'\t';
00219         out<<decz<<'\t';
00220         out<<rax<<'\t';
00221         out<<decx<<'\t';
00222         out<<razenith<<"\t";
00223         out<<deczenith <<'\t';
00224         out<<"1"<<'\t';
00225         out<<livetime <<'\t';
00226         out<<SAA<<'\t';
00227         out<<lon <<'\t';
00228         out<<lat <<'\t';
00229         out<<alt <<'\t';
00230         out<<curDir.l() <<'\t';
00231         out<<curDir.b()<<'\t';
00232         out<<xDir.l() <<'\t';
00233         out<<xDir.b()<<'\t';
00234         out<< rasun <<"\t"<<decsun  <<'\t';
00235         out<< sunDir().x() <<"\t"<< sunDir().y()  <<"\t"<< sunDir().z()  <<'\t';
00236         out<<ramoon <<"\t"<<decmoon   <<std::endl;
00237                                 
00238 
00239 
00240         setFilterPassed( false );
00241     log << MSG::DEBUG << "ExposureAlg found a TimeTick particle, ended this execution after making a record, filterpassed = " << filterPassed() << endreq;
00242 
00243     return sc;
00244 }
00245 
00246 //------------------------------------------------------------------------
00248 StatusCode ExposureAlg::finalize(){
00249     StatusCode  sc = StatusCode::SUCCESS;
00250     MsgStream log(msgSvc(), name());
00251     delete m_out;
00252     
00253     return sc;
00254 }
00255 

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