// DCATrackNtuple_t.cpp #include "DCATrackNtuple.h" #include "trfdca/SurfDCA.h" #include "trffit/HTrack.h" #include "trfbase/ETrack.h" #include #include using std::cout; using std::cerr; using std::endl; using std::string; using namespace trf; //********************************************************************** int main( ) { string component = "DCATrackNtuple"; 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 << ok_prefix << "Create MC-reco tuple." << endl; SurfacePtr psrf( new SurfDCA() ); TrackVector vec; TrackError err; for ( int i=0; i<5; ++i ) { err(i,i) = 1.0; } VTrack trv(psrf,vec); ETrack tre(psrf,vec,err); HTrack trh(tre); { int nc = 21; DCATrackNtuple ntp(true,true,false); assert( ntp.mc() ); assert( ntp.reco() ); assert( ! ntp.mc2() ); cout << ok_prefix << "Check for 3 matches, two not found, and 1 fake." << endl; assert(ntp.nrows() == 0 ); assert(ntp.ncolumns() == nc ); ntp.fill(trv,trh); ntp.fill(trv,trh); ntp.fill(trv,trh); ntp.fill(trv); ntp.fill(trv); ntp.fill(trh); assert(ntp.nrows() == 6 ); assert(ntp.ncolumns() == nc ); } //******************************************************************** cout << ok_prefix << "Create MC tuple." << endl; { int nc = 6; DCATrackNtuple ntp(true,false,false); assert( ntp.mc() ); assert( ! ntp.reco() ); assert( ! ntp.mc2() ); assert(ntp.nrows() == 0 ); assert(ntp.ncolumns() == nc ); ntp.fill(trv); ntp.fill(trv); assert(ntp.nrows() == 2 ); assert(ntp.ncolumns() == nc ); } //******************************************************************** cout << ok_prefix << "Create reco tuple." << endl; { int nc = 14; DCATrackNtuple ntp(false,true,false); assert( ! ntp.mc() ); assert( ntp.reco() ); assert( ! ntp.mc2() ); assert(ntp.nrows() == 0 ); assert(ntp.ncolumns() == nc ); ntp.fill(trh); ntp.fill(trh); ntp.fill(trh); assert(ntp.nrows() == 3 ); assert(ntp.ncolumns() == nc ); } //******************************************************************** cout << ok_prefix << "Create MC-MC tuple." << endl; { int nc = 11; DCATrackNtuple ntp(true,false,true); assert( ntp.mc() ); assert( ! ntp.reco() ); assert( ntp.mc2() ); assert(ntp.nrows() == 0 ); assert(ntp.ncolumns() == nc ); ntp.fill(trv,trv); ntp.fill(trv,trv); ntp.fill(trv,trv); ntp.fill(trv,trv); assert(ntp.nrows() == 4 ); assert(ntp.ncolumns() == nc ); } //******************************************************************** cout << ok_prefix << "Create MC-reco-MC tuple." << endl; { int nc = 27; DCATrackNtuple ntp(true,true,true); assert( ntp.mc() ); assert( ntp.reco() ); assert( ntp.mc2() ); assert(ntp.nrows() == 0 ); assert(ntp.ncolumns() == nc ); ntp.fill(trv,trh,trv); ntp.fill(trv,trh,trv); ntp.fill(trv,trh,trv); ntp.fill(trv,trh,trv); ntp.fill(trv,trh); ntp.fill(trv,trh); ntp.fill(trv,trh); ntp.fill(trv,trv); ntp.fill(trv,trv); ntp.fill(trh); assert(ntp.nrows() == 10 ); assert(ntp.ncolumns() == nc ); } //******************************************************************** cout << ok_prefix << "Create MC tuple with extra word." << endl; { int nc = 6; DCATrackNtuple ntp(true,false,false); assert( ntp.mc() ); assert( ! ntp.reco() ); assert( ! ntp.mc2() ); assert(ntp.nrows() == 0 ); assert(ntp.ncolumns() == nc ); ntp.add_column_float("x", -999); assert(ntp.ncolumns() == ++nc ); ntp.add_column_int("i", -999); assert(ntp.ncolumns() == ++nc ); ntp.set_auto_store(false); for ( int i=1; i<=10; ++i ) { ntp.fill(trv); ntp.fill_float("x",i); ntp.fill_int("i",10+i); int nr = ntp.store_row(); assert( nr == i ); } assert(ntp.nrows() == 10 ); assert(ntp.ncolumns() == nc ); } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }