// HitZPlane1Generator_t.cpp // Test HitZPlane1Generator. #include "HitZPlane1Generator.h" #include #include #include #include "SurfZPlane.h" #include "trfbase/ETrack.h" #include "trfbase/Hit.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::sqrt; using std::fabs; #endif using namespace trf; //********************************************************************** int main( ) { string component = "HitZPlane1Generator"; 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 zpos = 25.0; double wx = 0.1; double wy = 0.5; double daxy = 0.01; HitZPlane1Generator gen(zpos,wx,wy,daxy); cout << gen << endl; assert( new HitZPlane1Generator(zpos,wx,wy,daxy) != 0); assert( new HitZPlane1Generator(zpos,wx,wy,daxy) != 0); assert( new HitZPlane1Generator(zpos,wx,wy,daxy) != 0); assert( new HitZPlane1Generator(zpos,wx,wy,daxy) != 0); //******************************************************************** cout << ok_prefix << "Generate a list of hits." << endl; double x_track = 1.2345; double y_track = 6.789; double axy = wx*x_track+wy*y_track; SurfZPlane szp(zpos); TrackVector vec; vec(SurfZPlane::IX) = x_track; vec(SurfZPlane::IY) = y_track; TrackError err; VTrack trv(SurfacePtr(szp.new_pure_surface()),vec); ETrack tre(trv,err); ClusterList clusters; int nclus = 20; for ( int i=0; ipredict(tre); assert( newhits.size() == 1 ); hits.push_back( newhits.front() ); } assert( hits.size() == nclus ); //******************************************************************** cout << ok_prefix << "Generate list of measured values." << endl; double avg = 0.0; double sdev = 0.0; HitList::iterator ihit; for ( ihit=hits.begin(); ihit!=hits.end(); ++ihit ) { HitPtr phit = *ihit; assert( phit.pointer() != 0); double mval = phit->measured_vector()(0); double merr = phit->measured_error()(0,0); double pval = phit->predicted_vector()(0); double perr = phit->predicted_error()(0,0); assert( pval == axy); assert( is_equal(merr, daxy*daxy) ); cout << mval << endl; avg += mval; sdev += (mval-pval)*(mval-pval); } avg /= nclus; sdev = sqrt(sdev/nclus); cout << " Avg: " << avg << endl; cout << "Sdev: " << sdev << endl; assert( fabs( avg - axy ) < daxy ); assert( fabs( sdev - daxy ) < daxy ); //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }