// FilterShares_t.cpp #include "FilterShares.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "trfbase/SurfTest.h" #include "trfbase/ETrack.h" #include "trffit/MTrack.h" #include "trfbase/HitTest.h" #include "FilterPtr.h" using std::cout; using std::cerr; using std::endl; using std::string; using std::ostringstream; using std::istringstream; using namespace trf; //********************************************************************** int main( ) { string component = "FilterShares"; 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 << "Create filters." << endl; ObjTable::register_type(); FilterShares filt0(0); cout << filt0 << endl; FilterShares filt1(1); cout << filt1 << endl; FilterShares filt2(2); cout << filt2 << endl; FilterShares filt3(3); cout << filt3 << endl; //******************************************************************** cout << ok_prefix << "Generate some hits." << endl; SurfTest srf(1); ETrack tre( SurfacePtr(srf.new_pure_surface()) ); // 1st layer ClusterPtr pclu11 = new ClusterTest(srf,11); HitPtr phit11 = pclu11->predict(tre).front(); ClusterPtr pclu12 = new ClusterTest(srf,12); HitPtr phit12 = pclu12->predict(tre).front(); ClusterPtr pclu13 = new ClusterTest(srf,13); HitPtr phit13 = pclu13->predict(tre).front(); // 2nd layer ClusterPtr pclu21 = new ClusterTest(srf,21); HitPtr phit21 = pclu21->predict(tre).front(); ClusterPtr pclu22 = new ClusterTest(srf,22); HitPtr phit22 = pclu22->predict(tre).front(); ClusterPtr pclu23 = new ClusterTest(srf,23); HitPtr phit23 = pclu23->predict(tre).front(); // 3rd layer ClusterPtr pclu31 = new ClusterTest(srf,31); HitPtr phit31 = pclu31->predict(tre).front(); ClusterPtr pclu32 = new ClusterTest(srf,32); HitPtr phit32 = pclu32->predict(tre).front(); ClusterPtr pclu33 = new ClusterTest(srf,33); HitPtr phit33 = pclu33->predict(tre).front(); ClusterPtr pclu4 = new ClusterTest(srf,4); HitPtr phit4 = pclu4->predict(tre).front(); ClusterPtr pclu5 = new ClusterTest(srf,5); HitPtr phit5 = pclu5->predict(tre).front(); //******************************************************************** cout << ok_prefix << "Build list of tracks." << endl; Filter::MTrackArray trms; int ntrm = 5; MTrack* ptrm; // track 0 - bad (killed by 1) ptrm = new MTrack(tre); ptrm->add_hit(phit12); ptrm->add_hit(phit21); ptrm->add_hit(phit31); ptrm->set_fit(tre,1.0); trms.push_back(Filter::MTrackPtr(ptrm)); // track 1 - good ptrm = new MTrack(tre); ptrm->add_hit(phit11); ptrm->add_hit(phit21); ptrm->add_hit(phit31); ptrm->set_fit(tre,0.1); trms.push_back(Filter::MTrackPtr(ptrm)); // track 2 - good (though shares 1 hit with track 1) ptrm = new MTrack(tre); ptrm->add_hit(phit12); ptrm->add_hit(phit21); ptrm->add_hit(phit32); ptrm->set_fit(tre,0.7); trms.push_back(Filter::MTrackPtr(ptrm)); // track 3 - bad (killed by 4; does NOT kill 2) ptrm = new MTrack(tre); ptrm->add_hit(phit12); ptrm->add_hit(phit22); ptrm->add_hit(phit32); ptrm->set_fit(tre,0.5); trms.push_back(Filter::MTrackPtr(ptrm)); // track 4 - good ptrm = new MTrack(tre); ptrm->add_hit(phit13); ptrm->add_hit(phit22); ptrm->add_hit(phit32); ptrm->set_fit(tre,0.3); trms.push_back(Filter::MTrackPtr(ptrm)); assert( trms.size() == 5 ); //******************************************************************** Filter::FlagArray flags; int iflag; //******************************************************************** cout << ok_prefix << "Process 0 shared hits." << endl; flags = filt0.process(trms); assert( flags.size() == ntrm ); for ( iflag=0; iflagget_type() == FilterShares::get_static_type() ); assert( pfil->get_min_share_count() == 246 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }