// ThinCylMS_t.cpp #include "ThinCylMS.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfbase/SurfacePtr.h" #include "trfbase/ETrack.h" #include "SurfCylinder.h" using std::cout; using std::cerr; using std::endl; using std::string; using std::ostringstream; using std::istringstream; using namespace trf; //********************************************************************** int main( ) { string component = "ThinCylMS"; 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; } //******************************************************************** ObjTable::register_type(); ThinCylMS scatterIt(1.0); TrackError initialError; initialError(2,2) = 0.0; initialError(3,3) = 0.0; initialError(4,4) = 0.0; initialError(4,3) = 0.0; initialError(3,4) = 0.0; TrackVector trv; trv(0) = 1.0; trv(1) = 1.0; trv(2) = 1.0; trv(3) = 1.0; trv(4) = 1.0; SurfacePtr srf(new SurfCylinder( 20.0 )); ETrack tmpTrack( srf, trv, initialError ); tmpTrack.set_error( initialError ); scatterIt.interact( tmpTrack ); const TrackError& finalError = tmpTrack.get_error(); double trueLength = 1.0/cos(1.0)*sqrt(1.0 + 1.0); double thetaSqr = (0.0136)*(1.0/cos(atan(1.0)))*sqrt(trueLength)* (1 + 0.038*log(trueLength)); thetaSqr *= thetaSqr; double alfalf = (1.0 + 1.0); double tlamtlam = (alfalf*alfalf); double cc = (1.0); double ctlam = ((1.0)*(1.0 + 1.0)); double tlamc = (ctlam); alfalf *= thetaSqr; tlamtlam *= thetaSqr; cc *= thetaSqr; ctlam *= thetaSqr; tlamc *= thetaSqr; assert(scatterIt.get_rad_length() == 1.0); assert((finalError(2,2)-alfalf)<0.000001); assert((finalError(3,3)-tlamtlam)<0.000001); assert((finalError(4,4)-cc)<0.000001); assert((finalError(3,4)-ctlam)<0.000001); assert((finalError(4,3)-tlamc)<0.000001); //******************************************************************** cout << ok_prefix << "Write object data." << endl; { ObjPtr pobj( new ThinCylMS(1.23) ); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("obj1",pobj); cout << mystream.str() << endl; assert( ObjTable::has_object_name("obj1") ); string::size_type pos = 0; assert( (pos=mystream.str().find( "obj1 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "ThinCylMS ",pos)) != string::npos ); assert( (pos=mystream.str().find( "rad_length",pos)) != string::npos ); assert( (pos=mystream.str().find( "1.23 ",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ obj2 ThinCylMS rad_length=1.11; ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "obj2" ); const ThinCylMS* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == ThinCylMS::get_static_type() ); assert( pobj->get_rad_length() == 1.11 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }