From 8dab6c20308412974afb28ea1638a718f7e4b64e Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Thu, 10 Oct 2013 16:16:30 +0100 Subject: [PATCH] refs #8095 Unit tests fixed and hopefully correct --- .../inc/MantidDataHandling/FindDetectorsPar.h | 3 ++ .../DataHandling/src/FindDetectorsPar.cpp | 34 +++++++++++-------- .../DataHandling/test/FindDetectorsParTest.h | 21 ++++++------ 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsPar.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsPar.h index b494964644c3..815f8f2db230 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsPar.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsPar.h @@ -223,6 +223,9 @@ class AvrgDetector void addDetInfo(const Geometry::IDetector_const_sptr &spDet,const Kernel::V3D &Observer); void returnAvrgDetPar(DetParameters &det); + void setUseSpherical(bool shouldWe=true) + {m_useSphericalSizes = shouldWe;} + }; diff --git a/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp b/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp index 998e576c4839..d88185235b76 100644 --- a/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp +++ b/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp @@ -176,8 +176,6 @@ FindDetectorsPar::exec() } -// Constant for converting Radians to Degrees -const double rad2deg = 180.0 / M_PI; // functions defines the ouptput table with parameters void FindDetectorsPar::setOutputTable() @@ -217,6 +215,9 @@ void FindDetectorsPar::setOutputTable() } +// Constant for converting Radians to Degrees +const double rad2deg = 180.0 / M_PI; + /// method to cacluate the detectors parameters and add them to the average detector void AvrgDetector::addDetInfo(const Geometry::IDetector_const_sptr &spDet,const Kernel::V3D &Observer) { @@ -242,19 +243,22 @@ void AvrgDetector::addDetInfo(const Geometry::IDetector_const_sptr &spDet,const Kernel::V3D er(0,1,0),e_th,ez(0,0,1); //ez along beamline, which is always oz; (can be amended) if(dist2Det)er = toDet/dist2Det; // direction to the detector Kernel::V3D e_tg = er.cross_prod(ez); // tangential to the ring and anticloakwise; + e_tg.normalize(); + // make orthogonal + ez = e_tg.cross_prod(er); - coord[0]=er; - coord[1]=ez; - coord[2]=e_tg ; + coord[0]=er; // new X + coord[1]=ez; // new y + coord[2]=e_tg ; // new z bbox.setBoxAlignment(ringCentre,coord); spDet->getBoundingBox(bbox); // linear extensions of the bounding box orientied tangentially to the equal scattering angle circle - double azimMin = bbox.xMin(); - double azimMax = bbox.xMax(); - double polarMin = bbox.zMin(); // bounding box has been rotated according to coord above, so z is along e_tg - double polarMax = bbox.zMax(); + double azimMin = bbox.zMin(); + double azimMax = bbox.zMax(); + double polarMin = bbox.yMin(); // bounding box has been rotated according to coord above, so z is along e_tg + double polarMax = bbox.yMax(); if (m_useSphericalSizes) @@ -263,12 +267,12 @@ void AvrgDetector::addDetInfo(const Geometry::IDetector_const_sptr &spDet,const // convert to angular units double polarHalfSize = rad2deg*atan2(0.5*(polarMax-polarMin), dist2Det); - double azimHalfSize = rad2deg*atan2(0.5*(polarMax-azimMax), dist2Det); + double azimHalfSize = rad2deg*atan2(0.5*(azimMax-azimMin), dist2Det); - double polarMin = Polar -polarHalfSize; - double polarMax = Polar +polarHalfSize; - double azimMin = Azimut -azimHalfSize; - double azimMax = Azimut +azimHalfSize; + polarMin = Polar -polarHalfSize; + polarMax = Polar +polarHalfSize; + azimMin = Azimut -azimHalfSize; + azimMax = Azimut +azimHalfSize; } if (m_AzimMin>azimMin)m_AzimMin=azimMin; @@ -304,7 +308,7 @@ void FindDetectorsPar::calcDetPar(const Geometry::IDetector_const_sptr &spDet,co // define summator AvrgDetector detSum; // do we want spherical or linear box sizes? - detSum.m_useSphericalSizes = !m_SizesAreLinear; + detSum.setUseSpherical(!m_SizesAreLinear); if( nDetectors == 1) { diff --git a/Code/Mantid/Framework/DataHandling/test/FindDetectorsParTest.h b/Code/Mantid/Framework/DataHandling/test/FindDetectorsParTest.h index 10c0abaa5556..d6192a75332f 100644 --- a/Code/Mantid/Framework/DataHandling/test/FindDetectorsParTest.h +++ b/Code/Mantid/Framework/DataHandling/test/FindDetectorsParTest.h @@ -97,8 +97,8 @@ class FindDetectorsParTest : public CxxTest::TestSuite pattern[2] = "1,2,3,"; // dist pattern[0] = "2,3,4,"; // azimutal pattern[1] = "-3,-4,-5,"; //polar - pattern[3] = "75.9638,68.1986,63.4349,"; // atan(4,5,6)/dist; // az_width - pattern[4] = "78.6901,71.5651,66.8014,"; // atan(5,6,7)/dist; // pol_width + pattern[3] = "78.6901,71.5651,66.8014,"; // atan(5,6,7)/dist; // pol_width + pattern[4] = "75.9638,68.1986,63.4349,"; // atan(4,5,6)/dist; // az_width for(int i=0;i<5;i++){ std::stringstream buf; for(int j=0;j<3;j++){ @@ -147,11 +147,11 @@ class FindDetectorsParTest : public CxxTest::TestSuite Mantid::DataObjects::TableWorkspace_sptr spResult = AnalysisDataService::Instance().retrieveWS("DET_PAR2"); - TSM_ASSERT_DELTA("polar wrong ", 37.0858, spResult->cell(0,0),1.e-3); - TSM_ASSERT_DELTA("azimut wrong", 0, spResult->cell(0,1),1.e-3); - TSM_ASSERT_DELTA("flight path wrong ",7.52685, spResult->cell(0,2),1.e-3); - TSM_ASSERT_DELTA("polar width wrong ",23.2429, spResult->cell(0,3),1.e-3); // despite looking strange, this may have cence as detectors overlap; wander what MAPS will be - TSM_ASSERT_DELTA("azim width wrong ", 875.7862, spResult->cell(0,4),1.e-3); + TSM_ASSERT_DELTA("polar wrong ", 37.0451, spResult->cell(0,0),1.e-3); + TSM_ASSERT_DELTA("azimut wrong: some average angle -> 0 for many detectors", 8.1818, spResult->cell(0,1),1.e-3); + TSM_ASSERT_DELTA("flight path wrong ",7.5248, spResult->cell(0,2),1.e-3); + TSM_ASSERT_DELTA("polar width wrong ",20.0598, spResult->cell(0,3),1.e-3); + TSM_ASSERT_DELTA("azim width wrong ring of ~365deg", 354.6336, spResult->cell(0,4),1.e-3); AnalysisDataService::Instance().remove("DET_PAR2"); @@ -499,8 +499,8 @@ class FindDetectorsParTest : public CxxTest::TestSuite std::string azim_pattern("0,0,0,"); std::string pol_pattern("170.565,169.565,168.565,"); std::string sfp_pattern("1,1,1,"); + std::string polw_pattern("0.804071,0.804258,0.804442,"); std::string azw_pattern("5.72472,5.72472,5.72472,"); - std::string polw_pattern("0.792313,0.789995,0.787437,"); std::auto_ptr bufs[5]; @@ -513,8 +513,9 @@ class FindDetectorsParTest : public CxxTest::TestSuite TSM_ASSERT_EQUALS("azimut wrong",pol_pattern,bufs[0]->str()); TSM_ASSERT_EQUALS("polar wrong ",azim_pattern,bufs[1]->str()); TSM_ASSERT_EQUALS("flight path wrong ",sfp_pattern,bufs[2]->str()); - TSM_ASSERT_EQUALS("azim width wrong ",polw_pattern,bufs[3]->str()); - TSM_ASSERT_EQUALS("polar width wrong ",azw_pattern,bufs[4]->str()); + TSM_ASSERT_EQUALS("polar width wrong ",polw_pattern,bufs[3]->str()); + TSM_ASSERT_EQUALS("azimuthal width wrong ",azw_pattern,bufs[4]->str()); + } }; #endif