// AddFitCyl_Phi_t.cpp // Test AddFitCyl_Phi. #include "AddFitCyl_Phi.h" #include #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "trffit/HTrack.h" #include "HitCylPhi.h" #include "trfbase/HitTest.h" #include "trfutil/TRFMath.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 = "AddFitCyl_Phi"; 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; } //******************************************************************** cout << trf_format; cout << ok_prefix << "Test constructor." << endl; ObjTable::register_type(); AddFitCyl_Phi fit; cout << fit << endl; //******************************************************************** cout << ok_prefix << "Add 1st hit." << endl; double radius = 10.0; ETrack tre( SurfacePtr(new SurfCylinder(radius)) ); HTrack trh(tre); double phi = 1.234; double dphi = 0.00567; ClusterPtr pclus = new ClusCylPhi(radius,phi,dphi); HitList hits = pclus->predict(tre); HitPtr phit = hits.front(); cout << *phit << endl; cout << trh << endl; int stat = fit.add_hit(trh,phit); cout << trh << endl; cout << stat << endl; assert( stat == 0 ); assert( trh.get_hits().size() == 1 ); cout << "Track phi - hit phi: " << trh.get_track().get_vector()(0) - phi << endl; assert( is_equal( trh.get_track().get_vector()(0), phi ) ); assert( is_equal( trh.get_track().get_error(0,0), dphi*dphi ) ); //******************************************************************** cout << ok_prefix << "Try to add second hit." << endl; stat = fit.add_hit(trh,phit); cout << stat << endl; assert( stat ); assert( trh.get_hits().size() == 1 ); //******************************************************************** cout << ok_prefix << "Try to add 1st hit of wrong type." << endl; HTrack trh2(tre); HitPtr phit2( new HitTest(1) ); stat = fit.add_hit(trh2,phit2); cout << stat << endl; assert( stat ); //******************************************************************** cout << ok_prefix << "Write object data." << endl; { ObjPtr pobj( new AddFitCyl_Phi ); 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( "AddFitCyl_Phi ",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ obj2 AddFitCyl_Phi ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "obj2" ); const AddFitCyl_Phi* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == AddFitCyl_Phi::get_static_type() ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }