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

Generated on Thu May 12 12:28:05 2005 for New Track Event Model by doxygen 1.4.1