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

McCoordsAlg.cxx

Go to the documentation of this file.
00001 
00006 // Include files
00007 
00008 #include "GaudiKernel/Algorithm.h"
00009 #include "GaudiKernel/MsgStream.h"
00010 #include "GaudiKernel/AlgFactory.h"
00011 #include "GaudiKernel/SmartDataPtr.h"
00012 
00013 #include "astro/GPS.h"
00014 #include "geometry/Vector.h"
00015 
00016 #include <cassert>
00017 #include <map>
00018 
00019 // forward declatation of the worker
00020 class McCworker;
00021 
00022 namespace { // anonymous namespace for file-global
00023     std::string treename("MeritTuple");
00024     astro::GPS* gps;
00025 #include "Item.h"
00026 }
00027 
00028 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00032 class McCoordsAlg : public Algorithm {
00033 
00034 public:
00035     McCoordsAlg(const std::string& name, ISvcLocator* pSvcLocator); 
00036 
00037     StatusCode initialize();
00038     StatusCode execute();
00039     StatusCode finalize();
00040 private:
00042     McCworker * m_worker;
00043     //counter
00044     int m_count;
00045 };
00046 
00047 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00048 
00049 static const AlgFactory<McCoordsAlg>  Factory;
00050 const IAlgFactory& McCoordsAlgFactory = Factory;
00051 
00052 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00053 
00054 class McCworker{ 
00055 public:
00056     McCworker();
00057 
00058     void evaluate();
00059 
00060 private:
00061     // tuple items expect to find
00062     //TypedItem<unsigned int, 'i'> EvtRun, EvtEventId;
00063 
00064     // these all float or double
00065     Item McXDir;
00066     Item McYDir;
00067     Item McZDir;
00068 
00069     //McCoords entries to create
00070     float m_mcRa,m_mcDec,m_mcL,m_mcB;
00071     float m_mcZen,m_mcAzim;
00072 };
00073 
00074 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00075 McCoordsAlg::McCoordsAlg(const std::string& name, ISvcLocator* pSvcLocator) :
00076 Algorithm(name, pSvcLocator)
00077 {
00078     declareProperty("TreeName",  treename="MeritTuple");
00079 }
00080 
00081 StatusCode McCoordsAlg::initialize()
00082 {
00083     StatusCode  sc = StatusCode::SUCCESS;
00084 
00085     MsgStream log(msgSvc(), name());
00086 
00087     // Use the Job options service to get the Algorithm's parameters
00088     setProperties();
00089 
00090     // get a pointer to RootTupleSvc 
00091     if( (sc = service("RootTupleSvc", rootTupleSvc, true) ). isFailure() ) {
00092         log << MSG::ERROR << " failed to get the RootTupleSvc" << endreq;
00093         return sc;
00094     }
00095     m_worker = new McCworker();
00096 
00097     // get the GPS instance
00098     gps = astro::GPS::instance();
00099 
00100     m_count = 0;
00101 
00102     return sc;
00103 }
00104 
00105 StatusCode McCoordsAlg::execute()
00106 {
00107     StatusCode sc = StatusCode::SUCCESS;
00108 
00109     MsgStream log(msgSvc(), name());
00110 
00111     m_count++;
00112 
00113     // now have the worker do it
00114     m_worker->evaluate();
00115 
00116     return sc;
00117 }
00118 
00119 StatusCode McCoordsAlg::finalize()
00120 {
00121     return StatusCode::SUCCESS;
00122 }
00123 
00124 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00125 
00141 McCworker::McCworker()
00142 // initialize pointers to current items
00143 : McXDir("McXDir")
00144 , McYDir("McYDir")
00145 , McZDir("McZDir")
00146 {
00147     //now create new items 
00148 
00149     addItem( "McRa",            m_mcRa);
00150     addItem( "McDec",           m_mcDec);
00151     addItem( "McL",             m_mcL);
00152     addItem( "McB",             m_mcB);
00153     addItem( "McZenithTheta",   m_mcZen);
00154     addItem( "McEarthAzimuth",  m_mcAzim);
00155 }
00156 
00157 void McCworker::evaluate()
00158 {
00159     // convert to (ra, dec)
00160 
00161     Vector Mc_t0(McXDir, McYDir, McZDir);
00162     // Mc particle direction points down... 
00163     // toSky converts a *particle* direction
00164     // into a direction on the sky, so the minus-sign is taken care of!
00165 
00166     astro::SkyDir mcdir = gps->toSky( Mc_t0 );
00167     m_mcRa   = mcdir.ra();
00168     m_mcDec  = mcdir.dec();
00169     m_mcL = mcdir.l();
00170     m_mcB = mcdir.b();
00171 
00172     // Local zenith coordinates
00173     astro::SkyDir zenith(gps->zenithDir());  // pointing direction
00174     double zenith_theta = mcdir.difference(zenith); 
00175     if( fabs(zenith_theta)<1e-8) zenith_theta=0;
00176     // all this to do the azimuth angle :-(
00177     Hep3Vector north_pole(0,0,1);
00178     Hep3Vector east_dir( north_pole.cross(zenith()).unit() ); // east is perp to north_pole and zenith
00179     Hep3Vector north_dir( zenith().cross(east_dir));
00180     double earth_azimuth=atan2( mcdir().dot(east_dir), mcdir().dot(north_dir) );
00181     if( earth_azimuth <0) earth_azimuth += 2*M_PI; // to 0-360 deg.
00182     if( fabs(earth_azimuth)<1e-8) earth_azimuth=0;
00183     m_mcZen  = zenith_theta*180/M_PI;;
00184     m_mcAzim = earth_azimuth*180/M_PI;
00185 
00186     return;
00187 }
00188 //------------------------------------------------------------------------------
00189 

Generated on Mon Dec 1 20:09:05 2008 by doxygen 1.3.3