// BSurfXYPlane_t.cpp // Test BSurfXYPlane. #include "BSurfXYPlane.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfbase/ETrack.h" #include "trfbase/CrossStat.h" #include "trfutil/TRFMath.h" #include "trfutil/trfstream.h" #ifndef DEFECT_NO_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 = "BSurfXYPlane test (I): "; string error_prefix = "BSurfXYPlane test (E): "; cout << ok_prefix << "------ Testing component BSurfXYPlane. ------" << 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; BSurfXYPlane bxyp( 10.0, PI/3., -20.0, 30.0, -120.0, 130.0 ); cout << bxyp << endl; assert( is_equal( bxyp.get_parameter(SurfXYPlane::DISTNORM), 10.0 ) ); assert( is_equal( bxyp.get_parameter(SurfXYPlane::NORMPHI), PI/3. ) ); assert( is_equal( bxyp.get_vmin(), -20.0 ) ); assert( is_equal( bxyp.get_vmax(), 30.0 ) ); assert( is_equal( bxyp.get_zmin(), -120.0 ) ); assert( is_equal( bxyp.get_zmax(), 130.0 ) ); //******************************************************************** cout << ok_prefix << "Equality tests varying parameters." << endl; BSurfXYPlane bxyp1( 10.0, PI/3., -20.0, 30.0, -120.0, 130.0 ); BSurfXYPlane bxyp2( 10.0, PI/3., 20.0, 30.0, -120.0, 130.0 ); BSurfXYPlane bxyp3( 10.0, PI/3., -20.0, 20.0, -120.0, 130.0 ); BSurfXYPlane bxyp4( 20.0, PI/3., -20.0, 30.0, -120.0, 130.0 ); BSurfXYPlane bxyp5( 10.0, PI/5., -20.0, 30.0, -120.0, 130.0 ); BSurfXYPlane bxyp6( 10.0, PI/3., -20.0, 30.0, 121.0, 130.0 ); BSurfXYPlane bxyp7( 10.0, PI/3., -20.0, 30.0, -120.0, 131.0 ); assert( bxyp.bound_equal(bxyp) ); assert( bxyp.bound_equal(bxyp1) ); assert( ! bxyp.bound_equal(bxyp2) ); assert( ! bxyp.bound_equal(bxyp3) ); assert( ! bxyp.bound_equal(bxyp4) ); assert( ! bxyp.bound_equal(bxyp5) ); assert( ! bxyp.bound_equal(bxyp6) ); assert( ! bxyp.bound_equal(bxyp7) ); //******************************************************************** cout << ok_prefix << "Equality tests using base class." << endl; SurfXYPlane sxyp(10.0, PI/3.); SurfXYPlane* psxyp = &bxyp; assert( bxyp.bound_equal(*psxyp) ); assert( psxyp->bound_equal(bxyp) ); assert( ! psxyp->bound_equal(bxyp2) ); assert( ! bxyp.bound_equal(sxyp) ); assert( bxyp.pure_equal(sxyp) ); assert( sxyp.pure_equal(bxyp) ); //******************************************************************** cout << ok_prefix << "Test type." << endl; assert( bxyp.get_type() != 0 ); assert( bxyp.get_type() != sxyp.get_type() ); assert( bxyp.get_type() == BSurfXYPlane::get_static_type() ); //******************************************************************** cout << ok_prefix << "Test purity." << endl; assert( ! bxyp.is_pure() ); assert( sxyp.is_pure() ); assert( ! psxyp->is_pure() ); //******************************************************************** cout << ok_prefix << "Test crossing status." << endl; cout << bxyp << endl; TrackVector tvec; TrackError terr; terr(SurfXYPlane::IV,SurfXYPlane::IV) = 4.0; terr(SurfXYPlane::IZ,SurfXYPlane::IZ) = 4.0; // Checking V component tvec(SurfXYPlane::IZ) = 0.0; // completely inside tvec(SurfXYPlane::IV) = 15.0; ETrack trk1(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk1 << endl; CrossStat xs = bxyp.status(trk1); cout << xs << endl; assert( xs.in_bounds() ); assert( !xs.out_of_bounds() ); // inside overlapping out tvec(SurfXYPlane::IV) = 25.0; ETrack trk2(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); xs = bxyp.status(trk2); cout << trk2 << endl; cout << xs << endl; assert( xs.in_bounds()); assert( xs.out_of_bounds()); // outside overlapping in tvec(SurfXYPlane::IV) = 35.0; ETrack trk3(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk3 << endl; xs = bxyp.status(trk3); cout << xs << endl; assert( xs.in_bounds()); assert( xs.out_of_bounds()); // way outside tvec(SurfXYPlane::IV) = 45.0; ETrack trk4(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk4 << endl; xs = bxyp.status(trk4); cout << xs << endl; assert( !xs.in_bounds()); assert( xs.out_of_bounds()); // inside overlapping out tvec(SurfXYPlane::IV) = -15.0; ETrack trk5(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk5 << endl; xs = bxyp.status(trk5); cout << xs << endl; assert( xs.in_bounds()); assert( xs.out_of_bounds()); // outside overlapping in tvec(SurfXYPlane::IV) = -25.0; ETrack trk6(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk6 << endl; xs = bxyp.status(trk6); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // way outside tvec(SurfXYPlane::IV) = -35.0; ETrack trk7(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk7 << endl; xs = bxyp.status(trk7); cout << xs << endl; assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); // Checking Z component tvec(SurfXYPlane::IV) = 0.0; // completely inside tvec(SurfXYPlane::IZ) = 115.0; ETrack trk11(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk11 << endl; xs = bxyp.status(trk11); cout << xs << endl; assert( xs.in_bounds()); assert( !xs.out_of_bounds()); // inside overlapping out tvec(SurfXYPlane::IZ) = 125.0; ETrack trk12(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); xs = bxyp.status(trk12); cout << trk12 << endl; cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds()); // outside overlapping in tvec(SurfXYPlane::IZ) = 135.0; ETrack trk13(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk13 << endl; xs = bxyp.status(trk13); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // way outside tvec(SurfXYPlane::IZ) = 145.0; ETrack trk14(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk14 << endl; xs = bxyp.status(trk14); cout << xs << endl; assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); // inside overlapping out tvec(SurfXYPlane::IZ) = -115.0; ETrack trk15(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk15 << endl; xs = bxyp.status(trk15); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // outside overlapping in tvec(SurfXYPlane::IZ) = -125.0; ETrack trk16(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk16 << endl; xs = bxyp.status(trk16); cout << xs << endl; assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); // way outside tvec(SurfXYPlane::IZ) = -135.0; ETrack trk17(SurfacePtr(bxyp.new_pure_surface()),tvec,terr); cout << trk17 << endl; xs = bxyp.status(trk17); cout << xs << endl; assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); //******************************************************************** cout << ok_prefix << "Check cloning." << endl; Surface* psrf = bxyp.new_surface(); assert( psrf->get_type() == BSurfXYPlane::get_static_type() ); delete psrf; //******************************************************************** ObjTable::register_type(); cout << ok_prefix << "Write object data." << endl; { ObjPtr pobj( new BSurfXYPlane(12.3,1.2,-2.,2.,-3.,4.) ); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("xyp1",pobj); cout << mystream.str() << endl; assert( ObjTable::has_object_name("xyp1") ); string::size_type pos = 0; assert( (pos=mystream.str().find( "xyp1 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "BSurfXYPlane ",pos)) != string::npos ); assert( (pos=mystream.str().find( "dist",pos)) != string::npos ); assert( (pos=mystream.str().find( "12.3 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "phi",pos)) != string::npos ); assert( (pos=mystream.str().find( "1.2 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "vmin",pos)) != string::npos ); assert( (pos=mystream.str().find( "-2. ",pos)) != string::npos ); assert( (pos=mystream.str().find( "vmax",pos)) != string::npos ); assert( (pos=mystream.str().find( "2. ",pos)) != string::npos ); assert( (pos=mystream.str().find( "zmin",pos)) != string::npos ); assert( (pos=mystream.str().find( "-3. ",pos)) != string::npos ); assert( (pos=mystream.str().find( "zmax",pos)) != string::npos ); assert( (pos=mystream.str().find( "4. ",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ xyp2 BSurfXYPlane dist=24.6 phi=1.3 vmin=-2. vmax=2. zmin=-3. zmax=4. ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "xyp2" ); const BSurfXYPlane* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == BSurfXYPlane::get_static_type() ); assert( pobj->get_parameter(SurfXYPlane::DISTNORM) == 24.6 ); assert( pobj->get_parameter(SurfXYPlane::NORMPHI) == 1.3 ); assert( pobj->get_vmin() == -2. ); assert( pobj->get_vmax() == 2. ); assert( pobj->get_zmin() == -3. ); assert( pobj->get_zmax() == 4. ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }