// GTrackState_t.cpp // Test GTrackState. #include "GTrackState.hpp" #include #include #include #include #include "trfbase/SurfTest.h" #include "d0cluster/ChunkClusterIndex.hpp" #include "trfbase/MissTest.h" #include "FitStatus.hpp" #ifndef DEFECT_NO_STDLIB_NAMESPACES using std::cout; using std::cerr; using std::endl; using std::string; #endif using edm::CollisionID; using edm::ChunkID; using edm::Event; using namespace trf; //********************************************************************** int main( ) { string component = "GTrackState"; 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 << ok_prefix << "Construct default state." << endl; { GTrackState state; cout << state << endl; assert( ! state.is_valid() ); assert( ! state.has_valid_fit() ); } //******************************************************************** cout << ok_prefix << "Construct a valid state." << endl; double s = 2.34; SurfacePtr psrf(new SurfTest(1.0)); TrackVector vec; vec(0) = 1.0; vec(1) = 1.1; vec(2) = 1.2; vec(3) = 1.3; vec(4) = 1.4; TrackError err; err(0,0) = 0.01; err(1,2) = 0.11; err(2,2) = 0.21; err(3,3) = 0.31; err(4,4) = 0.41; ETrack tre(psrf,vec,err); GTrackState::FitStatus stat = GTrackState::OPTIMAL; double chsq = 12.345; GTrackState state1(s,tre,stat,chsq); cout << state1 << endl; assert( state1.s() == s ); assert( state1.track() == tre ); assert( state1.fit_status() == stat ); assert( state1.chi_square() == chsq ); assert( ! state1.cluster().is_valid() ); assert( ! state1.miss() ); assert( ! state1.smoother() ); assert( state1.is_valid() ); assert( state1.has_valid_fit() ); //******************************************************************** cout << ok_prefix << "Check constructor from s." << endl; { GTrackState state2(s); cout << state2 << endl; assert( state2 != state1 ); assert( state2.s() == s ); assert( ! state2.track().is_valid() ); assert( state2.fit_status() == INVALID ); assert( ! state2.cluster().is_valid() ); assert( ! state2.miss() ); assert( ! state2.smoother() ); assert( state2.is_valid() ); assert( ! state2.has_valid_fit() ); } //******************************************************************** cout << ok_prefix << "Check constructor with cluster." << endl; { EventPtr pevt( new Event(CollisionID(123,45)) ); ChunkID chkid(78); D0ClusterIndex iclu(246); ChunkClusterIndex pclu(pevt,chkid,iclu); GTrackState state2(s,tre,stat,chsq,pclu); cout << state2 << endl; assert( state2 != state1 ); assert( state2.s() == s ); assert( state2.track() == tre ); assert( state1.fit_status() == stat ); assert( state2.chi_square() == chsq ); assert( state2.cluster() == pclu ); assert( ! state2.miss() ); assert( ! state2.smoother() ); assert( state2.is_valid() ); assert( state2.has_valid_fit() ); } //******************************************************************** cout << ok_prefix << "Check constructor with miss." << endl; { MissPtr pmiss(new MissTest(1.0,0.5)); GTrackState state2(s,tre,stat,chsq,pmiss); cout << state2 << endl; assert( state2 != state1 ); assert( state2.s() == s ); assert( state2.track() == tre ); assert( state1.fit_status() == stat ); assert( state2.chi_square() == chsq ); assert( ! state2.cluster().is_valid() ); assert( state2.miss() != 0 ); assert( state2.miss() == pmiss ); assert( ! state2.smoother() ); assert( state2.is_valid() ); assert( state2.has_valid_fit() ); } //******************************************************************** cout << ok_prefix << "Check equality." << endl; { GTrackState state2(s,tre,stat,chsq); cout << state2 << endl; assert( state2 == state1 ); } { GTrackState state2(s+1.0,tre,stat,chsq); cout << state2 << endl; assert( ! (state2 == state1) ); } //******************************************************************** cout << ok_prefix << "Check fit drop." << endl; { GTrackState state2(s,tre,stat,chsq); cout << state2 << endl; assert( state2.has_valid_fit() ); state2.drop_fit(); assert( ! state2.has_valid_fit() ); assert( ! (state2 == state1) ); } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }