00001
00002
00003
00004
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
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
00024 #include "FluxSvc.h"
00025 #include "FluxSvc/IFlux.h"
00026 #include "Spectrum.h"
00027 #include "SpectrumFactory.h"
00028 #include "GPS.h"
00029
00030
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
00050 :Algorithm(name, pSvcLocator), m_out(0)
00051 {
00052
00053 declareProperty("source_name", m_source_name="default");
00054
00055 }
00056
00057
00059
00060 StatusCode sc = StatusCode::SUCCESS;
00061 MsgStream log(msgSvc(), name());
00062 log << MSG::INFO << "initialize" << endreq;
00063
00064
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
00073 m_out = new std::ofstream("orbitFromAlg.out");
00074 m_fluxSvc->setRockType(GPS::SLEWING);
00075
00076 return sc;
00077 }
00078
00079
00080
00082
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
00093 if(pcol==0){
00094
00095
00096
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
00107 currentTime = m_fluxSvc->currentFlux()->time();
00108 }
00109
00110
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
00118 double secondsperday = 60.*60.*24.;
00119
00120
00121
00122
00123 EarthOrbit orb;
00124 double julianDate = orb.dateFromSeconds(currentTime);
00125
00126
00127
00128 double intrvalstart = m_lasttime;
00129
00130 double intrvalend = currentTime;
00131
00132 double livetime = intrvalend - m_lasttime;
00133
00134 m_lasttime = intrvalend;
00135
00136 intrvalstart = orb.dateFromSeconds(intrvalstart);
00137 intrvalend = orb.dateFromSeconds(intrvalend);
00138
00139
00140 GPS::instance()->getPointingCharacteristics(currentTime);
00141
00142 Hep3Vector location = GPS::instance()->position(currentTime);
00143
00144
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
00170
00171
00172 DataObject *mc = new Event::D2EntryCol;
00173 sc=eventSvc()->registerObject(EventModel::MC::Event , mc);
00174
00175
00176
00177
00178
00179
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
00197 Event::D2EntryCol* elist = new Event::D2EntryCol;
00198 eventSvc()->retrieveObject("/Event/MC/D2EntryCol",(DataObject *&)elist);
00199
00200 Event::D2EntryCol::iterator curEntry = (*elist).begin();
00201
00202 (*curEntry)->writeOut(log);
00203
00204 SkyDir curDir(raz,decz);
00205 SkyDir xDir(rax,decx);
00206
00207 SkyDir sunDir(rasun,decsun);
00208
00209 sunDir()=(m_fluxSvc->transformGlastToGalactic(currentTime).inverse())*sunDir();
00210
00211
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
00249 StatusCode sc = StatusCode::SUCCESS;
00250 MsgStream log(msgSvc(), name());
00251 delete m_out;
00252
00253 return sc;
00254 }
00255