// GTrack.cpp // This is here to fix a mysterious dependency problem. #include "trfbase/Surface.h" #include "GTrack.hpp" #include #include #include "trfutil/STLprint.h" #include "FitStatus.hpp" #include "trfbase/Hit.h" #include "trfbase/ClusterPtr.h" #include "d0cluster_evt/ChunkClusterPtr.hpp" #ifdef GTrack_holds_chunk_id using edm::ChunkID; using edm::LinkIndex; #endif using std::ostream; using std::endl; using std::equal; using namespace trf; //********************************************************************** // Local constants, typedefs, fucntions and classes. //********************************************************************** namespace { //********************************************************************** // Invalid GTrackState for error return. const GTrackState BAD_STATE; //********************************************************************** // Order two doubles. void order(double& x1, double& x2) { if ( x1 > x2 ) { double tmp = x1; x1 = x2; x2 = tmp; } } //********************************************************************** } // end unnamed namespace //********************************************************************** // Static variables. //********************************************************************** const double GTrack::SMIN = -1.e30; const double GTrack::SMAX = 1.e30; //********************************************************************** // Member functions. //********************************************************************** // Default constructor. GTrack::GTrack() : _valid(false) { } //********************************************************************** // Constructor from a list of states. GTrack::GTrack(const StateList& states) : _valid(true), _states(states) { // Check below assumes list has at least one entry. assert( get_states().size() ); if ( ! get_states().size() ) _valid = false; // Check that the s-values are in range. assert( get_states().begin()->s() >= SMIN ); StateList::const_iterator ilast = --get_states().end(); assert( ilast->s() <= SMAX ); if ( get_states().begin()->s() < SMIN ) _valid = false; if ( ilast->s() > SMAX ) _valid = false; // Check that all states are valid and have valid fits. GTrack::StateList::const_iterator ista; for ( ista=get_states().begin(); ista!=get_states().end(); ++ista ) { FitStatus fstat = ista->fit_status(); assert( fstat != BADSTATE ); if ( fstat == BADSTATE ) _valid = false; } } //********************************************************************** // Destructor. GTrack::~GTrack() { } //********************************************************************** // Drop the fit for a specified state. int GTrack::drop_fit(double s) { GTrack::StateList::iterator ista = _states.find(GTrackState(s)); if ( ista == _states.end() ) return 1; ista->drop_fit(); return 0; } //********************************************************************** // Return a state at an s. // Return an invalid state is there is no state at that s. const GTrackState& GTrack::get_state(double s) const { GTrack::StateList::const_iterator ista = get_states().find( GTrackState(s) ); if ( ista == get_states().end() ) return BAD_STATE; return *ista; } //********************************************************************** // Return a state at a surface in a specified s-range. // Return an invalid state is there is no such state in that range. const GTrackState& GTrack::get_state(const SurfacePtr& psrf, double s1, double s2) const { order(s1,s2); StateList::const_iterator ista1 = get_states().lower_bound( GTrackState(s1) ); StateList::const_iterator ista2 = get_states().upper_bound( GTrackState(s2) ); StateList::const_iterator ista; for ( ista=ista1; ista!=ista2; ++ista ) { const GTrackState& state = *ista; if ( state.track().get_surface()->pure_equal(*psrf) ) return state; } return BAD_STATE; } // Return the number of measurements in the fit for this track int GTrack::get_num_measurements() const { StateList::const_iterator ista; int nmeas = 0; for ( ista=get_states().begin(); ista!=get_states().end(); ++ista ) { const GTrackState& state = *ista; const ChunkClusterIndex& cclui = state.cluster(); ChunkClusterPtr ppclu(cclui); ClusterPtr pclu( ppclu->new_trf_cluster() ); HitList hits( pclu->predict( state.track()) ); nmeas += (hits.front())->size(); } return nmeas; } #ifdef GTrack_holds_chunk_id //********************************************************************** // Set the chunk and object ID's. void GTrack::set_ids(ChunkID cid, unsigned int oid) { _cid = cid; _oid = oid; } //********************************************************************** // Retrieve the link index. LinkIndex GTrack::index() const { return LinkIndex(this, _cid, _oid); } #endif //********************************************************************** // Free functions. //********************************************************************** // Output stream. ostream& operator<<(ostream& stream, const GTrack& rhs) { print_list("State", rhs.get_states(), stream ); return stream; } //********************************************************************** // Equality. bool operator==(const GTrack& lhs, const GTrack& rhs) { return equal( lhs.get_states().begin(), lhs.get_states().end(), rhs.get_states().begin() ); } //********************************************************************** // Inequality. bool operator!=(const GTrack& lhs, const GTrack& rhs) { return ( ! (lhs==rhs) ); } //**********************************************************************