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::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
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 }