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

Track.cpp

Go to the documentation of this file.
00001 // $Id: Track.cpp,v 1.10 2005/05/25 08:38:00 hernando Exp $ // Include files
00002 
00003 // local
00004 #include "Event/Track.h"
00005 #include "Event/TrackKeys.h"
00006 #include "Event/TrackFunctor.h"
00007 #include <functional>
00008 
00009 //-----------------------------------------------------------------------------
00010 // Implementation file for class : Track
00011 //
00012 // 2004-12-14 : Jose Hernando, Eduardo Rodrigues
00013 //-----------------------------------------------------------------------------
00014 
00015 
00016 //=============================================================================
00017 // Retrieve the position and momentum vectors and the corresponding
00018 // 6D covariance matrix (pos:1->3,mom:4-6) at the physics state
00019 //=============================================================================
00020 void Track::positionAndMomentum( HepPoint3D &pos,
00021                                  HepVector3D &mom,
00022                                  HepSymMatrix &cov6D ) const
00023 {
00024   firstState().positionAndMomentum( pos, mom, cov6D );
00025 };
00026 
00027 //=============================================================================
00028 // Retrieve the position and momentum vectors at the physics state
00029 //=============================================================================
00030 void Track::positionAndMomentum( HepPoint3D &pos,
00031                                        HepVector3D &mom ) const
00032 {
00033   firstState().positionAndMomentum( pos, mom );
00034 };
00035 
00036 //=============================================================================
00037 // Retrieve the 3D-position (+ errors) at the physics state
00038 //=============================================================================
00039 void Track::position( HepPoint3D &pos,
00040                             HepSymMatrix &errPos ) const
00041 {
00042   pos    = firstState().position();
00043   errPos = firstState().errPosition();
00044 };
00045 
00046 //=============================================================================
00047 // Retrieve the slopes (dx/dz,dy/dz,1) at the physics state
00048 //=============================================================================
00049 void Track::slopes( HepVector3D &slopes,
00050                           HepSymMatrix &errSlopes ) const
00051 {
00052   slopes    = firstState().slopes();
00053   errSlopes = firstState().errSlopes();
00054 };
00055 
00056 //=============================================================================
00057 // Retrieve the momentum at the physics state
00058 //=============================================================================
00059 double Track::p() const
00060 {
00061   return firstState().p();
00062 };
00063 
00064 //=============================================================================
00065 // Retrieve the transverse momentum at the physics state
00066 //=============================================================================
00067 double Track::pt() const
00068 {
00069   return firstState().pt();
00070 };
00071 
00072 //=============================================================================
00073 // Retrieve the momentum vector (+ errors) at the physics state
00074 //=============================================================================
00075 void Track::momentum( HepVector3D &mom,
00076                             HepSymMatrix &errMom ) const
00077 {
00078   mom    = firstState().momentum();
00079   errMom = firstState().errMomentum();
00080 };
00081 
00082 //=============================================================================
00083 // Retrieve the 6D covariance matrix (x,y,z,px,py,pz) at the physics state
00084 //=============================================================================
00085 void Track::posMomCovariance( HepSymMatrix &cov6D ) const
00086 {
00087   cov6D = firstState().posMomCovariance();
00088 };
00089 
00090 //=============================================================================
00091 // Retrieve the reference to the state closest to the given z-position
00092 //=============================================================================
00093 State & Track::closestState( double z )
00094 {
00095   std::vector<State*>::iterator iter = 
00096     std::max_element(m_states.begin(),m_states.end(),
00097                      TrackFunctor::closestToZ<State>(z));
00098   if (iter == m_states.end())
00099     throw GaudiException( "No state closest to z","Track.cpp",
00100                           StatusCode::FAILURE );
00101   return *(*iter);
00102 };
00103 
00104 //=============================================================================
00105 // Retrieve the (const) reference to the state closest to the given z-position
00106 //=============================================================================
00107 const State & Track::closestState( double z ) const
00108 {
00109   std::vector<State*>::const_iterator iter = 
00110     std::max_element(m_states.begin(),m_states.end(),
00111                      TrackFunctor::closestToZ<State>(z));
00112   if (iter == m_states.end())
00113     throw GaudiException( "No state closest to z","Track.cpp",
00114                           StatusCode::FAILURE );
00115   return *(*iter);
00116 };
00117 
00118 //=============================================================================
00119 // Retrieve the reference to the state closest to the given plane
00120 //=============================================================================
00121 State & Track::closestState( const HepPlane3D &plane )
00122 {
00123   std::vector<State*>::iterator iter = 
00124     std::max_element(m_states.begin(),m_states.end(),
00125                      TrackFunctor::closestToPlane<State>(plane));
00126   if (iter == m_states.end())
00127     throw GaudiException( "No state closest to plane","Track.cpp",
00128                           StatusCode::FAILURE );
00129   return *(*iter);
00130 };
00131 
00132 //=============================================================================
00133 // Retrieve the (const) reference to the state closest to the given plane
00134 //=============================================================================
00135 const State & Track::closestState( const HepPlane3D &plane ) const
00136 {
00137   std::vector<State*>::const_iterator iter = 
00138     std::max_element(m_states.begin(),m_states.end(),
00139                      TrackFunctor::closestToPlane<State>(plane));
00140   if (iter == m_states.end())
00141     throw GaudiException( "No state closest to plane","Track.cpp",
00142                           StatusCode::FAILURE );
00143   return *(*iter);
00144 };
00145 
00146 //=============================================================================
00147 // check the existence of a state at a certain predefined location
00148 //=============================================================================
00149 bool Track::hasStateAt( unsigned int location ) const
00150 {
00151   std::vector<State*>::const_iterator iter =
00152     std::find_if(m_states.begin(),m_states.end(),
00153                  std::bind2nd(std::mem_fun(&State::checkLocation),location));
00154   // the last line should be equivalent to:
00155   //             TrackFunctor::HasKey<State>(&State::checkLocation,location));
00156   return (iter != m_states.end());
00157 };
00158 
00159 //=============================================================================
00160 // Retrieve the pointer to the state closest to the given plane
00161 //=============================================================================
00162 State& Track::stateAt( unsigned int location )
00163 {
00164   std::vector<State*>::iterator iter = 
00165     std::find_if(m_states.begin(),m_states.end(),
00166                  TrackFunctor::HasKey<State>(&State::checkLocation,location));
00167   if (iter == m_states.end())
00168     throw GaudiException( "There is no state at requested location",
00169                           "Track.cpp",
00170                           StatusCode::FAILURE );
00171   return *(*iter);
00172 };
00173 
00174 //=============================================================================
00175 // Retrieve the (const) pointer to the state at a given location
00176 //=============================================================================
00177 const State& Track::stateAt( unsigned int location ) const
00178 {
00179   std::vector<State*>::const_iterator iter = 
00180     std::find_if(m_states.begin(),m_states.end(),
00181                  TrackFunctor::HasKey<State>(&State::checkLocation,location));
00182   if (iter == m_states.end())
00183     throw GaudiException( "There is no state at requested location",
00184                           "Track.cpp",
00185                           StatusCode::FAILURE );
00186   return *(*iter);
00187 };
00188 
00189 //=============================================================================
00190 // reset the track
00191 //=============================================================================
00192 void Track::reset() 
00193 {
00194 
00195   m_chi2PerDoF = 0;
00196   m_nDoF       = 0;
00197   m_flags      = 0;
00198   m_lhcbIDs.clear();
00199   for (std::vector<State*>::iterator it = m_states.begin();
00200        it != m_states.end(); it++) delete *it;
00201   for (std::vector<Measurement*>::iterator it2 = m_measurements.begin();
00202        it2 != m_measurements.end(); it2++) delete *it2;
00203   for (std::vector<Node*>::iterator it3 = m_nodes.begin();
00204        it3 != m_nodes.end(); it3++) delete *it3;
00205   m_states.clear();
00206   m_measurements.clear();
00207   m_nodes.clear();
00208   m_ancestors.clear();
00209 };
00210 
00211 //=============================================================================
00212 // Clone the track
00213 //=============================================================================
00214 Track* Track::clone() const
00215 {
00216   Track* tr = new Track();
00217   tr->setChi2PerDoF( chi2PerDoF() );
00218   tr->setNDoF( nDoF() );
00219   tr->setFlags( flags() );
00220   tr->setLhcbIDs( lhcbIDs() );
00221   for (std::vector<State*>::const_iterator it = m_states.begin();
00222        it != m_states.end(); it++) tr->addToStates( *(*it));
00223   for (std::vector<Measurement*>::const_iterator it2 = m_measurements.begin();
00224        it2 != m_measurements.end(); it2++) 
00225     tr->addToMeasurements( *(*it2) );
00226   for (std::vector<Node*>::const_iterator it3 = m_nodes.begin();
00227        it3 != m_nodes.end(); it3++) tr->addToNodes( (*it3)->clone() );
00228   for (SmartRefVector<Track>::const_iterator it4 = m_ancestors.begin();
00229        it4 != m_ancestors.end();  it4++) tr->addToAncestors(*(*it4));
00230   
00231   return tr;
00232 };
00233 
00234 //=============================================================================
00235 // Clone the track
00236 //=============================================================================
00237 
00238 void Track::addToStates(const State& state) 
00239 {
00240   State* local = state.clone();
00241   m_states.push_back(local);
00242   int order = checkFlag(TrackKeys::Backward) ? -1 : 1;
00243   std::vector<State*>::iterator i = 
00244     std::upper_bound(m_states.begin(),
00245                      m_states.end(),
00246                      local,  
00247                      TrackFunctor::orderByZ<State>(order));
00248   m_states.insert(i,local);    
00249 }
00250 
00251 //=============================================================================
00252 void Track::addToMeasurements(const Measurement& meas) 
00253 {
00254   const LHCbID& id = meas.lhcbID();
00255   if (std::find(m_lhcbIDs.begin(),m_lhcbIDs.end(),id) == m_lhcbIDs.end())
00256     addToLhcbIDs(id);
00257   Measurement* local = meas.clone();
00258   m_measurements.push_back(local);
00259   int order = checkFlag(TrackKeys::Backward) ? -1 : 1;
00260   std::vector<Measurement*>::iterator i = 
00261     std::upper_bound(m_measurements.begin(),
00262                      m_measurements.end(),
00263                      local,  
00264                      TrackFunctor::orderByZ<Measurement>(order));
00265   m_measurements.insert(i,local);
00266 }
00267 //=============================================================================
00268 
00269 void Track::removeFromMeasurements(Measurement* meas) 
00270 {
00271   const LHCbID& id = meas->lhcbID();
00272   removeFromLhcbIDs(id);
00273   TrackFunctor::deleteFromList<Measurement>(m_measurements,meas);
00274 }
00275 
00276 void Track::removeFromNodes(Node* node) 
00277 {
00278   TrackFunctor::deleteFromList<Node>(m_nodes,node);
00279 }
00280 
00281 void Track::removeFromStates(State* state) 
00282 {
00283   TrackFunctor::deleteFromList<State>(m_states,state);
00284 }

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