// BSurfZPlane_t.cc // Test BSurfZPlane. #include "BSurfZPlane.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "trfutil/TRFMath.h" #include "trfbase/ETrack.h" #include "trfbase/CrossStat.h" #ifndef DEFECT_NO_STDLIB_NAMESPACES using std::cout; using std::cerr; using std::endl; using std::string; using std::ostringstream; using std::istringstream; #endif using namespace trf; //********************************************************************** int main( ) { string ok_prefix = "BSurfZPlane test (I): "; string error_prefix = "BSurfZPlane test (E): "; cout << ok_prefix << "------ Testing component BSurfZPlane. ------" << 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 constructor and get routines." << endl; BSurfZPlane bzp( 10.0, -20.0, 30.0, -120.0, 130.0 ); cout << bzp << endl; assert( is_equal( bzp.get_z(), 10.0 ) ); assert( is_equal( bzp.get_xmin(), -20.0 ) ); assert( is_equal( bzp.get_xmax(), 30.0 ) ); assert( is_equal( bzp.get_ymin(), -120.0 ) ); assert( is_equal( bzp.get_ymax(), 130.0 ) ); //******************************************************************** cout << ok_prefix << "Test type." << endl; assert( bzp.get_type() != 0 ); assert( bzp.get_type() == BSurfZPlane::get_static_type() ); //******************************************************************** cout << ok_prefix << "Check cloning." << endl; SurfacePtr psrf ( bzp.new_surface()); SurfacePtr psrf_pure(bzp.new_pure_surface()); assert( psrf->get_type() == BSurfZPlane::get_static_type() ); assert( psrf_pure->get_type() == SurfZPlane::get_static_type() ); //******************************************************************** cout << ok_prefix << "Equality tests varying parameters." << endl; SurfacePtr psrf1 ( new BSurfZPlane( 10.0, -20.0, 30.0, -120.0, 130.0 )); SurfacePtr psrf2 ( new BSurfZPlane( 10.0, 20.0, 30.0, -120.0, 130.0 )); SurfacePtr psrf3 ( new BSurfZPlane( 10.0, -20.0, 20.0, -120.0, 130.0 )); SurfacePtr psrf4 ( new BSurfZPlane( 20.0, -20.0, 30.0, -120.0, 130.0 )); SurfacePtr psrf5 ( new BSurfZPlane( 10.0, -20.0, 30.0, 121.0, 130.0 )); SurfacePtr psrf6 ( new BSurfZPlane( 10.0, -20.0, 30.0, -120.0, 131.0 )); assert( psrf->bound_equal(*psrf) ); assert( psrf->bound_equal(*psrf1) ); assert( ! psrf->bound_equal(*psrf2) ); assert( ! psrf->bound_equal(*psrf3) ); assert( ! psrf->bound_equal(*psrf4) ); assert( ! psrf->bound_equal(*psrf5) ); assert( ! psrf->bound_equal(*psrf6) ); //******************************************************************** cout << ok_prefix << "Test purity." << endl; assert( ! bzp.is_pure() ); assert( psrf_pure->is_pure() ); //******************************************************************** cout << ok_prefix << "Test crossing status." << endl; cout << bzp << endl; TrackVector tvec; TrackError terr; terr(SurfZPlane::IX,SurfZPlane::IX) = 4.0; terr(SurfZPlane::IY,SurfZPlane::IY) = 4.0; // Checking X component tvec(SurfZPlane::IY) = 0.0; // completely inside tvec(SurfZPlane::IX) = 15.0; ETrack trk1(psrf,tvec,terr); cout << trk1 << endl; CrossStat xs = psrf->status(trk1); cout << xs << endl; assert( xs.in_bounds() ); assert( !xs.out_of_bounds() ); // inside overlapping out tvec(SurfZPlane::IX) = 25.0; ETrack trk2(psrf,tvec,terr); xs = psrf->status(trk2); cout << trk2 << endl; cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // outside overlapping in tvec(SurfZPlane::IX) = 35.0; ETrack trk3(psrf,tvec,terr); cout << trk3 << endl; xs = psrf->status(trk3); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // way outside tvec(SurfZPlane::IX) = 45.0; ETrack trk4(psrf,tvec,terr); cout << trk4 << endl; xs = psrf->status(trk4); cout << xs << endl; assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); // inside overlapping out tvec(SurfZPlane::IX) = -15.0; ETrack trk5(psrf,tvec,terr); cout << trk5 << endl; xs = psrf->status(trk5); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // outside overlapping in tvec(SurfZPlane::IX) = -25.0; ETrack trk6(psrf,tvec,terr); cout << trk6 << endl; xs = psrf->status(trk6); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // way outside tvec(SurfZPlane::IX) = -35.0; ETrack trk7(psrf,tvec,terr); cout << trk7 << endl; xs = psrf->status(trk7); cout << xs << endl; assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); // Checking Y component tvec(SurfZPlane::IX) = 0.0; // completely inside tvec(SurfZPlane::IY) = 115.0; ETrack trk11(psrf,tvec,terr); cout << trk11 << endl; xs = psrf->status(trk11); cout << xs << endl; assert( xs.in_bounds() ); assert( !xs.out_of_bounds() ); // inside overlapping out tvec(SurfZPlane::IY) = 125.0; ETrack trk12(psrf,tvec,terr); xs = psrf->status(trk12); cout << trk12 << endl; cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // outside overlapping in tvec(SurfZPlane::IY) = 135.0; ETrack trk13(psrf,tvec,terr); cout << trk13 << endl; xs = psrf->status(trk13); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // way outside tvec(SurfZPlane::IY) = 145.0; ETrack trk14(psrf,tvec,terr); cout << trk14 << endl; xs = psrf->status(trk14); cout << xs << endl; assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); // inside overlapping out tvec(SurfZPlane::IY) = -115.0; ETrack trk15(psrf,tvec,terr); cout << trk15 << endl; xs = psrf->status(trk15); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // outside overlapping in tvec(SurfZPlane::IY) = -125.0; ETrack trk16(psrf,tvec,terr); cout << trk16 << endl; xs = psrf->status(trk16); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // way outside tvec(SurfZPlane::IY) = -135.0; ETrack trk17(psrf,tvec,terr); cout << trk17 << endl; xs = psrf->status(trk17); cout << xs << endl; assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); //******************************************************************** ObjTable::register_type(); cout << ok_prefix << "Write object data." << endl; { ObjPtr pobj( new BSurfZPlane(12.3,-2.,2.,-3.,4.) ); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("zp1",pobj); cout << mystream.str() << endl; assert( ObjTable::has_object_name("zp1") ); string::size_type pos = 0; assert( (pos=mystream.str().find( "zp1 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "BSurfZPlane ",pos)) != string::npos ); assert( (pos=mystream.str().find( "z",pos)) != string::npos ); assert( (pos=mystream.str().find( "12.3 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "xmin",pos)) != string::npos ); assert( (pos=mystream.str().find( "-2. ",pos)) != string::npos ); assert( (pos=mystream.str().find( "xmax",pos)) != string::npos ); assert( (pos=mystream.str().find( "2. ",pos)) != string::npos ); assert( (pos=mystream.str().find( "ymin",pos)) != string::npos ); assert( (pos=mystream.str().find( "-3. ",pos)) != string::npos ); assert( (pos=mystream.str().find( "ymax",pos)) != string::npos ); assert( (pos=mystream.str().find( "4. ",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ zp2 BSurfZPlane z=24.6 xmin=-2. xmax=2. ymin=-3. ymax=4. ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "zp2" ); const BSurfZPlane* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == BSurfZPlane::get_static_type() ); assert( pobj->get_z() == 24.6 ); assert( pobj->get_xmin() == -2. ); assert( pobj->get_xmax() == 2. ); assert( pobj->get_ymin() == -3. ); assert( pobj->get_ymax() == 4. ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }