// PropJoinCyl_t.cpp // Test PropJoinCyl. #include "PropJoinCyl.h" #include #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "trfbase/PropStat.h" #include "trfbase/TrackVector.h" #include "trfbase/VTrack.h" #include "trfbase/ETrack.h" #include "trfbase/PropDirectedTest.h" #include "trfbase/SurfTest.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 ok_prefix = "PropJoinCyl (I): "; string error_prefix = "PropJoinCyl test (E): "; cout << ok_prefix << "-------- Testing component PropJoinCyl. --------" << 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(); cout << trf_format; cout << ok_prefix << "Test constructor." << endl; PropagatorPtr pptest( new PropTest ); PropJoinCyl prop(0.1,1.0,pptest,pptest); cout << prop << endl; //******************************************************************** cout << ok_prefix << "Propagate a VTrack." << endl; { SurfacePtr psrf1( new SurfTest(1) ); SurfacePtr psrf2( new SurfTest(2) ); TrackVector vec; VTrack trv(psrf1,vec); PropStat pstat = prop.vec_dir_prop(trv,*psrf2,Propagator::FORWARD); cout << trv << endl; assert( pstat.success() ); // Two propagations ==> vec(1) = 2. assert( trv.get_vector()(1) == 2.0 ); } //******************************************************************** cout << ok_prefix << "Propagate an ETrack." << endl; { SurfacePtr psrf1( new SurfTest(1) ); SurfacePtr psrf2( new SurfTest(2) ); TrackVector vec; vec(1) = 3.0; 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; ETrack tre(psrf1,vec,err); PropStat pstat = prop.err_dir_prop(tre,*psrf2,Propagator::BACKWARD); cout << tre << endl; assert( pstat.success() ); // Two propagations ==> vec(1) = 3 + 1 - 1 = 3. assert( tre.get_vector()(1) == 3.0 ); } //******************************************************************** cout << ok_prefix << "Write object data." << endl; PropagatorPtr ppt1( new PropTest ); PropagatorPtr ppt2( new PropTest ); { ObjPtr pobj( new PropJoinCyl(0.1, 1.1, ppt1, ppt2) ); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("ptest1",ppt1); objstream.write_object("ptest2",ppt2); 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( "PropJoinCyl ",pos)) != string::npos ); assert( (pos=mystream.str().find( "rmin",pos)) != string::npos ); assert( (pos=mystream.str().find( "0.1 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "rfac",pos)) != string::npos ); assert( (pos=mystream.str().find( "1.1 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "prop1",pos)) != string::npos ); assert( (pos=mystream.str().find( "ptest1 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "prop2",pos)) != string::npos ); assert( (pos=mystream.str().find( "ptest2 ",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ obj2 PropJoinCyl rmin=0.2 rfac=2.0"; istring += "\n prop1=@ptest1 prop2=@ptest2"; istring += "\n]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "obj2" ); const PropJoinCyl* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == PropJoinCyl::get_static_type() ); assert( pobj->get_rmin() == 0.2 ); assert( pobj->get_rfac() == 2.0 ); assert( pobj->get_prop1() == ppt1 ); assert( pobj->get_prop2() == ppt2 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }