00001
00002
00003
00004 #include "Event/Track.h"
00005 #include "Event/TrackKeys.h"
00006 #include "Event/TrackFunctor.h"
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
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
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
00065
00066 double Track::p() const
00067 {
00068 return physicsState().p();
00069 };
00070
00071
00072
00073
00074 double Track::pt() const
00075 {
00076 return physicsState().pt();
00077 };
00078
00079
00080
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
00093
00094 StatusCode Track::posMomCovariance( HepSymMatrix &cov6D ) const
00095 {
00096 cov6D = physicsState().posMomCovariance();
00097
00098 return StatusCode::SUCCESS;
00099 };
00100
00101
00102
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
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
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
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
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
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
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
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
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
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