// FilterContains.cpp #include "FilterContains.h" #include "objstream/ObjData.hpp" #include "objstream/ObjTable.hpp" #include #include "trfutil/trfstream.h" #include "trffit/MTrack.h" using std::ostream; using trf::HitList; using trf::FilterContains; //********************************************************************** // Free functions. //********************************************************************** namespace { // Creator. ObjPtr create(const ObjData& data) { assert( data.get_object_type() == "FilterContains" ); return ObjPtr( new FilterContains ); } } //********************************************************************** // Helpers //********************************************************************** // Return true if the first list of hits is a subset of the second. // Two hits are considered the same if the have the same parent // cluster. bool check_contained(const HitList& hits_i, const HitList& hits_j) { assert( hits_i.size() < hits_j.size() ); HitList::const_iterator ihit; HitList::const_iterator jhit = hits_j.begin(); // Loop over the list with fewer hits. for ( ihit=hits_i.begin(); ihit!=hits_i.end(); ++ihit ) { // Search for a match in the other list. if ( jhit == hits_j.end() ) return false; while ( (*jhit)->get_cluster() != (*ihit)->get_cluster() ) if ( ++jhit == hits_j.end() ) return false; ++jhit; } return true; } //********************************************************************** // Member functions. //********************************************************************** // output stream void FilterContains::ostr(ostream& stream) const { stream << begin_object; stream << "Filter tracks contined in other tracks."; stream << end_object; } //********************************************************************** // constructor FilterContains::FilterContains() { } //********************************************************************** // Return the creator. ObjCreator FilterContains::get_creator() { return create; } //********************************************************************** // Write the object data. ObjData FilterContains::write_data() const { return ObjData( get_type_name() ); } //********************************************************************** // Process tracks. FilterContains::FlagArray FilterContains::process(MTrackArray& trms) const { // Create the output array initialized to accept all. // KCC will not compile with 2-arg constructor. Obscure errors. int size = trms.size(); #ifdef __KCC FlagArray flags(size); for (int k=0; kget_hits(); // Skip this track if it has already been rejected. if ( ! flags[i] ) continue; // Loop over all indices corresponding to larger chi-square. for ( int j=i+1; jget_hits(); // Skip this track if it has already been rejected. if ( ! flags[j] ) continue; // Reject one list if it is contained in the other. // Take no action if lists are identical. if ( ihits.size() < jhits.size() ) { if ( check_contained( ihits, jhits ) ) flags[i] = false; } else if ( jhits.size() < ihits.size() ) { if ( check_contained( jhits, ihits ) ) flags[j] = false; } } // end loop over second index. } // end loop over first index. return flags; } //**********************************************************************