// AddFitCyl_PhiZ_t.cpp // Test AddFitCyl_PhiZ. #include "AddFitCyl_PhiZ.h" #include #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/TRFMath.h" #include "trfutil/trfstream.h" #include "trffit/HTrack.h" #include "HitCylPhi.h" #include "HitCylPhiZ.h" #include "AddFitCyl_Phi.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_PhiZ"; 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(); cout << trf_format; cout << ok_prefix << "Enable tuple." << endl; assert( ! AddFitCyl_PhiZ::tuple_is_enabled() ); AddFitCyl_PhiZ::enable_tuple(); assert( AddFitCyl_PhiZ::tuple_is_enabled() ); AddFitCyl_PhiZ::disable_tuple(); assert( ! AddFitCyl_PhiZ::tuple_is_enabled() ); AddFitCyl_PhiZ::enable_tuple(); assert( AddFitCyl_PhiZ::tuple_is_enabled() ); //******************************************************************** cout << ok_prefix << "Test constructor." << endl; AddFitCyl_Phi fit1; AddFitCyl_PhiZ fit2(10.0,50.0); cout << fit1 << endl; cout << fit2 << endl; //******************************************************************** cout << ok_prefix << "Define measurements." << endl; double radius = 10.0; double stereo = 0.01; ETrack tre( SurfacePtr(new SurfCylinder(radius)) ); HTrack trh0(tre); double phi = 1.234; double z = 34.56; double phiz = phi + stereo*z; double dphi = 0.00567; double dphiz = 0.00789; //******************************************************************** cout << ok_prefix << "Add 1st (phi) hit." << endl; ClusterPtr pclus1 = new ClusCylPhi(radius,phi,dphi); HitList hits1 = pclus1->predict(tre); HitPtr phit1 = hits1.front(); cout << *phit1 << endl; int stat = fit1.add_hit(trh0,phit1); cout << trh0 << endl; cout << stat << endl; assert( stat == 0 ); assert( trh0.get_hits().size() == 1 ); //******************************************************************** cout << ok_prefix << "Add 2nd (phiz) hit." << endl; ClusterPtr pclus2 = new ClusCylPhiZ(radius,phiz,dphiz,stereo); HitList hits2 = pclus2->predict(tre); HitPtr phit2 = hits2.front(); cout << *phit2 << endl; HTrack trh1(trh0); stat = fit2.add_hit(trh1,phit2); cout << trh1 << endl; cout << stat << endl; assert( stat == 0 ); assert( stat == AddFitCyl_PhiZ::OK ); assert( trh1.get_hits().size() == 2 ); double track_phiz = trh1.get_track().get_vector()(0) + stereo*trh1.get_track().get_vector()(1); cout << "Track phiz - hit phiz: " << track_phiz - phi << endl; assert( is_equal( trh1.get_track().get_vector()(0), phi ) ); assert( is_equal( trh1.get_track().get_error(0,0), dphi*dphi ) ); //******************************************************************** cout << ok_prefix << "Try to add another phiz hit." << endl; stat = fit2.add_hit(trh1,phit2); cout << stat << endl; assert( stat ); assert( stat == AddFitCyl_PhiZ::WRONG_TYPE_EXISTING ); assert( trh1.get_hits().size() == 2 ); //******************************************************************** cout << ok_prefix << "Try to add 1st hit of wrong type." << endl; HTrack trh2(tre); stat = fit2.add_hit(trh2,phit1); cout << stat << endl; assert( stat ); assert( stat == AddFitCyl_PhiZ::WRONG_TYPE ); //******************************************************************** cout << ok_prefix << "Add out-of-range 2nd hit." << endl; double z3 = 74.56; double phiz3 = phi + stereo*z3; ClusterPtr pclus3 = new ClusCylPhiZ(radius,phiz3,dphiz,stereo); HitList hits3 = pclus3->predict(tre); HitPtr phit3 = hits3.front(); HTrack trh3(trh0); stat = fit2.add_hit(trh3,phit3); assert( stat ); assert( stat == AddFitCyl_PhiZ::OUT_OF_RANGE ); //******************************************************************** cout << ok_prefix << "Write object data." << endl; { ObjPtr pobj( new AddFitCyl_PhiZ(-12.3,45.6) ); 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_PhiZ ",pos)) != string::npos ); assert( (pos=mystream.str().find( "zmin",pos)) != string::npos ); assert( (pos=mystream.str().find( "12.3 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "zmax",pos)) != string::npos ); assert( (pos=mystream.str().find( "45.6 ",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ obj2 AddFitCyl_PhiZ zmin=-32.1 zmax=65.4 ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "obj2" ); const AddFitCyl_PhiZ* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == AddFitCyl_PhiZ::get_static_type() ); assert( pobj->get_zmin() == -32.1 ); assert( pobj->get_zmax() == 65.4 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }