// ClusFindXYPlane1_t.cc // Test component ClusFindXYPlane1. #include "ClusFindXYPlane1.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfbase/ETrack.h" #include "SurfXYPlane.h" #include "HitXYPlane1.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 = "ClusFindXYPlane1"; 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.; ClusFindXYPlane1 find1(dist1,phi1,0.01,0.02,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.; double wv2 = 0.1; double wz2 = 0.2; ClusFindXYPlane1 find2(dist2,phi2,wv2,wz2,10.0); cout << find2 << endl; //******************************************************************** cout << ok_prefix << "Add axy clusters to finder." << endl; ClusterPtr pclu21 = new ClusXYPlane1(dist2,phi2,wv2,wz2,3.004,0.02); ClusterPtr pclu22 = new ClusXYPlane1(dist2,phi2,wv2,wz2,3.071,0.02); //wrong ClusterPtr pclu23 = new ClusXYPlane1(dist2,phi2,wv2,wz2,2.935,0.02); ClusterPtr pclu24 = new ClusXYPlane1(dist2,phi2,wv2,wz2,2.929,0.02); //wrong ClusterPtr pclu25 = new ClusXYPlane1(dist2,phi2,wv2,wz2,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; SurfXYPlane srf2(dist2,phi2); TrackVector vec; TrackError err; err(SurfXYPlane::IV,SurfXYPlane::IV) = 0.001; err(SurfXYPlane::IZ,SurfXYPlane::IZ) = 0.001; 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 - wz2*vec(SurfXYPlane::IZ))/wv2; 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 ClusFindXYPlane1(30,0.12,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("ClusFindXYPlane1 ",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("vweight",pos)) != string::npos ); assert( (pos=mystream.str().find("0.1 ",pos)) != string::npos ); assert( (pos=mystream.str().find("zweight",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 ClusFindXYPlane1"; istring += "\n dist=60."; istring += "\n phi=0.24"; istring += "\n vweight=0.8"; istring += "\n zweight=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 ClusFindXYPlane1* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == ClusFindXYPlane1::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; //******************************************************************** }