#include #include #include #include #include #include // Unbelievably ugly hack to let me test private methods. #define private public #define protected public #include "IOADatabase.hxx" #undef private #undef protected #include "ICOMETLog.hxx" #include "IGeometryId.hxx" #include "IGeomIdManager.hxx" #include "COMETGeomId.hxx" #include "ICTHGeomId.hxx" #include "HEPUnits.hxx" namespace tut { struct baseGeometry { baseGeometry() { // Run before each test. COMET::IOADatabase::Get().RegisterGeometryLookup(NULL); COMET::IOADatabase::Get().RegisterAlignmentLookup(NULL); COMET::IOADatabase::Get().ClearGeometryCallbacks(); if (!gGeoManager) { COMET::IOADatabase::Get().GeomId().ReadGeometry( COMET::ISHAHashValue()); } else { COMET::IOADatabase::Get().GeomId().ResetGeometry(); } } ~baseGeometry() { // Run after each test. COMET::IOADatabase::Get().RegisterGeometryLookup(NULL); COMET::IOADatabase::Get().RegisterAlignmentLookup(NULL); COMET::IOADatabase::Get().ClearGeometryCallbacks(); } }; // Declare the test typedef test_group::object testGeometry; test_group groupGeometry("Geometry"); /* Comment out these tests for now. Needs to be fixed up for COMET. // Test that a geometry can be found. This is running without a file, and // the geometry has been loaded in the pre test setup, so this is testing // that the geometry override is working. If the geometry isn't found, // this throws an exception, so there isn't any reason to have an "ensure" // check. template<> template<> void testGeometry::test<1> () { COMET::ISHAHashValue hash = COMET::IOADatabase::Get().GeomId().GetHash(); COMET::IOADatabase::Get().SetGeometryOverride(hash); COMET::IOADatabase::Get().UpdateGeometry(); } /// Implement a IGeometryLookup class that returns alignment. This works /// on the default geometry. class IAlignmentLookup: public COMET::IOADatabase::IAlignmentLookup { unsigned int fCalls; public: std::vector< std::pair > fGeomIdYShift; IAlignmentLookup() {} virtual ~IAlignmentLookup() {} bool CheckAlignment(const COMET::ICOMETEvent* const event) { return true; } COMET::IAlignmentId StartAlignment(const COMET::ICOMETEvent* const event) { fCalls = 0; unsigned int aid[5] = {0,0,0,0,0}; aid[0] = fGeomIdYShift.size(); for (unsigned i=0; i template<> void testGeometry::test<2> () { // COMET::IOADatabase::Get().UpdateGeometry(); // Get the original position of the P0D detector. // COMET::IOADatabase::Get().GeomId().CdId(COMET::GeomId::P0D::Detector()); COMET::IOADatabase::Get().GeomId().CdId(COMET::GeomId::CTH::Detector()); double local[3] = {0,0,0}; double master[3]; gGeoManager->LocalToMaster(local,master); double oldY = master[1]; // Prepare the alignments. alignmentLookup.fGeomIdYShift.clear(); alignmentLookup.fGeomIdYShift.push_back( // std::pair(COMET::GeomId::P0D::Detector(), 2*unit::mm)); std::pair(COMET::GeomId::CTH::Detector(),2*unit::mm)); COMET::IOADatabase::Get().RegisterAlignmentLookup(&alignmentLookup); COMET::IOADatabase::Get().AlignGeometry(NULL); // Get the shifted position of the P0D detector. COMET::IOADatabase::Get().GeomId().CdId(COMET::GeomId::CTH::Detector()); gGeoManager->LocalToMaster(local,master); double newY = master[1]; ensure_distance("Alignment shift", newY-oldY, 2.0*unit::mm, 0.1*unit::mm); } /// Test the cumulative alignment capability. template<> template<> void testGeometry::test<3> () { // COMET::IOADatabase::Get().UpdateGeometry(); // Get the original position of the P0D detector. COMET::IOADatabase::Get().GeomId().CdId(COMET::GeomId::CTH::Module(1)); double local[3] = {0,0,0}; double master[3]; gGeoManager->LocalToMaster(local,master); double oldY = master[1]; // Prepare the alignments. alignmentLookup.fGeomIdYShift.clear(); alignmentLookup.fGeomIdYShift.push_back( std::pair(COMET::GeomId::CTH::Detector(), 3*unit::mm)); alignmentLookup.fGeomIdYShift.push_back( std::pair(COMET::GeomId::CTH::Module(1), 2*unit::mm)); COMET::IOADatabase::Get().RegisterAlignmentLookup(&alignmentLookup); COMET::IOADatabase::Get().AlignGeometry(NULL); // Get the shifted position of the P0D detector. COMET::IOADatabase::Get().GeomId().CdId(COMET::GeomId::CTH::Module(1)); gGeoManager->LocalToMaster(local,master); double newY = master[1]; ensure_distance("Alignment shift", newY-oldY, 5.0*unit::mm, 0.1*unit::mm); } /// Same as test 3, but apply shifts in different order. template<> template<> void testGeometry::test<4> () { // COMET::IOADatabase::Get().UpdateGeometry(); // Get the original position of the P0D detector. COMET::IOADatabase::Get().GeomId().CdId(COMET::GeomId::CTH::Module(1)); double local[3] = {0,0,0}; double master[3]; gGeoManager->LocalToMaster(local,master); double oldY = master[1]; // Prepare the alignments. alignmentLookup.fGeomIdYShift.clear(); alignmentLookup.fGeomIdYShift.push_back( std::pair(COMET::GeomId::CTH::Module(1), 2*unit::mm)); alignmentLookup.fGeomIdYShift.push_back( std::pair(COMET::GeomId::CTH::Detector(), 3*unit::mm)); COMET::IOADatabase::Get().RegisterAlignmentLookup(&alignmentLookup); COMET::IOADatabase::Get().AlignGeometry(NULL); // Get the shifted position of the P0D detector. COMET::IOADatabase::Get().GeomId().CdId(COMET::GeomId::CTH::Module(1)); gGeoManager->LocalToMaster(local,master); double newY = master[1]; ensure_distance("Alignment shift", newY-oldY, 5.0*unit::mm, 0.1*unit::mm); } /// Apply multiple alignments to the same volume. template<> template<> void testGeometry::test<5> () { // COMET::IOADatabase::Get().UpdateGeometry(); // Get the original position of the P0D detector. COMET::IOADatabase::Get().GeomId().CdId(COMET::GeomId::CTH::Module(1)); double local[3] = {0,0,0}; double master[3]; gGeoManager->LocalToMaster(local,master); double oldY = master[1]; // Prepare the alignments. alignmentLookup.fGeomIdYShift.clear(); alignmentLookup.fGeomIdYShift.push_back( std::pair(COMET::GeomId::CTH::Module(1), 2*unit::mm)); alignmentLookup.fGeomIdYShift.push_back( std::pair(COMET::GeomId::CTH::Module(1), 3*unit::mm)); alignmentLookup.fGeomIdYShift.push_back( std::pair(COMET::GeomId::CTH::Module(1), 4*unit::mm)); COMET::IOADatabase::Get().RegisterAlignmentLookup(&alignmentLookup); COMET::IOADatabase::Get().AlignGeometry(NULL); // Get the shifted position of the P0D detector. COMET::IOADatabase::Get().GeomId().CdId(COMET::GeomId::CTH::Module(1)); gGeoManager->LocalToMaster(local,master); double newY = master[1]; ensure_distance("Alignment shift", newY-oldY, 9.0*unit::mm, 0.1*unit::mm); } /// Make sure that the IGeomIdManager::ResetGeometry is working. template<> template<> void testGeometry::test<6> () { // Get the existing geometry. // COMET::IOADatabase::Get().UpdateGeometry(); COMET::IOADatabase::Get().RegisterAlignmentLookup(&alignmentLookup); COMET::IOADatabase::Get().AlignGeometry(NULL); COMET::ISHAHashValue hc = COMET::IOADatabase::Get().GeomId().GetHash(); COMET::IAlignmentId aid = COMET::IOADatabase::Get().GeomId().GetAlignmentId(); COMET::IOADatabase::Get().GeomId().ResetGeometry(); ensure_equals("Hash Code before and after reset", hc, COMET::IOADatabase::Get().GeomId().GetHash()); ensure_equals("Alignment Id Code before and after reset", aid, COMET::IOADatabase::Get().GeomId().GetAlignmentId()); } /// Make sure that the CdId method is working. template<> template<> void testGeometry::test<7> () { // COMET::IOADatabase::Get().UpdateGeometry(); for (int i=0; i<2; ++i) { ensure("CdId finds volume matching geometry id.", COMET::IOADatabase::Get().GeomId().CdId( COMET::GeomId::CTH::Module(i))); } ensure("CdId returns false for non-existent volume.", !COMET::IOADatabase::Get().GeomId().CdId( COMET::GeomId::CTH::Module(2))); } class ILocalGeometryChange: public COMET::IOADatabase::IGeometryChange { public: ILocalGeometryChange() : fCallCount(0) {} void Callback(const COMET::ICOMETEvent* const event) {++fCallCount;} int fCallCount; }; ILocalGeometryChange localGeometryChange; /// Test that the IGeometryChange call back is working. template<> template<> void testGeometry::test<8> () { COMET::ISHAHashValue hash = COMET::IOADatabase::Get().GeomId().GetHash(); COMET::IOADatabase::Get().SetGeometryOverride(hash); COMET::IOADatabase::Get().RegisterGeometryCallback(&localGeometryChange); COMET::IOADatabase::Get().UpdateGeometry(); ensure_equals("Call backs called", localGeometryChange.fCallCount,1); } /// Test that the water target identifiers. template<> template<> void testGeometry::test<9> () { for (int i=0; i<25; ++i) { COMET::IGeometryId targetId = COMET::GeomId::P0D::Target(i); ensure("CdId find the target volume.", COMET::IOADatabase::Get().GeomId().CdId(targetId)); } ensure("CdId returns false for non-existent target.", !COMET::IOADatabase::Get().GeomId().CdId( COMET::GeomId::P0D::Target(25))); } */ };