// Propagator_t.cpp #include "Propagator.h" #include #include #include "PropStat.h" #include "VTrack.h" #include "ETrack.h" #include "TrackVector.h" #include "SurfTest.h" using std::cout; using std::cerr; using std::endl; using std::string; using trf::TrackVector; using trf::TrackError; using trf::TrackDerivative; using trf::Surface; using trf::SurfacePtr; using trf::VTrack; using trf::ETrack; using trf::PropStat; using trf::Propagator; //********************************************************************** ObjPtr create(const ObjData& data); // Test concrete class. class TestProp : public Propagator { public: // static methods // Return the type name. static TypeName get_type_name() { return "TestProp"; } // Return the creator. static ObjCreator get_creator() { return create; } // Return the type. static Type get_static_type() { return get_creator(); } private: void ostr(ostream& stream) const { stream << "Test propagator"; } PropStat myprop(VTrack& trv, const Surface& srf, PropDir dir) const { SurfacePtr psrf( srf.new_pure_surface() ); trv.set_surface(psrf); PropStat pst; TrackVector vec = trv.get_vector(); if ( dir == BACKWARD ) { vec(1) -= 1.0; pst.set_forward(); } else { vec(1) += 1.0; pst.set_backward(); } trv.set_vector(vec); return pst; }; public: Type get_type() const { return get_static_type(); } ObjData write_data() const { return ObjData("TestProp"); } Propagator* new_propagator() const { return new TestProp; }; PropStat vec_prop(VTrack& trv, const Surface& srf, TrackDerivative* pder =0) const { return myprop(trv,srf,NEAREST); } PropStat vec_dir_prop(VTrack& trv, const Surface& srf, PropDir dir, TrackDerivative* pder =0) const { return myprop(trv,srf,dir); } PropStat err_prop(ETrack& trv, const Surface& srf, TrackDerivative* pder =0) const { return myprop(trv,srf,NEAREST); } PropStat err_dir_prop(ETrack& trv, const Surface& srf, PropDir dir, TrackDerivative* pder =0) const { return myprop(trv,srf,dir); } }; ObjPtr create(const ObjData& data) { assert( data.get_object_type() == "TestProp" ); if ( data.get_object_type() != "TestProp" ) return ObjPtr(0); return ObjPtr( new TestProp ); } //********************************************************************** int main( ) { string ok_prefix = "Propagator test (I): "; string error_prefix = "Propagator test (E): "; cout << ok_prefix << "------- Testing component Propagator. -------" << 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 << "Test constructor." << endl; ObjTable::register_type(); TestProp tprop; cout << tprop << endl; //******************************************************************** cout << ok_prefix << "Test default VTrack propagation." << endl; SurfacePtr ptsrf1( new SurfTest(1) ); SurfacePtr ptsrf2( new SurfTest(2) ); VTrack trv1(ptsrf1); VTrack trv2 = trv1; assert( *trv2.get_surface() == *ptsrf1 ); assert( *trv2.get_surface() != *ptsrf2 ); assert( trv2.get_vector() == trv1.get_vector() ); cout << trv2 << endl; tprop.vec_prop(trv2,*ptsrf2); cout << trv2 << endl; assert( *trv2.get_surface() == *ptsrf2 ); assert( trv2.get_vector()(1) > trv1.get_vector()(1) ); //******************************************************************** cout << ok_prefix << "Test backward VTrack propagation." << endl; SurfacePtr ptsrf3( new SurfTest(3) ); VTrack trv3 = trv2; cout << trv3 << endl; tprop.vec_dir_prop(trv3,*ptsrf3,Propagator::BACKWARD); cout << trv3 << endl; assert( *trv3.get_surface() == *ptsrf3 ); assert( trv3.get_vector()(1) < trv2.get_vector()(1) ); //******************************************************************** cout << ok_prefix << "Test default ETrack propagation." << endl; ETrack tre1(ptsrf1); TrackError err; err(0,0) = 0.01; err(1,1) = 0.02; err(2,2) = 0.03; err(3,3) = 0.04; err(4,4) = 0.05; tre1.set_error(err); ETrack tre2 = tre1; tre2.set_error(err); assert( *tre2.get_surface() == *ptsrf1 ); assert( *tre2.get_surface() != *ptsrf2 ); assert( tre2.get_vector() == tre1.get_vector() ); cout << tre2 << endl; tprop.err_prop(tre2,*ptsrf2); cout << tre2 << endl; assert( *tre2.get_surface() == *ptsrf2 ); assert( tre2.get_vector()(1) > tre1.get_vector()(1) ); //******************************************************************** cout << ok_prefix << "Test backward ETrack propagation." << endl; ETrack tre3 = tre2; cout << tre3 << endl; tprop.err_dir_prop(tre3,*ptsrf3,Propagator::BACKWARD); cout << tre3 << endl; assert( *tre3.get_surface() == *ptsrf3 ); assert( tre3.get_vector()(1) < tre2.get_vector()(1) ); //******************************************************************** cout << ok_prefix << "Test direction reduction." << endl; bool stat; Propagator::PropDir dir = Propagator::FORWARD_MOVE; assert( Propagator::reduce_direction(dir) ); assert( dir == Propagator::FORWARD ); assert( ! Propagator::reduce_direction(dir) ); assert( dir == Propagator::FORWARD ); dir = Propagator::BACKWARD_MOVE; assert( Propagator::reduce_direction(dir) ); assert( dir == Propagator::BACKWARD ); assert( ! Propagator::reduce_direction(dir) ); assert( dir == Propagator::BACKWARD ); dir = Propagator::NEAREST_MOVE; assert( Propagator::reduce_direction(dir) ); assert( dir == Propagator::NEAREST ); assert( ! Propagator::reduce_direction(dir) ); assert( dir == Propagator::NEAREST ); //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }