// AddFitZPlane_Z2_t.cpp // Test AddFitZPlane_Z2. #include "AddFitZPlane_Z2.h" #include #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "trfutil/TRFMath.h" #include "trffit/HTrack.h" #include "HitZPlane2.h" #include "trfbase/HitTest.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 { IX = SurfZPlane::IX, IY = SurfZPlane::IY, IDXDZ = SurfZPlane::IDXDZ, IDYDZ = SurfZPlane::IDYDZ, IQP = SurfZPlane::IQP }; //********************************************************************** int main( ) { string component = "AddFitZPlane_Z2"; 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 ptmin = 0.5; AddFitZPlane_Z2 fit(ptmin); assert(is_equal(ptmin,fit.get_ptmin())); cout << fit << endl; //******************************************************************** cout << ok_prefix << "Add 1st hit." << endl; double zpos1 = 10.; SurfZPlane srf1(zpos1); ETrack tre(SurfacePtr(srf1.new_pure_surface())); TrackVector vec; vec.fill(0.); tre.set_vector(vec); tre.set_forward(); HTrack trh(tre); double hitx = 11.; double hity = 12.; HitError dhm(2); dhm(ClusZPlane2::IX,ClusZPlane2::IX) = 0.022; dhm(ClusZPlane2::IX,ClusZPlane2::IY) = 0.012; dhm(ClusZPlane2::IY,ClusZPlane2::IY) = 0.032; ClusterPtr pclus = new ClusZPlane2(zpos1,hitx,hity,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()(IX) - hitx << endl; cout << "Track z - hit z: " << trh.get_track().get_vector()(IY) - hity << endl; assert( is_equal( trh.get_track().get_vector()(IX), hitx ) ); assert( is_equal( trh.get_track().get_vector()(IY), hity ) ); assert( is_equal( trh.get_track().get_error()(IX,IX), dhm(0,0) ) ); assert( is_equal( trh.get_track().get_error()(IX,IY), dhm(0,1) ) ); assert( is_equal( trh.get_track().get_error()(IY,IY), dhm(1,1) ) ); assert( is_equal( trh.get_track().get_error()(IQP,IQP), 1./ptmin/ptmin) ); assert( is_equal( trh.get_track().get_vector()(IQP), 0.001 ) ); double tx = trh.get_track().get_vector()(IDXDZ); double ty = trh.get_track().get_vector()(IDYDZ); double qp = trh.get_track().get_vector()(IQP); double pzpt = 1./sqrt(tx*tx+ty*ty); assert( fabs( ty*hitx - tx*hity) < 1.0e-10 ); assert( is_equal(pzpt , 100.) ); 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 zpos2 = 13.; ClusterPtr pclus2 = new ClusZPlane2(zpos2,hitx,hity,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(); ObjTable::register_type(); cout << ok_prefix << "Write object data." << endl; { ObjPtr pptmin( new ObjDouble(0.5) ); ObjPtr pobj( new AddFitZPlane_Z2(ptmin) ); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("ptmin",pptmin); 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( "AddFitZPlane_Z2 ",pos)) != string::npos ); assert( (pos=mystream.str().find( "ptmin",pos)) != string::npos ); assert( (pos=mystream.str().find( "0.5",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ obj2 AddFitZPlane_Z2 ptmin=@ptmin ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "obj2" ); const AddFitZPlane_Z2* pobj; ObjTable::get_object(name,pobj); assert( pobj != 0 ); assert( pobj->get_type() == AddFitZPlane_Z2::get_static_type() ); assert( pobj->get_ptmin() == 0.5 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }