Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TrackSelector.cpp

Go to the documentation of this file.
00001 // Include files
00002 // -------------
00003 // from Gaudi
00004 #include "GaudiKernel/ToolFactory.h"
00005 
00006 // from CLHEP
00007 #include "CLHEP/Units/SystemOfUnits.h"
00008 
00009 // from TrackEvent
00010 #include "Event/TrackKeys.h"
00011 
00012 // local
00013 #include "TrackSelector.h"
00014 
00015 //-----------------------------------------------------------------------------
00016 // Implementation file for class : TrackSelector
00017 //
00018 // 2005-05-04 : Eduardo Rodrigues (adaptations to new track event model)
00019 //
00020 //  28-07-2003: Jeroen van Tilburg
00021 //-----------------------------------------------------------------------------
00022 
00023 // Declaration of the Tool Factory
00024 static const  ToolFactory<TrackSelector>          s_factory ;
00025 const        IToolFactory& TrackSelectorFactory = s_factory ;
00026 
00027 //=============================================================================
00028 // Standard constructor, initializes variables
00029 //=============================================================================
00030 TrackSelector::TrackSelector( const std::string& type,
00031                               const std::string& name,
00032                               const IInterface* parent )
00033   : GaudiTool ( type, name , parent )
00034   , m_mcParticleJudge( 0 )
00035   , m_previousTrackType( TrackKeys::TypeUnknown )
00036   , m_previousMCParticle( 0 )
00037 {
00038   // interfaces
00039   declareInterface<ITrackSelector>(this);
00040   // job options
00041   declareProperty( "UniqueFlag",  m_uniqueFlag = true );
00042   declareProperty( "ValidFlag",   m_validFlag = true );
00043   declareProperty( "MinP",        m_minP = 0.0*GeV );
00044   declareProperty( "MaxP",        m_maxP = 100.0*TeV );
00045   declareProperty( "TrackTypes",  m_tracktypes );
00046   declareProperty( "MCParticles", m_mcParticleJudgeName = "TrackAcceptance" );
00047 }
00048 
00049 //=============================================================================
00050 // Destructor
00051 //=============================================================================
00052 TrackSelector::~TrackSelector() {};
00053 
00054 //=============================================================================
00055 // Initialization
00056 //=============================================================================
00057 StatusCode TrackSelector::initialize()
00058 {
00059   StatusCode sc = GaudiTool::initialize(); // must be executed first
00060   if ( sc.isFailure() ) return sc;  
00061 
00062   debug() << "==> Initialize" << endreq;
00063 
00064   // Retrieve the reconstructibility tool
00065   m_mcParticleJudge = tool<ITrackReconstructible>( m_mcParticleJudgeName );
00066 
00067   return StatusCode::SUCCESS;
00068 }
00069 
00070 //=============================================================================
00071 // Select the track
00072 //=============================================================================
00073 bool TrackSelector::select( Track* track ) const
00074 {
00075   bool selected = true;
00076 
00077   // Check the momentum of track (at first state)  
00078   State* firstState = *( track -> states().begin() );
00079   if ( firstState ) {
00080     double momentum = firstState -> p();
00081     if ( momentum < m_minP || momentum > m_maxP ) selected = false;
00082   }
00083 
00084   // Check if the track is of the requested type
00085   if ( !selectByTrackType( track ) ) selected = false;
00086 
00087   return selected;
00088 }
00089 
00090 //=============================================================================
00091 // Select the MCParticle
00092 //=============================================================================
00093 bool TrackSelector::select( MCParticle* mcParticle )
00094 {
00095   bool selected = true;
00096 
00097   // Check the momentum of MCParticle
00098   double momentum = mcParticle -> momentum().vect().mag();  
00099   if ( momentum < m_minP || momentum > m_maxP ) selected = false;
00100 
00101   // Check if the MCParticle is of the requested type
00102   if ( !selectByTrackType( mcParticle ) ) selected = false;
00103   
00104   return selected;
00105 }
00106 
00107 //=============================================================================
00108 // Select the Track only by track type, unique- and valid-flag
00109 //=============================================================================
00110 bool TrackSelector::selectByTrackType( Track* track ) const
00111 {
00112   bool selected = true;
00113 
00114   // Check the Unique flag
00115   if ( m_uniqueFlag && !( track->checkFlag( TrackKeys::Unique ) ) )
00116     selected = false;
00117 
00118   // Check the validity flag
00119   if ( m_validFlag && !( track->checkFlag( TrackKeys::Valid ) ) )
00120     selected = false;
00121 
00122   // Check if the track is of the requested type
00123   int tracktype = track -> type();
00124   if ( tracktype == TrackKeys::TypeUnknown ||
00125        ( !m_tracktypes.empty() &&  
00126          std::find( m_tracktypes.begin(), m_tracktypes.end(), 
00127                     tracktype ) == m_tracktypes.end() ) ) selected = false;
00128 
00129   return selected;
00130 }
00131 
00132 //=============================================================================
00133 // Select the MCParticle only by track type
00134 //=============================================================================
00135 bool TrackSelector::selectByTrackType( MCParticle* mcParticle )
00136 {
00137   bool selected = true;
00138 
00139   // Check if the MCParticle is of the requested type
00140   int tracktype = trackType( mcParticle );
00141   if ( tracktype == TrackKeys::TypeUnknown ||
00142        ( !m_tracktypes.empty() &&
00143          std::find( m_tracktypes.begin(), m_tracktypes.end(),  
00144                     tracktype ) == m_tracktypes.end() ) ) selected = false;
00145 
00146   return selected;
00147 }
00148 
00149 //=============================================================================
00150 // Get the track type identifyer of the MCParticle
00151 //=============================================================================
00152 unsigned int TrackSelector::trackType( MCParticle* mcPart )
00153 {
00154   bool hasVelo = m_mcParticleJudge -> hasVelo( mcPart );
00155   bool hasSeed = m_mcParticleJudge -> hasSeed( mcPart );
00156   bool hasTT   = m_mcParticleJudge -> hasTT( mcPart );
00157 
00158   const HepLorentzVector fourMom = mcPart->momentum();
00159 
00160   unsigned int tracktype = TrackKeys::TypeUnknown;
00161 
00162   if ( hasVelo && hasSeed ) {            // long track
00163     tracktype = TrackKeys::Long;
00164   } else if ( hasVelo && hasTT ) {       // upstream track
00165     tracktype = TrackKeys::Upstream;
00166   } else if ( hasSeed && hasTT ) {       // downstream track
00167     tracktype = TrackKeys::Downstream;
00168   } else if ( hasVelo ) {                // velo track
00169     tracktype = TrackKeys::Velo;
00170   } else if ( hasSeed ) {                // seed track
00171     tracktype = TrackKeys::Ttrack;
00172   } 
00173 
00174   m_previousTrackType  = tracktype;
00175   m_previousMCParticle = mcPart;
00176 
00177   return tracktype;
00178 }
00179 
00180 //=============================================================================
00181 // Set the track type of a Track with an MCParticle's type
00182 //=============================================================================
00183 StatusCode TrackSelector::setTrackType( MCParticle* mcPart,
00184                                         Track*& track )
00185 {
00186   unsigned int tracktype = TrackKeys::TypeUnknown;
00187   
00188   if ( mcPart == m_previousMCParticle ) {
00189     tracktype = m_previousTrackType;
00190   }
00191   else {
00192     tracktype = trackType( mcPart );
00193   }
00194 
00195   track -> setType ( tracktype );
00196   if ( TrackKeys::TypeUnknown == tracktype ) return StatusCode::FAILURE;
00197   else                                       return StatusCode::SUCCESS;
00198 }
00199 
00200 //=============================================================================

Generated on Fri May 27 13:59:37 2005 for New Track Event Model by doxygen 1.4.1