// ClusFindXYPlane2_t.cc // Test component ClusFindXYPlane2. #include "ClusFindXYPlane2.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfbase/ETrack.h" #include "SurfXYPlane.h" #include "HitXYPlane2.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 = "ClusFindXYPlane2"; 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 dist1 = 10.0; double phi1 = PI/4.; ClusFindXYPlane2 find1(dist1,phi1,10.0); cout << find1 << endl; //******************************************************************** cout << ok_prefix << "Check the surface." << endl; SurfXYPlane srf1(dist1,phi1); assert( srf1 == find1.get_surface() ); //******************************************************************** cout << ok_prefix << "Construct a axy finder." << endl; double dist2 = 20.0; double phi2 = PI/3.; ClusFindXYPlane2 find2(dist2,phi2,10.0); ClusFindXYPlane2 find_cont(dist2,phi2); ClusFindXYPlane2 find_cont2(dist2,phi2,10.); cout << find2 << endl; //******************************************************************** HitError dhm(2); dhm(ClusXYPlane2::IV,ClusXYPlane2::IV) = 0.002; dhm(ClusXYPlane2::IZ,ClusXYPlane2::IZ) = 0.008; dhm(ClusXYPlane2::IV,ClusXYPlane2::IZ) = 0.; cout << ok_prefix << "Add axy clusters to finder." << endl; ClusterPtr pclu21 = new ClusXYPlane2(dist2,phi2,3.03,35.30,dhm); ClusterPtr pclu22 = new ClusXYPlane2(dist2,phi2,2.79,35.0 ,dhm); //wrong ClusterPtr pclu23 = new ClusXYPlane2(dist2,phi2,2.85,34.8 ,dhm); ClusterPtr pclu24 = new ClusXYPlane2(dist2,phi2,3.21,35.01,dhm); //wrong ClusterPtr pclu25 = new ClusXYPlane2(dist2,phi2,3.12,35.26,dhm); ClusterPtr pclu26 = new ClusXYPlane2(dist2,phi2,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; SurfXYPlane srf2(dist2,phi2); TrackVector vec; TrackError err; err(SurfXYPlane::IV,SurfXYPlane::IV) = 0.002; err(SurfXYPlane::IZ,SurfXYPlane::IZ) = 0.008; err(SurfXYPlane::IDVDU,SurfXYPlane::IDVDU) = 0.01; err(SurfXYPlane::IDZDU,SurfXYPlane::IDZDU) = 0.01; err(SurfXYPlane::IQP,SurfXYPlane::IQP) = 0.01; vec(SurfXYPlane::IZ) = 35.0; vec(SurfXYPlane::IV) = 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 ClusFindXYPlane2(30,0.12,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("ClusFindXYPlane2 ",pos)) != string::npos ); assert( (pos=mystream.str().find("dist",pos)) != string::npos ); assert( (pos=mystream.str().find("30. ",pos)) != string::npos ); assert( (pos=mystream.str().find("phi",pos)) != string::npos ); assert( (pos=mystream.str().find(".12 ",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 ClusFindXYPlane2"; istring += "\n dist=60."; istring += "\n phi=0.24"; istring += "\n max_chsq_diff=20."; istring += "\n]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "obj2" ); const ClusFindXYPlane2* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == ClusFindXYPlane2::get_static_type() ); assert( ((const SurfXYPlane&)(pobj->get_surface())).get_parameter(SurfXYPlane::DISTNORM) == 60.0 ); assert( ((const SurfXYPlane&)(pobj->get_surface())).get_parameter(SurfXYPlane::NORMPHI) == 0.24 ); assert( pobj->get_max_chsq_diff() == 20.0 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }