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

FluxAlg.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/FluxSvc/src/FluxAlg.cxx,v 1.32 2002/10/06 19:47:57 burnett 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 // Event for creating the McEvent stuff
00014 #include "Event/TopLevel/Event.h"
00015 #include "Event/TopLevel/MCEvent.h"
00016 #include "Event/MonteCarlo/McParticle.h"
00017 #include "Event/TopLevel/EventModel.h"
00018 
00019 //flux
00020 #include "FluxSvc.h"
00021 #include "FluxSvc/IFlux.h"
00022 #include "Spectrum.h"
00023 #include "SpectrumFactory.h"
00024 
00025 #include "CLHEP/Vector/LorentzVector.h"
00026 
00027 #include <cassert>
00028 #include <vector>
00029 
00030 #include "FluxAlg.h"
00031 //------------------------------------------------------------------------
00032 
00033 
00034 static const AlgFactory<FluxAlg>  Factory;
00035 const IAlgFactory& FluxAlgFactory = Factory;
00036 
00037 //------------------------------------------------------------------------
00039 FluxAlg::FluxAlg(const std::string& name, ISvcLocator* pSvcLocator)
00040 :Algorithm(name, pSvcLocator) , m_sequence(0)
00041 {
00042     // declare properties with setProperties calls
00043     declareProperty("source_name",  m_source_name="default");
00044     declareProperty("MCrun",        m_run=100);
00045     
00046 }
00047 //------------------------------------------------------------------------
00049 StatusCode FluxAlg::initialize(){
00050     StatusCode  sc = StatusCode::SUCCESS;
00051     MsgStream log(msgSvc(), name());
00052     log << MSG::INFO << "initialize" << endreq;
00053     
00054     // Use the Job options service to set the Algorithm's parameters
00055     setProperties();
00056     
00057     if ( service("FluxSvc", m_fluxSvc).isFailure() ){
00058         log << MSG::ERROR << "Couldn't find the FluxSvc!" << endreq;
00059         return StatusCode::FAILURE;
00060     }
00061     
00062     log << MSG::INFO << "loading source..." << endreq;
00063     
00064     sc =  m_fluxSvc->source(m_source_name, m_flux);
00065     if( sc.isFailure()) {
00066         log << MSG::ERROR << "Could not find flux " << m_source_name << endreq;
00067         return sc;
00068     }
00069     log << MSG::INFO << "Source: "<< m_flux->title() << endreq;
00070     
00071     log << MSG::INFO << "Source title: " << m_flux->title() << endreq;
00072     log << MSG::INFO << "        area: " << m_flux->targetArea() << endreq;
00073     log << MSG::INFO << "        rate: " << m_flux->rate() << endreq;
00074     
00075     if ( service("ParticlePropertySvc", m_partSvc).isFailure() ){
00076         log << MSG::ERROR << "Couldn't find the ParticlePropertySvc!" << endreq;
00077         return StatusCode::FAILURE;
00078     }
00079     return sc;
00080 }
00081 
00082 
00083 //------------------------------------------------------------------------
00085 StatusCode FluxAlg::execute()
00086 {
00087     StatusCode  sc = StatusCode::SUCCESS;
00088     MsgStream   log( msgSvc(), name() );
00089     //
00090     // Purpose: have the flux service create parameters of an incoming particle 
00091     // if nothing has changed, then use the existing m_flux,
00092     // but if the "current" IFlux is not the same as the one we have now,
00093     // then change our m_flux pointer to be the new one.
00094     // Output:  a staturCode to ensure the function executed properly.
00095     
00096     if(m_fluxSvc->currentFlux() == m_flux){
00097         m_flux->generate();
00098     }else{
00099         m_flux = m_fluxSvc->currentFlux();
00100         m_flux->generate();
00101     }
00102     HepPoint3D p = m_flux->launchPoint();
00103     HepPoint3D d = m_flux->launchDir();
00104     double ke = m_flux->energy(); // kinetic energy in MeV
00105     std::string particleName = m_flux->particleName();
00106     //if it's a "timeTick, then ExposureAlg should take care of it, and no othe algorithms should care about it.
00107     if(particleName == "TimeTick"){
00108         log << MSG::DEBUG << particleName << " particle found, will exit particle creation/reconstruction loops" << endreq;
00109         particleName = "gamma"; 
00110         setFilterPassed( false );//no need to return - we want the time record on the TDS.  the ExposureAlg will handle the rest.
00111     }
00112     
00113     
00114     //here's where we get the particleID and mass for later.
00115     if( particleName=="p") particleName="proton";
00116     ParticleProperty* prop = m_partSvc->find(particleName);
00117     
00118     if( prop==0) {
00119         log << MSG::ERROR << "Particle name " << particleName << " not found by particle properties" << endreq;
00120         return StatusCode::FAILURE;
00121     }
00122     
00123     int partID = prop->jetsetID(); // same as stdhep id
00124     
00125     log << MSG::DEBUG << particleName
00126         << "(" << m_flux->energy()
00127         << " MeV), Launch: " 
00128         << "(" << p.x() <<", "<< p.y() <<", "<<p.z()<<")" 
00129         << " mm, Dir " 
00130         << "(" << d.x() <<", "<< d.y() <<", "<<d.z()<<")" 
00131         << endreq;
00132     
00133     
00134     // Here the TDS is prepared to receive hits vectors
00135     // Check for the MC branch - it will be created if it is not available
00136     Event::MCEvent* mch = 0;
00137 
00138     SmartDataPtr<Event::MCEvent> mcheader(eventSvc(), EventModel::MC::Event);
00139     if (mcheader == 0) {
00140         sc=eventSvc()->registerObject(EventModel::MC::Event , mch= new Event::MCEvent);
00141         if(sc.isFailure()) {
00142             log << MSG::WARNING << EventModel::MC::Event  <<" could not be registered on data store" << endreq;
00143             return sc;
00144         }
00145         
00146     }else mch = mcheader;
00147 
00148 
00149     mch->initialize(mch->getRunNumber(), m_flux->numSource(), mch->getSequence());
00150 
00151 
00152     
00153     Event::McParticleCol* pcol = new Event::McParticleCol;
00154     sc = eventSvc()->registerObject(EventModel::MC::McParticleCol, pcol);
00155     if( sc.isFailure()) {
00156         
00157         log << MSG::ERROR << "Could not Register "<< EventModel::MC::McParticleCol << endreq;
00158         
00159         return sc;
00160     }
00161     Event::McParticle * parent= new Event::McParticle;
00162     pcol->push_back(parent);
00163     
00164     double mass = prop->mass() , 
00165         energy = (ke+mass),
00166         momentum=sqrt(energy*energy - mass*mass); 
00167     HepLorentzVector pin(d*momentum,energy);
00168     
00169     // This parent particle decay at the start in the first particle, 
00170     // so initial momentum and final one are the same
00171     parent->initialize(parent, partID, 
00172         Event::McParticle::PRIMARY,
00173         pin,p);
00174     parent->finalize(pin, p);
00175     
00176     // get the event header to set the time
00177     Event::EventHeader* h = 0; 
00178 
00179     SmartDataPtr<Event::EventHeader> header(eventSvc(), EventModel::EventHeader);
00180     if(0==header) {
00181         // not already there: try to register instead
00182         sc = eventSvc()->registerObject(EventModel::EventHeader, h=new Event::EventHeader);
00183         if( sc.isFailure()) {
00184             log << MSG::WARNING << " could not find or register the event header" << endreq;
00185         }
00186     } else  h = header;
00187 
00188     h->setTime(m_flux->time());
00189     return StatusCode::SUCCESS;
00190 }
00191 
00192 //------------------------------------------------------------------------
00194 StatusCode FluxAlg::finalize(){
00195     StatusCode  sc = StatusCode::SUCCESS;
00196     MsgStream log(msgSvc(), name());
00197     
00198     return sc;
00199 }
00200 

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