// HTrack_t.cpp // Test component HTrack. #include "HTrack.h" #include #include #include #include "trfutil/trfstream.h" #include "trfbase/SurfTest.h" #include "trfbase/HitTest.h" using std::cout; using std::cerr; using std::endl; using std::string; using namespace trf; //********************************************************************** int main( ) { string component = "HTrack"; 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)) ); HTrack trh1(tre); cout << trh1 << endl; //******************************************************************** cout << ok_prefix << "Test status" << endl; // Track with good fit and no hits is fit. assert( trh1.is_fit() ); assert( trh1.get_hits().size() == 0 ); trh1.unset_fit(); assert( ! trh1.is_fit() ); assert( ! trh1.is_fit() ); trh1.set_fit(tre,0.0); assert( trh1.is_fit() ); assert( trh1.is_fit() ); trh1.unset_fit(); assert( ! trh1.is_fit() ); //******************************************************************** cout << ok_prefix << "Add hits." << endl; SurfTest srf1(10); ClusterPtr pclu(new ClusterTest(srf1,10)); ETrack tre1( SurfacePtr(srf1.new_pure_surface()) ); const HitList hits = pclu->predict(tre1); assert( hits.size() == 10 ); // ihit iterates over input hits HitList::const_iterator ihit = hits.begin(); // 0 trh1.set_fit(tre,0.0); trh1.add_hit( *ihit ); assert( ! trh1.is_fit() ); ++ihit; // 1 trh1.add_hit( *ihit ); trh1.set_fit(tre,0.0); assert( trh1.is_fit() ); assert( trh1.is_fit() ); trh1.unset_fit(); assert( ! trh1.is_fit() ); assert( ! trh1.is_fit() ); ++ihit; // 2 trh1.add_hit( *ihit ); cout << trh1 << endl; // jhit iterates over output hits assert( trh1.get_hits().size() == 3 ); HitList::const_iterator jhit; ihit = hits.begin(); jhit = trh1.get_hits().begin(); assert( **ihit == **jhit ); ++ihit; // 1 ++jhit; assert( **ihit == **jhit ); ++ihit; // 2 ++jhit; assert( **ihit == **jhit ); assert( trh1.get_hits().size() == 3 ); //******************************************************************** cout << ok_prefix << "Drop a hits" << endl;; trh1.set_fit(tre,0.0); HitList::iterator khit; ihit = hits.begin(); trh1.drop_hit(); assert( trh1.get_hits().size() == 2 ); assert( ! trh1.is_fit() ); jhit = trh1.get_hits().begin(); assert( **ihit == **jhit ); ++ihit; // 1 ++jhit; assert( **ihit == **jhit ); //******************************************************************** cout << ok_prefix << "Set track and chi-square." << endl; TrackVector vec; int i,j; for ( i=0; i<5; ++i ) vec(i) = 1.1*double(i); TrackError err; for ( i=0; i<5; ++i ) { for ( j=0; j<=i; ++j ) { double fac; if ( i == j ) fac = 0.1; else fac = 0.01; err(i,j) = ( double(i) + 0.1*double(j) ) * fac; } } ETrack tre2( SurfacePtr(srf1.new_pure_surface()), vec, err ); double chisq = 12.345; trh1.set_fit(tre2,chisq); cout << trh1 << endl; assert( trh1.is_fit() ); assert( trh1.get_track() == tre2 ); assert( trh1.is_fit() ); assert( trh1.get_chi_square() == chisq ); assert( trh1.is_fit() ); //******************************************************************** cout << ok_prefix << "Test copy constructor." << endl; HTrack trh2 = trh1; cout << trh2 << endl; assert( trh2.is_fit() ); assert( trh2.get_track() == trh1.get_track() ); assert( trh2.get_chi_square() == trh1.get_chi_square() ); assert( trh2.get_hits() == trh1.get_hits() ); //******************************************************************** cout << ok_prefix << "Test assignment." << endl; HTrack trh3(tre); trh3 = trh1; cout << trh3 << endl; assert( trh3.is_fit() ); assert( trh3.get_track() == trh1.get_track() ); assert( trh3.get_chi_square() == trh1.get_chi_square() ); assert( trh3.get_hits() == trh1.get_hits() ); //******************************************************************** cout << ok_prefix << "Check equality." << endl; assert( trh1 == trh3 ); assert( ! (trh1 != trh3) ); //******************************************************************** cout << ok_prefix << "Check Number of measurements." << endl; cout << trh1.get_num_meas() << endl; assert( trh1.get_num_meas()==4 ); //******************************************************************** // HitTest does not set mcids currently. cout << ok_prefix << "Check TrackMcHitInfo" << endl; cout << trh1.get_mcinfo().best_mcid() << endl; assert( trh1.get_mcinfo().best_mcid()==0 ); //******************************************************************** cout << ok_prefix << "Drop all hits." << endl; assert( trh3.is_fit() ); assert( trh3.get_hits().size() == 2 ); trh3.drop_hits(); assert( trh3.get_hits().size() == 0 ); assert( ! trh3.is_fit() ); trh3.drop_hits(); assert( trh3.get_hits().size() == 0 ); assert( ! trh3.is_fit() ); trh3.drop_hit(); assert( trh3.get_hits().size() == 0 ); assert( ! trh3.is_fit() ); //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }