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

ObfValsTool.cxx

Go to the documentation of this file.
00001 
00008 // Include files
00009 
00010 #include "ValBase.h"
00011 
00012 #include "GaudiKernel/IDataProviderSvc.h"
00013 #include "GaudiKernel/SmartDataPtr.h"
00014 #include "GaudiKernel/ToolFactory.h"
00015 #include "GaudiKernel/IToolSvc.h"
00016 #include "GaudiKernel/GaudiException.h" 
00017 
00018 #include "Event/TopLevel/EventModel.h"
00019 #include "Event/TopLevel/Event.h"
00020 #include "Event/MonteCarlo/McParticle.h"
00021 
00022 #include "CLHEP/Vector/Rotation.h"
00023 #include "geometry/Vector.h"
00024 
00025 #include "OnboardFilterTds/ObfFilterStatus.h"
00026 #include "OnboardFilterTds/ObfFilterTrack.h"
00027 #include "LdfEvent/LsfMetaEvent.h"
00028 
00035 class ObfValsTool : public ValBase
00036 {
00037 public:
00038 
00039     ObfValsTool( const std::string& type, 
00040         const std::string& name, 
00041         const IInterface* parent);
00042 
00043     virtual ~ObfValsTool() { }
00044 
00045     StatusCode initialize();
00046 
00047     StatusCode calculate();
00048 
00049     StatusCode finalize();
00050 
00051 private:
00052 
00053     // "Best" track variables
00054     int    m_nGrbHitsX;
00055     int    m_nGrbHitsY;
00056     float  m_grbSlpX;
00057     float  m_grbSlpY;
00058     float  m_grbIntX;
00059     float  m_grbIntY;
00060     float  m_grbZ;
00061     float  m_grbXdir;
00062     float  m_grbYdir;
00063     float  m_grbZdir;
00064     float  m_grbAngSep;
00065 
00066     // Filter status information
00067     int    m_gamStatus;
00068     int    m_gamState;
00069     int    m_hipStatus;
00070     int    m_hipState;
00071     int    m_mipStatus;
00072     int    m_mipState;
00073     int    m_dgnStatus;
00074     int    m_dgnState;
00075 
00076     int    m_gamStage;
00077     float  m_gamEnergy;
00078 
00079     int    m_warnNoFilterStatus;
00080 
00081 // Fsw filter info
00082     int    m_fswGamStatus;
00083     int    m_fswGamState;
00084     int    m_fswGamPrescaleIndex;
00085     int    m_fswGamPrescaleFactor;
00086     float  m_fswGamEnergy;
00087     int    m_fswGamStage;
00088     int    m_fswGamVersion;
00089 
00090     int    m_fswHipStatus;
00091     int    m_fswHipState;
00092     int    m_fswMipStatus;
00093     int    m_fswMipState;
00094 
00095     int    m_fswDgnStatus;
00096     int    m_fswDgnState;
00097     int    m_fswDgnPrescaleIndex;
00098     int    m_fswDgnPrescaleFactor;
00099   
00100 };
00101 
00102 // Static factory for instantiation of algtool objects
00103 static ToolFactory<ObfValsTool> s_factory;
00104 const IToolFactory& ObfValsToolFactory = s_factory;
00105 
00106 // Standard Constructor
00107 ObfValsTool::ObfValsTool(const std::string& type, 
00108                          const std::string& name, 
00109                          const IInterface* parent)
00110                          : ValBase( type, name, parent )
00111 {    
00112     // Declare additional interface
00113     declareInterface<IValsTool>(this); 
00114 }
00115 
00188 StatusCode ObfValsTool::initialize()
00189 {
00190     StatusCode sc = StatusCode::SUCCESS;
00191 
00192     MsgStream log(msgSvc(), name());
00193 
00194     if( ValBase::initialize().isFailure()) return StatusCode::FAILURE;
00195 
00196     // Status information from filters
00197     addItem("ObfGamStatus",         &m_gamStatus);
00198     addItem("ObfGamState",          &m_gamState);
00199     addItem("ObfGamStage",          &m_gamStage);
00200     addItem("ObfGamEnergy",         &m_gamEnergy);
00201 
00202     addItem("ObfHipStatus",         &m_hipStatus);
00203     addItem("ObfHipState",          &m_hipState);
00204 
00205     addItem("ObfMipStatus",         &m_mipStatus);
00206     addItem("ObfMipState",          &m_mipState);
00207 
00208     addItem("ObfDgnStatus",         &m_dgnStatus);
00209     addItem("ObfDgnState",          &m_dgnState);
00210 
00211     // "Best" track information
00212     addItem("GrbXHits",             &m_nGrbHitsX);
00213     addItem("GrbYHits",             &m_nGrbHitsY);
00214     addItem("GrbSlpX",              &m_grbSlpX);
00215     addItem("GrbSlpY",              &m_grbSlpY);
00216     addItem("GrbIntX",              &m_grbIntX);
00217     addItem("GrbIntY",              &m_grbIntY);
00218     addItem("GrbZ",                 &m_grbZ);
00219     addItem("GrbXDir",              &m_grbXdir);
00220     addItem("GrbYDir",              &m_grbYdir);
00221     addItem("GrbZDir",              &m_grbZdir);
00222     addItem("GrbMcAngSep",          &m_grbAngSep);
00223 
00224     addItem("FswGamStatus",         &m_fswGamStatus);
00225     addItem("FswGamState",          &m_fswGamState);
00226     addItem("FswGamEnergy",         &m_fswGamEnergy);
00227     addItem("FswGamStage",          &m_fswGamStage);
00228     addItem("FswGamPrescaleIndex",  &m_fswGamPrescaleIndex);
00229     addItem("FswGamPrescaleFactor", &m_fswGamPrescaleFactor);
00230     addItem("FswGamVersion",        &m_fswGamVersion);
00231 
00232     addItem("FswHipStatus",         &m_fswHipStatus);
00233     addItem("FswHipState",          &m_fswHipState);
00234     addItem("FswMipStatus",         &m_fswMipStatus);
00235     addItem("FswMipState",          &m_fswMipState);
00236 
00237     addItem("FswDgnStatus",         &m_fswDgnStatus);
00238     addItem("FswDgnState",          &m_fswDgnState);
00239     addItem("FswDgnPrescaleIndex",  &m_fswDgnPrescaleIndex);
00240     addItem("FswDgnPrescaleFactor", &m_fswDgnPrescaleFactor);
00241 
00242 
00243     zeroVals();
00244 
00245     m_warnNoFilterStatus = 0;
00246 
00247     return sc;
00248 }
00249 
00250 StatusCode ObfValsTool::calculate()
00251 {
00252     StatusCode sc = StatusCode::SUCCESS;
00253     MsgStream log(msgSvc(), name());
00254 
00255     // We'll use these when copying to the deprecated variables
00256     unsigned int filterStatusHi = 0;
00257     unsigned int filterStatusLo = 0;
00258 
00259     // Start with the status information returned from the filters
00260     // Look up the TDS class containing this information
00261     SmartDataPtr<OnboardFilterTds::ObfFilterStatus> 
00262         obfStatus(m_pEventSvc, "/Event/Filter/ObfFilterStatus");
00263 
00264     m_gamState = enums::Lsf::INVALID;
00265     m_dgnState = enums::Lsf::INVALID;
00266     m_hipState = enums::Lsf::INVALID;
00267     m_mipState = enums::Lsf::INVALID;
00268 
00269     // If it exists then fill filter status info
00270     if (obfStatus)
00271     {
00272         // Pointer to our retrieved objects
00273         const OnboardFilterTds::IObfStatus* obfResult = 0;
00274 
00275         // Start with Gamma Filter
00276         if (obfResult   = 
00277                 obfStatus->getFilterStatus(OnboardFilterTds::ObfFilterStatus::GammaFilter))
00278         {
00279             m_gamStatus    = obfResult->getStatusWord();
00280             m_gamState     = obfResult->getState();
00281             m_gamStage     = dynamic_cast<const OnboardFilterTds::ObfGammaStatus*>(obfResult)->getStage();
00282             m_gamEnergy    = dynamic_cast<const OnboardFilterTds::ObfGammaStatus*>(obfResult)->getEnergy();
00283         }
00284         else m_gamStatus = -1;
00285 
00286         // HFC Filter results
00287         if (obfResult   = 
00288                 obfStatus->getFilterStatus(OnboardFilterTds::ObfFilterStatus::HIPFilter))
00289         {
00290             m_hipStatus    = obfResult->getStatusWord();
00291             m_hipState     = obfResult->getState();
00292         }
00293         else m_hipStatus = -1;
00294 
00295         // MIP Filter results
00296         if (obfResult   = 
00297                 obfStatus->getFilterStatus(OnboardFilterTds::ObfFilterStatus::MIPFilter))
00298         {
00299             m_mipStatus    = obfResult->getStatusWord();
00300             m_mipState     = obfResult->getState();
00301         }
00302         else m_mipStatus = -1;
00303 
00304         // DFC Filter results
00305         if (obfResult   = 
00306                 obfStatus->getFilterStatus(OnboardFilterTds::ObfFilterStatus::DGNFilter))
00307         {
00308             m_dgnStatus    = obfResult ? obfResult->getStatusWord() : -1;
00309             m_dgnState     = obfResult->getState();
00310         }
00311         else m_dgnStatus = -1;
00312     }
00313     else 
00314     {
00315         m_warnNoFilterStatus++;
00316         if (   m_warnNoFilterStatus <= 10 ) 
00317         {
00318             log << MSG::WARNING << "ObfFilterStatus not found" ;
00319             if ( m_warnNoFilterStatus == 10 ) {
00320                 log << " -- Further WARNINGs on missing FilterStatus are suppressed"; }
00321             log  << endreq;
00322         }
00323     }
00324     // Next, try to find the Fsw versions of the above
00325 
00326     m_fswGamPrescaleIndex = LSF_INVALID_UINT;
00327     m_fswGamPrescaleFactor = LSF_INVALID_UINT;
00328 
00329     m_fswDgnPrescaleIndex = LSF_INVALID_UINT;
00330     m_fswDgnPrescaleFactor = LSF_INVALID_UINT;
00331 
00332     m_fswGamState = enums::Lsf::INVALID;
00333     m_fswDgnState = enums::Lsf::INVALID;
00334     m_fswHipState = enums::Lsf::INVALID;
00335     m_fswMipState = enums::Lsf::INVALID;
00336     
00337     m_fswGamVersion = enums::Lsf::INVALID;
00338 
00339     SmartDataPtr<LsfEvent::MetaEvent>  metaEventTds(m_pEventSvc, "/Event/MetaEvent");
00340     if (metaEventTds) {
00341         const lsfData::GammaHandler* gamma = metaEventTds->gammaFilter();
00342         if (gamma) {
00343             // rsd is Result Summary Data 
00344             if(gamma->rsd()) {
00345                 m_fswGamStatus = gamma->rsd()->status();  
00346                 m_fswGamVersion = gamma->version();
00347             }
00348             m_fswGamState = gamma->state();  
00349             m_fswGamPrescaleFactor = gamma->prescaleFactor();    
00350             m_fswGamPrescaleIndex  = gamma->lpaHandler().prescaleIndex();
00351             m_fswGamEnergy         = static_cast<float>(gamma->rsd()->energyInLeus())/4.0;
00352             m_fswGamStage          = gamma->rsd()->stage();
00353         }
00354         const lsfData::DgnHandler* dgn = metaEventTds->dgnFilter();
00355         if (dgn) {
00356             // rsd is Result Summary Data 
00357             if(dgn->rsd()) m_fswDgnStatus = dgn->rsd()->status();  
00358             m_fswDgnState = dgn->state();  
00359             m_fswDgnPrescaleFactor = dgn->prescaleFactor();  
00360             m_fswDgnPrescaleIndex  = dgn->lpaHandler().prescaleIndex(); 
00361         }
00362 
00363         const lsfData::HipHandler* hip = metaEventTds->hipFilter();       if (hip) {
00364             // rsd is Result Summary Data 
00365             if(hip->rsd()) m_fswHipStatus = hip->rsd()->status();  
00366             m_fswHipState = hip->state();  
00367             //m_fswHipPrescaleFactor = hip->prescaleFactor();  
00368             //m_fswHipPrescaleIndex  = hip->lpaHandler().prescaleIndex(); 
00369         }
00370 
00371         const lsfData::MipHandler* mip = metaEventTds->mipFilter();
00372         if (mip) {
00373             // rsd is Result Summary Data 
00374             if(mip->rsd()) m_fswMipStatus = mip->rsd()->status();  
00375             m_fswMipState = mip->state();  
00376             //m_fswMipPrescaleFactor = mip->prescaleFactor();  
00377             //m_fswMipPrescaleIndex  = mip->lpaHandler().prescaleIndex(); 
00378         }
00379 
00380 
00381     } else {
00382         log << MSG::DEBUG << "No MetaEvent" << endreq;
00383     }
00384 
00385     // Get the summary tracking information on the "best" track
00386     SmartDataPtr<OnboardFilterTds::ObfFilterTrack> 
00387         filterTrack(m_pEventSvc, "/Event/Filter/ObfFilterTrack");
00388 
00389     if( filterTrack )
00390     {
00391         m_nGrbHitsX = filterTrack->get_nXhits();
00392         m_nGrbHitsY = filterTrack->get_nYhits();
00393         m_grbSlpX   = filterTrack->get_slpXZ();
00394         m_grbSlpY   = filterTrack->get_slpYZ();
00395         m_grbIntX   = filterTrack->get_xInt();
00396         m_grbIntY   = filterTrack->get_yInt();
00397         m_grbZ      = filterTrack->get_z();
00398 
00399         // Calculate direction cosines for GRB track first
00400         if (m_nGrbHitsX > 0 && m_nGrbHitsY > 0)
00401         {
00402             double alpha = atan2(m_grbSlpY, m_grbSlpX);
00403 
00404             if (alpha < 0.) alpha += 2. * M_PI;
00405 
00406             double slope = sqrt(pow(m_grbSlpX,2) + pow(m_grbSlpY,2));
00407             double beta  = atan(slope);
00408 
00409             m_grbXdir = cos(alpha)*sin(beta);
00410             m_grbYdir = sin(alpha)*sin(beta);
00411             m_grbZdir = cos(beta);
00412 
00413             // Look up the McParticle collection in case its there... 
00414             SmartDataPtr<Event::McParticleCol> mcParticleCol(m_pEventSvc, EventModel::MC::McParticleCol);
00415 
00416             // If running Monte Carlo, determine FilterAngSep here
00417             if (mcParticleCol)
00418             {
00419                 // We only care about incident particle direction here, so can use the first particle
00420                 // in the McParticleCol
00421                 Event::McParticle* mcPart = *(mcParticleCol->begin());
00422 
00423                 CLHEP::HepLorentzVector Mc_p0 = mcPart->initialFourMomentum();
00424                 Vector                  Mc_t0 = Vector(Mc_p0.x(),Mc_p0.y(), Mc_p0.z()).unit();
00425                 Vector                  filtDir(-m_grbXdir, -m_grbYdir, -m_grbZdir);
00426 
00427                 double cosTheta = filtDir.dot(Mc_t0);
00428 
00429                 m_grbAngSep = acos(cosTheta);
00430             }
00431         }
00432     }
00433 
00434     return sc;
00435 }
00436 
00437 StatusCode ObfValsTool::finalize() {
00438 
00439     MsgStream log(msgSvc(), name());
00440     log << MSG::INFO ;
00441     log << endreq;
00442     if(m_warnNoFilterStatus>0)
00443         log << MSG::INFO 
00444         << "Number of warnings (FilterStatus not found): "
00445         << m_warnNoFilterStatus << endreq;
00446 
00447     //setFinalized(); //  prevent being called again
00448 
00449     return StatusCode::SUCCESS;
00450 }
00451 

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