// ClusFindZPlane1_t.cc // Test component ClusFindZPlane1. #include "ClusFindZPlane1.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfbase/ETrack.h" #include "SurfZPlane.h" #include "HitZPlane1.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; //********************************************************************** int main( ) { string component = "ClusFindZPlane1"; 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; double zpos1 = 10.0; ClusFindZPlane1 find1(zpos1,0.01,0.02,10.0); cout << find1 << endl; //******************************************************************** cout << ok_prefix << "Check the surface." << endl; SurfZPlane srf1(zpos1); assert( srf1 == find1.get_surface() ); //******************************************************************** cout << ok_prefix << "Construct a axy finder." << endl; double zpos2 = 20.0; double wx2 = 0.1; double wy2 = 0.2; ClusFindZPlane1 find2(zpos2,wx2,wy2,10.0); cout << find2 << endl; //******************************************************************** cout << ok_prefix << "Add axy clusters to finder." << endl; ClusterPtr pclu21 = new ClusZPlane1(zpos2,wx2,wy2,3.004,0.02); ClusterPtr pclu22 = new ClusZPlane1(zpos2,wx2,wy2,3.071,0.02); //wrong ClusterPtr pclu23 = new ClusZPlane1(zpos2,wx2,wy2,2.935,0.02); ClusterPtr pclu24 = new ClusZPlane1(zpos2,wx2,wy2,2.929,0.02); //wrong ClusterPtr pclu25 = new ClusZPlane1(zpos2,wx2,wy2,3.065,0.02); find2.add_cluster(pclu21); find2.add_cluster(pclu22); find2.add_cluster(pclu23); find2.add_cluster(pclu24); int stat = find2.add_cluster(pclu25); assert( ! stat ); assert( find2.get_clusters().size() == 5 ); //******************************************************************** cout << ok_prefix << "Find nearby axy clusters." << endl; SurfZPlane srf2(zpos2); TrackVector vec; TrackError err; err(SurfZPlane::IX,SurfZPlane::IX) = 0.001; err(SurfZPlane::IY,SurfZPlane::IY) = 0.001; err(SurfZPlane::IDXDZ,SurfZPlane::IDXDZ) = 0.01; err(SurfZPlane::IDYDZ,SurfZPlane::IDYDZ) = 0.01; err(SurfZPlane::IQP,SurfZPlane::IQP) = 0.01; vec(SurfZPlane::IY) = 35.0; vec(SurfZPlane::IX) = (3.0 - wy2*vec(SurfZPlane::IY))/wx2; ETrack tre2(SurfacePtr(srf2.new_pure_surface()),vec,err); cout << tre2 << endl; ClusterList nearby_clusters = find2.get_clusters(tre2); assert( nearby_clusters.size() == 3 ); cout << *nearby_clusters.front() << endl; cout << *nearby_clusters.back() << endl; assert( *nearby_clusters.front() == *pclu23 ); assert( *nearby_clusters.back() == *pclu25 ); //******************************************************************** cout << ok_prefix << "Drop clusters." << endl; find2.drop_clusters(); assert( find2.get_clusters().size() == 0 ); assert( find2.get_clusters(tre2).size() == 0 ); //******************************************************************** cout << ok_prefix << "Find a single cluster." << endl; find2.add_cluster(pclu23); assert( find2.get_clusters().size() == 1 ); assert( find2.get_clusters(tre2).size() == 1 ); //******************************************************************** ObjTable::register_type(); cout << ok_prefix << "Write object data." << endl; { ObjPtr pobj( new ClusFindZPlane1(30,0.1,0.9,10.0) ); 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("ClusFindZPlane1 ",pos)) != string::npos ); assert( (pos=mystream.str().find("z",pos)) != string::npos ); assert( (pos=mystream.str().find("30. ",pos)) != string::npos ); assert( (pos=mystream.str().find("xweight",pos)) != string::npos ); assert( (pos=mystream.str().find("0.1 ",pos)) != string::npos ); assert( (pos=mystream.str().find("yweight",pos)) != string::npos ); assert( (pos=mystream.str().find("0.9 ",pos)) != string::npos ); assert( (pos=mystream.str().find("max_chsq_diff",pos)) != string::npos ); assert( (pos=mystream.str().find("10. ",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ obj2 ClusFindZPlane1"; istring += "\n z=60."; istring += "\n xweight=0.8"; istring += "\n yweight=0.2"; istring += "\n max_chsq_diff=20."; istring += "\n]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "obj2" ); const ClusFindZPlane1* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == ClusFindZPlane1::get_static_type() ); assert( ((const SurfZPlane&)(pobj->get_surface())).get_z() == 60.0 ); assert( pobj->get_max_chsq_diff() == 20.0 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }