// ClusFindZPlane2_t.cc // Test component ClusFindZPlane2. #include "ClusFindZPlane2.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfbase/ETrack.h" #include "SurfZPlane.h" #include "HitZPlane2.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 = "ClusFindZPlane2"; 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; ClusFindZPlane2 find1(zpos1,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; ClusFindZPlane2 find2(zpos2,10.0); ClusFindZPlane2 find_cont(zpos2); ClusFindZPlane2 find_cont2(zpos2,10.); cout << find2 << endl; //******************************************************************** HitError dhm(2); dhm(ClusZPlane2::IX,ClusZPlane2::IX) = 0.002; dhm(ClusZPlane2::IY,ClusZPlane2::IY) = 0.008; dhm(ClusZPlane2::IX,ClusZPlane2::IY) = 0.; cout << ok_prefix << "Add axy clusters to finder." << endl; ClusterPtr pclu21 = new ClusZPlane2(zpos2,3.03,35.30,dhm); ClusterPtr pclu22 = new ClusZPlane2(zpos2,2.79,35.0 ,dhm); //wrong ClusterPtr pclu23 = new ClusZPlane2(zpos2,2.85,34.8 ,dhm); ClusterPtr pclu24 = new ClusZPlane2(zpos2,3.21,35.01,dhm); //wrong ClusterPtr pclu25 = new ClusZPlane2(zpos2,3.12,35.26,dhm); ClusterPtr pclu26 = new ClusZPlane2(zpos2,3.03,35.30,dhm); find2.add_cluster(pclu21); find2.add_cluster(pclu22); find2.add_cluster(pclu23); find2.add_cluster(pclu24); int stat = find2.add_cluster(pclu25); assert( ! stat ); find2.add_cluster(pclu26); assert( find2.get_clusters().size() == 6 ); find_cont.add_cluster(pclu21); find_cont.add_cluster(pclu22); find_cont.add_cluster(pclu23); find_cont.add_cluster(pclu24); find_cont.add_cluster(pclu25); find_cont.add_cluster(pclu26); assert( find_cont.get_clusters().size() == 6 ); find_cont2.add_cluster(pclu21); find_cont2.add_cluster(pclu22); find_cont2.add_cluster(pclu23); find_cont2.add_cluster(pclu24); find_cont2.add_cluster(pclu25); find_cont2.add_cluster(pclu26); assert( find_cont2.get_clusters().size() == 6 ); //******************************************************************** cout << ok_prefix << "Find nearby axy clusters." << endl; SurfZPlane srf2(zpos2); TrackVector vec; TrackError err; err(SurfZPlane::IX,SurfZPlane::IX) = 0.002; err(SurfZPlane::IY,SurfZPlane::IY) = 0.008; 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; ETrack tre2(SurfacePtr(srf2.new_pure_surface()),vec,err); cout << tre2 << endl; ClusterList nearby_clusters = find2.get_clusters(tre2); assert( nearby_clusters.size() == 4 ); assert( find2.get_clusters().size() == 6 ); const ClusterContainer* box = &find2.get_cluster_container(tre2,0,0); assert( box->size() == 4 ); box = &find_cont.get_cluster_container(tre2,0,0); assert( box->size() == 6 ); box = &find_cont2.get_cluster_container(tre2,0,0); assert( box->size() == 4 ); cout << *nearby_clusters.front() << endl; cout << *nearby_clusters.back() << endl; assert( *nearby_clusters.front() == *pclu21 ); assert( *nearby_clusters.back() == *pclu26 ); //******************************************************************** 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 ClusFindZPlane2(30,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("ClusFindZPlane2 ",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("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 ClusFindZPlane2"; istring += "\n z=60."; istring += "\n max_chsq_diff=20."; istring += "\n]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "obj2" ); const ClusFindZPlane2* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == ClusFindZPlane2::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; //******************************************************************** }