// MTrack_t.cpp // Test component MTrack. #include "MTrack.h" #include #include #include #include "trfutil/trfstream.h" #include "trfbase/SurfTest.h" #include "trfbase/HitTest.h" #include "trfbase/MissTest.h" using std::cout; using std::cerr; using std::endl; using std::string; using namespace trf; //********************************************************************** int main( ) { string component = "MTrack"; string ok_prefix = component + " (I): "; string error_prefix = component + " test (E): "; cout << ok_prefix << "-------- Testing component " + component + ". --------" << endl; // Make sure assert is enabled. bool assert_flag = false; assert ( ( assert_flag = true, assert_flag ) ); if ( ! assert_flag ) { cerr << "Assert is disabled" << endl; return 1; } //******************************************************************** cout << trf_format; cout << ok_prefix << "Test constructors" << endl; ETrack tre( SurfacePtr(new SurfTest(5)) ); MTrack trm1(tre); cout << trm1 << endl; //******************************************************************** cout << ok_prefix << "Generate hits." << endl; SurfTest srf1(10); ClusterPtr pclus = new ClusterTest(srf1,10); ETrack tre1( SurfacePtr(srf1.new_pure_surface()) ); const HitList hits = pclus->predict(tre1); assert( hits.size() == 10 ); //******************************************************************** cout << ok_prefix << "Add hits and misses." << endl; HitList::const_iterator ihit = hits.begin(); trm1.add_miss( MissTest(1.0,0.1) ); trm1.add_hit( *ihit++ ); trm1.add_hit( *ihit++ ); trm1.add_miss( MissTest(2.0,0.2) ); trm1.add_miss( MissTest(3.0,0.3) ); trm1.add_hit( *ihit++ ); trm1.add_miss( MissTest(4.0,0.4) ); cout << trm1 << endl; assert( trm1.get_hits().size() == 3 ); assert( trm1.get_misses().size() == 4 ); MTrack::HitMissList hitmisses = trm1.get_hits_and_misses(); assert( hitmisses.size() == 7 ); double like = trm1.get_miss_likelihood(); cout << "Total likelihood = " << like << endl; assert( like == 0.1*0.2*0.3*0.4 ); //******************************************************************** cout << ok_prefix << "Set fit." << endl; double chsq = 4.68; trm1.set_fit(tre1,chsq); cout << trm1 << endl; assert( trm1.is_fit() ); //******************************************************************** cout << ok_prefix << "Test copy constructor." << endl; MTrack trm2 = trm1; cout << trm2 << endl; assert( trm2.is_fit() ); assert( trm2.get_track() == trm1.get_track() ); assert( trm2.get_chi_square() == trm1.get_chi_square() ); assert( trm2.get_hits() == trm1.get_hits() ); assert( trm2.get_hits_and_misses() == trm1.get_hits_and_misses() ); //******************************************************************** cout << ok_prefix << "Test assignment." << endl; MTrack trm3(tre); trm3 = trm1; cout << trm3 << endl; assert( trm3.is_fit() ); assert( trm3.get_track() == trm1.get_track() ); assert( trm3.get_chi_square() == trm1.get_chi_square() ); assert( trm3.get_hits() == trm1.get_hits() ); assert( trm3.get_hits_and_misses() == trm1.get_hits_and_misses() ); //******************************************************************** cout << ok_prefix << "Test equality." << endl; assert( trm1 == trm3 ); assert( ! ( trm1 != trm3 ) ); //******************************************************************** cout << ok_prefix << "Drop all hits and misses." << endl;; { MTrack trm4(trm1); trm4.drop_hits(); cout << trm4 << endl; assert( trm4.get_hits().size() == 0 ); assert( trm4.get_misses().size() == 0 ); MTrack::HitMissList hitmisses = trm4.get_hits_and_misses(); assert( hitmisses.size() == 0 ); trm4.drop_hits(); assert( trm4.get_hits().size() == 0 ); assert( trm4.get_misses().size() == 0 ); } //******************************************************************** cout << ok_prefix << "Drop some hits and misses." << endl;; trm1.drop_hit(); trm1.drop_hit(); trm1.drop_miss(); trm1.drop_miss(); cout << trm1 << endl; assert( trm1.get_hits().size() == 1 ); assert( trm1.get_misses().size() == 2 ); hitmisses = trm1.get_hits_and_misses(); assert( hitmisses.size() == 3 ); like = trm1.get_miss_likelihood(); cout << "Total likelihood = " << like << endl; assert( like == 0.1*0.2 ); //******************************************************************** cout << ok_prefix << "Drop remaining hits and misses." << endl;; trm1.drop_miss(); trm1.drop_hit(); trm1.drop_miss(); cout << trm1 << endl; assert( trm1.get_hits().size() == 0 ); assert( trm1.get_misses().size() == 0 ); hitmisses = trm1.get_hits_and_misses(); assert( hitmisses.size() == 0 ); like = trm1.get_miss_likelihood(); cout << "Total likelihood = " << like << endl; assert( like == 1.0 ); //******************************************************************** cout << ok_prefix << "Test default constructor" << endl; MTrack trmd; cout << trmd << endl; //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }