// AddFitXYPlane_XY2_t.cpp // Test AddFitXYPlane_XY2. #include "AddFitXYPlane_XY2.h" #include #include #include #include #include "objstream/StdObjStream.hpp" #include "trffit/HTrack.h" #include "HitXYPlane2.h" #include "trfbase/HitTest.h" #include "trfutil/TRFMath.h" #include "trfutil/trfstream.h" #ifndef DEFECT_NO_STDLIB_NAMESPACES using std::cout; using std::cerr; using std::endl; using std::string; using std::ostringstream; using std::istringstream; #endif using namespace trf; // Assign track parameter indices. enum { IV = SurfXYPlane::IV, IZ = SurfXYPlane::IZ, IDVDU = SurfXYPlane::IDVDU, IDZDU = SurfXYPlane::IDZDU, IQP = SurfXYPlane::IQP }; //********************************************************************** int main( ) { string component = "AddFitXYPlane_XY2"; 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; AddFitXYPlane_XY2 fit; cout << fit << endl; //******************************************************************** cout << ok_prefix << "Add 1st hit." << endl; double dist1 = 10.; double phi1 = PI/4.; SurfXYPlane srf1(dist1,phi1); ETrack tre(SurfacePtr(srf1.new_pure_surface())); TrackVector vec; vec.fill(0.); tre.set_vector(vec); HTrack trh(tre); double hitv = 11.; double hitz = 12.; HitError dhm(2); dhm(ClusXYPlane2::IV,ClusXYPlane2::IV) = 0.022; dhm(ClusXYPlane2::IV,ClusXYPlane2::IZ) = 0.012; dhm(ClusXYPlane2::IZ,ClusXYPlane2::IZ) = 0.032; ClusterPtr pclus = new ClusXYPlane2(dist1,phi1,hitv,hitz,dhm); 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 v - hit v: " << trh.get_track().get_vector()(IV) - hitv << endl; cout << "Track z - hit z: " << trh.get_track().get_vector()(IZ) - hitz << endl; assert( trh.get_track().get_vector()(IV) == hitv ); assert( trh.get_track().get_vector()(IZ) == hitz ); assert( trh.get_track().get_error()(IV,IV) == dhm(0,0)); assert( trh.get_track().get_error()(IV,IZ) == dhm(0,1)); assert( trh.get_track().get_error()(IZ,IZ) == dhm(1,1)); assert( trh.get_track().is_forward()); //******************************************************************** 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); const SurfTest *psrf = (const SurfTest *)&srf1; ClusterPtr pclusw = new ClusterTest(*psrf,1); HitList hitsw = pclusw->predict(tre); HitPtr phitw = hitsw.front(); // HitPtr phitw = new HitTest(1); cout << *phitw << endl; stat = fit.add_hit(trh2,phitw); cout << stat << endl; assert( stat ); assert( trh2.get_hits().size() == 0 ); //******************************************************************** cout << ok_prefix << "Try to add 1st hit on wrong surface." << endl; double dist2 = 13.; double phi2 = PI/6.; ClusterPtr pclus2 = new ClusXYPlane2(dist2,phi2,hitv,hitz,dhm); HitList hits2 = pclus2->predict(tre); HitPtr phit2 = hits2.front(); stat = fit.add_hit(trh2,phit2); cout << stat << endl; assert( stat ); assert( trh2.get_hits().size() == 0 ); //******************************************************************** ObjTable::register_type(); cout << ok_prefix << "Write object data." << endl; { ObjPtr pobj( new AddFitXYPlane_XY2 ); 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( "AddFitXYPlane_XY2 ",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ obj2 AddFitXYPlane_XY2 ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "obj2" ); const AddFitXYPlane_XY2* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == AddFitXYPlane_XY2::get_static_type() ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }