00001
00002
00003
00004 #include "Event/Track.h"
00005 #include "Event/TrackKeys.h"
00006 #include "Event/TrackFunctor.h"
00007 #include <functional>
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00029
00030 void Track::positionAndMomentum( HepPoint3D &pos,
00031 HepVector3D &mom ) const
00032 {
00033 firstState().positionAndMomentum( pos, mom );
00034 };
00035
00036
00037
00038
00039 void Track::position( HepPoint3D &pos,
00040 HepSymMatrix &errPos ) const
00041 {
00042 pos = firstState().position();
00043 errPos = firstState().errPosition();
00044 };
00045
00046
00047
00048
00049 void Track::slopes( HepVector3D &slopes,
00050 HepSymMatrix &errSlopes ) const
00051 {
00052 slopes = firstState().slopes();
00053 errSlopes = firstState().errSlopes();
00054 };
00055
00056
00057
00058
00059 double Track::p() const
00060 {
00061 return firstState().p();
00062 };
00063
00064
00065
00066
00067 double Track::pt() const
00068 {
00069 return firstState().pt();
00070 };
00071
00072
00073
00074
00075 void Track::momentum( HepVector3D &mom,
00076 HepSymMatrix &errMom ) const
00077 {
00078 mom = firstState().momentum();
00079 errMom = firstState().errMomentum();
00080 };
00081
00082
00083
00084
00085 void Track::posMomCovariance( HepSymMatrix &cov6D ) const
00086 {
00087 cov6D = firstState().posMomCovariance();
00088 };
00089
00090
00091
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
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
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
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
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
00155
00156 return (iter != m_states.end());
00157 };
00158
00159
00160
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
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
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
00213
00214 Track* Track::cloneWithKey( ) const
00215 {
00216 int theKey = this -> key();
00217 Track* tr = new Track( theKey );
00218 tr->setChi2PerDoF( chi2PerDoF() );
00219 tr->setNDoF( nDoF() );
00220 tr->setFlags( flags() );
00221 tr->setLhcbIDs( lhcbIDs() );
00222 for (std::vector<State*>::const_iterator it = m_states.begin();
00223 it != m_states.end(); it++) tr->addToStates( *(*it));
00224 for (std::vector<Measurement*>::const_iterator it2 = m_measurements.begin();
00225 it2 != m_measurements.end(); it2++)
00226 tr->addToMeasurements( *(*it2) );
00227 for (std::vector<Node*>::const_iterator it3 = m_nodes.begin();
00228 it3 != m_nodes.end(); it3++) tr->addToNodes( (*it3)->clone() );
00229 for (SmartRefVector<Track>::const_iterator it4 = m_ancestors.begin();
00230 it4 != m_ancestors.end(); it4++) tr->addToAncestors(*(*it4));
00231
00232 return tr;
00233 };
00234
00235
00236
00237
00238 Track* Track::clone() const
00239 {
00240 Track* tr = new Track();
00241 tr->setChi2PerDoF( chi2PerDoF() );
00242 tr->setNDoF( nDoF() );
00243 tr->setFlags( flags() );
00244 tr->setLhcbIDs( lhcbIDs() );
00245 for (std::vector<State*>::const_iterator it = m_states.begin();
00246 it != m_states.end(); it++) tr->addToStates( *(*it));
00247 for (std::vector<Measurement*>::const_iterator it2 = m_measurements.begin();
00248 it2 != m_measurements.end(); it2++)
00249 tr->addToMeasurements( *(*it2) );
00250 for (std::vector<Node*>::const_iterator it3 = m_nodes.begin();
00251 it3 != m_nodes.end(); it3++) tr->addToNodes( (*it3)->clone() );
00252 for (SmartRefVector<Track>::const_iterator it4 = m_ancestors.begin();
00253 it4 != m_ancestors.end(); it4++) tr->addToAncestors(*(*it4));
00254
00255 return tr;
00256 };
00257
00258
00259
00260
00261 void Track::addToStates(const State& state)
00262 {
00263 State* local = state.clone();
00264 int order = checkFlag(TrackKeys::Backward) ? -1 : 1;
00265 std::vector<State*>::iterator i =
00266 std::upper_bound(m_states.begin(),
00267 m_states.end(),
00268 local,
00269 TrackFunctor::orderByZ<State>(order));
00270 m_states.insert(i,local);
00271 }
00272
00273
00274 void Track::addToMeasurements(const Measurement& meas)
00275 {
00276 const LHCbID& id = meas.lhcbID();
00277 if (std::find(m_lhcbIDs.begin(),m_lhcbIDs.end(),id) == m_lhcbIDs.end())
00278 addToLhcbIDs(id);
00279 Measurement* local = meas.clone();
00280 int order = checkFlag(TrackKeys::Backward) ? -1 : 1;
00281 std::vector<Measurement*>::iterator i =
00282 std::upper_bound(m_measurements.begin(),
00283 m_measurements.end(),
00284 local,
00285 TrackFunctor::orderByZ<Measurement>(order));
00286 m_measurements.insert(i,local);
00287 }
00288
00289
00290 void Track::removeFromMeasurements(Measurement* meas)
00291 {
00292 const LHCbID& id = meas->lhcbID();
00293 removeFromLhcbIDs(id);
00294 TrackFunctor::deleteFromList<Measurement>(m_measurements,meas);
00295 }
00296
00297 void Track::removeFromNodes(Node* node)
00298 {
00299 TrackFunctor::deleteFromList<Node>(m_nodes,node);
00300 }
00301
00302 void Track::removeFromStates(State* state)
00303 {
00304 TrackFunctor::deleteFromList<State>(m_states,state);
00305 }